@nylorun/core 0.8.0-beta → 0.10.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 +258 -0
- package/dist/compatibility.d.ts +58 -6
- package/dist/compatibility.js +82 -9
- package/dist/contracts.d.ts +2335 -377
- package/dist/contracts.js +1225 -173
- package/dist/define.d.ts +5 -5
- package/dist/define.js +3 -2
- package/dist/definition/assemble.js +15 -20
- package/dist/definition/bind-tool.js +1 -0
- package/dist/definition/bound.d.ts +2 -0
- package/dist/definition/builder.d.ts +4 -10
- package/dist/definition/builder.js +2 -26
- package/dist/definition/declaration.js +6 -2
- package/dist/definition/flow/compile.d.ts +0 -2
- package/dist/definition/flow/compile.js +1 -29
- package/dist/definition/flow/types.d.ts +1 -3
- package/dist/definition/model-failure.d.ts +4 -0
- package/dist/definition/model-failure.js +23 -0
- package/dist/definition/sandbox-capability.d.ts +12 -0
- package/dist/definition/sandbox-capability.js +33 -0
- package/dist/definition/schema.js +3 -0
- package/dist/definition/workflow/build.d.ts +3 -13
- package/dist/definition/workflow/build.js +3 -25
- package/dist/definition/workflow/chain.js +0 -1
- package/dist/definition/workflow/loop.js +0 -2
- package/dist/definition/workflow/map.js +0 -1
- package/dist/definition/workflow/parallel.js +0 -1
- package/dist/definition/workflow/runnable.d.ts +0 -4
- package/dist/definition/workflow/runnable.js +0 -34
- package/dist/definition/workflow/switch.js +0 -2
- package/dist/errors.d.ts +3 -1
- package/dist/types/middleware.d.ts +1 -3
- package/dist/types/model.d.ts +34 -1
- package/dist/types/observe.d.ts +7 -1
- package/dist/types/tool.d.ts +6 -0
- package/dist/types/transcript.d.ts +14 -1
- package/dist/utils/sandbox.d.ts +0 -4
- package/dist/utils/sandbox.js +0 -16
- package/package.json +1 -1
- package/dist/definition/sandbox.d.ts +0 -29
- package/dist/definition/sandbox.js +0 -93
package/dist/define.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ export type { AgentTool, BuiltAgent } from "./types/agent.js";
|
|
|
6
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 {
|
|
10
|
-
export type { SandboxCapability, SandboxCapabilityOptions, SandboxOptions, } from "./definition/sandbox.js";
|
|
9
|
+
export { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
|
|
11
10
|
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
12
11
|
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
13
12
|
export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
|
|
@@ -17,15 +16,16 @@ export type { McpCapability, McpOptions, McpServerSpec } from "./definition/mcp.
|
|
|
17
16
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
18
17
|
export { defineSchema } from "./definition/schema.js";
|
|
19
18
|
export { hashManifest } from "./utils/hash.js";
|
|
19
|
+
export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
|
|
20
20
|
export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
|
|
21
|
-
export {
|
|
21
|
+
export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
|
|
22
22
|
export type { SandboxToolName } from "./utils/sandbox.js";
|
|
23
23
|
export type { Implementations } from "./definition/implementations.js";
|
|
24
24
|
export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
|
|
25
25
|
export type { CapabilityDeclaration, CapabilityInput, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
|
|
26
26
|
export type { Patch, Decision, TurnDecision, HookAt, HookScope, HookManifest, HookState, HookToolCall, BeforeHook, AfterHook, BeforeHooks, AfterHooks, BeforeTurnArgs, BeforeStepArgs, AfterStepArgs, AfterTurnArgs, } from "./types/dynamics.js";
|
|
27
27
|
export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
|
|
28
|
-
export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
|
|
28
|
+
export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelFailureCode, ModelFailureOutcome, ModelProducer, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
|
|
29
29
|
export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
|
|
30
30
|
export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
|
|
31
31
|
export type { InputEvent, MessageInput, InteractionReply, TranscriptEntry, UserContentPart, } from "./types/transcript.js";
|
|
@@ -47,4 +47,4 @@ export { schemaFromJSON } from "./definition/schema-json.js";
|
|
|
47
47
|
export { normalizeSchema } from "./definition/schema.js";
|
|
48
48
|
export * from "./utils/immutable.js";
|
|
49
49
|
export * from "./utils/canonical.js";
|
|
50
|
-
export type { TranscriptToolsEntry } from "./types/transcript.js";
|
|
50
|
+
export type { TranscriptToolsEntry, TranscriptCompactionEntry } from "./types/transcript.js";
|
package/dist/define.js
CHANGED
|
@@ -2,15 +2,16 @@ export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./de
|
|
|
2
2
|
export { HarnessError, isHarnessError } from "./errors.js";
|
|
3
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 {
|
|
5
|
+
export { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
|
|
6
6
|
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
7
7
|
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
8
8
|
export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
|
|
9
9
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
10
10
|
export { defineSchema } from "./definition/schema.js";
|
|
11
11
|
export { hashManifest } from "./utils/hash.js";
|
|
12
|
+
export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
|
|
12
13
|
export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
|
|
13
|
-
export {
|
|
14
|
+
export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
|
|
14
15
|
export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
|
|
15
16
|
export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
|
|
16
17
|
export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
|
|
@@ -2,7 +2,7 @@ import { bindAgent } from "./bind-agent.js";
|
|
|
2
2
|
import { createManifest } from "./manifest.js";
|
|
3
3
|
import { createSkillTools } from "./skill-tools.js";
|
|
4
4
|
import { DELEGATE_NAME_PATTERN, delegateOf, delegatesOf } from "./delegate.js";
|
|
5
|
-
import {
|
|
5
|
+
import { SANDBOX_CAPABILITY_ID } from "./sandbox-capability.js";
|
|
6
6
|
const diagnostic = (code, message, extra = {}) => Object.freeze({ code, message, ...extra });
|
|
7
7
|
export function assembleAgent(middleware, identity, dynamics = new Map()) {
|
|
8
8
|
const diagnostics = [];
|
|
@@ -67,14 +67,12 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
|
|
|
67
67
|
for (const entry of item.tools ?? []) {
|
|
68
68
|
const owner = toolOwners.get(entry.name);
|
|
69
69
|
if (owner !== undefined && owner !== item.id)
|
|
70
|
-
diagnostics.push(diagnostic("tool.duplicate-name", `Tool '${entry.name}' is declared by capabilities '${owner}' and '${item.id}'`
|
|
71
|
-
(owner === "sandbox" || item.id === "sandbox"
|
|
72
|
-
? "; sandbox() provides built-in bash, read, write, edit, grep and glob tools, so rename yours"
|
|
73
|
-
: "")));
|
|
70
|
+
diagnostics.push(diagnostic("tool.duplicate-name", `Tool '${entry.name}' is declared by capabilities '${owner}' and '${item.id}'`));
|
|
74
71
|
else
|
|
75
72
|
toolOwners.set(entry.name, item.id);
|
|
76
73
|
}
|
|
77
74
|
diagnostics.push(...delegationDiagnostics(skilled.items));
|
|
75
|
+
diagnostics.push(...sandboxDiagnostics(skilled.items));
|
|
78
76
|
if (diagnostics.length)
|
|
79
77
|
return Object.freeze({
|
|
80
78
|
ok: false,
|
|
@@ -96,10 +94,6 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
|
|
|
96
94
|
/** v1 delegation is one level deep and non-interactive; anything else fails the build by name. */
|
|
97
95
|
function delegationDiagnostics(items) {
|
|
98
96
|
const found = [];
|
|
99
|
-
const sandboxes = new Set();
|
|
100
|
-
for (const item of items)
|
|
101
|
-
if (item.sandbox)
|
|
102
|
-
sandboxes.add(canonical(item.sandbox));
|
|
103
97
|
for (const item of items)
|
|
104
98
|
for (const tool of item.tools ?? []) {
|
|
105
99
|
const delegate = delegateOf(tool);
|
|
@@ -111,27 +105,28 @@ function delegationDiagnostics(items) {
|
|
|
111
105
|
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
106
|
if (!child.description?.trim())
|
|
113
107
|
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
|
-
|
|
115
|
-
|
|
116
|
-
const spec = child.sandbox;
|
|
117
|
-
if (spec && Object.keys(spec).length > 0)
|
|
118
|
-
sandboxes.add(canonical(spec));
|
|
108
|
+
// A flow agent runs in its own linked session; its agents may delegate in turn.
|
|
109
|
+
if (child.kind === "workflow")
|
|
119
110
|
continue;
|
|
120
|
-
}
|
|
121
111
|
const nested = delegatesOf(child)[0];
|
|
122
112
|
if (nested)
|
|
123
113
|
found.push(diagnostic("delegation.nested", `'${child.id}' delegates to '${nested.manifest.id}'; nested delegation is not supported yet`, extra));
|
|
124
114
|
for (const childTool of delegate.agent?.getBinding().tools ?? [])
|
|
125
115
|
if (childTool.approval)
|
|
126
116
|
found.push(diagnostic("delegation.approval-unsupported", `'${childTool.name}' in '${child.id}' needs approval; agents used as tools can't ask for it yet, so keep it on the parent`, extra));
|
|
127
|
-
for (const capability of child.capabilities)
|
|
128
|
-
if (capability.sandbox)
|
|
129
|
-
sandboxes.add(canonical(capability.sandbox));
|
|
130
117
|
}
|
|
131
|
-
if (sandboxes.size > 1)
|
|
132
|
-
found.push(diagnostic("sandbox.mismatch", "An agent and the agents it uses as tools share one sandbox, so every sandbox they declare must be identical"));
|
|
133
118
|
return found;
|
|
134
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Definitions declare no sandbox: a session gets one when it is opened (Sandboxes v3). A
|
|
122
|
+
* capability that still carries `sandbox` fails the build instead of being silently dropped.
|
|
123
|
+
* The Runtime's own capability (`nylorun.sandbox`, in a session's pinned manifest) is exempt.
|
|
124
|
+
*/
|
|
125
|
+
function sandboxDiagnostics(items) {
|
|
126
|
+
return items
|
|
127
|
+
.filter((item) => item.sandbox !== undefined && item.id !== SANDBOX_CAPABILITY_ID)
|
|
128
|
+
.map((item) => diagnostic("sandbox.in-definition", `Capability '${item.id}' declares a sandbox. Agents no longer declare one: open the session with it instead, createSession({ sandbox: { image, network: { allow }, resources } }), or set the Tenant's default sandbox.`));
|
|
129
|
+
}
|
|
135
130
|
const SKILL_TOOL_NAMES = new Set(["load_skill", "read_skill_resource"]);
|
|
136
131
|
function attachSkillTools(items) {
|
|
137
132
|
const skills = new Map();
|
|
@@ -22,6 +22,7 @@ export function bindTool(item, owner) {
|
|
|
22
22
|
execute: prepared.execute.bind(prepared),
|
|
23
23
|
...(prepared.approval === undefined ? {} : { approval: prepared.approval }),
|
|
24
24
|
...(prepared.effects === undefined ? {} : { effects: prepared.effects }),
|
|
25
|
+
...(prepared.background === undefined ? {} : { background: prepared.background }),
|
|
25
26
|
owner: Object.freeze({ ...owner }),
|
|
26
27
|
...(delegate === undefined ? {} : { delegate }),
|
|
27
28
|
});
|
|
@@ -11,6 +11,8 @@ export interface BoundToolDefinition<Info = unknown> extends Omit<ToolDefinition
|
|
|
11
11
|
readonly execute: (args: unknown, context: ToolExecutionContext<Info>) => Promise<ToolRunResult>;
|
|
12
12
|
readonly approval?: ToolApproval<ToolInputSchema>;
|
|
13
13
|
readonly effects?: ToolEffects;
|
|
14
|
+
/** Runs in the background when an Action endpoint serves it (`ToolDefinition.background`). */
|
|
15
|
+
readonly background?: boolean;
|
|
14
16
|
readonly owner: ToolOwner;
|
|
15
17
|
readonly source: ToolDefinition<any, any, any>;
|
|
16
18
|
/** Set when this tool is an agent used as a tool; the engine runs it. */
|
|
@@ -4,7 +4,7 @@ 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, McpServerManifest
|
|
7
|
+
import type { AgentManifest, McpServerManifest } from "../types/manifest.js";
|
|
8
8
|
import type { WorkflowBinding, WorkflowManifest } from "../types/workflow.js";
|
|
9
9
|
import type { AfterHook, BeforeHook, HookScope } from "../types/dynamics.js";
|
|
10
10
|
import type { Implementations } from "./implementations.js";
|
|
@@ -45,7 +45,6 @@ interface BuilderSnapshot {
|
|
|
45
45
|
readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
|
|
46
46
|
};
|
|
47
47
|
readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
|
|
48
|
-
readonly sandbox?: SandboxManifest;
|
|
49
48
|
readonly stages: readonly FlowStage[];
|
|
50
49
|
}
|
|
51
50
|
export declare class AgentBuildError extends HarnessError {
|
|
@@ -102,11 +101,6 @@ export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSourc
|
|
|
102
101
|
capability(bundle: CapabilityInput<Info> | {
|
|
103
102
|
toDeclaration(): CapabilityInput<Info>;
|
|
104
103
|
}): this;
|
|
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
104
|
/** Run `fn` before each turn. */
|
|
111
105
|
beforeTurn(fn: BeforeHook<"turn", Info>): this;
|
|
112
106
|
/** Run `fn` before every model call. */
|
|
@@ -117,11 +111,11 @@ export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSourc
|
|
|
117
111
|
afterTurn(fn: AfterHook<"turn", Info>): this;
|
|
118
112
|
/** The structured output. Set once. */
|
|
119
113
|
output<S extends ToolSchemaSource>(schema: S): AgentBuilder<Info, S, Id>;
|
|
120
|
-
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()
|
|
114
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
|
|
121
115
|
use(middleware: StepMiddleware<Info>): this;
|
|
122
|
-
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()
|
|
116
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
|
|
123
117
|
use(id: string, middleware: StepMiddleware<Info>): this;
|
|
124
|
-
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()
|
|
118
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
|
|
125
119
|
use(declaration: CapabilityInput<Info>): this;
|
|
126
120
|
/**
|
|
127
121
|
* @deprecated Use `.beforeTurn()` or `.beforeModel()`.
|
|
@@ -4,7 +4,6 @@ import { compileDeclaration } from "./declaration.js";
|
|
|
4
4
|
import { agentFrom } from "./from.js";
|
|
5
5
|
import { hooksFrom } from "./hooks.js";
|
|
6
6
|
import { isAgentItem } from "./delegate.js";
|
|
7
|
-
import { sandbox as sandboxCapability } from "./sandbox.js";
|
|
8
7
|
import { normalizeMcpServers } from "./mcp.js";
|
|
9
8
|
import { deprecate } from "../utils/deprecate.js";
|
|
10
9
|
import { WorkflowBuildError } from "./workflow/diagnostics.js";
|
|
@@ -136,28 +135,6 @@ export class AgentBuilder {
|
|
|
136
135
|
: bundle;
|
|
137
136
|
return this.addDeclaration(declaration, "capability()");
|
|
138
137
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Give the agent a Runtime-owned sandbox. On a flow agent, declares the one sandbox
|
|
141
|
-
* every agent in the flow shares.
|
|
142
|
-
*/
|
|
143
|
-
sandbox(spec = {}) {
|
|
144
|
-
const snapshot = this.#snapshot;
|
|
145
|
-
const capability = sandboxCapability(spec);
|
|
146
|
-
if (snapshot.sandbox !== undefined)
|
|
147
|
-
return this.spawn({
|
|
148
|
-
...snapshot,
|
|
149
|
-
diagnostics: addDiagnostics(snapshot.diagnostics, [singleValue(snapshot.id, "sandbox")]),
|
|
150
|
-
});
|
|
151
|
-
if (snapshot.body === "flow")
|
|
152
|
-
return this.spawn({ ...snapshot, sandbox: capability.sandbox });
|
|
153
|
-
const compiled = compileDeclaration(capability);
|
|
154
|
-
return this.spawn({
|
|
155
|
-
...snapshot,
|
|
156
|
-
sandbox: capability.sandbox,
|
|
157
|
-
entries: Object.freeze([...snapshot.entries, compiled.bound]),
|
|
158
|
-
dynamics: withDynamics(snapshot.dynamics, compiled.bound.id, {}),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
138
|
/** Run `fn` before each turn. */
|
|
162
139
|
beforeTurn(fn) {
|
|
163
140
|
return this.addAgentHook("before", "turn", fn);
|
|
@@ -186,7 +163,7 @@ export class AgentBuilder {
|
|
|
186
163
|
}
|
|
187
164
|
use(idOrMiddleware, middleware) {
|
|
188
165
|
if (typeof idOrMiddleware === "object") {
|
|
189
|
-
deprecate("NYLORUN_DEP_USE", ".use(capability) is deprecated. Use .capability(), .mcp(), .skills()
|
|
166
|
+
deprecate("NYLORUN_DEP_USE", ".use(capability) is deprecated. Use .capability(), .mcp(), .skills() or .plugin().");
|
|
190
167
|
const declaration = isCapabilityBuilder(idOrMiddleware)
|
|
191
168
|
? idOrMiddleware.toDeclaration()
|
|
192
169
|
: idOrMiddleware;
|
|
@@ -291,7 +268,6 @@ export class AgentBuilder {
|
|
|
291
268
|
stages: snapshot.stages,
|
|
292
269
|
...(snapshot.inputSchema === undefined ? {} : { inputSchema: snapshot.inputSchema }),
|
|
293
270
|
...(snapshot.outputSchema === undefined ? {} : { outputSchema: snapshot.outputSchema }),
|
|
294
|
-
...(snapshot.sandbox === undefined ? {} : { sandbox: snapshot.sandbox }),
|
|
295
271
|
});
|
|
296
272
|
}
|
|
297
273
|
catch (error) {
|
|
@@ -468,7 +444,7 @@ function hookMethod(at, scope) {
|
|
|
468
444
|
function singleValue(id, what) {
|
|
469
445
|
return Object.freeze({
|
|
470
446
|
code: "agent.single-value",
|
|
471
|
-
message: `'${id}' already has
|
|
447
|
+
message: `'${id}' already has an ${what}; set it once`,
|
|
472
448
|
});
|
|
473
449
|
}
|
|
474
450
|
function addDiagnostics(current, added) {
|
|
@@ -45,9 +45,10 @@ export function compileDeclaration(declaration) {
|
|
|
45
45
|
Object.keys(declaration.mcpServers).length === 0
|
|
46
46
|
? {}
|
|
47
47
|
: { mcpServers: declaration.mcpServers }),
|
|
48
|
-
|
|
48
|
+
// Definitions declare no sandbox; carry one through so the build can refuse it by name.
|
|
49
|
+
...(sandboxOf(declaration) === undefined
|
|
49
50
|
? {}
|
|
50
|
-
: { sandbox: declaration
|
|
51
|
+
: { sandbox: sandboxOf(declaration) }),
|
|
51
52
|
...(declaration.pluginRoot === undefined
|
|
52
53
|
? {}
|
|
53
54
|
: { pluginRoot: declaration.pluginRoot }),
|
|
@@ -103,3 +104,6 @@ function asTools(value) {
|
|
|
103
104
|
items: Object.freeze(value.items.map((item) => (isAgentItem(item) ? delegateTool(item) : item))),
|
|
104
105
|
});
|
|
105
106
|
}
|
|
107
|
+
function sandboxOf(declaration) {
|
|
108
|
+
return declaration.sandbox;
|
|
109
|
+
}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { JsonObject } from "../../types/shared.js";
|
|
10
10
|
import type { ToolSchemaSource } from "../../types/tool.js";
|
|
11
|
-
import type { SandboxManifest } from "../../types/manifest.js";
|
|
12
11
|
import { type BuiltWorkflow } from "../workflow/types.js";
|
|
13
12
|
import { type FlowStage } from "./spec.js";
|
|
14
13
|
export interface CompileFlowOptions {
|
|
@@ -19,7 +18,6 @@ export interface CompileFlowOptions {
|
|
|
19
18
|
readonly stages: readonly FlowStage[];
|
|
20
19
|
readonly inputSchema?: ToolSchemaSource;
|
|
21
20
|
readonly outputSchema?: ToolSchemaSource;
|
|
22
|
-
readonly sandbox?: SandboxManifest;
|
|
23
21
|
}
|
|
24
22
|
/** Compile a flow agent. Throws `WorkflowBuildError` with diagnostics. */
|
|
25
23
|
export declare function compileAgentFlow(options: CompileFlowOptions): BuiltWorkflow;
|
|
@@ -4,7 +4,7 @@ import { copyJsonObject } from "../../utils/immutable.js";
|
|
|
4
4
|
import { canonical } from "../../utils/canonical.js";
|
|
5
5
|
import { diagnostic, fail } from "../workflow/diagnostics.js";
|
|
6
6
|
import { isBuiltWorkflow } from "../workflow/types.js";
|
|
7
|
-
import { bindToolNode, builtAgentOf, isToolDefinition,
|
|
7
|
+
import { bindToolNode, builtAgentOf, isToolDefinition, toolManifestNode, } from "../workflow/runnable.js";
|
|
8
8
|
import { isFlowBuilder, isNamedChild } from "./spec.js";
|
|
9
9
|
import { forEachFlowNode, functionKey, isWorkflowManifestV2, leafPart, } from "./paths.js";
|
|
10
10
|
/** Compile a flow agent. Throws `WorkflowBuildError` with diagnostics. */
|
|
@@ -19,12 +19,10 @@ export function compileAgentFlow(options) {
|
|
|
19
19
|
code: new WeakMap(),
|
|
20
20
|
agents: {},
|
|
21
21
|
bindings: {},
|
|
22
|
-
sandboxSpecs: [],
|
|
23
22
|
diagnostics: [],
|
|
24
23
|
};
|
|
25
24
|
const root = { chain: stages.map((stage) => compileStage(stage, build)) };
|
|
26
25
|
const nodes = bindNodes(root, build);
|
|
27
|
-
const sandbox = flowSandbox(options.id, options.sandbox, build);
|
|
28
26
|
if (build.diagnostics.length)
|
|
29
27
|
fail(build.diagnostics);
|
|
30
28
|
const manifest = {
|
|
@@ -40,7 +38,6 @@ export function compileAgentFlow(options) {
|
|
|
40
38
|
...(options.outputSchema === undefined
|
|
41
39
|
? {}
|
|
42
40
|
: { outputSchema: jsonSchemaOf(options.outputSchema) }),
|
|
43
|
-
...(sandbox === undefined ? {} : { sandbox }),
|
|
44
41
|
root,
|
|
45
42
|
agents: build.agents,
|
|
46
43
|
};
|
|
@@ -174,7 +171,6 @@ function agentLeaf(agent, build) {
|
|
|
174
171
|
const resolved = builtAgentOf(agent);
|
|
175
172
|
embed(build, resolved.id, resolved.manifest);
|
|
176
173
|
addBinding(build, resolved.id, bindingFromAgent(resolved));
|
|
177
|
-
build.sandboxSpecs.push(...sandboxSpecsOf(resolved));
|
|
178
174
|
return { agent: resolved.id };
|
|
179
175
|
}
|
|
180
176
|
function nestedFlow(built, build) {
|
|
@@ -186,8 +182,6 @@ function nestedFlow(built, build) {
|
|
|
186
182
|
embed(build, built.id, built.manifest);
|
|
187
183
|
for (const [id, agent] of Object.entries(binding.agents))
|
|
188
184
|
addBinding(build, id, agent);
|
|
189
|
-
if (built.manifest.sandbox !== undefined)
|
|
190
|
-
build.sandboxSpecs.push(built.manifest.sandbox);
|
|
191
185
|
const node = { agent: built.id };
|
|
192
186
|
attach(build, node, { nested: binding });
|
|
193
187
|
return node;
|
|
@@ -269,28 +263,6 @@ function bindNodes(root, build) {
|
|
|
269
263
|
});
|
|
270
264
|
return nodes;
|
|
271
265
|
}
|
|
272
|
-
/**
|
|
273
|
-
* The flow's sandbox. Agents that declare a sandbox with options must all declare the
|
|
274
|
-
* same one, and match the flow's own when it declares one; `.sandbox()` with no options
|
|
275
|
-
* uses the flow's.
|
|
276
|
-
*/
|
|
277
|
-
function flowSandbox(id, declared, build) {
|
|
278
|
-
const specific = build.sandboxSpecs.filter((spec) => Object.keys(spec).length > 0);
|
|
279
|
-
const kinds = new Set(specific.map((spec) => canonical(spec)));
|
|
280
|
-
if (declared !== undefined && Object.keys(declared).length > 0)
|
|
281
|
-
kinds.add(canonical(declared));
|
|
282
|
-
if (kinds.size > 1) {
|
|
283
|
-
build.diagnostics.push(diagnostic("workflow.sandbox-mismatch", `The agents in flow agent '${id}' declare different sandboxes. Declare the sandbox once on the flow with .sandbox({ … }) and give the agents .sandbox() with no options.`));
|
|
284
|
-
return undefined;
|
|
285
|
-
}
|
|
286
|
-
if (declared !== undefined && Object.keys(declared).length > 0)
|
|
287
|
-
return declared;
|
|
288
|
-
if (specific.length > 0)
|
|
289
|
-
return specific[0];
|
|
290
|
-
if (declared !== undefined || build.sandboxSpecs.length > 0)
|
|
291
|
-
return {};
|
|
292
|
-
return undefined;
|
|
293
|
-
}
|
|
294
266
|
function jsonSchemaOf(source) {
|
|
295
267
|
return bindOutputContract(source).schema.jsonSchema;
|
|
296
268
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Types for flow agents: each stage's output types the next stage's `input`, and
|
|
3
3
|
* `results` gains an entry for every step whose id is known at compile time.
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
5
|
+
import type { AgentManifest } from "../../types/manifest.js";
|
|
6
6
|
import type { SchemaOutput, ToolSchemaSource } from "../../types/tool.js";
|
|
7
7
|
import type { Verdict } from "../../types/workflow.js";
|
|
8
8
|
import type { BuiltWorkflow } from "../workflow/types.js";
|
|
@@ -83,8 +83,6 @@ export interface FlowAgentBuilder<Info = unknown, In = any, Cur = any, Results =
|
|
|
83
83
|
/** Give this flow agent a new step id where there is no options object. */
|
|
84
84
|
withId(id: string): Named<this>;
|
|
85
85
|
output<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, In, Cur, Results, SchemaOutput<S>, Id>;
|
|
86
|
-
/** The one sandbox every agent in the flow shares. */
|
|
87
|
-
sandbox(spec?: SandboxManifest): FlowAgentBuilder<Info, In, Cur, Results, Out, Id>;
|
|
88
86
|
step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
|
|
89
87
|
readonly id?: StepId;
|
|
90
88
|
readonly input?: (args: StageArgs<Cur, Results, In>) => unknown;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ModelFailureCode, ModelFailureOutcome } from "../types/model.js";
|
|
2
|
+
export declare const MODEL_FAILURE_CODES: readonly ModelFailureCode[];
|
|
3
|
+
/** True for a model adapter's failure outcome (`{ kind: "failed", code, message, retryable }`). */
|
|
4
|
+
export declare function isModelFailureOutcome(value: unknown): value is ModelFailureOutcome;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const MODEL_FAILURE_CODES = Object.freeze([
|
|
2
|
+
"context_overflow",
|
|
3
|
+
"rate_limited",
|
|
4
|
+
"overloaded",
|
|
5
|
+
"timeout",
|
|
6
|
+
"transient",
|
|
7
|
+
"content_policy",
|
|
8
|
+
"auth",
|
|
9
|
+
"invalid_request",
|
|
10
|
+
"invalid_output",
|
|
11
|
+
"budget_exhausted",
|
|
12
|
+
]);
|
|
13
|
+
/** True for a model adapter's failure outcome (`{ kind: "failed", code, message, retryable }`). */
|
|
14
|
+
export function isModelFailureOutcome(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
|
+
return false;
|
|
17
|
+
const outcome = value;
|
|
18
|
+
return (outcome.kind === "failed" &&
|
|
19
|
+
typeof outcome.code === "string" &&
|
|
20
|
+
MODEL_FAILURE_CODES.includes(outcome.code) &&
|
|
21
|
+
typeof outcome.message === "string" &&
|
|
22
|
+
typeof outcome.retryable === "boolean");
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CapabilityManifest, SandboxManifest } from "../types/manifest.js";
|
|
2
|
+
/** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
|
|
3
|
+
export declare const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
|
|
4
|
+
/**
|
|
5
|
+
* The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
|
|
6
|
+
* instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
|
|
7
|
+
* tools are projected the way the builder projects any tool.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sandboxCapabilityManifest(spec: SandboxManifest, options?: {
|
|
10
|
+
/** The workspace path the backend uses, named in the tools' text. Default `/workspace`. */
|
|
11
|
+
readonly workspace?: string;
|
|
12
|
+
}): CapabilityManifest;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SANDBOX_INSTRUCTIONS, createSandboxTools } from "./sandbox-tools.js";
|
|
2
|
+
import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
3
|
+
import { normalizedSchemasFor } from "./schema.js";
|
|
4
|
+
import { copyJsonObject } from "../utils/immutable.js";
|
|
5
|
+
/** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
|
|
6
|
+
export const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
|
|
7
|
+
/**
|
|
8
|
+
* The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
|
|
9
|
+
* instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
|
|
10
|
+
* tools are projected the way the builder projects any tool.
|
|
11
|
+
*/
|
|
12
|
+
export function sandboxCapabilityManifest(spec, options = {}) {
|
|
13
|
+
const workspace = options.workspace ?? SANDBOX_WORKSPACE;
|
|
14
|
+
const text = (value) => value.replaceAll(SANDBOX_WORKSPACE, workspace);
|
|
15
|
+
const tools = createSandboxTools().map((tool) => {
|
|
16
|
+
const schemas = normalizedSchemasFor(tool);
|
|
17
|
+
return {
|
|
18
|
+
name: tool.name,
|
|
19
|
+
...(tool.description === undefined ? {} : { description: text(tool.description) }),
|
|
20
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
21
|
+
...(schemas.outputSchema === undefined
|
|
22
|
+
? {}
|
|
23
|
+
: { outputSchema: schemas.outputSchema.jsonSchema }),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
id: SANDBOX_CAPABILITY_ID,
|
|
28
|
+
type: "agent",
|
|
29
|
+
instructions: [text(SANDBOX_INSTRUCTIONS)],
|
|
30
|
+
tools,
|
|
31
|
+
sandbox: copyJsonObject(spec, "sandbox"),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -49,6 +49,9 @@ export function normalizeToolDefinition(definition) {
|
|
|
49
49
|
...(definition.effects === undefined
|
|
50
50
|
? {}
|
|
51
51
|
: { effects: definition.effects }),
|
|
52
|
+
...(definition.background === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { background: definition.background }),
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
57
|
/** Returns cached normalized contracts, preparing raw definitions on first bind. */
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import type { AgentBinding } from "../binding.js";
|
|
2
|
-
import type { BuildDiagnostic,
|
|
2
|
+
import type { BuildDiagnostic, JsonValue } from "../../types/shared.js";
|
|
3
3
|
import type { WorkflowNode, WorkflowNodeImplementation } from "../../types/workflow.js";
|
|
4
4
|
import type { ToolSchemaSource } from "../../types/tool.js";
|
|
5
5
|
import type { BuiltWorkflow } from "./types.js";
|
|
6
6
|
export type BuildAccumulator = {
|
|
7
7
|
readonly agents: Record<string, AgentBinding>;
|
|
8
8
|
readonly nodes: Record<string, WorkflowNodeImplementation>;
|
|
9
|
-
readonly sandboxSpecs: JsonObject[];
|
|
10
9
|
};
|
|
11
10
|
export declare function emptyAccumulator(): BuildAccumulator;
|
|
12
11
|
export declare function mergeChild(acc: BuildAccumulator, child: {
|
|
13
12
|
readonly agents: Record<string, AgentBinding>;
|
|
14
13
|
readonly nodes: Record<string, WorkflowNodeImplementation>;
|
|
15
|
-
readonly sandboxSpecs: readonly JsonObject[];
|
|
16
14
|
}): void;
|
|
17
|
-
/**
|
|
18
|
-
* Every agent in the tree that declares a sandbox must declare an identical spec
|
|
19
|
-
* (workflows.md §8). Returns the common spec, or undefined when none declare one.
|
|
20
|
-
*/
|
|
21
|
-
export declare function resolveWorkflowSandbox(specs: readonly JsonObject[]): {
|
|
22
|
-
sandbox?: JsonObject;
|
|
23
|
-
diagnostics: BuildDiagnostic[];
|
|
24
|
-
};
|
|
25
15
|
export type FinishOptions<In = JsonValue, Out = JsonValue> = {
|
|
26
16
|
readonly id: string;
|
|
27
17
|
readonly root: WorkflowNode;
|
|
@@ -32,7 +22,7 @@ export type FinishOptions<In = JsonValue, Out = JsonValue> = {
|
|
|
32
22
|
readonly diagnostics?: readonly BuildDiagnostic[];
|
|
33
23
|
};
|
|
34
24
|
/**
|
|
35
|
-
* Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON
|
|
36
|
-
*
|
|
25
|
+
* Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
|
|
26
|
+
* declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
|
|
37
27
|
*/
|
|
38
28
|
export declare function finishWorkflow<In = JsonValue, Out = JsonValue>(options: FinishOptions<In, Out>): BuiltWorkflow<In, Out>;
|
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
import { canonical } from "../../utils/canonical.js";
|
|
2
1
|
import { diagnostic, fail } from "./diagnostics.js";
|
|
3
2
|
export function emptyAccumulator() {
|
|
4
|
-
return { agents: {}, nodes: {}
|
|
3
|
+
return { agents: {}, nodes: {} };
|
|
5
4
|
}
|
|
6
5
|
export function mergeChild(acc, child) {
|
|
7
6
|
Object.assign(acc.agents, child.agents);
|
|
8
7
|
Object.assign(acc.nodes, child.nodes);
|
|
9
|
-
for (const spec of child.sandboxSpecs)
|
|
10
|
-
acc.sandboxSpecs.push(spec);
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
export function resolveWorkflowSandbox(specs) {
|
|
17
|
-
if (specs.length === 0)
|
|
18
|
-
return { diagnostics: [] };
|
|
19
|
-
const keys = new Set(specs.map((s) => canonical(s)));
|
|
20
|
-
if (keys.size > 1)
|
|
21
|
-
return {
|
|
22
|
-
diagnostics: [
|
|
23
|
-
diagnostic("workflow.sandbox-mismatch", "Every agent in the tree that declares a sandbox must declare an identical spec"),
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
return { sandbox: specs[0], diagnostics: [] };
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON,
|
|
30
|
-
* optional document-level sandbox (workflows.md §18).
|
|
10
|
+
* Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
|
|
11
|
+
* declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
|
|
31
12
|
*/
|
|
32
13
|
export function finishWorkflow(options) {
|
|
33
14
|
const diagnostics = [...(options.diagnostics ?? [])];
|
|
34
|
-
const { sandbox, diagnostics: sandboxDiagnostics } = resolveWorkflowSandbox(options.acc.sandboxSpecs);
|
|
35
|
-
diagnostics.push(...sandboxDiagnostics);
|
|
36
15
|
if (diagnostics.length)
|
|
37
16
|
fail(diagnostics);
|
|
38
17
|
const manifest = {
|
|
@@ -40,7 +19,6 @@ export function finishWorkflow(options) {
|
|
|
40
19
|
workflowSchemaVersion: 1,
|
|
41
20
|
id: options.id,
|
|
42
21
|
root: options.root,
|
|
43
|
-
...(sandbox === undefined ? {} : { sandbox: sandbox }),
|
|
44
22
|
};
|
|
45
23
|
const binding = Object.freeze({
|
|
46
24
|
manifest,
|
|
@@ -46,7 +46,6 @@ export function Loop(options) {
|
|
|
46
46
|
mergeChild(acc, {
|
|
47
47
|
agents: runResolved.agents,
|
|
48
48
|
nodes: remapNodeKeys(runResolved.nodes, runResolved.id, runPath),
|
|
49
|
-
sandboxSpecs: runResolved.sandboxSpecs,
|
|
50
49
|
});
|
|
51
50
|
let verifyField;
|
|
52
51
|
if (isVerifyFn(verify)) {
|
|
@@ -71,7 +70,6 @@ export function Loop(options) {
|
|
|
71
70
|
mergeChild(acc, {
|
|
72
71
|
agents: verifyChild.agents,
|
|
73
72
|
nodes: remapNodeKeys(verifyChild.nodes, verifyChild.id, `${id}/${verifyChild.id}`),
|
|
74
|
-
sandboxSpecs: verifyChild.sandboxSpecs,
|
|
75
73
|
});
|
|
76
74
|
const node = verifyChild.node;
|
|
77
75
|
if (!("agent" in node) && !("slot" in node)) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AgentTool, BuiltAgent } from "../../types/agent.js";
|
|
2
|
-
import type { JsonObject } from "../../types/shared.js";
|
|
3
2
|
import type { ToolDefinition } from "../../types/tool.js";
|
|
4
3
|
import type { WorkflowNode, WorkflowToolNode } from "../../types/workflow.js";
|
|
5
4
|
import type { AgentBinding } from "../binding.js";
|
|
@@ -17,7 +16,6 @@ export type ResolvedChild = {
|
|
|
17
16
|
/** Nested workflow implementations, keyed relative to the child root id. */
|
|
18
17
|
readonly nodes: Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>;
|
|
19
18
|
readonly tool?: BoundToolDefinition;
|
|
20
|
-
readonly sandboxSpecs: readonly JsonObject[];
|
|
21
19
|
readonly isReshapingSlot: boolean;
|
|
22
20
|
};
|
|
23
21
|
export declare function isToolDefinition(value: unknown): value is ToolDefinition;
|
|
@@ -25,8 +23,6 @@ export declare function isAgentLike(value: unknown): value is BuiltAgent | Agent
|
|
|
25
23
|
export declare function builtAgentOf(run: BuiltAgent | AgentTool | {
|
|
26
24
|
build(): BuiltAgent;
|
|
27
25
|
}): BuiltAgent;
|
|
28
|
-
/** Collect sandbox specs declared on an agent (and its delegates, one level). */
|
|
29
|
-
export declare function sandboxSpecsOf(agent: BuiltAgent | AgentTool): JsonObject[];
|
|
30
26
|
/**
|
|
31
27
|
* Project a tool for use as a workflow node.
|
|
32
28
|
* Unlike agent tools, workflow tool nodes may take any JSON Schema root type (workflows.md §9).
|