@runappsai/agent 0.1.8 → 0.1.9
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/dist/agent-core.umd.js +42 -42
- package/dist/agent.d.ts +14 -1
- package/dist/agent.js +46 -5
- package/dist/agent.umd.js +101 -99
- package/dist/chat.d.ts +8 -0
- package/dist/chat.js +45 -6
- package/dist/dom.d.ts +1 -0
- package/dist/dom.js +1 -0
- package/dist/index.cjs +104 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/provider.d.ts +28 -0
- package/dist/provider.js +1 -0
- package/dist/types.d.ts +13 -2
- package/dist/ui.cjs +63 -4
- package/dist/web-tools.d.ts +15 -0
- package/dist/web-tools.js +74 -0
- package/docs/agent.md +3 -2
- package/docs/chat-ui.md +1 -0
- package/docs/reference.md +1 -0
- package/docs/tools.md +12 -0
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export declare class Agent {
|
|
|
13
13
|
readonly workspace: Workspace | null;
|
|
14
14
|
readonly tools: Tool[];
|
|
15
15
|
private readonly opts;
|
|
16
|
+
/** `webTools` as configured (a function is read every turn). */
|
|
17
|
+
private web;
|
|
18
|
+
/** The platform's web tools, loaded the first time they are offered. */
|
|
19
|
+
private webCache;
|
|
16
20
|
private history;
|
|
17
21
|
private committed;
|
|
18
22
|
private droppedTurns;
|
|
@@ -67,6 +71,7 @@ export declare class Agent {
|
|
|
67
71
|
maxTokens?: number | "auto";
|
|
68
72
|
permissions?: Permissions;
|
|
69
73
|
reasoningEffort?: string | null;
|
|
74
|
+
webTools?: boolean;
|
|
70
75
|
}): void;
|
|
71
76
|
/** A snapshot to save (`restore` continues it). Taken at the last complete turn. */
|
|
72
77
|
export(): SessionData;
|
|
@@ -136,8 +141,14 @@ export declare class Agent {
|
|
|
136
141
|
private toWireHistory;
|
|
137
142
|
/** What the model in use takes besides text (undefined: not known — then it is sent). */
|
|
138
143
|
private mediaSupport;
|
|
139
|
-
/**
|
|
144
|
+
/** Whether the platform's web tools are offered now (`webTools`, `configure({ webTools })`). */
|
|
145
|
+
get webTools(): boolean;
|
|
146
|
+
/** The provider's platform has web tools (the RunApps client, SDK 0.19+). */
|
|
147
|
+
get webToolsAvailable(): boolean;
|
|
148
|
+
/** The tools offered this turn: `vision` tools only while the model is known to take pictures, the web tools while they are on. */
|
|
140
149
|
private activeTools;
|
|
150
|
+
/** The web tools, asked of the platform once (a failure is asked again next turn). */
|
|
151
|
+
private loadWeb;
|
|
141
152
|
/** The system prompt for the next request (what the model is told). */
|
|
142
153
|
systemPrompt(): Promise<string>;
|
|
143
154
|
/**
|
|
@@ -198,6 +209,8 @@ export declare class Agent {
|
|
|
198
209
|
* (requests never carry it).
|
|
199
210
|
*/
|
|
200
211
|
private markRunUsage;
|
|
212
|
+
/** A platform tool's charge: added to the cost, not counted as a model call. */
|
|
213
|
+
private addToolCost;
|
|
201
214
|
private addUsage;
|
|
202
215
|
/** How full the model's context is: tokens the next call would send (estimated) against the window. */
|
|
203
216
|
context(): Promise<{
|
package/dist/agent.js
CHANGED
|
@@ -11,6 +11,7 @@ import { expandSlash } from "./templates.js";
|
|
|
11
11
|
import { fileTools } from "./file-tools.js";
|
|
12
12
|
import { validateSchema } from "./json-schema.js";
|
|
13
13
|
import { sandboxTool } from "./sandbox.js";
|
|
14
|
+
import { webTools as loadWebTools } from "./web-tools.js";
|
|
14
15
|
import { DEFAULT_MAX_RESULT_CHARS, normalizeResult, textOf, toChatTool, truncate } from "./tool.js";
|
|
15
16
|
import { askUserTool, domUI } from "./dialogs.js";
|
|
16
17
|
import { fileGuard } from "./file-guard.js";
|
|
@@ -143,6 +144,10 @@ export class Agent {
|
|
|
143
144
|
workspace;
|
|
144
145
|
tools;
|
|
145
146
|
opts;
|
|
147
|
+
/** `webTools` as configured (a function is read every turn). */
|
|
148
|
+
web;
|
|
149
|
+
/** The platform's web tools, loaded the first time they are offered. */
|
|
150
|
+
webCache = null;
|
|
146
151
|
history = [];
|
|
147
152
|
committed = 0;
|
|
148
153
|
droppedTurns = 0;
|
|
@@ -195,6 +200,7 @@ export class Agent {
|
|
|
195
200
|
seen.add(t.name);
|
|
196
201
|
}
|
|
197
202
|
this.tools = tools;
|
|
203
|
+
this.web = opts.webTools ?? false;
|
|
198
204
|
if (opts.serverTools?.length && (opts.tools?.length || this.workspace || opts.sandbox !== false || opts.askUser !== false)) {
|
|
199
205
|
throw new Error("serverTools work only for an agent with no tools of its own (tools: [], workspace: null, sandbox: false, askUser: false) — the gateway runs that loop");
|
|
200
206
|
}
|
|
@@ -312,6 +318,8 @@ export class Agent {
|
|
|
312
318
|
configure(patch) {
|
|
313
319
|
if ("model" in patch)
|
|
314
320
|
this.model = patch.model || undefined;
|
|
321
|
+
if (typeof patch.webTools === "boolean")
|
|
322
|
+
this.web = patch.webTools;
|
|
315
323
|
if ("reasoningEffort" in patch) {
|
|
316
324
|
const extra = { ...(this.opts.extra ?? {}) };
|
|
317
325
|
if (patch.reasoningEffort)
|
|
@@ -770,12 +778,41 @@ export class Agent {
|
|
|
770
778
|
const [image, video, audio] = await Promise.all([this.accepts("image"), this.accepts("video"), this.accepts("audio")]);
|
|
771
779
|
return { image, video, audio };
|
|
772
780
|
}
|
|
773
|
-
/**
|
|
781
|
+
/** Whether the platform's web tools are offered now (`webTools`, `configure({ webTools })`). */
|
|
782
|
+
get webTools() {
|
|
783
|
+
return this.webToolsAvailable && (typeof this.web === "function" ? !!this.web() : this.web);
|
|
784
|
+
}
|
|
785
|
+
/** The provider's platform has web tools (the RunApps client, SDK 0.19+). */
|
|
786
|
+
get webToolsAvailable() {
|
|
787
|
+
return !!this.provider.platformTools;
|
|
788
|
+
}
|
|
789
|
+
/** The tools offered this turn: `vision` tools only while the model is known to take pictures, the web tools while they are on. */
|
|
774
790
|
async activeTools() {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
791
|
+
let tools = this.tools;
|
|
792
|
+
if (tools.some((t) => t.vision)) {
|
|
793
|
+
const sees = await this.accepts("image");
|
|
794
|
+
tools = tools.filter((t) => !t.vision || sees === true);
|
|
795
|
+
}
|
|
796
|
+
if (this.webTools) {
|
|
797
|
+
const web = await this.loadWeb();
|
|
798
|
+
const own = new Set(tools.map((t) => t.name));
|
|
799
|
+
const extra = web.filter((t) => !own.has(t.name));
|
|
800
|
+
if (extra.length)
|
|
801
|
+
tools = [...tools, ...extra];
|
|
802
|
+
}
|
|
803
|
+
return tools;
|
|
804
|
+
}
|
|
805
|
+
/** The web tools, asked of the platform once (a failure is asked again next turn). */
|
|
806
|
+
loadWeb() {
|
|
807
|
+
const platform = this.provider.platformTools;
|
|
808
|
+
if (!platform)
|
|
809
|
+
return Promise.resolve([]);
|
|
810
|
+
this.webCache ??= loadWebTools(platform, { onCost: (usd) => this.addToolCost(usd) }).catch((err) => {
|
|
811
|
+
this.webCache = null;
|
|
812
|
+
console.warn("[agent] could not load the web tools:", err);
|
|
813
|
+
return [];
|
|
814
|
+
});
|
|
815
|
+
return this.webCache;
|
|
779
816
|
}
|
|
780
817
|
/** The system prompt for the next request (what the model is told). */
|
|
781
818
|
async systemPrompt() {
|
|
@@ -1301,6 +1338,10 @@ export class Agent {
|
|
|
1301
1338
|
return;
|
|
1302
1339
|
}
|
|
1303
1340
|
}
|
|
1341
|
+
/** A platform tool's charge: added to the cost, not counted as a model call. */
|
|
1342
|
+
addToolCost(usd) {
|
|
1343
|
+
this._usage.total_cost = round(this._usage.total_cost + usd);
|
|
1344
|
+
}
|
|
1304
1345
|
addUsage(u) {
|
|
1305
1346
|
this._usage.total_cost = round(this._usage.total_cost + (u.total_cost ?? 0));
|
|
1306
1347
|
this._usage.prompt_tokens += u.prompt_tokens ?? 0;
|