@inupedia/spotlight-client 0.2.13 → 0.3.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.
Files changed (64) hide show
  1. package/dist/capabilities/channel.d.ts +28 -0
  2. package/dist/capabilities/channel.d.ts.map +1 -0
  3. package/dist/capabilities/channel.js +129 -0
  4. package/dist/capabilities/errors.d.ts +9 -0
  5. package/dist/capabilities/errors.d.ts.map +1 -0
  6. package/dist/capabilities/errors.js +19 -0
  7. package/dist/capabilities/handshake.d.ts +36 -0
  8. package/dist/capabilities/handshake.d.ts.map +1 -0
  9. package/dist/capabilities/handshake.js +78 -0
  10. package/dist/capabilities/hostActionExecutor.d.ts +19 -0
  11. package/dist/capabilities/hostActionExecutor.d.ts.map +1 -0
  12. package/dist/capabilities/hostActionExecutor.js +60 -0
  13. package/dist/capabilities/jsonSchema.d.ts +8 -0
  14. package/dist/capabilities/jsonSchema.d.ts.map +1 -0
  15. package/dist/capabilities/jsonSchema.js +43 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -0
  19. package/dist/node/capabilities/capabilityArtifact.d.ts +2 -0
  20. package/dist/node/capabilities/capabilityArtifact.d.ts.map +1 -1
  21. package/dist/node/capabilities/capabilityArtifact.js +6 -0
  22. package/dist/node/capabilities/capabilityFileMap.d.ts +2 -0
  23. package/dist/node/capabilities/capabilityFileMap.d.ts.map +1 -1
  24. package/dist/node/capabilities/capabilityFileMap.js +10 -2
  25. package/dist/node/capabilities/skillDirectoryLoader.d.ts +24 -0
  26. package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +1 -0
  27. package/dist/node/capabilities/skillDirectoryLoader.js +308 -0
  28. package/dist/node/capabilities/skillFileValidator.d.ts +8 -0
  29. package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
  30. package/dist/node/capabilities/skillFileValidator.js +46 -26
  31. package/dist/node/capabilities/skillManifest.d.ts +16 -0
  32. package/dist/node/capabilities/skillManifest.d.ts.map +1 -0
  33. package/dist/node/capabilities/skillManifest.js +22 -0
  34. package/dist/node/index.d.ts +2 -0
  35. package/dist/node/index.d.ts.map +1 -1
  36. package/dist/node/index.js +2 -0
  37. package/dist/node/publishCapabilitiesCli.d.ts +3 -0
  38. package/dist/node/publishCapabilitiesCli.d.ts.map +1 -0
  39. package/dist/node/publishCapabilitiesCli.js +36 -0
  40. package/dist/tools/frontendTool.d.ts +39 -0
  41. package/dist/tools/frontendTool.d.ts.map +1 -0
  42. package/dist/tools/frontendTool.js +51 -0
  43. package/dist/vite/capabilityBuild.d.ts +9 -0
  44. package/dist/vite/capabilityBuild.d.ts.map +1 -0
  45. package/dist/vite/capabilityBuild.js +164 -0
  46. package/dist/vite/capabilityBuildTypes.d.ts +31 -0
  47. package/dist/vite/capabilityBuildTypes.d.ts.map +1 -0
  48. package/dist/vite/capabilityBuildTypes.js +1 -0
  49. package/dist/vite/capabilityDevMiddleware.d.ts +5 -0
  50. package/dist/vite/capabilityDevMiddleware.d.ts.map +1 -0
  51. package/dist/vite/capabilityDevMiddleware.js +40 -0
  52. package/dist/vite/capabilityVirtualModule.d.ts +11 -0
  53. package/dist/vite/capabilityVirtualModule.d.ts.map +1 -0
  54. package/dist/vite/capabilityVirtualModule.js +43 -0
  55. package/dist/vite/capabilityVirtualModuleTypes.d.ts +12 -0
  56. package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +1 -0
  57. package/dist/vite/capabilityVirtualModuleTypes.js +1 -0
  58. package/dist/vite/index.d.ts +4 -0
  59. package/dist/vite/index.d.ts.map +1 -1
  60. package/dist/vite/index.js +3 -0
  61. package/dist/vite/spotlightCapabilities.d.ts +4 -0
  62. package/dist/vite/spotlightCapabilities.d.ts.map +1 -0
  63. package/dist/vite/spotlightCapabilities.js +170 -0
  64. package/package.json +7 -4
