@runappsai/agent 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +162 -2
- package/dist/agent-core.umd.js +266 -0
- package/dist/agent.d.ts +222 -0
- package/dist/agent.js +1331 -0
- package/dist/agent.umd.js +732 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +4 -0
- package/dist/chat-theme.d.ts +24 -0
- package/dist/chat-theme.js +101 -0
- package/dist/chat.d.ts +271 -0
- package/dist/chat.js +4097 -0
- package/dist/compaction.d.ts +48 -0
- package/dist/compaction.js +208 -0
- package/dist/completion.d.ts +29 -0
- package/dist/completion.js +88 -0
- package/dist/context.d.ts +44 -0
- package/dist/context.js +177 -0
- package/dist/debug-panel.d.ts +40 -0
- package/dist/debug-panel.js +262 -0
- package/dist/dialogs.d.ts +7 -0
- package/dist/dialogs.js +231 -0
- package/dist/directory-fs.d.ts +5 -0
- package/dist/directory-fs.js +118 -0
- package/dist/dom.d.ts +83 -0
- package/dist/dom.js +163 -0
- package/dist/edit.d.ts +22 -0
- package/dist/edit.js +133 -0
- package/dist/file-guard.d.ts +46 -0
- package/dist/file-guard.js +153 -0
- package/dist/file-tools.d.ts +16 -0
- package/dist/file-tools.js +339 -0
- package/dist/files-panel.d.ts +60 -0
- package/dist/files-panel.js +613 -0
- package/dist/index.cjs +4848 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +44 -0
- package/dist/json-schema.d.ts +3 -0
- package/dist/json-schema.js +141 -0
- package/dist/llm.d.ts +95 -0
- package/dist/llm.js +5 -0
- package/dist/markdown.d.ts +4 -0
- package/dist/markdown.js +265 -0
- package/dist/mcp.d.ts +82 -0
- package/dist/mcp.js +325 -0
- package/dist/node.cjs +402 -0
- package/dist/node.d.ts +78 -0
- package/dist/node.js +432 -0
- package/dist/pdf.d.ts +52 -0
- package/dist/pdf.js +77 -0
- package/dist/provider.d.ts +135 -0
- package/dist/provider.js +181 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.js +219 -0
- package/dist/select.d.ts +30 -0
- package/dist/select.js +185 -0
- package/dist/skill-zips.d.ts +28 -0
- package/dist/skill-zips.js +123 -0
- package/dist/skills.d.ts +20 -0
- package/dist/skills.js +111 -0
- package/dist/templates.d.ts +24 -0
- package/dist/templates.js +136 -0
- package/dist/tool.d.ts +28 -0
- package/dist/tool.js +102 -0
- package/dist/types.d.ts +571 -0
- package/dist/types.js +7 -0
- package/dist/ui.cjs +6246 -0
- package/dist/ui.d.ts +6 -0
- package/dist/ui.js +11 -0
- package/dist/vlist.d.ts +80 -0
- package/dist/vlist.js +277 -0
- package/dist/workspace.d.ts +343 -0
- package/dist/workspace.js +1203 -0
- package/dist/zip.d.ts +26 -0
- package/dist/zip.js +204 -0
- package/docs/agent.md +228 -0
- package/docs/chat-ui.md +307 -0
- package/docs/node.md +135 -0
- package/docs/providers.md +176 -0
- package/docs/reference.md +143 -0
- package/docs/skills.md +131 -0
- package/docs/tools.md +254 -0
- package/docs/workspace.md +198 -0
- package/package.json +59 -4
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Workspace and files
|
|
2
|
+
|
|
3
|
+
A workspace is the directory the agent works in. Give an agent one and it gets the file tools (`list_files`, `read_file`, `write_file`, `edit_file`, `delete_file`, `search_files`), skills, saved sessions, memory notes and prompt templates.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { openWorkspace, createAgent } from "@runappsai/agent";
|
|
7
|
+
|
|
8
|
+
const workspace = await openWorkspace(provider, { id: "default" });
|
|
9
|
+
await workspace.write("/notes/todo.md", "- ship v2\n");
|
|
10
|
+
|
|
11
|
+
const agent = createAgent(provider, { workspace });
|
|
12
|
+
await agent.prompt("Add 'write the launch post' to /notes/todo.md");
|
|
13
|
+
console.log(await workspace.readText("/notes/todo.md"));
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Where the files live
|
|
17
|
+
|
|
18
|
+
By default a workspace is a virtual file tree in **IndexedDB**: one database per app, in which every `id` is a separate directory. The same id opens the same files again after a reload and in other tabs.
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
openWorkspace(provider, {
|
|
22
|
+
id: "default", // which directory
|
|
23
|
+
project: "my-app", // which app's database (default: the provider's name)
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**A directory per conversation.** The chat UI takes a function and opens a directory under each session's id, so every conversation has its own files; resuming a conversation reopens them:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
renderChat(el, { provider, workspace: (sessionId) => openWorkspace(provider, { id: sessionId }) });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Pass one workspace instead (`workspace: await openWorkspace(provider, { id: "shared" })`) and every conversation shares the same files.
|
|
34
|
+
|
|
35
|
+
**A real folder.** `dir` makes a folder the directory itself — any `AgentFS`. In a browser, a folder the user picks (Chromium's File System Access API) or the origin-private file system:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { directoryFS } from "@runappsai/agent/ui";
|
|
39
|
+
|
|
40
|
+
const handle = await showDirectoryPicker({ mode: "readwrite" });
|
|
41
|
+
const workspace = await openWorkspace(provider, { id: "project", dir: directoryFS(handle, { description: "the user's project folder" }) });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In Node, a folder on disk — and `store` keeps the rest (sessions, the user's skills) on disk too instead of in memory (see [Node and the command line](node.md)):
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { nodeFS, nodeStore } from "@runappsai/agent/node";
|
|
48
|
+
|
|
49
|
+
const workspace = await openWorkspace(provider, { id: "project", dir: nodeFS(process.cwd()), store: nodeStore() });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Files then land in that folder; sessions and the user's skills stay in the workspace's store (IndexedDB in a browser).
|
|
53
|
+
|
|
54
|
+
**Where a workspace keeps things.** In a browser, IndexedDB. Where there is none (Node, Deno), memory — gone when the process ends — unless you give it a `store`: `nodeStore(folder)`, or your own `WorkspaceStoreFactory` (`open(dbName, space)` → a `WorkspaceStore`; see `nodeStore` in `src/node.ts` for a complete one).
|
|
55
|
+
|
|
56
|
+
## Reading and writing
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
await workspace.write("/data/report.csv", csvText); // text
|
|
60
|
+
await workspace.write("/img/logo.png", bytes, "image/png"); // bytes, with a type
|
|
61
|
+
const { data, size, contentType } = await workspace.read("/img/logo.png");
|
|
62
|
+
const text = await workspace.readText("/data/report.csv"); // throws for binary files
|
|
63
|
+
const pdf = await workspace.readAsText("/docs/spec.pdf"); // { text, kind: "pdf" } — see PDFs
|
|
64
|
+
await workspace.delete("/data/old.csv");
|
|
65
|
+
const files = await workspace.list("/data"); // [{ path, size, contentType, mtime }]
|
|
66
|
+
await workspace.exists("/data/report.csv");
|
|
67
|
+
await workspace.clearWork(); // empty the directory (skills stay)
|
|
68
|
+
await workspace.destroy(); // drop this directory and its sessions
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Paths are absolute and POSIX-style (`/a/b.txt`); `..` is resolved. Text is stored as strings, everything else as bytes.
|
|
72
|
+
|
|
73
|
+
## Mounting your app's data
|
|
74
|
+
|
|
75
|
+
Mount an `AgentFS` at a path and the agent reads (and, if you allow it, edits) your app's own data as files: the document being edited, a project's pages, a cloud folder.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const idOf = (path) => path.slice(1, -".xml".length); // "/page-1.xml" → "page-1"
|
|
79
|
+
const fileOf = (page) => ({ path: `/${page.id}.xml`, size: page.xml.length, mtime: page.updatedAt });
|
|
80
|
+
|
|
81
|
+
const pagesFS = {
|
|
82
|
+
description: "the diagram's pages, one XML file per page",
|
|
83
|
+
|
|
84
|
+
// Required: every file under `prefix` ("/" for all), and a file's content.
|
|
85
|
+
async list(prefix) {
|
|
86
|
+
return diagram.pages.map(fileOf).filter((f) => prefix === "/" || f.path.startsWith(prefix));
|
|
87
|
+
},
|
|
88
|
+
async read(path) {
|
|
89
|
+
const page = diagram.getPage(idOf(path));
|
|
90
|
+
if (!page) throw new Error(`No such file: ${path}`);
|
|
91
|
+
return page.xml; // text as a string, anything else as a Uint8Array
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// Optional: leave write and delete out for a read-only mount.
|
|
95
|
+
async write(path, content) { // creates or replaces
|
|
96
|
+
const xml = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
97
|
+
if (diagram.getPage(idOf(path))) diagram.setPageXml(idOf(path), xml);
|
|
98
|
+
else diagram.addPage(idOf(path), xml);
|
|
99
|
+
},
|
|
100
|
+
async delete(path) {
|
|
101
|
+
if (!diagram.getPage(idOf(path))) throw new Error(`No such file: ${path}`);
|
|
102
|
+
diagram.removePage(idOf(path));
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Optional: a quick look at one file (without it, the workspace finds the file in list()).
|
|
106
|
+
async stat(path) {
|
|
107
|
+
const page = diagram.getPage(idOf(path));
|
|
108
|
+
return page ? fileOf(page) : null;
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
// Optional: apply edit_file's replacements yourself, in place.
|
|
112
|
+
async edit(path, edits) {
|
|
113
|
+
const page = diagram.getPage(idOf(path));
|
|
114
|
+
if (!page) throw new Error(`No such file: ${path}`);
|
|
115
|
+
diagram.transaction(() => { // one undo step, other users' changes kept
|
|
116
|
+
for (const { oldText, newText } of edits) {
|
|
117
|
+
const at = page.xml.indexOf(oldText);
|
|
118
|
+
if (at < 0 || page.xml.indexOf(oldText, at + 1) >= 0) throw new Error(`"${oldText}" must appear exactly once in ${path}`);
|
|
119
|
+
page.replaceRange(at, at + oldText.length, newText);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
workspace.mount("/diagram", pagesFS);
|
|
126
|
+
// The agent sees /diagram/page-1.xml, … and its description in the system prompt.
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Editing.** The agent's `edit_file` sends only the replacements — `{ oldText, newText }` pairs, each `oldText` found once in the original — never the whole file. What happens next is up to the mount:
|
|
130
|
+
|
|
131
|
+
- **With `edit(path, edits)`**, the mount gets those replacements as they are and changes its data in place: one node of a document, a range in an editor's buffer, a transaction that keeps other users' concurrent changes and makes one undo step. Throw an Error with a readable message when an edit does not apply; the model sees it and tries again. Use the exported `applyEdits(path, text, edits)` if you want the workspace's own matching (exact first, then tolerant of curly quotes, dashes and trailing spaces).
|
|
132
|
+
- **Without it**, the workspace reads the file, applies the replacements and writes the whole result back with `write` — fine for files; a mount whose `write` has to rebuild a large structure from the whole text should implement `edit`.
|
|
133
|
+
|
|
134
|
+
So a mount with `read` and `write` supports `read_file`, `write_file` and `edit_file`; `edit` makes edits precise; `delete` adds `delete_file` (and the files panel's delete). Without `write`, `edit` and `delete` the mount is read-only, and the files panel shows it with a lock. `workspace.edit(path, edits)` does the same from your code.
|
|
135
|
+
|
|
136
|
+
Paths given to the mount are relative to it (`/page-1.xml`). A mount is your live data, not storage: nothing of it is saved by the workspace. `memoryFS({ "/a.md": "…" }, { description, readonly })` is a ready-made in-memory one (its `files` map is the content). `workspace.unmount("/diagram")` removes it.
|
|
137
|
+
|
|
138
|
+
## Files with a meaning
|
|
139
|
+
|
|
140
|
+
| Path | |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `/AGENTS.md` | Your instructions for this project; added to the system prompt. |
|
|
143
|
+
| `/memory/notes.md` | The agent's memory: it appends a line to remember something, and the notes are shown at the start of every conversation in this directory. |
|
|
144
|
+
| `/prompts/<name>.md` | Prompt templates, typed as `/name args`. |
|
|
145
|
+
| `/.agent/skills/` | The skills, generated and read-only (see [Skills](skills.md)). |
|
|
146
|
+
| `/skills/` | The user's skills, shared by every directory of the app. |
|
|
147
|
+
| `/uploads/` | Where the chat UI saves attached files (`uploadsDir`). |
|
|
148
|
+
|
|
149
|
+
### Prompt templates
|
|
150
|
+
|
|
151
|
+
A file `/prompts/standup.md`:
|
|
152
|
+
|
|
153
|
+
```markdown
|
|
154
|
+
---
|
|
155
|
+
description: Write my standup from the notes of a day
|
|
156
|
+
argument-hint: <date>
|
|
157
|
+
---
|
|
158
|
+
Read /notes/$1.md and write my standup: done, doing, blocked. Three bullets each at most.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Typing `/standup 2026-11-01` sends the expanded text. Arguments follow bash: `$1`, `$2`, `$@` (all), `${2:-default}`, `${@:2}` (from the second on); quotes group words. `listTemplates(workspace)` lists them (the chat shows them in its `/` menu).
|
|
162
|
+
|
|
163
|
+
## PDFs
|
|
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.
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
import { configurePdf } from "@runappsai/agent";
|
|
169
|
+
configurePdf({ url: "/vendor/pdf.min.mjs", workerUrl: "/vendor/pdf.worker.min.mjs" }); // a copy you host
|
|
170
|
+
configurePdf({ load: () => import("pdfjs-dist") }); // a bundled one
|
|
171
|
+
// In Node: nodePdf() from @runappsai/agent/node (with `npm i pdfjs-dist`).
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Change events
|
|
175
|
+
|
|
176
|
+
Every write and delete is reported, whoever made it — the agent, `run_js`, your code — and changes in other tabs of the app arrive too:
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
const off = workspace.onChange(({ path, kind, remote }) => {
|
|
180
|
+
// kind: "write" | "delete"; remote: true when another tab did it
|
|
181
|
+
if (path.startsWith("/notes/")) refreshNotesList();
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Keeping your own data with a directory
|
|
186
|
+
|
|
187
|
+
`putData(key, value)`, `getData(key)` and `deleteData(key)` store any JSON-able value alongside the directory (the chat keeps its rewind snapshots there). They are dropped with the directory.
|
|
188
|
+
|
|
189
|
+
## Sessions
|
|
190
|
+
|
|
191
|
+
`workspace.sessions` lists and manages the conversations saved in the app's database — see [Sessions](agent.md#sessions).
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
await workspace.sessions.list(); // every conversation of the app, newest first
|
|
195
|
+
await workspace.sessions.get(id);
|
|
196
|
+
await workspace.sessions.delete(id); // a conversation that had a directory of its own takes it along
|
|
197
|
+
await workspace.sessions.clear(); // all of them
|
|
198
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runappsai/agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
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
|
+
"license": "MIT",
|
|
7
|
+
"author": "RunApps",
|
|
8
|
+
"homepage": "https://github.com/runapps/agent",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/runapps/agent.git"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"unpkg": "./dist/agent.umd.js",
|
|
20
|
+
"jsdelivr": "./dist/agent.umd.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./ui": {
|
|
28
|
+
"types": "./dist/ui.d.ts",
|
|
29
|
+
"import": "./dist/ui.js",
|
|
30
|
+
"require": "./dist/ui.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./node": {
|
|
33
|
+
"types": "./dist/node.d.ts",
|
|
34
|
+
"import": "./dist/node.js",
|
|
35
|
+
"require": "./dist/node.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./browser": "./dist/agent.umd.js",
|
|
38
|
+
"./browser/core": "./dist/agent-core.umd.js",
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"docs",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && tsup",
|
|
49
|
+
"test": "npm run build && node --test --test-timeout=20000 tests/*.test.mjs",
|
|
50
|
+
"release:cdn": "bash scripts/publish-cdn.sh"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@runappsai/sdk": "^0.17.0",
|
|
54
|
+
"@types/node": "^22.20.5",
|
|
55
|
+
"fake-indexeddb": "^6.0.0",
|
|
56
|
+
"pdfjs-dist": "^5.7.284",
|
|
57
|
+
"tsup": "^8.5.1",
|
|
58
|
+
"typescript": "^5.9.0"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false
|
|
61
|
+
}
|