@nylorun/core 0.2.0-beta → 0.4.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.
@@ -1,11 +1,17 @@
1
1
  import type { JsonObject } from "./shared.js";
2
+ import type { HookManifest } from "./dynamics.js";
2
3
  /** Published manifest schema version (no top-level model — Runtime-owned). */
3
- export type ManifestSchemaVersion = 3;
4
+ export type ManifestSchemaVersion = 4;
4
5
  export interface ToolManifest {
5
6
  readonly name: string;
6
7
  readonly description?: string;
7
8
  readonly inputSchema: JsonObject;
8
9
  readonly outputSchema?: JsonObject;
10
+ /**
11
+ * Present when this tool is another agent. The engine runs it with a fresh context and
12
+ * returns its final output; its input is always `{ task: string }`. One level deep.
13
+ */
14
+ readonly agent?: AgentManifest;
9
15
  }
10
16
  export interface SkillManifest {
11
17
  readonly name: string;
@@ -29,6 +35,29 @@ export type McpServerManifest = {
29
35
  readonly url: string;
30
36
  readonly headers?: Readonly<Record<string, string>>;
31
37
  };
38
+ /** Network egress preset for a sandbox. Private ranges and metadata endpoints are always blocked. */
39
+ export type SandboxNetworkPreset = "none" | "dev" | "open";
40
+ /**
41
+ * What computer an agent needs. The Runtime decides where it runs; nothing here names a backend.
42
+ * Every field is optional; omitted fields take Runtime defaults.
43
+ */
44
+ export interface SandboxManifest {
45
+ /** OCI image reference. Default: the Runtime's default sandbox image. */
46
+ readonly image?: string;
47
+ readonly network?: {
48
+ /** Default: "dev" (package registries and code hosts over HTTPS). */
49
+ readonly preset?: SandboxNetworkPreset;
50
+ /** Extra hosts to allow, e.g. "api.github.com" or "*.example.com". */
51
+ readonly allow?: readonly string[];
52
+ };
53
+ readonly resources?: {
54
+ readonly cpus?: number;
55
+ /** Size such as "512MiB" or "2GiB". */
56
+ readonly memory?: string;
57
+ };
58
+ /** Stop compute after this long without use, e.g. "15m". Files persist. */
59
+ readonly idle?: string;
60
+ }
32
61
  export interface CapabilityManifest {
33
62
  readonly id: string;
34
63
  readonly type: "agent" | "agent-plugin";
@@ -39,8 +68,10 @@ export interface CapabilityManifest {
39
68
  readonly skills?: Readonly<Record<string, SkillManifest>>;
40
69
  readonly tools?: readonly ToolManifest[];
41
70
  readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
42
- readonly beforeModelCall?: boolean;
43
- readonly afterModelCall?: boolean;
71
+ /** Present when this capability gives the agent a Runtime-owned sandbox. */
72
+ readonly sandbox?: SandboxManifest;
73
+ /** Hook points this capability registered, in canonical order. */
74
+ readonly hooks?: readonly HookManifest[];
44
75
  }
45
76
  /** Reserved. Empty until later fields are defined. Omit `runtime` while it has no fields. */
46
77
  export interface RuntimeManifest {
@@ -1,6 +1,7 @@
1
1
  import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
2
  import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
- import type { McpServerManifest, SkillManifest } from "./manifest.js";
3
+ import type { AgentTool } from "./agent.js";
4
+ import type { McpServerManifest, SandboxManifest, SkillManifest } from "./manifest.js";
4
5
  /** Skill files held on the developer binding. Not a manifest field. */
5
6
  export interface SkillRecord {
6
7
  readonly name: string;
@@ -9,7 +10,7 @@ export interface SkillRecord {
9
10
  readonly resources?: Readonly<Record<string, string>>;
10
11
  }
11
12
  import type { ContextItem, JsonObject, Tripwire } from "./shared.js";
12
- import type { AfterModelCallFn, BeforeModelCallFn } from "./dynamics.js";
13
+ import type { AfterHooks, BeforeHooks } from "./dynamics.js";
13
14
  import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
14
15
  interface StepRequestBase {
15
16
  /** Opaque identity of the execution that owns this Step. */
@@ -69,6 +70,8 @@ export interface CapabilityDeclaration<Info = unknown> {
69
70
  /** File contents for load_skill. Omitted from the manifest. */
70
71
  readonly skillRecords?: Readonly<Record<string, SkillRecord>>;
71
72
  readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
73
+ /** Runtime-owned sandbox requirements. Declare the built-in sandbox tools alongside it. */
74
+ readonly sandbox?: SandboxManifest;
72
75
  /** Resolved package directory. Not projected into the manifest. */
73
76
  readonly pluginRoot?: string;
74
77
  /**
@@ -76,11 +79,17 @@ export interface CapabilityDeclaration<Info = unknown> {
76
79
  * Kept for local middleware composition through 1.0.
77
80
  */
78
81
  readonly model?: ModelDirective;
79
- /** @deprecated Prefer beforeModelCall / afterModelCall. Kept through 1.0. */
82
+ /** @deprecated Prefer before / after hooks. Kept through 1.0. */
80
83
  readonly middleware?: StepMiddleware<Info>;
81
- readonly beforeModelCall?: BeforeModelCallFn<Info>;
82
- readonly afterModelCall?: AfterModelCallFn<Info>;
84
+ /** Run before each turn or each model call (step). */
85
+ readonly before?: BeforeHooks<Info>;
86
+ /** Run after each model call (step) or after the turn's final answer. */
87
+ readonly after?: AfterHooks<Info>;
83
88
  }
89
+ /** What `.use()` accepts: a capability whose `tools` may also hold agents used as tools. */
90
+ export type CapabilityInput<Info = unknown> = Omit<CapabilityDeclaration<Info>, "tools"> & {
91
+ readonly tools?: CapabilityItems<ToolDefinition<any, Info, any> | AgentTool>;
92
+ };
84
93
  export interface MiddlewareContributions {
85
94
  readonly instructions?: readonly string[];
86
95
  readonly tools?: readonly {
@@ -1,7 +1,7 @@
1
1
  import type { ContextSnapshot, ModelCandidate, ModelCall, ModelConfigurationSnapshot } from "./model.js";
2
2
  import type { JsonObject, JsonValue } from "./shared.js";
3
3
  import type { InputEvent, TranscriptEntry } from "./transcript.js";
4
- import type { RequiredInteraction, ToolDescriptor, ToolResult } from "./tool.js";
4
+ import type { AgentRef, RequiredInteraction, ToolDescriptor, ToolResult } from "./tool.js";
5
5
  export type ObserveToolSnapshot = ToolDescriptor;
6
6
  /** JSON-only model-configuration view suitable for an observation stream. */
7
7
  export interface ObserveModelConfigurationSnapshot extends Omit<ModelConfigurationSnapshot, "tools"> {
@@ -144,6 +144,28 @@ export type ObserveEvent = {
144
144
  readonly attributes: {
145
145
  readonly token?: JsonValue;
146
146
  };
147
+ } | {
148
+ readonly type: "delegation.started";
149
+ readonly turnId: string;
150
+ readonly stepId: string;
151
+ readonly callId: string;
152
+ readonly invocationId: string;
153
+ readonly toolName: string;
154
+ readonly agent: AgentRef;
155
+ readonly attributes: {
156
+ readonly task: string;
157
+ };
158
+ } | {
159
+ readonly type: "delegation.completed";
160
+ readonly turnId: string;
161
+ readonly stepId: string;
162
+ readonly callId: string;
163
+ readonly invocationId: string;
164
+ readonly toolName: string;
165
+ readonly agent: AgentRef;
166
+ /** The agent's own end state: completed, failed, cancelled or paused. */
167
+ readonly status: string;
168
+ readonly attributes: ToolResult;
147
169
  } | {
148
170
  readonly type: "turn.completed";
149
171
  readonly turnId: string;
@@ -102,6 +102,15 @@ export interface ToolExecutionResume {
102
102
  readonly value?: JsonValue;
103
103
  readonly token?: JsonValue;
104
104
  }
105
+ /**
106
+ * The agent a call belongs to. `path` is `"<root>"` or `"<root>/<child>"`; `delegationId`
107
+ * identifies one run of an agent used as a tool and is absent for the root agent.
108
+ */
109
+ export interface AgentRef {
110
+ readonly id: string;
111
+ readonly path: string;
112
+ readonly delegationId?: string;
113
+ }
105
114
  interface ToolExecutionContextBase {
106
115
  readonly executionId: string;
107
116
  readonly turnId: string;
@@ -116,12 +125,14 @@ interface ToolExecutionContextBase {
116
125
  readonly idempotencyKey: string;
117
126
  /** True when this invocation is being offered again after an interrupted active call. */
118
127
  readonly redelivery?: boolean;
119
- /** Durable session memory (tools write; beforeModelCall reads). */
128
+ /** Durable session memory (tools write; hooks read). */
120
129
  readonly state: SessionStateBag;
121
130
  /** Session identity stub — Runtime fills this later. */
122
131
  readonly session: {
123
132
  readonly id: string;
124
133
  };
134
+ /** The agent this call belongs to: the root agent, or an agent used as a tool. */
135
+ readonly agent?: AgentRef;
125
136
  /** Live progress stub — emits an observation when a listener is present. */
126
137
  progress(message: string, data?: JsonObject): void;
127
138
  /** Durable wait: park for a human/app response. */
@@ -0,0 +1,17 @@
1
+ /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
+ /** Built-in tools every sandbox capability declares. The Runtime executes them. */
3
+ export declare const SANDBOX_TOOL_NAMES: readonly ["bash", "read", "write", "edit", "grep", "glob"];
4
+ export type SandboxToolName = (typeof SANDBOX_TOOL_NAMES)[number];
5
+ export declare const SANDBOX_WORKSPACE = "/workspace";
6
+ export declare const SANDBOX_NETWORK_PRESETS: readonly ["none", "dev", "open"];
7
+ /** Manifest fields this version implements. Anything else is rejected with a teaching error. */
8
+ export declare const SANDBOX_FIELDS: readonly ["image", "network", "resources", "idle"];
9
+ /** Fields from the sandbox design that later versions will accept. */
10
+ export declare const SANDBOX_DEFERRED_FIELDS: readonly ["setup", "setupKey", "files", "secrets", "mount", "onStart", "scope", "isolation", "own", "tools", "snapshot"];
11
+ export declare function isSandboxToolName(name: string): name is SandboxToolName;
12
+ /** Parse "15m", "30s", "1h" into milliseconds. Returns undefined when invalid. */
13
+ export declare function parseSandboxDuration(value: string): number | undefined;
14
+ /** Parse "512MiB", "2GiB" into bytes. Returns undefined when invalid. */
15
+ export declare function parseSandboxSize(value: string): number | undefined;
16
+ /** A host name, optionally with a leading "*." wildcard. No scheme, port, path or IP literal. */
17
+ export declare function isSandboxHostPattern(value: string): boolean;
@@ -0,0 +1,64 @@
1
+ /** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
2
+ /** Built-in tools every sandbox capability declares. The Runtime executes them. */
3
+ export const SANDBOX_TOOL_NAMES = Object.freeze([
4
+ "bash",
5
+ "read",
6
+ "write",
7
+ "edit",
8
+ "grep",
9
+ "glob",
10
+ ]);
11
+ export const SANDBOX_WORKSPACE = "/workspace";
12
+ export const SANDBOX_NETWORK_PRESETS = Object.freeze(["none", "dev", "open"]);
13
+ /** Manifest fields this version implements. Anything else is rejected with a teaching error. */
14
+ export const SANDBOX_FIELDS = Object.freeze(["image", "network", "resources", "idle"]);
15
+ /** Fields from the sandbox design that later versions will accept. */
16
+ export const SANDBOX_DEFERRED_FIELDS = Object.freeze([
17
+ "setup",
18
+ "setupKey",
19
+ "files",
20
+ "secrets",
21
+ "mount",
22
+ "onStart",
23
+ "scope",
24
+ "isolation",
25
+ "own",
26
+ "tools",
27
+ "snapshot",
28
+ ]);
29
+ export function isSandboxToolName(name) {
30
+ return SANDBOX_TOOL_NAMES.includes(name);
31
+ }
32
+ const DURATION = /^(\d+)(ms|s|m|h|d)$/;
33
+ const DURATION_MS = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
34
+ /** Parse "15m", "30s", "1h" into milliseconds. Returns undefined when invalid. */
35
+ export function parseSandboxDuration(value) {
36
+ const match = DURATION.exec(value.trim());
37
+ if (!match)
38
+ return undefined;
39
+ const amount = Number(match[1]);
40
+ return amount > 0 ? amount * DURATION_MS[match[2]] : undefined;
41
+ }
42
+ const SIZE = /^(\d+)(B|KiB|MiB|GiB|TiB)$/;
43
+ const SIZE_BYTES = { B: 1, KiB: 1024, MiB: 1024 ** 2, GiB: 1024 ** 3, TiB: 1024 ** 4 };
44
+ /** Parse "512MiB", "2GiB" into bytes. Returns undefined when invalid. */
45
+ export function parseSandboxSize(value) {
46
+ const match = SIZE.exec(value.trim());
47
+ if (!match)
48
+ return undefined;
49
+ const amount = Number(match[1]);
50
+ return amount > 0 ? amount * SIZE_BYTES[match[2]] : undefined;
51
+ }
52
+ const LABEL = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/;
53
+ /** A host name, optionally with a leading "*." wildcard. No scheme, port, path or IP literal. */
54
+ export function isSandboxHostPattern(value) {
55
+ const host = value.startsWith("*.") ? value.slice(2) : value;
56
+ if (host.length === 0 || host.length > 253)
57
+ return false;
58
+ const labels = host.toLowerCase().split(".");
59
+ if (labels.length < 2)
60
+ return false;
61
+ if (labels.every((label) => /^\d+$/.test(label)))
62
+ return false;
63
+ return labels.every((label) => LABEL.test(label));
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.2.0-beta",
3
+ "version": "0.4.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",