@nylorun/harness 0.35.1-beta → 0.36.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 +17 -0
- package/dist/api/host.js +12 -0
- package/dist/loop/model/files.d.ts +9 -0
- package/dist/loop/model/files.js +33 -3
- package/dist/loop/model/project.js +4 -4
- package/dist/tools/plan.d.ts +4 -4
- package/dist/tools/read-media.d.ts +30 -0
- package/dist/tools/read-media.js +95 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.36.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b6a7c1d: An agent sees the images and PDFs it makes in its sandbox (ADR-139). `read` of a file the turn's model reads as media, known by its extension (an image, a PDF, an Office document, audio or video), comes back as the file itself, shown to the model in the turn's files, instead of numbered lines of decoded bytes. Our engine runs it in the harness: it reads the bytes, checks they start as the type says, and stores them as an artifact for the model only. A model that can't read the kind is told so before anything is read or stored (`sandbox.unreadable`), and a file that isn't what its name says fails `sandbox.binary_file`.
|
|
8
|
+
|
|
9
|
+
- **Model-only artifacts.** `artifact.write` `begin` takes `audience: "model"` (Harness API 5, schema revision 5, `harness-api/v5.5.json`; only our own engine sends it). Such an artifact is readable by id and carries `audience: "model"` in its view and its `artifact.created` event, but is never listed (`GET /v1/artifacts`, a session's artifacts, pages) and is no A2A task file. Runtime store migration 0046 (`artifacts.audience`, nullable) runs at start.
|
|
10
|
+
- **Binary files.** The sandbox's `read` of any other binary file fails `sandbox.binary_file`, in words, instead of answering decoded bytes as text.
|
|
11
|
+
- **A cap per call.** A model call carries at most the 6 newest files from tool results as media; older ones in the same turn go as a note naming them, which `read_artifact` brings back. A person's own files are never capped.
|
|
12
|
+
- `read`'s description says what it now does, so the prompt prefix of every agent with a sandbox changes once: its first call after the upgrade misses the prompt cache.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Pin core to the tested release.
|
|
17
|
+
- Updated dependencies [b6a7c1d]
|
|
18
|
+
- @nylorun/core@0.40.0-beta
|
|
19
|
+
|
|
3
20
|
## 0.35.1-beta
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/api/host.js
CHANGED
|
@@ -20,6 +20,7 @@ import { HarnessApiError, effectRequestHash, writeArtifactBytes, } from "@nyloru
|
|
|
20
20
|
import { delegatesOf } from "@nylorun/core/define";
|
|
21
21
|
import { engineFeaturesOf } from "@nylorun/core/engine";
|
|
22
22
|
import { isArtifactTool, runArtifactTool } from "../tools/artifacts.js";
|
|
23
|
+
import { mediaReadOf, runMediaRead } from "../tools/read-media.js";
|
|
23
24
|
import { isSkillTool, mountSkills, runSkillTool } from "../tools/skills.js";
|
|
24
25
|
import { StepBudget, jsonBytes, mayNeedShaping, shapeToolOutcome, spillKey, } from "../tools/results.js";
|
|
25
26
|
import { isToolSearch, runToolSearch } from "../tools/tool-search.js";
|
|
@@ -59,6 +60,7 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
59
60
|
: effect.target?.kind === "harness"
|
|
60
61
|
? await engineTool(effect)
|
|
61
62
|
: ((await mounted(effect)) ??
|
|
63
|
+
(await media(effect)) ??
|
|
62
64
|
(await executors.tool(effect, signal, run, traceparent ? { traceparent } : {})));
|
|
63
65
|
const outcome = model ? value : await shape(effect, value);
|
|
64
66
|
const answer = await ask("effect.outcome", {
|
|
@@ -185,6 +187,16 @@ export function apiHost(channel, executors, run, engine, mcp) {
|
|
|
185
187
|
const mounted = async (effect) => effect.target?.kind === "sandbox" && executors.files
|
|
186
188
|
? mountSkills(executors.files, channel, run, signal)
|
|
187
189
|
: undefined;
|
|
190
|
+
/**
|
|
191
|
+
* A sandbox `read` of a file the model reads as media (ADR-139), which our engine runs over
|
|
192
|
+
* the run's sandbox files and the artifact seam: undefined for every other call.
|
|
193
|
+
*/
|
|
194
|
+
const media = async (effect) => {
|
|
195
|
+
const target = executors.files ? mediaReadOf(effect) : undefined;
|
|
196
|
+
return target === undefined
|
|
197
|
+
? undefined
|
|
198
|
+
: runMediaRead(effect, target, { channel, run, files: executors.files, signal });
|
|
199
|
+
};
|
|
188
200
|
/** Runs a call of one of our engine's own tools. */
|
|
189
201
|
const engineTool = (effect) => {
|
|
190
202
|
if (isToolSearch(effect))
|
|
@@ -71,7 +71,16 @@ export interface LiveFile {
|
|
|
71
71
|
readonly key: string;
|
|
72
72
|
readonly line: string;
|
|
73
73
|
readonly part: FilePart;
|
|
74
|
+
/** Where it came from: a person's message, or a tool's result. Default: a tool's. */
|
|
75
|
+
readonly origin?: "uploaded" | "tool";
|
|
74
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The most files from tool results one model call carries as media (ADR-139). A file the model
|
|
79
|
+
* looked at stays in the turn's files and is sent on every later call of the turn; past these,
|
|
80
|
+
* the oldest go as a note naming them, which `read_artifact` brings back. A person's own files
|
|
81
|
+
* are never capped.
|
|
82
|
+
*/
|
|
83
|
+
export declare const MODEL_CALL_TOOL_MEDIA = 6;
|
|
75
84
|
/** The key a file goes by in one call: its artifact version, or its reference. */
|
|
76
85
|
export declare function fileKeyOf(part: FilePart): string;
|
|
77
86
|
/**
|
package/dist/loop/model/files.js
CHANGED
|
@@ -65,6 +65,13 @@ export function mediaReferenceLine(part, origin, readable = true) {
|
|
|
65
65
|
// An agent without `read_artifact` (ADR-100) is not offered it.
|
|
66
66
|
return `[${what} ${name} · ${reference.artifactId} v${reference.version}${readable ? " · read_artifact to view" : ""}]`;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The most files from tool results one model call carries as media (ADR-139). A file the model
|
|
70
|
+
* looked at stays in the turn's files and is sent on every later call of the turn; past these,
|
|
71
|
+
* the oldest go as a note naming them, which `read_artifact` brings back. A person's own files
|
|
72
|
+
* are never capped.
|
|
73
|
+
*/
|
|
74
|
+
export const MODEL_CALL_TOOL_MEDIA = 6;
|
|
68
75
|
/** The key a file goes by in one call: its artifact version, or its reference. */
|
|
69
76
|
export function fileKeyOf(part) {
|
|
70
77
|
const reference = mediaReferenceOf(part.reference);
|
|
@@ -81,12 +88,35 @@ export function fileKeyOf(part) {
|
|
|
81
88
|
export async function representFiles(files, context, signal) {
|
|
82
89
|
const out = new Map();
|
|
83
90
|
let inlined = 0;
|
|
91
|
+
const views = new Map();
|
|
92
|
+
for (const file of files)
|
|
93
|
+
if (!views.has(file.key))
|
|
94
|
+
views.set(file.key, context ? fileView(file.part, context.model, context.limits) : { kind: "media" });
|
|
95
|
+
// The newest tool files go as media; older ones past the cap, as a note (ADR-139).
|
|
96
|
+
const capped = new Set();
|
|
97
|
+
if (context) {
|
|
98
|
+
let kept = 0;
|
|
99
|
+
for (const file of [...files].reverse()) {
|
|
100
|
+
if (file.origin === "uploaded" ||
|
|
101
|
+
views.get(file.key)?.kind !== "media" ||
|
|
102
|
+
capped.has(file.key))
|
|
103
|
+
continue;
|
|
104
|
+
if (kept < MODEL_CALL_TOOL_MEDIA)
|
|
105
|
+
kept += 1;
|
|
106
|
+
else
|
|
107
|
+
capped.add(file.key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
84
110
|
for (const file of files) {
|
|
85
111
|
if (out.has(file.key))
|
|
86
112
|
continue;
|
|
87
|
-
const view =
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
const view = views.get(file.key);
|
|
114
|
+
if (capped.has(file.key)) {
|
|
115
|
+
out.set(file.key, [
|
|
116
|
+
textPart(noteFor(file.part, "newer files from tools took its place in this call; read_artifact shows it again")),
|
|
117
|
+
]);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
90
120
|
if (view.kind === "media") {
|
|
91
121
|
out.set(file.key, [mediaPart(file.part)]);
|
|
92
122
|
continue;
|
|
@@ -38,10 +38,10 @@ export function projectModelCall(request, files, readable = true) {
|
|
|
38
38
|
*/
|
|
39
39
|
export function liveFilesOf(request, readable = true) {
|
|
40
40
|
const live = new Map();
|
|
41
|
-
const add = (line, part) => {
|
|
41
|
+
const add = (line, part, origin) => {
|
|
42
42
|
const key = fileKeyOf(part);
|
|
43
43
|
if (!live.has(key))
|
|
44
|
-
live.set(key, { key, line, part });
|
|
44
|
+
live.set(key, { key, line, part, origin });
|
|
45
45
|
};
|
|
46
46
|
for (const entry of request.transcript) {
|
|
47
47
|
if (entry.turnId !== request.turnId)
|
|
@@ -52,13 +52,13 @@ export function liveFilesOf(request, readable = true) {
|
|
|
52
52
|
continue;
|
|
53
53
|
for (const part of event.content ?? [])
|
|
54
54
|
if (part.type === "media")
|
|
55
|
-
add(mediaReferenceLine(part, "uploaded", readable), part);
|
|
55
|
+
add(mediaReferenceLine(part, "uploaded", readable), part, "uploaded");
|
|
56
56
|
}
|
|
57
57
|
else if (entry.kind === "tool-results")
|
|
58
58
|
for (const result of entry.results)
|
|
59
59
|
if (result.kind === "completed")
|
|
60
60
|
for (const file of result.files ?? [])
|
|
61
|
-
add(mediaReferenceLine(file, { tool: result.toolName }, readable), file);
|
|
61
|
+
add(mediaReferenceLine(file, { tool: result.toolName }, readable), file, "tool");
|
|
62
62
|
}
|
|
63
63
|
return [...live.values()];
|
|
64
64
|
}
|
package/dist/tools/plan.d.ts
CHANGED
|
@@ -43,18 +43,18 @@ export interface PlanToolContext {
|
|
|
43
43
|
* throws.
|
|
44
44
|
*/
|
|
45
45
|
export declare function runPlanTool(effect: HostEffect, context: PlanToolContext): Promise<{
|
|
46
|
-
output?: undefined;
|
|
47
46
|
readonly kind: "failed";
|
|
48
47
|
readonly code: "plan.invalid_input";
|
|
49
48
|
readonly message: string;
|
|
49
|
+
readonly output?: undefined;
|
|
50
50
|
} | {
|
|
51
|
-
output?: undefined;
|
|
52
51
|
readonly kind: "failed";
|
|
53
52
|
readonly code: "plan.not_recorded";
|
|
54
53
|
readonly message: `The plan was not recorded: ${string}`;
|
|
54
|
+
readonly output?: undefined;
|
|
55
55
|
} | {
|
|
56
|
-
code?: undefined;
|
|
57
|
-
message?: undefined;
|
|
56
|
+
readonly code?: undefined;
|
|
57
|
+
readonly message?: undefined;
|
|
58
58
|
readonly kind: "completed";
|
|
59
59
|
readonly output: string;
|
|
60
60
|
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ToolResultFile } from "@nylorun/core/define";
|
|
2
|
+
import { type ArtifactRequester } from "@nylorun/core/harness-api";
|
|
3
|
+
import type { HostEffect } from "../run/durable.js";
|
|
4
|
+
import type { FailedFileOutcome, HarnessFiles, HarnessRun } from "../api/executors.js";
|
|
5
|
+
export interface MediaReadContext {
|
|
6
|
+
readonly channel: ArtifactRequester;
|
|
7
|
+
readonly run: HarnessRun;
|
|
8
|
+
readonly files: HarnessFiles;
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
type Outcome = {
|
|
12
|
+
readonly kind: "completed";
|
|
13
|
+
readonly output: {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly contentType: string;
|
|
16
|
+
readonly size: number;
|
|
17
|
+
};
|
|
18
|
+
readonly files: readonly ToolResultFile[];
|
|
19
|
+
} | FailedFileOutcome;
|
|
20
|
+
/** The path and media type of a `read` call our engine runs as media, or undefined for the sandbox's. */
|
|
21
|
+
export declare function mediaReadOf(effect: HostEffect): {
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly contentType: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
/** Runs a `read` of a media file (`mediaReadOf`). */
|
|
26
|
+
export declare function runMediaRead(effect: HostEffect, target: {
|
|
27
|
+
readonly path: string;
|
|
28
|
+
readonly contentType: string;
|
|
29
|
+
}, context: MediaReadContext): Promise<Outcome>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `read` of a sandbox file the turn's model reads as media (ADR-139): an image, a PDF, an Office
|
|
3
|
+
* document, audio or video, known by its extension. Our engine runs it here instead of in the
|
|
4
|
+
* sandbox, which reads text: it reads the bytes (`files.read`), stores them as an artifact of the
|
|
5
|
+
* session for the model only (`artifact.write` with `audience: "model"`, keyed by the call), and
|
|
6
|
+
* answers with the file beside a short result, so the model sees it in the turn's files.
|
|
7
|
+
*
|
|
8
|
+
* - **Decided before anything is stored.** A kind the model doesn't read (`fileView`) fails
|
|
9
|
+
* `sandbox.unreadable`, in words, with no read and no write.
|
|
10
|
+
* - **Checked by its first bytes.** A `.png` that doesn't start like a PNG fails
|
|
11
|
+
* `sandbox.binary_file`, so the model never sees bytes as an image they aren't.
|
|
12
|
+
* - **No output.** The artifact is the model's: no A2A task file, never listed. The user's files
|
|
13
|
+
* still come from `save_artifact` and the outputs folder.
|
|
14
|
+
* - **Text is the sandbox's.** Text files and SVG (text the model reads as such) go to the
|
|
15
|
+
* sandbox's `read` as before; so does everything when the run has no sandbox files.
|
|
16
|
+
*/
|
|
17
|
+
import { contentTypeFor, essence, inputLabel, matchesSignature, modelInputOf, } from "@nylorun/core/contracts";
|
|
18
|
+
import { HarnessApiError, writeArtifactBytes, } from "@nylorun/core/harness-api";
|
|
19
|
+
import { fileView } from "../loop/model/files.js";
|
|
20
|
+
/** The sandbox operation this module takes over for media files. */
|
|
21
|
+
const READ = "read";
|
|
22
|
+
const failed = (code, message) => ({
|
|
23
|
+
kind: "failed",
|
|
24
|
+
code,
|
|
25
|
+
message,
|
|
26
|
+
});
|
|
27
|
+
/** The path and media type of a `read` call our engine runs as media, or undefined for the sandbox's. */
|
|
28
|
+
export function mediaReadOf(effect) {
|
|
29
|
+
if (effect.kind !== "tool" || effect.target?.kind !== "sandbox" || effect.toolName !== READ)
|
|
30
|
+
return undefined;
|
|
31
|
+
const path = effect.input?.path;
|
|
32
|
+
if (typeof path !== "string" || path === "")
|
|
33
|
+
return undefined;
|
|
34
|
+
const contentType = contentTypeFor(path);
|
|
35
|
+
const input = modelInputOf(contentType);
|
|
36
|
+
// Text, SVG (an image no model reads as one, but text it reads) and unknown types: the sandbox's.
|
|
37
|
+
if (input === undefined || input === "text" || essence(contentType) === "image/svg+xml")
|
|
38
|
+
return undefined;
|
|
39
|
+
return { path, contentType };
|
|
40
|
+
}
|
|
41
|
+
/** The file's name, for the artifact: the last part of its path. */
|
|
42
|
+
const nameOf = (path) => path.split("/").filter(Boolean).at(-1) ?? path;
|
|
43
|
+
/** Runs a `read` of a media file (`mediaReadOf`). */
|
|
44
|
+
export async function runMediaRead(effect, target, context) {
|
|
45
|
+
const { channel, run, files, signal } = context;
|
|
46
|
+
const { path, contentType } = target;
|
|
47
|
+
const { limits, model } = run.start;
|
|
48
|
+
const name = nameOf(path);
|
|
49
|
+
const kind = inputLabel(modelInputOf(contentType));
|
|
50
|
+
const view = fileView({ mediaType: contentType, reference: { name } }, model, limits);
|
|
51
|
+
if (view.kind === "note")
|
|
52
|
+
return failed("sandbox.unreadable", `${path} can't be shown to you: ${view.why}. Describe it from what made it instead.`);
|
|
53
|
+
const read = await files.read(run, path, limits.modelFileBytes, signal);
|
|
54
|
+
if (read.kind === "missing")
|
|
55
|
+
return failed("sandbox.not_found", `No file at ${read.path}`);
|
|
56
|
+
if (read.kind === "failed")
|
|
57
|
+
return read;
|
|
58
|
+
const { bytes } = read;
|
|
59
|
+
if (matchesSignature(contentType, bytes) === false)
|
|
60
|
+
return failed("sandbox.binary_file", `${read.path} doesn't start like the ${kind} its name says, so it isn't shown. Check how it was made.`);
|
|
61
|
+
try {
|
|
62
|
+
const { artifact } = await writeArtifactBytes(channel, {
|
|
63
|
+
runId: run.runId,
|
|
64
|
+
// The call is the write: a repeat of it answers the version it stored.
|
|
65
|
+
key: effect.effectId,
|
|
66
|
+
effectId: effect.effectId,
|
|
67
|
+
name,
|
|
68
|
+
contentType,
|
|
69
|
+
audience: "model",
|
|
70
|
+
chunkBytes: limits.chunkBytes,
|
|
71
|
+
signal,
|
|
72
|
+
}, bytes);
|
|
73
|
+
return {
|
|
74
|
+
kind: "completed",
|
|
75
|
+
output: { path: read.path, contentType, size: artifact.size },
|
|
76
|
+
files: [
|
|
77
|
+
{
|
|
78
|
+
mediaType: contentType,
|
|
79
|
+
reference: {
|
|
80
|
+
artifactId: artifact.artifactId,
|
|
81
|
+
version: artifact.version,
|
|
82
|
+
name,
|
|
83
|
+
size: artifact.size,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
// A quota is the Tenant's to raise: the model learns why it can't look.
|
|
91
|
+
if (error instanceof HarnessApiError && error.code === "limit_exceeded")
|
|
92
|
+
return failed("sandbox.too_large", `${path} can't be shown to you: ${error.message}`);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nylorun/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0-beta",
|
|
4
4
|
"description": "Nylorun's TypeScript agent execution engine. See github.com/nylorun/agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"zod": "^4.6.7"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@nylorun/core": "0.
|
|
80
|
+
"@nylorun/core": "0.40.0-beta"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"zod": "^4.6.7"
|