@nexart/ai-execution 0.8.0 → 0.10.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-CcqCDPrD.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-CcqCDPrD.cjs';
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';
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[];
@@ -501,4 +502,68 @@ interface CertifyAndAttestRunResult {
501
502
  */
502
503
  declare function certifyAndAttestRun(steps: StepParams[], options?: CertifyAndAttestRunOptions): Promise<CertifyAndAttestRunResult>;
503
504
 
504
- export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, 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, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
505
+ /**
506
+ * CER Protocol verification types — v0.9.0
507
+ *
508
+ * These are the canonical structured verification types for the NexArt
509
+ * Certified Execution Record (CER) Protocol. All NexArt-compatible verifiers
510
+ * should produce a CerVerificationResult.
511
+ *
512
+ * NOTE: The existing VerificationResult type (ok/errors/code shape) is preserved
513
+ * for backward compatibility. CerVerificationResult is the new protocol-aligned type.
514
+ */
515
+ type VerificationStatus = 'VERIFIED' | 'FAILED' | 'NOT_FOUND';
516
+ type CheckStatus = 'PASS' | 'FAIL' | 'SKIPPED';
517
+ declare const ReasonCode: {
518
+ readonly BUNDLE_HASH_MISMATCH: "BUNDLE_HASH_MISMATCH";
519
+ readonly NODE_SIGNATURE_INVALID: "NODE_SIGNATURE_INVALID";
520
+ readonly NODE_SIGNATURE_MISSING: "NODE_SIGNATURE_MISSING";
521
+ readonly RECEIPT_HASH_MISMATCH: "RECEIPT_HASH_MISMATCH";
522
+ readonly SCHEMA_VERSION_UNSUPPORTED: "SCHEMA_VERSION_UNSUPPORTED";
523
+ readonly RECORD_NOT_FOUND: "RECORD_NOT_FOUND";
524
+ readonly BUNDLE_CORRUPTED: "BUNDLE_CORRUPTED";
525
+ };
526
+ type ReasonCode = typeof ReasonCode[keyof typeof ReasonCode];
527
+ /**
528
+ * Canonical protocol verification result.
529
+ *
530
+ * Produced by verifyAiCerBundleDetailed() and verifyCodeModeSnapshotDetailed().
531
+ * All checks that are not applicable to a given bundle type are SKIPPED (never FAIL).
532
+ */
533
+ interface CerVerificationResult {
534
+ status: VerificationStatus;
535
+ checks: {
536
+ bundleIntegrity: CheckStatus;
537
+ nodeSignature: CheckStatus;
538
+ receiptConsistency: CheckStatus;
539
+ };
540
+ reasonCodes: ReasonCode[];
541
+ certificateHash: string;
542
+ bundleType: string;
543
+ verifiedAt: string;
544
+ verifier: string;
545
+ }
546
+
547
+ /**
548
+ * verifyAiCerBundleDetailed — protocol-aligned AI CER verifier
549
+ *
550
+ * Returns a CerVerificationResult conforming to the CER Protocol spec.
551
+ * Wraps the existing verifyCer() + hasAttestation() helpers and maps
552
+ * their results into the structured protocol schema.
553
+ */
554
+
555
+ /**
556
+ * Verify a CER AI execution bundle and return a structured CerVerificationResult.
557
+ *
558
+ * - bundleIntegrity: PASS/FAIL based on certificateHash integrity
559
+ * - nodeSignature: PASS if attestation present and structurally valid; SKIPPED if absent
560
+ * - receiptConsistency: mirrors nodeSignature (SKIPPED when no attestation)
561
+ *
562
+ * Attestation is optional — its absence sets nodeSignature/receiptConsistency
563
+ * to SKIPPED, not FAIL.
564
+ *
565
+ * @param bundle - The raw CER bundle (typed as unknown for safety; validated internally)
566
+ */
567
+ declare function verifyAiCerBundleDetailed(bundle: unknown): CerVerificationResult;
568
+
569
+ 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 };
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-CcqCDPrD.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-CcqCDPrD.js';
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';
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[];
@@ -501,4 +502,68 @@ interface CertifyAndAttestRunResult {
501
502
  */
502
503
  declare function certifyAndAttestRun(steps: StepParams[], options?: CertifyAndAttestRunOptions): Promise<CertifyAndAttestRunResult>;
503
504
 
504
- export { AiExecutionSnapshotV1, AiefProfile, AiefVerifyResult, AttestOptions, AttestationReceipt, AttestationResult, BundleDeclaration, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, type CertifyAndAttestRunOptions, type CertifyAndAttestRunResult, CertifyDecisionParams, CreateSnapshotParams, type ExportVerifiableRedactedOptions, type ExportVerifiableRedactedProvenance, type ExportVerifiableRedactedResult, type MakeToolEventParams, NodeKeysDocument, NodeReceiptVerifyResult, type ProfileValidationResult, type RedactBeforeSealPolicy, RunBuilder, RunBuilderOptions, RunSummary, RunSummaryVerifyResult, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, ToolEvent, VerificationResult, 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, verifyAief, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifyRunSummary, verifySnapshot };
505
+ /**
506
+ * CER Protocol verification types — v0.9.0
507
+ *
508
+ * These are the canonical structured verification types for the NexArt
509
+ * Certified Execution Record (CER) Protocol. All NexArt-compatible verifiers
510
+ * should produce a CerVerificationResult.
511
+ *
512
+ * NOTE: The existing VerificationResult type (ok/errors/code shape) is preserved
513
+ * for backward compatibility. CerVerificationResult is the new protocol-aligned type.
514
+ */
515
+ type VerificationStatus = 'VERIFIED' | 'FAILED' | 'NOT_FOUND';
516
+ type CheckStatus = 'PASS' | 'FAIL' | 'SKIPPED';
517
+ declare const ReasonCode: {
518
+ readonly BUNDLE_HASH_MISMATCH: "BUNDLE_HASH_MISMATCH";
519
+ readonly NODE_SIGNATURE_INVALID: "NODE_SIGNATURE_INVALID";
520
+ readonly NODE_SIGNATURE_MISSING: "NODE_SIGNATURE_MISSING";
521
+ readonly RECEIPT_HASH_MISMATCH: "RECEIPT_HASH_MISMATCH";
522
+ readonly SCHEMA_VERSION_UNSUPPORTED: "SCHEMA_VERSION_UNSUPPORTED";
523
+ readonly RECORD_NOT_FOUND: "RECORD_NOT_FOUND";
524
+ readonly BUNDLE_CORRUPTED: "BUNDLE_CORRUPTED";
525
+ };
526
+ type ReasonCode = typeof ReasonCode[keyof typeof ReasonCode];
527
+ /**
528
+ * Canonical protocol verification result.
529
+ *
530
+ * Produced by verifyAiCerBundleDetailed() and verifyCodeModeSnapshotDetailed().
531
+ * All checks that are not applicable to a given bundle type are SKIPPED (never FAIL).
532
+ */
533
+ interface CerVerificationResult {
534
+ status: VerificationStatus;
535
+ checks: {
536
+ bundleIntegrity: CheckStatus;
537
+ nodeSignature: CheckStatus;
538
+ receiptConsistency: CheckStatus;
539
+ };
540
+ reasonCodes: ReasonCode[];
541
+ certificateHash: string;
542
+ bundleType: string;
543
+ verifiedAt: string;
544
+ verifier: string;
545
+ }
546
+
547
+ /**
548
+ * verifyAiCerBundleDetailed — protocol-aligned AI CER verifier
549
+ *
550
+ * Returns a CerVerificationResult conforming to the CER Protocol spec.
551
+ * Wraps the existing verifyCer() + hasAttestation() helpers and maps
552
+ * their results into the structured protocol schema.
553
+ */
554
+
555
+ /**
556
+ * Verify a CER AI execution bundle and return a structured CerVerificationResult.
557
+ *
558
+ * - bundleIntegrity: PASS/FAIL based on certificateHash integrity
559
+ * - nodeSignature: PASS if attestation present and structurally valid; SKIPPED if absent
560
+ * - receiptConsistency: mirrors nodeSignature (SKIPPED when no attestation)
561
+ *
562
+ * Attestation is optional — its absence sets nodeSignature/receiptConsistency
563
+ * to SKIPPED, not FAIL.
564
+ *
565
+ * @param bundle - The raw CER bundle (typed as unknown for safety; validated internally)
566
+ */
567
+ declare function verifyAiCerBundleDetailed(bundle: unknown): CerVerificationResult;
568
+
569
+ 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 };
package/dist/index.mjs CHANGED
@@ -382,7 +382,7 @@ function certifyDecision(params) {
382
382
  conversationId: params.conversationId,
383
383
  prevStepHash: params.prevStepHash
384
384
  });
