@nylorun/core 0.21.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 +124 -0
- package/README.md +1 -1
- package/dist/compatibility.d.ts +37 -20
- package/dist/compatibility.js +38 -21
- package/dist/contracts.d.ts +531 -88
- package/dist/contracts.js +315 -204
- 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 +54 -8
- package/dist/definition/http-tool.js +175 -10
- 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/manifest-schemas.js +14 -2
- package/dist/schemas/agent-manifest.schema.json +14 -147
- package/dist/schemas/environment-manifest.schema.json +76 -16
- package/dist/types/manifest.d.ts +17 -18
- 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
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { DefinitionPart } from "./bound.js";
|
|
2
|
-
import type { AgentManifest, AgentRequirements
|
|
2
|
+
import type { AgentManifest, AgentRequirements } from "../types/manifest.js";
|
|
3
3
|
import type { JsonObject } from "../types/shared.js";
|
|
4
4
|
import type { ToolSchemaSource } from "../types/tool.js";
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The id of the part an agent rebuilt from its manifest gets for what one run adds to it: the
|
|
7
|
+
* session's tools and the text that goes with them (`agentFrom` `sessionTools`). Not hashed.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SESSION_PART_ID = "session";
|
|
7
10
|
/**
|
|
8
11
|
* The agent's manifest (v7): its parts merged in order, the instructions and tools concatenated,
|
|
9
|
-
* the skills and servers keyed by name. The
|
|
10
|
-
* it was pinned.
|
|
12
|
+
* the skills and servers keyed by name. The session part is not projected.
|
|
11
13
|
*/
|
|
12
14
|
export declare function createManifest(input: {
|
|
13
15
|
id: string;
|
|
@@ -16,6 +18,5 @@ export declare function createManifest(input: {
|
|
|
16
18
|
metadata?: JsonObject;
|
|
17
19
|
outputSchema?: ToolSchemaSource;
|
|
18
20
|
requires?: AgentRequirements;
|
|
19
|
-
runtime?: RuntimeManifest;
|
|
20
21
|
parts: readonly DefinitionPart[];
|
|
21
22
|
}): AgentManifest;
|
|
@@ -3,15 +3,17 @@ import { normalizedSchemasFor } from "./schema.js";
|
|
|
3
3
|
import { delegateOf } from "./delegate.js";
|
|
4
4
|
import { httpToolOf } from "./http-tool.js";
|
|
5
5
|
import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The id of the part an agent rebuilt from its manifest gets for what one run adds to it: the
|
|
8
|
+
* session's tools and the text that goes with them (`agentFrom` `sessionTools`). Not hashed.
|
|
9
|
+
*/
|
|
10
|
+
export const SESSION_PART_ID = "session";
|
|
8
11
|
/**
|
|
9
12
|
* The agent's manifest (v7): its parts merged in order, the instructions and tools concatenated,
|
|
10
|
-
* the skills and servers keyed by name. The
|
|
11
|
-
* it was pinned.
|
|
13
|
+
* the skills and servers keyed by name. The session part is not projected.
|
|
12
14
|
*/
|
|
13
15
|
export function createManifest(input) {
|
|
14
|
-
const authored = input.parts.filter((part) => part.id !==
|
|
16
|
+
const authored = input.parts.filter((part) => part.id !== SESSION_PART_ID);
|
|
15
17
|
const instructions = authored.flatMap((part) => part.instructions ?? []);
|
|
16
18
|
const tools = authored.flatMap((part) => (part.tools ?? []).map((tool) => projectTool(tool)));
|
|
17
19
|
const skills = {};
|
|
@@ -41,7 +43,6 @@ export function createManifest(input) {
|
|
|
41
43
|
...(Object.keys(skills).length === 0 ? {} : { skills }),
|
|
42
44
|
...(Object.keys(mcpServers).length === 0 ? {} : { mcpServers }),
|
|
43
45
|
...(input.requires === undefined ? {} : { requires: copyRequirements(input.requires) }),
|
|
44
|
-
...(input.runtime === undefined ? {} : { runtime: input.runtime }),
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
/** `requires` as plain data, its secret names sorted and each once. */
|
package/dist/definition/mcp.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const MCP_TOOL_DEFAULTS = "*";
|
|
|
20
20
|
export interface ResolvedMcpToolSettings {
|
|
21
21
|
readonly enabled: boolean;
|
|
22
22
|
readonly approval: ApprovalMode;
|
|
23
|
-
/** Undefined: nothing sets it, and the
|
|
23
|
+
/** Undefined: nothing sets it, and the harness decides (R2b C10, automatic deferral). */
|
|
24
24
|
readonly deferred?: boolean;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { JsonValue } from "../types/shared.js";
|
|
2
2
|
/**
|
|
3
3
|
* What a media part's `reference` holds when the Runtime made it (protocol 6, 12): the artifact
|
|
4
|
-
* version, by id, with the file's name and size in bytes when known.
|
|
4
|
+
* version, by id, with the file's name and size in bytes when known. The Model Gate fetches it,
|
|
5
|
+
* and a harness reads it to decide how the model sees the file (protocol 15).
|
|
5
6
|
*/
|
|
6
7
|
export interface MediaReference {
|
|
7
8
|
readonly artifactId: string;
|
|
@@ -11,13 +12,3 @@ export interface MediaReference {
|
|
|
11
12
|
}
|
|
12
13
|
/** The reference of a media part the Runtime made, or undefined for another host's. */
|
|
13
14
|
export declare function mediaReferenceOf(value: JsonValue | undefined): MediaReference | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* The line a file stands for in a prompt once its turn is over (protocol 12): its name, artifact
|
|
16
|
-
* id and version, and how the model reads it again. A file a tool returned names the tool.
|
|
17
|
-
*/
|
|
18
|
-
export declare function mediaReferenceLine(part: {
|
|
19
|
-
readonly mediaType: string;
|
|
20
|
-
readonly reference: JsonValue;
|
|
21
|
-
}, origin: "uploaded" | {
|
|
22
|
-
readonly tool: string;
|
|
23
|
-
}): string;
|
|
@@ -12,15 +12,3 @@ export function mediaReferenceOf(value) {
|
|
|
12
12
|
...(typeof size === "number" ? { size } : {}),
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* The line a file stands for in a prompt once its turn is over (protocol 12): its name, artifact
|
|
17
|
-
* id and version, and how the model reads it again. A file a tool returned names the tool.
|
|
18
|
-
*/
|
|
19
|
-
export function mediaReferenceLine(part, origin) {
|
|
20
|
-
const reference = mediaReferenceOf(part.reference);
|
|
21
|
-
const what = origin === "uploaded" ? "Uploaded artifact" : `Tool ${origin.tool} returned artifact`;
|
|
22
|
-
if (!reference)
|
|
23
|
-
return `[${what} (${part.mediaType})]`;
|
|
24
|
-
const name = JSON.stringify(reference.name ?? reference.artifactId);
|
|
25
|
-
return `[${what} ${name} · ${reference.artifactId} v${reference.version} · read_artifact to view]`;
|
|
26
|
-
}
|
|
@@ -9,6 +9,7 @@ export const REMOVED_MANIFEST_FIELDS = Object.freeze({
|
|
|
9
9
|
model: "Manifest must not include top-level model; Runtime owns model resolution",
|
|
10
10
|
hooks: "hooks were removed: the Runtime runs agents from their manifests alone. Use an HTTP tool, the Tenant's tool policy, or a loop verifier instead (see MIGRATION.md)",
|
|
11
11
|
capabilities: "Manifest v7 has no capabilities: the agent's instructions, tools, skills and mcpServers are top-level fields. Rebuild the agent with the current SDK (see MIGRATION.md)",
|
|
12
|
+
runtime: "Manifest field runtime was removed: since protocol 15 the harness writes the model's instructions and defines the sandbox and skill tools. Register the manifest your builder makes (see MIGRATION.md)",
|
|
12
13
|
});
|
|
13
14
|
/** Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 7. */
|
|
14
15
|
export function manifestVersionIssue(version) {
|
|
@@ -4,13 +4,6 @@ export interface ToolCallTrace {
|
|
|
4
4
|
readonly skill?: string;
|
|
5
5
|
readonly plugin?: PluginLabel;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* The skill of `manifest` a tool call ran. `load_skill` and `read_skill_resource` name it in their
|
|
9
|
-
* input. A sandbox tool (`bash`, `read`, `grep`, `glob`, …) is matched on the skills' mount path,
|
|
10
|
-
* `/skills/<name>@<hash>/` (or `/skills/<name>/`, before D66), in its input's text: exact for a path argument, and for `bash` only when the
|
|
11
|
-
* command names the path. The first skill of the agent the input names wins.
|
|
12
|
-
*/
|
|
13
|
-
export declare function skillOfToolCall(manifest: Pick<AgentManifest, "skills"> | undefined, toolName: string | undefined, input: unknown): string | undefined;
|
|
14
7
|
/** The plugin that brought the skill or MCP server `name` to `manifest`, if one did. */
|
|
15
8
|
export declare function pluginOf(manifest: Pick<AgentManifest, "skills" | "mcpServers"> | undefined, what: {
|
|
16
9
|
readonly skill?: string;
|
package/dist/definition/trace.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
import { SKILLS_MOUNT } from "../utils/definition-files.js";
|
|
2
|
-
import { isSandboxToolName } from "../utils/sandbox.js";
|
|
3
|
-
import { SKILL_TOOL_NAMES } from "./skill-tools.js";
|
|
4
|
-
const MOUNT = new RegExp(`${SKILLS_MOUNT}/([^/@\\s"'\`]+)(?:@[0-9a-f]{12})?/`, "g");
|
|
5
|
-
/**
|
|
6
|
-
* The skill of `manifest` a tool call ran. `load_skill` and `read_skill_resource` name it in their
|
|
7
|
-
* input. A sandbox tool (`bash`, `read`, `grep`, `glob`, …) is matched on the skills' mount path,
|
|
8
|
-
* `/skills/<name>@<hash>/` (or `/skills/<name>/`, before D66), in its input's text: exact for a path argument, and for `bash` only when the
|
|
9
|
-
* command names the path. The first skill of the agent the input names wins.
|
|
10
|
-
*/
|
|
11
|
-
export function skillOfToolCall(manifest, toolName, input) {
|
|
12
|
-
const skills = manifest?.skills;
|
|
13
|
-
if (!skills || toolName === undefined)
|
|
14
|
-
return undefined;
|
|
15
|
-
if (SKILL_TOOL_NAMES.has(toolName)) {
|
|
16
|
-
const name = input?.name;
|
|
17
|
-
return typeof name === "string" && skills[name] !== undefined ? name : undefined;
|
|
18
|
-
}
|
|
19
|
-
if (!isSandboxToolName(toolName))
|
|
20
|
-
return undefined;
|
|
21
|
-
for (const text of strings(input))
|
|
22
|
-
for (const match of text.matchAll(MOUNT))
|
|
23
|
-
if (skills[match[1]] !== undefined)
|
|
24
|
-
return match[1];
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
1
|
/** The plugin that brought the skill or MCP server `name` to `manifest`, if one did. */
|
|
28
2
|
export function pluginOf(manifest, what) {
|
|
29
3
|
if (what.skill !== undefined)
|
|
@@ -32,11 +6,3 @@ export function pluginOf(manifest, what) {
|
|
|
32
6
|
return manifest?.mcpServers?.[what.server]?.plugin;
|
|
33
7
|
return undefined;
|
|
34
8
|
}
|
|
35
|
-
/** The string values of a tool's input, one level deep: its path, pattern or command. */
|
|
36
|
-
function strings(input) {
|
|
37
|
-
if (typeof input === "string")
|
|
38
|
-
return [input];
|
|
39
|
-
if (!input || typeof input !== "object")
|
|
40
|
-
return [];
|
|
41
|
-
return Object.values(input).filter((value) => typeof value === "string");
|
|
42
|
-
}
|
|
@@ -4,6 +4,6 @@ import type { AgentManifest } from "../types/manifest.js";
|
|
|
4
4
|
* (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
|
|
5
5
|
* tighten its MCP servers' tool settings (R2b C9, Q18), and change its instructions, name,
|
|
6
6
|
* description and metadata. Its skills and servers are setup: the sandbox holds the skills from
|
|
7
|
-
* the session's start.
|
|
7
|
+
* the session's start.
|
|
8
8
|
*/
|
|
9
9
|
export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
|
|
@@ -58,15 +58,13 @@ function tightensServers(pinned, candidate) {
|
|
|
58
58
|
* (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
|
|
59
59
|
* tighten its MCP servers' tool settings (R2b C9, Q18), and change its instructions, name,
|
|
60
60
|
* description and metadata. Its skills and servers are setup: the sandbox holds the skills from
|
|
61
|
-
* the session's start.
|
|
61
|
+
* the session's start.
|
|
62
62
|
*/
|
|
63
63
|
export function isVariantOf(candidate, pinned) {
|
|
64
64
|
if (candidate.id !== pinned.id)
|
|
65
65
|
return false;
|
|
66
66
|
if (candidate.manifestSchemaVersion !== pinned.manifestSchemaVersion)
|
|
67
67
|
return false;
|
|
68
|
-
if (candidate.runtime !== undefined)
|
|
69
|
-
return false;
|
|
70
68
|
if (!same(candidate.outputSchema, pinned.outputSchema))
|
|
71
69
|
return false;
|
|
72
70
|
// What the agent needs of its Environment was checked when the session opened (D65).
|
|
@@ -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`.
|