@@ -0,0 +1,28 @@
1
+ import { type CapabilityHandshakeResultV1, type RenewCapabilityLeaseResultV1 } from "@inupedia/spotlight-protocol";
2
+ import type { FrontendToolRegistryV1 } from "../tools/frontendTool.js";
3
+ import { type CapabilityExecutionFenceV1 } from "./hostActionExecutor.js";
4
+ type AcceptedHandshake = Extract<CapabilityHandshakeResultV1, {
5
+ status: "accepted";
6
+ }>;
7
+ export interface CapabilityChannelV1 {
8
+ open(): void;
9
+ close(): void;
10
+ renew(): Promise<RenewCapabilityLeaseResultV1>;
11
+ reconnect(): Promise<void>;
12
+ fence(): Readonly<CapabilityExecutionFenceV1>;
13
+ }
14
+ export declare function createCapabilityChannel(options: {
15
+ endpoint: string;
16
+ handshake: AcceptedHandshake;
17
+ identity: {
18
+ sessionId: string;
19
+ browserInstanceId: string;
20
+ tabInstanceId: string;
21
+ signal?: AbortSignal;
22
+ };
23
+ registry: FrontendToolRegistryV1;
24
+ fetch: typeof globalThis.fetch;
25
+ createWebSocket?: (url: string) => WebSocket;
26
+ }): CapabilityChannelV1;
27
+ export {};
28
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +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,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC;IACxG,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC9C,GAAG,mBAAmB,CA+HtB"}
@@ -0,0 +1,129 @@
1
+ import { SPOTLIGHT_CAPABILITY_PROTOCOL_V1, } from "@inupedia/spotlight-protocol";
2
+ import { capabilityResponseJson, SpotlightCapabilityError } from "./errors.js";
3
+ import { createHostActionExecutor } from "./hostActionExecutor.js";
4
+ export function createCapabilityChannel(options) {
5
+ let leaseVersion = options.handshake.leaseVersion;
6
+ let connectionId = options.handshake.connectionId;
7
+ let connectionEpoch = options.handshake.connectionEpoch;
8
+ let channelToken = options.handshake.capabilityChannelToken;
9
+ let socket;
10
+ let heartbeat;
11
+ let renewal;
12
+ let renewalPending = false;
13
+ let closed = false;
14
+ const fence = () => Object.freeze({
15
+ sessionId: options.identity.sessionId,
16
+ capabilitySnapshotId: options.handshake.capabilitySnapshotId,
17
+ leaseId: options.handshake.leaseId,
18
+ leaseVersion,
19
+ connectionId,
20
+ connectionEpoch,
21
+ browserInstanceId: options.identity.browserInstanceId,
22
+ tabInstanceId: options.identity.tabInstanceId,
23
+ });
24
+ const executor = createHostActionExecutor({ registry: options.registry, fence });
25
+ const send = (message) => {
26
+ if (socket?.readyState === 1)
27
+ socket.send(JSON.stringify(message));
28
+ };
29
+ const close = () => {
30
+ closed = true;
31
+ if (heartbeat)
32
+ clearInterval(heartbeat);
33
+ if (renewal)
34
+ clearInterval(renewal);
35
+ heartbeat = undefined;
36
+ renewal = undefined;
37
+ socket?.close();
38
+ socket = undefined;
39
+ };
40
+ const open = () => {
41
+ if (closed)
42
+ throw new SpotlightCapabilityError("CAPABILITY_LEASE_FENCED", "Capability channel is closed.");
43
+ socket?.close();
44
+ const create = options.createWebSocket ?? ((url) => new WebSocket(url));
45
+ const origin = typeof location === "undefined" ? "http://localhost" : location.origin;
46
+ const base = new URL(options.endpoint.replace(/\/$/, "") + "/", origin);
47
+ const channelPath = options.handshake.capabilityChannelUrl.replace(/^\//, "");
48
+ const url = new URL(channelPath, base);
49
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
50
+ socket = create(url.toString());
51
+ socket.onopen = () => {
52
+ send({
53
+ type: "client_hello",
54
+ protocolVersion: SPOTLIGHT_CAPABILITY_PROTOCOL_V1,
55
+ capabilityChannelToken: channelToken,
56
+ browserInstanceId: options.identity.browserInstanceId,
57
+ tabInstanceId: options.identity.tabInstanceId,
58
+ });
59
+ if (heartbeat)
60
+ clearInterval(heartbeat);
61
+ heartbeat = setInterval(() => send({ type: "heartbeat", ...fence(), sentAt: new Date().toISOString() }), 5_000);
62
+ if (renewal)
63
+ clearInterval(renewal);
64
+ renewal = setInterval(() => {
65
+ if (renewalPending)
66
+ return;
67
+ renewalPending = true;
68
+ void renew().catch(() => close()).finally(() => { renewalPending = false; });
69
+ }, 5_000);
70
+ };
71
+ socket.onmessage = (event) => {
72
+ void (async () => {
73
+ const message = JSON.parse(String(event.data));
74
+ if (message.type === "host_action_request") {
75
+ for (const response of await executor.execute(message))
76
+ send(response);
77
+ }
78
+ else if (message.type === "channel_fenced") {
79
+ close();
80
+ }
81
+ })();
82
+ };
83
+ socket.onclose = () => {
84
+ if (heartbeat)
85
+ clearInterval(heartbeat);
86
+ if (renewal)
87
+ clearInterval(renewal);
88
+ heartbeat = undefined;
89
+ renewal = undefined;
90
+ };
91
+ };
92
+ const post = async (path, body) => capabilityResponseJson(await options.fetch(`${options.endpoint.replace(/\/$/, "")}${path}`, {
93
+ method: "POST",
94
+ headers: { "Content-Type": "application/json" },
95
+ body: JSON.stringify(body),
96
+ signal: options.identity.signal,
97
+ }));
98
+ const renew = async () => {
99
+ const current = fence();
100
+ const result = await post(`/v1/capabilities/leases/${encodeURIComponent(current.leaseId)}/renew`, { ...current, expectedLeaseVersion: current.leaseVersion, liveTools: options.registry.liveTools() });
101
+ if (result.status === "revoked") {
102
+ close();
103
+ throw new SpotlightCapabilityError("CAPABILITY_LEASE_REVOKED", result.reason);
104
+ }
105
+ leaseVersion = result.leaseVersion;
106
+ return result;
107
+ };
108
+ return Object.freeze({
109
+ open,
110
+ close,
111
+ fence,
112
+ 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
+ },
128
+ });
129
+ }
@@ -0,0 +1,9 @@
1
+ import type { CapabilityErrorCodeV1 } from "@inupedia/spotlight-protocol";
2
+ export declare class SpotlightCapabilityError extends Error {
3
+ readonly code: CapabilityErrorCodeV1;
4
+ readonly retryable: boolean;
5
+ readonly details?: Record<string, unknown> | undefined;
6
+ constructor(code: CapabilityErrorCodeV1, message: string, retryable?: boolean, details?: Record<string, unknown> | undefined);
7
+ }
8
+ export declare function capabilityResponseJson<T>(response: Response): Promise<T>;
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/capabilities/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAA6B,MAAM,8BAA8B,CAAC;AAErG,qBAAa,wBAAyB,SAAQ,KAAK;IAE/C,QAAQ,CAAC,IAAI,EAAE,qBAAqB;IAEpC,QAAQ,CAAC,SAAS;IAClB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAHjC,IAAI,EAAE,qBAAqB,EACpC,OAAO,EAAE,MAAM,EACN,SAAS,UAAQ,EACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAK7C;AAED,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAU9E"}
@@ -0,0 +1,19 @@
1
+ export class SpotlightCapabilityError extends Error {
2
+ code;
3
+ retryable;
4
+ details;
5
+ constructor(code, message, retryable = false, details) {
6
+ super(message);
7
+ this.code = code;
8
+ this.retryable = retryable;
9
+ this.details = details;
10
+ this.name = "SpotlightCapabilityError";
11
+ }
12
+ }
13
+ export async function capabilityResponseJson(response) {
14
+ const body = await response.json().catch(() => undefined);
15
+ if (response.ok)
16
+ return body;
17
+ const error = body && typeof body === "object" && "error" in body ? body.error : undefined;
18
+ throw new SpotlightCapabilityError(error?.code ?? "HANDSHAKE_STATE_CONFLICT", error?.message ?? `Capability request failed with HTTP ${response.status}.`, error?.retryable ?? false, error?.details);
19
+ }
@@ -0,0 +1,36 @@
1
+ import { type CapabilityHandshakeResultV1 } from "@inupedia/spotlight-protocol";
2
+ import type { CapabilityBuildInfoV1 } from "../vite/capabilityBuildTypes.js";
3
+ import type { FrontendToolRegistryV1, SpotlightProjectV1 } from "../tools/frontendTool.js";
4
+ import { type CapabilityChannelV1 } from "./channel.js";
5
+ export interface CapabilityConnectInputV1 {
6
+ sessionId: string;
7
+ browserInstanceId: string;
8
+ tabInstanceId: string;
9
+ signal?: AbortSignal;
10
+ openChannel?: boolean;
11
+ }
12
+ export interface CapabilityConnectResultV1 {
13
+ handshake: Extract<CapabilityHandshakeResultV1, {
14
+ status: "accepted";
15
+ }>;
16
+ channel?: CapabilityChannelV1;
17
+ }
18
+ export interface CreateCapabilityClientOptionsV1 {
19
+ endpoint: string;
20
+ project: SpotlightProjectV1;
21
+ registry: FrontendToolRegistryV1;
22
+ buildInfo: Readonly<CapabilityBuildInfoV1>;
23
+ openUploadStream: () => Promise<{
24
+ digest: string;
25
+ byteLength: number;
26
+ contentType: "application/gzip";
27
+ stream: ReadableStream<Uint8Array>;
28
+ }>;
29
+ fetch?: typeof globalThis.fetch;
30
+ createOfferId?: () => string;
31
+ createWebSocket?: (url: string) => WebSocket;
32
+ }
33
+ export declare function createCapabilityClient(options: CreateCapabilityClientOptionsV1): Readonly<{
34
+ connect(input: CapabilityConnectInputV1): Promise<CapabilityConnectResultV1>;
35
+ }>;
36
+ //# sourceMappingURL=handshake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/capabilities/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,OAAO,CAAC,2BAA2B,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACxE,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC3C,gBAAgB,EAAE,MAAM,OAAO,CAAC;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,kBAAkB,CAAC;QAChC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;KACpC,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC9C;AAMD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,+BAA+B;mBAqBtD,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;GAqDrF"}
@@ -0,0 +1,78 @@
1
+ import { SPOTLIGHT_CAPABILITY_PROTOCOL_V1, } from "@inupedia/spotlight-protocol";
2
+ import { createCapabilityChannel } from "./channel.js";
3
+ import { capabilityResponseJson } from "./errors.js";
4
+ function endpoint(base, path) {
5
+ return `${base.replace(/\/$/, "")}${path}`;
6
+ }
7
+ export function createCapabilityClient(options) {
8
+ const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
9
+ const offerIds = new Map();
10
+ const offerIdFor = (key) => {
11
+ const existing = offerIds.get(key);
12
+ if (existing)
13
+ return existing;
14
+ const created = options.createOfferId?.() ?? globalThis.crypto.randomUUID();
15
+ offerIds.set(key, created);
16
+ return created;
17
+ };
18
+ async function post(path, body, signal) {
19
+ return capabilityResponseJson(await fetcher(endpoint(options.endpoint, path), {
20
+ method: "POST",
21
+ headers: { "Content-Type": "application/json" },
22
+ body: JSON.stringify(body),
23
+ signal,
24
+ }));
25
+ }
26
+ return Object.freeze({
27
+ async connect(input) {
28
+ const key = [input.sessionId, options.buildInfo.frontendBuildId, options.buildInfo.artifactDigest, input.browserInstanceId, input.tabInstanceId].join("\u0000");
29
+ const offer = {
30
+ protocolVersion: SPOTLIGHT_CAPABILITY_PROTOCOL_V1,
31
+ offerId: offerIdFor(key),
32
+ projectId: options.project.projectId,
33
+ sessionId: input.sessionId,
34
+ frontendBuildId: options.buildInfo.frontendBuildId,
35
+ browserInstanceId: input.browserInstanceId,
36
+ tabInstanceId: input.tabInstanceId,
37
+ capabilityArtifact: {
38
+ digest: options.buildInfo.artifactDigest,
39
+ manifestDigest: options.buildInfo.manifestDigest,
40
+ skillManifestDigest: options.buildInfo.skillManifestDigest,
41
+ toolManifestDigest: options.buildInfo.toolManifestDigest,
42
+ byteLength: options.buildInfo.byteLength,
43
+ },
44
+ liveTools: options.registry.liveTools(),
45
+ };
46
+ let handshake = await post("/v1/capabilities/handshakes", offer, input.signal);
47
+ if (handshake.status === "upload_required") {
48
+ const upload = await options.openUploadStream();
49
+ const uploadRequest = {
50
+ method: "PUT",
51
+ headers: {
52
+ Authorization: `Bearer ${handshake.uploadToken}`,
53
+ "Content-Type": upload.contentType,
54
+ "Content-Length": String(upload.byteLength),
55
+ },
56
+ body: upload.stream,
57
+ signal: input.signal,
58
+ duplex: "half",
59
+ };
60
+ await capabilityResponseJson(await fetcher(endpoint(options.endpoint, handshake.uploadUrl), uploadRequest));
61
+ handshake = await post(`/v1/capabilities/handshakes/${encodeURIComponent(handshake.handshakeId)}/resume`, { resumeToken: handshake.resumeToken }, input.signal);
62
+ }
63
+ if (handshake.status !== "accepted")
64
+ throw new Error("Capability Handshake did not reach a terminal accepted state.");
65
+ const channel = input.openChannel === false ? undefined : createCapabilityChannel({
66
+ endpoint: options.endpoint,
67
+ handshake,
68
+ identity: input,
69
+ registry: options.registry,
70
+ fetch: fetcher,
71
+ createWebSocket: options.createWebSocket,
72
+ });
73
+ if (channel)
74
+ channel.open();
75
+ return { handshake, ...(channel ? { channel } : {}) };
76
+ },
77
+ });
78
+ }
@@ -0,0 +1,19 @@
1
+ import type { HostActionAckV2, HostActionNackV2, HostActionRequestV2, HostActionResultV2 } from "@inupedia/spotlight-protocol";
2
+ import type { FrontendToolRegistryV1 } from "../tools/frontendTool.js";
3
+ export interface CapabilityExecutionFenceV1 {
4
+ sessionId: string;
5
+ capabilitySnapshotId: string;
6
+ leaseId: string;
7
+ leaseVersion: number;
8
+ connectionId: string;
9
+ connectionEpoch: number;
10
+ browserInstanceId: string;
11
+ tabInstanceId: string;
12
+ }
13
+ export declare function createHostActionExecutor(options: {
14
+ registry: FrontendToolRegistryV1;
15
+ fence: CapabilityExecutionFenceV1 | (() => CapabilityExecutionFenceV1);
16
+ }): Readonly<{
17
+ execute(request: HostActionRequestV2): Promise<Array<HostActionAckV2 | HostActionNackV2 | HostActionResultV2>>;
18
+ }>;
19
+ //# sourceMappingURL=hostActionExecutor.d.ts.map
@@ -0,0 +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,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AASD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,EAAE,0BAA0B,GAAG,CAAC,MAAM,0BAA0B,CAAC,CAAC;CACxE;qBAE0B,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,GAAG,gBAAgB,GAAG,kBAAkB,CAAC,CAAC;GAiDvH"}
@@ -0,0 +1,60 @@
1
+ import { validateJsonSchemaValue } from "./jsonSchema.js";
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
+ }
7
+ export function createHostActionExecutor(options) {
8
+ 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
+ },
59
+ });
60
+ }
@@ -0,0 +1,8 @@
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 {};
8
+ //# sourceMappingURL=jsonSchema.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,43 @@
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]));
24
+ }
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;
42
+ }
43
+ }
package/dist/index.d.ts CHANGED
@@ -15,4 +15,9 @@ export { substituteSkillPlaceholders, executeInlineShellInMarkdown, prepareSkill
15
15
  export { registerSkillScriptTool, type RegisterSkillScriptToolOptions, type SkillScriptRunner, } from "./skillScriptTool.js";
16
16
  export { joinSkillScriptPath, type SkillScriptRunResult, } from "./skillScriptPath.js";
17
17
  export type { AgentDef } from "./agentDecoratorTypes.js";
18
+ export { createFrontendToolRegistry, defineFrontendTool, defineSpotlightProject, projectToolDescriptors, type FrontendToolDefinitionV1, type FrontendToolHandlerContextV1, type FrontendToolRegistryV1, type SpotlightProjectV1, } from "./tools/frontendTool.js";
19
+ export { createCapabilityClient, type CapabilityConnectInputV1, type CapabilityConnectResultV1, type CreateCapabilityClientOptionsV1, } from "./capabilities/handshake.js";
20
+ export { createCapabilityChannel, type CapabilityChannelV1, } from "./capabilities/channel.js";
21
+ export { createHostActionExecutor, type CapabilityExecutionFenceV1, } from "./capabilities/hostActionExecutor.js";
22
+ export { SpotlightCapabilityError } from "./capabilities/errors.js";
18
23
  //# 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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KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,qBAAqB,EACrB,KAAK,4BAA4B,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,2BAA2B,EAC3B,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,+BAA+B,GACrC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,uBAAuB,EACvB,KAAK,mBAAmB,GACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,EACxB,KAAK,0BAA0B,GAChC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -13,3 +13,8 @@ export { validateSkillFrontmatter, describeCapabilitySurface, SPOTLIGHT_LAYOUT,
13
13
  export { substituteSkillPlaceholders, executeInlineShellInMarkdown, prepareSkillMarkdownContent, } from "./skillPrompt.js";
14
14
  export { registerSkillScriptTool, } from "./skillScriptTool.js";
15
15
  export { joinSkillScriptPath, } from "./skillScriptPath.js";
16
+ export { createFrontendToolRegistry, defineFrontendTool, defineSpotlightProject, projectToolDescriptors, } from "./tools/frontendTool.js";
17
+ export { createCapabilityClient, } from "./capabilities/handshake.js";
18
+ export { createCapabilityChannel, } from "./capabilities/channel.js";
19
+ export { createHostActionExecutor, } from "./capabilities/hostActionExecutor.js";
20
+ export { SpotlightCapabilityError } from "./capabilities/errors.js";
@@ -3,10 +3,12 @@ export interface CapabilityArtifactBuildV1 {
3
3
  artifactVersion: "spotlight.capability-artifact/1";
4
4
  artifactDigest: string;
5
5
  manifestDigest: string;
6
+ skillManifestDigest: string;
6
7
  toolManifestDigest: string;
7
8
  byteLength: number;
8
9
  archive: Uint8Array;
9
10
  manifestBytes: Uint8Array;
11
+ skillManifestBytes: Uint8Array;
10
12
  toolManifestBytes: Uint8Array;
11
13
  }
12
14
  export declare function buildCapabilityArtifactV1(input: CapabilityArtifactInputV1): CapabilityArtifactBuildV1;
@@ -1 +1 @@
1
- {"version":3,"file":"capabilityArtifact.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityArtifact.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAK9E,MAAM,WAAW,yBAAyB;IACxC,eAAe,EAAE,iCAAiC,CAAC;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,aAAa,EAAE,UAAU,CAAC;IAC1B,iBAAiB,EAAE,UAAU,CAAC;CAC/B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,yBAAyB,GAC/B,yBAAyB,CA2B3B"}
1
+ {"version":3,"file":"capabilityArtifact.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityArtifact.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAM9E,MAAM,WAAW,yBAAyB;IACxC,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;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,aAAa,EAAE,UAAU,CAAC;IAC1B,kBAAkB,EAAE,UAAU,CAAC;IAC/B,iBAAiB,EAAE,UAAU,CAAC;CAC/B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,yBAAyB,GAC/B,yBAAyB,CAgC3B"}
@@ -1,15 +1,19 @@
1
1
  import { buildCapabilityFileMapV1, computeArtifactDigestV1, } from "./capabilityFileMap.js";
2
2
  import { encodeDeterministicGzipV1 } from "./deterministicGzip.js";
3
3
  import { encodeDeterministicUstarV1 } from "./deterministicTar.js";
4
+ import { buildSkillManifestV1 } from "./skillManifest.js";
4
5
  import { buildToolManifestV1 } from "./toolManifest.js";
5
6
  export function buildCapabilityArtifactV1(input) {
6
7
  const toolManifest = buildToolManifestV1(input.tools);
8
+ const skillManifest = buildSkillManifestV1(input.skills);
7
9
  const fileMap = buildCapabilityFileMapV1({
8
10
  skills: input.skills,
11
+ skillManifestBytes: skillManifest.bytes,
9
12
  toolManifestBytes: toolManifest.bytes,
10
13
  });
11
14
  const artifactDigest = computeArtifactDigestV1({
12
15
  manifestDigest: fileMap.manifestDigest,
16
+ skillManifestDigest: skillManifest.digest,
13
17
  toolManifestDigest: toolManifest.digest,
14
18
  payloads: fileMap.payloads,
15
19
  });
@@ -22,10 +26,12 @@ export function buildCapabilityArtifactV1(input) {
22
26
  artifactVersion: "spotlight.capability-artifact/1",
23
27
  artifactDigest,
24
28
  manifestDigest: fileMap.manifestDigest,
29
+ skillManifestDigest: skillManifest.digest,
25
30
  toolManifestDigest: toolManifest.digest,
26
31
  byteLength: archive.byteLength,
27
32
  archive,
28
33
  manifestBytes: Uint8Array.from(fileMap.manifestBytes),
34
+ skillManifestBytes: Uint8Array.from(skillManifest.bytes),
29
35
  toolManifestBytes: Uint8Array.from(toolManifest.bytes),
30
36
  };
31
37
  }
@@ -7,10 +7,12 @@ export interface BuiltCapabilityFileMapV1 {
7
7
  }
8
8
  export declare function buildCapabilityFileMapV1(input: {
9
9
  skills: CanonicalSkillInputV1[];
10
+ skillManifestBytes?: Uint8Array;
10
11
  toolManifestBytes: Uint8Array;
11
12
  }): BuiltCapabilityFileMapV1;
12
13
  export declare function computeArtifactDigestV1(input: {
13
14
  manifestDigest: string;
15
+ skillManifestDigest?: string;
14
16
  toolManifestDigest: string;
15
17
  payloads: Array<Pick<CapabilityPayloadFileV1, "path" | "sha256">>;
16
18
  }): string;
@@ -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,iBAAiB,EAAE,UAAU,CAAC;CAC/B,GAAG,wBAAwB,CAqF3B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;CACnE,GAAG,MAAM,CA2BT"}
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"}
@@ -165,7 +165,11 @@ function addPayload(payloads, seenPaths, payload) {
165
165
  payloads.push(payload);
166
166
  }
167
167
  export function buildCapabilityFileMapV1(input) {
168
- const root = readDataRecord(input, "Capability file-map input", new Set(["skills", "toolManifestBytes"]));
168
+ const root = readDataRecord(input, "Capability file-map input", new Set(["skills", "skillManifestBytes", "toolManifestBytes"]));
169
+ if (root.skillManifestBytes !== undefined && (isProxy(root.skillManifestBytes) ||
170
+ !(root.skillManifestBytes instanceof Uint8Array))) {
171
+ invalidInput("skillManifestBytes must be a Uint8Array");
172
+ }
169
173
  if (isProxy(root.toolManifestBytes) ||
170
174
  !(root.toolManifestBytes instanceof Uint8Array)) {
171
175
  invalidInput("toolManifestBytes must be a Uint8Array");
@@ -173,6 +177,9 @@ export function buildCapabilityFileMapV1(input) {
173
177
  const skills = readDenseDataArray(root.skills, "skills");
174
178
  const payloads = [];
175
179
  const seenPaths = new Set();
180
+ if (root.skillManifestBytes instanceof Uint8Array) {
181
+ addPayload(payloads, seenPaths, createPayload("skill-manifest.json", root.skillManifestBytes, "application/json"));
182
+ }
176
183
  addPayload(payloads, seenPaths, createPayload("tool-manifest.json", root.toolManifestBytes, "application/json"));
177
184
  for (const [skillIndex, skillValue] of skills.entries()) {
178
185
  const skill = readDataRecord(skillValue, `skills[${skillIndex}]`, new Set(["name", "files"]));
@@ -215,7 +222,7 @@ export function buildCapabilityFileMapV1(input) {
215
222
  };
216
223
  }
217
224
  export function computeArtifactDigestV1(input) {
218
- if (!SHA256_DIGEST.test(input.manifestDigest) || !SHA256_DIGEST.test(input.toolManifestDigest)) {
225
+ if (!SHA256_DIGEST.test(input.manifestDigest) || (input.skillManifestDigest !== undefined && !SHA256_DIGEST.test(input.skillManifestDigest)) || !SHA256_DIGEST.test(input.toolManifestDigest)) {
219
226
  throw new CapabilityArtifactError("ARTIFACT_JSON_NOT_IJSON", "Artifact preimage contains an invalid manifest digest");
220
227
  }
221
228
  const payloadDigests = input.payloads
@@ -229,6 +236,7 @@ export function computeArtifactDigestV1(input) {
229
236
  return sha256(canonicalizeJson({
230
237
  artifactVersion: "spotlight.capability-artifact/1",
231
238
  manifestDigest: input.manifestDigest,
239
+ ...(input.skillManifestDigest ? { skillManifestDigest: input.skillManifestDigest } : {}),
232
240
  toolManifestDigest: input.toolManifestDigest,
233
241
  payloadDigests,
234
242
  }));
@@ -0,0 +1,24 @@
1
+ import type { CanonicalSkillInputV1 } from "./capabilityArtifactTypes.js";
2
+ import type { ScannedSkill } from "./skillScanner.js";
3
+ export declare const CAPABILITY_SKILL_LIMITS_V1: {
4
+ readonly maxSkills: 200;
5
+ readonly maxFiles: 2000;
6
+ readonly maxExpandedBytes: number;
7
+ };
8
+ export type CapabilitySkillLoadErrorCodeV1 = "CAPABILITY_SKILL_ENTRY_UNSAFE" | "CAPABILITY_SKILL_LIMIT_EXCEEDED" | "CAPABILITY_FILE_LIMIT_EXCEEDED" | "CAPABILITY_EXPANDED_SIZE_EXCEEDED";
9
+ export declare class CapabilitySkillLoadErrorV1 extends Error {
10
+ readonly code: CapabilitySkillLoadErrorCodeV1;
11
+ constructor(code: CapabilitySkillLoadErrorCodeV1, message: string);
12
+ }
13
+ export interface LoadCanonicalSkillsInputV1 {
14
+ projectRoot: string;
15
+ skills: readonly ScannedSkill[];
16
+ }
17
+ export interface LoadedCanonicalSkillsV1 {
18
+ skills: CanonicalSkillInputV1[];
19
+ watchedFiles: string[];
20
+ fileCount: number;
21
+ expandedBytes: number;
22
+ }
23
+ export declare function loadCanonicalSkillsV1(input: LoadCanonicalSkillsInputV1): Promise<LoadedCanonicalSkillsV1>;
24
+ //# sourceMappingURL=skillDirectoryLoader.d.ts.map