@dudko.dev/agent-web-react 0.0.18 → 0.0.20

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/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -55,27 +45,26 @@ __export(src_exports, {
55
45
  ToolApprovalPrompt: () => ToolApprovalPrompt,
56
46
  ToolCallRow: () => ToolCallRow,
57
47
  UsageBadge: () => UsageBadge,
48
+ UserNoteRow: () => UserNoteRow,
58
49
  VaultCredentialStore: () => import_agent_web4.VaultCredentialStore,
59
50
  VirtualFileSystem: () => import_agent_web4.VirtualFileSystem,
60
51
  agentStateReducer: () => agentStateReducer,
61
52
  attachmentKindOf: () => attachmentKindOf,
62
53
  attachmentRefusal: () => attachmentRefusal,
63
54
  chatTitle: () => chatTitle,
64
- claimOAuthCallback: () => claimOAuthCallback,
65
55
  createAgent: () => import_agent_web4.createAgent,
66
56
  createFileTools: () => import_agent_web4.createFileTools,
67
57
  createInitialAgentState: () => createInitialAgentState,
58
+ createRunControl: () => import_agent_web4.createRunControl,
68
59
  createSubagentTool: () => import_agent_web4.createSubagentTool,
69
60
  createWebLLMEngine: () => createWebLLMEngine,
70
61
  createWebLLMModel: () => import_agent_web4.createWebLLMModel,
71
62
  defaultLabels: () => defaultLabels,
72
63
  defineSkill: () => import_agent_web4.defineSkill,
73
64
  defineTool: () => import_agent_web4.defineTool,
74
- describeMcpResult: () => describeMcpResult,
75
65
  downscaleImage: () => downscaleImage,
76
66
  filterCommands: () => filterCommands,
77
67
  formatElapsed: () => formatElapsed,
78
- isUnauthorizedError: () => isUnauthorizedError,
79
68
  isWebGPUAvailable: () => import_agent_web4.isWebGPUAvailable,
80
69
  loadSkillFromUrl: () => import_agent_web4.loadSkillFromUrl,
81
70
  markReadOnly: () => import_agent_web4.markReadOnly,
@@ -85,9 +74,8 @@ __export(src_exports, {
85
74
  parseSkillMarkdown: () => import_agent_web4.parseSkillMarkdown,
86
75
  parseSlash: () => parseSlash,
87
76
  preloadWebLLMModel: () => import_agent_web4.preloadWebLLMModel,
88
- readCallbackParams: () => readCallbackParams,
89
77
  serveSubagentWorker: () => import_agent_web4.serveSubagentWorker,
90
- stripOAuthParams: () => stripOAuthParams,
78
+ steerIntent: () => steerIntent,
91
79
  supportsImages: () => import_agent_web4.supportsImages,
92
80
  supportsPdf: () => import_agent_web4.supportsPdf,
93
81
  unloadWebLLMModel: () => import_agent_web4.unloadWebLLMModel,
@@ -98,8 +86,6 @@ __export(src_exports, {
98
86
  useCredentials: () => useCredentials,
99
87
  useLabels: () => useLabels,
100
88
  useLocalModel: () => useLocalModel,
101
- useMcp: () => useMcp,
102
- useMcpServers: () => useMcpServers,
103
89
  useOptionalAgentContext: () => useOptionalAgentContext,
104
90
  useSpeechToText: () => useSpeechToText,
105
91
  useVirtualFiles: () => useVirtualFiles,
@@ -152,6 +138,9 @@ var createInitialAgentState = () => ({
152
138
  runMessageId: void 0,
153
139
  approvals: [],
154
140
  subagents: [],
141
+ queued: [],
142
+ notes: [],
143
+ undelivered: [],
155
144
  skills: [],
156
145
  discoveredTools: [],
157
146
  compactions: [],
@@ -176,24 +165,24 @@ var patchStep = (steps, id, fn) => steps.map((s) => s.id === id ? fn(s) : s);
176
165
  var patchApproval = (approvals, id, fn) => approvals.map((a) => a.id === id ? fn(a) : a);
177
166
  var patchSubagent = (subagents, id, fn) => subagents.map((s) => s.id === id ? fn(s) : s);
178
167
  var runningStepId = (steps) => [...steps].reverse().find((s) => s.status === "running")?.id;
179
- var applySubagentEvent = (view2, event) => {
168
+ var applySubagentEvent = (view, event) => {
180
169
  switch (event.type) {
181
170
  case "step.start":
182
171
  return {
183
- ...view2,
184
- steps: view2.steps + 1,
172
+ ...view,
173
+ steps: view.steps + 1,
185
174
  activity: `step ${event.index}/${event.total}: ${event.step.description}`
186
175
  };
187
176
  case "step.tool-call":
188
- return { ...view2, toolCalls: view2.toolCalls + 1, activity: `\u2192 ${event.name}` };
177
+ return { ...view, toolCalls: view.toolCalls + 1, activity: `\u2192 ${event.name}` };
189
178
  case "final.text-delta":
190
- return { ...view2, text: view2.text + event.delta, activity: "writing the answer" };
179
+ return { ...view, text: view.text + event.delta, activity: "writing the answer" };
191
180
  case "final":
192
- return { ...view2, text: event.text };
181
+ return { ...view, text: event.text };
193
182
  case "usage":
194
- return { ...view2, usage: addUsage(view2.usage, event.usage) };
183
+ return { ...view, usage: addUsage(view.usage, event.usage) };
195
184
  default:
196
- return view2;
185
+ return view;
197
186
  }
198
187
  };
199
188
  var finalizeAssistant = (messages, content, extra = {}) => {
@@ -255,11 +244,20 @@ var applyEvent = (state, event, ctx) => {
255
244
  planThought: state.planThought || event.plan.thought
256
245
  };
257
246
  case "plan.revised":
258
- return { ...state, plan: event.plan, replan: { mode: "revise", reason: event.reason } };
247
+ return {
248
+ ...state,
249
+ plan: event.plan,
250
+ // `replan.decision` came first: keep its "because the user spoke" flag.
251
+ replan: {
252
+ mode: "revise",
253
+ reason: event.reason,
254
+ ...state.replan?.byUser ? { byUser: true } : {}
255
+ }
256
+ };
259
257
  case "plan.step-added":
260
258
  return state;
261
259
  case "step.start": {
262
- const view2 = {
260
+ const view = {
263
261
  id: event.step.id,
264
262
  index: event.index,
265
263
  total: event.total,
@@ -270,7 +268,7 @@ var applyEvent = (state, event, ctx) => {
270
268
  status: "running",
271
269
  blocked: false
272
270
  };
273
- return { ...state, steps: [...state.steps, view2] };
271
+ return { ...state, steps: [...state.steps, view] };
274
272
  }
275
273
  case "step.reasoning-delta":
276
274
  return {
@@ -355,7 +353,27 @@ var applyEvent = (state, event, ctx) => {
355
353
  }))
356
354
  };
357
355
  case "replan.decision":
358
- return { ...state, replan: { mode: event.mode, reason: event.reason } };
356
+ return {
357
+ ...state,
358
+ replan: {
359
+ mode: event.mode,
360
+ reason: event.reason,
361
+ ...event.byUser ? { byUser: true } : {}
362
+ }
363
+ };
364
+ case "message.queued":
365
+ return state.queued.some((q) => q.id === event.id) ? state : { ...state, queued: [...state.queued, { id: event.id, text: event.text }] };
366
+ case "message.delivered": {
367
+ const anchor = event.at === "round" ? runningStepId(state.steps) : event.at === "step" ? state.steps[state.steps.length - 1]?.id : void 0;
368
+ return {
369
+ ...state,
370
+ queued: state.queued.filter((q) => q.id !== event.id),
371
+ notes: [
372
+ ...state.notes,
373
+ { id: event.id, text: event.text, at: event.at, ...anchor ? { stepId: anchor } : {} }
374
+ ]
375
+ };
376
+ }
359
377
  case "final.text-delta": {
360
378
  const finalText = state.finalText + event.delta;
361
379
  return { ...state, finalText, messages: streamAssistant(state.messages, finalText) };
@@ -425,6 +443,7 @@ var applyEvent = (state, event, ctx) => {
425
443
  name: event.name,
426
444
  task: event.task,
427
445
  status: "running",
446
+ ...event.profile ? { profile: event.profile } : {},
428
447
  stepId: runningStepId(state.steps),
429
448
  activity: "starting",
430
449
  steps: 0,
@@ -459,8 +478,8 @@ var applyEvent = (state, event, ctx) => {
459
478
  ...state,
460
479
  subagents: patchSubagent(state.subagents, event.id, (s) => ({
461
480
  ...s,
462
- status: "error",
463
- activity: "failed",
481
+ status: event.stopped ? "stopped" : "error",
482
+ activity: event.stopped ? "stopped" : "failed",
464
483
  error: event.error
465
484
  }))
466
485
  };
@@ -521,6 +540,7 @@ var syncRunMessage = (state) => {
521
540
  const patch = {};
522
541
  if (m.steps !== state.steps) patch.steps = state.steps;
523
542
  if (m.subagents !== state.subagents) patch.subagents = state.subagents;
543
+ if (state.notes.length > 0 && m.notes !== state.notes) patch.notes = state.notes;
524
544
  if (m.usage !== state.usage) patch.usage = state.usage;
525
545
  if ((m.reasoning ?? "") !== state.finalReasoning) patch.reasoning = state.finalReasoning;
526
546
  if (m.skills !== state.skills) patch.skills = state.skills;
@@ -550,6 +570,8 @@ var agentStateReducer = (state, action) => {
550
570
  const events = cap > 0 ? [...state.events, action.event].slice(-cap) : [...state.events, action.event];
551
571
  return { ...next, events };
552
572
  }
573
+ case "undelivered":
574
+ return { ...state, queued: [], undelivered: action.texts };
553
575
  case "load": {
554
576
  const maxSeq = action.messages.reduce((n, m) => {
555
577
  const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
@@ -576,6 +598,9 @@ var useAgent = (config, options = {}) => {
576
598
  const [state, dispatch] = (0, import_react.useReducer)(agentStateReducer, void 0, createInitialAgentState);
577
599
  const agentRef = (0, import_react.useRef)(void 0);
578
600
  const abortRef = (0, import_react.useRef)(void 0);
601
+ const controlRef = (0, import_react.useRef)(void 0);
602
+ const stateRef = (0, import_react.useRef)(state);
603
+ stateRef.current = state;
579
604
  const [generation, setGeneration] = (0, import_react.useState)(0);
580
605
  const configRef = (0, import_react.useRef)(config);
581
606
  configRef.current = config;
@@ -648,16 +673,21 @@ var useAgent = (config, options = {}) => {
648
673
  },
649
674
  [settleAll]
650
675
  );
676
+ const runRef = (0, import_react.useRef)(void 0);
651
677
  const run = (0, import_react.useCallback)(
652
678
  async (goal, runOptions) => {
653
679
  const agent = agentRef.current;
654
680
  if (!agent || abortRef.current) return void 0;
655
681
  const controller = new AbortController();
656
682
  abortRef.current = controller;
683
+ const control = (0, import_agent_web.createRunControl)();
684
+ controlRef.current = control;
685
+ let left = [];
657
686
  dispatch({ type: "status", status: "running" });
658
687
  try {
659
- return await agent.run(goal, {
688
+ const result = await agent.run(goal, {
660
689
  signal: controller.signal,
690
+ control,
661
691
  sessionId: sessionRef.current,
662
692
  ...runOptions?.images?.length ? { images: runOptions.images } : {},
663
693
  ...runOptions?.files?.length ? { files: runOptions.files } : {},
@@ -677,7 +707,10 @@ var useAgent = (config, options = {}) => {
677
707
  }
678
708
  }
679
709
  });
710
+ left = result.undelivered ?? [];
711
+ return result;
680
712
  } catch (err) {
713
+ left = control.pending();
681
714
  dispatch({
682
715
  type: "event",
683
716
  event: { type: "error", phase: "run", error: errMessage(err) },
@@ -686,12 +719,36 @@ var useAgent = (config, options = {}) => {
686
719
  return void 0;
687
720
  } finally {
688
721
  abortRef.current = void 0;
722
+ controlRef.current = void 0;
689
723
  settleAll({ approved: false, reason: "the run ended" });
690
724
  dispatch({ type: "status", ...buildStatusRef.current });
725
+ if (left.length > 0) {
726
+ if (!controller.signal.aborted && optionsRef.current.followUp !== false) {
727
+ dispatch({ type: "undelivered", texts: [] });
728
+ void runRef.current?.(left.join("\n\n"));
729
+ } else {
730
+ dispatch({ type: "undelivered", texts: left });
731
+ }
732
+ } else {
733
+ dispatch({ type: "undelivered", texts: [] });
734
+ }
691
735
  }
692
736
  },
693
737
  [settleAll]
694
738
  );
739
+ runRef.current = run;
740
+ const send = (0, import_react.useCallback)((text) => controlRef.current?.send(text) ?? false, []);
741
+ const stopSubagent = (0, import_react.useCallback)(
742
+ (id) => controlRef.current?.stopSubagent(id) ?? false,
743
+ []
744
+ );
745
+ const sendUndelivered = (0, import_react.useCallback)(() => {
746
+ const texts = stateRef.current.undelivered;
747
+ if (texts.length === 0) return;
748
+ dispatch({ type: "undelivered", texts: [] });
749
+ void runRef.current?.(texts.join("\n\n"));
750
+ }, []);
751
+ const discardUndelivered = (0, import_react.useCallback)(() => dispatch({ type: "undelivered", texts: [] }), []);
695
752
  const stop = (0, import_react.useCallback)(() => {
696
753
  abortRef.current?.abort();
697
754
  settleAll({ approved: false, reason: "stopped by the user" });
@@ -745,6 +802,10 @@ var useAgent = (config, options = {}) => {
745
802
  ...state,
746
803
  run,
747
804
  stop,
805
+ send,
806
+ stopSubagent,
807
+ sendUndelivered,
808
+ discardUndelivered,
748
809
  reset,
749
810
  reload,
750
811
  agent: agentRef.current,
@@ -1060,684 +1121,25 @@ var useCredentials = (store) => {
1060
1121
  return { store: resolved, setKey, removeKey, hasKey, version };
1061
1122
  };
1062
1123
 
1063
- // src/hooks/use-mcp.ts
1064
- var import_react6 = require("react");
1065
- var OAUTH_UNSUPPORTED = "The installed @dudko.dev/agent-web has no MCP OAuth support. Upgrade the core to a version exporting BrowserOAuthProvider, or use a static Authorization header.";
1066
- var PENDING_KEY = "agent-web-react:mcp:pending";
1067
- var OAUTH_KEY = "agent-web-react:mcp:oauth";
1068
- var PENDING_TTL_MS = 10 * 60 * 1e3;
1069
- var modulePromise;
1070
- var loadMcp = () => {
1071
- modulePromise ??= import("@dudko.dev/agent-web/mcp").then((m) => m).catch((err) => {
1072
- modulePromise = void 0;
1073
- throw err;
1074
- });
1075
- return modulePromise;
1076
- };
1077
- var describeMcpResult = (result) => {
1078
- if (!result) return { status: "error", error: "The connector returned no result for the server" };
1079
- if (result.connected) return { status: "connected" };
1080
- if (result.needsAuthorization) return { status: "needs-authorization" };
1081
- return { status: "error", error: result.error ?? "Could not connect to the MCP server" };
1082
- };
1083
- var OAUTH_PARAMS = ["code", "state", "error", "error_description", "iss"];
1084
- var readCallbackParams = (href) => {
1085
- const target = href ?? (typeof globalThis.location !== "undefined" ? globalThis.location.href : void 0);
1086
- if (!target) return void 0;
1087
- let url;
1088
- try {
1089
- url = new URL(target);
1090
- } catch {
1091
- return void 0;
1092
- }
1093
- const params = new URLSearchParams(url.search);
1094
- const hash = url.hash.startsWith("#") ? url.hash.slice(1) : url.hash;
1095
- const q = hash.indexOf("?");
1096
- if (q >= 0) {
1097
- for (const [k, v] of new URLSearchParams(hash.slice(q + 1))) {
1098
- if (!params.has(k)) params.set(k, v);
1099
- }
1100
- }
1101
- const code = params.get("code") ?? void 0;
1102
- const error = params.get("error") ?? void 0;
1103
- if (!code && !error) return void 0;
1104
- return {
1105
- code,
1106
- state: params.get("state") ?? void 0,
1107
- error,
1108
- errorDescription: params.get("error_description") ?? void 0
1109
- };
1110
- };
1111
- var stripOAuthParams = (href) => {
1112
- const url = new URL(href);
1113
- for (const key of OAUTH_PARAMS) url.searchParams.delete(key);
1114
- const hash = url.hash.startsWith("#") ? url.hash.slice(1) : url.hash;
1115
- const q = hash.indexOf("?");
1116
- if (q >= 0) {
1117
- const params = new URLSearchParams(hash.slice(q + 1));
1118
- for (const key of OAUTH_PARAMS) params.delete(key);
1119
- const rest = params.toString();
1120
- url.hash = rest ? `${hash.slice(0, q)}?${rest}` : hash.slice(0, q);
1121
- }
1122
- return url.toString();
1123
- };
1124
- var claimedCallbacks = /* @__PURE__ */ new Set();
1125
- var claimOAuthCallback = (callback) => {
1126
- const key = `${callback.code ?? ""}|${callback.state ?? ""}|${callback.error ?? ""}`;
1127
- if (claimedCallbacks.has(key)) return false;
1128
- claimedCallbacks.add(key);
1129
- return true;
1130
- };
1131
- var readRecord = (key) => {
1132
- try {
1133
- const raw = globalThis.localStorage?.getItem(key);
1134
- return raw ? JSON.parse(raw) : void 0;
1135
- } catch {
1136
- return void 0;
1137
- }
1138
- };
1139
- var writeRecord = (key, value) => {
1140
- try {
1141
- if (value) globalThis.localStorage?.setItem(key, JSON.stringify(value));
1142
- else globalThis.localStorage?.removeItem(key);
1143
- } catch {
1144
- }
1145
- };
1146
- var defaultRedirectUrl = () => typeof globalThis.location === "undefined" ? "" : `${globalThis.location.origin}${globalThis.location.pathname}`;
1147
- var isUnauthorizedError = (err, mod) => {
1148
- if (!(err instanceof Error)) return false;
1149
- if (mod?.UnauthorizedError && err instanceof mod.UnauthorizedError) return true;
1150
- return err.constructor?.name === "UnauthorizedError";
1151
- };
1152
- var watchAuthorization = (tools, mod, onUnauthorized) => {
1153
- const entries = Object.entries(tools).map(([name, value]) => {
1154
- const tool = value;
1155
- if (typeof tool.execute !== "function") return [name, value];
1156
- const execute = tool.execute.bind(tool);
1157
- const watched = (args, options) => {
1158
- try {
1159
- const out = execute(args, options);
1160
- if (out && typeof out.then === "function") {
1161
- return out.then(void 0, (err) => {
1162
- if (isUnauthorizedError(err, mod)) onUnauthorized();
1163
- throw err;
1164
- });
1165
- }
1166
- return out;
1167
- } catch (err) {
1168
- if (isUnauthorizedError(err, mod)) onUnauthorized();
1169
- throw err;
1170
- }
1171
- };
1172
- return [name, { ...value, execute: watched }];
1173
- });
1174
- return Object.fromEntries(entries);
1175
- };
1176
- var useMcp = (options = {}) => {
1177
- const [status, setStatus] = (0, import_react6.useState)("idle");
1178
- const [tools, setTools] = (0, import_react6.useState)(void 0);
1179
- const [catalog, setCatalog] = (0, import_react6.useState)([]);
1180
- const [error, setError] = (0, import_react6.useState)(void 0);
1181
- const [authorizationUrl, setAuthorizationUrl] = (0, import_react6.useState)(void 0);
1182
- const [oauthSupported, setOauthSupported] = (0, import_react6.useState)(void 0);
1183
- const [completingAuthorization, setCompletingAuthorization] = (0, import_react6.useState)(
1184
- () => readCallbackParams() !== void 0
1185
- );
1186
- const connectionRef = (0, import_react6.useRef)(void 0);
1187
- const providerRef = (0, import_react6.useRef)(void 0);
1188
- const epochRef = (0, import_react6.useRef)(0);
1189
- const optionsRef = (0, import_react6.useRef)(options);
1190
- optionsRef.current = options;
1191
- const closeConnection = (0, import_react6.useCallback)(async () => {
1192
- const open = connectionRef.current;
1193
- connectionRef.current = void 0;
1194
- if (open) await open.close().catch(() => {
1195
- });
1196
- }, []);
1197
- const checkOAuthSupport = (0, import_react6.useCallback)(async () => {
1198
- try {
1199
- const mod = await loadMcp();
1200
- const supported = typeof mod.BrowserOAuthProvider === "function";
1201
- setOauthSupported(supported);
1202
- return supported;
1203
- } catch {
1204
- setOauthSupported(false);
1205
- return false;
1206
- }
1207
- }, []);
1208
- const connect = (0, import_react6.useCallback)(
1209
- async (opts) => {
1210
- const epoch = ++epochRef.current;
1211
- const current = () => epochRef.current === epoch;
1212
- await closeConnection();
1213
- if (!current()) return;
1214
- setStatus("connecting");
1215
- setError(void 0);
1216
- setAuthorizationUrl(void 0);
1217
- setTools(void 0);
1218
- setCatalog([]);
1219
- try {
1220
- const mod = await loadMcp();
1221
- setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
1222
- const name = opts.name ?? "mcp";
1223
- let authProvider;
1224
- if (opts.oauth) {
1225
- if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
1226
- const oauth = typeof opts.oauth === "object" ? opts.oauth : {};
1227
- const record = {
1228
- url: opts.url,
1229
- name,
1230
- redirectUrl: oauth.redirectUrl ?? defaultRedirectUrl(),
1231
- scope: oauth.scope,
1232
- clientName: oauth.clientName ?? optionsRef.current.clientName,
1233
- startedAt: Date.now()
1234
- };
1235
- authProvider = new mod.BrowserOAuthProvider({
1236
- serverUrl: record.url,
1237
- redirectUrl: record.redirectUrl,
1238
- clientName: record.clientName,
1239
- scope: record.scope
1240
- });
1241
- providerRef.current = authProvider;
1242
- writeRecord(PENDING_KEY, record);
1243
- writeRecord(OAUTH_KEY, record);
1244
- } else {
1245
- providerRef.current = void 0;
1246
- }
1247
- const connection = await mod.connectMcpHttp(
1248
- {
1249
- [name]: {
1250
- url: opts.url,
1251
- headers: opts.oauth ? void 0 : opts.headers,
1252
- authProvider
1253
- }
1254
- },
1255
- { clientName: optionsRef.current.clientName, onLog: optionsRef.current.onLog }
1256
- );
1257
- if (!current()) {
1258
- await connection.close().catch(() => {
1259
- });
1260
- return;
1261
- }
1262
- const outcome = describeMcpResult(connection.results[0]);
1263
- if (outcome.status !== "connected") {
1264
- await connection.close().catch(() => {
1265
- });
1266
- if (outcome.status === "needs-authorization") {
1267
- const url = authProvider?.authorizationUrl;
1268
- setAuthorizationUrl(url ? String(url) : void 0);
1269
- setStatus("needs-authorization");
1270
- return;
1271
- }
1272
- throw new Error(outcome.error);
1273
- }
1274
- connectionRef.current = connection;
1275
- writeRecord(PENDING_KEY, void 0);
1276
- setTools(
1277
- watchAuthorization(connection.tools, mod, () => {
1278
- if (!current()) return;
1279
- const url = providerRef.current?.authorizationUrl;
1280
- if (url) setAuthorizationUrl(String(url));
1281
- setStatus("needs-authorization");
1282
- })
1283
- );
1284
- setCatalog(connection.catalog);
1285
- setStatus("connected");
1286
- } catch (err) {
1287
- if (!current()) return;
1288
- setError(err instanceof Error ? err.message : String(err));
1289
- setStatus("error");
1290
- }
1291
- },
1292
- [closeConnection]
1293
- );
1294
- const disconnect = (0, import_react6.useCallback)(async () => {
1295
- epochRef.current++;
1296
- await closeConnection();
1297
- setTools(void 0);
1298
- setCatalog([]);
1299
- setAuthorizationUrl(void 0);
1300
- setError(void 0);
1301
- setStatus("idle");
1302
- }, [closeConnection]);
1303
- const authorize = (0, import_react6.useCallback)(() => {
1304
- if (authorizationUrl && typeof globalThis.location !== "undefined") {
1305
- globalThis.location.href = authorizationUrl;
1306
- }
1307
- }, [authorizationUrl]);
1308
- const forgetAuthorization = (0, import_react6.useCallback)(async () => {
1309
- const record = readRecord(OAUTH_KEY);
1310
- writeRecord(PENDING_KEY, void 0);
1311
- writeRecord(OAUTH_KEY, void 0);
1312
- let provider = providerRef.current;
1313
- if (!provider && record) {
1314
- const mod = await loadMcp().catch(() => void 0);
1315
- if (mod?.BrowserOAuthProvider) {
1316
- provider = new mod.BrowserOAuthProvider({
1317
- serverUrl: record.url,
1318
- redirectUrl: record.redirectUrl,
1319
- clientName: record.clientName,
1320
- scope: record.scope
1321
- });
1322
- }
1323
- }
1324
- await provider?.reset().catch(() => {
1325
- });
1326
- providerRef.current = void 0;
1327
- await disconnect();
1328
- }, [disconnect]);
1329
- (0, import_react6.useEffect)(() => {
1330
- const callback = readCallbackParams();
1331
- if (!callback) {
1332
- setCompletingAuthorization(false);
1333
- return;
1334
- }
1335
- const pending = readRecord(PENDING_KEY);
1336
- const fresh = pending !== void 0 && (pending.startedAt === void 0 || Date.now() - pending.startedAt < PENDING_TTL_MS);
1337
- if (!pending || !fresh) {
1338
- if (pending) writeRecord(PENDING_KEY, void 0);
1339
- setCompletingAuthorization(false);
1340
- return;
1341
- }
1342
- if (!claimOAuthCallback(callback)) {
1343
- setCompletingAuthorization(false);
1344
- return;
1345
- }
1346
- if (typeof globalThis.history !== "undefined") {
1347
- globalThis.history.replaceState(null, "", stripOAuthParams(globalThis.location.href));
1348
- }
1349
- void (async () => {
1350
- try {
1351
- const mod = await loadMcp();
1352
- setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
1353
- if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
1354
- const provider = new mod.BrowserOAuthProvider({
1355
- serverUrl: pending.url,
1356
- redirectUrl: pending.redirectUrl ?? defaultRedirectUrl(),
1357
- clientName: pending.clientName,
1358
- scope: pending.scope
1359
- });
1360
- providerRef.current = provider;
1361
- await mod.finishMcpOAuth(provider, callback);
1362
- writeRecord(PENDING_KEY, void 0);
1363
- setCompletingAuthorization(false);
1364
- await connect({ url: pending.url, name: pending.name, oauth: true });
1365
- } catch (err) {
1366
- writeRecord(PENDING_KEY, void 0);
1367
- setError(err instanceof Error ? err.message : String(err));
1368
- setStatus("error");
1369
- } finally {
1370
- setCompletingAuthorization(false);
1371
- }
1372
- })();
1373
- }, [connect]);
1374
- (0, import_react6.useEffect)(
1375
- () => () => {
1376
- epochRef.current++;
1377
- void closeConnection();
1378
- },
1379
- [closeConnection]
1380
- );
1381
- return {
1382
- status,
1383
- tools,
1384
- catalog,
1385
- error,
1386
- authorizationUrl,
1387
- oauthSupported,
1388
- completingAuthorization,
1389
- connect,
1390
- disconnect,
1391
- authorize,
1392
- forgetAuthorization,
1393
- checkOAuthSupport
1394
- };
1395
- };
1396
-
1397
- // src/hooks/use-mcp-servers.ts
1398
- var import_react7 = require("react");
1399
- var DEFAULT_KEY = "agent-web-react:mcp-servers";
1400
- var sanitize = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 32) || "mcp";
1401
- var view = (s, patch = {}) => ({
1402
- name: s.name,
1403
- url: s.url,
1404
- auth: s.auth,
1405
- status: "idle",
1406
- catalog: [],
1407
- ...patch
1408
- });
1409
- var useMcpServers = (options = {}) => {
1410
- const storageKey = options.storageKey ?? DEFAULT_KEY;
1411
- const pendingKey = `${storageKey}:pending`;
1412
- const persist = options.persist !== false;
1413
- const [servers, setServers] = (0, import_react7.useState)(
1414
- () => persist ? (readRecord(storageKey) ?? []).map((s) => view(s)) : []
1415
- );
1416
- const [oauthSupported, setOauthSupported] = (0, import_react7.useState)(void 0);
1417
- const [completingAuthorization, setCompleting] = (0, import_react7.useState)(
1418
- () => readCallbackParams() !== void 0 && readRecord(pendingKey) !== void 0
1419
- );
1420
- const [toolsVersion, setToolsVersion] = (0, import_react7.useState)(0);
1421
- const liveRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
1422
- const specsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
1423
- if (specsRef.current.size === 0 && servers.length > 0) {
1424
- for (const s of servers)
1425
- specsRef.current.set(s.name, { name: s.name, url: s.url, auth: s.auth });
1426
- }
1427
- const optionsRef = (0, import_react7.useRef)(options);
1428
- optionsRef.current = options;
1429
- const unmountedRef = (0, import_react7.useRef)(false);
1430
- const saveList = (0, import_react7.useCallback)(() => {
1431
- if (!persist) return;
1432
- writeRecord(storageKey, [...specsRef.current.values()]);
1433
- }, [persist, storageKey]);
1434
- const patch = (0, import_react7.useCallback)((name, p) => {
1435
- if (unmountedRef.current) return;
1436
- setServers((list) => list.map((s) => s.name === name ? { ...s, ...p } : s));
1437
- }, []);
1438
- const live = (name) => {
1439
- let l = liveRef.current.get(name);
1440
- if (!l) {
1441
- l = { epoch: 0 };
1442
- liveRef.current.set(name, l);
1443
- }
1444
- return l;
1445
- };
1446
- const closeServer = (0, import_react7.useCallback)(async (name) => {
1447
- const l = liveRef.current.get(name);
1448
- if (!l) return;
1449
- l.epoch += 1;
1450
- const open = l.connection;
1451
- l.connection = void 0;
1452
- if (l.tools) {
1453
- l.tools = void 0;
1454
- setToolsVersion((v) => v + 1);
1455
- }
1456
- if (open) await open.close().catch(() => {
1457
- });
1458
- }, []);
1459
- const providerFor = (mod, spec) => {
1460
- if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
1461
- return new mod.BrowserOAuthProvider({
1462
- serverUrl: spec.url,
1463
- redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
1464
- clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
1465
- scope: spec.oauth?.scope
1466
- });
1467
- };
1468
- const connectServer = (0, import_react7.useCallback)(
1469
- async (name) => {
1470
- const spec = specsRef.current.get(name);
1471
- if (!spec) return;
1472
- await closeServer(name);
1473
- const l = live(name);
1474
- const epoch = ++l.epoch;
1475
- const current = () => !unmountedRef.current && l.epoch === epoch;
1476
- if (spec.auth === "bearer" && !l.token) {
1477
- patch(name, { status: "idle", error: "Enter the bearer token to connect." });
1478
- return;
1479
- }
1480
- patch(name, {
1481
- status: "connecting",
1482
- error: void 0,
1483
- authorizationUrl: void 0,
1484
- catalog: []
1485
- });
1486
- try {
1487
- const mod = await loadMcp();
1488
- setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
1489
- let provider;
1490
- if (spec.auth === "oauth") {
1491
- provider = providerFor(mod, spec);
1492
- l.provider = provider;
1493
- }
1494
- const connection = await mod.connectMcpHttp(
1495
- {
1496
- [name]: {
1497
- url: spec.url,
1498
- headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
1499
- authProvider: provider,
1500
- connectTimeoutMs: optionsRef.current.connectTimeoutMs
1501
- }
1502
- },
1503
- {
1504
- clientName: optionsRef.current.clientName,
1505
- onLog: optionsRef.current.onLog,
1506
- connectTimeoutMs: optionsRef.current.connectTimeoutMs
1507
- }
1508
- );
1509
- if (!current()) {
1510
- await connection.close().catch(() => {
1511
- });
1512
- return;
1513
- }
1514
- const outcome = describeMcpResult(connection.results[0]);
1515
- if (outcome.status !== "connected") {
1516
- await connection.close().catch(() => {
1517
- });
1518
- if (outcome.status === "needs-authorization") {
1519
- const url = provider?.authorizationUrl;
1520
- patch(name, {
1521
- status: "needs-authorization",
1522
- authorizationUrl: url ? String(url) : void 0
1523
- });
1524
- return;
1525
- }
1526
- throw new Error(outcome.error);
1527
- }
1528
- l.connection = connection;
1529
- l.tools = watchAuthorization(connection.tools, mod, () => {
1530
- if (!current()) return;
1531
- const url = l.provider?.authorizationUrl;
1532
- patch(name, {
1533
- status: "needs-authorization",
1534
- authorizationUrl: url ? String(url) : void 0
1535
- });
1536
- });
1537
- setToolsVersion((v) => v + 1);
1538
- patch(name, { status: "connected", catalog: connection.catalog });
1539
- } catch (err) {
1540
- if (!current()) return;
1541
- patch(name, { status: "error", error: err instanceof Error ? err.message : String(err) });
1542
- }
1543
- },
1544
- // eslint-disable-next-line react-hooks/exhaustive-deps
1545
- [closeServer, patch, pendingKey]
1546
- );
1547
- const add = (0, import_react7.useCallback)(
1548
- async (input) => {
1549
- let name = sanitize(input.name);
1550
- const taken = specsRef.current.get(name);
1551
- if (taken && taken.url !== input.url) {
1552
- let n = 2;
1553
- while (specsRef.current.has(`${name}_${n}`)) n += 1;
1554
- name = `${name}_${n}`;
1555
- }
1556
- const spec = {
1557
- name,
1558
- url: input.url,
1559
- auth: input.auth ?? "none",
1560
- ...input.oauth ? { oauth: input.oauth } : {}
1561
- };
1562
- specsRef.current.set(name, spec);
1563
- live(name).token = input.auth === "bearer" ? input.token : void 0;
1564
- setServers(
1565
- (list) => list.some((s) => s.name === name) ? list.map((s) => s.name === name ? view(spec) : s) : [...list, view(spec)]
1566
- );
1567
- saveList();
1568
- await connectServer(name);
1569
- return name;
1570
- },
1571
- [connectServer, saveList]
1572
- );
1573
- const remove = (0, import_react7.useCallback)(
1574
- async (name) => {
1575
- await closeServer(name);
1576
- liveRef.current.delete(name);
1577
- specsRef.current.delete(name);
1578
- saveList();
1579
- setServers((list) => list.filter((s) => s.name !== name));
1580
- },
1581
- [closeServer, saveList]
1582
- );
1583
- const reconnect = (0, import_react7.useCallback)(
1584
- async (name, token) => {
1585
- if (token !== void 0) live(name).token = token;
1586
- await connectServer(name);
1587
- },
1588
- [connectServer]
1589
- );
1590
- const authorize = (0, import_react7.useCallback)(
1591
- (name) => {
1592
- const url = servers.find((s) => s.name === name)?.authorizationUrl;
1593
- const spec = specsRef.current.get(name);
1594
- if (!url || !spec || typeof globalThis.location === "undefined") return;
1595
- const pending = {
1596
- name,
1597
- url: spec.url,
1598
- redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
1599
- scope: spec.oauth?.scope,
1600
- clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
1601
- startedAt: Date.now()
1602
- };
1603
- writeRecord(pendingKey, pending);
1604
- globalThis.location.href = url;
1605
- },
1606
- [servers, pendingKey]
1607
- );
1608
- const forgetAuthorization = (0, import_react7.useCallback)(
1609
- async (name) => {
1610
- const spec = specsRef.current.get(name);
1611
- const l = liveRef.current.get(name);
1612
- let provider = l?.provider;
1613
- if (!provider && spec?.auth === "oauth") {
1614
- const mod = await loadMcp().catch(() => void 0);
1615
- if (mod?.BrowserOAuthProvider) provider = providerFor(mod, spec);
1616
- }
1617
- await provider?.reset().catch(() => {
1618
- });
1619
- if (l) l.provider = void 0;
1620
- const pending = readRecord(pendingKey);
1621
- if (pending?.name === name) writeRecord(pendingKey, void 0);
1622
- await closeServer(name);
1623
- patch(name, { status: "idle", authorizationUrl: void 0, catalog: [], error: void 0 });
1624
- },
1625
- // eslint-disable-next-line react-hooks/exhaustive-deps
1626
- [closeServer, patch, pendingKey]
1627
- );
1628
- const checkOAuthSupport = (0, import_react7.useCallback)(async () => {
1629
- try {
1630
- const mod = await loadMcp();
1631
- const supported = typeof mod.BrowserOAuthProvider === "function";
1632
- setOauthSupported(supported);
1633
- return supported;
1634
- } catch {
1635
- setOauthSupported(false);
1636
- return false;
1637
- }
1638
- }, []);
1639
- (0, import_react7.useEffect)(() => {
1640
- unmountedRef.current = false;
1641
- const callback = readCallbackParams();
1642
- const pending = readRecord(pendingKey);
1643
- const fresh = pending !== void 0 && Date.now() - pending.startedAt < PENDING_TTL_MS;
1644
- const ours = Boolean(callback && pending && fresh && claimOAuthCallback(callback));
1645
- if (callback && pending && !fresh) writeRecord(pendingKey, void 0);
1646
- if (ours && typeof globalThis.history !== "undefined") {
1647
- globalThis.history.replaceState(null, "", stripOAuthParams(globalThis.location.href));
1648
- }
1649
- const autoConnect = optionsRef.current.autoConnect !== false;
1650
- void (async () => {
1651
- if (ours && pending && callback) {
1652
- try {
1653
- const mod = await loadMcp();
1654
- setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
1655
- if (!mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
1656
- const spec = specsRef.current.get(pending.name) ?? {
1657
- name: pending.name,
1658
- url: pending.url,
1659
- auth: "oauth"
1660
- };
1661
- if (!specsRef.current.has(spec.name)) {
1662
- specsRef.current.set(spec.name, spec);
1663
- setServers((list) => [...list, view(spec)]);
1664
- saveList();
1665
- }
1666
- const provider = providerFor(mod, {
1667
- ...spec,
1668
- oauth: {
1669
- redirectUrl: pending.redirectUrl,
1670
- scope: pending.scope,
1671
- clientName: pending.clientName
1672
- }
1673
- });
1674
- live(spec.name).provider = provider;
1675
- await mod.finishMcpOAuth(provider, callback);
1676
- writeRecord(pendingKey, void 0);
1677
- } catch (err) {
1678
- writeRecord(pendingKey, void 0);
1679
- patch(pending.name, {
1680
- status: "error",
1681
- error: err instanceof Error ? err.message : String(err)
1682
- });
1683
- }
1684
- }
1685
- setCompleting(false);
1686
- if (autoConnect || ours) {
1687
- await Promise.all(
1688
- [...specsRef.current.keys()].filter((name) => autoConnect || name === pending?.name).map((name) => connectServer(name))
1689
- );
1690
- }
1691
- })();
1692
- return () => {
1693
- unmountedRef.current = true;
1694
- for (const name of liveRef.current.keys()) void closeServer(name);
1695
- };
1696
- }, []);
1697
- const tools = (0, import_react7.useMemo)(() => {
1698
- const merged = {};
1699
- for (const l of liveRef.current.values()) if (l.tools) Object.assign(merged, l.tools);
1700
- return merged;
1701
- }, [toolsVersion]);
1702
- const catalog = (0, import_react7.useMemo)(
1703
- () => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
1704
- [servers]
1705
- );
1706
- return {
1707
- servers,
1708
- tools,
1709
- catalog,
1710
- connectedCount: servers.filter((s) => s.status === "connected").length,
1711
- completingAuthorization,
1712
- oauthSupported,
1713
- checkOAuthSupport,
1714
- add,
1715
- remove,
1716
- reconnect,
1717
- authorize,
1718
- forgetAuthorization
1719
- };
1720
- };
1721
-
1722
1124
  // src/hooks/use-webllm-model.ts
1723
1125
  var import_agent_web3 = require("@dudko.dev/agent-web");
1724
1126
 
1725
1127
  // src/hooks/use-local-model.ts
1726
- var import_react8 = require("react");
1128
+ var import_react6 = require("react");
1727
1129
  var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
1728
1130
  var useLocalModel = (modelId, engine, options) => {
1729
- const [loaded, setLoaded] = (0, import_react8.useState)(void 0);
1730
- const [pending, setPending] = (0, import_react8.useState)();
1731
- const [failure, setFailure] = (0, import_react8.useState)();
1732
- const engineRef = (0, import_react8.useRef)(engine);
1131
+ const [loaded, setLoaded] = (0, import_react6.useState)(void 0);
1132
+ const [pending, setPending] = (0, import_react6.useState)();
1133
+ const [failure, setFailure] = (0, import_react6.useState)();
1134
+ const engineRef = (0, import_react6.useRef)(engine);
1733
1135
  engineRef.current = engine;
1734
- const loadedRef = (0, import_react8.useRef)(void 0);
1735
- const inflightRef = (0, import_react8.useRef)(
1136
+ const loadedRef = (0, import_react6.useRef)(void 0);
1137
+ const inflightRef = (0, import_react6.useRef)(
1736
1138
  void 0
1737
1139
  );
1738
1140
  const windowTokens = options?.contextWindowTokens;
1739
1141
  const key = keyOf(modelId, windowTokens);
1740
- const seqRef = (0, import_react8.useRef)(0);
1142
+ const seqRef = (0, import_react6.useRef)(0);
1741
1143
  const setHeld = (next) => {
1742
1144
  loadedRef.current = next;
1743
1145
  setLoaded(next);
@@ -1748,7 +1150,7 @@ var useLocalModel = (modelId, engine, options) => {
1748
1150
  } catch {
1749
1151
  }
1750
1152
  };
1751
- const load = (0, import_react8.useCallback)(() => {
1153
+ const load = (0, import_react6.useCallback)(() => {
1752
1154
  const id = modelId;
1753
1155
  if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
1754
1156
  if (inflightRef.current?.key === key) return inflightRef.current.promise;
@@ -1800,7 +1202,7 @@ var useLocalModel = (modelId, engine, options) => {
1800
1202
  inflightRef.current = { key, promise };
1801
1203
  return promise;
1802
1204
  }, [modelId, key]);
1803
- const unload = (0, import_react8.useCallback)(async () => {
1205
+ const unload = (0, import_react6.useCallback)(async () => {
1804
1206
  seqRef.current++;
1805
1207
  inflightRef.current = void 0;
1806
1208
  setPending(void 0);
@@ -1862,13 +1264,20 @@ var createWebLLMEngine = (options) => {
1862
1264
  };
1863
1265
 
1864
1266
  // src/labels.tsx
1865
- var import_react9 = require("react");
1267
+ var import_react7 = require("react");
1866
1268
 
1867
1269
  // src/composer.ts
1868
1270
  var parseSlash = (text) => {
1869
1271
  const m = /^\/([\w-]*)(?:\s+([\s\S]*))?$/.exec(text.trimStart());
1870
1272
  return m ? { name: m[1].toLowerCase(), args: (m[2] ?? "").trim() } : void 0;
1871
1273
  };
1274
+ var steerIntent = (input) => {
1275
+ if (!input.busy) return "idle";
1276
+ if (!input.steering) return "ignore";
1277
+ if (!input.raw && !input.hasAttachments) return "ignore";
1278
+ if (parseSlash(input.raw)) return "ignore";
1279
+ return input.hasAttachments ? "attachments" : "steer";
1280
+ };
1872
1281
  var filterCommands = (commands, query) => {
1873
1282
  const q = query.toLowerCase();
1874
1283
  if (!q) return commands;
@@ -2066,6 +1475,20 @@ var defaultLabels = {
2066
1475
  consentWaiting: "waiting for your consent",
2067
1476
  consentAllowed: "allowed",
2068
1477
  consentDenied: (reason) => `denied${reason ? ` \u2014 ${reason}` : ""}`,
1478
+ placeholderBusy: "Tell the agent something while it works\u2026",
1479
+ steer: "Send to the agent",
1480
+ noAttachmentsWhileBusy: "Files can\u2019t be added while the agent is working \u2014 send them with your next message.",
1481
+ queuedWaiting: "waiting for the agent\u2019s next step",
1482
+ noteAt: {
1483
+ round: "you said, between tool calls",
1484
+ step: "you said, after this step",
1485
+ final: "you said, before the answer"
1486
+ },
1487
+ undelivered: (n) => `Not delivered (${plural(n, "message", "messages")})`,
1488
+ sendUndelivered: "Send now",
1489
+ discardUndelivered: "Discard",
1490
+ stopSubagent: "Stop this subagent",
1491
+ subagentStopped: "stopped",
2069
1492
  failed: "failed",
2070
1493
  toolCostTitle: "Estimated tokens of the arguments and of the result fed back to the model (chars / 4), and the call's duration"
2071
1494
  };
@@ -2074,7 +1497,8 @@ var NESTED = [
2074
1497
  "modes",
2075
1498
  "commandGroups",
2076
1499
  "commandDescriptions",
2077
- "thinkingLevels"
1500
+ "thinkingLevels",
1501
+ "noteAt"
2078
1502
  ];
2079
1503
  var mergeLabels = (base2, over) => {
2080
1504
  if (!over) return base2;
@@ -2084,15 +1508,15 @@ var mergeLabels = (base2, over) => {
2084
1508
  }
2085
1509
  return out;
2086
1510
  };
2087
- var LabelsContext = (0, import_react9.createContext)(defaultLabels);
1511
+ var LabelsContext = (0, import_react7.createContext)(defaultLabels);
2088
1512
  var AgentLabelsProvider = ({ labels, children }) => {
2089
- const parent = (0, import_react9.useContext)(LabelsContext);
2090
- const value = (0, import_react9.useMemo)(() => mergeLabels(parent, labels), [parent, labels]);
1513
+ const parent = (0, import_react7.useContext)(LabelsContext);
1514
+ const value = (0, import_react7.useMemo)(() => mergeLabels(parent, labels), [parent, labels]);
2091
1515
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelsContext.Provider, { value, children });
2092
1516
  };
2093
1517
  var useLabels = (over) => {
2094
- const ctx = (0, import_react9.useContext)(LabelsContext);
2095
- return (0, import_react9.useMemo)(() => mergeLabels(ctx, over), [ctx, over]);
1518
+ const ctx = (0, import_react7.useContext)(LabelsContext);
1519
+ return (0, import_react7.useMemo)(() => mergeLabels(ctx, over), [ctx, over]);
2096
1520
  };
2097
1521
 
2098
1522
  // src/image-resize.ts
@@ -2145,25 +1569,25 @@ var downscaleImage = async (file, opts = {}) => {
2145
1569
  };
2146
1570
 
2147
1571
  // src/context.tsx
2148
- var import_react10 = require("react");
1572
+ var import_react8 = require("react");
2149
1573
  var import_jsx_runtime2 = require("react/jsx-runtime");
2150
- var AgentContext = (0, import_react10.createContext)(null);
1574
+ var AgentContext = (0, import_react8.createContext)(null);
2151
1575
  var AgentProvider = ({ config, children, ...options }) => {
2152
1576
  const agent = useAgent(config, options);
2153
1577
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AgentContext.Provider, { value: agent, children });
2154
1578
  };
2155
1579
  var useAgentContext = () => {
2156
- const ctx = (0, import_react10.useContext)(AgentContext);
1580
+ const ctx = (0, import_react8.useContext)(AgentContext);
2157
1581
  if (!ctx) throw new Error("useAgentContext must be used within an <AgentProvider>");
2158
1582
  return ctx;
2159
1583
  };
2160
- var useOptionalAgentContext = () => (0, import_react10.useContext)(AgentContext);
1584
+ var useOptionalAgentContext = () => (0, import_react8.useContext)(AgentContext);
2161
1585
 
2162
1586
  // src/components/AgentChat.tsx
2163
- var import_react15 = require("react");
1587
+ var import_react13 = require("react");
2164
1588
 
2165
1589
  // src/components/AgentComposer.tsx
2166
- var import_react11 = require("react");
1590
+ var import_react9 = require("react");
2167
1591
 
2168
1592
  // src/components/icons.tsx
2169
1593
  var import_jsx_runtime3 = require("react/jsx-runtime");
@@ -2242,9 +1666,9 @@ var thinkingDefaults = (l) => [
2242
1666
  var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
2243
1667
  var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EyeIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ShieldIcon, { size: 14 });
2244
1668
  var attachSeq = 0;
2245
- var useIsoLayoutEffect = typeof window === "undefined" ? import_react11.useEffect : import_react11.useLayoutEffect;
1669
+ var useIsoLayoutEffect = typeof window === "undefined" ? import_react9.useEffect : import_react9.useLayoutEffect;
2246
1670
  var useMenuPlacement = (open, anchor, align) => {
2247
- const [style, setStyle] = (0, import_react11.useState)();
1671
+ const [style, setStyle] = (0, import_react9.useState)();
2248
1672
  useIsoLayoutEffect(() => {
2249
1673
  if (!open) return;
2250
1674
  const place = () => {
@@ -2309,6 +1733,8 @@ var AgentComposer = ({
2309
1733
  showAgents = true,
2310
1734
  showApprovalMode = true,
2311
1735
  showNotices = true,
1736
+ steering = true,
1737
+ showQueued = true,
2312
1738
  compactWidth = 460,
2313
1739
  toolbarExtra,
2314
1740
  toolbarEnd,
@@ -2319,19 +1745,19 @@ var AgentComposer = ({
2319
1745
  const L = useLabels(labelsOverride);
2320
1746
  const MODE_CHIP = L.modes;
2321
1747
  const DEFAULT_THINKING = thinkingDefaults(L);
2322
- const [text, setText] = (0, import_react11.useState)("");
2323
- const [pending, setPending] = (0, import_react11.useState)([]);
2324
- const [menu, setMenu] = (0, import_react11.useState)(void 0);
2325
- const [active, setActive] = (0, import_react11.useState)(0);
2326
- const [dismissed, setDismissed] = (0, import_react11.useState)(() => /* @__PURE__ */ new Set());
2327
- const [attachError, setAttachError] = (0, import_react11.useState)();
2328
- const [dragging, setDragging] = (0, import_react11.useState)(false);
2329
- const rootRef = (0, import_react11.useRef)(null);
2330
- const modelRef = (0, import_react11.useRef)(null);
2331
- const modeRef = (0, import_react11.useRef)(null);
2332
- const [dropRect, setDropRect] = (0, import_react11.useState)();
2333
- const [compactBar, setCompactBar] = (0, import_react11.useState)(false);
2334
- (0, import_react11.useEffect)(() => {
1748
+ const [text, setText] = (0, import_react9.useState)("");
1749
+ const [pending, setPending] = (0, import_react9.useState)([]);
1750
+ const [menu, setMenu] = (0, import_react9.useState)(void 0);
1751
+ const [active, setActive] = (0, import_react9.useState)(0);
1752
+ const [dismissed, setDismissed] = (0, import_react9.useState)(() => /* @__PURE__ */ new Set());
1753
+ const [attachError, setAttachError] = (0, import_react9.useState)();
1754
+ const [dragging, setDragging] = (0, import_react9.useState)(false);
1755
+ const rootRef = (0, import_react9.useRef)(null);
1756
+ const modelRef = (0, import_react9.useRef)(null);
1757
+ const modeRef = (0, import_react9.useRef)(null);
1758
+ const [dropRect, setDropRect] = (0, import_react9.useState)();
1759
+ const [compactBar, setCompactBar] = (0, import_react9.useState)(false);
1760
+ (0, import_react9.useEffect)(() => {
2335
1761
  const el = rootRef.current;
2336
1762
  if (!el || typeof ResizeObserver === "undefined") return;
2337
1763
  const ro = new ResizeObserver(
@@ -2340,8 +1766,8 @@ var AgentComposer = ({
2340
1766
  ro.observe(el);
2341
1767
  return () => ro.disconnect();
2342
1768
  }, [compactWidth]);
2343
- const fileRef = (0, import_react11.useRef)(null);
2344
- const inputRef = (0, import_react11.useRef)(null);
1769
+ const fileRef = (0, import_react9.useRef)(null);
1770
+ const inputRef = (0, import_react9.useRef)(null);
2345
1771
  const busy = agent.isRunning;
2346
1772
  const ready = agent.isReady && !disabled;
2347
1773
  const caps = agent.agent?.capabilities;
@@ -2350,10 +1776,10 @@ var AgentComposer = ({
2350
1776
  onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
2351
1777
  });
2352
1778
  const showMic = speech !== false && stt.supported;
2353
- const [startedAt, setStartedAt] = (0, import_react11.useState)();
2354
- const [now, setNow] = (0, import_react11.useState)(() => Date.now());
2355
- const [lastElapsed, setLastElapsed] = (0, import_react11.useState)();
2356
- (0, import_react11.useEffect)(() => {
1779
+ const [startedAt, setStartedAt] = (0, import_react9.useState)();
1780
+ const [now, setNow] = (0, import_react9.useState)(() => Date.now());
1781
+ const [lastElapsed, setLastElapsed] = (0, import_react9.useState)();
1782
+ (0, import_react9.useEffect)(() => {
2357
1783
  if (!busy) {
2358
1784
  if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
2359
1785
  setStartedAt(void 0);
@@ -2366,7 +1792,7 @@ var AgentComposer = ({
2366
1792
  return () => clearInterval(id);
2367
1793
  }, [busy]);
2368
1794
  const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
2369
- const allCommands = (0, import_react11.useMemo)(() => {
1795
+ const allCommands = (0, import_react9.useMemo)(() => {
2370
1796
  const out = [];
2371
1797
  if (builtinCommands) {
2372
1798
  out.push(
@@ -2446,8 +1872,8 @@ var AgentComposer = ({
2446
1872
  const commandsStyle = useMenuPlacement(paletteOpen, rootRef, "stretch");
2447
1873
  const modelStyle = useMenuPlacement(menu === "model", modelRef, "left");
2448
1874
  const modeStyle = useMenuPlacement(menu === "mode", modeRef, "right");
2449
- (0, import_react11.useEffect)(() => setActive(0), [text, menu]);
2450
- (0, import_react11.useEffect)(() => {
1875
+ (0, import_react9.useEffect)(() => setActive(0), [text, menu]);
1876
+ (0, import_react9.useEffect)(() => {
2451
1877
  if (!menu) return;
2452
1878
  const onDown = (e) => {
2453
1879
  if (!rootRef.current?.contains(e.target)) setMenu(void 0);
@@ -2540,9 +1966,9 @@ var AgentComposer = ({
2540
1966
  e.preventDefault();
2541
1967
  void addFiles(pasted);
2542
1968
  };
2543
- const addFilesRef = (0, import_react11.useRef)(addFiles);
1969
+ const addFilesRef = (0, import_react9.useRef)(addFiles);
2544
1970
  addFilesRef.current = addFiles;
2545
- (0, import_react11.useEffect)(() => {
1971
+ (0, import_react9.useEffect)(() => {
2546
1972
  if (attachments === false) return;
2547
1973
  const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
2548
1974
  if (!target) return;
@@ -2586,7 +2012,17 @@ var AgentComposer = ({
2586
2012
  }, [attachments, dropZone]);
2587
2013
  const submit = () => {
2588
2014
  const raw = text.trim();
2589
- if (busy || !ready) return;
2015
+ const intent = steerIntent({ raw, busy, steering, hasAttachments: pending.length > 0 });
2016
+ if (intent === "steer") {
2017
+ if (agent.send(raw)) setText("");
2018
+ return;
2019
+ }
2020
+ if (intent === "attachments") {
2021
+ setAttachError(L.noAttachmentsWhileBusy);
2022
+ return;
2023
+ }
2024
+ if (intent === "ignore") return;
2025
+ if (!ready) return;
2590
2026
  const parsed = parseSlash(raw);
2591
2027
  if (parsed) {
2592
2028
  const cmd = allCommands.find((c) => c.name === parsed.name);
@@ -2684,6 +2120,24 @@ var AgentComposer = ({
2684
2120
  const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
2685
2121
  const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
2686
2122
  const canSend = ready && (text.trim().length > 0 || pending.length > 0);
2123
+ const canSteer = busy && steering && text.trim().length > 0;
2124
+ const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-queued", children: [
2125
+ agent.queued.map((q) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-queued__item", role: "status", children: [
2126
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ClockIcon, { size: 13, className: "awr-queued__icon" }),
2127
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-queued__text", title: q.text, children: q.text }),
2128
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-queued__state", children: L.queuedWaiting })
2129
+ ] }, q.id)),
2130
+ agent.undelivered.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-queued__item awr-queued__item--undelivered", role: "status", children: [
2131
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertIcon, { size: 13, className: "awr-queued__icon" }),
2132
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "awr-queued__text", title: agent.undelivered.join("\n\n"), children: [
2133
+ L.undelivered(agent.undelivered.length),
2134
+ ": ",
2135
+ agent.undelivered.join(" \xB7 ")
2136
+ ] }),
2137
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "awr-linkbtn", onClick: agent.sendUndelivered, children: L.sendUndelivered }),
2138
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "awr-linkbtn", onClick: agent.discardUndelivered, children: L.discardUndelivered })
2139
+ ] })
2140
+ ] }) : null;
2687
2141
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2688
2142
  "div",
2689
2143
  {
@@ -2696,6 +2150,7 @@ var AgentComposer = ({
2696
2150
  ref: rootRef,
2697
2151
  children: [
2698
2152
  dragging && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-dropnote", style: dropRect, "aria-hidden": "true", children: L.dropHint }),
2153
+ queuedStrip,
2699
2154
  notices.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-notices", children: notices.map((n) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `awr-notice awr-notice--${n.tone}`, role: "status", children: [
2700
2155
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: n.text }),
2701
2156
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -2768,7 +2223,7 @@ var AgentComposer = ({
2768
2223
  onChange: (e) => setText(e.target.value),
2769
2224
  onKeyDown,
2770
2225
  onPaste,
2771
- placeholder: stt.listening ? L.listening : placeholder ?? L.placeholder,
2226
+ placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
2772
2227
  disabled,
2773
2228
  rows: 2,
2774
2229
  "aria-label": L.message
@@ -2945,6 +2400,7 @@ var AgentComposer = ({
2945
2400
  ))
2946
2401
  ] })
2947
2402
  ] }),
2403
+ canSteer && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "awr-sendbtn", onClick: submit, "aria-label": L.steer, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SendIcon, { size: 16 }) }),
2948
2404
  busy ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2949
2405
  "button",
2950
2406
  {
@@ -2972,7 +2428,7 @@ var AgentComposer = ({
2972
2428
  };
2973
2429
 
2974
2430
  // src/components/ChatHistoryList.tsx
2975
- var import_react12 = require("react");
2431
+ var import_react10 = require("react");
2976
2432
  var import_jsx_runtime5 = require("react/jsx-runtime");
2977
2433
  var defaultTime = (ms) => {
2978
2434
  const d = new Date(ms);
@@ -3042,7 +2498,7 @@ var ChatHistoryList = ({
3042
2498
  }
3043
2499
  )
3044
2500
  ] }, c.id);
3045
- return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react12.Fragment, { children: renderChat(c, active, row) }, c.id) : row;
2501
+ return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react10.Fragment, { children: renderChat(c, active, row) }, c.id) : row;
3046
2502
  }) })
3047
2503
  ] });
3048
2504
  };
@@ -3166,7 +2622,7 @@ var ContextMeter = ({
3166
2622
  };
3167
2623
 
3168
2624
  // src/components/FilesPanel.tsx
3169
- var import_react13 = require("react");
2625
+ var import_react11 = require("react");
3170
2626
  var import_jsx_runtime7 = require("react/jsx-runtime");
3171
2627
  var PREVIEW_CHARS = 2e4;
3172
2628
  var FilesPanel = ({
@@ -3183,9 +2639,9 @@ var FilesPanel = ({
3183
2639
  }) => {
3184
2640
  const L = useLabels(labels);
3185
2641
  const fs = useVirtualFiles(vfs, prefix);
3186
- const [preview, setPreview] = (0, import_react13.useState)();
3187
- const inputRef = (0, import_react13.useRef)(null);
3188
- (0, import_react13.useEffect)(() => {
2642
+ const [preview, setPreview] = (0, import_react11.useState)();
2643
+ const inputRef = (0, import_react11.useRef)(null);
2644
+ (0, import_react11.useEffect)(() => {
3189
2645
  if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
3190
2646
  }, [fs.files, preview]);
3191
2647
  const open = async (f) => {
@@ -3286,7 +2742,7 @@ var FilesPanel = ({
3286
2742
  },
3287
2743
  f.path
3288
2744
  );
3289
- return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react13.Fragment, { children: renderFile(f, row) }, f.path) : row;
2745
+ return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react11.Fragment, { children: renderFile(f, row) }, f.path) : row;
3290
2746
  }) }),
3291
2747
  preview && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "awr-filepreview", children: preview.kind === "image" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: preview.src, alt: preview.path }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("pre", { children: preview.text.length > PREVIEW_CHARS ? `${preview.text.slice(0, PREVIEW_CHARS)}
3292
2748
  \u2026` : preview.text }) })
@@ -3294,7 +2750,7 @@ var FilesPanel = ({
3294
2750
  };
3295
2751
 
3296
2752
  // src/components/StepList.tsx
3297
- var import_react14 = require("react");
2753
+ var import_react12 = require("react");
3298
2754
  var import_jsx_runtime8 = require("react/jsx-runtime");
3299
2755
  var ToolCallRow = ({ call, showUsage = true, labels }) => {
3300
2756
  const L = useLabels(labels);
@@ -3319,6 +2775,7 @@ var ToolCallRow = ({ call, showUsage = true, labels }) => {
3319
2775
  };
3320
2776
  var SubagentRow = ({
3321
2777
  sub,
2778
+ onStop,
3322
2779
  labels
3323
2780
  }) => {
3324
2781
  const L = useLabels(labels);
@@ -3326,10 +2783,33 @@ var SubagentRow = ({
3326
2783
  /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-subagent__head", children: [
3327
2784
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BotIcon, { size: 13, className: "awr-subagent__icon" }),
3328
2785
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-subagent__name", children: sub.name }),
2786
+ sub.profile && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-subagent__profile", children: sub.profile }),
3329
2787
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-subagent__task", title: sub.task, children: previewValue(sub.task, 90) }),
3330
- sub.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpinnerIcon, { size: 12, className: "awr-tool__spin" })
2788
+ sub.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpinnerIcon, { size: 12, className: "awr-tool__spin" }),
2789
+ sub.status === "running" && onStop && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2790
+ "button",
2791
+ {
2792
+ type: "button",
2793
+ className: "awr-iconbtn awr-subagent__stop",
2794
+ "aria-label": L.stopSubagent,
2795
+ title: L.stopSubagent,
2796
+ onClick: () => onStop(sub.id),
2797
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(StopIcon, { size: 12 })
2798
+ }
2799
+ )
3331
2800
  ] }),
3332
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "awr-subagent__activity", children: sub.status === "error" ? sub.error : sub.status === "done" ? previewValue(sub.text, 160) : `${sub.activity}${sub.toolCalls ? ` \xB7 ${L.toolCalls(sub.toolCalls)}` : ""}` })
2801
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "awr-subagent__activity", children: sub.status === "error" ? sub.error : sub.status === "stopped" ? L.subagentStopped : sub.status === "done" ? previewValue(sub.text, 160) : `${sub.activity}${sub.toolCalls ? ` \xB7 ${L.toolCalls(sub.toolCalls)}` : ""}` })
2802
+ ] });
2803
+ };
2804
+ var UserNoteRow = ({
2805
+ note,
2806
+ labels
2807
+ }) => {
2808
+ const L = useLabels(labels);
2809
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-note awr-note--${note.at}`, children: [
2810
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SendIcon, { size: 12, className: "awr-note__icon" }),
2811
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-note__where", children: L.noteAt[note.at] }),
2812
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("q", { className: "awr-note__text", children: note.text })
3333
2813
  ] });
3334
2814
  };
3335
2815
  var decisionLabel = (a, L) => a.status === "pending" ? L.consentWaiting : a.status === "approved" ? L.consentAllowed : L.consentDenied(a.reason);
@@ -3337,6 +2817,8 @@ var StepItem = ({
3337
2817
  step,
3338
2818
  subagents,
3339
2819
  approvals,
2820
+ notes,
2821
+ onStopSubagent,
3340
2822
  showToolCalls,
3341
2823
  showUsage,
3342
2824
  showThoughts,
@@ -3363,20 +2845,24 @@ var StepItem = ({
3363
2845
  step.text.trim() && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-step__text", children: step.text.trim() }),
3364
2846
  showToolCalls && step.toolCalls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-step__tools", children: step.toolCalls.map((call, i) => {
3365
2847
  const row = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ToolCallRow, { call, showUsage }, i);
3366
- return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react14.Fragment, { children: renderToolCall(call, row) }, i) : row;
2848
+ return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react12.Fragment, { children: renderToolCall(call, row) }, i) : row;
3367
2849
  }) }),
3368
2850
  approvals.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-step__tools", children: approvals.map((a) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-tool awr-tool__row awr-tool--approval-${a.status}`, children: [
3369
2851
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ShieldIcon, { size: 13, className: "awr-tool__icon" }),
3370
2852
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("code", { className: "awr-tool__name", children: a.name }),
3371
2853
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-tool__args", children: decisionLabel(a, L) })
3372
2854
  ] }, a.id)) }),
3373
- subagents.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-subagents", children: subagents.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SubagentRow, { sub }, sub.id)) }),
2855
+ subagents.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-subagents", children: subagents.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SubagentRow, { sub, onStop: onStopSubagent }, sub.id)) }),
2856
+ notes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-notes", children: notes.map((n) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(UserNoteRow, { note: n }, n.id)) }),
3374
2857
  step.blocked && step.summary && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-step__blocked", children: step.summary })
3375
2858
  ] });
3376
2859
  var StepList = ({
3377
2860
  steps,
3378
2861
  subagents = [],
3379
2862
  approvals = [],
2863
+ notes = [],
2864
+ showNotes = true,
2865
+ onStopSubagent,
3380
2866
  showToolCalls = true,
3381
2867
  showUsage = true,
3382
2868
  showThoughts = true,
@@ -3386,20 +2872,27 @@ var StepList = ({
3386
2872
  }) => {
3387
2873
  const L = useLabels(labels);
3388
2874
  if (steps.length === 0) return null;
3389
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ol", { className: ["awr-steps", className].filter(Boolean).join(" "), children: steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3390
- StepItem,
3391
- {
3392
- step,
3393
- subagents: subagents.filter((s) => s.stepId === step.id),
3394
- approvals: approvals.filter((a) => a.stepId === step.id && a.status !== "pending"),
3395
- showToolCalls,
3396
- showUsage,
3397
- showThoughts,
3398
- renderToolCall,
3399
- L
3400
- },
3401
- step.id
3402
- )) });
2875
+ const known = new Set(steps.map((s) => s.id));
2876
+ const atEnd = showNotes ? notes.filter((n) => !n.stepId || !known.has(n.stepId)) : [];
2877
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("ol", { className: ["awr-steps", className].filter(Boolean).join(" "), children: [
2878
+ steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2879
+ StepItem,
2880
+ {
2881
+ step,
2882
+ subagents: subagents.filter((s) => s.stepId === step.id),
2883
+ approvals: approvals.filter((a) => a.stepId === step.id && a.status !== "pending"),
2884
+ notes: showNotes ? notes.filter((n) => n.stepId === step.id) : [],
2885
+ onStopSubagent,
2886
+ showToolCalls,
2887
+ showUsage,
2888
+ showThoughts,
2889
+ renderToolCall,
2890
+ L
2891
+ },
2892
+ step.id
2893
+ )),
2894
+ atEnd.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { className: "awr-step awr-step--notes", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-notes", children: atEnd.map((n) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(UserNoteRow, { note: n }, n.id)) }) })
2895
+ ] });
3403
2896
  };
3404
2897
 
3405
2898
  // src/components/MessageList.tsx
@@ -3435,6 +2928,8 @@ var MessageList = ({
3435
2928
  showToolCalls = true,
3436
2929
  showUsage = true,
3437
2930
  showThoughts = true,
2931
+ showNotes = true,
2932
+ onStopSubagent,
3438
2933
  activityOpen = false,
3439
2934
  liveExtra,
3440
2935
  renderContent,
@@ -3466,6 +2961,9 @@ var MessageList = ({
3466
2961
  steps,
3467
2962
  subagents: m.subagents,
3468
2963
  approvals: m.approvals,
2964
+ notes: m.notes,
2965
+ showNotes,
2966
+ onStopSubagent: m.pending ? onStopSubagent : void 0,
3469
2967
  showToolCalls,
3470
2968
  showUsage,
3471
2969
  showThoughts,
@@ -3607,6 +3105,8 @@ var AgentChatInner = ({
3607
3105
  showToolCalls = true,
3608
3106
  showUsage = true,
3609
3107
  showThoughts = true,
3108
+ showNotes = true,
3109
+ stoppableSubagents = true,
3610
3110
  showTotalUsage = true,
3611
3111
  showStatus = true,
3612
3112
  showApprovalMode = true,
@@ -3639,7 +3139,7 @@ var AgentChatInner = ({
3639
3139
  }
3640
3140
  const L = useLabels();
3641
3141
  const external = isHistoryHook(history) ? history : void 0;
3642
- const [ownStore] = (0, import_react15.useState)(
3142
+ const [ownStore] = (0, import_react13.useState)(
3643
3143
  () => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
3644
3144
  );
3645
3145
  const own = useChatHistory(agent, {
@@ -3647,9 +3147,9 @@ var AgentChatInner = ({
3647
3147
  enabled: Boolean(history) && !external
3648
3148
  });
3649
3149
  const chats = history ? external ?? own : void 0;
3650
- const rootRef = (0, import_react15.useRef)(null);
3651
- const [narrow, setNarrow] = (0, import_react15.useState)(void 0);
3652
- (0, import_react15.useEffect)(() => {
3150
+ const rootRef = (0, import_react13.useRef)(null);
3151
+ const [narrow, setNarrow] = (0, import_react13.useState)(void 0);
3152
+ (0, import_react13.useEffect)(() => {
3653
3153
  const el = rootRef.current;
3654
3154
  if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
3655
3155
  const measure = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
@@ -3658,9 +3158,9 @@ var AgentChatInner = ({
3658
3158
  ro.observe(el);
3659
3159
  return () => ro.disconnect();
3660
3160
  }, [narrowWidth]);
3661
- const [historyChoice, setHistoryOpen] = (0, import_react15.useState)(defaultHistoryOpen);
3161
+ const [historyChoice, setHistoryOpen] = (0, import_react13.useState)(defaultHistoryOpen);
3662
3162
  const historyOpen = historyChoice ?? narrow === false;
3663
- const [filesOpen, setFilesOpen] = (0, import_react15.useState)(defaultFilesOpen);
3163
+ const [filesOpen, setFilesOpen] = (0, import_react13.useState)(defaultFilesOpen);
3664
3164
  const toggleHistory = () => {
3665
3165
  setHistoryOpen(!historyOpen);
3666
3166
  if (narrow && !historyOpen) setFilesOpen(false);
@@ -3669,13 +3169,13 @@ var AgentChatInner = ({
3669
3169
  setFilesOpen((o) => !o);
3670
3170
  if (narrow && !filesOpen) setHistoryOpen(false);
3671
3171
  };
3672
- const bodyRef = (0, import_react15.useRef)(null);
3673
- const stickRef = (0, import_react15.useRef)(true);
3674
- (0, import_react15.useEffect)(() => {
3172
+ const bodyRef = (0, import_react13.useRef)(null);
3173
+ const stickRef = (0, import_react13.useRef)(true);
3174
+ (0, import_react13.useEffect)(() => {
3675
3175
  const el = bodyRef.current;
3676
3176
  if (el && stickRef.current) el.scrollTop = el.scrollHeight;
3677
3177
  }, [agent.messages, agent.steps, agent.finalText, agent.modelLoad, agent.pendingApprovals]);
3678
- const [compacting, setCompacting] = (0, import_react15.useState)(false);
3178
+ const [compacting, setCompacting] = (0, import_react13.useState)(false);
3679
3179
  const compact = () => {
3680
3180
  setCompacting(true);
3681
3181
  void agent.compact().finally(() => setCompacting(false));
@@ -3789,6 +3289,8 @@ var AgentChatInner = ({
3789
3289
  showToolCalls,
3790
3290
  showUsage,
3791
3291
  showThoughts,
3292
+ showNotes,
3293
+ onStopSubagent: stoppableSubagents ? agent.stopSubagent : void 0,
3792
3294
  activityOpen,
3793
3295
  liveExtra,
3794
3296
  renderContent,
@@ -3860,7 +3362,7 @@ var AgentChatInner = ({
3860
3362
  };
3861
3363
 
3862
3364
  // src/components/Composer.tsx
3863
- var import_react16 = require("react");
3365
+ var import_react14 = require("react");
3864
3366
  var import_jsx_runtime14 = require("react/jsx-runtime");
3865
3367
  var Composer = ({
3866
3368
  onSubmit,
@@ -3870,7 +3372,7 @@ var Composer = ({
3870
3372
  placeholder = "Ask the agent to do something\u2026",
3871
3373
  className
3872
3374
  }) => {
3873
- const [text, setText] = (0, import_react16.useState)("");
3375
+ const [text, setText] = (0, import_react14.useState)("");
3874
3376
  const submit = () => {
3875
3377
  const value = text.trim();
3876
3378
  if (!value || busy || disabled) return;
@@ -3983,7 +3485,7 @@ var ApprovalModeSwitch = ({
3983
3485
  );
3984
3486
 
3985
3487
  // src/components/ApiKeyForm.tsx
3986
- var import_react17 = require("react");
3488
+ var import_react15 = require("react");
3987
3489
  var import_jsx_runtime17 = require("react/jsx-runtime");
3988
3490
  var ApiKeyForm = ({
3989
3491
  credentials,
@@ -3993,10 +3495,10 @@ var ApiKeyForm = ({
3993
3495
  onChange,
3994
3496
  className
3995
3497
  }) => {
3996
- const [value, setValue] = (0, import_react17.useState)("");
3997
- const [present, setPresent] = (0, import_react17.useState)(false);
3998
- const [busy, setBusy] = (0, import_react17.useState)(false);
3999
- (0, import_react17.useEffect)(() => {
3498
+ const [value, setValue] = (0, import_react15.useState)("");
3499
+ const [present, setPresent] = (0, import_react15.useState)(false);
3500
+ const [busy, setBusy] = (0, import_react15.useState)(false);
3501
+ (0, import_react15.useEffect)(() => {
4000
3502
  let active = true;
4001
3503
  credentials.hasKey(credentialRef).then((has) => {
4002
3504
  if (active) setPresent(has);
@@ -4108,27 +3610,26 @@ var import_agent_web4 = require("@dudko.dev/agent-web");
4108
3610
  ToolApprovalPrompt,
4109
3611
  ToolCallRow,
4110
3612
  UsageBadge,
3613
+ UserNoteRow,
4111
3614
  VaultCredentialStore,
4112
3615
  VirtualFileSystem,
4113
3616
  agentStateReducer,
4114
3617
  attachmentKindOf,
4115
3618
  attachmentRefusal,
4116
3619
  chatTitle,
4117
- claimOAuthCallback,
4118
3620
  createAgent,
4119
3621
  createFileTools,
4120
3622
  createInitialAgentState,
3623
+ createRunControl,
4121
3624
  createSubagentTool,
4122
3625
  createWebLLMEngine,
4123
3626
  createWebLLMModel,
4124
3627
  defaultLabels,
4125
3628
  defineSkill,
4126
3629
  defineTool,
4127
- describeMcpResult,
4128
3630
  downscaleImage,
4129
3631
  filterCommands,
4130
3632
  formatElapsed,
4131
- isUnauthorizedError,
4132
3633
  isWebGPUAvailable,
4133
3634
  loadSkillFromUrl,
4134
3635
  markReadOnly,
@@ -4138,9 +3639,8 @@ var import_agent_web4 = require("@dudko.dev/agent-web");
4138
3639
  parseSkillMarkdown,
4139
3640
  parseSlash,
4140
3641
  preloadWebLLMModel,
4141
- readCallbackParams,
4142
3642
  serveSubagentWorker,
4143
- stripOAuthParams,
3643
+ steerIntent,
4144
3644
  supportsImages,
4145
3645
  supportsPdf,
4146
3646
  unloadWebLLMModel,
@@ -4151,8 +3651,6 @@ var import_agent_web4 = require("@dudko.dev/agent-web");
4151
3651
  useCredentials,
4152
3652
  useLabels,
4153
3653
  useLocalModel,
4154
- useMcp,
4155
- useMcpServers,
4156
3654
  useOptionalAgentContext,
4157
3655
  useSpeechToText,
4158
3656
  useVirtualFiles,