@tangle-network/agent-interface 5.10.18 → 5.10.19

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
  /**
2
2
  * Lifecycle bounds a caller may place on one environment create (#309).
3
3
  *
4
- * Both are whole seconds — a millisecond value that is not a whole second is
4
+ * Bounds use whole seconds — a millisecond value that is not a whole second is
5
5
  * refused, so a caller never believes a sub-second bound was honored. A
6
6
  * provider that cannot enforce a requested bound fails the create rather than
7
7
  * dropping the field; one whose platform caps the value honors the shorter.
@@ -11,4 +11,6 @@ export interface AgentEnvironmentLifetime {
11
11
  maxLifetimeMs?: number;
12
12
  /** After this long with no caller activity the platform may suspend or stop the environment. */
13
13
  idleTimeoutMs?: number;
14
+ /** Delete the sealed stopped generation after this platform-owned retention interval. */
15
+ deleteAfterStoppedMs?: number;
14
16
  }
@@ -121,8 +121,8 @@ export declare const EnvironmentLifecycleSchema: z.ZodObject<{
121
121
  resumable: z.ZodBoolean;
122
122
  mode: z.ZodOptional<z.ZodEnum<{
123
123
  none: "none";
124
- native: "native";
125
124
  replayed: "replayed";
125
+ native: "native";
126
126
  }>>;
127
127
  }, z.core.$strict>>;
