@nylorun/core 0.22.0-beta → 0.23.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 +102 -0
- package/README.md +1 -1
- package/dist/compatibility.d.ts +32 -16
- package/dist/compatibility.js +33 -17
- package/dist/contracts.d.ts +531 -88
- package/dist/contracts.js +297 -199
- package/dist/define.d.ts +8 -12
- package/dist/define.js +7 -11
- package/dist/definition/assemble.d.ts +1 -3
- package/dist/definition/assemble.js +4 -8
- package/dist/definition/bound.d.ts +1 -1
- package/dist/definition/delegate.d.ts +5 -0
- package/dist/definition/delegate.js +6 -1
- package/dist/definition/from.d.ts +4 -2
- package/dist/definition/from.js +11 -29
- package/dist/definition/http-tool.d.ts +5 -3
- package/dist/definition/http-tool.js +8 -5
- package/dist/definition/manifest.d.ts +7 -6
- package/dist/definition/manifest.js +7 -6
- package/dist/definition/mcp.d.ts +1 -1
- package/dist/definition/media-reference.d.ts +2 -11
- package/dist/definition/media-reference.js +0 -12
- package/dist/definition/model-failure.js +1 -0
- package/dist/definition/removed.js +1 -0
- package/dist/definition/trace.d.ts +0 -7
- package/dist/definition/trace.js +0 -34
- package/dist/definition/variant.d.ts +1 -1
- package/dist/definition/variant.js +1 -3
- package/dist/harness-api/artifacts.d.ts +84 -0
- package/dist/harness-api/artifacts.js +128 -0
- package/dist/harness-api/gates.d.ts +0 -4
- package/dist/harness-api/gates.js +0 -4
- package/dist/harness-api/harness-api.schema.json +2422 -924
- package/dist/harness-api/index.d.ts +9 -6
- package/dist/harness-api/index.js +9 -6
- package/dist/harness-api/json-schema.js +5 -2
- package/dist/harness-api/mcp.d.ts +77 -30
- package/dist/harness-api/mcp.js +42 -25
- package/dist/harness-api/messages.d.ts +45 -17
- package/dist/harness-api/messages.js +20 -5
- package/dist/harness-api/schema.d.ts +538 -198
- package/dist/harness-api/schema.js +298 -59
- package/dist/harness-api/transcript.d.ts +8 -10
- package/dist/harness-api/transcript.js +27 -11
- package/dist/harness-api/transport.d.ts +7 -1
- package/dist/harness-api/transport.js +10 -7
- package/dist/schemas/agent-manifest.schema.json +5 -146
- package/dist/schemas/environment-manifest.schema.json +56 -16
- package/dist/types/manifest.d.ts +3 -13
- package/dist/types/model.d.ts +10 -5
- package/dist/utils/definition-files.d.ts +20 -6
- package/dist/utils/definition-files.js +31 -17
- package/dist/utils/file-systems.d.ts +20 -0
- package/dist/utils/file-systems.js +20 -0
- package/dist/utils/harness-id.d.ts +4 -1
- package/dist/utils/harness-id.js +4 -1
- package/dist/utils/media-types.d.ts +30 -0
- package/dist/utils/media-types.js +128 -0
- package/dist/utils/runtime-limits.d.ts +229 -0
- package/dist/utils/runtime-limits.js +482 -0
- package/dist/utils/runtime-tools.d.ts +8 -16
- package/dist/utils/runtime-tools.js +8 -27
- package/dist/utils/sandbox.d.ts +4 -1
- package/dist/utils/sandbox.js +4 -1
- package/package.json +1 -1
- package/dist/definition/deferred-tools.d.ts +0 -27
- package/dist/definition/deferred-tools.js +0 -82
- package/dist/definition/runtime-manifest.d.ts +0 -30
- package/dist/definition/runtime-manifest.js +0 -132
- package/dist/definition/sandbox-tools.d.ts +0 -5
- package/dist/definition/sandbox-tools.js +0 -109
- package/dist/definition/skill-tools.d.ts +0 -23
- package/dist/definition/skill-tools.js +0 -76
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A harness's side of the artifact seam (protocol 15): reading an artifact the run's session may
|
|
3
|
+
* read in chunks (`artifact.read`), and writing one (`artifact.write`: `begin`, `chunk`,
|
|
4
|
+
* `commit`, `abort`). Chunks are at most `chunkBytes`: pass the run's
|
|
5
|
+
* `turn.start.limits.chunkBytes`, which core holds them to. Our engine's `read_artifact` and
|
|
6
|
+
* `save_artifact` use these, and any harness may.
|
|
7
|
+
*/
|
|
8
|
+
import type { HarnessChannel } from "./rpc.js";
|
|
9
|
+
import type { ArtifactMeta } from "./messages.js";
|
|
10
|
+
/** What the helpers need of a channel: its requests to core. */
|
|
11
|
+
export type ArtifactRequester = Pick<HarnessChannel, "request">;
|
|
12
|
+
export interface ReadArtifactOptions {
|
|
13
|
+
readonly runId: string;
|
|
14
|
+
readonly artifactId: string;
|
|
15
|
+
/** Default: the latest, which the first answer pins for the chunks after it. */
|
|
16
|
+
readonly version?: number;
|
|
17
|
+
/** The first byte to read. Default 0. */
|
|
18
|
+
readonly offset?: number;
|
|
19
|
+
/** The most bytes each request asks for: the run's `turn.start.limits.chunkBytes`. */
|
|
20
|
+
readonly chunkBytes: number;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface ReadArtifact {
|
|
24
|
+
readonly artifact: ArtifactMeta;
|
|
25
|
+
/**
|
|
26
|
+
* The bytes from `offset` to the end, a chunk at a time: the first came with `artifact`, the
|
|
27
|
+
* rest are asked for as they are read. Read it once.
|
|
28
|
+
*/
|
|
29
|
+
chunks(): AsyncIterable<Uint8Array>;
|
|
30
|
+
}
|
|
31
|
+
/** Opens an artifact to read: its metadata, and its bytes as chunks. */
|
|
32
|
+
export declare function readArtifact(channel: ArtifactRequester, options: ReadArtifactOptions): Promise<ReadArtifact>;
|
|
33
|
+
export interface ArtifactWriteOptions {
|
|
34
|
+
readonly runId: string;
|
|
35
|
+
/** Makes the write idempotent within the session: a key written before answers its version. */
|
|
36
|
+
readonly key: string;
|
|
37
|
+
/** A new artifact's name. */
|
|
38
|
+
readonly name?: string;
|
|
39
|
+
/** Write a new version of this artifact of the session instead. */
|
|
40
|
+
readonly artifactId?: string;
|
|
41
|
+
/** Default: what the name's extension implies. */
|
|
42
|
+
readonly contentType?: string;
|
|
43
|
+
/** The tool call the artifact comes from: an effect of the run's turn. */
|
|
44
|
+
readonly effectId?: string;
|
|
45
|
+
/** The body's size when known: core refuses one past its limits before a byte is sent. */
|
|
46
|
+
readonly size?: number;
|
|
47
|
+
/** The most bytes one chunk carries: the run's `turn.start.limits.chunkBytes`. */
|
|
48
|
+
readonly chunkBytes: number;
|
|
49
|
+
readonly signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
/** A version `artifact.write` stored, and whether this write stored it (not an earlier one). */
|
|
52
|
+
export interface WrittenArtifact {
|
|
53
|
+
readonly artifact: ArtifactMeta;
|
|
54
|
+
readonly created: boolean;
|
|
55
|
+
}
|
|
56
|
+
/** An upload in progress. */
|
|
57
|
+
export interface OpenArtifactWrite {
|
|
58
|
+
readonly kind: "open";
|
|
59
|
+
readonly uploadId: string;
|
|
60
|
+
/** The most bytes the upload may hold, when it opened. */
|
|
61
|
+
readonly maxBytes: number;
|
|
62
|
+
/** Sends `bytes` next, in chunks of at most `chunkBytes`. */
|
|
63
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
64
|
+
/** Stores what was sent as the version. */
|
|
65
|
+
commit(): Promise<WrittenArtifact>;
|
|
66
|
+
/** Drops the upload; nothing is stored. */
|
|
67
|
+
abort(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Begins a write. Answers `written` when the key was written before (nothing more to send), else
|
|
71
|
+
* the open upload.
|
|
72
|
+
*/
|
|
73
|
+
export declare function openArtifactWrite(channel: ArtifactRequester, options: ArtifactWriteOptions): Promise<({
|
|
74
|
+
readonly kind: "written";
|
|
75
|
+
} & WrittenArtifact) | OpenArtifactWrite>;
|
|
76
|
+
/**
|
|
77
|
+
* Writes `bytes` as the artifact: in the `begin` when they fit one chunk, else as an upload,
|
|
78
|
+
* which an error aborts.
|
|
79
|
+
*/
|
|
80
|
+
export declare function writeArtifactBytes(channel: ArtifactRequester, options: ArtifactWriteOptions, bytes: Uint8Array): Promise<WrittenArtifact>;
|
|
81
|
+
/** `bytes` as base64. */
|
|
82
|
+
export declare function toBase64(bytes: Uint8Array): string;
|
|
83
|
+
/** The bytes base64 `text` encodes. */
|
|
84
|
+
export declare function fromBase64(text: string): Uint8Array;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Opens an artifact to read: its metadata, and its bytes as chunks. */
|
|
2
|
+
export async function readArtifact(channel, options) {
|
|
3
|
+
const { runId, artifactId, chunkBytes, signal } = options;
|
|
4
|
+
const start = options.offset ?? 0;
|
|
5
|
+
const first = await channel.request("artifact.read", {
|
|
6
|
+
runId,
|
|
7
|
+
artifactId,
|
|
8
|
+
...(options.version === undefined ? {} : { version: options.version }),
|
|
9
|
+
offset: start,
|
|
10
|
+
length: chunkBytes,
|
|
11
|
+
}, signal);
|
|
12
|
+
// The chunks after the first read the version the first did, even if a newer one lands.
|
|
13
|
+
const version = first.artifact.version;
|
|
14
|
+
return {
|
|
15
|
+
artifact: first.artifact,
|
|
16
|
+
async *chunks() {
|
|
17
|
+
let answer = first;
|
|
18
|
+
let offset = start;
|
|
19
|
+
for (;;) {
|
|
20
|
+
const bytes = fromBase64(answer.base64);
|
|
21
|
+
if (bytes.byteLength > 0)
|
|
22
|
+
yield bytes;
|
|
23
|
+
offset += bytes.byteLength;
|
|
24
|
+
if (answer.eof || bytes.byteLength === 0)
|
|
25
|
+
return;
|
|
26
|
+
answer = await channel.request("artifact.read", { runId, artifactId, version, offset, length: chunkBytes }, signal);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Begins a write. Answers `written` when the key was written before (nothing more to send), else
|
|
33
|
+
* the open upload.
|
|
34
|
+
*/
|
|
35
|
+
export async function openArtifactWrite(channel, options) {
|
|
36
|
+
const answer = await channel.request("artifact.write", beginOf(options), options.signal);
|
|
37
|
+
return opened(channel, options, answer);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Writes `bytes` as the artifact: in the `begin` when they fit one chunk, else as an upload,
|
|
41
|
+
* which an error aborts.
|
|
42
|
+
*/
|
|
43
|
+
export async function writeArtifactBytes(channel, options, bytes) {
|
|
44
|
+
if (bytes.byteLength <= options.chunkBytes) {
|
|
45
|
+
const answer = await channel.request("artifact.write", { ...beginOf({ ...options, size: bytes.byteLength }), base64: toBase64(bytes) }, options.signal);
|
|
46
|
+
if (answer.status !== "written")
|
|
47
|
+
throw new Error(`artifact.write answered ${answer.status} to a whole body`);
|
|
48
|
+
return { artifact: answer.artifact, created: answer.created };
|
|
49
|
+
}
|
|
50
|
+
const upload = await openArtifactWrite(channel, { ...options, size: bytes.byteLength });
|
|
51
|
+
if (upload.kind === "written")
|
|
52
|
+
return { artifact: upload.artifact, created: upload.created };
|
|
53
|
+
try {
|
|
54
|
+
await upload.write(bytes);
|
|
55
|
+
return await upload.commit();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
await upload.abort().catch(() => undefined);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function beginOf(options) {
|
|
63
|
+
return {
|
|
64
|
+
runId: options.runId,
|
|
65
|
+
op: "begin",
|
|
66
|
+
key: options.key,
|
|
67
|
+
...(options.name === undefined ? {} : { name: options.name }),
|
|
68
|
+
...(options.artifactId === undefined ? {} : { artifactId: options.artifactId }),
|
|
69
|
+
...(options.contentType === undefined ? {} : { contentType: options.contentType }),
|
|
70
|
+
...(options.effectId === undefined ? {} : { effectId: options.effectId }),
|
|
71
|
+
...(options.size === undefined ? {} : { size: options.size }),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function opened(channel, options, begun) {
|
|
75
|
+
if (begun.status === "written")
|
|
76
|
+
return { kind: "written", artifact: begun.artifact, created: begun.created };
|
|
77
|
+
if (begun.status !== "open")
|
|
78
|
+
throw new Error(`artifact.write answered ${begun.status} to a begin`);
|
|
79
|
+
const { runId, chunkBytes, signal } = options;
|
|
80
|
+
const { uploadId, maxBytes } = begun;
|
|
81
|
+
let received = begun.received;
|
|
82
|
+
return {
|
|
83
|
+
kind: "open",
|
|
84
|
+
uploadId,
|
|
85
|
+
maxBytes,
|
|
86
|
+
async write(bytes) {
|
|
87
|
+
for (let at = 0; at < bytes.byteLength; at += chunkBytes) {
|
|
88
|
+
const chunk = bytes.subarray(at, Math.min(at + chunkBytes, bytes.byteLength));
|
|
89
|
+
const sent = await channel.request("artifact.write", { runId, op: "chunk", uploadId, offset: received, base64: toBase64(chunk) }, signal);
|
|
90
|
+
if (sent.status !== "open")
|
|
91
|
+
throw new Error(`artifact.write answered ${sent.status} to a chunk`);
|
|
92
|
+
received = sent.received;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async commit() {
|
|
96
|
+
const done = await channel.request("artifact.write", { runId, op: "commit", uploadId }, signal);
|
|
97
|
+
if (done.status !== "written")
|
|
98
|
+
throw new Error(`artifact.write answered ${done.status} to a commit`);
|
|
99
|
+
return { artifact: done.artifact, created: done.created };
|
|
100
|
+
},
|
|
101
|
+
async abort() {
|
|
102
|
+
await channel.request("artifact.write", { runId, op: "abort", uploadId });
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const NodeBuffer = globalThis.Buffer;
|
|
107
|
+
/** `bytes` as base64. */
|
|
108
|
+
export function toBase64(bytes) {
|
|
109
|
+
if (NodeBuffer)
|
|
110
|
+
return NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
111
|
+
let binary = "";
|
|
112
|
+
// `fromCharCode` takes its bytes as arguments: a slice at a time keeps under the engine's cap.
|
|
113
|
+
for (let at = 0; at < bytes.byteLength; at += 0x8000)
|
|
114
|
+
binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000));
|
|
115
|
+
return btoa(binary);
|
|
116
|
+
}
|
|
117
|
+
/** The bytes base64 `text` encodes. */
|
|
118
|
+
export function fromBase64(text) {
|
|
119
|
+
if (NodeBuffer) {
|
|
120
|
+
const decoded = NodeBuffer.from(text, "base64");
|
|
121
|
+
return new Uint8Array(decoded.buffer, decoded.byteOffset, decoded.byteLength);
|
|
122
|
+
}
|
|
123
|
+
const binary = atob(text);
|
|
124
|
+
const bytes = new Uint8Array(binary.length);
|
|
125
|
+
for (let at = 0; at < binary.length; at += 1)
|
|
126
|
+
bytes[at] = binary.charCodeAt(at);
|
|
127
|
+
return bytes;
|
|
128
|
+
}
|
|
@@ -30,10 +30,6 @@ export declare const MCP_LIST_PATH = "/nylorun/v1/mcp/list";
|
|
|
30
30
|
export declare const MCP_CLOSE_PATH = "/nylorun/v1/mcp/close";
|
|
31
31
|
export declare const TOOL_CALLS_PATH = "/nylorun/v1/tool-calls";
|
|
32
32
|
export declare const HTTP_CALLS_PATH = "/nylorun/v1/http-calls";
|
|
33
|
-
/** Largest model call body the gate reads: one `ModelCall` with its whole projected history. */
|
|
34
|
-
export declare const MAX_MODEL_CALL_BYTES: number;
|
|
35
|
-
/** Largest tool call body the gate reads. */
|
|
36
|
-
export declare const MAX_TOOL_BODY_BYTES: number;
|
|
37
33
|
/**
|
|
38
34
|
* One model call. It names no session, turn or agent: the gate takes them from the run token,
|
|
39
35
|
* and refuses a body that names them. `call` is the engine's `ModelCall`.
|
|
@@ -29,10 +29,6 @@ export const MCP_LIST_PATH = "/nylorun/v1/mcp/list";
|
|
|
29
29
|
export const MCP_CLOSE_PATH = "/nylorun/v1/mcp/close";
|
|
30
30
|
export const TOOL_CALLS_PATH = "/nylorun/v1/tool-calls";
|
|
31
31
|
export const HTTP_CALLS_PATH = "/nylorun/v1/http-calls";
|
|
32
|
-
/** Largest model call body the gate reads: one `ModelCall` with its whole projected history. */
|
|
33
|
-
export const MAX_MODEL_CALL_BYTES = 32 * 1024 * 1024;
|
|
34
|
-
/** Largest tool call body the gate reads. */
|
|
35
|
-
export const MAX_TOOL_BODY_BYTES = 8 * 1024 * 1024;
|
|
36
32
|
/**
|
|
37
33
|
* One model call. It names no session, turn or agent: the gate takes them from the run token,
|
|
38
34
|
* and refuses a body that names them. `call` is the engine's `ModelCall`.
|