@tangle-network/sandbox 0.69.10 → 0.69.12
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/index.d.ts +4 -4
- package/dist/agent/index.js +5 -5
- package/dist/agent/preview.d.ts +1 -1
- package/dist/agent/preview.js +3 -3
- package/dist/{agent-run-outcome-B5CzWxw4.d.ts → agent-run-outcome-BuebRCWr.d.ts} +2 -2
- package/dist/{api-request-D1UVNo16.js → api-request-EseiF9B1.js} +1 -1
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/browser-interactive-control-controller-Bt1vcu9c.js +4045 -0
- package/dist/{browser-interactive-control-controller-SI9hV6r5.d.ts → browser-interactive-control-controller-CVnME80O.d.ts} +5 -7
- package/dist/{chunked-upload-l6b9AWFA.js → chunked-upload-Df_5Q2x8.js} +1 -1
- package/dist/{chunked-upload-file-CLwAeLrM.js → chunked-upload-file-Dtm1GBkE.js} +2 -2
- package/dist/cli-auth-bundle-f2pt7sVA.js +2593 -0
- package/dist/{client-qjA1hNOp.js → client-BR_aABY2.js} +11 -11
- package/dist/{client-BGm6cw7B.d.ts → client-BWnbrifs.d.ts} +30 -32
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/{collaboration-BwLNv6sy.js → collaboration-BTGTf3We.js} +1 -1
- package/dist/{core-CG7T2arO.js → core-DeXa_YQ2.js} +5 -4
- package/dist/core.d.ts +6 -6
- package/dist/core.js +5 -5
- package/dist/{direct-http2-Pyj3Rvr1.js → direct-http2-B0ra_xhU.js} +1 -1
- package/dist/{errors-Bs5G7JdV.js → errors-ZmDrrk4f.js} +1 -1
- package/dist/harness-BD_OISom.js +201 -0
- package/dist/harness-DWL2MM4q.js +418 -0
- package/dist/{index-nXob5TkM.d.ts → index-DdcCRDq8.d.ts} +14 -16
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- package/dist/intelligence/index.js +2 -2
- package/dist/interactive-control.d.ts +1 -1
- package/dist/interactive-control.js +1 -1
- package/dist/{interactive-controller-DSDEfapN.js → interactive-controller-B4bQwRJL.js} +21 -8
- package/dist/{interactive-controller-FgmcS8_Y.d.ts → interactive-controller-DlFKGQqu.d.ts} +3 -4
- package/dist/lib/prepared-evidence.js +1 -1
- package/dist/lib/prepared-process.js +1 -1
- package/dist/{lines-D_HDAcVt.js → lines-BqZOl_io.js} +1 -1
- package/dist/{lines-BoVYnUCM.d.ts → lines-ptj8SyD4.d.ts} +1 -1
- package/dist/lines.d.ts +1 -1
- package/dist/lines.js +1 -1
- package/dist/{local-cli-auth-YGra1QUA.js → local-cli-auth-Cpi3hT3j.js} +1 -1
- package/dist/{mcp-local-Gz1Uygqk.js → mcp-local-BcRLN_Ic.js} +1 -1
- package/dist/{prepared-evidence-DUmJSegi.js → prepared-evidence-CuUh_mz6.js} +1 -1
- package/dist/{preview-Vu5knAuf.d.ts → preview-ByTCKjiK.d.ts} +3 -3
- package/dist/profile-schema-CT3hB1mG.js +1135 -0
- package/dist/{public-templates-B6_uwnRZ.d.ts → public-templates-O2mxBX7J.d.ts} +2 -2
- package/dist/public-templates.d.ts +1 -1
- package/dist/public-templates.js +1 -1
- package/dist/{raw-evidence-archive-D60Yg1-5.js → raw-evidence-archive-CqarcYcp.js} +1 -1
- package/dist/runtime.d.ts +5 -5
- package/dist/runtime.js +5 -5
- package/dist/{sandbox-BulsMs3K.js → sandbox-B1ROfJxe.js} +384 -46
- package/dist/{secp256k1-DxHlUI6v.js → secp256k1-CZWrpqxW.js} +1 -1
- package/dist/select-seat-command.d.ts +1 -1
- package/dist/select-seat-command.js +1 -1
- package/dist/session-gateway/index.js +3 -3
- package/dist/sha2-BUPMvGTk.js +694 -0
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-DdzOPPJ9.js → tangle-q-3ualoW.js} +4 -4
- package/dist/terminal-stream-types-DwXQzUbH.d.ts +3328 -0
- package/dist/{types-CkLWX7i5.d.ts → types-B28t5Sq1.d.ts} +10 -12
- package/package.json +6 -6
- package/dist/browser-interactive-control-controller-CLHNi8rG.js +0 -292
- package/dist/cli-auth-bundle-DmaEJ_qh.js +0 -1590
- package/dist/terminal-stream-types-DuzvL1ge.d.ts +0 -676
- /package/dist/{abort-signal-BKVZNJul.js → abort-signal-jU-SEjLT.js} +0 -0
- /package/dist/{cli-auth-bundle-CeNOYFje.d.ts → cli-auth-bundle-MskLEgtA.d.ts} +0 -0
- /package/dist/{index-C0RkLba5.d.ts → index-Dqcr9p97.d.ts} +0 -0
- /package/dist/{index-DaIF4c9p.d.ts → index-Dslyq85a.d.ts} +0 -0
- /package/dist/{keep-alive-fetch-Bi-zvHpN.js → keep-alive-fetch-C2DX2_rG.js} +0 -0
- /package/dist/{prepared-process-Dlk_9JVJ.js → prepared-process-LjBfQnZ5.js} +0 -0
- /package/dist/{preview-operations-eTUlPen5.js → preview-operations-BvgwYaoL.js} +0 -0
- /package/dist/{response-rewrap-BKkJ5hnn.js → response-rewrap-MBztoTLx.js} +0 -0
- /package/dist/{retry-after-header-U_L5Ml9Q.js → retry-after-header-BZbs5rig.js} +0 -0
- /package/dist/{sidecar-proxy-error-B2Hxt41g.js → sidecar-proxy-error-Dty4zmN7.js} +0 -0
- /package/dist/{sse-parser-CUfurwcm.js → sse-parser-DmO5gP6u.js} +0 -0
- /package/dist/{utils-DB8DnUCU.js → utils-vaFoyyiO.js} +0 -0
|
@@ -0,0 +1,4045 @@
|
|
|
1
|
+
import { a as canonicalCandidateDigest, f as isWellFormedUnicode, h as sha256DigestSchema, l as isCanonicalJsonValue, m as omitTopLevelDigest, n as REASONING_EFFORTS, o as canonicalCandidateJson, p as looksLikeCredential, t as harnessTypeSchema } from "./harness-BD_OISom.js";
|
|
2
|
+
import { C as boundedJsonRecordSchema$1, E as isBoundedEventContentJson$1, S as boundedIdentifierSchema$1, T as boundedStringSchema$1, _ as CONTRACT_MAX_ARRAY_LENGTH$1, b as boundedEventContentRecordSchema$1, g as sha256DigestSchema$1, h as omitTopLevelDigest$1, m as looksLikeCredential$1, n as REASONING_EFFORTS$1, o as canonicalCandidateDigest$1, p as isWellFormedUnicode$1, s as canonicalCandidateJson$1, t as harnessTypeSchema$1, u as isCanonicalJsonValue$1, v as CONTRACT_MAX_STRING_LENGTH$1, w as boundedJsonSchema$1, x as boundedEventContentStringSchema$1, y as boundedEventContentJsonSchema$1 } from "./harness-DWL2MM4q.js";
|
|
3
|
+
import { t as awaitWithAbort } from "./abort-signal-jU-SEjLT.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/contract-limits.js
|
|
6
|
+
/** Limits applied before a value is hashed, copied, or sent to a provider. */
|
|
7
|
+
const CONTRACT_MAX_STRING_LENGTH = 16384;
|
|
8
|
+
/** Maximum length of one canonical confidential-attestation quote. */
|
|
9
|
+
const CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH = 32768;
|
|
10
|
+
const CONTRACT_MAX_ARRAY_LENGTH = 1024;
|
|
11
|
+
const CONTRACT_MAX_JSON_BYTES = 1048576;
|
|
12
|
+
const boundedStringSchema = z.string().max(CONTRACT_MAX_STRING_LENGTH);
|
|
13
|
+
z.string().max(CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH);
|
|
14
|
+
const boundedIdentifierSchema = boundedStringSchema.min(1).max(512).refine((value) => value.trim() === value, "identifier cannot have outer whitespace");
|
|
15
|
+
/**
|
|
16
|
+
* Validate JSON without asking Zod to recursively copy an attacker-sized
|
|
17
|
+
* value. This is intentionally iterative so depth and collection limits are
|
|
18
|
+
* checked before canonical serialization.
|
|
19
|
+
*/
|
|
20
|
+
function isBoundedJsonValue(value) {
|
|
21
|
+
const pending = [{
|
|
22
|
+
value,
|
|
23
|
+
depth: 0
|
|
24
|
+
}];
|
|
25
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
26
|
+
let nodes = 0;
|
|
27
|
+
while (pending.length > 0) {
|
|
28
|
+
const item = pending.pop();
|
|
29
|
+
if (!item) continue;
|
|
30
|
+
nodes += 1;
|
|
31
|
+
if (nodes > 8192) return false;
|
|
32
|
+
const current = item.value;
|
|
33
|
+
if (item.leave) {
|
|
34
|
+
ancestors.delete(current);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (current === void 0) return false;
|
|
38
|
+
if (current === null || typeof current === "boolean") continue;
|
|
39
|
+
if (typeof current === "string") {
|
|
40
|
+
if (current.length > 16384) return false;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (typeof current === "number") {
|
|
44
|
+
if (!Number.isFinite(current)) return false;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (typeof current !== "object" || item.depth >= 16) return false;
|
|
48
|
+
if (ancestors.has(current)) return false;
|
|
49
|
+
ancestors.add(current);
|
|
50
|
+
pending.push({
|
|
51
|
+
value: current,
|
|
52
|
+
depth: item.depth,
|
|
53
|
+
leave: true
|
|
54
|
+
});
|
|
55
|
+
if (Array.isArray(current)) {
|
|
56
|
+
if (current.length > 1024) return false;
|
|
57
|
+
for (const entry of current) pending.push({
|
|
58
|
+
value: entry,
|
|
59
|
+
depth: item.depth + 1
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const prototype = Object.getPrototypeOf(current);
|
|
64
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
65
|
+
const keys = Object.keys(current);
|
|
66
|
+
if (keys.length > 256) return false;
|
|
67
|
+
for (const key of keys) {
|
|
68
|
+
if (key.length > 512) return false;
|
|
69
|
+
pending.push({
|
|
70
|
+
value: current[key],
|
|
71
|
+
depth: item.depth + 1
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
/** Exact serialized JSON UTF-8 byte count for one string scalar. */
|
|
78
|
+
function serializedJsonStringBytes(value) {
|
|
79
|
+
let bytes = 2;
|
|
80
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
81
|
+
const code = value.charCodeAt(index);
|
|
82
|
+
if (code === 34 || code === 92 || code === 8 || code === 12 || code === 10 || code === 13 || code === 9) bytes += 2;
|
|
83
|
+
else if (code < 32) bytes += 6;
|
|
84
|
+
else if (code >= 55296 && code <= 56319 && index + 1 < value.length) {
|
|
85
|
+
const next = value.charCodeAt(index + 1);
|
|
86
|
+
if (next >= 56320 && next <= 57343) {
|
|
87
|
+
bytes += 4;
|
|
88
|
+
index += 1;
|
|
89
|
+
} else bytes += 6;
|
|
90
|
+
} else if (code >= 55296 && code <= 57343) bytes += 6;
|
|
91
|
+
else if (code < 128) bytes += 1;
|
|
92
|
+
else if (code < 2048) bytes += 2;
|
|
93
|
+
else bytes += 3;
|
|
94
|
+
if (bytes > 1048576) return bytes;
|
|
95
|
+
}
|
|
96
|
+
return bytes;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Validate provider event and terminal content. Unlike ordinary metadata,
|
|
100
|
+
* content may contain a single large transcript or tool result. It remains
|
|
101
|
+
* finite, plain JSON with the normal structural limits, and its complete JSON
|
|
102
|
+
* representation is capped exactly by UTF-8 bytes.
|
|
103
|
+
*/
|
|
104
|
+
function isBoundedEventContentJson(value, { omitUndefinedObjectFields = false } = {}) {
|
|
105
|
+
const pending = [{
|
|
106
|
+
value,
|
|
107
|
+
depth: 0
|
|
108
|
+
}];
|
|
109
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
110
|
+
let nodes = 0;
|
|
111
|
+
let bytes = 0;
|
|
112
|
+
const addBytes = (additional) => {
|
|
113
|
+
bytes += additional;
|
|
114
|
+
return bytes <= CONTRACT_MAX_JSON_BYTES;
|
|
115
|
+
};
|
|
116
|
+
while (pending.length > 0) {
|
|
117
|
+
const item = pending.pop();
|
|
118
|
+
if (!item) continue;
|
|
119
|
+
const current = item.value;
|
|
120
|
+
if (current === void 0 && item.omitUndefined === true) continue;
|
|
121
|
+
nodes += 1;
|
|
122
|
+
if (nodes > 8192) return false;
|
|
123
|
+
if (item.leave) {
|
|
124
|
+
ancestors.delete(current);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (current === null) {
|
|
128
|
+
if (!addBytes(4)) return false;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (typeof current === "boolean") {
|
|
132
|
+
if (!addBytes(current ? 4 : 5)) return false;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (typeof current === "string") {
|
|
136
|
+
if (!addBytes(serializedJsonStringBytes(current))) return false;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (typeof current === "number") {
|
|
140
|
+
if (!Number.isFinite(current)) return false;
|
|
141
|
+
if (!addBytes(JSON.stringify(current).length)) return false;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (typeof current !== "object" || item.depth >= 16) return false;
|
|
145
|
+
if (ancestors.has(current)) return false;
|
|
146
|
+
ancestors.add(current);
|
|
147
|
+
pending.push({
|
|
148
|
+
value: current,
|
|
149
|
+
depth: item.depth,
|
|
150
|
+
leave: true
|
|
151
|
+
});
|
|
152
|
+
if (Array.isArray(current)) {
|
|
153
|
+
if (current.length > 1024) return false;
|
|
154
|
+
if (!addBytes(2 + Math.max(current.length - 1, 0))) return false;
|
|
155
|
+
const prototype = Object.getPrototypeOf(current);
|
|
156
|
+
if (prototype !== Array.prototype && prototype !== null) return false;
|
|
157
|
+
const entryKeys = Reflect.ownKeys(current).filter((key) => key !== "length");
|
|
158
|
+
if (entryKeys.length !== current.length) return false;
|
|
159
|
+
if (entryKeys.some((key) => {
|
|
160
|
+
if (typeof key !== "string" || !/^(?:0|[1-9][0-9]*)$/u.test(key)) return true;
|
|
161
|
+
const index = Number(key);
|
|
162
|
+
return !Number.isSafeInteger(index) || index < 0 || index >= current.length || index >= 4294967295;
|
|
163
|
+
})) return false;
|
|
164
|
+
for (const key of entryKeys) {
|
|
165
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
166
|
+
if (descriptor === void 0 || !descriptor.enumerable || !("value" in descriptor)) return false;
|
|
167
|
+
pending.push({
|
|
168
|
+
value: descriptor.value,
|
|
169
|
+
depth: item.depth + 1
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const prototype = Object.getPrototypeOf(current);
|
|
175
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
176
|
+
const entries = [];
|
|
177
|
+
for (const key of Reflect.ownKeys(current)) {
|
|
178
|
+
if (typeof key !== "string" || key.length > 512) return false;
|
|
179
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
180
|
+
if (descriptor === void 0 || !descriptor.enumerable || !("value" in descriptor)) return false;
|
|
181
|
+
if (descriptor.value === void 0 && omitUndefinedObjectFields) continue;
|
|
182
|
+
entries.push([key, descriptor]);
|
|
183
|
+
if (entries.length > 256) return false;
|
|
184
|
+
}
|
|
185
|
+
if (!addBytes(2 + Math.max(entries.length - 1, 0))) return false;
|
|
186
|
+
for (const [key, descriptor] of entries) {
|
|
187
|
+
if (!addBytes(serializedJsonStringBytes(key) + 1)) return false;
|
|
188
|
+
pending.push({
|
|
189
|
+
value: descriptor.value,
|
|
190
|
+
depth: item.depth + 1,
|
|
191
|
+
omitUndefined: omitUndefinedObjectFields
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
const boundedJsonSchema = z.custom(isBoundedJsonValue, { message: "value exceeds the contract bounds or is not finite JSON" });
|
|
198
|
+
const boundedJsonRecordSchema = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value) && isBoundedJsonValue(value), { message: "metadata exceeds the contract bounds or is not a JSON object" });
|
|
199
|
+
/** One provider event payload or terminal response, bounded as serialized UTF-8 JSON. */
|
|
200
|
+
const boundedEventContentJsonSchema = z.custom(isBoundedEventContentJson, { message: "event content exceeds its serialized byte bound or is not finite JSON" });
|
|
201
|
+
const boundedEventContentRecordSchema = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value) && isBoundedEventContentJson(value), { message: "event content exceeds its serialized byte bound or is not a JSON object" });
|
|
202
|
+
const boundedEventContentStringSchema = z.custom((value) => typeof value === "string" && isBoundedEventContentJson(value), { message: "event content exceeds its serialized byte bound or is not a string" });
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/native-session-event.js
|
|
205
|
+
/**
|
|
206
|
+
* Private adapter observation of a provider conversation or resume identity.
|
|
207
|
+
* The adapter must obtain this ID from its bound provider process or API.
|
|
208
|
+
* Caller keys, execution IDs, storage paths, and public session updates are not evidence.
|
|
209
|
+
* The execution owner binds this observation to its own execution and session.
|
|
210
|
+
* Public SSE and user-visible event streams must exclude this control event.
|
|
211
|
+
* An observation establishes identity only, not native artifact completeness.
|
|
212
|
+
*/
|
|
213
|
+
const NativeSessionObservedEventSchema$1 = z.object({
|
|
214
|
+
type: z.literal("native.session.observed"),
|
|
215
|
+
provider: z.string().regex(/^[a-z][a-z0-9-]{0,127}$/),
|
|
216
|
+
nativeSessionId: z.string().min(1).max(512).regex(/^\S+$/u)
|
|
217
|
+
}).strict();
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/environment-observation.js
|
|
220
|
+
const ObservationProvenanceSchema$1 = z.strictObject({
|
|
221
|
+
origin: z.enum([
|
|
222
|
+
"measured",
|
|
223
|
+
"reported",
|
|
224
|
+
"estimated"
|
|
225
|
+
]),
|
|
226
|
+
observedAt: z.iso.datetime().max(64),
|
|
227
|
+
source: boundedIdentifierSchema.optional()
|
|
228
|
+
});
|
|
229
|
+
/** Build a freshness-tagged observation schema around one value schema. */
|
|
230
|
+
function observationOf$1(value) {
|
|
231
|
+
return z.discriminatedUnion("state", [
|
|
232
|
+
z.strictObject({
|
|
233
|
+
state: z.literal("known"),
|
|
234
|
+
value,
|
|
235
|
+
provenance: ObservationProvenanceSchema$1
|
|
236
|
+
}),
|
|
237
|
+
z.strictObject({
|
|
238
|
+
state: z.literal("stale"),
|
|
239
|
+
value,
|
|
240
|
+
provenance: ObservationProvenanceSchema$1,
|
|
241
|
+
reason: boundedStringSchema.min(1)
|
|
242
|
+
}),
|
|
243
|
+
z.strictObject({
|
|
244
|
+
state: z.literal("unavailable"),
|
|
245
|
+
reason: boundedStringSchema.min(1)
|
|
246
|
+
}),
|
|
247
|
+
z.strictObject({
|
|
248
|
+
state: z.literal("redacted"),
|
|
249
|
+
reason: boundedStringSchema.min(1)
|
|
250
|
+
}),
|
|
251
|
+
z.strictObject({ state: z.literal("unknown") })
|
|
252
|
+
]);
|
|
253
|
+
}
|
|
254
|
+
const nonNegativeNumberSchema$1 = z.number().finite().nonnegative();
|
|
255
|
+
const ProviderIdentitySchema$1 = z.strictObject({
|
|
256
|
+
provider: boundedIdentifierSchema,
|
|
257
|
+
environmentId: boundedIdentifierSchema,
|
|
258
|
+
sessionId: boundedIdentifierSchema.optional(),
|
|
259
|
+
backend: boundedIdentifierSchema.optional()
|
|
260
|
+
});
|
|
261
|
+
const AgentEnvironmentStatusSchema$1 = z.enum([
|
|
262
|
+
"pending",
|
|
263
|
+
"provisioning",
|
|
264
|
+
"running",
|
|
265
|
+
"stopped",
|
|
266
|
+
"failed",
|
|
267
|
+
"expired",
|
|
268
|
+
"unknown"
|
|
269
|
+
]);
|
|
270
|
+
/** Lifecycle, cleanup, continuity, and persistence of one environment. */
|
|
271
|
+
const EnvironmentLifecycleSchema$1 = z.strictObject({
|
|
272
|
+
status: AgentEnvironmentStatusSchema$1,
|
|
273
|
+
cleanup: z.strictObject({
|
|
274
|
+
policy: z.enum([
|
|
275
|
+
"manual",
|
|
276
|
+
"idle",
|
|
277
|
+
"scheduled",
|
|
278
|
+
"on-exit"
|
|
279
|
+
]).optional(),
|
|
280
|
+
scheduledAt: z.iso.datetime().max(64).optional(),
|
|
281
|
+
confirmed: z.boolean().optional()
|
|
282
|
+
}).optional(),
|
|
283
|
+
continuity: z.strictObject({
|
|
284
|
+
resumable: z.boolean(),
|
|
285
|
+
mode: z.enum([
|
|
286
|
+
"native",
|
|
287
|
+
"replayed",
|
|
288
|
+
"none"
|
|
289
|
+
]).optional()
|
|
290
|
+
}).optional(),
|
|
291
|
+
persistence: z.strictObject({
|
|
292
|
+
durable: z.boolean(),
|
|
293
|
+
scope: z.enum([
|
|
294
|
+
"ephemeral",
|
|
295
|
+
"session",
|
|
296
|
+
"durable"
|
|
297
|
+
]).optional()
|
|
298
|
+
}).optional()
|
|
299
|
+
});
|
|
300
|
+
/**
|
|
301
|
+
* Credential-free network location. There is no field for a user, password,
|
|
302
|
+
* token, or other secret, and the host and scheme reject embedded credentials.
|
|
303
|
+
*/
|
|
304
|
+
const SafeEndpointSchema$1 = z.strictObject({
|
|
305
|
+
scheme: boundedIdentifierSchema.optional(),
|
|
306
|
+
host: boundedIdentifierSchema,
|
|
307
|
+
port: z.number().int().min(1).max(65535).optional(),
|
|
308
|
+
region: boundedIdentifierSchema.optional()
|
|
309
|
+
}).superRefine((endpoint, refinement) => {
|
|
310
|
+
if (/[@/\s]|:\/\//.test(endpoint.host)) refinement.addIssue({
|
|
311
|
+
code: "custom",
|
|
312
|
+
path: ["host"],
|
|
313
|
+
message: "endpoint host must not carry credentials, a scheme, or a path"
|
|
314
|
+
});
|
|
315
|
+
if (endpoint.scheme !== void 0 && /[@:/\s]/.test(endpoint.scheme)) refinement.addIssue({
|
|
316
|
+
code: "custom",
|
|
317
|
+
path: ["scheme"],
|
|
318
|
+
message: "endpoint scheme must be a bare protocol name"
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
/** Requested or effective compute shape, including an optional accelerator. */
|
|
322
|
+
const ResourceProfileSchema$1 = z.strictObject({
|
|
323
|
+
cpu: z.number().finite().positive().optional(),
|
|
324
|
+
memoryMb: z.number().int().positive().optional(),
|
|
325
|
+
diskMb: z.number().int().positive().optional(),
|
|
326
|
+
accelerator: z.strictObject({
|
|
327
|
+
kind: boundedIdentifierSchema,
|
|
328
|
+
count: z.number().int().positive(),
|
|
329
|
+
memoryMb: z.number().int().positive().optional()
|
|
330
|
+
}).optional()
|
|
331
|
+
});
|
|
332
|
+
/** A point-in-time or peak resource sample. */
|
|
333
|
+
const ResourceUseSampleSchema$1 = z.strictObject({
|
|
334
|
+
cpu: nonNegativeNumberSchema$1.optional(),
|
|
335
|
+
memoryMb: nonNegativeNumberSchema$1.optional(),
|
|
336
|
+
diskMb: nonNegativeNumberSchema$1.optional(),
|
|
337
|
+
acceleratorMemoryMb: nonNegativeNumberSchema$1.optional()
|
|
338
|
+
});
|
|
339
|
+
/** Where an environment was requested or verified to run. */
|
|
340
|
+
const PlacementDescriptorSchema$1 = z.strictObject({
|
|
341
|
+
kind: z.enum([
|
|
342
|
+
"local",
|
|
343
|
+
"sandbox",
|
|
344
|
+
"fleet",
|
|
345
|
+
"provider"
|
|
346
|
+
]),
|
|
347
|
+
sandboxId: boundedIdentifierSchema.optional(),
|
|
348
|
+
fleetId: boundedIdentifierSchema.optional(),
|
|
349
|
+
machineId: boundedIdentifierSchema.optional(),
|
|
350
|
+
region: boundedIdentifierSchema.optional()
|
|
351
|
+
});
|
|
352
|
+
/**
|
|
353
|
+
* Token usage and cost for one execution. Bound to the shared {@link TokenUsage}
|
|
354
|
+
* type so a change to the canonical shape is caught here.
|
|
355
|
+
*/
|
|
356
|
+
const ModelUsageSchema$1 = z.strictObject({
|
|
357
|
+
inputTokens: z.number().int().nonnegative(),
|
|
358
|
+
outputTokens: z.number().int().nonnegative(),
|
|
359
|
+
totalTokens: z.number().int().nonnegative().optional(),
|
|
360
|
+
cacheReadInputTokens: z.number().int().nonnegative().optional(),
|
|
361
|
+
cacheCreationInputTokens: z.number().int().nonnegative().optional(),
|
|
362
|
+
reasoningTokens: z.number().int().nonnegative().optional(),
|
|
363
|
+
cost: z.number().finite().nonnegative().optional()
|
|
364
|
+
});
|
|
365
|
+
/** Provider compute cost charged for one environment. */
|
|
366
|
+
const ComputeBillingSchema$1 = z.strictObject({
|
|
367
|
+
amount: nonNegativeNumberSchema$1,
|
|
368
|
+
currency: boundedIdentifierSchema
|
|
369
|
+
});
|
|
370
|
+
/** Account plan, credits, quota, and billing period. */
|
|
371
|
+
const AccountUsageSchema$1 = z.strictObject({
|
|
372
|
+
plan: observationOf$1(boundedIdentifierSchema).optional(),
|
|
373
|
+
credits: observationOf$1(z.strictObject({
|
|
374
|
+
remaining: nonNegativeNumberSchema$1,
|
|
375
|
+
unit: boundedIdentifierSchema
|
|
376
|
+
})).optional(),
|
|
377
|
+
quota: observationOf$1(z.strictObject({
|
|
378
|
+
limit: nonNegativeNumberSchema$1,
|
|
379
|
+
used: nonNegativeNumberSchema$1,
|
|
380
|
+
remaining: nonNegativeNumberSchema$1,
|
|
381
|
+
unit: boundedIdentifierSchema
|
|
382
|
+
})).optional(),
|
|
383
|
+
period: observationOf$1(z.strictObject({
|
|
384
|
+
start: z.iso.datetime().max(64),
|
|
385
|
+
end: z.iso.datetime().max(64)
|
|
386
|
+
})).optional()
|
|
387
|
+
});
|
|
388
|
+
z.strictObject({
|
|
389
|
+
subject: ProviderIdentitySchema$1,
|
|
390
|
+
capturedAt: z.iso.datetime().max(64),
|
|
391
|
+
identity: observationOf$1(ProviderIdentitySchema$1).optional(),
|
|
392
|
+
lifecycle: observationOf$1(EnvironmentLifecycleSchema$1).optional(),
|
|
393
|
+
endpoint: observationOf$1(SafeEndpointSchema$1).optional(),
|
|
394
|
+
placement: z.strictObject({
|
|
395
|
+
requested: PlacementDescriptorSchema$1.optional(),
|
|
396
|
+
verified: observationOf$1(PlacementDescriptorSchema$1).optional()
|
|
397
|
+
}).optional(),
|
|
398
|
+
resources: z.strictObject({
|
|
399
|
+
requested: ResourceProfileSchema$1.optional(),
|
|
400
|
+
effective: observationOf$1(ResourceProfileSchema$1).optional()
|
|
401
|
+
}).optional(),
|
|
402
|
+
resourceUse: z.strictObject({
|
|
403
|
+
current: observationOf$1(ResourceUseSampleSchema$1).optional(),
|
|
404
|
+
peak: observationOf$1(ResourceUseSampleSchema$1).optional()
|
|
405
|
+
}).optional(),
|
|
406
|
+
modelUsage: observationOf$1(ModelUsageSchema$1).optional(),
|
|
407
|
+
computeBilling: observationOf$1(ComputeBillingSchema$1).optional(),
|
|
408
|
+
accountUsage: AccountUsageSchema$1.optional()
|
|
409
|
+
});
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-fields.js
|
|
412
|
+
/**
|
|
413
|
+
* Field names whose own-key form collides with object internals. A record
|
|
414
|
+
* parser drops a raw `__proto__` key through the legacy prototype setter before
|
|
415
|
+
* a key schema runs, so every schema and validator over interaction data
|
|
416
|
+
* rejects these names against one owner rather than a private copy.
|
|
417
|
+
*/
|
|
418
|
+
const RESERVED_INTERACTION_FIELD_NAMES$1 = new Set([
|
|
419
|
+
"__proto__",
|
|
420
|
+
"constructor",
|
|
421
|
+
"prototype"
|
|
422
|
+
]);
|
|
423
|
+
const InteractionFieldNameSchema$1 = boundedIdentifierSchema.refine((value) => !RESERVED_INTERACTION_FIELD_NAMES$1.has(value), "interaction field name is reserved");
|
|
424
|
+
const FieldBase$1 = {
|
|
425
|
+
/** Stable key the answer is returned under in `InteractionResponse.data`. */
|
|
426
|
+
name: InteractionFieldNameSchema$1,
|
|
427
|
+
/** Human-readable label for the form control. */
|
|
428
|
+
label: boundedStringSchema.min(1),
|
|
429
|
+
/** Whether the answer must supply this field to be `accepted`. */
|
|
430
|
+
required: z.boolean().optional()
|
|
431
|
+
};
|
|
432
|
+
const InteractionFieldSchema$1 = z.discriminatedUnion("type", [
|
|
433
|
+
z.strictObject({
|
|
434
|
+
...FieldBase$1,
|
|
435
|
+
type: z.literal("text"),
|
|
436
|
+
multiline: z.boolean().optional(),
|
|
437
|
+
placeholder: boundedStringSchema.optional(),
|
|
438
|
+
/** Maximum answer length chosen by the request author. */
|
|
439
|
+
maxLength: z.number().int().positive().max(CONTRACT_MAX_STRING_LENGTH).optional(),
|
|
440
|
+
default: boundedStringSchema.optional()
|
|
441
|
+
}),
|
|
442
|
+
z.strictObject({
|
|
443
|
+
...FieldBase$1,
|
|
444
|
+
type: z.literal("number"),
|
|
445
|
+
min: z.number().finite().optional(),
|
|
446
|
+
max: z.number().finite().optional(),
|
|
447
|
+
default: z.number().finite().optional()
|
|
448
|
+
}),
|
|
449
|
+
z.strictObject({
|
|
450
|
+
...FieldBase$1,
|
|
451
|
+
type: z.literal("boolean"),
|
|
452
|
+
default: z.boolean().optional()
|
|
453
|
+
}),
|
|
454
|
+
z.strictObject({
|
|
455
|
+
...FieldBase$1,
|
|
456
|
+
type: z.literal("select"),
|
|
457
|
+
options: z.array(z.strictObject({
|
|
458
|
+
value: boundedIdentifierSchema,
|
|
459
|
+
label: boundedStringSchema.min(1),
|
|
460
|
+
description: boundedStringSchema.optional()
|
|
461
|
+
})).min(1).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
462
|
+
/** When true the user may pick more than one option. */
|
|
463
|
+
multi: z.boolean().optional(),
|
|
464
|
+
/**
|
|
465
|
+
* When true the answer may contain write-in values outside `options`
|
|
466
|
+
* (e.g. a rendered "Other…" choice carrying the user's own text).
|
|
467
|
+
* Write-ins must still be non-empty strings.
|
|
468
|
+
*/
|
|
469
|
+
allowCustom: z.boolean().optional(),
|
|
470
|
+
default: z.array(boundedIdentifierSchema).max(CONTRACT_MAX_ARRAY_LENGTH).optional()
|
|
471
|
+
}),
|
|
472
|
+
z.strictObject({
|
|
473
|
+
...FieldBase$1,
|
|
474
|
+
type: z.literal("secret"),
|
|
475
|
+
placeholder: boundedStringSchema.optional(),
|
|
476
|
+
/** Maximum answer length chosen by the request author. */
|
|
477
|
+
maxLength: z.number().int().positive().max(CONTRACT_MAX_STRING_LENGTH).optional()
|
|
478
|
+
})
|
|
479
|
+
]).superRefine((field, context) => {
|
|
480
|
+
if (field.type === "text" && field.default !== void 0 && field.maxLength !== void 0 && field.default.length > field.maxLength) {
|
|
481
|
+
context.addIssue({
|
|
482
|
+
code: "custom",
|
|
483
|
+
path: ["default"],
|
|
484
|
+
message: "text field default exceeds maxLength"
|
|
485
|
+
});
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (field.type === "number") {
|
|
489
|
+
if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) context.addIssue({
|
|
490
|
+
code: "custom",
|
|
491
|
+
path: ["max"],
|
|
492
|
+
message: "number field max must be greater than or equal to min"
|
|
493
|
+
});
|
|
494
|
+
if (field.default !== void 0 && field.min !== void 0 && field.default < field.min) context.addIssue({
|
|
495
|
+
code: "custom",
|
|
496
|
+
path: ["default"],
|
|
497
|
+
message: "number field default must be greater than or equal to min"
|
|
498
|
+
});
|
|
499
|
+
if (field.default !== void 0 && field.max !== void 0 && field.default > field.max) context.addIssue({
|
|
500
|
+
code: "custom",
|
|
501
|
+
path: ["default"],
|
|
502
|
+
message: "number field default must be less than or equal to max"
|
|
503
|
+
});
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (field.type !== "select") return;
|
|
507
|
+
const optionValues = field.options.map((option) => option.value);
|
|
508
|
+
if (new Set(optionValues).size !== optionValues.length) context.addIssue({
|
|
509
|
+
code: "custom",
|
|
510
|
+
path: ["options"],
|
|
511
|
+
message: "select option values must be unique"
|
|
512
|
+
});
|
|
513
|
+
if (field.default === void 0) return;
|
|
514
|
+
if (new Set(field.default).size !== field.default.length) context.addIssue({
|
|
515
|
+
code: "custom",
|
|
516
|
+
path: ["default"],
|
|
517
|
+
message: "select default values must be unique"
|
|
518
|
+
});
|
|
519
|
+
if (!field.multi && field.default.length > 1) context.addIssue({
|
|
520
|
+
code: "custom",
|
|
521
|
+
path: ["default"],
|
|
522
|
+
message: "single-select default may contain at most one value"
|
|
523
|
+
});
|
|
524
|
+
if (field.required && field.default.length === 0) context.addIssue({
|
|
525
|
+
code: "custom",
|
|
526
|
+
path: ["default"],
|
|
527
|
+
message: "required select default must contain a value"
|
|
528
|
+
});
|
|
529
|
+
const allowed = new Set(optionValues);
|
|
530
|
+
for (const value of field.default) {
|
|
531
|
+
if (allowed.has(value)) continue;
|
|
532
|
+
if (field.allowCustom === true && value.trim().length > 0) continue;
|
|
533
|
+
context.addIssue({
|
|
534
|
+
code: "custom",
|
|
535
|
+
path: ["default"],
|
|
536
|
+
message: `select default contains unknown option "${value}"`
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
const InteractionAnswerSpecSchema$1 = z.strictObject({ fields: z.array(InteractionFieldSchema$1).max(CONTRACT_MAX_ARRAY_LENGTH) }).superRefine((spec, context) => {
|
|
541
|
+
const names = spec.fields.map((field) => field.name);
|
|
542
|
+
if (new Set(names).size !== names.length) context.addIssue({
|
|
543
|
+
code: "custom",
|
|
544
|
+
path: ["fields"],
|
|
545
|
+
message: "interaction field names must be unique"
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
const InteractionFieldTypeSchema$1 = z.enum([
|
|
549
|
+
"text",
|
|
550
|
+
"number",
|
|
551
|
+
"boolean",
|
|
552
|
+
"select",
|
|
553
|
+
"secret"
|
|
554
|
+
]);
|
|
555
|
+
/** Scope at which an accepted answer may be reused by an explicit policy. */
|
|
556
|
+
const InteractionResponseScopeSchema$1 = z.enum([
|
|
557
|
+
"interaction",
|
|
558
|
+
"session",
|
|
559
|
+
"persistent"
|
|
560
|
+
]);
|
|
561
|
+
z.strictObject({
|
|
562
|
+
kinds: z.array(boundedIdentifierSchema).min(1).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
563
|
+
answerFieldTypes: z.array(InteractionFieldTypeSchema$1).min(1).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
564
|
+
responseScopes: z.array(InteractionResponseScopeSchema$1).min(1).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
565
|
+
secretAnswers: z.boolean(),
|
|
566
|
+
concurrentRequests: z.boolean(),
|
|
567
|
+
replay: z.boolean(),
|
|
568
|
+
responseIdempotency: z.boolean()
|
|
569
|
+
}).superRefine((capabilities, context) => {
|
|
570
|
+
if (capabilities.answerFieldTypes.includes("secret") !== capabilities.secretAnswers) context.addIssue({
|
|
571
|
+
code: "custom",
|
|
572
|
+
path: ["secretAnswers"],
|
|
573
|
+
message: "secretAnswers must agree with the secret answer field capability"
|
|
574
|
+
});
|
|
575
|
+
if (new Set(capabilities.kinds).size !== capabilities.kinds.length) context.addIssue({
|
|
576
|
+
code: "custom",
|
|
577
|
+
path: ["kinds"],
|
|
578
|
+
message: "interaction kinds must be unique"
|
|
579
|
+
});
|
|
580
|
+
if (new Set(capabilities.answerFieldTypes).size !== capabilities.answerFieldTypes.length) context.addIssue({
|
|
581
|
+
code: "custom",
|
|
582
|
+
path: ["answerFieldTypes"],
|
|
583
|
+
message: "interaction answer field types must be unique"
|
|
584
|
+
});
|
|
585
|
+
if (new Set(capabilities.responseScopes).size !== capabilities.responseScopes.length) context.addIssue({
|
|
586
|
+
code: "custom",
|
|
587
|
+
path: ["responseScopes"],
|
|
588
|
+
message: "interaction response scopes must be unique"
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-data.js
|
|
593
|
+
const InteractionSecretReferenceSchema$1 = z.strictObject({
|
|
594
|
+
kind: z.literal("secret_handle"),
|
|
595
|
+
handleId: boundedIdentifierSchema,
|
|
596
|
+
oneUse: z.literal(true)
|
|
597
|
+
});
|
|
598
|
+
const InteractionDataValueSchema$1 = z.union([
|
|
599
|
+
boundedStringSchema,
|
|
600
|
+
z.number().finite(),
|
|
601
|
+
z.boolean(),
|
|
602
|
+
z.array(boundedStringSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
603
|
+
InteractionSecretReferenceSchema$1
|
|
604
|
+
]);
|
|
605
|
+
/** Field values keyed by InteractionField.name. */
|
|
606
|
+
const InteractionDataSchema$1 = z.unknown().superRefine((value, refinement) => {
|
|
607
|
+
if (value === null || typeof value !== "object") return;
|
|
608
|
+
for (const key of Object.getOwnPropertyNames(value)) if (RESERVED_INTERACTION_FIELD_NAMES$1.has(key)) refinement.addIssue({
|
|
609
|
+
code: "custom",
|
|
610
|
+
message: `interaction field name "${key}" is reserved`
|
|
611
|
+
});
|
|
612
|
+
}).pipe(z.record(InteractionFieldNameSchema$1, InteractionDataValueSchema$1).superRefine((data, refinement) => {
|
|
613
|
+
if (Object.keys(data).length > 256) refinement.addIssue({
|
|
614
|
+
code: "custom",
|
|
615
|
+
message: "interaction data has too many fields"
|
|
616
|
+
});
|
|
617
|
+
})).transform((data) => {
|
|
618
|
+
const safe = Object.create(null);
|
|
619
|
+
for (const key of Object.keys(data)) safe[key] = data[key];
|
|
620
|
+
return safe;
|
|
621
|
+
});
|
|
622
|
+
const InteractionResolutionSchema$1 = z.discriminatedUnion("outcome", [
|
|
623
|
+
z.strictObject({
|
|
624
|
+
outcome: z.literal("accepted"),
|
|
625
|
+
data: InteractionDataSchema$1.optional()
|
|
626
|
+
}),
|
|
627
|
+
z.strictObject({
|
|
628
|
+
outcome: z.literal("declined"),
|
|
629
|
+
data: InteractionDataSchema$1.optional()
|
|
630
|
+
}),
|
|
631
|
+
z.strictObject({
|
|
632
|
+
outcome: z.literal("cancelled"),
|
|
633
|
+
data: InteractionDataSchema$1.optional()
|
|
634
|
+
})
|
|
635
|
+
]);
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-permissions.js
|
|
638
|
+
const InteractionKind$1 = {
|
|
639
|
+
/** Agent asks the user to answer/choose. Answer = the chosen field values. */
|
|
640
|
+
Question: "question",
|
|
641
|
+
/** Agent requests approval to run a tool/command. Answer = a `PermissionGrant`. */
|
|
642
|
+
Permission: "permission",
|
|
643
|
+
/** Agent shares a plan/todo list for review/approval. */
|
|
644
|
+
Plan: "plan"
|
|
645
|
+
};
|
|
646
|
+
const wellKnownInteractionKinds$1 = new Set(Object.values(InteractionKind$1));
|
|
647
|
+
const requestedInteractionKindSchema$1 = boundedIdentifierSchema.refine((value) => wellKnownInteractionKinds$1.has(value) || value.includes(".") && !value.startsWith(".") && !value.endsWith(".") && !value.includes(".."), "custom interaction kind must be namespaced");
|
|
648
|
+
z.record(requestedInteractionKindSchema$1, z.boolean()).superRefine((value, context) => {
|
|
649
|
+
if (Object.keys(value).length > 256) context.addIssue({
|
|
650
|
+
code: z.ZodIssueCode.custom,
|
|
651
|
+
message: `interaction posture exceeds 256 kinds`
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
/** Field name carrying the grant on a `permission` interaction's response. */
|
|
655
|
+
const PERMISSION_GRANT_FIELD$1 = "grant";
|
|
656
|
+
/** Graduated permission decision — the value of the `grant` field. */
|
|
657
|
+
const PermissionGrantSchema$1 = z.enum([
|
|
658
|
+
"allow_once",
|
|
659
|
+
"allow_session",
|
|
660
|
+
"allow_always",
|
|
661
|
+
"deny"
|
|
662
|
+
]);
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-answer-validation.js
|
|
665
|
+
/**
|
|
666
|
+
* Validate an accepted answer against its spec. Used by the broker before a
|
|
667
|
+
* response reaches the adapter, so malformed answers are rejected centrally.
|
|
668
|
+
*/
|
|
669
|
+
function validateInteractionAnswer$1(spec, data) {
|
|
670
|
+
const errors = [];
|
|
671
|
+
const parsedSpec = InteractionAnswerSpecSchema$1.safeParse(spec);
|
|
672
|
+
if (!parsedSpec.success) return {
|
|
673
|
+
ok: false,
|
|
674
|
+
errors: parsedSpec.error.issues.map((issue) => issue.message)
|
|
675
|
+
};
|
|
676
|
+
if (data !== void 0 && (!data || typeof data !== "object" || Array.isArray(data))) return {
|
|
677
|
+
ok: false,
|
|
678
|
+
errors: ["interaction data must be an object"]
|
|
679
|
+
};
|
|
680
|
+
const d = data ?? Object.create(null);
|
|
681
|
+
const prototype = Object.getPrototypeOf(d);
|
|
682
|
+
if (prototype !== Object.prototype && prototype !== null) return {
|
|
683
|
+
ok: false,
|
|
684
|
+
errors: ["interaction data must be a plain object"]
|
|
685
|
+
};
|
|
686
|
+
if (Object.keys(d).length > 256) return {
|
|
687
|
+
ok: false,
|
|
688
|
+
errors: ["interaction data has too many fields"]
|
|
689
|
+
};
|
|
690
|
+
const exactSpec = parsedSpec.data;
|
|
691
|
+
const knownFields = new Set(exactSpec.fields.map((field) => field.name));
|
|
692
|
+
for (const fieldName of Object.keys(d)) {
|
|
693
|
+
if (fieldName.length > 512) {
|
|
694
|
+
errors.push(`unknown field "${fieldName}"`);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
const rawValue = d[fieldName];
|
|
698
|
+
if (typeof rawValue === "string" && rawValue.length > 16384) errors.push(`field "${fieldName}" exceeds the contract string bound`);
|
|
699
|
+
else if (Array.isArray(rawValue)) {
|
|
700
|
+
if (rawValue.length > 1024) errors.push(`field "${fieldName}" has too many values`);
|
|
701
|
+
for (const entry of rawValue) if (typeof entry !== "string" || entry.length > 16384) {
|
|
702
|
+
errors.push(`field "${fieldName}" contains an invalid bounded value`);
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
} else if (rawValue && typeof rawValue === "object") {
|
|
706
|
+
const valuePrototype = Object.getPrototypeOf(rawValue);
|
|
707
|
+
if (valuePrototype !== Object.prototype && valuePrototype !== null || Object.keys(rawValue).length > 3) errors.push(`field "${fieldName}" contains an invalid object value`);
|
|
708
|
+
}
|
|
709
|
+
if (!knownFields.has(fieldName)) errors.push(`unknown field "${fieldName}"`);
|
|
710
|
+
}
|
|
711
|
+
for (const field of exactSpec.fields) {
|
|
712
|
+
const hasValue = Object.hasOwn(d, field.name);
|
|
713
|
+
const v = hasValue ? d[field.name] : void 0;
|
|
714
|
+
if (!(hasValue && v !== void 0 && v !== null && !(typeof v === "string" && v === ""))) {
|
|
715
|
+
if (field.required) errors.push(`missing required field "${field.name}"`);
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
switch (field.type) {
|
|
719
|
+
case "text":
|
|
720
|
+
if (typeof v !== "string") errors.push(`field "${field.name}" must be a string`);
|
|
721
|
+
else if (field.maxLength !== void 0 && v.length > field.maxLength) errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
722
|
+
break;
|
|
723
|
+
case "secret": {
|
|
724
|
+
const isHandle = typeof v === "object" && v !== null && !Array.isArray(v) && Object.keys(v).length === 3 && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null) && Object.hasOwn(v, "kind") && Object.hasOwn(v, "handleId") && Object.hasOwn(v, "oneUse") && v.kind === "secret_handle" && v.oneUse === true && boundedIdentifierSchema.safeParse(v.handleId).success;
|
|
725
|
+
if (typeof v !== "string" && !isHandle) errors.push(`field "${field.name}" must be a string or one-use secret handle`);
|
|
726
|
+
else if (typeof v === "string" && field.maxLength !== void 0 && v.length > field.maxLength) errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
case "number":
|
|
730
|
+
if (typeof v !== "number" || !Number.isFinite(v)) errors.push(`field "${field.name}" must be a finite number`);
|
|
731
|
+
else {
|
|
732
|
+
if (field.min !== void 0 && v < field.min) errors.push(`field "${field.name}" below min ${field.min}`);
|
|
733
|
+
if (field.max !== void 0 && v > field.max) errors.push(`field "${field.name}" above max ${field.max}`);
|
|
734
|
+
}
|
|
735
|
+
break;
|
|
736
|
+
case "boolean":
|
|
737
|
+
if (typeof v !== "boolean") errors.push(`field "${field.name}" must be a boolean`);
|
|
738
|
+
break;
|
|
739
|
+
case "select": {
|
|
740
|
+
if (!Array.isArray(v)) {
|
|
741
|
+
errors.push(`field "${field.name}" must be an array of option values`);
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
if (v.length > 1024) {
|
|
745
|
+
errors.push(`field "${field.name}" has too many option values`);
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
if (!field.multi && v.length > 1) errors.push(`field "${field.name}" accepts a single value`);
|
|
749
|
+
if (field.required && v.length === 0) errors.push(`field "${field.name}" requires a selection`);
|
|
750
|
+
const allowed = new Set(field.options.map((o) => o.value));
|
|
751
|
+
for (const choice of v) {
|
|
752
|
+
if (allowed.has(choice)) continue;
|
|
753
|
+
if (field.allowCustom === true) {
|
|
754
|
+
if (typeof choice !== "string" || choice.trim() === "") errors.push(`field "${field.name}" has blank write-in value`);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
errors.push(`field "${field.name}" has invalid option "${choice}"`);
|
|
758
|
+
}
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return errors.length === 0 ? { ok: true } : {
|
|
764
|
+
ok: false,
|
|
765
|
+
errors
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-resolution-validation.js
|
|
770
|
+
/**
|
|
771
|
+
* A declined or cancelled resolution submits no answer, so any secret-typed
|
|
772
|
+
* field it carries can only be leakage into a transport that retains it.
|
|
773
|
+
*/
|
|
774
|
+
function secretFieldErrors$1(spec, resolution) {
|
|
775
|
+
const secretFields = new Set(spec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
776
|
+
return Object.keys(resolution.data ?? {}).filter((fieldName) => secretFields.has(fieldName)).map((fieldName) => `field "${fieldName}" is secret and cannot ride a ${resolution.outcome} resolution`);
|
|
777
|
+
}
|
|
778
|
+
function validateResolutionForRequest$1(request, resolution) {
|
|
779
|
+
if (resolution.outcome !== "accepted") {
|
|
780
|
+
const errors = secretFieldErrors$1(request.answerSpec, resolution);
|
|
781
|
+
if (Object.keys(resolution.data ?? {}).length > 0) errors.push(`a ${resolution.outcome} resolution cannot carry answer fields`);
|
|
782
|
+
return errors;
|
|
783
|
+
}
|
|
784
|
+
const validation = validateInteractionAnswer$1(request.answerSpec, resolution.data);
|
|
785
|
+
const errors = validation.ok ? [] : [...validation.errors];
|
|
786
|
+
if (request.kind !== InteractionKind$1.Permission) return errors;
|
|
787
|
+
const grant = resolution.data?.[PERMISSION_GRANT_FIELD$1];
|
|
788
|
+
if (!Array.isArray(grant) || grant.length !== 1) {
|
|
789
|
+
errors.push("permission response must select exactly one \"grant\" value");
|
|
790
|
+
return errors;
|
|
791
|
+
}
|
|
792
|
+
const parsedGrant = PermissionGrantSchema$1.safeParse(grant[0]);
|
|
793
|
+
if (!parsedGrant.success) {
|
|
794
|
+
errors.push(`permission response has invalid grant "${String(grant[0])}"`);
|
|
795
|
+
return errors;
|
|
796
|
+
}
|
|
797
|
+
if (parsedGrant.data === "deny") return errors;
|
|
798
|
+
if (!new Set(request.responseScopes ?? ["interaction"]).has({
|
|
799
|
+
allow_once: "interaction",
|
|
800
|
+
allow_session: "session",
|
|
801
|
+
allow_always: "persistent",
|
|
802
|
+
deny: "interaction"
|
|
803
|
+
}[parsedGrant.data])) errors.push(`permission grant "${parsedGrant.data}" exceeds the request's response scopes`);
|
|
804
|
+
return errors;
|
|
805
|
+
}
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/interaction-envelope.js
|
|
808
|
+
const interactionOutcomeValues$1 = [
|
|
809
|
+
"accepted",
|
|
810
|
+
"declined",
|
|
811
|
+
"cancelled"
|
|
812
|
+
];
|
|
813
|
+
const InteractionSubjectSchema$1 = z.discriminatedUnion("type", [
|
|
814
|
+
z.strictObject({
|
|
815
|
+
type: z.literal("tool"),
|
|
816
|
+
toolName: boundedIdentifierSchema,
|
|
817
|
+
input: boundedJsonSchema.optional()
|
|
818
|
+
}),
|
|
819
|
+
z.strictObject({
|
|
820
|
+
type: z.literal("command"),
|
|
821
|
+
command: boundedStringSchema
|
|
822
|
+
}),
|
|
823
|
+
z.strictObject({
|
|
824
|
+
type: z.literal("file"),
|
|
825
|
+
path: boundedStringSchema,
|
|
826
|
+
preview: boundedStringSchema.optional()
|
|
827
|
+
}),
|
|
828
|
+
z.strictObject({
|
|
829
|
+
type: z.literal("resource"),
|
|
830
|
+
uri: boundedStringSchema
|
|
831
|
+
})
|
|
832
|
+
]);
|
|
833
|
+
const InteractionOutcomeSchema$1 = z.enum(interactionOutcomeValues$1);
|
|
834
|
+
const InteractionRequestBindingSchema$1 = z.strictObject({
|
|
835
|
+
runId: boundedIdentifierSchema,
|
|
836
|
+
provider: boundedIdentifierSchema,
|
|
837
|
+
environmentId: boundedIdentifierSchema,
|
|
838
|
+
sessionId: boundedIdentifierSchema,
|
|
839
|
+
executionId: boundedIdentifierSchema,
|
|
840
|
+
interactionId: boundedIdentifierSchema
|
|
841
|
+
});
|
|
842
|
+
InteractionRequestBindingSchema$1.omit({ interactionId: true });
|
|
843
|
+
/** Binding carried by a response command and acknowledgement. */
|
|
844
|
+
const InteractionBindingSchema$1 = z.strictObject({
|
|
845
|
+
...InteractionRequestBindingSchema$1.shape,
|
|
846
|
+
requestDigest: sha256DigestSchema
|
|
847
|
+
});
|
|
848
|
+
const InteractionRequestMaterialSchema$1 = z.strictObject({
|
|
849
|
+
id: boundedIdentifierSchema,
|
|
850
|
+
kind: boundedIdentifierSchema,
|
|
851
|
+
title: boundedStringSchema.min(1),
|
|
852
|
+
body: boundedStringSchema.optional(),
|
|
853
|
+
subject: InteractionSubjectSchema$1.optional(),
|
|
854
|
+
answerSpec: InteractionAnswerSpecSchema$1,
|
|
855
|
+
responseScopes: z.array(InteractionResponseScopeSchema$1).min(1).max(CONTRACT_MAX_ARRAY_LENGTH).optional(),
|
|
856
|
+
allowedOutcomes: z.array(InteractionOutcomeSchema$1).min(1).max(interactionOutcomeValues$1.length).optional(),
|
|
857
|
+
default: InteractionResolutionSchema$1.optional(),
|
|
858
|
+
timeoutMs: z.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
859
|
+
onTimeout: z.enum([
|
|
860
|
+
"default",
|
|
861
|
+
"fail",
|
|
862
|
+
"wait"
|
|
863
|
+
]).optional(),
|
|
864
|
+
binding: InteractionRequestBindingSchema$1
|
|
865
|
+
});
|
|
866
|
+
function interactionRequestDigest$1(request) {
|
|
867
|
+
const parsed = InteractionRequestMaterialSchema$1.parse(request);
|
|
868
|
+
rejectSecretDefaultValues$1(parsed);
|
|
869
|
+
return canonicalCandidateDigest(parsed);
|
|
870
|
+
}
|
|
871
|
+
function rejectSecretDefaultValues$1(request) {
|
|
872
|
+
const secretFields = new Set(request.answerSpec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
873
|
+
for (const fieldName of Object.keys(request.default?.data ?? {})) if (secretFields.has(fieldName)) throw new Error("secret answers cannot be embedded in interaction defaults");
|
|
874
|
+
}
|
|
875
|
+
const InteractionRequestSchema$1 = z.strictObject({
|
|
876
|
+
...InteractionRequestMaterialSchema$1.shape,
|
|
877
|
+
requestDigest: sha256DigestSchema
|
|
878
|
+
}).superRefine((request, context) => {
|
|
879
|
+
if (request.binding.interactionId !== request.id) context.addIssue({
|
|
880
|
+
code: "custom",
|
|
881
|
+
path: ["binding", "interactionId"],
|
|
882
|
+
message: "interaction binding must name the request id"
|
|
883
|
+
});
|
|
884
|
+
if (request.responseScopes && new Set(request.responseScopes).size !== request.responseScopes.length) context.addIssue({
|
|
885
|
+
code: "custom",
|
|
886
|
+
path: ["responseScopes"],
|
|
887
|
+
message: "interaction response scopes must be unique"
|
|
888
|
+
});
|
|
889
|
+
if (request.allowedOutcomes && new Set(request.allowedOutcomes).size !== request.allowedOutcomes.length) context.addIssue({
|
|
890
|
+
code: "custom",
|
|
891
|
+
path: ["allowedOutcomes"],
|
|
892
|
+
message: "interaction outcomes must be unique"
|
|
893
|
+
});
|
|
894
|
+
if (request.onTimeout === "default" && request.default === void 0) context.addIssue({
|
|
895
|
+
code: "custom",
|
|
896
|
+
path: ["default"],
|
|
897
|
+
message: "onTimeout=default requires a default resolution"
|
|
898
|
+
});
|
|
899
|
+
if (request.default && request.allowedOutcomes && !request.allowedOutcomes.includes(request.default.outcome)) context.addIssue({
|
|
900
|
+
code: "custom",
|
|
901
|
+
path: ["default", "outcome"],
|
|
902
|
+
message: "default outcome is not allowed by the request"
|
|
903
|
+
});
|
|
904
|
+
if (request.default) {
|
|
905
|
+
for (const error of validateResolutionForRequest$1(request, request.default)) context.addIssue({
|
|
906
|
+
code: "custom",
|
|
907
|
+
path: ["default"],
|
|
908
|
+
message: error
|
|
909
|
+
});
|
|
910
|
+
const secretFields = new Set(request.answerSpec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
911
|
+
for (const fieldName of Object.keys(request.default.data ?? {})) {
|
|
912
|
+
if (!secretFields.has(fieldName)) continue;
|
|
913
|
+
context.addIssue({
|
|
914
|
+
code: "custom",
|
|
915
|
+
path: [
|
|
916
|
+
"default",
|
|
917
|
+
"data",
|
|
918
|
+
fieldName
|
|
919
|
+
],
|
|
920
|
+
message: "secret answers cannot be embedded in interaction defaults"
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
const { requestDigest: _digest, ...material } = request;
|
|
925
|
+
if (!Object.keys(request.default?.data ?? {}).some((fieldName) => request.answerSpec.fields.some((field) => field.type === "secret" && field.name === fieldName))) {
|
|
926
|
+
if (request.requestDigest !== interactionRequestDigest$1(material)) context.addIssue({
|
|
927
|
+
code: "custom",
|
|
928
|
+
path: ["requestDigest"],
|
|
929
|
+
message: "interaction request digest does not match its content"
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
const InteractionResponseSchema$1 = z.discriminatedUnion("outcome", [
|
|
934
|
+
z.strictObject({
|
|
935
|
+
id: boundedIdentifierSchema,
|
|
936
|
+
outcome: z.literal("accepted"),
|
|
937
|
+
data: InteractionDataSchema$1.optional()
|
|
938
|
+
}),
|
|
939
|
+
z.strictObject({
|
|
940
|
+
id: boundedIdentifierSchema,
|
|
941
|
+
outcome: z.literal("declined"),
|
|
942
|
+
data: InteractionDataSchema$1.optional()
|
|
943
|
+
}),
|
|
944
|
+
z.strictObject({
|
|
945
|
+
id: boundedIdentifierSchema,
|
|
946
|
+
outcome: z.literal("cancelled"),
|
|
947
|
+
data: InteractionDataSchema$1.optional()
|
|
948
|
+
})
|
|
949
|
+
]);
|
|
950
|
+
/** Digest the exact binding and response carried by a retryable command. */
|
|
951
|
+
function interactionResponseCommandDigest$1(material) {
|
|
952
|
+
return canonicalCandidateDigest({
|
|
953
|
+
binding: InteractionBindingSchema$1.parse(material.binding),
|
|
954
|
+
response: InteractionResponseSchema$1.parse(material.response)
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
z.strictObject({
|
|
958
|
+
operationId: boundedIdentifierSchema,
|
|
959
|
+
binding: InteractionBindingSchema$1,
|
|
960
|
+
commandDigest: sha256DigestSchema,
|
|
961
|
+
response: InteractionResponseSchema$1
|
|
962
|
+
}).superRefine((command, context) => {
|
|
963
|
+
if (command.binding.interactionId !== command.response.id) context.addIssue({
|
|
964
|
+
code: "custom",
|
|
965
|
+
path: ["response", "id"],
|
|
966
|
+
message: "response id must match the bound interaction id"
|
|
967
|
+
});
|
|
968
|
+
if (command.commandDigest !== interactionResponseCommandDigest$1({
|
|
969
|
+
binding: command.binding,
|
|
970
|
+
response: command.response
|
|
971
|
+
})) context.addIssue({
|
|
972
|
+
code: "custom",
|
|
973
|
+
path: ["commandDigest"],
|
|
974
|
+
message: "interaction response command digest does not match its content"
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
const InteractionAcknowledgementStatusSchema$1 = z.enum([
|
|
978
|
+
"accepted",
|
|
979
|
+
"already_resolved_same",
|
|
980
|
+
"already_resolved_different",
|
|
981
|
+
"expired",
|
|
982
|
+
"cancelled",
|
|
983
|
+
"unknown_interaction",
|
|
984
|
+
"unknown_run",
|
|
985
|
+
"binding_mismatch",
|
|
986
|
+
"invalid_response",
|
|
987
|
+
"transport_failure"
|
|
988
|
+
]);
|
|
989
|
+
z.strictObject({
|
|
990
|
+
operationId: boundedIdentifierSchema,
|
|
991
|
+
binding: InteractionBindingSchema$1,
|
|
992
|
+
commandDigest: sha256DigestSchema,
|
|
993
|
+
status: InteractionAcknowledgementStatusSchema$1,
|
|
994
|
+
message: boundedStringSchema.min(1).optional(),
|
|
995
|
+
retryable: z.boolean().optional()
|
|
996
|
+
}).superRefine((acknowledgement, context) => {
|
|
997
|
+
if (["invalid_response", "transport_failure"].includes(acknowledgement.status) && acknowledgement.message === void 0) context.addIssue({
|
|
998
|
+
code: "custom",
|
|
999
|
+
path: ["message"],
|
|
1000
|
+
message: `${acknowledgement.status} must include a message`
|
|
1001
|
+
});
|
|
1002
|
+
if (acknowledgement.status === "transport_failure" && acknowledgement.retryable === void 0) context.addIssue({
|
|
1003
|
+
code: "custom",
|
|
1004
|
+
path: ["retryable"],
|
|
1005
|
+
message: "transport_failure must state whether retry is safe"
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/plan.js
|
|
1010
|
+
/**
|
|
1011
|
+
* Credential-free provider correlation committed with the plan. This union is
|
|
1012
|
+
* deliberately closed: adding plan support for another harness requires an
|
|
1013
|
+
* explicit resume contract instead of smuggling opaque metadata through.
|
|
1014
|
+
*/
|
|
1015
|
+
const PlanProviderStateSchema$1 = z.discriminatedUnion("kind", [
|
|
1016
|
+
z.object({
|
|
1017
|
+
kind: z.literal("claude-code"),
|
|
1018
|
+
version: z.literal(1),
|
|
1019
|
+
nativeSessionId: z.string().min(1)
|
|
1020
|
+
}).strict(),
|
|
1021
|
+
z.object({
|
|
1022
|
+
kind: z.literal("codex"),
|
|
1023
|
+
version: z.literal(1),
|
|
1024
|
+
threadId: z.string().min(1)
|
|
1025
|
+
}).strict(),
|
|
1026
|
+
z.object({
|
|
1027
|
+
kind: z.literal("opencode"),
|
|
1028
|
+
version: z.literal(1)
|
|
1029
|
+
}).strict()
|
|
1030
|
+
]);
|
|
1031
|
+
/**
|
|
1032
|
+
* A plan committed by the runtime before the planning turn is allowed to end.
|
|
1033
|
+
* The full body is part of the contract so consumers never reconstruct it from
|
|
1034
|
+
* rendered chat text.
|
|
1035
|
+
*/
|
|
1036
|
+
const DurablePlanSchema$1 = z.object({
|
|
1037
|
+
id: z.string().min(1),
|
|
1038
|
+
revision: z.number().int().positive(),
|
|
1039
|
+
title: z.string().trim().min(1).optional(),
|
|
1040
|
+
body: z.string().trim().min(1),
|
|
1041
|
+
submittedAt: z.string().datetime({ offset: true })
|
|
1042
|
+
}).strict();
|
|
1043
|
+
z.object({
|
|
1044
|
+
title: z.string().trim().min(1).optional(),
|
|
1045
|
+
body: z.string().trim().min(1),
|
|
1046
|
+
/** Stable provider tool-call identity reused when a lost acknowledgement retries. */
|
|
1047
|
+
sourceToolCallId: z.string().min(1),
|
|
1048
|
+
/** Credential-free correlation required to resume the deferred turn. */
|
|
1049
|
+
providerState: PlanProviderStateSchema$1
|
|
1050
|
+
}).strict();
|
|
1051
|
+
/** The human verdict that starts the next turn. */
|
|
1052
|
+
const PlanDecisionSchema$1 = z.discriminatedUnion("outcome", [z.object({ outcome: z.literal("approved") }).strict(), z.object({
|
|
1053
|
+
outcome: z.literal("rejected"),
|
|
1054
|
+
feedback: z.string().trim().min(1)
|
|
1055
|
+
}).strict()]);
|
|
1056
|
+
z.object({
|
|
1057
|
+
version: z.literal(1),
|
|
1058
|
+
plan: DurablePlanSchema$1,
|
|
1059
|
+
sourceToolCallId: z.string().min(1),
|
|
1060
|
+
decision: PlanDecisionSchema$1,
|
|
1061
|
+
/** Exact payload previously committed with the plan submission. */
|
|
1062
|
+
providerState: PlanProviderStateSchema$1
|
|
1063
|
+
}).strict();
|
|
1064
|
+
z.discriminatedUnion("type", [z.object({ type: z.literal("completed") }).strict(), z.object({
|
|
1065
|
+
type: z.literal("awaiting_plan_decision"),
|
|
1066
|
+
plan: DurablePlanSchema$1
|
|
1067
|
+
}).strict()]);
|
|
1068
|
+
//#endregion
|
|
1069
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/runtime-control.js
|
|
1070
|
+
const stableIdSchema$1 = boundedIdentifierSchema;
|
|
1071
|
+
const AgentExactRunControlRefSchema$1 = z.strictObject({
|
|
1072
|
+
runId: stableIdSchema$1,
|
|
1073
|
+
provider: stableIdSchema$1,
|
|
1074
|
+
environmentId: stableIdSchema$1,
|
|
1075
|
+
sessionId: stableIdSchema$1.optional(),
|
|
1076
|
+
executionId: stableIdSchema$1.optional(),
|
|
1077
|
+
requestDigest: sha256DigestSchema.optional()
|
|
1078
|
+
}).extend({
|
|
1079
|
+
sessionId: stableIdSchema$1,
|
|
1080
|
+
executionId: stableIdSchema$1,
|
|
1081
|
+
requestDigest: sha256DigestSchema
|
|
1082
|
+
});
|
|
1083
|
+
function agentRunCancellationRequestDigest$1(request) {
|
|
1084
|
+
const parsed = AgentRunCancellationRequestMaterialSchema$1.parse(request);
|
|
1085
|
+
return canonicalCandidateDigest({
|
|
1086
|
+
operationId: parsed.operationId,
|
|
1087
|
+
run: parsed.run,
|
|
1088
|
+
...parsed.reason === void 0 ? {} : { reason: parsed.reason }
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
const AgentRunCancellationRequestMaterialSchema$1 = z.strictObject({
|
|
1092
|
+
operationId: stableIdSchema$1,
|
|
1093
|
+
run: AgentExactRunControlRefSchema$1,
|
|
1094
|
+
reason: boundedStringSchema.min(1).max(2048).optional()
|
|
1095
|
+
});
|
|
1096
|
+
z.strictObject({
|
|
1097
|
+
...AgentRunCancellationRequestMaterialSchema$1.shape,
|
|
1098
|
+
requestDigest: sha256DigestSchema
|
|
1099
|
+
}).superRefine((request, refinement) => {
|
|
1100
|
+
const { requestDigest: _requestDigest, ...material } = request;
|
|
1101
|
+
if (request.requestDigest !== agentRunCancellationRequestDigest$1(material)) refinement.addIssue({
|
|
1102
|
+
code: "custom",
|
|
1103
|
+
path: ["requestDigest"],
|
|
1104
|
+
message: "run cancellation request digest does not match its content"
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
z.strictObject({
|
|
1108
|
+
operationId: stableIdSchema$1,
|
|
1109
|
+
requestDigest: sha256DigestSchema,
|
|
1110
|
+
run: AgentExactRunControlRefSchema$1,
|
|
1111
|
+
status: z.enum([
|
|
1112
|
+
"accepted",
|
|
1113
|
+
"replayed",
|
|
1114
|
+
"conflict",
|
|
1115
|
+
"unknown"
|
|
1116
|
+
]),
|
|
1117
|
+
effect: z.enum([
|
|
1118
|
+
"cancel_requested",
|
|
1119
|
+
"cancelled",
|
|
1120
|
+
"not_live",
|
|
1121
|
+
"unknown"
|
|
1122
|
+
]),
|
|
1123
|
+
message: boundedStringSchema.min(1).optional(),
|
|
1124
|
+
retryable: z.boolean().optional(),
|
|
1125
|
+
existingRequestDigest: sha256DigestSchema.optional()
|
|
1126
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
1127
|
+
const known = acknowledgement.effect !== "unknown";
|
|
1128
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !known || (acknowledgement.status === "conflict" || acknowledgement.status === "unknown") && known) refinement.addIssue({
|
|
1129
|
+
code: "custom",
|
|
1130
|
+
path: ["effect"],
|
|
1131
|
+
message: "cancellation status and effect certainty do not agree"
|
|
1132
|
+
});
|
|
1133
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === void 0) refinement.addIssue({
|
|
1134
|
+
code: "custom",
|
|
1135
|
+
path: ["existingRequestDigest"],
|
|
1136
|
+
message: "a cancellation conflict must include the existing digest"
|
|
1137
|
+
});
|
|
1138
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === acknowledgement.requestDigest) refinement.addIssue({
|
|
1139
|
+
code: "custom",
|
|
1140
|
+
path: ["existingRequestDigest"],
|
|
1141
|
+
message: "a cancellation conflict must identify a different request"
|
|
1142
|
+
});
|
|
1143
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
1144
|
+
code: "custom",
|
|
1145
|
+
path: ["existingRequestDigest"],
|
|
1146
|
+
message: "only a cancellation conflict may include an existing digest"
|
|
1147
|
+
});
|
|
1148
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== false)) refinement.addIssue({
|
|
1149
|
+
code: "custom",
|
|
1150
|
+
path: ["retryable"],
|
|
1151
|
+
message: "an unknown cancellation outcome must be explicit and non-repeatable"
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
const unknownRecordSchema$1 = boundedJsonRecordSchema;
|
|
1155
|
+
const partBase$1 = {
|
|
1156
|
+
id: stableIdSchema$1,
|
|
1157
|
+
sessionID: stableIdSchema$1,
|
|
1158
|
+
messageID: stableIdSchema$1
|
|
1159
|
+
};
|
|
1160
|
+
const toolTimeSchema$1 = z.strictObject({
|
|
1161
|
+
start: z.number().finite(),
|
|
1162
|
+
end: z.number().finite().optional()
|
|
1163
|
+
});
|
|
1164
|
+
const toolStateSchema$1 = z.discriminatedUnion("status", [
|
|
1165
|
+
z.strictObject({
|
|
1166
|
+
status: z.literal("pending"),
|
|
1167
|
+
input: boundedEventContentRecordSchema,
|
|
1168
|
+
raw: boundedEventContentStringSchema.optional()
|
|
1169
|
+
}),
|
|
1170
|
+
z.strictObject({
|
|
1171
|
+
status: z.literal("running"),
|
|
1172
|
+
input: boundedEventContentRecordSchema,
|
|
1173
|
+
title: boundedStringSchema.optional(),
|
|
1174
|
+
metadata: unknownRecordSchema$1.optional(),
|
|
1175
|
+
time: z.strictObject({ start: z.number().finite() }).optional()
|
|
1176
|
+
}),
|
|
1177
|
+
z.strictObject({
|
|
1178
|
+
status: z.literal("completed"),
|
|
1179
|
+
input: boundedEventContentRecordSchema,
|
|
1180
|
+
output: boundedEventContentJsonSchema,
|
|
1181
|
+
title: boundedStringSchema.optional(),
|
|
1182
|
+
metadata: unknownRecordSchema$1.optional(),
|
|
1183
|
+
time: z.strictObject({
|
|
1184
|
+
start: z.number().finite(),
|
|
1185
|
+
end: z.number().finite()
|
|
1186
|
+
}).optional()
|
|
1187
|
+
}),
|
|
1188
|
+
z.strictObject({
|
|
1189
|
+
status: z.enum(["error", "failed"]),
|
|
1190
|
+
input: boundedEventContentRecordSchema,
|
|
1191
|
+
error: boundedStringSchema.optional(),
|
|
1192
|
+
output: boundedEventContentJsonSchema.optional(),
|
|
1193
|
+
metadata: unknownRecordSchema$1.optional(),
|
|
1194
|
+
time: toolTimeSchema$1.optional()
|
|
1195
|
+
})
|
|
1196
|
+
]);
|
|
1197
|
+
const partSchema$1 = z.discriminatedUnion("type", [
|
|
1198
|
+
z.strictObject({
|
|
1199
|
+
...partBase$1,
|
|
1200
|
+
type: z.literal("text"),
|
|
1201
|
+
text: boundedEventContentStringSchema
|
|
1202
|
+
}),
|
|
1203
|
+
z.strictObject({
|
|
1204
|
+
...partBase$1,
|
|
1205
|
+
type: z.literal("tool"),
|
|
1206
|
+
callID: stableIdSchema$1.optional(),
|
|
1207
|
+
tool: stableIdSchema$1,
|
|
1208
|
+
state: toolStateSchema$1,
|
|
1209
|
+
metadata: unknownRecordSchema$1.optional()
|
|
1210
|
+
}),
|
|
1211
|
+
z.strictObject({
|
|
1212
|
+
...partBase$1,
|
|
1213
|
+
type: z.literal("reasoning"),
|
|
1214
|
+
text: boundedEventContentStringSchema
|
|
1215
|
+
}),
|
|
1216
|
+
z.strictObject({
|
|
1217
|
+
...partBase$1,
|
|
1218
|
+
type: z.literal("file"),
|
|
1219
|
+
filename: boundedStringSchema.optional(),
|
|
1220
|
+
mediaType: boundedStringSchema.optional(),
|
|
1221
|
+
url: boundedStringSchema.optional()
|
|
1222
|
+
}),
|
|
1223
|
+
z.strictObject({
|
|
1224
|
+
...partBase$1,
|
|
1225
|
+
type: z.literal("subtask"),
|
|
1226
|
+
prompt: boundedEventContentStringSchema,
|
|
1227
|
+
description: boundedStringSchema,
|
|
1228
|
+
agent: stableIdSchema$1
|
|
1229
|
+
})
|
|
1230
|
+
]);
|
|
1231
|
+
const TERMINAL_CHILD_TASK_STATUSES$1 = new Set([
|
|
1232
|
+
"completed",
|
|
1233
|
+
"failed",
|
|
1234
|
+
"cancelled"
|
|
1235
|
+
]);
|
|
1236
|
+
const epochMillisecondsSchema$1 = z.number().finite().nonnegative();
|
|
1237
|
+
/**
|
|
1238
|
+
* Provider-native child task lifecycle. Identity comes only from `childId`,
|
|
1239
|
+
* `parentChildId`, and `sourceEventId`; `raw` is opaque and bounded. A provider
|
|
1240
|
+
* without a stable `childId` emits no `child-task` event.
|
|
1241
|
+
*/
|
|
1242
|
+
const ChildTaskEventSchema$1 = z.strictObject({
|
|
1243
|
+
type: z.literal("child-task"),
|
|
1244
|
+
childId: stableIdSchema$1,
|
|
1245
|
+
parentChildId: stableIdSchema$1.optional(),
|
|
1246
|
+
status: z.enum([
|
|
1247
|
+
"started",
|
|
1248
|
+
"running",
|
|
1249
|
+
"completed",
|
|
1250
|
+
"failed",
|
|
1251
|
+
"cancelled"
|
|
1252
|
+
]),
|
|
1253
|
+
title: boundedStringSchema.optional(),
|
|
1254
|
+
time: z.strictObject({
|
|
1255
|
+
started: epochMillisecondsSchema$1,
|
|
1256
|
+
updated: epochMillisecondsSchema$1,
|
|
1257
|
+
ended: epochMillisecondsSchema$1.optional()
|
|
1258
|
+
}),
|
|
1259
|
+
runner: stableIdSchema$1.optional(),
|
|
1260
|
+
model: stableIdSchema$1.optional(),
|
|
1261
|
+
usage: ModelUsageSchema$1.optional(),
|
|
1262
|
+
terminalReason: boundedStringSchema.optional(),
|
|
1263
|
+
sourceEventId: stableIdSchema$1,
|
|
1264
|
+
raw: boundedJsonRecordSchema.optional()
|
|
1265
|
+
}).superRefine((event, refinement) => {
|
|
1266
|
+
const terminal = TERMINAL_CHILD_TASK_STATUSES$1.has(event.status);
|
|
1267
|
+
if (!terminal && event.time.ended !== void 0) refinement.addIssue({
|
|
1268
|
+
code: "custom",
|
|
1269
|
+
path: ["time", "ended"],
|
|
1270
|
+
message: "only a terminal child task status may carry an end time"
|
|
1271
|
+
});
|
|
1272
|
+
if (!terminal && event.terminalReason !== void 0) refinement.addIssue({
|
|
1273
|
+
code: "custom",
|
|
1274
|
+
path: ["terminalReason"],
|
|
1275
|
+
message: "only a terminal child task status may carry a terminal reason"
|
|
1276
|
+
});
|
|
1277
|
+
if (event.time.updated < event.time.started) refinement.addIssue({
|
|
1278
|
+
code: "custom",
|
|
1279
|
+
path: ["time", "updated"],
|
|
1280
|
+
message: "a child task update time cannot precede its start time"
|
|
1281
|
+
});
|
|
1282
|
+
if (event.time.ended !== void 0 && event.time.ended < event.time.started) refinement.addIssue({
|
|
1283
|
+
code: "custom",
|
|
1284
|
+
path: ["time", "ended"],
|
|
1285
|
+
message: "a child task end time cannot precede its start time"
|
|
1286
|
+
});
|
|
1287
|
+
if (event.parentChildId === event.childId) refinement.addIssue({
|
|
1288
|
+
code: "custom",
|
|
1289
|
+
path: ["parentChildId"],
|
|
1290
|
+
message: "a child task cannot be its own parent"
|
|
1291
|
+
});
|
|
1292
|
+
});
|
|
1293
|
+
const CanonicalStreamEventSchema$1 = z.discriminatedUnion("type", [
|
|
1294
|
+
z.strictObject({
|
|
1295
|
+
type: z.literal("message.part.updated"),
|
|
1296
|
+
part: partSchema$1,
|
|
1297
|
+
delta: boundedEventContentStringSchema.optional()
|
|
1298
|
+
}),
|
|
1299
|
+
z.strictObject({
|
|
1300
|
+
type: z.literal("tool-heartbeat"),
|
|
1301
|
+
toolName: stableIdSchema$1,
|
|
1302
|
+
partId: stableIdSchema$1,
|
|
1303
|
+
elapsedMs: z.number().finite().nonnegative()
|
|
1304
|
+
}),
|
|
1305
|
+
z.strictObject({
|
|
1306
|
+
type: z.literal("tool-slow"),
|
|
1307
|
+
toolName: stableIdSchema$1,
|
|
1308
|
+
partId: stableIdSchema$1,
|
|
1309
|
+
elapsedMs: z.number().finite().nonnegative(),
|
|
1310
|
+
thresholdMs: z.number().finite().nonnegative()
|
|
1311
|
+
}),
|
|
1312
|
+
z.strictObject({
|
|
1313
|
+
type: z.literal("model-processing"),
|
|
1314
|
+
phase: z.enum([
|
|
1315
|
+
"tool-result",
|
|
1316
|
+
"generating",
|
|
1317
|
+
"thinking"
|
|
1318
|
+
]),
|
|
1319
|
+
toolName: stableIdSchema$1.optional(),
|
|
1320
|
+
elapsedMs: z.number().finite().nonnegative().optional()
|
|
1321
|
+
}),
|
|
1322
|
+
z.strictObject({
|
|
1323
|
+
type: z.literal("status"),
|
|
1324
|
+
status: z.enum([
|
|
1325
|
+
"started",
|
|
1326
|
+
"processing",
|
|
1327
|
+
"completed",
|
|
1328
|
+
"failed",
|
|
1329
|
+
"cancelled"
|
|
1330
|
+
]),
|
|
1331
|
+
detail: boundedStringSchema.optional()
|
|
1332
|
+
}),
|
|
1333
|
+
z.strictObject({
|
|
1334
|
+
type: z.literal("warning"),
|
|
1335
|
+
code: stableIdSchema$1,
|
|
1336
|
+
message: boundedStringSchema
|
|
1337
|
+
}),
|
|
1338
|
+
z.strictObject({
|
|
1339
|
+
type: z.literal("raw"),
|
|
1340
|
+
backend: stableIdSchema$1,
|
|
1341
|
+
event: boundedEventContentJsonSchema
|
|
1342
|
+
}),
|
|
1343
|
+
NativeSessionObservedEventSchema$1,
|
|
1344
|
+
z.strictObject({
|
|
1345
|
+
type: z.literal("session.updated"),
|
|
1346
|
+
sessionId: stableIdSchema$1,
|
|
1347
|
+
title: boundedStringSchema.optional(),
|
|
1348
|
+
time: z.strictObject({
|
|
1349
|
+
created: z.number().finite().optional(),
|
|
1350
|
+
updated: z.number().finite().optional()
|
|
1351
|
+
}).optional()
|
|
1352
|
+
}),
|
|
1353
|
+
z.strictObject({
|
|
1354
|
+
type: z.literal("interaction"),
|
|
1355
|
+
request: InteractionRequestSchema$1
|
|
1356
|
+
}),
|
|
1357
|
+
z.strictObject({
|
|
1358
|
+
type: z.literal("interaction.cancel"),
|
|
1359
|
+
id: stableIdSchema$1,
|
|
1360
|
+
reason: boundedStringSchema.optional()
|
|
1361
|
+
}),
|
|
1362
|
+
z.strictObject({
|
|
1363
|
+
type: z.literal("plan.submitted"),
|
|
1364
|
+
plan: DurablePlanSchema$1
|
|
1365
|
+
}),
|
|
1366
|
+
ChildTaskEventSchema$1
|
|
1367
|
+
]).superRefine((event, refinement) => {
|
|
1368
|
+
if (!isBoundedEventContentJson(event, { omitUndefinedObjectFields: true })) refinement.addIssue({
|
|
1369
|
+
code: "custom",
|
|
1370
|
+
message: "canonical stream event exceeds its serialized byte bound"
|
|
1371
|
+
});
|
|
1372
|
+
});
|
|
1373
|
+
z.strictObject({
|
|
1374
|
+
runId: stableIdSchema$1,
|
|
1375
|
+
eventId: stableIdSchema$1,
|
|
1376
|
+
sequence: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
1377
|
+
cursor: stableIdSchema$1.optional(),
|
|
1378
|
+
occurredAt: z.iso.datetime().max(64).optional(),
|
|
1379
|
+
receivedAt: z.iso.datetime().max(64),
|
|
1380
|
+
event: CanonicalStreamEventSchema$1
|
|
1381
|
+
});
|
|
1382
|
+
//#endregion
|
|
1383
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/agent-profile-materialization.js
|
|
1384
|
+
/**
|
|
1385
|
+
* The canonical AgentProfile leaves that can affect one execution.
|
|
1386
|
+
*
|
|
1387
|
+
* Compound parents such as `model`, `prompt`, and `resources` are deliberately
|
|
1388
|
+
* absent. A producer must report the exact requested leaf instead of claiming
|
|
1389
|
+
* a parent while silently dropping one of its children. `systemPrompt` and
|
|
1390
|
+
* `appendSystemPrompt` are separate leaves for the same reason: a backend that
|
|
1391
|
+
* can only add text must report the requested replacement as unsatisfied rather
|
|
1392
|
+
* than acknowledge it.
|
|
1393
|
+
*/
|
|
1394
|
+
const AGENT_PROFILE_MATERIALIZATION_AXES$1 = [
|
|
1395
|
+
"name",
|
|
1396
|
+
"description",
|
|
1397
|
+
"version",
|
|
1398
|
+
"tags",
|
|
1399
|
+
"systemPrompt",
|
|
1400
|
+
"appendSystemPrompt",
|
|
1401
|
+
"instructions",
|
|
1402
|
+
"modelDefault",
|
|
1403
|
+
"modelSmall",
|
|
1404
|
+
"modelProvider",
|
|
1405
|
+
"modelReasoningEffort",
|
|
1406
|
+
"modelMaxVisibleOutputTokens",
|
|
1407
|
+
"modelMaxReasoningTokens",
|
|
1408
|
+
"modelMaxTotalOutputTokens",
|
|
1409
|
+
"modelMetadata",
|
|
1410
|
+
"harness",
|
|
1411
|
+
"seats",
|
|
1412
|
+
"permissions",
|
|
1413
|
+
"tools",
|
|
1414
|
+
"mcp",
|
|
1415
|
+
"connections",
|
|
1416
|
+
"subagents",
|
|
1417
|
+
"files",
|
|
1418
|
+
"resourceTools",
|
|
1419
|
+
"skills",
|
|
1420
|
+
"resourceAgents",
|
|
1421
|
+
"commands",
|
|
1422
|
+
"resourceInstructions",
|
|
1423
|
+
"resourceFailOnError",
|
|
1424
|
+
"hooks",
|
|
1425
|
+
"modes",
|
|
1426
|
+
"confidential",
|
|
1427
|
+
"metadata",
|
|
1428
|
+
"extensions"
|
|
1429
|
+
];
|
|
1430
|
+
[...Object.entries({
|
|
1431
|
+
default: "modelDefault",
|
|
1432
|
+
small: "modelSmall",
|
|
1433
|
+
provider: "modelProvider",
|
|
1434
|
+
reasoningEffort: "modelReasoningEffort",
|
|
1435
|
+
maxVisibleOutputTokens: "modelMaxVisibleOutputTokens",
|
|
1436
|
+
maxReasoningTokens: "modelMaxReasoningTokens",
|
|
1437
|
+
maxTotalOutputTokens: "modelMaxTotalOutputTokens",
|
|
1438
|
+
metadata: "modelMetadata"
|
|
1439
|
+
}).map(([property, axis]) => ({
|
|
1440
|
+
axis,
|
|
1441
|
+
rootPath: `/model/${property}`,
|
|
1442
|
+
value: (profile) => profile.model?.[property]
|
|
1443
|
+
}))];
|
|
1444
|
+
//#endregion
|
|
1445
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/agent-workspace-source-snapshot.js
|
|
1446
|
+
const controlCharacterPattern$1 = /[\u0000-\u001f\u007f]/;
|
|
1447
|
+
/** Shared public identifier used by workspace lifecycle contracts. */
|
|
1448
|
+
const agentWorkspacePublicIdentifierSchema$1 = z.string().min(1).max(500).refine((value) => value.trim().length > 0 && isWellFormedUnicode(value) && !controlCharacterPattern$1.test(value) && !looksLikeCredential(value), "public workspace identity cannot carry credential-like material");
|
|
1449
|
+
const agentWorkspaceSourceSnapshotPolicySchema$1 = z.strictObject({
|
|
1450
|
+
kind: z.literal("provider-declared"),
|
|
1451
|
+
name: agentWorkspacePublicIdentifierSchema$1,
|
|
1452
|
+
version: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
1453
|
+
digest: sha256DigestSchema
|
|
1454
|
+
});
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/agent-execution-preparation-receipt.js
|
|
1457
|
+
const nonBlankStringSchema$1 = z.string().refine((value) => value.trim().length > 0, "value cannot be blank");
|
|
1458
|
+
const publicMechanismIdentifierSchema$1 = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$/, "mechanism must be a public identifier, not launch arguments").refine((value) => !looksLikeCredential(value), "mechanism cannot carry credential-like material");
|
|
1459
|
+
const publicLifecycleIdentifierSchema$1 = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._~:/+-]{0,499}$/, "lifecycle identity must be a public identifier").refine((value) => !looksLikeCredential(value), "lifecycle identity cannot carry credential-like material");
|
|
1460
|
+
const publicReasonSchema$1 = nonBlankStringSchema$1.max(4e3).refine((value) => !looksLikeCredential(value), "reason cannot carry credential-like material");
|
|
1461
|
+
const jsonPointerSchema$1 = z.string().refine(isCanonicalJsonPointer$1, "path must be a canonical RFC 6901 JSON Pointer");
|
|
1462
|
+
const agentExecutionPreparationAxisResultSchema$1 = z.strictObject({
|
|
1463
|
+
axis: z.enum(AGENT_PROFILE_MATERIALIZATION_AXES$1),
|
|
1464
|
+
disposition: z.enum([
|
|
1465
|
+
"behavior",
|
|
1466
|
+
"control",
|
|
1467
|
+
"overridden",
|
|
1468
|
+
"unsupported"
|
|
1469
|
+
]),
|
|
1470
|
+
owner: z.enum(["runtime", "executor"]),
|
|
1471
|
+
mechanism: publicMechanismIdentifierSchema$1,
|
|
1472
|
+
evidenceDigest: sha256DigestSchema.optional(),
|
|
1473
|
+
path: jsonPointerSchema$1.optional(),
|
|
1474
|
+
reason: publicReasonSchema$1.optional()
|
|
1475
|
+
}).superRefine((result, context) => {
|
|
1476
|
+
const requiresReason = result.disposition === "overridden" || result.disposition === "unsupported";
|
|
1477
|
+
if (requiresReason && result.reason === void 0) context.addIssue({
|
|
1478
|
+
code: "custom",
|
|
1479
|
+
path: ["reason"],
|
|
1480
|
+
message: `${result.disposition} profile coverage requires a reason`
|
|
1481
|
+
});
|
|
1482
|
+
if (!requiresReason && result.reason !== void 0) context.addIssue({
|
|
1483
|
+
code: "custom",
|
|
1484
|
+
path: ["reason"],
|
|
1485
|
+
message: `${result.disposition} profile coverage cannot carry an override reason`
|
|
1486
|
+
});
|
|
1487
|
+
});
|
|
1488
|
+
const reasoningEffortSchema$1 = z.enum(REASONING_EFFORTS);
|
|
1489
|
+
const agentExecutionPreparationReasoningEffortSchema$1 = z.strictObject({
|
|
1490
|
+
requested: reasoningEffortSchema$1,
|
|
1491
|
+
resolved: reasoningEffortSchema$1.optional(),
|
|
1492
|
+
fidelity: z.enum([
|
|
1493
|
+
"exact",
|
|
1494
|
+
"clamped",
|
|
1495
|
+
"unsupported"
|
|
1496
|
+
])
|
|
1497
|
+
}).superRefine((effort, context) => {
|
|
1498
|
+
if (effort.fidelity === "unsupported") {
|
|
1499
|
+
if (effort.resolved !== void 0) context.addIssue({
|
|
1500
|
+
code: "custom",
|
|
1501
|
+
path: ["resolved"],
|
|
1502
|
+
message: "unsupported reasoning effort cannot claim a resolved value"
|
|
1503
|
+
});
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (effort.resolved === void 0) {
|
|
1507
|
+
context.addIssue({
|
|
1508
|
+
code: "custom",
|
|
1509
|
+
path: ["resolved"],
|
|
1510
|
+
message: `${effort.fidelity} reasoning fidelity requires a resolved value`
|
|
1511
|
+
});
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
if (effort.fidelity === "exact" && effort.resolved !== effort.requested) context.addIssue({
|
|
1515
|
+
code: "custom",
|
|
1516
|
+
path: ["resolved"],
|
|
1517
|
+
message: "exact reasoning fidelity must preserve the requested effort"
|
|
1518
|
+
});
|
|
1519
|
+
if (effort.fidelity === "clamped") {
|
|
1520
|
+
if (effort.resolved === effort.requested) context.addIssue({
|
|
1521
|
+
code: "custom",
|
|
1522
|
+
path: ["resolved"],
|
|
1523
|
+
message: "clamped reasoning fidelity must change the requested effort"
|
|
1524
|
+
});
|
|
1525
|
+
else if (!isDownwardReasoningClamp$1(effort.requested, effort.resolved)) context.addIssue({
|
|
1526
|
+
code: "custom",
|
|
1527
|
+
path: ["resolved"],
|
|
1528
|
+
message: "reasoning effort may clamp down but must never increase"
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
const agentExecutionPreparationReceiptSchema$1 = z.strictObject({
|
|
1533
|
+
kind: z.literal("agent-execution-preparation"),
|
|
1534
|
+
schemaVersion: z.literal(1),
|
|
1535
|
+
preparationId: nonBlankStringSchema$1.max(500),
|
|
1536
|
+
requestDigest: sha256DigestSchema,
|
|
1537
|
+
authoredProfileDigest: sha256DigestSchema,
|
|
1538
|
+
effectiveProfileDigest: sha256DigestSchema,
|
|
1539
|
+
backend: nonBlankStringSchema$1.max(200),
|
|
1540
|
+
harness: harnessTypeSchema,
|
|
1541
|
+
harnessVersion: nonBlankStringSchema$1.max(200),
|
|
1542
|
+
resolvedModel: z.strictObject({
|
|
1543
|
+
requested: z.string().max(500),
|
|
1544
|
+
resolved: nonBlankStringSchema$1.max(500),
|
|
1545
|
+
provider: z.string().max(200).optional(),
|
|
1546
|
+
reasoningEffort: agentExecutionPreparationReasoningEffortSchema$1.optional()
|
|
1547
|
+
}),
|
|
1548
|
+
workspace: z.strictObject({
|
|
1549
|
+
leaseId: publicLifecycleIdentifierSchema$1,
|
|
1550
|
+
provider: publicLifecycleIdentifierSchema$1,
|
|
1551
|
+
identityDigest: sha256DigestSchema,
|
|
1552
|
+
isolation: z.enum(["per-run", "shared"]),
|
|
1553
|
+
sourceSnapshotDigest: sha256DigestSchema,
|
|
1554
|
+
sourceSnapshotPolicy: agentWorkspaceSourceSnapshotPolicySchema$1,
|
|
1555
|
+
preparedWorkspaceDigest: sha256DigestSchema,
|
|
1556
|
+
profileActivationDigest: sha256DigestSchema
|
|
1557
|
+
}),
|
|
1558
|
+
axisResults: z.array(agentExecutionPreparationAxisResultSchema$1),
|
|
1559
|
+
executionPlanDigest: sha256DigestSchema,
|
|
1560
|
+
materializer: z.strictObject({
|
|
1561
|
+
name: nonBlankStringSchema$1.max(200),
|
|
1562
|
+
version: nonBlankStringSchema$1.max(200)
|
|
1563
|
+
}),
|
|
1564
|
+
expiresAtMs: z.number().int().positive().safe(),
|
|
1565
|
+
digest: sha256DigestSchema
|
|
1566
|
+
}).superRefine((receipt, context) => {
|
|
1567
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1568
|
+
for (const [index, result] of receipt.axisResults.entries()) {
|
|
1569
|
+
const key = agentExecutionPreparationAxisResultKey$1(result.axis, result.path);
|
|
1570
|
+
const previous = seen.get(key);
|
|
1571
|
+
if (previous !== void 0) context.addIssue({
|
|
1572
|
+
code: "custom",
|
|
1573
|
+
path: ["axisResults", index],
|
|
1574
|
+
message: agentExecutionPreparationAxisResultsEqual$1(previous, result) ? "duplicate profile axis/path result" : "conflicting profile axis/path results"
|
|
1575
|
+
});
|
|
1576
|
+
else seen.set(key, result);
|
|
1577
|
+
if (index > 0 && compareAgentExecutionPreparationAxisResults$1(receipt.axisResults[index - 1], result) >= 0) context.addIssue({
|
|
1578
|
+
code: "custom",
|
|
1579
|
+
path: ["axisResults", index],
|
|
1580
|
+
message: "profile axis/path results must be canonically sorted"
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
if (!isCanonicalJsonValue(receipt)) context.addIssue({
|
|
1584
|
+
code: "custom",
|
|
1585
|
+
message: "execution preparation receipt must contain only RFC 8785 JSON values"
|
|
1586
|
+
});
|
|
1587
|
+
else if (canonicalCandidateDigest(omitTopLevelDigest(receipt)) !== receipt.digest) context.addIssue({
|
|
1588
|
+
code: "custom",
|
|
1589
|
+
path: ["digest"],
|
|
1590
|
+
message: "execution preparation receipt digest is invalid"
|
|
1591
|
+
});
|
|
1592
|
+
});
|
|
1593
|
+
/** @internal Canonical identity for one preparation axis and path. */
|
|
1594
|
+
function agentExecutionPreparationAxisResultKey$1(axis, path) {
|
|
1595
|
+
return `${axis}\u0000${path ?? ""}`;
|
|
1596
|
+
}
|
|
1597
|
+
/** @internal Exact public equality for preparation axis rows. */
|
|
1598
|
+
function agentExecutionPreparationAxisResultsEqual$1(left, right) {
|
|
1599
|
+
try {
|
|
1600
|
+
return canonicalCandidateJson(left) === canonicalCandidateJson(right);
|
|
1601
|
+
} catch {
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
const AXIS_ORDER$1 = new Map(AGENT_PROFILE_MATERIALIZATION_AXES$1.map((axis, index) => [axis, index]));
|
|
1606
|
+
/** @internal Canonical order for preparation axis rows. */
|
|
1607
|
+
function compareAgentExecutionPreparationAxisResults$1(left, right) {
|
|
1608
|
+
const axisDifference = (AXIS_ORDER$1.get(left.axis) ?? Number.MAX_SAFE_INTEGER) - (AXIS_ORDER$1.get(right.axis) ?? Number.MAX_SAFE_INTEGER);
|
|
1609
|
+
if (axisDifference !== 0) return axisDifference;
|
|
1610
|
+
const leftPath = left.path ?? "";
|
|
1611
|
+
const rightPath = right.path ?? "";
|
|
1612
|
+
return leftPath < rightPath ? -1 : leftPath > rightPath ? 1 : 0;
|
|
1613
|
+
}
|
|
1614
|
+
function isCanonicalJsonPointer$1(value) {
|
|
1615
|
+
if (!value.startsWith("/") || !isWellFormedUnicode(value)) return false;
|
|
1616
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1617
|
+
if (value[index] !== "~") continue;
|
|
1618
|
+
const escape = value[index + 1];
|
|
1619
|
+
if (escape !== "0" && escape !== "1") return false;
|
|
1620
|
+
index += 1;
|
|
1621
|
+
}
|
|
1622
|
+
return true;
|
|
1623
|
+
}
|
|
1624
|
+
function isDownwardReasoningClamp$1(requested, resolved) {
|
|
1625
|
+
return REASONING_EFFORTS.indexOf(resolved) < REASONING_EFFORTS.indexOf(requested);
|
|
1626
|
+
}
|
|
1627
|
+
const agentInteractiveDimensionSchema$1 = z.number().int().positive().max(1e4);
|
|
1628
|
+
//#endregion
|
|
1629
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@4.0.0/node_modules/@tangle-network/agent-interface/dist/environment-interactive-control.js
|
|
1630
|
+
/**
|
|
1631
|
+
* Durable identity of one coding-agent TUI.
|
|
1632
|
+
*
|
|
1633
|
+
* This reference identifies the exact admitted run and preparation receipt.
|
|
1634
|
+
* It is not a generic shell id and cannot be used to create another process.
|
|
1635
|
+
*/
|
|
1636
|
+
const AgentInteractiveSessionRefSchema$1 = z.strictObject({
|
|
1637
|
+
run: AgentExactRunControlRefSchema$1,
|
|
1638
|
+
/** Canonical executor receipt containing the effective route and its proof. */
|
|
1639
|
+
preparationReceipt: agentExecutionPreparationReceiptSchema$1,
|
|
1640
|
+
/** Provider-issued identity of this exact process incarnation. */
|
|
1641
|
+
incarnationId: boundedIdentifierSchema,
|
|
1642
|
+
startedAt: z.iso.datetime().max(64)
|
|
1643
|
+
});
|
|
1644
|
+
/**
|
|
1645
|
+
* Provider-issued write authority for one exact interactive process.
|
|
1646
|
+
*
|
|
1647
|
+
* Expiry blocks mutations but does not kill the coding process. A coordinator
|
|
1648
|
+
* can issue a new compare-and-swap claim after expiry. The provider's PTY owner
|
|
1649
|
+
* lease remains the separate process-cleanup authority.
|
|
1650
|
+
*/
|
|
1651
|
+
const AgentInteractiveSessionControlClaimSchema$1 = z.strictObject({
|
|
1652
|
+
/** Canonical identity of the process ref this authority can mutate. */
|
|
1653
|
+
refDigest: sha256DigestSchema,
|
|
1654
|
+
/** Provider generation. A recovered coordinator must obtain a greater value. */
|
|
1655
|
+
generation: z.number().int().positive().safe(),
|
|
1656
|
+
/** Provider lease identity for this generation. */
|
|
1657
|
+
leaseId: boundedIdentifierSchema,
|
|
1658
|
+
/** Stable identity of the coordinator holding this lease. */
|
|
1659
|
+
holderId: boundedIdentifierSchema,
|
|
1660
|
+
expiresAt: z.iso.datetime().max(64)
|
|
1661
|
+
});
|
|
1662
|
+
const AgentInteractiveSessionControlClaimRequestMaterialSchema$1 = z.strictObject({
|
|
1663
|
+
operationId: boundedIdentifierSchema,
|
|
1664
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1665
|
+
holderId: boundedIdentifierSchema,
|
|
1666
|
+
expectedGeneration: z.number().int().nonnegative().safe()
|
|
1667
|
+
});
|
|
1668
|
+
function agentInteractiveSessionControlClaimRequestDigest$1(value) {
|
|
1669
|
+
const parsed = AgentInteractiveSessionControlClaimRequestMaterialSchema$1.parse(value);
|
|
1670
|
+
return canonicalCandidateDigest({
|
|
1671
|
+
kind: "agent-interactive-session-control-claim.v1",
|
|
1672
|
+
operationId: parsed.operationId,
|
|
1673
|
+
ref: parsed.ref,
|
|
1674
|
+
holderId: parsed.holderId,
|
|
1675
|
+
expectedGeneration: parsed.expectedGeneration
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
z.strictObject({
|
|
1679
|
+
...AgentInteractiveSessionControlClaimRequestMaterialSchema$1.shape,
|
|
1680
|
+
requestDigest: sha256DigestSchema
|
|
1681
|
+
}).superRefine((request, refinement) => {
|
|
1682
|
+
const { requestDigest: _requestDigest, ...material } = request;
|
|
1683
|
+
if (request.requestDigest !== agentInteractiveSessionControlClaimRequestDigest$1(material)) refinement.addIssue({
|
|
1684
|
+
code: "custom",
|
|
1685
|
+
path: ["requestDigest"],
|
|
1686
|
+
message: "interactive session control claim request digest does not match its content"
|
|
1687
|
+
});
|
|
1688
|
+
});
|
|
1689
|
+
const AgentInteractiveSessionControlClaimAcknowledgementSchema$1 = z.strictObject({
|
|
1690
|
+
operationId: boundedIdentifierSchema,
|
|
1691
|
+
requestDigest: sha256DigestSchema,
|
|
1692
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1693
|
+
status: z.enum([
|
|
1694
|
+
"accepted",
|
|
1695
|
+
"replayed",
|
|
1696
|
+
"conflict",
|
|
1697
|
+
"unknown"
|
|
1698
|
+
]),
|
|
1699
|
+
control: AgentInteractiveSessionControlClaimSchema$1.optional(),
|
|
1700
|
+
conflictReason: z.enum(["generation_mismatch", "operation_reuse"]).optional(),
|
|
1701
|
+
currentGeneration: z.number().int().nonnegative().safe().optional(),
|
|
1702
|
+
existingRequestDigest: sha256DigestSchema.optional(),
|
|
1703
|
+
message: boundedStringSchema.min(1).optional(),
|
|
1704
|
+
retryable: z.boolean().optional()
|
|
1705
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
1706
|
+
const hasControl = acknowledgement.control !== void 0;
|
|
1707
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !hasControl) refinement.addIssue({
|
|
1708
|
+
code: "custom",
|
|
1709
|
+
path: ["control"],
|
|
1710
|
+
message: "an accepted control claim must return its provider claim"
|
|
1711
|
+
});
|
|
1712
|
+
if (acknowledgement.status !== "accepted" && acknowledgement.status !== "replayed" && hasControl) refinement.addIssue({
|
|
1713
|
+
code: "custom",
|
|
1714
|
+
path: ["control"],
|
|
1715
|
+
message: "only an accepted or replayed claim may return control"
|
|
1716
|
+
});
|
|
1717
|
+
if (acknowledgement.status === "conflict" && acknowledgement.conflictReason === void 0) refinement.addIssue({
|
|
1718
|
+
code: "custom",
|
|
1719
|
+
path: ["conflictReason"],
|
|
1720
|
+
message: "a control claim conflict must distinguish generation mismatch from operation reuse"
|
|
1721
|
+
});
|
|
1722
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.conflictReason !== void 0) refinement.addIssue({
|
|
1723
|
+
code: "custom",
|
|
1724
|
+
path: ["conflictReason"],
|
|
1725
|
+
message: "only a control claim conflict may report a conflict reason"
|
|
1726
|
+
});
|
|
1727
|
+
if (hasControl && !agentInteractiveSessionControlClaimMatchesRef$1(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
1728
|
+
code: "custom",
|
|
1729
|
+
path: ["control", "refDigest"],
|
|
1730
|
+
message: "interactive control claim acknowledgement does not match its process ref"
|
|
1731
|
+
});
|
|
1732
|
+
if (acknowledgement.status === "conflict" && acknowledgement.currentGeneration === void 0) refinement.addIssue({
|
|
1733
|
+
code: "custom",
|
|
1734
|
+
path: ["currentGeneration"],
|
|
1735
|
+
message: "a control claim conflict must report the current generation"
|
|
1736
|
+
});
|
|
1737
|
+
if (acknowledgement.conflictReason === "generation_mismatch" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
1738
|
+
code: "custom",
|
|
1739
|
+
path: ["existingRequestDigest"],
|
|
1740
|
+
message: "a generation mismatch must not be reported as operation reuse"
|
|
1741
|
+
});
|
|
1742
|
+
if (acknowledgement.conflictReason === "operation_reuse" && acknowledgement.existingRequestDigest === void 0) refinement.addIssue({
|
|
1743
|
+
code: "custom",
|
|
1744
|
+
path: ["existingRequestDigest"],
|
|
1745
|
+
message: "operation reuse must report the digest already stored for this operation"
|
|
1746
|
+
});
|
|
1747
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === acknowledgement.requestDigest) refinement.addIssue({
|
|
1748
|
+
code: "custom",
|
|
1749
|
+
path: ["existingRequestDigest"],
|
|
1750
|
+
message: "a control claim conflict must identify different request material"
|
|
1751
|
+
});
|
|
1752
|
+
if (acknowledgement.status !== "conflict" && (acknowledgement.currentGeneration !== void 0 || acknowledgement.existingRequestDigest !== void 0)) refinement.addIssue({
|
|
1753
|
+
code: "custom",
|
|
1754
|
+
path: ["currentGeneration"],
|
|
1755
|
+
message: "only a control claim conflict may report existing generation state"
|
|
1756
|
+
});
|
|
1757
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
1758
|
+
code: "custom",
|
|
1759
|
+
path: ["retryable"],
|
|
1760
|
+
message: "an unknown control claim outcome must explicitly permit safe same-operation retry"
|
|
1761
|
+
});
|
|
1762
|
+
});
|
|
1763
|
+
/** Bind a provider-issued control claim to the exact process it can mutate. */
|
|
1764
|
+
function agentInteractiveSessionControlClaimMatchesRef$1(ref, claim) {
|
|
1765
|
+
const parsedRef = AgentInteractiveSessionRefSchema$1.safeParse(ref);
|
|
1766
|
+
const parsedClaim = AgentInteractiveSessionControlClaimSchema$1.safeParse(claim);
|
|
1767
|
+
return parsedRef.success && parsedClaim.success && parsedClaim.data.refDigest === canonicalCandidateDigest(parsedRef.data);
|
|
1768
|
+
}
|
|
1769
|
+
z.strictObject({
|
|
1770
|
+
/** Required because the returned terminal permits input and resize. */
|
|
1771
|
+
control: AgentInteractiveSessionControlClaimSchema$1,
|
|
1772
|
+
cols: agentInteractiveDimensionSchema$1.optional(),
|
|
1773
|
+
rows: agentInteractiveDimensionSchema$1.optional()
|
|
1774
|
+
});
|
|
1775
|
+
/** Provider-observed lifecycle of one native coding-agent TUI. */
|
|
1776
|
+
const AgentInteractiveSessionStatusSchema$1 = z.discriminatedUnion("state", [
|
|
1777
|
+
z.strictObject({
|
|
1778
|
+
state: z.literal("running"),
|
|
1779
|
+
ref: AgentInteractiveSessionRefSchema$1
|
|
1780
|
+
}),
|
|
1781
|
+
z.strictObject({
|
|
1782
|
+
state: z.literal("exited"),
|
|
1783
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1784
|
+
endedAt: z.iso.datetime().max(64),
|
|
1785
|
+
reason: z.enum([
|
|
1786
|
+
"exited",
|
|
1787
|
+
"stopped",
|
|
1788
|
+
"lost"
|
|
1789
|
+
]),
|
|
1790
|
+
exitCode: z.number().int().optional(),
|
|
1791
|
+
exitSignal: boundedStringSchema.min(1).optional()
|
|
1792
|
+
}),
|
|
1793
|
+
z.strictObject({
|
|
1794
|
+
state: z.literal("unknown"),
|
|
1795
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1796
|
+
message: boundedStringSchema.min(1),
|
|
1797
|
+
retryable: z.boolean()
|
|
1798
|
+
})
|
|
1799
|
+
]);
|
|
1800
|
+
const AgentInteractiveSessionStopCommandMaterialSchema$1 = z.strictObject({
|
|
1801
|
+
operationId: boundedIdentifierSchema,
|
|
1802
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1803
|
+
control: AgentInteractiveSessionControlClaimSchema$1
|
|
1804
|
+
}).superRefine((command, refinement) => {
|
|
1805
|
+
if (!agentInteractiveSessionControlClaimMatchesRef$1(command.ref, command.control)) refinement.addIssue({
|
|
1806
|
+
code: "custom",
|
|
1807
|
+
path: ["control", "refDigest"],
|
|
1808
|
+
message: "interactive stop control claim does not match its process ref"
|
|
1809
|
+
});
|
|
1810
|
+
});
|
|
1811
|
+
function agentInteractiveSessionStopRequestDigest$1(value) {
|
|
1812
|
+
const parsed = AgentInteractiveSessionStopCommandMaterialSchema$1.parse(value);
|
|
1813
|
+
return canonicalCandidateDigest({
|
|
1814
|
+
kind: "agent-interactive-session-stop.v1",
|
|
1815
|
+
operationId: parsed.operationId,
|
|
1816
|
+
ref: parsed.ref,
|
|
1817
|
+
control: parsed.control
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
z.strictObject({
|
|
1821
|
+
...AgentInteractiveSessionStopCommandMaterialSchema$1.shape,
|
|
1822
|
+
requestDigest: sha256DigestSchema
|
|
1823
|
+
}).superRefine((command, refinement) => {
|
|
1824
|
+
const { requestDigest: _requestDigest, ...material } = command;
|
|
1825
|
+
if (command.requestDigest !== agentInteractiveSessionStopRequestDigest$1(material)) refinement.addIssue({
|
|
1826
|
+
code: "custom",
|
|
1827
|
+
path: ["requestDigest"],
|
|
1828
|
+
message: "interactive stop request digest does not match its content"
|
|
1829
|
+
});
|
|
1830
|
+
});
|
|
1831
|
+
const AgentInteractiveSessionStopAcknowledgementSchema$1 = z.strictObject({
|
|
1832
|
+
operationId: boundedIdentifierSchema,
|
|
1833
|
+
requestDigest: sha256DigestSchema,
|
|
1834
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1835
|
+
control: AgentInteractiveSessionControlClaimSchema$1,
|
|
1836
|
+
status: z.enum([
|
|
1837
|
+
"accepted",
|
|
1838
|
+
"replayed",
|
|
1839
|
+
"conflict",
|
|
1840
|
+
"unknown"
|
|
1841
|
+
]),
|
|
1842
|
+
effect: z.enum([
|
|
1843
|
+
"stop_requested",
|
|
1844
|
+
"stopped",
|
|
1845
|
+
"not_live",
|
|
1846
|
+
"unknown"
|
|
1847
|
+
]),
|
|
1848
|
+
message: boundedStringSchema.min(1).optional(),
|
|
1849
|
+
retryable: z.boolean().optional(),
|
|
1850
|
+
existingRequestDigest: sha256DigestSchema.optional()
|
|
1851
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
1852
|
+
if (!agentInteractiveSessionControlClaimMatchesRef$1(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
1853
|
+
code: "custom",
|
|
1854
|
+
path: ["control", "refDigest"],
|
|
1855
|
+
message: "interactive stop acknowledgement control does not match its process ref"
|
|
1856
|
+
});
|
|
1857
|
+
const known = acknowledgement.effect !== "unknown";
|
|
1858
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !known || (acknowledgement.status === "conflict" || acknowledgement.status === "unknown") && known) refinement.addIssue({
|
|
1859
|
+
code: "custom",
|
|
1860
|
+
path: ["effect"],
|
|
1861
|
+
message: "interactive stop status and effect certainty do not agree"
|
|
1862
|
+
});
|
|
1863
|
+
if (acknowledgement.status === "conflict" && (acknowledgement.existingRequestDigest === void 0 || acknowledgement.existingRequestDigest === acknowledgement.requestDigest)) refinement.addIssue({
|
|
1864
|
+
code: "custom",
|
|
1865
|
+
path: ["existingRequestDigest"],
|
|
1866
|
+
message: "an interactive stop conflict must identify a different existing request"
|
|
1867
|
+
});
|
|
1868
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
1869
|
+
code: "custom",
|
|
1870
|
+
path: ["existingRequestDigest"],
|
|
1871
|
+
message: "only an interactive stop conflict may include an existing digest"
|
|
1872
|
+
});
|
|
1873
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
1874
|
+
code: "custom",
|
|
1875
|
+
path: ["retryable"],
|
|
1876
|
+
message: "an unknown interactive stop outcome must explicitly permit safe same-operation retry"
|
|
1877
|
+
});
|
|
1878
|
+
});
|
|
1879
|
+
const AgentInteractiveSessionPromptCommandMaterialSchema$1 = z.strictObject({
|
|
1880
|
+
operationId: boundedIdentifierSchema,
|
|
1881
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1882
|
+
control: AgentInteractiveSessionControlClaimSchema$1,
|
|
1883
|
+
prompt: boundedEventContentStringSchema.refine((value) => value.length >= 1, { message: "interactive prompt must not be empty" })
|
|
1884
|
+
}).superRefine((command, refinement) => {
|
|
1885
|
+
if (!agentInteractiveSessionControlClaimMatchesRef$1(command.ref, command.control)) refinement.addIssue({
|
|
1886
|
+
code: "custom",
|
|
1887
|
+
path: ["control", "refDigest"],
|
|
1888
|
+
message: "interactive prompt control claim does not match its process ref"
|
|
1889
|
+
});
|
|
1890
|
+
});
|
|
1891
|
+
function agentInteractiveSessionPromptRequestDigest$1(value) {
|
|
1892
|
+
const parsed = AgentInteractiveSessionPromptCommandMaterialSchema$1.parse(value);
|
|
1893
|
+
return canonicalCandidateDigest({
|
|
1894
|
+
kind: "agent-interactive-session-prompt.v1",
|
|
1895
|
+
operationId: parsed.operationId,
|
|
1896
|
+
ref: parsed.ref,
|
|
1897
|
+
control: parsed.control,
|
|
1898
|
+
prompt: parsed.prompt
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
z.strictObject({
|
|
1902
|
+
...AgentInteractiveSessionPromptCommandMaterialSchema$1.shape,
|
|
1903
|
+
requestDigest: sha256DigestSchema
|
|
1904
|
+
}).superRefine((command, refinement) => {
|
|
1905
|
+
const { requestDigest: _requestDigest, ...material } = command;
|
|
1906
|
+
if (command.requestDigest !== agentInteractiveSessionPromptRequestDigest$1(material)) refinement.addIssue({
|
|
1907
|
+
code: "custom",
|
|
1908
|
+
path: ["requestDigest"],
|
|
1909
|
+
message: "interactive session prompt request digest does not match its content"
|
|
1910
|
+
});
|
|
1911
|
+
});
|
|
1912
|
+
const AgentInteractiveSessionPromptAcknowledgementSchema$1 = z.strictObject({
|
|
1913
|
+
operationId: boundedIdentifierSchema,
|
|
1914
|
+
requestDigest: sha256DigestSchema,
|
|
1915
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
1916
|
+
control: AgentInteractiveSessionControlClaimSchema$1,
|
|
1917
|
+
status: z.enum([
|
|
1918
|
+
"accepted",
|
|
1919
|
+
"replayed",
|
|
1920
|
+
"conflict",
|
|
1921
|
+
"unknown"
|
|
1922
|
+
]),
|
|
1923
|
+
message: boundedStringSchema.min(1).optional(),
|
|
1924
|
+
retryable: z.boolean().optional(),
|
|
1925
|
+
existingRequestDigest: sha256DigestSchema.optional()
|
|
1926
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
1927
|
+
if (!agentInteractiveSessionControlClaimMatchesRef$1(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
1928
|
+
code: "custom",
|
|
1929
|
+
path: ["control", "refDigest"],
|
|
1930
|
+
message: "interactive prompt acknowledgement control claim does not match its process ref"
|
|
1931
|
+
});
|
|
1932
|
+
if (acknowledgement.status === "conflict" && (acknowledgement.existingRequestDigest === void 0 || acknowledgement.existingRequestDigest === acknowledgement.requestDigest)) refinement.addIssue({
|
|
1933
|
+
code: "custom",
|
|
1934
|
+
path: ["existingRequestDigest"],
|
|
1935
|
+
message: "an interactive prompt conflict must identify a different existing request"
|
|
1936
|
+
});
|
|
1937
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
1938
|
+
code: "custom",
|
|
1939
|
+
path: ["existingRequestDigest"],
|
|
1940
|
+
message: "only an interactive prompt conflict may include an existing digest"
|
|
1941
|
+
});
|
|
1942
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
1943
|
+
code: "custom",
|
|
1944
|
+
path: ["retryable"],
|
|
1945
|
+
message: "an unknown interactive prompt outcome must explicitly permit safe same-operation retry"
|
|
1946
|
+
});
|
|
1947
|
+
});
|
|
1948
|
+
//#endregion
|
|
1949
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/native-session-event.js
|
|
1950
|
+
/**
|
|
1951
|
+
* Private adapter observation of a provider conversation or resume identity.
|
|
1952
|
+
* The adapter must obtain this ID from its bound provider process or API.
|
|
1953
|
+
* Caller keys, execution IDs, storage paths, and public session updates are not evidence.
|
|
1954
|
+
* The execution owner binds this observation to its own execution and session.
|
|
1955
|
+
* Public SSE and user-visible event streams must exclude this control event.
|
|
1956
|
+
* An observation establishes identity only, not native artifact completeness.
|
|
1957
|
+
*/
|
|
1958
|
+
const NativeSessionObservedEventSchema = z.object({
|
|
1959
|
+
type: z.literal("native.session.observed"),
|
|
1960
|
+
provider: z.string().regex(/^[a-z][a-z0-9-]{0,127}$/),
|
|
1961
|
+
nativeSessionId: z.string().min(1).max(512).regex(/^\S+$/u)
|
|
1962
|
+
}).strict();
|
|
1963
|
+
//#endregion
|
|
1964
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/environment-observation.js
|
|
1965
|
+
const ObservationProvenanceSchema = z.strictObject({
|
|
1966
|
+
origin: z.enum([
|
|
1967
|
+
"measured",
|
|
1968
|
+
"reported",
|
|
1969
|
+
"estimated"
|
|
1970
|
+
]),
|
|
1971
|
+
observedAt: z.iso.datetime().max(64),
|
|
1972
|
+
source: boundedIdentifierSchema$1.optional()
|
|
1973
|
+
});
|
|
1974
|
+
/** Build a freshness-tagged observation schema around one value schema. */
|
|
1975
|
+
function observationOf(value) {
|
|
1976
|
+
return z.discriminatedUnion("state", [
|
|
1977
|
+
z.strictObject({
|
|
1978
|
+
state: z.literal("known"),
|
|
1979
|
+
value,
|
|
1980
|
+
provenance: ObservationProvenanceSchema
|
|
1981
|
+
}),
|
|
1982
|
+
z.strictObject({
|
|
1983
|
+
state: z.literal("stale"),
|
|
1984
|
+
value,
|
|
1985
|
+
provenance: ObservationProvenanceSchema,
|
|
1986
|
+
reason: boundedStringSchema$1.min(1)
|
|
1987
|
+
}),
|
|
1988
|
+
z.strictObject({
|
|
1989
|
+
state: z.literal("unavailable"),
|
|
1990
|
+
reason: boundedStringSchema$1.min(1)
|
|
1991
|
+
}),
|
|
1992
|
+
z.strictObject({
|
|
1993
|
+
state: z.literal("redacted"),
|
|
1994
|
+
reason: boundedStringSchema$1.min(1)
|
|
1995
|
+
}),
|
|
1996
|
+
z.strictObject({ state: z.literal("unknown") })
|
|
1997
|
+
]);
|
|
1998
|
+
}
|
|
1999
|
+
const nonNegativeNumberSchema = z.number().finite().nonnegative();
|
|
2000
|
+
const ProviderIdentitySchema = z.strictObject({
|
|
2001
|
+
provider: boundedIdentifierSchema$1,
|
|
2002
|
+
environmentId: boundedIdentifierSchema$1,
|
|
2003
|
+
sessionId: boundedIdentifierSchema$1.optional(),
|
|
2004
|
+
backend: boundedIdentifierSchema$1.optional()
|
|
2005
|
+
});
|
|
2006
|
+
const AgentEnvironmentStatusSchema = z.enum([
|
|
2007
|
+
"pending",
|
|
2008
|
+
"provisioning",
|
|
2009
|
+
"running",
|
|
2010
|
+
"stopped",
|
|
2011
|
+
"failed",
|
|
2012
|
+
"expired",
|
|
2013
|
+
"unknown"
|
|
2014
|
+
]);
|
|
2015
|
+
/** Lifecycle, cleanup, continuity, and persistence of one environment. */
|
|
2016
|
+
const EnvironmentLifecycleSchema = z.strictObject({
|
|
2017
|
+
status: AgentEnvironmentStatusSchema,
|
|
2018
|
+
cleanup: z.strictObject({
|
|
2019
|
+
policy: z.enum([
|
|
2020
|
+
"manual",
|
|
2021
|
+
"idle",
|
|
2022
|
+
"scheduled",
|
|
2023
|
+
"on-exit"
|
|
2024
|
+
]).optional(),
|
|
2025
|
+
scheduledAt: z.iso.datetime().max(64).optional(),
|
|
2026
|
+
confirmed: z.boolean().optional()
|
|
2027
|
+
}).optional(),
|
|
2028
|
+
continuity: z.strictObject({
|
|
2029
|
+
resumable: z.boolean(),
|
|
2030
|
+
mode: z.enum([
|
|
2031
|
+
"native",
|
|
2032
|
+
"replayed",
|
|
2033
|
+
"none"
|
|
2034
|
+
]).optional()
|
|
2035
|
+
}).optional(),
|
|
2036
|
+
persistence: z.strictObject({
|
|
2037
|
+
durable: z.boolean(),
|
|
2038
|
+
scope: z.enum([
|
|
2039
|
+
"ephemeral",
|
|
2040
|
+
"session",
|
|
2041
|
+
"durable"
|
|
2042
|
+
]).optional()
|
|
2043
|
+
}).optional()
|
|
2044
|
+
});
|
|
2045
|
+
/**
|
|
2046
|
+
* Credential-free network location. There is no field for a user, password,
|
|
2047
|
+
* token, or other secret, and the host and scheme reject embedded credentials.
|
|
2048
|
+
*/
|
|
2049
|
+
const SafeEndpointSchema = z.strictObject({
|
|
2050
|
+
scheme: boundedIdentifierSchema$1.optional(),
|
|
2051
|
+
host: boundedIdentifierSchema$1,
|
|
2052
|
+
port: z.number().int().min(1).max(65535).optional(),
|
|
2053
|
+
region: boundedIdentifierSchema$1.optional()
|
|
2054
|
+
}).superRefine((endpoint, refinement) => {
|
|
2055
|
+
if (/[@/\s]|:\/\//.test(endpoint.host)) refinement.addIssue({
|
|
2056
|
+
code: "custom",
|
|
2057
|
+
path: ["host"],
|
|
2058
|
+
message: "endpoint host must not carry credentials, a scheme, or a path"
|
|
2059
|
+
});
|
|
2060
|
+
if (endpoint.scheme !== void 0 && /[@:/\s]/.test(endpoint.scheme)) refinement.addIssue({
|
|
2061
|
+
code: "custom",
|
|
2062
|
+
path: ["scheme"],
|
|
2063
|
+
message: "endpoint scheme must be a bare protocol name"
|
|
2064
|
+
});
|
|
2065
|
+
});
|
|
2066
|
+
/** Requested or effective compute shape, including an optional accelerator. */
|
|
2067
|
+
const ResourceProfileSchema = z.strictObject({
|
|
2068
|
+
cpu: z.number().finite().positive().optional(),
|
|
2069
|
+
memoryMb: z.number().int().positive().optional(),
|
|
2070
|
+
diskMb: z.number().int().positive().optional(),
|
|
2071
|
+
accelerator: z.strictObject({
|
|
2072
|
+
kind: boundedIdentifierSchema$1,
|
|
2073
|
+
count: z.number().int().positive(),
|
|
2074
|
+
memoryMb: z.number().int().positive().optional()
|
|
2075
|
+
}).optional()
|
|
2076
|
+
});
|
|
2077
|
+
/** A point-in-time or peak resource sample. */
|
|
2078
|
+
const ResourceUseSampleSchema = z.strictObject({
|
|
2079
|
+
cpu: nonNegativeNumberSchema.optional(),
|
|
2080
|
+
memoryMb: nonNegativeNumberSchema.optional(),
|
|
2081
|
+
diskMb: nonNegativeNumberSchema.optional(),
|
|
2082
|
+
acceleratorMemoryMb: nonNegativeNumberSchema.optional()
|
|
2083
|
+
});
|
|
2084
|
+
/** Where an environment was requested or verified to run. */
|
|
2085
|
+
const PlacementDescriptorSchema = z.strictObject({
|
|
2086
|
+
kind: z.enum([
|
|
2087
|
+
"local",
|
|
2088
|
+
"sandbox",
|
|
2089
|
+
"fleet",
|
|
2090
|
+
"provider"
|
|
2091
|
+
]),
|
|
2092
|
+
sandboxId: boundedIdentifierSchema$1.optional(),
|
|
2093
|
+
fleetId: boundedIdentifierSchema$1.optional(),
|
|
2094
|
+
machineId: boundedIdentifierSchema$1.optional(),
|
|
2095
|
+
region: boundedIdentifierSchema$1.optional()
|
|
2096
|
+
});
|
|
2097
|
+
/**
|
|
2098
|
+
* Token usage and cost for one execution. Bound to the shared {@link TokenUsage}
|
|
2099
|
+
* type so a change to the canonical shape is caught here.
|
|
2100
|
+
*/
|
|
2101
|
+
const ModelUsageSchema = z.strictObject({
|
|
2102
|
+
inputTokens: z.number().int().nonnegative(),
|
|
2103
|
+
outputTokens: z.number().int().nonnegative(),
|
|
2104
|
+
totalTokens: z.number().int().nonnegative().optional(),
|
|
2105
|
+
cacheReadInputTokens: z.number().int().nonnegative().optional(),
|
|
2106
|
+
cacheCreationInputTokens: z.number().int().nonnegative().optional(),
|
|
2107
|
+
reasoningTokens: z.number().int().nonnegative().optional(),
|
|
2108
|
+
cost: z.number().finite().nonnegative().optional()
|
|
2109
|
+
});
|
|
2110
|
+
/** Provider compute cost charged for one environment. */
|
|
2111
|
+
const ComputeBillingSchema = z.strictObject({
|
|
2112
|
+
amount: nonNegativeNumberSchema,
|
|
2113
|
+
currency: boundedIdentifierSchema$1
|
|
2114
|
+
});
|
|
2115
|
+
/** Account plan, credits, quota, and billing period. */
|
|
2116
|
+
const AccountUsageSchema = z.strictObject({
|
|
2117
|
+
plan: observationOf(boundedIdentifierSchema$1).optional(),
|
|
2118
|
+
credits: observationOf(z.strictObject({
|
|
2119
|
+
remaining: nonNegativeNumberSchema,
|
|
2120
|
+
unit: boundedIdentifierSchema$1
|
|
2121
|
+
})).optional(),
|
|
2122
|
+
quota: observationOf(z.strictObject({
|
|
2123
|
+
limit: nonNegativeNumberSchema,
|
|
2124
|
+
used: nonNegativeNumberSchema,
|
|
2125
|
+
remaining: nonNegativeNumberSchema,
|
|
2126
|
+
unit: boundedIdentifierSchema$1
|
|
2127
|
+
})).optional(),
|
|
2128
|
+
period: observationOf(z.strictObject({
|
|
2129
|
+
start: z.iso.datetime().max(64),
|
|
2130
|
+
end: z.iso.datetime().max(64)
|
|
2131
|
+
})).optional()
|
|
2132
|
+
});
|
|
2133
|
+
z.strictObject({
|
|
2134
|
+
subject: ProviderIdentitySchema,
|
|
2135
|
+
capturedAt: z.iso.datetime().max(64),
|
|
2136
|
+
identity: observationOf(ProviderIdentitySchema).optional(),
|
|
2137
|
+
lifecycle: observationOf(EnvironmentLifecycleSchema).optional(),
|
|
2138
|
+
endpoint: observationOf(SafeEndpointSchema).optional(),
|
|
2139
|
+
placement: z.strictObject({
|
|
2140
|
+
requested: PlacementDescriptorSchema.optional(),
|
|
2141
|
+
verified: observationOf(PlacementDescriptorSchema).optional()
|
|
2142
|
+
}).optional(),
|
|
2143
|
+
resources: z.strictObject({
|
|
2144
|
+
requested: ResourceProfileSchema.optional(),
|
|
2145
|
+
effective: observationOf(ResourceProfileSchema).optional()
|
|
2146
|
+
}).optional(),
|
|
2147
|
+
resourceUse: z.strictObject({
|
|
2148
|
+
current: observationOf(ResourceUseSampleSchema).optional(),
|
|
2149
|
+
peak: observationOf(ResourceUseSampleSchema).optional()
|
|
2150
|
+
}).optional(),
|
|
2151
|
+
modelUsage: observationOf(ModelUsageSchema).optional(),
|
|
2152
|
+
computeBilling: observationOf(ComputeBillingSchema).optional(),
|
|
2153
|
+
accountUsage: AccountUsageSchema.optional()
|
|
2154
|
+
});
|
|
2155
|
+
//#endregion
|
|
2156
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-fields.js
|
|
2157
|
+
/**
|
|
2158
|
+
* Field names whose own-key form collides with object internals. A record
|
|
2159
|
+
* parser drops a raw `__proto__` key through the legacy prototype setter before
|
|
2160
|
+
* a key schema runs, so every schema and validator over interaction data
|
|
2161
|
+
* rejects these names against one owner rather than a private copy.
|
|
2162
|
+
*/
|
|
2163
|
+
const RESERVED_INTERACTION_FIELD_NAMES = new Set([
|
|
2164
|
+
"__proto__",
|
|
2165
|
+
"constructor",
|
|
2166
|
+
"prototype"
|
|
2167
|
+
]);
|
|
2168
|
+
const InteractionFieldNameSchema = boundedIdentifierSchema$1.refine((value) => !RESERVED_INTERACTION_FIELD_NAMES.has(value), "interaction field name is reserved");
|
|
2169
|
+
const FieldBase = {
|
|
2170
|
+
/** Stable key the answer is returned under in `InteractionResponse.data`. */
|
|
2171
|
+
name: InteractionFieldNameSchema,
|
|
2172
|
+
/** Human-readable label for the form control. */
|
|
2173
|
+
label: boundedStringSchema$1.min(1),
|
|
2174
|
+
/** Whether the answer must supply this field to be `accepted`. */
|
|
2175
|
+
required: z.boolean().optional()
|
|
2176
|
+
};
|
|
2177
|
+
const InteractionFieldSchema = z.discriminatedUnion("type", [
|
|
2178
|
+
z.strictObject({
|
|
2179
|
+
...FieldBase,
|
|
2180
|
+
type: z.literal("text"),
|
|
2181
|
+
multiline: z.boolean().optional(),
|
|
2182
|
+
placeholder: boundedStringSchema$1.optional(),
|
|
2183
|
+
/** Maximum answer length chosen by the request author. */
|
|
2184
|
+
maxLength: z.number().int().positive().max(CONTRACT_MAX_STRING_LENGTH$1).optional(),
|
|
2185
|
+
default: boundedStringSchema$1.optional()
|
|
2186
|
+
}),
|
|
2187
|
+
z.strictObject({
|
|
2188
|
+
...FieldBase,
|
|
2189
|
+
type: z.literal("number"),
|
|
2190
|
+
min: z.number().finite().optional(),
|
|
2191
|
+
max: z.number().finite().optional(),
|
|
2192
|
+
default: z.number().finite().optional()
|
|
2193
|
+
}),
|
|
2194
|
+
z.strictObject({
|
|
2195
|
+
...FieldBase,
|
|
2196
|
+
type: z.literal("boolean"),
|
|
2197
|
+
default: z.boolean().optional()
|
|
2198
|
+
}),
|
|
2199
|
+
z.strictObject({
|
|
2200
|
+
...FieldBase,
|
|
2201
|
+
type: z.literal("select"),
|
|
2202
|
+
options: z.array(z.strictObject({
|
|
2203
|
+
value: boundedIdentifierSchema$1,
|
|
2204
|
+
label: boundedStringSchema$1.min(1),
|
|
2205
|
+
description: boundedStringSchema$1.optional()
|
|
2206
|
+
})).min(1).max(CONTRACT_MAX_ARRAY_LENGTH$1),
|
|
2207
|
+
/** When true the user may pick more than one option. */
|
|
2208
|
+
multi: z.boolean().optional(),
|
|
2209
|
+
/**
|
|
2210
|
+
* When true the answer may contain write-in values outside `options`
|
|
2211
|
+
* (e.g. a rendered "Other…" choice carrying the user's own text).
|
|
2212
|
+
* Write-ins must still be non-empty strings.
|
|
2213
|
+
*/
|
|
2214
|
+
allowCustom: z.boolean().optional(),
|
|
2215
|
+
default: z.array(boundedIdentifierSchema$1).max(CONTRACT_MAX_ARRAY_LENGTH$1).optional()
|
|
2216
|
+
}),
|
|
2217
|
+
z.strictObject({
|
|
2218
|
+
...FieldBase,
|
|
2219
|
+
type: z.literal("secret"),
|
|
2220
|
+
placeholder: boundedStringSchema$1.optional(),
|
|
2221
|
+
/** Maximum answer length chosen by the request author. */
|
|
2222
|
+
maxLength: z.number().int().positive().max(CONTRACT_MAX_STRING_LENGTH$1).optional()
|
|
2223
|
+
})
|
|
2224
|
+
]).superRefine((field, context) => {
|
|
2225
|
+
if (field.type === "text" && field.default !== void 0 && field.maxLength !== void 0 && field.default.length > field.maxLength) {
|
|
2226
|
+
context.addIssue({
|
|
2227
|
+
code: "custom",
|
|
2228
|
+
path: ["default"],
|
|
2229
|
+
message: "text field default exceeds maxLength"
|
|
2230
|
+
});
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
if (field.type === "number") {
|
|
2234
|
+
if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) context.addIssue({
|
|
2235
|
+
code: "custom",
|
|
2236
|
+
path: ["max"],
|
|
2237
|
+
message: "number field max must be greater than or equal to min"
|
|
2238
|
+
});
|
|
2239
|
+
if (field.default !== void 0 && field.min !== void 0 && field.default < field.min) context.addIssue({
|
|
2240
|
+
code: "custom",
|
|
2241
|
+
path: ["default"],
|
|
2242
|
+
message: "number field default must be greater than or equal to min"
|
|
2243
|
+
});
|
|
2244
|
+
if (field.default !== void 0 && field.max !== void 0 && field.default > field.max) context.addIssue({
|
|
2245
|
+
code: "custom",
|
|
2246
|
+
path: ["default"],
|
|
2247
|
+
message: "number field default must be less than or equal to max"
|
|
2248
|
+
});
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
if (field.type !== "select") return;
|
|
2252
|
+
const optionValues = field.options.map((option) => option.value);
|
|
2253
|
+
if (new Set(optionValues).size !== optionValues.length) context.addIssue({
|
|
2254
|
+
code: "custom",
|
|
2255
|
+
path: ["options"],
|
|
2256
|
+
message: "select option values must be unique"
|
|
2257
|
+
});
|
|
2258
|
+
if (field.default === void 0) return;
|
|
2259
|
+
if (new Set(field.default).size !== field.default.length) context.addIssue({
|
|
2260
|
+
code: "custom",
|
|
2261
|
+
path: ["default"],
|
|
2262
|
+
message: "select default values must be unique"
|
|
2263
|
+
});
|
|
2264
|
+
if (!field.multi && field.default.length > 1) context.addIssue({
|
|
2265
|
+
code: "custom",
|
|
2266
|
+
path: ["default"],
|
|
2267
|
+
message: "single-select default may contain at most one value"
|
|
2268
|
+
});
|
|
2269
|
+
if (field.required && field.default.length === 0) context.addIssue({
|
|
2270
|
+
code: "custom",
|
|
2271
|
+
path: ["default"],
|
|
2272
|
+
message: "required select default must contain a value"
|
|
2273
|
+
});
|
|
2274
|
+
const allowed = new Set(optionValues);
|
|
2275
|
+
for (const value of field.default) {
|
|
2276
|
+
if (allowed.has(value)) continue;
|
|
2277
|
+
if (field.allowCustom === true && value.trim().length > 0) continue;
|
|
2278
|
+
context.addIssue({
|
|
2279
|
+
code: "custom",
|
|
2280
|
+
path: ["default"],
|
|
2281
|
+
message: `select default contains unknown option "${value}"`
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
const InteractionAnswerSpecSchema = z.strictObject({ fields: z.array(InteractionFieldSchema).max(CONTRACT_MAX_ARRAY_LENGTH$1) }).superRefine((spec, context) => {
|
|
2286
|
+
const names = spec.fields.map((field) => field.name);
|
|
2287
|
+
if (new Set(names).size !== names.length) context.addIssue({
|
|
2288
|
+
code: "custom",
|
|
2289
|
+
path: ["fields"],
|
|
2290
|
+
message: "interaction field names must be unique"
|
|
2291
|
+
});
|
|
2292
|
+
});
|
|
2293
|
+
const InteractionFieldTypeSchema = z.enum([
|
|
2294
|
+
"text",
|
|
2295
|
+
"number",
|
|
2296
|
+
"boolean",
|
|
2297
|
+
"select",
|
|
2298
|
+
"secret"
|
|
2299
|
+
]);
|
|
2300
|
+
/** Scope at which an accepted answer may be reused by an explicit policy. */
|
|
2301
|
+
const InteractionResponseScopeSchema = z.enum([
|
|
2302
|
+
"interaction",
|
|
2303
|
+
"session",
|
|
2304
|
+
"persistent"
|
|
2305
|
+
]);
|
|
2306
|
+
z.strictObject({
|
|
2307
|
+
kinds: z.array(boundedIdentifierSchema$1).min(1).max(CONTRACT_MAX_ARRAY_LENGTH$1),
|
|
2308
|
+
answerFieldTypes: z.array(InteractionFieldTypeSchema).min(1).max(CONTRACT_MAX_ARRAY_LENGTH$1),
|
|
2309
|
+
responseScopes: z.array(InteractionResponseScopeSchema).min(1).max(CONTRACT_MAX_ARRAY_LENGTH$1),
|
|
2310
|
+
secretAnswers: z.boolean(),
|
|
2311
|
+
concurrentRequests: z.boolean(),
|
|
2312
|
+
replay: z.boolean(),
|
|
2313
|
+
responseIdempotency: z.boolean()
|
|
2314
|
+
}).superRefine((capabilities, context) => {
|
|
2315
|
+
if (capabilities.answerFieldTypes.includes("secret") !== capabilities.secretAnswers) context.addIssue({
|
|
2316
|
+
code: "custom",
|
|
2317
|
+
path: ["secretAnswers"],
|
|
2318
|
+
message: "secretAnswers must agree with the secret answer field capability"
|
|
2319
|
+
});
|
|
2320
|
+
if (new Set(capabilities.kinds).size !== capabilities.kinds.length) context.addIssue({
|
|
2321
|
+
code: "custom",
|
|
2322
|
+
path: ["kinds"],
|
|
2323
|
+
message: "interaction kinds must be unique"
|
|
2324
|
+
});
|
|
2325
|
+
if (new Set(capabilities.answerFieldTypes).size !== capabilities.answerFieldTypes.length) context.addIssue({
|
|
2326
|
+
code: "custom",
|
|
2327
|
+
path: ["answerFieldTypes"],
|
|
2328
|
+
message: "interaction answer field types must be unique"
|
|
2329
|
+
});
|
|
2330
|
+
if (new Set(capabilities.responseScopes).size !== capabilities.responseScopes.length) context.addIssue({
|
|
2331
|
+
code: "custom",
|
|
2332
|
+
path: ["responseScopes"],
|
|
2333
|
+
message: "interaction response scopes must be unique"
|
|
2334
|
+
});
|
|
2335
|
+
});
|
|
2336
|
+
//#endregion
|
|
2337
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-data.js
|
|
2338
|
+
const InteractionSecretReferenceSchema = z.strictObject({
|
|
2339
|
+
kind: z.literal("secret_handle"),
|
|
2340
|
+
handleId: boundedIdentifierSchema$1,
|
|
2341
|
+
oneUse: z.literal(true)
|
|
2342
|
+
});
|
|
2343
|
+
const InteractionDataValueSchema = z.union([
|
|
2344
|
+
boundedStringSchema$1,
|
|
2345
|
+
z.number().finite(),
|
|
2346
|
+
z.boolean(),
|
|
2347
|
+
z.array(boundedStringSchema$1).max(CONTRACT_MAX_ARRAY_LENGTH$1),
|
|
2348
|
+
InteractionSecretReferenceSchema
|
|
2349
|
+
]);
|
|
2350
|
+
/** Field values keyed by InteractionField.name. */
|
|
2351
|
+
const InteractionDataSchema = z.unknown().superRefine((value, refinement) => {
|
|
2352
|
+
if (value === null || typeof value !== "object") return;
|
|
2353
|
+
for (const key of Object.getOwnPropertyNames(value)) if (RESERVED_INTERACTION_FIELD_NAMES.has(key)) refinement.addIssue({
|
|
2354
|
+
code: "custom",
|
|
2355
|
+
message: `interaction field name "${key}" is reserved`
|
|
2356
|
+
});
|
|
2357
|
+
}).pipe(z.record(InteractionFieldNameSchema, InteractionDataValueSchema).superRefine((data, refinement) => {
|
|
2358
|
+
if (Object.keys(data).length > 256) refinement.addIssue({
|
|
2359
|
+
code: "custom",
|
|
2360
|
+
message: "interaction data has too many fields"
|
|
2361
|
+
});
|
|
2362
|
+
})).transform((data) => {
|
|
2363
|
+
const safe = Object.create(null);
|
|
2364
|
+
for (const key of Object.keys(data)) safe[key] = data[key];
|
|
2365
|
+
return safe;
|
|
2366
|
+
});
|
|
2367
|
+
const InteractionResolutionSchema = z.discriminatedUnion("outcome", [
|
|
2368
|
+
z.strictObject({
|
|
2369
|
+
outcome: z.literal("accepted"),
|
|
2370
|
+
data: InteractionDataSchema.optional()
|
|
2371
|
+
}),
|
|
2372
|
+
z.strictObject({
|
|
2373
|
+
outcome: z.literal("declined"),
|
|
2374
|
+
data: InteractionDataSchema.optional()
|
|
2375
|
+
}),
|
|
2376
|
+
z.strictObject({
|
|
2377
|
+
outcome: z.literal("cancelled"),
|
|
2378
|
+
data: InteractionDataSchema.optional()
|
|
2379
|
+
})
|
|
2380
|
+
]);
|
|
2381
|
+
//#endregion
|
|
2382
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-permissions.js
|
|
2383
|
+
const InteractionKind = {
|
|
2384
|
+
/** Agent asks the user to answer/choose. Answer = the chosen field values. */
|
|
2385
|
+
Question: "question",
|
|
2386
|
+
/** Agent requests approval to run a tool/command. Answer = a `PermissionGrant`. */
|
|
2387
|
+
Permission: "permission",
|
|
2388
|
+
/** Agent shares a plan/todo list for review/approval. */
|
|
2389
|
+
Plan: "plan"
|
|
2390
|
+
};
|
|
2391
|
+
const wellKnownInteractionKinds = new Set(Object.values(InteractionKind));
|
|
2392
|
+
const requestedInteractionKindSchema = boundedIdentifierSchema$1.refine((value) => wellKnownInteractionKinds.has(value) || value.includes(".") && !value.startsWith(".") && !value.endsWith(".") && !value.includes(".."), "custom interaction kind must be namespaced");
|
|
2393
|
+
z.record(requestedInteractionKindSchema, z.boolean()).superRefine((value, context) => {
|
|
2394
|
+
if (Object.keys(value).length > 256) context.addIssue({
|
|
2395
|
+
code: z.ZodIssueCode.custom,
|
|
2396
|
+
message: `interaction posture exceeds 256 kinds`
|
|
2397
|
+
});
|
|
2398
|
+
});
|
|
2399
|
+
/** Field name carrying the grant on a `permission` interaction's response. */
|
|
2400
|
+
const PERMISSION_GRANT_FIELD = "grant";
|
|
2401
|
+
/** Graduated permission decision — the value of the `grant` field. */
|
|
2402
|
+
const PermissionGrantSchema = z.enum([
|
|
2403
|
+
"allow_once",
|
|
2404
|
+
"allow_session",
|
|
2405
|
+
"allow_always",
|
|
2406
|
+
"deny"
|
|
2407
|
+
]);
|
|
2408
|
+
//#endregion
|
|
2409
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-answer-validation.js
|
|
2410
|
+
/**
|
|
2411
|
+
* Validate an accepted answer against its spec. Used by the broker before a
|
|
2412
|
+
* response reaches the adapter, so malformed answers are rejected centrally.
|
|
2413
|
+
*/
|
|
2414
|
+
function validateInteractionAnswer(spec, data) {
|
|
2415
|
+
const errors = [];
|
|
2416
|
+
const parsedSpec = InteractionAnswerSpecSchema.safeParse(spec);
|
|
2417
|
+
if (!parsedSpec.success) return {
|
|
2418
|
+
ok: false,
|
|
2419
|
+
errors: parsedSpec.error.issues.map((issue) => issue.message)
|
|
2420
|
+
};
|
|
2421
|
+
if (data !== void 0 && (!data || typeof data !== "object" || Array.isArray(data))) return {
|
|
2422
|
+
ok: false,
|
|
2423
|
+
errors: ["interaction data must be an object"]
|
|
2424
|
+
};
|
|
2425
|
+
const d = data ?? Object.create(null);
|
|
2426
|
+
const prototype = Object.getPrototypeOf(d);
|
|
2427
|
+
if (prototype !== Object.prototype && prototype !== null) return {
|
|
2428
|
+
ok: false,
|
|
2429
|
+
errors: ["interaction data must be a plain object"]
|
|
2430
|
+
};
|
|
2431
|
+
if (Object.keys(d).length > 256) return {
|
|
2432
|
+
ok: false,
|
|
2433
|
+
errors: ["interaction data has too many fields"]
|
|
2434
|
+
};
|
|
2435
|
+
const exactSpec = parsedSpec.data;
|
|
2436
|
+
const knownFields = new Set(exactSpec.fields.map((field) => field.name));
|
|
2437
|
+
for (const fieldName of Object.keys(d)) {
|
|
2438
|
+
if (fieldName.length > 512) {
|
|
2439
|
+
errors.push(`unknown field "${fieldName}"`);
|
|
2440
|
+
continue;
|
|
2441
|
+
}
|
|
2442
|
+
const rawValue = d[fieldName];
|
|
2443
|
+
if (typeof rawValue === "string" && rawValue.length > 16384) errors.push(`field "${fieldName}" exceeds the contract string bound`);
|
|
2444
|
+
else if (Array.isArray(rawValue)) {
|
|
2445
|
+
if (rawValue.length > 1024) errors.push(`field "${fieldName}" has too many values`);
|
|
2446
|
+
for (const entry of rawValue) if (typeof entry !== "string" || entry.length > 16384) {
|
|
2447
|
+
errors.push(`field "${fieldName}" contains an invalid bounded value`);
|
|
2448
|
+
break;
|
|
2449
|
+
}
|
|
2450
|
+
} else if (rawValue && typeof rawValue === "object") {
|
|
2451
|
+
const valuePrototype = Object.getPrototypeOf(rawValue);
|
|
2452
|
+
if (valuePrototype !== Object.prototype && valuePrototype !== null || Object.keys(rawValue).length > 3) errors.push(`field "${fieldName}" contains an invalid object value`);
|
|
2453
|
+
}
|
|
2454
|
+
if (!knownFields.has(fieldName)) errors.push(`unknown field "${fieldName}"`);
|
|
2455
|
+
}
|
|
2456
|
+
for (const field of exactSpec.fields) {
|
|
2457
|
+
const hasValue = Object.hasOwn(d, field.name);
|
|
2458
|
+
const v = hasValue ? d[field.name] : void 0;
|
|
2459
|
+
if (!(hasValue && v !== void 0 && v !== null && !(typeof v === "string" && v === ""))) {
|
|
2460
|
+
if (field.required) errors.push(`missing required field "${field.name}"`);
|
|
2461
|
+
continue;
|
|
2462
|
+
}
|
|
2463
|
+
switch (field.type) {
|
|
2464
|
+
case "text":
|
|
2465
|
+
if (typeof v !== "string") errors.push(`field "${field.name}" must be a string`);
|
|
2466
|
+
else if (field.maxLength !== void 0 && v.length > field.maxLength) errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
2467
|
+
break;
|
|
2468
|
+
case "secret": {
|
|
2469
|
+
const isHandle = typeof v === "object" && v !== null && !Array.isArray(v) && Object.keys(v).length === 3 && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null) && Object.hasOwn(v, "kind") && Object.hasOwn(v, "handleId") && Object.hasOwn(v, "oneUse") && v.kind === "secret_handle" && v.oneUse === true && boundedIdentifierSchema$1.safeParse(v.handleId).success;
|
|
2470
|
+
if (typeof v !== "string" && !isHandle) errors.push(`field "${field.name}" must be a string or one-use secret handle`);
|
|
2471
|
+
else if (typeof v === "string" && field.maxLength !== void 0 && v.length > field.maxLength) errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
2472
|
+
break;
|
|
2473
|
+
}
|
|
2474
|
+
case "number":
|
|
2475
|
+
if (typeof v !== "number" || !Number.isFinite(v)) errors.push(`field "${field.name}" must be a finite number`);
|
|
2476
|
+
else {
|
|
2477
|
+
if (field.min !== void 0 && v < field.min) errors.push(`field "${field.name}" below min ${field.min}`);
|
|
2478
|
+
if (field.max !== void 0 && v > field.max) errors.push(`field "${field.name}" above max ${field.max}`);
|
|
2479
|
+
}
|
|
2480
|
+
break;
|
|
2481
|
+
case "boolean":
|
|
2482
|
+
if (typeof v !== "boolean") errors.push(`field "${field.name}" must be a boolean`);
|
|
2483
|
+
break;
|
|
2484
|
+
case "select": {
|
|
2485
|
+
if (!Array.isArray(v)) {
|
|
2486
|
+
errors.push(`field "${field.name}" must be an array of option values`);
|
|
2487
|
+
break;
|
|
2488
|
+
}
|
|
2489
|
+
if (v.length > 1024) {
|
|
2490
|
+
errors.push(`field "${field.name}" has too many option values`);
|
|
2491
|
+
break;
|
|
2492
|
+
}
|
|
2493
|
+
if (!field.multi && v.length > 1) errors.push(`field "${field.name}" accepts a single value`);
|
|
2494
|
+
if (field.required && v.length === 0) errors.push(`field "${field.name}" requires a selection`);
|
|
2495
|
+
const allowed = new Set(field.options.map((o) => o.value));
|
|
2496
|
+
for (const choice of v) {
|
|
2497
|
+
if (allowed.has(choice)) continue;
|
|
2498
|
+
if (field.allowCustom === true) {
|
|
2499
|
+
if (typeof choice !== "string" || choice.trim() === "") errors.push(`field "${field.name}" has blank write-in value`);
|
|
2500
|
+
continue;
|
|
2501
|
+
}
|
|
2502
|
+
errors.push(`field "${field.name}" has invalid option "${choice}"`);
|
|
2503
|
+
}
|
|
2504
|
+
break;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
return errors.length === 0 ? { ok: true } : {
|
|
2509
|
+
ok: false,
|
|
2510
|
+
errors
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
//#endregion
|
|
2514
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-resolution-validation.js
|
|
2515
|
+
/**
|
|
2516
|
+
* A declined or cancelled resolution submits no answer, so any secret-typed
|
|
2517
|
+
* field it carries can only be leakage into a transport that retains it.
|
|
2518
|
+
*/
|
|
2519
|
+
function secretFieldErrors(spec, resolution) {
|
|
2520
|
+
const secretFields = new Set(spec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
2521
|
+
return Object.keys(resolution.data ?? {}).filter((fieldName) => secretFields.has(fieldName)).map((fieldName) => `field "${fieldName}" is secret and cannot ride a ${resolution.outcome} resolution`);
|
|
2522
|
+
}
|
|
2523
|
+
function validateResolutionForRequest(request, resolution) {
|
|
2524
|
+
if (resolution.outcome !== "accepted") {
|
|
2525
|
+
const errors = secretFieldErrors(request.answerSpec, resolution);
|
|
2526
|
+
if (Object.keys(resolution.data ?? {}).length > 0) errors.push(`a ${resolution.outcome} resolution cannot carry answer fields`);
|
|
2527
|
+
return errors;
|
|
2528
|
+
}
|
|
2529
|
+
const validation = validateInteractionAnswer(request.answerSpec, resolution.data);
|
|
2530
|
+
const errors = validation.ok ? [] : [...validation.errors];
|
|
2531
|
+
if (request.kind !== InteractionKind.Permission) return errors;
|
|
2532
|
+
const grant = resolution.data?.[PERMISSION_GRANT_FIELD];
|
|
2533
|
+
if (!Array.isArray(grant) || grant.length !== 1) {
|
|
2534
|
+
errors.push("permission response must select exactly one \"grant\" value");
|
|
2535
|
+
return errors;
|
|
2536
|
+
}
|
|
2537
|
+
const parsedGrant = PermissionGrantSchema.safeParse(grant[0]);
|
|
2538
|
+
if (!parsedGrant.success) {
|
|
2539
|
+
errors.push(`permission response has invalid grant "${String(grant[0])}"`);
|
|
2540
|
+
return errors;
|
|
2541
|
+
}
|
|
2542
|
+
if (parsedGrant.data === "deny") return errors;
|
|
2543
|
+
if (!new Set(request.responseScopes ?? ["interaction"]).has({
|
|
2544
|
+
allow_once: "interaction",
|
|
2545
|
+
allow_session: "session",
|
|
2546
|
+
allow_always: "persistent",
|
|
2547
|
+
deny: "interaction"
|
|
2548
|
+
}[parsedGrant.data])) errors.push(`permission grant "${parsedGrant.data}" exceeds the request's response scopes`);
|
|
2549
|
+
return errors;
|
|
2550
|
+
}
|
|
2551
|
+
//#endregion
|
|
2552
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/interaction-envelope.js
|
|
2553
|
+
const interactionOutcomeValues = [
|
|
2554
|
+
"accepted",
|
|
2555
|
+
"declined",
|
|
2556
|
+
"cancelled"
|
|
2557
|
+
];
|
|
2558
|
+
const InteractionSubjectSchema = z.discriminatedUnion("type", [
|
|
2559
|
+
z.strictObject({
|
|
2560
|
+
type: z.literal("tool"),
|
|
2561
|
+
toolName: boundedIdentifierSchema$1,
|
|
2562
|
+
input: boundedJsonSchema$1.optional()
|
|
2563
|
+
}),
|
|
2564
|
+
z.strictObject({
|
|
2565
|
+
type: z.literal("command"),
|
|
2566
|
+
command: boundedStringSchema$1
|
|
2567
|
+
}),
|
|
2568
|
+
z.strictObject({
|
|
2569
|
+
type: z.literal("file"),
|
|
2570
|
+
path: boundedStringSchema$1,
|
|
2571
|
+
preview: boundedStringSchema$1.optional()
|
|
2572
|
+
}),
|
|
2573
|
+
z.strictObject({
|
|
2574
|
+
type: z.literal("resource"),
|
|
2575
|
+
uri: boundedStringSchema$1
|
|
2576
|
+
})
|
|
2577
|
+
]);
|
|
2578
|
+
const InteractionOutcomeSchema = z.enum(interactionOutcomeValues);
|
|
2579
|
+
const InteractionRequestBindingSchema = z.strictObject({
|
|
2580
|
+
runId: boundedIdentifierSchema$1,
|
|
2581
|
+
provider: boundedIdentifierSchema$1,
|
|
2582
|
+
environmentId: boundedIdentifierSchema$1,
|
|
2583
|
+
sessionId: boundedIdentifierSchema$1,
|
|
2584
|
+
executionId: boundedIdentifierSchema$1,
|
|
2585
|
+
interactionId: boundedIdentifierSchema$1
|
|
2586
|
+
});
|
|
2587
|
+
InteractionRequestBindingSchema.omit({ interactionId: true });
|
|
2588
|
+
/** Binding carried by a response command and acknowledgement. */
|
|
2589
|
+
const InteractionBindingSchema = z.strictObject({
|
|
2590
|
+
...InteractionRequestBindingSchema.shape,
|
|
2591
|
+
requestDigest: sha256DigestSchema$1
|
|
2592
|
+
});
|
|
2593
|
+
const InteractionRequestMaterialSchema = z.strictObject({
|
|
2594
|
+
id: boundedIdentifierSchema$1,
|
|
2595
|
+
kind: boundedIdentifierSchema$1,
|
|
2596
|
+
title: boundedStringSchema$1.min(1),
|
|
2597
|
+
body: boundedStringSchema$1.optional(),
|
|
2598
|
+
subject: InteractionSubjectSchema.optional(),
|
|
2599
|
+
answerSpec: InteractionAnswerSpecSchema,
|
|
2600
|
+
responseScopes: z.array(InteractionResponseScopeSchema).min(1).max(CONTRACT_MAX_ARRAY_LENGTH$1).optional(),
|
|
2601
|
+
allowedOutcomes: z.array(InteractionOutcomeSchema).min(1).max(interactionOutcomeValues.length).optional(),
|
|
2602
|
+
default: InteractionResolutionSchema.optional(),
|
|
2603
|
+
timeoutMs: z.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
2604
|
+
onTimeout: z.enum([
|
|
2605
|
+
"default",
|
|
2606
|
+
"fail",
|
|
2607
|
+
"wait"
|
|
2608
|
+
]).optional(),
|
|
2609
|
+
binding: InteractionRequestBindingSchema
|
|
2610
|
+
});
|
|
2611
|
+
function interactionRequestDigest(request) {
|
|
2612
|
+
const parsed = InteractionRequestMaterialSchema.parse(request);
|
|
2613
|
+
rejectSecretDefaultValues(parsed);
|
|
2614
|
+
return canonicalCandidateDigest$1(parsed);
|
|
2615
|
+
}
|
|
2616
|
+
function rejectSecretDefaultValues(request) {
|
|
2617
|
+
const secretFields = new Set(request.answerSpec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
2618
|
+
for (const fieldName of Object.keys(request.default?.data ?? {})) if (secretFields.has(fieldName)) throw new Error("secret answers cannot be embedded in interaction defaults");
|
|
2619
|
+
}
|
|
2620
|
+
const InteractionRequestSchema = z.strictObject({
|
|
2621
|
+
...InteractionRequestMaterialSchema.shape,
|
|
2622
|
+
requestDigest: sha256DigestSchema$1
|
|
2623
|
+
}).superRefine((request, context) => {
|
|
2624
|
+
if (request.binding.interactionId !== request.id) context.addIssue({
|
|
2625
|
+
code: "custom",
|
|
2626
|
+
path: ["binding", "interactionId"],
|
|
2627
|
+
message: "interaction binding must name the request id"
|
|
2628
|
+
});
|
|
2629
|
+
if (request.responseScopes && new Set(request.responseScopes).size !== request.responseScopes.length) context.addIssue({
|
|
2630
|
+
code: "custom",
|
|
2631
|
+
path: ["responseScopes"],
|
|
2632
|
+
message: "interaction response scopes must be unique"
|
|
2633
|
+
});
|
|
2634
|
+
if (request.allowedOutcomes && new Set(request.allowedOutcomes).size !== request.allowedOutcomes.length) context.addIssue({
|
|
2635
|
+
code: "custom",
|
|
2636
|
+
path: ["allowedOutcomes"],
|
|
2637
|
+
message: "interaction outcomes must be unique"
|
|
2638
|
+
});
|
|
2639
|
+
if (request.onTimeout === "default" && request.default === void 0) context.addIssue({
|
|
2640
|
+
code: "custom",
|
|
2641
|
+
path: ["default"],
|
|
2642
|
+
message: "onTimeout=default requires a default resolution"
|
|
2643
|
+
});
|
|
2644
|
+
if (request.default && request.allowedOutcomes && !request.allowedOutcomes.includes(request.default.outcome)) context.addIssue({
|
|
2645
|
+
code: "custom",
|
|
2646
|
+
path: ["default", "outcome"],
|
|
2647
|
+
message: "default outcome is not allowed by the request"
|
|
2648
|
+
});
|
|
2649
|
+
if (request.default) {
|
|
2650
|
+
for (const error of validateResolutionForRequest(request, request.default)) context.addIssue({
|
|
2651
|
+
code: "custom",
|
|
2652
|
+
path: ["default"],
|
|
2653
|
+
message: error
|
|
2654
|
+
});
|
|
2655
|
+
const secretFields = new Set(request.answerSpec.fields.filter((field) => field.type === "secret").map((field) => field.name));
|
|
2656
|
+
for (const fieldName of Object.keys(request.default.data ?? {})) {
|
|
2657
|
+
if (!secretFields.has(fieldName)) continue;
|
|
2658
|
+
context.addIssue({
|
|
2659
|
+
code: "custom",
|
|
2660
|
+
path: [
|
|
2661
|
+
"default",
|
|
2662
|
+
"data",
|
|
2663
|
+
fieldName
|
|
2664
|
+
],
|
|
2665
|
+
message: "secret answers cannot be embedded in interaction defaults"
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
const { requestDigest: _digest, ...material } = request;
|
|
2670
|
+
if (!Object.keys(request.default?.data ?? {}).some((fieldName) => request.answerSpec.fields.some((field) => field.type === "secret" && field.name === fieldName))) {
|
|
2671
|
+
if (request.requestDigest !== interactionRequestDigest(material)) context.addIssue({
|
|
2672
|
+
code: "custom",
|
|
2673
|
+
path: ["requestDigest"],
|
|
2674
|
+
message: "interaction request digest does not match its content"
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
const InteractionResponseSchema = z.discriminatedUnion("outcome", [
|
|
2679
|
+
z.strictObject({
|
|
2680
|
+
id: boundedIdentifierSchema$1,
|
|
2681
|
+
outcome: z.literal("accepted"),
|
|
2682
|
+
data: InteractionDataSchema.optional()
|
|
2683
|
+
}),
|
|
2684
|
+
z.strictObject({
|
|
2685
|
+
id: boundedIdentifierSchema$1,
|
|
2686
|
+
outcome: z.literal("declined"),
|
|
2687
|
+
data: InteractionDataSchema.optional()
|
|
2688
|
+
}),
|
|
2689
|
+
z.strictObject({
|
|
2690
|
+
id: boundedIdentifierSchema$1,
|
|
2691
|
+
outcome: z.literal("cancelled"),
|
|
2692
|
+
data: InteractionDataSchema.optional()
|
|
2693
|
+
})
|
|
2694
|
+
]);
|
|
2695
|
+
/** Digest the exact binding and response carried by a retryable command. */
|
|
2696
|
+
function interactionResponseCommandDigest(material) {
|
|
2697
|
+
return canonicalCandidateDigest$1({
|
|
2698
|
+
binding: InteractionBindingSchema.parse(material.binding),
|
|
2699
|
+
response: InteractionResponseSchema.parse(material.response)
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
/** Retryable command sent to an environment or retained session. */
|
|
2703
|
+
const InteractionResponseCommandSchema = z.strictObject({
|
|
2704
|
+
operationId: boundedIdentifierSchema$1,
|
|
2705
|
+
binding: InteractionBindingSchema,
|
|
2706
|
+
commandDigest: sha256DigestSchema$1,
|
|
2707
|
+
response: InteractionResponseSchema
|
|
2708
|
+
}).superRefine((command, context) => {
|
|
2709
|
+
if (command.binding.interactionId !== command.response.id) context.addIssue({
|
|
2710
|
+
code: "custom",
|
|
2711
|
+
path: ["response", "id"],
|
|
2712
|
+
message: "response id must match the bound interaction id"
|
|
2713
|
+
});
|
|
2714
|
+
if (command.commandDigest !== interactionResponseCommandDigest({
|
|
2715
|
+
binding: command.binding,
|
|
2716
|
+
response: command.response
|
|
2717
|
+
})) context.addIssue({
|
|
2718
|
+
code: "custom",
|
|
2719
|
+
path: ["commandDigest"],
|
|
2720
|
+
message: "interaction response command digest does not match its content"
|
|
2721
|
+
});
|
|
2722
|
+
});
|
|
2723
|
+
const InteractionAcknowledgementStatusSchema = z.enum([
|
|
2724
|
+
"accepted",
|
|
2725
|
+
"already_resolved_same",
|
|
2726
|
+
"already_resolved_different",
|
|
2727
|
+
"expired",
|
|
2728
|
+
"cancelled",
|
|
2729
|
+
"unknown_interaction",
|
|
2730
|
+
"unknown_run",
|
|
2731
|
+
"binding_mismatch",
|
|
2732
|
+
"invalid_response",
|
|
2733
|
+
"transport_failure"
|
|
2734
|
+
]);
|
|
2735
|
+
/** Durable result of one interaction response operation. */
|
|
2736
|
+
const InteractionAcknowledgementSchema = z.strictObject({
|
|
2737
|
+
operationId: boundedIdentifierSchema$1,
|
|
2738
|
+
binding: InteractionBindingSchema,
|
|
2739
|
+
commandDigest: sha256DigestSchema$1,
|
|
2740
|
+
status: InteractionAcknowledgementStatusSchema,
|
|
2741
|
+
message: boundedStringSchema$1.min(1).optional(),
|
|
2742
|
+
retryable: z.boolean().optional()
|
|
2743
|
+
}).superRefine((acknowledgement, context) => {
|
|
2744
|
+
if (["invalid_response", "transport_failure"].includes(acknowledgement.status) && acknowledgement.message === void 0) context.addIssue({
|
|
2745
|
+
code: "custom",
|
|
2746
|
+
path: ["message"],
|
|
2747
|
+
message: `${acknowledgement.status} must include a message`
|
|
2748
|
+
});
|
|
2749
|
+
if (acknowledgement.status === "transport_failure" && acknowledgement.retryable === void 0) context.addIssue({
|
|
2750
|
+
code: "custom",
|
|
2751
|
+
path: ["retryable"],
|
|
2752
|
+
message: "transport_failure must state whether retry is safe"
|
|
2753
|
+
});
|
|
2754
|
+
});
|
|
2755
|
+
//#endregion
|
|
2756
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/plan.js
|
|
2757
|
+
/**
|
|
2758
|
+
* Credential-free provider correlation committed with the plan. This union is
|
|
2759
|
+
* deliberately closed: adding plan support for another harness requires an
|
|
2760
|
+
* explicit resume contract instead of smuggling opaque metadata through.
|
|
2761
|
+
*/
|
|
2762
|
+
const PlanProviderStateSchema = z.discriminatedUnion("kind", [
|
|
2763
|
+
z.object({
|
|
2764
|
+
kind: z.literal("claude-code"),
|
|
2765
|
+
version: z.literal(1),
|
|
2766
|
+
nativeSessionId: z.string().min(1)
|
|
2767
|
+
}).strict(),
|
|
2768
|
+
z.object({
|
|
2769
|
+
kind: z.literal("codex"),
|
|
2770
|
+
version: z.literal(1),
|
|
2771
|
+
threadId: z.string().min(1)
|
|
2772
|
+
}).strict(),
|
|
2773
|
+
z.object({
|
|
2774
|
+
kind: z.literal("opencode"),
|
|
2775
|
+
version: z.literal(1)
|
|
2776
|
+
}).strict()
|
|
2777
|
+
]);
|
|
2778
|
+
/**
|
|
2779
|
+
* A plan committed by the runtime before the planning turn is allowed to end.
|
|
2780
|
+
* The full body is part of the contract so consumers never reconstruct it from
|
|
2781
|
+
* rendered chat text.
|
|
2782
|
+
*/
|
|
2783
|
+
const DurablePlanSchema = z.object({
|
|
2784
|
+
id: z.string().min(1),
|
|
2785
|
+
revision: z.number().int().positive(),
|
|
2786
|
+
title: z.string().trim().min(1).optional(),
|
|
2787
|
+
body: z.string().trim().min(1),
|
|
2788
|
+
submittedAt: z.string().datetime({ offset: true })
|
|
2789
|
+
}).strict();
|
|
2790
|
+
z.object({
|
|
2791
|
+
title: z.string().trim().min(1).optional(),
|
|
2792
|
+
body: z.string().trim().min(1),
|
|
2793
|
+
/** Stable provider tool-call identity reused when a lost acknowledgement retries. */
|
|
2794
|
+
sourceToolCallId: z.string().min(1),
|
|
2795
|
+
/** Credential-free correlation required to resume the deferred turn. */
|
|
2796
|
+
providerState: PlanProviderStateSchema
|
|
2797
|
+
}).strict();
|
|
2798
|
+
/** The human verdict that starts the next turn. */
|
|
2799
|
+
const PlanDecisionSchema = z.discriminatedUnion("outcome", [z.object({ outcome: z.literal("approved") }).strict(), z.object({
|
|
2800
|
+
outcome: z.literal("rejected"),
|
|
2801
|
+
feedback: z.string().trim().min(1)
|
|
2802
|
+
}).strict()]);
|
|
2803
|
+
/**
|
|
2804
|
+
* Typed server-originated continuation. Adapters consume this instead of
|
|
2805
|
+
* inferring approval from a free-form user message.
|
|
2806
|
+
*/
|
|
2807
|
+
const PlanContinuationSchema = z.object({
|
|
2808
|
+
version: z.literal(1),
|
|
2809
|
+
plan: DurablePlanSchema,
|
|
2810
|
+
sourceToolCallId: z.string().min(1),
|
|
2811
|
+
decision: PlanDecisionSchema,
|
|
2812
|
+
/** Exact payload previously committed with the plan submission. */
|
|
2813
|
+
providerState: PlanProviderStateSchema
|
|
2814
|
+
}).strict();
|
|
2815
|
+
/** Terminal meaning of a successfully completed adapter invocation. */
|
|
2816
|
+
const AgentExecutionOutcomeSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("completed") }).strict(), z.object({
|
|
2817
|
+
type: z.literal("awaiting_plan_decision"),
|
|
2818
|
+
plan: DurablePlanSchema
|
|
2819
|
+
}).strict()]);
|
|
2820
|
+
//#endregion
|
|
2821
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/runtime-control.js
|
|
2822
|
+
const stableIdSchema = boundedIdentifierSchema$1;
|
|
2823
|
+
const AgentExactRunControlRefSchema = z.strictObject({
|
|
2824
|
+
runId: stableIdSchema,
|
|
2825
|
+
provider: stableIdSchema,
|
|
2826
|
+
environmentId: stableIdSchema,
|
|
2827
|
+
sessionId: stableIdSchema.optional(),
|
|
2828
|
+
executionId: stableIdSchema.optional(),
|
|
2829
|
+
requestDigest: sha256DigestSchema$1.optional()
|
|
2830
|
+
}).extend({
|
|
2831
|
+
sessionId: stableIdSchema,
|
|
2832
|
+
executionId: stableIdSchema,
|
|
2833
|
+
requestDigest: sha256DigestSchema$1
|
|
2834
|
+
});
|
|
2835
|
+
/**
|
|
2836
|
+
* Whether two references name the same run.
|
|
2837
|
+
*
|
|
2838
|
+
* Comparison is over the reference's canonical form rather than a list of
|
|
2839
|
+
* field names, so a reference that gains a field is compared on it without a
|
|
2840
|
+
* caller having to remember: two runs that differ only in a field nobody
|
|
2841
|
+
* enumerated must not read as one run.
|
|
2842
|
+
*/
|
|
2843
|
+
function sameAgentRunControlRef(left, right) {
|
|
2844
|
+
return canonicalCandidateDigest$1(left) === canonicalCandidateDigest$1(right);
|
|
2845
|
+
}
|
|
2846
|
+
function agentRunCancellationRequestDigest(request) {
|
|
2847
|
+
const parsed = AgentRunCancellationRequestMaterialSchema.parse(request);
|
|
2848
|
+
return canonicalCandidateDigest$1({
|
|
2849
|
+
operationId: parsed.operationId,
|
|
2850
|
+
run: parsed.run,
|
|
2851
|
+
...parsed.reason === void 0 ? {} : { reason: parsed.reason }
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
const AgentRunCancellationRequestMaterialSchema = z.strictObject({
|
|
2855
|
+
operationId: stableIdSchema,
|
|
2856
|
+
run: AgentExactRunControlRefSchema,
|
|
2857
|
+
reason: boundedStringSchema$1.min(1).max(2048).optional()
|
|
2858
|
+
});
|
|
2859
|
+
const AgentRunCancellationRequestSchema = z.strictObject({
|
|
2860
|
+
...AgentRunCancellationRequestMaterialSchema.shape,
|
|
2861
|
+
requestDigest: sha256DigestSchema$1
|
|
2862
|
+
}).superRefine((request, refinement) => {
|
|
2863
|
+
const { requestDigest: _requestDigest, ...material } = request;
|
|
2864
|
+
if (request.requestDigest !== agentRunCancellationRequestDigest(material)) refinement.addIssue({
|
|
2865
|
+
code: "custom",
|
|
2866
|
+
path: ["requestDigest"],
|
|
2867
|
+
message: "run cancellation request digest does not match its content"
|
|
2868
|
+
});
|
|
2869
|
+
});
|
|
2870
|
+
const AgentRunCancellationAcknowledgementSchema = z.strictObject({
|
|
2871
|
+
operationId: stableIdSchema,
|
|
2872
|
+
requestDigest: sha256DigestSchema$1,
|
|
2873
|
+
run: AgentExactRunControlRefSchema,
|
|
2874
|
+
status: z.enum([
|
|
2875
|
+
"accepted",
|
|
2876
|
+
"replayed",
|
|
2877
|
+
"conflict",
|
|
2878
|
+
"unknown"
|
|
2879
|
+
]),
|
|
2880
|
+
effect: z.enum([
|
|
2881
|
+
"cancel_requested",
|
|
2882
|
+
"cancelled",
|
|
2883
|
+
"not_live",
|
|
2884
|
+
"unknown"
|
|
2885
|
+
]),
|
|
2886
|
+
message: boundedStringSchema$1.min(1).optional(),
|
|
2887
|
+
retryable: z.boolean().optional(),
|
|
2888
|
+
existingRequestDigest: sha256DigestSchema$1.optional()
|
|
2889
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
2890
|
+
const known = acknowledgement.effect !== "unknown";
|
|
2891
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !known || (acknowledgement.status === "conflict" || acknowledgement.status === "unknown") && known) refinement.addIssue({
|
|
2892
|
+
code: "custom",
|
|
2893
|
+
path: ["effect"],
|
|
2894
|
+
message: "cancellation status and effect certainty do not agree"
|
|
2895
|
+
});
|
|
2896
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === void 0) refinement.addIssue({
|
|
2897
|
+
code: "custom",
|
|
2898
|
+
path: ["existingRequestDigest"],
|
|
2899
|
+
message: "a cancellation conflict must include the existing digest"
|
|
2900
|
+
});
|
|
2901
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === acknowledgement.requestDigest) refinement.addIssue({
|
|
2902
|
+
code: "custom",
|
|
2903
|
+
path: ["existingRequestDigest"],
|
|
2904
|
+
message: "a cancellation conflict must identify a different request"
|
|
2905
|
+
});
|
|
2906
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
2907
|
+
code: "custom",
|
|
2908
|
+
path: ["existingRequestDigest"],
|
|
2909
|
+
message: "only a cancellation conflict may include an existing digest"
|
|
2910
|
+
});
|
|
2911
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== false)) refinement.addIssue({
|
|
2912
|
+
code: "custom",
|
|
2913
|
+
path: ["retryable"],
|
|
2914
|
+
message: "an unknown cancellation outcome must be explicit and non-repeatable"
|
|
2915
|
+
});
|
|
2916
|
+
});
|
|
2917
|
+
function agentRunCancellationAcknowledgementMatchesRequest(request, acknowledgement) {
|
|
2918
|
+
const exactRequest = AgentRunCancellationRequestSchema.safeParse(request);
|
|
2919
|
+
const exactAcknowledgement = AgentRunCancellationAcknowledgementSchema.safeParse(acknowledgement);
|
|
2920
|
+
if (!exactRequest.success || !exactAcknowledgement.success) return false;
|
|
2921
|
+
return exactAcknowledgement.data.operationId === exactRequest.data.operationId && exactAcknowledgement.data.requestDigest === exactRequest.data.requestDigest && sameAgentRunControlRef(exactAcknowledgement.data.run, exactRequest.data.run);
|
|
2922
|
+
}
|
|
2923
|
+
const unknownRecordSchema = boundedJsonRecordSchema$1;
|
|
2924
|
+
const partBase = {
|
|
2925
|
+
id: stableIdSchema,
|
|
2926
|
+
sessionID: stableIdSchema,
|
|
2927
|
+
messageID: stableIdSchema
|
|
2928
|
+
};
|
|
2929
|
+
const toolTimeSchema = z.strictObject({
|
|
2930
|
+
start: z.number().finite(),
|
|
2931
|
+
end: z.number().finite().optional()
|
|
2932
|
+
});
|
|
2933
|
+
const toolStateSchema = z.discriminatedUnion("status", [
|
|
2934
|
+
z.strictObject({
|
|
2935
|
+
status: z.literal("pending"),
|
|
2936
|
+
input: boundedEventContentRecordSchema$1,
|
|
2937
|
+
raw: boundedEventContentStringSchema$1.optional()
|
|
2938
|
+
}),
|
|
2939
|
+
z.strictObject({
|
|
2940
|
+
status: z.literal("running"),
|
|
2941
|
+
input: boundedEventContentRecordSchema$1,
|
|
2942
|
+
title: boundedStringSchema$1.optional(),
|
|
2943
|
+
metadata: unknownRecordSchema.optional(),
|
|
2944
|
+
time: z.strictObject({ start: z.number().finite() }).optional()
|
|
2945
|
+
}),
|
|
2946
|
+
z.strictObject({
|
|
2947
|
+
status: z.literal("completed"),
|
|
2948
|
+
input: boundedEventContentRecordSchema$1,
|
|
2949
|
+
output: boundedEventContentJsonSchema$1,
|
|
2950
|
+
title: boundedStringSchema$1.optional(),
|
|
2951
|
+
metadata: unknownRecordSchema.optional(),
|
|
2952
|
+
time: z.strictObject({
|
|
2953
|
+
start: z.number().finite(),
|
|
2954
|
+
end: z.number().finite()
|
|
2955
|
+
}).optional()
|
|
2956
|
+
}),
|
|
2957
|
+
z.strictObject({
|
|
2958
|
+
status: z.enum(["error", "failed"]),
|
|
2959
|
+
input: boundedEventContentRecordSchema$1,
|
|
2960
|
+
error: boundedStringSchema$1.optional(),
|
|
2961
|
+
output: boundedEventContentJsonSchema$1.optional(),
|
|
2962
|
+
metadata: unknownRecordSchema.optional(),
|
|
2963
|
+
time: toolTimeSchema.optional()
|
|
2964
|
+
})
|
|
2965
|
+
]);
|
|
2966
|
+
const partSchema = z.discriminatedUnion("type", [
|
|
2967
|
+
z.strictObject({
|
|
2968
|
+
...partBase,
|
|
2969
|
+
type: z.literal("text"),
|
|
2970
|
+
text: boundedEventContentStringSchema$1
|
|
2971
|
+
}),
|
|
2972
|
+
z.strictObject({
|
|
2973
|
+
...partBase,
|
|
2974
|
+
type: z.literal("tool"),
|
|
2975
|
+
callID: stableIdSchema.optional(),
|
|
2976
|
+
tool: stableIdSchema,
|
|
2977
|
+
state: toolStateSchema,
|
|
2978
|
+
metadata: unknownRecordSchema.optional()
|
|
2979
|
+
}),
|
|
2980
|
+
z.strictObject({
|
|
2981
|
+
...partBase,
|
|
2982
|
+
type: z.literal("reasoning"),
|
|
2983
|
+
text: boundedEventContentStringSchema$1
|
|
2984
|
+
}),
|
|
2985
|
+
z.strictObject({
|
|
2986
|
+
...partBase,
|
|
2987
|
+
type: z.literal("file"),
|
|
2988
|
+
filename: boundedStringSchema$1.optional(),
|
|
2989
|
+
mediaType: boundedStringSchema$1.optional(),
|
|
2990
|
+
url: boundedStringSchema$1.optional()
|
|
2991
|
+
}),
|
|
2992
|
+
z.strictObject({
|
|
2993
|
+
...partBase,
|
|
2994
|
+
type: z.literal("subtask"),
|
|
2995
|
+
prompt: boundedEventContentStringSchema$1,
|
|
2996
|
+
description: boundedStringSchema$1,
|
|
2997
|
+
agent: stableIdSchema
|
|
2998
|
+
})
|
|
2999
|
+
]);
|
|
3000
|
+
const TERMINAL_CHILD_TASK_STATUSES = new Set([
|
|
3001
|
+
"completed",
|
|
3002
|
+
"failed",
|
|
3003
|
+
"cancelled"
|
|
3004
|
+
]);
|
|
3005
|
+
const epochMillisecondsSchema = z.number().finite().nonnegative();
|
|
3006
|
+
/**
|
|
3007
|
+
* Provider-native child task lifecycle. Identity comes only from `childId`,
|
|
3008
|
+
* `parentChildId`, and `sourceEventId`; `raw` is opaque and bounded. A provider
|
|
3009
|
+
* without a stable `childId` emits no `child-task` event.
|
|
3010
|
+
*/
|
|
3011
|
+
const ChildTaskEventSchema = z.strictObject({
|
|
3012
|
+
type: z.literal("child-task"),
|
|
3013
|
+
childId: stableIdSchema,
|
|
3014
|
+
parentChildId: stableIdSchema.optional(),
|
|
3015
|
+
status: z.enum([
|
|
3016
|
+
"started",
|
|
3017
|
+
"running",
|
|
3018
|
+
"completed",
|
|
3019
|
+
"failed",
|
|
3020
|
+
"cancelled"
|
|
3021
|
+
]),
|
|
3022
|
+
title: boundedStringSchema$1.optional(),
|
|
3023
|
+
time: z.strictObject({
|
|
3024
|
+
started: epochMillisecondsSchema,
|
|
3025
|
+
updated: epochMillisecondsSchema,
|
|
3026
|
+
ended: epochMillisecondsSchema.optional()
|
|
3027
|
+
}),
|
|
3028
|
+
runner: stableIdSchema.optional(),
|
|
3029
|
+
model: stableIdSchema.optional(),
|
|
3030
|
+
usage: ModelUsageSchema.optional(),
|
|
3031
|
+
terminalReason: boundedStringSchema$1.optional(),
|
|
3032
|
+
sourceEventId: stableIdSchema,
|
|
3033
|
+
raw: boundedJsonRecordSchema$1.optional()
|
|
3034
|
+
}).superRefine((event, refinement) => {
|
|
3035
|
+
const terminal = TERMINAL_CHILD_TASK_STATUSES.has(event.status);
|
|
3036
|
+
if (!terminal && event.time.ended !== void 0) refinement.addIssue({
|
|
3037
|
+
code: "custom",
|
|
3038
|
+
path: ["time", "ended"],
|
|
3039
|
+
message: "only a terminal child task status may carry an end time"
|
|
3040
|
+
});
|
|
3041
|
+
if (!terminal && event.terminalReason !== void 0) refinement.addIssue({
|
|
3042
|
+
code: "custom",
|
|
3043
|
+
path: ["terminalReason"],
|
|
3044
|
+
message: "only a terminal child task status may carry a terminal reason"
|
|
3045
|
+
});
|
|
3046
|
+
if (event.time.updated < event.time.started) refinement.addIssue({
|
|
3047
|
+
code: "custom",
|
|
3048
|
+
path: ["time", "updated"],
|
|
3049
|
+
message: "a child task update time cannot precede its start time"
|
|
3050
|
+
});
|
|
3051
|
+
if (event.time.ended !== void 0 && event.time.ended < event.time.started) refinement.addIssue({
|
|
3052
|
+
code: "custom",
|
|
3053
|
+
path: ["time", "ended"],
|
|
3054
|
+
message: "a child task end time cannot precede its start time"
|
|
3055
|
+
});
|
|
3056
|
+
if (event.parentChildId === event.childId) refinement.addIssue({
|
|
3057
|
+
code: "custom",
|
|
3058
|
+
path: ["parentChildId"],
|
|
3059
|
+
message: "a child task cannot be its own parent"
|
|
3060
|
+
});
|
|
3061
|
+
});
|
|
3062
|
+
const CanonicalStreamEventSchema = z.discriminatedUnion("type", [
|
|
3063
|
+
z.strictObject({
|
|
3064
|
+
type: z.literal("message.part.updated"),
|
|
3065
|
+
part: partSchema,
|
|
3066
|
+
delta: boundedEventContentStringSchema$1.optional()
|
|
3067
|
+
}),
|
|
3068
|
+
z.strictObject({
|
|
3069
|
+
type: z.literal("tool-heartbeat"),
|
|
3070
|
+
toolName: stableIdSchema,
|
|
3071
|
+
partId: stableIdSchema,
|
|
3072
|
+
elapsedMs: z.number().finite().nonnegative()
|
|
3073
|
+
}),
|
|
3074
|
+
z.strictObject({
|
|
3075
|
+
type: z.literal("tool-slow"),
|
|
3076
|
+
toolName: stableIdSchema,
|
|
3077
|
+
partId: stableIdSchema,
|
|
3078
|
+
elapsedMs: z.number().finite().nonnegative(),
|
|
3079
|
+
thresholdMs: z.number().finite().nonnegative()
|
|
3080
|
+
}),
|
|
3081
|
+
z.strictObject({
|
|
3082
|
+
type: z.literal("model-processing"),
|
|
3083
|
+
phase: z.enum([
|
|
3084
|
+
"tool-result",
|
|
3085
|
+
"generating",
|
|
3086
|
+
"thinking"
|
|
3087
|
+
]),
|
|
3088
|
+
toolName: stableIdSchema.optional(),
|
|
3089
|
+
elapsedMs: z.number().finite().nonnegative().optional()
|
|
3090
|
+
}),
|
|
3091
|
+
z.strictObject({
|
|
3092
|
+
type: z.literal("status"),
|
|
3093
|
+
status: z.enum([
|
|
3094
|
+
"started",
|
|
3095
|
+
"processing",
|
|
3096
|
+
"completed",
|
|
3097
|
+
"failed",
|
|
3098
|
+
"cancelled"
|
|
3099
|
+
]),
|
|
3100
|
+
detail: boundedStringSchema$1.optional()
|
|
3101
|
+
}),
|
|
3102
|
+
z.strictObject({
|
|
3103
|
+
type: z.literal("warning"),
|
|
3104
|
+
code: stableIdSchema,
|
|
3105
|
+
message: boundedStringSchema$1
|
|
3106
|
+
}),
|
|
3107
|
+
z.strictObject({
|
|
3108
|
+
type: z.literal("raw"),
|
|
3109
|
+
backend: stableIdSchema,
|
|
3110
|
+
event: boundedEventContentJsonSchema$1
|
|
3111
|
+
}),
|
|
3112
|
+
NativeSessionObservedEventSchema,
|
|
3113
|
+
z.strictObject({
|
|
3114
|
+
type: z.literal("session.updated"),
|
|
3115
|
+
sessionId: stableIdSchema,
|
|
3116
|
+
title: boundedStringSchema$1.optional(),
|
|
3117
|
+
time: z.strictObject({
|
|
3118
|
+
created: z.number().finite().optional(),
|
|
3119
|
+
updated: z.number().finite().optional()
|
|
3120
|
+
}).optional()
|
|
3121
|
+
}),
|
|
3122
|
+
z.strictObject({
|
|
3123
|
+
type: z.literal("interaction"),
|
|
3124
|
+
request: InteractionRequestSchema
|
|
3125
|
+
}),
|
|
3126
|
+
z.strictObject({
|
|
3127
|
+
type: z.literal("interaction.cancel"),
|
|
3128
|
+
id: stableIdSchema,
|
|
3129
|
+
reason: boundedStringSchema$1.optional()
|
|
3130
|
+
}),
|
|
3131
|
+
z.strictObject({
|
|
3132
|
+
type: z.literal("plan.submitted"),
|
|
3133
|
+
plan: DurablePlanSchema
|
|
3134
|
+
}),
|
|
3135
|
+
ChildTaskEventSchema
|
|
3136
|
+
]).superRefine((event, refinement) => {
|
|
3137
|
+
if (!isBoundedEventContentJson$1(event, { omitUndefinedObjectFields: true })) refinement.addIssue({
|
|
3138
|
+
code: "custom",
|
|
3139
|
+
message: "canonical stream event exceeds its serialized byte bound"
|
|
3140
|
+
});
|
|
3141
|
+
});
|
|
3142
|
+
z.strictObject({
|
|
3143
|
+
runId: stableIdSchema,
|
|
3144
|
+
eventId: stableIdSchema,
|
|
3145
|
+
sequence: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
3146
|
+
cursor: stableIdSchema.optional(),
|
|
3147
|
+
occurredAt: z.iso.datetime().max(64).optional(),
|
|
3148
|
+
receivedAt: z.iso.datetime().max(64),
|
|
3149
|
+
event: CanonicalStreamEventSchema
|
|
3150
|
+
});
|
|
3151
|
+
//#endregion
|
|
3152
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/agent-workspace-source-snapshot.js
|
|
3153
|
+
const controlCharacterPattern = /[\u0000-\u001f\u007f]/;
|
|
3154
|
+
/** Shared public identifier used by workspace lifecycle contracts. */
|
|
3155
|
+
const agentWorkspacePublicIdentifierSchema = z.string().min(1).max(500).refine((value) => value.trim().length > 0 && isWellFormedUnicode$1(value) && !controlCharacterPattern.test(value) && !looksLikeCredential$1(value), "public workspace identity cannot carry credential-like material");
|
|
3156
|
+
const agentWorkspaceSourceSnapshotPolicySchema = z.strictObject({
|
|
3157
|
+
kind: z.literal("provider-declared"),
|
|
3158
|
+
name: agentWorkspacePublicIdentifierSchema,
|
|
3159
|
+
version: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
3160
|
+
digest: sha256DigestSchema$1
|
|
3161
|
+
});
|
|
3162
|
+
//#endregion
|
|
3163
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/agent-profile-materialization.js
|
|
3164
|
+
/**
|
|
3165
|
+
* The canonical AgentProfile leaves that can affect one execution.
|
|
3166
|
+
*
|
|
3167
|
+
* Compound parents such as `model`, `prompt`, and `resources` are deliberately
|
|
3168
|
+
* absent. A producer must report the exact requested leaf instead of claiming
|
|
3169
|
+
* a parent while silently dropping one of its children. `systemPrompt` and
|
|
3170
|
+
* `appendSystemPrompt` are separate leaves for the same reason: a backend that
|
|
3171
|
+
* can only add text must report the requested replacement as unsatisfied rather
|
|
3172
|
+
* than acknowledge it.
|
|
3173
|
+
*/
|
|
3174
|
+
const AGENT_PROFILE_MATERIALIZATION_AXES = [
|
|
3175
|
+
"name",
|
|
3176
|
+
"description",
|
|
3177
|
+
"version",
|
|
3178
|
+
"tags",
|
|
3179
|
+
"systemPrompt",
|
|
3180
|
+
"appendSystemPrompt",
|
|
3181
|
+
"instructions",
|
|
3182
|
+
"modelDefault",
|
|
3183
|
+
"modelSmall",
|
|
3184
|
+
"modelProvider",
|
|
3185
|
+
"modelReasoningEffort",
|
|
3186
|
+
"modelMaxVisibleOutputTokens",
|
|
3187
|
+
"modelMaxReasoningTokens",
|
|
3188
|
+
"modelMaxTotalOutputTokens",
|
|
3189
|
+
"modelMetadata",
|
|
3190
|
+
"harness",
|
|
3191
|
+
"seats",
|
|
3192
|
+
"proxySecrets",
|
|
3193
|
+
"permissions",
|
|
3194
|
+
"tools",
|
|
3195
|
+
"mcp",
|
|
3196
|
+
"connections",
|
|
3197
|
+
"subagents",
|
|
3198
|
+
"files",
|
|
3199
|
+
"resourceTools",
|
|
3200
|
+
"skills",
|
|
3201
|
+
"resourceAgents",
|
|
3202
|
+
"commands",
|
|
3203
|
+
"knowledge",
|
|
3204
|
+
"resourceInstructions",
|
|
3205
|
+
"resourceFailOnError",
|
|
3206
|
+
"hooks",
|
|
3207
|
+
"modes",
|
|
3208
|
+
"confidential",
|
|
3209
|
+
"metadata",
|
|
3210
|
+
"extensions"
|
|
3211
|
+
];
|
|
3212
|
+
[...Object.entries({
|
|
3213
|
+
default: "modelDefault",
|
|
3214
|
+
small: "modelSmall",
|
|
3215
|
+
provider: "modelProvider",
|
|
3216
|
+
reasoningEffort: "modelReasoningEffort",
|
|
3217
|
+
maxVisibleOutputTokens: "modelMaxVisibleOutputTokens",
|
|
3218
|
+
maxReasoningTokens: "modelMaxReasoningTokens",
|
|
3219
|
+
maxTotalOutputTokens: "modelMaxTotalOutputTokens",
|
|
3220
|
+
metadata: "modelMetadata"
|
|
3221
|
+
}).map(([property, axis]) => ({
|
|
3222
|
+
axis,
|
|
3223
|
+
rootPath: `/model/${property}`,
|
|
3224
|
+
value: (profile) => profile.model?.[property]
|
|
3225
|
+
}))];
|
|
3226
|
+
//#endregion
|
|
3227
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/agent-execution-preparation-receipt.js
|
|
3228
|
+
const nonBlankStringSchema = z.string().refine((value) => value.trim().length > 0, "value cannot be blank");
|
|
3229
|
+
const publicMechanismIdentifierSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$/, "mechanism must be a public identifier, not launch arguments").refine((value) => !looksLikeCredential$1(value), "mechanism cannot carry credential-like material");
|
|
3230
|
+
const publicLifecycleIdentifierSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._~:/+-]{0,499}$/, "lifecycle identity must be a public identifier").refine((value) => !looksLikeCredential$1(value), "lifecycle identity cannot carry credential-like material");
|
|
3231
|
+
const publicReasonSchema = nonBlankStringSchema.max(4e3).refine((value) => !looksLikeCredential$1(value), "reason cannot carry credential-like material");
|
|
3232
|
+
const jsonPointerSchema = z.string().refine(isCanonicalJsonPointer, "path must be a canonical RFC 6901 JSON Pointer");
|
|
3233
|
+
const agentExecutionPreparationAxisResultSchema = z.strictObject({
|
|
3234
|
+
axis: z.enum(AGENT_PROFILE_MATERIALIZATION_AXES),
|
|
3235
|
+
disposition: z.enum([
|
|
3236
|
+
"behavior",
|
|
3237
|
+
"control",
|
|
3238
|
+
"overridden",
|
|
3239
|
+
"unsupported"
|
|
3240
|
+
]),
|
|
3241
|
+
owner: z.enum(["runtime", "executor"]),
|
|
3242
|
+
mechanism: publicMechanismIdentifierSchema,
|
|
3243
|
+
evidenceDigest: sha256DigestSchema$1.optional(),
|
|
3244
|
+
path: jsonPointerSchema.optional(),
|
|
3245
|
+
reason: publicReasonSchema.optional()
|
|
3246
|
+
}).superRefine((result, context) => {
|
|
3247
|
+
const requiresReason = result.disposition === "overridden" || result.disposition === "unsupported";
|
|
3248
|
+
if (requiresReason && result.reason === void 0) context.addIssue({
|
|
3249
|
+
code: "custom",
|
|
3250
|
+
path: ["reason"],
|
|
3251
|
+
message: `${result.disposition} profile coverage requires a reason`
|
|
3252
|
+
});
|
|
3253
|
+
if (!requiresReason && result.reason !== void 0) context.addIssue({
|
|
3254
|
+
code: "custom",
|
|
3255
|
+
path: ["reason"],
|
|
3256
|
+
message: `${result.disposition} profile coverage cannot carry an override reason`
|
|
3257
|
+
});
|
|
3258
|
+
});
|
|
3259
|
+
const reasoningEffortSchema = z.enum(REASONING_EFFORTS$1);
|
|
3260
|
+
const agentExecutionPreparationReasoningEffortSchema = z.strictObject({
|
|
3261
|
+
requested: reasoningEffortSchema,
|
|
3262
|
+
resolved: reasoningEffortSchema.optional(),
|
|
3263
|
+
fidelity: z.enum([
|
|
3264
|
+
"exact",
|
|
3265
|
+
"clamped",
|
|
3266
|
+
"unsupported"
|
|
3267
|
+
])
|
|
3268
|
+
}).superRefine((effort, context) => {
|
|
3269
|
+
if (effort.fidelity === "unsupported") {
|
|
3270
|
+
if (effort.resolved !== void 0) context.addIssue({
|
|
3271
|
+
code: "custom",
|
|
3272
|
+
path: ["resolved"],
|
|
3273
|
+
message: "unsupported reasoning effort cannot claim a resolved value"
|
|
3274
|
+
});
|
|
3275
|
+
return;
|
|
3276
|
+
}
|
|
3277
|
+
if (effort.resolved === void 0) {
|
|
3278
|
+
context.addIssue({
|
|
3279
|
+
code: "custom",
|
|
3280
|
+
path: ["resolved"],
|
|
3281
|
+
message: `${effort.fidelity} reasoning fidelity requires a resolved value`
|
|
3282
|
+
});
|
|
3283
|
+
return;
|
|
3284
|
+
}
|
|
3285
|
+
if (effort.fidelity === "exact" && effort.resolved !== effort.requested) context.addIssue({
|
|
3286
|
+
code: "custom",
|
|
3287
|
+
path: ["resolved"],
|
|
3288
|
+
message: "exact reasoning fidelity must preserve the requested effort"
|
|
3289
|
+
});
|
|
3290
|
+
if (effort.fidelity === "clamped") {
|
|
3291
|
+
if (effort.resolved === effort.requested) context.addIssue({
|
|
3292
|
+
code: "custom",
|
|
3293
|
+
path: ["resolved"],
|
|
3294
|
+
message: "clamped reasoning fidelity must change the requested effort"
|
|
3295
|
+
});
|
|
3296
|
+
else if (!isDownwardReasoningClamp(effort.requested, effort.resolved)) context.addIssue({
|
|
3297
|
+
code: "custom",
|
|
3298
|
+
path: ["resolved"],
|
|
3299
|
+
message: "reasoning effort may clamp down but must never increase"
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
});
|
|
3303
|
+
const agentExecutionPreparationReceiptSchema = z.strictObject({
|
|
3304
|
+
kind: z.literal("agent-execution-preparation"),
|
|
3305
|
+
schemaVersion: z.literal(1),
|
|
3306
|
+
preparationId: nonBlankStringSchema.max(500),
|
|
3307
|
+
requestDigest: sha256DigestSchema$1,
|
|
3308
|
+
authoredProfileDigest: sha256DigestSchema$1,
|
|
3309
|
+
effectiveProfileDigest: sha256DigestSchema$1,
|
|
3310
|
+
backend: nonBlankStringSchema.max(200),
|
|
3311
|
+
harness: harnessTypeSchema$1,
|
|
3312
|
+
harnessVersion: nonBlankStringSchema.max(200),
|
|
3313
|
+
resolvedModel: z.strictObject({
|
|
3314
|
+
requested: z.string().max(500),
|
|
3315
|
+
resolved: nonBlankStringSchema.max(500),
|
|
3316
|
+
provider: z.string().max(200).optional(),
|
|
3317
|
+
reasoningEffort: agentExecutionPreparationReasoningEffortSchema.optional()
|
|
3318
|
+
}),
|
|
3319
|
+
workspace: z.strictObject({
|
|
3320
|
+
leaseId: publicLifecycleIdentifierSchema,
|
|
3321
|
+
provider: publicLifecycleIdentifierSchema,
|
|
3322
|
+
identityDigest: sha256DigestSchema$1,
|
|
3323
|
+
isolation: z.enum(["per-run", "shared"]),
|
|
3324
|
+
sourceSnapshotDigest: sha256DigestSchema$1,
|
|
3325
|
+
sourceSnapshotPolicy: agentWorkspaceSourceSnapshotPolicySchema,
|
|
3326
|
+
preparedWorkspaceDigest: sha256DigestSchema$1,
|
|
3327
|
+
profileActivationDigest: sha256DigestSchema$1
|
|
3328
|
+
}),
|
|
3329
|
+
axisResults: z.array(agentExecutionPreparationAxisResultSchema),
|
|
3330
|
+
executionPlanDigest: sha256DigestSchema$1,
|
|
3331
|
+
materializer: z.strictObject({
|
|
3332
|
+
name: nonBlankStringSchema.max(200),
|
|
3333
|
+
version: nonBlankStringSchema.max(200)
|
|
3334
|
+
}),
|
|
3335
|
+
expiresAtMs: z.number().int().positive().safe(),
|
|
3336
|
+
digest: sha256DigestSchema$1
|
|
3337
|
+
}).superRefine((receipt, context) => {
|
|
3338
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3339
|
+
for (const [index, result] of receipt.axisResults.entries()) {
|
|
3340
|
+
const key = agentExecutionPreparationAxisResultKey(result.axis, result.path);
|
|
3341
|
+
const previous = seen.get(key);
|
|
3342
|
+
if (previous !== void 0) context.addIssue({
|
|
3343
|
+
code: "custom",
|
|
3344
|
+
path: ["axisResults", index],
|
|
3345
|
+
message: agentExecutionPreparationAxisResultsEqual(previous, result) ? "duplicate profile axis/path result" : "conflicting profile axis/path results"
|
|
3346
|
+
});
|
|
3347
|
+
else seen.set(key, result);
|
|
3348
|
+
if (index > 0 && compareAgentExecutionPreparationAxisResults(receipt.axisResults[index - 1], result) >= 0) context.addIssue({
|
|
3349
|
+
code: "custom",
|
|
3350
|
+
path: ["axisResults", index],
|
|
3351
|
+
message: "profile axis/path results must be canonically sorted"
|
|
3352
|
+
});
|
|
3353
|
+
}
|
|
3354
|
+
if (!isCanonicalJsonValue$1(receipt)) context.addIssue({
|
|
3355
|
+
code: "custom",
|
|
3356
|
+
message: "execution preparation receipt must contain only RFC 8785 JSON values"
|
|
3357
|
+
});
|
|
3358
|
+
else if (canonicalCandidateDigest$1(omitTopLevelDigest$1(receipt)) !== receipt.digest) context.addIssue({
|
|
3359
|
+
code: "custom",
|
|
3360
|
+
path: ["digest"],
|
|
3361
|
+
message: "execution preparation receipt digest is invalid"
|
|
3362
|
+
});
|
|
3363
|
+
});
|
|
3364
|
+
/** @internal Canonical identity for one preparation axis and path. */
|
|
3365
|
+
function agentExecutionPreparationAxisResultKey(axis, path) {
|
|
3366
|
+
return `${axis}\u0000${path ?? ""}`;
|
|
3367
|
+
}
|
|
3368
|
+
/** @internal Exact public equality for preparation axis rows. */
|
|
3369
|
+
function agentExecutionPreparationAxisResultsEqual(left, right) {
|
|
3370
|
+
try {
|
|
3371
|
+
return canonicalCandidateJson$1(left) === canonicalCandidateJson$1(right);
|
|
3372
|
+
} catch {
|
|
3373
|
+
return false;
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
const AXIS_ORDER = new Map(AGENT_PROFILE_MATERIALIZATION_AXES.map((axis, index) => [axis, index]));
|
|
3377
|
+
/** @internal Canonical order for preparation axis rows. */
|
|
3378
|
+
function compareAgentExecutionPreparationAxisResults(left, right) {
|
|
3379
|
+
const axisDifference = (AXIS_ORDER.get(left.axis) ?? Number.MAX_SAFE_INTEGER) - (AXIS_ORDER.get(right.axis) ?? Number.MAX_SAFE_INTEGER);
|
|
3380
|
+
if (axisDifference !== 0) return axisDifference;
|
|
3381
|
+
const leftPath = left.path ?? "";
|
|
3382
|
+
const rightPath = right.path ?? "";
|
|
3383
|
+
return leftPath < rightPath ? -1 : leftPath > rightPath ? 1 : 0;
|
|
3384
|
+
}
|
|
3385
|
+
function isCanonicalJsonPointer(value) {
|
|
3386
|
+
if (!value.startsWith("/") || !isWellFormedUnicode$1(value)) return false;
|
|
3387
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
3388
|
+
if (value[index] !== "~") continue;
|
|
3389
|
+
const escape = value[index + 1];
|
|
3390
|
+
if (escape !== "0" && escape !== "1") return false;
|
|
3391
|
+
index += 1;
|
|
3392
|
+
}
|
|
3393
|
+
return true;
|
|
3394
|
+
}
|
|
3395
|
+
function isDownwardReasoningClamp(requested, resolved) {
|
|
3396
|
+
return REASONING_EFFORTS$1.indexOf(resolved) < REASONING_EFFORTS$1.indexOf(requested);
|
|
3397
|
+
}
|
|
3398
|
+
const agentInteractiveDimensionSchema = z.number().int().positive().max(1e4);
|
|
3399
|
+
/** @internal Compare every coordinate of two exact run references. */
|
|
3400
|
+
function sameAgentExactRun(left, right) {
|
|
3401
|
+
return left.runId === right.runId && left.provider === right.provider && left.environmentId === right.environmentId && left.sessionId === right.sessionId && left.executionId === right.executionId && left.requestDigest === right.requestDigest;
|
|
3402
|
+
}
|
|
3403
|
+
//#endregion
|
|
3404
|
+
//#region ../../../node_modules/.pnpm/@tangle-network+agent-interface@5.8.1/node_modules/@tangle-network/agent-interface/dist/environment-interactive-control.js
|
|
3405
|
+
/**
|
|
3406
|
+
* Durable identity of one coding-agent TUI.
|
|
3407
|
+
*
|
|
3408
|
+
* This reference identifies the exact admitted run and preparation receipt.
|
|
3409
|
+
* It is not a generic shell id and cannot be used to create another process.
|
|
3410
|
+
*/
|
|
3411
|
+
const AgentInteractiveSessionRefSchema = z.strictObject({
|
|
3412
|
+
run: AgentExactRunControlRefSchema,
|
|
3413
|
+
/** Canonical executor receipt containing the effective route and its proof. */
|
|
3414
|
+
preparationReceipt: agentExecutionPreparationReceiptSchema,
|
|
3415
|
+
/** Provider-issued identity of this exact process incarnation. */
|
|
3416
|
+
incarnationId: boundedIdentifierSchema$1,
|
|
3417
|
+
startedAt: z.iso.datetime().max(64)
|
|
3418
|
+
});
|
|
3419
|
+
/**
|
|
3420
|
+
* Provider-issued write authority for one exact interactive process.
|
|
3421
|
+
*
|
|
3422
|
+
* Expiry blocks mutations but does not kill the coding process. A coordinator
|
|
3423
|
+
* can issue a new compare-and-swap claim after expiry. The provider's PTY owner
|
|
3424
|
+
* lease remains the separate process-cleanup authority.
|
|
3425
|
+
*/
|
|
3426
|
+
const AgentInteractiveSessionControlClaimSchema = z.strictObject({
|
|
3427
|
+
/** Canonical identity of the process ref this authority can mutate. */
|
|
3428
|
+
refDigest: sha256DigestSchema$1,
|
|
3429
|
+
/** Provider generation. A recovered coordinator must obtain a greater value. */
|
|
3430
|
+
generation: z.number().int().positive().safe(),
|
|
3431
|
+
/** Provider lease identity for this generation. */
|
|
3432
|
+
leaseId: boundedIdentifierSchema$1,
|
|
3433
|
+
/** Stable identity of the coordinator holding this lease. */
|
|
3434
|
+
holderId: boundedIdentifierSchema$1,
|
|
3435
|
+
expiresAt: z.iso.datetime().max(64)
|
|
3436
|
+
});
|
|
3437
|
+
const AgentInteractiveSessionControlClaimRequestMaterialSchema = z.strictObject({
|
|
3438
|
+
operationId: boundedIdentifierSchema$1,
|
|
3439
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3440
|
+
holderId: boundedIdentifierSchema$1,
|
|
3441
|
+
expectedGeneration: z.number().int().nonnegative().safe()
|
|
3442
|
+
});
|
|
3443
|
+
function agentInteractiveSessionControlClaimRequestDigest(value) {
|
|
3444
|
+
const parsed = AgentInteractiveSessionControlClaimRequestMaterialSchema.parse(value);
|
|
3445
|
+
return canonicalCandidateDigest$1({
|
|
3446
|
+
kind: "agent-interactive-session-control-claim.v1",
|
|
3447
|
+
operationId: parsed.operationId,
|
|
3448
|
+
ref: parsed.ref,
|
|
3449
|
+
holderId: parsed.holderId,
|
|
3450
|
+
expectedGeneration: parsed.expectedGeneration
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
const AgentInteractiveSessionControlClaimRequestSchema = z.strictObject({
|
|
3454
|
+
...AgentInteractiveSessionControlClaimRequestMaterialSchema.shape,
|
|
3455
|
+
requestDigest: sha256DigestSchema$1
|
|
3456
|
+
}).superRefine((request, refinement) => {
|
|
3457
|
+
const { requestDigest: _requestDigest, ...material } = request;
|
|
3458
|
+
if (request.requestDigest !== agentInteractiveSessionControlClaimRequestDigest(material)) refinement.addIssue({
|
|
3459
|
+
code: "custom",
|
|
3460
|
+
path: ["requestDigest"],
|
|
3461
|
+
message: "interactive session control claim request digest does not match its content"
|
|
3462
|
+
});
|
|
3463
|
+
});
|
|
3464
|
+
const AgentInteractiveSessionControlClaimAcknowledgementSchema = z.strictObject({
|
|
3465
|
+
operationId: boundedIdentifierSchema$1,
|
|
3466
|
+
requestDigest: sha256DigestSchema$1,
|
|
3467
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3468
|
+
status: z.enum([
|
|
3469
|
+
"accepted",
|
|
3470
|
+
"replayed",
|
|
3471
|
+
"conflict",
|
|
3472
|
+
"unknown"
|
|
3473
|
+
]),
|
|
3474
|
+
control: AgentInteractiveSessionControlClaimSchema.optional(),
|
|
3475
|
+
conflictReason: z.enum(["generation_mismatch", "operation_reuse"]).optional(),
|
|
3476
|
+
currentGeneration: z.number().int().nonnegative().safe().optional(),
|
|
3477
|
+
existingRequestDigest: sha256DigestSchema$1.optional(),
|
|
3478
|
+
message: boundedStringSchema$1.min(1).optional(),
|
|
3479
|
+
retryable: z.boolean().optional()
|
|
3480
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
3481
|
+
const hasControl = acknowledgement.control !== void 0;
|
|
3482
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !hasControl) refinement.addIssue({
|
|
3483
|
+
code: "custom",
|
|
3484
|
+
path: ["control"],
|
|
3485
|
+
message: "an accepted control claim must return its provider claim"
|
|
3486
|
+
});
|
|
3487
|
+
if (acknowledgement.status !== "accepted" && acknowledgement.status !== "replayed" && hasControl) refinement.addIssue({
|
|
3488
|
+
code: "custom",
|
|
3489
|
+
path: ["control"],
|
|
3490
|
+
message: "only an accepted or replayed claim may return control"
|
|
3491
|
+
});
|
|
3492
|
+
if (acknowledgement.status === "conflict" && acknowledgement.conflictReason === void 0) refinement.addIssue({
|
|
3493
|
+
code: "custom",
|
|
3494
|
+
path: ["conflictReason"],
|
|
3495
|
+
message: "a control claim conflict must distinguish generation mismatch from operation reuse"
|
|
3496
|
+
});
|
|
3497
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.conflictReason !== void 0) refinement.addIssue({
|
|
3498
|
+
code: "custom",
|
|
3499
|
+
path: ["conflictReason"],
|
|
3500
|
+
message: "only a control claim conflict may report a conflict reason"
|
|
3501
|
+
});
|
|
3502
|
+
if (hasControl && !agentInteractiveSessionControlClaimMatchesRef(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
3503
|
+
code: "custom",
|
|
3504
|
+
path: ["control", "refDigest"],
|
|
3505
|
+
message: "interactive control claim acknowledgement does not match its process ref"
|
|
3506
|
+
});
|
|
3507
|
+
if (acknowledgement.status === "conflict" && acknowledgement.currentGeneration === void 0) refinement.addIssue({
|
|
3508
|
+
code: "custom",
|
|
3509
|
+
path: ["currentGeneration"],
|
|
3510
|
+
message: "a control claim conflict must report the current generation"
|
|
3511
|
+
});
|
|
3512
|
+
if (acknowledgement.conflictReason === "generation_mismatch" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
3513
|
+
code: "custom",
|
|
3514
|
+
path: ["existingRequestDigest"],
|
|
3515
|
+
message: "a generation mismatch must not be reported as operation reuse"
|
|
3516
|
+
});
|
|
3517
|
+
if (acknowledgement.conflictReason === "operation_reuse" && acknowledgement.existingRequestDigest === void 0) refinement.addIssue({
|
|
3518
|
+
code: "custom",
|
|
3519
|
+
path: ["existingRequestDigest"],
|
|
3520
|
+
message: "operation reuse must report the digest already stored for this operation"
|
|
3521
|
+
});
|
|
3522
|
+
if (acknowledgement.status === "conflict" && acknowledgement.existingRequestDigest === acknowledgement.requestDigest) refinement.addIssue({
|
|
3523
|
+
code: "custom",
|
|
3524
|
+
path: ["existingRequestDigest"],
|
|
3525
|
+
message: "a control claim conflict must identify different request material"
|
|
3526
|
+
});
|
|
3527
|
+
if (acknowledgement.status !== "conflict" && (acknowledgement.currentGeneration !== void 0 || acknowledgement.existingRequestDigest !== void 0)) refinement.addIssue({
|
|
3528
|
+
code: "custom",
|
|
3529
|
+
path: ["currentGeneration"],
|
|
3530
|
+
message: "only a control claim conflict may report existing generation state"
|
|
3531
|
+
});
|
|
3532
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
3533
|
+
code: "custom",
|
|
3534
|
+
path: ["retryable"],
|
|
3535
|
+
message: "an unknown control claim outcome must explicitly permit safe same-operation retry"
|
|
3536
|
+
});
|
|
3537
|
+
});
|
|
3538
|
+
function agentInteractiveSessionControlClaimAcknowledgementMatchesRequest(request, acknowledgement) {
|
|
3539
|
+
const exactRequest = AgentInteractiveSessionControlClaimRequestSchema.safeParse(request);
|
|
3540
|
+
const exactAcknowledgement = AgentInteractiveSessionControlClaimAcknowledgementSchema.safeParse(acknowledgement);
|
|
3541
|
+
if (!exactRequest.success || !exactAcknowledgement.success) return false;
|
|
3542
|
+
return exactAcknowledgement.data.operationId === exactRequest.data.operationId && exactAcknowledgement.data.requestDigest === exactRequest.data.requestDigest && canonicalCandidateDigest$1(exactAcknowledgement.data.ref) === canonicalCandidateDigest$1(exactRequest.data.ref);
|
|
3543
|
+
}
|
|
3544
|
+
/** Bind a provider-issued control claim to the exact process it can mutate. */
|
|
3545
|
+
function agentInteractiveSessionControlClaimMatchesRef(ref, claim) {
|
|
3546
|
+
const parsedRef = AgentInteractiveSessionRefSchema.safeParse(ref);
|
|
3547
|
+
const parsedClaim = AgentInteractiveSessionControlClaimSchema.safeParse(claim);
|
|
3548
|
+
return parsedRef.success && parsedClaim.success && parsedClaim.data.refDigest === canonicalCandidateDigest$1(parsedRef.data);
|
|
3549
|
+
}
|
|
3550
|
+
/** Compare two claims for one process without making a provider state claim. */
|
|
3551
|
+
function agentInteractiveSessionControlClaimIsNewer(candidate, current) {
|
|
3552
|
+
const parsedCandidate = AgentInteractiveSessionControlClaimSchema.safeParse(candidate);
|
|
3553
|
+
const parsedCurrent = AgentInteractiveSessionControlClaimSchema.safeParse(current);
|
|
3554
|
+
return parsedCandidate.success && parsedCurrent.success && parsedCandidate.data.refDigest === parsedCurrent.data.refDigest && parsedCandidate.data.generation > parsedCurrent.data.generation;
|
|
3555
|
+
}
|
|
3556
|
+
/** Geometry for one attachment to the existing coding-agent TUI. */
|
|
3557
|
+
const AgentInteractiveSessionAttachSchema = z.strictObject({
|
|
3558
|
+
/** Required because the returned terminal permits input and resize. */
|
|
3559
|
+
control: AgentInteractiveSessionControlClaimSchema,
|
|
3560
|
+
cols: agentInteractiveDimensionSchema.optional(),
|
|
3561
|
+
rows: agentInteractiveDimensionSchema.optional()
|
|
3562
|
+
});
|
|
3563
|
+
/** Provider-observed lifecycle of one native coding-agent TUI. */
|
|
3564
|
+
const AgentInteractiveSessionStatusSchema = z.discriminatedUnion("state", [
|
|
3565
|
+
z.strictObject({
|
|
3566
|
+
state: z.literal("running"),
|
|
3567
|
+
ref: AgentInteractiveSessionRefSchema
|
|
3568
|
+
}),
|
|
3569
|
+
z.strictObject({
|
|
3570
|
+
state: z.literal("exited"),
|
|
3571
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3572
|
+
endedAt: z.iso.datetime().max(64),
|
|
3573
|
+
reason: z.enum([
|
|
3574
|
+
"exited",
|
|
3575
|
+
"stopped",
|
|
3576
|
+
"lost"
|
|
3577
|
+
]),
|
|
3578
|
+
exitCode: z.number().int().optional(),
|
|
3579
|
+
exitSignal: boundedStringSchema$1.min(1).optional()
|
|
3580
|
+
}),
|
|
3581
|
+
z.strictObject({
|
|
3582
|
+
state: z.literal("unknown"),
|
|
3583
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3584
|
+
message: boundedStringSchema$1.min(1),
|
|
3585
|
+
retryable: z.boolean()
|
|
3586
|
+
})
|
|
3587
|
+
]);
|
|
3588
|
+
const AgentInteractiveSessionStopCommandMaterialSchema = z.strictObject({
|
|
3589
|
+
operationId: boundedIdentifierSchema$1,
|
|
3590
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3591
|
+
control: AgentInteractiveSessionControlClaimSchema
|
|
3592
|
+
}).superRefine((command, refinement) => {
|
|
3593
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(command.ref, command.control)) refinement.addIssue({
|
|
3594
|
+
code: "custom",
|
|
3595
|
+
path: ["control", "refDigest"],
|
|
3596
|
+
message: "interactive stop control claim does not match its process ref"
|
|
3597
|
+
});
|
|
3598
|
+
});
|
|
3599
|
+
function agentInteractiveSessionStopRequestDigest(value) {
|
|
3600
|
+
const parsed = AgentInteractiveSessionStopCommandMaterialSchema.parse(value);
|
|
3601
|
+
return canonicalCandidateDigest$1({
|
|
3602
|
+
kind: "agent-interactive-session-stop.v1",
|
|
3603
|
+
operationId: parsed.operationId,
|
|
3604
|
+
ref: parsed.ref,
|
|
3605
|
+
control: parsed.control
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
const AgentInteractiveSessionStopCommandSchema = z.strictObject({
|
|
3609
|
+
...AgentInteractiveSessionStopCommandMaterialSchema.shape,
|
|
3610
|
+
requestDigest: sha256DigestSchema$1
|
|
3611
|
+
}).superRefine((command, refinement) => {
|
|
3612
|
+
const { requestDigest: _requestDigest, ...material } = command;
|
|
3613
|
+
if (command.requestDigest !== agentInteractiveSessionStopRequestDigest(material)) refinement.addIssue({
|
|
3614
|
+
code: "custom",
|
|
3615
|
+
path: ["requestDigest"],
|
|
3616
|
+
message: "interactive stop request digest does not match its content"
|
|
3617
|
+
});
|
|
3618
|
+
});
|
|
3619
|
+
const AgentInteractiveSessionStopAcknowledgementSchema = z.strictObject({
|
|
3620
|
+
operationId: boundedIdentifierSchema$1,
|
|
3621
|
+
requestDigest: sha256DigestSchema$1,
|
|
3622
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3623
|
+
control: AgentInteractiveSessionControlClaimSchema,
|
|
3624
|
+
status: z.enum([
|
|
3625
|
+
"accepted",
|
|
3626
|
+
"replayed",
|
|
3627
|
+
"conflict",
|
|
3628
|
+
"unknown"
|
|
3629
|
+
]),
|
|
3630
|
+
effect: z.enum([
|
|
3631
|
+
"stop_requested",
|
|
3632
|
+
"stopped",
|
|
3633
|
+
"not_live",
|
|
3634
|
+
"unknown"
|
|
3635
|
+
]),
|
|
3636
|
+
message: boundedStringSchema$1.min(1).optional(),
|
|
3637
|
+
retryable: z.boolean().optional(),
|
|
3638
|
+
existingRequestDigest: sha256DigestSchema$1.optional()
|
|
3639
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
3640
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
3641
|
+
code: "custom",
|
|
3642
|
+
path: ["control", "refDigest"],
|
|
3643
|
+
message: "interactive stop acknowledgement control does not match its process ref"
|
|
3644
|
+
});
|
|
3645
|
+
const known = acknowledgement.effect !== "unknown";
|
|
3646
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && !known || (acknowledgement.status === "conflict" || acknowledgement.status === "unknown") && known) refinement.addIssue({
|
|
3647
|
+
code: "custom",
|
|
3648
|
+
path: ["effect"],
|
|
3649
|
+
message: "interactive stop status and effect certainty do not agree"
|
|
3650
|
+
});
|
|
3651
|
+
if (acknowledgement.status === "conflict" && (acknowledgement.existingRequestDigest === void 0 || acknowledgement.existingRequestDigest === acknowledgement.requestDigest)) refinement.addIssue({
|
|
3652
|
+
code: "custom",
|
|
3653
|
+
path: ["existingRequestDigest"],
|
|
3654
|
+
message: "an interactive stop conflict must identify a different existing request"
|
|
3655
|
+
});
|
|
3656
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
3657
|
+
code: "custom",
|
|
3658
|
+
path: ["existingRequestDigest"],
|
|
3659
|
+
message: "only an interactive stop conflict may include an existing digest"
|
|
3660
|
+
});
|
|
3661
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
3662
|
+
code: "custom",
|
|
3663
|
+
path: ["retryable"],
|
|
3664
|
+
message: "an unknown interactive stop outcome must explicitly permit safe same-operation retry"
|
|
3665
|
+
});
|
|
3666
|
+
});
|
|
3667
|
+
function agentInteractiveSessionStopAcknowledgementMatchesCommand(command, acknowledgement) {
|
|
3668
|
+
const exactCommand = AgentInteractiveSessionStopCommandSchema.safeParse(command);
|
|
3669
|
+
const exactAcknowledgement = AgentInteractiveSessionStopAcknowledgementSchema.safeParse(acknowledgement);
|
|
3670
|
+
if (!exactCommand.success || !exactAcknowledgement.success) return false;
|
|
3671
|
+
return exactAcknowledgement.data.operationId === exactCommand.data.operationId && exactAcknowledgement.data.requestDigest === exactCommand.data.requestDigest && canonicalCandidateDigest$1(exactAcknowledgement.data.ref) === canonicalCandidateDigest$1(exactCommand.data.ref) && canonicalCandidateDigest$1(exactAcknowledgement.data.control) === canonicalCandidateDigest$1(exactCommand.data.control);
|
|
3672
|
+
}
|
|
3673
|
+
const AgentInteractiveSessionPromptCommandMaterialSchema = z.strictObject({
|
|
3674
|
+
operationId: boundedIdentifierSchema$1,
|
|
3675
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3676
|
+
control: AgentInteractiveSessionControlClaimSchema,
|
|
3677
|
+
prompt: boundedEventContentStringSchema$1.refine((value) => value.length >= 1, { message: "interactive prompt must not be empty" })
|
|
3678
|
+
}).superRefine((command, refinement) => {
|
|
3679
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(command.ref, command.control)) refinement.addIssue({
|
|
3680
|
+
code: "custom",
|
|
3681
|
+
path: ["control", "refDigest"],
|
|
3682
|
+
message: "interactive prompt control claim does not match its process ref"
|
|
3683
|
+
});
|
|
3684
|
+
});
|
|
3685
|
+
function agentInteractiveSessionPromptRequestDigest(value) {
|
|
3686
|
+
const parsed = AgentInteractiveSessionPromptCommandMaterialSchema.parse(value);
|
|
3687
|
+
return canonicalCandidateDigest$1({
|
|
3688
|
+
kind: "agent-interactive-session-prompt.v1",
|
|
3689
|
+
operationId: parsed.operationId,
|
|
3690
|
+
ref: parsed.ref,
|
|
3691
|
+
control: parsed.control,
|
|
3692
|
+
prompt: parsed.prompt
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
const AgentInteractiveSessionPromptCommandSchema = z.strictObject({
|
|
3696
|
+
...AgentInteractiveSessionPromptCommandMaterialSchema.shape,
|
|
3697
|
+
requestDigest: sha256DigestSchema$1
|
|
3698
|
+
}).superRefine((command, refinement) => {
|
|
3699
|
+
const { requestDigest: _requestDigest, ...material } = command;
|
|
3700
|
+
if (command.requestDigest !== agentInteractiveSessionPromptRequestDigest(material)) refinement.addIssue({
|
|
3701
|
+
code: "custom",
|
|
3702
|
+
path: ["requestDigest"],
|
|
3703
|
+
message: "interactive session prompt request digest does not match its content"
|
|
3704
|
+
});
|
|
3705
|
+
});
|
|
3706
|
+
const AgentInteractiveSessionPromptAcknowledgementSchema = z.strictObject({
|
|
3707
|
+
operationId: boundedIdentifierSchema$1,
|
|
3708
|
+
requestDigest: sha256DigestSchema$1,
|
|
3709
|
+
ref: AgentInteractiveSessionRefSchema,
|
|
3710
|
+
control: AgentInteractiveSessionControlClaimSchema,
|
|
3711
|
+
status: z.enum([
|
|
3712
|
+
"accepted",
|
|
3713
|
+
"replayed",
|
|
3714
|
+
"conflict",
|
|
3715
|
+
"unknown"
|
|
3716
|
+
]),
|
|
3717
|
+
message: boundedStringSchema$1.min(1).optional(),
|
|
3718
|
+
retryable: z.boolean().optional(),
|
|
3719
|
+
existingRequestDigest: sha256DigestSchema$1.optional()
|
|
3720
|
+
}).superRefine((acknowledgement, refinement) => {
|
|
3721
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(acknowledgement.ref, acknowledgement.control)) refinement.addIssue({
|
|
3722
|
+
code: "custom",
|
|
3723
|
+
path: ["control", "refDigest"],
|
|
3724
|
+
message: "interactive prompt acknowledgement control claim does not match its process ref"
|
|
3725
|
+
});
|
|
3726
|
+
if (acknowledgement.status === "conflict" && (acknowledgement.existingRequestDigest === void 0 || acknowledgement.existingRequestDigest === acknowledgement.requestDigest)) refinement.addIssue({
|
|
3727
|
+
code: "custom",
|
|
3728
|
+
path: ["existingRequestDigest"],
|
|
3729
|
+
message: "an interactive prompt conflict must identify a different existing request"
|
|
3730
|
+
});
|
|
3731
|
+
if (acknowledgement.status !== "conflict" && acknowledgement.existingRequestDigest !== void 0) refinement.addIssue({
|
|
3732
|
+
code: "custom",
|
|
3733
|
+
path: ["existingRequestDigest"],
|
|
3734
|
+
message: "only an interactive prompt conflict may include an existing digest"
|
|
3735
|
+
});
|
|
3736
|
+
if (acknowledgement.status === "unknown" && (acknowledgement.message === void 0 || acknowledgement.retryable !== true)) refinement.addIssue({
|
|
3737
|
+
code: "custom",
|
|
3738
|
+
path: ["retryable"],
|
|
3739
|
+
message: "an unknown interactive prompt outcome must explicitly permit safe same-operation retry"
|
|
3740
|
+
});
|
|
3741
|
+
});
|
|
3742
|
+
function agentInteractiveSessionPromptAcknowledgementMatchesCommand(command, acknowledgement) {
|
|
3743
|
+
const exactCommand = AgentInteractiveSessionPromptCommandSchema.safeParse(command);
|
|
3744
|
+
const exactAcknowledgement = AgentInteractiveSessionPromptAcknowledgementSchema.safeParse(acknowledgement);
|
|
3745
|
+
if (!exactCommand.success || !exactAcknowledgement.success) return false;
|
|
3746
|
+
return exactAcknowledgement.data.operationId === exactCommand.data.operationId && exactAcknowledgement.data.requestDigest === exactCommand.data.requestDigest && canonicalCandidateDigest$1(exactAcknowledgement.data.ref) === canonicalCandidateDigest$1(exactCommand.data.ref) && canonicalCandidateDigest$1(exactAcknowledgement.data.control) === canonicalCandidateDigest$1(exactCommand.data.control);
|
|
3747
|
+
}
|
|
3748
|
+
/** Prove that a status belongs to the handle that requested it. */
|
|
3749
|
+
function agentInteractiveSessionStatusMatchesRef(ref, status) {
|
|
3750
|
+
const parsedRef = AgentInteractiveSessionRefSchema.safeParse(ref);
|
|
3751
|
+
const parsedStatus = AgentInteractiveSessionStatusSchema.safeParse(status);
|
|
3752
|
+
if (!parsedRef.success || !parsedStatus.success) return false;
|
|
3753
|
+
const observed = parsedStatus.data.ref;
|
|
3754
|
+
return observed.preparationReceipt.digest === parsedRef.data.preparationReceipt.digest && observed.incarnationId === parsedRef.data.incarnationId && observed.startedAt === parsedRef.data.startedAt && sameAgentExactRun(observed.run, parsedRef.data.run);
|
|
3755
|
+
}
|
|
3756
|
+
//#endregion
|
|
3757
|
+
//#region ../../../packages/runtime-contracts/dist/interactive-session-control-http.js
|
|
3758
|
+
const interactiveSessionStatusResponseSchema = z.object({
|
|
3759
|
+
success: z.literal(true),
|
|
3760
|
+
data: z.object({ status: AgentInteractiveSessionStatusSchema$1 }).strict()
|
|
3761
|
+
}).strict();
|
|
3762
|
+
const interactiveSessionControlClaimResponseSchema = z.object({
|
|
3763
|
+
success: z.literal(true),
|
|
3764
|
+
data: AgentInteractiveSessionControlClaimAcknowledgementSchema$1
|
|
3765
|
+
}).strict();
|
|
3766
|
+
const interactiveSessionControlReleaseBodySchema = z.object({
|
|
3767
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
3768
|
+
control: AgentInteractiveSessionControlClaimSchema$1
|
|
3769
|
+
}).strict();
|
|
3770
|
+
const interactiveSessionControlReleaseResponseSchema = z.object({
|
|
3771
|
+
success: z.literal(true),
|
|
3772
|
+
data: z.object({ status: z.enum([
|
|
3773
|
+
"released",
|
|
3774
|
+
"already-released",
|
|
3775
|
+
"absent"
|
|
3776
|
+
]) }).strict()
|
|
3777
|
+
}).strict();
|
|
3778
|
+
z.object({
|
|
3779
|
+
ref: AgentInteractiveSessionRefSchema$1,
|
|
3780
|
+
control: AgentInteractiveSessionControlClaimSchema$1
|
|
3781
|
+
}).strict();
|
|
3782
|
+
const interactiveSessionControlValidationResponseSchema = z.object({
|
|
3783
|
+
success: z.literal(true),
|
|
3784
|
+
data: z.object({ valid: z.literal(true) }).strict()
|
|
3785
|
+
}).strict();
|
|
3786
|
+
//#endregion
|
|
3787
|
+
//#region src/interactive-control-controller.ts
|
|
3788
|
+
/** A status response that cannot admit a terminal control claim. */
|
|
3789
|
+
var InteractiveSessionNotRunningError = class extends Error {
|
|
3790
|
+
constructor(status) {
|
|
3791
|
+
super("Interactive session is not running or has stale identity");
|
|
3792
|
+
this.status = status;
|
|
3793
|
+
this.name = "InteractiveSessionNotRunningError";
|
|
3794
|
+
}
|
|
3795
|
+
};
|
|
3796
|
+
/** Maximum time spent on bounded claim recovery and release cleanup. */
|
|
3797
|
+
const INTERACTIVE_CONTROL_CLEANUP_TIMEOUT_MS = 5e3;
|
|
3798
|
+
function randomId(prefix) {
|
|
3799
|
+
const cryptoApi = globalThis.crypto;
|
|
3800
|
+
if (cryptoApi && typeof cryptoApi.randomUUID === "function") return `${prefix}-${cryptoApi.randomUUID()}`;
|
|
3801
|
+
return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
3802
|
+
}
|
|
3803
|
+
/** Create a holder id for one in-memory interactive controller. */
|
|
3804
|
+
function createInteractiveControlHolderId(prefix = "interactive") {
|
|
3805
|
+
return randomId(prefix);
|
|
3806
|
+
}
|
|
3807
|
+
function assertInteractiveSessionRef(ref, options) {
|
|
3808
|
+
if (ref.run.sessionId !== options.sessionId || ref.incarnationId !== options.incarnationId || options.environmentId !== void 0 && ref.run.environmentId !== options.environmentId) throw new Error("Interactive session identity does not match this sandbox");
|
|
3809
|
+
}
|
|
3810
|
+
function assertActiveControlClaim(control) {
|
|
3811
|
+
const expiresAt = Date.parse(control.expiresAt);
|
|
3812
|
+
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) throw new Error("Interactive control claim is stale");
|
|
3813
|
+
}
|
|
3814
|
+
function createCleanupScope(timeoutMs) {
|
|
3815
|
+
const controller = new AbortController();
|
|
3816
|
+
const timer = setTimeout(() => {
|
|
3817
|
+
controller.abort(new DOMException(`Interactive control cleanup timed out after ${timeoutMs}ms`, "TimeoutError"));
|
|
3818
|
+
}, timeoutMs);
|
|
3819
|
+
return {
|
|
3820
|
+
signal: controller.signal,
|
|
3821
|
+
dispose: () => clearTimeout(timer)
|
|
3822
|
+
};
|
|
3823
|
+
}
|
|
3824
|
+
function claimAcknowledgementMatchesRequest(ref, request, acknowledgement) {
|
|
3825
|
+
if (!agentInteractiveSessionControlClaimAcknowledgementMatchesRequest(request, acknowledgement)) return false;
|
|
3826
|
+
if (acknowledgement.status !== "accepted" && acknowledgement.status !== "replayed") return true;
|
|
3827
|
+
return acknowledgement.control !== void 0 && agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control) && acknowledgement.control.holderId === request.holderId;
|
|
3828
|
+
}
|
|
3829
|
+
/**
|
|
3830
|
+
* Own the one status → claim → release sequence shared by browser and SDK callers.
|
|
3831
|
+
*
|
|
3832
|
+
* This module deliberately has no terminal or WebSocket dependency. Attach-capable
|
|
3833
|
+
* callers extend it with the stream operation after a claim has been resolved.
|
|
3834
|
+
*/
|
|
3835
|
+
var InteractiveSessionControlController = class {
|
|
3836
|
+
operationIdFactory;
|
|
3837
|
+
cleanupTimeoutMs;
|
|
3838
|
+
resolveInFlight;
|
|
3839
|
+
constructor(transport, options) {
|
|
3840
|
+
this.transport = transport;
|
|
3841
|
+
this.options = options;
|
|
3842
|
+
this.operationIdFactory = options.operationIdFactory ?? (() => randomId("interactive-claim"));
|
|
3843
|
+
this.cleanupTimeoutMs = options.cleanupTimeoutMs ?? 5e3;
|
|
3844
|
+
if (!Number.isFinite(this.cleanupTimeoutMs) || this.cleanupTimeoutMs <= 0) throw new RangeError("Interactive control cleanup timeout must be greater than zero");
|
|
3845
|
+
}
|
|
3846
|
+
async safelyReleaseClaim(identity) {
|
|
3847
|
+
const cleanupScope = createCleanupScope(this.cleanupTimeoutMs);
|
|
3848
|
+
try {
|
|
3849
|
+
await awaitWithAbort(this.release(identity, { signal: cleanupScope.signal }), cleanupScope.signal);
|
|
3850
|
+
} catch {} finally {
|
|
3851
|
+
cleanupScope.dispose();
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
/**
|
|
3855
|
+
* Recover a claim whose response or commit may have been lost or corrupted.
|
|
3856
|
+
*
|
|
3857
|
+
* The same operation id and digest make this replay idempotent. Recovery uses
|
|
3858
|
+
* an independent bounded signal so caller abort cannot strand an invisible claim.
|
|
3859
|
+
*/
|
|
3860
|
+
async recoverAmbiguousClaim(ref, request) {
|
|
3861
|
+
const cleanupScope = createCleanupScope(this.cleanupTimeoutMs);
|
|
3862
|
+
try {
|
|
3863
|
+
const acknowledgement = AgentInteractiveSessionControlClaimAcknowledgementSchema.parse(await awaitWithAbort(this.transport.claimControl(this.options.sessionId, request, { signal: cleanupScope.signal }), cleanupScope.signal));
|
|
3864
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && acknowledgement.control !== void 0 && claimAcknowledgementMatchesRequest(ref, request, acknowledgement) && agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control)) await this.safelyReleaseClaim({
|
|
3865
|
+
ref,
|
|
3866
|
+
control: acknowledgement.control
|
|
3867
|
+
});
|
|
3868
|
+
} catch {} finally {
|
|
3869
|
+
cleanupScope.dispose();
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
/** Release one claim that this controller resolved. */
|
|
3873
|
+
async release(identity, requestOptions) {
|
|
3874
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3875
|
+
const exactRef = AgentInteractiveSessionRefSchema.parse(identity.ref);
|
|
3876
|
+
assertInteractiveSessionRef(exactRef, this.options);
|
|
3877
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(exactRef, identity.control)) throw new Error("Interactive control claim is not bound to the session");
|
|
3878
|
+
await this.transport.releaseControl(this.options.sessionId, exactRef, identity.control, requestOptions);
|
|
3879
|
+
}
|
|
3880
|
+
/** Observe and claim the current exact process incarnation. */
|
|
3881
|
+
async resolve(requestOptions) {
|
|
3882
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3883
|
+
if (this.resolveInFlight !== void 0) return await awaitWithAbort(this.resolveInFlight, requestOptions?.signal);
|
|
3884
|
+
const operation = this.resolveInternal(requestOptions);
|
|
3885
|
+
let tracked;
|
|
3886
|
+
tracked = operation.finally(() => {
|
|
3887
|
+
if (this.resolveInFlight === tracked) this.resolveInFlight = void 0;
|
|
3888
|
+
});
|
|
3889
|
+
this.resolveInFlight = tracked;
|
|
3890
|
+
return await tracked;
|
|
3891
|
+
}
|
|
3892
|
+
async resolveInternal(requestOptions) {
|
|
3893
|
+
let claimedIdentity;
|
|
3894
|
+
try {
|
|
3895
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3896
|
+
const status = await this.transport.status(this.options.sessionId, this.options.incarnationId, requestOptions);
|
|
3897
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3898
|
+
if (status?.state !== "running") throw new InteractiveSessionNotRunningError(status);
|
|
3899
|
+
const ref = AgentInteractiveSessionRefSchema.parse(status.ref);
|
|
3900
|
+
assertInteractiveSessionRef(ref, this.options);
|
|
3901
|
+
let expectedGeneration = 1;
|
|
3902
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
3903
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3904
|
+
const material = {
|
|
3905
|
+
operationId: this.operationIdFactory(),
|
|
3906
|
+
ref,
|
|
3907
|
+
holderId: this.options.holderId,
|
|
3908
|
+
expectedGeneration
|
|
3909
|
+
};
|
|
3910
|
+
const request = AgentInteractiveSessionControlClaimRequestSchema.parse({
|
|
3911
|
+
...material,
|
|
3912
|
+
requestDigest: agentInteractiveSessionControlClaimRequestDigest(material)
|
|
3913
|
+
});
|
|
3914
|
+
let acknowledgement;
|
|
3915
|
+
try {
|
|
3916
|
+
acknowledgement = AgentInteractiveSessionControlClaimAcknowledgementSchema.parse(await this.transport.claimControl(this.options.sessionId, request, requestOptions));
|
|
3917
|
+
} catch (error) {
|
|
3918
|
+
await this.recoverAmbiguousClaim(ref, request);
|
|
3919
|
+
throw error;
|
|
3920
|
+
}
|
|
3921
|
+
if (!claimAcknowledgementMatchesRequest(ref, request, acknowledgement)) {
|
|
3922
|
+
await this.recoverAmbiguousClaim(ref, request);
|
|
3923
|
+
throw new Error("Interactive control claim acknowledgement does not match the request");
|
|
3924
|
+
}
|
|
3925
|
+
if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && acknowledgement.control) {
|
|
3926
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control)) throw new Error("Interactive control claim is not bound to the session");
|
|
3927
|
+
claimedIdentity = {
|
|
3928
|
+
ref,
|
|
3929
|
+
control: acknowledgement.control
|
|
3930
|
+
};
|
|
3931
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3932
|
+
assertActiveControlClaim(acknowledgement.control);
|
|
3933
|
+
return claimedIdentity;
|
|
3934
|
+
}
|
|
3935
|
+
requestOptions?.signal?.throwIfAborted();
|
|
3936
|
+
if (acknowledgement.status === "conflict" && acknowledgement.conflictReason === "generation_mismatch" && acknowledgement.currentGeneration !== void 0 && acknowledgement.currentGeneration > expectedGeneration) {
|
|
3937
|
+
expectedGeneration = acknowledgement.currentGeneration;
|
|
3938
|
+
continue;
|
|
3939
|
+
}
|
|
3940
|
+
throw new Error(acknowledgement.message ?? "Interactive control is held by another client");
|
|
3941
|
+
}
|
|
3942
|
+
throw new Error("Interactive control claim became stale during attach");
|
|
3943
|
+
} catch (error) {
|
|
3944
|
+
if (claimedIdentity !== void 0) await this.safelyReleaseClaim(claimedIdentity);
|
|
3945
|
+
throw error;
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
/** Expose the canonical ref digest used by persisted control identities. */
|
|
3949
|
+
static identityDigest(identity) {
|
|
3950
|
+
const ref = AgentInteractiveSessionRefSchema.parse(identity.ref);
|
|
3951
|
+
const control = AgentInteractiveSessionControlClaimSchema.parse(identity.control);
|
|
3952
|
+
if (!agentInteractiveSessionControlClaimMatchesRef(ref, control)) throw new Error("Interactive control claim is not bound to the session");
|
|
3953
|
+
return control.refDigest;
|
|
3954
|
+
}
|
|
3955
|
+
};
|
|
3956
|
+
/** Expose the same digest used to bind persistence and control identities. */
|
|
3957
|
+
function interactiveSessionIdentityDigest(identity) {
|
|
3958
|
+
return InteractiveSessionControlController.identityDigest(identity);
|
|
3959
|
+
}
|
|
3960
|
+
//#endregion
|
|
3961
|
+
//#region src/browser-interactive-control-controller.ts
|
|
3962
|
+
function browserInteractiveSessionEndpoint(baseUrl, sessionId, suffix = "") {
|
|
3963
|
+
return `${baseUrl.replace(/\/+$/, "")}/agents/sessions/${encodeURIComponent(sessionId)}/interactive${suffix}`;
|
|
3964
|
+
}
|
|
3965
|
+
function browserInteractiveTerminalEndpoint(baseUrl, sessionId) {
|
|
3966
|
+
return `${baseUrl.replace(/\/+$/, "")}/terminals/${encodeURIComponent(sessionId)}/ws`;
|
|
3967
|
+
}
|
|
3968
|
+
function authHeaders(token, includeContentType = false) {
|
|
3969
|
+
return {
|
|
3970
|
+
Authorization: `Bearer ${token}`,
|
|
3971
|
+
...includeContentType ? { "Content-Type": "application/json" } : {}
|
|
3972
|
+
};
|
|
3973
|
+
}
|
|
3974
|
+
async function readError(response) {
|
|
3975
|
+
if (response.status === 404) return /* @__PURE__ */ new Error("Interactive session identity is stale or no longer exists");
|
|
3976
|
+
return /* @__PURE__ */ new Error(`Interactive session request failed (${response.status})`);
|
|
3977
|
+
}
|
|
3978
|
+
function createBrowserInteractiveSessionControlTransport(options) {
|
|
3979
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
3980
|
+
if (typeof fetchImpl !== "function") throw new Error("Interactive browser controller requires fetch");
|
|
3981
|
+
return {
|
|
3982
|
+
async status(sessionId, incarnationId, requestOptions) {
|
|
3983
|
+
const response = await fetchImpl(`${browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId)}?incarnationId=${encodeURIComponent(incarnationId)}`, {
|
|
3984
|
+
headers: authHeaders(options.token),
|
|
3985
|
+
...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
|
|
3986
|
+
});
|
|
3987
|
+
if (response.status === 404) return null;
|
|
3988
|
+
if (!response.ok) throw await readError(response);
|
|
3989
|
+
const parsed = interactiveSessionStatusResponseSchema.safeParse(await response.json());
|
|
3990
|
+
if (!parsed.success) throw new Error("Interactive session is not running or has stale identity");
|
|
3991
|
+
return parsed.data.data.status;
|
|
3992
|
+
},
|
|
3993
|
+
async claimControl(sessionId, request, requestOptions) {
|
|
3994
|
+
const response = await fetchImpl(browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId, "/control"), {
|
|
3995
|
+
method: "POST",
|
|
3996
|
+
headers: authHeaders(options.token, true),
|
|
3997
|
+
body: JSON.stringify(request),
|
|
3998
|
+
...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
|
|
3999
|
+
});
|
|
4000
|
+
if (!response.ok) throw await readError(response);
|
|
4001
|
+
const parsed = interactiveSessionControlClaimResponseSchema.safeParse(await response.json());
|
|
4002
|
+
if (!parsed.success) throw new Error("Interactive control claim response is invalid");
|
|
4003
|
+
return parsed.data.data;
|
|
4004
|
+
},
|
|
4005
|
+
async releaseControl(sessionId, ref, control, requestOptions) {
|
|
4006
|
+
const body = interactiveSessionControlReleaseBodySchema.parse({
|
|
4007
|
+
ref,
|
|
4008
|
+
control
|
|
4009
|
+
});
|
|
4010
|
+
const response = await fetchImpl(browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId, "/control/release"), {
|
|
4011
|
+
method: "POST",
|
|
4012
|
+
headers: authHeaders(options.token, true),
|
|
4013
|
+
body: JSON.stringify(body),
|
|
4014
|
+
...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
|
|
4015
|
+
});
|
|
4016
|
+
if (!response.ok) throw await readError(response);
|
|
4017
|
+
if (!interactiveSessionControlReleaseResponseSchema.safeParse(await response.json()).success) throw new Error("Interactive control release response is invalid");
|
|
4018
|
+
}
|
|
4019
|
+
};
|
|
4020
|
+
}
|
|
4021
|
+
/** Browser controller for status, claim, and release without terminal attach. */
|
|
4022
|
+
var BrowserInteractiveSessionControlController = class extends InteractiveSessionControlController {
|
|
4023
|
+
constructor(options) {
|
|
4024
|
+
super(createBrowserInteractiveSessionControlTransport(options), options);
|
|
4025
|
+
}
|
|
4026
|
+
};
|
|
4027
|
+
/**
|
|
4028
|
+
* Return one stable browser holder per exact sandbox process incarnation.
|
|
4029
|
+
* Storage failures produce a new holder and never reuse persisted authority.
|
|
4030
|
+
*/
|
|
4031
|
+
function browserInteractiveControlHolderId(environmentId, sessionId, incarnationId) {
|
|
4032
|
+
const key = `tangle.interactive.control-holder:${environmentId}:${sessionId}:${incarnationId}`;
|
|
4033
|
+
try {
|
|
4034
|
+
const storage = globalThis.sessionStorage;
|
|
4035
|
+
const existing = storage.getItem(key);
|
|
4036
|
+
if (existing) return existing;
|
|
4037
|
+
const holderId = createInteractiveControlHolderId("browser");
|
|
4038
|
+
storage.setItem(key, holderId);
|
|
4039
|
+
return holderId;
|
|
4040
|
+
} catch {
|
|
4041
|
+
return createInteractiveControlHolderId("browser");
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
//#endregion
|
|
4045
|
+
export { agentInteractiveSessionStopAcknowledgementMatchesCommand as A, InteractionAcknowledgementSchema as B, AgentInteractiveSessionStopCommandSchema as C, agentInteractiveSessionPromptAcknowledgementMatchesCommand as D, agentInteractiveSessionControlClaimMatchesRef as E, AgentRunCancellationRequestSchema as F, AgentInteractiveSessionPromptAcknowledgementSchema$1 as G, InteractionResponseCommandSchema as H, agentRunCancellationAcknowledgementMatchesRequest as I, AgentInteractiveSessionStopAcknowledgementSchema$1 as J, AgentInteractiveSessionRefSchema$1 as K, AgentExecutionOutcomeSchema as L, sameAgentExactRun as M, AgentExactRunControlRefSchema as N, agentInteractiveSessionPromptRequestDigest as O, AgentRunCancellationAcknowledgementSchema as P, DurablePlanSchema as R, AgentInteractiveSessionStopAcknowledgementSchema as S, agentInteractiveSessionControlClaimIsNewer as T, InteractionResponseSchema as U, InteractionRequestSchema as V, AgentInteractiveSessionControlClaimSchema$1 as W, InteractionBindingSchema$1 as Y, AgentInteractiveSessionControlClaimRequestSchema as _, INTERACTIVE_CONTROL_CLEANUP_TIMEOUT_MS as a, AgentInteractiveSessionPromptCommandSchema as b, assertInteractiveSessionRef as c, interactiveSessionControlClaimResponseSchema as d, interactiveSessionControlReleaseResponseSchema as f, AgentInteractiveSessionControlClaimAcknowledgementSchema as g, AgentInteractiveSessionAttachSchema as h, createBrowserInteractiveSessionControlTransport as i, agentInteractiveDimensionSchema as j, agentInteractiveSessionStatusMatchesRef as k, createInteractiveControlHolderId as l, interactiveSessionStatusResponseSchema as m, browserInteractiveControlHolderId as n, InteractiveSessionControlController as o, interactiveSessionControlValidationResponseSchema as p, AgentInteractiveSessionStatusSchema$1 as q, browserInteractiveTerminalEndpoint as r, InteractiveSessionNotRunningError as s, BrowserInteractiveSessionControlController as t, interactiveSessionIdentityDigest as u, AgentInteractiveSessionControlClaimSchema as v, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest as w, AgentInteractiveSessionRefSchema as x, AgentInteractiveSessionPromptAcknowledgementSchema as y, PlanContinuationSchema as z };
|