@runappsai/agent 0.1.11 → 0.2.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/README.md +1 -1
- package/dist/agent-core.umd.js +90 -87
- package/dist/agent.d.ts +25 -1
- package/dist/agent.js +11 -7
- package/dist/agent.umd.js +140 -107
- package/dist/chat.d.ts +77 -8
- package/dist/chat.js +526 -49
- package/dist/debug-panel.d.ts +1 -1
- package/dist/debug-panel.js +1 -1
- package/dist/dialogs.js +43 -1
- package/dist/dom.d.ts +28 -1
- package/dist/dom.js +38 -1
- package/dist/files-panel.js +2 -2
- package/dist/index.cjs +555 -38
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/schedule.d.ts +152 -0
- package/dist/schedule.js +505 -0
- package/dist/types.d.ts +39 -2
- package/dist/ui.cjs +1094 -43
- package/dist/ui.d.ts +2 -0
- package/dist/vlist.d.ts +6 -0
- package/dist/vlist.js +16 -0
- package/docs/chat-ui.md +72 -1
- package/docs/tools.md +1 -0
- package/package.json +1 -1
package/dist/ui.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { renderChat, enhanceSelect, type ChatOptions, type ChatHandle, type ComposerAction, type SettingsField, type SettingsTab } from "./chat.js";
|
|
2
|
+
export type { FileDialog } from "./dom.js";
|
|
3
|
+
export type { ChatAgent, FormField } from "./index.js";
|
|
2
4
|
export { selectBox, type SelectBox, type SelectOption as SelectBoxOption } from "./select.js";
|
|
3
5
|
export { VirtualList, type VRow, type VListOptions } from "./vlist.js";
|
|
4
6
|
export { CHAT_PALETTES, CHAT_COLOR_TOKENS, CHAT_SHARED_TOKENS, type ChatPalette, type ChatVars, type ChatToken, type ChatColorToken } from "./chat-theme.js";
|
package/dist/vlist.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export declare class VirtualList {
|
|
|
57
57
|
/** Removes a row (its element is dropped from the DOM if shown). */
|
|
58
58
|
remove(row: VRow): void;
|
|
59
59
|
clear(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Puts row `i` at the top of the view and stops following the bottom. The
|
|
62
|
+
* rows above it are measured as they come into the window; the row stays
|
|
63
|
+
* where it is while they are (the layout anchors on the row at the top).
|
|
64
|
+
*/
|
|
65
|
+
scrollToIndex(i: number): void;
|
|
60
66
|
/** Jumps to the end and follows new output. */
|
|
61
67
|
scrollToBottom(): void;
|
|
62
68
|
/**
|
package/dist/vlist.js
CHANGED
|
@@ -121,6 +121,22 @@ export class VirtualList {
|
|
|
121
121
|
this.win.replaceChildren();
|
|
122
122
|
this.top.style.height = this.bottom.style.height = "0px";
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Puts row `i` at the top of the view and stops following the bottom. The
|
|
126
|
+
* rows above it are measured as they come into the window; the row stays
|
|
127
|
+
* where it is while they are (the layout anchors on the row at the top).
|
|
128
|
+
*/
|
|
129
|
+
scrollToIndex(i) {
|
|
130
|
+
if (this.disposed || i < 0 || i >= this.rows.length)
|
|
131
|
+
return;
|
|
132
|
+
this.pinned = null;
|
|
133
|
+
this.follow = false;
|
|
134
|
+
const total = this.computeOffsets();
|
|
135
|
+
// Room to scroll that far before the window is rebuilt there: the spacers are what gives the list its height.
|
|
136
|
+
this.bottom.style.height = `${total}px`;
|
|
137
|
+
this.setTop(this.offsets[i]);
|
|
138
|
+
this.layout();
|
|
139
|
+
}
|
|
124
140
|
/** Jumps to the end and follows new output. */
|
|
125
141
|
scrollToBottom() {
|
|
126
142
|
this.pinned = null;
|
package/docs/chat-ui.md
CHANGED
|
@@ -27,9 +27,11 @@
|
|
|
27
27
|
- **Tool calls** — one quiet line per chain of calls, worded from the tools ("read 2 files, edited 1 file"), opening to a card per call with arguments, result (pictures a tool returned shown under it), duration and status.
|
|
28
28
|
- **Questions** — `ask_user` and confirmations appear inline above the composer; while one waits the composer folds to a line, and answering brings the view back to the latest output. A short chat (under 420 px) keeps its composer compact.
|
|
29
29
|
- **The composer** — Enter sends (the ↵ button appears once there is something to send), Shift+Enter breaks a line. While the agent runs, the ↵ becomes a stop square, Enter **steers** (inserts into the current task) and ⌘↵ / Ctrl+↵ **queues** a follow-up (with typed text, *Steer* and *Follow-up* buttons appear too); queued messages sit in a card above the box with *send now*, *edit* and *remove*.
|
|
30
|
+
- **Auto-run** — each permission question offers *Always allow (this app)*: from then on every tool runs without asking, deleting, overwriting and publishing included (a note says so once). Turned off, or on, under *Tool permissions* in the settings. Kept per app in the browser; a user who never chose gets the app's `permissions` (`"ask"` by default, `"auto"` to start on). `ask_user` questions are not permissions and are always asked.
|
|
30
31
|
- **Attachments** — paperclip, drag and drop, or paste. Files are saved under `/uploads/` in the conversation's directory and named in the message; pictures also go to the model as images — unless the model is known to be text-only: then they stay files and the user is told the model cannot see them. A video (25 MB at most) goes to the model as a video unless the model is known not to take one. Without a directory, a text file or a PDF's text goes into the message itself. 20 MB per file.
|
|
31
32
|
- **Files** — the header's *Files* button opens the directory: a tree, an editor (⌘S, word wrap, Markdown preview), picture and PDF previews, upload, new file, download (folders as zip). File paths in replies open there. Live: changes by the agent show at once.
|
|
32
33
|
- **Skills** — the *Skills* button lists the skills (with a count), uploads zips, removes the user's own.
|
|
34
|
+
- **Scheduled tasks** (`schedule: true`) — the *Scheduled* button: the tasks, each with its schedule, next and last run; add, edit, pause, run now, delete, open its conversation. The agent can add, change and remove them itself. See [Scheduled tasks](#scheduled-tasks).
|
|
33
35
|
- **Chats** — the conversation list (the open one first), new chat, delete. Conversations keep running when you switch away (up to three in the background).
|
|
34
36
|
- **Settings** — the gear: model (with context and output limits, and which models see pictures), thinking level when the model has one, max turns, max output, tool permissions; and a *Context* tab for compaction — summarise older turns or only trim, how many tokens left starts it, how much of the newest stays word for word (each "Default" or a number, with what that comes to for the chosen model). Kept per app in the browser and applied to every conversation; only what differs from the app's defaults is kept, and a saved model the catalogue no longer lists is dropped (the default applies again).
|
|
35
37
|
- **Reply actions** — hover a reply: copy its answer, *answer again* (rewinds to its question, with the same restore choices, and sends it again), delete the question and its answer; on the right what the reply cost (its `runUsage`, in the model's `price.currency`), the tokens and calls in its tooltip.
|
|
@@ -91,6 +93,8 @@ Typing `/` lists the built-in commands, then the directory's prompt templates an
|
|
|
91
93
|
| `settings` | on | The settings gear. |
|
|
92
94
|
| `attachments` | on | Paperclip, drop and paste. |
|
|
93
95
|
| `webSearch` | shown when the provider has web tools | The globe beside the paperclip: turns the platform's web search and page reading on and off (`webTools`), kept per app. Hidden when `webTools` is a function of yours; `false` hides it. |
|
|
96
|
+
| `schedule` | off | Scheduled tasks: `true`, or `{ minMinutes, maxTasks, store, tools }`. See [Scheduled tasks](#scheduled-tasks). |
|
|
97
|
+
| `fileDialog` | the page's platform dialog | How the paperclip, the skills upload and the files panel pick files, and how downloads are saved: `{ openFiles({accept, multiple}) → File[], saveFile(blob, name) }`. Without it the chat uses `puter.ui.openFiles` / `saveFile` when the page has the RunApps file dialog (the user's files or this device), else the browser's chooser and downloads; `false` always uses the browser's. |
|
|
94
98
|
| `uploadsDir` | `/uploads` | Where attachments are saved (with a workspace and file tools; with `fileTools: false` a text file goes into the message itself, so the model can read it). |
|
|
95
99
|
| `showUsage` | on | The context ring in the header and its panel (context use, spending, *Compact now*). |
|
|
96
100
|
| `locale` | the document's | `"en"` or `"zh"`. |
|
|
@@ -108,9 +112,15 @@ Typing `/` lists the built-in commands, then the directory's prompt templates an
|
|
|
108
112
|
| `headerEnd` | | Buttons of your own after the settings gear (a close button). |
|
|
109
113
|
| `composerActions` | | Buttons of your own in the composer's toolbar (see below). |
|
|
110
114
|
| `settingsTabs` | | Tabs of your own in the settings panel (see below). |
|
|
111
|
-
| `permissionsSetting` | on |
|
|
115
|
+
| `permissionsSetting` | on | *Always allow (this app)* on permission questions and the *Tool permissions* choice in the settings; `false` for an app that decides when to ask itself. Not shown when `permissions` is a function or `agent` is given. |
|
|
112
116
|
| `rewindState` | | `{ label, take(), restore(value) }`: your app's own state (an editor's text, a form) snapshotted as each message is sent; rewinding offers `label` as a checkbox and calls `restore` with that snapshot. Needs a workspace. |
|
|
113
117
|
| `onSession(agent)` | | Called with each conversation's agent as it opens. |
|
|
118
|
+
| `headerStart` | | Elements of your own before the header's title (a button that opens your list of conversations). |
|
|
119
|
+
| `queue` | on | Steering and queueing while a run is going. `false`: the composer offers only *Stop* then, Enter sends nothing and what is typed stays in the box — for an agent that takes one message at a time. |
|
|
120
|
+
| `replyActions` | all on | `{ rewind, retry, delete }`: the actions under a message, each off when `false` — *Rewind* on a user message, *Answer again* and *Delete* under a reply. |
|
|
121
|
+
| `clearButton` | on | The header's *Clear* button of a one-conversation chat; `false` when your app clears or deletes conversations itself. |
|
|
122
|
+
| `commands` | all that apply | The built-in slash commands to keep, by name: `["help", "compact", "model", "context", "export"]`. |
|
|
123
|
+
| `uploadImage(file)` | | Uploads an attached picture and returns its address; the message then carries the address instead of the picture as a data URL. A site-relative address (`/uploads/a.png`) is shown in the conversation like any other. |
|
|
114
124
|
|
|
115
125
|
## The empty conversation: a greeting and starter prompts
|
|
116
126
|
|
|
@@ -164,6 +174,7 @@ await chat.deleteSession(id);
|
|
|
164
174
|
await chat.clear(); // start the open conversation over (the Clear button)
|
|
165
175
|
await chat.refresh(); // re-read skills and templates for the / menu
|
|
166
176
|
chat.setDebug(true);
|
|
177
|
+
chat.setTitle("Daily report"); // the header's title
|
|
167
178
|
chat.setAppearance({ theme: "dark", palette: "slate" });
|
|
168
179
|
chat.ui; // the inline dialogs — your own tools can use them
|
|
169
180
|
chat.unmount(); // remove it; agents the chat made are stopped
|
|
@@ -245,6 +256,24 @@ remove(); // take it out again
|
|
|
245
256
|
|
|
246
257
|
The user can remove it with its ×; sending takes it, and a message may be only context. The model gets one text part per item after the typed words, `[context] <label>` on the first line and `text` below; the user's bubble shows the chip, not the text. Rewinding to the message puts the items back into the composer. Mark page content as untrusted in `text` yourself when it is.
|
|
247
258
|
|
|
259
|
+
## Scheduled tasks
|
|
260
|
+
|
|
261
|
+
`schedule: true` gives the chat scheduled tasks: a prompt the agent runs on its own at set times.
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
renderChat(el, { client, workspace, schedule: true }); // defaults
|
|
265
|
+
renderChat(el, { client, workspace, schedule: { minMinutes: 15, maxTasks: 10 } });
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
- **When**: once (a date and time), every N minutes / hours / days, daily at a time on chosen weekdays, or a five-field cron expression — all in the user's local time.
|
|
269
|
+
- **Who sets them up**: the user, in the *Scheduled* panel (header), and the agent, through four tools it gets — `schedule_list`, `schedule_add`, `schedule_update`, `schedule_remove` — which run without asking (the user sees every task in the panel, marked *by AI*). "Every weekday at 9, summarise the news" in the chat is enough. `tools: false` keeps the agent out of it.
|
|
270
|
+
- **When they run**: only while the app is open in a browser — there is no server behind them. A task that is due waits until the chat is idle: nothing running in any conversation, no question open, and the user not typing in the composer. A run missed while the page was closed happens once when it is next opened (not once per missed time); a one-off then turns itself off. With the app open in several tabs, one of them runs it (a Web Lock per task).
|
|
271
|
+
- **Where they run**: each task has a conversation of its own, titled "⏰ <task name>", which every run adds to; it runs in the background (a notice when it starts and ends) and *Open its conversation* goes there. The message the agent gets starts with the task's name and time and says the user may not be watching; questions it asks (and permission questions) wait until the user opens that conversation. Without a conversation list (`sessions: false`, or your own `agent`) runs go into the one conversation.
|
|
272
|
+
- **Limits**: `minMinutes` (default 5) is the shortest repeat, so a task cannot spend the user's balance every minute; `maxTasks` (default 20).
|
|
273
|
+
- **Storage**: localStorage, per app (`__runapps_agent_chat:<app>:schedules`); `store` takes your own (`ScheduleStore`: `list`, `get`, `put`, `delete`, optional `subscribe`).
|
|
274
|
+
|
|
275
|
+
Without the chat UI, the same parts are exported: `scheduleTools(store, limits)` for an agent's tools, `new Scheduler({ store, run, idle, lockPrefix })` to fire due tasks (`start()`, `stop()`, `runNow(id)`), `localSchedules(key)` / `memorySchedules()`, and `nextRun`, `describeSchedule`, `parseCron` for the times.
|
|
276
|
+
|
|
248
277
|
## One conversation: `sessions: false`
|
|
249
278
|
|
|
250
279
|
An app with one conversation per document or project turns the list off:
|
|
@@ -274,6 +303,48 @@ renderChat(el, { agent });
|
|
|
274
303
|
|
|
275
304
|
The chat shows that agent; it does not make new ones (no conversation list or *New chat*; *Clear* starts it over).
|
|
276
305
|
|
|
306
|
+
### An agent that is not an `Agent`
|
|
307
|
+
|
|
308
|
+
`agent` only has to be a `ChatAgent`: the members of `Agent` the chat uses. So the conversation can live somewhere
|
|
309
|
+
else — a loop that runs on your server, with the browser sending messages and receiving a stream:
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import type { ChatAgent } from "@runappsai/agent";
|
|
313
|
+
|
|
314
|
+
class RemoteAgent implements ChatAgent {
|
|
315
|
+
// state the chat reads
|
|
316
|
+
id; provider; workspace = null; tools; messages; usage; lastEnd; busy; model; settings; title;
|
|
317
|
+
// what it calls
|
|
318
|
+
on(name, handler) {…} // run_start, text_delta, reasoning_delta, tool_start, tool_end, message_end, run_end, …
|
|
319
|
+
ready() {…} // resolves once `messages` holds the conversation
|
|
320
|
+
prompt(content) {…} // send to the server; emit the events as its stream arrives; resolve at the end
|
|
321
|
+
abort() {…} rewind(index) {…} continue() {…} compact() {…}
|
|
322
|
+
context() {…} limits() {…} modelInfo() {…} accepts(kind) {…} compactionFor(window) {…} configure(patch) {…}
|
|
323
|
+
}
|
|
324
|
+
renderChat(el, { agent: new RemoteAgent(…), queue: false, replyActions: { delete: false }, clearButton: false });
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
What the chat relies on:
|
|
328
|
+
|
|
329
|
+
- **Messages keep their identity.** The message a `run_start` event carried is the very object later found in `messages`
|
|
330
|
+
(rewinding looks it up there).
|
|
331
|
+
- **`busy`** is true from `run_start` until after `run_end`.
|
|
332
|
+
- **`tools`** is only read for each tool's `display` (label, icon, `tone`, `hidden`); nothing is executed.
|
|
333
|
+
- **Features it has no members for are switched off**: `queue: false` without `steer` / `followUp` / `dequeue`,
|
|
334
|
+
`replyActions.delete: false` without `remove`, `clearButton: false` (and no `/new` in `commands`) without `clear`.
|
|
335
|
+
- **Dialogs**: the host's agent asks through its own `ui`; pass it `chat.ui` to ask in the cards above the composer.
|
|
336
|
+
Besides `confirm`, `select` (now with `min` / `max` for several choices) and `input`, the built-in UIs have
|
|
337
|
+
`form(title, fields)` for several fields at once.
|
|
338
|
+
|
|
339
|
+
Two things exist for an agent whose messages change outside its own runs:
|
|
340
|
+
|
|
341
|
+
- `hasOlder` / `loadOlder()`: when `hasOlder` is true the conversation starts with a *Load earlier messages* row;
|
|
342
|
+
`loadOlder()` puts older messages in front and emits `history`.
|
|
343
|
+
- the `history` event, `{ reason: "older" | "newer" | "replace" }`: the transcript is drawn again from `messages` —
|
|
344
|
+
staying on what it showed (`older`), following the end if it was there (`newer`), or from its end (`replace`).
|
|
345
|
+
|
|
346
|
+
A `compaction` event may carry `summaryText` when the summary is not the first message (the older messages are kept).
|
|
347
|
+
|
|
277
348
|
## Theming
|
|
278
349
|
|
|
279
350
|
Every colour and font is a CSS custom property on the chat's root: `--ra-bg`, `--ra-panel`, `--ra-subtle`, `--ra-muted`, `--ra-fg`, `--ra-fg-muted`, `--ra-border`, `--ra-accent`, `--ra-accent-fg`, `--ra-accent-subtle`, `--ra-accent-muted`, `--ra-user-bg`, `--ra-link`, `--ra-ok`, `--ra-red`, `--ra-red-subtle`, `--ra-warn-fg`, `--ra-warn-bg`, `--ra-warn-border`, `--ra-shadow`, `--ra-shadow-md`, `--ra-font`, `--ra-mono`.
|
package/docs/tools.md
CHANGED
|
@@ -144,6 +144,7 @@ defineTool({
|
|
|
144
144
|
icon: "<svg …>", // the card's icon
|
|
145
145
|
render: ({ args, status, result, details }) => chipsFor(args, result), // your element under the title, visible while folded
|
|
146
146
|
outcome: ({ result }) => summaryOf(result), // beside the status mark ("Added", "$0.12")
|
|
147
|
+
tone: "danger", // marks the icon: "warning" (it spends or acts), "danger" (it deletes or publishes)
|
|
147
148
|
file: ({ path }) => path, // the workspace file it is about: the card offers to open it
|
|
148
149
|
},
|
|
149
150
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runappsai/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|