@hyperwindmill/caretaker-cli 0.31.0 → 0.33.0

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.
Files changed (35) hide show
  1. package/dist/cli/web/mcp_bridge.d.ts +1 -0
  2. package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
  3. package/dist/cli/web/mcp_bridge.js +11 -2
  4. package/dist/cli/web/scheduler/cycle_events.d.ts +8 -3
  5. package/dist/cli/web/scheduler/cycle_events.d.ts.map +1 -1
  6. package/dist/cli/web/scheduler/cycle_events.js +2 -0
  7. package/dist/cli/web/scheduler/email_triage.d.ts +70 -0
  8. package/dist/cli/web/scheduler/email_triage.d.ts.map +1 -0
  9. package/dist/cli/web/scheduler/email_triage.js +262 -0
  10. package/dist/cli/web/scheduler/email_triage_agent.d.ts +16 -0
  11. package/dist/cli/web/scheduler/email_triage_agent.d.ts.map +1 -0
  12. package/dist/cli/web/scheduler/email_triage_agent.js +94 -0
  13. package/dist/cli/web/scheduler/heartbeat.d.ts +1 -1
  14. package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
  15. package/dist/cli/web/scheduler/heartbeat.js +9 -5
  16. package/dist/cli/web/scheduler/service_runs.d.ts +12 -0
  17. package/dist/cli/web/scheduler/service_runs.d.ts.map +1 -0
  18. package/dist/cli/web/scheduler/service_runs.js +39 -0
  19. package/dist/cli/web/scheduler.d.ts +9 -0
  20. package/dist/cli/web/scheduler.d.ts.map +1 -1
  21. package/dist/cli/web/scheduler.js +25 -1
  22. package/dist/cli/web/server.d.ts.map +1 -1
  23. package/dist/cli/web/server.js +34 -1
  24. package/dist/harness/tools/builtin/email_tools.d.ts +1 -0
  25. package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -1
  26. package/dist/harness/tools/builtin/email_tools.js +41 -1
  27. package/dist/harness/tools/builtin/index.d.ts +2 -2
  28. package/dist/harness/tools/builtin/index.d.ts.map +1 -1
  29. package/dist/harness/tools/builtin/index.js +3 -2
  30. package/dist/lib/email.d.ts +20 -0
  31. package/dist/lib/email.d.ts.map +1 -1
  32. package/dist/lib/email.js +107 -33
  33. package/dist/webview/standalone.js +644 -333
  34. package/dist/webview/standalone.js.map +4 -4
  35. package/package.json +3 -3
@@ -17392,7 +17392,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
17392
17392
  }
17393
17393
 
17394
17394
  // src/SettingsPanel.tsx
17395
- var import_react21 = __toESM(require_react(), 1);
17395
+ var import_react22 = __toESM(require_react(), 1);
17396
17396
 
17397
17397
  // src/ProvidersTab.tsx
17398
17398
  var import_react7 = __toESM(require_react(), 1);
@@ -19848,8 +19848,36 @@ Please report this to https://github.com/markedjs/marked.`, e) {
19848
19848
  }
19849
19849
 
19850
19850
  // src/ServicesTab.tsx
19851
+ var import_react15 = __toESM(require_react(), 1);
19852
+
19853
+ // src/services_form_utils.ts
19854
+ function triageAccountOptions(services, agentId) {
19855
+ return services.filter(
19856
+ (s) => s.type === "email" && s.enabled && !!s.imapHost && !!s.smtpHost && (!s.allowedAgents?.length || s.allowedAgents.includes(agentId))
19857
+ );
19858
+ }
19859
+ function splitRecipients(raw) {
19860
+ return (raw || "").split(/[,\n;]/).map((r) => r.trim()).filter(Boolean);
19861
+ }
19862
+ function triageFormError(f, accounts) {
19863
+ if (!f.agentId) return "Please select an agent for this service.";
19864
+ if (f.cron.trim().split(/\s+/).filter(Boolean).length !== 5) {
19865
+ return 'Invalid cron expression. It must contain exactly 5 space-separated fields (e.g. "*/15 * * * *").';
19866
+ }
19867
+ if (!f.accountId) return "Select the email account to triage.";
19868
+ if (!accounts.some((a2) => a2.id === f.accountId)) {
19869
+ return "The selected email account is not available (it must be enabled, have IMAP and SMTP, and be open to the selected agent).";
19870
+ }
19871
+ if (splitRecipients(f.recipients).length === 0) return "Add at least one recipient for the triage report.";
19872
+ const n = Number(f.maxEmails);
19873
+ if (!/^\d+$/.test(f.maxEmails.trim()) || n < 1 || n > 200) return "Max emails must be a whole number between 1 and 200.";
19874
+ return null;
19875
+ }
19876
+
19877
+ // src/use_cycle_stream.ts
19851
19878
  var import_react14 = __toESM(require_react(), 1);
