@dudko.dev/agent-web-ui 0.0.6 → 0.0.8

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 (170) hide show
  1. package/README.md +52 -0
  2. package/dist/{chunk-NHU6WQM5.js → chunk-ETYLHTPK.js} +435 -1
  3. package/dist/{chunk-627OXMFG.js → chunk-HIHUK7YA.js} +5 -0
  4. package/dist/{chunk-S5AHUAFG.js → chunk-JEW2ZWYX.js} +4 -0
  5. package/dist/{chunk-VZCQXE3P.js → chunk-UO2Q7AIV.js} +4 -0
  6. package/dist/{chunk-V33T6VX3.js → chunk-VG5NLFI5.js} +4 -0
  7. package/dist/controller.cjs +452 -16
  8. package/dist/controller.d.cts +39 -3
  9. package/dist/controller.d.ts +39 -3
  10. package/dist/controller.js +39 -16
  11. package/dist/{en-Dg2MtzcJ.d.cts → en-CPCAidve.d.cts} +4 -0
  12. package/dist/{en-Dg2MtzcJ.d.ts → en-CPCAidve.d.ts} +4 -0
  13. package/dist/index.cjs +458 -4
  14. package/dist/index.d.cts +4 -3
  15. package/dist/index.d.ts +4 -3
  16. package/dist/index.js +37 -1
  17. package/dist/{labels-CCPL7t17.d.ts → labels-CeJMN8NU.d.ts} +9 -1
  18. package/dist/{labels-ipy-ydkp.d.cts → labels-D-NI4hKW.d.cts} +9 -1
  19. package/dist/locales/be.cjs +9 -0
  20. package/dist/locales/be.d.cts +2 -2
  21. package/dist/locales/be.d.ts +2 -2
  22. package/dist/locales/be.js +5 -1
  23. package/dist/locales/bg.cjs +9 -0
  24. package/dist/locales/bg.d.cts +2 -2
  25. package/dist/locales/bg.d.ts +2 -2
  26. package/dist/locales/bg.js +5 -1
  27. package/dist/locales/ca.cjs +9 -0
  28. package/dist/locales/ca.d.cts +2 -2
  29. package/dist/locales/ca.d.ts +2 -2
  30. package/dist/locales/ca.js +5 -1
  31. package/dist/locales/cs.cjs +9 -0
  32. package/dist/locales/cs.d.cts +2 -2
  33. package/dist/locales/cs.d.ts +2 -2
  34. package/dist/locales/cs.js +5 -1
  35. package/dist/locales/da.cjs +9 -0
  36. package/dist/locales/da.d.cts +2 -2
  37. package/dist/locales/da.d.ts +2 -2
  38. package/dist/locales/da.js +5 -1
  39. package/dist/locales/de.cjs +9 -0
  40. package/dist/locales/de.d.cts +2 -2
  41. package/dist/locales/de.d.ts +2 -2
  42. package/dist/locales/de.js +5 -1
  43. package/dist/locales/el.cjs +9 -0
  44. package/dist/locales/el.d.cts +2 -2
  45. package/dist/locales/el.d.ts +2 -2
  46. package/dist/locales/el.js +5 -1
  47. package/dist/locales/en.cjs +9 -0
  48. package/dist/locales/en.d.cts +2 -2
  49. package/dist/locales/en.d.ts +2 -2
  50. package/dist/locales/en.js +5 -1
  51. package/dist/locales/es-419.cjs +9 -0
  52. package/dist/locales/es-419.d.cts +2 -2
  53. package/dist/locales/es-419.d.ts +2 -2
  54. package/dist/locales/es-419.js +2 -2
  55. package/dist/locales/es.cjs +9 -0
  56. package/dist/locales/es.d.cts +2 -2
  57. package/dist/locales/es.d.ts +2 -2
  58. package/dist/locales/es.js +2 -2
  59. package/dist/locales/fi.cjs +9 -0
  60. package/dist/locales/fi.d.cts +2 -2
  61. package/dist/locales/fi.d.ts +2 -2
  62. package/dist/locales/fi.js +5 -1
  63. package/dist/locales/fr-CA.cjs +9 -0
  64. package/dist/locales/fr-CA.d.cts +2 -2
  65. package/dist/locales/fr-CA.d.ts +2 -2
  66. package/dist/locales/fr-CA.js +2 -2
  67. package/dist/locales/fr.cjs +9 -0
  68. package/dist/locales/fr.d.cts +2 -2
  69. package/dist/locales/fr.d.ts +2 -2
  70. package/dist/locales/fr.js +2 -2
  71. package/dist/locales/gn.cjs +9 -0
  72. package/dist/locales/gn.d.cts +2 -2
  73. package/dist/locales/gn.d.ts +2 -2
  74. package/dist/locales/gn.js +5 -1
  75. package/dist/locales/hr.cjs +9 -0
  76. package/dist/locales/hr.d.cts +2 -2
  77. package/dist/locales/hr.d.ts +2 -2
  78. package/dist/locales/hr.js +5 -1
  79. package/dist/locales/ht.cjs +9 -0
  80. package/dist/locales/ht.d.cts +2 -2
  81. package/dist/locales/ht.d.ts +2 -2
  82. package/dist/locales/ht.js +5 -1
  83. package/dist/locales/hu.cjs +9 -0
  84. package/dist/locales/hu.d.cts +2 -2
  85. package/dist/locales/hu.d.ts +2 -2
  86. package/dist/locales/hu.js +5 -1
  87. package/dist/locales/index.cjs +5 -0
  88. package/dist/locales/index.d.cts +4 -4
  89. package/dist/locales/index.d.ts +4 -4
  90. package/dist/locales/index.js +1 -1
  91. package/dist/locales/it.cjs +9 -0
  92. package/dist/locales/it.d.cts +2 -2
  93. package/dist/locales/it.d.ts +2 -2
  94. package/dist/locales/it.js +5 -1
  95. package/dist/locales/nb.cjs +9 -0
  96. package/dist/locales/nb.d.cts +2 -2
  97. package/dist/locales/nb.d.ts +2 -2
  98. package/dist/locales/nb.js +5 -1
  99. package/dist/locales/nl.cjs +9 -0
  100. package/dist/locales/nl.d.cts +2 -2
  101. package/dist/locales/nl.d.ts +2 -2
  102. package/dist/locales/nl.js +5 -1
  103. package/dist/locales/pl.cjs +9 -0
  104. package/dist/locales/pl.d.cts +2 -2
  105. package/dist/locales/pl.d.ts +2 -2
  106. package/dist/locales/pl.js +5 -1
  107. package/dist/locales/pt-BR.cjs +9 -0
  108. package/dist/locales/pt-BR.d.cts +2 -2
  109. package/dist/locales/pt-BR.d.ts +2 -2
  110. package/dist/locales/pt-BR.js +5 -1
  111. package/dist/locales/pt.cjs +9 -0
  112. package/dist/locales/pt.d.cts +2 -2
  113. package/dist/locales/pt.d.ts +2 -2
  114. package/dist/locales/pt.js +5 -1
  115. package/dist/locales/qu.cjs +9 -0
  116. package/dist/locales/qu.d.cts +2 -2
  117. package/dist/locales/qu.d.ts +2 -2
  118. package/dist/locales/qu.js +5 -1
  119. package/dist/locales/ro.cjs +9 -0
  120. package/dist/locales/ro.d.cts +2 -2
  121. package/dist/locales/ro.d.ts +2 -2
  122. package/dist/locales/ro.js +5 -1
  123. package/dist/locales/ru.cjs +9 -0
  124. package/dist/locales/ru.d.cts +2 -2
  125. package/dist/locales/ru.d.ts +2 -2
  126. package/dist/locales/ru.js +5 -1
  127. package/dist/locales/sk.cjs +9 -0
  128. package/dist/locales/sk.d.cts +2 -2
  129. package/dist/locales/sk.d.ts +2 -2
  130. package/dist/locales/sk.js +5 -1
  131. package/dist/locales/sq.cjs +9 -0
  132. package/dist/locales/sq.d.cts +2 -2
  133. package/dist/locales/sq.d.ts +2 -2
  134. package/dist/locales/sq.js +5 -1
  135. package/dist/locales/sr-Latn.cjs +9 -0
  136. package/dist/locales/sr-Latn.d.cts +2 -2
  137. package/dist/locales/sr-Latn.d.ts +2 -2
  138. package/dist/locales/sr-Latn.js +2 -2
  139. package/dist/locales/sr.cjs +9 -0
  140. package/dist/locales/sr.d.cts +2 -2
  141. package/dist/locales/sr.d.ts +2 -2
  142. package/dist/locales/sr.js +2 -2
  143. package/dist/locales/sv.cjs +9 -0
  144. package/dist/locales/sv.d.cts +2 -2
  145. package/dist/locales/sv.d.ts +2 -2
  146. package/dist/locales/sv.js +5 -1
  147. package/dist/locales/tr.cjs +9 -0
  148. package/dist/locales/tr.d.cts +2 -2
  149. package/dist/locales/tr.d.ts +2 -2
  150. package/dist/locales/tr.js +5 -1
  151. package/dist/locales/uk.cjs +9 -0
  152. package/dist/locales/uk.d.cts +2 -2
  153. package/dist/locales/uk.d.ts +2 -2
  154. package/dist/locales/uk.js +5 -1
  155. package/dist/page-context-BAmw4p6d.d.cts +244 -0
  156. package/dist/page-context-BAmw4p6d.d.ts +244 -0
  157. package/dist/pipeline-format.cjs +842 -0
  158. package/dist/pipeline-format.d.cts +512 -0
  159. package/dist/pipeline-format.d.ts +512 -0
  160. package/dist/pipeline-format.js +788 -0
  161. package/dist/pipeline.cjs +1 -0
  162. package/dist/pipeline.d.cts +2 -0
  163. package/dist/pipeline.d.ts +2 -0
  164. package/dist/pipeline.js +1 -0
  165. package/dist/styles.css +59 -0
  166. package/dist/{types-CQquuZpl.d.cts → types-B5cyqkWY.d.cts} +1 -1
  167. package/dist/{types-CXZfZVP5.d.ts → types-BgNjWN5Z.d.ts} +1 -1
  168. package/dist/{types-DnBCok3z.d.ts → types-CHFtTZjl.d.cts} +6 -0
  169. package/dist/{types-DnBCok3z.d.cts → types-CHFtTZjl.d.ts} +6 -0
  170. package/package.json +12 -2
