@tangle-network/agent-interface 0.25.0 → 0.26.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.
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { agentCandidateArtifactRefSchema, agentCandidateCapturedArtifactSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, } from "./agent-candidate-artifact-schema.js";
3
3
  import { agentCandidateResolvedModelSchema } from "./agent-candidate-execution-plan-schema.js";
4
- import { gitObjectSchema, isCanonicalJsonValue, sameGitObjectFormat, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
4
+ import { agentCandidateMediaTypeSchema, gitObjectSchema, isCanonicalJsonValue, sameGitObjectFormat, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
5
5
  const safeCountSchema = z
6
6
  .number()
7
7
  .int()
@@ -24,18 +24,6 @@ export const agentCandidateFixedSpendSchema = z
24
24
  })
25
25
  .strict();
26
26
  export const agentCandidateModelSettlementCallSchema = z
27
- .object({
28
- callId: boundedIdentifierSchema,
29
- traceSpanId: boundedIdentifierSchema,
30
- model: boundedIdentifierSchema,
31
- inputTokens: safeCountSchema,
32
- outputTokens: safeCountSchema,
33
- cachedInputTokens: safeCountSchema,
34
- reasoningTokens: safeCountSchema,
35
- costUsdNanos: safeCountSchema,
36
- })
37
- .strict();
38
- export const agentCandidateModelSettlementCallV2Schema = z
39
27
  .object({
40
28
  callId: boundedIdentifierSchema,
41
29
  generationId: boundedIdentifierSchema,
@@ -76,26 +64,14 @@ const modelSettlementMaterialShape = {
76
64
  resolved: agentCandidateResolvedModelSchema,
77
65
  usage: agentCandidateFixedSpendSchema,
78
66
  };
79
- export const agentCandidateModelSettlementMaterialV1Schema = z
80
- .object({
81
- schemaVersion: z.literal(1),
82
- ...modelSettlementMaterialShape,
83
- calls: z.array(agentCandidateModelSettlementCallSchema),
84
- })
85
- .strict()
86
- .superRefine(refineModelSettlementMaterial);
87
- export const agentCandidateModelSettlementMaterialV2Schema = z
67
+ export const agentCandidateModelSettlementMaterialSchema = z
88
68
  .object({
89
69
  schemaVersion: z.literal(2),
90
70
  ...modelSettlementMaterialShape,
91
- calls: z.array(agentCandidateModelSettlementCallV2Schema),
71
+ calls: z.array(agentCandidateModelSettlementCallSchema),
92
72
  })
93
73
  .strict()
94
74
  .superRefine(refineModelSettlementMaterial);
95
- export const agentCandidateModelSettlementMaterialSchema = z.union([
96
- agentCandidateModelSettlementMaterialV1Schema,
97
- agentCandidateModelSettlementMaterialV2Schema,
98
- ]);
99
75
  function refineModelSettlementMaterial(material, ctx) {
100
76
  const callIds = new Set();
101
77
  const traceSpanIds = new Set();
@@ -125,19 +101,14 @@ function refineModelSettlementMaterial(material, ctx) {
125
101
  });
126
102
  }
127
103
  traceSpanIds.add(call.traceSpanId);
128
- const generationId = "generationId" in call && typeof call.generationId === "string"
129
- ? call.generationId
130
- : undefined;
131
- if (generationId !== undefined) {
132
- if (generationIds.has(generationId)) {
133
- ctx.addIssue({
134
- code: "custom",
135
- path: ["calls", index, "generationId"],
136
- message: "model settlement generation ids must be unique",
137
- });
138
- }
139
- generationIds.add(generationId);
104
+ if (generationIds.has(call.generationId)) {
105
+ ctx.addIssue({
106
+ code: "custom",
107
+ path: ["calls", index, "generationId"],
108
+ message: "model settlement generation ids must be unique",
109
+ });
140
110
  }
111
+ generationIds.add(call.generationId);
141
112
  if (call.model !== material.resolved.model) {
142
113
  ctx.addIssue({
143
114
  code: "custom",
@@ -179,7 +150,7 @@ function refineModelSettlementMaterial(material, ctx) {
179
150
  });
180
151
  }
181
152
  }
182
- export const agentCandidateModelSettlementEvidenceSchema = evidenceSchema("agent-candidate-model-settlement", agentCandidateModelSettlementMaterialSchema, "model settlement");
153
+ export const agentCandidateModelSettlementEvidenceSchema = evidenceSchema(2, "agent-candidate-model-settlement", agentCandidateModelSettlementMaterialSchema, "model settlement");
183
154
  export const agentCandidateRepositoryStateSchema = z
184
155
  .object({
185
156
  identity: z.string().min(1),
@@ -199,42 +170,82 @@ export const agentCandidateRepositoryStateSchema = z
199
170
  });
200
171
  export const agentCandidateTaskOutcomeMaterialSchema = z
201
172
  .object({
202
- schemaVersion: z.literal(1),
173
+ schemaVersion: z.literal(2),
203
174
  kind: z.literal("agent-candidate-task-outcome-material"),
204
175
  executionPlanDigest: sha256DigestSchema,
205
- baseRepository: agentCandidateRepositoryStateSchema,
206
- resultRepository: agentCandidateRepositoryStateSchema,
207
- afterState: agentCandidateWorkspaceSnapshotEvidenceSchema,
208
- gitDiff: z
209
- .object({
210
- format: z.literal("git-diff-binary"),
211
- artifact: agentCandidateArtifactRefSchema,
212
- })
213
- .strict(),
176
+ outcome: z.discriminatedUnion("kind", [
177
+ z
178
+ .object({
179
+ kind: z.literal("workspace"),
180
+ baseRepository: agentCandidateRepositoryStateSchema,
181
+ resultRepository: agentCandidateRepositoryStateSchema,
182
+ afterState: agentCandidateWorkspaceSnapshotEvidenceSchema,
183
+ gitDiff: z
184
+ .object({
185
+ format: z.literal("git-diff-binary"),
186
+ artifact: agentCandidateArtifactRefSchema,
187
+ })
188
+ .strict(),
189
+ })
190
+ .strict(),
191
+ z
192
+ .object({
193
+ kind: z.literal("output"),
194
+ spec: z
195
+ .object({
196
+ mediaType: agentCandidateMediaTypeSchema,
197
+ maxBytes: z.number().int().positive().max(64 * 1024 * 1024),
198
+ })
199
+ .strict(),
200
+ artifact: agentCandidateArtifactRefSchema,
201
+ })
202
+ .strict(),
203
+ ]),
214
204
  })
215
205
  .strict()
216
206
  .superRefine((material, ctx) => {
217
- if (material.baseRepository.identity !== material.resultRepository.identity) {
207
+ if (material.outcome.kind === "workspace" &&
208
+ material.outcome.baseRepository.identity !==
209
+ material.outcome.resultRepository.identity) {
218
210
  ctx.addIssue({
219
211
  code: "custom",
220
- path: ["resultRepository", "identity"],
212
+ path: ["outcome", "resultRepository", "identity"],
221
213
  message: "base and result repository identities must match",
222
214
  });
223
215
  }
224
- if (material.baseRepository.rootIdentity !==
225
- material.resultRepository.rootIdentity) {
216
+ if (material.outcome.kind === "workspace" &&
217
+ material.outcome.baseRepository.rootIdentity !==
218
+ material.outcome.resultRepository.rootIdentity) {
226
219
  ctx.addIssue({
227
220
  code: "custom",
228
- path: ["resultRepository", "rootIdentity"],
221
+ path: ["outcome", "resultRepository", "rootIdentity"],
229
222
  message: "base and result repository roots must match",
230
223
  });
231
224
  }
232
- if (!sameGitObjectFormat(material.baseRepository.commit, material.resultRepository.commit) ||
233
- !sameGitObjectFormat(material.baseRepository.tree, material.resultRepository.tree)) {
225
+ if (material.outcome.kind === "workspace") {
226
+ if (!sameGitObjectFormat(material.outcome.baseRepository.commit, material.outcome.resultRepository.commit) ||
227
+ !sameGitObjectFormat(material.outcome.baseRepository.tree, material.outcome.resultRepository.tree)) {
228
+ ctx.addIssue({
229
+ code: "custom",
230
+ path: ["outcome", "resultRepository"],
231
+ message: "base and result repositories must use one Git object format",
232
+ });
233
+ }
234
+ }
235
+ if (material.outcome.kind === "output" &&
236
+ material.outcome.artifact.byteLength === 0) {
237
+ ctx.addIssue({
238
+ code: "custom",
239
+ path: ["outcome", "artifact"],
240
+ message: "task outcome artifact cannot be empty",
241
+ });
242
+ }
243
+ if (material.outcome.kind === "output" &&
244
+ material.outcome.artifact.byteLength > material.outcome.spec.maxBytes) {
234
245
  ctx.addIssue({
235
246
  code: "custom",
236
- path: ["resultRepository"],
237
- message: "base and result repositories must use one Git object format",
247
+ path: ["outcome", "artifact", "byteLength"],
248
+ message: "task outcome artifact exceeds its signed byte limit",
238
249
  });
239
250
  }
240
251
  if (!isCanonicalJsonValue(material)) {
@@ -244,7 +255,7 @@ export const agentCandidateTaskOutcomeMaterialSchema = z
244
255
  });
245
256
  }
246
257
  });
247
- export const agentCandidateTaskOutcomeEvidenceSchema = evidenceSchema("agent-candidate-task-outcome", agentCandidateTaskOutcomeMaterialSchema, "task outcome");
258
+ export const agentCandidateTaskOutcomeEvidenceSchema = evidenceSchema(2, "agent-candidate-task-outcome", agentCandidateTaskOutcomeMaterialSchema, "task outcome");
248
259
  export const agentCandidateBenchmarkDimensionSchema = z
249
260
  .object({
250
261
  name: normalizedDimensionNameSchema,
@@ -318,8 +329,8 @@ export const agentCandidateBenchmarkResultMaterialSchema = z
318
329
  });
319
330
  }
320
331
  });