19852
- var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
19879
+
19880
+ // src/chat_state.ts
19853
19881
  function closeStreamingAssistant(items) {
19854
19882
  const last = items[items.length - 1];
19855
19883
  if (!last || last.kind !== "assistant" || !last.streaming) return items;
@@ -19858,16 +19886,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
19858
19886
  function reconstructChatItems(messages) {
19859
19887
  let items = [];
19860
19888
  for (const msg of messages) {
19861
- if (msg.role === "user") {
19889
+ if (msg.recap) {
19862
19890
  items = closeStreamingAssistant(items);
19863
- items.push({ kind: "user", text: msg.content });
19891
+ items.push({ kind: "assistant", text: msg.content, streaming: false, label: "Cycle recap" });
19892
+ } else if (msg.role === "user") {
19893
+ items = closeStreamingAssistant(items);
19894
+ items.push({ kind: "user", text: msg.content, attachments: msg.attachments });
19864
19895
  } else if (msg.role === "assistant") {
19865
19896
  items = closeStreamingAssistant(items);
19866
19897
  if (msg.parts && msg.parts.length > 0) {
19867
19898
  for (const part of msg.parts) {
19868
19899
  if (part.type === "text") {
19869
19900
  items.push({ kind: "assistant", text: part.text, streaming: false });
19870
- } else if (part.type === "thinking") {
19901
+ } else if (part.type === "thinking" && part.text.trim().length > 0) {
19871
19902
  items.push({ kind: "thinking", text: part.text });
19872
19903
  } else if (part.type === "tool_use") {
19873
19904
  items.push({
@@ -19905,36 +19936,302 @@ Please report this to https://github.com/markedjs/marked.`, e) {
19905
19936
  }
19906
19937
  return closeStreamingAssistant(items);
19907
19938
  }
19939
+ function chatReducer(state, action) {
19940
+ switch (action.kind) {
19941
+ case "send-user":
19942
+ return {
19943
+ ...state,
19944
+ status: "streaming",
19945
+ errorText: null,
19946
+ items: [...state.items, { kind: "user", text: action.text, attachments: action.attachments }]
19947
+ };
19948
+ case "append-chunk": {
19949
+ const last = state.items[state.items.length - 1];
19950
+ if (last && last.kind === "assistant" && last.streaming) {
19951
+ const updated = { ...last, text: last.text + action.text };
19952
+ return { ...state, items: [...state.items.slice(0, -1), updated] };
19953
+ }
19954
+ return {
19955
+ ...state,
19956
+ items: [...state.items, { kind: "assistant", text: action.text, streaming: true }]
19957
+ };
19958
+ }
19959
+ case "append-thinking": {
19960
+ const last = state.items[state.items.length - 1];
19961
+ if (last && last.kind === "thinking") {
19962
+ const updated = { ...last, text: last.text + action.text };
19963
+ return { ...state, items: [...state.items.slice(0, -1), updated] };
19964
+ }
19965
+ return {
19966
+ ...state,
19967
+ items: [...state.items, { kind: "thinking", text: action.text }]
19968
+ };
19969
+ }
19970
+ case "tool-call":
19971
+ return {
19972
+ ...state,
19973
+ items: [
19974
+ ...closeStreamingAssistant(state.items),
19975
+ { kind: "tool", id: action.id, name: action.name, args: action.args, result: null }
19976
+ ]
19977
+ };
19978
+ case "tool-result": {
19979
+ const idx = state.items.findIndex(
19980
+ (it2) => it2.kind === "tool" && it2.id === action.id && it2.result === null
19981
+ );
19982
+ if (idx < 0) return state;
19983
+ const tool = state.items[idx];
19984
+ const updated = { ...tool, result: action.content };
19985
+ return {
19986
+ ...state,
19987
+ items: [...state.items.slice(0, idx), updated, ...state.items.slice(idx + 1)]
19988
+ };
19989
+ }
19990
+ case "permission-request":
19991
+ return {
19992
+ ...state,
19993
+ pendingConfirms: [
19994
+ ...state.pendingConfirms,
19995
+ { id: action.id, toolName: action.toolName, args: action.args }
19996
+ ]
19997
+ };
19998
+ case "permission-resolved":
19999
+ return {
20000
+ ...state,
20001
+ pendingConfirms: state.pendingConfirms.filter((p) => p.id !== action.id)
20002
+ };
20003
+ case "done":
20004
+ return {
20005
+ ...state,
20006
+ status: "idle",
20007
+ pendingConfirms: [],
20008
+ items: closeStreamingAssistant(state.items)
20009
+ };
20010
+ case "clear":
20011
+ return {
20012
+ ...state,
20013
+ items: [],
20014
+ status: "idle",
20015
+ errorText: null,
20016
+ pendingConfirms: [],
20017
+ contextUsage: null
20018
+ };
20019
+ case "error":
20020
+ return {
20021
+ ...state,
20022
+ status: "error",
20023
+ errorText: action.text,
20024
+ pendingConfirms: [],
20025
+ items: closeStreamingAssistant(state.items)
20026
+ };
20027
+ case "load-history": {
20028
+ const historyItems = reconstructChatItems(action.messages);
20029
+ return {
20030
+ ...state,
20031
+ items: historyItems,
20032
+ // A cycle opened mid-run keeps the stream indicator on until its `done`.
20033
+ status: action.streaming ? "streaming" : "idle",
20034
+ errorText: null,
20035
+ pendingConfirms: []
20036
+ };
20037
+ }
20038
+ case "context-usage":
20039
+ return {
20040
+ ...state,
20041
+ contextUsage: action.usage
20042
+ };
20043
+ }
20044
+ }
20045
+ var initialChatState = {
20046
+ items: [],
20047
+ status: "idle",
20048
+ errorText: null,
20049
+ pendingConfirms: [],
20050
+ contextUsage: null
20051
+ };
20052
+
20053
+ // src/use_cycle_stream.ts
20054
+ function useCycleStream(id, handlers) {
20055
+ const [chat, dispatch] = (0, import_react14.useReducer)(chatReducer, initialChatState);
20056
+ const ref = (0, import_react14.useRef)(handlers);
20057
+ ref.current = handlers;
20058
+ (0, import_react14.useEffect)(() => {
20059
+ function handle(event) {
20060
+ const msg = event.data;
20061
+ if (!msg || typeof msg !== "object" || !("type" in msg) || !("sessionId" in msg)) return;
20062
+ if (msg.sessionId !== id) return;
20063
+ if (msg.type === "cycleLoaded") {
20064
+ dispatch({ kind: "load-history", messages: msg.messages, streaming: msg.running });
20065
+ return;
20066
+ }
20067
+ if (msg.type !== "cycleEvent") return;
20068
+ const ev = msg.event;
20069
+ switch (ev.type) {
20070
+ case "user":
20071
+ dispatch({ kind: "send-user", text: ev.text });
20072
+ return;
20073
+ case "chunk":
20074
+ dispatch({ kind: "append-chunk", text: ev.text });
20075
+ return;
20076
+ case "thinking":
20077
+ dispatch({ kind: "append-thinking", text: ev.text });
20078
+ return;
20079
+ case "tool_call":
20080
+ dispatch({ kind: "tool-call", id: ev.id, name: ev.name, args: ev.args });
20081
+ return;
20082
+ case "tool_result":
20083
+ dispatch({ kind: "tool-result", id: ev.id, content: ev.content });
20084
+ return;
20085
+ case "done":
20086
+ dispatch({ kind: "done" });
20087
+ ref.current.onDone();
20088
+ return;
20089
+ case "error":
20090
+ dispatch({ kind: "error", text: ev.message });
20091
+ return;
20092
+ }
20093
+ }
20094
+ window.addEventListener("message", handle);
20095
+ ref.current.watch();
20096
+ return () => {
20097
+ window.removeEventListener("message", handle);
20098
+ ref.current.unwatch();
20099
+ };
20100
+ }, [id]);
20101
+ return chat;
20102
+ }
20103
+
20104
+ // src/ServicesTab.tsx
20105
+ var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
20106
+ function closeStreamingAssistant2(items) {
20107
+ const last = items[items.length - 1];
20108
+ if (!last || last.kind !== "assistant" || !last.streaming) return items;
20109
+ return [...items.slice(0, -1), { ...last, streaming: false }];
20110
+ }
20111
+ function reconstructChatItems2(messages) {
20112
+ let items = [];
20113
+ for (const msg of messages) {
20114
+ if (msg.role === "user") {
20115
+ items = closeStreamingAssistant2(items);
20116
+ items.push({ kind: "user", text: msg.content });
20117
+ } else if (msg.role === "assistant") {
20118
+ items = closeStreamingAssistant2(items);
20119
+ if (msg.parts && msg.parts.length > 0) {
20120
+ for (const part of msg.parts) {
20121
+ if (part.type === "text") {
20122
+ items.push({ kind: "assistant", text: part.text, streaming: false });
20123
+ } else if (part.type === "thinking") {
20124
+ items.push({ kind: "thinking", text: part.text });
20125
+ } else if (part.type === "tool_use") {
20126
+ items.push({
20127
+ kind: "tool",
20128
+ id: part.id,
20129
+ name: part.name,
20130
+ args: part.args,
20131
+ result: null
20132
+ });
20133
+ }
20134
+ }
20135
+ } else {
20136
+ items.push({ kind: "assistant", text: msg.content, streaming: false });
20137
+ }
20138
+ } else if (msg.role === "tool") {
20139
+ const toolCallId = msg.toolCallId;
20140
+ if (toolCallId) {
20141
+ const idx = items.findIndex(
20142
+ (it2) => it2.kind === "tool" && it2.id === toolCallId && it2.result === null
20143
+ );
20144
+ if (idx !== -1) {
20145
+ const toolItem = items[idx];
20146
+ items[idx] = { ...toolItem, result: msg.content };
20147
+ } else {
20148
+ items.push({
20149
+ kind: "tool",
20150
+ id: toolCallId,
20151
+ name: "unknown_tool",
20152
+ args: {},
20153
+ result: msg.content
20154
+ });
20155
+ }
20156
+ }
20157
+ }
20158
+ }
20159
+ return closeStreamingAssistant2(items);
20160
+ }
20161
+ function LiveServiceRun({
20162
+ runId,
20163
+ agentName,
20164
+ postMessage,
20165
+ onFinished
20166
+ }) {
20167
+ const chat = useCycleStream(runId, {
20168
+ watch: () => postMessage({ type: "watchServiceRun", runId }),
20169
+ unwatch: () => postMessage({ type: "unwatchCycle", sessionId: runId }),
20170
+ onDone: onFinished
20171
+ });
20172
+ const running = chat.status === "streaming";
20173
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20174
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "execution-console__run-header", children: [
20175
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
20176
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { style: { fontSize: "12px", fontWeight: 700 }, children: [
20177
+ "Run: ",
20178
+ runId
20179
+ ] }),
20180
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: { fontSize: "10px", color: "var(--vscode-descriptionForeground)" }, children: running ? "Running\u2026" : "Finished without writing a log" })
20181
+ ] }),
20182
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { style: { fontSize: "11px", color: "var(--vscode-descriptionForeground)" }, children: [
20183
+ "Agent: ",
20184
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: agentName })
20185
+ ] })
20186
+ ] }),
20187
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "messages", style: { padding: "20px 24px", flex: 1, overflowY: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MessageList, { items: chat.items, isStreaming: running, agentName }) }),
20188
+ chat.errorText && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "notice notice--block", children: chat.errorText })
20189
+ ] });
20190
+ }
19908
20191
  function ServicesTab({ config, agents, postMessage, taskRuns = {} }) {
19909
20192
  const tasks = config.scheduler?.tasks || [];
19910
- const [editingTask, setEditingTask] = (0, import_react14.useState)(null);
19911
- const [isCreating, setIsCreating] = (0, import_react14.useState)(false);
19912
- const [viewingTaskLogs, setViewingTaskLogs] = (0, import_react14.useState)(null);
19913
- const [selectedRunId, setSelectedRunId] = (0, import_react14.useState)(null);
19914
- const [name, setName] = (0, import_react14.useState)("");
19915
- const [type, setType] = (0, import_react14.useState)("heartbeat");
19916
- const [enabled, setEnabled] = (0, import_react14.useState)(true);
19917
- const [agentId, setAgentId] = (0, import_react14.useState)("");
19918
- const [workingDir, setWorkingDir] = (0, import_react14.useState)("");
19919
- const [prompt, setPrompt] = (0, import_react14.useState)("");
19920
- const [cron, setCron] = (0, import_react14.useState)("*/15 * * * *");
19921
- const [telegramBotToken, setTelegramBotToken] = (0, import_react14.useState)("");
19922
- const [telegramAllowedChats, setTelegramAllowedChats] = (0, import_react14.useState)("");
19923
- const [imapHost, setImapHost] = (0, import_react14.useState)("");
19924
- const [imapPort, setImapPort] = (0, import_react14.useState)("993");
19925
- const [imapUser, setImapUser] = (0, import_react14.useState)("");
19926
- const [imapPassword, setImapPassword] = (0, import_react14.useState)("");
19927
- const [imapSecure, setImapSecure] = (0, import_react14.useState)(true);
19928
- const [smtpHost, setSmtpHost] = (0, import_react14.useState)("");
19929
- const [smtpPort, setSmtpPort] = (0, import_react14.useState)("587");
19930
- const [smtpSecure, setSmtpSecure] = (0, import_react14.useState)(false);
19931
- const [smtpFrom, setSmtpFrom] = (0, import_react14.useState)("");
19932
- const [smtpUser, setSmtpUser] = (0, import_react14.useState)("");
19933
- const [smtpPassword, setSmtpPassword] = (0, import_react14.useState)("");
19934
- const [allowedSenders, setAllowedSenders] = (0, import_react14.useState)("");
19935
- const [allowedRecipients, setAllowedRecipients] = (0, import_react14.useState)("");
19936
- const [allowedAgents, setAllowedAgents] = (0, import_react14.useState)([]);
19937
- const [errorMsg, setErrorMsg] = (0, import_react14.useState)(null);
20193
+ const [editingTask, setEditingTask] = (0, import_react15.useState)(null);
20194
+ const [isCreating, setIsCreating] = (0, import_react15.useState)(false);
20195
+ const [viewingTaskLogs, setViewingTaskLogs] = (0, import_react15.useState)(null);
20196
+ const [selectedRunId, setSelectedRunId] = (0, import_react15.useState)(null);
20197
+ const [liveRuns, setLiveRuns] = (0, import_react15.useState)({});
20198
+ (0, import_react15.useEffect)(() => {
20199
+ function handle(event) {
20200
+ const msg = event.data;
20201
+ if (!msg || typeof msg !== "object" || msg.type !== "serviceRunActive") return;
20202
+ setLiveRuns((prev) => ({ ...prev, [msg.serviceId]: { runId: msg.runId, finished: false } }));
20203
+ }
20204
+ window.addEventListener("message", handle);
20205
+ return () => window.removeEventListener("message", handle);
20206
+ }, []);
20207
+ const [name, setName] = (0, import_react15.useState)("");
20208
+ const [type, setType] = (0, import_react15.useState)("heartbeat");
20209
+ const [enabled, setEnabled] = (0, import_react15.useState)(true);
20210
+ const [agentId, setAgentId] = (0, import_react15.useState)("");
20211
+ const [workingDir, setWorkingDir] = (0, import_react15.useState)("");
20212
+ const [prompt, setPrompt] = (0, import_react15.useState)("");
20213
+ const [cron, setCron] = (0, import_react15.useState)("*/15 * * * *");
20214
+ const [telegramBotToken, setTelegramBotToken] = (0, import_react15.useState)("");
20215
+ const [telegramAllowedChats, setTelegramAllowedChats] = (0, import_react15.useState)("");
20216
+ const [imapHost, setImapHost] = (0, import_react15.useState)("");
20217
+ const [imapPort, setImapPort] = (0, import_react15.useState)("993");
20218
+ const [imapUser, setImapUser] = (0, import_react15.useState)("");
20219
+ const [imapPassword, setImapPassword] = (0, import_react15.useState)("");
20220
+ const [imapSecure, setImapSecure] = (0, import_react15.useState)(true);
20221
+ const [smtpHost, setSmtpHost] = (0, import_react15.useState)("");
20222
+ const [smtpPort, setSmtpPort] = (0, import_react15.useState)("587");
20223
+ const [smtpSecure, setSmtpSecure] = (0, import_react15.useState)(false);
20224
+ const [smtpFrom, setSmtpFrom] = (0, import_react15.useState)("");
20225
+ const [smtpUser, setSmtpUser] = (0, import_react15.useState)("");
20226
+ const [smtpPassword, setSmtpPassword] = (0, import_react15.useState)("");
20227
+ const [allowedSenders, setAllowedSenders] = (0, import_react15.useState)("");
20228
+ const [allowedRecipients, setAllowedRecipients] = (0, import_react15.useState)("");
20229
+ const [allowedAgents, setAllowedAgents] = (0, import_react15.useState)([]);
20230
+ const [triageAccountId, setTriageAccountId] = (0, import_react15.useState)("");
20231
+ const [triageRecipients, setTriageRecipients] = (0, import_react15.useState)("");
20232
+ const [triageMaxEmails, setTriageMaxEmails] = (0, import_react15.useState)("50");
20233
+ const [triageSubjectPrefix, setTriageSubjectPrefix] = (0, import_react15.useState)("");
20234
+ const [errorMsg, setErrorMsg] = (0, import_react15.useState)(null);
19938
20235
  const startEdit = (task) => {
19939
20236
  setEditingTask(task);
19940
20237
  setIsCreating(false);
@@ -19961,6 +20258,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
19961
20258
  setAllowedSenders(task.allowedSenders || "");
19962
20259
  setAllowedRecipients(task.allowedRecipients || "");
19963
20260
  setAllowedAgents(task.allowedAgents || []);
20261
+ setTriageAccountId(task.triageAccountId || "");
20262
+ setTriageRecipients(task.triageRecipients || "");
20263
+ setTriageMaxEmails(task.triageMaxEmails ? String(task.triageMaxEmails) : "50");
20264
+ setTriageSubjectPrefix(task.triageSubjectPrefix || "");
19964
20265
  setErrorMsg(null);
19965
20266
  };
19966
20267
  const startCreate = () => {
@@ -19989,6 +20290,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
19989
20290
  setAllowedSenders("");
19990
20291
  setAllowedRecipients("");
19991
20292
  setAllowedAgents([]);
20293
+ setTriageAccountId("");
20294
+ setTriageRecipients("");
20295
+ setTriageMaxEmails("50");
20296
+ setTriageSubjectPrefix("");
19992
20297
  setErrorMsg(null);
19993
20298
  };
19994
20299
  const cancelForm = () => {
@@ -20026,6 +20331,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20026
20331
  setErrorMsg('Invalid cron expression. It must contain exactly 5 space-separated fields (e.g. "*/15 * * * *").');
20027
20332
  return;
20028
20333
  }
20334
+ } else if (type === "email_triage") {
20335
+ const err = triageFormError(
20336
+ { agentId, cron: trimmedCron, accountId: triageAccountId, recipients: triageRecipients, maxEmails: triageMaxEmails },
20337
+ triageAccountOptions(tasks, agentId)
20338
+ );
20339
+ if (err) {
20340
+ setErrorMsg(err);
20341
+ return;
20342
+ }
20029
20343
  } else if (type === "telegram") {
20030
20344
  if (!telegramBotToken.trim()) {
20031
20345
  setErrorMsg("Telegram Bot Token is required.");
@@ -20075,6 +20389,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20075
20389
  telegramBotToken: telegramBotToken.trim(),
20076
20390
  telegramAllowedChats: telegramAllowedChats.trim()
20077
20391
  } : {},
20392
+ ...type === "email_triage" ? {
20393
+ triageAccountId,
20394
+ triageRecipients: triageRecipients.trim(),
20395
+ triageMaxEmails: Number(triageMaxEmails),
20396
+ triageSubjectPrefix: triageSubjectPrefix.trim()
20397
+ } : {},
20078
20398
  ...type === "email" ? {
20079
20399
  imapHost: imapHost.trim(),
20080
20400
  imapPort: Number(imapPort),
@@ -20145,13 +20465,30 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20145
20465
  const openLogViewer = (task) => {
20146
20466
  setViewingTaskLogs(task);
20147
20467
  setSelectedRunId(null);
20468
+ setLiveRuns((prev) => {
20469
+ if (!prev[task.id]?.finished) return prev;
20470
+ const { [task.id]: _gone, ...rest } = prev;
20471
+ return rest;
20472
+ });
20148
20473
  postMessage({ type: "getTaskRuns", taskId: task.id });
20149
20474
  };
20475
+ const runNow = (task) => {
20476
+ postMessage({ type: "runService", serviceId: task.id });
20477
+ openLogViewer(task);
20478
+ };
20479
+ const onLiveRunFinished = (serviceId, runId) => {
20480
+ setLiveRuns(
20481
+ (prev) => prev[serviceId]?.runId === runId ? { ...prev, [serviceId]: { runId, finished: true } } : prev
20482
+ );
20483
+ postMessage({ type: "getTaskRuns", taskId: serviceId });
20484
+ };
20150
20485
  const showForm = isCreating || editingTask !== null;
20151
20486
  const runs = viewingTaskLogs ? taskRuns[viewingTaskLogs.id] || [] : [];
20152
- const activeRunId = selectedRunId || runs[0]?.runId;
20487
+ const live = viewingTaskLogs ? liveRuns[viewingTaskLogs.id] : void 0;
20488
+ const liveUnsaved = live && !runs.some((r) => r.runId === live.runId) ? live : void 0;
20489
+ const activeRunId = selectedRunId || liveUnsaved?.runId || runs[0]?.runId;
20153
20490
  const activeRun = runs.find((r) => r.runId === activeRunId);
20154
- const activeRunChatItems = (0, import_react14.useMemo)(() => activeRun ? reconstructChatItems(activeRun.messages || []) : [], [activeRun]);
20491
+ const activeRunChatItems = (0, import_react15.useMemo)(() => activeRun ? reconstructChatItems2(activeRun.messages || []) : [], [activeRun]);
20155
20492
  const selectedAgentName = viewingTaskLogs ? agents.find((a2) => a2.id === viewingTaskLogs.agentId)?.name : "";
20156
20493
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "tab-pane services-tab", children: [
20157
20494
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "tab-pane__header", children: [
@@ -20200,7 +20537,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20200
20537
  children: [
20201
20538
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "heartbeat", children: "Heartbeat (Scheduled Agent Run)" }),
20202
20539
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "telegram", children: "Telegram Bot (Poller)" }),
20203
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "email", children: "Email (IMAP credentials)" })
20540
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "email", children: "Email (IMAP credentials)" }),
20541
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "email_triage", children: "Email triage (Scheduled Report)" })
20204
20542
  ]
