@inupedia/spotlight-client 0.3.0 → 0.3.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.
Files changed (42) hide show
  1. package/dist/capabilities/channel.d.ts.map +1 -1
  2. package/dist/capabilities/channel.js +68 -31
  3. package/dist/capabilities/hostActionExecutor.d.ts +4 -1
  4. package/dist/capabilities/hostActionExecutor.d.ts.map +1 -1
  5. package/dist/capabilities/hostActionExecutor.js +51 -55
  6. package/dist/capabilities/jsonSchema.d.ts +1 -7
  7. package/dist/capabilities/jsonSchema.d.ts.map +1 -1
  8. package/dist/capabilities/jsonSchema.js +70 -40
  9. package/dist/capabilities/runtimeCapabilities.d.ts +25 -0
  10. package/dist/capabilities/runtimeCapabilities.d.ts.map +1 -0
  11. package/dist/capabilities/runtimeCapabilities.js +53 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -0
  15. package/dist/node/capabilities/archivePath.d.ts +4 -0
  16. package/dist/node/capabilities/archivePath.d.ts.map +1 -0
  17. package/dist/node/capabilities/archivePath.js +22 -0
  18. package/dist/node/capabilities/capabilityFileMap.d.ts.map +1 -1
  19. package/dist/node/capabilities/capabilityFileMap.js +3 -12
  20. package/dist/node/capabilities/deterministicTar.d.ts.map +1 -1
  21. package/dist/node/capabilities/deterministicTar.js +3 -12
  22. package/dist/node/capabilityPublishCli.d.ts +2 -0
  23. package/dist/node/capabilityPublishCli.d.ts.map +1 -0
  24. package/dist/node/capabilityPublishCli.js +115 -0
  25. package/dist/node/cli/spotlightCapabilitiesPublish.d.ts +3 -0
  26. package/dist/node/cli/spotlightCapabilitiesPublish.d.ts.map +1 -0
  27. package/dist/node/cli/spotlightCapabilitiesPublish.js +3 -0
  28. package/dist/node/index.d.ts +2 -0
  29. package/dist/node/index.d.ts.map +1 -1
  30. package/dist/node/index.js +2 -0
  31. package/dist/node/publishCapabilityArtifact.d.ts +12 -0
  32. package/dist/node/publishCapabilityArtifact.d.ts.map +1 -0
  33. package/dist/node/publishCapabilityArtifact.js +25 -0
  34. package/dist/vite/capabilityBuild.d.ts.map +1 -1
  35. package/dist/vite/capabilityBuild.js +9 -4
  36. package/dist/vite/capabilityBuildTypes.d.ts +1 -0
  37. package/dist/vite/capabilityBuildTypes.d.ts.map +1 -1
  38. package/dist/vite/capabilityVirtualModule.d.ts.map +1 -1
  39. package/dist/vite/capabilityVirtualModule.js +16 -1
  40. package/dist/vite/spotlightCapabilities.d.ts.map +1 -1
  41. package/dist/vite/spotlightCapabilities.js +12 -1
  42. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/capabilities/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EAElC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAA4B,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAEpG,KAAK,iBAAiB,GAAG,OAAO,CAAC,2BAA2B,EAAE;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAEtF,MAAM,WAAW,mBAAmB;IAClC,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAC/C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,IAAI,QAAQ,CAAC,0BAA0B,CAAC,CAAC;CAC/C;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAA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,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC9C,GAAG,mBAAmB,CA4JtB"}
