style: format native commands bits

This commit is contained in:
Peter Steinberger
2026-01-12 22:45:47 +00:00
parent 2785009c6f
commit 2e08a868a7
3 changed files with 41 additions and 35 deletions

View File

@@ -1977,7 +1977,9 @@ describe("directive behavior", () => {
baseUrl: "http://127.0.0.1:1234/v1",
apiKey: "lmstudio",
api: "openai-responses",
models: [{ id: "minimax-m2.1-gs32", name: "MiniMax M2.1 GS32" }],
models: [
{ id: "minimax-m2.1-gs32", name: "MiniMax M2.1 GS32" },
],
},
},
},
@@ -1986,11 +1988,11 @@ describe("directive behavior", () => {
);
const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text).toContain("Model set to minimax/MiniMax-M2.1");
expect(text).toContain("Model reset to default (minimax/MiniMax-M2.1).");
const store = loadSessionStore(storePath);
const entry = store["agent:main:main"];
expect(entry.modelOverride).toBe("MiniMax-M2.1");
expect(entry.providerOverride).toBe("minimax");
expect(entry.modelOverride).toBeUndefined();
expect(entry.providerOverride).toBeUndefined();
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
});
});

View File

@@ -74,10 +74,8 @@ function scoreFuzzyMatch(params: {
if (!fragment) return 0;
let score = 0;
if (value === fragment) score = Math.max(score, weights.exact);
if (value.startsWith(fragment))
score = Math.max(score, weights.starts);
if (value.includes(fragment))
score = Math.max(score, weights.includes);
if (value.startsWith(fragment)) score = Math.max(score, weights.starts);
if (value.includes(fragment)) score = Math.max(score, weights.includes);
return score;
};

View File

@@ -954,36 +954,40 @@ export function createTelegramBot(opts: TelegramBotOptions) {
logVerbose("telegram: setMyCommands unavailable; skipping registration");
}
if (typeof (bot as unknown as { command?: unknown }).command !== "function") {
if (
typeof (bot as unknown as { command?: unknown }).command !== "function"
) {
logVerbose("telegram: bot.command unavailable; skipping native handlers");
} else {
for (const command of nativeCommands) {
bot.command(command.name, async (ctx) => {
const msg = ctx.message;
if (!msg) return;
if (shouldSkipUpdate(ctx)) return;
const chatId = msg.chat.id;
const isGroup =
msg.chat.type === "group" || msg.chat.type === "supergroup";
const messageThreadId = (msg as { message_thread_id?: number })
.message_thread_id;
const isForum = (msg.chat as { is_forum?: boolean }).is_forum === true;
const storeAllowFrom = await readTelegramAllowFromStore().catch(
() => [],
);
const { groupConfig, topicConfig } = resolveTelegramGroupConfig(
chatId,
messageThreadId,
);
const groupAllowOverride = firstDefined(
topicConfig?.allowFrom,
groupConfig?.allowFrom,
);
const effectiveGroupAllow = normalizeAllowFrom([
...(groupAllowOverride ?? groupAllowFrom ?? []),
...storeAllowFrom,
]);
const hasGroupAllowOverride = typeof groupAllowOverride !== "undefined";
const msg = ctx.message;
if (!msg) return;
if (shouldSkipUpdate(ctx)) return;
const chatId = msg.chat.id;
const isGroup =
msg.chat.type === "group" || msg.chat.type === "supergroup";
const messageThreadId = (msg as { message_thread_id?: number })
.message_thread_id;
const isForum =
(msg.chat as { is_forum?: boolean }).is_forum === true;
const storeAllowFrom = await readTelegramAllowFromStore().catch(
() => [],
);
const { groupConfig, topicConfig } = resolveTelegramGroupConfig(
chatId,
messageThreadId,
);
const groupAllowOverride = firstDefined(
topicConfig?.allowFrom,
groupConfig?.allowFrom,
);
const effectiveGroupAllow = normalizeAllowFrom([
...(groupAllowOverride ?? groupAllowFrom ?? []),
...storeAllowFrom,
]);
const hasGroupAllowOverride =
typeof groupAllowOverride !== "undefined";
if (isGroup && groupConfig?.enabled === false) {
await bot.api.sendMessage(chatId, "This group is disabled.");
@@ -1148,7 +1152,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
}
}
} else if (nativeDisabledExplicit) {
const api = bot.api as unknown as { setMyCommands?: (commands: []) => Promise<unknown> };
const api = bot.api as unknown as {
setMyCommands?: (commands: []) => Promise<unknown>;
};
if (typeof api.setMyCommands === "function") {
api.setMyCommands([]).catch((err) => {
runtime.error?.(