20205
20543
  }
20206
20544
  )
@@ -20294,9 +20632,137 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20294
20632
  }
20295
20633
  )
20296
20634
  ] })
20297
- ] }) : type === "telegram" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20635
+ ] }) : type === "email_triage" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20298
20636
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20299
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "tg-token", children: "Telegram Bot Token" }),
20637
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "task-cron", children: "Cron Timing" }),
20638
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20639
+ "input",
20640
+ {
20641
+ id: "task-cron",
20642
+ type: "text",
20643
+ placeholder: "e.g. 0 8 * * * (every morning at 8)",
20644
+ value: cron,
20645
+ onChange: (e) => setCron(e.target.value)
20646
+ }
20647
+ )
20648
+ ] }),
20649
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20650
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "triage-account", children: "Email account" }),
20651
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
20652
+ "select",
20653
+ {
20654
+ id: "triage-account",
20655
+ value: triageAccountId,
20656
+ onChange: (e) => setTriageAccountId(e.target.value),
20657
+ style: {
20658
+ width: "100%",
20659
+ padding: "6px 8px",
20660
+ borderRadius: "var(--radius-sm)",
20661
+ background: "var(--vscode-dropdown-background, #252526)",
20662
+ color: "var(--vscode-dropdown-foreground, #cccccc)",
20663
+ border: "1px solid var(--vscode-dropdown-border, #3c3c3c)",
20664
+ fontSize: "12px",
20665
+ cursor: "pointer"
20666
+ },
20667
+ children: [
20668
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "", disabled: true, children: "-- Select account --" }),
20669
+ triageAccountOptions(tasks, agentId).map((a2) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: a2.id, children: a2.name }, a2.id))
20670
+ ]
20671
+ }
20672
+ ),
20673
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "field-hint", style: { fontSize: "11px", opacity: 0.8, marginTop: "4px" }, children: "Only enabled email services with both IMAP and SMTP configured are listed." })
20674
+ ] }),
20675
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20676
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "triage-recipients", children: "Report recipients (one per line)" }),
20677
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20678
+ "textarea",
20679
+ {
20680
+ id: "triage-recipients",
20681
+ placeholder: "you@example.com",
20682
+ value: triageRecipients,
20683
+ onChange: (e) => setTriageRecipients(e.target.value),
20684
+ rows: 3,
20685
+ style: {
20686
+ width: "100%",
20687
+ padding: "8px",
20688
+ borderRadius: "var(--radius-sm)",
20689
+ background: "var(--vscode-input-background, #252526)",
20690
+ color: "var(--vscode-input-foreground, #cccccc)",
20691
+ border: "1px solid var(--vscode-input-border, #3c3c3c)",
20692
+ fontFamily: "inherit",
20693
+ fontSize: "12px",
20694
+ resize: "vertical"
20695
+ }
20696
+ }
20697
+ )
20698
+ ] }),
20699
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20700
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "triage-max", children: "Max emails per run (1-200)" }),
20701
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20702
+ "input",
20703
+ {
20704
+ id: "triage-max",
20705
+ type: "number",
20706
+ min: 1,
20707
+ max: 200,
20708
+ value: triageMaxEmails,
20709
+ onChange: (e) => setTriageMaxEmails(e.target.value)
20710
+ }
20711
+ )
20712
+ ] }),
20713
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20714
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "triage-prefix", children: "Subject prefix (optional)" }),
20715
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20716
+ "input",
20717
+ {
20718
+ id: "triage-prefix",
20719
+ type: "text",
20720
+ placeholder: "[Email Triage]",
20721
+ value: triageSubjectPrefix,
20722
+ onChange: (e) => setTriageSubjectPrefix(e.target.value)
20723
+ }
20724
+ )
20725
+ ] }),
20726
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20727
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "task-dir", children: "Working Directory (Absolute path, optional)" }),
20728
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20729
+ "input",
20730
+ {
20731
+ id: "task-dir",
20732
+ type: "text",
20733
+ placeholder: "e.g. /home/user/project (default: process.cwd())",
20734
+ value: workingDir,
20735
+ onChange: (e) => setWorkingDir(e.target.value)
20736
+ }
20737
+ )
20738
+ ] }),
20739
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20740
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "task-prompt", children: "Extra triage instructions (optional)" }),
20741
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20742
+ "textarea",
20743
+ {
20744
+ id: "task-prompt",
20745
+ placeholder: "e.g. Treat anything from our main client as urgent.",
20746
+ value: prompt,
20747
+ onChange: (e) => setPrompt(e.target.value),
20748
+ rows: 4,
20749
+ style: {
20750
+ width: "100%",
20751
+ padding: "8px",
20752
+ borderRadius: "var(--radius-sm)",
20753
+ background: "var(--vscode-input-background, #252526)",
20754
+ color: "var(--vscode-input-foreground, #cccccc)",
20755
+ border: "1px solid var(--vscode-input-border, #3c3c3c)",
20756
+ fontFamily: "inherit",
20757
+ fontSize: "12px",
20758
+ resize: "vertical"
20759
+ }
20760
+ }
20761
+ )
20762
+ ] })
20763
+ ] }) : type === "telegram" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20764
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "form-group", children: [
20765
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: "tg-token", children: "Telegram Bot Token" }),
20300
20766
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20301
20767
  "input",
