@nexart/ai-execution 0.3.0 → 0.4.1
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 +44 -9
- package/dist/index.cjs +696 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +55 -11
- package/dist/index.mjs +638 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers/anthropic.cjs +258 -0
- package/dist/providers/anthropic.cjs.map +1 -0
- package/dist/providers/anthropic.d.cts +24 -0
- package/dist/providers/anthropic.d.ts +7 -5
- package/dist/providers/anthropic.mjs +221 -0
- package/dist/providers/anthropic.mjs.map +1 -0
- package/dist/providers/openai.cjs +259 -0
- package/dist/providers/openai.cjs.map +1 -0
- package/dist/providers/openai.d.cts +24 -0
- package/dist/providers/openai.d.ts +7 -5
- package/dist/providers/openai.mjs +222 -0
- package/dist/providers/openai.mjs.map +1 -0
- package/dist/providers/wrap.cjs +221 -0
- package/dist/providers/wrap.cjs.map +1 -0
- package/dist/providers/wrap.d.cts +9 -0
- package/dist/providers/wrap.d.ts +5 -3
- package/dist/providers/wrap.mjs +186 -0
- package/dist/providers/wrap.mjs.map +1 -0
- package/dist/{types.d.ts → types-342Snbrb.d.cts} +31 -16
- package/dist/types-342Snbrb.d.ts +169 -0
- package/package.json +18 -11
- package/dist/archive.d.ts +0 -4
- package/dist/archive.d.ts.map +0 -1
- package/dist/archive.js +0 -28
- package/dist/archive.js.map +0 -1
- package/dist/attest.d.ts +0 -3
- package/dist/attest.d.ts.map +0 -1
- package/dist/attest.js +0 -79
- package/dist/attest.js.map +0 -1
- package/dist/canonicalJson.d.ts +0 -2
- package/dist/canonicalJson.d.ts.map +0 -1
- package/dist/canonicalJson.js +0 -38
- package/dist/canonicalJson.js.map +0 -1
- package/dist/cer.d.ts +0 -7
- package/dist/cer.d.ts.map +0 -1
- package/dist/cer.js +0 -61
- package/dist/cer.js.map +0 -1
- package/dist/certify.d.ts +0 -3
- package/dist/certify.d.ts.map +0 -1
- package/dist/certify.js +0 -27
- package/dist/certify.js.map +0 -1
- package/dist/errors.d.ts +0 -11
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -21
- package/dist/errors.js.map +0 -1
- package/dist/hash.d.ts +0 -6
- package/dist/hash.d.ts.map +0 -1
- package/dist/hash.js +0 -32
- package/dist/hash.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -11
- package/dist/index.js.map +0 -1
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -61
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -62
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/wrap.d.ts.map +0 -1
- package/dist/providers/wrap.js +0 -28
- package/dist/providers/wrap.js.map +0 -1
- package/dist/run.d.ts +0 -14
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -62
- package/dist/run.js.map +0 -1
- package/dist/snapshot.d.ts +0 -4
- package/dist/snapshot.d.ts.map +0 -1
- package/dist/snapshot.js +0 -113
- package/dist/snapshot.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/providers/wrap.ts
|
|
2
|
+
import * as crypto2 from "crypto";
|
|
3
|
+
|
|
4
|
+
// src/hash.ts
|
|
5
|
+
import * as crypto from "crypto";
|
|
6
|
+
|
|
7
|
+
// src/canonicalJson.ts
|
|
8
|
+
function toCanonicalJson(value) {
|
|
9
|
+
return canonicalize(value);
|
|
10
|
+
}
|
|
11
|
+
function canonicalize(value) {
|
|
12
|
+
if (value === null) {
|
|
13
|
+
return "null";
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === "boolean") {
|
|
16
|
+
return value ? "true" : "false";
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "number") {
|
|
19
|
+
if (!Number.isFinite(value)) {
|
|
20
|
+
throw new Error(`Non-finite number not allowed in canonical JSON: ${value}`);
|
|
21
|
+
}
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
return JSON.stringify(value);
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
const items = value.map((item) => canonicalize(item));
|
|
29
|
+
return "[" + items.join(",") + "]";
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object") {
|
|
32
|
+
const obj = value;
|
|
33
|
+
const keys = Object.keys(obj).sort();
|
|
34
|
+
const entries = keys.map((key) => {
|
|
35
|
+
const val = obj[key];
|
|
36
|
+
if (val === void 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return JSON.stringify(key) + ":" + canonicalize(val);
|
|
40
|
+
}).filter((e) => e !== null);
|
|
41
|
+
return "{" + entries.join(",") + "}";
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Unsupported type for canonical JSON: ${typeof value}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/hash.ts
|
|
47
|
+
function sha256Hex(data) {
|
|
48
|
+
const hash = crypto.createHash("sha256");
|
|
49
|
+
if (typeof data === "string") {
|
|
50
|
+
hash.update(data, "utf-8");
|
|
51
|
+
} else {
|
|
52
|
+
hash.update(data);
|
|
53
|
+
}
|
|
54
|
+
return hash.digest("hex");
|
|
55
|
+
}
|
|
56
|
+
function hashUtf8(value) {
|
|
57
|
+
return `sha256:${sha256Hex(value)}`;
|
|
58
|
+
}
|
|
59
|
+
function hashCanonicalJson(value) {
|
|
60
|
+
const canonical = toCanonicalJson(value);
|
|
61
|
+
return `sha256:${sha256Hex(canonical)}`;
|
|
62
|
+
}
|
|
63
|
+
function computeInputHash(input) {
|
|
64
|
+
if (typeof input === "string") {
|
|
65
|
+
return hashUtf8(input);
|
|
66
|
+
}
|
|
67
|
+
return hashCanonicalJson(input);
|
|
68
|
+
}
|
|
69
|
+
function computeOutputHash(output) {
|
|
70
|
+
if (typeof output === "string") {
|
|
71
|
+
return hashUtf8(output);
|
|
72
|
+
}
|
|
73
|
+
return hashCanonicalJson(output);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/snapshot.ts
|
|
77
|
+
var PACKAGE_VERSION = "0.4.1";
|
|
78
|
+
function validateParameters(params) {
|
|
79
|
+
const errors = [];
|
|
80
|
+
if (typeof params.temperature !== "number" || !Number.isFinite(params.temperature)) {
|
|
81
|
+
errors.push(`parameters.temperature must be a finite number, got: ${params.temperature}`);
|
|
82
|
+
}
|
|
83
|
+
if (typeof params.maxTokens !== "number" || !Number.isFinite(params.maxTokens)) {
|
|
84
|
+
errors.push(`parameters.maxTokens must be a finite number, got: ${params.maxTokens}`);
|
|
85
|
+
}
|
|
86
|
+
if (params.topP !== null && (typeof params.topP !== "number" || !Number.isFinite(params.topP))) {
|
|
87
|
+
errors.push(`parameters.topP must be a finite number or null, got: ${params.topP}`);
|
|
88
|
+
}
|
|
89
|
+
if (params.seed !== null && (typeof params.seed !== "number" || !Number.isFinite(params.seed))) {
|
|
90
|
+
errors.push(`parameters.seed must be a finite number or null, got: ${params.seed}`);
|
|
91
|
+
}
|
|
92
|
+
return errors;
|
|
93
|
+
}
|
|
94
|
+
function createSnapshot(params) {
|
|
95
|
+
const paramErrors = validateParameters(params.parameters);
|
|
96
|
+
if (paramErrors.length > 0) {
|
|
97
|
+
throw new Error(`Invalid parameters: ${paramErrors.join("; ")}`);
|
|
98
|
+
}
|
|
99
|
+
const inputHash = computeInputHash(params.input);
|
|
100
|
+
const outputHash = computeOutputHash(params.output);
|
|
101
|
+
const snapshot = {
|
|
102
|
+
type: "ai.execution.v1",
|
|
103
|
+
protocolVersion: "1.2.0",
|
|
104
|
+
executionSurface: "ai",
|
|
105
|
+
executionId: params.executionId,
|
|
106
|
+
timestamp: params.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
107
|
+
provider: params.provider,
|
|
108
|
+
model: params.model,
|
|
109
|
+
modelVersion: params.modelVersion ?? null,
|
|
110
|
+
prompt: params.prompt,
|
|
111
|
+
input: params.input,
|
|
112
|
+
inputHash,
|
|
113
|
+
parameters: {
|
|
114
|
+
temperature: params.parameters.temperature,
|
|
115
|
+
maxTokens: params.parameters.maxTokens,
|
|
116
|
+
topP: params.parameters.topP ?? null,
|
|
117
|
+
seed: params.parameters.seed ?? null
|
|
118
|
+
},
|
|
119
|
+
output: params.output,
|
|
120
|
+
outputHash,
|
|
121
|
+
sdkVersion: params.sdkVersion ?? PACKAGE_VERSION,
|
|
122
|
+
appId: params.appId ?? null
|
|
123
|
+
};
|
|
124
|
+
if (params.runId !== void 0) snapshot.runId = params.runId ?? null;
|
|
125
|
+
if (params.stepId !== void 0) snapshot.stepId = params.stepId ?? null;
|
|
126
|
+
if (params.stepIndex !== void 0) snapshot.stepIndex = params.stepIndex ?? null;
|
|
127
|
+
if (params.workflowId !== void 0) snapshot.workflowId = params.workflowId ?? null;
|
|
128
|
+
if (params.conversationId !== void 0) snapshot.conversationId = params.conversationId ?? null;
|
|
129
|
+
if (params.prevStepHash !== void 0) snapshot.prevStepHash = params.prevStepHash ?? null;
|
|
130
|
+
return snapshot;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/cer.ts
|
|
134
|
+
function computeCertificateHash(payload) {
|
|
135
|
+
const canonical = toCanonicalJson(payload);
|
|
136
|
+
return `sha256:${sha256Hex(canonical)}`;
|
|
137
|
+
}
|
|
138
|
+
function sealCer(snapshot, options) {
|
|
139
|
+
const createdAt = options?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
140
|
+
const payload = {
|
|
141
|
+
bundleType: "cer.ai.execution.v1",
|
|
142
|
+
createdAt,
|
|
143
|
+
snapshot,
|
|
144
|
+
version: "0.1"
|
|
145
|
+
};
|
|
146
|
+
const certificateHash = computeCertificateHash(payload);
|
|
147
|
+
const bundle = {
|
|
148
|
+
bundleType: "cer.ai.execution.v1",
|
|
149
|
+
certificateHash,
|
|
150
|
+
createdAt,
|
|
151
|
+
version: "0.1",
|
|
152
|
+
snapshot
|
|
153
|
+
};
|
|
154
|
+
if (options?.meta) {
|
|
155
|
+
bundle.meta = options.meta;
|
|
156
|
+
}
|
|
157
|
+
return bundle;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/providers/wrap.ts
|
|
161
|
+
function wrapProvider(config) {
|
|
162
|
+
return {
|
|
163
|
+
async execute(params) {
|
|
164
|
+
const raw = await config.callFn(params.providerInput);
|
|
165
|
+
const output = config.extractOutput(raw);
|
|
166
|
+
const modelVersion = config.extractModelVersion ? config.extractModelVersion(raw) : params.modelVersion ?? null;
|
|
167
|
+
const snapshot = createSnapshot({
|
|
168
|
+
executionId: params.executionId ?? crypto2.randomUUID(),
|
|
169
|
+
provider: config.provider,
|
|
170
|
+
model: params.model,
|
|
171
|
+
modelVersion,
|
|
172
|
+
prompt: params.prompt,
|
|
173
|
+
input: params.input,
|
|
174
|
+
parameters: params.parameters,
|
|
175
|
+
output,
|
|
176
|
+
appId: params.appId
|
|
177
|
+
});
|
|
178
|
+
const bundle = sealCer(snapshot, { meta: params.meta });
|
|
179
|
+
return { output, snapshot, bundle };
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
wrapProvider
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=wrap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/wrap.ts","../../src/hash.ts","../../src/canonicalJson.ts","../../src/snapshot.ts","../../src/cer.ts"],"sourcesContent":["import * as crypto from 'crypto';\nimport type {\n ProviderConfig,\n WrappedExecutionParams,\n WrappedExecutionResult,\n} from '../types.js';\nimport { createSnapshot } from '../snapshot.js';\nimport { sealCer } from '../cer.js';\n\nexport function wrapProvider<TInput = unknown, TOutput = unknown>(\n config: ProviderConfig<TInput, TOutput>,\n) {\n return {\n async execute(params: WrappedExecutionParams & { providerInput: TInput }): Promise<WrappedExecutionResult> {\n const raw = await config.callFn(params.providerInput);\n const output = config.extractOutput(raw);\n const modelVersion = config.extractModelVersion\n ? config.extractModelVersion(raw)\n : (params.modelVersion ?? null);\n\n const snapshot = createSnapshot({\n executionId: params.executionId ?? crypto.randomUUID(),\n provider: config.provider,\n model: params.model,\n modelVersion,\n prompt: params.prompt,\n input: params.input,\n parameters: params.parameters,\n output,\n appId: params.appId,\n });\n\n const bundle = sealCer(snapshot, { meta: params.meta });\n\n return { output, snapshot, bundle };\n },\n };\n}\n","import * as crypto from 'crypto';\nimport { toCanonicalJson } from './canonicalJson.js';\n\nexport function sha256Hex(data: string | Uint8Array): string {\n const hash = crypto.createHash('sha256');\n if (typeof data === 'string') {\n hash.update(data, 'utf-8');\n } else {\n hash.update(data);\n }\n return hash.digest('hex');\n}\n\nexport function hashUtf8(value: string): string {\n return `sha256:${sha256Hex(value)}`;\n}\n\nexport function hashCanonicalJson(value: unknown): string {\n const canonical = toCanonicalJson(value);\n return `sha256:${sha256Hex(canonical)}`;\n}\n\nexport function computeInputHash(input: string | Record<string, unknown>): string {\n if (typeof input === 'string') {\n return hashUtf8(input);\n }\n return hashCanonicalJson(input);\n}\n\nexport function computeOutputHash(output: string | Record<string, unknown>): string {\n if (typeof output === 'string') {\n return hashUtf8(output);\n }\n return hashCanonicalJson(output);\n}\n","export function toCanonicalJson(value: unknown): string {\n return canonicalize(value);\n}\n\nfunction canonicalize(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n\n if (typeof value === 'boolean') {\n return value ? 'true' : 'false';\n }\n\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n throw new Error(`Non-finite number not allowed in canonical JSON: ${value}`);\n }\n return JSON.stringify(value);\n }\n\n if (typeof value === 'string') {\n return JSON.stringify(value);\n }\n\n if (Array.isArray(value)) {\n const items = value.map(item => canonicalize(item));\n return '[' + items.join(',') + ']';\n }\n\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n const entries = keys.map(key => {\n const val = obj[key];\n if (val === undefined) {\n return null;\n }\n return JSON.stringify(key) + ':' + canonicalize(val);\n }).filter(e => e !== null);\n return '{' + entries.join(',') + '}';\n }\n\n throw new Error(`Unsupported type for canonical JSON: ${typeof value}`);\n}\n","import type { AiExecutionSnapshotV1, CreateSnapshotParams, VerificationResult, AiExecutionParameters } from './types.js';\nimport { CerVerifyCode } from './types.js';\nimport { computeInputHash, computeOutputHash } from './hash.js';\n\nconst PACKAGE_VERSION = '0.4.1';\n\nfunction validateParameters(params: AiExecutionParameters): string[] {\n const errors: string[] = [];\n\n if (typeof params.temperature !== 'number' || !Number.isFinite(params.temperature)) {\n errors.push(`parameters.temperature must be a finite number, got: ${params.temperature}`);\n }\n\n if (typeof params.maxTokens !== 'number' || !Number.isFinite(params.maxTokens)) {\n errors.push(`parameters.maxTokens must be a finite number, got: ${params.maxTokens}`);\n }\n\n if (params.topP !== null && (typeof params.topP !== 'number' || !Number.isFinite(params.topP))) {\n errors.push(`parameters.topP must be a finite number or null, got: ${params.topP}`);\n }\n\n if (params.seed !== null && (typeof params.seed !== 'number' || !Number.isFinite(params.seed))) {\n errors.push(`parameters.seed must be a finite number or null, got: ${params.seed}`);\n }\n\n return errors;\n}\n\nexport function createSnapshot(params: CreateSnapshotParams): AiExecutionSnapshotV1 {\n const paramErrors = validateParameters(params.parameters);\n if (paramErrors.length > 0) {\n throw new Error(`Invalid parameters: ${paramErrors.join('; ')}`);\n }\n\n const inputHash = computeInputHash(params.input);\n const outputHash = computeOutputHash(params.output);\n\n const snapshot: AiExecutionSnapshotV1 = {\n type: 'ai.execution.v1',\n protocolVersion: '1.2.0',\n executionSurface: 'ai',\n executionId: params.executionId,\n timestamp: params.timestamp ?? new Date().toISOString(),\n provider: params.provider,\n model: params.model,\n modelVersion: params.modelVersion ?? null,\n prompt: params.prompt,\n input: params.input,\n inputHash,\n parameters: {\n temperature: params.parameters.temperature,\n maxTokens: params.parameters.maxTokens,\n topP: params.parameters.topP ?? null,\n seed: params.parameters.seed ?? null,\n },\n output: params.output,\n outputHash,\n sdkVersion: params.sdkVersion ?? PACKAGE_VERSION,\n appId: params.appId ?? null,\n };\n\n if (params.runId !== undefined) snapshot.runId = params.runId ?? null;\n if (params.stepId !== undefined) snapshot.stepId = params.stepId ?? null;\n if (params.stepIndex !== undefined) snapshot.stepIndex = params.stepIndex ?? null;\n if (params.workflowId !== undefined) snapshot.workflowId = params.workflowId ?? null;\n if (params.conversationId !== undefined) snapshot.conversationId = params.conversationId ?? null;\n if (params.prevStepHash !== undefined) snapshot.prevStepHash = params.prevStepHash ?? null;\n\n return snapshot;\n}\n\nexport function verifySnapshot(snapshot: AiExecutionSnapshotV1): VerificationResult {\n const schemaErrors: string[] = [];\n const formatErrors: string[] = [];\n const inputHashErrors: string[] = [];\n const outputHashErrors: string[] = [];\n\n if (snapshot.type !== 'ai.execution.v1') {\n schemaErrors.push(`Expected type \"ai.execution.v1\", got \"${snapshot.type}\"`);\n }\n\n if (snapshot.protocolVersion !== '1.2.0') {\n schemaErrors.push(`Expected protocolVersion \"1.2.0\", got \"${snapshot.protocolVersion}\"`);\n }\n\n if (snapshot.executionSurface !== 'ai') {\n schemaErrors.push(`Expected executionSurface \"ai\", got \"${snapshot.executionSurface}\"`);\n }\n\n if (!snapshot.executionId || typeof snapshot.executionId !== 'string') {\n schemaErrors.push('executionId must be a non-empty string');\n }\n\n if (!snapshot.timestamp || typeof snapshot.timestamp !== 'string') {\n schemaErrors.push('timestamp must be a non-empty string');\n }\n\n if (!snapshot.provider || typeof snapshot.provider !== 'string') {\n schemaErrors.push('provider must be a non-empty string');\n }\n\n if (!snapshot.model || typeof snapshot.model !== 'string') {\n schemaErrors.push('model must be a non-empty string');\n }\n\n if (!snapshot.prompt || typeof snapshot.prompt !== 'string') {\n schemaErrors.push('prompt must be a non-empty string');\n }\n\n if (snapshot.input === undefined || snapshot.input === null) {\n schemaErrors.push('input must be a string or object');\n }\n\n if (snapshot.output === undefined || snapshot.output === null) {\n schemaErrors.push('output must be a string or object');\n }\n\n const paramErrors = validateParameters(snapshot.parameters);\n schemaErrors.push(...paramErrors);\n\n if (!snapshot.inputHash || !snapshot.inputHash.startsWith('sha256:')) {\n formatErrors.push(`inputHash must start with \"sha256:\", got \"${snapshot.inputHash}\"`);\n }\n\n if (!snapshot.outputHash || !snapshot.outputHash.startsWith('sha256:')) {\n formatErrors.push(`outputHash must start with \"sha256:\", got \"${snapshot.outputHash}\"`);\n }\n\n if (formatErrors.length === 0) {\n const expectedInputHash = computeInputHash(snapshot.input);\n if (snapshot.inputHash !== expectedInputHash) {\n inputHashErrors.push(`inputHash mismatch: expected ${expectedInputHash}, got ${snapshot.inputHash}`);\n }\n\n const expectedOutputHash = computeOutputHash(snapshot.output);\n if (snapshot.outputHash !== expectedOutputHash) {\n outputHashErrors.push(`outputHash mismatch: expected ${expectedOutputHash}, got ${snapshot.outputHash}`);\n }\n }\n\n const errors = [...schemaErrors, ...formatErrors, ...inputHashErrors, ...outputHashErrors];\n\n if (errors.length === 0) {\n return { ok: true, errors: [], code: CerVerifyCode.OK };\n }\n\n let code: typeof CerVerifyCode[keyof typeof CerVerifyCode];\n let details: string[];\n\n if (schemaErrors.length > 0) {\n code = CerVerifyCode.SCHEMA_ERROR;\n details = schemaErrors;\n } else if (formatErrors.length > 0) {\n code = CerVerifyCode.INVALID_SHA256_FORMAT;\n details = formatErrors;\n } else if (inputHashErrors.length > 0 && outputHashErrors.length > 0) {\n code = CerVerifyCode.SNAPSHOT_HASH_MISMATCH;\n details = [...inputHashErrors, ...outputHashErrors];\n } else if (inputHashErrors.length > 0) {\n code = CerVerifyCode.INPUT_HASH_MISMATCH;\n details = inputHashErrors;\n } else if (outputHashErrors.length > 0) {\n code = CerVerifyCode.OUTPUT_HASH_MISMATCH;\n details = outputHashErrors;\n } else {\n code = CerVerifyCode.UNKNOWN_ERROR;\n details = errors;\n }\n\n return { ok: false, errors, code, details };\n}\n","import type { AiExecutionSnapshotV1, CerAiExecutionBundle, CerMeta, VerificationResult } from './types.js';\nimport { CerVerifyCode } from './types.js';\nimport { toCanonicalJson } from './canonicalJson.js';\nimport { sha256Hex } from './hash.js';\nimport { verifySnapshot } from './snapshot.js';\n\ninterface CertificatePayload {\n bundleType: 'cer.ai.execution.v1';\n createdAt: string;\n snapshot: AiExecutionSnapshotV1;\n version: '0.1';\n}\n\nfunction computeCertificateHash(payload: CertificatePayload): string {\n const canonical = toCanonicalJson(payload);\n return `sha256:${sha256Hex(canonical)}`;\n}\n\nexport function sealCer(\n snapshot: AiExecutionSnapshotV1,\n options?: { createdAt?: string; meta?: CerMeta }\n): CerAiExecutionBundle {\n const createdAt = options?.createdAt ?? new Date().toISOString();\n\n const payload: CertificatePayload = {\n bundleType: 'cer.ai.execution.v1',\n createdAt,\n snapshot,\n version: '0.1',\n };\n\n const certificateHash = computeCertificateHash(payload);\n\n const bundle: CerAiExecutionBundle = {\n bundleType: 'cer.ai.execution.v1',\n certificateHash,\n createdAt,\n version: '0.1',\n snapshot,\n };\n\n if (options?.meta) {\n bundle.meta = options.meta;\n }\n\n return bundle;\n}\n\nexport function verifyCer(bundle: CerAiExecutionBundle): VerificationResult {\n const schemaErrors: string[] = [];\n const formatErrors: string[] = [];\n\n if (bundle.bundleType !== 'cer.ai.execution.v1') {\n schemaErrors.push(`Expected bundleType \"cer.ai.execution.v1\", got \"${bundle.bundleType}\"`);\n }\n\n if (bundle.version !== '0.1') {\n schemaErrors.push(`Expected version \"0.1\", got \"${bundle.version}\"`);\n }\n\n if (!bundle.createdAt || typeof bundle.createdAt !== 'string') {\n schemaErrors.push('createdAt must be a non-empty string');\n }\n\n if (!bundle.certificateHash || !bundle.certificateHash.startsWith('sha256:')) {\n formatErrors.push(`certificateHash must start with \"sha256:\", got \"${bundle.certificateHash}\"`);\n }\n\n if (!bundle.snapshot) {\n schemaErrors.push('snapshot is required');\n const allErrors = [...schemaErrors, ...formatErrors];\n return { ok: false, errors: allErrors, code: CerVerifyCode.SCHEMA_ERROR, details: schemaErrors };\n }\n\n let canonicalizationError: string | null = null;\n let snapshotResult: VerificationResult | null = null;\n\n try {\n snapshotResult = verifySnapshot(bundle.snapshot);\n } catch (err) {\n canonicalizationError = err instanceof Error ? err.message : String(err);\n }\n\n if (canonicalizationError !== null) {\n const errors = [...schemaErrors, ...formatErrors, canonicalizationError];\n return { ok: false, errors, code: CerVerifyCode.CANONICALIZATION_ERROR, details: [canonicalizationError] };\n }\n\n const snapshotErrors = snapshotResult!.errors;\n\n const certHashErrors: string[] = [];\n try {\n const payload: CertificatePayload = {\n bundleType: 'cer.ai.execution.v1',\n createdAt: bundle.createdAt,\n snapshot: bundle.snapshot,\n version: '0.1',\n };\n const expectedHash = computeCertificateHash(payload);\n if (bundle.certificateHash !== expectedHash) {\n certHashErrors.push(`certificateHash mismatch: expected ${expectedHash}, got ${bundle.certificateHash}`);\n }\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n const errors = [...schemaErrors, ...formatErrors, ...snapshotErrors, msg];\n return { ok: false, errors, code: CerVerifyCode.CANONICALIZATION_ERROR, details: [msg] };\n }\n\n const errors = [...schemaErrors, ...formatErrors, ...snapshotErrors, ...certHashErrors];\n\n if (errors.length === 0) {\n return { ok: true, errors: [], code: CerVerifyCode.OK };\n }\n\n let code: typeof CerVerifyCode[keyof typeof CerVerifyCode];\n let details: string[];\n\n if (schemaErrors.length > 0) {\n code = CerVerifyCode.SCHEMA_ERROR;\n details = schemaErrors;\n } else if (formatErrors.length > 0) {\n code = CerVerifyCode.INVALID_SHA256_FORMAT;\n details = formatErrors;\n } else if (certHashErrors.length > 0 && snapshotErrors.length === 0) {\n code = CerVerifyCode.CERTIFICATE_HASH_MISMATCH;\n details = certHashErrors;\n } else if (snapshotResult && snapshotResult.code !== CerVerifyCode.OK) {\n code = snapshotResult.code;\n details = snapshotResult.details ?? snapshotErrors;\n } else if (certHashErrors.length > 0) {\n code = CerVerifyCode.CERTIFICATE_HASH_MISMATCH;\n details = certHashErrors;\n } else {\n code = CerVerifyCode.UNKNOWN_ERROR;\n details = errors;\n }\n\n return { ok: false, errors, code, details };\n}\n"],"mappings":";AAAA,YAAYA,aAAY;;;ACAxB,YAAY,YAAY;;;ACAjB,SAAS,gBAAgB,OAAwB;AACtD,SAAO,aAAa,KAAK;AAC3B;AAEA,SAAS,aAAa,OAAwB;AAC5C,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,WAAW;AAC9B,WAAO,QAAQ,SAAS;AAAA,EAC1B;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,oDAAoD,KAAK,EAAE;AAAA,IAC7E;AACA,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,UAAM,QAAQ,MAAM,IAAI,UAAQ,aAAa,IAAI,CAAC;AAClD,WAAO,MAAM,MAAM,KAAK,GAAG,IAAI;AAAA,EACjC;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,MAAM;AACZ,UAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,UAAM,UAAU,KAAK,IAAI,SAAO;AAC9B,YAAM,MAAM,IAAI,GAAG;AACnB,UAAI,QAAQ,QAAW;AACrB,eAAO;AAAA,MACT;AACA,aAAO,KAAK,UAAU,GAAG,IAAI,MAAM,aAAa,GAAG;AAAA,IACrD,CAAC,EAAE,OAAO,OAAK,MAAM,IAAI;AACzB,WAAO,MAAM,QAAQ,KAAK,GAAG,IAAI;AAAA,EACnC;AAEA,QAAM,IAAI,MAAM,wCAAwC,OAAO,KAAK,EAAE;AACxE;;;ADxCO,SAAS,UAAU,MAAmC;AAC3D,QAAM,OAAc,kBAAW,QAAQ;AACvC,MAAI,OAAO,SAAS,UAAU;AAC5B,SAAK,OAAO,MAAM,OAAO;AAAA,EAC3B,OAAO;AACL,SAAK,OAAO,IAAI;AAAA,EAClB;AACA,SAAO,KAAK,OAAO,KAAK;AAC1B;AAEO,SAAS,SAAS,OAAuB;AAC9C,SAAO,UAAU,UAAU,KAAK,CAAC;AACnC;AAEO,SAAS,kBAAkB,OAAwB;AACxD,QAAM,YAAY,gBAAgB,KAAK;AACvC,SAAO,UAAU,UAAU,SAAS,CAAC;AACvC;AAEO,SAAS,iBAAiB,OAAiD;AAChF,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,KAAK;AAAA,EACvB;AACA,SAAO,kBAAkB,KAAK;AAChC;AAEO,SAAS,kBAAkB,QAAkD;AAClF,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,SAAS,MAAM;AAAA,EACxB;AACA,SAAO,kBAAkB,MAAM;AACjC;;;AE9BA,IAAM,kBAAkB;AAExB,SAAS,mBAAmB,QAAyC;AACnE,QAAM,SAAmB,CAAC;AAE1B,MAAI,OAAO,OAAO,gBAAgB,YAAY,CAAC,OAAO,SAAS,OAAO,WAAW,GAAG;AAClF,WAAO,KAAK,wDAAwD,OAAO,WAAW,EAAE;AAAA,EAC1F;AAEA,MAAI,OAAO,OAAO,cAAc,YAAY,CAAC,OAAO,SAAS,OAAO,SAAS,GAAG;AAC9E,WAAO,KAAK,sDAAsD,OAAO,SAAS,EAAE;AAAA,EACtF;AAEA,MAAI,OAAO,SAAS,SAAS,OAAO,OAAO,SAAS,YAAY,CAAC,OAAO,SAAS,OAAO,IAAI,IAAI;AAC9F,WAAO,KAAK,yDAAyD,OAAO,IAAI,EAAE;AAAA,EACpF;AAEA,MAAI,OAAO,SAAS,SAAS,OAAO,OAAO,SAAS,YAAY,CAAC,OAAO,SAAS,OAAO,IAAI,IAAI;AAC9F,WAAO,KAAK,yDAAyD,OAAO,IAAI,EAAE;AAAA,EACpF;AAEA,SAAO;AACT;AAEO,SAAS,eAAe,QAAqD;AAClF,QAAM,cAAc,mBAAmB,OAAO,UAAU;AACxD,MAAI,YAAY,SAAS,GAAG;AAC1B,UAAM,IAAI,MAAM,uBAAuB,YAAY,KAAK,IAAI,CAAC,EAAE;AAAA,EACjE;AAEA,QAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,QAAM,aAAa,kBAAkB,OAAO,MAAM;AAElD,QAAM,WAAkC;AAAA,IACtC,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,IAClB,aAAa,OAAO;AAAA,IACpB,WAAW,OAAO,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,IACtD,UAAU,OAAO;AAAA,IACjB,OAAO,OAAO;AAAA,IACd,cAAc,OAAO,gBAAgB;AAAA,IACrC,QAAQ,OAAO;AAAA,IACf,OAAO,OAAO;AAAA,IACd;AAAA,IACA,YAAY;AAAA,MACV,aAAa,OAAO,WAAW;AAAA,MAC/B,WAAW,OAAO,WAAW;AAAA,MAC7B,MAAM,OAAO,WAAW,QAAQ;AAAA,MAChC,MAAM,OAAO,WAAW,QAAQ;AAAA,IAClC;AAAA,IACA,QAAQ,OAAO;AAAA,IACf;AAAA,IACA,YAAY,OAAO,cAAc;AAAA,IACjC,OAAO,OAAO,SAAS;AAAA,EACzB;AAEA,MAAI,OAAO,UAAU,OAAW,UAAS,QAAQ,OAAO,SAAS;AACjE,MAAI,OAAO,WAAW,OAAW,UAAS,SAAS,OAAO,UAAU;AACpE,MAAI,OAAO,cAAc,OAAW,UAAS,YAAY,OAAO,aAAa;AAC7E,MAAI,OAAO,eAAe,OAAW,UAAS,aAAa,OAAO,cAAc;AAChF,MAAI,OAAO,mBAAmB,OAAW,UAAS,iBAAiB,OAAO,kBAAkB;AAC5F,MAAI,OAAO,iBAAiB,OAAW,UAAS,eAAe,OAAO,gBAAgB;AAEtF,SAAO;AACT;;;ACxDA,SAAS,uBAAuB,SAAqC;AACnE,QAAM,YAAY,gBAAgB,OAAO;AACzC,SAAO,UAAU,UAAU,SAAS,CAAC;AACvC;AAEO,SAAS,QACd,UACA,SACsB;AACtB,QAAM,YAAY,SAAS,cAAa,oBAAI,KAAK,GAAE,YAAY;AAE/D,QAAM,UAA8B;AAAA,IAClC,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,uBAAuB,OAAO;AAEtD,QAAM,SAA+B;AAAA,IACnC,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AAEA,MAAI,SAAS,MAAM;AACjB,WAAO,OAAO,QAAQ;AAAA,EACxB;AAEA,SAAO;AACT;;;AJrCO,SAAS,aACd,QACA;AACA,SAAO;AAAA,IACL,MAAM,QAAQ,QAA6F;AACzG,YAAM,MAAM,MAAM,OAAO,OAAO,OAAO,aAAa;AACpD,YAAM,SAAS,OAAO,cAAc,GAAG;AACvC,YAAM,eAAe,OAAO,sBACxB,OAAO,oBAAoB,GAAG,IAC7B,OAAO,gBAAgB;AAE5B,YAAM,WAAW,eAAe;AAAA,QAC9B,aAAa,OAAO,eAAsB,mBAAW;AAAA,QACrD,UAAU,OAAO;AAAA,QACjB,OAAO,OAAO;AAAA,QACd;AAAA,QACA,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,YAAY,OAAO;AAAA,QACnB;AAAA,QACA,OAAO,OAAO;AAAA,MAChB,CAAC;AAED,YAAM,SAAS,QAAQ,UAAU,EAAE,MAAM,OAAO,KAAK,CAAC;AAEtD,aAAO,EAAE,QAAQ,UAAU,OAAO;AAAA,IACpC;AAAA,EACF;AACF;","names":["crypto"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
interface AiExecutionParameters {
|
|
2
2
|
temperature: number;
|
|
3
3
|
maxTokens: number;
|
|
4
4
|
topP: number | null;
|
|
5
5
|
seed: number | null;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface AiExecutionSnapshotV1 {
|
|
8
8
|
type: 'ai.execution.v1';
|
|
9
9
|
protocolVersion: '1.2.0';
|
|
10
10
|
executionSurface: 'ai';
|
|
@@ -28,12 +28,12 @@ export interface AiExecutionSnapshotV1 {
|
|
|
28
28
|
conversationId?: string | null;
|
|
29
29
|
prevStepHash?: string | null;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
interface CerMeta {
|
|
32
32
|
source?: string;
|
|
33
33
|
tags?: string[];
|
|
34
34
|
[key: string]: unknown;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface CerAiExecutionBundle {
|
|
37
37
|
bundleType: 'cer.ai.execution.v1';
|
|
38
38
|
certificateHash: string;
|
|
39
39
|
createdAt: string;
|
|
@@ -41,11 +41,25 @@ export interface CerAiExecutionBundle {
|
|
|
41
41
|
snapshot: AiExecutionSnapshotV1;
|
|
42
42
|
meta?: CerMeta;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
declare const CerVerifyCode: {
|
|
45
|
+
readonly OK: "OK";
|
|
46
|
+
readonly CERTIFICATE_HASH_MISMATCH: "CERTIFICATE_HASH_MISMATCH";
|
|
47
|
+
readonly SNAPSHOT_HASH_MISMATCH: "SNAPSHOT_HASH_MISMATCH";
|
|
48
|
+
readonly INPUT_HASH_MISMATCH: "INPUT_HASH_MISMATCH";
|
|
49
|
+
readonly OUTPUT_HASH_MISMATCH: "OUTPUT_HASH_MISMATCH";
|
|
50
|
+
readonly INVALID_SHA256_FORMAT: "INVALID_SHA256_FORMAT";
|
|
51
|
+
readonly CANONICALIZATION_ERROR: "CANONICALIZATION_ERROR";
|
|
52
|
+
readonly SCHEMA_ERROR: "SCHEMA_ERROR";
|
|
53
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
54
|
+
};
|
|
55
|
+
type CerVerifyCode = typeof CerVerifyCode[keyof typeof CerVerifyCode];
|
|
56
|
+
interface VerificationResult {
|
|
45
57
|
ok: boolean;
|
|
46
58
|
errors: string[];
|
|
59
|
+
code: CerVerifyCode;
|
|
60
|
+
details?: string[];
|
|
47
61
|
}
|
|
48
|
-
|
|
62
|
+
interface CreateSnapshotParams {
|
|
49
63
|
executionId: string;
|
|
50
64
|
timestamp?: string;
|
|
51
65
|
provider: string;
|
|
@@ -64,7 +78,7 @@ export interface CreateSnapshotParams {
|
|
|
64
78
|
conversationId?: string | null;
|
|
65
79
|
prevStepHash?: string | null;
|
|
66
80
|
}
|
|
67
|
-
|
|
81
|
+
interface AttestationResult {
|
|
68
82
|
ok: boolean;
|
|
69
83
|
attestationId?: string;
|
|
70
84
|
nodeRuntimeHash?: string;
|
|
@@ -73,12 +87,12 @@ export interface AttestationResult {
|
|
|
73
87
|
errors?: string[];
|
|
74
88
|
raw?: unknown;
|
|
75
89
|
}
|
|
76
|
-
|
|
90
|
+
interface AttestOptions {
|
|
77
91
|
nodeUrl: string;
|
|
78
92
|
apiKey: string;
|
|
79
93
|
timeoutMs?: number;
|
|
80
94
|
}
|
|
81
|
-
|
|
95
|
+
interface CertifyDecisionParams {
|
|
82
96
|
executionId?: string;
|
|
83
97
|
timestamp?: string;
|
|
84
98
|
provider: string;
|
|
@@ -98,13 +112,13 @@ export interface CertifyDecisionParams {
|
|
|
98
112
|
conversationId?: string | null;
|
|
99
113
|
prevStepHash?: string | null;
|
|
100
114
|
}
|
|
101
|
-
|
|
115
|
+
interface RunBuilderOptions {
|
|
102
116
|
runId?: string;
|
|
103
117
|
workflowId?: string | null;
|
|
104
118
|
conversationId?: string | null;
|
|
105
119
|
appId?: string | null;
|
|
106
120
|
}
|
|
107
|
-
|
|
121
|
+
interface StepParams {
|
|
108
122
|
stepId?: string;
|
|
109
123
|
provider: string;
|
|
110
124
|
model: string;
|
|
@@ -116,7 +130,7 @@ export interface StepParams {
|
|
|
116
130
|
timestamp?: string;
|
|
117
131
|
meta?: CerMeta;
|
|
118
132
|
}
|
|
119
|
-
|
|
133
|
+
interface RunSummary {
|
|
120
134
|
runId: string;
|
|
121
135
|
workflowId: string | null;
|
|
122
136
|
conversationId: string | null;
|
|
@@ -130,13 +144,13 @@ export interface RunSummary {
|
|
|
130
144
|
}>;
|
|
131
145
|
finalStepHash: string | null;
|
|
132
146
|
}
|
|
133
|
-
|
|
147
|
+
interface ProviderConfig<TInput = unknown, TOutput = unknown> {
|
|
134
148
|
provider: string;
|
|
135
149
|
callFn: (input: TInput) => Promise<TOutput>;
|
|
136
150
|
extractOutput: (raw: TOutput) => string | Record<string, unknown>;
|
|
137
151
|
extractModelVersion?: (raw: TOutput) => string | null;
|
|
138
152
|
}
|
|
139
|
-
|
|
153
|
+
interface WrappedExecutionParams {
|
|
140
154
|
prompt: string;
|
|
141
155
|
input: string | Record<string, unknown>;
|
|
142
156
|
model: string;
|
|
@@ -146,9 +160,10 @@ export interface WrappedExecutionParams {
|
|
|
146
160
|
meta?: CerMeta;
|
|
147
161
|
executionId?: string;
|
|
148
162
|
}
|
|
149
|
-
|
|
163
|
+
interface WrappedExecutionResult {
|
|
150
164
|
output: string | Record<string, unknown>;
|
|
151
165
|
snapshot: AiExecutionSnapshotV1;
|
|
152
166
|
bundle: CerAiExecutionBundle;
|
|
153
167
|
}
|
|
154
|
-
|
|
168
|
+
|
|
169
|
+
export { type AiExecutionSnapshotV1 as A, type CreateSnapshotParams as C, type ProviderConfig as P, type RunBuilderOptions as R, type StepParams as S, type VerificationResult as V, type WrappedExecutionParams as W, type CerMeta as a, type CerAiExecutionBundle as b, type CertifyDecisionParams as c, type RunSummary as d, type AttestOptions as e, type AttestationResult as f, CerVerifyCode as g, type AiExecutionParameters as h, type WrappedExecutionResult as i };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
interface AiExecutionParameters {
|
|
2
|
+
temperature: number;
|
|
3
|
+
maxTokens: number;
|
|
4
|
+
topP: number | null;
|
|
5
|
+
seed: number | null;
|
|
6
|
+
}
|
|
7
|
+
interface AiExecutionSnapshotV1 {
|
|
8
|
+
type: 'ai.execution.v1';
|
|
9
|
+
protocolVersion: '1.2.0';
|
|
10
|
+
executionSurface: 'ai';
|
|
11
|
+
executionId: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
provider: string;
|
|
14
|
+
model: string;
|
|
15
|
+
modelVersion: string | null;
|
|
16
|
+
prompt: string;
|
|
17
|
+
input: string | Record<string, unknown>;
|
|
18
|
+
inputHash: string;
|
|
19
|
+
parameters: AiExecutionParameters;
|
|
20
|
+
output: string | Record<string, unknown>;
|
|
21
|
+
outputHash: string;
|
|
22
|
+
sdkVersion: string | null;
|
|
23
|
+
appId: string | null;
|
|
24
|
+
runId?: string | null;
|
|
25
|
+
stepId?: string | null;
|
|
26
|
+
stepIndex?: number | null;
|
|
27
|
+
workflowId?: string | null;
|
|
28
|
+
conversationId?: string | null;
|
|
29
|
+
prevStepHash?: string | null;
|
|
30
|
+
}
|
|
31
|
+
interface CerMeta {
|
|
32
|
+
source?: string;
|
|
33
|
+
tags?: string[];
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
interface CerAiExecutionBundle {
|
|
37
|
+
bundleType: 'cer.ai.execution.v1';
|
|
38
|
+
certificateHash: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
version: '0.1';
|
|
41
|
+
snapshot: AiExecutionSnapshotV1;
|
|
42
|
+
meta?: CerMeta;
|
|
43
|
+
}
|
|
44
|
+
declare const CerVerifyCode: {
|
|
45
|
+
readonly OK: "OK";
|
|
46
|
+
readonly CERTIFICATE_HASH_MISMATCH: "CERTIFICATE_HASH_MISMATCH";
|
|
47
|
+
readonly SNAPSHOT_HASH_MISMATCH: "SNAPSHOT_HASH_MISMATCH";
|
|
48
|
+
readonly INPUT_HASH_MISMATCH: "INPUT_HASH_MISMATCH";
|
|
49
|
+
readonly OUTPUT_HASH_MISMATCH: "OUTPUT_HASH_MISMATCH";
|
|
50
|
+
readonly INVALID_SHA256_FORMAT: "INVALID_SHA256_FORMAT";
|
|
51
|
+
readonly CANONICALIZATION_ERROR: "CANONICALIZATION_ERROR";
|
|
52
|
+
readonly SCHEMA_ERROR: "SCHEMA_ERROR";
|
|
53
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
54
|
+
};
|
|
55
|
+
type CerVerifyCode = typeof CerVerifyCode[keyof typeof CerVerifyCode];
|
|
56
|
+
interface VerificationResult {
|
|
57
|
+
ok: boolean;
|
|
58
|
+
errors: string[];
|
|
59
|
+
code: CerVerifyCode;
|
|
60
|
+
details?: string[];
|
|
61
|
+
}
|
|
62
|
+
interface CreateSnapshotParams {
|
|
63
|
+
executionId: string;
|
|
64
|
+
timestamp?: string;
|
|
65
|
+
provider: string;
|
|
66
|
+
model: string;
|
|
67
|
+
modelVersion?: string | null;
|
|
68
|
+
prompt: string;
|
|
69
|
+
input: string | Record<string, unknown>;
|
|
70
|
+
parameters: AiExecutionParameters;
|
|
71
|
+
output: string | Record<string, unknown>;
|
|
72
|
+
sdkVersion?: string | null;
|
|
73
|
+
appId?: string | null;
|
|
74
|
+
runId?: string | null;
|
|
75
|
+
stepId?: string | null;
|
|
76
|
+
stepIndex?: number | null;
|
|
77
|
+
workflowId?: string | null;
|
|
78
|
+
conversationId?: string | null;
|
|
79
|
+
prevStepHash?: string | null;
|
|
80
|
+
}
|
|
81
|
+
interface AttestationResult {
|
|
82
|
+
ok: boolean;
|
|
83
|
+
attestationId?: string;
|
|
84
|
+
nodeRuntimeHash?: string;
|
|
85
|
+
certificateHash?: string;
|
|
86
|
+
protocolVersion?: string;
|
|
87
|
+
errors?: string[];
|
|
88
|
+
raw?: unknown;
|
|
89
|
+
}
|
|
90
|
+
interface AttestOptions {
|
|
91
|
+
nodeUrl: string;
|
|
92
|
+
apiKey: string;
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
}
|
|
95
|
+
interface CertifyDecisionParams {
|
|
96
|
+
executionId?: string;
|
|
97
|
+
timestamp?: string;
|
|
98
|
+
provider: string;
|
|
99
|
+
model: string;
|
|
100
|
+
modelVersion?: string | null;
|
|
101
|
+
prompt: string;
|
|
102
|
+
input: string | Record<string, unknown>;
|
|
103
|
+
parameters: AiExecutionParameters;
|
|
104
|
+
output: string | Record<string, unknown>;
|
|
105
|
+
sdkVersion?: string | null;
|
|
106
|
+
appId?: string | null;
|
|
107
|
+
meta?: CerMeta;
|
|
108
|
+
runId?: string | null;
|
|
109
|
+
stepId?: string | null;
|
|
110
|
+
stepIndex?: number | null;
|
|
111
|
+
workflowId?: string | null;
|
|
112
|
+
conversationId?: string | null;
|
|
113
|
+
prevStepHash?: string | null;
|
|
114
|
+
}
|
|
115
|
+
interface RunBuilderOptions {
|
|
116
|
+
runId?: string;
|
|
117
|
+
workflowId?: string | null;
|
|
118
|
+
conversationId?: string | null;
|
|
119
|
+
appId?: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface StepParams {
|
|
122
|
+
stepId?: string;
|
|
123
|
+
provider: string;
|
|
124
|
+
model: string;
|
|
125
|
+
modelVersion?: string | null;
|
|
126
|
+
prompt: string;
|
|
127
|
+
input: string | Record<string, unknown>;
|
|
128
|
+
parameters: AiExecutionParameters;
|
|
129
|
+
output: string | Record<string, unknown>;
|
|
130
|
+
timestamp?: string;
|
|
131
|
+
meta?: CerMeta;
|
|
132
|
+
}
|
|
133
|
+
interface RunSummary {
|
|
134
|
+
runId: string;
|
|
135
|
+
workflowId: string | null;
|
|
136
|
+
conversationId: string | null;
|
|
137
|
+
stepCount: number;
|
|
138
|
+
steps: Array<{
|
|
139
|
+
stepIndex: number;
|
|
140
|
+
stepId: string;
|
|
141
|
+
executionId: string;
|
|
142
|
+
certificateHash: string;
|
|
143
|
+
prevStepHash: string | null;
|
|
144
|
+
}>;
|
|
145
|
+
finalStepHash: string | null;
|
|
146
|
+
}
|
|
147
|
+
interface ProviderConfig<TInput = unknown, TOutput = unknown> {
|
|
148
|
+
provider: string;
|
|
149
|
+
callFn: (input: TInput) => Promise<TOutput>;
|
|
150
|
+
extractOutput: (raw: TOutput) => string | Record<string, unknown>;
|
|
151
|
+
extractModelVersion?: (raw: TOutput) => string | null;
|
|
152
|
+
}
|
|
153
|
+
interface WrappedExecutionParams {
|
|
154
|
+
prompt: string;
|
|
155
|
+
input: string | Record<string, unknown>;
|
|
156
|
+
model: string;
|
|
157
|
+
parameters: AiExecutionParameters;
|
|
158
|
+
modelVersion?: string | null;
|
|
159
|
+
appId?: string | null;
|
|
160
|
+
meta?: CerMeta;
|
|
161
|
+
executionId?: string;
|
|
162
|
+
}
|
|
163
|
+
interface WrappedExecutionResult {
|
|
164
|
+
output: string | Record<string, unknown>;
|
|
165
|
+
snapshot: AiExecutionSnapshotV1;
|
|
166
|
+
bundle: CerAiExecutionBundle;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { type AiExecutionSnapshotV1 as A, type CreateSnapshotParams as C, type ProviderConfig as P, type RunBuilderOptions as R, type StepParams as S, type VerificationResult as V, type WrappedExecutionParams as W, type CerMeta as a, type CerAiExecutionBundle as b, type CertifyDecisionParams as c, type RunSummary as d, type AttestOptions as e, type AttestationResult as f, CerVerifyCode as g, type AiExecutionParameters as h, type WrappedExecutionResult as i };
|
package/package.json
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexart/ai-execution",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "AI Execution Integrity — tamper-evident records and Certified Execution Records (CER) for AI operations",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
12
14
|
},
|
|
13
15
|
"./providers/openai": {
|
|
14
16
|
"types": "./dist/providers/openai.d.ts",
|
|
15
|
-
"import": "./dist/providers/openai.
|
|
17
|
+
"import": "./dist/providers/openai.mjs",
|
|
18
|
+
"require": "./dist/providers/openai.cjs"
|
|
16
19
|
},
|
|
17
20
|
"./providers/anthropic": {
|
|
18
21
|
"types": "./dist/providers/anthropic.d.ts",
|
|
19
|
-
"import": "./dist/providers/anthropic.
|
|
22
|
+
"import": "./dist/providers/anthropic.mjs",
|
|
23
|
+
"require": "./dist/providers/anthropic.cjs"
|
|
20
24
|
},
|
|
21
25
|
"./providers/wrap": {
|
|
22
26
|
"types": "./dist/providers/wrap.d.ts",
|
|
23
|
-
"import": "./dist/providers/wrap.
|
|
24
|
-
|
|
27
|
+
"import": "./dist/providers/wrap.mjs",
|
|
28
|
+
"require": "./dist/providers/wrap.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
25
31
|
},
|
|
26
32
|
"scripts": {
|
|
27
|
-
"build": "
|
|
28
|
-
"
|
|
29
|
-
"
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"build:tsc": "tsc",
|
|
35
|
+
"test": "tsc && node --test dist-tsc/__tests__/vectors.test.js dist-tsc/__tests__/fixtures.test.js dist-tsc/__tests__/v020.test.js dist-tsc/__tests__/v030.test.js dist-tsc/__tests__/v040.test.js dist-tsc/__tests__/v041.test.js",
|
|
36
|
+
"release": "npm run build && npm run test && npm version patch && npm publish --access public",
|
|
30
37
|
"prepublishOnly": "npm run build && npm run test"
|
|
31
38
|
},
|
|
32
39
|
"keywords": [
|
|
@@ -49,11 +56,11 @@
|
|
|
49
56
|
},
|
|
50
57
|
"files": [
|
|
51
58
|
"dist",
|
|
52
|
-
"!dist/__tests__",
|
|
53
59
|
"fixtures",
|
|
54
60
|
"README.md"
|
|
55
61
|
],
|
|
56
62
|
"devDependencies": {
|
|
63
|
+
"tsup": "^8.0.0",
|
|
57
64
|
"typescript": "^5.0.0"
|
|
58
65
|
}
|
|
59
66
|
}
|
package/dist/archive.d.ts
DELETED
package/dist/archive.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAKvD,wBAAgB,SAAS,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAwB5D"}
|
package/dist/archive.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { toCanonicalJson } from './canonicalJson.js';
|
|
2
|
-
import { verifyCer } from './cer.js';
|
|
3
|
-
import { CerVerificationError } from './errors.js';
|
|
4
|
-
export function exportCer(bundle) {
|
|
5
|
-
return toCanonicalJson(bundle);
|
|
6
|
-
}
|
|
7
|
-
export function importCer(json) {
|
|
8
|
-
let parsed;
|
|
9
|
-
try {
|
|
10
|
-
parsed = JSON.parse(json);
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
throw new CerVerificationError([`Invalid JSON: ${err.message}`]);
|
|
14
|
-
}
|
|
15
|
-
const bundle = parsed;
|
|
16
|
-
if (!bundle || typeof bundle !== 'object') {
|
|
17
|
-
throw new CerVerificationError(['Parsed value is not an object']);
|
|
18
|
-
}
|
|
19
|
-
if (bundle.bundleType !== 'cer.ai.execution.v1') {
|
|
20
|
-
throw new CerVerificationError([`Expected bundleType "cer.ai.execution.v1", got "${bundle.bundleType}"`]);
|
|
21
|
-
}
|
|
22
|
-
const result = verifyCer(bundle);
|
|
23
|
-
if (!result.ok) {
|
|
24
|
-
throw new CerVerificationError(result.errors);
|
|
25
|
-
}
|
|
26
|
-
return bundle;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=archive.js.map
|
package/dist/archive.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,UAAU,SAAS,CAAC,MAA4B;IACpD,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,oBAAoB,CAAC,CAAC,iBAAkB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,MAAM,GAAG,MAA8B,CAAC;IAE9C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,oBAAoB,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,KAAK,qBAAqB,EAAE,CAAC;QAChD,MAAM,IAAI,oBAAoB,CAAC,CAAC,mDAAmD,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAC5G,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/attest.d.ts
DELETED
package/dist/attest.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attest.d.ts","sourceRoot":"","sources":["../src/attest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAczF,wBAAsB,MAAM,CAC1B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,iBAAiB,CAAC,CA0F5B"}
|