@runappsai/agent 0.1.15 → 0.2.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 +45 -45
- package/dist/agent.d.ts +20 -0
- package/dist/agent.umd.js +117 -110
- package/dist/chat.d.ts +37 -7
- package/dist/chat.js +158 -39
- package/dist/debug-panel.d.ts +1 -1
- package/dist/debug-panel.js +1 -1
- package/dist/dialogs.js +43 -1
- package/dist/index.cjs +41 -1
- package/dist/index.d.ts +2 -2
- package/dist/provider.d.ts +11 -1
- package/dist/types.d.ts +36 -2
- package/dist/ui.cjs +168 -35
- package/dist/ui.d.ts +1 -0
- package/dist/vlist.d.ts +6 -0
- package/dist/vlist.js +16 -0
- package/docs/chat-ui.md +49 -0
- package/docs/tools.md +1 -0
- package/package.json +1 -1
package/dist/chat.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { type FileDialog } from "./dom.js";
|
|
|
2
2
|
import { type SelectBox } from "./select.js";
|
|
3
3
|
import { type ScheduleStore, type ScheduleLimits } from "./schedule.js";
|
|
4
4
|
import { CHAT_PALETTES, type ChatPalette, type ChatVars } from "./chat-theme.js";
|
|
5
|
-
import {
|
|
6
|
-
import type { ModelProvider, RunAppsClientLike, Workspace, AgentOptions, AgentUI, RunResult } from "./index.js";
|
|
5
|
+
import type { ChatAgent, ModelProvider, RunAppsClientLike, Workspace, AgentOptions, AgentUI, RunResult } from "./index.js";
|
|
7
6
|
export interface ChatOptions extends Omit<AgentOptions, "workspace"> {
|
|
8
7
|
/**
|
|
9
8
|
* Where the model calls go (required unless `agent` is given): a
|
|
@@ -20,7 +19,7 @@ export interface ChatOptions extends Omit<AgentOptions, "workspace"> {
|
|
|
20
19
|
*/
|
|
21
20
|
workspace?: Workspace | null | ((sessionId: string) => Workspace | Promise<Workspace>);
|
|
22
21
|
/** An agent the host made itself; its own `ui` answers questions, and the session menu is off. */
|
|
23
|
-
agent?:
|
|
22
|
+
agent?: ChatAgent;
|
|
24
23
|
/**
|
|
25
24
|
* Which session to open: `true` (default) continues the one this app
|
|
26
25
|
* last had open in this browser (a new chat when there is none), a
|
|
@@ -207,7 +206,36 @@ export interface ChatOptions extends Omit<AgentOptions, "workspace"> {
|
|
|
207
206
|
*/
|
|
208
207
|
composerActions?: Array<HTMLElement | ComposerAction>;
|
|
209
208
|
/** Called with each session's agent as the chat opens it (the first one, a new chat, a resumed one). */
|
|
210
|
-
onSession?: (agent:
|
|
209
|
+
onSession?: (agent: ChatAgent) => void;
|
|
210
|
+
/**
|
|
211
|
+
* Steering and queueing while a run is going (default on). `false`: the
|
|
212
|
+
* composer offers only Stop then, Enter sends nothing and what is typed
|
|
213
|
+
* stays in the box — for an agent that takes one message at a time.
|
|
214
|
+
*/
|
|
215
|
+
queue?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* The actions under a message, each on unless `false`: `rewind` (a user
|
|
218
|
+
* message: back to it, its text in the composer), `retry` ("Answer again"
|
|
219
|
+
* under a reply) and `delete` (remove the turn, which needs the agent's `remove`).
|
|
220
|
+
*/
|
|
221
|
+
replyActions?: {
|
|
222
|
+
rewind?: boolean;
|
|
223
|
+
retry?: boolean;
|
|
224
|
+
delete?: boolean;
|
|
225
|
+
};
|
|
226
|
+
/** Elements of your own at the start of the header, before the title (a button that opens the host's list of conversations). */
|
|
227
|
+
headerStart?: HTMLElement[];
|
|
228
|
+
/** The header's Clear button of a one-chat chat (default on); `false` when the host clears or deletes conversations itself. */
|
|
229
|
+
clearButton?: boolean;
|
|
230
|
+
/** The built-in slash commands to keep, by name ("help", "compact", "model", "context", "export", …). Default: all that apply. */
|
|
231
|
+
commands?: string[];
|
|
232
|
+
/**
|
|
233
|
+
* Uploads an attached image and returns its address: the message then
|
|
234
|
+
* carries that address instead of the image's bytes as a data URL (small
|
|
235
|
+
* messages; the host's server reads the image from where it was put).
|
|
236
|
+
* A rejection drops the image and tells the user why.
|
|
237
|
+
*/
|
|
238
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
211
239
|
}
|
|
212
240
|
/** A setting of the host's in the gear's panel. */
|
|
213
241
|
export type SettingsField = {
|
|
@@ -253,7 +281,7 @@ export interface ComposerAction {
|
|
|
253
281
|
}
|
|
254
282
|
export interface ChatHandle {
|
|
255
283
|
/** The current session's agent (set once `ready` resolves when the workspace is made per session). */
|
|
256
|
-
readonly agent:
|
|
284
|
+
readonly agent: ChatAgent;
|
|
257
285
|
/** Resolves once the first session is open and drawn. */
|
|
258
286
|
readonly ready: Promise<void>;
|
|
259
287
|
readonly element: HTMLElement;
|
|
@@ -265,9 +293,9 @@ export interface ChatHandle {
|
|
|
265
293
|
/** Puts `text` into the composer at the cursor (spaced from what is around it), keeping what was typed. */
|
|
266
294
|
insertText(text: string): void;
|
|
267
295
|
/** Starts a fresh conversation (a new agent with the same options). */
|
|
268
|
-
newSession(): Promise<
|
|
296
|
+
newSession(): Promise<ChatAgent>;
|
|
269
297
|
/** Continues a saved session of the workspace. */
|
|
270
|
-
resume(id: string): Promise<
|
|
298
|
+
resume(id: string): Promise<ChatAgent>;
|
|
271
299
|
/** Deletes a saved session (and the directory made for it); the current one is replaced by a new chat. */
|
|
272
300
|
deleteSession(id: string): Promise<void>;
|
|
273
301
|
/**
|
|
@@ -294,6 +322,8 @@ export interface ChatHandle {
|
|
|
294
322
|
setDebug(on: boolean): void;
|
|
295
323
|
/** Changes a `composerActions` button by its id: label, icon, title, hidden, disabled, onClick. */
|
|
296
324
|
updateComposerAction(id: string, patch: Partial<Omit<ComposerAction, "id">>): void;
|
|
325
|
+
/** Changes the header's title while mounted (a conversation the host names once it knows what it is about). */
|
|
326
|
+
setTitle(title: string): void;
|
|
297
327
|
/** Changes the look while mounted: light/dark, palette, token overrides (each left out stays). */
|
|
298
328
|
setAppearance(opts: {
|
|
299
329
|
theme?: "auto" | "light" | "dark";
|
package/dist/chat.js
CHANGED
|
@@ -46,6 +46,7 @@ const STRINGS = {
|
|
|
46
46
|
sTabModel: "Model", sTabContext: "Context", sCompact: "When the context is nearly full", sCompactSummary: "Summarise older turns (one extra model call)", sCompactTrim: "Only trim: drop old tool results, then the oldest turns", sCompactAt: "Start when fewer tokens than this are left", sKeepRecent: "Keep this many of the newest tokens word for word", sDefaultN: "Default ({n})", sCompactNote: "{model}: starts with {at} tokens left and keeps about {keep} word for word (capped at 20% / 40% of its {window} window)", sCompactNoteTrim: "{model}: trims with fewer than {at} tokens left (capped at 20% of its {window} window)", autoTrim: "Auto-trim", debug: "Debug", dCalls: "Calls", dRequests: "Requests", dEvents: "Events", dContext: "Context", dTools: "Tools", dClear: "Clear the record", dFilter: "Filter by type",
|
|
47
47
|
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.",
|
|
48
48
|
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",
|
|
49
|
+
older: "Load earlier messages", olderBusy: "Wait for the reply to finish, then load earlier messages.",
|
|
49
50
|
rewindMsg: "The conversation after it is dropped and the message goes back into the composer.", rewindFiles: "Also restore the directory's files to that moment", rewindGone: "This message is no longer in the conversation.", rewindSnapshot: "{n} files ({size}) as they were at {time}", rewindPartial: "Files over 2 MB were not in the snapshot and stay as they are.", rewindGoneFile: "{path} is no longer in the directory.",
|
|
50
51
|
running: "running", waitingAnswer: "waiting for your answer", finished: "finished", bgLimit: "{n} conversations are already running in the background; stop one before switching away from this one.",
|
|
51
52
|
settings: "Settings", sVision: "sees pictures", sVisionYes: "sees pictures", sVisionNo: "text only", noVision: "{model} cannot see pictures: they are saved as files, but the model will not see what is in them.", sEffort: "Thinking", sEffortDefault: "Model default", sEffortNone: "this model does not expose a thinking level", sModel: "Model", sDefault: "Platform default", sMaxTurns: "Max turns per run", sMaxTokens: "Max output per reply", sPrice: "Price", sPriceLine: "input {in} · output {out} per M tokens", sPerCall: "{amount} per call", sAuto: "Model's maximum", sCustomN: "Set a number", filter: "Filter…", sPerms: "Tool permissions", sAsk: "Ask before destructive tools", sAutoPerm: "Allow everything", sCustom: "Decided by the app",
|
|
@@ -62,7 +63,7 @@ const STRINGS = {
|
|
|
62
63
|
worked: "Worked for {t}", workedNoTime: "Work", sec: "{s}s", minSec: "{m}m {s}s", hourMin: "{h}h {m}m",
|
|
63
64
|
command: "Command", user: "User", compacting: "Compacting the context…", nothingToCompact: "Nothing to compact yet", busyCmd: "Wait for the current task to finish, or stop it, first", nothingToExport: "Nothing to export yet", nothingToContinue: "Nothing to continue",
|
|
64
65
|
unknownModel: "No model named \"{name}\"", modelSet: "Model: {name}", effortSet: "Thinking: {name}", effortLevels: "Thinking levels of {model}: {levels}", unknownEffort: "\"{name}\" is not a thinking level of {model} ({levels})", debugOff: "Debug mode is off",
|
|
65
|
-
cmdsTitle: "Commands", cmdsMore: "Templates (/name) and skills (/skill:name) are listed as you type.", autoCompact: "Auto-compaction", autoCompactAt: "when less than {n} tokens are left", directory: "Directory", messagesLabel: "Messages",
|
|
66
|
+
cmdsTitle: "Commands", cmdsMore: "Templates (/name) and skills (/skill:name) are listed as you type.", autoCompact: "Auto-compaction", autoCompactAt: "when less than {n} tokens are left", autoCompactFull: "when the context is full", directory: "Directory", messagesLabel: "Messages",
|
|
66
67
|
cmdArgs: { compact: "[focus]", model: "[name]", effort: "[level]" },
|
|
67
68
|
cmd: { help: "Show these commands", new: "Start a new conversation", resume: "Open a saved conversation", compact: "Summarise older turns now; add what the summary must keep", continue: "Continue the last run", model: "Switch model; no name opens the settings", effort: "Set the thinking level", context: "Context use, model and spending", export: "Download the conversation as Markdown", files: "Open the file manager", settings: "Open the settings", debug: "Show or hide the debug panel" },
|
|
68
69
|
},
|
|
@@ -86,6 +87,7 @@ const STRINGS = {
|
|
|
86
87
|
sTabModel: "模型", sTabContext: "上下文", sCompact: "上下文快满时", sCompactSummary: "把较早的对话写成摘要(多一次模型调用)", sCompactTrim: "只裁剪:先删旧的工具结果,再删最早的对话", sCompactAt: "剩余少于多少 tokens 时开始", sKeepRecent: "原样保留最近多少 tokens", sDefaultN: "默认({n})", sCompactNote: "{model}:剩余 {at} tokens 时开始,原样保留约 {keep} tokens(最多为上下文 {window} 的 20% / 40%)", sCompactNoteTrim: "{model}:剩余少于 {at} tokens 时裁剪(最多为上下文 {window} 的 20%)", autoTrim: "自动裁剪", debug: "调试", dCalls: "调用", dRequests: "请求", dEvents: "事件", dContext: "上下文", dTools: "工具", dClear: "清空记录", dFilter: "按类型过滤",
|
|
87
88
|
dNoCalls: "还没有工具调用。", dNoRequests: "还没有模型请求。每次调用模型都会记在这里,包括发了什么、收到什么。", dNoEvents: "还没有事件。",
|
|
88
89
|
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} 次调用",
|
|
90
|
+
older: "加载更早的消息", olderBusy: "等这次回复结束后再加载更早的消息。",
|
|
89
91
|
rewindMsg: "它之后的对话会被删除,消息内容放回输入框。", rewindFiles: "同时把目录里的文件恢复到那一刻", rewindGone: "这条消息已不在对话里(可能已被压缩)。", rewindSnapshot: "{time} 时的 {n} 个文件({size})", rewindPartial: "超过 2 MB 的文件没进快照,会保持原样。", rewindGoneFile: "{path} 已不在目录里。",
|
|
90
92
|
running: "运行中", waitingAnswer: "等待你回答", finished: "已完成", bgLimit: "后台已有 {n} 个会话在运行,先停掉一个再切换。",
|
|
91
93
|
settings: "设置", sVision: "可看图", sVisionYes: "可看图", sVisionNo: "仅文字", noVision: "{model} 不能看图:图片已保存为文件,但模型看不到图里的内容。", sEffort: "思考强度", sEffortDefault: "模型默认", sEffortNone: "这个模型没有思考强度可调", sModel: "模型", sDefault: "平台默认", sMaxTurns: "每次运行最大轮数", sMaxTokens: "单次回复最大输出", sPrice: "单价", sPriceLine: "每百万 tokens 输入 {in} · 输出 {out}", sPerCall: "每次调用 {amount}", sAuto: "模型上限", sCustomN: "自定义", filter: "搜索…", sPerms: "工具权限", sAsk: "破坏性操作先询问", sAutoPerm: "全部自动允许", sCustom: "由应用决定",
|
|
@@ -102,7 +104,7 @@ const STRINGS = {
|
|
|
102
104
|
worked: "已工作 {t}", workedNoTime: "工作过程", sec: "{s}秒", minSec: "{m}分{s}秒", hourMin: "{h}小时{m}分",
|
|
103
105
|
command: "命令", user: "用户", compacting: "正在压缩上下文…", nothingToCompact: "暂时没有可压缩的内容", busyCmd: "请等当前任务结束(或先停止)", nothingToExport: "还没有可导出的内容", nothingToContinue: "没有可继续的内容",
|
|
104
106
|
unknownModel: "没有名为“{name}”的模型", modelSet: "模型:{name}", effortSet: "思考强度:{name}", effortLevels: "{model} 的思考强度:{levels}", unknownEffort: "“{name}”不是 {model} 的思考强度({levels})", debugOff: "调试模式未开启",
|
|
105
|
-
cmdsTitle: "命令", cmdsMore: "模板(/名称)和 Skill(/skill:名称)在输入时列出。", autoCompact: "自动压缩", autoCompactAt: "剩余不足 {n} tokens 时", directory: "目录", messagesLabel: "消息",
|
|
107
|
+
cmdsTitle: "命令", cmdsMore: "模板(/名称)和 Skill(/skill:名称)在输入时列出。", autoCompact: "自动压缩", autoCompactAt: "剩余不足 {n} tokens 时", autoCompactFull: "上下文用满时", directory: "目录", messagesLabel: "消息",
|
|
106
108
|
cmdArgs: { compact: "[重点]", model: "[名称]", effort: "[档位]" },
|
|
107
109
|
cmd: { help: "显示这些命令", new: "开始新对话", resume: "打开保存的对话", compact: "立即压缩较早的对话,可附上要保留的重点", continue: "继续上一次运行", model: "切换模型,不带名称则打开设置", effort: "设置思考强度", context: "上下文占用、模型和花费", export: "把对话下载为 Markdown", files: "打开文件管理", settings: "打开设置", debug: "显示或隐藏调试面板" },
|
|
108
110
|
},
|
|
@@ -343,6 +345,8 @@ const CSS = tokenCSS() + `
|
|
|
343
345
|
@keyframes ra-shimmer{from{background-position:100% 0}to{background-position:0 0}}
|
|
344
346
|
@media (prefers-reduced-motion:reduce){.ra-pending>span{animation:none;color:var(--ra-fg-muted);background:none}}
|
|
345
347
|
.ra-time{text-align:center;font-size:12px;color:var(--ra-fg-muted);padding:14px 0 2px}
|
|
348
|
+
.ra-olderrow{display:flex;justify-content:center;padding:6px 0 2px}
|
|
349
|
+
.ra-chat .ra-older{font-size:12px;color:var(--ra-fg-muted)}
|
|
346
350
|
.ra-work{border-bottom:1px solid var(--ra-border);padding-bottom:6px;margin-bottom:4px}
|
|
347
351
|
.ra-work>summary{display:inline-flex;align-items:center;gap:4px;font-size:13px;color:var(--ra-fg-muted);cursor:pointer;list-style:none;user-select:none;padding:2px 0}
|
|
348
352
|
.ra-work>summary::-webkit-details-marker{display:none}
|
|
@@ -395,6 +399,8 @@ const CSS = tokenCSS() + `
|
|
|
395
399
|
.ra-tool>summary .ra-chev{color:var(--ra-fg-muted);transition:transform .15s}
|
|
396
400
|
.ra-tool[open]>summary .ra-chev{transform:rotate(90deg)}
|
|
397
401
|
.ra-tool .ra-ticon{width:20px;height:20px;border-radius:4px;background:var(--ra-accent-subtle);color:var(--ra-accent-fg);display:inline-flex;align-items:center;justify-content:center}
|
|
402
|
+
.ra-tool .ra-ticon[data-tone="warning"]{background:var(--ra-warn-bg);color:var(--ra-warn-fg)}
|
|
403
|
+
.ra-tool .ra-ticon[data-tone="danger"]{background:var(--ra-red-subtle);color:var(--ra-red)}
|
|
398
404
|
.ra-tool.fail .ra-ticon{background:var(--ra-red-subtle);color:var(--ra-red)}
|
|
399
405
|
.ra-tool .ra-tname{font-weight:600;white-space:nowrap}
|
|
400
406
|
.ra-tool .ra-tname.own{font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis}
|
|
@@ -446,6 +452,9 @@ const CSS = tokenCSS() + `
|
|
|
446
452
|
.ra-q .ra-opt small{display:block;color:var(--ra-fg-muted);font-size:12px}
|
|
447
453
|
.ra-q .ra-field{border:1px solid var(--ra-border);border-radius:6px;padding:6px 10px;background:var(--ra-bg);width:100%;font-size:14px}
|
|
448
454
|
.ra-q .ra-field:focus{border-color:var(--ra-accent)}
|
|
455
|
+
.ra-q .ra-field.bad{border-color:var(--ra-red)}
|
|
456
|
+
.ra-q .ra-form{display:flex;flex-direction:column;gap:8px;margin:2px 0 4px}
|
|
457
|
+
.ra-q .ra-ff{display:flex;flex-direction:column;gap:4px;font-size:13px;color:var(--ra-fg-muted)}
|
|
449
458
|
.ra-q textarea.ra-field{min-height:96px;max-height:200px;resize:vertical}
|
|
450
459
|
.ra-btns{display:flex;justify-content:flex-end;gap:8px}
|
|
451
460
|
.ra-cbody{margin:2px 0 10px;max-height:min(60vh,560px);overflow:auto;min-width:0}
|
|
@@ -946,11 +955,62 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
946
955
|
}
|
|
947
956
|
card.append(list);
|
|
948
957
|
const row = h("div", "ra-btns");
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
958
|
+
const pickedNow = () => inputs.filter((i) => i.checked).map((i) => (i.value === "__other__" ? (other?.value.trim() ?? "") : i.value)).filter(Boolean);
|
|
959
|
+
// How many may be picked (several choices only): OK waits until the count fits.
|
|
960
|
+
const min = opts.multi ? opts.min ?? 1 : 1, max = opts.multi ? opts.max : undefined;
|
|
961
|
+
const fits = (n) => n >= min && (max === undefined || n <= max);
|
|
962
|
+
const okBtn = btn(t.ok, "solid", () => { const picked = pickedNow(); if (fits(picked.length))
|
|
963
|
+
done(picked); });
|
|
964
|
+
if (opts.multi && (opts.min !== undefined || opts.max !== undefined)) {
|
|
965
|
+
const sync = () => { okBtn.disabled = !fits(pickedNow().length); };
|
|
966
|
+
list.addEventListener("change", sync);
|
|
967
|
+
list.addEventListener("input", sync);
|
|
968
|
+
sync();
|
|
969
|
+
}
|
|
970
|
+
row.append(btn(t.cancel, "ghost", () => done(null)), okBtn);
|
|
971
|
+
card.append(row);
|
|
972
|
+
}, null, opts.signal),
|
|
973
|
+
form: (title, fields, opts = {}) => open((card, done) => {
|
|
974
|
+
head(card, title, opts.message);
|
|
975
|
+
const box = h("div", "ra-form");
|
|
976
|
+
const inputs = fields.map((f) => {
|
|
977
|
+
const label = h("label", "ra-ff");
|
|
978
|
+
label.append(h("span", "", (f.label ?? f.name) + (f.required ? " *" : "")));
|
|
979
|
+
const input = h("input", "ra-field");
|
|
980
|
+
input.type = f.type === "number" ? "number" : "text";
|
|
981
|
+
input.name = f.name;
|
|
982
|
+
if (f.type === "number")
|
|
983
|
+
input.step = "any";
|
|
984
|
+
if (f.placeholder)
|
|
985
|
+
input.placeholder = f.placeholder;
|
|
986
|
+
if (f.initial !== undefined)
|
|
987
|
+
input.value = String(f.initial);
|
|
988
|
+
label.append(input);
|
|
989
|
+
box.append(label);
|
|
990
|
+
return { f, input };
|
|
991
|
+
});
|
|
992
|
+
const submit = () => {
|
|
993
|
+
const out = {};
|
|
994
|
+
for (const { f, input } of inputs) {
|
|
995
|
+
const raw = input.value.trim();
|
|
996
|
+
const bad = (!raw && f.required) || (!!raw && f.type === "number" && !Number.isFinite(Number(raw)));
|
|
997
|
+
input.classList.toggle("bad", bad);
|
|
998
|
+
if (bad) {
|
|
999
|
+
input.focus();
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (raw)
|
|
1003
|
+
out[f.name] = f.type === "number" ? Number(raw) : raw;
|
|
1004
|
+
}
|
|
1005
|
+
done(out);
|
|
1006
|
+
};
|
|
1007
|
+
box.addEventListener("keydown", (ev) => { const e = ev; if (e.key === "Enter" && !e.isComposing) {
|
|
1008
|
+
e.preventDefault();
|
|
1009
|
+
submit();
|
|
1010
|
+
} });
|
|
1011
|
+
card.append(box);
|
|
1012
|
+
const row = h("div", "ra-btns");
|
|
1013
|
+
row.append(btn(t.cancel, "ghost", () => done(null)), btn(opts.ok ?? t.submit, "solid", submit));
|
|
954
1014
|
card.append(row);
|
|
955
1015
|
}, null, opts.signal),
|
|
956
1016
|
input: (title, opts = {}) => open((card, done) => {
|
|
@@ -1040,7 +1100,9 @@ export function renderChat(target, opts) {
|
|
|
1040
1100
|
injectStyles();
|
|
1041
1101
|
const lang = pickLocale(opts.locale);
|
|
1042
1102
|
const t = STRINGS[lang];
|
|
1043
|
-
const { toolSettings, client: clientOpt, provider: providerOpt, agent: givenAgent, workspace: wsOpt, resume: resumeOpt, palette: paletteOpt, vars: varsOpt, className, debug: debugOpt, settings: _settingsOpt, skillsMenu, title, placeholder, emptyState, suggestions, sessions, locale: _l, theme, showUsage, attachments: attachOpt, fileDialog: fileDialogOpt, uploadsDir: uploadsOpt, onOpenFile, onLink, onSession, files: filesOpt, headerActions, headerEnd, settingsTabs, composerTop, composerActions, permissionsSetting, rewindState, nextPrompt, webSearch: webSearchOpt, schedule: scheduleOpt, ...agentOpts } = opts;
|
|
1103
|
+
const { toolSettings, client: clientOpt, provider: providerOpt, agent: givenAgent, workspace: wsOpt, resume: resumeOpt, palette: paletteOpt, vars: varsOpt, className, debug: debugOpt, settings: _settingsOpt, skillsMenu, title, placeholder, emptyState, suggestions, sessions, locale: _l, theme, showUsage, attachments: attachOpt, fileDialog: fileDialogOpt, uploadsDir: uploadsOpt, onOpenFile, onLink, onSession, files: filesOpt, headerActions, headerEnd, settingsTabs, composerTop, composerActions, permissionsSetting, rewindState, nextPrompt, webSearch: webSearchOpt, schedule: scheduleOpt, queue: queueOpt, replyActions, clearButton, commands: commandsOpt, uploadImage, headerStart, ...agentOpts } = opts;
|
|
1104
|
+
// Steering and queueing while a run is going (off: the composer only offers Stop then, and what is typed stays in it).
|
|
1105
|
+
const canQueue = queueOpt !== false;
|
|
1044
1106
|
const uploadsDir = "/" + (uploadsOpt ?? "/uploads").replace(/^\/+|\/+$/g, "");
|
|
1045
1107
|
setFileDialog(fileDialogOpt);
|
|
1046
1108
|
const provider = providerOpt ? toProvider(providerOpt) : clientOpt ? toProvider(clientOpt) : givenAgent?.provider ?? null;
|
|
@@ -1126,7 +1188,7 @@ export function renderChat(target, opts) {
|
|
|
1126
1188
|
clearBtn.style.display = "none";
|
|
1127
1189
|
// One conversation, no list of them (sessions: false, or the host's own agent): Clear stands in for New chat, and shows only when there is something to clear.
|
|
1128
1190
|
let oneChat = false;
|
|
1129
|
-
const syncClear = () => { clearBtn.style.display = oneChat && agent?.messages.length ? "" : "none"; };
|
|
1191
|
+
const syncClear = () => { clearBtn.style.display = clearButton !== false && oneChat && agent?.messages.length ? "" : "none"; };
|
|
1130
1192
|
// How full the context is, as a ring; a click opens the numbers and the spending.
|
|
1131
1193
|
const useBtn = h("button", "ra-btn ghost ra-usebtn");
|
|
1132
1194
|
useBtn.type = "button";
|
|
@@ -1142,9 +1204,9 @@ export function renderChat(target, opts) {
|
|
|
1142
1204
|
if (!btn.title)
|
|
1143
1205
|
btn.title = label;
|
|
1144
1206
|
}
|
|
1145
|
-
for (const el of [...(headerActions ?? []), ...(headerEnd ?? []), ...(composerTop ? [composerTop] : []), ...(emptyState instanceof HTMLElement ? [emptyState] : [])])
|
|
1207
|
+
for (const el of [...(headerStart ?? []), ...(headerActions ?? []), ...(headerEnd ?? []), ...(composerTop ? [composerTop] : []), ...(emptyState instanceof HTMLElement ? [emptyState] : [])])
|
|
1146
1208
|
el.classList.add("ra-host");
|
|
1147
|
-
head.append(titleEl, modelEl, h("span", "ra-sp"), useBtn, debugBtn, filesBtn, skillsBtn, schedBtn, histBtn, newBtn, clearBtn, ...(headerActions ?? []), setBtn, ...(headerEnd ?? []));
|
|
1209
|
+
head.append(...(headerStart ?? []), titleEl, modelEl, h("span", "ra-sp"), useBtn, debugBtn, filesBtn, skillsBtn, schedBtn, histBtn, newBtn, clearBtn, ...(headerActions ?? []), setBtn, ...(headerEnd ?? []));
|
|
1148
1210
|
if (title === false)
|
|
1149
1211
|
head.style.display = "none";
|
|
1150
1212
|
const log = h("div", "ra-log");
|
|
@@ -1417,7 +1479,7 @@ export function renderChat(target, opts) {
|
|
|
1417
1479
|
});
|
|
1418
1480
|
/** Whether rewinding may restore files: only a directory of the session's own, kept in IndexedDB (not a folder on disk, not shared). */
|
|
1419
1481
|
const restorable = (a) => !!a.workspace && typeof wsOpt === "function" && !a.workspace.root;
|
|
1420
|
-
const background = () => [...live.values()].filter((a) => a !== agent && (a.busy || a.queued
|
|
1482
|
+
const background = () => [...live.values()].filter((a) => a !== agent && (a.busy || (a.queued?.length ?? 0) > 0 || waiting.has(a.id)));
|
|
1421
1483
|
const titleOfAgent = (a) => { const text = a.title ?? titleOf({ v: 2, id: a.id, messages: a.messages, usage: a.usage, droppedTurns: 0, savedAt: 0 }); return text === UNTITLED ? t.untitled : text.length > 40 ? text.slice(0, 37) + "…" : text; };
|
|
1422
1484
|
const markBackground = () => histBtn.classList.toggle("ra-bg", background().length > 0);
|
|
1423
1485
|
/** The Chats count: the conversations, open one included, shown once there is another (redrawn after a run, a switch, a delete). */
|
|
@@ -1476,7 +1538,7 @@ export function renderChat(target, opts) {
|
|
|
1476
1538
|
ui.notify(`${titleOfAgent(a)} · ${t.finished}`);
|
|
1477
1539
|
// `busy` flips after the run's promise settles, a tick after this event.
|
|
1478
1540
|
setTimeout(() => { if (!mounted)
|
|
1479
|
-
return; if (agent !== a && !a.busy && !a.queued
|
|
1541
|
+
return; if (agent !== a && !a.busy && !a.queued?.length && !waiting.has(a.id)) {
|
|
1480
1542
|
live.delete(a.id);
|
|
1481
1543
|
unwatchBackground(a);
|
|
1482
1544
|
release(a);
|
|
@@ -1675,7 +1737,7 @@ export function renderChat(target, opts) {
|
|
|
1675
1737
|
back.title = t.rewind;
|
|
1676
1738
|
back.setAttribute("aria-label", t.rewind);
|
|
1677
1739
|
back.addEventListener("click", () => void rewindTo(row));
|
|
1678
|
-
foot.append(time, copy, back);
|
|
1740
|
+
foot.append(time, copy, ...(replyActions?.rewind === false ? [] : [back]));
|
|
1679
1741
|
el.addEventListener("mouseenter", () => row.update());
|
|
1680
1742
|
row.update = () => {
|
|
1681
1743
|
const ts = tsOf(row.msg);
|
|
@@ -1840,13 +1902,13 @@ export function renderChat(target, opts) {
|
|
|
1840
1902
|
ui.cancelAll();
|
|
1841
1903
|
await a.abort();
|
|
1842
1904
|
}
|
|
1843
|
-
await a.remove(turn.start, turn.end);
|
|
1905
|
+
await a.remove?.(turn.start, turn.end);
|
|
1844
1906
|
}
|
|
1845
1907
|
catch (err) {
|
|
1846
1908
|
ui.notify(err.message, "error");
|
|
1847
1909
|
}
|
|
1848
1910
|
})());
|
|
1849
|
-
foot.append(copy, again, del);
|
|
1911
|
+
foot.append(copy, ...(replyActions?.retry === false ? [] : [again]), ...(replyActions?.delete === false ? [] : [del]));
|
|
1850
1912
|
const u = last.runUsage;
|
|
1851
1913
|
if (u && u.calls) {
|
|
1852
1914
|
const show = (currency) => { cost.textContent = t.replyCost.replace("{cost}", fmtCost(u.total_cost, currency)); };
|
|
@@ -1881,7 +1943,8 @@ export function renderChat(target, opts) {
|
|
|
1881
1943
|
if (m)
|
|
1882
1944
|
inline.set(m[1], m[2]);
|
|
1883
1945
|
}
|
|
1884
|
-
|
|
1946
|
+
// The pictures the message carried: inline, or at an address (a host that uploads them: `uploadImage`).
|
|
1947
|
+
const images = imagesOf(parts);
|
|
1885
1948
|
const files = [], paths = [], missing = [];
|
|
1886
1949
|
for (const line of block.text.split("\n").slice(1)) {
|
|
1887
1950
|
const a = parseAttachLine(line);
|
|
@@ -2156,6 +2219,8 @@ export function renderChat(target, opts) {
|
|
|
2156
2219
|
const d = displayOf(name), label = labelOf(name, args);
|
|
2157
2220
|
const icon = h("span", "ra-ticon");
|
|
2158
2221
|
icon.innerHTML = d?.icon ?? (TOOL_ICON[name] ?? I.wrench)();
|
|
2222
|
+
if (d?.tone)
|
|
2223
|
+
icon.dataset.tone = d.tone;
|
|
2159
2224
|
const end = h("span", "ra-tend");
|
|
2160
2225
|
end.innerHTML = '<span class="ra-spin"></span>';
|
|
2161
2226
|
sum.innerHTML = `<span class="ra-chev">${I.chev()}</span>`;
|
|
@@ -2296,7 +2361,7 @@ export function renderChat(target, opts) {
|
|
|
2296
2361
|
return card;
|
|
2297
2362
|
};
|
|
2298
2363
|
/** Pictures a tool returned, shown under its result (a screenshot, a chart). */
|
|
2299
|
-
const imagesOf = (content) => Array.isArray(content) ? content.flatMap((p) => (p.type === "image_url" && /^(data:image\/|https
|
|
2364
|
+
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] : [])) : [];
|
|
2300
2365
|
/** The file a finished call is about, when it really is one: open it and, unless the app handles files itself, download it. */
|
|
2301
2366
|
const offerFile = async (card) => {
|
|
2302
2367
|
const ws = agent?.workspace;
|
|
@@ -2438,6 +2503,24 @@ export function renderChat(target, opts) {
|
|
|
2438
2503
|
// One row per reply, as live: every turn between two user messages; text-less turns (thinking + tool calls) share a group.
|
|
2439
2504
|
let last = null;
|
|
2440
2505
|
let lastUserTs;
|
|
2506
|
+
// An agent that holds only the recent part of its conversation: the rest comes on demand.
|
|
2507
|
+
const src = agent;
|
|
2508
|
+
if (src?.hasOlder && src.loadOlder) {
|
|
2509
|
+
const b = h("button", "ra-btn ghost ra-older");
|
|
2510
|
+
b.type = "button";
|
|
2511
|
+
b.textContent = t.older;
|
|
2512
|
+
b.addEventListener("click", () => {
|
|
2513
|
+
if (src.busy) {
|
|
2514
|
+
ui.notify(t.olderBusy, "warning");
|
|
2515
|
+
return;
|
|
2516
|
+
}
|
|
2517
|
+
b.disabled = true;
|
|
2518
|
+
void src.loadOlder().catch((err) => { b.disabled = false; ui.notify(err.message, "error"); });
|
|
2519
|
+
});
|
|
2520
|
+
const el = h("div", "ra-olderrow");
|
|
2521
|
+
el.append(b);
|
|
2522
|
+
addRow({ render: () => el, el });
|
|
2523
|
+
}
|
|
2441
2524
|
const flush = (atEnd = false) => {
|
|
2442
2525
|
if (!last)
|
|
2443
2526
|
return;
|
|
@@ -2585,17 +2668,21 @@ export function renderChat(target, opts) {
|
|
|
2585
2668
|
? scheduleTools(schedStore, { ...schedCfg, onChange: () => refreshSched() }).map((x) => ({ ...x, display: { ...x.display, icon: I.clock(), label: schedLabels[x.name] } }))
|
|
2586
2669
|
: [];
|
|
2587
2670
|
const chatTools = [...(agentOpts.tools ?? []), ...(nextPrompt ? [nextPromptTool] : []), ...schedTools];
|
|
2671
|
+
// A host's agent brings its own tools: the ones it hides are read from it as well (when it is attached).
|
|
2588
2672
|
const hiddenTools = new Set(chatTools.filter((x) => x.display?.hidden).map((x) => x.name));
|
|
2673
|
+
const hideToolsOf = (a) => { for (const x of a.tools ?? [])
|
|
2674
|
+
if (x.display?.hidden)
|
|
2675
|
+
hiddenTools.add(x.name); };
|
|
2589
2676
|
/** Send is there only while idle with something to send (text, a file, context); steer and follow-up only while busy with something to send. */
|
|
2590
2677
|
const syncSend = () => {
|
|
2591
2678
|
const busy = root.dataset.busy === "1", any = !!(ta.value.trim() || pendingFiles.length || pendingContext.length);
|
|
2592
2679
|
sendBtn.style.display = !busy && any ? "" : "none";
|
|
2593
|
-
steerBtn.style.display = fuBtn.style.display = busy && any ? "" : "none";
|
|
2680
|
+
steerBtn.style.display = fuBtn.style.display = canQueue && busy && any ? "" : "none";
|
|
2594
2681
|
};
|
|
2595
2682
|
const setBusy = (busy) => {
|
|
2596
2683
|
root.dataset.busy = busy ? "1" : "";
|
|
2597
|
-
ta.placeholder = busy ? fill(t.placeholderBusy) : (nextSuggestion ?? placeholder ?? t.placeholder);
|
|
2598
|
-
hint.textContent = fill(busy ? t.hintBusy : nextSuggestion ? t.hintNext : t.hintIdle);
|
|
2684
|
+
ta.placeholder = busy && canQueue ? fill(t.placeholderBusy) : (nextSuggestion ?? placeholder ?? t.placeholder);
|
|
2685
|
+
hint.textContent = fill(busy && canQueue ? t.hintBusy : nextSuggestion ? t.hintNext : t.hintIdle);
|
|
2599
2686
|
syncSend();
|
|
2600
2687
|
stopBtn.style.display = busy ? "" : "none";
|
|
2601
2688
|
renderQueue();
|
|
@@ -2617,16 +2704,16 @@ export function renderChat(target, opts) {
|
|
|
2617
2704
|
const box = h("span", "ra-qa");
|
|
2618
2705
|
// Send now: a queued follow-up becomes a steer, inserted at the next step of the running task.
|
|
2619
2706
|
if (item.kind !== "steer")
|
|
2620
|
-
box.append(btn(I.enter(), t.sendNow, () => { if (a.dequeue(item.message))
|
|
2621
|
-
a.steer(item.message.content); renderQueue(); }));
|
|
2707
|
+
box.append(btn(I.enter(), t.sendNow, () => { if (a.dequeue?.(item.message))
|
|
2708
|
+
a.steer?.(item.message.content); renderQueue(); }));
|
|
2622
2709
|
box.append(btn(I.pen(), t.editQueued, () => {
|
|
2623
|
-
if (!a.dequeue(item.message))
|
|
2710
|
+
if (!a.dequeue?.(item.message))
|
|
2624
2711
|
return;
|
|
2625
2712
|
ta.value = ta.value.trim() ? `${textOf(item.message)}\n${ta.value}` : textOf(item.message);
|
|
2626
2713
|
ta.focus();
|
|
2627
2714
|
renderQueue();
|
|
2628
2715
|
}));
|
|
2629
|
-
box.append(btn(I.x(14), t.remove, () => { a.dequeue(item.message); renderQueue(); }));
|
|
2716
|
+
box.append(btn(I.x(14), t.remove, () => { a.dequeue?.(item.message); renderQueue(); }));
|
|
2630
2717
|
return box;
|
|
2631
2718
|
};
|
|
2632
2719
|
const kindTag = (item) => (item.kind === "steer" ? h("span", "ra-qk", t.steer) : null);
|
|
@@ -2859,6 +2946,16 @@ export function renderChat(target, opts) {
|
|
|
2859
2946
|
parts.push({ type: "video_url", video_url: { url: b64 } });
|
|
2860
2947
|
}
|
|
2861
2948
|
if (a.image && !blind && a.file.size <= MAX_IMAGE_PART) {
|
|
2949
|
+
if (uploadImage) {
|
|
2950
|
+
// The host puts the picture where its server reads it: the message carries the address.
|
|
2951
|
+
try {
|
|
2952
|
+
parts.push({ type: "image_url", image_url: { url: await uploadImage(a.file) } });
|
|
2953
|
+
}
|
|
2954
|
+
catch (err) {
|
|
2955
|
+
ui.notify(`${a.name}: ${err?.message || String(err)}`, "error");
|
|
2956
|
+
}
|
|
2957
|
+
continue;
|
|
2958
|
+
}
|
|
2862
2959
|
const b64 = await new Promise((res) => { const r = new FileReader(); r.onload = () => res(String(r.result)); r.readAsDataURL(a.file); });
|
|
2863
2960
|
parts.push({ type: "image_url", image_url: { url: b64 } });
|
|
2864
2961
|
}
|
|
@@ -2880,6 +2977,9 @@ export function renderChat(target, opts) {
|
|
|
2880
2977
|
clearNext();
|
|
2881
2978
|
if (runBuiltin(text))
|
|
2882
2979
|
return;
|
|
2980
|
+
// Without a queue nothing is sent while a run (or a compaction) is going: the text waits in the composer.
|
|
2981
|
+
if (!canQueue && (agent.busy || compacting))
|
|
2982
|
+
return;
|
|
2883
2983
|
// While compacting, a message waits for it and then runs (Enter, Steer and Follow-up alike).
|
|
2884
2984
|
if (compacting)
|
|
2885
2985
|
mode = "followUp";
|
|
@@ -2937,9 +3037,9 @@ export function renderChat(target, opts) {
|
|
|
2937
3037
|
return;
|
|
2938
3038
|
}
|
|
2939
3039
|
if (mode === "steer")
|
|
2940
|
-
a.steer(content);
|
|
3040
|
+
a.steer?.(content);
|
|
2941
3041
|
else
|
|
2942
|
-
void a.followUp(content).catch(() => undefined);
|
|
3042
|
+
void a.followUp?.(content).catch(() => undefined);
|
|
2943
3043
|
renderQueue();
|
|
2944
3044
|
}
|
|
2945
3045
|
catch (err) {
|
|
@@ -3069,9 +3169,10 @@ export function renderChat(target, opts) {
|
|
|
3069
3169
|
if (!hasSettings)
|
|
3070
3170
|
setBtn.style.display = "none";
|
|
3071
3171
|
let modelsCache = null;
|
|
3072
|
-
/** The thinking levels a model offers (`options.inputs
|
|
3172
|
+
/** The thinking levels a model offers (its input_schema's `reasoning_effort`, else the old `options.inputs`), or null when it has none. */
|
|
3073
3173
|
const effortOf = (m) => {
|
|
3074
|
-
const
|
|
3174
|
+
const p = m?.input_schema?.properties?.reasoning_effort;
|
|
3175
|
+
const f = p && typeof p === "object" ? p : m?.input_schema?.properties ? undefined : m?.options?.inputs?.reasoning_effort;
|
|
3075
3176
|
if (!f)
|
|
3076
3177
|
return null;
|
|
3077
3178
|
const levels = (f.enum ?? []).filter((v) => typeof v === "string");
|
|
@@ -3392,7 +3493,7 @@ export function renderChat(target, opts) {
|
|
|
3392
3493
|
const b = h("button");
|
|
3393
3494
|
b.type = "button";
|
|
3394
3495
|
const bg = s ? live.get(s.id) : undefined;
|
|
3395
|
-
const state = s && bg && bg !== cur ? (waiting.has(s.id) ? ` · ${t.waitingAnswer}` : bg.busy || bg.queued
|
|
3496
|
+
const state = s && bg && bg !== cur ? (waiting.has(s.id) ? ` · ${t.waitingAnswer}` : bg.busy || bg.queued?.length ? ` · ${t.running}` : "") : "";
|
|
3396
3497
|
// The title line: the title shortens, the "Current" tag (and a spinner for a running session) always shows.
|
|
3397
3498
|
const name = h("span", "ra-mt");
|
|
3398
3499
|
if (state && !waiting.has(s.id))
|
|
@@ -3613,7 +3714,7 @@ export function renderChat(target, opts) {
|
|
|
3613
3714
|
}
|
|
3614
3715
|
// Its own conversation is named after it (the first message would be the run's header).
|
|
3615
3716
|
if (!givenAgent && !oneChat)
|
|
3616
|
-
a.setTitle(`⏰ ${task.name}`);
|
|
3717
|
+
a.setTitle?.(`⏰ ${task.name}`);
|
|
3617
3718
|
ui.notify(t.schedStarted.replace("{name}", task.name));
|
|
3618
3719
|
const r = a === agent ? await promptFromHost(text) : await a.prompt(text);
|
|
3619
3720
|
refreshHistCount();
|
|
@@ -3623,7 +3724,7 @@ export function renderChat(target, opts) {
|
|
|
3623
3724
|
};
|
|
3624
3725
|
/** Idle: nothing running in any conversation, no question open, not switching, the user not typing. */
|
|
3625
3726
|
const schedIdle = () => mounted && !switching && !!agent && asked === 0 && waiting.size === 0
|
|
3626
|
-
&& ![...live.values()].some((a) => a.busy || a.queued
|
|
3727
|
+
&& ![...live.values()].some((a) => a.busy || (a.queued?.length ?? 0) > 0)
|
|
3627
3728
|
&& !(document.activeElement === ta && ta.value.trim());
|
|
3628
3729
|
const scheduler = schedStore ? new Scheduler({ store: schedStore, run: runScheduled, idle: schedIdle, lockPrefix: `__runapps_agent_chat:${project}:schedules`, onChange: () => refreshSched() }) : null;
|
|
3629
3730
|
if (scheduler) {
|
|
@@ -3992,7 +4093,7 @@ export function renderChat(target, opts) {
|
|
|
3992
4093
|
compacting = true;
|
|
3993
4094
|
let summary = null;
|
|
3994
4095
|
try {
|
|
3995
|
-
summary = await a.summarize(asked?.msg);
|
|
4096
|
+
summary = (await a.summarize?.(asked?.msg)) ?? null;
|
|
3996
4097
|
}
|
|
3997
4098
|
finally {
|
|
3998
4099
|
compacting = false;
|
|
@@ -4002,7 +4103,7 @@ export function renderChat(target, opts) {
|
|
|
4002
4103
|
await (oneChat ? clearConversation() : newSession().then(() => undefined));
|
|
4003
4104
|
const b = agent;
|
|
4004
4105
|
if (summary) {
|
|
4005
|
-
await b.seed(summary);
|
|
4106
|
+
await b.seed?.(summary);
|
|
4006
4107
|
renderHistory(b.messages);
|
|
4007
4108
|
showUsage_(b);
|
|
4008
4109
|
}
|
|
@@ -4196,7 +4297,7 @@ export function renderChat(target, opts) {
|
|
|
4196
4297
|
];
|
|
4197
4298
|
/** The built-ins this chat offers now (the files, settings and debug ones only where their button shows). */
|
|
4198
4299
|
const builtinCommands = () => builtins
|
|
4199
|
-
.filter((b) => (b.name !== "files" || (!!agent?.workspace && filesOpt !== false)) && (b.name !== "settings" || hasSettings) && (b.name !== "debug" || debugOn) && (b.name !== "resume" || (!givenAgent && !!agent?.workspace && !oneChat)))
|
|
4300
|
+
.filter((b) => (!commandsOpt || commandsOpt.includes(b.name)) && (b.name !== "files" || (!!agent?.workspace && filesOpt !== false)) && (b.name !== "settings" || hasSettings) && (b.name !== "debug" || debugOn) && (b.name !== "resume" || (!givenAgent && !!agent?.workspace && !oneChat)))
|
|
4200
4301
|
.map((b) => ({ name: b.name, description: b.name === "new" && oneChat ? t.confirmClear.split(/[??]/)[0] : t.cmd[b.name] ?? "", kind: t.command, args: b.args, builtin: true }));
|
|
4201
4302
|
/** `/name [arg]` naming a built-in: run it here (nothing goes to the model). */
|
|
4202
4303
|
const runBuiltin = (text) => {
|
|
@@ -4257,7 +4358,7 @@ export function renderChat(target, opts) {
|
|
|
4257
4358
|
};
|
|
4258
4359
|
const cap = (x) => x.charAt(0).toUpperCase() + x.slice(1);
|
|
4259
4360
|
/** "Auto-compaction: when less than 16k tokens are left" (or Auto-trim), as the agent will do it now. */
|
|
4260
|
-
const compactLine = (a, window) => { const c = a.compactionFor(window); return `${c.summarize ? t.autoCompact : t.autoTrim}: ${t.autoCompactAt.replace("{n}", fmtTokens(c.reserveTokens))}`; };
|
|
4361
|
+
const compactLine = (a, window) => { const c = a.compactionFor(window); return `${c.summarize ? t.autoCompact : t.autoTrim}: ${c.reserveTokens > 0 ? t.autoCompactAt.replace("{n}", fmtTokens(c.reserveTokens)) : t.autoCompactFull}`; };
|
|
4261
4362
|
const pctOf = (used, window) => { const p = used / window; return used && p < 0.01 ? "<1%" : `${Math.round(Math.min(1, p) * 100)}%`; };
|
|
4262
4363
|
/** The usage panel: how full the context is, what the conversation has cost, and Compact now. */
|
|
4263
4364
|
const fillUsage = (panel, a, c) => {
|
|
@@ -4331,6 +4432,7 @@ export function renderChat(target, opts) {
|
|
|
4331
4432
|
for (const u of unsub)
|
|
4332
4433
|
u();
|
|
4333
4434
|
unsub = [];
|
|
4435
|
+
hideToolsOf(a);
|
|
4334
4436
|
// Skills added or removed anywhere (the menu, the agent, another tab): the count and the / list follow.
|
|
4335
4437
|
if (a.workspace) {
|
|
4336
4438
|
const ws = a.workspace;
|
|
@@ -4422,6 +4524,22 @@ export function renderChat(target, opts) {
|
|
|
4422
4524
|
renderHistory(a.messages);
|
|
4423
4525
|
showUsage_(a);
|
|
4424
4526
|
} });
|
|
4527
|
+
on("history", (ev) => {
|
|
4528
|
+
if (agent !== a)
|
|
4529
|
+
return;
|
|
4530
|
+
const before = list.length, hadOlder = before > 0 && list.rows[0]?.el?.classList.contains("ra-olderrow") === true;
|
|
4531
|
+
const following = list.follow, top = log.scrollTop;
|
|
4532
|
+
renderHistory(a.messages);
|
|
4533
|
+
// The row that was first is now further down by what came in before it.
|
|
4534
|
+
if (ev.reason === "older")
|
|
4535
|
+
list.scrollToIndex(Math.max(0, list.length - (before - (hadOlder ? 1 : 0))));
|
|
4536
|
+
else if (ev.reason === "newer" && !following) {
|
|
4537
|
+
list.follow = false;
|
|
4538
|
+
log.scrollTop = top;
|
|
4539
|
+
list.layout();
|
|
4540
|
+
}
|
|
4541
|
+
showUsage_(a);
|
|
4542
|
+
});
|
|
4425
4543
|
on("text_delta", (ev) => {
|
|
4426
4544
|
const act = ensureActive();
|
|
4427
4545
|
clearPending(act);
|
|
@@ -4528,7 +4646,7 @@ export function renderChat(target, opts) {
|
|
|
4528
4646
|
if (!ev.summary)
|
|
4529
4647
|
trimNoted = ev.runId ?? null;
|
|
4530
4648
|
const first = a.messages[0];
|
|
4531
|
-
const s = first && typeof first.content === "string" ? summaryOf(first) : null;
|
|
4649
|
+
const s = ev.summaryText ?? (first && typeof first.content === "string" ? summaryOf(first) : null);
|
|
4532
4650
|
addNote(ev.summary ? t.compacted : t.trimmed, ev.summary && s ? s : undefined);
|
|
4533
4651
|
});
|
|
4534
4652
|
on("run_end", (r) => {
|
|
@@ -4607,7 +4725,7 @@ export function renderChat(target, opts) {
|
|
|
4607
4725
|
return agent;
|
|
4608
4726
|
const prev = agent;
|
|
4609
4727
|
if (prev) {
|
|
4610
|
-
if (prev.busy || prev.queued
|
|
4728
|
+
if (prev.busy || (prev.queued?.length ?? 0) > 0) {
|
|
4611
4729
|
if (background().length >= MAX_BACKGROUND) {
|
|
4612
4730
|
ui.notify(t.bgLimit.replace("{n}", String(background().length)), "warning");
|
|
4613
4731
|
return prev;
|
|
@@ -4633,7 +4751,7 @@ export function renderChat(target, opts) {
|
|
|
4633
4751
|
await ready;
|
|
4634
4752
|
const a = agent ?? givenAgent;
|
|
4635
4753
|
ui.cancelAll();
|
|
4636
|
-
await a.clear();
|
|
4754
|
+
await a.clear?.();
|
|
4637
4755
|
if (agent === a || givenAgent === a) {
|
|
4638
4756
|
renderHistory(a.messages);
|
|
4639
4757
|
showUsage_(a);
|
|
@@ -4718,6 +4836,7 @@ export function renderChat(target, opts) {
|
|
|
4718
4836
|
clear: clearConversation,
|
|
4719
4837
|
addContext,
|
|
4720
4838
|
setDebug(on) { debugOn = on; applyDebug(); },
|
|
4839
|
+
setTitle(text) { titleEl.textContent = text; },
|
|
4721
4840
|
updateComposerAction(id, patch) { const e = actionBtns.get(id); if (!e)
|
|
4722
4841
|
return; Object.assign(e.a, patch); drawAction(e.btn, e.a); },
|
|
4723
4842
|
setAppearance(o) {
|
package/dist/debug-panel.d.ts
CHANGED
package/dist/debug-panel.js
CHANGED
|
@@ -164,7 +164,7 @@ export function debugPanel(opts) {
|
|
|
164
164
|
rows.append(h("span", "ra-dmuted", "context"), ctx);
|
|
165
165
|
void a.context().then((c) => { ctx.textContent = `${c.used} / ${c.window} (${((c.used / c.window) * 100).toFixed(2)}%)`; }).catch(() => { ctx.textContent = "—"; });
|
|
166
166
|
const sys = pre("…", "tall");
|
|
167
|
-
void a.systemPrompt().then((p) => { sys.textContent = p; }).catch((err) => { sys.textContent = String(err); });
|
|
167
|
+
void (a.systemPrompt?.() ?? Promise.resolve("(this agent does not expose its system prompt)")).then((p) => { sys.textContent = p; }).catch((err) => { sys.textContent = String(err); });
|
|
168
168
|
box.append(rows, label(t.dSystem), sys, label(`${t.dMessages} (${msgs.length})`), pre(msgs, "tall"));
|
|
169
169
|
return [box];
|
|
170
170
|
};
|