@nexart/ai-execution 0.9.0 → 0.11.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/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, B as BundleDeclaration, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as SanitizeStorageOptions, h as AttestationReceipt, N as NodeKeysDocument, i as NodeReceiptVerifyResult, j as SignedAttestationReceipt, k as CerVerifyCode, l as AiefVerifyResult, T as ToolEvent, m as RunSummaryVerifyResult, n as AiefProfile } from './types-C5t12OK8.cjs';
2
- export { o as AiExecutionParameters, p as AttestationReceiptResult, q as ClientDefaults, r as NexArtClient, P as ProviderCallParams, s as ProviderCallResult, t as ProviderConfig, u as RedactionEnvelope, W as WrappedExecutionParams, v as WrappedExecutionResult } from './types-C5t12OK8.cjs';
1
+ import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, B as BundleDeclaration, b as CerContextSignal, c as CerAiExecutionBundle, d as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, e as RunSummary, f as AttestOptions, g as AttestationResult, h as SanitizeStorageOptions, i as AttestationReceipt, N as NodeKeysDocument, j as NodeReceiptVerifyResult, k as SignedAttestationReceipt, l as CerVerifyCode, m as AiefVerifyResult, T as ToolEvent, n as RunSummaryVerifyResult, o as AiefProfile } from './types-C_M2xSWK.cjs';
2
+ export { p as AiExecutionParameters, q as AttestationReceiptResult, r as CerContext, s as ClientDefaults, t as NexArtClient, P as ProviderCallParams, u as ProviderCallResult, v as ProviderConfig, w as RedactionEnvelope, W as WrappedExecutionParams, x as WrappedExecutionResult } from './types-C_M2xSWK.cjs';
3
3
  export { wrapProvider } from './providers/wrap.cjs';
4
+ export { AttestDecisionFn, LangChainAttestedResult, LangChainCerResult, LangChainCertificationInput, certifyLangChainRun, createLangChainCer } from './langchain.cjs';
4
5
 
5
6
  declare class CerVerificationError extends Error {
6
7
  readonly errors: string[];
@@ -28,6 +29,8 @@ declare function sealCer(snapshot: AiExecutionSnapshotV1, options?: {
28
29
  createdAt?: string;
29
30
  meta?: CerMeta;
30
31
  declaration?: BundleDeclaration;
32
+ /** v0.10.0 — upstream signals to bind as evidence. Included in certificateHash. */
33
+ signals?: CerContextSignal[];
31
34
  }): CerAiExecutionBundle;
32
35
  declare function verifyCer(bundle: CerAiExecutionBundle): VerificationResult;
33
36
 
@@ -565,4 +568,4 @@ interface CerVerificationResult {
565
568
  */
566
569
  declare function verifyAiCerBundleDetailed(bundle: unknown): CerVerificationResult;
567
570
 
568
- export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, type CerVerificationResult, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, type CheckStatus, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, ReasonCode, ReasonCode as ReasonCodeType, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, type VerificationStatus, type VerifyRunSummaryOptions, attest, attestIfNeeded, certifyAndAttestDecision, certifyAndAttestRun, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, exportVerifiableRedacted, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashToolOutput, hashUtf8, importCer, makeToolEvent, mapToAiefReason, redactBeforeSeal, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, validateProfile, verifyCer as verify, verifyAiCerBundleDetailed, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
571
+ export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerContextSignal, CerMeta, CerVerificationError, type CerVerificationResult, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, type CheckStatus, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, ReasonCode, ReasonCode as ReasonCodeType, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, type VerificationStatus, type VerifyRunSummaryOptions, attest, attestIfNeeded, certifyAndAttestDecision, certifyAndAttestRun, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, exportVerifiableRedacted, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashToolOutput, hashUtf8, importCer, makeToolEvent, mapToAiefReason, redactBeforeSeal, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, validateProfile, verifyCer as verify, verifyAiCerBundleDetailed, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, B as BundleDeclaration, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as SanitizeStorageOptions, h as AttestationReceipt, N as NodeKeysDocument, i as NodeReceiptVerifyResult, j as SignedAttestationReceipt, k as CerVerifyCode, l as AiefVerifyResult, T as ToolEvent, m as RunSummaryVerifyResult, n as AiefProfile } from './types-C5t12OK8.js';
2
- export { o as AiExecutionParameters, p as AttestationReceiptResult, q as ClientDefaults, r as NexArtClient, P as ProviderCallParams, s as ProviderCallResult, t as ProviderConfig, u as RedactionEnvelope, W as WrappedExecutionParams, v as WrappedExecutionResult } from './types-C5t12OK8.js';
1
+ import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, B as BundleDeclaration, b as CerContextSignal, c as CerAiExecutionBundle, d as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, e as RunSummary, f as AttestOptions, g as AttestationResult, h as SanitizeStorageOptions, i as AttestationReceipt, N as NodeKeysDocument, j as NodeReceiptVerifyResult, k as SignedAttestationReceipt, l as CerVerifyCode, m as AiefVerifyResult, T as ToolEvent, n as RunSummaryVerifyResult, o as AiefProfile } from './types-C_M2xSWK.js';
2
+ export { p as AiExecutionParameters, q as AttestationReceiptResult, r as CerContext, s as ClientDefaults, t as NexArtClient, P as ProviderCallParams, u as ProviderCallResult, v as ProviderConfig, w as RedactionEnvelope, W as WrappedExecutionParams, x as WrappedExecutionResult } from './types-C_M2xSWK.js';
3
3
  export { wrapProvider } from './providers/wrap.js';