128
128
  persistence: z.ZodOptional<z.ZodObject<{
@@ -445,8 +445,8 @@ export declare const AgentEnvironmentObservationSchema: z.ZodObject<{
445
445
  resumable: z.ZodBoolean;
446
446
  mode: z.ZodOptional<z.ZodEnum<{
447
447
  none: "none";
448
- native: "native";
449
448
  replayed: "replayed";
449
+ native: "native";
450
450
  }>>;
451
451
  }, z.core.$strict>>;
452
452
  persistence: z.ZodOptional<z.ZodObject<{
@@ -493,8 +493,8 @@ export declare const AgentEnvironmentObservationSchema: z.ZodObject<{
493
493
  resumable: z.ZodBoolean;
494
494
  mode: z.ZodOptional<z.ZodEnum<{
495
495
  none: "none";
496
- native: "native";
497
496
  replayed: "replayed";
497
+ native: "native";
498
498
  }>>;
499
499
  }, z.core.$strict>>;
500
500
  persistence: z.ZodOptional<z.ZodObject<{
@@ -11,3 +11,4 @@ export * from "./environment-provider-error.js";
11
11
  export * from "./workspace-cwd.js";
12
12
  export * from "./workspace-snapshot.js";
13
13
  export * from "./proxy-secrets.js";
14
+ export { AgentTurnFailureSchema, type AgentTurnFailure } from "./execution-failure.js";
@@ -11,3 +11,4 @@ export * from "./environment-provider-error.js";
11
11
  export * from "./workspace-cwd.js";
12
12
  export * from "./workspace-snapshot.js";
13
13
  export * from "./proxy-secrets.js";
14
+ export { AgentTurnFailureSchema } from "./execution-failure.js";
@@ -1,3 +1,5 @@
1
+ import type { Sha256Digest } from "./agent-candidate.js";
2
+ import type { CreateAgentEnvironmentInput } from "./environment-runtime.js";
1
3
  import { z } from "zod";
2
4
  import type { WorkspaceCwd } from "./workspace-cwd.js";
3
5
  import { type WorkspaceCheckpointRef } from "./workspace-checkpoint.js";
@@ -241,3 +243,20 @@ export interface PlacementInfo {
241
243
  region?: string;
242
244
  providerMetadata?: Record<string, unknown>;
243
245
  }
246
+ /** Canonical create identity excludes the operation key and per-attempt abort signal.
247
+ * Keyed creates require canonical JSON; unkeyed creates may retain opaque mapper values.
248
+ * @internal */
249
+ export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
250
+ /** @internal State held by one provider adapter for keyed create retries. */
251
+ export interface AgentEnvironmentCreateIdempotencyRecord<T> {
252
+ readonly digest: Sha256Digest;
253
+ readonly pending: Promise<T>;
254
+ environment?: T;
255
+ }
256
+ /** Coalesce concurrent keyed creates and reject changed-input collisions before another create effect.
257
+ * The backing service retains keys across adapter reconstruction.
258
+ * The creating call keeps the provider's verdict; subsequent same-key calls receive a replayed view.
259
+ * Keyed callbacks receive an immutable canonical JSON snapshot shared by their digest, so later caller
260
+ * mutation cannot change accepted input. Unkeyed callbacks retain opaque mapper values by identity.
261
+ * @internal */
262
+ export declare function createAgentEnvironmentWithIdempotency<T extends object>(records: Map<string, AgentEnvironmentCreateIdempotencyRecord<T>>, input: CreateAgentEnvironmentInput, create: (input: CreateAgentEnvironmentInput) => Promise<T>): Promise<T>;
@@ -1,3 +1,5 @@
1
+ import { canonicalCandidateDigest, canonicalCandidateJson } from "./agent-candidate-schema-common.js";
2
+ import { deepFreeze } from "./deep-freeze.js";
1
3
  import { z } from "zod";
2
4
  import { boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH, } from "./contract-limits.js";
3
5
  import { workspaceCwdSchema } from "./workspace-cwd.js";
@@ -65,3 +67,66 @@ export const ResourceRequestSchema = z.strictObject({
65
67
  gpu: boundedIdentifierSchema.optional(),
66
68
  providerOptions: boundedJsonRecordSchema.optional(),
67
69
  });
70
+ /** Canonical create identity excludes the operation key and per-attempt abort signal.
71
+ * Keyed creates require canonical JSON; unkeyed creates may retain opaque mapper values.
72
+ * @internal */
73
+ export function agentEnvironmentCreateInputDigest(input) {
74
+ const { idempotencyKey: _idempotencyKey, signal: _signal, ...material } = input;
75
+ return canonicalCandidateDigest({
76
+ kind: "agent-environment-create.v1",
77
+ input: material,
78
+ });
79
+ }
80
+ /** Same-key callers share one environment, with creation:"replayed" because they provisioned nothing.
81
+ * Members must not read this; shallow replay views reject classes whose prototype would be lost.
82
+ * @internal */
83
+ function replayedAgentEnvironmentView(environment) {
84
+ const prototype = Object.getPrototypeOf(environment);
85
+ if (prototype !== Object.prototype && prototype !== null) {
86
+ throw new Error("a replayed agent environment view requires a plain object environment");
87
+ }
88
+ return { ...environment, creation: "replayed" };
89
+ }
90
+ /** Coalesce concurrent keyed creates and reject changed-input collisions before another create effect.
91
+ * The backing service retains keys across adapter reconstruction.
92
+ * The creating call keeps the provider's verdict; subsequent same-key calls receive a replayed view.
93
+ * Keyed callbacks receive an immutable canonical JSON snapshot shared by their digest, so later caller
94
+ * mutation cannot change accepted input. Unkeyed callbacks retain opaque mapper values by identity.
95
+ * @internal */
96
+ export async function createAgentEnvironmentWithIdempotency(records, input, create) {
97
+ const { idempotencyKey: key, signal, ...material } = input;
98
+ signal?.throwIfAborted();
99
+ if (key === undefined)
100
+ return create(input);
101
+ const snapshot = deepFreeze(JSON.parse(canonicalCandidateJson(material)));
102
+ const acceptedInput = Object.freeze({
103
+ ...snapshot,
104
+ idempotencyKey: key,
105
+ ...(signal === undefined ? {} : { signal }),
106
+ });
107
+ const digest = agentEnvironmentCreateInputDigest(acceptedInput);
108
+ const existing = records.get(key);
109
+ if (existing !== undefined) {
110
+ if (existing.digest !== digest) {
111
+ throw new Error("agent environment create idempotency key conflicts with a different create input");
112
+ }
113
+ return replayedAgentEnvironmentView(existing.environment ?? (await existing.pending));
114
+ }
115
+ const pending = Promise.resolve().then(() => create(acceptedInput));
116
+ const record = {
117
+ digest,
118
+ pending,
119
+ };
120
+ records.set(key, record);
121
+ try {
122
+ const environment = await pending;
123
+ if (records.get(key) === record)
124
+ record.environment = environment;
125
+ return environment;
126
+ }
127
+ catch (error) {
128
+ if (records.get(key) === record)
129
+ records.delete(key);
130
+ throw error;
131
+ }
132
+ }
@@ -1,9 +1,10 @@
1
+ import { type AgentTurnFailure } from "./execution-failure.js";
1
2
  import { z } from "zod";
2
3
  import { type ProxySecretBinding, type ProxySecretCapabilities, type ProxySecretReceipt, type ProxySecretParents } from "./proxy-secrets.js";
3
4
  import type { AgentRuntimeAttachments } from "./runtime-attachments.js";
4
5
  import type { AgentEnvironmentLifetime } from "./environment-lifetime.js";
5
6
  export { AgentRuntimeAttachmentsSchema, type AgentRuntimeAttachments } from "./runtime-attachments.js";
6
- import type { AgentCandidateArtifactPort, Sha256Digest } from "./agent-candidate.js";
7
+ import type { AgentCandidateArtifactPort } from "./agent-candidate.js";
7
8
  import type { AgentProfile, AgentProfileCapabilities, AgentProfileValidationResult } from "./agent-profile.js";
8
9
  import type { InputPart } from "./parts.js";
9
10
  import type { StreamEvent } from "./stream-events.js";
@@ -884,6 +885,7 @@ export interface AgentTurnResult {
884
885
  text: string;
885
886
  success: boolean;
886
887
  error?: string;
888
+ failure?: AgentTurnFailure;
887
889
  sessionId?: string;
888
890
  usage?: TokenUsage;
889
891
  metadata?: Record<string, unknown>;
@@ -895,6 +897,17 @@ export declare const AgentTurnResultSchema: z.ZodObject<{
895
897
  text: z.ZodCustom<string, string>;
896
898
  success: z.ZodBoolean;
897
899
  error: z.ZodOptional<z.ZodString>;
900
+ failure: z.ZodOptional<z.ZodObject<{
901
+ kind: z.ZodEnum<{
902
+ capacity: "capacity";
903
+ caller: "caller";
904
+ infra: "infra";
905
+ work: "work";
906
+ }>;
907
+ code: z.ZodString;
908
+ resetAt: z.ZodOptional<z.ZodISODateTime>;
909
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
910
+ }, z.core.$strict>>;
898
911
  sessionId: z.ZodOptional<z.ZodString>;
899
912
  usage: z.ZodOptional<z.ZodObject<{
900
913
  inputTokens: z.ZodNumber;
@@ -1053,6 +1066,17 @@ export declare const AgentNativeContextContinuationResultSchema: z.ZodUnion<read
1053
1066
  text: z.ZodCustom<string, string>;
1054
1067
  success: z.ZodBoolean;
1055
1068
  error: z.ZodOptional<z.ZodString>;
1069
+ failure: z.ZodOptional<z.ZodObject<{
1070
+ kind: z.ZodEnum<{
1071
+ capacity: "capacity";
1072
+ caller: "caller";
1073
+ infra: "infra";
1074
+ work: "work";
1075
+ }>;
1076
+ code: z.ZodString;
1077
+ resetAt: z.ZodOptional<z.ZodISODateTime>;
1078
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
1079
+ }, z.core.$strict>>;
1056
1080
  sessionId: z.ZodOptional<z.ZodString>;
1057
1081
  usage: z.ZodOptional<z.ZodObject<{
1058
1082
  inputTokens: z.ZodNumber;
@@ -1345,12 +1369,8 @@ export interface AgentEnvironment {
1345
1369
  readonly id: string;
1346
1370
  readonly provider: string;
1347
1371
  readonly name?: string;
1348
- /**
1349
- * The verdict of the create call that returned this object. It is a
1350
- * per-call fact: a same-key replay returns a view of the same environment
1351
- * with `creation: "replayed"`. Absent on `get()` results and when the
1352
- * provider cannot prove which outcome happened.
1353
- */
1372
+ /** Per-create verdict: a same-key replay returns this environment with creation:"replayed".
1373
+ * Absent on get() or when the provider cannot prove the create's outcome. */
1354
1374
  readonly creation?: AgentEnvironmentCreation;
1355
1375
  /** Authoritative receipt returned only by a qualified context-transfer attachment. */
1356
1376
  readonly contextTransferReceipt?: ContextTransferReceipt;
@@ -1358,23 +1378,12 @@ export interface AgentEnvironment {
1358
1378
  readonly proxySecretReceipt?: ProxySecretReceipt;
1359
1379
  /** API-verified effective parent pins read from current custody. */
1360
1380
  readonly proxySecretParents?: ProxySecretParents;
1361
- /**
1362
- * Detached metadata returned by the provider.
1363
- * It can contain caller-authored annotations and is not authorization evidence.
1364
- */
1381
+ /** Detached provider metadata can include caller annotations; it is not authorization evidence. */
1365
1382
  readonly metadata?: Readonly<Record<string, unknown>>;
1366
- /**
1367
- * The capability document for THIS environment, and the document a caller
1368
- * reads to decide which operation to offer against it.
1369
- *
1370
- * A capability the connected deployment decides is environment-scoped: one
1371
- * provider reaches deployments of different ages, so
1372
- * {@link AgentEnvironmentProvider.capabilities} can only state what holds
1373
- * before an environment exists. A provider that measures a capability per
1374
- * environment publishes the measured answer here, and the operations this
1375
- * environment exposes match it exactly. Absent when the provider document
1376
- * already describes every environment it creates.
1377
- */
1383
+ /** This deployment's capability document; exposed operations match it.
1384
+ * Provider capabilities describe what is known before create; deployments
1385
+ * reached by one provider can differ in age. Absent when provider capabilities
1386
+ * already describe every environment it creates. */
1378
1387
  readonly capabilities?: AgentEnvironmentCapabilities;
1379
1388
  status(options?: {
1380
1389
  signal?: AbortSignal;
@@ -1693,15 +1702,15 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
1693
1702
  confidential: z.ZodBoolean;
1694
1703
  exactProcess: z.ZodOptional<z.ZodObject<{
1695
1704
  egress: z.ZodArray<z.ZodEnum<{
1696
- strict: "strict";
1697
1705
  blocked: "blocked";
1706
+ strict: "strict";
1698
1707
  }>>;
1699
1708
  }, z.core.$strict>>;
1700
1709
  create: z.ZodOptional<z.ZodObject<{
1701
1710
  egress: z.ZodOptional<z.ZodArray<z.ZodEnum<{
1702
- open: "open";
1703
- strict: "strict";
1704
1711
  blocked: "blocked";
1712
+ strict: "strict";
1713
+ open: "open";
1705
1714
  }>>>;
1706
1715
  durableIdempotency: z.ZodOptional<z.ZodBoolean>;
1707
1716
  billingOwner: z.ZodOptional<z.ZodBoolean>;
@@ -1763,18 +1772,18 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
1763
1772
  }, z.core.$strict>;
1764
1773
  export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
1765
1774
  profile: AgentProfileRef;
1766
- /**
1767
- * Runtime-owned execution inputs, separate from authored profile identity.
1768
- * Providers must refuse unsupported attachments and authored MCP alias collisions.
1769
- * Credentials are sensitive transport input; never include them in receipts or logs.
1770
- * Attachments participate in keyed create identity and cannot be refreshed by replay.
1771
- */
1775
+ /** Runtime-owned attachments participate in keyed identity, not profile identity, and cannot refresh by replay.
1776
+ * Refuse unsupported attachments or MCP alias collisions; never log their credentials. */
1772
1777
  runtimeAttachments?: AgentRuntimeAttachments;
1773
1778
  /** Exact caller-owned id required by an accepted destination contract. */
1774
1779
  requestedId?: string;
1775
1780
  /** Agent backend inside the provider, for example "opencode" or "codex". */
1776
1781
  backend?: string;
1777
1782
  workspace?: WorkspaceRequest;
1783
+ /** Paths the platform seals with the stopped generation before retirement. */
1784
+ retain?: {
1785
+ paths: readonly string[];
1786
+ };
1778
1787
  resources?: ResourceRequest;
1779
1788
  env?: Record<string, string>;
1780
1789
  secrets?: (string | {
@@ -1790,76 +1799,22 @@ export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
1790
1799
  proxySecrets?: readonly ProxySecretBinding[];
1791
1800
  /** Host-only total destination-to-parent selection; null means explicit independent root. */
1792
1801
  proxySecretParents?: ProxySecretParents;
1793
- /**
1794
- * Outbound network policy for this environment.
1795
- *
1796
- * When absent the provider applies its own default. That default can be a strict allowlist,
1797
- * and a model endpoint the environment must reach is then refused inside the environment as an
1798
- * authorization error that names no policy. Declare the policy whenever the destinations the
1799
- * environment needs are known.
1800
- *
1801
- * A provider that cannot satisfy the requested mode must fail the create rather than weaken or
1802
- * widen the policy. {@link AgentEnvironmentCapabilities.create} names the modes it accepts.
1803
- */
1802
+ /** Outbound network policy. Omission uses the provider default, which may be a strict allowlist.
1803
+ * Declare known required destinations; providers must refuse unsupported modes instead of widening
1804
+ * or weakening them. create capabilities name the accepted modes. */
1804
1805
  egress?: AgentEnvironmentEgressPolicy;
1805
- /**
1806
- * Platform account whose balance funds this environment's managed model usage.
1807
- *
1808
- * A trusted first-party service acting for an authenticated user sets it. The provider honors
1809
- * it only for a caller its platform has authorized to bill that account, and rejects the create
1810
- * otherwise. It never grants a caller permission to charge an arbitrary account.
1811
- */
1806
+ /** Platform account funding managed model usage. Only a trusted service authorized to bill
1807
+ * that authenticated user's account may set it; other creates are rejected. */
1812
1808
  billingOwner?: string;
1813
1809
  metadata?: Record<string, unknown>;
1814
1810
  name?: string;
1815
- /**
1816
- * Stable identity for one logical environment create.
1817
- *
1818
- * When present, the provider must use this key as one idempotent operation:
1819
- * the same key with canonically equal create input must return or reconstruct
1820
- * the same environment, while a different input must be rejected.
1821
- */
1811
+ /** Idempotent create identity: the same key with equal canonical input reconstructs the same
1812
+ * environment; different input under that key is refused. */
1822
1813
  idempotencyKey?: string;
1823
1814
  signal?: AbortSignal;
1824
1815
  providerOptions?: Record<string, unknown>;
1825
1816
  }
1826
- /**
1827
- * Compute the canonical identity of a generic environment create request.
1828
- *
1829
- * The operation key names the request and the abort signal controls one
1830
- * attempt, so neither belongs in the input identity. Every other field is
1831
- * canonicalized with the shared RFC 8785 JSON representation.
1832
- * A keyed create therefore accepts only canonical JSON material.
1833
- * Unkeyed creates can retain opaque provider-native mapper values.
1834
- * @internal
1835
- */
1836
- export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
1837
- /** @internal State held by one provider adapter for keyed create retries. */
1838
- export interface AgentEnvironmentCreateIdempotencyRecord<T> {
1839
- readonly digest: Sha256Digest;
1840
- readonly pending: Promise<T>;
1841
- environment?: T;
1842
- }
1843
- /**
1844
- * Apply the generic create contract to one provider adapter's keyed requests.
1845
- *
1846
- * The provider's backing service remains responsible for retaining the key
1847
- * across adapter reconstruction. This helper coalesces concurrent retries and
1848
- * rejects collisions before the provider performs another create effect.
1849
- *
1850
- * The call that runs `create` receives the environment the provider built,
1851
- * with the creation verdict the provider could prove. Every same-key call
1852
- * after it, including one that awaited the same pending create, receives
1853
- * {@link replayedAgentEnvironmentView} of that environment.
1854
- *
1855
- * A keyed create callback receives one immutable canonical JSON snapshot.
1856
- * Its digest and provider therefore read identical request bytes even when
1857
- * the caller mutates its original object after this function returns.
1858
- * An unkeyed create retains its original input so opaque provider-native
1859
- * mapper values retain their public identity.
1860
- * @internal
1861
- */
1862
- export declare function createAgentEnvironmentWithIdempotency<T extends object>(records: Map<string, AgentEnvironmentCreateIdempotencyRecord<T>>, input: CreateAgentEnvironmentInput, create: (input: CreateAgentEnvironmentInput) => Promise<T>): Promise<T>;
1817
+ export { agentEnvironmentCreateInputDigest, createAgentEnvironmentWithIdempotency, type AgentEnvironmentCreateIdempotencyRecord } from "./environment-requests.js";
1863
1818
  /** Reconstruct an existing environment; never allocates a replacement. */
1864
1819
  export interface AgentEnvironmentGetOptions {
1865
1820
  signal?: AbortSignal;
@@ -1,7 +1,7 @@
1
+ import { AgentTurnFailureSchema } from "./execution-failure.js";
1
2
  import { z } from "zod";
2
3
  import { ProxySecretCapabilitiesSchema, ProxySecretParentsSchema, isProxySecretParentsTotal, ProxySecretsSchema, ProxySecretUpdateControlsSchema } from "./proxy-secrets.js";
3
4
  export { AgentRuntimeAttachmentsSchema } from "./runtime-attachments.js";
4
- import { canonicalCandidateDigest, canonicalCandidateJson, } from "./agent-candidate-schema-common.js";
5
5
  import { agentProfileSchema } from "./profile-schema.js";
6
6
  import { TokenUsageSchema } from "./execution-types.js";
7
7
  import { InteractionCapabilitiesSchema, RequestedInteractionsSchema } from "./interaction.js";
@@ -10,7 +10,6 @@ import { AgentExactRunControlRefSchema, AgentRunControlRefSchema, CanonicalStrea
10
10
  import { AgentProfileCapabilitiesSchema } from "./environment-profile-capabilities.js";
11
11
  import { boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
12
12
  import { InputPartSchema } from "./portable-context-shared.js";
13
- import { deepFreeze } from "./deep-freeze.js";
14
13
  export const AgentTurnInputSchema = z.strictObject({
15
14
  profile: agentProfileSchema.optional(),
16
15
  // A prompt is what the agent is asked to do, so it is CONTENT: its size is set by the work,
@@ -54,6 +53,7 @@ export const AgentTurnResultSchema = z.strictObject({
54
53
  text: boundedEventContentStringSchema,
55
54
  success: z.boolean(),
56
55
  error: boundedStringSchema.optional(),
56
+ failure: AgentTurnFailureSchema.optional(),
57
57
  sessionId: boundedIdentifierSchema.optional(),
58
58
  usage: TokenUsageSchema.optional(),
59
59
  metadata: boundedJsonRecordSchema.optional(),
@@ -436,96 +436,7 @@ export const AgentEnvironmentCapabilitiesSchema = z
436
436
  });
437
437
  }
438
438
  });
439
- /**
440
- * Compute the canonical identity of a generic environment create request.
441
- *
442
- * The operation key names the request and the abort signal controls one
443
- * attempt, so neither belongs in the input identity. Every other field is
444
- * canonicalized with the shared RFC 8785 JSON representation.
445
- * A keyed create therefore accepts only canonical JSON material.
446
- * Unkeyed creates can retain opaque provider-native mapper values.
447
- * @internal
448
- */
449
- export function agentEnvironmentCreateInputDigest(input) {
450
- const { idempotencyKey: _idempotencyKey, signal: _signal, ...material } = input;
451
- return canonicalCandidateDigest({
452
- kind: "agent-environment-create.v1",
453
- input: material,
454
- });
455
- }
456
- /**
457
- * Return the per-call view of an environment that a same-key create replayed.
458
- *
459
- * The view shares every member of the environment, so operations act on the
460
- * one environment, and it states `creation: "replayed"` because this call
461
- * provisioned nothing. The copy is shallow, so the environment must be a plain
462
- * object whose members do not read `this`; a class instance loses its
463
- * prototype members in a copy and is rejected.
464
- * @internal
465
- */
466
- function replayedAgentEnvironmentView(environment) {
467
- const prototype = Object.getPrototypeOf(environment);
468
- if (prototype !== Object.prototype && prototype !== null) {
469
- throw new Error("a replayed agent environment view requires a plain object environment");
470
- }
471
- return { ...environment, creation: "replayed" };
472
- }
473
- /**
474
- * Apply the generic create contract to one provider adapter's keyed requests.
475
- *
476
- * The provider's backing service remains responsible for retaining the key
477
- * across adapter reconstruction. This helper coalesces concurrent retries and
478
- * rejects collisions before the provider performs another create effect.
479
- *
480
- * The call that runs `create` receives the environment the provider built,
481
- * with the creation verdict the provider could prove. Every same-key call
482
- * after it, including one that awaited the same pending create, receives
483
- * {@link replayedAgentEnvironmentView} of that environment.
484
- *
485
- * A keyed create callback receives one immutable canonical JSON snapshot.
486
- * Its digest and provider therefore read identical request bytes even when
487
- * the caller mutates its original object after this function returns.
488
- * An unkeyed create retains its original input so opaque provider-native
489
- * mapper values retain their public identity.
490
- * @internal
491
- */
492
- export async function createAgentEnvironmentWithIdempotency(records, input, create) {
493
- const { idempotencyKey: key, signal, ...material } = input;
494
- signal?.throwIfAborted();
495
- if (key === undefined)
496
- return create(input);
497
- const snapshot = deepFreeze(JSON.parse(canonicalCandidateJson(material)));
498
- const acceptedInput = Object.freeze({
499
- ...snapshot,
500
- idempotencyKey: key,
501
- ...(signal === undefined ? {} : { signal }),
502
- });
503
- const digest = agentEnvironmentCreateInputDigest(acceptedInput);
504
- const existing = records.get(key);
505
- if (existing !== undefined) {
506
- if (existing.digest !== digest) {
507
- throw new Error("agent environment create idempotency key conflicts with a different create input");
508
- }
509
- return replayedAgentEnvironmentView(existing.environment ?? (await existing.pending));
510
- }
511
- const pending = Promise.resolve().then(() => create(acceptedInput));
512
- const record = {
513
- digest,
514
- pending,
515
- };
516
- records.set(key, record);
517
- try {
518
- const environment = await pending;
519
- if (records.get(key) === record)
520
- record.environment = environment;
521
- return environment;
522
- }
523
- catch (error) {
524
- if (records.get(key) === record)
525
- records.delete(key);
526
- throw error;
527
- }
528
- }
439
+ export { agentEnvironmentCreateInputDigest, createAgentEnvironmentWithIdempotency } from "./environment-requests.js";
529
440
  // Keep the existing parser strict: published providers that import it must not silently
530
441
  // accept readOnly and then perform their ordinary reconnect side effects.
531
442
  const environmentGetSignalSchema = z.custom().optional();
@@ -22,3 +22,16 @@ export declare class AgentExecutionError extends Error {
22
22
  readonly receipt: AgentExecutionFailureReceipt;
23
23
  constructor(message: string, receipt: AgentExecutionFailureReceipt, options?: ErrorOptions);
24
24
  }
25
+ /** Stable producer-owned turn classification, retained independently of its diagnostic text. */
26
+ export declare const AgentTurnFailureSchema: z.ZodObject<{
27
+ kind: z.ZodEnum<{
28
+ capacity: "capacity";
29
+ caller: "caller";
30
+ infra: "infra";
31
+ work: "work";
32
+ }>;
33
+ code: z.ZodString;
34
+ resetAt: z.ZodOptional<z.ZodISODateTime>;
35
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
36
+ }, z.core.$strict>;
37
+ export type AgentTurnFailure = z.infer<typeof AgentTurnFailureSchema>;
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { boundedIdentifierSchema } from "./contract-limits.js";
2
3
  import { deepFreeze } from "./deep-freeze.js";
3
4
  import { TokenUsageSchema } from "./execution-types.js";
4
5
  export const AgentExecutionFailureReceiptSchema = z.strictObject({
@@ -18,3 +19,10 @@ export class AgentExecutionError extends Error {
18
19
  this.receipt = deepFreeze(AgentExecutionFailureReceiptSchema.parse(receipt));
19
20
  }
20
21
  }
22
+ /** Stable producer-owned turn classification, retained independently of its diagnostic text. */
23
+ export const AgentTurnFailureSchema = z.strictObject({
24
+ kind: z.enum(["capacity", "caller", "infra", "work"]),
25
+ code: boundedIdentifierSchema,
26
+ resetAt: z.iso.datetime().optional(),
27
+ retryAfterMs: z.number().int().nonnegative().safe().optional(),
28
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "5.10.18",
3
+ "version": "5.10.19",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",