@inupedia/spotlight-client 0.3.6 → 0.4.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.
- package/README.md +14 -123
- package/dist/clientTool.d.ts +42 -0
- package/dist/clientTool.d.ts.map +1 -0
- package/dist/clientTool.js +97 -0
- package/dist/index.d.ts +2 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -18
- package/dist/node/capabilities/skillFileValidator.d.ts +0 -8
- package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
- package/dist/node/capabilities/skillFileValidator.js +26 -46
- package/dist/node/index.d.ts +0 -10
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +0 -9
- package/dist/vite/index.d.ts +1 -7
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +1 -4
- package/dist/vite/spotlightClientTools.d.ts +27 -0
- package/dist/vite/spotlightClientTools.d.ts.map +1 -0
- package/dist/vite/spotlightClientTools.js +424 -0
- package/package.json +6 -20
- package/dist/capabilities/channel.d.ts +0 -28
- package/dist/capabilities/channel.d.ts.map +0 -1
- package/dist/capabilities/channel.js +0 -194
- package/dist/capabilities/errors.d.ts +0 -9
- package/dist/capabilities/errors.d.ts.map +0 -1
- package/dist/capabilities/errors.js +0 -19
- package/dist/capabilities/handshake.d.ts +0 -38
- package/dist/capabilities/handshake.d.ts.map +0 -1
- package/dist/capabilities/handshake.js +0 -139
- package/dist/capabilities/hostActionExecutor.d.ts +0 -22
- package/dist/capabilities/hostActionExecutor.d.ts.map +0 -1
- package/dist/capabilities/hostActionExecutor.js +0 -56
- package/dist/capabilities/jsonSchema.d.ts +0 -2
- package/dist/capabilities/jsonSchema.d.ts.map +0 -1
- package/dist/capabilities/jsonSchema.js +0 -73
- package/dist/capabilities/runtimeCapabilities.d.ts +0 -25
- package/dist/capabilities/runtimeCapabilities.d.ts.map +0 -1
- package/dist/capabilities/runtimeCapabilities.js +0 -53
- package/dist/node/capabilities/archivePath.d.ts +0 -4
- package/dist/node/capabilities/archivePath.d.ts.map +0 -1
- package/dist/node/capabilities/archivePath.js +0 -22
- 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 -15
- package/dist/node/capabilities/capabilityArtifact.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifact.js +0 -37
- 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 -19
- package/dist/node/capabilities/capabilityFileMap.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityFileMap.js +0 -234
- 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 -128
- package/dist/node/capabilities/skillDirectoryLoader.d.ts +0 -24
- package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +0 -1
- package/dist/node/capabilities/skillDirectoryLoader.js +0 -308
- package/dist/node/capabilities/skillManifest.d.ts +0 -16
- package/dist/node/capabilities/skillManifest.d.ts.map +0 -1
- package/dist/node/capabilities/skillManifest.js +0 -22
- 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/capabilityPublishCli.d.ts +0 -2
- package/dist/node/capabilityPublishCli.d.ts.map +0 -1
- package/dist/node/capabilityPublishCli.js +0 -115
- package/dist/node/cli/spotlightCapabilitiesPublish.d.ts +0 -3
- package/dist/node/cli/spotlightCapabilitiesPublish.d.ts.map +0 -1
- package/dist/node/cli/spotlightCapabilitiesPublish.js +0 -3
- package/dist/node/publishCapabilitiesCli.d.ts +0 -3
- package/dist/node/publishCapabilitiesCli.d.ts.map +0 -1
- package/dist/node/publishCapabilitiesCli.js +0 -36
- package/dist/node/publishCapabilityArtifact.d.ts +0 -12
- package/dist/node/publishCapabilityArtifact.d.ts.map +0 -1
- package/dist/node/publishCapabilityArtifact.js +0 -25
- package/dist/runtimeId.d.ts +0 -3
- package/dist/runtimeId.d.ts.map +0 -1
- package/dist/runtimeId.js +0 -29
- package/dist/tools/frontendTool.d.ts +0 -39
- package/dist/tools/frontendTool.d.ts.map +0 -1
- package/dist/tools/frontendTool.js +0 -51
- package/dist/vite/capabilityBuild.d.ts +0 -9
- package/dist/vite/capabilityBuild.d.ts.map +0 -1
- package/dist/vite/capabilityBuild.js +0 -169
- package/dist/vite/capabilityBuildTypes.d.ts +0 -32
- package/dist/vite/capabilityBuildTypes.d.ts.map +0 -1
- package/dist/vite/capabilityBuildTypes.js +0 -1
- package/dist/vite/capabilityDevMiddleware.d.ts +0 -5
- package/dist/vite/capabilityDevMiddleware.d.ts.map +0 -1
- package/dist/vite/capabilityDevMiddleware.js +0 -42
- package/dist/vite/capabilityVirtualModule.d.ts +0 -11
- package/dist/vite/capabilityVirtualModule.d.ts.map +0 -1
- package/dist/vite/capabilityVirtualModule.js +0 -60
- package/dist/vite/capabilityVirtualModuleTypes.d.ts +0 -12
- package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +0 -1
- package/dist/vite/capabilityVirtualModuleTypes.js +0 -1
- package/dist/vite/spotlightAgentIoc.d.ts +0 -11
- package/dist/vite/spotlightAgentIoc.d.ts.map +0 -1
- package/dist/vite/spotlightAgentIoc.js +0 -331
- package/dist/vite/spotlightCapabilities.d.ts +0 -4
- package/dist/vite/spotlightCapabilities.d.ts.map +0 -1
- package/dist/vite/spotlightCapabilities.js +0 -187
- package/src/agentDecorator.d.ts +0 -17
|
@@ -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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityPublishCli.d.ts","sourceRoot":"","sources":["../../src/node/capabilityPublishCli.ts"],"names":[],"mappings":"AAsCA,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CASxF"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { access, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { basename, dirname, join } from "node:path";
|
|
4
|
-
import { gunzipSync } from "node:zlib";
|
|
5
|
-
import { canonicalizeJson } from "./capabilities/canonicalJson.js";
|
|
6
|
-
import { computeArtifactDigestV1 } from "./capabilities/capabilityFileMap.js";
|
|
7
|
-
import { canonicalArchivePathProblem } from "./capabilities/archivePath.js";
|
|
8
|
-
function args(argv) { const parsed = {}; for (let i = 0; i < argv.length; i += 2) {
|
|
9
|
-
const k = argv[i], v = argv[i + 1];
|
|
10
|
-
if (!k?.startsWith("--") || !v)
|
|
11
|
-
throw new TypeError("Capability publish CLI expects --key value arguments.");
|
|
12
|
-
parsed[k.slice(2)] = v;
|
|
13
|
-
} return parsed; }
|
|
14
|
-
const sha256 = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
15
|
-
function tarFiles(archive) {
|
|
16
|
-
const tar = Uint8Array.from(gunzipSync(archive));
|
|
17
|
-
const files = new Map();
|
|
18
|
-
const seenPaths = new Set();
|
|
19
|
-
let offset = 0;
|
|
20
|
-
const text = (bytes) => new TextDecoder().decode(bytes.subarray(0, bytes.indexOf(0) < 0 ? bytes.length : bytes.indexOf(0)));
|
|
21
|
-
while (offset + 512 <= tar.length) {
|
|
22
|
-
const h = tar.subarray(offset, offset + 512);
|
|
23
|
-
if (h.every((b) => b === 0)) {
|
|
24
|
-
const second = tar.subarray(offset + 512, offset + 1024);
|
|
25
|
-
if (second.length < 512 || !second.every((b) => b === 0) || !tar.subarray(offset + 1024).every((b) => b === 0))
|
|
26
|
-
throw new TypeError("Invalid USTAR trailing content.");
|
|
27
|
-
return files;
|
|
28
|
-
}
|
|
29
|
-
const storedText = text(h.subarray(148, 156)).trim();
|
|
30
|
-
if (!/^[0-7]+$/.test(storedText))
|
|
31
|
-
throw new TypeError("Invalid USTAR header checksum field.");
|
|
32
|
-
const stored = Number.parseInt(storedText, 8);
|
|
33
|
-
let sum = 0;
|
|
34
|
-
for (let i = 0; i < 512; i++)
|
|
35
|
-
sum += i >= 148 && i < 156 ? 32 : (h[i] ?? 0);
|
|
36
|
-
if (sum !== stored)
|
|
37
|
-
throw new TypeError("Invalid USTAR header checksum.");
|
|
38
|
-
if (text(h.subarray(257, 263)) !== "ustar" || text(h.subarray(263, 265)) !== "00")
|
|
39
|
-
throw new TypeError("Invalid USTAR header magic.");
|
|
40
|
-
const type = h[156];
|
|
41
|
-
if (type !== 48 && type !== 0 && type !== 53)
|
|
42
|
-
throw new TypeError("Artifact contains an unsupported USTAR entry.");
|
|
43
|
-
const name = text(h.subarray(0, 100));
|
|
44
|
-
const prefix = text(h.subarray(345, 500));
|
|
45
|
-
const rawPath = prefix ? `${prefix}/${name}` : name;
|
|
46
|
-
const isDirectory = type === 53;
|
|
47
|
-
const path = isDirectory ? rawPath.replace(/\/$/, "") : rawPath;
|
|
48
|
-
if (canonicalArchivePathProblem(rawPath, { directory: isDirectory }) || seenPaths.has(path))
|
|
49
|
-
throw new TypeError("Invalid or duplicate USTAR path.");
|
|
50
|
-
seenPaths.add(path);
|
|
51
|
-
const sizeText = text(h.subarray(124, 136)).trim();
|
|
52
|
-
if (!/^[0-7]+$/.test(sizeText))
|
|
53
|
-
throw new TypeError("Invalid USTAR size field.");
|
|
54
|
-
const size = Number.parseInt(sizeText, 8);
|
|
55
|
-
if (isDirectory && size !== 0)
|
|
56
|
-
throw new TypeError("USTAR directory must be zero length.");
|
|
57
|
-
const start = offset + 512, end = start + size, padded = start + Math.ceil(size / 512) * 512;
|
|
58
|
-
if (end > tar.length || !tar.subarray(end, padded).every((b) => b === 0))
|
|
59
|
-
throw new TypeError("Invalid USTAR payload padding.");
|
|
60
|
-
if (!isDirectory)
|
|
61
|
-
files.set(path, tar.slice(start, end));
|
|
62
|
-
offset = padded;
|
|
63
|
-
}
|
|
64
|
-
throw new TypeError("USTAR archive is missing terminal zero blocks.");
|
|
65
|
-
}
|
|
66
|
-
function verify(archive, info) {
|
|
67
|
-
const files = tarFiles(archive);
|
|
68
|
-
const manifestBytes = files.get("manifest.json"), skillBytes = files.get("skill-manifest.json"), toolBytes = files.get("tool-manifest.json");
|
|
69
|
-
if (!manifestBytes || !skillBytes || !toolBytes)
|
|
70
|
-
throw new TypeError("Artifact is missing required manifests.");
|
|
71
|
-
const manifest = JSON.parse(new TextDecoder().decode(manifestBytes));
|
|
72
|
-
const manifestPaths = manifest.files.map((entry) => entry.path);
|
|
73
|
-
if (new Set(manifestPaths).size !== manifestPaths.length)
|
|
74
|
-
throw new TypeError("Artifact manifest contains duplicate file declarations.");
|
|
75
|
-
const declared = new Set(["manifest.json", ...manifestPaths]);
|
|
76
|
-
if (files.size !== declared.size || [...files.keys()].some((path) => !declared.has(path)))
|
|
77
|
-
throw new TypeError("Artifact contains undeclared regular files.");
|
|
78
|
-
for (const entry of manifest.files) {
|
|
79
|
-
const bytes = files.get(entry.path);
|
|
80
|
-
if (!bytes || bytes.byteLength !== entry.byteLength || sha256(bytes) !== entry.sha256)
|
|
81
|
-
throw new TypeError(`Artifact payload mismatch: ${entry.path}`);
|
|
82
|
-
}
|
|
83
|
-
const manifestDigest = sha256(manifestBytes), skillManifestDigest = sha256(skillBytes), toolManifestDigest = sha256(toolBytes);
|
|
84
|
-
const artifactDigest = computeArtifactDigestV1({ manifestDigest, skillManifestDigest, toolManifestDigest, payloads: manifest.files });
|
|
85
|
-
const actual = { digest: artifactDigest, manifestDigest, skillManifestDigest, toolManifestDigest, byteLength: archive.byteLength };
|
|
86
|
-
const expected = { digest: info.artifactDigest, manifestDigest: info.manifestDigest, skillManifestDigest: info.skillManifestDigest, toolManifestDigest: info.toolManifestDigest, byteLength: info.byteLength };
|
|
87
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected))
|
|
88
|
-
throw new TypeError("Artifact digests do not match build info.");
|
|
89
|
-
return actual;
|
|
90
|
-
}
|
|
91
|
-
export async function runCapabilityPublishCliV1(argv) {
|
|
92
|
-
const input = args(argv);
|
|
93
|
-
if (!input.artifact || !input["build-info"] || !input["out-dir"])
|
|
94
|
-
throw new TypeError("Required: --artifact --build-info --out-dir");
|
|
95
|
-
const [archive, infoText] = await Promise.all([readFile(input.artifact), readFile(input["build-info"], "utf8")]);
|
|
96
|
-
const info = JSON.parse(infoText);
|
|
97
|
-
for (const field of ["projectId", "frontendBuildId"])
|
|
98
|
-
if (typeof info[field] !== "string" || !info[field])
|
|
99
|
-
throw new TypeError(`Invalid build info field: ${field}`);
|
|
100
|
-
const artifact = verify(archive, info);
|
|
101
|
-
const attestation = { schemaVersion: "spotlight.capability-attestation/1", projectId: info.projectId, frontendBuildId: info.frontendBuildId, artifact, createdAt: input["created-at"] ?? new Date().toISOString() };
|
|
102
|
-
const out = input["out-dir"];
|
|
103
|
-
await mkdir(dirname(out), { recursive: true });
|
|
104
|
-
await access(out).then(() => { throw new TypeError("Publish output already exists."); }, () => undefined);
|
|
105
|
-
const staging = await mkdtemp(join(dirname(out), `.${basename(out)}.tmp-`));
|
|
106
|
-
try {
|
|
107
|
-
await Promise.all([writeFile(join(staging, `${artifact.digest}.tgz`), archive, { flag: "wx" }), writeFile(join(staging, "capability-attestation.json"), `${new TextDecoder().decode(canonicalizeJson(attestation))}\n`, { flag: "wx", encoding: "utf8" })]);
|
|
108
|
-
await rename(staging, out);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
await rm(staging, { recursive: true, force: true });
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
return 0;
|
|
115
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spotlightCapabilitiesPublish.d.ts","sourceRoot":"","sources":["../../../src/node/cli/spotlightCapabilitiesPublish.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runCapabilityPublishCliV1 } from "../capabilityPublishCli.js";
|
|
3
|
-
runCapabilityPublishCliV1(process.argv.slice(2)).then((code) => { process.exitCode = code; }, (error) => { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publishCapabilitiesCli.d.ts","sourceRoot":"","sources":["../../src/node/publishCapabilitiesCli.ts"],"names":[],"mappings":""}
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { CapabilityArtifactBuildV1 } from "./capabilities/capabilityArtifact.js";
|
|
2
|
-
export declare function publishCapabilityArtifactV1(input: {
|
|
3
|
-
outDir: string;
|
|
4
|
-
projectId: string;
|
|
5
|
-
frontendBuildId: string;
|
|
6
|
-
build: CapabilityArtifactBuildV1;
|
|
7
|
-
createdAt?: string;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
artifactPath: string;
|
|
10
|
-
attestationPath: string;
|
|
11
|
-
}>;
|
|
12
|
-
//# sourceMappingURL=publishCapabilityArtifact.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publishCapabilityArtifact.d.ts","sourceRoot":"","sources":["../../src/node/publishCapabilityArtifact.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAGtF,wBAAsB,2BAA2B,CAAC,KAAK,EAAE;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,yBAAyB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CAqB7D"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { canonicalizeJson } from "./capabilities/canonicalJson.js";
|
|
4
|
-
export async function publishCapabilityArtifactV1(input) {
|
|
5
|
-
await mkdir(input.outDir, { recursive: true });
|
|
6
|
-
const artifactPath = join(input.outDir, `${input.build.artifactDigest}.tgz`);
|
|
7
|
-
const attestationPath = join(input.outDir, "capability-attestation.json");
|
|
8
|
-
const artifact = {
|
|
9
|
-
digest: input.build.artifactDigest,
|
|
10
|
-
manifestDigest: input.build.manifestDigest,
|
|
11
|
-
skillManifestDigest: input.build.skillManifestDigest,
|
|
12
|
-
toolManifestDigest: input.build.toolManifestDigest,
|
|
13
|
-
byteLength: input.build.byteLength,
|
|
14
|
-
};
|
|
15
|
-
const attestation = {
|
|
16
|
-
schemaVersion: "spotlight.capability-attestation/1",
|
|
17
|
-
projectId: input.projectId,
|
|
18
|
-
frontendBuildId: input.frontendBuildId,
|
|
19
|
-
artifact,
|
|
20
|
-
createdAt: input.createdAt ?? new Date().toISOString(),
|
|
21
|
-
};
|
|
22
|
-
await writeFile(artifactPath, input.build.archive, { flag: "wx" });
|
|
23
|
-
await writeFile(attestationPath, `${new TextDecoder().decode(canonicalizeJson(attestation))}\n`, { flag: "wx", encoding: "utf8" });
|
|
24
|
-
return { artifactPath, attestationPath };
|
|
25
|
-
}
|
package/dist/runtimeId.d.ts
DELETED
package/dist/runtimeId.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeId.d.ts","sourceRoot":"","sources":["../src/runtimeId.ts"],"names":[],"mappings":"AAYA,oEAAoE;AACpE,wBAAgB,eAAe,IAAI,MAAM,CAiBxC"}
|
package/dist/runtimeId.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function randomBytes() {
|
|
2
|
-
const bytes = new Uint8Array(16);
|
|
3
|
-
const cryptoApi = globalThis.crypto;
|
|
4
|
-
if (typeof cryptoApi?.getRandomValues === "function") {
|
|
5
|
-
return cryptoApi.getRandomValues(bytes);
|
|
6
|
-
}
|
|
7
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
8
|
-
bytes[index] = Math.floor(Math.random() * 256);
|
|
9
|
-
}
|
|
10
|
-
return bytes;
|
|
11
|
-
}
|
|
12
|
-
/** Create a UUID v4 without requiring Crypto.randomUUID support. */
|
|
13
|
-
export function createRuntimeId() {
|
|
14
|
-
const cryptoApi = globalThis.crypto;
|
|
15
|
-
if (typeof cryptoApi?.randomUUID === "function") {
|
|
16
|
-
return cryptoApi.randomUUID();
|
|
17
|
-
}
|
|
18
|
-
const bytes = randomBytes();
|
|
19
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
20
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
21
|
-
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
22
|
-
return [
|
|
23
|
-
hex.slice(0, 4).join(""),
|
|
24
|
-
hex.slice(4, 6).join(""),
|
|
25
|
-
hex.slice(6, 8).join(""),
|
|
26
|
-
hex.slice(8, 10).join(""),
|
|
27
|
-
hex.slice(10, 16).join(""),
|
|
28
|
-
].join("-");
|
|
29
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,51 +0,0 @@
|
|
|
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,9 +0,0 @@
|
|
|
1
|
-
import type { CapabilityPluginBuildResultV1, SpotlightCapabilitiesOptionsV1, SpotlightCapabilityProjectBuildV1 } from "./capabilityBuildTypes.js";
|
|
2
|
-
export type { CapabilityBuildInfoV1, CapabilityPluginBuildResultV1, SpotlightCapabilitiesOptionsV1, SpotlightCapabilityProjectBuildV1, } from "./capabilityBuildTypes.js";
|
|
3
|
-
export declare function buildViteCapabilitiesV1(input: {
|
|
4
|
-
root: string;
|
|
5
|
-
command: "serve" | "build";
|
|
6
|
-
project: SpotlightCapabilityProjectBuildV1;
|
|
7
|
-
options?: SpotlightCapabilitiesOptionsV1;
|
|
8
|
-
}): Promise<CapabilityPluginBuildResultV1>;
|
|
9
|
-
//# sourceMappingURL=capabilityBuild.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilityBuild.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuild.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AAGnC,YAAY,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,2BAA2B,CAAC;AA2HnC,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,OAAO,EAAE,iCAAiC,CAAC;IAC3C,OAAO,CAAC,EAAE,8BAA8B,CAAC;CAC1C,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA8FzC"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { resolve, sep } from "node:path";
|
|
2
|
-
import { isProxy } from "node:util/types";
|
|
3
|
-
import { buildCapabilityArtifactV1, buildToolManifestV1, CapabilityArtifactError, loadCanonicalSkillsV1, scanProjectSkills, } from "../node/index.js";
|
|
4
|
-
import { validateSkillContent } from "../node/capabilities/skillFileValidator.js";
|
|
5
|
-
const PROJECT_FIELDS = new Set(["projectId", "skillRoots", "tools"]);
|
|
6
|
-
function invalidInput(message) {
|
|
7
|
-
throw new CapabilityArtifactError("ARTIFACT_INPUT_INVALID", message);
|
|
8
|
-
}
|
|
9
|
-
function validateProject(value) {
|
|
10
|
-
if (value === null ||
|
|
11
|
-
typeof value !== "object" ||
|
|
12
|
-
Array.isArray(value) ||
|
|
13
|
-
isProxy(value)) {
|
|
14
|
-
invalidInput("Capability project must be a plain object");
|
|
15
|
-
}
|
|
16
|
-
const prototype = Object.getPrototypeOf(value);
|
|
17
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
18
|
-
invalidInput("Capability project must be a plain object");
|
|
19
|
-
}
|
|
20
|
-
const keys = Reflect.ownKeys(value);
|
|
21
|
-
if ((keys.length !== 2 && keys.length !== 3) ||
|
|
22
|
-
keys.some((key) => typeof key !== "string" || !PROJECT_FIELDS.has(key))) {
|
|
23
|
-
invalidInput("Capability project own fields must be projectId, tools, and optional skillRoots");
|
|
24
|
-
}
|
|
25
|
-
const readDataField = (field) => {
|
|
26
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, field);
|
|
27
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) {
|
|
28
|
-
invalidInput(`Capability project field ${field} must be an enumerable data property`);
|
|
29
|
-
}
|
|
30
|
-
return descriptor.value;
|
|
31
|
-
};
|
|
32
|
-
const projectId = readDataField("projectId");
|
|
33
|
-
const tools = readDataField("tools");
|
|
34
|
-
const skillRootsDescriptor = Object.getOwnPropertyDescriptor(value, "skillRoots");
|
|
35
|
-
if (skillRootsDescriptor && (!skillRootsDescriptor.enumerable || !("value" in skillRootsDescriptor))) {
|
|
36
|
-
invalidInput("Capability project field skillRoots must be an enumerable data property");
|
|
37
|
-
}
|
|
38
|
-
if (typeof projectId !== "string" || projectId.trim().length === 0) {
|
|
39
|
-
invalidInput("Capability projectId must be a non-empty string");
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
projectId,
|
|
43
|
-
...(skillRootsDescriptor ? { skillRoots: skillRootsDescriptor.value } : {}),
|
|
44
|
-
tools: tools,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function safeToolDescriptors(tools) {
|
|
48
|
-
return tools.map((tool, index) => {
|
|
49
|
-
if (isProxy(tool)) {
|
|
50
|
-
throw new CapabilityArtifactError("ARTIFACT_JSON_UNSUPPORTED_VALUE", `Tool descriptor ${index} must not be a Proxy`);
|
|
51
|
-
}
|
|
52
|
-
if (tool === null || typeof tool !== "object" || Array.isArray(tool)) {
|
|
53
|
-
invalidInput(`Tool descriptor ${index} must be a plain object`);
|
|
54
|
-
}
|
|
55
|
-
const result = {};
|
|
56
|
-
for (const key of Reflect.ownKeys(tool)) {
|
|
57
|
-
if (typeof key !== "string")
|
|
58
|
-
invalidInput(`Tool descriptor ${index} contains a symbol field`);
|
|
59
|
-
const descriptor = Object.getOwnPropertyDescriptor(tool, key);
|
|
60
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) {
|
|
61
|
-
throw new CapabilityArtifactError("ARTIFACT_JSON_UNSUPPORTED_VALUE", `Tool descriptor ${index}.${key} must be an enumerable data property`);
|
|
62
|
-
}
|
|
63
|
-
if (key !== "execute")
|
|
64
|
-
result[key] = descriptor.value;
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function throwDiagnostic(diagnostic) {
|
|
70
|
-
const message = "message" in diagnostic
|
|
71
|
-
? diagnostic.message
|
|
72
|
-
: `Skill scan failed with ${diagnostic.code}`;
|
|
73
|
-
throw Object.assign(new Error(message), diagnostic);
|
|
74
|
-
}
|
|
75
|
-
function freezeDiagnostic(diagnostic) {
|
|
76
|
-
if ("candidates" in diagnostic) {
|
|
77
|
-
const candidates = [...diagnostic.candidates];
|
|
78
|
-
Object.freeze(candidates);
|
|
79
|
-
return Object.freeze({
|
|
80
|
-
code: diagnostic.code,
|
|
81
|
-
severity: diagnostic.severity,
|
|
82
|
-
name: diagnostic.name,
|
|
83
|
-
...(diagnostic.selected === undefined
|
|
84
|
-
? {}
|
|
85
|
-
: { selected: diagnostic.selected }),
|
|
86
|
-
candidates,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return Object.freeze({
|
|
90
|
-
code: diagnostic.code,
|
|
91
|
-
severity: diagnostic.severity,
|
|
92
|
-
message: diagnostic.message,
|
|
93
|
-
skillFile: diagnostic.skillFile,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
export async function buildViteCapabilitiesV1(input) {
|
|
97
|
-
const project = validateProject(input.project);
|
|
98
|
-
const toolManifest = buildToolManifestV1(safeToolDescriptors(project.tools));
|
|
99
|
-
const frontendBuildId = input.options?.frontendBuildId;
|
|
100
|
-
if (input.command === "build" &&
|
|
101
|
-
(frontendBuildId === undefined || frontendBuildId.trim().length === 0)) {
|
|
102
|
-
invalidInput("Production capability builds require frontendBuildId");
|
|
103
|
-
}
|
|
104
|
-
const mode = input.command === "build" ? "strict" : "compat";
|
|
105
|
-
const scan = await scanProjectSkills({
|
|
106
|
-
projectRoot: input.root,
|
|
107
|
-
mode,
|
|
108
|
-
skillRoots: input.options?.skillRoots ?? project.skillRoots,
|
|
109
|
-
});
|
|
110
|
-
const scanErrorDiagnostic = scan.diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
111
|
-
if (scanErrorDiagnostic)
|
|
112
|
-
throwDiagnostic(scanErrorDiagnostic);
|
|
113
|
-
const loaded = await loadCanonicalSkillsV1({
|
|
114
|
-
projectRoot: input.root,
|
|
115
|
-
skills: scan.skills,
|
|
116
|
-
});
|
|
117
|
-
const loadedByName = new Map(loaded.skills.map((skill) => [skill.name, skill]));
|
|
118
|
-
const validation = await Promise.all(scan.skills.map(async (skill) => {
|
|
119
|
-
const loadedSkill = loadedByName.get(skill.name);
|
|
120
|
-
if (!loadedSkill) {
|
|
121
|
-
invalidInput(`Loaded Skill snapshot is missing ${skill.name}`);
|
|
122
|
-
}
|
|
123
|
-
const skillFile = loadedSkill.files.find((file) => file.relativePath === "SKILL.md");
|
|
124
|
-
if (!skillFile) {
|
|
125
|
-
invalidInput(`Loaded Skill ${skill.name} is missing SKILL.md`);
|
|
126
|
-
}
|
|
127
|
-
const files = new Map(loadedSkill.files.map((file) => [file.relativePath, file.bytes]));
|
|
128
|
-
return validateSkillContent({
|
|
129
|
-
skill,
|
|
130
|
-
markdown: Buffer.from(skillFile.bytes).toString("utf8"),
|
|
131
|
-
mode,
|
|
132
|
-
skillRoot: resolve(input.root, skill.directory),
|
|
133
|
-
async readReference(relativePath) {
|
|
134
|
-
const snapshotPath = relativePath.split(sep).join("/");
|
|
135
|
-
return files.get(snapshotPath);
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
}));
|
|
139
|
-
const diagnostics = [
|
|
140
|
-
...scan.diagnostics,
|
|
141
|
-
...validation.flatMap((result) => result.diagnostics),
|
|
142
|
-
].map(freezeDiagnostic);
|
|
143
|
-
const errorDiagnostic = diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
144
|
-
if (errorDiagnostic)
|
|
145
|
-
throwDiagnostic(errorDiagnostic);
|
|
146
|
-
const artifact = buildCapabilityArtifactV1({
|
|
147
|
-
skills: loaded.skills,
|
|
148
|
-
tools: toolManifest.manifest.tools,
|
|
149
|
-
});
|
|
150
|
-
const buildInfo = Object.freeze({
|
|
151
|
-
schemaVersion: "spotlight.capability-build-info/1",
|
|
152
|
-
projectId: project.projectId,
|
|
153
|
-
frontendBuildId: input.command === "build"
|
|
154
|
-
? frontendBuildId
|
|
155
|
-
: `dev:${artifact.artifactDigest}`,
|
|
156
|
-
artifactVersion: artifact.artifactVersion,
|
|
157
|
-
artifactDigest: artifact.artifactDigest,
|
|
158
|
-
manifestDigest: artifact.manifestDigest,
|
|
159
|
-
skillManifestDigest: artifact.skillManifestDigest,
|
|
160
|
-
toolManifestDigest: artifact.toolManifestDigest,
|
|
161
|
-
byteLength: artifact.byteLength,
|
|
162
|
-
});
|
|
163
|
-
return {
|
|
164
|
-
buildInfo,
|
|
165
|
-
archive: artifact.archive,
|
|
166
|
-
watchedFiles: Object.freeze([...loaded.watchedFiles]),
|
|
167
|
-
diagnostics: Object.freeze([...diagnostics]),
|
|
168
|
-
};
|
|
169
|
-
}
|