@runappsai/agent 0.1.6 → 0.1.7

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/docs/tools.md CHANGED
@@ -48,6 +48,8 @@ execute(args, ctx)
48
48
  | `agent` | The agent. |
49
49
  | `callId` | The model's id for this call. |
50
50
  | `progress(made)` | Say whether this call brought anything new (see [Calls that go nowhere](#calls-that-go-nowhere)). |
51
+ | `parentId` | Set when another tool made this call (`ctx.callTool`, `tools.x()` in `run_js`): the result is for code, so the tool need not page it. |
52
+ | `callTool(name, args, { signal? })` | Call another of the agent's tools through the same gate; answers `{ status, text, details }` (see [Calling tools from `run_js`](#calling-tools-from-run_js)). |
51
53
 
52
54
  ```js
53
55
  const exportReport = defineTool({
@@ -142,6 +144,7 @@ defineTool({
142
144
  icon: "<svg …>", // the card's icon
143
145
  render: ({ args, status, result, details }) => chipsFor(args, result), // your element under the title, visible while folded
144
146
  outcome: ({ result }) => summaryOf(result), // beside the status mark ("Added", "$0.12")
147
+ file: ({ path }) => path, // the workspace file it is about: the card offers to open it
145
148
  },
146
149
  });
147
150
  ```
@@ -228,7 +231,7 @@ In a browser the server must allow your page's origin (CORS) and expose the `Mcp
228
231
  | Tool | | Option |
229
232
  |---|---|---|
230
233
  | `ask_user` | One to three questions to the user, with options or free text, when a request is unclear. | `askUser: false` removes it |
231
- | `run_js` | JavaScript the model writes, run in a Worker: no DOM, no network, a captured console, and `fs` bound to the workspace. The model computes, parses and transforms data with it instead of guessing, and runs skills' scripts. | `sandbox: false`, or `{ timeoutMs, network }` |
234
+ | `run_js` | JavaScript the model writes, run in a Worker: no DOM, no network, a captured console, and `tools` for the agent's other tools ([below](#calling-tools-from-run_js)). The model computes, parses and transforms data with it instead of guessing, and runs skills' scripts. Stopping the run ends the worker, even one stuck in a loop. | `sandbox: false`, or `{ timeoutMs, network, maxToolCalls, maxCodeChars }` |
232
235
  | `list_files` | Files under a folder, with sizes. | with a workspace |
233
236
  | `read_file` | A file, 2000 lines / 50 KB per call, `offset` and `limit` to continue; a PDF as text; a picture shown to a model that sees pictures. | |
234
237
  | `write_file` | Create or replace a file (`replace: true`: without reading it first, for a rewrite from scratch). | |
@@ -237,18 +240,36 @@ In a browser the server must allow your page's origin (CORS) and expose the `Mcp
237
240
  | `move_file`, `copy_file` | Move/rename or copy a file; never over an existing one. What was read of the source counts as read of the copy. | |
238
241
  | `search_files` | Search file contents. | |
239
242
 
243
+ ### Calling tools from `run_js`
244
+
245
+ The code has a `tools` object with the agent's other tools; there is no other way to the files. A large result the model only needs to compute over never enters the conversation:
246
+
247
+ ```js
248
+ const orders = JSON.parse(await tools.read_orders({ limit: 200 }));
249
+ return { count: orders.length, won: orders.filter((o) => o.profit > 0).length };
250
+ ```
251
+
252
+ - **The same gate as the model's calls**: the schema, the tool's `validate`, `onToolCall`, permissions and `confirm`. A call that fails or is declined throws what the model would have been told.
253
+ - **The whole result**: `await tools.x(args)` resolves with the tool's text, not cut to its `maxResultChars` (2 000 000 chars at most). `read_file` gives the whole file unless the code passes `offset` or `limit`, and `list_files` the whole list: their limits are for what the model has to read, and a tool of your own can do the same by looking at `ctx.parentId`. What `run_js` returns to the model is still limited to 24 000.
254
+ - **Not there**: `run_js` itself, `ask_user`, tools with `endsRun`, `vision` (code cannot look at a picture) or `display.hidden`, and a tool you mark `callableFromCode: false` (the model can still call it; the code is told it cannot).
255
+ - **One at a time**, in the order called, also under `Promise.all`.
256
+ - **Limits**: `maxToolCalls` (50 per run), `maxCodeChars` (20 000). `timeoutMs` counts the code's own time: waiting for a tool or the user's answer does not use it up.
257
+ - **It ends with the code**: when the code returns, times out or is stopped, a call still queued never starts and one in progress gets its signal aborted.
258
+
259
+ The chat shows these calls inside the `run_js` card. Apps see `tool_start`, `tool_update` and `tool_end` with `parentId` set to the `run_js` call. They are not added to the conversation, so a saved session keeps only the `run_js` card. A tool of your own can do the same with `ctx.callTool(name, args)`, which answers `{ status, text, details }`.
260
+
240
261
  ### Read before write
241
262
 
242
263
  The agent does not change a file from a stale or partial view of it — the user may be editing files while it works:
243
264
 
244
- - **Overwrite** (`write_file`, `fs.write` in `run_js`) of an existing file needs the model to have read all of it in this conversation. After a partial read, `write_file` refuses once and puts the unread lines in its error (up to one read's worth: 2000 lines or 50 KB); they count as read, so the next `write_file` goes through, or the error says from which `offset` to read on. `fs.write` just says to read the rest.
265
+ - **Overwrite** (`write_file`) of an existing file needs the model to have read all of it in this conversation. After a partial read, `write_file` refuses once and puts the unread lines in its error (up to one read's worth: 2000 lines or 50 KB); they count as read, so the next `write_file` goes through, or the error says from which `offset` to read on. `fs.write` just says to read the rest.
245
266
  - **`replace: true`** on `write_file` overwrites an existing file without reading it, for when the user asked for it to be rewritten from scratch. The result says what went unread (`Replaced /a.js (3 bytes). Its previous content (3 lines) was replaced without being read.`), so it shows in the tool card. The parameter exists only while the guard is on.
246
267
  - **Edit** (`edit_file`) needs it to have read the file — part is enough, since an edit only replaces the text it quotes.
247
- - **Delete** (`delete_file`, `fs.remove`) of a file it read is refused if the file changed since; a file it never read can be deleted.
268
+ - **Delete** (`delete_file`) of a file it read is refused if the file changed since; a file it never read can be deleted.
248
269
  - Any of them is refused when the file **changed since the model read it** — the user edited it in the files panel, your app changed a mounted document, another tab wrote it. The model is told why and reads the file again.
249
270
 
250
- New files can always be written, and the model's own writes count as read. `fs.read` in `run_js` counts as reading. A file's version is its modified time, size and a fingerprint of its content (files over 4 MB: time and size), so even a same-size change in the same instant shows. What the model has read is forgotten when the conversation is compacted or rewound, since it no longer has those contents. Turn it all off with `readBeforeWrite: false`.
271
+ New files can always be written, and the model's own writes count as read. Calls from `run_js` count like any other. A file's version is its modified time, size and a fingerprint of its content (files over 4 MB: time and size), so even a same-size change in the same instant shows. What the model has read is forgotten when the conversation is compacted or rewound, since it no longer has those contents. Turn it all off with `readBeforeWrite: false`.
251
272
 
252
- The file tools come with a workspace; `fileTools: ["read_file", "list_files", "search_files"]` gives a read-only agent, `fileTools: false` none. The system prompt mentions only the file tools the model has; with none (and no `run_js`) it says nothing about the directory or its skills.
273
+ The file tools come with a workspace; `fileTools: ["read_file", "list_files", "search_files"]` gives a read-only agent, `fileTools: false` none. The system prompt mentions only the file tools the model has; with none it says nothing about the directory or its skills, and `run_js` cannot reach the files either.
253
274
 
254
- `sandboxTool(workspace, options)` and `runInSandbox(workspace, code, input)` are exported if you want the sandbox on its own.
275
+ `sandboxTool(options)` and `runInSandbox(code, input, options)` are exported if you want the sandbox on its own.
package/docs/workspace.md CHANGED
@@ -162,7 +162,7 @@ Typing `/standup 2026-11-01` sends the expanded text. Arguments follow bash: `$1
162
162
 
163
163
  ## PDFs
164
164
 
165
- `read_file` (and `fs.read` inside `run_js`) reads a PDF as the text of its pages, each under a `--- page N ---` line; a scanned PDF without a text layer says so. The text comes from Mozilla's pdf.js, loaded from jsDelivr the first time a PDF is read (about 500 KB gzipped; nothing is added to this package), and is cached with the directory until the file changes.
165
+ `read_file` reads a PDF as the text of its pages, each under a `--- page N ---` line; a scanned PDF without a text layer says so. The text comes from Mozilla's pdf.js, loaded from jsDelivr the first time a PDF is read (about 500 KB gzipped; nothing is added to this package), and is cached with the directory until the file changes.
166
166
 
167
167
  ```js
168
168
  import { configurePdf } from "@runappsai/agent";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runappsai/agent",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "description": "Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.",
6
6
  "license": "MIT",