@@ -9,8 +9,23 @@ export function createCapabilityChannel(options) {
9
9
  let socket;
10
10
  let heartbeat;
11
11
  let renewal;
12
- let renewalPending = false;
12
+ let renewalPendingGeneration;
13
+ let reconnectTimer;
14
+ let reconnectAttempt = 0;
15
+ let generation = 0;
16
+ let reservationSerial = 0;
13
17
  let closed = false;
18
+ let reserveAndOpen;
19
+ const scheduleReconnect = () => {
20
+ if (closed || reconnectTimer)
21
+ return;
22
+ const delay = Math.min(250 * 2 ** reconnectAttempt, 5_000);
23
+ reconnectAttempt += 1;
24
+ reconnectTimer = setTimeout(() => {
25
+ reconnectTimer = undefined;
26
+ void reserveAndOpen().catch(scheduleReconnect);
27
+ }, delay);
28
+ };
14
29
  const fence = () => Object.freeze({
15
30
  sessionId: options.identity.sessionId,
16
31
  capabilitySnapshotId: options.handshake.capabilitySnapshotId,
@@ -22,24 +37,26 @@ export function createCapabilityChannel(options) {
22
37
  tabInstanceId: options.identity.tabInstanceId,
23
38
  });
24
39
  const executor = createHostActionExecutor({ registry: options.registry, fence });
25
- const send = (message) => {
26
- if (socket?.readyState === 1)
27
- socket.send(JSON.stringify(message));
28
- };
29
40
  const close = () => {
30
41
  closed = true;
31
42
  if (heartbeat)
32
43
  clearInterval(heartbeat);
33
44
  if (renewal)
34
45
  clearInterval(renewal);
46
+ if (reconnectTimer)
47
+ clearTimeout(reconnectTimer);
35
48
  heartbeat = undefined;
36
49
  renewal = undefined;
50
+ if (socket)
51
+ socket.onclose = null;
37
52
  socket?.close();
38
53
  socket = undefined;
39
54
  };
40
55
  const open = () => {
41
56
  if (closed)
42
57
  throw new SpotlightCapabilityError("CAPABILITY_LEASE_FENCED", "Capability channel is closed.");
58
+ if (socket)
59
+ socket.onclose = null;
43
60
  socket?.close();
44
61
  const create = options.createWebSocket ?? ((url) => new WebSocket(url));
45
62
  const origin = typeof location === "undefined" ? "http://localhost" : location.origin;
@@ -47,9 +64,16 @@ export function createCapabilityChannel(options) {
47
64
  const channelPath = options.handshake.capabilityChannelUrl.replace(/^\//, "");
48
65
  const url = new URL(channelPath, base);
49
66
  url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
50
- socket = create(url.toString());
51
- socket.onopen = () => {
52
- send({
67
+ const localSocket = create(url.toString());
68
+ const localGeneration = ++generation;
69
+ socket = localSocket;
70
+ const sendLocal = (message) => { if (!closed && socket === localSocket && generation === localGeneration && localSocket.readyState === 1)
71
+ localSocket.send(JSON.stringify(message)); };
72
+ localSocket.onopen = () => {
73
+ if (socket !== localSocket || generation !== localGeneration || closed)
74
+ return;
75
+ reconnectAttempt = 0;
76
+ sendLocal({
53
77
  type: "client_hello",
54
78
  protocolVersion: SPOTLIGHT_CAPABILITY_PROTOCOL_V1,
55
79
  capabilityChannelToken: channelToken,
@@ -58,35 +82,40 @@ export function createCapabilityChannel(options) {
58
82
  });
59
83
  if (heartbeat)
60
84
  clearInterval(heartbeat);
61
- heartbeat = setInterval(() => send({ type: "heartbeat", ...fence(), sentAt: new Date().toISOString() }), 5_000);
85
+ heartbeat = setInterval(() => sendLocal({ type: "heartbeat", ...fence(), sentAt: new Date().toISOString() }), 5_000);
62
86
  if (renewal)
63
87
  clearInterval(renewal);
64
88
  renewal = setInterval(() => {
65
- if (renewalPending)
89
+ if (renewalPendingGeneration === localGeneration)
66
90
  return;
67
- renewalPending = true;
68
- void renew().catch(() => close()).finally(() => { renewalPending = false; });
91
+ renewalPendingGeneration = localGeneration;
92
+ void renew().catch(scheduleReconnect).finally(() => { if (renewalPendingGeneration === localGeneration)
93
+ renewalPendingGeneration = undefined; });
69
94
  }, 5_000);
70
95
  };
71
- socket.onmessage = (event) => {
96
+ localSocket.onmessage = (event) => {
97
+ if (socket !== localSocket || generation !== localGeneration || closed)
98
+ return;
72
99
  void (async () => {
73
100
  const message = JSON.parse(String(event.data));
74
101
  if (message.type === "host_action_request") {
75
- for (const response of await executor.execute(message))
76
- send(response);
102
+ await executor.executeStreaming(message, sendLocal);
77
103
  }
78
104
  else if (message.type === "channel_fenced") {
79
105
  close();
80
106
  }
81
107
  })();
82
108
  };
83
- socket.onclose = () => {
109
+ localSocket.onclose = () => {
110
+ if (socket !== localSocket || generation !== localGeneration || closed)
111
+ return;
84
112
  if (heartbeat)
85
113
  clearInterval(heartbeat);
86
114
  if (renewal)
87
115
  clearInterval(renewal);
88
116
  heartbeat = undefined;
89
117
  renewal = undefined;
118
+ scheduleReconnect();
90
119
  };
91
120
  };
92
121
  const post = async (path, body) => capabilityResponseJson(await options.fetch(`${options.endpoint.replace(/\/$/, "")}${path}`, {
@@ -97,7 +126,10 @@ export function createCapabilityChannel(options) {
97
126
  }));
98
127
  const renew = async () => {
99
128
  const current = fence();
129
+ const startedGeneration = generation;
100
130
  const result = await post(`/v1/capabilities/leases/${encodeURIComponent(current.leaseId)}/renew`, { ...current, expectedLeaseVersion: current.leaseVersion, liveTools: options.registry.liveTools() });
131
+ if (startedGeneration !== generation || closed)
132
+ return result;
101
133
  if (result.status === "revoked") {
102
134
  close();
103
135
  throw new SpotlightCapabilityError("CAPABILITY_LEASE_REVOKED", result.reason);
@@ -105,25 +137,30 @@ export function createCapabilityChannel(options) {
105
137
  leaseVersion = result.leaseVersion;
106
138
  return result;
107
139
  };
140
+ reserveAndOpen = async () => {
141
+ const current = fence();
142
+ const startedGeneration = generation;
143
+ const serial = ++reservationSerial;
144
+ const reserved = await post(`/v1/capabilities/leases/${encodeURIComponent(current.leaseId)}/connections`, {
145
+ expectedConnectionId: current.connectionId,
146
+ expectedConnectionEpoch: current.connectionEpoch,
147
+ expectedLeaseVersion: current.leaseVersion,
148
+ browserInstanceId: current.browserInstanceId,
149
+ tabInstanceId: current.tabInstanceId,
150
+ });
151
+ if (closed || startedGeneration !== generation || serial !== reservationSerial)
152
+ return;
153
+ leaseVersion = reserved.leaseVersion;
154
+ connectionId = reserved.connectionId;
155
+ connectionEpoch = reserved.connectionEpoch;
156
+ channelToken = reserved.capabilityChannelToken;
157
+ open();
158
+ };
108
159
  return Object.freeze({
109
160
  open,
110
161
  close,
111
162
  fence,
112
163
  renew,
113
- async reconnect() {
114
- const current = fence();
115
- const reserved = await post(`/v1/capabilities/leases/${encodeURIComponent(current.leaseId)}/connections`, {
116
- expectedConnectionId: current.connectionId,
117
- expectedConnectionEpoch: current.connectionEpoch,
118
- expectedLeaseVersion: current.leaseVersion,
119
- browserInstanceId: current.browserInstanceId,
120
- tabInstanceId: current.tabInstanceId,
121
- });
122
- leaseVersion = reserved.leaseVersion;
123
- connectionId = reserved.connectionId;
124
- connectionEpoch = reserved.connectionEpoch;
125
- channelToken = reserved.capabilityChannelToken;
126
- open();
127
- },
164
+ reconnect: reserveAndOpen,
128
165
  });
129
166
  }
@@ -10,10 +10,13 @@ export interface CapabilityExecutionFenceV1 {
10
10
  browserInstanceId: string;
11
11
  tabInstanceId: string;
12
12
  }
13
+ type HostMessage = HostActionAckV2 | HostActionNackV2 | HostActionResultV2;
13
14
  export declare function createHostActionExecutor(options: {
14
15
  registry: FrontendToolRegistryV1;
15
16
  fence: CapabilityExecutionFenceV1 | (() => CapabilityExecutionFenceV1);
16
17
  }): Readonly<{
17
- execute(request: HostActionRequestV2): Promise<Array<HostActionAckV2 | HostActionNackV2 | HostActionResultV2>>;
18
+ executeStreaming: (request: HostActionRequestV2, emit: (message: HostMessage) => void) => Promise<void>;
19
+ execute(request: HostActionRequestV2): Promise<HostMessage[]>;
18
20
  }>;
21
+ export {};
19
22
  //# sourceMappingURL=hostActionExecutor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hostActionExecutor.d.ts","sourceRoot":"","sources":["../../src/capabilities/hostActionExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGvE,M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AM,0BAA0B,CAAC,CAAA;CAAE;gCACnH,mBAAmB,QAAQ,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,KAAG,OAAO,CAAC,IAAI,CAAC;qBA8BzF,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;GAEtE"}
@@ -1,60 +1,56 @@
1
- import { validateJsonSchemaValue } from "./jsonSchema.js";
1
+ import { validateJsonSchemaV1 } from "./jsonSchema.js";
2
2
  const FENCE_FIELDS = ["sessionId", "capabilitySnapshotId", "leaseId", "leaseVersion", "connectionId", "connectionEpoch", "browserInstanceId", "tabInstanceId"];
3
- function nack(request, code, message) {
4
- const { type: _type, input: _input, deadlineAt: _deadline, idempotencyKey: _key, confirmationGrantId: _grant, maxAttempts: _max, ...fence } = request;
5
- return { ...fence, type: "host_action_nack", status: "nack", handlerStarted: false, error: { code, message } };
6
- }
3
+ function nack(request, code, message) { const { type: _t, input: _i, deadlineAt: _d, idempotencyKey: _k, confirmationGrantId: _g, maxAttempts: _m, ...fence } = request; return { ...fence, type: "host_action_nack", status: "nack", handlerStarted: false, error: { code, message } }; }
7
4
  export function createHostActionExecutor(options) {
5
+ const executeStreaming = async (request, emit) => {
6
+ const current = typeof options.fence === "function" ? options.fence() : options.fence;
7
+ const reject = (code, message) => { emit(nack(request, code, message)); };
8
+ if (FENCE_FIELDS.some((field) => request[field] !== current[field]))
9
+ return reject("CAPABILITY_LEASE_FENCED", "Host action fence is stale.");
10
+ const tool = options.registry.get(request.tool.name, request.tool.version);
11
+ if (!tool || request.tool.target !== "browser")
12
+ return reject("TOOL_NOT_REGISTERED", "Frontend Tool is not registered.");
13
+ if (!options.registry.liveTools().some((entry) => entry.name === tool.name && entry.version === tool.version))
14
+ return reject("HOST_OFFLINE", "Frontend Tool handler is not live.");
15
+ const inputError = validateJsonSchemaV1(tool.inputSchema, request.input);
16
+ if (inputError)
17
+ return reject("TOOL_INPUT_INVALID", inputError);
18
+ const deadlineAt = Date.parse(request.deadlineAt);
19
+ const delay = deadlineAt - Date.now();
20
+ if (!Number.isFinite(deadlineAt) || delay <= 0)
21
+ return reject("HOST_ACTION_TIMEOUT", "Host action deadline is invalid or elapsed.");
22
+ const { type: _t, input: _i, deadlineAt: _d, idempotencyKey: _k, confirmationGrantId: _g, maxAttempts: _m, ...fence } = request;
23
+ emit({ ...fence, type: "host_action_ack", status: "ack" });
24
+ const controller = new AbortController();
25
+ let timer;
26
+ const deadline = new Promise((_, rejectDeadline) => { const schedule = () => { const remaining = deadlineAt - Date.now(); if (remaining <= 0) {
27
+ controller.abort("deadline");
28
+ rejectDeadline(new SpotlightDeadlineError());
29
+ return;
30
+ } timer = setTimeout(schedule, Math.min(remaining, 0x7fffffff)); }; schedule(); });
31
+ try {
32
+ const output = await Promise.race([Promise.resolve(tool.execute(request.input, { projectId: options.registry.projectId, sessionId: request.sessionId, callId: request.callId, attempt: request.attempt, fence, ...(request.idempotencyKey ? { idempotencyKey: request.idempotencyKey } : {}), signal: controller.signal })), deadline]);
33
+ const outputError = tool.outputSchema ? validateJsonSchemaV1(tool.outputSchema, output) : undefined;
34
+ if (outputError)
35
+ return emit({ ...fence, type: "host_action_result", outcome: "threw", error: { code: "TOOL_OUTPUT_INVALID", message: outputError } });
36
+ const bytes = new TextEncoder().encode(JSON.stringify(output ?? null)).byteLength;
37
+ if (bytes > (tool.maxOutputBytes ?? 1024 * 1024))
38
+ return emit({ ...fence, type: "host_action_result", outcome: "threw", error: { code: "TOOL_OUTPUT_INVALID", message: "Frontend Tool output exceeds maxOutputBytes." } });
39
+ emit({ ...fence, type: "host_action_result", outcome: "returned", output });
40
+ }
41
+ catch (error) {
42
+ emit({ ...fence, type: "host_action_result", outcome: "threw", error: { code: error instanceof SpotlightDeadlineError ? "UNKNOWN_OUTCOME" : "TOOL_RUN_FAILED", message: error instanceof Error ? error.message : "Frontend Tool failed." } });
43
+ }
44
+ finally {
45
+ if (timer)
46
+ clearTimeout(timer);
47
+ }
48
+ };
8
49
  return Object.freeze({
9
- async execute(request) {
10
- const current = typeof options.fence === "function" ? options.fence() : options.fence;
11
- if (FENCE_FIELDS.some((field) => request[field] !== current[field])) {
12
- return [nack(request, "CAPABILITY_LEASE_FENCED", "Host action fence is stale.")];
13
- }
14
- const tool = options.registry.get(request.tool.name, request.tool.version);
15
- if (!tool || request.tool.target !== "browser") {
16
- return [nack(request, "TOOL_NOT_REGISTERED", "Frontend Tool is not registered.")];
17
- }
18
- if (!options.registry.liveTools().some((entry) => entry.name === tool.name && entry.version === tool.version)) {
19
- return [nack(request, "HOST_OFFLINE", "Frontend Tool handler is not live.")];
20
- }
21
- if (Date.parse(request.deadlineAt) <= Date.now()) {
22
- return [nack(request, "HOST_ACTION_TIMEOUT", "Host action deadline has elapsed.")];
23
- }
24
- if (!validateJsonSchemaValue(tool.inputSchema, request.input)) {
25
- return [nack(request, "TOOL_INPUT_INVALID", "Frontend Tool input does not match inputSchema.")];
26
- }
27
- const { type: _type, input: _input, deadlineAt: _deadline, idempotencyKey: _key, confirmationGrantId: _grant, maxAttempts: _max, ...fence } = request;
28
- const ack = { ...fence, type: "host_action_ack", status: "ack" };
29
- const controller = new AbortController();
30
- const delay = Math.max(0, Date.parse(request.deadlineAt) - Date.now());
31
- const timeout = setTimeout(() => controller.abort("deadline"), delay);
32
- try {
33
- const output = await tool.execute(request.input, {
34
- projectId: options.registry.projectId,
35
- sessionId: request.sessionId,
36
- callId: request.callId,
37
- attempt: request.attempt,
38
- fence,
39
- ...(request.idempotencyKey ? { idempotencyKey: request.idempotencyKey } : {}),
40
- signal: controller.signal,
41
- });
42
- const outputBytes = new TextEncoder().encode(JSON.stringify(output ?? null)).byteLength;
43
- if (tool.outputSchema && !validateJsonSchemaValue(tool.outputSchema, output)) {
44
- return [ack, { ...fence, type: "host_action_result", outcome: "threw", error: { code: "TOOL_OUTPUT_INVALID", message: "Frontend Tool output does not match outputSchema." } }];
45
- }
46
- if (outputBytes > (tool.maxOutputBytes ?? 1024 * 1024)) {
47
- return [ack, { ...fence, type: "host_action_result", outcome: "threw", error: { code: "TOOL_OUTPUT_INVALID", message: "Frontend Tool output exceeds maxOutputBytes." } }];
48
- }
49
- return [ack, { ...fence, type: "host_action_result", outcome: "returned", output }];
50
- }
51
- catch (error) {
52
- const code = controller.signal.aborted ? "HOST_ACTION_TIMEOUT" : "TOOL_RUN_FAILED";
53
- return [ack, { ...fence, type: "host_action_result", outcome: "threw", error: { code, message: error instanceof Error ? error.message : "Frontend Tool failed." } }];
54
- }
55
- finally {
56
- clearTimeout(timeout);
57
- }
58
- },
50
+ executeStreaming,
51
+ async execute(request) { const messages = []; await executeStreaming(request, (message) => messages.push(message)); return messages; },
59
52
  });
60
53
  }
54
+ class SpotlightDeadlineError extends Error {
55
+ constructor() { super("Frontend Tool deadline elapsed."); }
56
+ }
@@ -1,8 +1,2 @@
1
- type JsonSchema = Record<string, unknown>;
2
- /**
3
- * Browser-safe validator for the JSON Schema subset admitted by Capability v1.
4
- * Artifact admission remains the authority for validating schema documents.
5
- */
6
- export declare function validateJsonSchemaValue(schema: JsonSchema, value: unknown): boolean;
7
- export {};
1
+ export declare function validateJsonSchemaV1(schema: Record<string, unknown>, value: unknown, path?: string): string | undefined;
8
2
  //# sourceMappingURL=jsonSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonSchema.d.ts","sourceRoot":"","sources":["../../src/capabilities/jsonSchema.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAM1C;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAiCnF"}
1
+ {"version":3,"file":"jsonSchema.d.ts","sourceRoot":"","sources":["../../src/capabilities/jsonSchema.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,SAAM,GAAI,MAAM,GAAG,SAAS,CA+CrH"}
@@ -1,43 +1,73 @@
1
- function isObject(value) {
2
- return value !== null && typeof value === "object" && !Array.isArray(value);
3
- }
4
- /**
5
- * Browser-safe validator for the JSON Schema subset admitted by Capability v1.
6
- * Artifact admission remains the authority for validating schema documents.
7
- */
8
- export function validateJsonSchemaValue(schema, value) {
9
- if (Array.isArray(schema.enum) && !schema.enum.some((entry) => Object.is(entry, value)))
10
- return false;
11
- if ("const" in schema && !Object.is(schema.const, value))
12
- return false;
13
- switch (schema.type) {
14
- case "object": {
15
- if (!isObject(value))
16
- return false;
17
- const properties = isObject(schema.properties) ? schema.properties : {};
18
- const required = Array.isArray(schema.required) ? schema.required : [];
19
- if (required.some((key) => typeof key !== "string" || !(key in value)))
20
- return false;
21
- if (schema.additionalProperties === false && Object.keys(value).some((key) => !(key in properties)))
22
- return false;
23
- return Object.entries(properties).every(([key, child]) => !(key in value) || !isObject(child) || validateJsonSchemaValue(child, value[key]));
1
+ export function validateJsonSchemaV1(schema, value, path = "$") {
2
+ const type = schema.type;
3
+ if (typeof type === "string") {
4
+ const valid = type === "object" ? value !== null && typeof value === "object" && !Array.isArray(value)
5
+ : type === "array" ? Array.isArray(value)
6
+ : type === "integer" ? Number.isInteger(value)
7
+ : type === "number" ? typeof value === "number" && Number.isFinite(value)
8
+ : type === "string" ? typeof value === "string"
9
+ : type === "boolean" ? typeof value === "boolean"
10
+ : type === "null" ? value === null : true;
11
+ if (!valid)
12
+ return `${path} must be ${type}`;
13
+ }
14
+ if (Array.isArray(schema.enum) && !schema.enum.some((entry) => jsonEqual(entry, value)))
15
+ return `${path} is not an allowed value`;
16
+ if ("const" in schema && !jsonEqual(schema.const, value))
17
+ return `${path} must equal const`;
18
+ if (typeof value === "string") {
19
+ if (typeof schema.minLength === "number" && value.length < schema.minLength)
20
+ return `${path} is shorter than minLength`;
21
+ if (typeof schema.maxLength === "number" && value.length > schema.maxLength)
22
+ return `${path} is longer than maxLength`;
23
+ if (typeof schema.pattern === "string" && !new RegExp(schema.pattern).test(value))
24
+ return `${path} does not match pattern`;
25
+ }
26
+ if (typeof value === "number") {
27
+ if (typeof schema.minimum === "number" && value < schema.minimum)
28
+ return `${path} is below minimum`;
29
+ if (typeof schema.maximum === "number" && value > schema.maximum)
30
+ return `${path} is above maximum`;
31
+ }
32
+ if (schema.type === "object" && value !== null && typeof value === "object" && !Array.isArray(value)) {
33
+ const record = value;
34
+ for (const required of Array.isArray(schema.required) ? schema.required : []) {
35
+ if (typeof required === "string" && !(required in record))
36
+ return `${path}.${required} is required`;
37
+ }
38
+ const properties = schema.properties && typeof schema.properties === "object" ? schema.properties : {};
39
+ if (schema.additionalProperties === false) {
40
+ const unknown = Object.keys(record).find((key) => !(key in properties));
41
+ if (unknown)
42
+ return `${path}.${unknown} is not allowed`;
24
43
  }
25
- case "array":
26
- return Array.isArray(value) && (!isObject(schema.items) || value.every((item) => validateJsonSchemaValue(schema.items, item)));
27
- case "string":
28
- return typeof value === "string" &&
29
- (typeof schema.minLength !== "number" || value.length >= schema.minLength) &&
30
- (typeof schema.maxLength !== "number" || value.length <= schema.maxLength) &&
31
- (typeof schema.pattern !== "string" || new RegExp(schema.pattern).test(value));
32
- case "integer":
33
- return Number.isInteger(value) && (typeof schema.minimum !== "number" || value >= schema.minimum) && (typeof schema.maximum !== "number" || value <= schema.maximum);
34
- case "number":
35
- return typeof value === "number" && Number.isFinite(value) && (typeof schema.minimum !== "number" || value >= schema.minimum) && (typeof schema.maximum !== "number" || value <= schema.maximum);
36
- case "boolean":
37
- return typeof value === "boolean";
38
- case "null":
39
- return value === null;
40
- default:
41
- return true;
44
+ for (const [key, child] of Object.entries(properties)) {
45
+ if (key in record && child && typeof child === "object" && !Array.isArray(child)) {
46
+ const error = validateJsonSchemaV1(child, record[key], `${path}.${key}`);
47
+ if (error)
48
+ return error;
49
+ }
50
+ }
51
+ }
52
+ if (schema.type === "array" && Array.isArray(value) && schema.items && typeof schema.items === "object" && !Array.isArray(schema.items)) {
53
+ for (let index = 0; index < value.length; index += 1) {
54
+ const error = validateJsonSchemaV1(schema.items, value[index], `${path}[${index}]`);
55
+ if (error)
56
+ return error;
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ function jsonEqual(left, right) {
62
+ if (Object.is(left, right))
63
+ return true;
64
+ if (Array.isArray(left) || Array.isArray(right))
65
+ return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((entry, index) => jsonEqual(entry, right[index]));
66
+ if (left && right && typeof left === "object" && typeof right === "object") {
67
+ const a = left;
68
+ const b = right;
69
+ const keys = Object.keys(a);
70
+ return keys.length === Object.keys(b).length && keys.every((key) => key in b && jsonEqual(a[key], b[key]));
42
71
  }
72
+ return false;
43
73
  }
@@ -0,0 +1,25 @@
1
+ import type { CapabilityBuildInfoV1 } from "../vite/capabilityBuildTypes.js";
2
+ export interface RegisteredCapabilityRuntimeV1 {
3
+ capabilityBuildInfo: Readonly<CapabilityBuildInfoV1>;
4
+ openUploadStream: () => Promise<{
5
+ digest: string;
6
+ byteLength: number;
7
+ contentType: "application/gzip";
8
+ stream: ReadableStream<Uint8Array>;
9
+ }>;
10
+ }
11
+ export declare const CAPABILITY_RUNTIME_SYMBOL_V1 = "inupedia.spotlight.capability-runtime/1";
12
+ export declare function registerCapabilityRuntimeV1(runtime: RegisteredCapabilityRuntimeV1): void;
13
+ export declare function getCapabilityRuntimeV1(projectId: string): Readonly<{
14
+ subscribe(listener: (info: Readonly<CapabilityBuildInfoV1>) => void): () => boolean;
15
+ capabilityBuildInfo: Readonly<CapabilityBuildInfoV1>;
16
+ openUploadStream: () => Promise<{
17
+ digest: string;
18
+ byteLength: number;
19
+ contentType: "application/gzip";
20
+ stream: ReadableStream<Uint8Array>;
21
+ }>;
22
+ }> | undefined;
23
+ export declare function subscribeCapabilityRuntimeV1(projectId: string, listener: (info: Readonly<CapabilityBuildInfoV1>) => void): () => void;
24
+ export declare function waitForCapabilityRuntimeV1(projectId: string, signal?: AbortSignal): Promise<RegisteredCapabilityRuntimeV1>;
25
+ //# sourceMappingURL=runtimeCapabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeCapabilities.d.ts","sourceRoot":"","sources":["../../src/capabilities/runtimeCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E,MAAM,WAAW,6BAA6B;IAC5C,mBAAmB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IACrD,gBAAgB,EAAE,MAAM,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,kBAAkB,CAAC;QAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;KAAE,CAAC,CAAC;CAC9I;AAOD,eAAO,MAAM,4BAA4B,4CAA4C,CAAC;AAQtF,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,6BAA6B,GAAG,IAAI,CAIxF;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM;wBAMhC,CAAC,IAAI,EAAE,QAAQ,CAAC,qBAAqB,CAAC,KAAK,IAAI;yBA7BhD,QAAQ,CAAC,qBAAqB,CAAC;sBAClC,MAAM,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,kBAAkB,CAAC;QAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;KAAE,CAAC;eAmC7I;AAED,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,qBAAqB,CAAC,KAAK,IAAI,GACxD,MAAM,IAAI,CAMZ;AAED,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,6BAA6B,CAAC,CAexC"}
@@ -0,0 +1,53 @@
1
+ export const CAPABILITY_RUNTIME_SYMBOL_V1 = "inupedia.spotlight.capability-runtime/1";
2
+ function store() {
3
+ const root = globalThis;
4
+ const key = Symbol.for(CAPABILITY_RUNTIME_SYMBOL_V1);
5
+ return root[key] ??= { providers: new Map(), listeners: new Map() };
6
+ }
7
+ export function registerCapabilityRuntimeV1(runtime) {
8
+ const state = store();
9
+ state.providers.set(runtime.capabilityBuildInfo.projectId, runtime);
10
+ for (const listener of state.listeners.get(runtime.capabilityBuildInfo.projectId) ?? [])
11
+ listener(runtime.capabilityBuildInfo);
12
+ }
13
+ export function getCapabilityRuntimeV1(projectId) {
14
+ const state = store();
15
+ const provider = state.providers.get(projectId);
16
+ if (!provider)
17
+ return undefined;
18
+ return Object.freeze({
19
+ ...provider,
20
+ subscribe(listener) {
21
+ const listeners = state.listeners.get(projectId) ?? new Set();
22
+ listeners.add(listener);
23
+ state.listeners.set(projectId, listeners);
24
+ return () => listeners.delete(listener);
25
+ },
26
+ });
27
+ }
28
+ export function subscribeCapabilityRuntimeV1(projectId, listener) {
29
+ const state = store();
30
+ const listeners = state.listeners.get(projectId) ?? new Set();
31
+ listeners.add(listener);
32
+ state.listeners.set(projectId, listeners);
33
+ return () => listeners.delete(listener);
34
+ }
35
+ export function waitForCapabilityRuntimeV1(projectId, signal) {
36
+ if (signal?.aborted)
37
+ return Promise.reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
38
+ const existing = getCapabilityRuntimeV1(projectId);
39
+ if (existing)
40
+ return Promise.resolve(existing);
41
+ return new Promise((resolve, reject) => {
42
+ const onAbort = () => { unsubscribe(); reject(signal?.reason ?? new DOMException("Aborted", "AbortError")); };
43
+ const unsubscribe = subscribeCapabilityRuntimeV1(projectId, () => {
44
+ const registered = getCapabilityRuntimeV1(projectId);
45
+ if (!registered)
46
+ return;
47
+ unsubscribe();
48
+ signal?.removeEventListener("abort", onAbort);
49
+ resolve(registered);
50
+ });
51
+ signal?.addEventListener("abort", onAbort, { once: true });
52
+ });
53
+ }
package/dist/index.d.ts CHANGED
@@ -20,4 +20,5 @@ export { createCapabilityClient, type CapabilityConnectInputV1, type CapabilityC
20
20
  export { createCapabilityChannel, type CapabilityChannelV1, } from "./capabilities/channel.js";
21
21
  export { createHostActionExecutor, type CapabilityExecutionFenceV1, } from "./capabilities/hostActionExecutor.js";
22
22
  export { SpotlightCapabilityError } from "./capabilities/errors.js";
23
+ export { getCapabilityRuntimeV1, registerCapabilityRuntimeV1, subscribeCapabilityRuntimeV1, waitForCapabilityRuntimeV1, type RegisteredCapabilityRuntimeV1, } from "./capabilities/runtimeCapabilities.js";
23
24
  //# 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,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,mCAAmC,EACnC,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,+BAA+B,GACrC,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,uBAAuB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,8BAA8B,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OA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,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,KAAK,6BAA6B,GACnC,MAAM,uCAAuC,CAAC"}
package/dist/index.js CHANGED
@@ -18,3 +18,4 @@ export { createCapabilityClient, } from "./capabilities/handshake.js";
18
18
  export { createCapabilityChannel, } from "./capabilities/channel.js";
19
19
  export { createHostActionExecutor, } from "./capabilities/hostActionExecutor.js";
20
20
  export { SpotlightCapabilityError } from "./capabilities/errors.js";
21
+ export { getCapabilityRuntimeV1, registerCapabilityRuntimeV1, subscribeCapabilityRuntimeV1, waitForCapabilityRuntimeV1, } from "./capabilities/runtimeCapabilities.js";
@@ -0,0 +1,4 @@
1
+ export declare function canonicalArchivePathProblem(path: string, options?: {
2
+ directory?: boolean;
3
+ }): string | undefined;
4
+ //# sourceMappingURL=archivePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archivePath.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/archivePath.ts"],"names":[],"mappings":"AAEA,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GACpC,MAAM,GAAG,SAAS,CAYpB"}
@@ -0,0 +1,22 @@
1
+ import { containsLoneSurrogate } from "./canonicalJson.js";
2
+ export function canonicalArchivePathProblem(path, options = {}) {
3
+ const directory = options.directory === true;
4
+ const normalized = directory && path.endsWith("/") ? path.slice(0, -1) : path;
5
+ if (!normalized)
6
+ return "path is empty";
7
+ if (normalized.startsWith("/"))
8
+ return "path is absolute";
9
+ if (/^[A-Za-z]:/.test(normalized))
10
+ return "path has a Windows drive prefix";
11
+ if (normalized.includes("\\"))
12
+ return "path contains a backslash";
13
+ if (normalized.includes("\0"))
14
+ return "path contains NUL";
15
+ if (containsLoneSurrogate(normalized))
16
+ return "path contains a lone surrogate";
17
+ if (!directory && path.endsWith("/"))
18
+ return "file path has a trailing slash";
19
+ if (normalized.split("/").some((segment) => segment === "" || segment === "." || segment === ".."))
20
+ return "path contains an empty or dot segment";
21
+ return undefined;
22
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"capabilityFileMap.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityFileMap.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,8BAA8B,CAAC;AA+BtC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,QAAQ,EAAE,wBAAwB,CAAC;IACnC,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAoLD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,iBAAiB,EAAE,UAAU,CAAC;CAC/B,GAAG,wBAAwB,CAmG3B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;CACnE,GAAG,MAAM,CA4BT"}
1
+ {"version":3,"file":"capabilityFileMap.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityFileMap.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,8BAA8B,CAAC;AA+BtC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,QAAQ,EAAE,wBAAwB,CAAC;IACnC,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAqKD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,iBAAiB,EAAE,UAAU,CAAC;CAC/B,GAAG,wBAAwB,CAmG3B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;CACnE,GAAG,MAAM,CA4BT"}
@@ -1,7 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { isProxy } from "node:util/types";
3
- import { canonicalizeJson, compareUtf16, containsLoneSurrogate, } from "./canonicalJson.js";
3
+ import { canonicalizeJson, compareUtf16, } from "./canonicalJson.js";
4
4
  import { CapabilityArtifactError } from "./capabilityArtifactError.js";
5
+ import { canonicalArchivePathProblem } from "./archivePath.js";
5
6
  const CANONICAL_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
6
7
  const SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
7
8
  const textEncoder = new TextEncoder();
@@ -119,19 +120,9 @@ function validateRelativePath(relativePath) {
119
120
  if (typeof relativePath !== "string") {
120
121
  invalidInput("Skill relativePath must be a string");
121
122
  }
122
- if (relativePath.length === 0 ||
123
- relativePath.startsWith("/") ||
124
- /^[A-Za-z]:/.test(relativePath) ||
125
- relativePath.includes("\\") ||
126
- relativePath.includes("\0") ||
127
- containsLoneSurrogate(relativePath) ||
128
- relativePath.endsWith("/")) {
123
+ if (canonicalArchivePathProblem(relativePath)) {
129
124
  throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid Skill relative path: ${relativePath}`);
130
125
  }
131
- const segments = relativePath.split("/");
132
- if (segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
133
- throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid Skill relative path segment: ${relativePath}`);
134
- }
135
126
  }
136
127
  function ensureUstarPath(path) {
137
128
  if (!canRepresentUstarPath(path)) {
@@ -1 +1 @@
1
- {"version":3,"file":"deterministicTar.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicTar.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AAqKD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,CA2B9E"}
1
+ {"version":3,"file":"deterministicTar.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicTar.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AAwJD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,CA2B9E"}
@@ -1,4 +1,5 @@
1
- import { compareUtf16, containsLoneSurrogate } from "./canonicalJson.js";
1
+ import { compareUtf16 } from "./canonicalJson.js";
2
+ import { canonicalArchivePathProblem } from "./archivePath.js";
2
3
  import { CapabilityArtifactError } from "./capabilityArtifactError.js";
3
4
  const TAR_BLOCK_SIZE = 512;
4
5
  const textEncoder = new TextEncoder();
@@ -6,18 +7,8 @@ function failInvalidPath(path) {
6
7
  throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid USTAR file path: ${path}`);
7
8
  }
8
9
  function validateFilePath(path) {
9
- if (path.length === 0 ||
10
- path.startsWith("/") ||
11
- /^[A-Za-z]:/.test(path) ||
12
- path.includes("\\") ||
13
- path.includes("\0") ||
14
- containsLoneSurrogate(path) ||
15
- path.endsWith("/")) {
10
+ if (canonicalArchivePathProblem(path))
16
11
  failInvalidPath(path);
17
- }
18
- if (path.split("/").some((segment) => segment === "" || segment === "." || segment === "..")) {
19
- failInvalidPath(path);
20
- }
21
12
  }
22
13
  function byteLength(value) {
23
14
  return textEncoder.encode(value).byteLength;
@@ -0,0 +1,2 @@
1
+ export declare function runCapabilityPublishCliV1(argv: readonly string[]): Promise<number>;
2
+ //# sourceMappingURL=capabilityPublishCli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityPublishCli.d.ts","sourceRoot":"","sources":["../../src/node/capabilityPublishCli.ts"],"names":[],"mappings":"AAsCA,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CASxF"}
@@ -0,0 +1,115 @@
1
+ import { createHash } from "node:crypto";
2
+ import { access, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
3
+ import { basename, dirname, join } from "node:path";
4
+ import { gunzipSync } from "node:zlib";
5
+ import { canonicalizeJson } from "./capabilities/canonicalJson.js";
6
+ import { computeArtifactDigestV1 } from "./capabilities/capabilityFileMap.js";
7
+ import { canonicalArchivePathProblem } from "./capabilities/archivePath.js";
8
+ function args(argv) { const parsed = {}; for (let i = 0; i < argv.length; i += 2) {
9
+ const k = argv[i], v = argv[i + 1];
10
+ if (!k?.startsWith("--") || !v)
11
+ throw new TypeError("Capability publish CLI expects --key value arguments.");
12
+ parsed[k.slice(2)] = v;
13
+ } return parsed; }
14
+ const sha256 = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
15
+ function tarFiles(archive) {
16
+ const tar = Uint8Array.from(gunzipSync(archive));
17
+ const files = new Map();
18
+ const seenPaths = new Set();
19
+ let offset = 0;
20
+ const text = (bytes) => new TextDecoder().decode(bytes.subarray(0, bytes.indexOf(0) < 0 ? bytes.length : bytes.indexOf(0)));
21
+ while (offset + 512 <= tar.length) {
22
+ const h = tar.subarray(offset, offset + 512);
23
+ if (h.every((b) => b === 0)) {
24
+ const second = tar.subarray(offset + 512, offset + 1024);
25
+ if (second.length < 512 || !second.every((b) => b === 0) || !tar.subarray(offset + 1024).every((b) => b === 0))
26
+ throw new TypeError("Invalid USTAR trailing content.");
27
+ return files;
28
+ }
29
+ const storedText = text(h.subarray(148, 156)).trim();
30
+ if (!/^[0-7]+$/.test(storedText))
31
+ throw new TypeError("Invalid USTAR header checksum field.");
32
+ const stored = Number.parseInt(storedText, 8);
33
+ let sum = 0;
34
+ for (let i = 0; i < 512; i++)
35
+ sum += i >= 148 && i < 156 ? 32 : (h[i] ?? 0);
36
+ if (sum !== stored)
37
+ throw new TypeError("Invalid USTAR header checksum.");
38
+ if (text(h.subarray(257, 263)) !== "ustar" || text(h.subarray(263, 265)) !== "00")
39
+ throw new TypeError("Invalid USTAR header magic.");
40
+ const type = h[156];
41
+ if (type !== 48 && type !== 0 && type !== 53)
42
+ throw new TypeError("Artifact contains an unsupported USTAR entry.");
43
+ const name = text(h.subarray(0, 100));
44
+ const prefix = text(h.subarray(345, 500));
45
+ const rawPath = prefix ? `${prefix}/${name}` : name;
46
+ const isDirectory = type === 53;
47
+ const path = isDirectory ? rawPath.replace(/\/$/, "") : rawPath;
48
+ if (canonicalArchivePathProblem(rawPath, { directory: isDirectory }) || seenPaths.has(path))
49
+ throw new TypeError("Invalid or duplicate USTAR path.");
50
+ seenPaths.add(path);
51
+ const sizeText = text(h.subarray(124, 136)).trim();
52
+ if (!/^[0-7]+$/.test(sizeText))
53
+ throw new TypeError("Invalid USTAR size field.");
54
+ const size = Number.parseInt(sizeText, 8);
55
+ if (isDirectory && size !== 0)
56
+ throw new TypeError("USTAR directory must be zero length.");
57
+ const start = offset + 512, end = start + size, padded = start + Math.ceil(size / 512) * 512;
58
+ if (end > tar.length || !tar.subarray(end, padded).every((b) => b === 0))
59
+ throw new TypeError("Invalid USTAR payload padding.");
60
+ if (!isDirectory)
61
+ files.set(path, tar.slice(start, end));
62
+ offset = padded;
63
+ }
64
+ throw new TypeError("USTAR archive is missing terminal zero blocks.");
65
+ }
66
+ function verify(archive, info) {
67
+ const files = tarFiles(archive);
68
+ const manifestBytes = files.get("manifest.json"), skillBytes = files.get("skill-manifest.json"), toolBytes = files.get("tool-manifest.json");
69
+ if (!manifestBytes || !skillBytes || !toolBytes)
70
+ throw new TypeError("Artifact is missing required manifests.");
71
+ const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
72
+ const manifestPaths = manifest.files.map((entry) => entry.path);
73
+ if (new Set(manifestPaths).size !== manifestPaths.length)
74
+ throw new TypeError("Artifact manifest contains duplicate file declarations.");
75
+ const declared = new Set(["manifest.json", ...manifestPaths]);
76
+ if (files.size !== declared.size || [...files.keys()].some((path) => !declared.has(path)))
77
+ throw new TypeError("Artifact contains undeclared regular files.");
78
+ for (const entry of manifest.files) {
79
+ const bytes = files.get(entry.path);
80
+ if (!bytes || bytes.byteLength !== entry.byteLength || sha256(bytes) !== entry.sha256)
81
+ throw new TypeError(`Artifact payload mismatch: ${entry.path}`);
82
+ }
83
+ const manifestDigest = sha256(manifestBytes), skillManifestDigest = sha256(skillBytes), toolManifestDigest = sha256(toolBytes);
84
+ const artifactDigest = computeArtifactDigestV1({ manifestDigest, skillManifestDigest, toolManifestDigest, payloads: manifest.files });
85
+ const actual = { digest: artifactDigest, manifestDigest, skillManifestDigest, toolManifestDigest, byteLength: archive.byteLength };
86
+ const expected = { digest: info.artifactDigest, manifestDigest: info.manifestDigest, skillManifestDigest: info.skillManifestDigest, toolManifestDigest: info.toolManifestDigest, byteLength: info.byteLength };
87
+ if (JSON.stringify(actual) !== JSON.stringify(expected))
88
+ throw new TypeError("Artifact digests do not match build info.");
89
+ return actual;
90
+ }
91
+ export async function runCapabilityPublishCliV1(argv) {
92
+ const input = args(argv);
93
+ if (!input.artifact || !input["build-info"] || !input["out-dir"])
94
+ throw new TypeError("Required: --artifact --build-info --out-dir");
95
+ const [archive, infoText] = await Promise.all([readFile(input.artifact), readFile(input["build-info"], "utf8")]);
96
+ const info = JSON.parse(infoText);
97
+ for (const field of ["projectId", "frontendBuildId"])
98
+ if (typeof info[field] !== "string" || !info[field])
99
+ throw new TypeError(`Invalid build info field: ${field}`);
100
+ const artifact = verify(archive, info);
101
+ const attestation = { schemaVersion: "spotlight.capability-attestation/1", projectId: info.projectId, frontendBuildId: info.frontendBuildId, artifact, createdAt: input["created-at"] ?? new Date().toISOString() };
102
+ const out = input["out-dir"];
103
+ await mkdir(dirname(out), { recursive: true });
104
+ await access(out).then(() => { throw new TypeError("Publish output already exists."); }, () => undefined);
105
+ const staging = await mkdtemp(join(dirname(out), `.${basename(out)}.tmp-`));
106
+ try {
107
+ await Promise.all([writeFile(join(staging, `${artifact.digest}.tgz`), archive, { flag: "wx" }), writeFile(join(staging, "capability-attestation.json"), `${new TextDecoder().decode(canonicalizeJson(attestation))}\n`, { flag: "wx", encoding: "utf8" })]);
108
+ await rename(staging, out);
109
+ }
110
+ catch (error) {
111
+ await rm(staging, { recursive: true, force: true });
112
+ throw error;
113
+ }
114
+ return 0;
115
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=spotlightCapabilitiesPublish.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spotlightCapabilitiesPublish.d.ts","sourceRoot":"","sources":["../../../src/node/cli/spotlightCapabilitiesPublish.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runCapabilityPublishCliV1 } from "../capabilityPublishCli.js";
3
+ runCapabilityPublishCliV1(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (error) => { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; });
@@ -11,4 +11,6 @@ export type { CanonicalSkillFileInputV1, CanonicalSkillInputV1, CapabilityArtifa
11
11
  export { canonicalizeJson, compareUtf16, type CanonicalJsonValue, } from "./capabilities/canonicalJson.js";
12
12
  export { buildToolManifestV1, type BuiltToolManifestV1, type ToolManifestV1, } from "./capabilities/toolManifest.js";
13
13
  export { buildSkillManifestV1, type CapabilitySkillManifestEntryV1, type CapabilitySkillManifestV1, } from "./capabilities/skillManifest.js";
14
+ export { publishCapabilityArtifactV1 } from "./publishCapabilityArtifact.js";
15
+ export { runCapabilityPublishCliV1 } from "./capabilityPublishCli.js";
14
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,GAC7B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACrC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,KAAK,2BAA2B,GACjC,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACV,y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9C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,KAAK,2BAA2B,GACjC,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,kBAAkB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,GAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -10,3 +10,5 @@ export { CAPABILITY_ARTIFACT_ERROR_CODES, CapabilityArtifactError, } from "./cap
10
10
  export { canonicalizeJson, compareUtf16, } from "./capabilities/canonicalJson.js";
11
11
  export { buildToolManifestV1, } from "./capabilities/toolManifest.js";
12
12
  export { buildSkillManifestV1, } from "./capabilities/skillManifest.js";
13
+ export { publishCapabilityArtifactV1 } from "./publishCapabilityArtifact.js";
14
+ export { runCapabilityPublishCliV1 } from "./capabilityPublishCli.js";
@@ -0,0 +1,12 @@
1
+ import type { CapabilityArtifactBuildV1 } from "./capabilities/capabilityArtifact.js";
2
+ export declare function publishCapabilityArtifactV1(input: {
3
+ outDir: string;
4
+ projectId: string;
5
+ frontendBuildId: string;
6
+ build: CapabilityArtifactBuildV1;
7
+ createdAt?: string;
8
+ }): Promise<{
9
+ artifactPath: string;
10
+ attestationPath: string;
11
+ }>;
12
+ //# sourceMappingURL=publishCapabilityArtifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishCapabilityArtifact.d.ts","sourceRoot":"","sources":["../../src/node/publishCapabilityArtifact.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAGtF,wBAAsB,2BAA2B,CAAC,KAAK,EAAE;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,yBAAyB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CAqB7D"}
@@ -0,0 +1,25 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { canonicalizeJson } from "./capabilities/canonicalJson.js";
4
+ export async function publishCapabilityArtifactV1(input) {
5
+ await mkdir(input.outDir, { recursive: true });
6
+ const artifactPath = join(input.outDir, `${input.build.artifactDigest}.tgz`);
7
+ const attestationPath = join(input.outDir, "capability-attestation.json");
8
+ const artifact = {
9
+ digest: input.build.artifactDigest,
10
+ manifestDigest: input.build.manifestDigest,
11
+ skillManifestDigest: input.build.skillManifestDigest,
12
+ toolManifestDigest: input.build.toolManifestDigest,
13
+ byteLength: input.build.byteLength,
14
+ };
15
+ const attestation = {
16
+ schemaVersion: "spotlight.capability-attestation/1",
17
+ projectId: input.projectId,
18
+ frontendBuildId: input.frontendBuildId,
19
+ artifact,
20
+ createdAt: input.createdAt ?? new Date().toISOString(),
21
+ };
22
+ await writeFile(artifactPath, input.build.archive, { flag: "wx" });
23
+ await writeFile(attestationPath, `${new TextDecoder().decode(canonicalizeJson(attestation))}\n`, { flag: "wx", encoding: "utf8" });
24
+ return { artifactPath, attestationPath };
25
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"capabilityBuild.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuild.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,2BAA2B,CAAC;AAsHnC,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,OAAO,EAAE,iCAAiC,CAAC;IAC3C,OAAO,CAAC,EAAE,8BAA8B,CAAC;CAC1C,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA8FzC"}
1
+ {"version":3,"file":"capabilityBuild.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuild.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AAGnC,YAAY,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,2BAA2B,CAAC;AA2HnC,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,OAAO,EAAE,iCAAiC,CAAC;IAC3C,OAAO,CAAC,EAAE,8BAA8B,CAAC;CAC1C,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA8FzC"}
@@ -2,7 +2,7 @@ import { resolve, sep } from "node:path";
2
2
  import { isProxy } from "node:util/types";
3
3
  import { buildCapabilityArtifactV1, buildToolManifestV1, CapabilityArtifactError, loadCanonicalSkillsV1, scanProjectSkills, } from "../node/index.js";
4
4
  import { validateSkillContent } from "../node/capabilities/skillFileValidator.js";
5
- const PROJECT_FIELDS = new Set(["projectId", "tools"]);
5
+ const PROJECT_FIELDS = new Set(["projectId", "skillRoots", "tools"]);
6
6
  function invalidInput(message) {
7
7
  throw new CapabilityArtifactError("ARTIFACT_INPUT_INVALID", message);
8
8
  }
@@ -18,9 +18,9 @@ function validateProject(value) {
18
18
  invalidInput("Capability project must be a plain object");
19
19
  }
20
20
  const keys = Reflect.ownKeys(value);
21
- if (keys.length !== PROJECT_FIELDS.size ||
21
+ if ((keys.length !== 2 && keys.length !== 3) ||
22
22
  keys.some((key) => typeof key !== "string" || !PROJECT_FIELDS.has(key))) {
23
- invalidInput("Capability project own fields must be exactly projectId and tools");
23
+ invalidInput("Capability project own fields must be projectId, tools, and optional skillRoots");
24
24
  }
25
25
  const readDataField = (field) => {
26
26
  const descriptor = Object.getOwnPropertyDescriptor(value, field);
@@ -31,11 +31,16 @@ function validateProject(value) {
31
31
  };
32
32
  const projectId = readDataField("projectId");
33
33
  const tools = readDataField("tools");
34
+ const skillRootsDescriptor = Object.getOwnPropertyDescriptor(value, "skillRoots");
35
+ if (skillRootsDescriptor && (!skillRootsDescriptor.enumerable || !("value" in skillRootsDescriptor))) {
36
+ invalidInput("Capability project field skillRoots must be an enumerable data property");
37
+ }
34
38
  if (typeof projectId !== "string" || projectId.trim().length === 0) {
35
39
  invalidInput("Capability projectId must be a non-empty string");
36
40
  }
37
41
  return {
38
42
  projectId,
43
+ ...(skillRootsDescriptor ? { skillRoots: skillRootsDescriptor.value } : {}),
39
44
  tools: tools,
40
45
  };
41
46
  }
@@ -100,7 +105,7 @@ export async function buildViteCapabilitiesV1(input) {
100
105
  const scan = await scanProjectSkills({
101
106
  projectRoot: input.root,
102
107
  mode,
103
- skillRoots: input.options?.skillRoots,
108
+ skillRoots: input.options?.skillRoots ?? project.skillRoots,
104
109
  });
105
110
  const scanErrorDiagnostic = scan.diagnostics.find((diagnostic) => diagnostic.severity === "error");
106
111
  if (scanErrorDiagnostic)
@@ -4,6 +4,7 @@ import type { SkillRootInput, SkillScanDiagnostic } from "../node/capabilities/s
4
4
  import type { AgentSkillDiagnostic } from "../node/capabilities/skillValidator.js";
5
5
  export interface SpotlightCapabilityProjectBuildV1 {
6
6
  projectId: string;
7
+ skillRoots?: readonly SkillRootInput[];
7
8
  tools: readonly (FrontendToolDescriptorV1 | FrontendToolDefinitionV1)[];
8
9
  }
9
10
  export interface SpotlightCapabilitiesOptionsV1 {
@@ -1 +1 @@
1
- {"version":3,"file":"capabilityBuildTypes.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuildTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC,wBAAwB,GAAG,wBAAwB,CAAC,EAAE,CAAC;CACzE;AAED,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,mCAAmC,CAAC;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,iCAAiC,CAAC;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,6BAA6B;IAC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AS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC3C,OAAO,EAAE,UAAU,CAAC;IACpB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,WAAW,EAAE,SAAS,CAAC,mBAAmB,GAAG,oBAAoB,CAAC,EAAE,CAAC;CACtE"}
@@ -1 +1 @@
1
- {"version":3,"file":"capabilityVirtualModule.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,eAAO,MAAM,gCAAgC,EAC3C,gCAAyC,CAAC;AAC5C,eAAO,MAAM,yCAAyC,EACpD,kCAA2C,CAAC;AAE9C,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAyCD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC1C,OAAO,GAAE,QAAQ,CAAC;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAM,GAClD,QAAQ,CAAC,yBAAyB,CAAC,CAQrC"}
1
+ {"version":3,"file":"capabilityVirtualModule.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,eAAO,MAAM,gCAAgC,EAC3C,gCAAyC,CAAC;AAC5C,eAAO,MAAM,yCAAyC,EACpD,kCAA2C,CAAC;AAE9C,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAyCD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC1C,OAAO,GAAE,QAAQ,CAAC;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAM,GAClD,QAAQ,CAAC,yBAAyB,CAAC,CAuBrC"}
@@ -36,8 +36,23 @@ function developmentProviderSource(buildInfo) {
36
36
  }
37
37
  export function buildCapabilityVirtualModuleV1(buildInfo, options = {}) {
38
38
  const canonicalBuildInfoJson = new TextDecoder().decode(canonicalizeJson(buildInfo));
39
+ const registrationSource = `const __spotlightRuntimeKey = Symbol.for("inupedia.spotlight.capability-runtime/1");
40
+ function registerCapabilityRuntimeV1(runtime) {
41
+ const store = globalThis[__spotlightRuntimeKey] ??= { providers: new Map(), listeners: new Map() };
42
+ store.providers.set(runtime.capabilityBuildInfo.projectId, runtime);
43
+ for (const listener of store.listeners.get(runtime.capabilityBuildInfo.projectId) ?? []) listener(runtime.capabilityBuildInfo);
44
+ }
45
+ registerCapabilityRuntimeV1({ capabilityBuildInfo, openUploadStream });
46
+ if (import.meta.hot) {
47
+ import.meta.hot.on("spotlight:capability-build", (event) => {
48
+ if (event?.buildInfo?.projectId === capabilityBuildInfo.projectId) {
49
+ const store = globalThis[__spotlightRuntimeKey];
50
+ for (const listener of store?.listeners.get(capabilityBuildInfo.projectId) ?? []) listener(Object.freeze(event.buildInfo));
51
+ }
52
+ });
53
+ }`;
39
54
  return Object.freeze({
40
55
  canonicalBuildInfoJson,
41
- source: `export const capabilityBuildInfo = Object.freeze(${canonicalBuildInfoJson});\n\n${options.runtimeUpload === true ? developmentProviderSource(buildInfo) : disabledProviderSource()}\n`,
56
+ source: `export const capabilityBuildInfo = Object.freeze(${canonicalBuildInfoJson});\n\n${options.runtimeUpload === true ? developmentProviderSource(buildInfo) : disabledProviderSource()}\n\n${registrationSource}\n`,
42
57
  });
43
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"spotlightCapabilities.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAKlE,OAAO,EAGL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AAuB9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CAyKR"}
1
+ {"version":3,"file":"spotlightCapabilities.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAKlE,OAAO,EAGL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AAuB9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CAoLR"}
@@ -65,6 +65,9 @@ export function spotlightCapabilities(project, options) {
65
65
  if (moduleNode !== undefined) {
66
66
  server?.moduleGraph.invalidateModule(moduleNode);
67
67
  }
68
+ server?.ws?.send("spotlight:capability-build", {
69
+ buildInfo: nextState.result.buildInfo,
70
+ });
68
71
  }
69
72
  catch (error) {
70
73
  state = previousState;
@@ -88,7 +91,7 @@ export function spotlightCapabilities(project, options) {
88
91
  configResolved(config) {
89
92
  root = config.root;
90
93
  command = config.command;
91
- const roots = options?.skillRoots ?? DEFAULT_SKILL_ROOTS;
94
+ const roots = options?.skillRoots ?? project.skillRoots ?? DEFAULT_SKILL_ROOTS;
92
95
  relevantRoots = Object.freeze(roots.map((entry) => {
93
96
  const path = typeof entry === "string" ? entry : entry.path;
94
97
  return resolve(config.root, path);
@@ -143,6 +146,14 @@ export function spotlightCapabilities(project, options) {
143
146
  ? RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID
144
147
  : null;
145
148
  },
149
+ transformIndexHtml() {
150
+ return [{
151
+ tag: "script",
152
+ attrs: { type: "module" },
153
+ children: `import ${JSON.stringify(SPOTLIGHT_CAPABILITIES_MODULE_ID)};`,
154
+ injectTo: "head-prepend",
155
+ }];
156
+ },
146
157
  load(id) {
147
158
  if (id !== RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID)
148
159
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inupedia/spotlight-client",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "HTTP/SSE helpers and host tool bridge for Inupedia Spotlight (monorepo workspace package)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "main": "./dist/index.js",
30
30
  "types": "./dist/index.d.ts",
31
31
  "bin": {
32
+ "spotlight-capabilities-publish": "./dist/node/cli/spotlightCapabilitiesPublish.js",
32
33
  "spotlight-capabilities": "./dist/node/publishCapabilitiesCli.js"
33
34
  },
34
35
  "publishConfig": {
@@ -46,7 +47,7 @@
46
47
  "fflate": "0.8.3",
47
48
  "magic-string": "^0.30.21",
48
49
  "yaml": "^2.8.4",
49
- "@inupedia/spotlight-protocol": "0.3.0"
50
+ "@inupedia/spotlight-protocol": "0.3.1"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"