@tangle-network/agent-interface 0.25.0 → 0.26.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.
@@ -1,8 +1,7 @@
1
1
  import { z } from "zod";
2
- import { agentCandidateCapturedArtifactSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, } from "./agent-candidate-artifact-schema.js";
2
+ import { agentCandidateArtifactRefSchema, agentCandidateCapturedArtifactSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, } from "./agent-candidate-artifact-schema.js";
3
3
  import { agentCandidateExecutionPlanEvidenceSchema, agentCandidateProfilePlanEvidenceSchema, agentCandidateResolvedModelSchema, } from "./agent-candidate-execution-plan-schema.js";
4
- import { agentCandidateSpendSchema, } from "./agent-candidate-lineage-schema.js";
5
- import { agentCandidateBenchmarkResultEvidenceSchema, agentCandidateFixedSpendSchema, agentCandidateModelSettlementEvidenceSchema, agentCandidateTaskOutcomeEvidenceSchema, sameFixedSpend, } from "./agent-candidate-outcome-schema.js";
4
+ import { agentCandidateBenchmarkResultEvidenceSchema, agentCandidateModelSettlementEvidenceSchema, agentCandidateTaskOutcomeEvidenceSchema, } from "./agent-candidate-outcome-schema.js";
6
5
  import { gitObjectSchema, isCanonicalJsonValue, isSafeRelativePath, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
7
6
  import { harnessTypeSchema } from "./harness.js";
8
7
  const entrypointReceiptSchema = z
@@ -45,12 +44,6 @@ export const agentCandidateTraceEvidenceSchema = z
45
44
  });
46
45
  }
47
46
  });
