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", baseUrl: "http://127.0.0.1:1234/v1",
apiKey: "lmstudio", apiKey: "lmstudio",
api: "openai-responses", 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; 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 store = loadSessionStore(storePath);
const entry = store["agent:main:main"]; const entry = store["agent:main:main"];
expect(entry.modelOverride).toBe("MiniMax-M2.1"); expect(entry.modelOverride).toBeUndefined();
expect(entry.providerOverride).toBe("minimax"); expect(entry.providerOverride).toBeUndefined();
expect(runEmbeddedPiAgent).not.toHaveBeenCalled(); expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
}); });
}); });

View File

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

View File

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