@@ -1,3 +1,5 @@
1
+ import { P as PageContextOptions, a as PageContext, b as PageContextCollector } from './page-context-BAmw4p6d.js';
2
+ export { c as createPageContextCollector, t as trackPageFocus } from './page-context-BAmw4p6d.js';
1
3
  import { AgentEvent, RunFile, RunResult, AskUserAnswer, ToolApprovalMode, AppToolCallRequest, AppSamplingRequest, AppSamplingView, AppSamplingResult, CompactResult, IUsage, BrowserAgentConfig, AgentEventHandler, Agent } from '@dudko.dev/agent-web';
2
4
  import { PendingQuestion } from './index.js';
3
5
  import { ChatAttachment, ChatMessage, AgentUiState, ApprovalView } from './index.js';
@@ -49,6 +51,12 @@ interface RemoteAgentOptions {
49
51
  minMs?: number;
50
52
  maxMs?: number;
51
53
  };
54
+ /**
55
+ * What the person is looking at, read at send time and POSTed with each message as `context`
56
+ * (ALL collectors off by default: nothing is sent without them). The gateway keeps only the
57
+ * keys its operator allows (`contextKeys`) and checks them; see `page-context.ts`.
58
+ */
59
+ pageContext?: PageContextOptions;
52
60
  }