48
- export const agentCandidateModelUsageSchema = z
49
- .object({
50
- resolved: agentCandidateResolvedModelSchema,
51
- usage: agentCandidateSpendSchema,
52
- })
53
- .strict();
54
47
  export const agentCandidateMemoryReceiptSchema = z.discriminatedUnion("mode", [
55
48
  z.object({ mode: z.literal("disabled") }).strict(),
56
49
  z
@@ -82,7 +75,7 @@ export const agentCandidateTerminationSchema = z.discriminatedUnion("kind", [
82
75
  ]);
83
76
  export const agentCandidateMaterializationReceiptSchema = z
84
77
  .object({
85
- schemaVersion: z.literal(1),
78
+ schemaVersion: z.literal(2),
86
79
  kind: z.literal("agent-candidate-materialization"),
87
80
  digestAlgorithm: z.literal("rfc8785-sha256"),
88
81
  bundleDigest: sha256DigestSchema,
@@ -216,62 +209,16 @@ export const agentCandidateMaterializationReceiptSchema = z
216
209
  });
217
210
  export const agentCandidateRunReceiptSchema = z
218
211
  .object({
219
- schemaVersion: z.literal(1),
212
+ schemaVersion: z.literal(3),
220
213
  kind: z.literal("agent-candidate-run"),
221
214
  digestAlgorithm: z.literal("rfc8785-sha256"),
222
215
  bundleDigest: sha256DigestSchema,
223
216
  materializationReceiptDigest: sha256DigestSchema,
224
217
  executionPlanDigest: sha256DigestSchema,
225
218
  memory: agentCandidateMemoryReceiptSchema,
226
- usage: agentCandidateSpendSchema,
227
- modelUsage: agentCandidateModelUsageSchema,
228
219
  trace: agentCandidateTraceEvidenceSchema,
229
220
  termination: agentCandidateTerminationSchema,
230
- digest: sha256DigestSchema,
231
- })
232
- .strict()
233
- .superRefine((receipt, ctx) => {
234
- const usageMatchesModel = receipt.usage.costUsd === receipt.modelUsage.usage.costUsd &&
235
- receipt.usage.inputTokens === receipt.modelUsage.usage.inputTokens &&
236
- receipt.usage.outputTokens === receipt.modelUsage.usage.outputTokens &&
237
- receipt.usage.cachedInputTokens ===
238
- receipt.modelUsage.usage.cachedInputTokens &&
239
- receipt.usage.modelCalls === receipt.modelUsage.usage.modelCalls;
240
- if (!usageMatchesModel) {
241
- ctx.addIssue({
242
- code: "custom",
243
- path: ["modelUsage", "usage"],
244
- message: "single-model usage must equal aggregate protected usage",
245
- });
246
- }
247
- if (receipt.trace.modelCallCount !== receipt.modelUsage.usage.modelCalls) {
248
- ctx.addIssue({
249
- code: "custom",
250
- path: ["trace", "modelCallCount"],
251
- message: "trace model-call count must match protected single-model usage",
252
- });
253
- }
254
- if (!isCanonicalJsonValue(receipt)) {
255
- ctx.addIssue({
256
- code: "custom",
257
- message: "run receipt must contain only RFC 8785 JSON values",
258
- });
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,
221
+ executorCapture: agentCandidateArtifactRefSchema,
275
222
  modelSettlement: agentCandidateModelSettlementEvidenceSchema,
276
223
  taskOutcome: agentCandidateTaskOutcomeEvidenceSchema,
277
224
  benchmarkResult: agentCandidateBenchmarkResultEvidenceSchema,
@@ -279,41 +226,6 @@ export const agentCandidateRunReceiptV2Schema = z
279
226
  })
280
227
  .strict()
281
228
  .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
229
  if (receipt.modelSettlement.material.executionPlanDigest !==
318
230
  receipt.executionPlanDigest) {
319
231
  ctx.addIssue({
@@ -322,7 +234,8 @@ export const agentCandidateRunReceiptV2Schema = z
322
234
  message: "model settlement must bind the executed plan",
323
235
  });
324
236
  }
325
- if (receipt.trace.modelCallCount !== receipt.fixedUsage.modelCalls) {
237
+ if (receipt.trace.modelCallCount !==
238
+ receipt.modelSettlement.material.usage.modelCalls) {
326
239
  ctx.addIssue({
327
240
  code: "custom",
328
241
  path: ["trace", "modelCallCount"],
@@ -360,29 +273,7 @@ export const agentCandidateRunReceiptV2Schema = z
360
273
  });
361
274
  }
362
275
  });
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
- }
377
276
  const _materializationReceiptSchemaMatchesType = true;
378
277
  const _runReceiptSchemaMatchesType = true;
379
- const _anyRunReceiptSchemaMatchesType = true;
380
- const _runReceiptV1SchemaMatchesType = true;
381
- const _runReceiptV2SchemaMatchesType = true;
382
- const _v2MustNotSatisfyOriginalReceipt = true;
383
278
  void _materializationReceiptSchemaMatchesType;
384
279
  void _runReceiptSchemaMatchesType;
385
- void _anyRunReceiptSchemaMatchesType;
386
- void _runReceiptV1SchemaMatchesType;
387
- void _runReceiptV2SchemaMatchesType;
388
- void _v2MustNotSatisfyOriginalReceipt;
@@ -4,6 +4,8 @@ export declare const sha256DigestSchema: z.ZodType<Sha256Digest>;
4
4
  export declare const gitObjectSchema: z.ZodString;
5
5
  export declare const environmentNameSchema: z.ZodString;
6
6
  export declare const headerNameSchema: z.ZodString;
7
+ export declare const agentCandidateMediaTypeSchema: z.ZodString;
8
+ export declare function sha256Utf8(value: string): Sha256Digest;
7
9
  export declare function isWellFormedUnicode(value: string): boolean;
8
10
  export declare function isSafeRelativePath(value: string, allowDot: boolean): boolean;
9
11
  export declare function isSafeExecutable(value: string): boolean;
@@ -1,8 +1,10 @@
1
+ import { sha256 } from "@noble/hashes/sha256";
1
2
  import { z } from "zod";
2
3
  const sha256Pattern = /^sha256:[a-f0-9]{64}$/;
3
4
  const gitObjectPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
4
5
  const environmentNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
6
  const headerNamePattern = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
7
+ const mediaTypePattern = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;
6
8
  const githubComponentPattern = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/;
7
9
  const secretNamePattern = /(?:^|[_-])(?:api[_-]?key|access[_-]?key|private[_-]?key|token|secret|password|credentials?|authorization|cookie|database[_-]?url|dsn|pat)(?:[_-]|$)/i;
8
10
  const obviousSecretValuePattern = /(?:\b(?:sk|gh[pousr]|github_pat|AKIA)[-_A-Za-z0-9]{12,}\b|-----BEGIN [A-Z ]*PRIVATE KEY-----|\bBearer\s+\S+)/;
@@ -29,6 +31,12 @@ export const sha256DigestSchema = z
29
31
  export const gitObjectSchema = z.string().regex(gitObjectPattern);
30
32
  export const environmentNameSchema = z.string().regex(environmentNamePattern);
31
33
  export const headerNameSchema = z.string().regex(headerNamePattern);
34
+ export const agentCandidateMediaTypeSchema = z.string().regex(mediaTypePattern);
35
+ export function sha256Utf8(value) {
36
+ const bytes = sha256(new TextEncoder().encode(value));
37
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
38
+ return `sha256:${hex}`;
39
+ }
32
40
  export function isWellFormedUnicode(value) {
33
41
  for (let index = 0; index < value.length; index++) {
34
42
  const code = value.charCodeAt(index);
@@ -8,7 +8,7 @@ import { z } from "zod";
8
8
  * compares lowercase `sha256:<hex>` identities before materialization.
9
9
  */
10
10
  export declare const agentCandidateBundleSchema: z.ZodObject<{
11
- schemaVersion: z.ZodLiteral<1>;
11
+ schemaVersion: z.ZodLiteral<2>;
12
12
  kind: z.ZodLiteral<"agent-candidate-bundle">;
13
13
  digestAlgorithm: z.ZodLiteral<"rfc8785-sha256">;
14
14
  profile: z.ZodObject<{
@@ -359,15 +359,15 @@ export declare const agentCandidateBundleSchema: z.ZodObject<{
359
359
  kind: z.ZodLiteral<"evaluator-task-container">;
360
360
  }, z.core.$strict>], "kind">;
361
361
  workspace: z.ZodOptional<z.ZodObject<{
362
- schemaVersion: z.ZodLiteral<1>;
362
+ schemaVersion: z.ZodLiteral<2>;
363
363
  kind: z.ZodLiteral<"agent-candidate-workspace-snapshot">;
364
364
  digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
365
365
  material: z.ZodObject<{
366
- schemaVersion: z.ZodLiteral<1>;
366
+ schemaVersion: z.ZodLiteral<2>;
367
367
  kind: z.ZodLiteral<"agent-candidate-workspace-manifest">;
368
368
  files: z.ZodArray<z.ZodObject<{
369
369
  path: z.ZodString;
370
- mode: z.ZodUnion<readonly [z.ZodLiteral<420>, z.ZodLiteral<493>]>;
370
+ mode: z.ZodNumber;
371
371
  sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
372
372
  byteLength: z.ZodNumber;
373
373
  }, z.core.$strict>>;
@@ -418,8 +418,71 @@ export declare const agentCandidateBundleSchema: z.ZodObject<{
418
418
  }, z.core.$strict>;
419
419
  }, z.core.$strict>;
420
420
  knowledge: z.ZodOptional<z.ZodObject<{
421
- snapshotId: z.ZodString;
422
- manifest: z.ZodObject<{
421
+ candidate: z.ZodObject<{
422
+ schemaVersion: z.ZodLiteral<1>;
423
+ kind: z.ZodLiteral<"knowledge-improvement-candidate">;
424
+ runId: z.ZodString;
425
+ candidateId: z.ZodString;
426
+ goalHash: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
427
+ baseHash: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
428
+ candidateHash: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
429
+ evidenceHash: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
430
+ promotionPlanHash: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
431
+ }, z.core.$strict>;
432
+ snapshot: z.ZodObject<{
433
+ schemaVersion: z.ZodLiteral<2>;
434
+ kind: z.ZodLiteral<"agent-candidate-workspace-snapshot">;
435
+ digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
436
+ material: z.ZodObject<{
437
+ schemaVersion: z.ZodLiteral<2>;
438
+ kind: z.ZodLiteral<"agent-candidate-workspace-manifest">;
439
+ files: z.ZodArray<z.ZodObject<{
440
+ path: z.ZodString;
441
+ mode: z.ZodNumber;
442
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
443
+ byteLength: z.ZodNumber;
444
+ }, z.core.$strict>>;
445
+ }, z.core.$strict>;
446
+ manifest: z.ZodUnion<readonly [z.ZodObject<{
447
+ locator: z.ZodDiscriminatedUnion<[z.ZodObject<{
448
+ kind: z.ZodLiteral<"s3">;
449
+ bucket: z.ZodString;
450
+ key: z.ZodString;
451
+ region: z.ZodOptional<z.ZodString>;
452
+ }, z.core.$strict>, z.ZodObject<{
453
+ kind: z.ZodLiteral<"ipfs">;
454
+ cid: z.ZodString;
455
+ path: z.ZodOptional<z.ZodString>;
456
+ }, z.core.$strict>], "kind">;
457
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
458
+ byteLength: z.ZodNumber;
459
+ }, z.core.$strict>, z.ZodObject<{
460
+ encoding: z.ZodLiteral<"base64">;
461
+ content: z.ZodString;
462
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
463
+ byteLength: z.ZodNumber;
464
+ }, z.core.$strict>]>;
465
+ archive: z.ZodUnion<readonly [z.ZodObject<{
466
+ locator: z.ZodDiscriminatedUnion<[z.ZodObject<{
467
+ kind: z.ZodLiteral<"s3">;
468
+ bucket: z.ZodString;
469
+ key: z.ZodString;
470
+ region: z.ZodOptional<z.ZodString>;
471
+ }, z.core.$strict>, z.ZodObject<{
472
+ kind: z.ZodLiteral<"ipfs">;
473
+ cid: z.ZodString;
474
+ path: z.ZodOptional<z.ZodString>;
475
+ }, z.core.$strict>], "kind">;
476
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
477
+ byteLength: z.ZodNumber;
478
+ }, z.core.$strict>, z.ZodObject<{
479
+ encoding: z.ZodLiteral<"base64">;
480
+ content: z.ZodString;
481
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
482
+ byteLength: z.ZodNumber;
483
+ }, z.core.$strict>]>;
484
+ }, z.core.$strict>;
485
+ retrievalConfig: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
423
486
  locator: z.ZodDiscriminatedUnion<[z.ZodObject<{
424
487
  kind: z.ZodLiteral<"s3">;
425
488
  bucket: z.ZodString;
@@ -432,7 +495,31 @@ export declare const agentCandidateBundleSchema: z.ZodObject<{
432
495
  }, z.core.$strict>], "kind">;
433
496
  sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
434
497
  byteLength: z.ZodNumber;
435
- }, z.core.$strict>;
498
+ }, z.core.$strict>, z.ZodObject<{
499
+ encoding: z.ZodLiteral<"base64">;
500
+ content: z.ZodString;
501
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
502
+ byteLength: z.ZodNumber;
503
+ }, z.core.$strict>]>>;
504
+ evaluation: z.ZodUnion<readonly [z.ZodObject<{
505
+ locator: z.ZodDiscriminatedUnion<[z.ZodObject<{
506
+ kind: z.ZodLiteral<"s3">;
507
+ bucket: z.ZodString;
508
+ key: z.ZodString;
509
+ region: z.ZodOptional<z.ZodString>;
510
+ }, z.core.$strict>, z.ZodObject<{
511
+ kind: z.ZodLiteral<"ipfs">;
512
+ cid: z.ZodString;
513
+ path: z.ZodOptional<z.ZodString>;
514
+ }, z.core.$strict>], "kind">;
515
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
516
+ byteLength: z.ZodNumber;
517
+ }, z.core.$strict>, z.ZodObject<{
518
+ encoding: z.ZodLiteral<"base64">;
519
+ content: z.ZodString;
520
+ sha256: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
521
+ byteLength: z.ZodNumber;
522
+ }, z.core.$strict>]>;
436
523
  }, z.core.$strict>>;
437
524
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
438
525
  mode: z.ZodLiteral<"disabled">;
@@ -14,7 +14,7 @@ import { canonicalizeHarness } from "./harness.js";
14
14
  */
15
15
  export const agentCandidateBundleSchema = z
16
16
  .object({
17
- schemaVersion: z.literal(1),
17
+ schemaVersion: z.literal(2),
18
18
  kind: z.literal("agent-candidate-bundle"),
19
19
  digestAlgorithm: z.literal("rfc8785-sha256"),
20
20
  profile: agentCandidateProfileSchema,