Skip to content

Commit 50463bd

Browse files
authored
Merge pull request #72 from odefun/feat/channel-models-provider-1770589
fix: update channel model selectors by provider
2 parents 375c146 + dd93f3e commit 50463bd

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed

packages/ims/slack/commands.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,31 @@ function buildSettingsModal(params: {
132132
text: { type: "plain_text" as const, text: AGENT_PROVIDER_LABELS[provider] },
133133
value: provider,
134134
}));
135-
const modelOptions = opencodeModels.length > 0
136-
? opencodeModels.map((model) => ({
137-
text: { type: "plain_text" as const, text: model },
138-
value: model,
139-
}))
140-
: [{ text: { type: "plain_text" as const, text: "No models configured" }, value: "__none__" }];
141-
const codexModelOptions = [
142-
{ text: { type: "plain_text" as const, text: "Use default (gpt-5.3-codex)" }, value: "__default__" },
143-
...codexModels.map((model) => ({
144-
text: { type: "plain_text" as const, text: model },
145-
value: model,
146-
})),
147-
];
148-
149-
const availableModels = selectedProvider === "codex" ? codexModelOptions.map((entry) => entry.value) : opencodeModels;
135+
const providerModels = selectedProvider === "opencode"
136+
? opencodeModels
137+
: selectedProvider === "codex"
138+
? codexModels
139+
: null;
140+
const modelOptions = providerModels && selectedProvider === "opencode"
141+
? (opencodeModels.length > 0
142+
? opencodeModels.map((model) => ({
143+
text: { type: "plain_text" as const, text: model },
144+
value: model,
145+
}))
146+
: [{ text: { type: "plain_text" as const, text: "No models configured" }, value: "__none__" }])
147+
: providerModels && selectedProvider === "codex"
148+
? [
149+
{ text: { type: "plain_text" as const, text: "Use default (gpt-5.3-codex)" }, value: "__default__" },
150+
...codexModels.map((model) => ({
151+
text: { type: "plain_text" as const, text: model },
152+
value: model,
153+
})),
154+
]
155+
: [];
156+
157+
const availableModels = selectedProvider === "codex"
158+
? modelOptions.map((entry) => entry.value)
159+
: providerModels ?? [];
150160
const matchedSelectedModel = findMatchingModel(availableModels, selectedModel);
151161
const initialModel = matchedSelectedModel
152162
? matchedSelectedModel
@@ -168,6 +178,7 @@ function buildSettingsModal(params: {
168178
{
169179
type: "input" as const,
170180
block_id: PROVIDER_BLOCK,
181+
dispatch_action: true,
171182
label: { type: "plain_text" as const, text: "Provider" },
172183
element: {
173184
type: "static_select" as const,
@@ -178,9 +189,8 @@ function buildSettingsModal(params: {
178189
},
179190
];
180191

181-
if (selectedProvider === "opencode" || selectedProvider === "codex") {
182-
const options = selectedProvider === "opencode" ? modelOptions : codexModelOptions;
183-
const initialOption = options.find((option) => option.value === initialModel);
192+
if (providerModels) {
193+
const initialOption = modelOptions.find((option) => option.value === initialModel);
184194
blocks.push(
185195
{
186196
type: "input" as const,
@@ -190,7 +200,7 @@ function buildSettingsModal(params: {
190200
element: {
191201
type: "static_select" as const,
192202
action_id: MODEL_ACTION,
193-
options,
203+
options: modelOptions,
194204
initial_option: initialOption,
195205
},
196206
},

packages/web-ui/src/routes/local-setting/slack-bot/[workspaceName]/+page.svelte

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,20 @@
6565
}
6666
6767
function shouldShowChannelModel(channel: { agentProvider?: string }): boolean {
68-
return getChannelProvider(channel) === "opencode";
68+
const provider = getChannelProvider(channel);
69+
return getProviderModels(provider) !== null;
70+
}
71+
72+
function getProviderModels(provider: AgentProvider): string[] | null {
73+
const config = $localSettingStore.config.agents as Record<string, { models?: string[] }>;
74+
const entry = config[provider];
75+
return Array.isArray(entry?.models) ? entry.models : null;
76+
}
77+
78+
function getChannelModelSelectValue(channel: { agentProvider?: string; model: string }): string {
79+
const provider = getChannelProvider(channel);
80+
if (provider === "codex" && !channel.model) return "__default__";
81+
return channel.model;
6982
}
7083
7184
function onWorkspaceFieldInput(
@@ -90,16 +103,20 @@
90103
function onChannelProviderChange(workspaceId: string, channelId: string, event: Event): void {
91104
const selected = (event.currentTarget as HTMLSelectElement).value;
92105
const provider = parseAgentProvider(selected);
106+
const providerModels = getProviderModels(provider) ?? [];
93107
localSettingStore.updateWorkspace(workspaceId, (workspace) => ({
94108
...workspace,
95109
channelDetails: workspace.channelDetails.map((channel) => {
96110
if (channel.id !== channelId) return channel;
111+
const nextModel = provider === "codex"
112+
? (providerModels.includes(channel.model) ? channel.model : "")
113+
: (providerModels.length > 0
114+
? (providerModels.includes(channel.model) ? channel.model : (providerModels[0] ?? ""))
115+
: "");
97116
return {
98117
...channel,
99118
agentProvider: provider,
100-
model: provider === "opencode"
101-
? channel.model || $localSettingStore.config.agents.opencode.models[0] || ""
102-
: "",
119+
model: nextModel,
103120
};
104121
}),
105122
}));
@@ -115,7 +132,8 @@
115132
}
116133
117134
function onChannelModelSelect(workspaceId: string, channelId: string, event: Event): void {
118-
onChannelModelChange(workspaceId, channelId, (event.currentTarget as HTMLSelectElement).value);
135+
const value = (event.currentTarget as HTMLSelectElement).value;
136+
onChannelModelChange(workspaceId, channelId, value === "__default__" ? "" : value);
119137
}
120138
121139
function onChannelWorkingDirectoryChange(workspaceId: string, channelId: string, workingDirectory: string): void {
@@ -279,13 +297,20 @@
279297
<label for={`channel-model-${channel.id}`}>Model</label>
280298
<select
281299
id={`channel-model-${channel.id}`}
282-
value={channel.model}
300+
value={getChannelModelSelectValue(channel)}
283301
on:change={(event) => onChannelModelSelect(selectedWorkspace.id, channel.id, event)}
284302
>
285-
{#if !$localSettingStore.config.agents.opencode.models.includes(channel.model) && channel.model}
303+
{#if getChannelProvider(channel) === "codex"}
304+
<option value="__default__">Use default (gpt-5.3-codex)</option>
305+
{/if}
306+
{#if (getProviderModels(getChannelProvider(channel)) ?? []).length === 0
307+
&& getChannelProvider(channel) !== "codex"}
308+
<option value="" disabled>No models configured</option>
309+
{/if}
310+
{#if !(getProviderModels(getChannelProvider(channel)) ?? []).includes(channel.model) && channel.model}
286311
<option value={channel.model}>{channel.model}</option>
287312
{/if}
288-
{#each $localSettingStore.config.agents.opencode.models as model}
313+
{#each getProviderModels(getChannelProvider(channel)) ?? [] as model}
289314
<option value={model}>{model}</option>
290315
{/each}
291316
</select>

0 commit comments

Comments
 (0)