fix(types): stabilize skill token extraction (#9920)

This commit is contained in:
backryun
2026-08-10 12:28:07 +09:00
committed by GitHub
parent f390327c88
commit de2679f6d1
2 changed files with 27 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ function toLowerText(value: unknown): string {
}
function extractTokens(value: string): Set<string> {
const matches = value.toLowerCase().match(/[a-z0-9]+/g) || [];
const matches: string[] = value.toLowerCase().match(/[a-z0-9]+/g) ?? [];
return new Set(matches.filter((t) => t.length >= TOKEN_MIN_LEN));
}

View File

@@ -186,6 +186,32 @@ test("injectSkills auto mode matches message/context semantics and applies score
});
});
test("injectSkills auto mode only scores name tokens with at least three characters", async () => {
for (const name of ["aiSearch", "apiSearch"]) {
await skillRegistry.register({
name,
version: "1.0.0",
description: "find",
schema: { input: {}, output: {} },
handler: `${name}-handler`,
enabled: true,
mode: "auto",
apiKeyId: "key-token-length",
});
}
const tools = injectSkills({
provider: "other",
apiKeyId: "key-token-length",
messages: [{ role: "user", content: "ai api find" }],
});
assert.deepEqual(
tools.map((tool) => (tool as { function: { name: string } }).function.name),
["apiSearch@1.0.0"]
);
});
test("injectSkills auto mode prefers provider-matching tagged skills", async () => {
await skillRegistry.register({
name: "openaiDocTool",