4
+ export { AttestDecisionFn, LangChainAttestedResult, LangChainCerResult, LangChainCertificationInput, certifyLangChainRun, createLangChainCer } from './langchain.js';
4
5
 
5
6
  declare class CerVerificationError extends Error {
6
7
  readonly errors: string[];
@@ -28,6 +29,8 @@ declare function sealCer(snapshot: AiExecutionSnapshotV1, options?: {
28
29
  createdAt?: string;
29
30
  meta?: CerMeta;
30
31
  declaration?: BundleDeclaration;
32
+ /** v0.10.0 — upstream signals to bind as evidence. Included in certificateHash. */
33
+ signals?: CerContextSignal[];
31
34
  }): CerAiExecutionBundle;
32
35
  declare function verifyCer(bundle: CerAiExecutionBundle): VerificationResult;
33
36
 
@@ -565,4 +568,4 @@ interface CerVerificationResult {
565
568
  */
566
569
  declare function verifyAiCerBundleDetailed(bundle: unknown): CerVerificationResult;
567
570
 
568
- export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, type CerVerificationResult, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, type CheckStatus, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, ReasonCode, ReasonCode as ReasonCodeType, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, type VerificationStatus, type VerifyRunSummaryOptions, attest, attestIfNeeded, certifyAndAttestDecision, certifyAndAttestRun, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, exportVerifiableRedacted, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashToolOutput, hashUtf8, importCer, makeToolEvent, mapToAiefReason, redactBeforeSeal, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, validateProfile, verifyCer as verify, verifyAiCerBundleDetailed, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
571
+ export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerContextSignal, CerMeta, CerVerificationError, type CerVerificationResult, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, type CheckStatus, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, ReasonCode, ReasonCode as ReasonCodeType, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, type VerificationStatus, type VerifyRunSummaryOptions, attest, attestIfNeeded, certifyAndAttestDecision, certifyAndAttestRun, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, exportVerifiableRedacted, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashToolOutput, hashUtf8, importCer, makeToolEvent, mapToAiefReason, redactBeforeSeal, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, validateProfile, verifyCer as verify, verifyAiCerBundleDetailed, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
package/dist/index.mjs CHANGED
@@ -258,14 +258,22 @@ function computeCertificateHash(payload) {
258
258
  const canonical = toCanonicalJson(payload);
259
259
  return `sha256:${sha256Hex(canonical)}`;
260
260
  }
261
+ function buildContext(signals) {
262
+ if (!signals || signals.length === 0) return void 0;
263
+ return { signals };
264
+ }
261
265
  function sealCer(snapshot, options) {
262
266
  const createdAt = options?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
267
+ const context = buildContext(options?.signals);
263
268
  const payload = {
264
269
  bundleType: "cer.ai.execution.v1",
265
270
  createdAt,
266
271
  snapshot,
267
272
  version: "0.1"
268
273
  };
274
+ if (context) {
275
+ payload.context = context;
276
+ }
269
277
  const certificateHash = computeCertificateHash(payload);
270
278
  const bundle = {
271
279
  bundleType: "cer.ai.execution.v1",
@@ -274,6 +282,9 @@ function sealCer(snapshot, options) {
274
282
  version: "0.1",
275
283
  snapshot
276
284
  };
285
+ if (context) {
286
+ bundle.context = context;
287
+ }
277
288
  if (options?.meta) {
278
289
  bundle.meta = options.meta;
279
290
  }
@@ -322,6 +333,10 @@ function verifyCer(bundle) {
322
333
  snapshot: bundle.snapshot,
323
334
  version: "0.1"
324
335
  };
336
+ const verifyContext = buildContext(bundle.context?.signals);
337
+ if (verifyContext) {
338
+ payload.context = verifyContext;
339
+ }
325
340
  const expectedHash = computeCertificateHash(payload);
326
341
  if (bundle.certificateHash !== expectedHash) {
327
342
  certHashErrors.push(`certificateHash mismatch: expected ${expectedHash}, got ${bundle.certificateHash}`);
@@ -382,7 +397,11 @@ function certifyDecision(params) {
382
397
  conversationId: params.conversationId,
383
398
  prevStepHash: params.prevStepHash
384
399
  });
385
- return sealCer(snapshot, { createdAt: params.createdAt, meta: params.meta });
400
+ return sealCer(snapshot, {
401
+ createdAt: params.createdAt,
402
+ meta: params.meta,
403
+ signals: params.signals
404
+ });
386
405
  }
387
406
 
388
407
  // src/run.ts
@@ -2543,6 +2562,100 @@ function verifyAiCerBundleDetailed(bundle) {
2543
2562
  verifier
2544
2563
  };
2545
2564
  }
2565
+
2566
+ // src/langchain.ts
2567
+ import * as crypto6 from "crypto";
2568
+ function normalizeCerValue(value) {
2569
+ if (typeof value === "string") return value;
2570
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
2571
+ return value;
2572
+ }
2573
+ if (Array.isArray(value)) return { items: value };
2574
+ return String(value);
2575
+ }
2576
+ function extractPrompt(input, metadata) {
2577
+ if (typeof metadata?.prompt === "string" && metadata.prompt.length > 0) {
2578
+ return metadata.prompt;
2579
+ }
2580
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) {
2581
+ const obj = input;
2582
+ if (Array.isArray(obj.messages) && obj.messages.length > 0) {
2583
+ const first = obj.messages[0];
2584
+ if (typeof first?.content === "string" && first.content.length > 0) {
2585
+ return first.content;
2586
+ }
2587
+ }
2588
+ if (typeof obj.prompt === "string" && obj.prompt.length > 0) return obj.prompt;
2589
+ if (typeof obj.text === "string" && obj.text.length > 0) return obj.text;
2590
+ }
2591
+ if (typeof input === "string" && input.length > 0) return input;
2592
+ return "[LangChain run]";
2593
+ }
2594
+ function buildMeta(metadata) {
2595
+ if (!metadata || Object.keys(metadata).length === 0) return void 0;
2596
+ const reserved = /* @__PURE__ */ new Set(["prompt", "appId", "runId", "workflowId", "conversationId"]);
2597
+ const extraTags = [];
2598
+ for (const [k, v] of Object.entries(metadata)) {
2599
+ if (!reserved.has(k)) {
2600
+ extraTags.push(typeof v === "string" ? `${k}:${v}` : `${k}:${JSON.stringify(v)}`);
2601
+ }
2602
+ }
2603
+ return extraTags.length > 0 ? { tags: extraTags } : void 0;
2604
+ }
2605
+ function resolveParameters(params) {
2606
+ return {
2607
+ temperature: params?.temperature ?? 0,
2608
+ maxTokens: params?.maxTokens ?? 0,
2609
+ topP: params?.topP ?? null,
2610
+ seed: params?.seed ?? null
2611
+ };
2612
+ }
2613
+ function buildCertifyParams(input, executionId) {
2614
+ return {
2615
+ executionId,
2616
+ timestamp: input.timestamp,
2617
+ createdAt: input.createdAt,
2618
+ provider: input.provider,
2619
+ model: input.model,
2620
+ modelVersion: input.modelVersion ?? null,
2621
+ prompt: extractPrompt(input.input, input.metadata),
2622
+ input: normalizeCerValue(input.input),
2623
+ output: normalizeCerValue(input.output),
2624
+ parameters: resolveParameters(input.parameters),
2625
+ appId: typeof input.metadata?.appId === "string" ? input.metadata.appId : null,
2626
+ runId: typeof input.metadata?.runId === "string" ? input.metadata.runId : void 0,
2627
+ workflowId: typeof input.metadata?.workflowId === "string" ? input.metadata.workflowId : void 0,
2628
+ conversationId: typeof input.metadata?.conversationId === "string" ? input.metadata.conversationId : void 0,
2629
+ meta: buildMeta(input.metadata),
2630
+ signals: input.signals
2631
+ };
2632
+ }
2633
+ function createLangChainCer(input) {
2634
+ const executionId = input.executionId ?? crypto6.randomUUID();
2635
+ const bundle = certifyDecision(buildCertifyParams(input, executionId));
2636
+ return {
2637
+ bundle,
2638
+ certificateHash: bundle.certificateHash,
2639
+ executionId: bundle.snapshot.executionId
2640
+ };
2641
+ }
2642
+ function certifyLangChainRun(input, _options) {
2643
+ if (input.nodeUrl && input.apiKey) {
2644
+ const executionId = input.executionId ?? crypto6.randomUUID();
2645
+ const certifyParams = buildCertifyParams({ ...input, executionId }, executionId);
2646
+ const attestFn = _options?._attestFn ?? certifyAndAttestDecision;
2647
+ return attestFn(certifyParams, { nodeUrl: input.nodeUrl, apiKey: input.apiKey }).then(
2648
+ ({ bundle, receipt }) => ({
2649
+ bundle,
2650
+ receipt,
2651
+ certificateHash: bundle.certificateHash,
2652
+ executionId: bundle.snapshot.executionId,
2653
+ attested: true
2654
+ })
2655
+ );
2656
+ }
2657
+ return createLangChainCer(input);
2658
+ }
2546
2659
  export {
2547
2660
  CerAttestationError,
2548
2661
  CerVerificationError,
@@ -2555,9 +2668,11 @@ export {
2555
2668
  certifyAndAttestRun,
2556
2669
  certifyDecision,
2557
2670
  certifyDecisionFromProviderCall,
2671
+ certifyLangChainRun,
2558
2672
  computeInputHash,
2559
2673
  computeOutputHash,
2560
2674
  createClient,
2675
+ createLangChainCer,
2561
2676
  createSnapshot,
2562
2677
  exportCer,
2563
2678
  exportVerifiableRedacted,