@inupedia/spotlight-client 0.5.19 → 0.7.0

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.
@@ -0,0 +1,28 @@
1
+ import { type FrontendToolManifestV1, type HostToolResultRequest, type SpotlightInitializeResponse, type SpotlightSkillRegistration, type SpotlightThread, type SpotlightTurn, type SpotlightTurnEvent, type SpotlightTurnStartRequest } from "@inupedia/spotlight-protocol";
2
+ import { type SpotlightClientConfig } from "./http.js";
3
+ export interface SpotlightAppClientOptions extends SpotlightClientConfig {
4
+ toolManifest: FrontendToolManifestV1 | (() => FrontendToolManifestV1 | Promise<FrontendToolManifestV1>);
5
+ skills?: SpotlightSkillRegistration[] | (() => SpotlightSkillRegistration[]);
6
+ clientInfo?: {
7
+ name?: string;
8
+ title?: string;
9
+ version?: string;
10
+ };
11
+ }
12
+ export declare class SpotlightAppClient {
13
+ private readonly options;
14
+ private readonly http;
15
+ private initialization;
16
+ private initializedDigest;
17
+ constructor(options: SpotlightAppClientOptions);
18
+ initialize(signal?: AbortSignal): Promise<SpotlightInitializeResponse>;
19
+ startThread(threadId?: string, signal?: AbortSignal): Promise<SpotlightThread>;
20
+ startTurn(threadId: string, request: SpotlightTurnStartRequest, signal?: AbortSignal): Promise<SpotlightTurn>;
21
+ streamTurn(turnId: string, signal?: AbortSignal): AsyncGenerator<SpotlightTurnEvent>;
22
+ submitToolResult(turnId: string, result: HostToolResultRequest, signal?: AbortSignal): Promise<{
23
+ ok: true;
24
+ }>;
25
+ cancelTurn(turnId: string): Promise<void>;
26
+ }
27
+ export declare function createSpotlightAppClient(options: SpotlightAppClientOptions): SpotlightAppClient;
28
+ //# sourceMappingURL=appClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appClient.d.ts","sourceRoot":"","sources":["../src/appClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EA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,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,151 @@
1
+ import { SPOTLIGHT_APP_PROTOCOL_V1, defaultSpotlightClientCapabilities, } from "@inupedia/spotlight-protocol";
2
+ import { buildJsonHeaders, createSpotlightHttp, } from "./http.js";
3
+ function valueOf(value) {
4
+ return typeof value === "function" ? value() : value;
5
+ }
6
+ async function asyncValueOf(value) {
7
+ return typeof value === "function"
8
+ ? await value()
9
+ : value;
10
+ }
11
+ function reconnectDelay(attempt) {
12
+ return Math.min(400 * 2 ** attempt, 5_000);
13
+ }
14
+ function wait(ms) {
15
+ return new Promise((resolve) => setTimeout(resolve, ms));
16
+ }
17
+ function parseSseFrames(buffer) {
18
+ const frames = buffer.split(/\n\n/u);
19
+ const rest = frames.pop() ?? "";
20
+ const events = frames.flatMap((frame) => {
21
+ const data = frame
22
+ .split(/\n/u)
23
+ .filter((line) => line.startsWith("data:"))
24
+ .map((line) => line.slice(5).trimStart())
25
+ .join("\n");
26
+ if (!data)
27
+ return [];
28
+ try {
29
+ const parsed = JSON.parse(data);
30
+ return parsed.type === "ping" && !("seq" in parsed)
31
+ ? []
32
+ : [parsed];
33
+ }
34
+ catch {
35
+ return [];
36
+ }
37
+ });
38
+ return { events, rest };
39
+ }
40
+ export class SpotlightAppClient {
41
+ options;
42
+ http;
43
+ initialization = null;
44
+ initializedDigest = null;
45
+ constructor(options) {
46
+ this.options = options;
47
+ this.http = createSpotlightHttp(options);
48
+ }
49
+ async initialize(signal) {
50
+ const manifest = await asyncValueOf(this.options.toolManifest);
51
+ if (this.initialization && this.initializedDigest === manifest.manifestDigest) {
52
+ return this.initialization;
53
+ }
54
+ this.initializedDigest = manifest.manifestDigest;
55
+ this.initialization = this.http.postJson("/v1/initialize", {
56
+ protocolVersion: SPOTLIGHT_APP_PROTOCOL_V1,
57
+ projectId: this.options.projectId,
58
+ clientInfo: {
59
+ name: this.options.clientInfo?.name ?? "spotlight-typescript",
60
+ title: this.options.clientInfo?.title,
61
+ version: this.options.clientInfo?.version ?? "0.7.0",
62
+ },
63
+ capabilities: defaultSpotlightClientCapabilities(),
64
+ toolManifest: manifest,
65
+ skills: this.options.skills ? valueOf(this.options.skills) : [],
66
+ }, signal).catch((error) => {
67
+ this.initialization = null;
68
+ throw error;
69
+ });
70
+ return this.initialization;
71
+ }
72
+ async startThread(threadId, signal) {
73
+ await this.initialize(signal);
74
+ const response = await this.http.postJson("/v1/threads", { projectId: this.options.projectId, threadId }, signal);
75
+ return response.thread;
76
+ }
77
+ async startTurn(threadId, request, signal) {
78
+ await this.initialize(signal);
79
+ const response = await this.http.postJson(`/v1/threads/${encodeURIComponent(threadId)}/turns`, request, signal);
80
+ return response.turn;
81
+ }
82
+ async *streamTurn(turnId, signal) {
83
+ let lastSeq = 0;
84
+ let reconnects = 0;
85
+ while (!signal?.aborted) {
86
+ const query = lastSeq > 0 ? `?lastEventId=${lastSeq}` : "";
87
+ let response;
88
+ try {
89
+ response = await fetch(`${this.http.getBase()}/v1/turns/${encodeURIComponent(turnId)}/events${query}`, { headers: buildJsonHeaders(this.http.config), signal });
90
+ }
91
+ catch (error) {
92
+ if (signal?.aborted)
93
+ throw error;
94
+ reconnects += 1;
95
+ if (reconnects > 6)
96
+ throw error;
97
+ await wait(reconnectDelay(reconnects - 1));
98
+ continue;
99
+ }
100
+ if (response.status === 410) {
101
+ throw new Error("Spotlight 后端已不再保留这次 Turn,请重新提问。");
102
+ }
103
+ if (!response.ok || !response.body) {
104
+ throw new Error(`Spotlight Turn 事件流连接失败:${response.status}`);
105
+ }
106
+ const reader = response.body.getReader();
107
+ const decoder = new TextDecoder();
108
+ let buffer = "";
109
+ let terminal = false;
110
+ try {
111
+ while (true) {
112
+ const { done, value } = await reader.read();
113
+ if (done)
114
+ break;
115
+ buffer += decoder.decode(value, { stream: true });
116
+ const parsed = parseSseFrames(buffer);
117
+ buffer = parsed.rest;
118
+ for (const event of parsed.events) {
119
+ if (event.seq <= lastSeq)
120
+ continue;
121
+ lastSeq = event.seq;
122
+ yield event;
123
+ if (event.type === "turn.completed" || event.type === "turn.failed") {
124
+ terminal = true;
125
+ return;
126
+ }
127
+ }
128
+ }
129
+ }
130
+ finally {
131
+ reader.releaseLock();
132
+ }
133
+ if (terminal || signal?.aborted)
134
+ return;
135
+ reconnects += 1;
136
+ if (reconnects > 6) {
137
+ throw new Error("Spotlight Turn 事件流多次重连失败,请重试。");
138
+ }
139
+ await wait(reconnectDelay(reconnects - 1));
140
+ }
141
+ }
142
+ submitToolResult(turnId, result, signal) {
143
+ return this.http.postJson(`/v1/turns/${encodeURIComponent(turnId)}/tool-results`, result, signal);
144
+ }
145
+ cancelTurn(turnId) {
146
+ return fetch(`${this.http.getBase()}/v1/turns/${encodeURIComponent(turnId)}`, { method: "DELETE", headers: buildJsonHeaders(this.http.config) }).then(() => undefined);
147
+ }
148
+ }
149
+ export function createSpotlightAppClient(options) {
150
+ return new SpotlightAppClient(options);
151
+ }
@@ -1,4 +1,4 @@
1
- import { type FrontendToolDescriptorV1, type FrontendToolManifestV1, type JsonSchemaV1, type ToolReplayPolicyV1, type ToolRiskLevelV1, type ToolSideEffectV1 } from "@inupedia/spotlight-protocol";
1
+ import { type FrontendToolDescriptorV1, type FrontendToolManifestV1, type JsonSchemaV1, type ToolReplayPolicyV1, type ToolRiskLevelV1, type ToolSideEffectV1, type ToolTierV1 } from "@inupedia/spotlight-protocol";
2
2
  export declare const CLIENT_TOOL_META: unique symbol;
