@tangle-network/agent-interface 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contract-limits.d.ts +13 -0
- package/dist/contract-limits.js +163 -0
- package/dist/environment-interactive-control.d.ts +1 -1
- package/dist/environment-interactive-control.js +8 -2
- package/dist/environment-runtime.d.ts +3 -3
- package/dist/environment-runtime.js +10 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/portable-context-continuation.d.ts +1 -1
- package/dist/portable-context-continuation.js +3 -2
- package/dist/runtime-control.d.ts +0 -1
- package/dist/runtime-control.js +26 -14
- package/package.json +1 -1
|
@@ -18,10 +18,23 @@ export declare const boundedIdentifierSchema: z.ZodString;
|
|
|
18
18
|
* checked before canonical serialization.
|
|
19
19
|
*/
|
|
20
20
|
export declare function isBoundedJsonValue(value: unknown): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validate provider event and terminal content. Unlike ordinary metadata,
|
|
23
|
+
* content may contain a single large transcript or tool result. It remains
|
|
24
|
+
* finite, plain JSON with the normal structural limits, and its complete JSON
|
|
25
|
+
* representation is capped exactly by UTF-8 bytes.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isBoundedEventContentJson(value: unknown, { omitUndefinedObjectFields }?: {
|
|
28
|
+
omitUndefinedObjectFields?: boolean;
|
|
29
|
+
}): boolean;
|
|
21
30
|
/** Validate digest input while matching JSON's omission of undefined object fields. */
|
|
22
31
|
export declare function isBoundedJsonMaterial(value: unknown): boolean;
|
|
23
32
|
export declare const boundedJsonSchema: z.ZodCustom<unknown, unknown>;
|
|
24
33
|
export declare const boundedJsonRecordSchema: z.ZodCustom<Record<string, unknown>, Record<string, unknown>>;
|
|
34
|
+
/** One provider event payload or terminal response, bounded as serialized UTF-8 JSON. */
|
|
35
|
+
export declare const boundedEventContentJsonSchema: z.ZodCustom<unknown, unknown>;
|
|
36
|
+
export declare const boundedEventContentRecordSchema: z.ZodCustom<Record<string, unknown>, Record<string, unknown>>;
|
|
37
|
+
export declare const boundedEventContentStringSchema: z.ZodCustom<string, string>;
|
|
25
38
|
export declare function assertBoundedJson(value: unknown): void;
|
|
26
39
|
export declare function assertBoundedSerializedJson(value: string): void;
|
|
27
40
|
/** Copy arbitrary metadata into a map that cannot inherit prototype keys. */
|
package/dist/contract-limits.js
CHANGED
|
@@ -84,6 +84,162 @@ export function isBoundedJsonValue(value) {
|
|
|
84
84
|
}
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
|
+
/** Exact serialized JSON UTF-8 byte count for one string scalar. */
|
|
88
|
+
function serializedJsonStringBytes(value) {
|
|
89
|
+
let bytes = 2; // Opening and closing quotes.
|
|
90
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
91
|
+
const code = value.charCodeAt(index);
|
|
92
|
+
if (code === 0x22 || code === 0x5c || code === 0x08 || code === 0x0c || code === 0x0a || code === 0x0d || code === 0x09) {
|
|
93
|
+
bytes += 2;
|
|
94
|
+
}
|
|
95
|
+
else if (code < 0x20) {
|
|
96
|
+
bytes += 6;
|
|
97
|
+
}
|
|
98
|
+
else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length) {
|
|
99
|
+
const next = value.charCodeAt(index + 1);
|
|
100
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
101
|
+
bytes += 4;
|
|
102
|
+
index += 1;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
bytes += 6;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (code >= 0xd800 && code <= 0xdfff) {
|
|
109
|
+
bytes += 6;
|
|
110
|
+
}
|
|
111
|
+
else if (code < 0x80) {
|
|
112
|
+
bytes += 1;
|
|
113
|
+
}
|
|
114
|
+
else if (code < 0x800) {
|
|
115
|
+
bytes += 2;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
bytes += 3;
|
|
119
|
+
}
|
|
120
|
+
if (bytes > CONTRACT_MAX_JSON_BYTES)
|
|
121
|
+
return bytes;
|
|
122
|
+
}
|
|
123
|
+
return bytes;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate provider event and terminal content. Unlike ordinary metadata,
|
|
127
|
+
* content may contain a single large transcript or tool result. It remains
|
|
128
|
+
* finite, plain JSON with the normal structural limits, and its complete JSON
|
|
129
|
+
* representation is capped exactly by UTF-8 bytes.
|
|
130
|
+
*/
|
|
131
|
+
export function isBoundedEventContentJson(value, { omitUndefinedObjectFields = false } = {}) {
|
|
132
|
+
const pending = [
|
|
133
|
+
{ value, depth: 0 },
|
|
134
|
+
];
|
|
135
|
+
const ancestors = new Set();
|
|
136
|
+
let nodes = 0;
|
|
137
|
+
let bytes = 0;
|
|
138
|
+
const addBytes = (additional) => {
|
|
139
|
+
bytes += additional;
|
|
140
|
+
return bytes <= CONTRACT_MAX_JSON_BYTES;
|
|
141
|
+
};
|
|
142
|
+
while (pending.length > 0) {
|
|
143
|
+
const item = pending.pop();
|
|
144
|
+
if (!item)
|
|
145
|
+
continue;
|
|
146
|
+
const current = item.value;
|
|
147
|
+
if (current === undefined && item.omitUndefined === true)
|
|
148
|
+
continue;
|
|
149
|
+
nodes += 1;
|
|
150
|
+
if (nodes > CONTRACT_MAX_JSON_NODES)
|
|
151
|
+
return false;
|
|
152
|
+
if (item.leave) {
|
|
153
|
+
ancestors.delete(current);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (current === null) {
|
|
157
|
+
if (!addBytes(4))
|
|
158
|
+
return false;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (typeof current === "boolean") {
|
|
162
|
+
if (!addBytes(current ? 4 : 5))
|
|
163
|
+
return false;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (typeof current === "string") {
|
|
167
|
+
if (!addBytes(serializedJsonStringBytes(current)))
|
|
168
|
+
return false;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (typeof current === "number") {
|
|
172
|
+
if (!Number.isFinite(current))
|
|
173
|
+
return false;
|
|
174
|
+
if (!addBytes(JSON.stringify(current).length))
|
|
175
|
+
return false;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (typeof current !== "object" || item.depth >= CONTRACT_MAX_JSON_DEPTH) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (ancestors.has(current))
|
|
182
|
+
return false;
|
|
183
|
+
ancestors.add(current);
|
|
184
|
+
pending.push({ value: current, depth: item.depth, leave: true });
|
|
185
|
+
if (Array.isArray(current)) {
|
|
186
|
+
if (current.length > CONTRACT_MAX_ARRAY_LENGTH)
|
|
187
|
+
return false;
|
|
188
|
+
if (!addBytes(2 + Math.max(current.length - 1, 0)))
|
|
189
|
+
return false;
|
|
190
|
+
const prototype = Object.getPrototypeOf(current);
|
|
191
|
+
if (prototype !== Array.prototype && prototype !== null)
|
|
192
|
+
return false;
|
|
193
|
+
const keys = Reflect.ownKeys(current);
|
|
194
|
+
const entryKeys = keys.filter((key) => key !== "length");
|
|
195
|
+
if (entryKeys.length !== current.length)
|
|
196
|
+
return false;
|
|
197
|
+
if (entryKeys.some((key) => {
|
|
198
|
+
if (typeof key !== "string" || !/^(?:0|[1-9][0-9]*)$/u.test(key))
|
|
199
|
+
return true;
|
|
200
|
+
const index = Number(key);
|
|
201
|
+
return !Number.isSafeInteger(index) || index < 0 || index >= current.length || index >= 4_294_967_295;
|
|
202
|
+
})) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
for (const key of entryKeys) {
|
|
206
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
207
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor))
|
|
208
|
+
return false;
|
|
209
|
+
pending.push({ value: descriptor.value, depth: item.depth + 1 });
|
|
210
|
+
}
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const prototype = Object.getPrototypeOf(current);
|
|
214
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
215
|
+
return false;
|
|
216
|
+
const entries = [];
|
|
217
|
+
for (const key of Reflect.ownKeys(current)) {
|
|
218
|
+
if (typeof key !== "string" || key.length > CONTRACT_MAX_IDENTIFIER_LENGTH)
|
|
219
|
+
return false;
|
|
220
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
221
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor))
|
|
222
|
+
return false;
|
|
223
|
+
if (descriptor.value === undefined && omitUndefinedObjectFields)
|
|
224
|
+
continue;
|
|
225
|
+
entries.push([key, descriptor]);
|
|
226
|
+
if (entries.length > CONTRACT_MAX_MAP_ENTRIES)
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
if (!addBytes(2 + Math.max(entries.length - 1, 0)))
|
|
230
|
+
return false;
|
|
231
|
+
for (const [key, descriptor] of entries) {
|
|
232
|
+
if (!addBytes(serializedJsonStringBytes(key) + 1))
|
|
233
|
+
return false;
|
|
234
|
+
pending.push({
|
|
235
|
+
value: descriptor.value,
|
|
236
|
+
depth: item.depth + 1,
|
|
237
|
+
omitUndefined: omitUndefinedObjectFields,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
87
243
|
/** Validate digest input while matching JSON's omission of undefined object fields. */
|
|
88
244
|
export function isBoundedJsonMaterial(value) {
|
|
89
245
|
const pending = [{ value, depth: 0 }];
|
|
@@ -158,6 +314,13 @@ export const boundedJsonRecordSchema = z.custom((value) => typeof value === "obj
|
|
|
158
314
|
value !== null &&
|
|
159
315
|
!Array.isArray(value) &&
|
|
160
316
|
isBoundedJsonValue(value), { message: "metadata exceeds the contract bounds or is not a JSON object" });
|
|
317
|
+
/** One provider event payload or terminal response, bounded as serialized UTF-8 JSON. */
|
|
318
|
+
export const boundedEventContentJsonSchema = z.custom(isBoundedEventContentJson, { message: "event content exceeds its serialized byte bound or is not finite JSON" });
|
|
319
|
+
export const boundedEventContentRecordSchema = z.custom((value) => typeof value === "object" &&
|
|
320
|
+
value !== null &&
|
|
321
|
+
!Array.isArray(value) &&
|
|
322
|
+
isBoundedEventContentJson(value), { message: "event content exceeds its serialized byte bound or is not a JSON object" });
|
|
323
|
+
export const boundedEventContentStringSchema = z.custom((value) => typeof value === "string" && isBoundedEventContentJson(value), { message: "event content exceeds its serialized byte bound or is not a string" });
|
|
161
324
|
export function assertBoundedJson(value) {
|
|
162
325
|
if (!isBoundedJsonValue(value)) {
|
|
163
326
|
throw new Error("value exceeds the contract bounds or is not finite JSON");
|
|
@@ -1512,7 +1512,7 @@ export declare const AgentInteractiveSessionPromptCommandSchema: z.ZodObject<{
|
|
|
1512
1512
|
holderId: z.ZodString;
|
|
1513
1513
|
expiresAt: z.ZodISODateTime;
|
|
1514
1514
|
}, z.core.$strict>;
|
|
1515
|
-
prompt: z.
|
|
1515
|
+
prompt: z.ZodCustom<string, string>;
|
|
1516
1516
|
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
1517
1517
|
}, z.core.$strict>;
|
|
1518
1518
|
export interface AgentInteractiveSessionPromptAcknowledgement {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { canonicalCandidateDigest, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
|
|
3
3
|
import { agentExecutionPreparationReceiptSchema, } from "./agent-execution-preparation-receipt.js";
|
|
4
|
-
import { boundedIdentifierSchema, boundedStringSchema, } from "./contract-limits.js";
|
|
4
|
+
import { boundedIdentifierSchema, boundedEventContentStringSchema, boundedStringSchema, } from "./contract-limits.js";
|
|
5
5
|
import { agentInteractiveDimensionSchema as interactiveDimensionSchema, sameAgentExactRun as sameExactRun, } from "./environment-interactive-shared.js";
|
|
6
6
|
import { AgentExactRunControlRefSchema } from "./runtime-control.js";
|
|
7
7
|
/**
|
|
@@ -348,7 +348,13 @@ const AgentInteractiveSessionPromptCommandMaterialSchema = z
|
|
|
348
348
|
operationId: boundedIdentifierSchema,
|
|
349
349
|
ref: AgentInteractiveSessionRefSchema,
|
|
350
350
|
control: AgentInteractiveSessionControlClaimSchema,
|
|
351
|
-
|
|
351
|
+
// Content, not metadata: see environment-runtime.ts.
|
|
352
|
+
// Content, not metadata: see environment-runtime.ts. `boundedEventContentStringSchema` is a
|
|
353
|
+
// custom schema and carries no `.min`, so the non-empty requirement is kept as a refinement —
|
|
354
|
+
// an interactive prompt with nothing in it is still refused.
|
|
355
|
+
prompt: boundedEventContentStringSchema.refine((value) => value.length >= 1, {
|
|
356
|
+
message: "interactive prompt must not be empty",
|
|
357
|
+
}),
|
|
352
358
|
})
|
|
353
359
|
.superRefine((command, refinement) => {
|
|
354
360
|
if (!agentInteractiveSessionControlClaimMatchesRef(command.ref, command.control)) {
|
|
@@ -38,7 +38,7 @@ export interface AgentTurnInput {
|
|
|
38
38
|
providerOptions?: Record<string, unknown>;
|
|
39
39
|
}
|
|
40
40
|
export declare const AgentTurnInputSchema: z.ZodObject<{
|
|
41
|
-
prompt: z.ZodOptional<z.
|
|
41
|
+
prompt: z.ZodOptional<z.ZodCustom<string, string>>;
|
|
42
42
|
parts: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
43
43
|
type: z.ZodLiteral<"text">;
|
|
44
44
|
text: z.ZodString;
|
|
@@ -257,7 +257,7 @@ export interface AgentTurnResult {
|
|
|
257
257
|
}
|
|
258
258
|
/** Runtime validator for a provider turn returned from durable continuation. */
|
|
259
259
|
export declare const AgentTurnResultSchema: z.ZodObject<{
|
|
260
|
-
text: z.
|
|
260
|
+
text: z.ZodCustom<string, string>;
|
|
261
261
|
success: z.ZodBoolean;
|
|
262
262
|
error: z.ZodOptional<z.ZodString>;
|
|
263
263
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
@@ -413,7 +413,7 @@ export declare const AgentNativeContextContinuationResultSchema: z.ZodUnion<read
|
|
|
413
413
|
}>;
|
|
414
414
|
}, z.core.$strip>>;
|
|
415
415
|
result: z.ZodObject<{
|
|
416
|
-
text: z.
|
|
416
|
+
text: z.ZodCustom<string, string>;
|
|
417
417
|
success: z.ZodBoolean;
|
|
418
418
|
error: z.ZodOptional<z.ZodString>;
|
|
419
419
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
@@ -5,11 +5,16 @@ import { InteractionCapabilitiesSchema, RequestedInteractionsSchema } from "./in
|
|
|
5
5
|
import { ContextTransferReceiptSchema, ContextTransferRequestSchema, NativeContextBoundaryProofSchema, NativeContextContinuationAcknowledgementSchema, NativeContextContinuationRequestSchema, nativeContextContinuationAcknowledgementMatches } from "./portable-context.js";
|
|
6
6
|
import { AgentExactRunControlRefSchema, AgentRunControlRefSchema, CanonicalStreamEventSchema } from "./runtime-control.js";
|
|
7
7
|
import { AgentProfileCapabilitiesSchema } from "./environment-profile-capabilities.js";
|
|
8
|
-
import { boundedIdentifierSchema, boundedJsonRecordSchema,
|
|
8
|
+
import { boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
|
|
9
9
|
import { InputPartSchema } from "./portable-context-shared.js";
|
|
10
10
|
import { deepFreeze } from "./deep-freeze.js";
|
|
11
11
|
export const AgentTurnInputSchema = z.strictObject({
|
|
12
|
-
prompt:
|
|
12
|
+
// A prompt is what the agent is asked to do, so it is CONTENT: its size is set by the work,
|
|
13
|
+
// not by the protocol. Held to the metadata bound it capped a manager's brief at 16,384
|
|
14
|
+
// characters, which refused a director handing a checker a 27 KB patch to re-verify a measured
|
|
15
|
+
// result (agent-sdk#313). Refusal is still right here — a silently shortened instruction is
|
|
16
|
+
// worse than none — so only the ceiling moves.
|
|
17
|
+
prompt: boundedEventContentStringSchema.optional(),
|
|
13
18
|
parts: z.array(InputPartSchema).max(CONTRACT_MAX_ARRAY_LENGTH).optional(),
|
|
14
19
|
sessionId: boundedIdentifierSchema.optional(),
|
|
15
20
|
model: boundedIdentifierSchema.optional(),
|
|
@@ -37,16 +42,16 @@ const TokenUsageSchema = z.strictObject({
|
|
|
37
42
|
});
|
|
38
43
|
const AgentEnvironmentEventSchema = z.strictObject({
|
|
39
44
|
type: boundedIdentifierSchema,
|
|
40
|
-
data:
|
|
45
|
+
data: boundedEventContentRecordSchema,
|
|
41
46
|
id: boundedIdentifierSchema.optional(),
|
|
42
47
|
normalized: CanonicalStreamEventSchema.optional(),
|
|
43
48
|
usage: TokenUsageSchema.optional(),
|
|
44
49
|
usageMode: z.enum(["delta", "cumulative"]).optional(),
|
|
45
|
-
providerEvent:
|
|
50
|
+
providerEvent: boundedEventContentJsonSchema.optional(),
|
|
46
51
|
});
|
|
47
52
|
/** Runtime validator for a provider turn returned from durable continuation. */
|
|
48
53
|
export const AgentTurnResultSchema = z.strictObject({
|
|
49
|
-
text:
|
|
54
|
+
text: boundedEventContentStringSchema,
|
|
50
55
|
success: z.boolean(),
|
|
51
56
|
error: boundedStringSchema.optional(),
|
|
52
57
|
sessionId: boundedIdentifierSchema.optional(),
|
package/dist/index.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ export * from "./harness-capabilities.js";
|
|
|
40
40
|
export * from "./profile-schema.js";
|
|
41
41
|
export * from "./profile-security.js";
|
|
42
42
|
export * from "./sandbox-size.js";
|
|
43
|
-
export { CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH, } from "./contract-limits.js";
|
|
43
|
+
export { CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH, CONTRACT_MAX_JSON_BYTES, boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, isBoundedEventContentJson, } from "./contract-limits.js";
|
|
44
44
|
export { AgentEnvironmentEgressPolicySchema } from "./environment-requests.js";
|
package/dist/index.js
CHANGED
|
@@ -38,5 +38,5 @@ export * from "./harness-capabilities.js";
|
|
|
38
38
|
export * from "./profile-schema.js";
|
|
39
39
|
export * from "./profile-security.js";
|
|
40
40
|
export * from "./sandbox-size.js";
|
|
41
|
-
export { CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH, } from "./contract-limits.js";
|
|
41
|
+
export { CONTRACT_MAX_CONFIDENTIAL_ATTESTATION_QUOTE_LENGTH, CONTRACT_MAX_JSON_BYTES, boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, isBoundedEventContentJson, } from "./contract-limits.js";
|
|
42
42
|
export { AgentEnvironmentEgressPolicySchema } from "./environment-requests.js";
|
|
@@ -62,7 +62,7 @@ export interface NativeContextContinuationTurn {
|
|
|
62
62
|
providerOptions?: Record<string, unknown>;
|
|
63
63
|
}
|
|
64
64
|
export declare const NativeContextContinuationTurnSchema: z.ZodObject<{
|
|
65
|
-
prompt: z.ZodOptional<z.
|
|
65
|
+
prompt: z.ZodOptional<z.ZodCustom<string, string>>;
|
|
66
66
|
parts: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
67
67
|
type: z.ZodLiteral<"text">;
|
|
68
68
|
text: z.ZodString;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { AgentExactRunControlRefSchema, } from "./runtime-control.js";
|
|
3
3
|
import { idSchema, InputPartSchema, jsonRecordSchema, sha256DigestSchema, wireDigest } from "./portable-context-shared.js";
|
|
4
|
-
import { boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
|
|
4
|
+
import { boundedEventContentStringSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
|
|
5
5
|
export const NativeContextBoundarySchema = z
|
|
6
6
|
.discriminatedUnion("kind", [
|
|
7
7
|
z.strictObject({ kind: z.literal("token"), token: idSchema }),
|
|
@@ -40,7 +40,8 @@ const NativeContextContinuationRequestMaterialSchema = z.strictObject({
|
|
|
40
40
|
expectedBoundary: NativeContextBoundaryProofSchema,
|
|
41
41
|
});
|
|
42
42
|
export const NativeContextContinuationTurnSchema = z.strictObject({
|
|
43
|
-
|
|
43
|
+
// Content, not metadata: see environment-runtime.ts.
|
|
44
|
+
prompt: boundedEventContentStringSchema.optional(),
|
|
44
45
|
parts: z.array(InputPartSchema).max(CONTRACT_MAX_ARRAY_LENGTH).optional(),
|
|
45
46
|
model: idSchema.optional(),
|
|
46
47
|
context: jsonRecordSchema.optional(),
|
|
@@ -164,7 +164,6 @@ export declare const AgentRunControlAcknowledgementSchema: z.ZodObject<{
|
|
|
164
164
|
existingRequestDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
|
|
165
165
|
}, z.core.$strict>;
|
|
166
166
|
export declare function agentRunControlAcknowledgementMatchesRequest(request: AgentRunControlRequest, acknowledgement: AgentRunControlAcknowledgement): boolean;
|
|
167
|
-
/** Runtime validator for every member of the existing canonical event union. */
|
|
168
167
|
export declare const CanonicalStreamEventSchema: z.ZodType<StreamEvent>;
|
|
169
168
|
/** Ordered, replayable envelope around the existing canonical event union. */
|
|
170
169
|
export interface RuntimeEventEnvelope {
|
package/dist/runtime-control.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { canonicalCandidateDigest, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
|
|
3
|
-
import { boundedIdentifierSchema, boundedJsonRecordSchema,
|
|
3
|
+
import { boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, isBoundedEventContentJson, } from "./contract-limits.js";
|
|
4
4
|
import { ModelUsageSchema } from "./environment-observation.js";
|
|
5
5
|
import { InteractionRequestSchema } from "./interaction.js";
|
|
6
6
|
import { DurablePlanSchema } from "./plan.js";
|
|
@@ -213,20 +213,20 @@ const toolTimeSchema = z.strictObject({
|
|
|
213
213
|
const toolStateSchema = z.discriminatedUnion("status", [
|
|
214
214
|
z.strictObject({
|
|
215
215
|
status: z.literal("pending"),
|
|
216
|
-
input:
|
|
217
|
-
raw:
|
|
216
|
+
input: boundedEventContentRecordSchema,
|
|
217
|
+
raw: boundedEventContentStringSchema.optional(),
|
|
218
218
|
}),
|
|
219
219
|
z.strictObject({
|
|
220
220
|
status: z.literal("running"),
|
|
221
|
-
input:
|
|
221
|
+
input: boundedEventContentRecordSchema,
|
|
222
222
|
title: boundedStringSchema.optional(),
|
|
223
223
|
metadata: unknownRecordSchema.optional(),
|
|
224
224
|
time: z.strictObject({ start: z.number().finite() }).optional(),
|
|
225
225
|
}),
|
|
226
226
|
z.strictObject({
|
|
227
227
|
status: z.literal("completed"),
|
|
228
|
-
input:
|
|
229
|
-
output:
|
|
228
|
+
input: boundedEventContentRecordSchema,
|
|
229
|
+
output: boundedEventContentJsonSchema,
|
|
230
230
|
title: boundedStringSchema.optional(),
|
|
231
231
|
metadata: unknownRecordSchema.optional(),
|
|
232
232
|
time: z.strictObject({
|
|
@@ -236,15 +236,15 @@ const toolStateSchema = z.discriminatedUnion("status", [
|
|
|
236
236
|
}),
|
|
237
237
|
z.strictObject({
|
|
238
238
|
status: z.enum(["error", "failed"]),
|
|
239
|
-
input:
|
|
239
|
+
input: boundedEventContentRecordSchema,
|
|
240
240
|
error: boundedStringSchema.optional(),
|
|
241
|
-
output:
|
|
241
|
+
output: boundedEventContentJsonSchema.optional(),
|
|
242
242
|
metadata: unknownRecordSchema.optional(),
|
|
243
243
|
time: toolTimeSchema.optional(),
|
|
244
244
|
}),
|
|
245
245
|
]);
|
|
246
246
|
const partSchema = z.discriminatedUnion("type", [
|
|
247
|
-
z.strictObject({ ...partBase, type: z.literal("text"), text:
|
|
247
|
+
z.strictObject({ ...partBase, type: z.literal("text"), text: boundedEventContentStringSchema }),
|
|
248
248
|
z.strictObject({
|
|
249
249
|
...partBase,
|
|
250
250
|
type: z.literal("tool"),
|
|
@@ -256,7 +256,7 @@ const partSchema = z.discriminatedUnion("type", [
|
|
|
256
256
|
z.strictObject({
|
|
257
257
|
...partBase,
|
|
258
258
|
type: z.literal("reasoning"),
|
|
259
|
-
text:
|
|
259
|
+
text: boundedEventContentStringSchema,
|
|
260
260
|
}),
|
|
261
261
|
z.strictObject({
|
|
262
262
|
...partBase,
|
|
@@ -268,7 +268,8 @@ const partSchema = z.discriminatedUnion("type", [
|
|
|
268
268
|
z.strictObject({
|
|
269
269
|
...partBase,
|
|
270
270
|
type: z.literal("subtask"),
|
|
271
|
-
|
|
271
|
+
// Content, not metadata: see environment-runtime.ts.
|
|
272
|
+
prompt: boundedEventContentStringSchema,
|
|
272
273
|
description: boundedStringSchema,
|
|
273
274
|
agent: stableIdSchema,
|
|
274
275
|
}),
|
|
@@ -338,11 +339,11 @@ const ChildTaskEventSchema = z
|
|
|
338
339
|
}
|
|
339
340
|
});
|
|
340
341
|
/** Runtime validator for every member of the existing canonical event union. */
|
|
341
|
-
|
|
342
|
+
const CanonicalStreamEventUnionSchema = z.discriminatedUnion("type", [
|
|
342
343
|
z.strictObject({
|
|
343
344
|
type: z.literal("message.part.updated"),
|
|
344
345
|
part: partSchema,
|
|
345
|
-
delta:
|
|
346
|
+
delta: boundedEventContentStringSchema.optional(),
|
|
346
347
|
}),
|
|
347
348
|
z.strictObject({
|
|
348
349
|
type: z.literal("tool-heartbeat"),
|
|
@@ -382,7 +383,7 @@ export const CanonicalStreamEventSchema = z.discriminatedUnion("type", [
|
|
|
382
383
|
z.strictObject({
|
|
383
384
|
type: z.literal("raw"),
|
|
384
385
|
backend: stableIdSchema,
|
|
385
|
-
event:
|
|
386
|
+
event: boundedEventContentJsonSchema,
|
|
386
387
|
}),
|
|
387
388
|
z.strictObject({
|
|
388
389
|
type: z.literal("session.updated"),
|
|
@@ -408,6 +409,17 @@ export const CanonicalStreamEventSchema = z.discriminatedUnion("type", [
|
|
|
408
409
|
}),
|
|
409
410
|
ChildTaskEventSchema,
|
|
410
411
|
]);
|
|
412
|
+
export const CanonicalStreamEventSchema = CanonicalStreamEventUnionSchema.superRefine((event, refinement) => {
|
|
413
|
+
// Zod retains explicitly supplied optional `undefined` fields, whereas a
|
|
414
|
+
// JSON event omits them. Canonical events use that wire-equivalent omission
|
|
415
|
+
// without making raw provider records accept undefined.
|
|
416
|
+
if (!isBoundedEventContentJson(event, { omitUndefinedObjectFields: true })) {
|
|
417
|
+
refinement.addIssue({
|
|
418
|
+
code: "custom",
|
|
419
|
+
message: "canonical stream event exceeds its serialized byte bound",
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
});
|
|
411
423
|
export const RuntimeEventEnvelopeSchema = z.strictObject({
|
|
412
424
|
runId: stableIdSchema,
|
|
413
425
|
eventId: stableIdSchema,
|