20302
20768
  {
@@ -20639,6 +21105,22 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20639
21105
  task.imapPort,
20640
21106
  task.smtpHost ? ` \xB7 SMTP ${task.smtpHost}:${task.smtpPort}` : " \xB7 sending off",
20641
21107
  task.allowedAgents?.length ? ` \xB7 agents: ${task.allowedAgents.map((id) => agents.find((a2) => a2.id === id)?.name || id).join(", ")}` : " \xB7 any agent"
21108
+ ] }) : task.type === "email_triage" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "settings-card__subtitle", style: { fontSize: "11px", marginTop: "4px" }, children: [
21109
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: "Agent:" }),
21110
+ " ",
21111
+ agentName,
21112
+ " \xB7 ",
21113
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: "Schedule:" }),
21114
+ " ",
21115
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("code", { children: task.cron }),
21116
+ " \xB7 ",
21117
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: "Account:" }),
21118
+ " ",
21119
+ tasks.find((t) => t.id === task.triageAccountId)?.name || "missing",
21120
+ " \xB7",
21121
+ " ",
21122
+ splitRecipients(task.triageRecipients).length,
21123
+ " recipient(s)"
20642
21124
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20643
21125
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "settings-card__subtitle", style: { fontSize: "11px", marginTop: "4px" }, children: [
20644
21126
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: "Agent:" }),
@@ -20657,7 +21139,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20657
21139
  ] })
