@inupedia/spotlight-client 0.2.14 → 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 (43) 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/skillManifest.d.ts +16 -0
  26. package/dist/node/capabilities/skillManifest.d.ts.map +1 -0
  27. package/dist/node/capabilities/skillManifest.js +22 -0
  28. package/dist/node/index.d.ts +1 -0
  29. package/dist/node/index.d.ts.map +1 -1
  30. package/dist/node/index.js +1 -0
  31. package/dist/node/publishCapabilitiesCli.d.ts +3 -0
  32. package/dist/node/publishCapabilitiesCli.d.ts.map +1 -0
  33. package/dist/node/publishCapabilitiesCli.js +36 -0
  34. package/dist/tools/frontendTool.d.ts +39 -0
  35. package/dist/tools/frontendTool.d.ts.map +1 -0
  36. package/dist/tools/frontendTool.js +51 -0
  37. package/dist/vite/capabilityBuild.d.ts.map +1 -1
  38. package/dist/vite/capabilityBuild.js +24 -1
  39. package/dist/vite/capabilityBuildTypes.d.ts +3 -1
  40. package/dist/vite/capabilityBuildTypes.d.ts.map +1 -1
  41. package/dist/vite/spotlightCapabilities.d.ts.map +1 -1
  42. package/dist/vite/spotlightCapabilities.js +5 -0
  43. package/package.json +5 -2
