eve-hub 0.14.3 → 0.14.4

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # eve-hub
2
2
 
3
+ ## 0.14.4
4
+
5
+ ### Patch Changes
6
+
7
+ - `post_message` carries a post's images (`images`: sandbox paths, or `screenshot` on a local hub) and uploads the documents its markdown links point at (a sandbox path becomes `hub://upload/<id>` on a hosted hub, `file://` on a local one). Its text is capped at 700 characters, link targets excluded, and `![]()` is refused. `show` refuses images. `attach_image` is removed. Docs are written in markdown, which the app renders in Vercel's report design; HTML only for a bespoke layout.
8
+
9
+ Upgrade boundary: the hub no longer collects images uploaded by `attach_image`. A bot still on eve-hub 0.14.3 or older keeps a working `attach_image` (the upload succeeds), but its image never reaches a post. Redeploy every bot on 0.14.4 together with the hub that carries this release.
10
+
3
11
  ## 0.14.3
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -4,7 +4,7 @@ The bot-side code every hub agent shares (milestone M3 in [`docs/architecture`](
4
4
 
5
5
  | Module | What it is | Bots use it as |
6
6
  |---|---|---|
7
- | `tools/update_thread.ts`, `list_threads.ts`, `read_thread.ts`, `react.ts`, `show.ts`, `attach_image.ts`, `browser.ts` | Registry and workspace tools (`defineTool`) | `agent/tools/<same name>.ts` |
7
+ | `tools/update_thread.ts`, `list_threads.ts`, `read_thread.ts`, `react.ts`, `show.ts`, `browser.ts` | Registry and workspace tools (`defineTool`) | `agent/tools/<same name>.ts` |
8
8
  | `tools/create_thread.ts`, `post_message.ts`, `archive_thread.ts`, `unarchive_thread.ts`, `list_agents.ts`, `create_agent.ts`, `remove_agent.ts`, `restart_agent.ts`, `tag_threads.ts`, `apply_tags.ts` | The orchestrator's tools | `main`'s `agent/tools/<same name>.ts` |
9
9
  | `hooks/sandbox.ts` | Migrates legacy Docker sessions to the host sandbox (`defineHook`) | `agent/hooks/sandbox.ts` |
10
10
  | `instructions/main.ts`, `main-instructions.mjs` | main's instructions (`defineInstructions`), rendered at build time from the kit's `templates/main-instructions.md` (identity, role) between the shared templates, each in its own tag, so no workspace carries a copy | `main`'s `agent/instructions.ts`; workspace-only additions in `agent/role/*.md` (inside `<role>`) |
package/host-browser.js CHANGED
@@ -132,8 +132,8 @@ class SandboxBrowser {
132
132
  onClose;
133
133
  // One action at a time per browser. Tool calls in one model step run in
134
134
  // parallel, and Chromium drops a Page.captureScreenshot that's in flight
135
- // when a navigation commits: it never answers. So `open` + `attach_image
136
- // {screenshot}` side by side hung the turn. Serialized, the screenshot
135
+ // when a navigation commits: it never answers. So `open` + a
136
+ // screenshot side by side hung the turn. Serialized, the screenshot
137
137
  // waits for the page to load and then captures it.
138
138
  chain = Promise.resolve();
139
139
  exclusive(fn) {
@@ -0,0 +1,20 @@
1
+ export type SandboxFiles = {
2
+ readBinaryFile(input: {
3
+ path: string;
4
+ }): PromiseLike<Uint8Array | null | undefined>;
5
+ resolvePath(path: string): string;
6
+ };
7
+ export type Uploaded = {
8
+ id: string;
9
+ name: string;
10
+ size: number;
11
+ };
12
+ export declare const hostedHub: () => boolean;
13
+ export declare const IMAGE_FILE: RegExp;
14
+ /** A markdown link target that names a sandbox file: an absolute path, or one under the home directory. */
15
+ export declare const isSandboxPath: (target: string) => boolean;
16
+ export declare function readSandboxFile(sandbox: SandboxFiles, path: string): Promise<Uint8Array>;
17
+ export declare function uploadBytes(bytes: Uint8Array, name: string, what: string): Promise<Uploaded>;
18
+ export declare const uploadFile: (sandbox: SandboxFiles, path: string, what: string) => Promise<Uploaded>;
19
+ /** Where the human's app opens a sandbox document from: hub://upload/<id> on a hosted hub, file:// on a local one. */
20
+ export declare function documentUrl(sandbox: SandboxFiles, path: string, what: string): Promise<string>;
package/hub-upload.js ADDED
@@ -0,0 +1,42 @@
1
+ // A bot's sandbox files on the hub: the upload path `show` and `post_message` share. An image
2
+ // is uploaded on both hubs (it rides a message, store/attachments). A document goes as
3
+ // file:// on a local hub (the bot's files are the human's) and, on a hosted one (a deployed
4
+ // bot, or HUB_TOKEN set), as a snapshot uploaded to the hub (hub://upload/<sha>.<ext>),
5
+ // since the human's Mac can't read the sandbox.
6
+ import { basename } from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+ import { registryFetch } from "./registry-fetch.mjs";
9
+ export const hostedHub = () => Boolean(process.env.VERCEL || process.env.HUB_TOKEN);
10
+ export const IMAGE_FILE = /\.(png|jpe?g|gif|webp|heic)$/i;
11
+ /** A markdown link target that names a sandbox file: an absolute path, or one under the home directory. */
12
+ export const isSandboxPath = (target) => /^(\/|\$HOME\/|~\/)/.test(target);
13
+ // The sandbox resolves `~/`; `$HOME/` is the same place spelled as the shell does.
14
+ const sandboxPath = (path) => path.replace(/^\$HOME\//, "~/");
15
+ export async function readSandboxFile(sandbox, path) {
16
+ const bytes = await sandbox.readBinaryFile({ path: sandboxPath(path) });
17
+ if (!bytes)
18
+ throw new Error(`no file at ${path}`);
19
+ return bytes;
20
+ }
21
+ export async function uploadBytes(bytes, name, what) {
22
+ const res = await registryFetch(`/api/uploads`, {
23
+ method: "POST",
24
+ headers: { "content-type": "application/octet-stream", "x-filename": encodeURIComponent(name) },
25
+ body: new Uint8Array(bytes),
26
+ signal: AbortSignal.timeout(30_000),
27
+ }).catch((error) => {
28
+ throw new Error(`${what} failed: the upload didn't finish (${error.message})`);
29
+ });
30
+ const body = (await res.json().catch(() => ({})));
31
+ if (!res.ok || typeof body.id !== "string")
32
+ throw new Error(`${what} failed: the upload was refused (${body.error ?? res.status})`);
33
+ return { id: body.id, name: body.name ?? name, size: body.size ?? bytes.length };
34
+ }
35
+ export const uploadFile = async (sandbox, path, what) => uploadBytes(await readSandboxFile(sandbox, path), basename(path), what);
36
+ /** Where the human's app opens a sandbox document from: hub://upload/<id> on a hosted hub, file:// on a local one. */
37
+ export async function documentUrl(sandbox, path, what) {
38
+ if (hostedHub())
39
+ return `hub://upload/${(await uploadFile(sandbox, path, what)).id}`;
40
+ await readSandboxFile(sandbox, path);
41
+ return pathToFileURL(sandbox.resolvePath(sandboxPath(path))).href;
42
+ }
package/kit-modules.json CHANGED
@@ -17,7 +17,6 @@
17
17
  "skills/onboarding-profile",
18
18
  "tools/apply_tags",
19
19
  "tools/archive_thread",
20
- "tools/attach_image",
21
20
  "tools/bash",
22
21
  "tools/browser",
23
22
  "tools/create_agent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve-hub",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Bot-side code shared by every hub agent: registry tools, the roster hook, the eve channel, the host sandbox and browser, and model helpers.",
6
6
  "type": "module",
package/stubs.mjs CHANGED
@@ -10,7 +10,6 @@ export const KIT_FILES = {
10
10
  "tools/react.ts": ["React to a message with an emoji."],
11
11
  "tools/show.ts": ["Move the human's screen to a thread, DM, or message, or open a page or file beside the thread."],
12
12
  "tools/browser.ts": ["Its own headless browser, watched live in the Computer view."],
13
- "tools/attach_image.ts": ["Puts an image (a sandbox file or a browser screenshot) on this turn's reply."],
14
13
  "tools/view_image.ts": ["Shows the bot an image (a sandbox file or a browser screenshot) so it can see it."],
15
14
  "tools/update_thread.ts": ["Update a thread this bot is in: title, track, domain and summary."],
16
15
  "tools/list_threads.ts": ["Every workspace thread, from any session."],
@@ -50,7 +49,7 @@ export const MAIN_KIT_FILES = {
50
49
  // hub's machine: the sandbox hook (it migrates host sessions, and deletes any
51
50
  // sandbox that resolves /workspace as itself, which a Vercel Sandbox does),
52
51
  // the kit's bash (HostSandbox's root, the daemon's env; eve's own bash runs
53
- // instead), the browser and the screenshot paths of attach_image/view_image,
52
+ // instead), the browser and the screenshot path of view_image,
54
53
  // restart_hub (the hub's own code), memory (the workspace's files), and main's prune schedule (it cleans the hub machine's disk).
55
54
  // main's dash schedule stays: off the hub's machine it has no PR data (its lookup runs `gh`).
56
55
  export const DEPLOYED_KIT_FILES = new Set([
@@ -7,10 +7,11 @@
7
7
  - How: a `flow`, `sequence`, `chart` or `ask` form sent with `post_message`; load the `forms` skill for the shapes, tables and syntax.
8
8
  - Never draw with characters: no arrows, boxes, numbered timelines or tables in a code fence.
9
9
  - **Disclose one step at a time**
10
- - First bubble: the point or the question, in at most two sentences. The inbox and notifications show only its first line.
11
- - After a `---` line (blank lines around it): what the reader needs to act, and nothing more.
12
- - A linked file, PR or message: the full evidence, one click away, never pasted.
13
- - Be ready to go deep when asked: that is the next step, not this one.
10
+ - A post is at most 2 sentences (the point or the question; the inbox shows only its first line), then at most 3 bullets or one small table: what the reader needs to act, and nothing more. `post_message` refuses more than 700 characters.
11
+ - Depth (evidence, analysis, options, a long table) goes in a doc: write a markdown file in your sandbox and link it in the post, `[the analysis](/workspace/notes/analysis.md)`; `post_message` uploads it and the link opens it beside the thread, already styled. Never paste it. Write HTML only for a layout markdown can't hold, following the `vercel-design` skill when you have it.
12
+ - Images go in `post_message`'s `images` (sandbox paths), never in the text.
13
+ - A file reaches the human only as a markdown link in a post or through `show`, which upload it. A raw sandbox path in text is a file they can't open.
14
+ - Once you have posted into the thread, your turn's closing text is not posted: say nothing after a post.
14
15
  - Why: the first line is often all that's read; depth one click away costs nothing until it's wanted.
15
16
  - **Say only what's new**
16
17
  - Post only what changes what the reader does next; react when nothing is new.
@@ -1,7 +1,15 @@
1
+ export declare const MAX_CHARS = 700;
2
+ /** The characters the cap counts: the text without its links' targets. */
3
+ export declare const postLength: (text: string) => number;
4
+ /** The error for a text the thread shouldn't carry, or null. */
5
+ export declare function textError(text: string): string | null;
6
+ /** The text with each sandbox-path link target replaced by where the human's app opens it. */
7
+ export declare function rewriteDocLinks(text: string, open: (path: string) => Promise<string>): Promise<string>;
1
8
  declare const _default: import("eve/tools").ToolDefinition<{
2
9
  threadId?: string | undefined;
3
10
  agent?: string | undefined;
4
11
  text: string;
12
+ images?: string[] | undefined;
5
13
  policy?: "abort" | "queue" | "steer" | undefined;
6
14
  status?: "done" | "planning" | "reviewing" | "working" | undefined;
7
15
  metadata?: {
@@ -27,6 +35,7 @@ declare const _default: import("eve/tools").ToolDefinition<{
27
35
  threadId?: string | undefined;
28
36
  agent?: string | undefined;
29
37
  text: string;
38
+ images?: string[] | undefined;
30
39
  policy?: "abort" | "queue" | "steer" | undefined;
31
40
  status?: "done" | "planning" | "reviewing" | "working" | undefined;
32
41
  metadata?: {
@@ -1,14 +1,19 @@
1
1
  import { defineTool } from "eve/tools";
2
2
  import { z } from "zod";
3
+ import { documentUrl, hostedHub, isSandboxPath, uploadBytes, uploadFile } from "../hub-upload.js";
3
4
  import { registryFetch } from "../registry-fetch.mjs";
4
5
  // Posts as you into a thread or DM, from whichever session you're in. With no
5
- // target it posts into the thread you're in, as part of the running turn: it
6
- // carries the turn's id and the images collected so far,
7
- // and if it's your turn's last act (alone or with reactions), your end-of-turn text isn't posted. Into
8
- // another thread, mentions wake bots exactly as your replies do; posting into
9
- // a bot's DM wakes that bot; archived threads refuse it. Your session in the
10
- // target thread, if any, isn't woken; it sees the message as yours the next
11
- // time it's addressed.
6
+ // target it posts into the thread you're in, as part of the running turn: once
7
+ // a turn has posted there, its end-of-turn text isn't posted. Into another
8
+ // thread, mentions wake bots exactly as your replies do; posting into a bot's
9
+ // DM wakes that bot; archived threads refuse it. Your session in the target
10
+ // thread, if any, isn't woken; it sees the message as yours the next time it's
11
+ // addressed.
12
+ //
13
+ // The text is capped (MAX_CHARS, link targets excluded): depth goes in a
14
+ // document the post links by its sandbox path, which is uploaded and the link
15
+ // rewritten to where the hub serves it (hub-upload.ts). Images go in `images`
16
+ // and ride the post.
12
17
  //
13
18
  // `policy` is how a post reaches the one bot it @-mentions: queue (default)
14
19
  // waits for that bot's turn to end, steer folds into its running turn, abort
@@ -17,12 +22,48 @@ import { registryFetch } from "../registry-fetch.mjs";
17
22
  // A status post: `status` is the thread's phase after it (the hub checks the
18
23
  // move), the text is its summary, `metadata` its PR and sha. The hub keeps the
19
24
  // latest one per bot and thread for the workspace state and the Dash.
25
+ export const MAX_CHARS = 700;
26
+ const LINK = /\[([^\]]*)\]\(([^)\s]+)\)/g;
27
+ const IMAGE_SYNTAX = /!\[[^\]]*\]\([^)]*\)/;
28
+ const SCREENSHOT = "screenshot";
29
+ /** The characters the cap counts: the text without its links' targets. */
30
+ export const postLength = (text) => text.replace(LINK, (_, label) => `[${label}]()`).length;
31
+ /** The error for a text the thread shouldn't carry, or null. */
32
+ export function textError(text) {
33
+ if (IMAGE_SYNTAX.test(text))
34
+ return "Images don't go in the text: pass the file's sandbox path in `images` and it shows inline";
35
+ if (postLength(text) > MAX_CHARS)
36
+ return "Too long: move the detail into a doc and link it";
37
+ return null;
38
+ }
39
+ /** The text with each sandbox-path link target replaced by where the human's app opens it. */
40
+ export async function rewriteDocLinks(text, open) {
41
+ const links = [...text.matchAll(LINK)].filter((m) => isSandboxPath(m[2]));
42
+ const urls = await Promise.all(links.map((m) => open(m[2])));
43
+ let out = "", at = 0;
44
+ links.forEach((m, i) => {
45
+ const start = m.index + m[0].length - m[2].length - 1;
46
+ out += text.slice(at, start) + urls[i];
47
+ at = start + m[2].length;
48
+ });
49
+ return out + text.slice(at);
50
+ }
51
+ async function screenshot(sessionId) {
52
+ if (hostedHub())
53
+ throw new Error("a browser screenshot needs the hub's machine: on a hosted hub save the image to a sandbox file and pass its path in `images`");
54
+ const { browserFor } = await import("../host-browser.js");
55
+ const browser = await browserFor(sessionId);
56
+ if (browser.url === "about:blank")
57
+ throw new Error("your browser has no page open; open one with the browser tool first");
58
+ return browser.screenshot();
59
+ }
20
60
  export default defineTool({
21
- description: "Post a message as you. Leave out threadId and agent to post into the thread you're in, while you work: posting doesn't end your turn, and once your turn has posted into this thread, its end-of-turn text isn't posted, so put your result in a post. Or post into another workspace thread or a bot's DM. @-mentions wake bots the same way your replies do (at most one, never yourself); `@all` wakes every participant; each bot's gate decides whether it replies. Posting into a bot's DM wakes that bot. Archived threads are refused. `policy` says how a post reaches the one bot it @-mentions: queue (default) runs as its next turn, or starts one now if it is idle; steer lands in its RUNNING turn at the next step boundary and the bot folds it in without a restart, to correct course mid-turn; abort stops its turn in that thread (running commands are killed, the process keeps running) and the text starts its fresh turn, \"stop, do this instead\". Steer and abort need exactly one @-mention, not `@all`, and cut into work already under way: use them only to change what a running turn is doing. A status post sets the thread's phase: planning, working, reviewing or done; allowed moves are start → planning or working, planning → working, working → reviewing, reviewing → working (fix first), planning (rethink) or done. Any other move is refused with the allowed next phases. The text is a phase marker, not a report: at most 8 plain words on what is happening now (\"Building the input-count fix\"), with no bot or role names, no restating the phase, no parentheticals. Test results, branch names and caveats go in a separate message. The PR URL and sha go in metadata, never in the text.",
61
+ description: "Post a message as you. Leave out threadId and agent to post into the thread you're in, while you work: posting doesn't end your turn, and once your turn has posted into this thread, its end-of-turn text isn't posted, so put your result in a post. Or post into another workspace thread or a bot's DM. The text is at most 700 characters (link targets don't count): the point in 2 sentences, then at most 3 bullets or one small table. Depth goes in a document: write it to a file and link it in the text by its sandbox path, `[the plan](/workspace/plan.md)`; the file is uploaded and the link opens it beside the thread. Images go in `images` (sandbox paths; `screenshot` for your browser's page on a local hub) and show inline; never write `![]()`. @-mentions wake bots the same way your replies do (at most one, never yourself); `@all` wakes every participant; each bot's gate decides whether it replies. Posting into a bot's DM wakes that bot. Archived threads are refused. `policy` says how a post reaches the one bot it @-mentions: queue (default) runs as its next turn, or starts one now if it is idle; steer lands in its RUNNING turn at the next step boundary and the bot folds it in without a restart, to correct course mid-turn; abort stops its turn in that thread (running commands are killed, the process keeps running) and the text starts its fresh turn, \"stop, do this instead\". Steer and abort need exactly one @-mention, not `@all`, and cut into work already under way: use them only to change what a running turn is doing. A status post sets the thread's phase: planning, working, reviewing or done; allowed moves are start → planning or working, planning → working, working → reviewing, reviewing → working (fix first), planning (rethink) or done. Any other move is refused with the allowed next phases. The text is a phase marker, not a report: at most 8 plain words on what is happening now (\"Building the input-count fix\"), with no bot or role names, no restating the phase, no parentheticals. Test results, branch names and caveats go in a separate message. The PR URL and sha go in metadata, never in the text.",
22
62
  inputSchema: z.object({
23
63
  threadId: z.string().optional().describe("Another thread's id, e.g. thr_0002, or a DM id, dm-<bot>. Omit it to post into the thread you're in."),
24
64
  agent: z.string().optional().describe("Post into this bot's DM instead of a thread."),
25
- text: z.string().describe("The message. @-mention the one bot who should act. On a status post: at most 8 plain words on what is happening now."),
65
+ text: z.string().describe("The message, at most 700 characters (link targets don't count). A markdown link to a sandbox path uploads that document. @-mention the one bot who should act. On a status post: at most 8 plain words on what is happening now."),
66
+ images: z.array(z.string()).optional().describe("Images to show inline on this post: sandbox paths (PNG, JPEG, GIF or WebP, up to 3 MB each), or `screenshot` for your browser's current page (local hub only)."),
26
67
  policy: z.enum(["queue", "steer", "abort"]).optional().describe("How the post reaches the one bot it @-mentions: queue (default), steer into its running turn, or abort its turn and start a fresh one on this text."),
27
68
  status: z.enum(["planning", "working", "reviewing", "done"]).optional().describe("The thread's phase after this post. Makes it a status post."),
28
69
  metadata: z
@@ -39,12 +80,19 @@ export default defineTool({
39
80
  .describe("With a verdict: what the human has to pick. [] when nothing; required with ship."),
40
81
  tested: z.string().optional().describe("With a verdict: what you ran to check it, in a sentence (shown on the Dash row)."),
41
82
  }),
42
- async execute({ threadId, agent, text, policy, status, metadata, verdict, decisions, tested }, ctx) {
83
+ async execute({ threadId, agent, text, images, policy, status, metadata, verdict, decisions, tested }, ctx) {
84
+ const bad = textError(text);
85
+ if (bad)
86
+ throw new Error(bad);
43
87
  const target = threadId ?? (agent ? `dm-${agent.replace(/^@/, "")}` : "here");
88
+ let sandbox;
89
+ const files = async () => (sandbox ??= await ctx.getSandbox());
90
+ const posted = await rewriteDocLinks(text, async (path) => documentUrl(await files(), path, "post_message"));
91
+ const attachments = await Promise.all((images ?? []).map(async (image) => image === SCREENSHOT ? uploadBytes(await screenshot(ctx.session.id), "screenshot.png", "post_message") : uploadFile(await files(), image, "post_message")));
44
92
  const res = await registryFetch(`/api/threads/${encodeURIComponent(target)}/messages`, {
45
93
  method: "POST",
46
94
  headers: { "content-type": "application/json" },
47
- body: JSON.stringify({ text, sessionId: ctx.session.id, ...(policy ? { policy } : {}), ...(status ? { status } : {}), ...(metadata ? { metadata } : {}), ...(verdict ? { verdict } : {}), ...(decisions ? { decisions } : {}), ...(tested ? { tested } : {}) }),
95
+ body: JSON.stringify({ text: posted, sessionId: ctx.session.id, ...(attachments.length ? { attachments: attachments.map(({ id, name }) => ({ id, name })) } : {}), ...(policy ? { policy } : {}), ...(status ? { status } : {}), ...(metadata ? { metadata } : {}), ...(verdict ? { verdict } : {}), ...(decisions ? { decisions } : {}), ...(tested ? { tested } : {}) }),
48
96
  });
49
97
  if (!res.ok)
50
98
  throw new Error(`post_message failed: ${res.status} ${await res.text()}`);
package/tools/show.js CHANGED
@@ -1,23 +1,22 @@
1
1
  import { basename } from "node:path";
2
- import { pathToFileURL } from "node:url";
3
2
  import { defineTool } from "eve/tools";
4
3
  import { z } from "zod";
4
+ import { documentUrl, IMAGE_FILE } from "../hub-upload.js";
5
5
  import { registryFetch } from "../registry-fetch.mjs";
6
6
  // Moves the human's workspace UI, e.g. to a thread you just opened or a
7
7
  // message they need to look at, or opens a page or file in the pane beside
8
8
  // the thread. They see a note saying you did it and why.
9
9
  //
10
- // A file goes as file:// on a local hub (the bot's files are the human's) and,
11
- // on a hosted hub (a deployed bot, or HUB_TOKEN set), as a snapshot uploaded to the hub
12
- // (hub://upload/<sha>.<ext>), since the human's Mac can't read the sandbox.
10
+ // A file opens from where the hub can serve it (hub-upload.ts). An image is
11
+ // refused: it belongs on a post, where the thread shows it inline.
13
12
  export default defineTool({
14
- description: "Move the human's screen to a place in the workspace: a thread (threadId), a bot's DM (agent), optionally scrolled to and highlighting one message (messageId). Or open a web page (uri) or a file from your sandbox (path: markdown, text or code, an image, a PDF; line for text) in a tab beside this thread, without moving them. Use when you want them to look at something now. Rarely move their screen: only when they must look now.",
13
+ description: "Move the human's screen to a place in the workspace: a thread (threadId), a bot's DM (agent), optionally scrolled to and highlighting one message (messageId). Or open a web page (uri) or a document from your sandbox (path: markdown, html, text or code, a PDF; line for text) in a tab beside this thread, without moving them. Not for images: those go in post_message's `images`. A document the human should keep is better linked from a post (post_message uploads a sandbox path in a markdown link); show only when they must look now. Rarely move their screen.",
15
14
  inputSchema: z.object({
16
15
  threadId: z.string().optional().describe("Thread id, e.g. thr_0002."),
17
16
  agent: z.string().optional().describe("Open this bot's DM instead of a thread."),
18
17
  messageId: z.string().optional().describe("Also scroll to and highlight this message, like opening a link to it."),
19
18
  uri: z.string().optional().describe("An http(s) page to open beside the thread."),
20
- path: z.string().optional().describe("A file in your sandbox to open beside the thread, e.g. /workspace/repo/PLAN.md."),
19
+ path: z.string().optional().describe("A document in your sandbox to open beside the thread, e.g. /workspace/repo/PLAN.md. Not an image."),
21
20
  line: z.number().int().positive().optional().describe("With path: the line a text or code file opens at."),
22
21
  reason: z.string().describe("One short line shown to the human, e.g. 'the plan is ready for review'."),
23
22
  }),
@@ -26,28 +25,12 @@ export default defineTool({
26
25
  throw new Error("pass path or uri, not both");
27
26
  if (line && !path)
28
27
  throw new Error("line goes with path");
28
+ if (path && IMAGE_FILE.test(path))
29
+ throw new Error(`${basename(path)} is an image: post it with post_message's images instead, so it shows in the thread`);
29
30
  let open = uri, title;
30
31
  if (path) {
31
32
  title = basename(path);
32
- const sandbox = await ctx.getSandbox();
33
- if (process.env.VERCEL || process.env.HUB_TOKEN) {
34
- const bytes = await sandbox.readBinaryFile({ path });
35
- if (!bytes)
36
- throw new Error(`no file at ${path}`);
37
- const res = await registryFetch(`/api/uploads`, {
38
- method: "POST",
39
- headers: { "content-type": "application/octet-stream", "x-filename": encodeURIComponent(basename(path)) },
40
- body: new Uint8Array(bytes),
41
- signal: AbortSignal.timeout(30_000),
42
- });
43
- const body = await res.json().catch(() => ({}));
44
- if (!res.ok)
45
- throw new Error(`show failed: the upload was refused (${body.error ?? res.status})`);
46
- open = `hub://upload/${body.id}`;
47
- }
48
- else {
49
- open = pathToFileURL(sandbox.resolvePath(path)).href;
50
- }
33
+ open = await documentUrl(await ctx.getSandbox(), path, "show");
51
34
  }
52
35
  const res = await registryFetch(`/api/ui`, {
53
36
  method: "POST",
@@ -1,6 +1,7 @@
1
1
  // The `view_image` tool: shows the bot an image so it can actually see it.
2
- // `read_file` only reads text and `attach_image` posts an image without the
3
- // bot seeing it, so without this a bot can take a screenshot but not check it.
2
+ // `read_file` only reads text and post_message's `images` posts an image
3
+ // without the bot seeing it, so without this a bot can take a screenshot but
4
+ // not check it.
4
5
  // The bytes come from the bot's sandbox (a file path) or its browser (a
5
6
  // screenshot) and reach the model as an image part of the tool result.
6
7
  //
@@ -101,7 +102,7 @@ export function toModelOutput(output) {
101
102
  ]);
102
103
  }
103
104
  export default defineTool({
104
- description: "Look at an image yourself: a PNG, JPEG, GIF, or WebP file from your sandbox (path), or a screenshot of your browser's current page (screenshot: true). The image comes back to you so you can see it and describe it. Use it to check screenshots and captures before you attach or report them; `read_file` can't read images and `attach_image` only posts them. Large images are scaled to 1568px on the long edge.",
105
+ description: "Look at an image yourself: a PNG, JPEG, GIF, or WebP file from your sandbox (path), or a screenshot of your browser's current page (screenshot: true). The image comes back to you so you can see it and describe it. Use it to check screenshots and captures before you post them (post_message `images`); `read_file` can't read images. Large images are scaled to 1568px on the long edge.",
105
106
  inputSchema: z.object({
106
107
  path: z.string().optional().describe("Image file in your sandbox, e.g. /tmp/shot.png."),
107
108
  screenshot: z.boolean().optional().describe("View a screenshot of your browser instead of a file."),
@@ -1,16 +0,0 @@
1
- declare const _default: import("eve/tools").ToolDefinition<{
2
- path?: string | undefined;
3
- screenshot?: boolean | undefined;
4
- }, {
5
- attachment: any;
6
- note: string;
7
- }> & {
8
- execute(input: {
9
- path?: string | undefined;
10
- screenshot?: boolean | undefined;
11
- }, ctx: import("eve/tools").ToolContext): Promise<{
12
- attachment: any;
13
- note: string;
14
- }>;
15
- };
16
- export default _default;
@@ -1,51 +0,0 @@
1
- // The `attach_image` tool: puts an image on the bot's reply. The bytes come
2
- // from the bot's own sandbox (a file path) or its browser (a screenshot) and
3
- // go to the registry's upload store; the registry posts them with the turn's
4
- // final message.
5
- import { basename } from "node:path";
6
- import { defineTool } from "eve/tools";
7
- import { z } from "zod";
8
- import { browserFor } from "../host-browser.js";
9
- import { registryFetch } from "../registry-fetch.mjs";
10
- export default defineTool({
11
- description: "Attach an image to your reply in this thread: a PNG, JPEG, GIF, or WebP file from your sandbox (path), or a screenshot of your browser's current page (screenshot: true). Up to 3 MB each. It is posted with your final message for this turn, so mention what it shows there. Never write `![]()` for it.",
12
- inputSchema: z.object({
13
- path: z.string().optional().describe("Image file in your sandbox, e.g. /workspace/out/chart.png."),
14
- screenshot: z.boolean().optional().describe("Attach a screenshot of your browser instead of a file."),
15
- }),
16
- async execute({ path, screenshot }, ctx) {
17
- if (Boolean(path) === Boolean(screenshot))
18
- throw new Error("pass exactly one of path or screenshot");
19
- let bytes;
20
- let name;
21
- if (screenshot) {
22
- const browser = await browserFor(ctx.session.id);
23
- if (browser.url === "about:blank")
24
- throw new Error("your browser has no page open; open one with the browser tool first");
25
- bytes = await browser.screenshot();
26
- name = "screenshot.png";
27
- }
28
- else {
29
- const sandbox = await ctx.getSandbox();
30
- const file = await sandbox.readBinaryFile({ path: path });
31
- if (!file)
32
- throw new Error(`no file at ${path}`);
33
- bytes = file;
34
- name = basename(path);
35
- }
36
- const res = await registryFetch(`/api/uploads`, {
37
- method: "POST",
38
- headers: { "content-type": "application/octet-stream", "x-filename": encodeURIComponent(name) },
39
- body: new Uint8Array(bytes),
40
- signal: AbortSignal.timeout(30_000),
41
- }).catch((error) => {
42
- throw new Error(`attach failed: the upload didn't finish (${error.message})`);
43
- });
44
- const body = await res.json().catch(() => ({}));
45
- if (!res.ok)
46
- throw new Error(`attach failed: ${body.error ?? res.status}`);
47
- // The action.result stream event carries this reference on the exact turn
48
- // that owns the call. Uploading bytes does not mutate session lifecycle.
49
- return { attachment: body, note: "posts with your final message" };
50
- },
51
- });