20658
21140
  ] }),
20659
21141
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "settings-card__actions", children: [
20660
- task.type === "heartbeat" && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
21142
+ (task.type === "heartbeat" || task.type === "email_triage") && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
21143
+ "button",
21144
+ {
21145
+ className: "icon-btn",
21146
+ onClick: () => runNow(task),
21147
+ title: "Run now (ignores schedule and Off state)",
21148
+ "aria-label": "Run now",
21149
+ style: { fontSize: "12px", marginRight: "4px" },
21150
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Play, { size: 13 })
21151
+ }
21152
+ ),
21153
+ (task.type === "heartbeat" || task.type === "email_triage") && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
20661
21154
  "button",
20662
21155
  {
20663
21156
  className: "icon-btn",
@@ -20712,7 +21205,29 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20712
21205
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "execution-console__body", children: [
20713
21206
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "execution-console__runs-list", children: [
20714
21207
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "app__sidebar-section-title", style: { paddingLeft: "4px", marginBottom: "8px" }, children: "Execution History" }),
20715
- runs.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "app__sidebar-empty-text", children: "No execution runs recorded yet." }) : runs.map((run) => {
21208
+ liveUnsaved && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
21209
+ "button",
21210
+ {
21211
+ className: `execution-console__run-item ${liveUnsaved.runId === activeRunId ? "execution-console__run-item--active" : ""}`,
21212
+ onClick: () => setSelectedRunId(liveUnsaved.runId),
21213
+ children: [
21214
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", width: "100%" }, children: [
21215
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: { fontSize: "10px", color: "var(--vscode-descriptionForeground)" }, children: liveUnsaved.runId }),
21216
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: {
21217
+ fontSize: "9px",
21218
+ fontWeight: 700,
21219
+ padding: "1px 5px",
21220
+ borderRadius: "10px",
21221
+ background: "oklch(0.72 0.14 230 / 0.12)",
21222
+ color: "oklch(0.72 0.14 230)",
21223
+ border: "1px solid oklch(0.72 0.14 230 / 0.3)"
21224
+ }, children: liveUnsaved.finished ? "ENDED" : "RUNNING" })
21225
+ ] }),
21226
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: { fontSize: "11px", fontWeight: 600, marginTop: "2px" }, children: liveUnsaved.finished ? "No log written" : "In progress" })
21227
+ ]
21228
+ }
21229
+ ),
21230
+ runs.length === 0 ? !liveUnsaved && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "app__sidebar-empty-text", children: "No execution runs recorded yet." }) : runs.map((run) => {
20716
21231
  const isSelected = run.runId === activeRunId;
20717
21232
  const date = new Date(run.timestamp);
20718
21233
  const formattedDate = date.toLocaleString();
@@ -20742,7 +21257,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20742
21257
  );
20743
21258
  })
20744
21259
  ] }),
20745
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "execution-console__run-details", children: activeRun ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
21260
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "execution-console__run-details", children: liveUnsaved && activeRunId === liveUnsaved.runId ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
21261
+ LiveServiceRun,
21262
+ {
21263
+ runId: liveUnsaved.runId,
21264
+ agentName: selectedAgentName,
21265
+ postMessage,
21266
+ onFinished: () => onLiveRunFinished(viewingTaskLogs.id, liveUnsaved.runId)
21267
+ },
21268
+ liveUnsaved.runId
21269
+ ) : activeRun ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
20746
21270
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "execution-console__run-header", children: [
20747
21271
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "2px" }, children: [
20748
21272
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { style: { fontSize: "12px", fontWeight: 700 }, children: [
@@ -20774,7 +21298,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20774
21298
  }
20775
21299
 
20776
21300
  // src/VoiceTab.tsx
20777
- var import_react18 = __toESM(require_react(), 1);
21301
+ var import_react19 = __toESM(require_react(), 1);
20778
21302
 
20779
21303
  // src/voice_utils.ts
20780
21304
  var END_OF_TURN_MS = 1200;
@@ -20849,7 +21373,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20849
21373
  }
20850
21374
 
20851
21375
  // src/VoiceBackendBlock.tsx
20852
- var import_react15 = __toESM(require_react(), 1);
21376
+ var import_react16 = __toESM(require_react(), 1);
20853
21377
 
20854
21378
  // src/voice_backend_utils.ts
20855
21379
  function backendStatusText(status) {
@@ -20875,11 +21399,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20875
21399
  onStatusChange,
20876
21400
  hint
20877
21401
  }) {
20878
- const [busy, setBusy] = (0, import_react15.useState)(false);
20879
- const [progress, setProgress] = (0, import_react15.useState)(null);
20880
- const [error, setError] = (0, import_react15.useState)(null);
20881
- const [confirmingDelete, setConfirmingDelete] = (0, import_react15.useState)(false);
20882
- const confirmDeleteTimer = (0, import_react15.useRef)(null);
21402
+ const [busy, setBusy] = (0, import_react16.useState)(false);
21403
+ const [progress, setProgress] = (0, import_react16.useState)(null);
21404
+ const [error, setError] = (0, import_react16.useState)(null);
21405
+ const [confirmingDelete, setConfirmingDelete] = (0, import_react16.useState)(false);
21406
+ const confirmDeleteTimer = (0, import_react16.useRef)(null);
20883
21407
  const disarmDelete = () => {
20884
21408
  if (confirmDeleteTimer.current) clearTimeout(confirmDeleteTimer.current);
20885
21409
  confirmDeleteTimer.current = null;
@@ -20893,14 +21417,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
20893
21417
  CONFIRM_DELETE_MS
20894
21418
  );
20895
21419
  };
