@nylorun/core 0.12.0-beta → 0.15.0-beta
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/CHANGELOG.md +159 -0
- package/dist/compatibility.d.ts +84 -50
- package/dist/compatibility.js +84 -67
- package/dist/contracts.d.ts +462 -1196
- package/dist/contracts.js +403 -681
- package/dist/define.d.ts +13 -10
- package/dist/define.js +7 -4
- package/dist/definition/assemble.d.ts +0 -3
- package/dist/definition/assemble.js +13 -19
- package/dist/definition/bind-agent.js +0 -2
- package/dist/definition/bind-tool.js +0 -1
- package/dist/definition/bound.d.ts +3 -10
- package/dist/definition/builder.d.ts +19 -55
- package/dist/definition/builder.js +19 -130
- package/dist/definition/capability.d.ts +3 -15
- package/dist/definition/capability.js +3 -25
- package/dist/definition/code-tools.d.ts +22 -0
- package/dist/definition/code-tools.js +46 -0
- package/dist/definition/declaration.d.ts +0 -3
- package/dist/definition/declaration.js +8 -11
- package/dist/definition/delegate.d.ts +7 -7
- package/dist/definition/flow/compile.d.ts +4 -5
- package/dist/definition/flow/compile.js +120 -72
- package/dist/definition/flow/from.d.ts +2 -2
- package/dist/definition/flow/from.js +14 -33
- package/dist/definition/flow/index.d.ts +2 -2
- package/dist/definition/flow/index.js +2 -2
- package/dist/definition/flow/paths.d.ts +32 -17
- package/dist/definition/flow/paths.js +35 -14
- package/dist/definition/flow/spec.d.ts +6 -9
- package/dist/definition/flow/spec.js +49 -31
- package/dist/definition/flow/types.d.ts +40 -116
- package/dist/definition/from.js +36 -41
- package/dist/definition/helpers.d.ts +1 -1
- package/dist/definition/helpers.js +1 -1
- package/dist/definition/http-tool.d.ts +66 -0
- package/dist/definition/http-tool.js +131 -0
- package/dist/definition/implementations.d.ts +0 -3
- package/dist/definition/manifest.js +5 -4
- package/dist/definition/mcp.d.ts +4 -2
- package/dist/definition/mcp.js +14 -18
- package/dist/definition/removed.d.ts +10 -0
- package/dist/definition/removed.js +26 -0
- package/dist/definition/sandbox-capability.d.ts +2 -0
- package/dist/definition/sandbox-capability.js +11 -1
- package/dist/definition/schema.js +0 -3
- package/dist/definition/skill-tools.d.ts +16 -2
- package/dist/definition/skill-tools.js +38 -31
- package/dist/definition/variant.d.ts +1 -1
- package/dist/definition/variant.js +3 -14
- package/dist/definition/workflow/diagnostics.d.ts +1 -7
- package/dist/definition/workflow/diagnostics.js +1 -24
- package/dist/definition/workflow/index.d.ts +3 -17
- package/dist/definition/workflow/index.js +2 -9
- package/dist/definition/workflow/runnable.d.ts +2 -34
- package/dist/definition/workflow/runnable.js +8 -142
- package/dist/definition/workflow/types.d.ts +1 -10
- package/dist/harness-api/messages.d.ts +24 -27
- package/dist/harness-api/messages.js +1 -1
- package/dist/harness-api/schema.d.ts +0 -16
- package/dist/harness-api/schema.js +5 -12
- package/dist/index.d.ts +1 -1
- package/dist/types/manifest.d.ts +41 -14
- package/dist/types/middleware.d.ts +11 -16
- package/dist/types/observe.d.ts +0 -6
- package/dist/types/tool.d.ts +0 -6
- package/dist/types/workflow.d.ts +54 -110
- package/dist/utils/definition-files.d.ts +31 -0
- package/dist/utils/definition-files.js +84 -0
- package/package.json +1 -1
- package/dist/definition/hooks.d.ts +0 -19
- package/dist/definition/hooks.js +0 -67
- package/dist/definition/workflow/build.d.ts +0 -28
- package/dist/definition/workflow/build.js +0 -40
- package/dist/definition/workflow/chain.d.ts +0 -49
- package/dist/definition/workflow/chain.js +0 -40
- package/dist/definition/workflow/loop.d.ts +0 -54
- package/dist/definition/workflow/loop.js +0 -100
- package/dist/definition/workflow/map.d.ts +0 -17
- package/dist/definition/workflow/map.js +0 -45
- package/dist/definition/workflow/parallel.d.ts +0 -19
- package/dist/definition/workflow/parallel.js +0 -36
- package/dist/definition/workflow/patch.d.ts +0 -11
- package/dist/definition/workflow/patch.js +0 -45
- package/dist/definition/workflow/slot.d.ts +0 -23
- package/dist/definition/workflow/slot.js +0 -16
- package/dist/definition/workflow/switch.d.ts +0 -26
- package/dist/definition/workflow/switch.js +0 -64
- package/dist/types/dynamics.d.ts +0 -101
- package/dist/types/dynamics.js +0 -1
package/dist/contracts.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** Public wire contracts only. Never import checkpoint or engine modules here. */
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
|
|
4
|
-
import {
|
|
4
|
+
import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
|
|
5
5
|
import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
|
|
6
|
+
import { stdioMcpRefusal } from "./definition/mcp.js";
|
|
7
|
+
import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
|
|
6
8
|
import { canonical } from "./utils/canonical.js";
|
|
9
|
+
import { DEFINITION_FILE_MAX_BYTES, skillFilesIssue } from "./utils/definition-files.js";
|
|
7
10
|
export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
|
|
11
|
+
export { DEFINITION_FILE_MAX_BYTES, SKILL_FILES_MAX, definitionFilesOf, isDefinitionFileHash, } from "./utils/definition-files.js";
|
|
8
12
|
import { ERROR_CODES } from "./compatibility.js";
|
|
9
13
|
export const RequestIdSchema = z.string().min(1);
|
|
10
14
|
export const IdempotencyKeySchema = z.string().min(1).max(256);
|
|
@@ -22,22 +26,13 @@ const jsonValue = z
|
|
|
22
26
|
]))
|
|
23
27
|
.meta({ id: "JsonValue" });
|
|
24
28
|
const mcpServerSchema = z.discriminatedUnion("type", [
|
|
25
|
-
z
|
|
26
|
-
.object({
|
|
27
|
-
name: z.string().min(1),
|
|
28
|
-
type: z.literal("stdio"),
|
|
29
|
-
command: z.string().min(1),
|
|
30
|
-
args: z.array(z.string()).optional(),
|
|
31
|
-
env: z.record(z.string(), z.string()).optional(),
|
|
32
|
-
cwd: z.string().optional(),
|
|
33
|
-
})
|
|
34
|
-
.strict(),
|
|
35
29
|
z
|
|
36
30
|
.object({
|
|
37
31
|
name: z.string().min(1),
|
|
38
32
|
type: z.literal("streamable-http"),
|
|
39
33
|
url: z.string().min(1),
|
|
40
34
|
headers: z.record(z.string(), z.string()).optional(),
|
|
35
|
+
approval: z.enum(APPROVAL_MODES).optional(),
|
|
41
36
|
})
|
|
42
37
|
.strict(),
|
|
43
38
|
z
|
|
@@ -46,13 +41,28 @@ const mcpServerSchema = z.discriminatedUnion("type", [
|
|
|
46
41
|
type: z.literal("sse"),
|
|
47
42
|
url: z.string().min(1),
|
|
48
43
|
headers: z.record(z.string(), z.string()).optional(),
|
|
44
|
+
approval: z.enum(APPROVAL_MODES).optional(),
|
|
49
45
|
})
|
|
50
46
|
.strict(),
|
|
51
|
-
]);
|
|
47
|
+
], { error: (issue) => stdioIssue(issue.input) });
|
|
48
|
+
/** The refusal of a `stdio` server; other bad declarations keep zod's own message. */
|
|
49
|
+
function stdioIssue(input) {
|
|
50
|
+
if (!input || typeof input !== "object")
|
|
51
|
+
return undefined;
|
|
52
|
+
const server = input;
|
|
53
|
+
if (server.type !== "stdio")
|
|
54
|
+
return undefined;
|
|
55
|
+
return stdioMcpRefusal(typeof server.name === "string" ? server.name : "(unnamed)");
|
|
56
|
+
}
|
|
52
57
|
const skillManifestSchema = z
|
|
53
58
|
.object({
|
|
54
59
|
name: z.string().min(1),
|
|
55
60
|
description: z.string().min(1),
|
|
61
|
+
files: z.record(z.string(), z.string()).superRefine((files, ctx) => {
|
|
62
|
+
const issue = skillFilesIssue(files);
|
|
63
|
+
if (issue)
|
|
64
|
+
ctx.addIssue({ code: "custom", message: `Skill ${issue}` });
|
|
65
|
+
}),
|
|
56
66
|
})
|
|
57
67
|
.strict();
|
|
58
68
|
const sandboxManifestSchema = z
|
|
@@ -89,6 +99,26 @@ const sandboxManifestSchema = z
|
|
|
89
99
|
.optional(),
|
|
90
100
|
})
|
|
91
101
|
.strict();
|
|
102
|
+
const httpToolTargetSchema = z
|
|
103
|
+
.object({
|
|
104
|
+
url: z.string().superRefine((url, ctx) => {
|
|
105
|
+
const issue = httpUrlIssue(url);
|
|
106
|
+
if (issue)
|
|
107
|
+
ctx.addIssue({ code: "custom", message: issue });
|
|
108
|
+
}),
|
|
109
|
+
method: z.enum(HTTP_TOOL_METHODS).optional(),
|
|
110
|
+
credential: z.string().min(1).optional(),
|
|
111
|
+
timeoutMs: z.number().int().positive().max(HTTP_TOOL_MAX_TIMEOUT_MS).optional(),
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
/** A name kept for a later kind of `what` (tool, verifier), refused for now. */
|
|
115
|
+
const reservedKind = (what) => z
|
|
116
|
+
.unknown()
|
|
117
|
+
.refine((value) => value === undefined, { message: "Functions are not available yet" })
|
|
118
|
+
.optional()
|
|
119
|
+
.meta({ description: `Reserved for a later kind of ${what}; refused for now.` });
|
|
120
|
+
/** Names kept for later kinds of tool, beside `agent` and `http`. */
|
|
121
|
+
const reservedToolKind = reservedKind("tool");
|
|
92
122
|
const toolManifestSchema = z
|
|
93
123
|
.object({
|
|
94
124
|
name: z.string().min(1),
|
|
@@ -96,27 +126,44 @@ const toolManifestSchema = z
|
|
|
96
126
|
inputSchema: jsonObject,
|
|
97
127
|
outputSchema: jsonObject.optional(),
|
|
98
128
|
agent: z
|
|
99
|
-
.lazy(() => z.union([
|
|
129
|
+
.lazy(() => z.union([workflowManifestSchema, AgentManifestSchema]))
|
|
100
130
|
.meta({ id: "ToolAgentManifest" })
|
|
101
131
|
.optional(),
|
|
132
|
+
http: httpToolTargetSchema.optional(),
|
|
133
|
+
approval: z.enum(APPROVAL_MODES).optional(),
|
|
134
|
+
fn: reservedToolKind,
|
|
135
|
+
command: reservedToolKind,
|
|
102
136
|
})
|
|
103
|
-
.strict()
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
137
|
+
.strict()
|
|
138
|
+
.superRefine((tool, ctx) => {
|
|
139
|
+
if (tool.agent !== undefined && tool.http !== undefined)
|
|
140
|
+
ctx.addIssue({
|
|
141
|
+
code: "custom",
|
|
142
|
+
message: `Tool '${tool.name}' is an agent or an HTTP request, not both`,
|
|
143
|
+
});
|
|
144
|
+
if (tool.approval !== undefined && tool.http === undefined)
|
|
145
|
+
ctx.addIssue({
|
|
146
|
+
code: "custom",
|
|
147
|
+
path: ["approval"],
|
|
148
|
+
message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
/** A capability naming a field manifest v5 removed is refused with what replaces it. */
|
|
152
|
+
const removedFieldError = (issue) => {
|
|
153
|
+
if (issue.code !== "unrecognized_keys")
|
|
154
|
+
return undefined;
|
|
155
|
+
const removed = issue.keys?.find((key) => REMOVED_CAPABILITY_FIELDS[key] !== undefined);
|
|
156
|
+
return removed === undefined ? undefined : REMOVED_CAPABILITY_FIELDS[removed];
|
|
157
|
+
};
|
|
110
158
|
export const AgentManifestSchema = z
|
|
111
159
|
.object({
|
|
112
|
-
manifestSchemaVersion: z.literal(
|
|
160
|
+
manifestSchemaVersion: z.literal(5, { error: (issue) => manifestVersionIssue(issue.input) }),
|
|
113
161
|
id: z.string().min(1),
|
|
114
162
|
name: z.string().min(1).optional(),
|
|
115
163
|
description: z.string().optional(),
|
|
116
164
|
metadata: jsonObject.optional(),
|
|
117
165
|
outputSchema: jsonObject.optional(),
|
|
118
|
-
capabilities: z.array(z
|
|
119
|
-
.object({
|
|
166
|
+
capabilities: z.array(z.strictObject({
|
|
120
167
|
id: z.string().min(1),
|
|
121
168
|
type: z.enum(["agent", "agent-plugin"]),
|
|
122
169
|
name: z.string().min(1).optional(),
|
|
@@ -127,20 +174,16 @@ export const AgentManifestSchema = z
|
|
|
127
174
|
tools: z.array(toolManifestSchema).optional(),
|
|
128
175
|
mcpServers: z.record(z.string(), mcpServerSchema).optional(),
|
|
129
176
|
sandbox: sandboxManifestSchema.optional(),
|
|
130
|
-
|
|
131
|
-
.array(hookPointSchema)
|
|
132
|
-
.optional()
|
|
133
|
-
.superRefine((hooks, ctx) => {
|
|
134
|
-
const issue = hooks === undefined ? undefined : hookListIssue(hooks);
|
|
135
|
-
if (issue)
|
|
136
|
-
ctx.addIssue({ code: "custom", message: issue });
|
|
137
|
-
}),
|
|
138
|
-
})
|
|
139
|
-
.strict()),
|
|
177
|
+
}, { error: removedFieldError })),
|
|
140
178
|
runtime: z.object({}).strict().optional(),
|
|
179
|
+
// Reserved for Functions, which are deferred: developer code the Runtime will run from
|
|
180
|
+
// uploaded definition files (a `functions/` folder). Any value is refused below.
|
|
181
|
+
functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
|
|
141
182
|
})
|
|
142
183
|
.strict()
|
|
143
184
|
.superRefine((manifest, ctx) => {
|
|
185
|
+
if (manifest.functions !== undefined)
|
|
186
|
+
ctx.addIssue({ code: "custom", path: ["functions"], message: "Functions are not available yet" });
|
|
144
187
|
delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
|
|
145
188
|
const ids = new Set();
|
|
146
189
|
const names = new Set();
|
|
@@ -256,10 +299,38 @@ function delegationIssues(manifest, issue) {
|
|
|
256
299
|
if (sandboxes.size > 1)
|
|
257
300
|
issue("An agent and the agents it uses as tools must declare identical sandboxes");
|
|
258
301
|
}
|
|
259
|
-
|
|
260
|
-
const
|
|
302
|
+
// Workflow manifest v3 (flow agents): `id` on any node, embedded agents, no functions.
|
|
303
|
+
const workflowNodeOptions = { id: z.string().min(1).optional() };
|
|
304
|
+
const workflowAgentNodeSchema = z
|
|
305
|
+
.object({ agent: z.string().min(1), ...workflowNodeOptions })
|
|
306
|
+
.strict();
|
|
307
|
+
/**
|
|
308
|
+
* What judges a Loop attempt: a verifier agent (`{ agent, id? }`) or an HTTP verifier
|
|
309
|
+
* (`{ http }`). `fn` and `command` are reserved for later kinds of verifier.
|
|
310
|
+
*/
|
|
311
|
+
const workflowLoopVerifySchema = z
|
|
312
|
+
.object({
|
|
313
|
+
agent: z.string().min(1).optional(),
|
|
314
|
+
http: httpToolTargetSchema.optional(),
|
|
315
|
+
fn: reservedKind("verifier"),
|
|
316
|
+
command: reservedKind("verifier"),
|
|
317
|
+
...workflowNodeOptions,
|
|
318
|
+
})
|
|
319
|
+
.strict()
|
|
320
|
+
.superRefine((verify, ctx) => {
|
|
321
|
+
if (verify.fn !== undefined || verify.command !== undefined)
|
|
322
|
+
return;
|
|
323
|
+
if ((verify.agent === undefined) === (verify.http === undefined))
|
|
324
|
+
ctx.addIssue({
|
|
325
|
+
code: "custom",
|
|
326
|
+
message: "A Loop's verify is a verifier agent ({ agent }) or an HTTP verifier ({ http }): exactly one",
|
|
327
|
+
});
|
|
328
|
+
else if (verify.http !== undefined && verify.id !== undefined)
|
|
329
|
+
ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
|
|
330
|
+
})
|
|
331
|
+
.meta({ id: "WorkflowLoopVerify" });
|
|
261
332
|
const workflowNodeSchema = z.lazy(() => z.union([
|
|
262
|
-
|
|
333
|
+
workflowAgentNodeSchema,
|
|
263
334
|
z
|
|
264
335
|
.object({
|
|
265
336
|
tool: z
|
|
@@ -268,173 +339,60 @@ const workflowNodeSchema = z.lazy(() => z.union([
|
|
|
268
339
|
description: z.string().optional(),
|
|
269
340
|
inputSchema: jsonObject.optional(),
|
|
270
341
|
outputSchema: jsonObject.optional(),
|
|
342
|
+
/** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
|
|
343
|
+
http: httpToolTargetSchema.optional(),
|
|
271
344
|
})
|
|
272
345
|
.strict(),
|
|
346
|
+
...workflowNodeOptions,
|
|
273
347
|
})
|
|
274
348
|
.strict(),
|
|
275
|
-
z
|
|
276
|
-
.object({
|
|
277
|
-
chain: z
|
|
278
|
-
.object({
|
|
279
|
-
id: z.string().min(1),
|
|
280
|
-
steps: z.array(workflowNodeSchema).min(1),
|
|
281
|
-
})
|
|
282
|
-
.strict(),
|
|
283
|
-
})
|
|
284
|
-
.strict(),
|
|
349
|
+
z.object({ chain: z.array(workflowNodeSchema).min(1), ...workflowNodeOptions }).strict(),
|
|
285
350
|
z
|
|
286
351
|
.object({
|
|
287
352
|
switch: z
|
|
288
353
|
.object({
|
|
289
|
-
id: z.string().min(1),
|
|
290
|
-
on: workflowFnRefSchema,
|
|
291
354
|
cases: z.record(z.string(), workflowNodeSchema),
|
|
292
355
|
default: workflowNodeSchema.optional(),
|
|
293
356
|
})
|
|
294
357
|
.strict(),
|
|
358
|
+
...workflowNodeOptions,
|
|
295
359
|
})
|
|
296
360
|
.strict(),
|
|
297
361
|
z
|
|
298
362
|
.object({
|
|
299
363
|
parallel: z
|
|
300
|
-
.
|
|
301
|
-
id: z.string().min(1),
|
|
302
|
-
branches: z.record(z.string(), workflowNodeSchema),
|
|
303
|
-
})
|
|
304
|
-
.strict(),
|
|
305
|
-
})
|
|
306
|
-
.strict(),
|
|
307
|
-
z
|
|
308
|
-
.object({
|
|
309
|
-
map: z
|
|
310
|
-
.object({
|
|
311
|
-
id: z.string().min(1),
|
|
312
|
-
over: workflowFnRefSchema,
|
|
313
|
-
each: workflowNodeSchema,
|
|
314
|
-
})
|
|
315
|
-
.strict(),
|
|
316
|
-
})
|
|
317
|
-
.strict(),
|
|
318
|
-
z
|
|
319
|
-
.object({
|
|
320
|
-
loop: z
|
|
321
|
-
.object({
|
|
322
|
-
id: z.string().min(1),
|
|
323
|
-
run: workflowNodeSchema,
|
|
324
|
-
verify: z.union([
|
|
325
|
-
workflowFnRefSchema,
|
|
326
|
-
z.object({ agent: z.string().min(1) }).strict(),
|
|
327
|
-
z
|
|
328
|
-
.object({
|
|
329
|
-
slot: z
|
|
330
|
-
.object({
|
|
331
|
-
id: z.string().min(1).optional(),
|
|
332
|
-
input: workflowFnRefSchema.optional(),
|
|
333
|
-
run: workflowNodeSchema,
|
|
334
|
-
})
|
|
335
|
-
.strict(),
|
|
336
|
-
})
|
|
337
|
-
.strict(),
|
|
338
|
-
]),
|
|
339
|
-
decide: workflowFnRefSchema,
|
|
340
|
-
})
|
|
341
|
-
.strict(),
|
|
342
|
-
})
|
|
343
|
-
.strict(),
|
|
344
|
-
z
|
|
345
|
-
.object({
|
|
346
|
-
slot: z
|
|
347
|
-
.object({
|
|
348
|
-
id: z.string().min(1).optional(),
|
|
349
|
-
input: workflowFnRefSchema.optional(),
|
|
350
|
-
run: workflowNodeSchema,
|
|
351
|
-
})
|
|
352
|
-
.strict(),
|
|
353
|
-
})
|
|
354
|
-
.strict(),
|
|
355
|
-
])).meta({ id: "WorkflowNode" });
|
|
356
|
-
const workflowV1ManifestSchema = z
|
|
357
|
-
.object({
|
|
358
|
-
kind: z.literal("workflow"),
|
|
359
|
-
workflowSchemaVersion: z.literal(1),
|
|
360
|
-
id: z.string().min(1),
|
|
361
|
-
root: workflowNodeSchema,
|
|
362
|
-
sandbox: sandboxManifestSchema.optional(),
|
|
363
|
-
})
|
|
364
|
-
.strict();
|
|
365
|
-
// v2 (Flow Agents): `id` and `input` on any node, no slots, embedded agents.
|
|
366
|
-
const workflowNodeOptionsV2 = {
|
|
367
|
-
id: z.string().min(1).optional(),
|
|
368
|
-
input: workflowFnRefSchema.optional(),
|
|
369
|
-
};
|
|
370
|
-
const workflowAgentNodeV2Schema = z
|
|
371
|
-
.object({ agent: z.string().min(1), ...workflowNodeOptionsV2 })
|
|
372
|
-
.strict();
|
|
373
|
-
const workflowNodeV2Schema = z.lazy(() => z.union([
|
|
374
|
-
workflowAgentNodeV2Schema,
|
|
375
|
-
z
|
|
376
|
-
.object({
|
|
377
|
-
tool: z
|
|
378
|
-
.object({
|
|
379
|
-
name: z.string().min(1),
|
|
380
|
-
description: z.string().optional(),
|
|
381
|
-
inputSchema: jsonObject.optional(),
|
|
382
|
-
outputSchema: jsonObject.optional(),
|
|
383
|
-
})
|
|
384
|
-
.strict(),
|
|
385
|
-
...workflowNodeOptionsV2,
|
|
386
|
-
})
|
|
387
|
-
.strict(),
|
|
388
|
-
z.object({ chain: z.array(workflowNodeV2Schema).min(1), ...workflowNodeOptionsV2 }).strict(),
|
|
389
|
-
z
|
|
390
|
-
.object({
|
|
391
|
-
switch: z
|
|
392
|
-
.object({
|
|
393
|
-
on: workflowFnRefSchema,
|
|
394
|
-
cases: z.record(z.string(), workflowNodeV2Schema),
|
|
395
|
-
default: workflowNodeV2Schema.optional(),
|
|
396
|
-
})
|
|
397
|
-
.strict(),
|
|
398
|
-
...workflowNodeOptionsV2,
|
|
399
|
-
})
|
|
400
|
-
.strict(),
|
|
401
|
-
z
|
|
402
|
-
.object({
|
|
403
|
-
parallel: z
|
|
404
|
-
.record(z.string(), workflowNodeV2Schema)
|
|
364
|
+
.record(z.string(), workflowNodeSchema)
|
|
405
365
|
.refine((branches) => Object.keys(branches).length > 0, {
|
|
406
366
|
message: "parallel needs at least one branch",
|
|
407
367
|
}),
|
|
408
|
-
...
|
|
368
|
+
...workflowNodeOptions,
|
|
409
369
|
})
|
|
410
370
|
.strict(),
|
|
411
371
|
z
|
|
412
372
|
.object({
|
|
413
|
-
map: z.object({ each:
|
|
414
|
-
...
|
|
373
|
+
map: z.object({ each: workflowNodeSchema }).strict(),
|
|
374
|
+
...workflowNodeOptions,
|
|
415
375
|
})
|
|
416
376
|
.strict(),
|
|
417
377
|
z
|
|
418
378
|
.object({
|
|
419
379
|
loop: z
|
|
420
380
|
.object({
|
|
421
|
-
run:
|
|
422
|
-
verify:
|
|
423
|
-
max: z.number().int().positive()
|
|
424
|
-
decide: workflowFnRefSchema.optional(),
|
|
381
|
+
run: workflowNodeSchema,
|
|
382
|
+
verify: workflowLoopVerifySchema,
|
|
383
|
+
max: z.number().int().positive(),
|
|
425
384
|
})
|
|
426
|
-
.strict()
|
|
427
|
-
|
|
428
|
-
message: "loop needs max or decide",
|
|
429
|
-
}),
|
|
430
|
-
...workflowNodeOptionsV2,
|
|
385
|
+
.strict(),
|
|
386
|
+
...workflowNodeOptions,
|
|
431
387
|
})
|
|
432
388
|
.strict(),
|
|
433
|
-
])).meta({ id: "
|
|
434
|
-
const
|
|
389
|
+
])).meta({ id: "WorkflowNode" });
|
|
390
|
+
const workflowManifestSchema = z.lazy(() => z
|
|
435
391
|
.object({
|
|
436
392
|
kind: z.literal("workflow"),
|
|
437
|
-
workflowSchemaVersion: z.literal(
|
|
393
|
+
workflowSchemaVersion: z.literal(3, {
|
|
394
|
+
error: (issue) => workflowVersionIssue(issue.input),
|
|
395
|
+
}),
|
|
438
396
|
id: z.string().min(1),
|
|
439
397
|
name: z.string().min(1).optional(),
|
|
440
398
|
description: z.string().optional(),
|
|
@@ -442,8 +400,8 @@ const workflowV2ManifestSchema = z.lazy(() => z
|
|
|
442
400
|
inputSchema: jsonObject.optional(),
|
|
443
401
|
outputSchema: jsonObject.optional(),
|
|
444
402
|
sandbox: sandboxManifestSchema.optional(),
|
|
445
|
-
root:
|
|
446
|
-
agents: z.record(z.string().min(1), z.union([
|
|
403
|
+
root: workflowNodeSchema,
|
|
404
|
+
agents: z.record(z.string().min(1), z.union([workflowManifestSchema, AgentManifestSchema])),
|
|
447
405
|
})
|
|
448
406
|
.strict()
|
|
449
407
|
.superRefine((manifest, ctx) => {
|
|
@@ -463,7 +421,7 @@ const workflowV2ManifestSchema = z.lazy(() => z
|
|
|
463
421
|
message: `Embedded agent '${agent.id}' must be keyed by its id`,
|
|
464
422
|
});
|
|
465
423
|
}
|
|
466
|
-
})).meta({ id: "
|
|
424
|
+
})).meta({ id: "WorkflowManifest" });
|
|
467
425
|
function referencedAgents(node) {
|
|
468
426
|
const out = [];
|
|
469
427
|
const visit = (child) => {
|
|
@@ -490,10 +448,7 @@ function referencedAgents(node) {
|
|
|
490
448
|
return out;
|
|
491
449
|
}
|
|
492
450
|
/** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
|
|
493
|
-
export const WorkflowManifestSchema =
|
|
494
|
-
workflowV1ManifestSchema,
|
|
495
|
-
workflowV2ManifestSchema,
|
|
496
|
-
]);
|
|
451
|
+
export const WorkflowManifestSchema = workflowManifestSchema;
|
|
497
452
|
/** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
|
|
498
453
|
export const DefinitionDocumentSchema = z.union([
|
|
499
454
|
AgentManifestSchema,
|
|
@@ -505,7 +460,6 @@ export const PutAgentRequestSchema = z
|
|
|
505
460
|
/** Agent or workflow document. Registry `kind` is carried on the document. */
|
|
506
461
|
manifest: DefinitionDocumentSchema,
|
|
507
462
|
implementationVersion: z.string().min(1),
|
|
508
|
-
pluginRoots: z.record(z.string(), absolutePath).optional(),
|
|
509
463
|
})
|
|
510
464
|
.strict();
|
|
511
465
|
export const CredentialSelectionSchema = z
|
|
@@ -555,14 +509,14 @@ export function isSandboxId(value) {
|
|
|
555
509
|
value.length <= SANDBOX_ID_MAX_LENGTH &&
|
|
556
510
|
SANDBOX_ID_PATTERN.test(value));
|
|
557
511
|
}
|
|
558
|
-
/**
|
|
512
|
+
/** A sandbox grant: an exact sandbox id, or a prefix ending in `/*` (`team-a/*`). */
|
|
559
513
|
export function isSandboxGrant(value) {
|
|
560
514
|
if (typeof value !== "string")
|
|
561
515
|
return false;
|
|
562
516
|
return value.endsWith("/*") ? isSandboxId(value.slice(0, -2)) : isSandboxId(value);
|
|
563
517
|
}
|
|
564
518
|
/**
|
|
565
|
-
* Whether `grants` (a
|
|
519
|
+
* Whether `grants` (a token caller's sandbox grants) reach sandbox `id`: an exact entry, or a prefix
|
|
566
520
|
* entry `p/*` for any id below `p/`. No grants reach no sandbox.
|
|
567
521
|
*/
|
|
568
522
|
export function sandboxGranted(grants, id) {
|
|
@@ -864,14 +818,33 @@ const oauthRefreshSchema = z
|
|
|
864
818
|
tokenEndpointAuth: tokenEndpointAuthSchema,
|
|
865
819
|
})
|
|
866
820
|
.strict();
|
|
821
|
+
/** The owner of every installation vault (`scope: "installation"`); a reserved subject. */
|
|
822
|
+
export const INSTALLATION_OWNER = "installation";
|
|
867
823
|
export const CreateVaultRequestSchema = z
|
|
868
824
|
.object({
|
|
869
825
|
...vaultWriteBase,
|
|
870
826
|
name: z.string().min(1),
|
|
871
|
-
|
|
827
|
+
/**
|
|
828
|
+
* `user` (the default): one person's vault, owned by `ownerUserId`. `installation`: the
|
|
829
|
+
* installation's own vault, owned by `installation`, which any session may attach;
|
|
830
|
+
* management keys only (the Management API).
|
|
831
|
+
*/
|
|
832
|
+
scope: z.enum(["user", "installation"]).optional(),
|
|
833
|
+
/** Required for a `user` vault; absent (or `installation`) for an installation vault. */
|
|
834
|
+
ownerUserId: z.string().min(1).optional(),
|
|
872
835
|
metadata: z.record(z.string(), z.string()).optional(),
|
|
873
836
|
})
|
|
874
|
-
.strict()
|
|
837
|
+
.strict()
|
|
838
|
+
.superRefine((value, ctx) => {
|
|
839
|
+
if ((value.scope ?? "user") === "user") {
|
|
840
|
+
if (value.ownerUserId === undefined)
|
|
841
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "ownerUserId is required for a user vault" });
|
|
842
|
+
else if (value.ownerUserId === INSTALLATION_OWNER)
|
|
843
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "installation is reserved for installation vaults" });
|
|
844
|
+
}
|
|
845
|
+
else if (value.ownerUserId !== undefined && value.ownerUserId !== INSTALLATION_OWNER)
|
|
846
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "An installation vault is owned by installation" });
|
|
847
|
+
});
|
|
875
848
|
export const CreateCredentialRequestSchema = z
|
|
876
849
|
.object({
|
|
877
850
|
...vaultWriteBase,
|
|
@@ -1035,7 +1008,8 @@ export const MessageEventBodySchema = z.union([
|
|
|
1035
1008
|
})
|
|
1036
1009
|
.strict(),
|
|
1037
1010
|
]);
|
|
1038
|
-
|
|
1011
|
+
/** What one effect came to: its value, and the agent state it changes. */
|
|
1012
|
+
export const EffectOutcomeSchema = z
|
|
1039
1013
|
.object({
|
|
1040
1014
|
value: z.unknown(),
|
|
1041
1015
|
statePatch: jsonObject.optional(),
|
|
@@ -1162,82 +1136,6 @@ export const AgentRefSchema = z
|
|
|
1162
1136
|
delegationId: z.string().min(1).optional(),
|
|
1163
1137
|
})
|
|
1164
1138
|
.strict();
|
|
1165
|
-
const actionBase = {
|
|
1166
|
-
actionId: z.string(),
|
|
1167
|
-
sessionId: z.string(),
|
|
1168
|
-
turnId: z.string(),
|
|
1169
|
-
agentId: z.string(),
|
|
1170
|
-
manifestHash: z.string(),
|
|
1171
|
-
implementationVersion: z.string(),
|
|
1172
|
-
input: z.unknown(),
|
|
1173
|
-
context: jsonObject,
|
|
1174
|
-
/** `delivering`: sent to the agent's Action endpoint, not answered yet. */
|
|
1175
|
-
status: z.enum(["pending", "delivering", "completed", "uncertain", "cancelled"]),
|
|
1176
|
-
/** How many times it was delivered; a delivery token names the one it is for. */
|
|
1177
|
-
generation: z.number().int().nonnegative(),
|
|
1178
|
-
/** When an unanswered delivery counts as lost. Set only while `delivering`. */
|
|
1179
|
-
deadlineAt: z.string().nullable().optional(),
|
|
1180
|
-
agent: AgentRefSchema.optional(),
|
|
1181
|
-
};
|
|
1182
|
-
/** The hook point an action runs, and the capabilities that registered it (manifest order). */
|
|
1183
|
-
export const ActionHookSchema = z
|
|
1184
|
-
.object({
|
|
1185
|
-
at: z.enum(["before", "after"]),
|
|
1186
|
-
scope: z.enum(["turn", "step"]),
|
|
1187
|
-
capabilityIds: z.array(z.string().min(1)).min(1),
|
|
1188
|
-
})
|
|
1189
|
-
.strict();
|
|
1190
|
-
const agentToolActionSchema = z
|
|
1191
|
-
.object({
|
|
1192
|
-
...actionBase,
|
|
1193
|
-
kind: z.literal("tool"),
|
|
1194
|
-
capabilityId: z.string(),
|
|
1195
|
-
toolName: z.string(),
|
|
1196
|
-
inputSchema: jsonObject.optional(),
|
|
1197
|
-
outputSchema: jsonObject.optional(),
|
|
1198
|
-
})
|
|
1199
|
-
.strict();
|
|
1200
|
-
/** Tool node on a workflow: routed by path + key instead of capabilityId. */
|
|
1201
|
-
const workflowToolActionSchema = z
|
|
1202
|
-
.object({
|
|
1203
|
-
...actionBase,
|
|
1204
|
-
kind: z.literal("tool"),
|
|
1205
|
-
path: z.string().min(1),
|
|
1206
|
-
key: z.string().min(1),
|
|
1207
|
-
inputSchema: jsonObject.optional(),
|
|
1208
|
-
outputSchema: jsonObject.optional(),
|
|
1209
|
-
})
|
|
1210
|
-
.strict();
|
|
1211
|
-
const hookActionSchema = z
|
|
1212
|
-
.object({
|
|
1213
|
-
...actionBase,
|
|
1214
|
-
kind: z.literal("hook"),
|
|
1215
|
-
hook: ActionHookSchema,
|
|
1216
|
-
})
|
|
1217
|
-
.strict();
|
|
1218
|
-
const fnActionSchema = z
|
|
1219
|
-
.object({
|
|
1220
|
-
...actionBase,
|
|
1221
|
-
kind: z.literal("fn"),
|
|
1222
|
-
path: z.string().min(1),
|
|
1223
|
-
key: z.string().min(1),
|
|
1224
|
-
})
|
|
1225
|
-
.strict();
|
|
1226
|
-
const verifyActionSchema = z
|
|
1227
|
-
.object({
|
|
1228
|
-
...actionBase,
|
|
1229
|
-
kind: z.literal("verify"),
|
|
1230
|
-
path: z.string().min(1),
|
|
1231
|
-
key: z.string().min(1),
|
|
1232
|
-
})
|
|
1233
|
-
.strict();
|
|
1234
|
-
export const ActionSchema = z.union([
|
|
1235
|
-
agentToolActionSchema,
|
|
1236
|
-
workflowToolActionSchema,
|
|
1237
|
-
hookActionSchema,
|
|
1238
|
-
fnActionSchema,
|
|
1239
|
-
verifyActionSchema,
|
|
1240
|
-
]);
|
|
1241
1139
|
/**
|
|
1242
1140
|
* Transcript events (Host feature `transcript-events`): the log entries a chat UI
|
|
1243
1141
|
* renders. They are part of the event catalog (`EVENT_CATALOG`); `parseTranscriptEvent`
|
|
@@ -1301,7 +1199,7 @@ export const ContextCompactedPayloadSchema = z
|
|
|
1301
1199
|
...eventAgent,
|
|
1302
1200
|
})
|
|
1303
1201
|
.passthrough();
|
|
1304
|
-
/** `tool.completed`:
|
|
1202
|
+
/** `tool.completed`: a tool the Runtime ran (HTTP, MCP, sandbox, built-in). `error` for a tool error. */
|
|
1305
1203
|
export const ToolCompletedPayloadSchema = z
|
|
1306
1204
|
.object({
|
|
1307
1205
|
...toolIds,
|
|
@@ -1312,27 +1210,6 @@ export const ToolCompletedPayloadSchema = z
|
|
|
1312
1210
|
...eventAgent,
|
|
1313
1211
|
})
|
|
1314
1212
|
.passthrough();
|
|
1315
|
-
/** `action.pending` and `action.completed`; tool actions carry `callId` and `invocationId`. */
|
|
1316
|
-
const actionEventBase = {
|
|
1317
|
-
actionId: z.string().min(1),
|
|
1318
|
-
kind: z.string(),
|
|
1319
|
-
toolName: z.string().optional(),
|
|
1320
|
-
/** A workflow Action: its node's path and key. */
|
|
1321
|
-
path: z.string().optional(),
|
|
1322
|
-
key: z.string().optional(),
|
|
1323
|
-
callId: z.string().optional(),
|
|
1324
|
-
invocationId: z.string().optional(),
|
|
1325
|
-
...eventAgent,
|
|
1326
|
-
};
|
|
1327
|
-
export const ActionPendingPayloadSchema = z
|
|
1328
|
-
.object({ ...actionEventBase, input: z.unknown() })
|
|
1329
|
-
.passthrough();
|
|
1330
|
-
export const ActionCompletedPayloadSchema = z
|
|
1331
|
-
.object({ ...actionEventBase, result: z.unknown() })
|
|
1332
|
-
.passthrough();
|
|
1333
|
-
export const ActionUncertainPayloadSchema = z
|
|
1334
|
-
.object({ actionId: z.string().min(1), ...eventAgent })
|
|
1335
|
-
.passthrough();
|
|
1336
1213
|
export const EffectUncertainPayloadSchema = z
|
|
1337
1214
|
.object({ effectId: z.string().min(1), message: z.string().optional() })
|
|
1338
1215
|
.passthrough();
|
|
@@ -1344,6 +1221,8 @@ export const TurnPausedPayloadSchema = z
|
|
|
1344
1221
|
interactions: z.array(z
|
|
1345
1222
|
.object({
|
|
1346
1223
|
invocationId: z.string().min(1),
|
|
1224
|
+
/** The model's tool call id, when an agent's tool call asked. */
|
|
1225
|
+
callId: z.string().min(1).optional(),
|
|
1347
1226
|
interaction: z
|
|
1348
1227
|
.object({ id: z.string().min(1), kind: z.string() })
|
|
1349
1228
|
.passthrough(),
|
|
@@ -1377,9 +1256,6 @@ const TRANSCRIPT_PAYLOADS = {
|
|
|
1377
1256
|
"model.failed": ModelFailedPayloadSchema,
|
|
1378
1257
|
"context.compacted": ContextCompactedPayloadSchema,
|
|
1379
1258
|
"tool.completed": ToolCompletedPayloadSchema,
|
|
1380
|
-
"action.pending": ActionPendingPayloadSchema,
|
|
1381
|
-
"action.completed": ActionCompletedPayloadSchema,
|
|
1382
|
-
"action.uncertain": ActionUncertainPayloadSchema,
|
|
1383
1259
|
"effect.uncertain": EffectUncertainPayloadSchema,
|
|
1384
1260
|
"turn.completed": TurnCompletedPayloadSchema,
|
|
1385
1261
|
"turn.paused": TurnPausedPayloadSchema,
|
|
@@ -1420,24 +1296,6 @@ export const CommandRespondPayloadSchema = z
|
|
|
1420
1296
|
value: z.unknown(),
|
|
1421
1297
|
})
|
|
1422
1298
|
.passthrough();
|
|
1423
|
-
/** `action.delivered`: the Runtime sent an Action to its endpoint. */
|
|
1424
|
-
export const ActionDeliveredPayloadSchema = z
|
|
1425
|
-
.object({
|
|
1426
|
-
actionId: z.string().min(1),
|
|
1427
|
-
generation: z.number().int().positive(),
|
|
1428
|
-
...eventAgent,
|
|
1429
|
-
})
|
|
1430
|
-
.passthrough();
|
|
1431
|
-
/** `action.delivery_failed`: a delivery did not reach its endpoint, or was refused; it is retried. */
|
|
1432
|
-
export const ActionDeliveryFailedPayloadSchema = z
|
|
1433
|
-
.object({
|
|
1434
|
-
actionId: z.string().min(1),
|
|
1435
|
-
generation: z.number().int().positive(),
|
|
1436
|
-
reason: z.string(),
|
|
1437
|
-
message: z.string().optional(),
|
|
1438
|
-
retryInMs: z.number().int().nonnegative(),
|
|
1439
|
-
})
|
|
1440
|
-
.passthrough();
|
|
1441
1299
|
/** `sandbox.state`: the session's sandbox changed state. */
|
|
1442
1300
|
export const SandboxStatePayloadSchema = z
|
|
1443
1301
|
.object({
|
|
@@ -1469,7 +1327,7 @@ export const SandboxExecPayloadSchema = z
|
|
|
1469
1327
|
durationMs: z.number().nonnegative(),
|
|
1470
1328
|
})
|
|
1471
1329
|
.passthrough();
|
|
1472
|
-
/** `node.started`: a workflow node
|
|
1330
|
+
/** `node.started`: a workflow tool node started. */
|
|
1473
1331
|
export const NodeStartedPayloadSchema = z
|
|
1474
1332
|
.object({
|
|
1475
1333
|
path: z.string(),
|
|
@@ -1507,15 +1365,6 @@ export const LoopVerifiedPayloadSchema = z
|
|
|
1507
1365
|
data: z.unknown().optional(),
|
|
1508
1366
|
})
|
|
1509
1367
|
.passthrough();
|
|
1510
|
-
/** `loop.decided`: a Loop's decide step chose to iterate again (`input`) or finish (`output`). */
|
|
1511
|
-
export const LoopDecidedPayloadSchema = z
|
|
1512
|
-
.object({
|
|
1513
|
-
path: z.string(),
|
|
1514
|
-
n: z.number().int(),
|
|
1515
|
-
next: z.enum(["input", "output"]),
|
|
1516
|
-
patched: z.boolean(),
|
|
1517
|
-
})
|
|
1518
|
-
.passthrough();
|
|
1519
1368
|
/**
|
|
1520
1369
|
* `transcript.updated` (internal; blueprint P0.3): the own loop's model-facing transcript after a
|
|
1521
1370
|
* settled segment, as an edit of the previous one: keep its first `keep` entries, then append
|
|
@@ -1602,6 +1451,30 @@ export const ArtifactExportSkippedPayloadSchema = z
|
|
|
1602
1451
|
export const ArtifactExportFailedPayloadSchema = z
|
|
1603
1452
|
.object({ name: z.string(), message: z.string() })
|
|
1604
1453
|
.passthrough();
|
|
1454
|
+
/** What readying one declared MCP server found (`mcp.discovered`). */
|
|
1455
|
+
export const McpServerOutcomeSchema = z
|
|
1456
|
+
.object({
|
|
1457
|
+
/** The agent used as a tool that declares the server; absent for the session's root agent. */
|
|
1458
|
+
agentId: z.string().optional(),
|
|
1459
|
+
capabilityId: z.string(),
|
|
1460
|
+
serverName: z.string(),
|
|
1461
|
+
/** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
|
|
1462
|
+
outcome: z.enum(["connected", "refused", "failed"]),
|
|
1463
|
+
message: z.string(),
|
|
1464
|
+
/** The tools it added to the session; 0 unless connected. */
|
|
1465
|
+
tools: z.number().int().nonnegative(),
|
|
1466
|
+
/** The credentials a refusal names. */
|
|
1467
|
+
credentialIds: z.array(z.string()).optional(),
|
|
1468
|
+
})
|
|
1469
|
+
.passthrough();
|
|
1470
|
+
/**
|
|
1471
|
+
* `mcp.discovered`: the session's first turn readied its MCP servers and pinned the tools they
|
|
1472
|
+
* offer, one outcome per declared server. A server that did not connect adds no tools for the
|
|
1473
|
+
* session's life, so this is where the model's missing tools show (also `mcpDiagnostics`).
|
|
1474
|
+
*/
|
|
1475
|
+
export const McpDiscoveredPayloadSchema = z
|
|
1476
|
+
.object({ servers: z.array(McpServerOutcomeSchema) })
|
|
1477
|
+
.passthrough();
|
|
1605
1478
|
/**
|
|
1606
1479
|
* The event catalog (Durable Streams §9.5): every session event type, its payload schema, its
|
|
1607
1480
|
* payload schema version and who writes it. A type not listed here cannot be written. A type
|
|
@@ -1624,18 +1497,10 @@ export const EVENT_CATALOG = {
|
|
|
1624
1497
|
"model.failed": { payload: ModelFailedPayloadSchema, source: "loop", version: 1 },
|
|
1625
1498
|
"context.compacted": { payload: ContextCompactedPayloadSchema, source: "loop", version: 1 },
|
|
1626
1499
|
"tool.completed": { payload: ToolCompletedPayloadSchema, source: "loop", version: 1 },
|
|
1627
|
-
"action.pending": { payload: ActionPendingPayloadSchema, source: "loop", version: 1 },
|
|
1628
|
-
"action.delivered": { payload: ActionDeliveredPayloadSchema, source: "loop", version: 1 },
|
|
1629
|
-
"action.delivery_failed": {
|
|
1630
|
-
payload: ActionDeliveryFailedPayloadSchema,
|
|
1631
|
-
source: "loop",
|
|
1632
|
-
version: 1,
|
|
1633
|
-
},
|
|
1634
|
-
"action.completed": { payload: ActionCompletedPayloadSchema, source: "api", version: 1 },
|
|
1635
|
-
"action.uncertain": { payload: ActionUncertainPayloadSchema, source: "loop", version: 1 },
|
|
1636
1500
|
"effect.uncertain": { payload: EffectUncertainPayloadSchema, source: "loop", version: 1 },
|
|
1637
1501
|
"delegation.started": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
|
|
1638
1502
|
"delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
|
|
1503
|
+
"mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1 },
|
|
1639
1504
|
"sandbox.state": { payload: SandboxStatePayloadSchema, source: "loop", version: 1 },
|
|
1640
1505
|
"sandbox.exec": { payload: SandboxExecPayloadSchema, source: "loop", version: 1 },
|
|
1641
1506
|
"sandbox.attached": { payload: SandboxAttachedPayloadSchema, source: "api", version: 1 },
|
|
@@ -1643,7 +1508,6 @@ export const EVENT_CATALOG = {
|
|
|
1643
1508
|
"node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
|
|
1644
1509
|
"loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
|
|
1645
1510
|
"loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
|
|
1646
|
-
"loop.decided": { payload: LoopDecidedPayloadSchema, source: "api", version: 1 },
|
|
1647
1511
|
"artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1 },
|
|
1648
1512
|
"artifact.version.created": {
|
|
1649
1513
|
payload: ArtifactVersionPayloadSchema,
|
|
@@ -1729,6 +1593,10 @@ export const ReadyResponseSchema = z.object({
|
|
|
1729
1593
|
status: z.enum(["ready", "not_ready"]),
|
|
1730
1594
|
service: z.string(),
|
|
1731
1595
|
checks: z.record(z.string(), z.boolean()),
|
|
1596
|
+
/** The open Tenant's harnesses: `connected` counts those on the Harness API listener. */
|
|
1597
|
+
harness: z
|
|
1598
|
+
.object({ mode: z.enum(["remote", "in-process"]), connected: z.number().int().nonnegative() })
|
|
1599
|
+
.optional(),
|
|
1732
1600
|
});
|
|
1733
1601
|
export const ProtocolRejectedResponseSchema = z
|
|
1734
1602
|
.object({
|
|
@@ -1769,8 +1637,8 @@ export const TenantCauseSchema = z
|
|
|
1769
1637
|
})
|
|
1770
1638
|
.strict();
|
|
1771
1639
|
/**
|
|
1772
|
-
* The Host's one Tenant
|
|
1773
|
-
*
|
|
1640
|
+
* The Host's one Tenant. `unavailable` while it opens, when opening it failed (`cause`), or
|
|
1641
|
+
* when it is closing.
|
|
1774
1642
|
*/
|
|
1775
1643
|
export const HostTenantSchema = z
|
|
1776
1644
|
.object({
|
|
@@ -1812,48 +1680,30 @@ export const HarnessStatusSchema = z
|
|
|
1812
1680
|
workspace: z.boolean(),
|
|
1813
1681
|
})
|
|
1814
1682
|
.strict();
|
|
1815
|
-
|
|
1683
|
+
/**
|
|
1684
|
+
* A key of the Tenant (`/v1/tenant/keys`, `nylorun-operate keys`), named by its id
|
|
1685
|
+
* (`APPLICATION_KEY_ID_PATTERN`), with its role. The Runtime keeps only its hash.
|
|
1686
|
+
*/
|
|
1687
|
+
export const OperatorKeySchema = z
|
|
1816
1688
|
.object({
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
uncertainEffects: z.number().int().nonnegative(),
|
|
1822
|
-
/** This process's stream relay, when it runs one (a Host with S2). */
|
|
1823
|
-
relay: StreamRelayStatusSchema.optional(),
|
|
1824
|
-
/** The open Tenant's harnesses. */
|
|
1825
|
-
harness: HarnessStatusSchema.optional(),
|
|
1689
|
+
id: z.string().min(1),
|
|
1690
|
+
role: z.string().min(1),
|
|
1691
|
+
/** When the current key was issued: created, or last rotated. */
|
|
1692
|
+
createdAt: z.string().min(1),
|
|
1826
1693
|
})
|
|
1827
1694
|
.strict();
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
url: z.string().min(1),
|
|
1832
|
-
pid: z.number().int(),
|
|
1833
|
-
version: z.string().min(1),
|
|
1834
|
-
protocol: ProtocolRangeSchema,
|
|
1835
|
-
tenant: HostTenantSchema,
|
|
1836
|
-
aggregate: HostAggregateSchema,
|
|
1837
|
-
})
|
|
1695
|
+
/** `GET /v1/tenant/keys`: the Tenant's keys, by id. */
|
|
1696
|
+
export const ListOperatorKeysResponseSchema = z
|
|
1697
|
+
.object({ keys: z.array(OperatorKeySchema) })
|
|
1838
1698
|
.strict();
|
|
1839
|
-
/**
|
|
1840
|
-
export const
|
|
1841
|
-
.
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
aggregate: HostAggregateSchema,
|
|
1848
|
-
host: z
|
|
1849
|
-
.object({
|
|
1850
|
-
hostId: z.string().min(1),
|
|
1851
|
-
url: z.string().min(1),
|
|
1852
|
-
pid: z.number().int(),
|
|
1853
|
-
})
|
|
1854
|
-
.strict()
|
|
1855
|
-
.optional(),
|
|
1856
|
-
})
|
|
1699
|
+
/** `PUT /v1/tenant/keys/{keyId}`: the new key, shown this once; `rotated` when it replaced one. */
|
|
1700
|
+
export const PutOperatorKeyResponseSchema = OperatorKeySchema.extend({
|
|
1701
|
+
key: z.string().regex(/^[0-9a-f]{64}$/),
|
|
1702
|
+
rotated: z.boolean(),
|
|
1703
|
+
}).strict();
|
|
1704
|
+
/** `DELETE /v1/tenant/keys/{keyId}`: the key no longer authenticates. */
|
|
1705
|
+
export const DeleteOperatorKeyResponseSchema = z
|
|
1706
|
+
.object({ id: z.string().min(1), deleted: z.literal(true) })
|
|
1857
1707
|
.strict();
|
|
1858
1708
|
/**
|
|
1859
1709
|
* `.nylorun/link.json`: the installation a Project uses. Format 3 names the local `tenant`
|
|
@@ -1873,11 +1723,17 @@ export const ProjectLinkFileSchema = z
|
|
|
1873
1723
|
tenantId: z.string().min(1).optional(),
|
|
1874
1724
|
})
|
|
1875
1725
|
.passthrough();
|
|
1726
|
+
/**
|
|
1727
|
+
* `.nylorun/credentials.json`: the Project's application key and, from protocol 8, its
|
|
1728
|
+
* management key. Still format 1: readers that predate the management key ignore it.
|
|
1729
|
+
*/
|
|
1876
1730
|
export const ProjectCredentialsFileSchema = z
|
|
1877
1731
|
.object({
|
|
1878
1732
|
format: z.union([z.literal(0), z.literal(1)]).default(0),
|
|
1879
1733
|
applicationKey: z.string().regex(/^[0-9a-f]{64}$/),
|
|
1880
1734
|
principalId: z.string().min(1),
|
|
1735
|
+
managementKey: z.string().regex(/^[0-9a-f]{64}$/).optional(),
|
|
1736
|
+
managementPrincipalId: z.string().min(1).optional(),
|
|
1881
1737
|
})
|
|
1882
1738
|
.passthrough();
|
|
1883
1739
|
export const HostModelViewSchema = z.union([
|
|
@@ -1902,24 +1758,16 @@ export const TenantStatusSchema = z
|
|
|
1902
1758
|
store: z.boolean(),
|
|
1903
1759
|
scheduler: z.boolean(),
|
|
1904
1760
|
model: z.boolean(),
|
|
1905
|
-
endpoints: z.boolean(),
|
|
1906
1761
|
schema: z.boolean(),
|
|
1907
1762
|
})
|
|
1908
1763
|
.strict(),
|
|
1909
1764
|
model: HostModelViewSchema,
|
|
1910
|
-
agents
|
|
1911
|
-
|
|
1912
|
-
agentId: z.string(),
|
|
1913
|
-
registered: z.boolean(),
|
|
1914
|
-
/** The agent has a registered Action endpoint. */
|
|
1915
|
-
endpoint: z.boolean(),
|
|
1916
|
-
})
|
|
1917
|
-
.strict()),
|
|
1765
|
+
/** The registered agents. */
|
|
1766
|
+
agents: z.array(z.object({ agentId: z.string() }).strict()),
|
|
1918
1767
|
counts: z
|
|
1919
1768
|
.object({
|
|
1920
1769
|
sessions: z.number().int().nonnegative(),
|
|
1921
1770
|
runningSessions: z.number().int().nonnegative(),
|
|
1922
|
-
pendingActions: z.number().int().nonnegative(),
|
|
1923
1771
|
uncertainEffects: z.number().int().nonnegative(),
|
|
1924
1772
|
})
|
|
1925
1773
|
.strict(),
|
|
@@ -2016,22 +1864,30 @@ export const ResetTenantRequestSchema = z
|
|
|
2016
1864
|
.strict();
|
|
2017
1865
|
/**
|
|
2018
1866
|
* Acting for a subject (Host feature `subject-headers`): what an application principal may
|
|
2019
|
-
* narrow a request to. `sessions:own`
|
|
2020
|
-
*
|
|
2021
|
-
*
|
|
1867
|
+
* narrow a request to. `sessions:own` reaches only the subject's own sessions; the others reach
|
|
1868
|
+
* Tenant-wide resources. `sandboxes:write` creates and deletes sandboxes (Host feature
|
|
1869
|
+
* `sandboxes`); a token caller's reach only the ids its sandbox grants name. Vaults are the
|
|
1870
|
+
* installation's, managed with management keys on the Management API (protocol 8).
|
|
2022
1871
|
*/
|
|
2023
1872
|
export const SUBJECT_SCOPES = [
|
|
2024
1873
|
"agents:read",
|
|
2025
1874
|
"agents:write",
|
|
2026
1875
|
"sessions:own",
|
|
2027
|
-
"vaults:own",
|
|
2028
|
-
"tenant:settings",
|
|
2029
1876
|
"sandboxes:write",
|
|
2030
1877
|
];
|
|
1878
|
+
/**
|
|
1879
|
+
* Retired scopes: `Nylorun-Scopes` may still name them (older clients do), and they grant
|
|
1880
|
+
* nothing. `vaults:own` left in protocol 7; `tenant:settings` in protocol 8, when the Tenant's
|
|
1881
|
+
* settings moved to the Management API, which no subject reaches.
|
|
1882
|
+
*/
|
|
1883
|
+
const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
|
|
2031
1884
|
/** 1–200 visible ASCII characters; spaces only inside. */
|
|
2032
1885
|
const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
|
|
2033
|
-
/**
|
|
2034
|
-
|
|
1886
|
+
/**
|
|
1887
|
+
* Owner ids the Runtime uses itself: the host model's vault is owned by `host`, installation
|
|
1888
|
+
* vaults by `installation`.
|
|
1889
|
+
*/
|
|
1890
|
+
const RESERVED_SUBJECTS = new Set(["host", INSTALLATION_OWNER]);
|
|
2035
1891
|
/** A valid subject: 1–200 visible ASCII characters, not reserved by the Runtime. */
|
|
2036
1892
|
export function isSubject(value) {
|
|
2037
1893
|
return (typeof value === "string" &&
|
|
@@ -2050,12 +1906,13 @@ export function parseSubjectHeaders(subject, scopes) {
|
|
|
2050
1906
|
};
|
|
2051
1907
|
if (RESERVED_SUBJECTS.has(subject))
|
|
2052
1908
|
return { ok: false, message: `Subject ${subject} is reserved` };
|
|
2053
|
-
const
|
|
2054
|
-
if (
|
|
1909
|
+
const named = (scopes ?? "").split(" ").filter(Boolean);
|
|
1910
|
+
if (named.length === 0)
|
|
2055
1911
|
return {
|
|
2056
1912
|
ok: false,
|
|
2057
1913
|
message: "Nylorun-Scopes is required with Nylorun-Subject",
|
|
2058
1914
|
};
|
|
1915
|
+
const names = named.filter((name) => !RETIRED_SUBJECT_SCOPES.includes(name));
|
|
2059
1916
|
const unknown = names.filter((name) => !SUBJECT_SCOPES.includes(name));
|
|
2060
1917
|
if (unknown.length > 0)
|
|
2061
1918
|
return { ok: false, message: `Unknown scope ${unknown.join(", ")}` };
|
|
@@ -2065,127 +1922,33 @@ export function parseSubjectHeaders(subject, scopes) {
|
|
|
2065
1922
|
scopes: new Set(names),
|
|
2066
1923
|
};
|
|
2067
1924
|
}
|
|
2068
|
-
// ---
|
|
2069
|
-
/**
|
|
1925
|
+
// --- token callers (Host feature `trusted-issuers`) ------------------------------------------
|
|
1926
|
+
/**
|
|
1927
|
+
* Scopes a token caller (a trusted issuer's token) may carry: never `agents:write`.
|
|
1928
|
+
*/
|
|
2070
1929
|
export const TOKEN_SCOPES = [
|
|
2071
1930
|
"agents:read",
|
|
2072
1931
|
"sessions:own",
|
|
2073
|
-
"vaults:own",
|
|
2074
1932
|
"sandboxes:write",
|
|
2075
1933
|
];
|
|
2076
|
-
/** The most
|
|
1934
|
+
/** The most sandbox grants one token caller carries. */
|
|
2077
1935
|
export const TOKEN_SANDBOX_GRANTS_MAX = 16;
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
export const
|
|
2083
|
-
/**
|
|
2084
|
-
|
|
1936
|
+
/**
|
|
1937
|
+
* The longest a token the Runtime signs itself lives, in seconds (capability links): rotating
|
|
1938
|
+
* signing keys revokes the previous key once the longest token it may have signed has expired.
|
|
1939
|
+
*/
|
|
1940
|
+
export const TOKEN_TTL_MAX_SECONDS = 900;
|
|
1941
|
+
/**
|
|
1942
|
+
* The `iss` of every token a Tenant's Runtime signs itself: capability links, run, host and
|
|
1943
|
+
* egress tokens.
|
|
1944
|
+
*/
|
|
1945
|
+
export function tenantTokenIssuer(tenantId) {
|
|
2085
1946
|
return `urn:nylorun:tenant:${tenantId}`;
|
|
2086
1947
|
}
|
|
2087
|
-
/** Token lifetimes, in seconds. */
|
|
2088
|
-
export const TOKEN_TTL_MIN_SECONDS = 60;
|
|
2089
|
-
export const TOKEN_TTL_MAX_SECONDS = 900;
|
|
2090
|
-
export const TOKEN_TTL_DEFAULT_SECONDS = 600;
|
|
2091
|
-
/** A role's name in the access policy; `anon` is reserved for publishable keys. */
|
|
2092
|
-
export const ROLE_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
2093
1948
|
const AgentAllowlistSchema = z.union([
|
|
2094
1949
|
z.literal("*"),
|
|
2095
1950
|
z.array(z.string().min(1)),
|
|
2096
1951
|
]);
|
|
2097
|
-
export const RoleLimitsSchema = z
|
|
2098
|
-
.object({
|
|
2099
|
-
turnsPerHour: z.number().int().min(1).max(100_000).optional(),
|
|
2100
|
-
concurrentTurns: z.number().int().min(1).max(1000).optional(),
|
|
2101
|
-
})
|
|
2102
|
-
.strict();
|
|
2103
|
-
export const AccessRoleSchema = z
|
|
2104
|
-
.object({
|
|
2105
|
-
scopes: z.array(TokenScopeSchema).min(1),
|
|
2106
|
-
agents: AgentAllowlistSchema,
|
|
2107
|
-
limits: RoleLimitsSchema.optional(),
|
|
2108
|
-
})
|
|
2109
|
-
.strict();
|
|
2110
|
-
/**
|
|
2111
|
-
* The Tenant's access policy: what each role may do with a subject token, what a publishable
|
|
2112
|
-
* key grants alone (`anon`), and how long tokens live. Without roles nothing can be minted.
|
|
2113
|
-
*/
|
|
2114
|
-
export const AccessPolicySchema = z
|
|
2115
|
-
.object({
|
|
2116
|
-
version: z.literal(1),
|
|
2117
|
-
roles: z
|
|
2118
|
-
.record(z.string(), AccessRoleSchema)
|
|
2119
|
-
.superRefine((roles, issue) => {
|
|
2120
|
-
for (const name of Object.keys(roles))
|
|
2121
|
-
if (!ROLE_NAME_PATTERN.test(name) || name === "anon")
|
|
2122
|
-
issue.addIssue({
|
|
2123
|
-
code: "custom",
|
|
2124
|
-
message: `Role name ${name} is invalid or reserved`,
|
|
2125
|
-
path: [name],
|
|
2126
|
-
});
|
|
2127
|
-
}),
|
|
2128
|
-
anon: z
|
|
2129
|
-
.object({
|
|
2130
|
-
scopes: z.array(z.literal("agents:read")),
|
|
2131
|
-
agents: AgentAllowlistSchema,
|
|
2132
|
-
})
|
|
2133
|
-
.strict(),
|
|
2134
|
-
tokens: z
|
|
2135
|
-
.object({
|
|
2136
|
-
maxTtlSeconds: z
|
|
2137
|
-
.number()
|
|
2138
|
-
.int()
|
|
2139
|
-
.min(TOKEN_TTL_MIN_SECONDS)
|
|
2140
|
-
.max(TOKEN_TTL_MAX_SECONDS),
|
|
2141
|
-
})
|
|
2142
|
-
.strict(),
|
|
2143
|
-
})
|
|
2144
|
-
.strict();
|
|
2145
|
-
/** The policy of a Tenant that never set one: no roles, nothing for `anon`. */
|
|
2146
|
-
export const DEFAULT_ACCESS_POLICY = Object.freeze({
|
|
2147
|
-
version: 1,
|
|
2148
|
-
roles: {},
|
|
2149
|
-
anon: { scopes: [], agents: [] },
|
|
2150
|
-
tokens: { maxTtlSeconds: TOKEN_TTL_DEFAULT_SECONDS },
|
|
2151
|
-
});
|
|
2152
|
-
export const PutAccessPolicyRequestSchema = z
|
|
2153
|
-
.object({ requestId: RequestIdSchema, policy: AccessPolicySchema })
|
|
2154
|
-
.strict();
|
|
2155
|
-
export const CreateTokenRequestSchema = z
|
|
2156
|
-
.object({
|
|
2157
|
-
requestId: RequestIdSchema,
|
|
2158
|
-
subject: z.string().refine(isSubject, "subject must be 1-200 visible ASCII characters and not reserved"),
|
|
2159
|
-
role: z.string().regex(ROLE_NAME_PATTERN),
|
|
2160
|
-
scopes: z.array(TokenScopeSchema).min(1).optional(),
|
|
2161
|
-
agents: z.array(z.string().min(1)).optional(),
|
|
2162
|
-
/**
|
|
2163
|
-
* The sandboxes the token reaches (its `sbx` claim): exact ids, or prefixes ending in `/*`.
|
|
2164
|
-
* Absent or empty: none (Host feature `sandboxes`).
|
|
2165
|
-
*/
|
|
2166
|
-
sandboxes: z.array(SandboxGrantSchema).max(TOKEN_SANDBOX_GRANTS_MAX).optional(),
|
|
2167
|
-
ttlSeconds: z
|
|
2168
|
-
.number()
|
|
2169
|
-
.int()
|
|
2170
|
-
.min(TOKEN_TTL_MIN_SECONDS)
|
|
2171
|
-
.max(TOKEN_TTL_MAX_SECONDS)
|
|
2172
|
-
.optional(),
|
|
2173
|
-
})
|
|
2174
|
-
.strict();
|
|
2175
|
-
export const CreateTokenResponseSchema = z
|
|
2176
|
-
.object({
|
|
2177
|
-
token: z.string().min(1),
|
|
2178
|
-
/** ISO time the token stops being accepted. */
|
|
2179
|
-
expiresAt: z.string().min(1),
|
|
2180
|
-
subject: z.string(),
|
|
2181
|
-
role: z.string(),
|
|
2182
|
-
scopes: z.array(TokenScopeSchema),
|
|
2183
|
-
agents: AgentAllowlistSchema,
|
|
2184
|
-
/** The token's `sbx` grants, when it has any. */
|
|
2185
|
-
sandboxes: z.array(z.string()).optional(),
|
|
2186
|
-
keyId: z.string(),
|
|
2187
|
-
})
|
|
2188
|
-
.strict();
|
|
2189
1952
|
export const SIGNING_KEY_STATES = ["standby", "current", "previous", "revoked"];
|
|
2190
1953
|
/** A public JSON Web Key as the JWKS publishes it. */
|
|
2191
1954
|
export const PublicJwkSchema = z
|
|
@@ -2221,18 +1984,47 @@ export const RotateSigningKeysRequestSchema = z
|
|
|
2221
1984
|
export const RevokeSigningKeyRequestSchema = z
|
|
2222
1985
|
.object({ requestId: RequestIdSchema })
|
|
2223
1986
|
.strict();
|
|
2224
|
-
|
|
1987
|
+
// --- trusted issuers (Host feature `trusted-issuers`) --------------------------------------
|
|
1988
|
+
/**
|
|
1989
|
+
* Scopes a trusted issuer's tokens may carry (`allowedScopes` in the identity file): the
|
|
1990
|
+
* token scopes, and `studio`, an operator scope no Runtime route requires (Studio
|
|
1991
|
+
* admits a person who holds it, Tenant-wide).
|
|
1992
|
+
*/
|
|
1993
|
+
export const ISSUER_SCOPES = [...TOKEN_SCOPES, "studio"];
|
|
1994
|
+
/** Every scope a caller can hold: the subject scopes, and an issuer token's `studio`. */
|
|
1995
|
+
export const CALLER_SCOPES = [...SUBJECT_SCOPES, "studio"];
|
|
1996
|
+
/**
|
|
1997
|
+
* `GET /v1/me`: who the Runtime takes the caller to be, for any credential.
|
|
1998
|
+
*
|
|
1999
|
+
* - `via` is how the caller authenticated: `application:<principalId>` (an application key,
|
|
2000
|
+
* acting as itself), `subject` (an application key acting for `Nylorun-Subject`) or
|
|
2001
|
+
* `issuer:<name>` (a token from the identity file's issuer `name`).
|
|
2002
|
+
* - `subject` is the person the request acts for; absent for an application key alone.
|
|
2003
|
+
* - `scopes`: what the caller holds. An application key alone holds every subject scope.
|
|
2004
|
+
* - `agents`: the agents it may reach, `*` for all.
|
|
2005
|
+
* - `sandboxes`: the sandbox grants of a token caller (empty reaches none); absent for an
|
|
2006
|
+
* application key, alone or acting for a subject, which no grant limits.
|
|
2007
|
+
*/
|
|
2008
|
+
export const MeResponseSchema = z
|
|
2225
2009
|
.object({
|
|
2226
|
-
|
|
2227
|
-
|
|
2010
|
+
subject: z
|
|
2011
|
+
.string()
|
|
2012
|
+
.optional()
|
|
2013
|
+
.meta({ description: "The person the request acts for; absent for an application key alone" }),
|
|
2014
|
+
scopes: z.array(z.enum(CALLER_SCOPES)),
|
|
2015
|
+
agents: AgentAllowlistSchema,
|
|
2016
|
+
sandboxes: z
|
|
2017
|
+
.array(z.string())
|
|
2018
|
+
.optional()
|
|
2019
|
+
.meta({
|
|
2020
|
+
description: "A token caller's sandbox grants (empty reaches none); absent when no grant limits the caller",
|
|
2021
|
+
}),
|
|
2022
|
+
via: z.string().meta({
|
|
2023
|
+
description: "How the caller authenticated: `application:<principalId>`, `management:<principalId>`, `subject` or `issuer:<name>`",
|
|
2024
|
+
}),
|
|
2228
2025
|
})
|
|
2229
2026
|
.strict();
|
|
2230
|
-
|
|
2231
|
-
.object({ subject: z.string(), epoch: z.number().int().nonnegative() })
|
|
2232
|
-
.strict();
|
|
2233
|
-
// --- publishable keys (Host feature `browser-access`) --------------------------------------
|
|
2234
|
-
/** Loopback origins with any port, for development: `http://localhost:*`, `http://127.0.0.1:*`. */
|
|
2235
|
-
export const LOOPBACK_ORIGIN_WILDCARDS = ["http://localhost:*", "http://127.0.0.1:*"];
|
|
2027
|
+
// --- origins ---------------------------------------------------------------------------------
|
|
2236
2028
|
/** True for a serialized web origin: `scheme://host[:port]`, lowercase, no path. */
|
|
2237
2029
|
export function isSerializedOrigin(value) {
|
|
2238
2030
|
let url;
|
|
@@ -2247,51 +2039,7 @@ export function isSerializedOrigin(value) {
|
|
|
2247
2039
|
// Host names only: no wildcards or other characters URL parsing lets through.
|
|
2248
2040
|
/^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*|\[[0-9a-f:.]+\])$/.test(url.hostname));
|
|
2249
2041
|
}
|
|
2250
|
-
|
|
2251
|
-
export const OriginEntrySchema = z
|
|
2252
|
-
.string()
|
|
2253
|
-
.refine((value) => LOOPBACK_ORIGIN_WILDCARDS.includes(value) ||
|
|
2254
|
-
isSerializedOrigin(value), "must be an origin such as https://app.example.com, or http://localhost:*");
|
|
2255
|
-
/** True when `origin` (a request's `Origin`) is allowed by `origins`. */
|
|
2256
|
-
export function originAllowed(origins, origin) {
|
|
2257
|
-
if (!isSerializedOrigin(origin))
|
|
2258
|
-
return false;
|
|
2259
|
-
for (const entry of origins) {
|
|
2260
|
-
if (entry === origin)
|
|
2261
|
-
return true;
|
|
2262
|
-
if (entry.endsWith(":*")) {
|
|
2263
|
-
const prefix = entry.slice(0, -1);
|
|
2264
|
-
if (origin.startsWith(prefix) && /^\d{1,5}$/.test(origin.slice(prefix.length)))
|
|
2265
|
-
return true;
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
return false;
|
|
2269
|
-
}
|
|
2270
|
-
export const PublishableKeySchema = z
|
|
2271
|
-
.object({
|
|
2272
|
-
id: z.string(),
|
|
2273
|
-
name: z.string(),
|
|
2274
|
-
key: z.string(),
|
|
2275
|
-
origins: z.array(z.string()),
|
|
2276
|
-
createdAt: z.string(),
|
|
2277
|
-
revokedAt: z.string().nullable(),
|
|
2278
|
-
})
|
|
2279
|
-
.strict();
|
|
2280
|
-
export const CreatePublishableKeyRequestSchema = z
|
|
2281
|
-
.object({
|
|
2282
|
-
requestId: RequestIdSchema,
|
|
2283
|
-
name: z.string().min(1).max(100),
|
|
2284
|
-
/** `[]` allows native apps only (no `Origin`). */
|
|
2285
|
-
origins: z.array(OriginEntrySchema).max(100),
|
|
2286
|
-
})
|
|
2287
|
-
.strict();
|
|
2288
|
-
export const UpdatePublishableKeyRequestSchema = z
|
|
2289
|
-
.object({
|
|
2290
|
-
requestId: RequestIdSchema,
|
|
2291
|
-
origins: z.array(OriginEntrySchema).max(100),
|
|
2292
|
-
})
|
|
2293
|
-
.strict();
|
|
2294
|
-
// Successful answers of the Tenant and Admin APIs that had no schema of their own. With the
|
|
2042
|
+
// Successful answers of the Runtime and Management APIs that had no schema of their own. With the
|
|
2295
2043
|
// request schemas above they describe every body the Runtime sends (its OpenAPI document).
|
|
2296
2044
|
/** `GET /v1/agents` with an application key: every definition, manifest included. */
|
|
2297
2045
|
export const AgentDefinitionViewSchema = z
|
|
@@ -2305,7 +2053,7 @@ export const AgentDefinitionViewSchema = z
|
|
|
2305
2053
|
export const ListAgentsResponseSchema = z
|
|
2306
2054
|
.object({ agents: z.array(AgentDefinitionViewSchema) })
|
|
2307
2055
|
.strict();
|
|
2308
|
-
/** `GET /v1/agents` with a
|
|
2056
|
+
/** `GET /v1/agents` with a token caller's credential: the allowed agents' names only. */
|
|
2309
2057
|
export const PublicAgentSchema = z
|
|
2310
2058
|
.object({
|
|
2311
2059
|
agentId: z.string(),
|
|
@@ -2373,8 +2121,6 @@ export const SessionViewSchema = z
|
|
|
2373
2121
|
/** What the session waits on: interactions, approvals, timers. */
|
|
2374
2122
|
waits: z.unknown().optional(),
|
|
2375
2123
|
error: z.string().optional(),
|
|
2376
|
-
/** Its Actions that are pending, being delivered or uncertain. */
|
|
2377
|
-
actions: z.array(ActionSchema),
|
|
2378
2124
|
uncertainEffects: z.array(z
|
|
2379
2125
|
.object({
|
|
2380
2126
|
effectId: z.string(),
|
|
@@ -2559,18 +2305,31 @@ export const ListVaultsResponseSchema = z.object({ vaults: z.array(VaultInfoSche
|
|
|
2559
2305
|
export const ListCredentialsResponseSchema = z
|
|
2560
2306
|
.object({ credentials: z.array(CredentialInfoSchema) })
|
|
2561
2307
|
.strict();
|
|
2562
|
-
/**
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2308
|
+
/**
|
|
2309
|
+
* `POST /v1/vaults/{vaultId}/oauth/start` (F9 C2): sign the installation in to the remote MCP
|
|
2310
|
+
* server at `url`, declared as `server`, and store its OAuth credential in the installation vault.
|
|
2311
|
+
* `clientId` names a client registered with the authorization server; without one the Runtime
|
|
2312
|
+
* registers itself (RFC 7591) when the server allows it.
|
|
2313
|
+
*/
|
|
2314
|
+
export const StartOAuthRequestSchema = z
|
|
2315
|
+
.object({
|
|
2316
|
+
url: z.string().min(1).max(2048),
|
|
2317
|
+
server: z.string().min(1).max(128),
|
|
2318
|
+
clientId: z.string().min(1).max(512).optional(),
|
|
2319
|
+
})
|
|
2567
2320
|
.strict();
|
|
2568
|
-
|
|
2569
|
-
|
|
2321
|
+
/** Where to send the browser, and until when the sign-in can finish. */
|
|
2322
|
+
export const StartOAuthResponseSchema = z
|
|
2323
|
+
.object({ authorizeUrl: z.string(), expiresAt: z.string() })
|
|
2570
2324
|
.strict();
|
|
2571
|
-
/**
|
|
2325
|
+
/** A deleted vault or credential. */
|
|
2326
|
+
export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
|
|
2327
|
+
/**
|
|
2328
|
+
* The last frame of a session stream the Runtime ends: `event: nylorun.closed`, when the
|
|
2329
|
+
* token caller's token expires.
|
|
2330
|
+
*/
|
|
2572
2331
|
export const StreamClosedFrameSchema = z
|
|
2573
|
-
.object({ reason: z.enum(["token_expired"
|
|
2332
|
+
.object({ reason: z.enum(["token_expired"]) })
|
|
2574
2333
|
.strict();
|
|
2575
2334
|
/**
|
|
2576
2335
|
* The `code` of an AG-UI `RUN_ERROR` the Runtime sends: a rejection's code, or `session_busy`
|
|
@@ -2581,128 +2340,6 @@ export const AgUiRunErrorCodeSchema = z.enum([
|
|
|
2581
2340
|
"session_busy",
|
|
2582
2341
|
"runtime_error",
|
|
2583
2342
|
]);
|
|
2584
|
-
// --- Action endpoints: the Runtime delivers Actions over HTTP ------------------------------
|
|
2585
|
-
/** The JWT `typ` of a delivery token (RFC 8725 explicit typing). */
|
|
2586
|
-
export const DELIVERY_TOKEN_TYPE = "nylorun-delivery+jwt";
|
|
2587
|
-
/**
|
|
2588
|
-
* A delivery token lives no longer than a subject token: rotating signing keys revokes the
|
|
2589
|
-
* previous key once the longest token it may have signed has expired.
|
|
2590
|
-
*/
|
|
2591
|
-
export const DELIVERY_TOKEN_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
|
|
2592
|
-
/** Inline delivery timeouts, in milliseconds. The maximum keeps a token within its lifetime. */
|
|
2593
|
-
export const ENDPOINT_TIMEOUT_DEFAULT_MS = 60_000;
|
|
2594
|
-
export const ENDPOINT_TIMEOUT_MAX_MS = (DELIVERY_TOKEN_MAX_TTL_SECONDS - 60) * 1000;
|
|
2595
|
-
/** In-flight deliveries per endpoint when the registration does not say. */
|
|
2596
|
-
export const ENDPOINT_MAX_CONCURRENT_DEFAULT = 16;
|
|
2597
|
-
const isEndpointUrl = (value) => {
|
|
2598
|
-
try {
|
|
2599
|
-
const url = new URL(value);
|
|
2600
|
-
return ((url.protocol === "http:" || url.protocol === "https:") &&
|
|
2601
|
-
!url.username &&
|
|
2602
|
-
!url.password &&
|
|
2603
|
-
!url.hash);
|
|
2604
|
-
}
|
|
2605
|
-
catch {
|
|
2606
|
-
return false;
|
|
2607
|
-
}
|
|
2608
|
-
};
|
|
2609
|
-
const EndpointUrlSchema = z
|
|
2610
|
-
.string()
|
|
2611
|
-
.max(2048)
|
|
2612
|
-
.refine(isEndpointUrl, {
|
|
2613
|
-
message: "An endpoint URL is an http or https URL without credentials or a fragment",
|
|
2614
|
-
});
|
|
2615
|
-
/** One agent's or workflow's Action endpoint, as the application registers it. */
|
|
2616
|
-
export const EndpointRegistrationSchema = z
|
|
2617
|
-
.object({
|
|
2618
|
-
agentId: z.string().min(1),
|
|
2619
|
-
url: EndpointUrlSchema,
|
|
2620
|
-
implementationVersion: z.string().min(1),
|
|
2621
|
-
manifestHash: z.string().min(1).optional(),
|
|
2622
|
-
timeoutMs: z.number().int().min(1000).max(ENDPOINT_TIMEOUT_MAX_MS).optional(),
|
|
2623
|
-
maxConcurrent: z.number().int().min(1).max(256).optional(),
|
|
2624
|
-
})
|
|
2625
|
-
.strict();
|
|
2626
|
-
export const PutEndpointsRequestSchema = z
|
|
2627
|
-
.object({
|
|
2628
|
-
endpoints: z
|
|
2629
|
-
.array(EndpointRegistrationSchema)
|
|
2630
|
-
.min(1)
|
|
2631
|
-
.max(64)
|
|
2632
|
-
.refine((endpoints) => new Set(endpoints.map((e) => e.agentId)).size === endpoints.length, { message: "Endpoint registrations must be unique per agent" }),
|
|
2633
|
-
})
|
|
2634
|
-
.strict();
|
|
2635
|
-
/** What recent deliveries and the last ping say about an endpoint. */
|
|
2636
|
-
export const EndpointHealthSchema = z
|
|
2637
|
-
.object({
|
|
2638
|
-
lastDeliveryAt: z.string().optional(),
|
|
2639
|
-
lastSuccessAt: z.string().optional(),
|
|
2640
|
-
lastError: z.object({ code: z.string(), message: z.string() }).optional(),
|
|
2641
|
-
consecutiveFailures: z.number().int().nonnegative(),
|
|
2642
|
-
/** What the handler reported serving on the last ping. */
|
|
2643
|
-
served: z
|
|
2644
|
-
.object({
|
|
2645
|
-
implementationVersion: z.string(),
|
|
2646
|
-
manifestHash: z.string().optional(),
|
|
2647
|
-
})
|
|
2648
|
-
.strict()
|
|
2649
|
-
.optional(),
|
|
2650
|
-
})
|
|
2651
|
-
.strict();
|
|
2652
|
-
export const EndpointSchema = z
|
|
2653
|
-
.object({
|
|
2654
|
-
agentId: z.string(),
|
|
2655
|
-
url: z.string(),
|
|
2656
|
-
implementationVersion: z.string(),
|
|
2657
|
-
manifestHash: z.string().optional(),
|
|
2658
|
-
timeoutMs: z.number().int(),
|
|
2659
|
-
maxConcurrent: z.number().int(),
|
|
2660
|
-
health: EndpointHealthSchema,
|
|
2661
|
-
updatedAt: z.string(),
|
|
2662
|
-
})
|
|
2663
|
-
.strict();
|
|
2664
|
-
export const ListEndpointsResponseSchema = z
|
|
2665
|
-
.object({
|
|
2666
|
-
endpoints: z.array(EndpointSchema),
|
|
2667
|
-
})
|
|
2668
|
-
.strict();
|
|
2669
|
-
export const DeleteEndpointResponseSchema = z
|
|
2670
|
-
.object({ agentId: z.string(), deleted: z.literal(true) })
|
|
2671
|
-
.strict();
|
|
2672
|
-
/** The body the Runtime POSTs to an Action endpoint. */
|
|
2673
|
-
export const ActionDeliverySchema = z.discriminatedUnion("type", [
|
|
2674
|
-
z
|
|
2675
|
-
.object({
|
|
2676
|
-
type: z.literal("action"),
|
|
2677
|
-
action: ActionSchema,
|
|
2678
|
-
/** The Action's session has a sandbox, so `ctx.sandbox` is available. */
|
|
2679
|
-
sandbox: z.boolean(),
|
|
2680
|
-
})
|
|
2681
|
-
.strict(),
|
|
2682
|
-
z
|
|
2683
|
-
.object({
|
|
2684
|
-
type: z.literal("ping"),
|
|
2685
|
-
agentId: z.string().min(1),
|
|
2686
|
-
manifestHash: z.string().min(1).optional(),
|
|
2687
|
-
})
|
|
2688
|
-
.strict(),
|
|
2689
|
-
]);
|
|
2690
|
-
/** An Action endpoint's answer to a ping. */
|
|
2691
|
-
export const EndpointPingResponseSchema = z.object({
|
|
2692
|
-
agentId: z.string(),
|
|
2693
|
-
implementationVersion: z.string(),
|
|
2694
|
-
manifestHash: z.string().optional(),
|
|
2695
|
-
});
|
|
2696
|
-
/** The answer to a background delivery's heartbeat: a fresh token and the new deadline. */
|
|
2697
|
-
export const DeliveryHeartbeatResponseSchema = z.object({
|
|
2698
|
-
token: z.string().min(1),
|
|
2699
|
-
deadlineAt: z.string(),
|
|
2700
|
-
});
|
|
2701
|
-
/**
|
|
2702
|
-
* The receipt of a background result (`POST /v1/actions/:id/result`): a session command's
|
|
2703
|
-
* receipt without `requestId`, since the result carries none. The same result again returns it.
|
|
2704
|
-
*/
|
|
2705
|
-
export const ActionResultReceiptSchema = AcceptedResponseSchema.omit({ requestId: true });
|
|
2706
2343
|
// --- Studio embedding (Studio design §8) ---------------------------------------------------
|
|
2707
2344
|
/** A Tenant id as Studio's routes accept it. */
|
|
2708
2345
|
const STUDIO_TENANT_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
@@ -2788,7 +2425,8 @@ export const StudioEmbedMessageSchema = z.discriminatedUnion("kind", [
|
|
|
2788
2425
|
embed("token.expiring", { expiresAt: z.string().nullable() }),
|
|
2789
2426
|
embed("route.changed", { route: z.string() }),
|
|
2790
2427
|
embed("open.external", { url: EXTERNAL_URL }),
|
|
2791
|
-
|
|
2428
|
+
/** Asks the embedding app to open this session in its own UI. */
|
|
2429
|
+
embed("open.session", { sessionId: z.string().min(1) }),
|
|
2792
2430
|
embed("error", { code: z.string().min(1), message: z.string() }),
|
|
2793
2431
|
]);
|
|
2794
2432
|
/** Schemes that never name an embedder. */
|
|
@@ -2828,10 +2466,7 @@ export function parseFrameAncestors(value) {
|
|
|
2828
2466
|
// --- File artifacts (protocol 6, blueprint D35, F8.1) ----------------------------------------
|
|
2829
2467
|
/** The JWT `typ` of a capability link's token (RFC 8725 explicit typing). */
|
|
2830
2468
|
export const ARTIFACT_LINK_TOKEN_TYPE = "nylorun-artifact+jwt";
|
|
2831
|
-
/**
|
|
2832
|
-
* A capability link lives no longer than a subject token: rotating signing keys revokes the
|
|
2833
|
-
* previous key once the longest token it may have signed has expired.
|
|
2834
|
-
*/
|
|
2469
|
+
/** A capability link lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
|
|
2835
2470
|
export const ARTIFACT_LINK_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
|
|
2836
2471
|
export const ARTIFACT_LINK_DEFAULT_TTL_SECONDS = 300;
|
|
2837
2472
|
/** A Tenant's limits when it sets none: 100 MiB per file, 10 GiB in all. */
|
|
@@ -2886,6 +2521,16 @@ export const ListArtifactsResponseSchema = z
|
|
|
2886
2521
|
export const UploadArtifactResponseSchema = z
|
|
2887
2522
|
.object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
|
|
2888
2523
|
.strict();
|
|
2524
|
+
/**
|
|
2525
|
+
* `PUT /v1/files/sha256:{hex}`: a definition file the Runtime holds (track R2 M4), named by the
|
|
2526
|
+
* SHA-256 of its bytes. `201` stored it, `200` already had it.
|
|
2527
|
+
*/
|
|
2528
|
+
export const DefinitionFileViewSchema = z
|
|
2529
|
+
.object({
|
|
2530
|
+
sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
2531
|
+
size: z.number().int().nonnegative().max(DEFINITION_FILE_MAX_BYTES),
|
|
2532
|
+
})
|
|
2533
|
+
.strict();
|
|
2889
2534
|
export const DeleteArtifactResponseSchema = z
|
|
2890
2535
|
.object({ artifactId: z.string(), deleted: z.boolean() })
|
|
2891
2536
|
.strict();
|
|
@@ -2998,3 +2643,80 @@ export const TenantArtifactsViewSchema = z
|
|
|
2998
2643
|
usedBytes: z.number().int().nonnegative(),
|
|
2999
2644
|
})
|
|
3000
2645
|
.strict();
|
|
2646
|
+
/** Opt-in session reads (Host feature `session-reads`). */
|
|
2647
|
+
export const SessionListItemSchema = SessionSummarySchema.extend({
|
|
2648
|
+
lastTurnId: z.string().nullable(),
|
|
2649
|
+
sandboxId: z.string().nullable(),
|
|
2650
|
+
createdAt: z.string().nullable(),
|
|
2651
|
+
lastEventAt: z.string().nullable(),
|
|
2652
|
+
}).strict();
|
|
2653
|
+
export const SessionPageSchema = z
|
|
2654
|
+
.object({ sessions: z.array(SessionListItemSchema), nextCursor: z.string().nullable() })
|
|
2655
|
+
.strict();
|
|
2656
|
+
export const SessionManifestViewSchema = z
|
|
2657
|
+
.object({
|
|
2658
|
+
sessionId: z.string(),
|
|
2659
|
+
agentId: z.string(),
|
|
2660
|
+
manifestHash: z.string(),
|
|
2661
|
+
implementationVersion: z.string(),
|
|
2662
|
+
manifest: z.record(z.string(), z.unknown()),
|
|
2663
|
+
})
|
|
2664
|
+
.strict();
|
|
2665
|
+
export const HistoryPageSchema = SessionItemsResponseSchema.extend({ tail: z.boolean() });
|
|
2666
|
+
const usageNumbers = {
|
|
2667
|
+
inputTokens: z.number().int().nonnegative(),
|
|
2668
|
+
outputTokens: z.number().int().nonnegative(),
|
|
2669
|
+
totalTokens: z.number().int().nonnegative(),
|
|
2670
|
+
cachedTokens: z.number().int().nonnegative(),
|
|
2671
|
+
cacheWriteTokens: z.number().int().nonnegative(),
|
|
2672
|
+
reasoningTokens: z.number().int().nonnegative(),
|
|
2673
|
+
costUsd: z.number().nonnegative(),
|
|
2674
|
+
};
|
|
2675
|
+
export const SessionUsageTotalsSchema = z
|
|
2676
|
+
.object({
|
|
2677
|
+
sessionId: z.string(),
|
|
2678
|
+
turnId: z.string().nullable(),
|
|
2679
|
+
asOf: z.string(),
|
|
2680
|
+
...usageNumbers,
|
|
2681
|
+
calls: z.number().int().nonnegative(),
|
|
2682
|
+
duplicates: z.number().int().nonnegative(),
|
|
2683
|
+
unpricedCalls: z.number().int().nonnegative(),
|
|
2684
|
+
unreportedCalls: z.number().int().nonnegative(),
|
|
2685
|
+
unknownQualityCalls: z.number().int().nonnegative(),
|
|
2686
|
+
})
|
|
2687
|
+
.strict();
|
|
2688
|
+
export const ModelCallSchema = z
|
|
2689
|
+
.object({
|
|
2690
|
+
id: z.string(),
|
|
2691
|
+
sessionId: z.string(),
|
|
2692
|
+
turnId: z.string(),
|
|
2693
|
+
agentId: z.string(),
|
|
2694
|
+
provider: z.string().nullable(),
|
|
2695
|
+
model: z.string().nullable(),
|
|
2696
|
+
at: z.string(),
|
|
2697
|
+
outcome: z.enum(["completed", "failed"]),
|
|
2698
|
+
usage: z
|
|
2699
|
+
.object({
|
|
2700
|
+
...usageNumbers,
|
|
2701
|
+
duplicate: z.boolean(),
|
|
2702
|
+
tokensReported: z.boolean().nullable(),
|
|
2703
|
+
costKnown: z.boolean().nullable(),
|
|
2704
|
+
})
|
|
2705
|
+
.strict()
|
|
2706
|
+
.nullable(),
|
|
2707
|
+
})
|
|
2708
|
+
.strict();
|
|
2709
|
+
export const ModelCallsPageSchema = z
|
|
2710
|
+
.object({ calls: z.array(ModelCallSchema), nextCursor: z.string().nullable(), asOf: z.string() })
|
|
2711
|
+
.strict();
|
|
2712
|
+
export const ModelCallExportPageSchema = z
|
|
2713
|
+
.object({
|
|
2714
|
+
calls: z.array(ModelCallSchema),
|
|
2715
|
+
next: z.string().nullable(),
|
|
2716
|
+
caughtUp: z.boolean(),
|
|
2717
|
+
asOf: z.string(),
|
|
2718
|
+
})
|
|
2719
|
+
.strict();
|
|
2720
|
+
export const SandboxPageSchema = z
|
|
2721
|
+
.object({ sandboxes: z.array(SandboxViewSchema), nextCursor: z.string().nullable() })
|
|
2722
|
+
.strict();
|