@tangle-network/agent-interface 0.21.0 → 0.23.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.
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { agentCandidateCapturedArtifactSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, } from "./agent-candidate-artifact-schema.js";
3
3
  import { agentCandidateExecutionPlanEvidenceSchema, agentCandidateProfilePlanEvidenceSchema, agentCandidateResolvedModelSchema, } from "./agent-candidate-execution-plan-schema.js";
4
4
  import { agentCandidateSpendSchema, } from "./agent-candidate-lineage-schema.js";
5
+ import { agentCandidateBenchmarkResultEvidenceSchema, agentCandidateFixedSpendSchema, agentCandidateModelSettlementEvidenceSchema, agentCandidateTaskOutcomeEvidenceSchema, sameFixedSpend, } from "./agent-candidate-outcome-schema.js";
5
6
  import { gitObjectSchema, isCanonicalJsonValue, isSafeRelativePath, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
6
7
  import { harnessTypeSchema } from "./harness.js";
7
8
  const entrypointReceiptSchema = z
@@ -257,7 +258,131 @@ export const agentCandidateRunReceiptSchema = z
257
258
  });
258
259
  }
259
260
  });
261
+ export const agentCandidateRunReceiptV2Schema = z
262
+ .object({
263
+ schemaVersion: z.literal(2),
264
+ kind: z.literal("agent-candidate-run"),
265
+ digestAlgorithm: z.literal("rfc8785-sha256"),
266
+ bundleDigest: sha256DigestSchema,
267
+ materializationReceiptDigest: sha256DigestSchema,
268
+ executionPlanDigest: sha256DigestSchema,
269
+ memory: agentCandidateMemoryReceiptSchema,
270
+ usage: agentCandidateSpendSchema,
271
+ modelUsage: agentCandidateModelUsageSchema,
272
+ trace: agentCandidateTraceEvidenceSchema,
273
+ termination: agentCandidateTerminationSchema,
274
+ fixedUsage: agentCandidateFixedSpendSchema,
275
+ modelSettlement: agentCandidateModelSettlementEvidenceSchema,
276
+ taskOutcome: agentCandidateTaskOutcomeEvidenceSchema,
277
+ benchmarkResult: agentCandidateBenchmarkResultEvidenceSchema,
278
+ digest: sha256DigestSchema,
279
+ })
280
+ .strict()
281
+ .superRefine((receipt, ctx) => {
282
+ const legacyUsageMatchesModel = receipt.usage.costUsd === receipt.modelUsage.usage.costUsd &&
283
+ receipt.usage.inputTokens === receipt.modelUsage.usage.inputTokens &&
284
+ receipt.usage.outputTokens === receipt.modelUsage.usage.outputTokens &&
285
+ receipt.usage.cachedInputTokens ===
286
+ receipt.modelUsage.usage.cachedInputTokens &&
287
+ receipt.usage.modelCalls === receipt.modelUsage.usage.modelCalls;
288
+ if (!legacyUsageMatchesModel) {
289
+ ctx.addIssue({
290
+ code: "custom",
291
+ path: ["modelUsage", "usage"],
292
+ message: "single-model usage must equal aggregate protected usage",
293
+ });
294
+ }
295
+ if (!legacyUsageMatchesFixed(receipt.usage, receipt.fixedUsage)) {
296
+ ctx.addIssue({
297
+ code: "custom",
298
+ path: ["fixedUsage"],
299
+ message: "fixed usage must exactly preserve the legacy usage totals",
300
+ });
301
+ }
302
+ if (!sameFixedSpend(receipt.fixedUsage, receipt.modelSettlement.material.usage)) {
303
+ ctx.addIssue({
304
+ code: "custom",
305
+ path: ["modelSettlement", "material", "usage"],
306
+ message: "model settlement aggregate must equal fixed run usage",
307
+ });
308
+ }
309
+ if (JSON.stringify(receipt.modelUsage.resolved) !==
310
+ JSON.stringify(receipt.modelSettlement.material.resolved)) {
311
+ ctx.addIssue({
312
+ code: "custom",
313
+ path: ["modelSettlement", "material", "resolved"],
314
+ message: "model settlement must bind the run's resolved model",
315
+ });
316
+ }
317
+ if (receipt.modelSettlement.material.executionPlanDigest !==
318
+ receipt.executionPlanDigest) {
319
+ ctx.addIssue({
320
+ code: "custom",
321
+ path: ["modelSettlement", "material", "executionPlanDigest"],
322
+ message: "model settlement must bind the executed plan",
323
+ });
324
+ }
325
+ if (receipt.trace.modelCallCount !== receipt.fixedUsage.modelCalls) {
326
+ ctx.addIssue({
327
+ code: "custom",
328
+ path: ["trace", "modelCallCount"],
329
+ message: "trace model-call count must match fixed run usage",
330
+ });
331
+ }
332
+ if (receipt.taskOutcome.material.executionPlanDigest !==
333
+ receipt.executionPlanDigest) {
334
+ ctx.addIssue({
335
+ code: "custom",
336
+ path: ["taskOutcome", "material", "executionPlanDigest"],
337
+ message: "task outcome must bind the executed plan",
338
+ });
339
+ }
340
+ if (receipt.benchmarkResult.material.executionPlanDigest !==
341
+ receipt.executionPlanDigest) {
342
+ ctx.addIssue({
343
+ code: "custom",
344
+ path: ["benchmarkResult", "material", "executionPlanDigest"],
345
+ message: "benchmark result must bind the executed plan",
346
+ });
347
+ }
348
+ if (receipt.benchmarkResult.material.taskOutcomeDigest !==
349
+ receipt.taskOutcome.digest) {
350
+ ctx.addIssue({
351
+ code: "custom",
352
+ path: ["benchmarkResult", "material", "taskOutcomeDigest"],
353
+ message: "benchmark result must bind the exact task outcome",
354
+ });
355
+ }
356
+ if (!isCanonicalJsonValue(receipt)) {
357
+ ctx.addIssue({
358
+ code: "custom",
359
+ message: "run receipt must contain only RFC 8785 JSON values",
360
+ });
361
+ }
362
+ });
363
+ /** Explicit V1 alias; the original schema export remains unchanged. */
364
+ export const agentCandidateRunReceiptV1Schema = agentCandidateRunReceiptSchema;
365
+ /** Parses both receipt generations without changing the original V1 export. */
366
+ export const agentCandidateRunReceiptAnyVersionSchema = z.union([
367
+ agentCandidateRunReceiptSchema,
368
+ agentCandidateRunReceiptV2Schema,
369
+ ]);
370
+ function legacyUsageMatchesFixed(legacy, fixed) {
371
+ return (legacy.costUsd === fixed.costUsdNanos / 1_000_000_000 &&
372
+ legacy.inputTokens === fixed.inputTokens &&
373
+ legacy.outputTokens === fixed.outputTokens &&
374
+ (legacy.cachedInputTokens ?? 0) === fixed.cachedInputTokens &&
375
+ legacy.modelCalls === fixed.modelCalls);
376
+ }
260
377
  const _materializationReceiptSchemaMatchesType = true;
