@inupedia/spotlight-client 0.2.12 → 0.2.14

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 (55) hide show
  1. package/dist/node/capabilities/canonicalJson.d.ts +7 -0
  2. package/dist/node/capabilities/canonicalJson.d.ts.map +1 -0
  3. package/dist/node/capabilities/canonicalJson.js +122 -0
  4. package/dist/node/capabilities/capabilityArtifact.d.ts +13 -0
  5. package/dist/node/capabilities/capabilityArtifact.d.ts.map +1 -0
  6. package/dist/node/capabilities/capabilityArtifact.js +31 -0
  7. package/dist/node/capabilities/capabilityArtifactError.d.ts +7 -0
  8. package/dist/node/capabilities/capabilityArtifactError.d.ts.map +1 -0
  9. package/dist/node/capabilities/capabilityArtifactError.js +19 -0
  10. package/dist/node/capabilities/capabilityArtifactTypes.d.ts +32 -0
  11. package/dist/node/capabilities/capabilityArtifactTypes.d.ts.map +1 -0
  12. package/dist/node/capabilities/capabilityArtifactTypes.js +1 -0
  13. package/dist/node/capabilities/capabilityFileMap.d.ts +17 -0
  14. package/dist/node/capabilities/capabilityFileMap.d.ts.map +1 -0
  15. package/dist/node/capabilities/capabilityFileMap.js +235 -0
  16. package/dist/node/capabilities/deterministicGzip.d.ts +2 -0
  17. package/dist/node/capabilities/deterministicGzip.d.ts.map +1 -0
  18. package/dist/node/capabilities/deterministicGzip.js +51 -0
  19. package/dist/node/capabilities/deterministicTar.d.ts +6 -0
  20. package/dist/node/capabilities/deterministicTar.d.ts.map +1 -0
  21. package/dist/node/capabilities/deterministicTar.js +137 -0
  22. package/dist/node/capabilities/skillDirectoryLoader.d.ts +24 -0
  23. package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +1 -0
  24. package/dist/node/capabilities/skillDirectoryLoader.js +308 -0
  25. package/dist/node/capabilities/skillFileValidator.d.ts +8 -0
  26. package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
  27. package/dist/node/capabilities/skillFileValidator.js +46 -26
  28. package/dist/node/capabilities/toolManifest.d.ts +12 -0
  29. package/dist/node/capabilities/toolManifest.d.ts.map +1 -0
  30. package/dist/node/capabilities/toolManifest.js +111 -0
  31. package/dist/node/index.d.ts +7 -0
  32. package/dist/node/index.d.ts.map +1 -1
  33. package/dist/node/index.js +6 -0
  34. package/dist/vite/capabilityBuild.d.ts +9 -0
  35. package/dist/vite/capabilityBuild.d.ts.map +1 -0
  36. package/dist/vite/capabilityBuild.js +141 -0
  37. package/dist/vite/capabilityBuildTypes.d.ts +29 -0
  38. package/dist/vite/capabilityBuildTypes.d.ts.map +1 -0
  39. package/dist/vite/capabilityBuildTypes.js +1 -0
  40. package/dist/vite/capabilityDevMiddleware.d.ts +5 -0
  41. package/dist/vite/capabilityDevMiddleware.d.ts.map +1 -0
  42. package/dist/vite/capabilityDevMiddleware.js +40 -0
  43. package/dist/vite/capabilityVirtualModule.d.ts +11 -0
  44. package/dist/vite/capabilityVirtualModule.d.ts.map +1 -0
  45. package/dist/vite/capabilityVirtualModule.js +43 -0
  46. package/dist/vite/capabilityVirtualModuleTypes.d.ts +12 -0
  47. package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +1 -0
  48. package/dist/vite/capabilityVirtualModuleTypes.js +1 -0
  49. package/dist/vite/index.d.ts +4 -0
  50. package/dist/vite/index.d.ts.map +1 -1
  51. package/dist/vite/index.js +3 -0
  52. package/dist/vite/spotlightCapabilities.d.ts +4 -0
  53. package/dist/vite/spotlightCapabilities.d.ts.map +1 -0
  54. package/dist/vite/spotlightCapabilities.js +165 -0
  55. package/package.json +8 -6
