@runappsai/agent 0.3.0 → 0.3.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.
- package/dist/agent-core.umd.js +63 -54
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +10 -3
- package/dist/agent.umd.js +103 -94
- package/dist/index.cjs +121 -8
- package/dist/mcp.d.ts +1 -1
- package/dist/results.d.ts +9 -0
- package/dist/results.js +130 -0
- package/dist/tool.d.ts +1 -1
- package/dist/tool.js +2 -1
- package/dist/types.d.ts +1 -1
- package/docs/tools.md +1 -1
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class Agent {
|
|
|
23
23
|
/** The platform's web tools, loaded the first time they are offered. */
|
|
24
24
|
private webCache;
|
|
25
25
|
private history;
|
|
26
|
+
private recall;
|
|
26
27
|
private committed;
|
|
27
28
|
private droppedTurns;
|
|
28
29
|
private _usage;
|
|
@@ -158,6 +159,7 @@ export declare class Agent {
|
|
|
158
159
|
private run;
|
|
159
160
|
/** Moves queued steering into the history and says so (`steered`), so a UI draws each message once, when it lands. */
|
|
160
161
|
private applySteering;
|
|
162
|
+
/** `budget`: tokens a request should stay under (tool results are left out to get there, see results.ts); 0 for none. */
|
|
161
163
|
private toWireHistory;
|
|
162
164
|
/** What the model in use takes besides text (undefined: not known — then it is sent). */
|
|
163
165
|
private mediaSupport;
|
package/dist/agent.js
CHANGED
|
@@ -13,6 +13,7 @@ import { validateSchema } from "./json-schema.js";
|
|
|
13
13
|
import { sandboxTool } from "./sandbox.js";
|
|
14
14
|
import { webTools as loadWebTools } from "./web-tools.js";
|
|
15
15
|
import { DEFAULT_MAX_RESULT_CHARS, normalizeResult, textOf, toChatTool, truncate } from "./tool.js";
|
|
16
|
+
import { needsRecall, RECALL_TOOL, recallTool, shapeResults } from "./results.js";
|
|
16
17
|
import { askUserTool, domUI } from "./dialogs.js";
|
|
17
18
|
import { fileGuard } from "./file-guard.js";
|
|
18
19
|
import { isMachineTitle, normalizePath, titleOf, UNTITLED } from "./workspace.js";
|
|
@@ -153,6 +154,7 @@ export class Agent {
|
|
|
153
154
|
/** The platform's web tools, loaded the first time they are offered. */
|
|
154
155
|
webCache = null;
|
|
155
156
|
history = [];
|
|
157
|
+
recall = null;
|
|
156
158
|
committed = 0;
|
|
157
159
|
droppedTurns = 0;
|
|
158
160
|
_usage = emptyUsage();
|
|
@@ -645,7 +647,7 @@ export class Agent {
|
|
|
645
647
|
const params = {
|
|
646
648
|
...(this.opts.extra ?? {}),
|
|
647
649
|
model: this.opts.model ?? "",
|
|
648
|
-
messages: [{ role: "system", content: system }, ...this.toWireHistory(await this.mediaSupport())],
|
|
650
|
+
messages: [{ role: "system", content: system }, ...this.toWireHistory(await this.mediaSupport(), Math.floor(window * 0.6), fixed)],
|
|
649
651
|
max_tokens: maxTokens,
|
|
650
652
|
};
|
|
651
653
|
if (!params.model)
|
|
@@ -798,14 +800,16 @@ export class Agent {
|
|
|
798
800
|
this.loop.warned = false;
|
|
799
801
|
this.emit("steered", { runId, messages: steer });
|
|
800
802
|
}
|
|
801
|
-
|
|
803
|
+
/** `budget`: tokens a request should stay under (tool results are left out to get there, see results.ts); 0 for none. */
|
|
804
|
+
toWireHistory(media = {}, budget = 0, system) {
|
|
802
805
|
let lastUser = -1;
|
|
803
806
|
for (let i = this.history.length - 1; i >= 0; i--)
|
|
804
807
|
if (this.history[i].role === "user") {
|
|
805
808
|
lastUser = i;
|
|
806
809
|
break;
|
|
807
810
|
}
|
|
808
|
-
|
|
811
|
+
const wire = shapeResults(this.history.map((m, i) => toWire(m, i < lastUser)), budget, system);
|
|
812
|
+
return withoutMedia(moveToolImages(wire), media, this.opts.model);
|
|
809
813
|
}
|
|
810
814
|
/** What the model in use takes besides text (undefined: not known — then it is sent). */
|
|
811
815
|
async mediaSupport() {
|
|
@@ -823,6 +827,9 @@ export class Agent {
|
|
|
823
827
|
/** The tools offered this turn: `vision` tools only while the model is known to take pictures, the web tools while they are on. */
|
|
824
828
|
async activeTools() {
|
|
825
829
|
let tools = this.tools;
|
|
830
|
+
// recall_result once a result could have been shortened in what is sent (results.ts)
|
|
831
|
+
if (needsRecall(this.history) && !tools.some((t) => t.name === RECALL_TOOL))
|
|
832
|
+
tools = [...tools, (this.recall ??= recallTool(() => this.history))];
|
|
826
833
|
if (tools.some((t) => t.vision)) {
|
|
827
834
|
const sees = await this.accepts("image");
|
|
828
835
|
tools = tools.filter((t) => !t.vision || sees === true);
|