@runappsai/agent 0.0.0-stage → 0.1.1

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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -2
  3. package/dist/agent-core.umd.js +266 -0
  4. package/dist/agent.d.ts +222 -0
  5. package/dist/agent.js +1331 -0
  6. package/dist/agent.umd.js +732 -0
  7. package/dist/browser.d.ts +2 -0
  8. package/dist/browser.js +4 -0
  9. package/dist/chat-theme.d.ts +24 -0
  10. package/dist/chat-theme.js +101 -0
  11. package/dist/chat.d.ts +271 -0
  12. package/dist/chat.js +4099 -0
  13. package/dist/compaction.d.ts +48 -0
  14. package/dist/compaction.js +208 -0
  15. package/dist/completion.d.ts +29 -0
  16. package/dist/completion.js +88 -0
  17. package/dist/context.d.ts +44 -0
  18. package/dist/context.js +177 -0
  19. package/dist/debug-panel.d.ts +40 -0
  20. package/dist/debug-panel.js +262 -0
  21. package/dist/dialogs.d.ts +7 -0
  22. package/dist/dialogs.js +231 -0
  23. package/dist/directory-fs.d.ts +5 -0
  24. package/dist/directory-fs.js +118 -0
  25. package/dist/dom.d.ts +83 -0
  26. package/dist/dom.js +163 -0
  27. package/dist/edit.d.ts +22 -0
  28. package/dist/edit.js +133 -0
  29. package/dist/file-guard.d.ts +46 -0
  30. package/dist/file-guard.js +153 -0
  31. package/dist/file-tools.d.ts +16 -0
  32. package/dist/file-tools.js +339 -0
  33. package/dist/files-panel.d.ts +60 -0
  34. package/dist/files-panel.js +613 -0
  35. package/dist/index.cjs +4848 -0
  36. package/dist/index.d.ts +37 -0
  37. package/dist/index.js +44 -0
  38. package/dist/json-schema.d.ts +3 -0
  39. package/dist/json-schema.js +141 -0
  40. package/dist/llm.d.ts +95 -0
  41. package/dist/llm.js +5 -0
  42. package/dist/markdown.d.ts +4 -0
  43. package/dist/markdown.js +265 -0
  44. package/dist/mcp.d.ts +82 -0
  45. package/dist/mcp.js +325 -0
  46. package/dist/node.cjs +402 -0
  47. package/dist/node.d.ts +78 -0
  48. package/dist/node.js +432 -0
  49. package/dist/pdf.d.ts +52 -0
  50. package/dist/pdf.js +77 -0
  51. package/dist/provider.d.ts +135 -0
  52. package/dist/provider.js +181 -0
  53. package/dist/sandbox.d.ts +33 -0
  54. package/dist/sandbox.js +219 -0
  55. package/dist/select.d.ts +30 -0
  56. package/dist/select.js +185 -0
  57. package/dist/skill-zips.d.ts +28 -0
  58. package/dist/skill-zips.js +123 -0
  59. package/dist/skills.d.ts +20 -0
  60. package/dist/skills.js +111 -0
  61. package/dist/templates.d.ts +24 -0
  62. package/dist/templates.js +136 -0
  63. package/dist/tool.d.ts +28 -0
  64. package/dist/tool.js +102 -0
  65. package/dist/types.d.ts +571 -0
  66. package/dist/types.js +7 -0
  67. package/dist/ui.cjs +6247 -0
  68. package/dist/ui.d.ts +6 -0
  69. package/dist/ui.js +11 -0
  70. package/dist/vlist.d.ts +80 -0
  71. package/dist/vlist.js +277 -0
  72. package/dist/workspace.d.ts +343 -0
  73. package/dist/workspace.js +1203 -0
  74. package/dist/zip.d.ts +26 -0
  75. package/dist/zip.js +204 -0
  76. package/docs/agent.md +228 -0
  77. package/docs/chat-ui.md +307 -0
  78. package/docs/node.md +135 -0
  79. package/docs/providers.md +176 -0
  80. package/docs/reference.md +143 -0
  81. package/docs/skills.md +131 -0
  82. package/docs/tools.md +254 -0
  83. package/docs/workspace.md +198 -0
  84. package/package.json +59 -4
