@inupedia/spotlight-client 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @inupedia/spotlight-client
2
2
 
3
- Spotlight 的浏览器 Tool SDK。业务项目只需要用 `defineClientTool` 包装已有函数;Tool 名称、说明和 JSON Schema 在构建期自动生成。
3
+ Spotlight 的浏览器 Tool SDK。业务项目只注册 Tools / Skills,然后调用 `thread.run()`;Tool 名称、说明、JSON Schema、manifest digest、Capability Session、SSE 重连和 Tool 结果回传都由 SDK 处理。
4
4
 
5
5
  ```ts
6
6
  import { defineClientTool } from "@inupedia/spotlight-client";
@@ -11,6 +11,18 @@ export const playVideoFullscreen = defineClientTool(
11
11
  await videoService.playFullscreen(name);
12
12
  },
13
13
  );
14
+
15
+ const client = createSpotlightAppClient({
16
+ serverUrl: "/spotlight-api",
17
+ projectId: "my-project",
18
+ frontendBuildId: import.meta.env.VITE_BUILD_SHA,
19
+ tools: [playVideoFullscreen],
20
+ skills: [videoMonitoringSkill],
21
+ });
22
+
23
+ const thread = client.thread();
24
+ const result = await thread.run("看看泸定取水口");
25
+ console.log(result.finalResponse);
14
26
  ```
15
27
 
16
28
  Vite 项目必须启用构建插件:
@@ -24,7 +36,7 @@ spotlightClientTools({
24
36
  });
