@tangle-network/agent-interface 0.21.0 → 0.22.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";
@@ -513,6 +523,112 @@ export interface AgentCandidateRunReceiptV1 {
513
523
  termination: AgentCandidateTermination;
514
524
  digest: Sha256Digest;
515
525
  }
526
+ /** One evaluator-mediated model call in a terminal settlement. */
527
+ export interface AgentCandidateModelSettlementCall {
528
+ callId: string;
529
+ traceSpanId: string;
530
+ model: string;
531
+ inputTokens: number;
532
+ outputTokens: number;
533
+ cachedInputTokens: number;
534
+ reasoningTokens: number;
535
+ costUsdNanos: number;
536
+ }
537
+ /** Canonical model-access ledger after the evaluator has revoked the grant. */
538
+ export interface AgentCandidateModelSettlementMaterialV1 {
539
+ schemaVersion: 1;
540
+ kind: "agent-candidate-model-settlement-material";
541
+ executionPlanDigest: Sha256Digest;
542
+ preparationId: string;
543
+ grantDigest: Sha256Digest;
544
+ closed: true;
545
+ resolved: AgentCandidateResolvedModel;
546
+ calls: AgentCandidateModelSettlementCall[];
547
+ usage: AgentCandidateFixedSpend;
548
+ }
549
+ export interface AgentCandidateModelSettlementEvidence {
550
+ schemaVersion: 1;
551
+ kind: "agent-candidate-model-settlement";
552
+ digest: Sha256Digest;
553
+ material: AgentCandidateModelSettlementMaterialV1;
554
+ artifact: AgentCandidateCapturedArtifact;
555
+ }
556
+ /** Git identity before or after a task execution. */
557
+ export interface AgentCandidateRepositoryState {
558
+ identity: string;
559
+ rootIdentity: string;
560
+ commit: string;
561
+ tree: string;
562
+ }
563
+ /** Canonical repository result produced by the candidate on one task. */
564
+ export interface AgentCandidateTaskOutcomeMaterialV1 {
565
+ schemaVersion: 1;
566
+ kind: "agent-candidate-task-outcome-material";
567
+ executionPlanDigest: Sha256Digest;
568
+ baseRepository: AgentCandidateRepositoryState;
569
+ resultRepository: AgentCandidateRepositoryState;
570
+ afterState: AgentCandidateWorkspaceSnapshotEvidence;
571
+ gitDiff: {
572
+ format: "git-diff-binary";
573
+ artifact: AgentCandidateArtifactRef;
574
+ };
575
+ }
576
+ export interface AgentCandidateTaskOutcomeEvidence {
577
+ schemaVersion: 1;
578
+ kind: "agent-candidate-task-outcome";
579
+ digest: Sha256Digest;
580
+ material: AgentCandidateTaskOutcomeMaterialV1;
581
+ artifact: AgentCandidateCapturedArtifact;
582
+ }
583
+ export interface AgentCandidateBenchmarkDimension {
584
+ name: string;
585
+ score: number;
586
+ }
587
+ /** Canonical executable-grade result for one task outcome. */
588
+ export interface AgentCandidateBenchmarkResultMaterialV1 {
589
+ schemaVersion: 1;
590
+ kind: "agent-candidate-benchmark-result-material";
591
+ executionPlanDigest: Sha256Digest;
592
+ taskOutcomeDigest: Sha256Digest;
593
+ benchmark: {
594
+ name: string;
595
+ version: string;
596
+ taskId: string;
597
+ splitDigest: Sha256Digest;
598
+ };
599
+ grader: {
600
+ name: string;
601
+ version: string;
602
+ artifact: AgentCandidateArtifactRef;
603
+ };
604
+ /** Raw grader output required to independently audit the reported verdict. */
605
+ evidence: AgentCandidateArtifactRef;
606
+ score: number;
607
+ passed: boolean;
608
+ dimensions: AgentCandidateBenchmarkDimension[];
609
+ }
610
+ export interface AgentCandidateBenchmarkResultEvidence {
611
+ schemaVersion: 1;
612
+ kind: "agent-candidate-benchmark-result";
613
+ digest: Sha256Digest;
614
+ material: AgentCandidateBenchmarkResultMaterialV1;
615
+ artifact: AgentCandidateCapturedArtifact;
616
+ }
617
+ /**
618
+ * Terminal candidate receipt with lossless spend, exact repository output,
619
+ * and executable benchmark evidence. V1 fields remain present for consumers
620
+ * that have not yet adopted the stronger evidence surfaces.
621
+ */
622
+ export interface AgentCandidateRunReceiptV2 extends Omit<AgentCandidateRunReceiptV1, "schemaVersion"> {
623
+ schemaVersion: 2;
624
+ fixedUsage: AgentCandidateFixedSpend;
625
+ modelSettlement: AgentCandidateModelSettlementEvidence;
626
+ taskOutcome: AgentCandidateTaskOutcomeEvidence;
627
+ benchmarkResult: AgentCandidateBenchmarkResultEvidence;
628
+ }
629
+ /** Backward-compatible V1 receipt name. */
516
630
  export type AgentCandidateRunReceipt = AgentCandidateRunReceiptV1;
631
+ /** Explicit parser target for consumers that accept both receipt generations. */
632
+ export type AgentCandidateRunReceiptAnyVersion = AgentCandidateRunReceiptV1 | AgentCandidateRunReceiptV2;
517
633
  /** Declare a candidate bundle while retaining literal inference. */
518
634
  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.22.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",