@nylorun/core 0.11.0-beta → 0.13.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 +92 -0
- package/dist/compatibility.d.ts +71 -34
- package/dist/compatibility.js +76 -46
- package/dist/contracts.d.ts +1078 -215
- package/dist/contracts.js +742 -181
- package/dist/define.d.ts +1 -1
- package/dist/define.js +1 -1
- package/dist/definition/sandbox-capability.d.ts +13 -0
- package/dist/definition/sandbox-capability.js +59 -0
- package/dist/harness-api/errors.d.ts +7 -0
- package/dist/harness-api/errors.js +9 -0
- package/dist/harness-api/hash.d.ts +12 -0
- package/dist/harness-api/hash.js +34 -0
- package/dist/harness-api/index.d.ts +10 -0
- package/dist/harness-api/index.js +10 -0
- package/dist/harness-api/messages.d.ts +394 -0
- package/dist/harness-api/messages.js +21 -0
- package/dist/harness-api/rpc.d.ts +78 -0
- package/dist/harness-api/rpc.js +240 -0
- package/dist/harness-api/schema.d.ts +155 -0
- package/dist/harness-api/schema.js +271 -0
- package/dist/harness-api/transcript.d.ts +29 -0
- package/dist/harness-api/transcript.js +74 -0
- package/package.json +6 -2
package/dist/define.d.ts
CHANGED
|
@@ -6,7 +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 { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
|
|
9
|
+
export { ARTIFACTS_CAPABILITY_ID, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
|
|
10
10
|
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
11
11
|
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
12
12
|
export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
|
package/dist/define.js
CHANGED
|
@@ -2,7 +2,7 @@ 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 { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
|
|
5
|
+
export { ARTIFACTS_CAPABILITY_ID, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, 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";
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { CapabilityManifest, SandboxManifest } from "../types/manifest.js";
|
|
2
2
|
/** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
|
|
3
3
|
export declare const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
|
|
4
|
+
/**
|
|
5
|
+
* Id of the capability that gives our engine `save_artifact` (protocol 6): the Runtime adds it
|
|
6
|
+
* beside the sandbox capability, so `nylorun.artifacts/save_artifact` is the built-in tool
|
|
7
|
+
* `nylorun.save_artifact`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ARTIFACTS_CAPABILITY_ID = "nylorun.artifacts";
|
|
10
|
+
export declare const SAVE_ARTIFACT_TOOL = "save_artifact";
|
|
11
|
+
/**
|
|
12
|
+
* The capability manifest that gives a session `save_artifact`: one tool that stores a sandbox
|
|
13
|
+
* file, or inline text, as a file artifact of the session. Its schema is part of the hashed
|
|
14
|
+
* manifest; change it deliberately.
|
|
15
|
+
*/
|
|
16
|
+
export declare function artifactsCapabilityManifest(): CapabilityManifest;
|
|
4
17
|
/**
|
|
5
18
|
* The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
|
|
6
19
|
* instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
|
|
@@ -1,9 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { SANDBOX_INSTRUCTIONS, createSandboxTools } from "./sandbox-tools.js";
|
|
3
|
+
import { tool } from "./helpers.js";
|
|
4
|
+
import { ToolError } from "./tool-error.js";
|
|
2
5
|
import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
3
6
|
import { normalizedSchemasFor } from "./schema.js";
|
|
4
7
|
import { copyJsonObject } from "../utils/immutable.js";
|
|
5
8
|
/** Id of the capability the Runtime adds to a session whose sandbox was chosen at open. */
|
|
6
9
|
export const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
|
|
10
|
+
/**
|
|
11
|
+
* Id of the capability that gives our engine `save_artifact` (protocol 6): the Runtime adds it
|
|
12
|
+
* beside the sandbox capability, so `nylorun.artifacts/save_artifact` is the built-in tool
|
|
13
|
+
* `nylorun.save_artifact`.
|
|
14
|
+
*/
|
|
15
|
+
export const ARTIFACTS_CAPABILITY_ID = "nylorun.artifacts";
|
|
16
|
+
export const SAVE_ARTIFACT_TOOL = "save_artifact";
|
|
17
|
+
const ARTIFACTS_INSTRUCTIONS = "Use save_artifact to hand the user a file you made: a path in the sandbox, or text you pass as content. " +
|
|
18
|
+
"The user sees it as an artifact of this session and can download it; reply with its name, not its bytes. " +
|
|
19
|
+
"Files you write under /workspace/outputs reach the user too: when your turn ends, they become the session's outputs folder.";
|
|
20
|
+
async function artifactsRuntimeOnly() {
|
|
21
|
+
throw new ToolError("artifacts.runtime-only", "save_artifact runs in the Nylorun Runtime. Connect the agent to a Runtime to use it.");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The capability manifest that gives a session `save_artifact`: one tool that stores a sandbox
|
|
25
|
+
* file, or inline text, as a file artifact of the session. Its schema is part of the hashed
|
|
26
|
+
* manifest; change it deliberately.
|
|
27
|
+
*/
|
|
28
|
+
export function artifactsCapabilityManifest() {
|
|
29
|
+
const saveArtifact = tool({
|
|
30
|
+
name: SAVE_ARTIFACT_TOOL,
|
|
31
|
+
description: `Save a file as an artifact of this session, for the user to download. Give path (a file in the sandbox; relative paths resolve under ${SANDBOX_WORKSPACE}) or content (text), not both. ` +
|
|
32
|
+
"Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.",
|
|
33
|
+
inputSchema: z.object({
|
|
34
|
+
path: z.string().min(1).optional().describe("A file in the sandbox."),
|
|
35
|
+
content: z.string().optional().describe("Text to save instead of a file."),
|
|
36
|
+
name: z
|
|
37
|
+
.string()
|
|
38
|
+
.min(1)
|
|
39
|
+
.max(255)
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("The artifact's name. Default: the file's name."),
|
|
42
|
+
contentType: z
|
|
43
|
+
.string()
|
|
44
|
+
.min(1)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("The media type, e.g. image/png. Default: from the name's extension."),
|
|
47
|
+
artifactId: z.string().min(1).optional().describe("Save a new version of this artifact."),
|
|
48
|
+
}),
|
|
49
|
+
effects: "write",
|
|
50
|
+
execute: artifactsRuntimeOnly,
|
|
51
|
+
});
|
|
52
|
+
const schemas = normalizedSchemasFor(saveArtifact);
|
|
53
|
+
return {
|
|
54
|
+
id: ARTIFACTS_CAPABILITY_ID,
|
|
55
|
+
type: "agent",
|
|
56
|
+
instructions: [ARTIFACTS_INSTRUCTIONS],
|
|
57
|
+
tools: [
|
|
58
|
+
{
|
|
59
|
+
name: saveArtifact.name,
|
|
60
|
+
...(saveArtifact.description === undefined ? {} : { description: saveArtifact.description }),
|
|
61
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
7
66
|
/**
|
|
8
67
|
* The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
|
|
9
68
|
* instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HarnessErrorCode } from "./messages.js";
|
|
2
|
+
/** An error a request answers with; the code crosses the wire, the message too. */
|
|
3
|
+
export declare class HarnessApiError extends Error {
|
|
4
|
+
readonly code: HarnessErrorCode;
|
|
5
|
+
readonly name = "HarnessApiError";
|
|
6
|
+
constructor(code: HarnessErrorCode, message: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EffectIntent } from "./messages.js";
|
|
2
|
+
/**
|
|
3
|
+
* What an effect's journal row must match on replay. A delegation's context carries only the
|
|
4
|
+
* parent's tool call id, for its events; rows journaled before it existed still match.
|
|
5
|
+
*/
|
|
6
|
+
export declare function requestIdentity<T extends Pick<EffectIntent, "kind" | "context">>(request: T): Omit<T, "context"> | T;
|
|
7
|
+
/**
|
|
8
|
+
* The SHA-256 of an effect's identity, canonical JSON (keys sorted by code unit, `undefined`
|
|
9
|
+
* members dropped). Hashed with the model call's prompt, so a replay that would send another
|
|
10
|
+
* prompt under the same effect id is drift, though the prompt itself is never sent twice.
|
|
11
|
+
*/
|
|
12
|
+
export declare function effectRequestHash(request: Pick<EffectIntent, "kind" | "context">): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* What an effect's journal row must match on replay. A delegation's context carries only the
|
|
5
|
+
* parent's tool call id, for its events; rows journaled before it existed still match.
|
|
6
|
+
*/
|
|
7
|
+
export function requestIdentity(request) {
|
|
8
|
+
if (request.kind !== "delegation")
|
|
9
|
+
return request;
|
|
10
|
+
const { context: _, ...identity } = request;
|
|
11
|
+
return identity;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The SHA-256 of an effect's identity, canonical JSON (keys sorted by code unit, `undefined`
|
|
15
|
+
* members dropped). Hashed with the model call's prompt, so a replay that would send another
|
|
16
|
+
* prompt under the same effect id is drift, though the prompt itself is never sent twice.
|
|
17
|
+
*/
|
|
18
|
+
export function effectRequestHash(request) {
|
|
19
|
+
return bytesToHex(sha256(utf8ToBytes(canonicalJson(requestIdentity(request)))));
|
|
20
|
+
}
|
|
21
|
+
function canonicalJson(value) {
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return `[${value.map((item) => canonicalJson(item ?? null)).join(",")}]`;
|
|
24
|
+
if (value && typeof value === "object") {
|
|
25
|
+
const members = [];
|
|
26
|
+
for (const key of Object.keys(value).sort()) {
|
|
27
|
+
const item = value[key];
|
|
28
|
+
if (item !== undefined)
|
|
29
|
+
members.push(`${JSON.stringify(key)}:${canonicalJson(item)}`);
|
|
30
|
+
}
|
|
31
|
+
return `{${members.join(",")}}`;
|
|
32
|
+
}
|
|
33
|
+
return JSON.stringify(value) ?? "null";
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nylorun/core/harness-api`: the protocol between core and a harness (Harness API v1). Types,
|
|
3
|
+
* schemas, the effect request hash, transcript edits and the RPC channel; no engine and no I/O.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./messages.js";
|
|
6
|
+
export { HarnessApiError } from "./errors.js";
|
|
7
|
+
export { effectRequestHash, requestIdentity } from "./hash.js";
|
|
8
|
+
export { CHUNK_BYTES, TranscriptFoldError, applyUpdate, applyUpdates, transcriptOf, transcriptUpdates, withTranscript, type TranscriptUpdate, } from "./transcript.js";
|
|
9
|
+
export { createChannel, memoryChannels, memoryPorts, type Frame, type HarnessChannel, type MemoryPortsOptions, type MessageListener, type Port, type RequestHandler, } from "./rpc.js";
|
|
10
|
+
export { EffectIntentSchema, FrameSchema, TurnOutputSchema, TurnStartSchema, validateFrame, validateMessage, validateParams, validateResult, } from "./schema.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@nylorun/core/harness-api`: the protocol between core and a harness (Harness API v1). Types,
|
|
3
|
+
* schemas, the effect request hash, transcript edits and the RPC channel; no engine and no I/O.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./messages.js";
|
|
6
|
+
export { HarnessApiError } from "./errors.js";
|
|
7
|
+
export { effectRequestHash, requestIdentity } from "./hash.js";
|
|
8
|
+
export { CHUNK_BYTES, TranscriptFoldError, applyUpdate, applyUpdates, transcriptOf, transcriptUpdates, withTranscript, } from "./transcript.js";
|
|
9
|
+
export { createChannel, memoryChannels, memoryPorts, } from "./rpc.js";
|
|
10
|
+
export { EffectIntentSchema, FrameSchema, TurnOutputSchema, TurnStartSchema, validateFrame, validateMessage, validateParams, validateResult, } from "./schema.js";
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness API v1 (blueprint D37–D42): the messages between core and a harness. A run is a
|
|
3
|
+
* lease on one session's segment; core records, the harness runs the engine. Who executes what:
|
|
4
|
+
* the harness runs model, MCP and sandbox calls; core runs Actions, hooks, flow work, linked
|
|
5
|
+
* sessions, delegation journaling, settle and takeover.
|
|
6
|
+
*/
|
|
7
|
+
import type { ActionOutcome } from "../contracts.js";
|
|
8
|
+
import type { AgentRef } from "../types/tool.js";
|
|
9
|
+
import type { TranscriptUpdate } from "./transcript.js";
|
|
10
|
+
export declare const HARNESS_API_VERSION = 1;
|
|
11
|
+
/** Why core stopped a run. Matches the advance's abort kinds. */
|
|
12
|
+
export type AbortReason = "cancel" | "shutdown" | "deadline" | "ownership.lost";
|
|
13
|
+
export declare const ABORT_REASONS: readonly AbortReason[];
|
|
14
|
+
/** Why a harness gave a run back without an output. */
|
|
15
|
+
export type ReleaseReason = "shutdown" | "ownership.lost" | "connection.lost";
|
|
16
|
+
/**
|
|
17
|
+
* Events a harness may claim: for a run it holds, or for a workspace request core sent it. A
|
|
18
|
+
* `sandbox.state` claim carries the workspace's compute record, which core keeps.
|
|
19
|
+
*/
|
|
20
|
+
export declare const HARNESS_CLAIMS: readonly ["sandbox.state", "sandbox.exec"];
|
|
21
|
+
export type HarnessClaim = (typeof HARNESS_CLAIMS)[number];
|
|
22
|
+
export declare const HARNESS_ERROR_CODES: readonly ["run_not_held", "turn_cancelled", "ownership_lost", "effect_drift", "invalid", "unavailable", "internal"];
|
|
23
|
+
export type HarnessErrorCode = (typeof HARNESS_ERROR_CODES)[number];
|
|
24
|
+
/** One effect the engine asks for: a `HostEffect`, by structure. Model intents carry no `input`. */
|
|
25
|
+
export interface EffectIntent {
|
|
26
|
+
readonly effectId: string;
|
|
27
|
+
readonly sessionId: string;
|
|
28
|
+
readonly turnId: string;
|
|
29
|
+
readonly agentId: string;
|
|
30
|
+
readonly manifestHash: string;
|
|
31
|
+
readonly kind: "model" | "tool" | "hook" | "delegation" | "agent" | "fn" | "verify";
|
|
32
|
+
readonly agent?: AgentRef;
|
|
33
|
+
readonly capabilityId?: string;
|
|
34
|
+
readonly toolName?: string;
|
|
35
|
+
readonly hook?: {
|
|
36
|
+
readonly at: "before" | "after";
|
|
37
|
+
readonly scope: "turn" | "step";
|
|
38
|
+
readonly capabilityIds: readonly string[];
|
|
39
|
+
};
|
|
40
|
+
readonly path?: string;
|
|
41
|
+
readonly key?: string;
|
|
42
|
+
readonly iterations?: string;
|
|
43
|
+
readonly input?: unknown;
|
|
44
|
+
readonly context: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/** A completed outcome of the segment, with the hash of the request it answered. */
|
|
47
|
+
export interface RecordedOutcome {
|
|
48
|
+
readonly effectId: string;
|
|
49
|
+
readonly requestHash: string;
|
|
50
|
+
readonly outcome: ActionOutcome;
|
|
51
|
+
}
|
|
52
|
+
/** The lease on one run. `token` is the run token (F5) when the gates require one. */
|
|
53
|
+
export interface RunGrant {
|
|
54
|
+
readonly runId: string;
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
readonly turnId: string;
|
|
57
|
+
readonly epoch: number;
|
|
58
|
+
readonly token?: string;
|
|
59
|
+
readonly tokenExpiresAt?: string;
|
|
60
|
+
}
|
|
61
|
+
/** Where a harness sends the session's tool calls. */
|
|
62
|
+
export interface RunRouting {
|
|
63
|
+
/** The session's pinned manifest: an effect's agent resolves against it. */
|
|
64
|
+
readonly rootManifest: unknown;
|
|
65
|
+
readonly pluginRoots: Readonly<Record<string, string>>;
|
|
66
|
+
readonly mcpSnapshot?: unknown;
|
|
67
|
+
/** The session that owns the tree's sandbox, and the sandbox resource it is attached to. */
|
|
68
|
+
readonly sandbox?: {
|
|
69
|
+
readonly ownerId: string;
|
|
70
|
+
readonly sandboxId?: string;
|
|
71
|
+
readonly spec?: unknown;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** What a run starts from: `turn.start` (message, continue, resume) or `approval.answer`. */
|
|
75
|
+
export interface TurnStart {
|
|
76
|
+
readonly type: "turn.start" | "approval.answer";
|
|
77
|
+
readonly engine: "agent" | "flow";
|
|
78
|
+
/** The turn's manifest (agent) or the workflow manifest (flow). */
|
|
79
|
+
readonly manifest: unknown;
|
|
80
|
+
/** The segment's checkpoint; an agent's state has no transcript (`transcript.cursor`). */
|
|
81
|
+
readonly checkpoint: unknown;
|
|
82
|
+
readonly sessionTools?: readonly unknown[];
|
|
83
|
+
/** Completed outcomes of this segment, resolved without asking core. */
|
|
84
|
+
readonly outcomes: readonly RecordedOutcome[];
|
|
85
|
+
/** The record position the session's transcript was folded at. */
|
|
86
|
+
readonly transcript: {
|
|
87
|
+
readonly cursor: number;
|
|
88
|
+
};
|
|
89
|
+
readonly options: {
|
|
90
|
+
readonly yieldAfter?: {
|
|
91
|
+
readonly steps?: number;
|
|
92
|
+
readonly ms?: number;
|
|
93
|
+
};
|
|
94
|
+
readonly flowLimits?: unknown;
|
|
95
|
+
readonly fixtureModel: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* How long the run may wait for a pending Action's outcome in its lease (F6.2,
|
|
98
|
+
* `effect.resolved`) before the segment ends as waiting. 0 or absent: it never waits.
|
|
99
|
+
*/
|
|
100
|
+
readonly holdMs?: number;
|
|
101
|
+
};
|
|
102
|
+
readonly routing: RunRouting;
|
|
103
|
+
}
|
|
104
|
+
/** How a segment ended, as the harness reports it. */
|
|
105
|
+
export type TurnStatus = "completed" | "paused" | "yielded" | "waiting" | "uncertain" | "failed" | "cancelled";
|
|
106
|
+
/**
|
|
107
|
+
* A segment's end. `state` is the agent's engine state without its transcript; `transcript`
|
|
108
|
+
* edits the transcript the segment started from. `thrown` reports an engine that threw.
|
|
109
|
+
*/
|
|
110
|
+
export interface TurnOutput {
|
|
111
|
+
readonly runId: string;
|
|
112
|
+
readonly status?: TurnStatus;
|
|
113
|
+
readonly state?: unknown;
|
|
114
|
+
readonly output?: unknown;
|
|
115
|
+
readonly pending?: unknown;
|
|
116
|
+
readonly error?: unknown;
|
|
117
|
+
readonly effectIds?: readonly string[];
|
|
118
|
+
readonly cancelEffectIds?: readonly string[];
|
|
119
|
+
readonly transcript?: readonly TranscriptUpdate[];
|
|
120
|
+
readonly thrown?: {
|
|
121
|
+
readonly code?: string;
|
|
122
|
+
readonly message: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export type OutputMethod = "turn.completed" | "turn.paused" | "turn.waiting" | "turn.failed" | "checkpoint";
|
|
126
|
+
export type IntentAnswer = {
|
|
127
|
+
readonly status: "completed";
|
|
128
|
+
readonly outcome: ActionOutcome;
|
|
129
|
+
} | {
|
|
130
|
+
readonly status: "pending" | "uncertain";
|
|
131
|
+
} | {
|
|
132
|
+
readonly status: "execute";
|
|
133
|
+
readonly rejoin?: true;
|
|
134
|
+
};
|
|
135
|
+
export type OutcomeAnswer = {
|
|
136
|
+
readonly status: "completed";
|
|
137
|
+
readonly outcome: ActionOutcome;
|
|
138
|
+
} | {
|
|
139
|
+
readonly status: "uncertain";
|
|
140
|
+
};
|
|
141
|
+
/** Requests a harness sends to core, with their answers. */
|
|
142
|
+
export interface HarnessRequests {
|
|
143
|
+
/**
|
|
144
|
+
* `capabilities.workspace` declares that the harness serves the Tenant's workspaces (F6.2):
|
|
145
|
+
* core then sends it the `workspace.*` requests. The answer names the Tenant (its workspace
|
|
146
|
+
* keys are scoped by it) and the sandbox backend preference the harness selects with.
|
|
147
|
+
*/
|
|
148
|
+
hello: {
|
|
149
|
+
params: {
|
|
150
|
+
api: number;
|
|
151
|
+
name: string;
|
|
152
|
+
version: string;
|
|
153
|
+
capabilities: {
|
|
154
|
+
workspace?: unknown;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
result: {
|
|
158
|
+
api: number;
|
|
159
|
+
tenantId: string;
|
|
160
|
+
sandbox: {
|
|
161
|
+
backend: string | null;
|
|
162
|
+
};
|
|
163
|
+
renewEveryMs: number;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
lease: {
|
|
167
|
+
params: {
|
|
168
|
+
slots?: number;
|
|
169
|
+
};
|
|
170
|
+
result: {
|
|
171
|
+
run: RunGrant;
|
|
172
|
+
input: TurnStart;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
"lease.renew": {
|
|
176
|
+
params: {
|
|
177
|
+
runId: string;
|
|
178
|
+
};
|
|
179
|
+
result: {
|
|
180
|
+
ok: true;
|
|
181
|
+
token?: string;
|
|
182
|
+
tokenExpiresAt?: string;
|
|
183
|
+
} | {
|
|
184
|
+
ok: false;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
"lease.release": {
|
|
188
|
+
params: {
|
|
189
|
+
runId: string;
|
|
190
|
+
reason: ReleaseReason;
|
|
191
|
+
};
|
|
192
|
+
result: Record<string, never>;
|
|
193
|
+
};
|
|
194
|
+
"effect.intent": {
|
|
195
|
+
params: {
|
|
196
|
+
runId: string;
|
|
197
|
+
effect: EffectIntent;
|
|
198
|
+
requestHash: string;
|
|
199
|
+
};
|
|
200
|
+
result: IntentAnswer;
|
|
201
|
+
};
|
|
202
|
+
"effect.outcome": {
|
|
203
|
+
params: {
|
|
204
|
+
runId: string;
|
|
205
|
+
effectId: string;
|
|
206
|
+
value: unknown;
|
|
207
|
+
} | {
|
|
208
|
+
runId: string;
|
|
209
|
+
effectId: string;
|
|
210
|
+
error: string;
|
|
211
|
+
};
|
|
212
|
+
result: OutcomeAnswer;
|
|
213
|
+
};
|
|
214
|
+
"transcript.read": {
|
|
215
|
+
params: {
|
|
216
|
+
runId: string;
|
|
217
|
+
};
|
|
218
|
+
result: {
|
|
219
|
+
cursor: number;
|
|
220
|
+
entries: unknown[];
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
event: {
|
|
224
|
+
params: {
|
|
225
|
+
runId?: string;
|
|
226
|
+
sessionId: string;
|
|
227
|
+
turnId: string | null;
|
|
228
|
+
type: HarnessClaim;
|
|
229
|
+
payload: unknown;
|
|
230
|
+
/** With `sandbox.state`: the workspace's compute record as it is now. */
|
|
231
|
+
record?: WorkspaceRecord;
|
|
232
|
+
};
|
|
233
|
+
result: Record<string, never>;
|
|
234
|
+
};
|
|
235
|
+
"session.mcp": {
|
|
236
|
+
params: {
|
|
237
|
+
runId: string;
|
|
238
|
+
snapshot?: unknown;
|
|
239
|
+
diagnostics: unknown[];
|
|
240
|
+
};
|
|
241
|
+
result: {
|
|
242
|
+
snapshot: unknown;
|
|
243
|
+
sessionTools: unknown[];
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
"turn.completed": {
|
|
247
|
+
params: TurnOutput;
|
|
248
|
+
result: {
|
|
249
|
+
cursor?: number;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
"turn.paused": {
|
|
253
|
+
params: TurnOutput;
|
|
254
|
+
result: {
|
|
255
|
+
cursor?: number;
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
"turn.waiting": {
|
|
259
|
+
params: TurnOutput;
|
|
260
|
+
result: {
|
|
261
|
+
cursor?: number;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
"turn.failed": {
|
|
265
|
+
params: TurnOutput;
|
|
266
|
+
result: {
|
|
267
|
+
cursor?: number;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
/** A yielded segment's state: ends the run, the turn goes on in the next. */
|
|
271
|
+
checkpoint: {
|
|
272
|
+
params: TurnOutput;
|
|
273
|
+
result: {
|
|
274
|
+
cursor?: number;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/** The session a workspace request acts for: the workspace's owner and its sandbox resource. */
|
|
279
|
+
export interface WorkspaceSession {
|
|
280
|
+
/** The session that owns the workspace: its log records the workspace's events. */
|
|
281
|
+
readonly ownerId: string;
|
|
282
|
+
readonly sandboxId?: string;
|
|
283
|
+
readonly activeTurnId: string | null;
|
|
284
|
+
}
|
|
285
|
+
/** A workspace's compute record, as the harness keeps it. */
|
|
286
|
+
export interface WorkspaceRecord {
|
|
287
|
+
readonly key: string;
|
|
288
|
+
readonly sessionId: string;
|
|
289
|
+
readonly sandboxId?: string;
|
|
290
|
+
readonly backend: string;
|
|
291
|
+
readonly image: string;
|
|
292
|
+
readonly state: "creating" | "running" | "stopped";
|
|
293
|
+
readonly createdAt: string;
|
|
294
|
+
readonly updatedAt: string;
|
|
295
|
+
}
|
|
296
|
+
/** A sandbox tool call core sends to the harness that serves workspaces. */
|
|
297
|
+
export interface WorkspaceCall {
|
|
298
|
+
readonly session: WorkspaceSession;
|
|
299
|
+
/** The sandbox spec the workspace runs (`SandboxManifest`). */
|
|
300
|
+
readonly spec: unknown;
|
|
301
|
+
readonly tool: string;
|
|
302
|
+
readonly input: unknown;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* A file of a workspace read as bytes (`save_artifact`, F8.1), at most `maxBytes`. The answer is
|
|
306
|
+
* `{kind: "read", path, base64}`, `{kind: "missing", path}` or a failed tool outcome.
|
|
307
|
+
*/
|
|
308
|
+
export interface WorkspaceBytesCall {
|
|
309
|
+
readonly session: WorkspaceSession;
|
|
310
|
+
readonly spec: unknown;
|
|
311
|
+
readonly bytes: {
|
|
312
|
+
readonly path: string;
|
|
313
|
+
readonly maxBytes: number;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The regular files under a directory of a workspace, recursively, at most `maxEntries + 1`
|
|
318
|
+
* (the turn-end export, F8.2). The answer is `{kind: "listed", path, listing: {entries,
|
|
319
|
+
* truncated}}`, `{kind: "missing", path}` (no sandbox yet, or not a directory) or a failed tool
|
|
320
|
+
* outcome.
|
|
321
|
+
*/
|
|
322
|
+
export interface WorkspaceListCall {
|
|
323
|
+
readonly session: WorkspaceSession;
|
|
324
|
+
readonly spec: unknown;
|
|
325
|
+
readonly list: {
|
|
326
|
+
readonly dir: string;
|
|
327
|
+
readonly maxEntries: number;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Requests core sends to a harness that declared `workspace` (F6.2), with their answers. A
|
|
332
|
+
* sandbox tool's answer is its `SandboxToolOutcome`; the harness claims its `sandbox.*` events
|
|
333
|
+
* while the request is in flight. `workspace.read` stays generic: F8.2 exports outputs
|
|
334
|
+
* through it.
|
|
335
|
+
*/
|
|
336
|
+
export interface CoreRequests {
|
|
337
|
+
"workspace.read": {
|
|
338
|
+
params: WorkspaceCall | WorkspaceBytesCall | WorkspaceListCall;
|
|
339
|
+
result: Record<string, unknown>;
|
|
340
|
+
};
|
|
341
|
+
"workspace.write": {
|
|
342
|
+
params: WorkspaceCall;
|
|
343
|
+
result: Record<string, unknown>;
|
|
344
|
+
};
|
|
345
|
+
"workspace.exec": {
|
|
346
|
+
params: WorkspaceCall;
|
|
347
|
+
result: Record<string, unknown>;
|
|
348
|
+
};
|
|
349
|
+
/** The harness's sandbox selection report (`GET /v1/tenant/sandbox`, Tenant status). */
|
|
350
|
+
"workspace.report": {
|
|
351
|
+
params: Record<string, never>;
|
|
352
|
+
result: Record<string, unknown>;
|
|
353
|
+
};
|
|
354
|
+
/** Stops idle workspaces, then lists every workspace the harness keeps. */
|
|
355
|
+
"workspace.sweep": {
|
|
356
|
+
params: {
|
|
357
|
+
now?: number;
|
|
358
|
+
};
|
|
359
|
+
result: {
|
|
360
|
+
workspaces: WorkspaceRecord[];
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
/** Deletes workspaces with their files: by key, by sandbox resource, or all of them. */
|
|
364
|
+
"workspace.remove": {
|
|
365
|
+
params: {
|
|
366
|
+
keys?: string[];
|
|
367
|
+
sandboxIds?: string[];
|
|
368
|
+
all?: true;
|
|
369
|
+
};
|
|
370
|
+
result: Record<string, never>;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/** Messages core sends to a harness, without an answer. */
|
|
374
|
+
export interface CoreMessages {
|
|
375
|
+
/** `message` is core's abort message, which the run's executors see as theirs. */
|
|
376
|
+
cancel: {
|
|
377
|
+
runId: string;
|
|
378
|
+
reason: AbortReason;
|
|
379
|
+
message?: string;
|
|
380
|
+
};
|
|
381
|
+
/** F6.2: an Action's outcome for a run held while it is pending. */
|
|
382
|
+
"effect.resolved": {
|
|
383
|
+
runId: string;
|
|
384
|
+
effectId: string;
|
|
385
|
+
outcome: ActionOutcome;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
export type HarnessMethod = keyof HarnessRequests;
|
|
389
|
+
export type CoreMethod = keyof CoreRequests;
|
|
390
|
+
export type CoreMessage = keyof CoreMessages;
|
|
391
|
+
type Requests = HarnessRequests & CoreRequests;
|
|
392
|
+
export type ParamsOf<M extends keyof Requests> = Requests[M]["params"];
|
|
393
|
+
export type ResultOf<M extends keyof Requests> = Requests[M]["result"];
|
|
394
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const HARNESS_API_VERSION = 1;
|
|
2
|
+
export const ABORT_REASONS = [
|
|
3
|
+
"cancel",
|
|
4
|
+
"shutdown",
|
|
5
|
+
"deadline",
|
|
6
|
+
"ownership.lost",
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Events a harness may claim: for a run it holds, or for a workspace request core sent it. A
|
|
10
|
+
* `sandbox.state` claim carries the workspace's compute record, which core keeps.
|
|
11
|
+
*/
|
|
12
|
+
export const HARNESS_CLAIMS = ["sandbox.state", "sandbox.exec"];
|
|
13
|
+
export const HARNESS_ERROR_CODES = [
|
|
14
|
+
"run_not_held",
|
|
15
|
+
"turn_cancelled",
|
|
16
|
+
"ownership_lost",
|
|
17
|
+
"effect_drift",
|
|
18
|
+
"invalid",
|
|
19
|
+
"unavailable",
|
|
20
|
+
"internal",
|
|
21
|
+
];
|