385
- return sealCer(snapshot, { meta: params.meta });
385
+ return sealCer(snapshot, { createdAt: params.createdAt, meta: params.meta });
386
386
  }
387
387
 
388
388
  // src/run.ts
@@ -2463,10 +2463,184 @@ async function certifyAndAttestRun(steps, options) {
2463
2463
  finalStepHash: runSummary.finalStepHash
2464
2464
  };
2465
2465
  }
2466
+
2467
+ // src/cerProtocol.ts
2468
+ var ReasonCode = {
2469
+ BUNDLE_HASH_MISMATCH: "BUNDLE_HASH_MISMATCH",
2470
+ NODE_SIGNATURE_INVALID: "NODE_SIGNATURE_INVALID",
2471
+ NODE_SIGNATURE_MISSING: "NODE_SIGNATURE_MISSING",
2472
+ RECEIPT_HASH_MISMATCH: "RECEIPT_HASH_MISMATCH",
2473
+ SCHEMA_VERSION_UNSUPPORTED: "SCHEMA_VERSION_UNSUPPORTED",
2474
+ RECORD_NOT_FOUND: "RECORD_NOT_FOUND",
2475
+ BUNDLE_CORRUPTED: "BUNDLE_CORRUPTED"
2476
+ };
2477
+
2478
+ // src/verifyDetailed.ts
2479
+ function mapCerCodeToReasonCodes(cerCode) {
2480
+ switch (cerCode) {
2481
+ case CerVerifyCode.CERTIFICATE_HASH_MISMATCH:
2482
+ case CerVerifyCode.SNAPSHOT_HASH_MISMATCH:
2483
+ case CerVerifyCode.INPUT_HASH_MISMATCH:
2484
+ case CerVerifyCode.OUTPUT_HASH_MISMATCH:
2485
+ return [ReasonCode.BUNDLE_HASH_MISMATCH];
2486
+ case CerVerifyCode.SCHEMA_ERROR:
2487
+ return [ReasonCode.SCHEMA_VERSION_UNSUPPORTED];
2488
+ case CerVerifyCode.CANONICALIZATION_ERROR:
2489
+ case CerVerifyCode.UNKNOWN_ERROR:
2490
+ case CerVerifyCode.INVALID_SHA256_FORMAT:
2491
+ return [ReasonCode.BUNDLE_CORRUPTED];
2492
+ case CerVerifyCode.ATTESTATION_INVALID_SIGNATURE:
2493
+ case CerVerifyCode.ATTESTATION_KEY_FORMAT_UNSUPPORTED:
2494
+ case CerVerifyCode.ATTESTATION_KEY_NOT_FOUND:
2495
+ return [ReasonCode.NODE_SIGNATURE_INVALID];
2496
+ case CerVerifyCode.ATTESTATION_MISSING:
2497
+ return [ReasonCode.NODE_SIGNATURE_MISSING];
2498
+ default:
2499
+ return [];
2500
+ }
2501
+ }
2502
+ function verifyAiCerBundleDetailed(bundle) {
2503
+ const verifiedAt = (/* @__PURE__ */ new Date()).toISOString();
2504
+ const verifier = "@nexart/ai-execution";
2505
+ if (!bundle || typeof bundle !== "object" || Array.isArray(bundle)) {
2506
+ return {
2507
+ status: "FAILED",
2508
+ checks: { bundleIntegrity: "FAIL", nodeSignature: "SKIPPED", receiptConsistency: "SKIPPED" },
2509
+ reasonCodes: [ReasonCode.BUNDLE_CORRUPTED],
2510
+ certificateHash: "",
2511
+ bundleType: "",
2512
+ verifiedAt,
2513
+ verifier
2514
+ };
2515
+ }
2516
+ const b = bundle;
2517
+ const bundleType = typeof b["bundleType"] === "string" ? b["bundleType"] : "";
2518
+ const certificateHash = typeof b["certificateHash"] === "string" ? b["certificateHash"] : "";
2519
+ if (bundleType !== "cer.ai.execution.v1") {
2520
+ return {
2521
+ status: "FAILED",
2522
+ checks: { bundleIntegrity: "FAIL", nodeSignature: "SKIPPED", receiptConsistency: "SKIPPED" },
2523
+ reasonCodes: [ReasonCode.SCHEMA_VERSION_UNSUPPORTED],
2524
+ certificateHash,
2525
+ bundleType,
2526
+ verifiedAt,
2527
+ verifier
2528
+ };
2529
+ }
2530
+ const cerResult = verifyCer(bundle);
2531
+ const bundleIntegrity = cerResult.ok ? "PASS" : "FAIL";
2532
+ const attestationPresent = hasAttestation(bundle);
2533
+ const nodeSignature = attestationPresent ? "PASS" : "SKIPPED";
2534
+ const receiptConsistency = attestationPresent ? "PASS" : "SKIPPED";
2535
+ const reasonCodes = cerResult.ok ? [] : mapCerCodeToReasonCodes(cerResult.code);
2536
+ return {
2537
+ status: cerResult.ok ? "VERIFIED" : "FAILED",
2538
+ checks: { bundleIntegrity, nodeSignature, receiptConsistency },
2539
+ reasonCodes,
2540
+ certificateHash,
2541
+ bundleType,
2542
+ verifiedAt,
2543
+ verifier
2544
+ };
2545
+ }
2546
+
2547
+ // src/langchain.ts
2548
+ import * as crypto6 from "crypto";
2549
+ function normalizeCerValue(value) {
2550
+ if (typeof value === "string") return value;
2551
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
2552
+ return value;
2553
+ }
2554
+ if (Array.isArray(value)) return { items: value };
2555
+ return String(value);
2556
+ }
2557
+ function extractPrompt(input, metadata) {
2558
+ if (typeof metadata?.prompt === "string" && metadata.prompt.length > 0) {
2559
+ return metadata.prompt;
2560
+ }
2561
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) {
2562
+ const obj = input;
2563
+ if (Array.isArray(obj.messages) && obj.messages.length > 0) {
2564
+ const first = obj.messages[0];
2565
+ if (typeof first?.content === "string" && first.content.length > 0) {
2566
+ return first.content;
2567
+ }
2568
+ }
2569
+ if (typeof obj.prompt === "string" && obj.prompt.length > 0) return obj.prompt;
2570
+ if (typeof obj.text === "string" && obj.text.length > 0) return obj.text;
2571
+ }
2572
+ if (typeof input === "string" && input.length > 0) return input;
2573
+ return "[LangChain run]";
2574
+ }
2575
+ function buildMeta(metadata) {
2576
+ if (!metadata || Object.keys(metadata).length === 0) return void 0;
2577
+ const reserved = /* @__PURE__ */ new Set(["prompt", "appId", "runId", "workflowId", "conversationId"]);
2578
+ const extraTags = [];
2579
+ for (const [k, v] of Object.entries(metadata)) {
2580
+ if (!reserved.has(k)) {
2581
+ extraTags.push(typeof v === "string" ? `${k}:${v}` : `${k}:${JSON.stringify(v)}`);
2582
+ }
2583
+ }
2584
+ return extraTags.length > 0 ? { tags: extraTags } : void 0;
2585
+ }
2586
+ function resolveParameters(params) {
2587
+ return {
2588
+ temperature: params?.temperature ?? 0,
2589
+ maxTokens: params?.maxTokens ?? 0,
2590
+ topP: params?.topP ?? null,
2591
+ seed: params?.seed ?? null
2592
+ };
2593
+ }
2594
+ function buildCertifyParams(input, executionId) {
2595
+ return {
2596
+ executionId,
2597
+ timestamp: input.timestamp,
2598
+ createdAt: input.createdAt,
2599
+ provider: input.provider,
2600
+ model: input.model,
2601
+ modelVersion: input.modelVersion ?? null,
2602
+ prompt: extractPrompt(input.input, input.metadata),
2603
+ input: normalizeCerValue(input.input),
2604
+ output: normalizeCerValue(input.output),
2605
+ parameters: resolveParameters(input.parameters),
2606
+ appId: typeof input.metadata?.appId === "string" ? input.metadata.appId : null,
2607
+ runId: typeof input.metadata?.runId === "string" ? input.metadata.runId : void 0,
2608
+ workflowId: typeof input.metadata?.workflowId === "string" ? input.metadata.workflowId : void 0,
2609
+ conversationId: typeof input.metadata?.conversationId === "string" ? input.metadata.conversationId : void 0,
2610
+ meta: buildMeta(input.metadata)
2611
+ };
2612
+ }
2613
+ function createLangChainCer(input) {
2614
+ const executionId = input.executionId ?? crypto6.randomUUID();
2615
+ const bundle = certifyDecision(buildCertifyParams(input, executionId));
2616
+ return {
2617
+ bundle,
2618
+ certificateHash: bundle.certificateHash,
2619
+ executionId: bundle.snapshot.executionId
2620
+ };
2621
+ }
2622
+ function certifyLangChainRun(input, _options) {
2623
+ if (input.nodeUrl && input.apiKey) {
2624
+ const executionId = input.executionId ?? crypto6.randomUUID();
2625
+ const certifyParams = buildCertifyParams({ ...input, executionId }, executionId);
2626
+ const attestFn = _options?._attestFn ?? certifyAndAttestDecision;
2627
+ return attestFn(certifyParams, { nodeUrl: input.nodeUrl, apiKey: input.apiKey }).then(
2628
+ ({ bundle, receipt }) => ({
2629
+ bundle,
2630
+ receipt,
2631
+ certificateHash: bundle.certificateHash,
2632
+ executionId: bundle.snapshot.executionId,
2633
+ attested: true
2634
+ })
2635
+ );
2636
+ }
2637
+ return createLangChainCer(input);
2638
+ }
2466
2639
  export {
2467
2640
  CerAttestationError,
2468
2641
  CerVerificationError,
2469
2642
  CerVerifyCode,
2643
+ ReasonCode,
2470
2644
  RunBuilder,
2471
2645
  attest,
2472
2646
  attestIfNeeded,
@@ -2474,9 +2648,11 @@ export {
2474
2648
  certifyAndAttestRun,
2475
2649
  certifyDecision,
2476
2650
  certifyDecisionFromProviderCall,
2651
+ certifyLangChainRun,
2477
2652
  computeInputHash,
2478
2653
  computeOutputHash,
2479
2654
  createClient,
2655
+ createLangChainCer,
2480
2656
  createSnapshot,
2481
2657
  exportCer,
2482
2658
  exportVerifiableRedacted,
@@ -2499,6 +2675,7 @@ export {
2499
2675
  toCanonicalJson,
2500
2676
  validateProfile,
2501
2677
  verifyCer as verify,
2678
+ verifyAiCerBundleDetailed,
2502
2679
  verifyAief,
2503
2680
  verifyBundleAttestation,
2504
2681
  verifyCer,