@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
package/dist/ui.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { renderChat, enhanceSelect, type ChatOptions, type ChatHandle, type ComposerAction, type SettingsField, type SettingsTab } from "./chat.js";
2
+ export { selectBox, type SelectBox, type SelectOption as SelectBoxOption } from "./select.js";
3
+ export { VirtualList, type VRow, type VListOptions } from "./vlist.js";
4
+ export { CHAT_PALETTES, CHAT_COLOR_TOKENS, CHAT_SHARED_TOKENS, type ChatPalette, type ChatVars, type ChatToken, type ChatColorToken } from "./chat-theme.js";
5
+ export { renderMarkdown, renderInline, escapeHTML } from "./markdown.js";
6
+ export { directoryFS } from "./directory-fs.js";
package/dist/ui.js ADDED
@@ -0,0 +1,11 @@
1
+ // @runappsai/agent/ui — the chat UI for web pages: `renderChat`, the
2
+ // dropdown (`selectBox`, `enhanceSelect`), the theme tokens, the Markdown
3
+ // renderer, the virtual list, and `directoryFS` (a folder the user picks
4
+ // in the browser as the workspace's directory). It runs on the core
5
+ // (`@runappsai/agent`), which it imports rather than bundles.
6
+ export { renderChat, enhanceSelect } from "./chat.js";
7
+ export { selectBox } from "./select.js";
8
+ export { VirtualList } from "./vlist.js";
9
+ export { CHAT_PALETTES, CHAT_COLOR_TOKENS, CHAT_SHARED_TOKENS } from "./chat-theme.js";
10
+ export { renderMarkdown, renderInline, escapeHTML } from "./markdown.js";
11
+ export { directoryFS } from "./directory-fs.js";
@@ -0,0 +1,80 @@
1
+ export interface VRow {
2
+ /** Builds the row's element once; later calls return the same one. */
3
+ render(): HTMLElement;
4
+ /** Set by the list: the element once built. */
5
+ el?: HTMLElement | null;
6
+ /** Measured (or estimated) height, kept across detach. */
7
+ height?: number;
8
+ }
9
+ export interface VListOptions {
10
+ /** Height assumed for a row not yet measured. */
11
+ estimate?: number;
12
+ /** Pixels rendered beyond the viewport on each side. */
13
+ overscan?: number;
14
+ /** Class of the wrapper around each row. */
15
+ rowClass?: string;
16
+ /** Within this distance of the bottom (after the user scrolls) the list follows new output again. Default 2. */
17
+ followWithin?: number;
18
+ /** Called when the list starts or stops following the bottom (a "jump to the end" button shows while it does not). */
19
+ onFollow?: (following: boolean) => void;
20
+ }
21
+ export declare class VirtualList {
22
+ readonly scroller: HTMLElement;
23
+ readonly inner: HTMLElement;
24
+ readonly rows: VRow[];
25
+ private _follow;
26
+ private readonly onFollow?;
27
+ /** Whether the list sticks to the bottom as rows grow (true until the user scrolls up). */
28
+ get follow(): boolean;
29
+ set follow(v: boolean);
30
+ private readonly top;
31
+ private readonly win;
32
+ private readonly bottom;
33
+ private readonly wrappers;
34
+ private readonly ro;
35
+ private readonly estimate;
36
+ private readonly overscan;
37
+ private readonly rowClass;
38
+ private readonly followWithin;
39
+ private offsets;
40
+ private first;
41
+ private last;
42
+ private frame;
43
+ private disposed;
44
+ /** scrollTop the list itself last set; a scroll event landing there is not the user's. */
45
+ private expectedTop;
46
+ /** An element the user just clicked (a summary being opened): kept where it is on screen while rows resize. */
47
+ private pinned;
48
+ private lastTop;
49
+ constructor(scroller: HTMLElement, inner: HTMLElement, opts?: VListOptions);
50
+ private onScroll;
51
+ private onWheel;
52
+ private touchY;
53
+ private onTouch;
54
+ private setTop;
55
+ get length(): number;
56
+ push(row: VRow): void;
57
+ /** Removes a row (its element is dropped from the DOM if shown). */
58
+ remove(row: VRow): void;
59
+ clear(): void;
60
+ /** Jumps to the end and follows new output. */
61
+ scrollToBottom(): void;
62
+ /**
63
+ * Keeps `el` at its current place on screen while the rows around it
64
+ * change size for a moment (a details element being opened): the list
65
+ * stops following the bottom, so what opens grows downward instead of
66
+ * the view snapping to the end. A scroll by the user ends the pin.
67
+ */
68
+ pin(el: Element, ms?: number): void;
69
+ private applyPin;
70
+ /** Something changed size or was added: lay out on the next frame. */
71
+ schedule(): void;
72
+ dispose(): void;
73
+ private detach;
74
+ private wrapper;
75
+ private computeOffsets;
76
+ /** First index whose bottom edge is past `y`. */
77
+ private indexAt;
78
+ layout(): void;
79
+ private layoutRows;
80
+ }
package/dist/vlist.js ADDED
@@ -0,0 +1,277 @@
1
+ // A virtual list for the transcript: rows are built on first view and
2
+ // only the rows around the viewport are in the DOM (react-virtuoso's job
3
+ // in the harness app, done here with spacers and measured heights).
4
+ // Rows keep their element once built, so a card's open state and a live
5
+ // row's updates survive leaving and re-entering the window.
6
+ export class VirtualList {
7
+ scroller;
8
+ inner;
9
+ rows = [];
10
+ _follow = true;
11
+ onFollow;
12
+ /** Whether the list sticks to the bottom as rows grow (true until the user scrolls up). */
13
+ get follow() { return this._follow; }
14
+ set follow(v) { if (v === this._follow)
15
+ return; this._follow = v; this.onFollow?.(v); }
16
+ top;
17
+ win;
18
+ bottom;
19
+ wrappers = new Map();
20
+ ro;
21
+ estimate;
22
+ overscan;
23
+ rowClass;
24
+ followWithin;
25
+ offsets = [];
26
+ first = 0;
27
+ last = -1;
28
+ frame = null;
29
+ disposed = false;
30
+ /** scrollTop the list itself last set; a scroll event landing there is not the user's. */
31
+ expectedTop = -1;
32
+ /** An element the user just clicked (a summary being opened): kept where it is on screen while rows resize. */
33
+ pinned = null;
34
+ lastTop = 0;
35
+ constructor(scroller, inner, opts = {}) {
36
+ this.scroller = scroller;
37
+ this.inner = inner;
38
+ this.estimate = opts.estimate ?? 96;
39
+ this.overscan = opts.overscan ?? 400;
40
+ this.rowClass = opts.rowClass ?? "";
41
+ this.followWithin = opts.followWithin ?? 2;
42
+ this.onFollow = opts.onFollow;
43
+ this.top = document.createElement("div");
44
+ this.win = document.createElement("div");
45
+ this.bottom = document.createElement("div");
46
+ inner.append(this.top, this.win, this.bottom);
47
+ scroller.style.overflowAnchor = "none";
48
+ scroller.addEventListener("scroll", this.onScroll, { passive: true });
49
+ // A wheel or finger moving up is the user leaving the bottom: stop following at once, before any layout can snap back.
50
+ scroller.addEventListener("wheel", this.onWheel, { passive: true });
51
+ scroller.addEventListener("touchstart", this.onTouch, { passive: true });
52
+ this.ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => this.schedule());
53
+ if (this.ro)
54
+ this.ro.observe(scroller);
55
+ }
56
+ onScroll = () => {
57
+ const s = this.scroller;
58
+ const top = s.scrollTop;
59
+ const ours = this.expectedTop >= 0 && Math.abs(top - this.expectedTop) <= 1;
60
+ this.expectedTop = -1;
61
+ if (!ours) {
62
+ this.pinned = null;
63
+ // At the bottom first: content that shrinks (a sent composer, an answered card) pulls scrollTop down
64
+ // to the new end, which is not the user leaving it. Leaving is a move up that ends above the end.
65
+ const atBottom = s.scrollHeight - top - s.clientHeight <= this.followWithin;
66
+ if (atBottom)
67
+ this.follow = true;
68
+ else if (top < this.lastTop - 0.5)
69
+ this.follow = false;
70
+ }
71
+ this.lastTop = top;
72
+ this.schedule();
73
+ };
74
+ // A wheel up only leaves the bottom when there is somewhere to go.
75
+ onWheel = (e) => { this.pinned = null; if (e.deltaY < 0 && this.scroller.scrollTop > 0)
76
+ this.follow = false; };
77
+ touchY = 0;
78
+ onTouch = (e) => {
79
+ this.touchY = e.touches[0]?.clientY ?? 0;
80
+ const move = (ev) => { const y = ev.touches[0]?.clientY ?? 0; if (y > this.touchY + 2 && this.scroller.scrollTop > 0)
81
+ this.follow = false; };
82
+ const end = () => { this.scroller.removeEventListener("touchmove", move); this.scroller.removeEventListener("touchend", end); this.scroller.removeEventListener("touchcancel", end); };
83
+ this.scroller.addEventListener("touchmove", move, { passive: true });
84
+ this.scroller.addEventListener("touchend", end, { passive: true });
85
+ this.scroller.addEventListener("touchcancel", end, { passive: true });
86
+ };
87
+ setTop(v) {
88
+ const s = this.scroller;
89
+ if (Math.abs(s.scrollTop - v) <= 0.5)
90
+ return;
91
+ this.expectedTop = v;
92
+ s.scrollTop = v;
93
+ this.lastTop = s.scrollTop;
94
+ }
95
+ get length() { return this.rows.length; }
96
+ push(row) {
97
+ row.height ??= this.estimate;
98
+ this.rows.push(row);
99
+ this.schedule();
100
+ }
101
+ /** Removes a row (its element is dropped from the DOM if shown). */
102
+ remove(row) {
103
+ const i = this.rows.indexOf(row);
104
+ if (i < 0)
105
+ return;
106
+ this.rows.splice(i, 1);
107
+ this.detach(row);
108
+ // Indices after it moved: rebuild the window instead of trusting first/last.
109
+ this.first = 0;
110
+ this.last = -1;
111
+ this.schedule();
112
+ }
113
+ clear() {
114
+ for (const r of this.rows)
115
+ this.detach(r);
116
+ this.rows.length = 0;
117
+ this.offsets = [];
118
+ this.first = 0;
119
+ this.last = -1;
120
+ this.follow = true;
121
+ this.win.replaceChildren();
122
+ this.top.style.height = this.bottom.style.height = "0px";
123
+ }
124
+ /** Jumps to the end and follows new output. */
125
+ scrollToBottom() {
126
+ this.pinned = null;
127
+ this.follow = true;
128
+ this.layout();
129
+ }
130
+ /**
131
+ * Keeps `el` at its current place on screen while the rows around it
132
+ * change size for a moment (a details element being opened): the list
133
+ * stops following the bottom, so what opens grows downward instead of
134
+ * the view snapping to the end. A scroll by the user ends the pin.
135
+ */
136
+ pin(el, ms = 800) {
137
+ this.pinned = { el, offset: el.getBoundingClientRect().top - this.scroller.getBoundingClientRect().top, until: Date.now() + ms };
138
+ this.follow = false;
139
+ }
140
+ applyPin() {
141
+ const p = this.pinned;
142
+ if (!p)
143
+ return;
144
+ if (!p.el.isConnected || Date.now() > p.until) {
145
+ this.pinned = null;
146
+ return;
147
+ }
148
+ const d = p.el.getBoundingClientRect().top - this.scroller.getBoundingClientRect().top - p.offset;
149
+ if (Math.abs(d) > 0.5)
150
+ this.setTop(this.scroller.scrollTop + d);
151
+ }
152
+ /** Something changed size or was added: lay out on the next frame. */
153
+ schedule() {
154
+ if (this.disposed || this.frame !== null)
155
+ return;
156
+ this.frame = requestAnimationFrame(() => { this.frame = null; this.layout(); });
157
+ }
158
+ dispose() {
159
+ this.disposed = true;
160
+ if (this.frame !== null)
161
+ cancelAnimationFrame(this.frame);
162
+ this.scroller.removeEventListener("scroll", this.onScroll);
163
+ this.scroller.removeEventListener("wheel", this.onWheel);
164
+ this.scroller.removeEventListener("touchstart", this.onTouch);
165
+ this.ro?.disconnect();
166
+ }
167
+ detach(row) {
168
+ const w = this.wrappers.get(row);
169
+ if (!w)
170
+ return;
171
+ this.ro?.unobserve(w);
172
+ w.remove();
173
+ this.wrappers.delete(row);
174
+ }
175
+ wrapper(row) {
176
+ let w = this.wrappers.get(row);
177
+ if (w)
178
+ return w;
179
+ w = document.createElement("div");
180
+ if (this.rowClass)
181
+ w.className = this.rowClass;
182
+ if (!row.el)
183
+ row.el = row.render();
184
+ w.append(row.el);
185
+ this.wrappers.set(row, w);
186
+ this.ro?.observe(w);
187
+ return w;
188
+ }
189
+ computeOffsets() {
190
+ const n = this.rows.length;
191
+ this.offsets.length = n + 1;
192
+ let y = 0;
193
+ for (let i = 0; i < n; i++) {
194
+ this.offsets[i] = y;
195
+ y += this.rows[i].height ?? this.estimate;
196
+ }
197
+ this.offsets[n] = y;
198
+ return y;
199
+ }
200
+ /** First index whose bottom edge is past `y`. */
201
+ indexAt(y) {
202
+ let lo = 0, hi = this.rows.length - 1;
203
+ while (lo < hi) {
204
+ const mid = (lo + hi) >> 1;
205
+ if (this.offsets[mid + 1] <= y)
206
+ lo = mid + 1;
207
+ else
208
+ hi = mid;
209
+ }
210
+ return lo;
211
+ }
212
+ layout() {
213
+ if (this.disposed)
214
+ return;
215
+ try {
216
+ this.layoutRows();
217
+ }
218
+ finally {
219
+ this.applyPin();
220
+ }
221
+ }
222
+ layoutRows() {
223
+ const s = this.scroller;
224
+ const n = this.rows.length;
225
+ if (!n) {
226
+ this.win.replaceChildren();
227
+ this.top.style.height = this.bottom.style.height = "0px";
228
+ return;
229
+ }
230
+ const view = s.clientHeight || 600;
231
+ for (let pass = 0; pass < 4; pass++) {
232
+ const total = this.computeOffsets();
233
+ // Keep the row at the top of the viewport where it is unless following the end.
234
+ const scrollTop = this.follow ? Math.max(0, total - view) : s.scrollTop;
235
+ const anchor = this.indexAt(scrollTop);
236
+ const anchorDelta = this.offsets[anchor] - scrollTop;
237
+ const first = this.indexAt(Math.max(0, scrollTop - this.overscan));
238
+ const last = Math.min(n - 1, this.indexAt(Math.min(total - 1, scrollTop + view + this.overscan)));
239
+ // Reconcile the window.
240
+ if (first !== this.first || last !== this.last || this.win.childElementCount !== last - first + 1) {
241
+ const keep = new Set(this.rows.slice(first, last + 1));
242
+ for (const [row, w] of this.wrappers)
243
+ if (!keep.has(row)) {
244
+ this.ro?.unobserve(w);
245
+ w.remove();
246
+ this.wrappers.delete(row);
247
+ }
248
+ const kids = [];
249
+ for (let i = first; i <= last; i++)
250
+ kids.push(this.wrapper(this.rows[i]));
251
+ this.win.replaceChildren(...kids);
252
+ this.first = first;
253
+ this.last = last;
254
+ }
255
+ this.top.style.height = `${this.offsets[first]}px`;
256
+ this.bottom.style.height = `${total - this.offsets[last + 1]}px`;
257
+ // Measure what is shown; a change means another pass with the new sizes.
258
+ let changed = false;
259
+ for (let i = first; i <= last; i++) {
260
+ const row = this.rows[i];
261
+ const hgt = this.wrappers.get(row).offsetHeight;
262
+ if (hgt && hgt !== row.height) {
263
+ row.height = hgt;
264
+ changed = true;
265
+ }
266
+ }
267
+ if (changed) {
268
+ const total2 = this.computeOffsets();
269
+ this.setTop(this.follow ? Math.max(0, total2 - view) : Math.max(0, this.offsets[anchor] - anchorDelta));
270
+ continue;
271
+ }
272
+ if (this.follow && Math.abs(s.scrollTop - Math.max(0, total - view)) > 1)
273
+ this.setTop(Math.max(0, total - view));
274
+ return;
275
+ }
276
+ }
277
+ }