@runappsai/agent 0.1.6 → 0.1.8
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 +86 -78
- package/dist/agent.d.ts +1 -0
- package/dist/agent.js +26 -14
- package/dist/agent.umd.js +125 -116
- package/dist/chat.js +59 -21
- package/dist/context.js +3 -1
- package/dist/dialogs.js +2 -0
- package/dist/file-guard.js +1 -1
- package/dist/file-tools.d.ts +1 -1
- package/dist/file-tools.js +9 -5
- package/dist/index.cjs +127 -83
- package/dist/index.d.ts +1 -1
- package/dist/sandbox.d.ts +15 -9
- package/dist/sandbox.js +105 -75
- package/dist/types.d.ts +32 -1
- package/dist/ui.cjs +58 -25
- package/dist/vlist.js +19 -13
- package/dist/workspace.js +1 -1
- package/docs/agent.md +2 -2
- package/docs/chat-ui.md +2 -2
- package/docs/node.md +1 -1
- package/docs/reference.md +2 -2
- package/docs/skills.md +1 -1
- package/docs/tools.md +27 -6
- package/docs/workspace.md +1 -1
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -178,6 +178,7 @@ export declare class Agent {
|
|
|
178
178
|
private callModel;
|
|
179
179
|
private runBatch;
|
|
180
180
|
private skipTool;
|
|
181
|
+
/** `parentId`: a call made from inside that tool call (ctx.callTool); its result goes back to the tool, not into the conversation. */
|
|
181
182
|
private runTool;
|
|
182
183
|
private permitted;
|
|
183
184
|
/** After an abort, every open tool call gets a result so the transcript stays valid. */
|
package/dist/agent.js
CHANGED
|
@@ -11,7 +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 { normalizeResult, textOf, toChatTool } from "./tool.js";
|
|
14
|
+
import { DEFAULT_MAX_RESULT_CHARS, normalizeResult, textOf, toChatTool, truncate } from "./tool.js";
|
|
15
15
|
import { askUserTool, domUI } from "./dialogs.js";
|
|
16
16
|
import { fileGuard } from "./file-guard.js";
|
|
17
17
|
import { isMachineTitle, normalizePath, titleOf, UNTITLED } from "./workspace.js";
|
|
@@ -22,6 +22,8 @@ const MEMORY_PATH = "/memory/notes.md";
|
|
|
22
22
|
const AGENTS_PATH = "/AGENTS.md";
|
|
23
23
|
const MAX_NOTES_CHARS = 6000;
|
|
24
24
|
const MAX_RETRIES = 3;
|
|
25
|
+
/** The longest result a tool called from another tool (ctx.callTool) hands back. */
|
|
26
|
+
const NESTED_RESULT_CHARS = 2_000_000;
|
|
25
27
|
const LOOP_WARN = 3;
|
|
26
28
|
const LOOP_STOP = 6;
|
|
27
29
|
/**
|
|
@@ -171,7 +173,7 @@ export class Agent {
|
|
|
171
173
|
this.ui = opts.ui ?? domUI();
|
|
172
174
|
this.workspace = opts.workspace ?? null;
|
|
173
175
|
const tools = [...(opts.tools ?? [])];
|
|
174
|
-
// What the model has read, for the file tools
|
|
176
|
+
// What the model has read, for the file tools; forgotten when the conversation is compacted or rewound.
|
|
175
177
|
const guard = this.workspace ? fileGuard(this.workspace, { enabled: opts.readBeforeWrite !== false }) : undefined;
|
|
176
178
|
if (guard) {
|
|
177
179
|
const sync = () => guard.retain(this.filesInView());
|
|
@@ -185,7 +187,7 @@ export class Agent {
|
|
|
185
187
|
if (opts.askUser !== false)
|
|
186
188
|
tools.push(askUserTool());
|
|
187
189
|
if (opts.sandbox !== false)
|
|
188
|
-
tools.push(sandboxTool(
|
|
190
|
+
tools.push(sandboxTool(typeof opts.sandbox === "object" ? opts.sandbox : {}));
|
|
189
191
|
const seen = new Set();
|
|
190
192
|
for (const t of tools) {
|
|
191
193
|
if (seen.has(t.name))
|
|
@@ -794,8 +796,8 @@ export class Agent {
|
|
|
794
796
|
appName: this.opts.appName,
|
|
795
797
|
instructions: typeof this.opts.instructions === "function" ? this.opts.instructions() : this.opts.instructions,
|
|
796
798
|
tools,
|
|
797
|
-
//
|
|
798
|
-
workspaceDescription: ws && tools.some((t) => FILE_TOOL_NAMES.has(t.name)
|
|
799
|
+
// Without file tools the directory is only where the session is kept.
|
|
800
|
+
workspaceDescription: ws && tools.some((t) => FILE_TOOL_NAMES.has(t.name)) ? ws.describe() : undefined,
|
|
799
801
|
skills: ws ? await ws.skills() : [],
|
|
800
802
|
hasSandbox: tools.some((t) => t.name === "run_js"),
|
|
801
803
|
hasAskUser: tools.some((t) => t.name === "ask_user"),
|
|
@@ -1079,18 +1081,22 @@ export class Agent {
|
|
|
1079
1081
|
this.emit("tool_start", { runId, id, name, args: call.function.arguments });
|
|
1080
1082
|
this.emit("tool_end", { runId, id, name, status: "skipped", result: why, durationMs: 0 });
|
|
1081
1083
|
// A batch cut short by the user's new instruction: that is progress of its own.
|
|
1082
|
-
return { message: { role: "tool", tool_call_id: id, content: why }, key: "", changed: false, progress: true };
|
|
1084
|
+
return { message: { role: "tool", tool_call_id: id, content: why }, key: "", changed: false, progress: true, status: "skipped" };
|
|
1083
1085
|
}
|
|
1084
|
-
|
|
1086
|
+
/** `parentId`: a call made from inside that tool call (ctx.callTool); its result goes back to the tool, not into the conversation. */
|
|
1087
|
+
async runTool(call, runId, signal, truncated, parentId) {
|
|
1085
1088
|
const id = call.id ?? "";
|
|
1089
|
+
const nested = parentId ? { parentId } : {};
|
|
1086
1090
|
const name = call.function.name;
|
|
1087
1091
|
const started = Date.now();
|
|
1088
1092
|
let progress;
|
|
1089
1093
|
let tool;
|
|
1090
1094
|
const finish = (status, content, details) => {
|
|
1091
1095
|
const result = textOf(content);
|
|
1092
|
-
this.emit("tool_end", { runId, id, name, status, result, details, durationMs: Date.now() - started, ...(typeof content === "string" ? {} : { content }) });
|
|
1096
|
+
this.emit("tool_end", { runId, id, name, status, result: parentId ? truncate(result, DEFAULT_MAX_RESULT_CHARS).text : result, details, durationMs: Date.now() - started, ...nested, ...(typeof content === "string" ? {} : { content }) });
|
|
1093
1097
|
return {
|
|
1098
|
+
status,
|
|
1099
|
+
details,
|
|
1094
1100
|
message: { role: "tool", tool_call_id: id, content },
|
|
1095
1101
|
// A read is judged by what it returned (another range of the same lines is nothing new); a change by what it was asked to do too.
|
|
1096
1102
|
key: tool?.readOnly ? `${name}|${status}|${result.slice(0, 4000)}` : `${name}|${call.function.arguments.slice(0, 4000)}|${status}|${result.slice(0, 2000)}`,
|
|
@@ -1103,7 +1109,7 @@ export class Agent {
|
|
|
1103
1109
|
return finish("skipped", SKIPPED_STOP);
|
|
1104
1110
|
if (truncated) {
|
|
1105
1111
|
// pi: nothing from a reply cut by the output limit runs.
|
|
1106
|
-
this.emit("tool_start", { runId, id, name, args: call.function.arguments });
|
|
1112
|
+
this.emit("tool_start", { runId, id, name, args: call.function.arguments, ...nested });
|
|
1107
1113
|
return finish("error", `Tool call "${name}" was not executed: the response hit the output token limit, so its arguments may be truncated. Re-issue the tool call with complete arguments.`);
|
|
1108
1114
|
}
|
|
1109
1115
|
const offered = await this.activeTools();
|
|
@@ -1113,10 +1119,10 @@ export class Agent {
|
|
|
1113
1119
|
args = call.function.arguments.trim() ? JSON.parse(call.function.arguments) : {};
|
|
1114
1120
|
}
|
|
1115
1121
|
catch {
|
|
1116
|
-
this.emit("tool_start", { runId, id, name, args: call.function.arguments });
|
|
1122
|
+
this.emit("tool_start", { runId, id, name, args: call.function.arguments, ...nested });
|
|
1117
1123
|
return finish("error", "Error: the arguments are not valid JSON.");
|
|
1118
1124
|
}
|
|
1119
|
-
this.emit("tool_start", { runId, id, name, args });
|
|
1125
|
+
this.emit("tool_start", { runId, id, name, args, ...nested });
|
|
1120
1126
|
if (!tool)
|
|
1121
1127
|
return finish("error", `Error: there is no tool named "${name}". Available tools: ${offered.map((t) => t.name).join(", ")}.`);
|
|
1122
1128
|
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
@@ -1159,13 +1165,14 @@ export class Agent {
|
|
|
1159
1165
|
try {
|
|
1160
1166
|
const own = tool.whenStopped?.(args);
|
|
1161
1167
|
if (own !== undefined) {
|
|
1162
|
-
const norm = normalizeResult(own, tool.maxResultChars);
|
|
1168
|
+
const norm = normalizeResult(own, parentId ? NESTED_RESULT_CHARS : tool.maxResultChars);
|
|
1163
1169
|
return finish("skipped", norm.content, norm.details);
|
|
1164
1170
|
}
|
|
1165
1171
|
}
|
|
1166
1172
|
catch { /* the default note */ }
|
|
1167
1173
|
return finish("skipped", SKIPPED_STOP);
|
|
1168
1174
|
};
|
|
1175
|
+
let inner = 0;
|
|
1169
1176
|
try {
|
|
1170
1177
|
const value = await raceAbort(Promise.resolve(tool.execute(args, {
|
|
1171
1178
|
signal,
|
|
@@ -1173,12 +1180,17 @@ export class Agent {
|
|
|
1173
1180
|
workspace: this.workspace,
|
|
1174
1181
|
agent: this,
|
|
1175
1182
|
callId: id,
|
|
1176
|
-
|
|
1183
|
+
parentId,
|
|
1184
|
+
update: (content) => this.emit("tool_update", { runId, id, name, content, ...nested }),
|
|
1177
1185
|
progress: (made) => { progress = made; },
|
|
1186
|
+
callTool: async (toolName, toolArgs, o) => {
|
|
1187
|
+
const out = await this.runTool({ id: `${id}.${++inner}`, type: "function", function: { name: toolName, arguments: JSON.stringify(toolArgs ?? {}) } }, runId, o?.signal ?? signal, false, id);
|
|
1188
|
+
return { status: out.status, text: textOf(out.message.content), details: out.details };
|
|
1189
|
+
},
|
|
1178
1190
|
})), signal);
|
|
1179
1191
|
if (signal.aborted)
|
|
1180
1192
|
return stoppedIn();
|
|
1181
|
-
const norm = normalizeResult(value, tool.maxResultChars);
|
|
1193
|
+
const norm = normalizeResult(value, parentId ? NESTED_RESULT_CHARS : tool.maxResultChars);
|
|
1182
1194
|
return finish("ok", norm.content, norm.details);
|
|
1183
1195
|
}
|
|
1184
1196
|
catch (err) {
|