20896
- (0, import_react15.useEffect)(
21420
+ (0, import_react16.useEffect)(
20897
21421
  () => () => {
20898
21422
  if (confirmDeleteTimer.current) clearTimeout(confirmDeleteTimer.current);
20899
21423
  },
20900
21424
  []
20901
21425
  );
20902
- const lastContainer = (0, import_react15.useRef)(null);
20903
- (0, import_react15.useEffect)(() => {
21426
+ const lastContainer = (0, import_react16.useRef)(null);
21427
+ (0, import_react16.useEffect)(() => {
20904
21428
  if (status.container === "running" && lastContainer.current !== "running") {
20905
21429
  setError(null);
20906
21430
  }
@@ -21010,7 +21534,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21010
21534
  }
21011
21535
 
21012
21536
  // src/BuiltinVoiceBlock.tsx
21013
- var import_react16 = __toESM(require_react(), 1);
21537
+ var import_react17 = __toESM(require_react(), 1);
21014
21538
  var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
21015
21539
  var MB = 1024 * 1024;
21016
21540
  function sizeLabel(bytes) {
@@ -21030,10 +21554,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21030
21554
  voice,
21031
21555
  onVoiceChange
21032
21556
  }) {
21033
- const [busy, setBusy] = (0, import_react16.useState)(false);
21034
- const [progress, setProgress] = (0, import_react16.useState)(null);
21035
- const [error, setError] = (0, import_react16.useState)(null);
21036
- const [confirmingDelete, setConfirmingDelete] = (0, import_react16.useState)(false);
21557
+ const [busy, setBusy] = (0, import_react17.useState)(false);
21558
+ const [progress, setProgress] = (0, import_react17.useState)(null);
21559
+ const [error, setError] = (0, import_react17.useState)(null);
21560
+ const [confirmingDelete, setConfirmingDelete] = (0, import_react17.useState)(false);
21037
21561
  const loadError = status.runtime.loadError;
21038
21562
  const selected = status.languages.find((l) => l.id === language);
21039
21563
  const query = `?language=${encodeURIComponent(language)}`;
@@ -21160,17 +21684,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21160
21684
  }
21161
21685
 
21162
21686
  // src/BuiltinSttBlock.tsx
21163
- var import_react17 = __toESM(require_react(), 1);
21687
+ var import_react18 = __toESM(require_react(), 1);
21164
21688
  var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
21165
21689
  var MB2 = 1024 * 1024;
21166
21690
  function sizeLabel2(bytes) {
21167
21691
  return `${Math.max(1, Math.round(bytes / MB2))} MB`;
21168
21692
  }
21169
21693
  function BuiltinSttBlock({ status, onStatusChange, model, onModelChange }) {
21170
- const [busy, setBusy] = (0, import_react17.useState)(false);
21171
- const [progress, setProgress] = (0, import_react17.useState)(null);
21172
- const [error, setError] = (0, import_react17.useState)(null);
21173
- const [confirmingDelete, setConfirmingDelete] = (0, import_react17.useState)(false);
21694
+ const [busy, setBusy] = (0, import_react18.useState)(false);
21695
+ const [progress, setProgress] = (0, import_react18.useState)(null);
21696
+ const [error, setError] = (0, import_react18.useState)(null);
21697
+ const [confirmingDelete, setConfirmingDelete] = (0, import_react18.useState)(false);
21174
21698
  const loadError = status.runtime.loadError;
21175
21699
  const selected = status.stt.find((m2) => m2.id === model);
21176
21700
  const query = `?stt=${encodeURIComponent(model)}`;
@@ -21641,39 +22165,39 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21641
22165
  }
21642
22166
  function VoiceTab({ config, onSave, postMessage, sttCatalogResult, ttsCatalogResult }) {
21643
22167
  const current = config.voice ?? EMPTY;
21644
- const [enabled, setEnabled] = (0, import_react18.useState)(current.enabled);
21645
- const [endpoint, setEndpoint] = (0, import_react18.useState)(current.endpoint);
21646
- const [apiKey, setApiKey] = (0, import_react18.useState)(current.apiKey ?? "");
21647
- const [sttModel, setSttModel] = (0, import_react18.useState)(current.sttModel);
21648
- const [ttsEndpoint, setTtsEndpoint] = (0, import_react18.useState)(current.ttsEndpoint ?? "");
21649
- const [ttsApiKey, setTtsApiKey] = (0, import_react18.useState)(current.ttsApiKey ?? "");
21650
- const [ttsModel, setTtsModel] = (0, import_react18.useState)(current.ttsModel ?? "");
21651
- const [ttsVoice, setTtsVoice] = (0, import_react18.useState)(current.ttsVoice ?? "");
21652
- const [ttsSpeed, setTtsSpeed] = (0, import_react18.useState)(
22168
+ const [enabled, setEnabled] = (0, import_react19.useState)(current.enabled);
22169
+ const [endpoint, setEndpoint] = (0, import_react19.useState)(current.endpoint);
22170
+ const [apiKey, setApiKey] = (0, import_react19.useState)(current.apiKey ?? "");
22171
+ const [sttModel, setSttModel] = (0, import_react19.useState)(current.sttModel);
22172
+ const [ttsEndpoint, setTtsEndpoint] = (0, import_react19.useState)(current.ttsEndpoint ?? "");
22173
+ const [ttsApiKey, setTtsApiKey] = (0, import_react19.useState)(current.ttsApiKey ?? "");
22174
+ const [ttsModel, setTtsModel] = (0, import_react19.useState)(current.ttsModel ?? "");
22175
+ const [ttsVoice, setTtsVoice] = (0, import_react19.useState)(current.ttsVoice ?? "");
22176
+ const [ttsSpeed, setTtsSpeed] = (0, import_react19.useState)(
21653
22177
  current.ttsSpeed === void 0 ? "" : String(current.ttsSpeed)
21654
22178
  );
21655
- const [lang, setLang] = (0, import_react18.useState)(current.lang ?? "");
21656
- const [bufferMs, setBufferMs] = (0, import_react18.useState)(
22179
+ const [lang, setLang] = (0, import_react19.useState)(current.lang ?? "");
22180
+ const [bufferMs, setBufferMs] = (0, import_react19.useState)(
21657
22181
  current.playbackBufferMs === void 0 ? "" : String(current.playbackBufferMs)
21658
22182
  );
21659
- const [ttsEngine, setTtsEngine] = (0, import_react18.useState)(current.ttsEngine ?? "endpoint");
21660
- const [sttEngine, setSttEngine] = (0, import_react18.useState)(current.sttEngine ?? "endpoint");
21661
- const [sttBuiltinModel, setSttBuiltinModel] = (0, import_react18.useState)(current.sttBuiltinModel ?? "base");
21662
- const [ttsLanguage, setTtsLanguage] = (0, import_react18.useState)(current.ttsLanguage ?? "");
21663
- const [pronEnabled, setPronEnabled] = (0, import_react18.useState)(current.pronunciationEnabled ?? false);
21664
- const [pronunciation, setPronunciation] = (0, import_react18.useState)(
22183
+ const [ttsEngine, setTtsEngine] = (0, import_react19.useState)(current.ttsEngine ?? "endpoint");
22184
+ const [sttEngine, setSttEngine] = (0, import_react19.useState)(current.sttEngine ?? "endpoint");
22185
+ const [sttBuiltinModel, setSttBuiltinModel] = (0, import_react19.useState)(current.sttBuiltinModel ?? "base");
22186
+ const [ttsLanguage, setTtsLanguage] = (0, import_react19.useState)(current.ttsLanguage ?? "");
22187
+ const [pronEnabled, setPronEnabled] = (0, import_react19.useState)(current.pronunciationEnabled ?? false);
22188
+ const [pronunciation, setPronunciation] = (0, import_react19.useState)(
21665
22189
  current.pronunciation ?? {}
21666
22190
  );
21667
- const [builtinStatus, setBuiltinStatus] = (0, import_react18.useState)(null);
21668
- const [listening, setListening] = (0, import_react18.useState)(false);
21669
- const [listenError, setListenError] = (0, import_react18.useState)(null);
21670
- const listenAbort = (0, import_react18.useRef)(null);
21671
- const [fetching, setFetching] = (0, import_react18.useState)(false);
21672
- const [fetchingTts, setFetchingTts] = (0, import_react18.useState)(false);
21673
- const [saveState, setSaveState] = (0, import_react18.useState)("idle");
21674
- const pendingSave = (0, import_react18.useRef)(null);
21675
- const [autoStartBackend, setAutoStartBackend] = (0, import_react18.useState)(current.autoStartBackend ?? false);
21676
- const [backendStatuses, setBackendStatuses] = (0, import_react18.useState)(null);
22191
+ const [builtinStatus, setBuiltinStatus] = (0, import_react19.useState)(null);
22192
+ const [listening, setListening] = (0, import_react19.useState)(false);
22193
+ const [listenError, setListenError] = (0, import_react19.useState)(null);
22194
+ const listenAbort = (0, import_react19.useRef)(null);
22195
+ const [fetching, setFetching] = (0, import_react19.useState)(false);
22196
+ const [fetchingTts, setFetchingTts] = (0, import_react19.useState)(false);
22197
+ const [saveState, setSaveState] = (0, import_react19.useState)("idle");
22198
+ const pendingSave = (0, import_react19.useRef)(null);
22199
+ const [autoStartBackend, setAutoStartBackend] = (0, import_react19.useState)(current.autoStartBackend ?? false);
22200
+ const [backendStatuses, setBackendStatuses] = (0, import_react19.useState)(null);
21677
22201
  const fetchBackendStatuses = async () => {
21678
22202
  try {
21679
22203
  const res = await fetch("/api/voice/backend");
@@ -21683,12 +22207,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21683
22207
  } catch {
21684
22208
  }
21685
22209
  };
21686
- (0, import_react18.useEffect)(() => {
22210
+ (0, import_react19.useEffect)(() => {
21687
22211
  fetch("/api/voice/builtin").then((res) => res.ok ? res.json() : null).then((st2) => st2 && setBuiltinStatus(st2)).catch(() => {
21688
22212
  });
21689
22213
  return () => listenAbort.current?.abort();
21690
22214
  }, []);
21691
- (0, import_react18.useEffect)(() => {
22215
+ (0, import_react19.useEffect)(() => {
21692
22216
  fetchBackendStatuses();
21693
22217
  const interval = setInterval(fetchBackendStatuses, BACKEND_POLL_MS);
21694
22218
  return () => clearInterval(interval);
@@ -21698,23 +22222,23 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21698
22222
  (prev) => prev ? { ...prev, [target]: status } : { stt: status, tts: null }
21699
22223
  );
21700
22224
  };
21701
- (0, import_react18.useEffect)(() => {
22225
+ (0, import_react19.useEffect)(() => {
21702
22226
  if (sttCatalogResult) setFetching(false);
21703
22227
  }, [sttCatalogResult]);
21704
- (0, import_react18.useEffect)(() => {
22228
+ (0, import_react19.useEffect)(() => {
21705
22229
  if (ttsCatalogResult) setFetchingTts(false);
21706
22230
  }, [ttsCatalogResult]);
21707
- (0, import_react18.useEffect)(() => {
22231
+ (0, import_react19.useEffect)(() => {
21708
22232
  if (saveState !== "saving" || pendingSave.current === null) return;
21709
22233
  if (voiceSignature(config.voice) !== pendingSave.current) return;
21710
22234
  setSaveState("saved");
21711
22235
  }, [config.voice, saveState]);
21712
- (0, import_react18.useEffect)(() => {
22236
+ (0, import_react19.useEffect)(() => {
21713
22237
  if (saveState !== "saved") return;
21714
22238
  const clear = setTimeout(() => setSaveState("idle"), 2500);
21715
22239
  return () => clearTimeout(clear);
21716
22240
  }, [saveState]);
21717
- (0, import_react18.useEffect)(() => {
22241
+ (0, import_react19.useEffect)(() => {
21718
22242
  if (saveState !== "saving") return;
21719
22243
  const giveUp = setTimeout(() => setSaveState("idle"), 6e3);
21720
22244
  return () => clearTimeout(giveUp);
@@ -21759,7 +22283,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
21759
22283
  const builtin = ttsEngine === "builtin";
21760
22284
  const sttBuiltin = sttEngine === "builtin" && !!builtinStatus;
21761
22285
  const showEndpoint = !sttBuiltin || !builtin;
21762
- const synthCode = (0, import_react18.useMemo)(() => {
22286
+ const synthCode = (0, import_react19.useMemo)(() => {
21763
22287
  if (builtin) return builtinStatus?.languages.find((l) => l.id === ttsLanguage)?.code ?? null;
21764
22288
  return lang.trim().split(/[-_]/)[0].toLowerCase() || null;
21765
22289
  }, [builtin, builtinStatus, ttsLanguage, lang]);
@@ -22210,7 +22734,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22210
22734
  }
22211
22735
 
22212
22736
  // src/MemoryTab.tsx
22213
- var import_react19 = __toESM(require_react(), 1);
22737
+ var import_react20 = __toESM(require_react(), 1);
22214
22738
 
22215
22739
  // src/memory_tab_utils.ts
22216
22740
  function buildMemoryConfig(form) {
@@ -22232,23 +22756,23 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22232
22756
  var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
22233
22757
  function MemoryTab({ config, agents, onSave }) {
22234
22758
  const current = config.memory;
22235
- const [enabled, setEnabled] = (0, import_react19.useState)(!!current);
22236
- const [agentId, setAgentId] = (0, import_react19.useState)(current?.agentId ?? "");
22237
- const [sweepMinutes, setSweepMinutes] = (0, import_react19.useState)(
22759
+ const [enabled, setEnabled] = (0, import_react20.useState)(!!current);
22760
+ const [agentId, setAgentId] = (0, import_react20.useState)(current?.agentId ?? "");
22761
+ const [sweepMinutes, setSweepMinutes] = (0, import_react20.useState)(
22238
22762
  current?.sweepMinutes === void 0 ? "" : String(current.sweepMinutes)
22239
22763
  );
22240
- const [minNewMessages, setMinNewMessages] = (0, import_react19.useState)(
22764
+ const [minNewMessages, setMinNewMessages] = (0, import_react20.useState)(
22241
22765
  current?.minNewMessages === void 0 ? "" : String(current.minNewMessages)
22242
22766
  );
22243
- const [saveState, setSaveState] = (0, import_react19.useState)("idle");
22244
- const pendingSave = (0, import_react19.useRef)(null);
22245
- (0, import_react19.useEffect)(() => {
22767
+ const [saveState, setSaveState] = (0, import_react20.useState)("idle");
22768
+ const pendingSave = (0, import_react20.useRef)(null);
22769
+ (0, import_react20.useEffect)(() => {
22246
22770
  if (saveState !== "saving" || pendingSave.current === null) return;
22247
22771
  if (memorySignature(config.memory) !== pendingSave.current)
22248
22772
  return;
22249
22773
  setSaveState("saved");
22250
22774
  }, [config.memory, saveState]);
22251
- (0, import_react19.useEffect)(() => {
22775
+ (0, import_react20.useEffect)(() => {
22252
22776
  if (saveState !== "saved") return;
22253
22777
  const t = setTimeout(() => setSaveState("idle"), 2e3);
22254
22778
  return () => clearTimeout(t);
@@ -22335,7 +22859,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22335
22859
  }
22336
22860
 
22337
22861
  // src/DesktopTab.tsx
22338
- var import_react20 = __toESM(require_react(), 1);
22862
+ var import_react21 = __toESM(require_react(), 1);
22339
22863
 
22340
22864
  // src/desktop_tab_utils.ts
22341
22865
  var DEFAULT_ASSISTANT_SHORTCUT = "CommandOrControl+Shift+Space";
@@ -22353,18 +22877,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22353
22877
  var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
22354
22878
  function DesktopTab({ config, agents, onSave }) {
22355
22879
  const current = config.desktopAssistant;
22356
- const [enabled, setEnabled] = (0, import_react20.useState)(!!current);
22357
- const [agentId, setAgentId] = (0, import_react20.useState)(current?.agentId ?? "");
22358
- const [shortcut, setShortcut] = (0, import_react20.useState)(current?.shortcut ?? "");
22359
- const [saveState, setSaveState] = (0, import_react20.useState)("idle");
22360
- const pendingSave = (0, import_react20.useRef)(null);
22361
- (0, import_react20.useEffect)(() => {
22880
+ const [enabled, setEnabled] = (0, import_react21.useState)(!!current);
22881
+ const [agentId, setAgentId] = (0, import_react21.useState)(current?.agentId ?? "");
22882
+ const [shortcut, setShortcut] = (0, import_react21.useState)(current?.shortcut ?? "");
22883
+ const [saveState, setSaveState] = (0, import_react21.useState)("idle");
22884
+ const pendingSave = (0, import_react21.useRef)(null);
22885
+ (0, import_react21.useEffect)(() => {
22362
22886
  if (saveState !== "saving" || pendingSave.current === null) return;
22363
22887
  if (desktopAssistantSignature(config.desktopAssistant) !== pendingSave.current)
22364
22888
  return;
22365
22889
  setSaveState("saved");
22366
22890
  }, [config.desktopAssistant, saveState]);
22367
- (0, import_react20.useEffect)(() => {
22891
+ (0, import_react21.useEffect)(() => {
22368
22892
  if (saveState !== "saved") return;
22369
22893
  const t = setTimeout(() => setSaveState("idle"), 2e3);
22370
22894
  return () => clearTimeout(t);
@@ -22468,7 +22992,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22468
22992
  onClose,
22469
22993
  initialTab = "providers"
22470
22994
  }) {
22471
- const [activeTab, setActiveTab] = (0, import_react21.useState)(initialTab);
22995
+ const [activeTab, setActiveTab] = (0, import_react22.useState)(initialTab);
22472
22996
  if (!settingsData) {
22473
22997
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "settings-panel settings-panel--loading", children: [
22474
22998
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("button", { className: "settings-panel__back-btn", onClick: onClose, children: [
@@ -22670,229 +23194,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
22670
23194
  // src/ProjectsTab.tsx
22671
23195
  var import_react23 = __toESM(require_react(), 1);
22672
23196
 
22673
- // src/TaskCycleView.tsx
22674
- var import_react22 = __toESM(require_react(), 1);
22675
-
22676
- // src/chat_state.ts
22677
- function closeStreamingAssistant2(items) {
22678
- const last = items[items.length - 1];
22679
- if (!last || last.kind !== "assistant" || !last.streaming) return items;
22680
- return [...items.slice(0, -1), { ...last, streaming: false }];
22681
- }
22682
- function reconstructChatItems2(messages) {
22683
- let items = [];
22684
- for (const msg of messages) {
22685
- if (msg.recap) {
22686
- items = closeStreamingAssistant2(items);
22687
- items.push({ kind: "assistant", text: msg.content, streaming: false, label: "Cycle recap" });
22688
- } else if (msg.role === "user") {
22689
- items = closeStreamingAssistant2(items);
22690
- items.push({ kind: "user", text: msg.content, attachments: msg.attachments });
22691
- } else if (msg.role === "assistant") {
22692
- items = closeStreamingAssistant2(items);
22693
- if (msg.parts && msg.parts.length > 0) {
22694
- for (const part of msg.parts) {
22695
- if (part.type === "text") {
22696
- items.push({ kind: "assistant", text: part.text, streaming: false });
22697
- } else if (part.type === "thinking" && part.text.trim().length > 0) {
22698
- items.push({ kind: "thinking", text: part.text });
22699
- } else if (part.type === "tool_use") {
22700
- items.push({
22701
- kind: "tool",
22702
- id: part.id,
22703
- name: part.name,
22704
- args: part.args,
22705
- result: null
22706
- });
22707
- }
22708
- }
22709
- } else {
22710
- items.push({ kind: "assistant", text: msg.content, streaming: false });
22711
- }
22712
- } else if (msg.role === "tool") {
22713
- const toolCallId = msg.toolCallId;
22714
- if (toolCallId) {
22715
- const idx = items.findIndex(
22716
- (it2) => it2.kind === "tool" && it2.id === toolCallId && it2.result === null
22717
- );
22718
- if (idx !== -1) {
22719
- const toolItem = items[idx];
22720
- items[idx] = { ...toolItem, result: msg.content };
22721
- } else {
22722
- items.push({
22723
- kind: "tool",
22724
- id: toolCallId,
22725
- name: "unknown_tool",
22726
- args: {},
22727
- result: msg.content
22728
- });
22729
- }
22730
- }
22731
- }
22732
- }
22733
- return closeStreamingAssistant2(items);
22734
- }
22735
- function chatReducer(state, action) {
22736
- switch (action.kind) {
22737
- case "send-user":
22738
- return {
22739
- ...state,
22740
- status: "streaming",
22741
- errorText: null,
22742
- items: [...state.items, { kind: "user", text: action.text, attachments: action.attachments }]
22743
- };
22744
- case "append-chunk": {
22745
- const last = state.items[state.items.length - 1];
22746
- if (last && last.kind === "assistant" && last.streaming) {
22747
- const updated = { ...last, text: last.text + action.text };
22748
- return { ...state, items: [...state.items.slice(0, -1), updated] };
22749
- }
22750
- return {
22751
- ...state,
22752
- items: [...state.items, { kind: "assistant", text: action.text, streaming: true }]
22753
- };
22754
- }
22755
- case "append-thinking": {
22756
- const last = state.items[state.items.length - 1];
22757
- if (last && last.kind === "thinking") {
22758
- const updated = { ...last, text: last.text + action.text };
22759
- return { ...state, items: [...state.items.slice(0, -1), updated] };
22760
- }
22761
- return {
22762
- ...state,
22763
- items: [...state.items, { kind: "thinking", text: action.text }]
22764
- };
22765
- }
22766
- case "tool-call":
22767
- return {
22768
- ...state,
22769
- items: [
22770
- ...closeStreamingAssistant2(state.items),
22771
- { kind: "tool", id: action.id, name: action.name, args: action.args, result: null }
22772
- ]
22773
- };
22774
- case "tool-result": {
22775
- const idx = state.items.findIndex(
22776
- (it2) => it2.kind === "tool" && it2.id === action.id && it2.result === null
22777
- );
22778
- if (idx < 0) return state;
22779
- const tool = state.items[idx];
22780
- const updated = { ...tool, result: action.content };
22781
- return {
22782
- ...state,
22783
- items: [...state.items.slice(0, idx), updated, ...state.items.slice(idx + 1)]
22784
- };
22785
- }
22786
- case "permission-request":
22787
- return {
22788
- ...state,
22789
- pendingConfirms: [
22790
- ...state.pendingConfirms,
22791
- { id: action.id, toolName: action.toolName, args: action.args }
22792
- ]
22793
- };
22794
- case "permission-resolved":
22795
- return {
22796
- ...state,
22797
- pendingConfirms: state.pendingConfirms.filter((p) => p.id !== action.id)
22798
- };
22799
- case "done":
22800
- return {
22801
- ...state,
22802
- status: "idle",
22803
- pendingConfirms: [],
22804
- items: closeStreamingAssistant2(state.items)
22805
- };
22806
- case "clear":
22807
- return {
22808
- ...state,
22809
- items: [],
22810
- status: "idle",
22811
- errorText: null,
22812
- pendingConfirms: [],
22813
- contextUsage: null
22814
- };
22815
- case "error":
22816
- return {
22817
- ...state,
22818
- status: "error",
22819
- errorText: action.text,
22820
- pendingConfirms: [],
22821
- items: closeStreamingAssistant2(state.items)
22822
- };
22823
- case "load-history": {
22824
- const historyItems = reconstructChatItems2(action.messages);
22825
- return {
22826
- ...state,
22827
- items: historyItems,
22828
- // A cycle opened mid-run keeps the stream indicator on until its `done`.
22829
- status: action.streaming ? "streaming" : "idle",
22830
- errorText: null,
22831
- pendingConfirms: []
22832
- };
22833
- }
22834
- case "context-usage":
22835
- return {
22836
- ...state,
22837
- contextUsage: action.usage
22838
- };
22839
- }
22840
- }
22841
- var initialChatState = {
22842
- items: [],
22843
- status: "idle",
22844
- errorText: null,
22845
- pendingConfirms: [],
22846
- contextUsage: null
22847
- };
22848
-
22849
23197
  // src/TaskCycleView.tsx
22850
23198
  var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
22851
23199
  function TaskCycleView({ item, postMessage, onBack }) {
22852
- const [chat, dispatch] = (0, import_react22.useReducer)(chatReducer, initialChatState);
22853
23200
  const { sessionId, agentId } = item;
22854
- const postRef = (0, import_react22.useRef)(postMessage);
22855
- postRef.current = postMessage;
22856
- (0, import_react22.useEffect)(() => {
22857
- function handle(event) {
22858
- const msg = event.data;
22859
- if (!msg || typeof msg !== "object" || !("type" in msg) || !("sessionId" in msg)) return;
22860
- if (msg.sessionId !== sessionId) return;
22861
- if (msg.type === "cycleLoaded") {
22862
- dispatch({ kind: "load-history", messages: msg.messages, streaming: msg.running });
22863
- return;
22864
- }
22865
- if (msg.type !== "cycleEvent") return;
22866
- const ev = msg.event;
22867
- switch (ev.type) {
22868
- case "chunk":
22869
- dispatch({ kind: "append-chunk", text: ev.text });
22870
- return;
22871
- case "thinking":
22872
- dispatch({ kind: "append-thinking", text: ev.text });
22873
- return;
22874
- case "tool_call":
22875
- dispatch({ kind: "tool-call", id: ev.id, name: ev.name, args: ev.args });
22876
- return;
22877
- case "tool_result":
22878
- dispatch({ kind: "tool-result", id: ev.id, content: ev.content });
22879
- return;
22880
- case "done":
22881
- dispatch({ kind: "done" });
22882
- postRef.current({ type: "watchCycle", agentId, sessionId });
22883
- return;
22884
- case "error":
22885
- dispatch({ kind: "error", text: ev.message });
22886
- return;
22887
- }
22888
- }
22889
- window.addEventListener("message", handle);
22890
- postRef.current({ type: "watchCycle", agentId, sessionId });
22891
- return () => {
22892
- window.removeEventListener("message", handle);
22893
- postRef.current({ type: "unwatchCycle", sessionId });
22894
- };
22895
- }, [sessionId, agentId]);
23201
+ const chat = useCycleStream(sessionId, {
23202
+ watch: () => postMessage({ type: "watchCycle", agentId, sessionId }),
23203
+ unwatch: () => postMessage({ type: "unwatchCycle", sessionId }),
23204
+ // The recap is persisted before `done`: reload the finished session from disk.
23205
+ onDone: () => postMessage({ type: "watchCycle", agentId, sessionId })
23206
+ });
22896
23207
  const running = chat.status === "streaming";
22897
23208
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { style: { flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: [
22898
23209
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("header", { className: "app__chat-header task-view__sub-header", style: { padding: "10px 14px" }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px" }, children: [