@tangle-network/agent-interface 5.10.17 → 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.
- package/dist/agent-profile.d.ts +2 -2
- package/dist/environment-interactive-start.d.ts +2 -0
- package/dist/environment-lifetime.d.ts +3 -1
- package/dist/environment-observation.d.ts +3 -3
- package/dist/environment-provider.d.ts +1 -0
- package/dist/environment-provider.js +1 -0
- package/dist/environment-requests.d.ts +19 -0
- package/dist/environment-requests.js +65 -0
- package/dist/environment-runtime.d.ts +55 -94
- package/dist/environment-runtime.js +3 -92
- package/dist/execution-failure.d.ts +13 -0
- package/dist/execution-failure.js +8 -0
- package/dist/portable-context-transfer.d.ts +2 -0
- package/dist/profile-schema.d.ts +4 -0
- package/dist/profile-schema.js +6 -3
- package/package.json +1 -1
package/dist/agent-profile.d.ts
CHANGED
|
@@ -148,8 +148,8 @@ export interface AgentProfileSeat {
|
|
|
148
148
|
model: string;
|
|
149
149
|
/** Override profile.model.reasoningEffort for this stage; omission inherits, none disables thinking. */
|
|
150
150
|
reasoningEffort?: ReasoningEffort;
|
|
151
|
-
/** This stage's credential intent; omitted inherits profile.model.metadata.credentialSource (absent there means
|
|
152
|
-
credentialSource?: "subscription" | "managed";
|
|
151
|
+
/** This stage's credential intent; omitted inherits profile.model.metadata.credentialSource (absent there means router). */
|
|
152
|
+
credentialSource?: "router" | "api-key" | "subscription" | "managed";
|
|
153
153
|
/** Select all eligible accounts in account-manager order, or one named account. */
|
|
154
154
|
selector: {
|
|
155
155
|
kind: "all-eligible";
|
|
@@ -103,6 +103,8 @@ export declare const AgentInteractiveSessionStartSchema: z.ZodObject<{
|
|
|
103
103
|
ultracode: "ultracode";
|
|
104
104
|
}>>;
|
|
105
105
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
106
|
+
router: "router";
|
|
107
|
+
"api-key": "api-key";
|
|
106
108
|
subscription: "subscription";
|
|
107
109
|
managed: "managed";
|
|
108
110
|
}>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lifecycle bounds a caller may place on one environment create (#309).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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<{
|
|
@@ -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
|
|
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";
|
|
@@ -128,6 +129,8 @@ export declare const AgentTurnInputSchema: z.ZodObject<{
|
|
|
128
129
|
ultracode: "ultracode";
|
|
129
130
|
}>>;
|
|
130
131
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
132
|
+
router: "router";
|
|
133
|
+
"api-key": "api-key";
|
|
131
134
|
subscription: "subscription";
|
|
132
135
|
managed: "managed";
|
|
133
136
|
}>>;
|
|
@@ -541,6 +544,8 @@ export declare const AgentTurnInputSchema: z.ZodObject<{
|
|
|
541
544
|
ultracode: "ultracode";
|
|
542
545
|
}>>;
|
|
543
546
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
547
|
+
router: "router";
|
|
548
|
+
"api-key": "api-key";
|
|
544
549
|
subscription: "subscription";
|
|
545
550
|
managed: "managed";
|
|
546
551
|
}>>;
|
|
@@ -880,6 +885,7 @@ export interface AgentTurnResult {
|
|
|
880
885
|
text: string;
|
|
881
886
|
success: boolean;
|
|
882
887
|
error?: string;
|
|
888
|
+
failure?: AgentTurnFailure;
|
|
883
889
|
sessionId?: string;
|
|
884
890
|
usage?: TokenUsage;
|
|
885
891
|
metadata?: Record<string, unknown>;
|
|
@@ -891,6 +897,17 @@ export declare const AgentTurnResultSchema: z.ZodObject<{
|
|
|
891
897
|
text: z.ZodCustom<string, string>;
|
|
892
898
|
success: z.ZodBoolean;
|
|
893
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>>;
|
|
894
911
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
895
912
|
usage: z.ZodOptional<z.ZodObject<{
|
|
896
913
|
inputTokens: z.ZodNumber;
|
|
@@ -1049,6 +1066,17 @@ export declare const AgentNativeContextContinuationResultSchema: z.ZodUnion<read
|
|
|
1049
1066
|
text: z.ZodCustom<string, string>;
|
|
1050
1067
|
success: z.ZodBoolean;
|
|
1051
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>>;
|
|
1052
1080
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
1053
1081
|
usage: z.ZodOptional<z.ZodObject<{
|
|
1054
1082
|
inputTokens: z.ZodNumber;
|
|
@@ -1341,12 +1369,8 @@ export interface AgentEnvironment {
|
|
|
1341
1369
|
readonly id: string;
|
|
1342
1370
|
readonly provider: string;
|
|
1343
1371
|
readonly name?: string;
|
|
1344
|
-
/**
|
|
1345
|
-
*
|
|
1346
|
-
* per-call fact: a same-key replay returns a view of the same environment
|
|
1347
|
-
* with `creation: "replayed"`. Absent on `get()` results and when the
|
|
1348
|
-
* provider cannot prove which outcome happened.
|
|
1349
|
-
*/
|
|
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. */
|
|
1350
1374
|
readonly creation?: AgentEnvironmentCreation;
|
|
1351
1375
|
/** Authoritative receipt returned only by a qualified context-transfer attachment. */
|
|
1352
1376
|
readonly contextTransferReceipt?: ContextTransferReceipt;
|
|
@@ -1354,23 +1378,12 @@ export interface AgentEnvironment {
|
|
|
1354
1378
|
readonly proxySecretReceipt?: ProxySecretReceipt;
|
|
1355
1379
|
/** API-verified effective parent pins read from current custody. */
|
|
1356
1380
|
readonly proxySecretParents?: ProxySecretParents;
|
|
1357
|
-
/**
|
|
1358
|
-
* Detached metadata returned by the provider.
|
|
1359
|
-
* It can contain caller-authored annotations and is not authorization evidence.
|
|
1360
|
-
*/
|
|
1381
|
+
/** Detached provider metadata can include caller annotations; it is not authorization evidence. */
|
|
1361
1382
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1362
|
-
/**
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
* A capability the connected deployment decides is environment-scoped: one
|
|
1367
|
-
* provider reaches deployments of different ages, so
|
|
1368
|
-
* {@link AgentEnvironmentProvider.capabilities} can only state what holds
|
|
1369
|
-
* before an environment exists. A provider that measures a capability per
|
|
1370
|
-
* environment publishes the measured answer here, and the operations this
|
|
1371
|
-
* environment exposes match it exactly. Absent when the provider document
|
|
1372
|
-
* already describes every environment it creates.
|
|
1373
|
-
*/
|
|
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. */
|
|
1374
1387
|
readonly capabilities?: AgentEnvironmentCapabilities;
|
|
1375
1388
|
status(options?: {
|
|
1376
1389
|
signal?: AbortSignal;
|
|
@@ -1689,15 +1702,15 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
|
|
|
1689
1702
|
confidential: z.ZodBoolean;
|
|
1690
1703
|
exactProcess: z.ZodOptional<z.ZodObject<{
|
|
1691
1704
|
egress: z.ZodArray<z.ZodEnum<{
|
|
1692
|
-
strict: "strict";
|
|
1693
1705
|
blocked: "blocked";
|
|
1706
|
+
strict: "strict";
|
|
1694
1707
|
}>>;
|
|
1695
1708
|
}, z.core.$strict>>;
|
|
1696
1709
|
create: z.ZodOptional<z.ZodObject<{
|
|
1697
1710
|
egress: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1698
|
-
open: "open";
|
|
1699
|
-
strict: "strict";
|
|
1700
1711
|
blocked: "blocked";
|
|
1712
|
+
strict: "strict";
|
|
1713
|
+
open: "open";
|
|
1701
1714
|
}>>>;
|
|
1702
1715
|
durableIdempotency: z.ZodOptional<z.ZodBoolean>;
|
|
1703
1716
|
billingOwner: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1759,18 +1772,18 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
|
|
|
1759
1772
|
}, z.core.$strict>;
|
|
1760
1773
|
export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
|
|
1761
1774
|
profile: AgentProfileRef;
|
|
1762
|
-
/**
|
|
1763
|
-
*
|
|
1764
|
-
* Providers must refuse unsupported attachments and authored MCP alias collisions.
|
|
1765
|
-
* Credentials are sensitive transport input; never include them in receipts or logs.
|
|
1766
|
-
* Attachments participate in keyed create identity and cannot be refreshed by replay.
|
|
1767
|
-
*/
|
|
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. */
|
|
1768
1777
|
runtimeAttachments?: AgentRuntimeAttachments;
|
|
1769
1778
|
/** Exact caller-owned id required by an accepted destination contract. */
|
|
1770
1779
|
requestedId?: string;
|
|
1771
1780
|
/** Agent backend inside the provider, for example "opencode" or "codex". */
|
|
1772
1781
|
backend?: string;
|
|
1773
1782
|
workspace?: WorkspaceRequest;
|
|
1783
|
+
/** Paths the platform seals with the stopped generation before retirement. */
|
|
1784
|
+
retain?: {
|
|
1785
|
+
paths: readonly string[];
|
|
1786
|
+
};
|
|
1774
1787
|
resources?: ResourceRequest;
|
|
1775
1788
|
env?: Record<string, string>;
|
|
1776
1789
|
secrets?: (string | {
|
|
@@ -1786,76 +1799,22 @@ export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
|
|
|
1786
1799
|
proxySecrets?: readonly ProxySecretBinding[];
|
|
1787
1800
|
/** Host-only total destination-to-parent selection; null means explicit independent root. */
|
|
1788
1801
|
proxySecretParents?: ProxySecretParents;
|
|
1789
|
-
/**
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
* When absent the provider applies its own default. That default can be a strict allowlist,
|
|
1793
|
-
* and a model endpoint the environment must reach is then refused inside the environment as an
|
|
1794
|
-
* authorization error that names no policy. Declare the policy whenever the destinations the
|
|
1795
|
-
* environment needs are known.
|
|
1796
|
-
*
|
|
1797
|
-
* A provider that cannot satisfy the requested mode must fail the create rather than weaken or
|
|
1798
|
-
* widen the policy. {@link AgentEnvironmentCapabilities.create} names the modes it accepts.
|
|
1799
|
-
*/
|
|
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. */
|
|
1800
1805
|
egress?: AgentEnvironmentEgressPolicy;
|
|
1801
|
-
/**
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
* A trusted first-party service acting for an authenticated user sets it. The provider honors
|
|
1805
|
-
* it only for a caller its platform has authorized to bill that account, and rejects the create
|
|
1806
|
-
* otherwise. It never grants a caller permission to charge an arbitrary account.
|
|
1807
|
-
*/
|
|
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. */
|
|
1808
1808
|
billingOwner?: string;
|
|
1809
1809
|
metadata?: Record<string, unknown>;
|
|
1810
1810
|
name?: string;
|
|
1811
|
-
/**
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
* When present, the provider must use this key as one idempotent operation:
|
|
1815
|
-
* the same key with canonically equal create input must return or reconstruct
|
|
1816
|
-
* the same environment, while a different input must be rejected.
|
|
1817
|
-
*/
|
|
1811
|
+
/** Idempotent create identity: the same key with equal canonical input reconstructs the same
|
|
1812
|
+
* environment; different input under that key is refused. */
|
|
1818
1813
|
idempotencyKey?: string;
|
|
1819
1814
|
signal?: AbortSignal;
|
|
1820
1815
|
providerOptions?: Record<string, unknown>;
|
|
1821
1816
|
}
|
|
1822
|
-
|
|
1823
|
-
* Compute the canonical identity of a generic environment create request.
|
|
1824
|
-
*
|
|
1825
|
-
* The operation key names the request and the abort signal controls one
|
|
1826
|
-
* attempt, so neither belongs in the input identity. Every other field is
|
|
1827
|
-
* canonicalized with the shared RFC 8785 JSON representation.
|
|
1828
|
-
* A keyed create therefore accepts only canonical JSON material.
|
|
1829
|
-
* Unkeyed creates can retain opaque provider-native mapper values.
|
|
1830
|
-
* @internal
|
|
1831
|
-
*/
|
|
1832
|
-
export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
|
|
1833
|
-
/** @internal State held by one provider adapter for keyed create retries. */
|
|
1834
|
-
export interface AgentEnvironmentCreateIdempotencyRecord<T> {
|
|
1835
|
-
readonly digest: Sha256Digest;
|
|
1836
|
-
readonly pending: Promise<T>;
|
|
1837
|
-
environment?: T;
|
|
1838
|
-
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Apply the generic create contract to one provider adapter's keyed requests.
|
|
1841
|
-
*
|
|
1842
|
-
* The provider's backing service remains responsible for retaining the key
|
|
1843
|
-
* across adapter reconstruction. This helper coalesces concurrent retries and
|
|
1844
|
-
* rejects collisions before the provider performs another create effect.
|
|
1845
|
-
*
|
|
1846
|
-
* The call that runs `create` receives the environment the provider built,
|
|
1847
|
-
* with the creation verdict the provider could prove. Every same-key call
|
|
1848
|
-
* after it, including one that awaited the same pending create, receives
|
|
1849
|
-
* {@link replayedAgentEnvironmentView} of that environment.
|
|
1850
|
-
*
|
|
1851
|
-
* A keyed create callback receives one immutable canonical JSON snapshot.
|
|
1852
|
-
* Its digest and provider therefore read identical request bytes even when
|
|
1853
|
-
* the caller mutates its original object after this function returns.
|
|
1854
|
-
* An unkeyed create retains its original input so opaque provider-native
|
|
1855
|
-
* mapper values retain their public identity.
|
|
1856
|
-
* @internal
|
|
1857
|
-
*/
|
|
1858
|
-
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";
|
|
1859
1818
|
/** Reconstruct an existing environment; never allocates a replacement. */
|
|
1860
1819
|
export interface AgentEnvironmentGetOptions {
|
|
1861
1820
|
signal?: AbortSignal;
|
|
@@ -2067,6 +2026,8 @@ export declare const AgentEnvironmentGetOptionsSchema: z.ZodObject<{
|
|
|
2067
2026
|
ultracode: "ultracode";
|
|
2068
2027
|
}>>;
|
|
2069
2028
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
2029
|
+
router: "router";
|
|
2030
|
+
"api-key": "api-key";
|
|
2070
2031
|
subscription: "subscription";
|
|
2071
2032
|
managed: "managed";
|
|
2072
2033
|
}>>;
|
|
@@ -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
|
+
});
|
|
@@ -213,6 +213,8 @@ export declare const ContextTransferRequestSchema: z.ZodObject<{
|
|
|
213
213
|
ultracode: "ultracode";
|
|
214
214
|
}>>;
|
|
215
215
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
216
|
+
router: "router";
|
|
217
|
+
"api-key": "api-key";
|
|
216
218
|
subscription: "subscription";
|
|
217
219
|
managed: "managed";
|
|
218
220
|
}>>;
|
package/dist/profile-schema.d.ts
CHANGED
|
@@ -204,6 +204,8 @@ export declare const agentProfileSeatSchema: z.ZodObject<{
|
|
|
204
204
|
ultracode: "ultracode";
|
|
205
205
|
}>>;
|
|
206
206
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
207
|
+
router: "router";
|
|
208
|
+
"api-key": "api-key";
|
|
207
209
|
subscription: "subscription";
|
|
208
210
|
managed: "managed";
|
|
209
211
|
}>>;
|
|
@@ -574,6 +576,8 @@ export declare const agentProfileSchema: z.ZodObject<{
|
|
|
574
576
|
ultracode: "ultracode";
|
|
575
577
|
}>>;
|
|
576
578
|
credentialSource: z.ZodOptional<z.ZodEnum<{
|
|
579
|
+
router: "router";
|
|
580
|
+
"api-key": "api-key";
|
|
577
581
|
subscription: "subscription";
|
|
578
582
|
managed: "managed";
|
|
579
583
|
}>>;
|
package/dist/profile-schema.js
CHANGED
|
@@ -114,7 +114,7 @@ export const agentProfileSeatSchema = z.strictObject({
|
|
|
114
114
|
provider: z.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
115
115
|
model: z.string().min(1).refine((value) => value.trim() === value, "model must be canonical"),
|
|
116
116
|
reasoningEffort: reasoningEffortSchema.optional(),
|
|
117
|
-
credentialSource: z.enum(["subscription", "managed"]).optional(),
|
|
117
|
+
credentialSource: z.enum(["router", "api-key", "subscription", "managed"]).optional(),
|
|
118
118
|
selector: z.union([
|
|
119
119
|
z.strictObject({ kind: z.literal("all-eligible") }),
|
|
120
120
|
z.strictObject({ kind: z.literal("seat"), id: z.string().min(1).refine((value) => value.trim() === value, "seat id must be canonical") }),
|
|
@@ -427,7 +427,7 @@ export const agentProfileSchema = z
|
|
|
427
427
|
.superRefine((profile, context) => {
|
|
428
428
|
validateNestedRecordKeys(profile, context, [], new Set());
|
|
429
429
|
if (profile.seats?.length) {
|
|
430
|
-
const first = profile.seats[0], source = profile.model?.metadata?.credentialSource ?? "
|
|
430
|
+
const first = profile.seats[0], source = profile.model?.metadata?.credentialSource ?? "router";
|
|
431
431
|
if (first.harness !== profile.harness || first.provider !== profile.model?.provider ||
|
|
432
432
|
first.model !== profile.model?.default) {
|
|
433
433
|
context.addIssue({ code: "custom", path: ["seats", 0], message: "first seat must match profile harness, model.provider, and model.default" });
|
|
@@ -435,7 +435,10 @@ export const agentProfileSchema = z
|
|
|
435
435
|
if (first.reasoningEffort !== undefined && first.reasoningEffort !== profile.model?.reasoningEffort) {
|
|
436
436
|
context.addIssue({ code: "custom", path: ["seats", 0, "reasoningEffort"], message: "first seat reasoningEffort must match profile model.reasoningEffort" });
|
|
437
437
|
}
|
|
438
|
-
|
|
438
|
+
// `managed` is the deprecated spelling of `router`: an authored profile may still carry
|
|
439
|
+
// either, and the two agree wherever the default would apply (#440).
|
|
440
|
+
const spell = (value) => (value === "managed" ? "router" : value);
|
|
441
|
+
if ((first.credentialSource ?? source) !== source && spell(first.credentialSource) !== spell(source)) {
|
|
439
442
|
context.addIssue({ code: "custom", path: ["seats", 0, "credentialSource"], message: "first seat credentialSource must match profile model.metadata.credentialSource" });
|
|
440
443
|
}
|
|
441
444
|
if (first.tools !== undefined &&
|