321
- export const agentCandidateBenchmarkResultEvidenceSchema = evidenceSchema("agent-candidate-benchmark-result", agentCandidateBenchmarkResultMaterialSchema, "benchmark result");
322
- export function sameFixedSpend(left, right) {
332
+ export const agentCandidateBenchmarkResultEvidenceSchema = evidenceSchema(1, "agent-candidate-benchmark-result", agentCandidateBenchmarkResultMaterialSchema, "benchmark result");
333
+ function sameFixedSpend(left, right) {
323
334
  return (left.inputTokens === right.inputTokens &&
324
335
  left.outputTokens === right.outputTokens &&
325
336
  left.cachedInputTokens === right.cachedInputTokens &&
@@ -327,10 +338,10 @@ export function sameFixedSpend(left, right) {
327
338
  left.modelCalls === right.modelCalls &&
328
339
  left.costUsdNanos === right.costUsdNanos);
329
340
  }
330
- function evidenceSchema(kind, material, label) {
341
+ function evidenceSchema(schemaVersion, kind, material, label) {
331
342
  return z
332
343
  .object({
333
- schemaVersion: z.literal(1),
344
+ schemaVersion: z.literal(schemaVersion),
334
345
  kind: z.literal(kind),
335
346
  digest: sha256DigestSchema,
336
347
  material,