@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,222 @@
1
+ import type { ChatMessage, ContentPart, Unsubscribe } from "./llm.js";
2
+ import { type InputKind, type ModelInfo, type ModelProvider, type RunAppsClientLike } from "./provider.js";
3
+ import type { AgentEventMap, AgentEventName, AgentOptions, AgentUI, AgentUsage, Permissions, RunEnd, RunResult, SessionData, Tool } from "./types.js";
4
+ import { type Workspace } from "./workspace.js";
5
+ export type PromptContent = string | ContentPart[];
6
+ type Handler<K extends AgentEventName> = (event: AgentEventMap[K]) => void;
7
+ type AnyHandler = (name: AgentEventName, event: AgentEventMap[AgentEventName]) => void;
8
+ export declare class Agent {
9
+ readonly id: string;
10
+ /** Where the model calls go. */
11
+ readonly provider: ModelProvider;
12
+ readonly ui: AgentUI;
13
+ readonly workspace: Workspace | null;
14
+ readonly tools: Tool[];
15
+ private readonly opts;
16
+ private history;
17
+ private committed;
18
+ private droppedTurns;
19
+ private _usage;
20
+ private readonly handlers;
21
+ private readonly anyHandlers;
22
+ private queue;
23
+ private current;
24
+ private chain;
25
+ private pendingSkills;
26
+ /** The catalogue's entry for the model in use (undefined: not listed, or no catalogue); asked once per model. */
27
+ private catalogue;
28
+ /** The guard against calls that go nowhere: results seen since the last change, rounds in a row without anything new. */
29
+ private loop;
30
+ /** The turn of the running run (0 outside one), for events of calls made outside the turn's own request. */
31
+ private turnNow;
32
+ private readonly loaded;
33
+ private createdAt;
34
+ /** The session's title, fixed once known (a later compaction must not turn it into the summary's first words). */
35
+ private title;
36
+ private _ended;
37
+ private persist;
38
+ /** `provider`: a ModelProvider, or a RunApps SDK client (wrapped in runappsProvider). */
39
+ constructor(provider: ModelProvider | RunAppsClientLike, opts?: AgentOptions);
40
+ private applySession;
41
+ /** Resolves once a saved session (if any) has been loaded. */
42
+ ready(): Promise<void>;
43
+ private saveSession;
44
+ on<K extends AgentEventName>(name: K, handler: Handler<K>): Unsubscribe;
45
+ on(name: "*", handler: AnyHandler): Unsubscribe;
46
+ private emit;
47
+ /** The transcript (a copy), without the system prompt. */
48
+ get messages(): ChatMessage[];
49
+ get usage(): AgentUsage;
50
+ /** How the last run ended when it did not finish (stopped, turn limit, error) — kept with the session until another run starts. */
51
+ get lastEnd(): RunEnd | null;
52
+ get busy(): boolean;
53
+ get model(): string | undefined;
54
+ set model(name: string | undefined);
55
+ /** The settings a user may change mid-conversation. */
56
+ get settings(): {
57
+ model?: string;
58
+ maxTurns: number;
59
+ maxTokens: number | "auto";
60
+ permissions: "ask" | "auto" | "custom";
61
+ reasoningEffort?: string;
62
+ };
63
+ /** Changes settings for the runs that follow (a run in progress keeps its own). `undefined` leaves a field alone; `reasoningEffort: null` takes the model's default. */
64
+ configure(patch: {
65
+ model?: string;
66
+ maxTurns?: number;
67
+ maxTokens?: number | "auto";
68
+ permissions?: Permissions;
69
+ reasoningEffort?: string | null;
70
+ }): void;
71
+ /** A snapshot to save (`restore` continues it). Taken at the last complete turn. */
72
+ export(): SessionData;
73
+ /** Forgets the conversation (the workspace stays). */
74
+ reset(): void;
75
+ /**
76
+ * Loads a skill for the next prompt: its instructions are placed before
77
+ * the user's message, as if the user had asked for that skill.
78
+ */
79
+ useSkill(name: string): void;
80
+ /**
81
+ * Sends a user message and runs until the model answers. While a run is
82
+ * active the message is queued as a follow-up (same as `followUp`).
83
+ */
84
+ prompt(content: PromptContent, init?: {
85
+ signal?: AbortSignal;
86
+ }): Promise<RunResult>;
87
+ /** Adds guidance that the model sees after the current tool batch; queued when idle like `prompt`. */
88
+ steer(content: PromptContent): Promise<RunResult> | void;
89
+ /** Runs after the current run has finished. */
90
+ followUp(content: PromptContent): Promise<RunResult>;
91
+ /** What waits for the current run: steering (joins the next turn) and follow-ups (run after it). */
92
+ get queued(): Array<{
93
+ kind: "steer" | "followUp";
94
+ message: ChatMessage;
95
+ }>;
96
+ /** Drops one queued message (by the object `queued` lists); a waiting `followUp()` resolves as aborted. */
97
+ dequeue(message: ChatMessage): boolean;
98
+ /** Drops everything queued; a waiting `followUp()` resolves as aborted. */
99
+ clearQueue(): void;
100
+ /** Stops the current run (pending tool calls get a "skipped" result) and drops the queue. */
101
+ abort(): Promise<void>;
102
+ private enqueue;
103
+ private userMessage;
104
+ /**
105
+ * Goes back to before message `index` (as in `messages`): later messages
106
+ * are dropped and the session saved. The caller re-sends or edits the
107
+ * message. Not while a run is active.
108
+ */
109
+ rewind(index: number): Promise<void>;
110
+ /**
111
+ * Deletes messages `start` to `end` (exclusive; default the end) — a
112
+ * question and its answer, say — and saves. Delete whole turns (from a
113
+ * user message to the next one), so every tool call keeps its result.
114
+ * Listeners get a `rewind` event with index `start`.
115
+ */
116
+ remove(start: number, end?: number): Promise<void>;
117
+ /**
118
+ * Starts the conversation over, keeping its id: stops a run, drops the
119
+ * queue, the messages, the title, how the last run ended and the usage,
120
+ * and saves that. The workspace's files are not touched. Listeners get a
121
+ * `rewind` event with index 0.
122
+ */
123
+ clear(): Promise<void>;
124
+ /**
125
+ * Picks the conversation up where it stopped — after a turn limit, an
126
+ * error or a stop — with no new user message and a fresh turn count
127
+ * (pi's `agent.continue()`). The model is called on the history as it
128
+ * is. Not while a run is active; nothing to continue is an error.
129
+ */
130
+ continue(): Promise<RunResult>;
131
+ private start;
132
+ private drainFollowUps;
133
+ private run;
134
+ /** Moves queued steering into the history and says so (`steered`), so a UI draws each message once, when it lands. */
135
+ private applySteering;
136
+ private toWireHistory;
137
+ /** What the model in use takes besides text (undefined: not known — then it is sent). */
138
+ private mediaSupport;
139
+ /** The tools offered this turn: `vision` tools only while the model is known to take pictures. */
140
+ private activeTools;
141
+ /** The system prompt for the next request (what the model is told). */
142
+ systemPrompt(): Promise<string>;
143
+ /**
144
+ * Summarises the older turns into a checkpoint now (the loop does this
145
+ * by itself when the window is nearly full). Resolves true when a
146
+ * summary replaced older turns. `focus` tells the summary what to keep
147
+ * above all. Every turn before the latest may be summarised, even when
148
+ * all of them would fit in `keepRecentTokens`.
149
+ */
150
+ compact(focus?: string): Promise<boolean>;
151
+ private compactWith;
152
+ /** `/skill:name args` and `/template args` in a user message. */
153
+ private expandSlashes;
154
+ /** One model call with retries for transient failures. */
155
+ private callModel;
156
+ private runBatch;
157
+ private skipTool;
158
+ private runTool;
159
+ private permitted;
160
+ /** After an abort, every open tool call gets a result so the transcript stays valid. */
161
+ private closeOpenToolCalls;
162
+ /**
163
+ * After each batch: did it bring anything new? A tool that changes things
164
+ * succeeding with arguments it had not had is progress (and what was seen
165
+ * before may be worth seeing again); otherwise a result counts when the
166
+ * tool says so, or when the run has not had the same one since the last change.
167
+ */
168
+ private checkLoop;
169
+ private resetLoop;
170
+ private balanceLimited;
171
+ /**
172
+ * Puts what the run spent on the last reply it wrote (`runUsage`): the
173
+ * chat shows it under that reply, and it is saved with the conversation
174
+ * (requests never carry it).
175
+ */
176
+ private markRunUsage;
177
+ private addUsage;
178
+ /** How full the model's context is: tokens the next call would send (estimated) against the window. */
179
+ context(): Promise<{
180
+ used: number;
181
+ window: number;
182
+ }>;
183
+ /**
184
+ * The files whose contents are still in the conversation: read (with the
185
+ * result not trimmed away) or written by the model in a turn that was kept.
186
+ * The rest were summarised or dropped, so the model must read them again.
187
+ */
188
+ private filesInView;
189
+ /** The system prompt and the tools' schemas, as they count against the window. */
190
+ private fixedText;
191
+ /**
192
+ * The model's limits as the agent uses them: `input` is the context
193
+ * window, `output` the `max_tokens` of each call — the catalogue's
194
+ * figures for the model (its `max_input_tokens` / `max_tokens`). A number
195
+ * `maxInputTokens` caps the window (a budget: never more than the model
196
+ * takes, when the catalogue says); a number `maxTokens` replaces the output.
197
+ */
198
+ limits(): Promise<{
199
+ input: number;
200
+ output: number;
201
+ }>;
202
+ private contextTokens;
203
+ private catalogueLimits;
204
+ /**
205
+ * The catalogue's entry for the model in use — the named model, else the
206
+ * provider's default chat model — or undefined when the provider has no
207
+ * catalogue or does not list it.
208
+ */
209
+ modelInfo(): Promise<ModelInfo | undefined>;
210
+ /**
211
+ * Whether the model in use takes pictures (`"image"`), video or audio as
212
+ * input: the `vision` option when given (for pictures), else the
213
+ * catalogue's `input_modalities`. Undefined when nothing says.
214
+ */
215
+ accepts(kind: InputKind): Promise<boolean | undefined>;
216
+ private withSkillPrefaces;
217
+ /** Tokens of the transcript alone (estimate, no system prompt); `context()` gives the full figure and the window. */
218
+ estimateContext(): number;
219
+ /** The model's context window in tokens (from the catalogue); same as `(await limits()).input`. */
220
+ contextWindow(): Promise<number>;
221
+ }
222
+ export {};