@nylorun/core 0.17.0-beta → 0.19.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,13 +1,11 @@
1
1
  import { HarnessError } from "../errors.js";
2
2
  import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
- import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
5
- import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue } from "./removed.js";
4
+ import { assertJson, deepFreeze } from "../utils/immutable.js";
6
5
  import { delegateFromManifest, delegateOf } from "./delegate.js";
7
- import { mcpToolSettingsVersionIssue, stdioMcpRefusal, usesMcpToolSettings } from "./mcp.js";
8
6
  import { SKILL_TOOL_NAMES } from "./skill-tools.js";
9
- import { skillFilesIssue } from "../utils/definition-files.js";
10
7
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
8
+ import { AgentManifestSchema } from "../contracts.js";
11
9
  /** Tools the engine or the Runtime runs, which need no implementation: agents and HTTP tools. */
12
10
  const declarative = (tool) => delegateOf(tool) !== undefined || httpToolOf(tool) !== undefined;
13
11
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
@@ -149,191 +147,27 @@ function resolveTools(capability, tools) {
149
147
  throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
150
148
  });
151
149
  }
150
+ /**
151
+ * The manifest as `AgentManifestSchema` accepts it (the Runtime's own check), as a frozen copy.
152
+ * A refusal is `agent.build-failed` with the schema's messages.
153
+ */
152
154
  function normalizeManifest(json) {
153
155
  if (!json || typeof json !== "object" || Array.isArray(json))
154
156
  throw new HarnessError("agent.build-failed", "Agent.from requires a manifest object");
155
- const value = json;
156
- if (typeof value.id !== "string" || !value.id)
157
- throw new HarnessError("agent.build-failed", "Manifest id must be a non-empty string");
158
- if ("name" in value && value.name !== undefined) {
159
- if (typeof value.name !== "string" || !value.name)
160
- throw new HarnessError("agent.build-failed", "Manifest name must be a non-empty string");
161
- }
162
- if (!Array.isArray(value.capabilities))
163
- throw new HarnessError("agent.build-failed", "Manifest capabilities must be an array");
164
- if ("schemaVersion" in value && value.schemaVersion !== undefined)
165
- throw new HarnessError("agent.build-failed", "Manifest field schemaVersion was renamed to manifestSchemaVersion");
166
- const versionIssue = manifestVersionIssue(value.manifestSchemaVersion);
167
- if (versionIssue)
168
- throw new HarnessError("agent.build-failed", versionIssue);
169
- if ("functions" in value && value.functions !== undefined)
170
- throw new HarnessError("agent.build-failed", "Functions are not available yet");
171
- // Reject top-level model (Runtime-owned).
172
- if ("model" in value && value.model !== undefined)
173
- throw new HarnessError("agent.build-failed", "Manifest must not include top-level model; Runtime owns model resolution");
174
- if ("description" in value && value.description !== undefined) {
175
- if (typeof value.description !== "string")
176
- throw new HarnessError("agent.build-failed", "Manifest description must be a string");
177
- }
178
- const metadata = "metadata" in value && value.metadata !== undefined
179
- ? copyJsonObject(value.metadata, "metadata")
180
- : undefined;
181
- const runtime = normalizeRuntime(value.runtime);
182
- const capabilities = value.capabilities.map(normalizeCapability);
183
- const version = value.manifestSchemaVersion;
184
- const servers = new Set();
185
- for (const capability of capabilities)
186
- for (const [name, server] of Object.entries(capability.mcpServers ?? {})) {
187
- if (servers.has(name))
188
- throw new HarnessError("agent.build-failed", `Duplicate MCP server '${name}'`);
189
- servers.add(name);
190
- if (version === 5 && usesMcpToolSettings(server))
191
- throw new HarnessError("agent.build-failed", mcpToolSettingsVersionIssue(name));
192
- }
193
- return deepFreeze({
194
- // The manifest's own version: a v6 manifest without v6 fields keeps its hash.
195
- manifestSchemaVersion: version,
196
- id: value.id,
197
- ...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
198
- ...(typeof value.description === "string"
199
- ? { description: value.description }
200
- : {}),
201
- ...(metadata === undefined ? {} : { metadata }),
202
- ...(value.outputSchema && typeof value.outputSchema === "object"
203
- ? { outputSchema: value.outputSchema }
204
- : {}),
205
- capabilities,
206
- ...(runtime === undefined ? {} : { runtime }),
207
- });
208
- }
209
- function normalizeRuntime(value) {
210
- if (value === undefined)
211
- return undefined;
212
- if (!value ||
213
- typeof value !== "object" ||
214
- Array.isArray(value) ||
215
- Object.keys(value).length > 0)
216
- throw new HarnessError("agent.build-failed", "runtime must be an empty object when present");
217
- return {};
218
- }
219
- function normalizeCapability(capability) {
220
- const raw = capability;
221
- if ("name" in raw && raw.name !== undefined) {
222
- if (typeof raw.name !== "string" || !raw.name)
223
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' name must be a non-empty string`);
224
- }
225
- if ("description" in raw && raw.description !== undefined) {
226
- if (typeof raw.description !== "string")
227
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' description must be a string`);
228
- }
229
- if ("model" in raw && raw.model !== undefined)
230
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' must not include model; Runtime owns model resolution`);
231
- if (capability.type !== "agent" && capability.type !== "agent-plugin")
232
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' type must be agent or agent-plugin`);
233
- for (const [field, message] of Object.entries(REMOVED_CAPABILITY_FIELDS))
234
- if (field in raw)
235
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}': ${message}`);
236
- const metadata = capability.metadata === undefined
237
- ? undefined
238
- : copyJsonObject(capability.metadata, "metadata");
239
- const mcpServers = normalizeMcpServers(capability.id, capability.mcpServers);
240
- const skills = normalizeSkills(capability.id, capability.skills);
241
- return Object.freeze({
242
- id: capability.id,
243
- type: capability.type,
244
- ...(typeof raw.name === "string" && raw.name ? { name: raw.name } : {}),
245
- ...(typeof raw.description === "string"
246
- ? { description: raw.description }
247
- : {}),
248
- ...(metadata === undefined ? {} : { metadata }),
249
- ...(capability.instructions
250
- ? { instructions: Object.freeze([...capability.instructions]) }
251
- : {}),
252
- ...(capability.tools
253
- ? { tools: Object.freeze(capability.tools.map(normalizeTool)) }
254
- : {}),
255
- ...(skills === undefined ? {} : { skills }),
256
- ...(mcpServers === undefined ? {} : { mcpServers }),
257
- ...(capability.sandbox === undefined
258
- ? {}
259
- : {
260
- sandbox: deepFreeze(copyJsonObject(capability.sandbox, "sandbox")),
261
- }),
262
- });
263
- }
264
- function normalizeSkills(capabilityId, skills) {
265
- if (skills === undefined)
266
- return undefined;
267
- if (!skills ||
268
- typeof skills !== "object" ||
269
- Array.isArray(skills) ||
270
- Object.keys(skills).length === 0)
271
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills must be a non-empty map or omitted`);
272
- const normalized = {};
273
- for (const [key, skill] of Object.entries(skills)) {
274
- if (!skill ||
275
- typeof skill !== "object" ||
276
- skill.name !== key ||
277
- typeof skill.description !== "string" ||
278
- skill.description.length === 0)
279
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills key '${key}' must equal the skill name`);
280
- const issue = skillFilesIssue(skill.files);
281
- if (issue)
282
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skill '${key}' ${issue}`);
283
- normalized[key] = Object.freeze({
284
- name: skill.name,
285
- description: skill.description,
286
- files: Object.freeze({ ...skill.files }),
287
- });
288
- }
289
- return Object.freeze(normalized);
290
- }
291
- function normalizeMcpServers(capabilityId, servers) {
292
- if (servers === undefined)
293
- return undefined;
294
- if (!servers ||
295
- typeof servers !== "object" ||
296
- Array.isArray(servers) ||
297
- Object.keys(servers).length === 0)
298
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers must be a non-empty map or omitted`);
299
- const normalized = {};
300
- for (const [key, server] of Object.entries(servers)) {
301
- if (server.type === "stdio")
302
- throw new HarnessError("agent.build-failed", stdioMcpRefusal(key));
303
- if (!isMcpServer(server) || server.name !== key)
304
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers key '${key}' must equal the server name`);
305
- normalized[key] = server;
306
- }
307
- return Object.freeze(normalized);
308
- }
309
- function isMcpServer(value) {
310
- if (!value || typeof value !== "object" || Array.isArray(value))
311
- return false;
312
- const server = value;
313
- if (typeof server.name !== "string" || !server.name)
314
- return false;
315
- if (server.type === "streamable-http" || server.type === "sse")
316
- return typeof server.url === "string" && server.url.length > 0;
317
- return false;
318
- }
319
- function normalizeTool(tool) {
320
- return Object.freeze({
321
- name: tool.name,
322
- ...(tool.description === undefined
323
- ? {}
324
- : { description: tool.description }),
325
- inputSchema: tool.inputSchema,
326
- ...(tool.outputSchema === undefined
327
- ? {}
328
- : { outputSchema: tool.outputSchema }),
329
- ...(tool.agent === undefined
330
- ? {}
331
- : {
332
- agent: "kind" in tool.agent
333
- ? deepFreeze(JSON.parse(JSON.stringify(tool.agent)))
334
- : normalizeManifest(tool.agent),
335
- }),
336
- ...(tool.http === undefined ? {} : { http: Object.freeze({ ...tool.http }) }),
337
- ...(tool.approval === undefined ? {} : { approval: tool.approval }),
338
- });
157
+ const parsed = AgentManifestSchema.safeParse(json);
158
+ if (!parsed.success)
159
+ throw new HarnessError("agent.build-failed", parsed.error.issues
160
+ .map((issue) => issue.path.length === 0
161
+ ? issue.message
162
+ : `${issue.path.join(".")}: ${issue.message}`)
163
+ .join("; "));
164
+ // The schema checks no value of a JSON object; metadata must be JSON data, as before.
165
+ const manifest = parsed.data;
166
+ for (const metadata of [
167
+ manifest.metadata,
168
+ ...manifest.capabilities.map((capability) => capability.metadata),
169
+ ])
170
+ if (metadata !== undefined)
171
+ assertJson(metadata, "metadata");
172
+ return deepFreeze(JSON.parse(JSON.stringify(manifest)));
339
173
  }
@@ -1,9 +1,11 @@
1
1
  /**
2
- * Manifest fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
2
+ * Capability fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
3
3
  * manifest v3 for flow agents) is the first where the Runtime never calls the developer's code
4
- * during a session (see MIGRATION.md).
4
+ * during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
5
5
  */
6
6
  export declare const REMOVED_CAPABILITY_FIELDS: Readonly<Record<string, string>>;
7
+ /** Manifest fields an older SDK wrote, and why each is refused. */
8
+ export declare const REMOVED_MANIFEST_FIELDS: Readonly<Record<string, string>>;
7
9
  /**
8
10
  * Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
9
11
  * version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
@@ -1,12 +1,18 @@
1
1
  /**
2
- * Manifest fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
2
+ * Capability fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
3
3
  * manifest v3 for flow agents) is the first where the Runtime never calls the developer's code
4
- * during a session (see MIGRATION.md).
4
+ * during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
5
5
  */
6
6
  export const REMOVED_CAPABILITY_FIELDS = Object.freeze({
7
7
  hooks: "hooks were removed: the Runtime no longer calls your code during a session. Use an HTTP tool, approval on a tool, or a loop verifier instead (see MIGRATION.md)",
8
8
  beforeModelCall: "beforeModelCall was removed with hooks (see MIGRATION.md)",
9
9
  afterModelCall: "afterModelCall was removed with hooks (see MIGRATION.md)",
10
+ model: "A capability must not include model; the Runtime owns model resolution",
11
+ });
12
+ /** Manifest fields an older SDK wrote, and why each is refused. */
13
+ export const REMOVED_MANIFEST_FIELDS = Object.freeze({
14
+ schemaVersion: "Manifest field schemaVersion was renamed to manifestSchemaVersion",
15
+ model: "Manifest must not include top-level model; Runtime owns model resolution",
10
16
  });
11
17
  /**
12
18
  * Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
@@ -3,17 +3,17 @@
3
3
  * between core and a harness. A run is a lease on one session's segment; core records, the
4
4
  * harness runs the engine. Who executes what: the harness runs model, MCP, HTTP and sandbox
5
5
  * calls; core runs flow work, linked sessions, delegation journaling, `save_artifact`, the
6
- * skill tools, settle and takeover.
6
+ * skill tools, settle and takeover. Each message's type is inferred from its schema
7
+ * (`schema.ts`), which a socket validates it with.
7
8
  */
8
- import type { EffectOutcome } from "../contracts.js";
9
- import type { AgentRef } from "../types/tool.js";
10
- import type { TranscriptUpdate } from "./transcript.js";
9
+ import type { z } from "zod";
10
+ import type { EffectIntentSchema, IntentAnswerSchema, OutcomeAnswerSchema, RecordedOutcomeSchema, ReleaseReasonSchema, RequestTypes, RunGrantSchema, RunRoutingSchema, TurnOutputSchema, TurnStartSchema, WorkspaceBytesCallSchema, WorkspaceCallSchema, WorkspaceListCallSchema, WorkspaceRecordSchema, WorkspaceSessionSchema, coreMessages, coreRequests, harnessRequests } from "./schema.js";
11
11
  export declare const HARNESS_API_VERSION = 2;
12
12
  /** Why core stopped a run. Matches the advance's abort kinds. */
13
- export type AbortReason = "cancel" | "shutdown" | "deadline" | "ownership.lost";
14
- export declare const ABORT_REASONS: readonly AbortReason[];
13
+ export declare const ABORT_REASONS: readonly ["cancel", "shutdown", "deadline", "ownership.lost"];
14
+ export type AbortReason = (typeof ABORT_REASONS)[number];
15
15
  /** Why a harness gave a run back without an output. */
16
- export type ReleaseReason = "shutdown" | "ownership.lost" | "connection.lost";
16
+ export type ReleaseReason = z.infer<typeof ReleaseReasonSchema>;
17
17
  /**
18
18
  * Events a harness may claim: for a run it holds, or for a workspace request core sent it. A
19
19
  * `sandbox.state` claim carries the workspace's compute record, which core keeps.
@@ -23,365 +23,43 @@ export type HarnessClaim = (typeof HARNESS_CLAIMS)[number];
23
23
  export declare const HARNESS_ERROR_CODES: readonly ["run_not_held", "turn_cancelled", "ownership_lost", "effect_drift", "invalid", "unavailable", "internal"];
24
24
  export type HarnessErrorCode = (typeof HARNESS_ERROR_CODES)[number];
25
25
  /** One effect the engine asks for: a `HostEffect`, by structure. Model intents carry no `input`. */
26
- export interface EffectIntent {
27
- readonly effectId: string;
28
- readonly sessionId: string;
29
- readonly turnId: string;
30
- readonly agentId: string;
31
- readonly manifestHash: string;
32
- readonly kind: "model" | "tool" | "delegation" | "agent";
33
- readonly agent?: AgentRef;
34
- readonly capabilityId?: string;
35
- readonly toolName?: string;
36
- readonly path?: string;
37
- readonly key?: string;
38
- readonly iterations?: string;
39
- readonly input?: unknown;
40
- readonly context: Record<string, unknown>;
41
- }
26
+ export type EffectIntent = z.infer<typeof EffectIntentSchema>;
42
27
  /** A completed outcome of the segment, with the hash of the request it answered. */
43
- export interface RecordedOutcome {
44
- readonly effectId: string;
45
- readonly requestHash: string;
46
- readonly outcome: EffectOutcome;
47
- }
28
+ export type RecordedOutcome = z.infer<typeof RecordedOutcomeSchema>;
48
29
  /** The lease on one run. `token` is the run token (F5) when the gates require one. */
49
- export interface RunGrant {
50
- readonly runId: string;
51
- readonly sessionId: string;
52
- readonly turnId: string;
53
- readonly epoch: number;
54
- readonly token?: string;
55
- readonly tokenExpiresAt?: string;
56
- }
30
+ export type RunGrant = z.infer<typeof RunGrantSchema>;
57
31
  /** Where a harness sends the session's tool calls. */
58
- export interface RunRouting {
59
- /** The session's pinned manifest: an effect's agent resolves against it. */
60
- readonly rootManifest: unknown;
61
- readonly mcpSnapshot?: unknown;
62
- /** The session that owns the tree's sandbox, and the sandbox resource it is attached to. */
63
- readonly sandbox?: {
64
- readonly ownerId: string;
65
- readonly sandboxId?: string;
66
- readonly spec?: unknown;
67
- };
68
- }
32
+ export type RunRouting = z.infer<typeof RunRoutingSchema>;
69
33
  /** What a run starts from: `turn.start` (message, continue, resume) or `approval.answer`. */
70
- export interface TurnStart {
71
- readonly type: "turn.start" | "approval.answer";
72
- readonly engine: "agent" | "flow";
73
- /** The turn's manifest (agent) or the workflow manifest (flow). */
74
- readonly manifest: unknown;
75
- /** The segment's checkpoint; an agent's state has no transcript (`transcript.cursor`). */
76
- readonly checkpoint: unknown;
77
- readonly sessionTools?: readonly unknown[];
78
- /** Completed outcomes of this segment, resolved without asking core. */
79
- readonly outcomes: readonly RecordedOutcome[];
80
- /** The record position the session's transcript was folded at. */
81
- readonly transcript: {
82
- readonly cursor: number;
83
- };
84
- readonly options: {
85
- readonly yieldAfter?: {
86
- readonly steps?: number;
87
- readonly ms?: number;
88
- };
89
- readonly flowLimits?: unknown;
90
- readonly fixtureModel: boolean;
91
- };
92
- readonly routing: RunRouting;
93
- }
94
- /** How a segment ended, as the harness reports it. */
95
- export type TurnStatus = "completed" | "paused" | "yielded" | "waiting" | "uncertain" | "failed" | "cancelled";
34
+ export type TurnStart = z.infer<typeof TurnStartSchema>;
96
35
  /**
97
36
  * A segment's end. `state` is the agent's engine state without its transcript; `transcript`
98
37
  * edits the transcript the segment started from. `thrown` reports an engine that threw.
99
38
  */
100
- export interface TurnOutput {
101
- readonly runId: string;
102
- readonly status?: TurnStatus;
103
- readonly state?: unknown;
104
- readonly output?: unknown;
105
- readonly pending?: unknown;
106
- readonly error?: unknown;
107
- readonly effectIds?: readonly string[];
108
- readonly cancelEffectIds?: readonly string[];
109
- readonly transcript?: readonly TranscriptUpdate[];
110
- readonly thrown?: {
111
- readonly code?: string;
112
- readonly message: string;
113
- };
114
- }
39
+ export type TurnOutput = z.infer<typeof TurnOutputSchema>;
40
+ /** How a segment ended, as the harness reports it. */
41
+ export type TurnStatus = NonNullable<TurnOutput["status"]>;
115
42
  export type OutputMethod = "turn.completed" | "turn.paused" | "turn.waiting" | "turn.failed" | "checkpoint";
116
- export type IntentAnswer = {
117
- readonly status: "completed";
118
- readonly outcome: EffectOutcome;
119
- } | {
120
- readonly status: "pending" | "uncertain";
121
- } | {
122
- readonly status: "execute";
123
- readonly rejoin?: true;
124
- };
125
- export type OutcomeAnswer = {
126
- readonly status: "completed";
127
- readonly outcome: EffectOutcome;
128
- } | {
129
- readonly status: "uncertain";
130
- };
43
+ export type IntentAnswer = z.infer<typeof IntentAnswerSchema>;
44
+ export type OutcomeAnswer = z.infer<typeof OutcomeAnswerSchema>;
131
45
  /** Requests a harness sends to core, with their answers. */
132
- export interface HarnessRequests {
133
- /**
134
- * `capabilities.workspace` declares that the harness serves the Tenant's workspaces (F6.2):
135
- * core then sends it the `workspace.*` requests. The answer names the Tenant (its workspace
136
- * keys are scoped by it) and the sandbox backend preference the harness selects with.
137
- */
138
- hello: {
139
- params: {
140
- api: number;
141
- name: string;
142
- version: string;
143
- capabilities: {
144
- workspace?: unknown;
145
- };
146
- };
147
- result: {
148
- api: number;
149
- tenantId: string;
150
- sandbox: {
151
- backend: string | null;
152
- };
153
- renewEveryMs: number;
154
- };
155
- };
156
- lease: {
157
- params: {
158
- slots?: number;
159
- };
160
- result: {
161
- run: RunGrant;
162
- input: TurnStart;
163
- };
164
- };
165
- "lease.renew": {
166
- params: {
167
- runId: string;
168
- };
169
- result: {
170
- ok: true;
171
- token?: string;
172
- tokenExpiresAt?: string;
173
- } | {
174
- ok: false;
175
- };
176
- };
177
- "lease.release": {
178
- params: {
179
- runId: string;
180
- reason: ReleaseReason;
181
- };
182
- result: Record<string, never>;
183
- };
184
- "effect.intent": {
185
- params: {
186
- runId: string;
187
- effect: EffectIntent;
188
- requestHash: string;
189
- };
190
- result: IntentAnswer;
191
- };
192
- "effect.outcome": {
193
- params: {
194
- runId: string;
195
- effectId: string;
196
- value: unknown;
197
- } | {
198
- runId: string;
199
- effectId: string;
200
- error: string;
201
- };
202
- result: OutcomeAnswer;
203
- };
204
- "transcript.read": {
205
- params: {
206
- runId: string;
207
- };
208
- result: {
209
- cursor: number;
210
- entries: unknown[];
211
- };
212
- };
213
- event: {
214
- params: {
215
- runId?: string;
216
- sessionId: string;
217
- turnId: string | null;
218
- type: HarnessClaim;
219
- payload: unknown;
220
- /** With `sandbox.state`: the workspace's compute record as it is now. */
221
- record?: WorkspaceRecord;
222
- };
223
- result: Record<string, never>;
224
- };
225
- "session.mcp": {
226
- params: {
227
- runId: string;
228
- snapshot?: unknown;
229
- diagnostics: unknown[];
230
- };
231
- result: {
232
- snapshot: unknown;
233
- sessionTools: unknown[];
234
- };
235
- };
236
- /**
237
- * A definition file's bytes, base64 (track R2 M4): one the run's definition names, for the
238
- * skills its sandbox mounts.
239
- */
240
- "definition.file": {
241
- params: {
242
- runId: string;
243
- sha256: string;
244
- };
245
- result: {
246
- base64: string;
247
- };
248
- };
249
- "turn.completed": {
250
- params: TurnOutput;
251
- result: {
252
- cursor?: number;
253
- };
254
- };
255
- "turn.paused": {
256
- params: TurnOutput;
257
- result: {
258
- cursor?: number;
259
- };
260
- };
261
- "turn.waiting": {
262
- params: TurnOutput;
263
- result: {
264
- cursor?: number;
265
- };
266
- };
267
- "turn.failed": {
268
- params: TurnOutput;
269
- result: {
270
- cursor?: number;
271
- };
272
- };
273
- /** A yielded segment's state: ends the run, the turn goes on in the next. */
274
- checkpoint: {
275
- params: TurnOutput;
276
- result: {
277
- cursor?: number;
278
- };
279
- };
280
- }
46
+ export type HarnessRequests = RequestTypes<typeof harnessRequests>;
281
47
  /** The session a workspace request acts for: the workspace's owner and its sandbox resource. */
282
- export interface WorkspaceSession {
283
- /** The session that owns the workspace: its log records the workspace's events. */
284
- readonly ownerId: string;
285
- readonly sandboxId?: string;
286
- readonly activeTurnId: string | null;
287
- }
48
+ export type WorkspaceSession = z.infer<typeof WorkspaceSessionSchema>;
288
49
  /** A workspace's compute record, as the harness keeps it. */
289
- export interface WorkspaceRecord {
290
- readonly key: string;
291
- readonly sessionId: string;
292
- readonly sandboxId?: string;
293
- readonly backend: string;
294
- readonly image: string;
295
- readonly state: "creating" | "running" | "stopped";
296
- readonly createdAt: string;
297
- readonly updatedAt: string;
298
- }
50
+ export type WorkspaceRecord = z.infer<typeof WorkspaceRecordSchema>;
299
51
  /** A sandbox tool call core sends to the harness that serves workspaces. */
300
- export interface WorkspaceCall {
301
- readonly session: WorkspaceSession;
302
- /** The sandbox spec the workspace runs (`SandboxManifest`). */
303
- readonly spec: unknown;
304
- readonly tool: string;
305
- readonly input: unknown;
306
- }
307
- /**
308
- * A file of a workspace read as bytes (`save_artifact`, F8.1), at most `maxBytes`. The answer is
309
- * `{kind: "read", path, base64}`, `{kind: "missing", path}` or a failed tool outcome.
310
- */
311
- export interface WorkspaceBytesCall {
312
- readonly session: WorkspaceSession;
313
- readonly spec: unknown;
314
- readonly bytes: {
315
- readonly path: string;
316
- readonly maxBytes: number;
317
- };
318
- }
319
- /**
320
- * The regular files under a directory of a workspace, recursively, at most `maxEntries + 1`
321
- * (the turn-end export, F8.2). The answer is `{kind: "listed", path, listing: {entries,
322
- * truncated}}`, `{kind: "missing", path}` (no sandbox yet, or not a directory) or a failed tool
323
- * outcome.
324
- */
325
- export interface WorkspaceListCall {
326
- readonly session: WorkspaceSession;
327
- readonly spec: unknown;
328
- readonly list: {
329
- readonly dir: string;
330
- readonly maxEntries: number;
331
- };
332
- }
333
- /**
334
- * Requests core sends to a harness that declared `workspace` (F6.2), with their answers. A
335
- * sandbox tool's answer is its `SandboxToolOutcome`; the harness claims its `sandbox.*` events
336
- * while the request is in flight. `workspace.read` stays generic: F8.2 exports outputs
337
- * through it.
338
- */
339
- export interface CoreRequests {
340
- "workspace.read": {
341
- params: WorkspaceCall | WorkspaceBytesCall | WorkspaceListCall;
342
- result: Record<string, unknown>;
343
- };
344
- "workspace.write": {
345
- params: WorkspaceCall;
346
- result: Record<string, unknown>;
347
- };
348
- "workspace.exec": {
349
- params: WorkspaceCall;
350
- result: Record<string, unknown>;
351
- };
352
- /** The harness's sandbox selection report (`GET /v1/tenant/sandbox`, Tenant status). */
353
- "workspace.report": {
354
- params: Record<string, never>;
355
- result: Record<string, unknown>;
356
- };
357
- /** Stops idle workspaces, then lists every workspace the harness keeps. */
358
- "workspace.sweep": {
359
- params: {
360
- now?: number;
361
- };
362
- result: {
363
- workspaces: WorkspaceRecord[];
364
- };
365
- };
366
- /** Deletes workspaces with their files: by key, by sandbox resource, or all of them. */
367
- "workspace.remove": {
368
- params: {
369
- keys?: string[];
370
- sandboxIds?: string[];
371
- all?: true;
372
- };
373
- result: Record<string, never>;
374
- };
375
- }
52
+ export type WorkspaceCall = z.infer<typeof WorkspaceCallSchema>;
53
+ /** A file of a workspace read as bytes (`save_artifact`, F8.1), at most `maxBytes`. */
54
+ export type WorkspaceBytesCall = z.infer<typeof WorkspaceBytesCallSchema>;
55
+ /** The regular files under a directory of a workspace (the turn-end export, F8.2). */
56
+ export type WorkspaceListCall = z.infer<typeof WorkspaceListCallSchema>;
57
+ /** Requests core sends to a harness that declared `workspace` (F6.2), with their answers. */
58
+ export type CoreRequests = RequestTypes<typeof coreRequests>;
376
59
  /** Messages core sends to a harness, without an answer. */
377
- export interface CoreMessages {
378
- /** `message` is core's abort message, which the run's executors see as theirs. */
379
- cancel: {
380
- runId: string;
381
- reason: AbortReason;
382
- message?: string;
383
- };
384
- }
60
+ export type CoreMessages = {
61
+ [M in keyof typeof coreMessages]: z.infer<(typeof coreMessages)[M]>;
62
+ };
385
63
  export type HarnessMethod = keyof HarnessRequests;
386
64
  export type CoreMethod = keyof CoreRequests;
387
65
  export type CoreMessage = keyof CoreMessages;