261
378
  const _runReceiptSchemaMatchesType = true;
379
+ const _anyRunReceiptSchemaMatchesType = true;
380
+ const _runReceiptV1SchemaMatchesType = true;
381
+ const _runReceiptV2SchemaMatchesType = true;
382
+ const _v2MustNotSatisfyOriginalReceipt = true;
262
383
  void _materializationReceiptSchemaMatchesType;
263
384
  void _runReceiptSchemaMatchesType;
385
+ void _anyRunReceiptSchemaMatchesType;
386
+ void _runReceiptV1SchemaMatchesType;
387
+ void _runReceiptV2SchemaMatchesType;
388
+ void _v2MustNotSatisfyOriginalReceipt;
@@ -493,6 +493,7 @@ export * from "./agent-candidate-artifact-schema.js";
493
493
  export * from "./agent-candidate-code-schema.js";
494
494
  export * from "./agent-candidate-execution-plan-schema.js";
495
495
  export * from "./agent-candidate-lineage-schema.js";
496
+ export * from "./agent-candidate-outcome-schema.js";
496
497
  export * from "./agent-candidate-profile-schema.js";
497
498
  export * from "./agent-candidate-receipt-schema.js";
498
499
  export { sha256DigestSchema } from "./agent-candidate-schema-common.js";