@@ -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,iC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upedia/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,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,OAAO,EACL,4BAA4B,EAC5B,KAAK,sBAAsB,GAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,YAAY,EACZ,OAAO,EACP,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,SAAS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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,EAC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kB,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,16 @@
1
+ import type { CanonicalSkillInputV1 } from "./capabilityArtifactTypes.js";
2
+ export interface CapabilitySkillManifestEntryV1 {
3
+ name: string;
4
+ entrypoint: string;
5
+ files: string[];
6
+ }
7
+ export interface CapabilitySkillManifestV1 {
8
+ schemaVersion: "spotlight.skill-manifest/1";
9
+ skills: CapabilitySkillManifestEntryV1[];
10
+ }
11
+ export declare function buildSkillManifestV1(skills: CanonicalSkillInputV1[]): {
12
+ manifest: CapabilitySkillManifestV1;
13
+ bytes: Uint8Array<ArrayBufferLike>;
14
+ digest: string;
15
+ };
16
+ //# sourceMappingURL=skillManifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skillManifest.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/skillManifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,4BAA4B,CAAC;IAC5C,MAAM,EAAE,8BAA8B,EAAE,CAAC;CAC1C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,EAAE;cAeP,yBAAyB;;;EAIrF"}
@@ -0,0 +1,22 @@
1
+ import { createHash } from "node:crypto";
2
+ import { canonicalizeJson, compareUtf16 } from "./canonicalJson.js";
3
+ export function buildSkillManifestV1(skills) {
4
+ const manifest = {
5
+ schemaVersion: "spotlight.skill-manifest/1",
6
+ skills: skills
7
+ .map((skill) => ({
8
+ name: skill.name,
9
+ entrypoint: `skills/${skill.name}/SKILL.md`,
10
+ files: skill.files
11
+ .map((file) => `skills/${skill.name}/${file.relativePath}`)
12
+ .sort(compareUtf16),
13
+ }))
14
+ .sort((left, right) => compareUtf16(left.name, right.name)),
15
+ };
16
+ const bytes = canonicalizeJson(manifest);
17
+ return {
18
+ manifest: JSON.parse(new TextDecoder().decode(bytes)),
19
+ bytes,
20
+ digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}`,
21
+ };
22
+ }
@@ -10,4 +10,5 @@ export { CAPABILITY_ARTIFACT_ERROR_CODES, CapabilityArtifactError, type Capabili
10
10
  export type { CanonicalSkillFileInputV1, CanonicalSkillInputV1, CapabilityArtifactInputV1, CapabilityFileManifestEntryV1, CapabilityFileManifestV1, CapabilityPayloadFileV1, } from "./capabilities/capabilityArtifactTypes.js";
11
11
  export { canonicalizeJson, compareUtf16, type CanonicalJsonValue, } from "./capabilities/canonicalJson.js";
12
12
  export { buildToolManifestV1, type BuiltToolManifestV1, type ToolManifestV1, } from "./capabilities/toolManifest.js";
13
+ export { buildSkillManifestV1, type CapabilitySkillManifestEntryV1, type CapabilitySkillManifestV1, } from "./capabilities/skillManifest.js";
13
14
  //# 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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KAAK,yBAAyB,GAC/B,MAAM,iCAAiC,CAAC"}
@@ -9,3 +9,4 @@ export { buildCapabilityFileMapV1, computeArtifactDigestV1, } from "./capabiliti
9
9
  export { CAPABILITY_ARTIFACT_ERROR_CODES, CapabilityArtifactError, } from "./capabilities/capabilityArtifactError.js";
10
10
  export { canonicalizeJson, compareUtf16, } from "./capabilities/canonicalJson.js";
11
11
  export { buildToolManifestV1, } from "./capabilities/toolManifest.js";
12
+ export { buildSkillManifestV1, } from "./capabilities/skillManifest.js";
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=publishCapabilitiesCli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishCapabilitiesCli.d.ts","sourceRoot":"","sources":["../../src/node/publishCapabilitiesCli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises";
3
+ import { resolve } from "node:path";
4
+ function argument(name) {
5
+ const index = process.argv.indexOf(`--${name}`);
6
+ const value = index >= 0 ? process.argv[index + 1] : undefined;
7
+ if (!value)
8
+ throw new Error(`Missing --${name}`);
9
+ return value;
10
+ }
11
+ async function main() {
12
+ const endpoint = argument("endpoint").replace(/\/$/, "");
13
+ const info = JSON.parse(await readFile(resolve(argument("build-info")), "utf8"));
14
+ const archive = await readFile(resolve(argument("artifact")));
15
+ const apiKey = process.env.SPOTLIGHT_API_KEY;
16
+ const response = await fetch(`${endpoint}/v1/capability-artifacts/${encodeURIComponent(info.artifactDigest)}/published`, {
17
+ method: "PUT",
18
+ headers: {
19
+ "Content-Type": "application/gzip",
20
+ ...(apiKey ? { "X-Spotlight-Api-Key": apiKey } : {}),
21
+ "X-Spotlight-Project-Id": info.projectId,
22
+ "X-Spotlight-Frontend-Build-Id": info.frontendBuildId,
23
+ "X-Spotlight-Manifest-Digest": info.manifestDigest,
24
+ "X-Spotlight-Skill-Manifest-Digest": info.skillManifestDigest,
25
+ "X-Spotlight-Tool-Manifest-Digest": info.toolManifestDigest,
26
+ },
27
+ body: archive,
28
+ });
29
+ if (!response.ok)
30
+ throw new Error(`Artifact publish failed (${response.status}): ${await response.text()}`);
31
+ process.stdout.write(`${await response.text()}\n`);
32
+ }
33
+ main().catch((error) => {
34
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
35
+ process.exitCode = 1;
36
+ });
@@ -0,0 +1,39 @@
1
+ import type { FrontendToolDescriptorV1, HostActionFenceV2 } from "@inupedia/spotlight-protocol";
2
+ export interface FrontendToolHandlerContextV1 {
3
+ projectId: string;
4
+ sessionId: string;
5
+ callId: string;
6
+ attempt: number;
7
+ fence: Readonly<HostActionFenceV2>;
8
+ idempotencyKey?: string;
9
+ signal: AbortSignal;
10
+ }
11
+ export interface FrontendToolDefinitionV1<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> extends FrontendToolDescriptorV1 {
12
+ execute: (input: TInput, context: FrontendToolHandlerContextV1) => TOutput | Promise<TOutput>;
13
+ }
14
+ /** Heterogeneous project registry erases handler generics only at the collection boundary. */
15
+ export type AnyFrontendToolDefinitionV1 = FrontendToolDefinitionV1<any, any>;
16
+ export interface SpotlightProjectV1 {
17
+ readonly projectId: string;
18
+ readonly skillRoots?: readonly string[];
19
+ readonly tools: readonly AnyFrontendToolDefinitionV1[];
20
+ }
21
+ export declare function defineFrontendTool<TInput extends Record<string, unknown>, TOutput = unknown>(definition: FrontendToolDefinitionV1<TInput, TOutput>): FrontendToolDefinitionV1<TInput, TOutput>;
22
+ export declare function defineSpotlightProject(input: {
23
+ projectId: string;
24
+ skillRoots?: readonly string[];
25
+ tools: readonly AnyFrontendToolDefinitionV1[];
26
+ }): SpotlightProjectV1;
27
+ export declare function projectToolDescriptors(project: Pick<SpotlightProjectV1, "tools">): FrontendToolDescriptorV1[];
28
+ export interface FrontendToolRegistryV1 {
29
+ readonly projectId: string;
30
+ get(name: string, version: string): AnyFrontendToolDefinitionV1 | undefined;
31
+ setLive(name: string, version: string, live: boolean): void;
32
+ liveTools(): Array<{
33
+ name: string;
34
+ version: string;
35
+ }>;
36
+ descriptors(): FrontendToolDescriptorV1[];
37
+ }
38
+ export declare function createFrontendToolRegistry(project: SpotlightProjectV1): FrontendToolRegistryV1;
39
+ //# sourceMappingURL=frontendTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontendTool.d.ts","sourceRoot":"","sources":["../../src/tools/frontendTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB,CACvC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,GAAG,OAAO,CACjB,SAAQ,wBAAwB;IAChC,OAAO,EAAE,CACP,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,4BAA4B,KAClC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,8FAA8F;AAC9F,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAE7E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,2BAA2B,EAAE,CAAC;CACxD;AAED,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,OAAO,GAAG,OAAO,EACjB,UAAU,EAAE,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAKlG;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,KAAK,EAAE,SAAS,2BAA2B,EAAE,CAAC;CAC/C,GAAG,kBAAkB,CAgBrB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,GACzC,wBAAwB,EAAE,CAI5B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,2BAA2B,GAAG,SAAS,CAAC;IAC5E,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5D,SAAS,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,WAAW,IAAI,wBAAwB,EAAE,CAAC;CAC3C;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,kBAAkB,GAAG,sBAAsB,CAqB9F"}
@@ -0,0 +1,51 @@
1
+ export function defineFrontendTool(definition) {
2
+ if (typeof definition.execute !== "function") {
3
+ throw new TypeError("Frontend Tool execute must be a function.");
4
+ }
5
+ return Object.freeze({ ...definition });
6
+ }
7
+ export function defineSpotlightProject(input) {
8
+ const projectId = input.projectId.trim();
9
+ if (!projectId)
10
+ throw new TypeError("Spotlight projectId must be non-empty.");
11
+ const identities = new Set();
12
+ for (const tool of input.tools) {
13
+ const identity = `${tool.name}@${tool.version}`;
14
+ if (identities.has(identity))
15
+ throw new TypeError(`Duplicate Frontend Tool: ${identity}`);
16
+ identities.add(identity);
17
+ }
18
+ return Object.freeze({
19
+ projectId,
20
+ ...(input.skillRoots
21
+ ? { skillRoots: Object.freeze([...input.skillRoots]) }
22
+ : {}),
23
+ tools: Object.freeze([...input.tools]),
24
+ });
25
+ }
26
+ export function projectToolDescriptors(project) {
27
+ return project.tools.map(({ execute: _execute, ...descriptor }) => JSON.parse(JSON.stringify(descriptor)));
28
+ }
29
+ export function createFrontendToolRegistry(project) {
30
+ const definitions = new Map(project.tools.map((tool) => [`${tool.name}@${tool.version}`, tool]));
31
+ const live = new Set(definitions.keys());
32
+ const key = (name, version) => `${name}@${version}`;
33
+ return Object.freeze({
34
+ projectId: project.projectId,
35
+ get: (name, version) => definitions.get(key(name, version)),
36
+ setLive(name, version, value) {
37
+ const identity = key(name, version);
38
+ if (!definitions.has(identity))
39
+ throw new TypeError(`Unknown Frontend Tool: ${identity}`);
40
+ if (value)
41
+ live.add(identity);
42
+ else
43
+ live.delete(identity);
44
+ },
45
+ liveTools: () => [...live].sort().map((identity) => {
46
+ const tool = definitions.get(identity);
47
+ return { name: tool.name, version: tool.version };
48
+ }),
49
+ descriptors: () => projectToolDescriptors(project),
50
+ });
51
+ }
@@ -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;AAyFnC,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,CA6FzC"}
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"}
@@ -39,6 +39,28 @@ function validateProject(value) {
39
39
  tools: tools,
40
40
  };
41
41
  }
42
+ function safeToolDescriptors(tools) {
43
+ return tools.map((tool, index) => {
44
+ if (isProxy(tool)) {
45
+ throw new CapabilityArtifactError("ARTIFACT_JSON_UNSUPPORTED_VALUE", `Tool descriptor ${index} must not be a Proxy`);
46
+ }
47
+ if (tool === null || typeof tool !== "object" || Array.isArray(tool)) {
48
+ invalidInput(`Tool descriptor ${index} must be a plain object`);
49
+ }
50
+ const result = {};
51
+ for (const key of Reflect.ownKeys(tool)) {
52
+ if (typeof key !== "string")
53
+ invalidInput(`Tool descriptor ${index} contains a symbol field`);
54
+ const descriptor = Object.getOwnPropertyDescriptor(tool, key);
55
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
56
+ throw new CapabilityArtifactError("ARTIFACT_JSON_UNSUPPORTED_VALUE", `Tool descriptor ${index}.${key} must be an enumerable data property`);
57
+ }
58
+ if (key !== "execute")
59
+ result[key] = descriptor.value;
60
+ }
61
+ return result;
62
+ });
63
+ }
42
64
  function throwDiagnostic(diagnostic) {
43
65
  const message = "message" in diagnostic
44
66
  ? diagnostic.message
@@ -68,7 +90,7 @@ function freezeDiagnostic(diagnostic) {
68
90
  }
69
91
  export async function buildViteCapabilitiesV1(input) {
70
92
  const project = validateProject(input.project);
71
- const toolManifest = buildToolManifestV1(project.tools);
93
+ const toolManifest = buildToolManifestV1(safeToolDescriptors(project.tools));
72
94
  const frontendBuildId = input.options?.frontendBuildId;
73
95
  if (input.command === "build" &&
74
96
  (frontendBuildId === undefined || frontendBuildId.trim().length === 0)) {
@@ -129,6 +151,7 @@ export async function buildViteCapabilitiesV1(input) {
129
151
  artifactVersion: artifact.artifactVersion,
130
152
  artifactDigest: artifact.artifactDigest,
131
153
  manifestDigest: artifact.manifestDigest,
154
+ skillManifestDigest: artifact.skillManifestDigest,
132
155
  toolManifestDigest: artifact.toolManifestDigest,
133
156
  byteLength: artifact.byteLength,
134
157
  });
@@ -1,9 +1,10 @@
1
1
  import type { FrontendToolDescriptorV1 } from "@inupedia/spotlight-protocol";
2
+ import type { FrontendToolDefinitionV1 } from "../tools/frontendTool.js";
2
3
  import type { SkillRootInput, SkillScanDiagnostic } from "../node/capabilities/skillScanner.js";
3
4
  import type { AgentSkillDiagnostic } from "../node/capabilities/skillValidator.js";
4
5
  export interface SpotlightCapabilityProjectBuildV1 {
5
6
  projectId: string;
6
- tools: readonly FrontendToolDescriptorV1[];
7
+ tools: readonly (FrontendToolDescriptorV1 | FrontendToolDefinitionV1)[];
7
8
  }
8
9
  export interface SpotlightCapabilitiesOptionsV1 {
9
10
  skillRoots?: readonly SkillRootInput[];
@@ -17,6 +18,7 @@ export interface CapabilityBuildInfoV1 {
17
18
  artifactVersion: "spotlight.capability-artifact/1";
18
19
  artifactDigest: string;
19
20
  manifestDigest: string;
21
+ skillManifestDigest: string;
20
22
  toolManifestDigest: string;
21
23
  byteLength: number;
22
24
  }
@@ -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;AAE7E,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,wBAAwB,EAAE,CAAC;CAC5C;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,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,6BAA6B;IAC5C,SAAS,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
+ {"version":3,"file":"capabilityBuildTypes.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuildTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,C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AK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AAuB9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CAoKR"}
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"}
@@ -160,6 +160,11 @@ export function spotlightCapabilities(project, options) {
160
160
  fileName: "capability-build-info.json",
161
161
  source: `${current.virtualModule.canonicalBuildInfoJson}\n`,
162
162
  });
163
+ this.emitFile({
164
+ type: "asset",
165
+ fileName: `capability-artifacts/${current.result.buildInfo.artifactDigest}.tar.gz`,
166
+ source: current.result.archive,
167
+ });
163
168
  },
164
169
  };
165
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inupedia/spotlight-client",
3
- "version": "0.2.14",
3
+ "version": "0.3.0",
4
4
  "description": "HTTP/SSE helpers and host tool bridge for Inupedia Spotlight (monorepo workspace package)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,6 +28,9 @@
28
28
  },
29
29
  "main": "./dist/index.js",
30
30
  "types": "./dist/index.d.ts",
31
+ "bin": {
32
+ "spotlight-capabilities": "./dist/node/publishCapabilitiesCli.js"
33
+ },
31
34
  "publishConfig": {
32
35
  "access": "public"
33
36
  },
@@ -43,7 +46,7 @@
43
46
  "fflate": "0.8.3",
44
47
  "magic-string": "^0.30.21",
45
48
  "yaml": "^2.8.4",
46
- "@inupedia/spotlight-protocol": "0.2.14"
49
+ "@inupedia/spotlight-protocol": "0.3.0"
47
50
  },
48
51
  "peerDependencies": {
49
52
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"