3
3
  export interface ClientToolSchemaOverride {
4
4
  input: JsonSchemaV1;
@@ -8,6 +8,12 @@ export interface ClientToolOptions {
8
8
  /** Escape hatch for types the build plugin cannot safely infer. */
9
9
  schema?: ClientToolSchemaOverride;
10
10
  version?: string;
11
+ /**
12
+ * What the runtime must guarantee before dispatching this tool. Declare it
13
+ * directly; the legacy fields below only exist to keep older call sites
14
+ * working and are derived from each other when `tier` is omitted.
15
+ */
16
+ tier?: ToolTierV1;
11
17
  sideEffect?: ToolSideEffectV1;
12
18
  replayPolicy?: ToolReplayPolicyV1;
13
19
  riskLevel?: ToolRiskLevelV1;
@@ -1 +1 @@
1
- {"version":3,"file":"clientTool.d.ts","sourceRoot":"","sources":["../src/clientTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,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,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,KACV,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,MAAM,UAAU,CAAC,MAA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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"}
@@ -1,4 +1,4 @@
1
- import { SPOTLIGHT_CAPABILITY_PROTOCOL_V1, } from "@inupedia/spotlight-protocol";
1
+ import { deriveToolTier, isToolTierReplaySafe, SPOTLIGHT_CAPABILITY_PROTOCOL_V1, } from "@inupedia/spotlight-protocol";
2
2
  export const CLIENT_TOOL_META = Symbol.for("inupedia.spotlight.client-tool");
3
3
  function isGeneratedMeta(value) {
4
4
  return Boolean(value &&
@@ -26,6 +26,12 @@ export function defineClientTool(handler, options) {
26
26
  }
27
27
  export function getClientToolDescriptor(tool) {
28
28
  const meta = tool[CLIENT_TOOL_META];
29
+ const legacy = {
30
+ sideEffect: meta.sideEffect ?? "ui",
31
+ replayPolicy: meta.replayPolicy ?? "never",
32
+ riskLevel: meta.riskLevel ?? "low",
33
+ requiresConfirmation: meta.requiresConfirmation ?? false,
34
+ };
29
35
  return {
30
36
  name: meta.name,
31
37
  version: meta.version ?? "1.0.0",
@@ -33,21 +39,28 @@ export function getClientToolDescriptor(tool) {
33
39
  inputSchema: meta.schema.input,
34
40
  outputSchema: meta.schema.output,
35
41
  maxOutputBytes: meta.maxOutputBytes,
36
- sideEffect: meta.sideEffect ?? "ui",
37
- replayPolicy: meta.replayPolicy ?? "never",
38
- riskLevel: meta.riskLevel ?? "low",
39
- requiresConfirmation: meta.requiresConfirmation ?? false,
42
+ tier: deriveToolTier({ tier: meta.tier, ...legacy }),
43
+ ...legacy,
40
44
  };
41
45
  }
42
46
  export function createClientToolRegistry(tools) {
43
47
  const byName = new Map();
48
+ const unsupported = [];
44
49
  for (const tool of tools) {
45
50
  const descriptor = getClientToolDescriptor(tool);
46
51
  if (byName.has(descriptor.name)) {
47
52
  throw new Error(`Duplicate client tool: ${descriptor.name}`);
48
53
  }
54
+ // Every dispatch path recovers by re-running the call, so a tool that
55
+ // cannot be re-run safely must not reach the runtime at all.
56
+ if (!isToolTierReplaySafe(descriptor.tier ?? "navigate")) {
57
+ unsupported.push(descriptor.name);
58
+ }
49
59
  byName.set(descriptor.name, tool);
50
60
  }
61
+ 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
+ }
51
64
  return {
52
65
  descriptors: [...byName.values()].map(getClientToolDescriptor),
53
66
  has(name) {
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { fetchDefaultCommandCatalog, mergeCommandCatalogs, serializeSkillsForRem
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,4B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L,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { fetchDefaultCommandCatalog, mergeCommandCatalogs, serializeSkillsForRem
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) {
@@ -6,12 +6,14 @@ export interface SpotlightClientToolsOptions {
6
6
  manifestFileName?: string;
7
7
  }
8
8
  type JsonSchema = Record<string, unknown>;
9
+ type ToolTier = "observe" | "query" | "navigate" | "mutate";
9
10
  type BuildDescriptor = {
10
11
  name: string;
11
12
  version: string;
12
13
  description: string;
13
14
  inputSchema: JsonSchema;
14
15
  outputSchema?: JsonSchema;
16
+ tier?: ToolTier;
15
17
  sideEffect: "none" | "ui" | "external";
16
18
  replayPolicy: "safe" | "idempotency-key" | "never";
17
19
  riskLevel: "low" | "medium" | "high";
@@ -1 +1 @@
1
- {"version":3,"file":"spotlightClientTools.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightClientTools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAyL1C,KAAK,eAAe,GAAG;IACrB,IAAI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E,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;IACvC,YAAY,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC;IACnD,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAkGF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,eAAe,KAAK,IAAI;;;SA4IrD;AAED,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,OAAO,GAAE,2BAAgC,GACxC,MAAM,CA0DR"}
@@ -187,11 +187,29 @@ function shouldInclude(id, include) {
187
187
  return false;
188
188
  return typeof include === "string" ? clean.includes(include) : include.test(clean);
189
189
  }
190
+ function withTier(descriptor) {
191
+ return { ...descriptor, tier: buildTier(descriptor) };
192
+ }
193
+ /** Mirrors `deriveToolTier` in the protocol package, which cannot be imported here. */
194
+ function buildTier(descriptor) {
195
+ if (descriptor.tier)
196
+ return descriptor.tier;
197
+ if (descriptor.sideEffect === "external")
198
+ return "mutate";
199
+ if (descriptor.riskLevel === "high" || descriptor.requiresConfirmation) {
200
+ return "mutate";
201
+ }
202
+ if (descriptor.sideEffect === "none") {
203
+ return descriptor.replayPolicy === "safe" ? "query" : "navigate";
204
+ }
205
+ return "navigate";
206
+ }
190
207
  function staticToolOptions(options, path) {
191
208
  if (!options)
192
209
  return {};
193
210
  const allowed = new Set([
194
211
  "version",
212
+ "tier",
195
213
  "sideEffect",
196
214
  "replayPolicy",
197
215
  "riskLevel",
@@ -213,6 +231,10 @@ function staticToolOptions(options, path) {
213
231
  if (values.version !== undefined && typeof values.version !== "string") {
214
232
  throw new Error("version must be a string literal");
215
233
  }
234
+ if (values.tier !== undefined &&
235
+ !["observe", "query", "navigate", "mutate"].includes(String(values.tier))) {
236
+ throw new Error("tier must be observe, query, navigate or mutate");
237
+ }
216
238
  if (values.sideEffect !== undefined &&
217
239
  !["none", "ui", "external"].includes(String(values.sideEffect))) {
218
240
  throw new Error("sideEffect must be none, ui or external");
@@ -302,7 +324,7 @@ export function transformSpotlightClientTools(code, id, onDescriptor) {
302
324
  ...(schema ? [`schema:${JSON.stringify(schema)}`] : []),
303
325
  ].join(",");
304
326
  if (schema) {
305
- onDescriptor?.({
327
+ onDescriptor?.(withTier({
306
328
  name: path.node.id.name,
307
329
  version: "1.0.0",
308
330
  description,
@@ -313,7 +335,7 @@ export function transformSpotlightClientTools(code, id, onDescriptor) {
313
335
  riskLevel: "low",
314
336
  requiresConfirmation: false,
315
337
  ...descriptorOptions,
316
- });
338
+ }));
317
339
  }
318
340
  else if (optionArg) {
319
341
  const schemaProperty = optionArg.properties.find((property) => t.isObjectProperty(property) &&
@@ -324,7 +346,7 @@ export function transformSpotlightClientTools(code, id, onDescriptor) {
324
346
  if (!parsed?.input || typeof parsed.input !== "object") {
325
347
  throw new Error("schema.input must be an object");
326
348
  }
327
- onDescriptor?.({
349
+ onDescriptor?.(withTier({
328
350
  name: path.node.id.name,
329
351
  version: "1.0.0",
330
352
  description,
@@ -335,7 +357,7 @@ export function transformSpotlightClientTools(code, id, onDescriptor) {
335
357
  riskLevel: "low",
336
358
  requiresConfirmation: false,
337
359
  ...descriptorOptions,
338
- });
360
+ }));
339
361
  }
340
362
  catch (error) {
341
363
  if (onDescriptor) {
@@ -402,6 +424,12 @@ export default function spotlightClientTools(options = {}) {
402
424
  if (descriptors.size === 0) {
403
425
  throw new Error("spotlightClientTools: production manifest has no tools");
404
426
  }
427
+ const unsupported = [...descriptors.values()]
428
+ .filter((descriptor) => descriptor.tier === "mutate")
429
+ .map((descriptor) => descriptor.name);
430
+ if (unsupported.length > 0) {
431
+ throw new Error(`spotlightClientTools: the runtime cannot dispatch "mutate" tier tools yet: ${unsupported.join(", ")}. See docs/design/capability-protocol-v2.md.`);
432
+ }
405
433
  const unsigned = {
406
434
  protocolVersion: "spotlight.capabilities/1",
407
435
  projectId: options.projectId.trim(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inupedia/spotlight-client",
3
- "version": "0.5.19",
3
+ "version": "0.7.0",
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.5.19"
36
+ "@inupedia/spotlight-protocol": "0.7.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"