@nylorun/core 0.6.0-beta → 0.8.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 +66 -0
- package/dist/compatibility.d.ts +13 -2
- package/dist/compatibility.js +19 -1
- package/dist/contracts.d.ts +247 -0
- package/dist/contracts.js +353 -4
- package/dist/define.d.ts +10 -2
- package/dist/define.js +5 -1
- package/dist/definition/assemble.js +7 -0
- package/dist/definition/builder.d.ts +122 -16
- package/dist/definition/builder.js +354 -53
- package/dist/definition/capability.d.ts +55 -0
- package/dist/definition/capability.js +104 -0
- package/dist/definition/delegate.d.ts +25 -4
- package/dist/definition/delegate.js +34 -6
- package/dist/definition/flow/compile.d.ts +25 -0
- package/dist/definition/flow/compile.js +302 -0
- package/dist/definition/flow/from.d.ts +11 -0
- package/dist/definition/flow/from.js +78 -0
- package/dist/definition/flow/index.d.ts +11 -0
- package/dist/definition/flow/index.js +11 -0
- package/dist/definition/flow/paths.d.ts +60 -0
- package/dist/definition/flow/paths.js +90 -0
- package/dist/definition/flow/spec.d.ts +66 -0
- package/dist/definition/flow/spec.js +130 -0
- package/dist/definition/flow/types.d.ts +159 -0
- package/dist/definition/flow/types.js +1 -0
- package/dist/definition/from.js +5 -1
- package/dist/definition/helpers.d.ts +1 -16
- package/dist/definition/helpers.js +1 -30
- package/dist/definition/mcp.d.ts +37 -0
- package/dist/definition/mcp.js +81 -0
- package/dist/definition/sandbox.d.ts +29 -0
- package/dist/definition/sandbox.js +93 -0
- package/dist/definition/workflow/loop.js +2 -2
- package/dist/definition/workflow/runnable.d.ts +13 -1
- package/dist/definition/workflow/runnable.js +11 -7
- package/dist/types/manifest.d.ts +4 -2
- package/dist/types/workflow.d.ts +72 -3
- package/dist/utils/deprecate.d.ts +3 -0
- package/dist/utils/deprecate.js +25 -0
- package/package.json +2 -2
package/dist/contracts.js
CHANGED
|
@@ -5,6 +5,7 @@ import { hookListIssue } from "./definition/hooks.js";
|
|
|
5
5
|
import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
|
|
6
6
|
import { canonical } from "./utils/canonical.js";
|
|
7
7
|
export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
|
|
8
|
+
import { DERIVED_PRINCIPAL_ID_PATTERN } from "./compatibility.js";
|
|
8
9
|
import { ERROR_CODES } from "./compatibility.js";
|
|
9
10
|
export const RequestIdSchema = z.string().min(1);
|
|
10
11
|
export const IdempotencyKeySchema = z.string().min(1).max(256);
|
|
@@ -91,7 +92,9 @@ const toolManifestSchema = z
|
|
|
91
92
|
description: z.string().optional(),
|
|
92
93
|
inputSchema: jsonObject,
|
|
93
94
|
outputSchema: jsonObject.optional(),
|
|
94
|
-
agent: z
|
|
95
|
+
agent: z
|
|
96
|
+
.lazy(() => z.union([workflowV2ManifestSchema, AgentManifestSchema]))
|
|
97
|
+
.optional(),
|
|
95
98
|
})
|
|
96
99
|
.strict();
|
|
97
100
|
const hookPointSchema = z
|
|
@@ -219,6 +222,20 @@ function delegationIssues(manifest, issue) {
|
|
|
219
222
|
const child = tool.agent;
|
|
220
223
|
if (!child)
|
|
221
224
|
continue;
|
|
225
|
+
if ("kind" in child) {
|
|
226
|
+
// A flow agent runs in its own linked session; its leaves may delegate in turn.
|
|
227
|
+
if (tool.name !== child.id)
|
|
228
|
+
issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
|
|
229
|
+
if (!child.description?.trim() || tool.description !== child.description)
|
|
230
|
+
issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
|
|
231
|
+
if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
|
|
232
|
+
issue(`Agent tool '${tool.name}' must take the standard { task } input`);
|
|
233
|
+
if (tool.outputSchema !== undefined)
|
|
234
|
+
issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
|
|
235
|
+
if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
|
|
236
|
+
sandboxes.add(canonical(child.sandbox));
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
222
239
|
if (tool.name !== child.id)
|
|
223
240
|
issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
|
|
224
241
|
if (!child.description?.trim() || tool.description !== child.description)
|
|
@@ -332,8 +349,7 @@ const workflowNodeSchema = z.lazy(() => z.union([
|
|
|
332
349
|
})
|
|
333
350
|
.strict(),
|
|
334
351
|
]));
|
|
335
|
-
|
|
336
|
-
export const WorkflowManifestSchema = z
|
|
352
|
+
const workflowV1ManifestSchema = z
|
|
337
353
|
.object({
|
|
338
354
|
kind: z.literal("workflow"),
|
|
339
355
|
workflowSchemaVersion: z.literal(1),
|
|
@@ -342,6 +358,138 @@ export const WorkflowManifestSchema = z
|
|
|
342
358
|
sandbox: sandboxManifestSchema.optional(),
|
|
343
359
|
})
|
|
344
360
|
.strict();
|
|
361
|
+
// v2 (Flow Agents): `id` and `input` on any node, no slots, embedded agents.
|
|
362
|
+
const workflowNodeOptionsV2 = {
|
|
363
|
+
id: z.string().min(1).optional(),
|
|
364
|
+
input: workflowFnRefSchema.optional(),
|
|
365
|
+
};
|
|
366
|
+
const workflowAgentNodeV2Schema = z
|
|
367
|
+
.object({ agent: z.string().min(1), ...workflowNodeOptionsV2 })
|
|
368
|
+
.strict();
|
|
369
|
+
const workflowNodeV2Schema = z.lazy(() => z.union([
|
|
370
|
+
workflowAgentNodeV2Schema,
|
|
371
|
+
z
|
|
372
|
+
.object({
|
|
373
|
+
tool: z
|
|
374
|
+
.object({
|
|
375
|
+
name: z.string().min(1),
|
|
376
|
+
description: z.string().optional(),
|
|
377
|
+
inputSchema: jsonObject.optional(),
|
|
378
|
+
outputSchema: jsonObject.optional(),
|
|
379
|
+
})
|
|
380
|
+
.strict(),
|
|
381
|
+
...workflowNodeOptionsV2,
|
|
382
|
+
})
|
|
383
|
+
.strict(),
|
|
384
|
+
z.object({ chain: z.array(workflowNodeV2Schema).min(1), ...workflowNodeOptionsV2 }).strict(),
|
|
385
|
+
z
|
|
386
|
+
.object({
|
|
387
|
+
switch: z
|
|
388
|
+
.object({
|
|
389
|
+
on: workflowFnRefSchema,
|
|
390
|
+
cases: z.record(z.string(), workflowNodeV2Schema),
|
|
391
|
+
default: workflowNodeV2Schema.optional(),
|
|
392
|
+
})
|
|
393
|
+
.strict(),
|
|
394
|
+
...workflowNodeOptionsV2,
|
|
395
|
+
})
|
|
396
|
+
.strict(),
|
|
397
|
+
z
|
|
398
|
+
.object({
|
|
399
|
+
parallel: z
|
|
400
|
+
.record(z.string(), workflowNodeV2Schema)
|
|
401
|
+
.refine((branches) => Object.keys(branches).length > 0, {
|
|
402
|
+
message: "parallel needs at least one branch",
|
|
403
|
+
}),
|
|
404
|
+
...workflowNodeOptionsV2,
|
|
405
|
+
})
|
|
406
|
+
.strict(),
|
|
407
|
+
z
|
|
408
|
+
.object({
|
|
409
|
+
map: z.object({ each: workflowNodeV2Schema }).strict(),
|
|
410
|
+
...workflowNodeOptionsV2,
|
|
411
|
+
})
|
|
412
|
+
.strict(),
|
|
413
|
+
z
|
|
414
|
+
.object({
|
|
415
|
+
loop: z
|
|
416
|
+
.object({
|
|
417
|
+
run: workflowNodeV2Schema,
|
|
418
|
+
verify: z.union([workflowFnRefSchema, workflowAgentNodeV2Schema]),
|
|
419
|
+
max: z.number().int().positive().optional(),
|
|
420
|
+
decide: workflowFnRefSchema.optional(),
|
|
421
|
+
})
|
|
422
|
+
.strict()
|
|
423
|
+
.refine((loop) => loop.max !== undefined || loop.decide !== undefined, {
|
|
424
|
+
message: "loop needs max or decide",
|
|
425
|
+
}),
|
|
426
|
+
...workflowNodeOptionsV2,
|
|
427
|
+
})
|
|
428
|
+
.strict(),
|
|
429
|
+
]));
|
|
430
|
+
const workflowV2ManifestSchema = z.lazy(() => z
|
|
431
|
+
.object({
|
|
432
|
+
kind: z.literal("workflow"),
|
|
433
|
+
workflowSchemaVersion: z.literal(2),
|
|
434
|
+
id: z.string().min(1),
|
|
435
|
+
name: z.string().min(1).optional(),
|
|
436
|
+
description: z.string().optional(),
|
|
437
|
+
metadata: jsonObject.optional(),
|
|
438
|
+
inputSchema: jsonObject.optional(),
|
|
439
|
+
outputSchema: jsonObject.optional(),
|
|
440
|
+
sandbox: sandboxManifestSchema.optional(),
|
|
441
|
+
root: workflowNodeV2Schema,
|
|
442
|
+
agents: z.record(z.string().min(1), z.union([workflowV2ManifestSchema, AgentManifestSchema])),
|
|
443
|
+
})
|
|
444
|
+
.strict()
|
|
445
|
+
.superRefine((manifest, ctx) => {
|
|
446
|
+
for (const agentId of referencedAgents(manifest.root)) {
|
|
447
|
+
if (!(agentId in manifest.agents))
|
|
448
|
+
ctx.addIssue({
|
|
449
|
+
code: "custom",
|
|
450
|
+
path: ["agents"],
|
|
451
|
+
message: `Agent '${agentId}' is used in the flow but not embedded in agents`,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
for (const [key, agent] of Object.entries(manifest.agents)) {
|
|
455
|
+
if (agent.id !== key)
|
|
456
|
+
ctx.addIssue({
|
|
457
|
+
code: "custom",
|
|
458
|
+
path: ["agents", key],
|
|
459
|
+
message: `Embedded agent '${agent.id}' must be keyed by its id`,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}));
|
|
463
|
+
function referencedAgents(node) {
|
|
464
|
+
const out = [];
|
|
465
|
+
const visit = (child) => {
|
|
466
|
+
if ("agent" in child)
|
|
467
|
+
out.push(child.agent);
|
|
468
|
+
else if ("chain" in child)
|
|
469
|
+
child.chain.forEach(visit);
|
|
470
|
+
else if ("switch" in child) {
|
|
471
|
+
Object.values(child.switch.cases).forEach(visit);
|
|
472
|
+
if (child.switch.default)
|
|
473
|
+
visit(child.switch.default);
|
|
474
|
+
}
|
|
475
|
+
else if ("parallel" in child)
|
|
476
|
+
Object.values(child.parallel).forEach(visit);
|
|
477
|
+
else if ("map" in child)
|
|
478
|
+
visit(child.map.each);
|
|
479
|
+
else if ("loop" in child) {
|
|
480
|
+
visit(child.loop.run);
|
|
481
|
+
if ("agent" in child.loop.verify)
|
|
482
|
+
visit(child.loop.verify);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
visit(node);
|
|
486
|
+
return out;
|
|
487
|
+
}
|
|
488
|
+
/** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
|
|
489
|
+
export const WorkflowManifestSchema = z.union([
|
|
490
|
+
workflowV1ManifestSchema,
|
|
491
|
+
workflowV2ManifestSchema,
|
|
492
|
+
]);
|
|
345
493
|
/** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
|
|
346
494
|
export const DefinitionDocumentSchema = z.union([
|
|
347
495
|
AgentManifestSchema,
|
|
@@ -667,6 +815,126 @@ export const ActionSchema = z.union([
|
|
|
667
815
|
fnActionSchema,
|
|
668
816
|
verifyActionSchema,
|
|
669
817
|
]);
|
|
818
|
+
/**
|
|
819
|
+
* Transcript events (Host feature `transcript-events`): the log entries a chat UI
|
|
820
|
+
* renders. `LiveEvent.payload` stays `unknown` on the wire; `parseTranscriptEvent`
|
|
821
|
+
* types the ones a client reads. Objects pass unknown fields through, so a newer
|
|
822
|
+
* Host can add fields without breaking older clients.
|
|
823
|
+
*/
|
|
824
|
+
const eventAgent = { agent: AgentRefSchema.passthrough().optional() };
|
|
825
|
+
const toolIds = {
|
|
826
|
+
/** The model's tool call id. */
|
|
827
|
+
callId: z.string().min(1),
|
|
828
|
+
/** The harness invocation of the call; interactions refer to it. */
|
|
829
|
+
invocationId: z.string().min(1),
|
|
830
|
+
};
|
|
831
|
+
/** `message.assistant`: one completed model step. `invocationId` is the model call's. */
|
|
832
|
+
export const AssistantMessagePayloadSchema = z
|
|
833
|
+
.object({
|
|
834
|
+
invocationId: z.string().min(1),
|
|
835
|
+
text: z.string(),
|
|
836
|
+
toolCalls: z.array(z
|
|
837
|
+
.object({
|
|
838
|
+
callId: z.string().min(1),
|
|
839
|
+
name: z.string().min(1),
|
|
840
|
+
input: z.unknown(),
|
|
841
|
+
})
|
|
842
|
+
.passthrough()),
|
|
843
|
+
...eventAgent,
|
|
844
|
+
})
|
|
845
|
+
.passthrough();
|
|
846
|
+
/** `tool.completed`: an MCP or sandbox tool the Runtime ran. `error` for a tool error. */
|
|
847
|
+
export const ToolCompletedPayloadSchema = z
|
|
848
|
+
.object({
|
|
849
|
+
...toolIds,
|
|
850
|
+
capabilityId: z.string().min(1),
|
|
851
|
+
toolName: z.string().min(1),
|
|
852
|
+
output: z.unknown().optional(),
|
|
853
|
+
error: z.object({ code: z.string(), message: z.string() }).passthrough().optional(),
|
|
854
|
+
...eventAgent,
|
|
855
|
+
})
|
|
856
|
+
.passthrough();
|
|
857
|
+
/** `action.pending` and `action.completed`; tool actions carry `callId` and `invocationId`. */
|
|
858
|
+
const actionEventBase = {
|
|
859
|
+
actionId: z.string().min(1),
|
|
860
|
+
kind: z.string(),
|
|
861
|
+
toolName: z.string().optional(),
|
|
862
|
+
callId: z.string().optional(),
|
|
863
|
+
invocationId: z.string().optional(),
|
|
864
|
+
...eventAgent,
|
|
865
|
+
};
|
|
866
|
+
export const ActionPendingPayloadSchema = z
|
|
867
|
+
.object({ ...actionEventBase, input: z.unknown() })
|
|
868
|
+
.passthrough();
|
|
869
|
+
export const ActionCompletedPayloadSchema = z
|
|
870
|
+
.object({ ...actionEventBase, result: z.unknown() })
|
|
871
|
+
.passthrough();
|
|
872
|
+
export const ActionUncertainPayloadSchema = z
|
|
873
|
+
.object({ actionId: z.string().min(1), ...eventAgent })
|
|
874
|
+
.passthrough();
|
|
875
|
+
export const EffectUncertainPayloadSchema = z
|
|
876
|
+
.object({ effectId: z.string().min(1), message: z.string().optional() })
|
|
877
|
+
.passthrough();
|
|
878
|
+
export const TurnCompletedPayloadSchema = z
|
|
879
|
+
.object({ output: z.unknown() })
|
|
880
|
+
.passthrough();
|
|
881
|
+
export const TurnPausedPayloadSchema = z
|
|
882
|
+
.object({
|
|
883
|
+
interactions: z.array(z
|
|
884
|
+
.object({
|
|
885
|
+
invocationId: z.string().min(1),
|
|
886
|
+
interaction: z
|
|
887
|
+
.object({ id: z.string().min(1), kind: z.string() })
|
|
888
|
+
.passthrough(),
|
|
889
|
+
status: z.string().optional(),
|
|
890
|
+
})
|
|
891
|
+
.passthrough()),
|
|
892
|
+
})
|
|
893
|
+
.passthrough();
|
|
894
|
+
/** Either `{ error: { code, message } }` or, when a segment threw, `{ message }`. */
|
|
895
|
+
export const TurnFailedPayloadSchema = z
|
|
896
|
+
.object({
|
|
897
|
+
error: z
|
|
898
|
+
.object({ code: z.string().optional(), message: z.string().optional() })
|
|
899
|
+
.passthrough()
|
|
900
|
+
.optional(),
|
|
901
|
+
message: z.string().optional(),
|
|
902
|
+
})
|
|
903
|
+
.passthrough();
|
|
904
|
+
export const TurnCancelledPayloadSchema = z
|
|
905
|
+
.object({ reason: z.string().optional() })
|
|
906
|
+
.passthrough();
|
|
907
|
+
/** Lifecycle of an agent used as a tool. `agent.delegationId` is the parent call's invocation. */
|
|
908
|
+
export const DelegationPayloadSchema = z
|
|
909
|
+
.object({
|
|
910
|
+
agent: AgentRefSchema.passthrough(),
|
|
911
|
+
callId: z.string().optional(),
|
|
912
|
+
})
|
|
913
|
+
.passthrough();
|
|
914
|
+
const TRANSCRIPT_PAYLOADS = {
|
|
915
|
+
"message.assistant": AssistantMessagePayloadSchema,
|
|
916
|
+
"tool.completed": ToolCompletedPayloadSchema,
|
|
917
|
+
"action.pending": ActionPendingPayloadSchema,
|
|
918
|
+
"action.completed": ActionCompletedPayloadSchema,
|
|
919
|
+
"action.uncertain": ActionUncertainPayloadSchema,
|
|
920
|
+
"effect.uncertain": EffectUncertainPayloadSchema,
|
|
921
|
+
"turn.completed": TurnCompletedPayloadSchema,
|
|
922
|
+
"turn.paused": TurnPausedPayloadSchema,
|
|
923
|
+
"turn.failed": TurnFailedPayloadSchema,
|
|
924
|
+
"turn.cancelled": TurnCancelledPayloadSchema,
|
|
925
|
+
"delegation.started": DelegationPayloadSchema,
|
|
926
|
+
"delegation.completed": DelegationPayloadSchema,
|
|
927
|
+
};
|
|
928
|
+
export const TRANSCRIPT_EVENT_TYPES = Object.keys(TRANSCRIPT_PAYLOADS);
|
|
929
|
+
/** Types a transcript event's payload; `undefined` for other types or a malformed payload. */
|
|
930
|
+
export function parseTranscriptEvent(event) {
|
|
931
|
+
if (!Object.hasOwn(TRANSCRIPT_PAYLOADS, event.type))
|
|
932
|
+
return undefined;
|
|
933
|
+
const parsed = TRANSCRIPT_PAYLOADS[event.type].safeParse(event.payload);
|
|
934
|
+
return parsed.success
|
|
935
|
+
? { ...event, payload: parsed.data }
|
|
936
|
+
: undefined;
|
|
937
|
+
}
|
|
670
938
|
export const ActionClaimRequestSchema = z
|
|
671
939
|
.object({
|
|
672
940
|
requestId: RequestIdSchema,
|
|
@@ -775,8 +1043,46 @@ export const CreateTenantRequestSchema = z
|
|
|
775
1043
|
.string()
|
|
776
1044
|
.regex(/^[0-9a-f]{64}$/)
|
|
777
1045
|
.optional(),
|
|
1046
|
+
/**
|
|
1047
|
+
* SHA-256 of each derived principal's key (feature `derived-principals`): application
|
|
1048
|
+
* principals whose keys the admin key derives, so their clients store no key.
|
|
1049
|
+
*/
|
|
1050
|
+
derivedPrincipals: z
|
|
1051
|
+
.array(z
|
|
1052
|
+
.object({
|
|
1053
|
+
id: z
|
|
1054
|
+
.string()
|
|
1055
|
+
.regex(DERIVED_PRINCIPAL_ID_PATTERN)
|
|
1056
|
+
.refine((id) => id !== "studio", "principal id `studio` is reserved"),
|
|
1057
|
+
credentialHash: z.string().regex(/^[0-9a-f]{64}$/),
|
|
1058
|
+
})
|
|
1059
|
+
.strict())
|
|
1060
|
+
.max(16)
|
|
1061
|
+
.optional(),
|
|
778
1062
|
})
|
|
779
|
-
.strict()
|
|
1063
|
+
.strict()
|
|
1064
|
+
.superRefine((body, ctx) => {
|
|
1065
|
+
const ids = new Set([body.principalId]);
|
|
1066
|
+
const hashes = new Set([body.credentialHash]);
|
|
1067
|
+
if (body.studioCredentialHash)
|
|
1068
|
+
hashes.add(body.studioCredentialHash);
|
|
1069
|
+
for (const [index, principal] of (body.derivedPrincipals ?? []).entries()) {
|
|
1070
|
+
if (ids.has(principal.id))
|
|
1071
|
+
ctx.addIssue({
|
|
1072
|
+
code: "custom",
|
|
1073
|
+
path: ["derivedPrincipals", index, "id"],
|
|
1074
|
+
message: `Principal id ${principal.id} is used twice`,
|
|
1075
|
+
});
|
|
1076
|
+
if (hashes.has(principal.credentialHash))
|
|
1077
|
+
ctx.addIssue({
|
|
1078
|
+
code: "custom",
|
|
1079
|
+
path: ["derivedPrincipals", index, "credentialHash"],
|
|
1080
|
+
message: "Every principal needs its own credential",
|
|
1081
|
+
});
|
|
1082
|
+
ids.add(principal.id);
|
|
1083
|
+
hashes.add(principal.credentialHash);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
780
1086
|
export const AdminTenantSchema = z
|
|
781
1087
|
.object({
|
|
782
1088
|
id: z.string().min(1),
|
|
@@ -991,3 +1297,46 @@ export const ResetTenantRequestSchema = z
|
|
|
991
1297
|
activeWork: z.enum(["drain", "cancel"]),
|
|
992
1298
|
})
|
|
993
1299
|
.strict();
|
|
1300
|
+
/**
|
|
1301
|
+
* Acting for a subject (Host feature `subject-headers`): what an application principal may
|
|
1302
|
+
* narrow a request to. `sessions:own` and `vaults:own` reach only the subject's own sessions
|
|
1303
|
+
* and vaults; the others reach Tenant-wide resources.
|
|
1304
|
+
*/
|
|
1305
|
+
export const SUBJECT_SCOPES = [
|
|
1306
|
+
"agents:read",
|
|
1307
|
+
"agents:write",
|
|
1308
|
+
"sessions:own",
|
|
1309
|
+
"vaults:own",
|
|
1310
|
+
"tenant:settings",
|
|
1311
|
+
];
|
|
1312
|
+
/** 1–200 visible ASCII characters; spaces only inside. */
|
|
1313
|
+
const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
|
|
1314
|
+
/** Owner ids the Runtime uses itself: the host model's vault is owned by `host`. */
|
|
1315
|
+
const RESERVED_SUBJECTS = new Set(["host"]);
|
|
1316
|
+
/**
|
|
1317
|
+
* Validates `Nylorun-Subject` and `Nylorun-Scopes`. Returns the subject and its scopes, or a
|
|
1318
|
+
* message naming what is wrong. Scopes are required: the Runtime never grants a default.
|
|
1319
|
+
*/
|
|
1320
|
+
export function parseSubjectHeaders(subject, scopes) {
|
|
1321
|
+
if (!SUBJECT_PATTERN.test(subject))
|
|
1322
|
+
return {
|
|
1323
|
+
ok: false,
|
|
1324
|
+
message: "Nylorun-Subject must be 1-200 visible ASCII characters",
|
|
1325
|
+
};
|
|
1326
|
+
if (RESERVED_SUBJECTS.has(subject))
|
|
1327
|
+
return { ok: false, message: `Subject ${subject} is reserved` };
|
|
1328
|
+
const names = (scopes ?? "").split(" ").filter(Boolean);
|
|
1329
|
+
if (names.length === 0)
|
|
1330
|
+
return {
|
|
1331
|
+
ok: false,
|
|
1332
|
+
message: "Nylorun-Scopes is required with Nylorun-Subject",
|
|
1333
|
+
};
|
|
1334
|
+
const unknown = names.filter((name) => !SUBJECT_SCOPES.includes(name));
|
|
1335
|
+
if (unknown.length > 0)
|
|
1336
|
+
return { ok: false, message: `Unknown scope ${unknown.join(", ")}` };
|
|
1337
|
+
return {
|
|
1338
|
+
ok: true,
|
|
1339
|
+
subject,
|
|
1340
|
+
scopes: new Set(names),
|
|
1341
|
+
};
|
|
1342
|
+
}
|
package/dist/define.d.ts
CHANGED
|
@@ -3,9 +3,17 @@ export type { AgentOptions } from "./definition/builder.js";
|
|
|
3
3
|
export { HarnessError, isHarnessError } from "./errors.js";
|
|
4
4
|
export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
|
|
5
5
|
export type { AgentTool, BuiltAgent } from "./types/agent.js";
|
|
6
|
-
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
|
|
6
|
+
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
|
|
7
7
|
export type { Delegate } from "./definition/delegate.js";
|
|
8
8
|
export { capability, middleware, model, tool } from "./definition/helpers.js";
|
|
9
|
+
export { sandbox, SandboxError } from "./definition/sandbox.js";
|
|
10
|
+
export type { SandboxCapability, SandboxCapabilityOptions, SandboxOptions, } from "./definition/sandbox.js";
|
|
11
|
+
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
12
|
+
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
13
|
+
export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
|
|
14
|
+
export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
|
|
15
|
+
export type { FlowAgentBuilder, Flow, Named, StageArgs, NestedStageArgs, FlowOut, LoopChoice, LoopDecideArgs as FlowLoopDecideArgs, LoopVerifyFn as FlowLoopVerifyFn, FlowFunctionRole, FlowNodeVisit, FlowImplementations, } from "./definition/flow/index.js";
|
|
16
|
+
export type { McpCapability, McpOptions, McpServerSpec } from "./definition/mcp.js";
|
|
9
17
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
10
18
|
export { defineSchema } from "./definition/schema.js";
|
|
11
19
|
export { hashManifest } from "./utils/hash.js";
|
|
@@ -28,7 +36,7 @@ export type { AgentBinding } from "./definition/binding.js";
|
|
|
28
36
|
export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
|
|
29
37
|
export type { BuiltWorkflow, OutputOf, InputOf, LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, ChainOptions, ChainStep, ChainResults, ChainSlot, SwitchOptions, SwitchCases, ParallelOptions, ParallelBranches, MapOptions, MapOver, Slot, SlotInputArgs, WorkflowRunnable, } from "./definition/workflow/index.js";
|
|
30
38
|
export { isVariantOf } from "./definition/variant.js";
|
|
31
|
-
export type { Verdict, WorkflowBinding, WorkflowManifest } from "./types/workflow.js";
|
|
39
|
+
export type { Verdict, WorkflowBinding, WorkflowManifest, WorkflowManifestV1, WorkflowManifestV2, WorkflowNodeV2, } from "./types/workflow.js";
|
|
32
40
|
export type { BoundMiddleware, BoundToolDefinition, } from "./definition/bound.js";
|
|
33
41
|
export { bindTool } from "./definition/bind-tool.js";
|
|
34
42
|
export { bindOutputContract } from "./definition/output-contract.js";
|
package/dist/define.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
|
|
2
2
|
export { HarnessError, isHarnessError } from "./errors.js";
|
|
3
|
-
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
|
|
3
|
+
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
|
|
4
4
|
export { capability, middleware, model, tool } from "./definition/helpers.js";
|
|
5
|
+
export { sandbox, SandboxError } from "./definition/sandbox.js";
|
|
6
|
+
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
7
|
+
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
8
|
+
export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
|
|
5
9
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
6
10
|
export { defineSchema } from "./definition/schema.js";
|
|
7
11
|
export { hashManifest } from "./utils/hash.js";
|
|
@@ -111,6 +111,13 @@ function delegationDiagnostics(items) {
|
|
|
111
111
|
found.push(diagnostic("delegation.invalid-name", `Agent '${child.id}' is used as a tool, so its id must be 1-64 letters, digits, '_' or '-'`, extra));
|
|
112
112
|
if (!child.description?.trim())
|
|
113
113
|
found.push(diagnostic("delegation.description-required", `Agent '${child.id}' is used as a tool by capability '${item.id}' and needs a description: the parent's model reads it to decide when to delegate`, extra));
|
|
114
|
+
if (child.kind === "workflow") {
|
|
115
|
+
// A flow agent runs in its own linked session; its agents may delegate in turn.
|
|
116
|
+
const spec = child.sandbox;
|
|
117
|
+
if (spec && Object.keys(spec).length > 0)
|
|
118
|
+
sandboxes.add(canonical(spec));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
114
121
|
const nested = delegatesOf(child)[0];
|
|
115
122
|
if (nested)
|
|
116
123
|
found.push(diagnostic("delegation.nested", `'${child.id}' delegates to '${nested.manifest.id}'; nested delegation is not supported yet`, extra));
|
|
@@ -4,30 +4,49 @@ import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
|
|
|
4
4
|
import { HarnessError } from "../errors.js";
|
|
5
5
|
import type { ToolDefinition, ToolSchemaSource, SchemaOutput } from "../types/tool.js";
|
|
6
6
|
import type { AgentTool, BuiltAgent } from "../types/agent.js";
|
|
7
|
-
import type { AgentManifest } from "../types/manifest.js";
|
|
7
|
+
import type { AgentManifest, McpServerManifest, SandboxManifest } from "../types/manifest.js";
|
|
8
|
+
import type { WorkflowBinding, WorkflowManifest } from "../types/workflow.js";
|
|
8
9
|
import type { AfterHook, BeforeHook, HookScope } from "../types/dynamics.js";
|
|
9
10
|
import type { Implementations } from "./implementations.js";
|
|
10
11
|
import { type CapabilityDynamics } from "./assemble.js";
|
|
12
|
+
import { type McpServerSpec } from "./mcp.js";
|
|
13
|
+
import { type FlowImplementations } from "./flow/from.js";
|
|
14
|
+
import { type BuiltWorkflow } from "./workflow/types.js";
|
|
15
|
+
import { type FlowStage } from "./flow/spec.js";
|
|
16
|
+
import type { AddResult, BranchesOut, CaseKey, CasesOut, FlowAgentBuilder, FlowOut, IdOf, LoopChoice, LoopDecideArgs, LoopVerifyFn, Named, StageArgs } from "./flow/types.js";
|
|
11
17
|
export interface AgentOptions<Schema extends ToolSchemaSource | undefined = undefined> {
|
|
18
|
+
/** @deprecated Use `.output(schema)`. */
|
|
12
19
|
readonly outputSchema?: Schema;
|
|
13
20
|
readonly id: string;
|
|
14
21
|
readonly name?: string;
|
|
15
22
|
readonly description?: string;
|
|
16
23
|
readonly metadata?: JsonObject;
|
|
24
|
+
/** @deprecated Use `.instructions(...)`. */
|
|
17
25
|
readonly instructions?: string | readonly string[];
|
|
18
|
-
/**
|
|
26
|
+
/** @deprecated Use `.tools(...)` and `.subagents(...)`. */
|
|
19
27
|
readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
|
|
20
28
|
}
|
|
29
|
+
type Body = "none" | "react" | "flow";
|
|
21
30
|
interface BuilderSnapshot {
|
|
22
31
|
readonly id: string;
|
|
23
32
|
readonly name?: string;
|
|
24
33
|
readonly description?: string;
|
|
25
34
|
readonly metadata?: JsonObject;
|
|
26
35
|
readonly outputSchema?: ToolSchemaSource;
|
|
36
|
+
readonly inputSchema?: ToolSchemaSource;
|
|
27
37
|
readonly entries: readonly BoundMiddleware[];
|
|
28
38
|
readonly dynamics: ReadonlyMap<string, CapabilityDynamics>;
|
|
29
39
|
/** Builder-level problems, reported with the assembly diagnostics. */
|
|
30
40
|
readonly diagnostics?: readonly BuildDiagnostic[];
|
|
41
|
+
readonly body: Body;
|
|
42
|
+
/** Raw items of the `"agent"` capability, so later calls can add to it. */
|
|
43
|
+
readonly agentPart?: {
|
|
44
|
+
readonly instructions?: readonly string[];
|
|
45
|
+
readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
|
|
46
|
+
};
|
|
47
|
+
readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
|
|
48
|
+
readonly sandbox?: SandboxManifest;
|
|
49
|
+
readonly stages: readonly FlowStage[];
|
|
31
50
|
}
|
|
32
51
|
export declare class AgentBuildError extends HarnessError {
|
|
33
52
|
readonly diagnostics: readonly BuildDiagnostic[];
|
|
@@ -36,39 +55,126 @@ export declare class AgentBuildError extends HarnessError {
|
|
|
36
55
|
export declare class AgentLifecycleError extends HarnessError {
|
|
37
56
|
constructor(message: string);
|
|
38
57
|
}
|
|
39
|
-
export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined>(options: AgentOptions<Schema>
|
|
58
|
+
export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, const Id extends string = string>(options: AgentOptions<Schema> & {
|
|
59
|
+
readonly id: Id;
|
|
60
|
+
}): AgentBuilder<Info, Schema, Id>;
|
|
40
61
|
export declare namespace Agent {
|
|
62
|
+
/** Rebuild a flow agent from its workflow manifest v2 and the code its stage keys name. */
|
|
63
|
+
function from(json: import("../types/workflow.js").WorkflowManifestV2, implementations?: FlowImplementations): BuiltWorkflow;
|
|
64
|
+
/** Rebuild an agent from its manifest and the code its capabilities name. */
|
|
41
65
|
function from<Info = unknown>(json: AgentManifest | import("../types/shared.js").JsonObject, implementations: Implementations<Info>): BuiltAgent<Info>;
|
|
42
66
|
}
|
|
43
67
|
declare const SNAPSHOT: unique symbol;
|
|
44
|
-
|
|
68
|
+
type SchemaOut<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : never;
|
|
69
|
+
type ReactOutput<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : string;
|
|
70
|
+
type StartFlow<Info, Schema, Id extends string, Cur, Results> = FlowAgentBuilder<Info, any, Cur, Results, SchemaOut<Schema>, Id>;
|
|
71
|
+
export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, Id extends string = string> {
|
|
45
72
|
#private;
|
|
73
|
+
/** Phantom carriers for flow typing (never set at runtime). */
|
|
74
|
+
readonly __output?: ReactOutput<Schema>;
|
|
75
|
+
readonly __id?: Id;
|
|
46
76
|
getBinding(): import("./binding.js").AgentBinding;
|
|
47
77
|
constructor(options: AgentOptions<Schema>);
|
|
48
78
|
/** @internal */
|
|
49
79
|
constructor(snapshot: BuilderSnapshot, brand: typeof SNAPSHOT);
|
|
50
|
-
static create<Info, Schema extends ToolSchemaSource | undefined>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema>;
|
|
51
|
-
|
|
80
|
+
static create<Info, Schema extends ToolSchemaSource | undefined, Id extends string = string>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema, Id>;
|
|
81
|
+
/** @internal True for an agent whose body is a flow. */
|
|
82
|
+
static isFlowAgent(value: unknown): boolean;
|
|
83
|
+
/** A new builder of the same class (subclasses survive chaining). */
|
|
84
|
+
protected spawn(snapshot: BuilderSnapshot): this;
|
|
52
85
|
/** Compose-time identity — available before `.build()`. */
|
|
53
|
-
get id():
|
|
86
|
+
get id(): Id;
|
|
54
87
|
get name(): string | undefined;
|
|
55
88
|
get manifest(): AgentManifest;
|
|
89
|
+
/** A flow agent's input and output schemas (local; not on the v1 wire). */
|
|
90
|
+
get inputSchema(): ToolSchemaSource | undefined;
|
|
91
|
+
get outputSchema(): ToolSchemaSource | undefined;
|
|
56
92
|
toJSON(): AgentManifest;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
/** Add instructions. Repeated calls add more. */
|
|
94
|
+
instructions(...text: readonly string[]): this;
|
|
95
|
+
/** Add tools. Repeated calls add more. Agents belong in `.subagents()`. */
|
|
96
|
+
tools(...tools: readonly (ToolDefinition<any, any, any> | AgentTool)[]): this;
|
|
97
|
+
/** Add agents the model may delegate a self-contained task to. */
|
|
98
|
+
subagents(...agents: readonly AgentTool[]): this;
|
|
99
|
+
/** Declare MCP servers. A server's `name` defaults to its key; calls merge. */
|
|
100
|
+
mcp(servers: Readonly<Record<string, McpServerSpec>>): this;
|
|
101
|
+
/** Attach a reusable bundle made with `capability({ id })`. */
|
|
102
|
+
capability(bundle: CapabilityInput<Info> | {
|
|
103
|
+
toDeclaration(): CapabilityInput<Info>;
|
|
104
|
+
}): this;
|
|
60
105
|
/**
|
|
106
|
+
* Give the agent a Runtime-owned sandbox. On a flow agent, declares the one sandbox
|
|
107
|
+
* every agent in the flow shares.
|
|
108
|
+
*/
|
|
109
|
+
sandbox(spec?: SandboxManifest): this;
|
|
110
|
+
/** Run `fn` before each turn. */
|
|
111
|
+
beforeTurn(fn: BeforeHook<"turn", Info>): this;
|
|
112
|
+
/** Run `fn` before every model call. */
|
|
113
|
+
beforeModel(fn: BeforeHook<"step", Info>): this;
|
|
114
|
+
/** Run `fn` after every model call. */
|
|
115
|
+
afterModel(fn: AfterHook<"step", Info>): this;
|
|
116
|
+
/** Run `fn` after the turn's final answer. */
|
|
117
|
+
afterTurn(fn: AfterHook<"turn", Info>): this;
|
|
118
|
+
/** The structured output. Set once. */
|
|
119
|
+
output<S extends ToolSchemaSource>(schema: S): AgentBuilder<Info, S, Id>;
|
|
120
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
121
|
+
use(middleware: StepMiddleware<Info>): this;
|
|
122
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
123
|
+
use(id: string, middleware: StepMiddleware<Info>): this;
|
|
124
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
125
|
+
use(declaration: CapabilityInput<Info>): this;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `.beforeTurn()` or `.beforeModel()`.
|
|
61
128
|
* Run `fn` before each turn (`"turn"`) or before every model call (`"step"`).
|
|
62
|
-
* The returned Patch applies to the whole turn or to that one model call.
|
|
63
129
|
*/
|
|
64
|
-
before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>):
|
|
130
|
+
before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>): this;
|
|
65
131
|
/**
|
|
132
|
+
* @deprecated Use `.afterModel()` or `.afterTurn()`.
|
|
66
133
|
* Run `fn` after every model call (`"step"`) or after the turn's final answer (`"turn"`).
|
|
67
134
|
*/
|
|
68
|
-
after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>):
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
135
|
+
after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>): this;
|
|
136
|
+
/** The flow agent's input. Set once. */
|
|
137
|
+
input<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, SchemaOutput<S>, SchemaOutput<S>, {}, SchemaOut<Schema>, Id>;
|
|
138
|
+
step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
|
|
139
|
+
readonly id?: StepId;
|
|
140
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
141
|
+
}): StartFlow<Info, Schema, Id, FlowOut<C>, AddResult<{}, StepId, FlowOut<C>>>;
|
|
142
|
+
switch<const Cases extends Readonly<Record<string, unknown>>, T, const StageId extends string = string>(cases: Cases, options: {
|
|
143
|
+
readonly input: (args: StageArgs<any, {}, any>) => T;
|
|
144
|
+
readonly on: (args: StageArgs<T, {}, any>) => CaseKey<Cases>;
|
|
145
|
+
readonly id?: StageId;
|
|
146
|
+
}): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
|
|
147
|
+
switch<const Cases extends Readonly<Record<string, unknown>>, const StageId extends string = string>(cases: Cases, options: {
|
|
148
|
+
readonly on: (args: StageArgs<any, {}, any>) => CaseKey<Cases>;
|
|
149
|
+
readonly id?: StageId;
|
|
150
|
+
}): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
|
|
151
|
+
parallel<const Branches extends Readonly<Record<string, unknown>>, const StageId extends string = string>(branches: Branches, options?: {
|
|
152
|
+
readonly id?: StageId;
|
|
153
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
154
|
+
}): StartFlow<Info, Schema, Id, BranchesOut<Branches>, AddResult<{}, StageId, BranchesOut<Branches>>>;
|
|
155
|
+
map<E, const StageId extends string = string>(each: E, options?: {
|
|
156
|
+
readonly id?: StageId;
|
|
157
|
+
readonly input?: (args: StageArgs<any, {}, any>) => readonly unknown[];
|
|
158
|
+
}): StartFlow<Info, Schema, Id, FlowOut<E>[], AddResult<{}, StageId, FlowOut<E>[]>>;
|
|
159
|
+
loop<B, const StageId extends string = string>(body: B, options: {
|
|
160
|
+
readonly verify: LoopVerifyFn<any, FlowOut<B>> | object;
|
|
161
|
+
readonly max?: number;
|
|
162
|
+
readonly decide?: (args: LoopDecideArgs<any, FlowOut<B>>) => LoopChoice<FlowOut<B>>;
|
|
163
|
+
readonly id?: StageId;
|
|
164
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
165
|
+
}): StartFlow<Info, Schema, Id, FlowOut<B>, AddResult<{}, StageId, FlowOut<B>>>;
|
|
166
|
+
/** Give this agent a new step id where there is no options object. */
|
|
167
|
+
withId(id: string): Named<this>;
|
|
168
|
+
/** Optional no-op: returns the assembled agent facade (a workflow for flow agents). */
|
|
169
|
+
build(): BuiltAgent<Info, ReactOutput<Schema>>;
|
|
72
170
|
private ensure;
|
|
171
|
+
/** Record which body a method belongs to; mixing bodies is a build error. */
|
|
172
|
+
private bodyFor;
|
|
173
|
+
private addStage;
|
|
174
|
+
private withAgentItems;
|
|
175
|
+
private addDeclaration;
|
|
176
|
+
private appendCompiled;
|
|
177
|
+
private addAgentHook;
|
|
73
178
|
}
|
|
74
179
|
export type { Implementations };
|
|
180
|
+
export type { WorkflowBinding, WorkflowManifest };
|