@@ -0,0 +1,343 @@
1
+ import { type ModelProvider, type RunAppsClientLike } from "./provider.js";
2
+ import type { AgentFS, FileStat, SessionData, SessionSummary, Skill } from "./types.js";
3
+ import { type Inflate } from "./zip.js";
4
+ import { type TextEdit } from "./edit.js";
5
+ /** Where a workspace keeps its skills unless `skillsDir` says otherwise. */
6
+ export declare const DEFAULT_SKILLS_DIR = "/.agent/skills";
7
+ /** @deprecated use DEFAULT_SKILLS_DIR / `workspace.skillsDir` */
8
+ export declare const SKILLS_ROOT = "/.agent/skills";
9
+ /** Where the user's skills live unless `userSkillsDir` says otherwise. */
10
+ export declare const DEFAULT_USER_SKILLS_DIR = "/skills";
11
+ /**
12
+ * A skill known up front by its name and description, whose zip is fetched only the first time
13
+ * it is used (the agent reads a file of it, or `/skill:name`): `load` returns the zip — a Blob,
14
+ * an ArrayBuffer, a Uint8Array, or a URL / `files:` path to fetch. Loaded once per page.
15
+ */
16
+ export interface LazySkill {
17
+ name: string;
18
+ description: string;
19
+ load: () => Blob | ArrayBuffer | Uint8Array | string | Promise<Blob | ArrayBuffer | Uint8Array | string>;
20
+ /** Only used when asked for (`/skill:name`), never picked by the model. */
21
+ disableModelInvocation?: boolean;
22
+ }
23
+ /** A skills zip the app provides: a URL / bundle path / `files:<path>`, the bytes, either with a name, or a LazySkill. */
24
+ export type SkillSource = string | Blob | Uint8Array | {
25
+ name: string;
26
+ data: string | Blob | Uint8Array;
27
+ } | LazySkill;
28
+ type Layer = "skills" | "work";
29
+ /** A file as a WorkspaceStore keeps it. */
30
+ export interface FileRecord {
31
+ /** The directory (workspace id) the file belongs to. */
32
+ space?: string;
33
+ path: string;
34
+ data: string | Uint8Array;
35
+ contentType?: string;
36
+ mtime: number;
37
+ layer: Layer;
38
+ /** The skills source the file came from (skills layer). */
39
+ source?: string;
40
+ }
41
+ /**
42
+ * Where a workspace keeps its files (when it has no `dir`), its meta data
43
+ * and the app's sessions: one store per directory (`space`) of an app's
44
+ * database. IndexedDB in browsers, memory elsewhere, or a store of your
45
+ * own through the `store` option (`nodeStore()` keeps it on disk).
46
+ */
47
+ export interface WorkspaceStore {
48
+ get(path: string): Promise<FileRecord | undefined>;
49
+ /** A file's size and time without its content (optional; else `get`). */
50
+ stat?(path: string): Promise<FileStat | null>;
51
+ put(rec: FileRecord): Promise<void>;
52
+ delete(path: string): Promise<void>;
53
+ list(prefix: string): Promise<FileRecord[]>;
54
+ /** The files under `prefix` without their content (optional; else `list`). */
55
+ listStats?(prefix: string): Promise<FileStat[]>;
56
+ getMeta<T>(key: string): Promise<T | undefined>;
57
+ putMeta(key: string, value: unknown): Promise<void>;
58
+ deleteMeta(key: string): Promise<void>;
59
+ /** Meta values whose key starts with `prefix`. */
60
+ listMeta<T>(prefix: string): Promise<T[]>;
61
+ /** Meta keys that start with `prefix`. */
62
+ listMetaKeys(prefix: string): Promise<string[]>;
63
+ getSession(space: string, id: string): Promise<SessionData | undefined>;
64
+ /** Saved under `data.space`. */
65
+ putSession(data: SessionData): Promise<void>;
66
+ deleteSession(space: string, id: string): Promise<void>;
67
+ /** Every session in the app's database, whichever directory saved it. */
68
+ listSessions(): Promise<SessionData[]>;
69
+ /** Drops a directory's files, meta and sessions (this one by default). */
70
+ clear(space?: string): Promise<void>;
71
+ close(): void;
72
+ }
73
+ /** Opens the store of one directory (`space`) of an app's database (`dbName`). */
74
+ export interface WorkspaceStoreFactory {
75
+ open(dbName: string, space: string): Promise<WorkspaceStore>;
76
+ }
77
+ /** Saved agent sessions of a workspace (`workspace.sessions`). */
78
+ export interface SessionStore {
79
+ /** Newest first. */
80
+ list(): Promise<SessionSummary[]>;
81
+ get(id: string): Promise<SessionData | null>;
82
+ save(data: SessionData): Promise<void>;
83
+ /**
84
+ * Deletes a session — of this directory, else the one in the directory
85
+ * named after it (the chat's layout); `space` picks one exactly (a
86
+ * summary's `workspace`). A session saved from a directory of its own
87
+ * id takes that directory with it.
88
+ */
89
+ delete(id: string, space?: string): Promise<void>;
90
+ /** Deletes every session of the app (and the directories made for them). */
91
+ clear(): Promise<void>;
92
+ }
93
+ export interface WorkspaceOptions {
94
+ /**
95
+ * Which directory: ids are separate trees in the app's database (give
96
+ * each chat session its own id to isolate them); the same id (default
97
+ * `"default"`) opens the same tree, also across tabs and reloads.
98
+ */
99
+ id?: string;
100
+ /** The app the database belongs to; `openWorkspace` fills it in from the provider's `name`. */
101
+ project?: string;
102
+ /**
103
+ * The app's skills zip(s): a path or URL (`/skills.zip` in the bundle,
104
+ * a public link), `files:<path>` for a file in the user's RunApps
105
+ * storage (fetched with the SDK's token), a Blob / File / Uint8Array,
106
+ * or `{ name, data }`. Read in place each time the page opens them —
107
+ * never stored; a URL is fetched once per page. They are the app's:
108
+ * the user cannot remove them. A `LazySkill` (`{ name, description,
109
+ * load }`) is listed at once and its zip fetched only when first used.
110
+ * A function returning the list (sync or async) is called at open and
111
+ * on `refreshSkills()`.
112
+ */
113
+ skills?: SkillSource | SkillSource[] | (() => SkillSource[] | Promise<SkillSource[]>);
114
+ /** The generated, read-only skills folder, `<skillsDir>/<name>/SKILL.md` (default `/.agent/skills`). */
115
+ skillsDir?: string;
116
+ /**
117
+ * The user's skills, shared by every directory of the app (default
118
+ * `/skills`; `false`: none): skill zips (read in place) and skill
119
+ * folders (`<userSkillsDir>/<name>/SKILL.md`, which the agent may
120
+ * write). Each shows up in `skillsDir`.
121
+ */
122
+ userSkillsDir?: string | false;
123
+ /**
124
+ * Whether the user has skills of their own (default true). `false`:
125
+ * only the app's `skills` — no `userSkillsDir`, nothing to upload,
126
+ * remove or write, and the agent is not told it may make skills.
127
+ */
128
+ userSkills?: boolean;
129
+ /**
130
+ * The directory itself, instead of the IndexedDB tree: `directoryFS(handle)`
131
+ * for a folder picked with `showDirectoryPicker()`, or any `AgentFS`.
132
+ * Sessions and skills-zip bookkeeping still go to IndexedDB under `id`.
133
+ */
134
+ dir?: AgentFS;
135
+ /** Inflate for runtimes without DecompressionStream (tests: zlib.inflateRawSync). */
136
+ inflate?: Inflate;
137
+ fetch?: typeof fetch;
138
+ /** IndexedDB to use (an `IDBFactory`; tests pass fake-indexeddb's); in-memory when the runtime has none and no `store` is given. */
139
+ indexedDB?: object | null;
140
+ /** Keep the workspace somewhere other than IndexedDB — `nodeStore(dir)` from `@runappsai/agent/node` keeps it on disk. */
141
+ store?: WorkspaceStoreFactory;
142
+ }
143
+ /** A file of the directory was written or deleted — by this page, or (`remote`) by another tab of the app. */
144
+ export interface WorkspaceChange {
145
+ path: string;
146
+ kind: "write" | "delete";
147
+ remote?: boolean;
148
+ }
149
+ export interface WorkspaceRead {
150
+ data: string | Uint8Array;
151
+ contentType?: string;
152
+ size: number;
153
+ }
154
+ export declare class Workspace {
155
+ /** The directory's id. */
156
+ readonly id: string;
157
+ /** The app's database (shared by every id of the app). */
158
+ readonly dbName: string;
159
+ /** The generated, read-only skills folder (`<skillsDir>/<name>/SKILL.md`). */
160
+ readonly skillsDir: string;
161
+ /** The user's skills folder, shared by the app's directories (null: none). */
162
+ readonly userSkillsDir: string | null;
163
+ /** The folder the directory lives in when opened with `dir` (null: IndexedDB). */
164
+ readonly root: AgentFS | null;
165
+ private store;
166
+ /** The user's skills folder (one tree for the whole app). */
167
+ private lib;
168
+ private readonly mounts;
169
+ /** The skills in `skillsDir`, by folder name. */
170
+ private skillViews;
171
+ /** The app's zips, loaded at open. */
172
+ private builtins;
173
+ /** The app's skills that load on first use. */
174
+ private lazySkills;
175
+ /** The `skills` option resolved (a function called): what loadBuiltins worked from. */
176
+ private resolvedSources;
177
+ private readonly changeListeners;
178
+ private channel;
179
+ private readonly sources;
180
+ /** Reads `files:` skills sources (the provider's own storage). */
181
+ private readonly provider;
182
+ private readonly inflate?;
183
+ private readonly fetchFn;
184
+ /** Part of the page cache key for the app's zips: a host's own fetch is its own cache. */
185
+ private readonly fetchKey;
186
+ private readonly idb;
187
+ private readonly storeFactory;
188
+ private skillCache;
189
+ private opened;
190
+ /**
191
+ * The agent sessions saved in the app's database — every directory's,
192
+ * each summary naming its `workspace` (the directory id it was saved
193
+ * from), so a chat that gives each session its own directory can list
194
+ * them all from any one.
195
+ */
196
+ readonly sessions: SessionStore;
197
+ constructor(provider: ModelProvider | RunAppsClientLike | null, opts?: WorkspaceOptions);
198
+ /** Opens the database and brings the skills layer up to date. */
199
+ static open(provider: ModelProvider | RunAppsClientLike | null, opts?: WorkspaceOptions): Promise<Workspace>;
200
+ /** Resolves once the database is open and skills are unpacked (idempotent). */
201
+ ready(): Promise<void>;
202
+ /**
203
+ * Releases the database connection and the change channel. The
204
+ * workspace stays usable: the next call opens them again. A host that
205
+ * makes a workspace per session closes the ones it no longer shows.
206
+ */
207
+ close(): void;
208
+ /** Exposes `fs` under `prefix` (e.g. `/doc`); its paths are relative to the prefix. */
209
+ mount(prefix: string, fs: AgentFS): void;
210
+ unmount(prefix: string): void;
211
+ /**
212
+ * Called for every write and delete in this directory, from any code in
213
+ * this page and from other tabs of the app (`remote: true`, relayed over
214
+ * a BroadcastChannel). Returns the unsubscribe function. A files view
215
+ * refreshes on this instead of guessing when the agent wrote something.
216
+ */
217
+ onChange(fn: (change: WorkspaceChange) => void): () => void;
218
+ private openChannel;
219
+ private emitChange;
220
+ /** What the system prompt says about the tree. */
221
+ describe(): string;
222
+ /** The mount (or the root directory) that serves `path`; null means the IndexedDB tree. */
223
+ private route;
224
+ private inSkills;
225
+ private putFile;
226
+ private rmFile;
227
+ list(prefix?: string): Promise<FileStat[]>;
228
+ stat(path: string): Promise<FileStat | null>;
229
+ exists(path: string): Promise<boolean>;
230
+ read(path: string): Promise<WorkspaceRead>;
231
+ /** Whether `path` has files under it (a folder, in a tree that stores only files). */
232
+ isFolder(path: string): Promise<boolean>;
233
+ private missing;
234
+ /** The file as text; throws for binary files. */
235
+ readText(path: string): Promise<string>;
236
+ /**
237
+ * A file as text for reading: text files as they are, a PDF as the text
238
+ * of its pages (pdf.js, loaded on first use; the result is cached with
239
+ * the directory and redone when the file changes); null for other
240
+ * binary files.
241
+ */
242
+ readAsText(path: string): Promise<{
243
+ text: string;
244
+ kind: "text" | "pdf";
245
+ } | null>;
246
+ write(path: string, content: string | Uint8Array, contentType?: string): Promise<void>;
247
+ /**
248
+ * Replaces each `oldText` (found once, in the original) by its `newText`.
249
+ * A mount (or `dir`) that implements `edit` gets the edits as they are;
250
+ * otherwise the file is read, edited (`applyEdits`: exact, then tolerant
251
+ * of quotes, dashes and trailing spaces) and written back whole.
252
+ */
253
+ edit(path: string, edits: TextEdit[]): Promise<void>;
254
+ delete(path: string): Promise<void>;
255
+ /** The mount a path falls under, or null for the directory itself. */
256
+ mountOf(path: string): string | null;
257
+ /** Whether writes to a path are refused (a read-only mount, or a `dir` root without write). */
258
+ isReadOnly(path: string): boolean;
259
+ /** Whether a path is under the skills folder or the user's skills folder. */
260
+ isSkillPath(path: string): boolean;
261
+ /** A value of the host's kept with this directory (checkpoints, settings); `null` deletes it. */
262
+ getData<T>(key: string): Promise<T | undefined>;
263
+ putData(key: string, value: unknown): Promise<void>;
264
+ deleteData(key: string): Promise<void>;
265
+ /** Removes every file outside the skills folder (mounts and skills stay). */
266
+ clearWork(): Promise<void>;
267
+ /** The skills: every `<skillsDir>/<name>/SKILL.md` (parsed once, until a skill changes). */
268
+ skills(): Promise<Skill[]>;
269
+ /**
270
+ * Adds a skill (or a pack of skills) from a zip — a URL / bundle path /
271
+ * `files:<path>` string, or the bytes (a `File` from an
272
+ * `<input type=file>`, a Blob, a Uint8Array) — to the user's skills:
273
+ * the zip is saved as `<userSkillsDir>/<name>.zip` (the same name
274
+ * replaces it) and read in place; `unpack: true` writes its skill
275
+ * folders there instead, as files that can be edited. A zip with
276
+ * SKILL.md at its root is one skill named `name` (else after the file);
277
+ * otherwise each folder with a SKILL.md is one. Returns what was added.
278
+ */
279
+ installSkill(source: string | Blob | Uint8Array, opts?: {
280
+ name?: string;
281
+ unpack?: boolean;
282
+ }): Promise<Skill[]>;
283
+ /**
284
+ * Removes one of the user's skills: its zip in `userSkillsDir` (with
285
+ * every skill the zip holds) or its folder there. The app's skills
286
+ * cannot be removed. Returns false when there is no such skill.
287
+ */
288
+ removeSkill(name: string): Promise<boolean>;
289
+ /** The body (instructions) of a skill, by name. */
290
+ skillBody(name: string): Promise<{
291
+ skill: Skill;
292
+ body: string;
293
+ }>;
294
+ /** Fetches the app's skills zips again (bypassing the page's copy; lazy ones load again when next used) and regenerates the skills folder. */
295
+ refreshSkills(): Promise<void>;
296
+ /** The app's zips, from the `skills` option (a failed one is left out and logged); lazy ones are only noted. */
297
+ private loadBuiltins;
298
+ /** Regenerates `skillsDir`: the app's zips, then the user's zips and folders (a user's skill of the same name wins). */
299
+ private rebuildSkills;
300
+ /**
301
+ * A lazy skill's files: its SKILL.md is listed before anything is loaded; the first read (or a
302
+ * look at any other file) loads the zip — once per page — and from then on it is the zip's tree.
303
+ */
304
+ private lazyFS;
305
+ /** The generated skills folder: read-only, one subtree per skill. */
306
+ private skillsFS;
307
+ /** The user's skills folder: one tree in the app's database, shared by every directory. */
308
+ private userFS;
309
+ /** A file of the user's skills changed here: regenerate, tell the app's other workspaces and this one's listeners. */
310
+ private userSkillsChanged;
311
+ /**
312
+ * Moves skills from before the generated folder: once per app, the
313
+ * user's uploads kept in the old library become zips in the user's
314
+ * skills; once per directory, skill files stored in its `skillsDir`
315
+ * (hand-written, written by the agent, unpacked uploads) move to the
316
+ * user's skills and copies unpacked from the app's zips are dropped.
317
+ */
318
+ private migrateSkills;
319
+ private fetchSource;
320
+ /** Deletes this directory: its files, its skills bookkeeping and the sessions saved from it. Other ids of the app stay. */
321
+ destroy(): Promise<void>;
322
+ }
323
+ /** Absolute, `/`-separated, no `.`/`..`/doubled slashes, no trailing slash. */
324
+ export declare function normalizePath(path: string): string;
325
+ export declare function guessType(path: string, data: string | Uint8Array): string;
326
+ /** UTF-8 text of `bytes`, or null when it is not text. */
327
+ export declare function decodeText(bytes: Uint8Array): string | null;
328
+ /** A title for a session without one: its first user message, shortened. */
329
+ export declare const UNTITLED = "Untitled";
330
+ /** The first thing the user wrote: what they typed for an expanded command, never a compaction summary, an agent note or an attachment list. */
331
+ export declare function titleOf(d: SessionData): string;
332
+ /** A title that is not the user's words: a compaction summary, an expanded skill, an agent note, an attachment list, the host's context. */
333
+ export declare function isMachineTitle(title: string): boolean;
334
+ /** Runs fn holding the origin-wide Web Lock `name`; without Web Locks it just runs fn. */
335
+ export declare function withLock<T>(name: string, fn: () => Promise<T>): Promise<T>;
336
+ /** An in-memory AgentFS, for tests and for documents an app builds on the fly. */
337
+ export declare function memoryFS(initial?: Record<string, string | Uint8Array>, opts?: {
338
+ description?: string;
339
+ readonly?: boolean;
340
+ }): AgentFS & {
341
+ files: Map<string, string | Uint8Array>;
342
+ };
343
+ export {};