@runappsai/agent 0.1.5 → 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 +109 -101
- package/dist/agent.d.ts +1 -0
- package/dist/agent.js +27 -13
- package/dist/agent.umd.js +147 -138
- package/dist/chat.js +65 -23
- package/dist/context.js +14 -3
- 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 +138 -84
- 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 +53 -21
- 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)}
|
|
@@ -783,6 +784,7 @@ function parseAttachLine(line) {
|
|
|
783
784
|
const typedOf = (m) => m?.typed;
|
|
784
785
|
/** Added to the agent's instructions when it has a directory: how to hand a file to the user. */
|
|
785
786
|
const linksHint = (uploads) => `When you create or change a file for the user, name its absolute path in backticks (for example \`/index.html\`); in the chat that path becomes a link that opens the file. Files the user attaches arrive under ${uploads}.`;
|
|
787
|
+
const attachHint = (uploads) => `Files the user attaches arrive under ${uploads}.`;
|
|
786
788
|
const filesHint = (uploads) => `The user can browse, edit and download every file of the directory from the chat's Files panel. When you create or change a file for the user, name its absolute path in backticks (for example \`${uploads}/report.csv\`); in the chat that path becomes a link that opens the file, with a download button. Files the user attaches arrive under ${uploads}.`;
|
|
787
789
|
/** Text when the type or extension says so, or when the first 8 KB hold no NUL byte and decode as UTF-8. */
|
|
788
790
|
function decodeText(file, bytes) {
|
|
@@ -970,6 +972,16 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
970
972
|
},
|
|
971
973
|
};
|
|
972
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
|
+
};
|
|
973
985
|
const LAST_KEY = (project) => `__runapps_agent_chat:${project}:last`;
|
|
974
986
|
function readLast(project) {
|
|
975
987
|
try {
|
|
@@ -1970,11 +1982,11 @@ export function renderChat(target, opts) {
|
|
|
1970
1982
|
const text = code.textContent?.trim() ?? "";
|
|
1971
1983
|
if (!/^\/[^\s`'"<>]+$/.test(text) || text.length > 200)
|
|
1972
1984
|
continue;
|
|
1973
|
-
void ws
|
|
1985
|
+
void isFile(ws, text).then((ok) => { if (ok && !code.classList.contains("ra-path")) {
|
|
1974
1986
|
code.classList.add("ra-path");
|
|
1975
1987
|
code.dataset.path = text;
|
|
1976
1988
|
code.title = t.open;
|
|
1977
|
-
code.insertAdjacentHTML("beforeend", I.
|
|
1989
|
+
code.insertAdjacentHTML("beforeend", I.file(11));
|
|
1978
1990
|
} });
|
|
1979
1991
|
}
|
|
1980
1992
|
};
|
|
@@ -2042,8 +2054,10 @@ export function renderChat(target, opts) {
|
|
|
2042
2054
|
const end = h("span", "ra-tend");
|
|
2043
2055
|
end.innerHTML = '<span class="ra-spin"></span>';
|
|
2044
2056
|
sum.innerHTML = `<span class="ra-chev">${I.chev()}</span>`;
|
|
2045
|
-
|
|
2046
|
-
|
|
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) {
|
|
2047
2061
|
title.title = name;
|
|
2048
2062
|
title.classList.add("own");
|
|
2049
2063
|
}
|
|
@@ -2051,18 +2065,6 @@ export function renderChat(target, opts) {
|
|
|
2051
2065
|
const tb = h("div", "ra-tbody");
|
|
2052
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));
|
|
2053
2067
|
tb.append(h("div", "ra-tlabel", t.args), argsPre);
|
|
2054
|
-
const path = args && typeof args === "object" && typeof args.path === "string" ? args.path : null;
|
|
2055
|
-
if (path && name !== "delete_file" && name !== "list_files" && name !== "search_files") {
|
|
2056
|
-
const acts = h("div", "ra-tacts");
|
|
2057
|
-
const o = h("button", "ra-open", `${t.open} ${path}`);
|
|
2058
|
-
o.type = "button";
|
|
2059
|
-
o.addEventListener("click", () => openPath(path));
|
|
2060
|
-
const d = h("button", "ra-open", t.download);
|
|
2061
|
-
d.type = "button";
|
|
2062
|
-
d.addEventListener("click", () => void panel.download(path));
|
|
2063
|
-
acts.append(o, d);
|
|
2064
|
-
tb.append(acts);
|
|
2065
|
-
}
|
|
2066
2068
|
el.append(sum, tb);
|
|
2067
2069
|
const card = { el, name, args, end, body: tb, update: null, result: null };
|
|
2068
2070
|
renderCustom(card, { status: "running" });
|
|
@@ -2171,9 +2173,18 @@ export function renderChat(target, opts) {
|
|
|
2171
2173
|
chev.innerHTML = I.chev(12);
|
|
2172
2174
|
sum.append(chev);
|
|
2173
2175
|
};
|
|
2174
|
-
const addCard = (id, name, args, body) => {
|
|
2176
|
+
const addCard = (id, name, args, body, parent) => {
|
|
2175
2177
|
const card = makeCard(name, args);
|
|
2176
|
-
|
|
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);
|
|
2177
2188
|
cards.set(id, card);
|
|
2178
2189
|
refreshGroup(card.el);
|
|
2179
2190
|
list.schedule();
|
|
@@ -2181,6 +2192,27 @@ export function renderChat(target, opts) {
|
|
|
2181
2192
|
};
|
|
2182
2193
|
/** Pictures a tool returned, shown under its result (a screenshot, a chart). */
|
|
2183
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
|
+
};
|
|
2184
2216
|
const finishCard = (card, status, result, durationMs, images = [], details) => {
|
|
2185
2217
|
const ok = status === "ok";
|
|
2186
2218
|
const fail = status === "error" || status === "blocked";
|
|
@@ -2206,6 +2238,13 @@ export function renderChat(target, opts) {
|
|
|
2206
2238
|
card.el.classList.toggle("fail", fail);
|
|
2207
2239
|
renderCustom(card, { status, result, details });
|
|
2208
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
|
+
}
|
|
2209
2248
|
if (!card.result) {
|
|
2210
2249
|
card.result = h("pre", "");
|
|
2211
2250
|
card.body.append(h("div", "ra-tlabel", status === "error" ? t.error : t.result), card.result);
|
|
@@ -3975,7 +4014,7 @@ export function renderChat(target, opts) {
|
|
|
3975
4014
|
if (hiddenTools.has(ev.name))
|
|
3976
4015
|
return;
|
|
3977
4016
|
flushActive(true);
|
|
3978
|
-
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);
|
|
3979
4018
|
// The folded group says which tool; the preview shows what it is doing.
|
|
3980
4019
|
const r = describeRunning({ name: ev.name, args: ev.args }, card.el);
|
|
3981
4020
|
// A file's name goes in the label; anything longer (code, a query) is the preview's.
|
|
@@ -4083,8 +4122,11 @@ export function renderChat(target, opts) {
|
|
|
4083
4122
|
const workspace = typeof wsOpt === "function" ? await wsOpt(sid) : wsOpt ?? null;
|
|
4084
4123
|
// The host's instructions may be a function (re-read every turn): the hint joins whatever it returns.
|
|
4085
4124
|
const base = agentOpts.instructions;
|
|
4086
|
-
|
|
4087
|
-
const
|
|
4125
|
+
// Only about what the model can do: no file tools, nothing about files (attachments then go into the message); read-only, only where attachments land.
|
|
4126
|
+
const fileOpt = agentOpts.fileTools;
|
|
4127
|
+
const writes = fileOpt === undefined || fileOpt === true || (Array.isArray(fileOpt) && (fileOpt.includes("write_file") || fileOpt.includes("edit_file")));
|
|
4128
|
+
const hint = fileOpt === false ? "" : !writes ? attachHint(uploadsDir) : filesOpt === false ? linksHint(uploadsDir) : filesHint(uploadsDir);
|
|
4129
|
+
const instructions = !workspace || !hint ? base : typeof base === "function" ? () => [base(), hint].filter(Boolean).join("\n\n") : [base, hint].filter(Boolean).join("\n\n");
|
|
4088
4130
|
const over = {};
|
|
4089
4131
|
if (userSettings.model)
|
|
4090
4132
|
over.model = userSettings.model;
|
package/dist/context.js
CHANGED
|
@@ -23,22 +23,33 @@ 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"));
|
|
30
|
+
// Only what the model can really call: a tool it does not have costs a failed turn.
|
|
31
|
+
const has = (name) => input.tools.some((t) => t.name === name);
|
|
28
32
|
if (input.workspaceDescription) {
|
|
33
|
+
const look = ["list_files", "read_file"].filter(has);
|
|
34
|
+
const uses = [
|
|
35
|
+
look.length ? `${look.join(" and ")} to look around` : "",
|
|
36
|
+
has("edit_file") ? "edit_file for small changes (each oldText must match exactly once)" : "",
|
|
37
|
+
has("write_file") ? "write_file for new files or rewrites" : "",
|
|
38
|
+
].filter(Boolean);
|
|
29
39
|
out.push("# Workspace\nYou have a file tree (absolute POSIX paths).\n" + input.workspaceDescription +
|
|
30
|
-
|
|
40
|
+
(uses.length ? `\nUse ${uses.join(", ")}.` : "") +
|
|
41
|
+
(has("write_file") && has("edit_file") ? " A reply has an output limit: a file longer than you can emit in one call is written in parts — write_file the first part, then edit_file to append the rest (oldText = the last lines written) — never one huge write_file." : "") +
|
|
31
42
|
(input.canWrite && input.memoryPath ? `\nTo remember something for later conversations (a preference, a decision, a fact about the user's project), append a short line to ${input.memoryPath}; it is shown to you at the start of every conversation.` : ""));
|
|
32
43
|
}
|
|
33
44
|
if (input.memory?.trim()) {
|
|
34
45
|
out.push(`# Memory\nYour notes from earlier conversations (${input.memoryPath ?? "/memory/notes.md"}):\n` + input.memory.trim());
|
|
35
46
|
}
|
|
36
47
|
const visible = input.skills.filter((s) => !s.disableModelInvocation);
|
|
37
|
-
if (visible.length) {
|
|
48
|
+
if (visible.length && has("read_file")) {
|
|
38
49
|
const esc = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
39
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." +
|
|
40
51
|
(input.hasSandbox
|
|
41
|
-
? "\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."
|
|
42
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.") +
|
|
43
54
|
"\n\n<available_skills>\n" +
|
|
44
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;
|