@@ -139,6 +139,7 @@ export * from "./agent-candidate-artifact-schema.js";
139
139
  export * from "./agent-candidate-code-schema.js";
140
140
  export * from "./agent-candidate-execution-plan-schema.js";
141
141
  export * from "./agent-candidate-lineage-schema.js";
142
+ export * from "./agent-candidate-outcome-schema.js";
142
143
  export * from "./agent-candidate-profile-schema.js";
143
144
  export * from "./agent-candidate-receipt-schema.js";
144
145
  export { sha256DigestSchema } from "./agent-candidate-schema-common.js";
@@ -216,6 +216,16 @@ export interface AgentCandidateSpend {
216
216
  cachedInputTokens?: number;
217
217
  modelCalls: number;
218
218
  }
219
+ /** Lossless evaluator-owned usage totals for one candidate execution. */
220
+ export interface AgentCandidateFixedSpend {
221
+ inputTokens: number;
222
+ outputTokens: number;
223
+ cachedInputTokens: number;
224
+ reasoningTokens: number;
225
+ modelCalls: number;
226
+ /** Integer billionths of one US dollar. */
227
+ costUsdNanos: number;
228
+ }
219
229
  /** Evidence and ancestry that produced the immutable candidate. */
220
230
  export interface AgentCandidateLineage {
221
231
  source: "optimizer" | "human" | "import" | "compound";
@@ -342,6 +352,13 @@ export interface AgentCandidateProfileApplication {
342
352
  targetWorkspace: AgentCandidateWorkingDirectory["workspace"];
343
353
  mountPaths: string[];
344
354
  }
355
+ /** Evaluator-owned network exception for the one frozen model gateway. */
356
+ export type AgentCandidateModelAccessNetwork = {
357
+ mode: "disabled";
358
+ } | {
359
+ mode: "gateway-only";
360
+ domains: string[];
361
+ };
345
362
  /**
346
363
  * Canonical, digest-free per-task execution identity document.
347
364
  *
@@ -395,6 +412,7 @@ export interface AgentCandidateExecutionPlanMaterialV1 {
395
412
  access: {
396
413
  kind: "evaluator-mediated";
397
414
  grantDigest: Sha256Digest;
415
+ network: AgentCandidateModelAccessNetwork;
398
416
  };
399
417
  routes: Array<{
400
418
  kind: "primary";
@@ -513,6 +531,112 @@ export interface AgentCandidateRunReceiptV1 {
513
531
  termination: AgentCandidateTermination;
514
532
  digest: Sha256Digest;
515
533
  }
534
+ /** One evaluator-mediated model call in a terminal settlement. */
535
+ export interface AgentCandidateModelSettlementCall {
536
+ callId: string;
537
+ traceSpanId: string;
538
+ model: string;
539
+ inputTokens: number;
540
+ outputTokens: number;
541
+ cachedInputTokens: number;
542
+ reasoningTokens: number;
543
+ costUsdNanos: number;
544
+ }
545
+ /** Canonical model-access ledger after the evaluator has revoked the grant. */
546
+ export interface AgentCandidateModelSettlementMaterialV1 {
547
+ schemaVersion: 1;
548
+ kind: "agent-candidate-model-settlement-material";
549
+ executionPlanDigest: Sha256Digest;
550
+ preparationId: string;
551
+ grantDigest: Sha256Digest;
552
+ closed: true;
553
+ resolved: AgentCandidateResolvedModel;
554
+ calls: AgentCandidateModelSettlementCall[];
555
+ usage: AgentCandidateFixedSpend;
556
+ }
557
+ export interface AgentCandidateModelSettlementEvidence {
558
+ schemaVersion: 1;
559
+ kind: "agent-candidate-model-settlement";
560
+ digest: Sha256Digest;
561
+ material: AgentCandidateModelSettlementMaterialV1;
562
+ artifact: AgentCandidateCapturedArtifact;
563
+ }
564
+ /** Git identity before or after a task execution. */
565
+ export interface AgentCandidateRepositoryState {
566
+ identity: string;
567
+ rootIdentity: string;
568
+ commit: string;
569
+ tree: string;
570
+ }
571
+ /** Canonical repository result produced by the candidate on one task. */
572
+ export interface AgentCandidateTaskOutcomeMaterialV1 {
573
+ schemaVersion: 1;
574
+ kind: "agent-candidate-task-outcome-material";
575
+ executionPlanDigest: Sha256Digest;
576
+ baseRepository: AgentCandidateRepositoryState;
577
+ resultRepository: AgentCandidateRepositoryState;
578
+ afterState: AgentCandidateWorkspaceSnapshotEvidence;
579
+ gitDiff: {
580
+ format: "git-diff-binary";
581
+ artifact: AgentCandidateArtifactRef;
582
+ };
583
+ }
584
+ export interface AgentCandidateTaskOutcomeEvidence {
585
+ schemaVersion: 1;
586
+ kind: "agent-candidate-task-outcome";
587
+ digest: Sha256Digest;
588
+ material: AgentCandidateTaskOutcomeMaterialV1;
589
+ artifact: AgentCandidateCapturedArtifact;
590
+ }
591
+ export interface AgentCandidateBenchmarkDimension {
592
+ name: string;
593
+ score: number;
594
+ }
595
+ /** Canonical executable-grade result for one task outcome. */
596
+ export interface AgentCandidateBenchmarkResultMaterialV1 {
597
+ schemaVersion: 1;
598
+ kind: "agent-candidate-benchmark-result-material";
599
+ executionPlanDigest: Sha256Digest;
600
+ taskOutcomeDigest: Sha256Digest;
601
+ benchmark: {
602
+ name: string;
603
+ version: string;
604
+ taskId: string;
605
+ splitDigest: Sha256Digest;
606
+ };
607
+ grader: {
608
+ name: string;
609
+ version: string;
610
+ artifact: AgentCandidateArtifactRef;
611
+ };
612
+ /** Raw grader output required to independently audit the reported verdict. */
613
+ evidence: AgentCandidateArtifactRef;
614
+ score: number;
615
+ passed: boolean;
616
+ dimensions: AgentCandidateBenchmarkDimension[];
617
+ }
618
+ export interface AgentCandidateBenchmarkResultEvidence {
619
+ schemaVersion: 1;
620
+ kind: "agent-candidate-benchmark-result";
621
+ digest: Sha256Digest;
622
+ material: AgentCandidateBenchmarkResultMaterialV1;
623
+ artifact: AgentCandidateCapturedArtifact;
624
+ }
625
+ /**
626
+ * Terminal candidate receipt with lossless spend, exact repository output,
627
+ * and executable benchmark evidence. V1 fields remain present for consumers
628
+ * that have not yet adopted the stronger evidence surfaces.
629
+ */
630
+ export interface AgentCandidateRunReceiptV2 extends Omit<AgentCandidateRunReceiptV1, "schemaVersion"> {
631
+ schemaVersion: 2;
632
+ fixedUsage: AgentCandidateFixedSpend;
633
+ modelSettlement: AgentCandidateModelSettlementEvidence;
634
+ taskOutcome: AgentCandidateTaskOutcomeEvidence;
635
+ benchmarkResult: AgentCandidateBenchmarkResultEvidence;
636
+ }
637
+ /** Backward-compatible V1 receipt name. */
516
638
  export type AgentCandidateRunReceipt = AgentCandidateRunReceiptV1;
639
+ /** Explicit parser target for consumers that accept both receipt generations. */
640
+ export type AgentCandidateRunReceiptAnyVersion = AgentCandidateRunReceiptV1 | AgentCandidateRunReceiptV2;
517
641
  /** Declare a candidate bundle while retaining literal inference. */
518
642
  export declare function defineAgentCandidateBundle<T extends AgentCandidateBundle>(bundle: T): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",