53
61
  /**
54
62
  * What `onEvent` is told with an event. `live`: the event belongs to a turn that a message sent
@@ -169,6 +177,13 @@ interface AgentControllerOptions {
169
177
  * stopping it is explicit: `sendRemote` / `stopRemote`. Consent requests stay in that tab.
170
178
  */
171
179
  watch?: boolean;
180
+ /**
181
+ * What the person is looking at, read at SEND time and passed with each message (the core's
182
+ * `run(goal, { context })` / `control.send(text, { context })`): which collectors (ALL off by
183
+ * default), the host's `extra`, `include` / `exclude`, `maxChars`. See `page-context.ts` and the
184
+ * React package's docs/chat.md, "Page context". Untrusted data for the agent, never policy.
185
+ */
186
+ pageContext?: PageContextOptions;
172
187
  }
173
188
  interface ApproveOptions {
174
189
  /** Also allow this tool for the rest of the agent's life ("always allow"). */
@@ -187,6 +202,16 @@ interface RunGoalOptions {
187
202
  files?: RunFile[];
188
203
  /** What the transcript shows as attached to this turn (thumbnails, chips). */
189
204
  attachments?: ChatAttachment[];
205
+ /**
206
+ * The page context for this message: given (the composer collected it), `false` (the person
207
+ * turned sharing off for this message), or absent - collected now from `options.pageContext`.
208
+ */
209
+ context?: PageContext | false;
210
+ }
211
+ /** `send`'s options. */
212
+ interface SendOptions {
213
+ /** As `RunGoalOptions.context`; absent = collected now (the location only if already known). */
214
+ context?: PageContext | false;
190
215
  }
191
216
  /**
192
217
  * A tool call an MCP App asks for, as `approveAppToolCall` takes it: the core's request, plus
@@ -262,7 +287,18 @@ interface AgentControllerActions {
262
287
  * flight or the text is empty — then use `run`. Watch `queued` / `notes`. Only this tab's run:
263
288
  * for the conversation's run in another tab, `sendRemote`.
264
289
  */
265
- send: (text: string) => boolean;
290
+ send: (text: string, options?: SendOptions) => boolean;
291
+ /**
292
+ * What the next message would share (`options.pageContext`), read now without asking anything:
293
+ * for the composer's chip. A location not known yet is `PAGE_CONTEXT_ASK_ON_SEND`. `undefined`
294
+ * when the host shares nothing.
295
+ */
296
+ previewPageContext: () => PageContext | undefined;
297
+ /**
298
+ * The controller's page-context collector (`options.pageContext`): a chat gives it a focus
299
+ * tracker (`setTracker(trackPageFocus(...))`) so the focus and selection are read outside it.
300
+ */
301
+ pageContextCollector: () => PageContextCollector;
266
302
  /** Stop ONE running subagent (`SubagentView.id`); the run and its siblings go on. */
267
303
  stopSubagent: (id: string) => boolean;
268
304
  /**
@@ -368,5 +404,5 @@ declare const createInitialAgentSnapshot: (config: BrowserAgentConfig) => AgentC
368
404
  */
369
405
  declare const createAgentController: (initialConfig: BrowserAgentConfig, initialOptions?: AgentControllerOptions) => AgentController;
370
406
 
371
- export { createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
372
- export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, RemoteEventInfo, RemoteFrame, RunGoalOptions };
407
+ export { PageContext, PageContextCollector, PageContextOptions, createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
408
+ export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, RemoteEventInfo, RemoteFrame, RunGoalOptions, SendOptions };
@@ -5,6 +5,7 @@ import {
5
5
  askUserWith,
6
6
  createApprovalQueue,
7
7
  createInitialAgentState,
8
+ createPageContextCollector,
8
9
  createQuestionQueue,
9
10
  errMessage,
10
11
  followOtherTabs,
@@ -12,8 +13,10 @@ import {
12
13
  loadAgentCore,
13
14
  pendingApprovalsOf,
14
15
  questionTimeoutOf,
15
- remoteAnswerOf
16
- } from "./chunk-NHU6WQM5.js";
16
+ remoteAnswerOf,
17
+ trackPageFocus,
18
+ withoutAskOnSend
19
+ } from "./chunk-ETYLHTPK.js";
17
20
 
18
21
  // src/remote-controller.ts
19
22
  var createSseParser = (onFrame, onRetry) => {
@@ -108,6 +111,7 @@ var snapshotOf = (state, sessionId, answering) => Object.freeze({
108
111
  });
109
112
  var createRemoteAgentController = (options) => {
110
113
  const base = options.baseUrl.replace(/\/+$/, "");
114
+ const pageContexts = createPageContextCollector(() => options.pageContext);
111
115
  const doFetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
112
116
  const minWait = Math.max(0, options.reconnect?.minMs ?? 1e3);
113
117
  const maxWait = Math.max(minWait, options.reconnect?.maxMs ?? 3e4);
@@ -408,7 +412,8 @@ var createRemoteAgentController = (options) => {
408
412
  sentHere.add(id);
409
413
  const ended = new Promise((resolve) => runs.set(id, resolve));
410
414
  try {
411
- await sendMessage(id, text);
415
+ const context = runOptions?.context === false ? void 0 : runOptions?.context ?? await pageContexts.collect({ ask: true });
416
+ await sendMessage(id, text, context);
412
417
  } catch (err) {
413
418
  runs.delete(id);
414
419
  waiting = waiting.filter((w) => w.id !== id);
@@ -420,11 +425,12 @@ var createRemoteAgentController = (options) => {
420
425
  }
421
426
  return ended;
422
427
  };
423
- const sendMessage = async (id, text) => {
428
+ const sendMessage = async (id, text, context) => {
424
429
  const sid = sessionId;
430
+ const withContext = context && Object.keys(context).length ? { context } : {};
425
431
  if (sid) {
426
432
  try {
427
- await post(`/sessions/${encodeURIComponent(sid)}/messages`, { text, id });
433
+ await post(`/sessions/${encodeURIComponent(sid)}/messages`, { text, id, ...withContext });
428
434
  return;
429
435
  } catch (err) {
430
436
  const gone = err instanceof GatewayError && (err.status === 404 || err.status === 409 && err.code === "session_ended");
@@ -432,7 +438,7 @@ var createRemoteAgentController = (options) => {
432
438
  forgetSession();
433
439
  }
434
440
  }
435
- const made = await post("/sessions", { message: text, id });
441
+ const made = await post("/sessions", { message: text, id, ...withContext });
436
442
  if (disposed) return;
437
443
  if (typeof made?.sessionId !== "string")
438
444
  throw new Error("the agent’s server started no session");
@@ -443,20 +449,23 @@ var createRemoteAgentController = (options) => {
443
449
  setSession(made.sessionId);
444
450
  void openStream();
445
451
  };
446
- const send = (text) => {
452
+ const send = (text, sendOptions) => {
447
453
  const clean = typeof text === "string" ? text.trim() : "";
448
454
  if (disposed || state.status !== "running" || !clean || !sessionId) return false;
449
455
  const id = newMessageId();
450
456
  waiting.push({ id, text: clean });
451
457
  sentHere.add(id);
452
458
  fold(event({ type: "message.queued", id, text: clean }));
453
- void post(`/sessions/${encodeURIComponent(sessionId)}/messages`, { text: clean, id }).catch(
454
- (err) => {
455
- waiting = waiting.filter((w) => w.id !== id);
456
- fold({ type: "undelivered", texts: [...state.undelivered, clean], keepQueued: true });
457
- sayError(err);
458
- }
459
- );
459
+ const context = sendOptions?.context === false ? void 0 : sendOptions?.context ?? withoutAskOnSend(pageContexts.preview());
460
+ void post(`/sessions/${encodeURIComponent(sessionId)}/messages`, {
461
+ text: clean,
462
+ id,
463
+ ...context && Object.keys(context).length ? { context } : {}
464
+ }).catch((err) => {
465
+ waiting = waiting.filter((w) => w.id !== id);
466
+ fold({ type: "undelivered", texts: [...state.undelivered, clean], keepQueued: true });
467
+ sayError(err);
468
+ });
460
469
  return true;
461
470
  };
462
471
  const stop = () => {
@@ -545,6 +554,8 @@ var createRemoteAgentController = (options) => {
545
554
  stopRemote: () => {
546
555
  },
547
556
  send,
557
+ previewPageContext: () => pageContexts.preview(),
558
+ pageContextCollector: () => pageContexts,
548
559
  sendRemote: () => false,
549
560
  stopSubagent: () => false,
550
561
  forgetSkill: async () => false,
@@ -606,6 +617,7 @@ var createInitialAgentSnapshot = (config) => snapshotOf2(createInitialAgentState
606
617
  var createAgentController = (initialConfig, initialOptions = {}) => {
607
618
  let config = initialConfig;
608
619
  let options = initialOptions;
620
+ const pageContexts = createPageContextCollector(() => options.pageContext);
609
621
  let disposed = false;
610
622
  let state = createInitialAgentState();
611
623
  let pendingQuestions = [];
@@ -789,10 +801,12 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
789
801
  });
790
802
  }
791
803
  try {
804
+ const context = runOptions?.context === false ? void 0 : runOptions?.context ?? await pageContexts.collect({ ask: true });
792
805
  const result = await current.run(goal, {
793
806
  signal: controller.signal,
794
807
  control: runControl,
795
808
  sessionId,
809
+ ...context && Object.keys(context).length ? { context } : {},
796
810
  ...runOptions?.images?.length ? { images: runOptions.images } : {},
797
811
  ...runOptions?.files?.length ? { files: runOptions.files } : {},
798
812
  onEvent: (event) => {
@@ -850,7 +864,12 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
850
864
  }
851
865
  }
852
866
  };
853
- const send = (text) => control?.send(text) ?? false;
867
+ const send = (text, sendOptions) => {
868
+ if (!control) return false;
869
+ const context = sendOptions?.context === false ? void 0 : sendOptions?.context ?? withoutAskOnSend(pageContexts.preview());
870
+ return context && Object.keys(context).length ? control.send(text, { context }) : control.send(text);
871
+ };
872
+ const previewPageContext = () => pageContexts.preview();
854
873
  let remoteSends = 0;
855
874
  const sendRemote = (text) => {
856
875
  const current = watch;
@@ -1028,6 +1047,8 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
1028
1047
  stop,
1029
1048
  stopRemote,
1030
1049
  send,
1050
+ previewPageContext,
1051
+ pageContextCollector: () => pageContexts,
1031
1052
  sendRemote,
1032
1053
  stopSubagent,
1033
1054
  forgetSkill,
@@ -1049,9 +1070,11 @@ export {
1049
1070
  createAgentController,
1050
1071
  createInitialAgentSnapshot,
1051
1072
  createInitialRemoteSnapshot,
1073
+ createPageContextCollector,
1052
1074
  createRemoteAgentController,
1053
1075
  createSseParser,
1054
1076
  parseRemoteCursor,
1055
1077
  remoteEventOf,
1056
- remoteEventScope
1078
+ remoteEventScope,
1079
+ trackPageFocus
1057
1080
  };
@@ -166,6 +166,10 @@ declare const catalog: {
166
166
  questionOther: string;
167
167
  questionOtherLabel: string;
168
168
  questionSkip: string;
169
+ pageContextSharing: string;
170
+ pageContextNotSharing: string;
171
+ pageContextDontShare: string;
172
+ pageContextAskedOnSend: string;
169
173
  questionExpiresIn: string;
170
174
  questionRemote: string;
171
175
  questionAutomatic: string;
@@ -166,6 +166,10 @@ declare const catalog: {
166
166
  questionOther: string;
167
167
  questionOtherLabel: string;
168
168
  questionSkip: string;
169
+ pageContextSharing: string;
170
+ pageContextNotSharing: string;
171
+ pageContextDontShare: string;
172
+ pageContextAskedOnSend: string;
169
173
  questionExpiresIn: string;
170
174
  questionRemote: string;
171
175
  questionAutomatic: string;