@runappsai/agent 0.3.1 → 0.3.3

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/chat.js CHANGED
@@ -11,6 +11,7 @@
11
11
  // height composer that never resizes while typing, and a virtual
12
12
  // transcript (`VirtualList`) that keeps only the rows near the viewport
13
13
  // in the DOM, so a long history costs nothing to open.
14
+ import { STATE_MARK } from "./context.js";
14
15
  import { escapeHTML } from "./markdown.js";
15
16
  import { VirtualList } from "./vlist.js";
16
17
  import { chooseFiles, downloadBlob, h, I, modal, modalConfirm, renderMD, setFileDialog } from "./dom.js";
@@ -45,7 +46,7 @@ const STRINGS = {
45
46
  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",
46
47
  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
48
  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
- 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
+ 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", replyCache: "cache hit {p}%", replyCached: " ({n} from cache)",
49
50
  older: "Load earlier messages", olderBusy: "Wait for the reply to finish, then load earlier messages.",
50
51
  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.",
51
52
  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.",
@@ -86,7 +87,7 @@ const STRINGS = {
86
87
  runCode: "运行代码", ingRead: "正在读取", ingList: "正在查看", ingSearch: "正在搜索", ingWrite: "正在写入", ingEdit: "正在修改", ingDelete: "正在删除", ingRun: "正在运行代码", ingAsk: "正在询问你", ingOther: "正在执行", current: "当前", jumpEnd: "回到最新",
87
88
  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: "按类型过滤",
88
89
  dNoCalls: "还没有工具调用。", dNoRequests: "还没有模型请求。每次调用模型都会记在这里,包括发了什么、收到什么。", dNoEvents: "还没有事件。",
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
+ 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} 次调用", replyCache: "缓存命中 {p}%", replyCached: "(其中缓存 {n})",
90
91
  older: "加载更早的消息", olderBusy: "等这次回复结束后再加载更早的消息。",
91
92
  rewindMsg: "它之后的对话会被删除,消息内容放回输入框。", rewindFiles: "同时把目录里的文件恢复到那一刻", rewindGone: "这条消息已不在对话里(可能已被压缩)。", rewindSnapshot: "{time} 时的 {n} 个文件({size})", rewindPartial: "超过 2 MB 的文件没进快照,会保持原样。", rewindGoneFile: "{path} 已不在目录里。",
92
93
  running: "运行中", waitingAnswer: "等待你回答", finished: "已完成", bgLimit: "后台已有 {n} 个会话在运行,先停掉一个再切换。",
@@ -2023,7 +2024,7 @@ export function renderChat(target, opts) {
2023
2024
  const userRow = (content, msg) => {
2024
2025
  const parts = textPartsOf(content);
2025
2026
  // Expanded slash commands show what was typed; the expansion is for the model.
2026
- const own = parts.filter((p) => !p.startsWith(ATTACH_MARK) && !p.startsWith(CONTEXT_MARK) && !p.startsWith("<file name="));
2027
+ const own = parts.filter((p) => !p.startsWith(ATTACH_MARK) && !p.startsWith(CONTEXT_MARK) && !p.startsWith(STATE_MARK) && !p.startsWith("<file name="));
2027
2028
  const typed = typedOf(msg);
2028
2029
  const row = { msg, text: typed ?? own.join("\n"), update: () => undefined, render: () => userEl(content, row) };
2029
2030
  return row;
@@ -2183,7 +2184,10 @@ export function renderChat(target, opts) {
2183
2184
  foot.append(copy, ...(replyActions?.retry === false ? [] : [again]), ...(replyActions?.delete === false ? [] : [del]));
2184
2185
  const u = last.runUsage;
2185
2186
  if (u && u.calls) {
2186
- const show = (currency) => { cost.textContent = t.replyCost.replace("{cost}", fmtCost(u.total_cost, currency)); };
2187
+ // The share of the input read from the provider's prompt cache, on the line itself: it is most of what decides the cost.
2188
+ const cached = u.cached_tokens ?? 0;
2189
+ const hit = cached > 0 && u.prompt_tokens > 0 ? " · " + t.replyCache.replace("{p}", String(Math.round((cached / u.prompt_tokens) * 100))) : "";
2190
+ const show = (currency) => { cost.textContent = t.replyCost.replace("{cost}", fmtCost(u.total_cost, currency)) + hit; };
2187
2191
  const cost = h("span", "ra-cost");
2188
2192
  show(costCurrency);
2189
2193
  // In the model's currency: asked of its catalogue entry when not known yet.
@@ -2191,7 +2195,7 @@ export function renderChat(target, opts) {
2191
2195
  if (costCurrency === undefined && a)
2192
2196
  void a.modelInfo().then((info) => { if (info?.price?.currency)
2193
2197
  show(info.price.currency); }).catch(() => undefined);
2194
- cost.title = t.replyUsage.replace("{in}", fmtTokens(u.prompt_tokens)).replace("{out}", fmtTokens(u.completion_tokens)).replace("{calls}", String(u.calls));
2198
+ cost.title = t.replyUsage.replace("{in}", fmtTokens(u.prompt_tokens) + (cached > 0 ? t.replyCached.replace("{n}", fmtTokens(cached)) : "")).replace("{out}", fmtTokens(u.completion_tokens)).replace("{calls}", String(u.calls));
2195
2199
  foot.append(cost);
2196
2200
  }
2197
2201
  return foot;
package/dist/context.d.ts CHANGED
@@ -21,6 +21,11 @@ export interface SystemPromptInput {
21
21
  now?: Date;
22
22
  }
23
23
  export declare function buildSystemPrompt(input: SystemPromptInput): string;
24
+ /**
25
+ * Starts the part `messageContext` adds to a user message (the host's state when it was sent).
26
+ * The model reads it; the chat does not show it, and it is never a session title.
27
+ */
28
+ export declare const STATE_MARK = "[state] ";
24
29
  /** The gateway's own estimate: a token per 3 bytes, 1600 per image. */
25
30
  export declare function estimateTokens(messages: ChatMessage[], system?: string): number;
26
31
  export interface FitResult {
package/dist/context.js CHANGED
@@ -75,6 +75,11 @@ export function buildSystemPrompt(input) {
75
75
  /* Budget */
76
76
  /* ------------------------------------------------------------------ */
77
77
  const IMAGE_TOKENS = 1600;
78
+ /**
79
+ * Starts the part `messageContext` adds to a user message (the host's state when it was sent).
80
+ * The model reads it; the chat does not show it, and it is never a session title.
81
+ */
82
+ export const STATE_MARK = "[state] ";
78
83
  /** The gateway's own estimate: a token per 3 bytes, 1600 per image. */
79
84
  export function estimateTokens(messages, system) {
80
85
  let bytes = system ? utf8Length(system) : 0;
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ __export(src_exports, {
30
30
  MCPError: () => MCPError,
31
31
  PartialReadError: () => PartialReadError,
32
32
  ProviderError: () => ProviderError,
33
+ STATE_MARK: () => STATE_MARK,
33
34
  Scheduler: () => Scheduler,
34
35
  UNTITLED: () => UNTITLED,
35
36
  WEB_TOOL_NAMES: () => WEB_TOOL_NAMES,
@@ -353,6 +354,7 @@ Your notes from earlier conversations (${input.memoryPath ?? "/memory/notes.md"}
353
354
  return out.join("\n\n");
354
355
  }
355
356
  var IMAGE_TOKENS = 1600;
357
+ var STATE_MARK = "[state] ";
356
358
  function estimateTokens(messages, system) {
357
359
  let bytes = system ? utf8Length(system) : 0;
358
360
  let images = 0;
@@ -2475,7 +2477,7 @@ function titleOf(d) {
2475
2477
  return UNTITLED;
2476
2478
  }
2477
2479
  function isMachineTitle(title) {
2478
- return /^(The conversation history before this point|<skill[\s>]|\[environment\]|\[attachments\]|\[context\] )|\[attachments\]/.test(title);
2480
+ return /^(The conversation history before this point|<skill[\s>]|\[environment\]|\[attachments\]|\[context\] |\[state\] )|\[attachments\]/.test(title);
2479
2481
  }
2480
2482
  function withLock(name, fn) {
2481
2483
  const locks2 = typeof navigator !== "undefined" ? navigator.locks : void 0;
@@ -4198,6 +4200,38 @@ var Agent = class {
4198
4200
  this.emit("queued", { kind, message });
4199
4201
  });
4200
4202
  }
4203
+ /**
4204
+ * A user message joining the conversation, with the host's state (`messageContext`) as it is now
4205
+ * as its last part. Done when it joins, not when it is typed: a queued message carries the state
4206
+ * it is answered in. State the conversation already ends on is not said again.
4207
+ */
4208
+ withState(m, last = this.lastState()) {
4209
+ let state;
4210
+ try {
4211
+ state = this.opts.messageContext?.();
4212
+ } catch {
4213
+ state = void 0;
4214
+ }
4215
+ if (!state || state === last) return m;
4216
+ const parts = typeof m.content === "string" ? [{ type: "text", text: m.content }] : [...m.content ?? []];
4217
+ parts.push({ type: "text", text: STATE_MARK + state });
4218
+ return { ...m, content: parts };
4219
+ }
4220
+ /**
4221
+ * The newest state still in the conversation. Read from the history itself, not remembered:
4222
+ * compaction, a rewind or a reload can take the message that carried it away.
4223
+ */
4224
+ lastState(messages = this.history) {
4225
+ for (let i = messages.length - 1; i >= 0; i--) {
4226
+ const m = messages[i];
4227
+ if (m.role !== "user" || !Array.isArray(m.content)) continue;
4228
+ for (let j = m.content.length - 1; j >= 0; j--) {
4229
+ const part = m.content[j];
4230
+ if (part.type === "text" && part.text.startsWith(STATE_MARK)) return part.text.slice(STATE_MARK.length);
4231
+ }
4232
+ }
4233
+ return void 0;
4234
+ }
4201
4235
  userMessage(content) {
4202
4236
  const parts = typeof content === "string" ? [{ type: "text", text: content }] : content.slice();
4203
4237
  return { role: "user", content: parts.length === 1 && parts[0].type === "text" ? parts[0].text : parts, ts: Date.now() };
@@ -4304,6 +4338,7 @@ var Agent = class {
4304
4338
  prefaced = message;
4305
4339
  prefaceError = err instanceof Error ? err : new Error(String(err));
4306
4340
  }
4341
+ prefaced = this.withState(prefaced);
4307
4342
  this.history.push(prefaced);
4308
4343
  }
4309
4344
  this._ended = null;
@@ -4467,7 +4502,8 @@ var Agent = class {
4467
4502
  }
4468
4503
  /** Moves queued steering into the history and says so (`steered`), so a UI draws each message once, when it lands. */
4469
4504
  applySteering(runId) {
4470
- const steer = this.queue.filter((q) => q.kind === "steer").map((q) => q.message);
4505
+ const steer = [];
4506
+ for (const q of this.queue) if (q.kind === "steer") steer.push(this.withState(q.message, this.lastState(steer) ?? this.lastState()));
4471
4507
  if (!steer.length) return;
4472
4508
  this.queue = this.queue.filter((q) => q.kind !== "steer");
4473
4509
  this.history.push(...steer);
@@ -4968,7 +5004,8 @@ Fix the call and try again.`);
4968
5004
  total_cost: round(u.total_cost - before.total_cost),
4969
5005
  prompt_tokens: u.prompt_tokens - before.prompt_tokens,
4970
5006
  completion_tokens: u.completion_tokens - before.completion_tokens,
4971
- calls: u.calls - before.calls
5007
+ calls: u.calls - before.calls,
5008
+ ...(u.cached_tokens ?? 0) > (before.cached_tokens ?? 0) ? { cached_tokens: (u.cached_tokens ?? 0) - (before.cached_tokens ?? 0) } : {}
4972
5009
  };
4973
5010
  return;
4974
5011
  }
@@ -4981,6 +5018,8 @@ Fix the call and try again.`);
4981
5018
  this._usage.total_cost = round(this._usage.total_cost + (u.total_cost ?? 0));
4982
5019
  this._usage.prompt_tokens += u.prompt_tokens ?? 0;
4983
5020
  this._usage.completion_tokens += u.completion_tokens ?? 0;
5021
+ const cached = u.prompt_tokens_details?.cached_tokens ?? 0;
5022
+ if (cached > 0) this._usage.cached_tokens = (this._usage.cached_tokens ?? 0) + cached;
4984
5023
  this._usage.calls++;
4985
5024
  }
4986
5025
  /** How full the model's context is: tokens the next call would send (estimated) against the window. */
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ export { connectMCP, MCPError, type MCPConnection, type MCPOptions, type MCPTool
32
32
  export { sandboxTool, runInSandbox, type SandboxOptions, type SandboxResult, type SandboxToolBridge } from "./sandbox.js";
33
33
  export { parseSkill, parseFrontmatter } from "./skills.js";
34
34
  export { collectCompletion, type CollectedCompletion } from "./completion.js";
35
- export { buildSystemPrompt, estimateTokens, fitBudget, groupTurns } from "./context.js";
35
+ export { buildSystemPrompt, estimateTokens, fitBudget, groupTurns, STATE_MARK } from "./context.js";
36
36
  export { validateSchema } from "./json-schema.js";
37
37
  export { listZip, readZipEntry, buildZip, type ZipEntry, type Inflate } from "./zip.js";
38
38
  export { skillZipFS, skillFoldersOf, subFS } from "./skill-zips.js";
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ export { connectMCP, MCPError } from "./mcp.js";
40
40
  export { sandboxTool, runInSandbox } from "./sandbox.js";
41
41
  export { parseSkill, parseFrontmatter } from "./skills.js";
42
42
  export { collectCompletion } from "./completion.js";
43
- export { buildSystemPrompt, estimateTokens, fitBudget, groupTurns } from "./context.js";
43
+ export { buildSystemPrompt, estimateTokens, fitBudget, groupTurns, STATE_MARK } from "./context.js";
44
44
  export { validateSchema } from "./json-schema.js";
45
45
  export { listZip, readZipEntry, buildZip } from "./zip.js";
46
46
  export { skillZipFS, skillFoldersOf, subFS } from "./skill-zips.js";
package/dist/llm.d.ts CHANGED
@@ -59,6 +59,10 @@ export interface Usage {
59
59
  prompt_tokens?: number;
60
60
  completion_tokens?: number;
61
61
  total_tokens?: number;
62
+ /** cached_tokens: the part of prompt_tokens the provider read from its prompt cache. */
63
+ prompt_tokens_details?: {
64
+ cached_tokens?: number;
65
+ };
62
66
  /** What the call cost in USD, when the provider says (RunApps does). */
63
67
  total_cost?: number;
64
68
  }
package/dist/types.d.ts CHANGED
@@ -344,6 +344,8 @@ export interface AgentUsage {
344
344
  completion_tokens: number;
345
345
  /** Model calls made (turns), including retries that returned usage. */
346
346
  calls: number;
347
+ /** Of prompt_tokens, those the provider read from its prompt cache (usage.prompt_tokens_details.cached_tokens), when it says. */
348
+ cached_tokens?: number;
347
349
  }
348
350
  export interface RunResult {
349
351
  runId: string;
@@ -548,6 +550,14 @@ export interface AgentOptions {
548
550
  model?: string;
549
551
  /** The app's own system instructions (a function is re-read every turn). */
550
552
  instructions?: string | (() => string);
553
+ /**
554
+ * The app's state as it is now (what an editor holds, what is selected, ...), added to each user
555
+ * message when it joins the conversation and kept with it. Put what changes here rather than in
556
+ * `instructions`: a system prompt that changes from one request to the next keeps the provider's
557
+ * prompt cache from ever hitting, while this text, once sent, stays the same in every later request.
558
+ * State the conversation already ends on is not added again. Empty or a throw: nothing is added.
559
+ */
560
+ messageContext?: () => string | undefined;
551
561
  /** A short name for the app, used in the system prompt. */
552
562
  appName?: string;
553
563
  /** Private prompt reference(s) (RunApps: `{id, vars}`), forwarded on every request. */
package/dist/ui.cjs CHANGED
@@ -36,6 +36,9 @@ __export(ui_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(ui_exports);
38
38
 
39
+ // src/context.ts
40
+ var STATE_MARK = "[state] ";
41
+
39
42
  // src/markdown.ts
40
43
  var ESC = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
41
44
  function escapeHTML(s) {
@@ -2709,6 +2712,8 @@ var STRINGS = {
2709
2712
  delTurnMsg: "They are removed from the conversation; files stay as they are.",
2710
2713
  replyCost: "Cost: {cost}",
2711
2714
  replyUsage: "{in} in \xB7 {out} out \xB7 {calls} calls",
2715
+ replyCache: "cache hit {p}%",
2716
+ replyCached: " ({n} from cache)",
2712
2717
  older: "Load earlier messages",
2713
2718
  olderBusy: "Wait for the reply to finish, then load earlier messages.",
2714
2719
  rewindMsg: "The conversation after it is dropped and the message goes back into the composer.",
@@ -3030,6 +3035,8 @@ var STRINGS = {
3030
3035
  delTurnMsg: "\u8FD9\u6761\u63D0\u95EE\u548C\u5B83\u7684\u56DE\u7B54\u4F1A\u4ECE\u5BF9\u8BDD\u4E2D\u5220\u9664\uFF0C\u6587\u4EF6\u4E0D\u53D7\u5F71\u54CD\u3002",
3031
3036
  replyCost: "\u8D39\u7528\uFF1A{cost}",
3032
3037
  replyUsage: "\u8F93\u5165 {in} \xB7 \u8F93\u51FA {out} \xB7 {calls} \u6B21\u8C03\u7528",
3038
+ replyCache: "\u7F13\u5B58\u547D\u4E2D {p}%",
3039
+ replyCached: "\uFF08\u5176\u4E2D\u7F13\u5B58 {n}\uFF09",
3033
3040
  older: "\u52A0\u8F7D\u66F4\u65E9\u7684\u6D88\u606F",
3034
3041
  olderBusy: "\u7B49\u8FD9\u6B21\u56DE\u590D\u7ED3\u675F\u540E\u518D\u52A0\u8F7D\u66F4\u65E9\u7684\u6D88\u606F\u3002",
3035
3042
  rewindMsg: "\u5B83\u4E4B\u540E\u7684\u5BF9\u8BDD\u4F1A\u88AB\u5220\u9664\uFF0C\u6D88\u606F\u5185\u5BB9\u653E\u56DE\u8F93\u5165\u6846\u3002",
@@ -4940,7 +4947,7 @@ ${t.webHint}`;
4940
4947
  };
4941
4948
  const userRow = (content, msg) => {
4942
4949
  const parts = textPartsOf(content);
4943
- const own = parts.filter((p) => !p.startsWith(ATTACH_MARK) && !p.startsWith(CONTEXT_MARK) && !p.startsWith("<file name="));
4950
+ const own = parts.filter((p) => !p.startsWith(ATTACH_MARK) && !p.startsWith(CONTEXT_MARK) && !p.startsWith(STATE_MARK) && !p.startsWith("<file name="));
4944
4951
  const typed = typedOf(msg);
4945
4952
  const row = { msg, text: typed ?? own.join("\n"), update: () => void 0, render: () => userEl(content, row) };
4946
4953
  return row;
@@ -5091,8 +5098,10 @@ ${t.webHint}`;
5091
5098
  foot.append(copy, ...replyActions?.retry === false ? [] : [again], ...replyActions?.delete === false ? [] : [del]);
5092
5099
  const u = last.runUsage;
5093
5100
  if (u && u.calls) {
5101
+ const cached = u.cached_tokens ?? 0;
5102
+ const hit = cached > 0 && u.prompt_tokens > 0 ? " \xB7 " + t.replyCache.replace("{p}", String(Math.round(cached / u.prompt_tokens * 100))) : "";
5094
5103
  const show = (currency) => {
5095
- cost.textContent = t.replyCost.replace("{cost}", fmtCost(u.total_cost, currency));
5104
+ cost.textContent = t.replyCost.replace("{cost}", fmtCost(u.total_cost, currency)) + hit;
5096
5105
  };
5097
5106
  const cost = h("span", "ra-cost");
5098
5107
  show(costCurrency);
@@ -5100,7 +5109,7 @@ ${t.webHint}`;
5100
5109
  if (costCurrency === void 0 && a) void a.modelInfo().then((info) => {
5101
5110
  if (info?.price?.currency) show(info.price.currency);
5102
5111
  }).catch(() => void 0);
5103
- cost.title = t.replyUsage.replace("{in}", fmtTokens(u.prompt_tokens)).replace("{out}", fmtTokens(u.completion_tokens)).replace("{calls}", String(u.calls));
5112
+ cost.title = t.replyUsage.replace("{in}", fmtTokens(u.prompt_tokens) + (cached > 0 ? t.replyCached.replace("{n}", fmtTokens(cached)) : "")).replace("{out}", fmtTokens(u.completion_tokens)).replace("{calls}", String(u.calls));
5104
5113
  foot.append(cost);
5105
5114
  }
5106
5115
  return foot;
package/dist/workspace.js CHANGED
@@ -1162,7 +1162,7 @@ export function titleOf(d) {
1162
1162
  }
1163
1163
  /** A title that is not the user's words: a compaction summary, an expanded skill, an agent note, an attachment list, the host's context. */
1164
1164
  export function isMachineTitle(title) {
1165
- return /^(The conversation history before this point|<skill[\s>]|\[environment\]|\[attachments\]|\[context\] )|\[attachments\]/.test(title);
1165
+ return /^(The conversation history before this point|<skill[\s>]|\[environment\]|\[attachments\]|\[context\] |\[state\] )|\[attachments\]/.test(title);
1166
1166
  }
1167
1167
  /** Runs fn holding the origin-wide Web Lock `name`; without Web Locks it just runs fn. */
1168
1168
  export function withLock(name, fn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runappsai/agent",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "description": "Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.",
6
6
  "license": "MIT",