feat(tui): autocomplete skill references

This commit is contained in:
chengyongru
2026-08-25 23:11:24 +08:00
committed by chengyongru
parent 649e3958c5
commit b218d3e7f8
7 changed files with 436 additions and 6 deletions
+48
View File
@@ -3,6 +3,7 @@ import { describe, expect, test } from "bun:test"
import {
NanobotClient,
GatewayConnectionError,
fetchAvailableSkills,
fetchGatewayConnection,
fetchHistory,
fetchMentionCandidates,
@@ -805,6 +806,53 @@ describe("gateway protocol", () => {
}
})
test("loads only enabled and available skills", async () => {
const original = globalThis.fetch
let authorization = ""
globalThis.fetch = ((_: string | URL | Request, init?: RequestInit) => {
authorization = new Headers(init?.headers).get("Authorization") || ""
return Promise.resolve(new Response(JSON.stringify({
skills: [
{
name: "verify",
description: "Verify public behavior",
source: "builtin",
enabled: true,
available: true,
},
{
name: "disabled",
description: "Disabled skill",
source: "workspace",
enabled: false,
available: true,
},
{
name: "unavailable",
description: "Missing dependency",
source: "builtin",
enabled: true,
available: false,
},
{ name: "my skill", enabled: true, available: true },
{ name: "技能", enabled: true, available: true },
{ enabled: true, available: true },
],
})))
}) as typeof fetch
try {
expect(await fetchAvailableSkills("http://nanobot.test", "secret")).toEqual([{
name: "verify",
description: "Verify public behavior",
source: "builtin",
}])
expect(authorization).toBe("Bearer secret")
} finally {
globalThis.fetch = original
}
})
test("drops slash commands with unknown lifecycle metadata", async () => {
const original = globalThis.fetch
globalThis.fetch = (() => Promise.resolve(new Response(JSON.stringify({