@inupedia/spotlight-client 0.2.13 → 0.2.15
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.
- package/dist/node/index.d.ts +0 -6
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +0 -5
- package/package.json +4 -6
- package/dist/node/capabilities/canonicalJson.d.ts +0 -7
- package/dist/node/capabilities/canonicalJson.d.ts.map +0 -1
- package/dist/node/capabilities/canonicalJson.js +0 -122
- package/dist/node/capabilities/capabilityArtifact.d.ts +0 -13
- package/dist/node/capabilities/capabilityArtifact.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifact.js +0 -31
- package/dist/node/capabilities/capabilityArtifactError.d.ts +0 -7
- package/dist/node/capabilities/capabilityArtifactError.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifactError.js +0 -19
- package/dist/node/capabilities/capabilityArtifactTypes.d.ts +0 -32
- package/dist/node/capabilities/capabilityArtifactTypes.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifactTypes.js +0 -1
- package/dist/node/capabilities/capabilityFileMap.d.ts +0 -17
- package/dist/node/capabilities/capabilityFileMap.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityFileMap.js +0 -235
- package/dist/node/capabilities/deterministicGzip.d.ts +0 -2
- package/dist/node/capabilities/deterministicGzip.d.ts.map +0 -1
- package/dist/node/capabilities/deterministicGzip.js +0 -51
- package/dist/node/capabilities/deterministicTar.d.ts +0 -6
- package/dist/node/capabilities/deterministicTar.d.ts.map +0 -1
- package/dist/node/capabilities/deterministicTar.js +0 -137
- package/dist/node/capabilities/toolManifest.d.ts +0 -12
- package/dist/node/capabilities/toolManifest.d.ts.map +0 -1
- package/dist/node/capabilities/toolManifest.js +0 -111
package/dist/node/index.d.ts
CHANGED
|
@@ -3,10 +3,4 @@ export { createNodeSkillScriptRunner } from "./skillScriptRunner.js";
|
|
|
3
3
|
export { DEFAULT_SKILL_ROOTS, scanProjectSkills, type ScanProjectSkillsOptions, type ScannedSkill, type SkillRootInput, type SkillScanDiagnostic, type SkillScanMode, type SkillScanResult, } from "./capabilities/skillScanner.js";
|
|
4
4
|
export { validateAgentSkillMarkdown, type AgentSkillDiagnostic, type AgentSkillDiagnosticCode, type AgentSkillDiagnosticSeverity, type AgentSkillValidationResult, type ValidatedAgentSkill, type ValidateAgentSkillMarkdownInput, } from "./capabilities/skillValidator.js";
|
|
5
5
|
export { validateScannedSkill, type ValidateScannedSkillInput, } from "./capabilities/skillFileValidator.js";
|
|
6
|
-
export { buildCapabilityArtifactV1, type CapabilityArtifactBuildV1, } from "./capabilities/capabilityArtifact.js";
|
|
7
|
-
export { buildCapabilityFileMapV1, computeArtifactDigestV1, type BuiltCapabilityFileMapV1, } from "./capabilities/capabilityFileMap.js";
|
|
8
|
-
export { CAPABILITY_ARTIFACT_ERROR_CODES, CapabilityArtifactError, type CapabilityArtifactErrorCode, } from "./capabilities/capabilityArtifactError.js";
|
|
9
|
-
export type { CanonicalSkillFileInputV1, CanonicalSkillInputV1, CapabilityArtifactInputV1, CapabilityFileManifestEntryV1, CapabilityFileManifestV1, CapabilityPayloadFileV1, } from "./capabilities/capabilityArtifactTypes.js";
|
|
10
|
-
export { canonicalizeJson, compareUtf16, type CanonicalJsonValue, } from "./capabilities/canonicalJson.js";
|
|
11
|
-
export { buildToolManifestV1, type BuiltToolManifestV1, type ToolManifestV1, } from "./capabilities/toolManifest.js";
|
|
12
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACrC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACrC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC"}
|
package/dist/node/index.js
CHANGED
|
@@ -3,8 +3,3 @@ export { createNodeSkillScriptRunner } from "./skillScriptRunner.js";
|
|
|
3
3
|
export { DEFAULT_SKILL_ROOTS, scanProjectSkills, } from "./capabilities/skillScanner.js";
|
|
4
4
|
export { validateAgentSkillMarkdown, } from "./capabilities/skillValidator.js";
|
|
5
5
|
export { validateScannedSkill, } from "./capabilities/skillFileValidator.js";
|
|
6
|
-
export { buildCapabilityArtifactV1, } from "./capabilities/capabilityArtifact.js";
|
|
7
|
-
export { buildCapabilityFileMapV1, computeArtifactDigestV1, } from "./capabilities/capabilityFileMap.js";
|
|
8
|
-
export { CAPABILITY_ARTIFACT_ERROR_CODES, CapabilityArtifactError, } from "./capabilities/capabilityArtifactError.js";
|
|
9
|
-
export { canonicalizeJson, compareUtf16, } from "./capabilities/canonicalJson.js";
|
|
10
|
-
export { buildToolManifestV1, } from "./capabilities/toolManifest.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inupedia/spotlight-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "HTTP/SSE helpers and host tool bridge for Inupedia Spotlight (monorepo workspace package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,11 +39,9 @@
|
|
|
39
39
|
"@babel/parser": "^7.28.5",
|
|
40
40
|
"@babel/traverse": "^7.28.5",
|
|
41
41
|
"@babel/types": "^7.28.5",
|
|
42
|
-
"canonicalize": "3.0.0",
|
|
43
|
-
"fflate": "0.8.3",
|
|
44
42
|
"magic-string": "^0.30.21",
|
|
45
43
|
"yaml": "^2.8.4",
|
|
46
|
-
"@inupedia/spotlight-protocol": "0.2.
|
|
44
|
+
"@inupedia/spotlight-protocol": "0.2.15"
|
|
47
45
|
},
|
|
48
46
|
"peerDependencies": {
|
|
49
47
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
@@ -57,8 +55,8 @@
|
|
|
57
55
|
"@types/babel__traverse": "^7.28.0",
|
|
58
56
|
"@types/node": "^24.10.1",
|
|
59
57
|
"typescript": "^5.9.3",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
58
|
+
"vitest": "^4.0.18",
|
|
59
|
+
"vite": "^7.3.1"
|
|
62
60
|
},
|
|
63
61
|
"scripts": {
|
|
64
62
|
"clean": "rm -rf dist",
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,235 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deterministicTar.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicTar.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AAqKD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,CA2B9E"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { compareUtf16, containsLoneSurrogate } from "./canonicalJson.js";
|
|
2
|
-
import { CapabilityArtifactError } from "./capabilityArtifactError.js";
|
|
3
|
-
const TAR_BLOCK_SIZE = 512;
|
|
4
|
-
const textEncoder = new TextEncoder();
|
|
5
|
-
function failInvalidPath(path) {
|
|
6
|
-
throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid USTAR file path: ${path}`);
|
|
7
|
-
}
|
|
8
|
-
function validateFilePath(path) {
|
|
9
|
-
if (path.length === 0 ||
|
|
10
|
-
path.startsWith("/") ||
|
|
11
|
-
/^[A-Za-z]:/.test(path) ||
|
|
12
|
-
path.includes("\\") ||
|
|
13
|
-
path.includes("\0") ||
|
|
14
|
-
containsLoneSurrogate(path) ||
|
|
15
|
-
path.endsWith("/")) {
|
|
16
|
-
failInvalidPath(path);
|
|
17
|
-
}
|
|
18
|
-
if (path.split("/").some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
19
|
-
failInvalidPath(path);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function byteLength(value) {
|
|
23
|
-
return textEncoder.encode(value).byteLength;
|
|
24
|
-
}
|
|
25
|
-
function splitUstarPath(path) {
|
|
26
|
-
if (byteLength(path) <= 100)
|
|
27
|
-
return { name: path, prefix: "" };
|
|
28
|
-
for (let index = path.lastIndexOf("/"); index > 0; index = path.lastIndexOf("/", index - 1)) {
|
|
29
|
-
const prefix = path.slice(0, index);
|
|
30
|
-
const name = path.slice(index + 1);
|
|
31
|
-
if (name.length > 0 && byteLength(prefix) <= 155 && byteLength(name) <= 100) {
|
|
32
|
-
return { name, prefix };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw new CapabilityArtifactError("ARTIFACT_PATH_USTAR_UNREPRESENTABLE", `Path cannot be represented by POSIX USTAR: ${path}`);
|
|
36
|
-
}
|
|
37
|
-
function writeAscii(block, offset, length, value) {
|
|
38
|
-
const bytes = textEncoder.encode(value);
|
|
39
|
-
if (bytes.byteLength > length) {
|
|
40
|
-
throw new CapabilityArtifactError("ARTIFACT_PATH_USTAR_UNREPRESENTABLE", `USTAR field exceeds ${length} bytes: ${value}`);
|
|
41
|
-
}
|
|
42
|
-
block.set(bytes, offset);
|
|
43
|
-
}
|
|
44
|
-
function writeOctal(block, offset, length, value) {
|
|
45
|
-
if (!Number.isSafeInteger(value) || value < 0) {
|
|
46
|
-
throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR numeric field is outside the safe integer range: ${value}`);
|
|
47
|
-
}
|
|
48
|
-
const octal = value.toString(8);
|
|
49
|
-
if (octal.length > length - 1) {
|
|
50
|
-
throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR numeric field exceeds ${length - 1} octal digits: ${value}`);
|
|
51
|
-
}
|
|
52
|
-
writeAscii(block, offset, length, `${octal.padStart(length - 1, "0")}\0`);
|
|
53
|
-
}
|
|
54
|
-
function writeChecksum(block, checksum) {
|
|
55
|
-
const octal = checksum.toString(8);
|
|
56
|
-
if (octal.length > 6) {
|
|
57
|
-
throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR checksum exceeds six octal digits: ${checksum}`);
|
|
58
|
-
}
|
|
59
|
-
writeAscii(block, 148, 8, `${octal.padStart(6, "0")}\0 `);
|
|
60
|
-
}
|
|
61
|
-
function createHeader(entry) {
|
|
62
|
-
const block = new Uint8Array(TAR_BLOCK_SIZE);
|
|
63
|
-
const { name, prefix } = splitUstarPath(entry.path);
|
|
64
|
-
writeAscii(block, 0, 100, name);
|
|
65
|
-
writeOctal(block, 100, 8, entry.type === "directory" ? 0o755 : 0o644);
|
|
66
|
-
writeOctal(block, 108, 8, 0);
|
|
67
|
-
writeOctal(block, 116, 8, 0);
|
|
68
|
-
writeOctal(block, 124, 12, entry.type === "directory" ? 0 : entry.bytes.byteLength);
|
|
69
|
-
writeOctal(block, 136, 12, 0);
|
|
70
|
-
block.fill(0x20, 148, 156);
|
|
71
|
-
block[156] = (entry.type === "directory" ? "5" : "0").charCodeAt(0);
|
|
72
|
-
writeAscii(block, 257, 6, "ustar\0");
|
|
73
|
-
writeAscii(block, 263, 2, "00");
|
|
74
|
-
writeOctal(block, 329, 8, 0);
|
|
75
|
-
writeOctal(block, 337, 8, 0);
|
|
76
|
-
writeAscii(block, 345, 155, prefix);
|
|
77
|
-
let checksum = 0;
|
|
78
|
-
for (const byte of block)
|
|
79
|
-
checksum += byte;
|
|
80
|
-
writeChecksum(block, checksum);
|
|
81
|
-
return block;
|
|
82
|
-
}
|
|
83
|
-
function collectEntries(files) {
|
|
84
|
-
const filePaths = new Set();
|
|
85
|
-
const directoryPaths = new Set();
|
|
86
|
-
const fileEntries = [];
|
|
87
|
-
for (const file of files) {
|
|
88
|
-
validateFilePath(file.path);
|
|
89
|
-
splitUstarPath(file.path);
|
|
90
|
-
if (filePaths.has(file.path)) {
|
|
91
|
-
throw new CapabilityArtifactError("ARTIFACT_PATH_DUPLICATE", `Duplicate USTAR file path: ${file.path}`);
|
|
92
|
-
}
|
|
93
|
-
filePaths.add(file.path);
|
|
94
|
-
fileEntries.push({ path: file.path, type: "file", bytes: file.bytes });
|
|
95
|
-
const segments = file.path.split("/");
|
|
96
|
-
for (let index = 1; index < segments.length; index += 1) {
|
|
97
|
-
const directory = `${segments.slice(0, index).join("/")}/`;
|
|
98
|
-
splitUstarPath(directory);
|
|
99
|
-
directoryPaths.add(directory);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
for (const directory of directoryPaths) {
|
|
103
|
-
if (filePaths.has(directory.slice(0, -1))) {
|
|
104
|
-
throw new CapabilityArtifactError("ARTIFACT_PATH_DUPLICATE", `USTAR path is both a file and directory: ${directory}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const entries = [
|
|
108
|
-
...[...directoryPaths].map((path) => ({ path, type: "directory" })),
|
|
109
|
-
...fileEntries,
|
|
110
|
-
];
|
|
111
|
-
entries.sort((left, right) => compareUtf16(left.path, right.path));
|
|
112
|
-
return entries;
|
|
113
|
-
}
|
|
114
|
-
export function encodeDeterministicUstarV1(files) {
|
|
115
|
-
const entries = collectEntries(files);
|
|
116
|
-
let totalLength = TAR_BLOCK_SIZE * 2;
|
|
117
|
-
for (const entry of entries) {
|
|
118
|
-
totalLength += TAR_BLOCK_SIZE;
|
|
119
|
-
if (entry.type === "file") {
|
|
120
|
-
totalLength += Math.ceil(entry.bytes.byteLength / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;
|
|
121
|
-
}
|
|
122
|
-
if (!Number.isSafeInteger(totalLength)) {
|
|
123
|
-
throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", "USTAR archive size exceeds the safe integer range");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const archive = new Uint8Array(totalLength);
|
|
127
|
-
let offset = 0;
|
|
128
|
-
for (const entry of entries) {
|
|
129
|
-
archive.set(createHeader(entry), offset);
|
|
130
|
-
offset += TAR_BLOCK_SIZE;
|
|
131
|
-
if (entry.type === "file") {
|
|
132
|
-
archive.set(entry.bytes, offset);
|
|
133
|
-
offset += Math.ceil(entry.bytes.byteLength / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return archive;
|
|
137
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { FrontendToolDescriptorV1 } from "@inupedia/spotlight-protocol";
|
|
2
|
-
export interface ToolManifestV1 {
|
|
3
|
-
schemaVersion: "spotlight.tool-manifest/1";
|
|
4
|
-
tools: FrontendToolDescriptorV1[];
|
|
5
|
-
}
|
|
6
|
-
export interface BuiltToolManifestV1 {
|
|
7
|
-
manifest: ToolManifestV1;
|
|
8
|
-
bytes: Uint8Array;
|
|
9
|
-
digest: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function buildToolManifestV1(tools: FrontendToolDescriptorV1[]): BuiltToolManifestV1;
|
|
12
|
-
//# sourceMappingURL=toolManifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toolManifest.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/toolManifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAK7E,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,2BAA2B,CAAC;IAC3C,KAAK,EAAE,wBAAwB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAwGD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,wBAAwB,EAAE,GAChC,mBAAmB,CAkCrB"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { isProxy } from "node:util/types";
|
|
3
|
-
import { canonicalizeJson, compareUtf16 } from "./canonicalJson.js";
|
|
4
|
-
import { CapabilityArtifactError } from "./capabilityArtifactError.js";
|
|
5
|
-
const TOOL_FIELDS = new Set([
|
|
6
|
-
"name",
|
|
7
|
-
"version",
|
|
8
|
-
"description",
|
|
9
|
-
"inputSchema",
|
|
10
|
-
"outputSchema",
|
|
11
|
-
"maxOutputBytes",
|
|
12
|
-
"sideEffect",
|
|
13
|
-
"replayPolicy",
|
|
14
|
-
"riskLevel",
|
|
15
|
-
"requiresConfirmation",
|
|
16
|
-
]);
|
|
17
|
-
const SIDE_EFFECTS = new Set(["none", "ui", "external"]);
|
|
18
|
-
const REPLAY_POLICIES = new Set(["safe", "idempotency-key", "never"]);
|
|
19
|
-
const RISK_LEVELS = new Set(["low", "medium", "high"]);
|
|
20
|
-
function sha256(bytes) {
|
|
21
|
-
return `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
22
|
-
}
|
|
23
|
-
function compareTools(left, right) {
|
|
24
|
-
return compareUtf16(left.name, right.name) || compareUtf16(left.version, right.version);
|
|
25
|
-
}
|
|
26
|
-
function invalidTool(message) {
|
|
27
|
-
throw new CapabilityArtifactError("ARTIFACT_TOOL_INVALID", message);
|
|
28
|
-
}
|
|
29
|
-
function isPlainObject(value) {
|
|
30
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const prototype = Object.getPrototypeOf(value);
|
|
34
|
-
return prototype === Object.prototype || prototype === null;
|
|
35
|
-
}
|
|
36
|
-
function validateToolDescriptor(value) {
|
|
37
|
-
canonicalizeJson(value);
|
|
38
|
-
if (!isPlainObject(value)) {
|
|
39
|
-
invalidTool("Tool descriptor must be a plain JSON object");
|
|
40
|
-
}
|
|
41
|
-
const unknownFields = Object.keys(value)
|
|
42
|
-
.filter((field) => !TOOL_FIELDS.has(field))
|
|
43
|
-
.sort(compareUtf16);
|
|
44
|
-
if (unknownFields.length > 0) {
|
|
45
|
-
invalidTool(`Unknown Tool descriptor fields: ${unknownFields.join(", ")}`);
|
|
46
|
-
}
|
|
47
|
-
const tool = value;
|
|
48
|
-
if (typeof tool.name !== "string" || tool.name.trim().length === 0) {
|
|
49
|
-
invalidTool("Tool name must be a non-empty string");
|
|
50
|
-
}
|
|
51
|
-
if (typeof tool.version !== "string" || tool.version.trim().length === 0) {
|
|
52
|
-
invalidTool(`Tool ${tool.name} version must be a non-empty string`);
|
|
53
|
-
}
|
|
54
|
-
if (typeof tool.description !== "string" ||
|
|
55
|
-
tool.description.trim().length === 0) {
|
|
56
|
-
invalidTool(`Tool ${tool.name} description must be a non-empty string`);
|
|
57
|
-
}
|
|
58
|
-
if (!isPlainObject(tool.inputSchema)) {
|
|
59
|
-
invalidTool(`Tool ${tool.name} inputSchema must be a JSON object`);
|
|
60
|
-
}
|
|
61
|
-
if (tool.outputSchema !== undefined && !isPlainObject(tool.outputSchema)) {
|
|
62
|
-
invalidTool(`Tool ${tool.name} outputSchema must be a JSON object`);
|
|
63
|
-
}
|
|
64
|
-
if (tool.maxOutputBytes !== undefined &&
|
|
65
|
-
(!Number.isSafeInteger(tool.maxOutputBytes) || tool.maxOutputBytes <= 0)) {
|
|
66
|
-
invalidTool(`Tool ${tool.name} maxOutputBytes must be a positive safe integer`);
|
|
67
|
-
}
|
|
68
|
-
if (typeof tool.sideEffect !== "string" || !SIDE_EFFECTS.has(tool.sideEffect)) {
|
|
69
|
-
invalidTool(`Tool ${tool.name} has an invalid sideEffect`);
|
|
70
|
-
}
|
|
71
|
-
if (typeof tool.replayPolicy !== "string" ||
|
|
72
|
-
!REPLAY_POLICIES.has(tool.replayPolicy)) {
|
|
73
|
-
invalidTool(`Tool ${tool.name} has an invalid replayPolicy`);
|
|
74
|
-
}
|
|
75
|
-
if (tool.riskLevel !== undefined &&
|
|
76
|
-
(typeof tool.riskLevel !== "string" || !RISK_LEVELS.has(tool.riskLevel))) {
|
|
77
|
-
invalidTool(`Tool ${tool.name} has an invalid riskLevel`);
|
|
78
|
-
}
|
|
79
|
-
if (tool.requiresConfirmation !== undefined &&
|
|
80
|
-
typeof tool.requiresConfirmation !== "boolean") {
|
|
81
|
-
invalidTool(`Tool ${tool.name} requiresConfirmation must be boolean`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export function buildToolManifestV1(tools) {
|
|
85
|
-
if (isProxy(tools) || !Array.isArray(tools)) {
|
|
86
|
-
invalidTool("Tool collection must be an array");
|
|
87
|
-
}
|
|
88
|
-
canonicalizeJson(tools);
|
|
89
|
-
for (const tool of tools)
|
|
90
|
-
validateToolDescriptor(tool);
|
|
91
|
-
const sortedTools = [...tools].sort(compareTools);
|
|
92
|
-
for (let index = 1; index < sortedTools.length; index += 1) {
|
|
93
|
-
const previous = sortedTools[index - 1];
|
|
94
|
-
const current = sortedTools[index];
|
|
95
|
-
if (previous?.name === current?.name &&
|
|
96
|
-
previous.version === current.version) {
|
|
97
|
-
throw new CapabilityArtifactError("ARTIFACT_TOOL_DUPLICATE", `Duplicate Tool identity: ${current.name}@${current.version}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const candidate = {
|
|
101
|
-
schemaVersion: "spotlight.tool-manifest/1",
|
|
102
|
-
tools: sortedTools,
|
|
103
|
-
};
|
|
104
|
-
const bytes = canonicalizeJson(candidate);
|
|
105
|
-
const manifest = JSON.parse(new TextDecoder().decode(bytes));
|
|
106
|
-
return {
|
|
107
|
-
manifest,
|
|
108
|
-
bytes,
|
|
109
|
-
digest: sha256(bytes),
|
|
110
|
-
};
|
|
111
|
-
}
|