@@ -0,0 +1,7 @@
1
+ export type CanonicalJsonValue = null | boolean | number | string | CanonicalJsonValue[] | {
2
+ [key: string]: CanonicalJsonValue;
3
+ };
4
+ export declare function compareUtf16(left: string, right: string): number;
5
+ export declare function containsLoneSurrogate(value: string): boolean;
6
+ export declare function canonicalizeJson(value: unknown): Uint8Array;
7
+ //# sourceMappingURL=canonicalJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalJson.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/canonicalJson.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,kBAAkB,GAC1B,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,kBAAkB,EAAE,GACpB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAA;CAAE,CAAC;AAI1C,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAa5D;AAkJD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAW3D"}
@@ -0,0 +1,122 @@
1
+ import canonicalize from "canonicalize";
2
+ import { isProxy } from "node:util/types";
3
+ import { CapabilityArtifactError } from "./capabilityArtifactError.js";
4
+ const textEncoder = new TextEncoder();
5
+ export function compareUtf16(left, right) {
6
+ if (left === right)
7
+ return 0;
8
+ return left < right ? -1 : 1;
9
+ }
10
+ export function containsLoneSurrogate(value) {
11
+ for (let index = 0; index < value.length; index += 1) {
12
+ const code = value.charCodeAt(index);
13
+ if (code >= 0xd800 && code <= 0xdbff) {
14
+ if (index + 1 >= value.length)
15
+ return true;
16
+ const next = value.charCodeAt(index + 1);
17
+ if (next < 0xdc00 || next > 0xdfff)
18
+ return true;
19
+ index += 1;
20
+ continue;
21
+ }
22
+ if (code >= 0xdc00 && code <= 0xdfff)
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+ function fail(code, path, reason) {
28
+ throw new CapabilityArtifactError(code, `${path}: ${reason}`);
29
+ }
30
+ function validateString(value, path) {
31
+ if (containsLoneSurrogate(value)) {
32
+ fail("ARTIFACT_JSON_NOT_IJSON", path, "contains a lone surrogate");
33
+ }
34
+ }
35
+ function validateArray(value, path, stack) {
36
+ const ownKeys = Reflect.ownKeys(value);
37
+ const indexedKeys = [];
38
+ for (const key of ownKeys) {
39
+ if (key === "length")
40
+ continue;
41
+ const index = typeof key === "string" ? Number(key) : Number.NaN;
42
+ if (typeof key !== "string" ||
43
+ !/^(?:0|[1-9]\d*)$/.test(key) ||
44
+ !Number.isInteger(index) ||
45
+ index < 0 ||
46
+ index > 0xfffffffe ||
47
+ String(index) !== key) {
48
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "array contains a non-index property");
49
+ }
50
+ indexedKeys.push(key);
51
+ }
52
+ if (indexedKeys.length !== value.length) {
53
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "sparse array entries are not supported");
54
+ }
55
+ for (const key of indexedKeys) {
56
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
57
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
58
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", `${path}[${key}]`, "accessor and non-enumerable array entries are not supported");
59
+ }
60
+ validateJsonValue(descriptor.value, `${path}[${key}]`, stack);
61
+ }
62
+ }
63
+ function validateObject(value, path, stack) {
64
+ const prototype = Object.getPrototypeOf(value);
65
+ if (prototype !== Object.prototype && prototype !== null) {
66
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "only plain JSON objects are supported");
67
+ }
68
+ for (const key of Reflect.ownKeys(value)) {
69
+ if (typeof key !== "string") {
70
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "symbol-keyed properties are not supported");
71
+ }
72
+ validateString(key, `${path} property name`);
73
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
74
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
75
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", `${path}.${key}`, "accessor and non-enumerable properties are not supported");
76
+ }
77
+ validateJsonValue(descriptor.value, `${path}.${key}`, stack);
78
+ }
79
+ }
80
+ function validateJsonValue(value, path, stack) {
81
+ if (value === null || typeof value === "boolean")
82
+ return;
83
+ if (typeof value === "string") {
84
+ validateString(value, path);
85
+ return;
86
+ }
87
+ if (typeof value === "number") {
88
+ if (!Number.isFinite(value)) {
89
+ fail("ARTIFACT_JSON_NOT_IJSON", path, "number must be finite");
90
+ }
91
+ return;
92
+ }
93
+ if (typeof value !== "object") {
94
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, `unsupported value type ${typeof value}`);
95
+ }
96
+ if (isProxy(value)) {
97
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "Proxy values are not supported");
98
+ }
99
+ if (stack.has(value)) {
100
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", path, "cyclic value graph");
101
+ }
102
+ stack.add(value);
103
+ try {
104
+ if (Array.isArray(value)) {
105
+ validateArray(value, path, stack);
106
+ }
107
+ else {
108
+ validateObject(value, path, stack);
109
+ }
110
+ }
111
+ finally {
112
+ stack.delete(value);
113
+ }
114
+ }
115
+ export function canonicalizeJson(value) {
116
+ validateJsonValue(value, "$", new WeakSet());
117
+ const serialized = canonicalize(value);
118
+ if (serialized === undefined) {
119
+ fail("ARTIFACT_JSON_UNSUPPORTED_VALUE", "$", "canonicalizer returned no JSON output");
120
+ }
121
+ return textEncoder.encode(serialized);
122
+ }
@@ -0,0 +1,13 @@
1
+ import type { CapabilityArtifactInputV1 } from "./capabilityArtifactTypes.js";
2
+ export interface CapabilityArtifactBuildV1 {
3
+ artifactVersion: "spotlight.capability-artifact/1";
4
+ artifactDigest: string;
5
+ manifestDigest: string;
6
+ toolManifestDigest: string;
7
+ byteLength: number;
8
+ archive: Uint8Array;
9
+ manifestBytes: Uint8Array;
10
+ toolManifestBytes: Uint8Array;
11
+ }
12
+ export declare function buildCapabilityArtifactV1(input: CapabilityArtifactInputV1): CapabilityArtifactBuildV1;
13
+ //# sourceMappingURL=capabilityArtifact.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,31 @@
1
+ import { buildCapabilityFileMapV1, computeArtifactDigestV1, } from "./capabilityFileMap.js";
2
+ import { encodeDeterministicGzipV1 } from "./deterministicGzip.js";
3
+ import { encodeDeterministicUstarV1 } from "./deterministicTar.js";
4
+ import { buildToolManifestV1 } from "./toolManifest.js";
5
+ export function buildCapabilityArtifactV1(input) {
6
+ const toolManifest = buildToolManifestV1(input.tools);
7
+ const fileMap = buildCapabilityFileMapV1({
8
+ skills: input.skills,
9
+ toolManifestBytes: toolManifest.bytes,
10
+ });
11
+ const artifactDigest = computeArtifactDigestV1({
12
+ manifestDigest: fileMap.manifestDigest,
13
+ toolManifestDigest: toolManifest.digest,
14
+ payloads: fileMap.payloads,
15
+ });
16
+ const tar = encodeDeterministicUstarV1([
17
+ { path: "manifest.json", bytes: fileMap.manifestBytes },
18
+ ...fileMap.payloads.map(({ path, bytes }) => ({ path, bytes })),
19
+ ]);
20
+ const archive = encodeDeterministicGzipV1(tar);
21
+ return {
22
+ artifactVersion: "spotlight.capability-artifact/1",
23
+ artifactDigest,
24
+ manifestDigest: fileMap.manifestDigest,
25
+ toolManifestDigest: toolManifest.digest,
26
+ byteLength: archive.byteLength,
27
+ archive,
28
+ manifestBytes: Uint8Array.from(fileMap.manifestBytes),
29
+ toolManifestBytes: Uint8Array.from(toolManifest.bytes),
30
+ };
31
+ }
@@ -0,0 +1,7 @@
1
+ export declare const CAPABILITY_ARTIFACT_ERROR_CODES: readonly ["ARTIFACT_JSON_NOT_IJSON", "ARTIFACT_JSON_UNSUPPORTED_VALUE", "ARTIFACT_INPUT_INVALID", "ARTIFACT_TOOL_DUPLICATE", "ARTIFACT_TOOL_INVALID", "ARTIFACT_PATH_INVALID", "ARTIFACT_PATH_DUPLICATE", "ARTIFACT_PATH_USTAR_UNREPRESENTABLE", "ARTIFACT_SIZE_OVERFLOW"];
2
+ export type CapabilityArtifactErrorCode = (typeof CAPABILITY_ARTIFACT_ERROR_CODES)[number];
3
+ export declare class CapabilityArtifactError extends Error {
4
+ readonly code: CapabilityArtifactErrorCode;
5
+ constructor(code: CapabilityArtifactErrorCode, message: string);
6
+ }
7
+ //# sourceMappingURL=capabilityArtifactError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityArtifactError.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityArtifactError.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,4QAUlC,CAAC;AAEX,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,+BAA+B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;gBAE/B,IAAI,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM;CAK/D"}
@@ -0,0 +1,19 @@
1
+ export const CAPABILITY_ARTIFACT_ERROR_CODES = [
2
+ "ARTIFACT_JSON_NOT_IJSON",
3
+ "ARTIFACT_JSON_UNSUPPORTED_VALUE",
4
+ "ARTIFACT_INPUT_INVALID",
5
+ "ARTIFACT_TOOL_DUPLICATE",
6
+ "ARTIFACT_TOOL_INVALID",
7
+ "ARTIFACT_PATH_INVALID",
8
+ "ARTIFACT_PATH_DUPLICATE",
9
+ "ARTIFACT_PATH_USTAR_UNREPRESENTABLE",
10
+ "ARTIFACT_SIZE_OVERFLOW",
11
+ ];
12
+ export class CapabilityArtifactError extends Error {
13
+ code;
14
+ constructor(code, message) {
15
+ super(message);
16
+ this.name = "CapabilityArtifactError";
17
+ this.code = code;
18
+ }
19
+ }
@@ -0,0 +1,32 @@
1
+ import type { FrontendToolDescriptorV1 } from "@inupedia/spotlight-protocol";
2
+ export interface CanonicalSkillFileInputV1 {
3
+ relativePath: string;
4
+ bytes: Uint8Array;
5
+ mediaType?: string;
6
+ }
7
+ export interface CanonicalSkillInputV1 {
8
+ name: string;
9
+ files: CanonicalSkillFileInputV1[];
10
+ }
11
+ export interface CapabilityArtifactInputV1 {
12
+ skills: CanonicalSkillInputV1[];
13
+ tools: FrontendToolDescriptorV1[];
14
+ }
15
+ export interface CapabilityPayloadFileV1 {
16
+ path: string;
17
+ bytes: Uint8Array;
18
+ sha256: string;
19
+ byteLength: number;
20
+ mediaType: string;
21
+ }
22
+ export interface CapabilityFileManifestEntryV1 {
23
+ path: string;
24
+ sha256: string;
25
+ byteLength: number;
26
+ mediaType: string;
27
+ }
28
+ export interface CapabilityFileManifestV1 {
29
+ schemaVersion: "spotlight.capability-manifest/1";
30
+ files: CapabilityFileManifestEntryV1[];
31
+ }
32
+ //# sourceMappingURL=capabilityArtifactTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityArtifactTypes.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/capabilityArtifactTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAE7E,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,yBAAyB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,KAAK,EAAE,wBAAwB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,iCAAiC,CAAC;IACjD,KAAK,EAAE,6BAA6B,EAAE,CAAC;CACxC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { CanonicalSkillInputV1, CapabilityFileManifestV1, CapabilityPayloadFileV1 } from "./capabilityArtifactTypes.js";
2
+ export interface BuiltCapabilityFileMapV1 {
3
+ payloads: CapabilityPayloadFileV1[];
4
+ manifest: CapabilityFileManifestV1;
5
+ manifestBytes: Uint8Array;
6
+ manifestDigest: string;
7
+ }
8
+ export declare function buildCapabilityFileMapV1(input: {
9
+ skills: CanonicalSkillInputV1[];
10
+ toolManifestBytes: Uint8Array;
11
+ }): BuiltCapabilityFileMapV1;
12
+ export declare function computeArtifactDigestV1(input: {
13
+ manifestDigest: string;
14
+ toolManifestDigest: string;
15
+ payloads: Array<Pick<CapabilityPayloadFileV1, "path" | "sha256">>;
16
+ }): string;
17
+ //# sourceMappingURL=capabilityFileMap.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,235 @@
1
+ import { createHash } from "node:crypto";
2
+ import { isProxy } from "node:util/types";
3
+ import { canonicalizeJson, compareUtf16, containsLoneSurrogate, } from "./canonicalJson.js";
4
+ import { CapabilityArtifactError } from "./capabilityArtifactError.js";
5
+ const CANONICAL_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
6
+ const SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
7
+ const textEncoder = new TextEncoder();
8
+ const MEDIA_TYPES = {
9
+ ".md": "text/markdown; charset=utf-8",
10
+ ".txt": "text/plain; charset=utf-8",
11
+ ".json": "application/json",
12
+ ".yaml": "application/yaml",
13
+ ".yml": "application/yaml",
14
+ ".js": "text/javascript; charset=utf-8",
15
+ ".mjs": "text/javascript; charset=utf-8",
16
+ ".cjs": "text/javascript; charset=utf-8",
17
+ ".ts": "text/typescript; charset=utf-8",
18
+ ".tsx": "text/tsx; charset=utf-8",
19
+ ".css": "text/css; charset=utf-8",
20
+ ".html": "text/html; charset=utf-8",
21
+ ".svg": "image/svg+xml",
22
+ ".png": "image/png",
23
+ ".jpg": "image/jpeg",
24
+ ".jpeg": "image/jpeg",
25
+ ".webp": "image/webp",
26
+ ".gif": "image/gif",
27
+ ".pdf": "application/pdf",
28
+ ".mp4": "video/mp4",
29
+ ".webm": "video/webm",
30
+ ".wasm": "application/wasm",
31
+ };
32
+ function invalidInput(message) {
33
+ throw new CapabilityArtifactError("ARTIFACT_INPUT_INVALID", message);
34
+ }
35
+ function isCanonicalArrayIndex(key) {
36
+ if (!/^(?:0|[1-9]\d*)$/.test(key))
37
+ return false;
38
+ const index = Number(key);
39
+ return (Number.isInteger(index) &&
40
+ index >= 0 &&
41
+ index <= 0xfffffffe &&
42
+ String(index) === key);
43
+ }
44
+ function readDenseDataArray(value, label) {
45
+ if (isProxy(value))
46
+ invalidInput(`${label} must not be a Proxy`);
47
+ if (!Array.isArray(value))
48
+ invalidInput(`${label} must be an array`);
49
+ const keys = [];
50
+ for (const key of Reflect.ownKeys(value)) {
51
+ if (key === "length")
52
+ continue;
53
+ if (typeof key !== "string" || !isCanonicalArrayIndex(key)) {
54
+ invalidInput(`${label} contains a non-index property`);
55
+ }
56
+ keys.push(key);
57
+ }
58
+ if (keys.length !== value.length)
59
+ invalidInput(`${label} must be dense`);
60
+ keys.sort((left, right) => Number(left) - Number(right));
61
+ return keys.map((key) => {
62
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
63
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
64
+ invalidInput(`${label}[${key}] must be an enumerable data property`);
65
+ }
66
+ return descriptor.value;
67
+ });
68
+ }
69
+ function readDataRecord(value, label, allowedFields) {
70
+ if (isProxy(value))
71
+ invalidInput(`${label} must not be a Proxy`);
72
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
73
+ invalidInput(`${label} must be a plain object`);
74
+ }
75
+ const prototype = Object.getPrototypeOf(value);
76
+ if (prototype !== Object.prototype && prototype !== null) {
77
+ invalidInput(`${label} must be a plain object`);
78
+ }
79
+ const record = {};
80
+ for (const key of Reflect.ownKeys(value)) {
81
+ if (typeof key !== "string" || !allowedFields.has(key)) {
82
+ invalidInput(`${label} contains an unknown field`);
83
+ }
84
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
85
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
86
+ invalidInput(`${label}.${key} must be an enumerable data property`);
87
+ }
88
+ record[key] = descriptor.value;
89
+ }
90
+ return record;
91
+ }
92
+ function sha256(bytes) {
93
+ return `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
94
+ }
95
+ function byteLength(value) {
96
+ return textEncoder.encode(value).byteLength;
97
+ }
98
+ function canRepresentUstarPath(path) {
99
+ if (byteLength(path) <= 100)
100
+ return true;
101
+ for (let index = path.lastIndexOf("/"); index > 0; index = path.lastIndexOf("/", index - 1)) {
102
+ const prefix = path.slice(0, index);
103
+ const name = path.slice(index + 1);
104
+ if (name.length > 0 && byteLength(prefix) <= 155 && byteLength(name) <= 100) {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ function validateSkillName(name) {
111
+ if (typeof name !== "string") {
112
+ invalidInput("Skill name must be a string");
113
+ }
114
+ if (!CANONICAL_SKILL_NAME.test(name) || name.length > 64) {
115
+ throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid canonical Skill name: ${name}`);
116
+ }
117
+ }
118
+ function validateRelativePath(relativePath) {
119
+ if (typeof relativePath !== "string") {
120
+ invalidInput("Skill relativePath must be a string");
121
+ }
122
+ if (relativePath.length === 0 ||
123
+ relativePath.startsWith("/") ||
124
+ /^[A-Za-z]:/.test(relativePath) ||
125
+ relativePath.includes("\\") ||
126
+ relativePath.includes("\0") ||
127
+ containsLoneSurrogate(relativePath) ||
128
+ relativePath.endsWith("/")) {
129
+ throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid Skill relative path: ${relativePath}`);
130
+ }
131
+ const segments = relativePath.split("/");
132
+ if (segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
133
+ throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid Skill relative path segment: ${relativePath}`);
134
+ }
135
+ }
136
+ function ensureUstarPath(path) {
137
+ if (!canRepresentUstarPath(path)) {
138
+ throw new CapabilityArtifactError("ARTIFACT_PATH_USTAR_UNREPRESENTABLE", `Path cannot be represented by POSIX USTAR: ${path}`);
139
+ }
140
+ }
141
+ function inferMediaType(path) {
142
+ const filename = path.slice(path.lastIndexOf("/") + 1);
143
+ const dot = filename.lastIndexOf(".");
144
+ const extension = dot >= 0 ? filename.slice(dot).toLowerCase() : "";
145
+ return MEDIA_TYPES[extension] ?? "application/octet-stream";
146
+ }
147
+ function createPayload(path, sourceBytes, mediaType) {
148
+ const bytes = Uint8Array.from(sourceBytes);
149
+ if (!Number.isSafeInteger(bytes.byteLength)) {
150
+ throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `Payload byte length exceeds safe integer range: ${path}`);
151
+ }
152
+ return {
153
+ path,
154
+ bytes,
155
+ sha256: sha256(bytes),
156
+ byteLength: bytes.byteLength,
157
+ mediaType,
158
+ };
159
+ }
160
+ function addPayload(payloads, seenPaths, payload) {
161
+ if (seenPaths.has(payload.path)) {
162
+ throw new CapabilityArtifactError("ARTIFACT_PATH_DUPLICATE", `Duplicate Artifact payload path: ${payload.path}`);
163
+ }
164
+ seenPaths.add(payload.path);
165
+ payloads.push(payload);
166
+ }
167
+ export function buildCapabilityFileMapV1(input) {
168
+ const root = readDataRecord(input, "Capability file-map input", new Set(["skills", "toolManifestBytes"]));
169
+ if (isProxy(root.toolManifestBytes) ||
170
+ !(root.toolManifestBytes instanceof Uint8Array)) {
171
+ invalidInput("toolManifestBytes must be a Uint8Array");
172
+ }
173
+ const skills = readDenseDataArray(root.skills, "skills");
174
+ const payloads = [];
175
+ const seenPaths = new Set();
176
+ addPayload(payloads, seenPaths, createPayload("tool-manifest.json", root.toolManifestBytes, "application/json"));
177
+ for (const [skillIndex, skillValue] of skills.entries()) {
178
+ const skill = readDataRecord(skillValue, `skills[${skillIndex}]`, new Set(["name", "files"]));
179
+ validateSkillName(skill.name);
180
+ const files = readDenseDataArray(skill.files, `skills[${skillIndex}].files`);
181
+ for (const [fileIndex, fileValue] of files.entries()) {
182
+ const file = readDataRecord(fileValue, `skills[${skillIndex}].files[${fileIndex}]`, new Set(["relativePath", "bytes", "mediaType"]));
183
+ validateRelativePath(file.relativePath);
184
+ if (isProxy(file.bytes) || !(file.bytes instanceof Uint8Array)) {
185
+ invalidInput(`skills[${skillIndex}].files[${fileIndex}].bytes must be a Uint8Array`);
186
+ }
187
+ if (file.mediaType !== undefined &&
188
+ (typeof file.mediaType !== "string" || file.mediaType.trim().length === 0)) {
189
+ invalidInput(`skills[${skillIndex}].files[${fileIndex}].mediaType must be a non-empty string`);
190
+ }
191
+ const path = `skills/${skill.name}/${file.relativePath}`;
192
+ ensureUstarPath(path);
193
+ addPayload(payloads, seenPaths, createPayload(path, file.bytes, typeof file.mediaType === "string"
194
+ ? file.mediaType
195
+ : inferMediaType(path)));
196
+ }
197
+ }
198
+ payloads.sort((left, right) => compareUtf16(left.path, right.path));
199
+ const candidate = {
200
+ schemaVersion: "spotlight.capability-manifest/1",
201
+ files: payloads.map(({ path, sha256: digest, byteLength: length, mediaType }) => ({
202
+ path,
203
+ sha256: digest,
204
+ byteLength: length,
205
+ mediaType,
206
+ })),
207
+ };
208
+ const manifestBytes = canonicalizeJson(candidate);
209
+ const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
210
+ return {
211
+ payloads,
212
+ manifest,
213
+ manifestBytes,
214
+ manifestDigest: sha256(manifestBytes),
215
+ };
216
+ }
217
+ export function computeArtifactDigestV1(input) {
218
+ if (!SHA256_DIGEST.test(input.manifestDigest) || !SHA256_DIGEST.test(input.toolManifestDigest)) {
219
+ throw new CapabilityArtifactError("ARTIFACT_JSON_NOT_IJSON", "Artifact preimage contains an invalid manifest digest");
220
+ }
221
+ const payloadDigests = input.payloads
222
+ .map(({ path, sha256: digest }) => {
223
+ if (!SHA256_DIGEST.test(digest)) {
224
+ throw new CapabilityArtifactError("ARTIFACT_JSON_NOT_IJSON", `Artifact preimage contains an invalid payload digest: ${path}`);
225
+ }
226
+ return { path, sha256: digest };
227
+ })
228
+ .sort((left, right) => compareUtf16(left.path, right.path));
229
+ return sha256(canonicalizeJson({
230
+ artifactVersion: "spotlight.capability-artifact/1",
231
+ manifestDigest: input.manifestDigest,
232
+ toolManifestDigest: input.toolManifestDigest,
233
+ payloadDigests,
234
+ }));
235
+ }
@@ -0,0 +1,2 @@
1
+ export declare function encodeDeterministicGzipV1(input: Uint8Array): Uint8Array;
2
+ //# sourceMappingURL=deterministicGzip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministicGzip.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicGzip.ts"],"names":[],"mappings":"AAuCA,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CA0BvE"}
@@ -0,0 +1,51 @@
1
+ import { deflateSync } from "fflate";
2
+ import { CapabilityArtifactError } from "./capabilityArtifactError.js";
3
+ const GZIP_HEADER = Uint8Array.from([
4
+ 0x1f,
5
+ 0x8b,
6
+ 8,
7
+ 0,
8
+ 0,
9
+ 0,
10
+ 0,
11
+ 0,
12
+ 2,
13
+ 255,
14
+ ]);
15
+ const GZIP_FOOTER_SIZE = 8;
16
+ const CRC32_TABLE = createCrc32Table();
17
+ function createCrc32Table() {
18
+ const table = new Uint32Array(256);
19
+ for (let value = 0; value < table.length; value += 1) {
20
+ let crc = value;
21
+ for (let bit = 0; bit < 8; bit += 1) {
22
+ crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
23
+ }
24
+ table[value] = crc >>> 0;
25
+ }
26
+ return table;
27
+ }
28
+ function crc32(bytes) {
29
+ let crc = 0xffffffff;
30
+ for (const byte of bytes) {
31
+ crc = (crc >>> 8) ^ (CRC32_TABLE[(crc ^ byte) & 0xff] ?? 0);
32
+ }
33
+ return (crc ^ 0xffffffff) >>> 0;
34
+ }
35
+ export function encodeDeterministicGzipV1(input) {
36
+ const compressed = Uint8Array.from(deflateSync(input, {
37
+ level: 9,
38
+ mem: 8,
39
+ }));
40
+ const totalLength = GZIP_HEADER.byteLength + compressed.byteLength + GZIP_FOOTER_SIZE;
41
+ if (!Number.isSafeInteger(totalLength)) {
42
+ throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", "gzip output exceeds the safe integer range");
43
+ }
44
+ const output = new Uint8Array(totalLength);
45
+ output.set(GZIP_HEADER, 0);
46
+ output.set(compressed, GZIP_HEADER.byteLength);
47
+ const footer = new DataView(output.buffer, output.byteOffset + output.byteLength - GZIP_FOOTER_SIZE, GZIP_FOOTER_SIZE);
48
+ footer.setUint32(0, crc32(input), true);
49
+ footer.setUint32(4, input.byteLength >>> 0, true);
50
+ return output;
51
+ }
@@ -0,0 +1,6 @@
1
+ export interface TarFileEntryV1 {
2
+ path: string;
3
+ bytes: Uint8Array;
4
+ }
5
+ export declare function encodeDeterministicUstarV1(files: TarFileEntryV1[]): Uint8Array;
6
+ //# sourceMappingURL=deterministicTar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministicTar.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicTar.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AAqKD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,CA2B9E"}