Skip to content

Commit 5ff28b4

Browse files
committed
fix(telegram): narrow resolveModelSelection callback type via destructure
1 parent 6d154a2 commit 5ff28b4

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎extensions/telegram/src/model-buttons.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,49 +154,50 @@ export function resolveModelSelection(params: {
154154
providers: readonly string[];
155155
byProvider: ReadonlyMap<string, ReadonlySet<string>>;
156156
}): ResolveModelSelectionResult {
157-
if (params.callback.type === "select-index") {
158-
const modelSet = params.byProvider.get(params.callback.provider);
157+
const { callback } = params;
158+
if (callback.type === "select-index") {
159+
const modelSet = params.byProvider.get(callback.provider);
159160
if (!modelSet || modelSet.size === 0) {
160161
return {
161162
kind: "ambiguous",
162-
model: `<index:${params.callback.index}>`,
163+
model: `<index:${callback.index}>`,
163164
matchingProviders: [],
164165
};
165166
}
166167
// The keyboard sorts the provider's models alphabetically before paginating,
167168
// so the index in the callback maps directly to the sorted list position.
168169
const sortedModels = [...modelSet].toSorted((left, right) => left.localeCompare(right));
169-
const model = sortedModels[params.callback.index];
170+
const model = sortedModels[callback.index];
170171
if (!model) {
171172
return {
172173
kind: "ambiguous",
173-
model: `<index:${params.callback.index}>`,
174+
model: `<index:${callback.index}>`,
174175
matchingProviders: [],
175176
};
176177
}
177-
return { kind: "resolved", provider: params.callback.provider, model };
178+
return { kind: "resolved", provider: callback.provider, model };
178179
}
179180

180-
if (params.callback.provider) {
181+
if (callback.provider) {
181182
return {
182183
kind: "resolved",
183-
provider: params.callback.provider,
184-
model: params.callback.model,
184+
provider: callback.provider,
185+
model: callback.model,
185186
};
186187
}
187188
const matchingProviders = params.providers.filter((id) =>
188-
params.byProvider.get(id)?.has(params.callback.model),
189+
params.byProvider.get(id)?.has(callback.model),
189190
);
190191
if (matchingProviders.length === 1) {
191192
return {
192193
kind: "resolved",
193194
provider: matchingProviders[0],
194-
model: params.callback.model,
195+
model: callback.model,
195196
};
196197
}
197198
return {
198199
kind: "ambiguous",
199-
model: params.callback.model,
200+
model: callback.model,
200201
matchingProviders,
201202
};
202203
}

0 commit comments

Comments
 (0)