@inupedia/spotlight-client 0.5.19 → 0.6.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.
@@ -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,mEAAm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AG,OAAO,IACtD,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACnC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;CACtD,CAAC;AAeJ;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAC5D,OAAO,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,OAAO,CAAC,EAAE,iBAAiB,GAAG,uBAAuB,GACpD,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAa7B;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,UAAU,GACf,wBAAwB,CAkB1B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE;;cAsBvD,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"}
@@ -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) {
@@ -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,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,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;AA0EF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,eAAe,KAAK,IAAI;;;SAwIrD;AAED,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,OAAO,GAAE,2BAAgC,GACxC,MAAM,CAkDR"}
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,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE5D,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,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.6.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.6.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"