@runappsai/agent 0.1.6 → 0.1.7
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 +124 -115
- 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 +48 -19
- 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/chat.js
CHANGED
|
@@ -39,7 +39,7 @@ const STRINGS = {
|
|
|
39
39
|
attach: "Attach files", drop: "Drop files to attach", tooLarge: "is too large (max 20 MB)", remove: "Remove",
|
|
40
40
|
toolsRunning: "Running", toolsDone: "Ran {n} tool calls", toolsDone1: "Ran 1 tool call", toolsFailed: "{n} failed",
|
|
41
41
|
actRead: "read {n} file(s)", actList: "listed {n} folder(s)", actSearch: "searched {n} time(s)", actWrite: "wrote {n} file(s)", actEdit: "edited {n} file(s)", actDelete: "deleted {n} file(s)", actRun: "ran {n} snippet(s)", actAsk: "asked you {n} time(s)", actOther: "used {name}",
|
|
42
|
-
ingRead: "Reading", ingList: "Listing", ingSearch: "Searching", ingWrite: "Writing", ingEdit: "Editing", ingDelete: "Deleting", ingRun: "Running code", ingAsk: "Asking you", ingOther: "Running", current: "Current", jumpEnd: "Jump to the latest",
|
|
42
|
+
runCode: "Run code", ingRead: "Reading", ingList: "Listing", ingSearch: "Searching", ingWrite: "Writing", ingEdit: "Editing", ingDelete: "Deleting", ingRun: "Running code", ingAsk: "Asking you", ingOther: "Running", current: "Current", jumpEnd: "Jump to the latest",
|
|
43
43
|
sTabModel: "Model", debug: "Debug", dCalls: "Calls", dRequests: "Requests", dEvents: "Events", dContext: "Context", dTools: "Tools", dClear: "Clear the record", dFilter: "Filter by type",
|
|
44
44
|
dNoCalls: "No tool calls yet.", dNoRequests: "No model requests yet. Each call to the model is listed here with what was sent and what came back.", dNoEvents: "No events yet.",
|
|
45
45
|
dSystem: "System prompt", dMessages: "Messages sent to the model", dPayload: "Request", dResponse: "Response", dRun: "Run", dTurn: "Turn {n}", sent: "sent", justNow: "Just now", minutesAgo: "{n} min ago", hoursAgo: "{n} h ago", context: "context", copy: "Copy", copied: "Copied", rewind: "Rewind to here", rewindTitle: "Rewind to this message", regen: "Answer again", regenTitle: "Answer this question again", regenMsg: "This answer and what follows are dropped and the question is sent again.", delTurn: "Delete", delTurnTitle: "Delete this question and its answer?", delTurnMsg: "They are removed from the conversation; files stay as they are.", replyCost: "Cost: {cost}", replyUsage: "{in} in · {out} out · {calls} calls",
|
|
@@ -78,7 +78,7 @@ const STRINGS = {
|
|
|
78
78
|
attach: "添加附件", drop: "松开即可添加附件", tooLarge: "太大了(最大 20 MB)", remove: "移除",
|
|
79
79
|
toolsRunning: "正在执行", toolsDone: "执行了 {n} 个工具调用", toolsDone1: "执行了 1 个工具调用", toolsFailed: "{n} 个失败",
|
|
80
80
|
actRead: "读取了 {n} 个文件", actList: "查看了 {n} 个目录", actSearch: "搜索了 {n} 次", actWrite: "写入了 {n} 个文件", actEdit: "修改了 {n} 个文件", actDelete: "删除了 {n} 个文件", actRun: "运行了 {n} 段代码", actAsk: "询问了你 {n} 次", actOther: "调用了 {name}",
|
|
81
|
-
ingRead: "正在读取", ingList: "正在查看", ingSearch: "正在搜索", ingWrite: "正在写入", ingEdit: "正在修改", ingDelete: "正在删除", ingRun: "正在运行代码", ingAsk: "正在询问你", ingOther: "正在执行", current: "当前", jumpEnd: "回到最新",
|
|
81
|
+
runCode: "运行代码", ingRead: "正在读取", ingList: "正在查看", ingSearch: "正在搜索", ingWrite: "正在写入", ingEdit: "正在修改", ingDelete: "正在删除", ingRun: "正在运行代码", ingAsk: "正在询问你", ingOther: "正在执行", current: "当前", jumpEnd: "回到最新",
|
|
82
82
|
sTabModel: "模型", debug: "调试", dCalls: "调用", dRequests: "请求", dEvents: "事件", dContext: "上下文", dTools: "工具", dClear: "清空记录", dFilter: "按类型过滤",
|
|
83
83
|
dNoCalls: "还没有工具调用。", dNoRequests: "还没有模型请求。每次调用模型都会记在这里,包括发了什么、收到什么。", dNoEvents: "还没有事件。",
|
|
84
84
|
dSystem: "系统提示词", dMessages: "发给模型的消息", dPayload: "请求内容", dResponse: "响应", dRun: "运行", dTurn: "第 {n} 轮", sent: "已发送", justNow: "刚刚", minutesAgo: "{n} 分钟前", hoursAgo: "{n} 小时前", context: "上下文", copy: "复制", copied: "已复制", rewind: "回退到这里", rewindTitle: "回退到这条消息", regen: "重新回答", regenTitle: "重新回答这个问题", regenMsg: "这个回答及之后的对话会被删除,问题重新发送。", delTurn: "删除", delTurnTitle: "删除这一轮问答?", delTurnMsg: "这条提问和它的回答会从对话中删除,文件不受影响。", replyCost: "费用:{cost}", replyUsage: "输入 {in} · 输出 {out} · {calls} 次调用",
|
|
@@ -365,6 +365,7 @@ const CSS = tokenCSS() + `
|
|
|
365
365
|
.ra-tg .ra-tgb{display:flex;flex-direction:column;gap:8px;margin-top:6px}
|
|
366
366
|
.ra-tool{border:1px solid var(--ra-border);border-radius:6px;overflow:hidden;font-size:14px}
|
|
367
367
|
.ra-tool.fail{border-color:var(--ra-red)}
|
|
368
|
+
.ra-tnest{display:flex;flex-direction:column;gap:4px;margin:6px 0}
|
|
368
369
|
.ra-tool>summary{display:flex;align-items:center;gap:8px;padding:7px 10px;cursor:pointer;list-style:none;user-select:none}
|
|
369
370
|
.ra-tool>summary::-webkit-details-marker{display:none}
|
|
370
371
|
.ra-tool>summary:hover{background:var(--ra-muted)}
|
|
@@ -971,6 +972,16 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
971
972
|
},
|
|
972
973
|
};
|
|
973
974
|
}
|
|
975
|
+
/** Tools whose `path` is a file of the directory; any other tool says so with `display.file`. */
|
|
976
|
+
const FILE_CARD_TOOLS = new Set(["read_file", "write_file", "edit_file"]);
|
|
977
|
+
const isFile = async (ws, path) => {
|
|
978
|
+
try {
|
|
979
|
+
return (await ws.exists(path)) && !(await ws.isFolder(path));
|
|
980
|
+
}
|
|
981
|
+
catch {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
974
985
|
const LAST_KEY = (project) => `__runapps_agent_chat:${project}:last`;
|
|
975
986
|
function readLast(project) {
|
|
976
987
|
try {
|
|
@@ -1971,11 +1982,11 @@ export function renderChat(target, opts) {
|
|
|
1971
1982
|
const text = code.textContent?.trim() ?? "";
|
|
1972
1983
|
if (!/^\/[^\s`'"<>]+$/.test(text) || text.length > 200)
|
|
1973
1984
|
continue;
|
|
1974
|
-
void ws
|
|
1985
|
+
void isFile(ws, text).then((ok) => { if (ok && !code.classList.contains("ra-path")) {
|
|
1975
1986
|
code.classList.add("ra-path");
|
|
1976
1987
|
code.dataset.path = text;
|
|
1977
1988
|
code.title = t.open;
|
|
1978
|
-
code.insertAdjacentHTML("beforeend", I.
|
|
1989
|
+
code.insertAdjacentHTML("beforeend", I.file(11));
|
|
1979
1990
|
} });
|
|
1980
1991
|
}
|
|
1981
1992
|
};
|
|
@@ -2043,8 +2054,10 @@ export function renderChat(target, opts) {
|
|
|
2043
2054
|
const end = h("span", "ra-tend");
|
|
2044
2055
|
end.innerHTML = '<span class="ra-spin"></span>';
|
|
2045
2056
|
sum.innerHTML = `<span class="ra-chev">${I.chev()}</span>`;
|
|
2046
|
-
|
|
2047
|
-
|
|
2057
|
+
// The model's name for it means nothing to a reader; its first line of code is the summary beside it.
|
|
2058
|
+
const shown = label ?? (name === "run_js" ? t.runCode : undefined);
|
|
2059
|
+
const title = h("span", "ra-tname", shown ?? name);
|
|
2060
|
+
if (shown) {
|
|
2048
2061
|
title.title = name;
|
|
2049
2062
|
title.classList.add("own");
|
|
2050
2063
|
}
|
|
@@ -2052,18 +2065,6 @@ export function renderChat(target, opts) {
|
|
|
2052
2065
|
const tb = h("div", "ra-tbody");
|
|
2053
2066
|
const argsPre = h("pre", "", name === "run_js" && args && typeof args === "object" && typeof args.code === "string" ? args.code : typeof args === "string" ? args : JSON.stringify(args, null, 2));
|
|
2054
2067
|
tb.append(h("div", "ra-tlabel", t.args), argsPre);
|
|
2055
|
-
const path = args && typeof args === "object" && typeof args.path === "string" ? args.path : null;
|
|
2056
|
-
if (path && name !== "delete_file" && name !== "list_files" && name !== "search_files") {
|
|
2057
|
-
const acts = h("div", "ra-tacts");
|
|
2058
|
-
const o = h("button", "ra-open", `${t.open} ${path}`);
|
|
2059
|
-
o.type = "button";
|
|
2060
|
-
o.addEventListener("click", () => openPath(path));
|
|
2061
|
-
const d = h("button", "ra-open", t.download);
|
|
2062
|
-
d.type = "button";
|
|
2063
|
-
d.addEventListener("click", () => void panel.download(path));
|
|
2064
|
-
acts.append(o, d);
|
|
2065
|
-
tb.append(acts);
|
|
2066
|
-
}
|
|
2067
2068
|
el.append(sum, tb);
|
|
2068
2069
|
const card = { el, name, args, end, body: tb, update: null, result: null };
|
|
2069
2070
|
renderCustom(card, { status: "running" });
|
|
@@ -2172,9 +2173,18 @@ export function renderChat(target, opts) {
|
|
|
2172
2173
|
chev.innerHTML = I.chev(12);
|
|
2173
2174
|
sum.append(chev);
|
|
2174
2175
|
};
|
|
2175
|
-
const addCard = (id, name, args, body) => {
|
|
2176
|
+
const addCard = (id, name, args, body, parent) => {
|
|
2176
2177
|
const card = makeCard(name, args);
|
|
2177
|
-
|
|
2178
|
+
if (parent) {
|
|
2179
|
+
// A call made from inside another (run_js's tools.x()): under that call's code, its result after it.
|
|
2180
|
+
if (!parent.nested) {
|
|
2181
|
+
parent.nested = h("div", "ra-tnest");
|
|
2182
|
+
parent.body.append(parent.nested);
|
|
2183
|
+
}
|
|
2184
|
+
parent.nested.append(card.el);
|
|
2185
|
+
}
|
|
2186
|
+
else
|
|
2187
|
+
groupIn(body).append(card.el);
|
|
2178
2188
|
cards.set(id, card);
|
|
2179
2189
|
refreshGroup(card.el);
|
|
2180
2190
|
list.schedule();
|
|
@@ -2182,6 +2192,27 @@ export function renderChat(target, opts) {
|
|
|
2182
2192
|
};
|
|
2183
2193
|
/** Pictures a tool returned, shown under its result (a screenshot, a chart). */
|
|
2184
2194
|
const imagesOf = (content) => Array.isArray(content) ? content.flatMap((p) => (p.type === "image_url" && /^(data:image\/|https?:)/.test(p.image_url.url) ? [p.image_url.url] : [])) : [];
|
|
2195
|
+
/** The file a finished call is about, when it really is one: open it and, unless the app handles files itself, download it. */
|
|
2196
|
+
const offerFile = async (card) => {
|
|
2197
|
+
const ws = agent?.workspace;
|
|
2198
|
+
const d = displayOf(card.name), a = card.args;
|
|
2199
|
+
const path = d?.file ? tryDisplay(() => d.file(card.args)) : FILE_CARD_TOOLS.has(card.name) && a && typeof a === "object" && typeof a.path === "string" ? a.path : null;
|
|
2200
|
+
if (!ws || !path || !(await isFile(ws, path)))
|
|
2201
|
+
return;
|
|
2202
|
+
const acts = h("div", "ra-tacts");
|
|
2203
|
+
const o = h("button", "ra-open", `${t.open} ${path}`);
|
|
2204
|
+
o.type = "button";
|
|
2205
|
+
o.addEventListener("click", () => openPath(path));
|
|
2206
|
+
acts.append(o);
|
|
2207
|
+
if (!onOpenFile) {
|
|
2208
|
+
const dl = h("button", "ra-open", t.download);
|
|
2209
|
+
dl.type = "button";
|
|
2210
|
+
dl.addEventListener("click", () => void panel.download(path));
|
|
2211
|
+
acts.append(dl);
|
|
2212
|
+
}
|
|
2213
|
+
card.body.querySelector(":scope>pre")?.after(acts);
|
|
2214
|
+
list.schedule();
|
|
2215
|
+
};
|
|
2185
2216
|
const finishCard = (card, status, result, durationMs, images = [], details) => {
|
|
2186
2217
|
const ok = status === "ok";
|
|
2187
2218
|
const fail = status === "error" || status === "blocked";
|
|
@@ -2207,6 +2238,13 @@ export function renderChat(target, opts) {
|
|
|
2207
2238
|
card.el.classList.toggle("fail", fail);
|
|
2208
2239
|
renderCustom(card, { status, result, details });
|
|
2209
2240
|
card.update?.remove();
|
|
2241
|
+
// Asked when the card is opened: the file may be gone by then, and a folded card costs nothing.
|
|
2242
|
+
if (ok) {
|
|
2243
|
+
if (card.el.open)
|
|
2244
|
+
void offerFile(card);
|
|
2245
|
+
else
|
|
2246
|
+
card.el.addEventListener("toggle", () => void offerFile(card), { once: true });
|
|
2247
|
+
}
|
|
2210
2248
|
if (!card.result) {
|
|
2211
2249
|
card.result = h("pre", "");
|
|
2212
2250
|
card.body.append(h("div", "ra-tlabel", status === "error" ? t.error : t.result), card.result);
|
|
@@ -3976,7 +4014,7 @@ export function renderChat(target, opts) {
|
|
|
3976
4014
|
if (hiddenTools.has(ev.name))
|
|
3977
4015
|
return;
|
|
3978
4016
|
flushActive(true);
|
|
3979
|
-
const card = addCard(ev.id, ev.name, ev.args, ensureActive().body);
|
|
4017
|
+
const card = addCard(ev.id, ev.name, ev.args, ensureActive().body, ev.parentId ? cards.get(ev.parentId) : undefined);
|
|
3980
4018
|
// The folded group says which tool; the preview shows what it is doing.
|
|
3981
4019
|
const r = describeRunning({ name: ev.name, args: ev.args }, card.el);
|
|
3982
4020
|
// A file's name goes in the label; anything longer (code, a query) is the preview's.
|
package/dist/context.js
CHANGED
|
@@ -23,6 +23,8 @@ export function buildSystemPrompt(input) {
|
|
|
23
23
|
}
|
|
24
24
|
if (input.hasSandbox) {
|
|
25
25
|
rules.push("For arithmetic, dates, counting, parsing or any other computation, run run_js instead of working it out in your head, and report the computed result.");
|
|
26
|
+
if (input.tools.some((t) => t.name === "read_file"))
|
|
27
|
+
rules.push("Inside run_js, tools.read_file({ path }) returns the whole file and tools.list_files the whole list; the output limits apply only when you call them yourself.");
|
|
26
28
|
}
|
|
27
29
|
out.push("# How to work\n" + rules.map((r) => `- ${r}`).join("\n"));
|
|
28
30
|
// Only what the model can really call: a tool it does not have costs a failed turn.
|
|
@@ -47,7 +49,7 @@ export function buildSystemPrompt(input) {
|
|
|
47
49
|
const esc = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
48
50
|
out.push("# Skills\nThe following skills provide specialized instructions for specific tasks.\nUse read_file to load a skill's file when the task matches its description.\nWhen a skill file references a relative path, resolve it against the skill directory (the folder of SKILL.md) and use that absolute path in tool calls." +
|
|
49
51
|
(input.hasSandbox
|
|
50
|
-
? "\nThe only runtime here is run_js (JavaScript in a sandbox: no shell, no Python, no network). A skill's scripts written for another language (Python, shell, Ruby…) cannot be run as they are: read the script, port its logic to JavaScript and run that with run_js, keeping the same inputs, outputs and behaviour (
|
|
52
|
+
? "\nThe only runtime here is run_js (JavaScript in a sandbox: no shell, no Python, no network). A skill's scripts written for another language (Python, shell, Ruby…) cannot be run as they are: read the script, port its logic to JavaScript and run that with run_js, keeping the same inputs, outputs and behaviour (tools.read_file for files the script reads; browser-safe APIs only — no npm imports, no subprocesses, no network); tell the user it was ported. If a script truly needs what the sandbox lacks (a binary, a network service), say so and do the part that can be done."
|
|
51
53
|
: "\nThere is no runtime for scripts here: a skill's scripts (Python, shell, JavaScript…) cannot be executed; follow their logic by hand where feasible and say so, or tell the user what cannot be done.") +
|
|
52
54
|
"\n\n<available_skills>\n" +
|
|
53
55
|
visible.map((s) => ` <skill>\n <name>${esc(s.name)}</name>\n <description>${esc(s.description)}</description>\n <location>${esc(s.path)}</location>\n </skill>`).join("\n") +
|
package/dist/dialogs.js
CHANGED
|
@@ -169,6 +169,8 @@ export function nullUI() {
|
|
|
169
169
|
export function askUserTool() {
|
|
170
170
|
return defineTool({
|
|
171
171
|
name: "ask_user",
|
|
172
|
+
// The model asks, between its steps; code in the middle of a run does not.
|
|
173
|
+
callableFromCode: false,
|
|
172
174
|
description: "Ask the user one to three questions when the request is genuinely ambiguous and the answer changes what you would do. Give 2–5 short options when there are natural choices (allow_other adds a free-text choice); leave options out for a free-text answer. Do not ask what you can reasonably decide yourself.",
|
|
173
175
|
parameters: {
|
|
174
176
|
type: "object",
|
package/dist/file-guard.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Read before write: what the model has seen of each file, so that it does
|
|
2
2
|
// not overwrite, edit or delete a file from a stale or partial view — the
|
|
3
3
|
// user may edit files while it works. One guard per agent, shared by the
|
|
4
|
-
// file tools
|
|
4
|
+
// file tools; when the conversation is compacted or
|
|
5
5
|
// rewound it forgets the files whose contents the model no longer has.
|
|
6
6
|
import { decodeText } from "./workspace.js";
|
|
7
7
|
/** Content larger than this is versioned by time and size alone (not read to fingerprint it). */
|
package/dist/file-tools.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface FileToolsOptions {
|
|
|
10
10
|
* file can always be written.
|
|
11
11
|
*/
|
|
12
12
|
readBeforeWrite?: boolean;
|
|
13
|
-
/** The agent's guard
|
|
13
|
+
/** The agent's guard (made here when not given). */
|
|
14
14
|
guard?: FileGuard;
|
|
15
15
|
}
|
|
16
16
|
export declare function fileTools(ws: Workspace, opts?: FileToolsOptions): Tool[];
|
package/dist/file-tools.js
CHANGED
|
@@ -31,12 +31,14 @@ export function fileTools(ws, opts = {}) {
|
|
|
31
31
|
properties: { path: { type: "string", description: "Folder to list. Default /" } },
|
|
32
32
|
additionalProperties: false,
|
|
33
33
|
},
|
|
34
|
-
async execute({ path }) {
|
|
34
|
+
async execute({ path }, ctx) {
|
|
35
35
|
const files = await ws.list(path || "/");
|
|
36
36
|
if (!files.length)
|
|
37
37
|
return `No files under ${normalizePath(path || "/")}.`;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// Called from code the whole list: the limit is there for what the model has to read.
|
|
39
|
+
const max = ctx?.parentId ? Infinity : MAX_LIST;
|
|
40
|
+
const lines = files.slice(0, max).map((f) => `${f.path} (${f.size} B)`);
|
|
41
|
+
if (files.length > max)
|
|
40
42
|
lines.push(`\n[${MAX_LIST} entries limit reached (${files.length} in all). List a sub-folder.]`);
|
|
41
43
|
return lines.join("\n");
|
|
42
44
|
},
|
|
@@ -99,13 +101,15 @@ export function fileTools(ws, opts = {}) {
|
|
|
99
101
|
await files.saw(normalizePath(path), { start: total + 1, end: total, total });
|
|
100
102
|
return `Offset ${start} is beyond end of file (${total} lines total)`;
|
|
101
103
|
}
|
|
102
|
-
|
|
104
|
+
// Called from code the whole file: the limits are there for what the model has to read.
|
|
105
|
+
const whole = !!ctx?.parentId;
|
|
106
|
+
const want = whole ? limit ?? Infinity : limit !== undefined ? Math.min(limit, MAX_READ_LINES) : MAX_READ_LINES;
|
|
103
107
|
const out = [];
|
|
104
108
|
let bytes = 0;
|
|
105
109
|
let end = start - 1;
|
|
106
110
|
for (let i = start - 1; i < total && out.length < want; i++) {
|
|
107
111
|
const b = new TextEncoder().encode(lines[i]).byteLength + 1;
|
|
108
|
-
if (bytes + b > MAX_READ_BYTES && out.length > 0)
|
|
112
|
+
if (!whole && bytes + b > MAX_READ_BYTES && out.length > 0)
|
|
109
113
|
break;
|
|
110
114
|
out.push(lines[i]);
|
|
111
115
|
bytes += b;
|