25
37
  ```
26
38
 
27
- 生产构建会输出 `spotlight-client-manifest.json`。Server 只信任 CI 发布、与前端 Build ID 绑定的清单,不信任浏览器临时声明的 Tool。
39
+ 生产构建会输出 `spotlight-client-manifest.json`。首次初始化后 Server 保存不可变 Capability Snapshot,后续 Turn 不再重复上传整份 Tools / Skills。
28
40
 
29
41
  完整接入、显式 Schema 和生产部署见 [Client Tool 接入指南](../../docs/client-tools.md)。
30
42
 
@@ -0,0 +1,76 @@
1
+ import { type FrontendToolManifestV1, type HostToolResultRequest, type SpotlightInitializeResponse, type SpotlightItem, type SpotlightSkill, type SpotlightSkillRegistration, type SpotlightThread, type SpotlightTurn, type SpotlightTurnEvent, type SpotlightTurnStartRequest } from "@inupedia/spotlight-protocol";
2
+ import { type SpotlightClientConfig } from "./http.js";
3
+ import { type ClientTool } from "./clientTool.js";
4
+ export interface SpotlightAppClientOptions extends SpotlightClientConfig {
5
+ toolManifest?: FrontendToolManifestV1 | (() => FrontendToolManifestV1 | Promise<FrontendToolManifestV1>);
6
+ /** Preferred: register Tools and let the SDK derive and snapshot the manifest. */
7
+ tools?: readonly ClientTool[] | (() => readonly ClientTool[]);
8
+ frontendBuildId?: string;
9
+ skills?: Array<SpotlightSkill | SpotlightSkillRegistration> | (() => Array<SpotlightSkill | SpotlightSkillRegistration>);
10
+ executeTool?: (request: {
11
+ turnId: string;
12
+ item: Extract<SpotlightItem, {
13
+ type: "tool_call";
14
+ }>;
15
+ }) => Promise<{
16
+ success: boolean;
17
+ output?: unknown;
18
+ error?: string;
19
+ trace?: HostToolResultRequest["trace"];
20
+ uiContext?: HostToolResultRequest["uiContext"];
21
+ }>;
22
+ approveTool?: (request: {
23
+ turnId: string;
24
+ item: Extract<SpotlightItem, {
25
+ type: "tool_call";
26
+ }>;
27
+ reason?: string;
28
+ }) => boolean | Promise<boolean>;
29
+ clientInfo?: {
30
+ name?: string;
31
+ title?: string;
32
+ version?: string;
33
+ };
34
+ }
35
+ export interface SpotlightRunResult {
36
+ thread: SpotlightThread;
37
+ turn: SpotlightTurn;
38
+ events: SpotlightTurnEvent[];
39
+ items: SpotlightItem[];
40
+ finalResponse: string;
41
+ summary?: Extract<SpotlightTurnEvent, {
42
+ type: "turn.completed";
43
+ }>["summary"];
44
+ }
45
+ export interface SpotlightRunOptions extends Omit<SpotlightTurnStartRequest, "input"> {
46
+ signal?: AbortSignal;
47
+ threadId?: string;
48
+ }
49
+ export interface SpotlightThreadHandle {
50
+ readonly id: string | undefined;
51
+ run(input: string, options?: Omit<SpotlightRunOptions, "threadId">): Promise<SpotlightRunResult>;
52
+ }
53
+ export declare class SpotlightAppClient {
54
+ private readonly options;
55
+ private readonly http;
56
+ private initialization;
57
+ private initializedDigest;
58
+ private capabilitySessionId;
59
+ private toolRegistry;
60
+ constructor(options: SpotlightAppClientOptions);
61
+ private manifest;
62
+ initialize(signal?: AbortSignal): Promise<SpotlightInitializeResponse>;
63
+ startThread(threadId?: string, signal?: AbortSignal): Promise<SpotlightThread>;
64
+ thread(threadId?: string): SpotlightThreadHandle;
65
+ listThreads(signal?: AbortSignal): Promise<SpotlightThread[]>;
66
+ forkThread(threadId: string, signal?: AbortSignal): Promise<SpotlightThread>;
67
+ startTurn(threadId: string, request: SpotlightTurnStartRequest, signal?: AbortSignal): Promise<SpotlightTurn>;
68
+ run(input: string, options?: SpotlightRunOptions): Promise<SpotlightRunResult>;
69
+ streamTurn(turnId: string, signal?: AbortSignal): AsyncGenerator<SpotlightTurnEvent>;
70
+ submitToolResult(turnId: string, result: HostToolResultRequest, signal?: AbortSignal): Promise<{
71
+ ok: true;
72
+ }>;
73
+ cancelTurn(turnId: string): Promise<void>;
74
+ }
75
+ export declare function createSpotlightAppClient(options: SpotlightAppClientOptions): SpotlightAppClient;
76
+ //# sourceMappingURL=appClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appClient.d.ts","sourceRoot":"","sources":["../src/appClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,yBAA0B,SAAQ,qBAAqB;IACtE,YAAY,CAAC,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AQ7D,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAS5E,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,yBAAyB,EAClC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC;IAoBnB,GAAG,CACP,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAyDvB,UAAU,CACf,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,kBAAkB,CAAC;IAyDrC,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,qBAAqB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,CAAC;IAQxB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM1C;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,yBAAyB,GACjC,kBAAkB,CAEpB"}
@@ -0,0 +1,282 @@
1
+ import { SPOTLIGHT_APP_PROTOCOL_V1, defaultSpotlightClientCapabilities, spotlightSkillToolNames, } from "@inupedia/spotlight-protocol";
2
+ import { buildJsonHeaders, createSpotlightHttp, SpotlightHttpError, } from "./http.js";
3
+ import { createClientToolManifest, createClientToolRegistry, } from "./clientTool.js";
4
+ function valueOf(value) {
5
+ return typeof value === "function" ? value() : value;
6
+ }
7
+ function normalizeSkills(skills) {
8
+ const definitions = skills.map((skill) => {
9
+ const candidate = skill;
10
+ return {
11
+ ...candidate,
12
+ policy: candidate.policy ?? {
13
+ allowImplicitInvocation: candidate.allowImplicitInvocation !== false,
14
+ },
15
+ };
16
+ });
17
+ return {
18
+ definitions,
19
+ registrations: definitions.map((skill) => ({
20
+ name: skill.name,
21
+ displayName: skill.interface?.displayName ?? skill.displayName,
22
+ description: skill.description,
23
+ version: skill.version,
24
+ allowImplicitInvocation: skill.policy?.allowImplicitInvocation ?? skill.disableModelInvocation !== true,
25
+ userInvocable: skill.userInvocable,
26
+ dependencies: { tools: spotlightSkillToolNames(skill) },
27
+ })),
28
+ };
29
+ }
30
+ async function asyncValueOf(value) {
31
+ return typeof value === "function"
32
+ ? await value()
33
+ : value;
34
+ }
35
+ function reconnectDelay(attempt) {
36
+ return Math.min(400 * 2 ** attempt, 5_000);
37
+ }
38
+ function wait(ms) {
39
+ return new Promise((resolve) => setTimeout(resolve, ms));
40
+ }
41
+ function parseSseFrames(buffer) {
42
+ const frames = buffer.split(/\n\n/u);
43
+ const rest = frames.pop() ?? "";
44
+ const events = frames.flatMap((frame) => {
45
+ const data = frame
46
+ .split(/\n/u)
47
+ .filter((line) => line.startsWith("data:"))
48
+ .map((line) => line.slice(5).trimStart())
49
+ .join("\n");
50
+ if (!data)
51
+ return [];
52
+ try {
53
+ const parsed = JSON.parse(data);
54
+ return parsed.type === "ping" && !("seq" in parsed)
55
+ ? []
56
+ : [parsed];
57
+ }
58
+ catch {
59
+ return [];
60
+ }
61
+ });
62
+ return { events, rest };
63
+ }
64
+ export class SpotlightAppClient {
65
+ options;
66
+ http;
67
+ initialization = null;
68
+ initializedDigest = null;
69
+ capabilitySessionId = null;
70
+ toolRegistry = null;
71
+ constructor(options) {
72
+ this.options = options;
73
+ this.http = createSpotlightHttp(options);
74
+ }
75
+ async manifest() {
76
+ if (this.options.toolManifest)
77
+ return asyncValueOf(this.options.toolManifest);
78
+ if (!this.options.tools) {
79
+ throw new Error("Spotlight requires tools or toolManifest");
80
+ }
81
+ const tools = valueOf(this.options.tools);
82
+ this.toolRegistry = createClientToolRegistry(tools);
83
+ return createClientToolManifest({
84
+ projectId: this.options.projectId,
85
+ frontendBuildId: this.options.frontendBuildId?.trim() || "development",
86
+ tools,
87
+ });
88
+ }
89
+ async initialize(signal) {
90
+ const manifest = await this.manifest();
91
+ if (this.initialization && this.initializedDigest === manifest.manifestDigest) {
92
+ return this.initialization;
93
+ }
94
+ this.initializedDigest = manifest.manifestDigest;
95
+ const normalizedSkills = normalizeSkills(this.options.skills ? valueOf(this.options.skills) : []);
96
+ this.initialization = this.http.postJson("/v1/initialize", {
97
+ protocolVersion: SPOTLIGHT_APP_PROTOCOL_V1,
98
+ projectId: this.options.projectId,
99
+ clientInfo: {
100
+ name: this.options.clientInfo?.name ?? "spotlight-typescript",
101
+ title: this.options.clientInfo?.title,
102
+ version: this.options.clientInfo?.version ?? "0.7.1",
103
+ },
104
+ capabilities: defaultSpotlightClientCapabilities(),
105
+ toolManifest: manifest,
106
+ skills: normalizedSkills.registrations,
107
+ skillDefinitions: normalizedSkills.definitions,
108
+ }, signal).then((response) => {
109
+ this.capabilitySessionId = response.capabilitySession.id;
110
+ return response;
111
+ }).catch((error) => {
112
+ this.initialization = null;
113
+ this.capabilitySessionId = null;
114
+ throw error;
115
+ });
116
+ return this.initialization;
117
+ }
118
+ async startThread(threadId, signal) {
119
+ await this.initialize(signal);
120
+ const response = await this.http.postJson("/v1/threads", { projectId: this.options.projectId, threadId }, signal);
121
+ return response.thread;
122
+ }
123
+ thread(threadId) {
124
+ let resolvedId = threadId;
125
+ return {
126
+ get id() {
127
+ return resolvedId;
128
+ },
129
+ run: async (input, options = {}) => {
130
+ const result = await this.run(input, { ...options, threadId: resolvedId });
131
+ resolvedId = result.thread.id;
132
+ return result;
133
+ },
134
+ };
135
+ }
136
+ async listThreads(signal) {
137
+ const response = await this.http.getJson("/v1/threads", signal);
138
+ return response.threads;
139
+ }
140
+ async forkThread(threadId, signal) {
141
+ const response = await this.http.postJson(`/v1/threads/${encodeURIComponent(threadId)}/fork`, {}, signal);
142
+ return response.thread;
143
+ }
144
+ async startTurn(threadId, request, signal) {
145
+ await this.initialize(signal);
146
+ const start = () => this.http.postJson(`/v1/threads/${encodeURIComponent(threadId)}/turns`, { ...request, capabilitySessionId: request.capabilitySessionId ?? this.capabilitySessionId }, signal);
147
+ try {
148
+ return (await start()).turn;
149
+ }
150
+ catch (error) {
151
+ if (!(error instanceof SpotlightHttpError) || error.code !== "CAPABILITY_SESSION_EXPIRED") {
152
+ throw error;
153
+ }
154
+ this.initialization = null;
155
+ this.capabilitySessionId = null;
156
+ await this.initialize(signal);
157
+ return (await start()).turn;
158
+ }
159
+ }
160
+ async run(input, options = {}) {
161
+ const { signal, threadId, ...request } = options;
162
+ const thread = await this.startThread(threadId, signal);
163
+ const turn = await this.startTurn(thread.id, { ...request, input }, signal);
164
+ const events = [];
165
+ const items = new Map();
166
+ const submitted = new Set();
167
+ let finalResponse = "";
168
+ let summary;
169
+ for await (const event of this.streamTurn(turn.id, signal)) {
170
+ events.push(event);
171
+ if (event.type === "item.started" || event.type === "item.updated" || event.type === "item.completed") {
172
+ items.set(event.item.id, event.item);
173
+ const clientRequest = event.item.type === "tool_call" ? event.item.clientRequest : undefined;
174
+ if (event.item.type === "tool_call" &&
175
+ event.item.status === "waiting_for_client" &&
176
+ clientRequest &&
177
+ !submitted.has(clientRequest.correlationId)) {
178
+ submitted.add(clientRequest.correlationId);
179
+ let approved = !clientRequest.approvalRequired;
180
+ if (!approved && this.options.approveTool) {
181
+ approved = await this.options.approveTool({
182
+ turnId: turn.id,
183
+ item: event.item,
184
+ reason: clientRequest.approvalReason,
185
+ });
186
+ }
187
+ const result = !approved
188
+ ? { success: false, error: "Tool execution was not approved" }
189
+ : this.options.executeTool
190
+ ? await this.options.executeTool({ turnId: turn.id, item: event.item })
191
+ : this.toolRegistry?.has(event.item.tool)
192
+ ? {
193
+ success: true,
194
+ output: await this.toolRegistry.execute(event.item.tool, event.item.arguments),
195
+ }
196
+ : { success: false, error: `Client tool is not registered: ${event.item.tool}` };
197
+ await this.submitToolResult(turn.id, {
198
+ correlationId: clientRequest.correlationId,
199
+ ...result,
200
+ }, signal);
201
+ }
202
+ }
203
+ else if (event.type === "turn.failed") {
204
+ throw new Error(event.error.message);
205
+ }
206
+ else if (event.type === "turn.completed") {
207
+ finalResponse = event.finalResponse;
208
+ summary = event.summary;
209
+ }
210
+ }
211
+ return { thread, turn, events, items: [...items.values()], finalResponse, summary };
212
+ }
213
+ async *streamTurn(turnId, signal) {
214
+ let lastSeq = 0;
215
+ let reconnects = 0;
216
+ while (!signal?.aborted) {
217
+ const query = lastSeq > 0 ? `?lastEventId=${lastSeq}` : "";
218
+ let response;
219
+ try {
220
+ response = await fetch(`${this.http.getBase()}/v1/turns/${encodeURIComponent(turnId)}/events${query}`, { headers: buildJsonHeaders(this.http.config), signal });
221
+ }
222
+ catch (error) {
223
+ if (signal?.aborted)
224
+ throw error;
225
+ reconnects += 1;
226
+ if (reconnects > 6)
227
+ throw error;
228
+ await wait(reconnectDelay(reconnects - 1));
229
+ continue;
230
+ }
231
+ if (response.status === 410) {
232
+ throw new Error("Spotlight 后端已不再保留这次 Turn,请重新提问。");
233
+ }
234
+ if (!response.ok || !response.body) {
235
+ throw new Error(`Spotlight Turn 事件流连接失败:${response.status}`);
236
+ }
237
+ const reader = response.body.getReader();
238
+ const decoder = new TextDecoder();
239
+ let buffer = "";
240
+ let terminal = false;
241
+ try {
242
+ while (true) {
243
+ const { done, value } = await reader.read();
244
+ if (done)
245
+ break;
246
+ buffer += decoder.decode(value, { stream: true });
247
+ const parsed = parseSseFrames(buffer);
248
+ buffer = parsed.rest;
249
+ for (const event of parsed.events) {
250
+ if (event.seq <= lastSeq)
251
+ continue;
252
+ lastSeq = event.seq;
253
+ yield event;
254
+ if (event.type === "turn.completed" || event.type === "turn.failed") {
255
+ terminal = true;
256
+ return;
257
+ }
258
+ }
259
+ }
260
+ }
261
+ finally {
262
+ reader.releaseLock();
263
+ }
264
+ if (terminal || signal?.aborted)
265
+ return;
266
+ reconnects += 1;
267
+ if (reconnects > 6) {
268
+ throw new Error("Spotlight Turn 事件流多次重连失败,请重试。");
269
+ }
270
+ await wait(reconnectDelay(reconnects - 1));
271
+ }
272
+ }
273
+ submitToolResult(turnId, result, signal) {
274
+ return this.http.postJson(`/v1/turns/${encodeURIComponent(turnId)}/tool-results`, result, signal);
275
+ }
276
+ cancelTurn(turnId) {
277
+ return fetch(`${this.http.getBase()}/v1/turns/${encodeURIComponent(turnId)}`, { method: "DELETE", headers: buildJsonHeaders(this.http.config) }).then(() => undefined);
278
+ }
279
+ }
280
+ export function createSpotlightAppClient(options) {
281
+ return new SpotlightAppClient(options);
282
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"clientTool.d.ts","sourceRoot":"","sources":["../src/clientTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAChB,MAAM,8BAA8B,CAAC;AAEtC,eAAO,MAAM,gBAAgB,eAA+C,CAAC;AAE7E,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,wBAAwB,CAAC;CAClC;AAED,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,IAAI,CAC/C,KAAK,EAAE,MAAM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U,EAAE;;cAyBvD,MAAM,GAAG,OAAO;kBAGN,MAAM,SAAS,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;EAMhE;AAuHD,wBAAsB,wBAAwB,CAAC,OAAO,EAAE;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAelC"}
@@ -53,13 +53,14 @@ export function createClientToolRegistry(tools) {
53
53
  }
54
54
  // Every dispatch path recovers by re-running the call, so a tool that
55
55
  // cannot be re-run safely must not reach the runtime at all.
56
- if (!isToolTierReplaySafe(descriptor.tier ?? "navigate")) {
56
+ if (!isToolTierReplaySafe(descriptor.tier ?? "navigate") &&
57
+ descriptor.requiresConfirmation !== true) {
57
58
  unsupported.push(descriptor.name);
58
59
  }
59
60
  byName.set(descriptor.name, tool);
60
61
  }
61
62
  if (unsupported.length > 0) {
62
- throw new Error(`Client tools at the "mutate" tier cannot be registered yet: ${unsupported.join(", ")}. See docs/design/capability-protocol-v2.md.`);
63
+ throw new Error(`Client tools at the "mutate" tier must set requiresConfirmation: true: ${unsupported.join(", ")}.`);
63
64
  }
64
65
  return {
65
66
  descriptors: [...byName.values()].map(getClientToolDescriptor),
package/dist/http.d.ts CHANGED
@@ -4,6 +4,13 @@ export interface SpotlightClientConfig {
4
4
  apiKey?: string;
5
5
  projectId: string;
6
6
  }
7
+ export declare class SpotlightHttpError extends Error {
8
+ readonly status: number;
9
+ readonly code?: string | undefined;
10
+ readonly retryable?: boolean | undefined;
11
+ readonly details?: unknown | undefined;
12
+ constructor(message: string, status: number, code?: string | undefined, retryable?: boolean | undefined, details?: unknown | undefined);
13
+ }
7
14
  export declare function normalizeServerUrl(url: string): string;
8
15
  export declare function resolveSpotlightClientConfig(partial: Partial<SpotlightClientConfig> & Pick<SpotlightClientConfig, "projectId">): SpotlightClientConfig;
9
16
  export declare function buildJsonHeaders(config: SpotlightClientConfig): Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,GACjF,qBAAqB,CAMvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAStF;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,MAAM,GACX,MAAM,CAGR;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,qBAAqB;;;;+BAQlC,MAAM;YACnB,CAAC,QAAQ,MAAM,WAAW,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;aAWjD,CAAC,QACR,MAAM,QACN,OAAO,WACJ,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC;EAchB;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAGzC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO;gBAJ1B,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,SAAS,CAAC,EAAE,OAAO,YAAA,EACnB,OAAO,CAAC,EAAE,OAAO,YAAA;CAK7B;AAsBD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,GACjF,qBAAqB,CAMvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAStF;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,MAAM,GACX,MAAM,CAGR;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,qBAAqB;;;;+BAQlC,MAAM;YACnB,CAAC,QAAQ,MAAM,WAAW,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;aAWjD,CAAC,QACR,MAAM,QACN,OAAO,WACJ,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC;EAchB;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
package/dist/http.js CHANGED
@@ -1,3 +1,28 @@
1
+ export class SpotlightHttpError extends Error {
2
+ status;
3
+ code;
4
+ retryable;
5
+ details;
6
+ constructor(message, status, code, retryable, details) {
7
+ super(message);
8
+ this.status = status;
9
+ this.code = code;
10
+ this.retryable = retryable;
11
+ this.details = details;
12
+ this.name = "SpotlightHttpError";
13
+ }
14
+ }
15
+ function responseError(method, path, status, text) {
16
+ let parsed = {};
17
+ try {
18
+ parsed = JSON.parse(text);
19
+ }
20
+ catch {
21
+ // Non-JSON reverse-proxy errors still receive a useful fallback below.
22
+ }
23
+ const error = parsed.error;
24
+ return new SpotlightHttpError(error?.message ?? parsed.message ?? `Spotlight ${method} ${path} failed: ${status}`, status, error?.code, error?.retryable, error?.details);
25
+ }
1
26
  export function normalizeServerUrl(url) {
2
27
  return url.replace(/\/$/, "");
3
28
  }
@@ -37,7 +62,7 @@ export function createSpotlightHttp(config) {
37
62
  });
38
63
  const text = await res.text().catch(() => "");
39
64
  if (!res.ok) {
40
- throw new Error(`Spotlight GET ${path} failed: ${res.status} ${text}`);
65
+ throw responseError("GET", path, res.status, text);
41
66
  }
42
67
  return JSON.parse(text);
43
68
  },
@@ -50,7 +75,7 @@ export function createSpotlightHttp(config) {
50
75
  });
51
76
  const text = await res.text().catch(() => "");
52
77
  if (!res.ok) {
53
- throw new Error(`Spotlight POST ${path} failed: ${res.status} ${text}`);
78
+ throw responseError("POST", path, res.status, text);
54
79
  }
55
80
  return JSON.parse(text);
56
81
  },
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export type { SpotlightClientConfig } from "./http.js";
2
2
  export { CLIENT_TOOL_META, createClientToolManifest, createClientToolRegistry, defineClientTool, getClientToolDescriptor, type ClientTool, type ClientToolHandler, type ClientToolOptions, type ClientToolSchemaOverride, type GeneratedClientToolMeta, } from "./clientTool.js";
3
- export { appendProjectQuery, buildJsonHeaders, createSpotlightHttp, normalizeServerUrl, resolveSpotlightClientConfig, type SpotlightHttp, } from "./http.js";
3
+ export { appendProjectQuery, buildJsonHeaders, createSpotlightHttp, normalizeServerUrl, resolveSpotlightClientConfig, SpotlightHttpError, type SpotlightHttp, } from "./http.js";
4
4
  export { fetchDefaultCommandCatalog, mergeCommandCatalogs, serializeSkillsForRemote, } from "./host.js";
5
5
  export { validateSkillFrontmatter, describeCapabilitySurface, SPOTLIGHT_LAYOUT, SPOTLIGHT_SKILL_LOAD_LEVELS, spotlightSkillsGlobPattern, type SkillValidationResult, type SpotlightSkillFrontmatter, } from "./skillServiceStandard.js";
6
6
  export { substituteSkillPlaceholders, executeInlineShellInMarkdown, prepareSkillMarkdownContent, } from "./skillPrompt.js";
7
7
  export { joinSkillScriptPath, type SkillScriptRunResult, } from "./skillScriptPath.js";
8
+ export * from "./appClient.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAClB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CLIENT_TOOL_META, createClientToolManifest, createClientToolRegistry, defineClientTool, getClientToolDescriptor, } from "./clientTool.js";
2
- export { appendProjectQuery, buildJsonHeaders, createSpotlightHttp, normalizeServerUrl, resolveSpotlightClientConfig, } from "./http.js";
2
+ export { appendProjectQuery, buildJsonHeaders, createSpotlightHttp, normalizeServerUrl, resolveSpotlightClientConfig, SpotlightHttpError, } from "./http.js";
3
3
  export { fetchDefaultCommandCatalog, mergeCommandCatalogs, serializeSkillsForRemote, } from "./host.js";
4
4
  export { validateSkillFrontmatter, describeCapabilitySurface, SPOTLIGHT_LAYOUT, SPOTLIGHT_SKILL_LOAD_LEVELS, spotlightSkillsGlobPattern, } from "./skillServiceStandard.js";
5
5
  export { substituteSkillPlaceholders, executeInlineShellInMarkdown, prepareSkillMarkdownContent, } from "./skillPrompt.js";
6
6
  export { joinSkillScriptPath, } from "./skillScriptPath.js";
7
+ export * from "./appClient.js";
@@ -1 +1 @@
1
- {"version":3,"file":"skillServiceStandard.d.ts","sourceRoot":"","sources":["../src/skillServiceStandard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC/B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,oBAAoB,EAAE,CAAC;CAChC,CAAC;AAgBF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,qBAAqB,CA4DvB;AAED,8DAA8D;AAC9D,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAa5E;AAED,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,yBAAyB,GAC/B,CAAC"}
1
+ {"version":3,"file":"skillServiceStandard.d.ts","sourceRoot":"","sources":["../src/skillServiceStandard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC/B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,oBAAoB,EAAE,CAAC;CAChC,CAAC;AA4BF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,qBAAqB,CAiEvB;AAED,8DAA8D;AAC9D,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAa5E;AAED,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,yBAAyB,GAC/B,CAAC"}
@@ -13,6 +13,21 @@ function asStringList(value) {
13
13
  }
14
14
  return [];
15
15
  }
16
+ function dependencyToolNames(value) {
17
+ if (!value || typeof value !== "object")
18
+ return [];
19
+ const tools = value.tools;
20
+ if (!Array.isArray(tools))
21
+ return [];
22
+ return tools.flatMap((tool) => {
23
+ if (typeof tool === "string")
24
+ return tool.trim() ? [tool.trim()] : [];
25
+ if (!tool || typeof tool !== "object")
26
+ return [];
27
+ const name = tool.value;
28
+ return typeof name === "string" && name.trim() ? [name.trim()] : [];
29
+ });
30
+ }
16
31
  /**
17
32
  * Validate skill frontmatter against Spotlight + Agent Skills conventions.
18
33
  * Use in CI or local skill authoring tools.
@@ -50,10 +65,13 @@ export function validateSkillFrontmatter(data) {
50
65
  ? data["response-strategy"]
51
66
  : "";
52
67
  const allowedTools = asStringList(data["allowed-tools"]);
53
- if (strategy === "tool_answer" && allowedTools.length === 0) {
68
+ const dependencyTools = dependencyToolNames(data.dependencies);
69
+ if (strategy === "tool_answer" &&
70
+ allowedTools.length === 0 &&
71
+ dependencyTools.length === 0) {
54
72
  issues.push({
55
73
  level: "error",
56
- message: "spotlight-response-strategy: tool_answer 时必须声明 allowed-tools",
74
+ message: "spotlight-response-strategy: tool_answer 时必须声明 dependencies.tools(旧版 allowed-tools 也可)",
57
75
  });
58
76
  }
59
77
  if (data.keywords != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inupedia/spotlight-client",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Build-described browser Client Tools and HTTP helpers for Inupedia Spotlight",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "@babel/types": "^7.28.5",
34
34
  "magic-string": "^0.30.21",
35
35
  "yaml": "^2.8.4",
36
- "@inupedia/spotlight-protocol": "0.6.0"
36
+ "@inupedia/spotlight-protocol": "0.7.1"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"