@dudko.dev/agent-web-ui 0.0.3 → 0.0.5

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 (88) hide show
  1. package/README.md +78 -6
  2. package/dist/{chunk-UNIXGP4N.js → chunk-627OXMFG.js} +2 -0
  3. package/dist/{chunk-G7LQTOA2.js → chunk-NHU6WQM5.js} +61 -6
  4. package/dist/controller.cjs +621 -20
  5. package/dist/controller.d.cts +110 -3
  6. package/dist/controller.d.ts +110 -3
  7. package/dist/controller.js +575 -17
  8. package/dist/index.cjs +81 -14
  9. package/dist/index.d.cts +28 -10
  10. package/dist/index.d.ts +28 -10
  11. package/dist/index.js +27 -8
  12. package/dist/{labels-DH1ESUtm.d.ts → labels-CCPL7t17.d.ts} +8 -1
  13. package/dist/{labels-CmiTBLWD.d.cts → labels-ipy-ydkp.d.cts} +8 -1
  14. package/dist/locales/be.cjs +2 -0
  15. package/dist/locales/be.js +1 -1
  16. package/dist/locales/bg.cjs +2 -0
  17. package/dist/locales/bg.js +1 -1
  18. package/dist/locales/ca.cjs +2 -0
  19. package/dist/locales/ca.js +1 -1
  20. package/dist/locales/cs.cjs +2 -0
  21. package/dist/locales/cs.js +1 -1
  22. package/dist/locales/da.cjs +2 -0
  23. package/dist/locales/da.js +1 -1
  24. package/dist/locales/de.cjs +2 -0
  25. package/dist/locales/de.js +1 -1
  26. package/dist/locales/el.cjs +2 -0
  27. package/dist/locales/el.js +1 -1
  28. package/dist/locales/en.cjs +2 -0
  29. package/dist/locales/en.js +1 -1
  30. package/dist/locales/es-419.cjs +2 -0
  31. package/dist/locales/es-419.js +1 -1
  32. package/dist/locales/es.cjs +2 -0
  33. package/dist/locales/es.js +1 -1
  34. package/dist/locales/fi.cjs +2 -0
  35. package/dist/locales/fi.js +1 -1
  36. package/dist/locales/fr-CA.cjs +2 -0
  37. package/dist/locales/fr-CA.js +1 -1
  38. package/dist/locales/fr.cjs +2 -0
  39. package/dist/locales/fr.js +1 -1
  40. package/dist/locales/gn.cjs +2 -0
  41. package/dist/locales/gn.js +1 -1
  42. package/dist/locales/hr.cjs +2 -0
  43. package/dist/locales/hr.js +1 -1
  44. package/dist/locales/ht.cjs +2 -0
  45. package/dist/locales/ht.js +1 -1
  46. package/dist/locales/hu.cjs +2 -0
  47. package/dist/locales/hu.js +1 -1
  48. package/dist/locales/index.cjs +2 -0
  49. package/dist/locales/index.js +1 -1
  50. package/dist/locales/it.cjs +2 -0
  51. package/dist/locales/it.js +1 -1
  52. package/dist/locales/nb.cjs +2 -0
  53. package/dist/locales/nb.js +1 -1
  54. package/dist/locales/nl.cjs +2 -0
  55. package/dist/locales/nl.js +1 -1
  56. package/dist/locales/pl.cjs +2 -0
  57. package/dist/locales/pl.js +1 -1
  58. package/dist/locales/pt-BR.cjs +2 -0
  59. package/dist/locales/pt-BR.js +1 -1
  60. package/dist/locales/pt.cjs +2 -0
  61. package/dist/locales/pt.js +1 -1
  62. package/dist/locales/qu.cjs +2 -0
  63. package/dist/locales/qu.js +1 -1
  64. package/dist/locales/ro.cjs +2 -0
  65. package/dist/locales/ro.js +1 -1
  66. package/dist/locales/ru.cjs +2 -0
  67. package/dist/locales/ru.js +1 -1
  68. package/dist/locales/sk.cjs +2 -0
  69. package/dist/locales/sk.js +1 -1
  70. package/dist/locales/sq.cjs +2 -0
  71. package/dist/locales/sq.js +1 -1
  72. package/dist/locales/sr-Latn.cjs +2 -0
  73. package/dist/locales/sr-Latn.js +1 -1
  74. package/dist/locales/sr.cjs +2 -0
  75. package/dist/locales/sr.js +1 -1
  76. package/dist/locales/sv.cjs +2 -0
  77. package/dist/locales/sv.js +1 -1
  78. package/dist/locales/tr.cjs +2 -0
  79. package/dist/locales/tr.js +1 -1
  80. package/dist/locales/uk.cjs +2 -0
  81. package/dist/locales/uk.js +1 -1
  82. package/dist/markdown.cjs +36 -0
  83. package/dist/markdown.d.cts +27 -1
  84. package/dist/markdown.d.ts +27 -1
  85. package/dist/markdown.js +33 -0
  86. package/dist/mcp-app.cjs +1 -4
  87. package/dist/mcp-app.js +1 -2
  88. package/package.json +1 -1
@@ -1,7 +1,114 @@
1
- import { RunFile, RunResult, AskUserAnswer, ToolApprovalMode, AppToolCallRequest, AppSamplingRequest, AppSamplingView, AppSamplingResult, CompactResult, IUsage, BrowserAgentConfig, AgentEventHandler, Agent } from '@dudko.dev/agent-web';
1
+ import { AgentEvent, RunFile, RunResult, AskUserAnswer, ToolApprovalMode, AppToolCallRequest, AppSamplingRequest, AppSamplingView, AppSamplingResult, CompactResult, IUsage, BrowserAgentConfig, AgentEventHandler, Agent } from '@dudko.dev/agent-web';
2
2
  import { PendingQuestion } from './index.cjs';
3
3
  import { ChatAttachment, ChatMessage, AgentUiState, ApprovalView } from './index.cjs';
4
4
 
5
+ /** Headers for every request to the gateway, or a function that returns them (called each time). */
6
+ type RemoteAgentHeaders = HeadersInit | (() => HeadersInit | undefined | Promise<HeadersInit | undefined>);
7
+ /** How `createRemoteAgentController` reaches the gateway. */
8
+ interface RemoteAgentOptions {
9
+ /**
10
+ * The gateway's base URL - the routes are appended to it (`<baseUrl>/sessions`, …). Absolute,
11
+ * or relative to the page.
12
+ */
13
+ baseUrl: string;
14
+ /**
15
+ * A session to continue (one `onSessionId` gave before - e.g. kept in `sessionStorage`): its
16
+ * stream is replayed from the start, so the transcript comes back. Without it, the first message
17
+ * starts a new session. A session the gateway no longer knows (404) is forgotten.
18
+ */
19
+ sessionId?: string;
20
+ /**
21
+ * Headers for every request (`Authorization: Bearer …`, a signed visitor token): an object, or a
22
+ * function called before each request - so a token can be refreshed. Nothing else is added but
23
+ * `content-type` / `accept` / `last-event-id`.
24
+ */
25
+ headers?: RemoteAgentHeaders;
26
+ /** `fetch`'s `credentials` (default `'same-origin'`; `'include'` sends a cookie cross-site). */
27
+ credentials?: RequestCredentials;
28
+ /** The `fetch` to use (default the global one). */
29
+ fetch?: typeof fetch;
30
+ /**
31
+ * Told the session's id when it changes: a new session started (the first message), one given
32
+ * that the gateway no longer knows (`undefined`), `reset` (`undefined`), `loadChat`.
33
+ */
34
+ onSessionId?: (sessionId: string | undefined) => void;
35
+ /**
36
+ * Every event, after the reducer folded it: the server agent's, a turn's start as the core's
37
+ * `run.start` and its end as `final` / `stopped` / `error` (as a local run's), the swarm's
38
+ * `turn.started` / `turn.ended` markers as they came. A run's `tool.approval-resolved` that only
39
+ * says it parked is not told.
40
+ */
41
+ onEvent?: (event: AgentEvent) => void;
42
+ /** Cap the retained raw event log (default 200; 0 = unbounded). */
43
+ maxEvents?: number;
44
+ /**
45
+ * The wait before the stream is opened again after a drop: from `minMs` (default 1000, or the
46
+ * gateway's `retry:` if larger) doubled up to `maxMs` (default 30 000); reset by a frame.
47
+ */
48
+ reconnect?: {
49
+ minMs?: number;
50
+ maxMs?: number;
51
+ };
52
+ }
53
+ /** One frame of the gateway's stream: `id:` (the cursor) and the JSON of `data:`. */
54
+ interface RemoteFrame {
55
+ id?: string;
56
+ data: string;
57
+ }
58
+ /**
59
+ * An SSE parser fed chunk by chunk (`text/event-stream`): frames end at a blank line, `data:` lines
60
+ * are joined by `\n`, a `:` line is a comment, `retry:` is reported. Lines may end in `\n`, `\r\n`
61
+ * or `\r`, and a chunk may end anywhere - inside a line, inside a CRLF.
62
+ */
63
+ declare const createSseParser: (onFrame: (frame: RemoteFrame) => void, onRetry?: (ms: number) => void) => {
64
+ push: (chunk: string) => void;
65
+ };
66
+ /** A cursor (`<turn>:<attempt>:<seq>`) as numbers; `undefined` when it is not one. */
67
+ declare const parseRemoteCursor: (raw: string | undefined) => {
68
+ turn: number;
69
+ attempt: number;
70
+ seq: number;
71
+ } | undefined;
72
+ /**
73
+ * What a part of the view an event writes into, so the copy a LATER attempt of the turn writes
74
+ * again replaces the earlier one (delivery is at-least-once: a step a crash interrupted runs again
75
+ * under the next attempt, and a resumed turn opens the step it parked in again). `undefined`: an
76
+ * event that is never written twice (a marker, an approval, usage).
77
+ */
78
+ declare const remoteEventScope: (event: {
79
+ type: string;
80
+ step?: unknown;
81
+ }) => string | undefined;
82
+ /**
83
+ * A server event as the browser's reducer reads it: the Node core's `error` carries an Error,
84
+ * which the stream stores as `{ name, message }` - the reducer wants its text.
85
+ */
86
+ declare const remoteEventOf: (event: Record<string, unknown>) => AgentEvent;
87
+ /** The snapshot of a remote controller before anything happened (what a view shows first). */
88
+ declare const createInitialRemoteSnapshot: (options?: Pick<RemoteAgentOptions, "sessionId">) => AgentControllerSnapshot;
89
+ /**
90
+ * The agent on a server, as a controller: see the module's header. The stream of a session given
91
+ * as `sessionId` is opened at once; otherwise the first `run` starts a session. `dispose` closes
92
+ * the stream and lets everything go.
93
+ *
94
+ * ```js
95
+ * const chat = createRemoteAgentController({
96
+ * baseUrl: 'https://support.example.com/agent',
97
+ * headers: async () => ({ authorization: `Bearer ${await visitorToken()}` }),
98
+ * sessionId: sessionStorage.getItem('chat') ?? undefined,
99
+ * onSessionId: (id) => (id ? sessionStorage.setItem('chat', id) : sessionStorage.removeItem('chat')),
100
+ * })
101
+ * ```
102
+ *
103
+ * What a server agent does not have answers as "not available", as the local controller does
104
+ * before its agent exists: `agent` is `undefined`; `answerQuestion`, `stopSubagent`, `sendRemote`
105
+ * and `forgetSkill` answer `false`; `compact` resolves `undefined`; `approveAppToolCall` and
106
+ * `sampleForApp` throw; `setApprovalMode`, `stopRemote` and `reload` do nothing (`reload` opens
107
+ * the stream again). `run` takes text only (images or files: refused, said as an error). A run's
108
+ * result is the turn's: its answer, `stopped`, its usage.
109
+ */
110
+ declare const createRemoteAgentController: (options: RemoteAgentOptions) => AgentController;
111
+
5
112
  /** How a controller behaves. `useAgent`'s options are these plus `deps`. */
6
113
  interface AgentControllerOptions {
7
114
  /** Invoked for every raw agent event, after the internal reducer folds it. */
@@ -249,5 +356,5 @@ declare const createInitialAgentSnapshot: (config: BrowserAgentConfig) => AgentC
249
356
  */
250
357
  declare const createAgentController: (initialConfig: BrowserAgentConfig, initialOptions?: AgentControllerOptions) => AgentController;
251
358
 
252
- export { createAgentController, createInitialAgentSnapshot };
253
- export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RunGoalOptions };
359
+ export { createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
360
+ export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, RemoteFrame, RunGoalOptions };
@@ -1,7 +1,114 @@
1
- import { RunFile, RunResult, AskUserAnswer, ToolApprovalMode, AppToolCallRequest, AppSamplingRequest, AppSamplingView, AppSamplingResult, CompactResult, IUsage, BrowserAgentConfig, AgentEventHandler, Agent } from '@dudko.dev/agent-web';
1
+ import { AgentEvent, RunFile, RunResult, AskUserAnswer, ToolApprovalMode, AppToolCallRequest, AppSamplingRequest, AppSamplingView, AppSamplingResult, CompactResult, IUsage, BrowserAgentConfig, AgentEventHandler, Agent } from '@dudko.dev/agent-web';
2
2
  import { PendingQuestion } from './index.js';
3
3
  import { ChatAttachment, ChatMessage, AgentUiState, ApprovalView } from './index.js';
4
4
 
5
+ /** Headers for every request to the gateway, or a function that returns them (called each time). */
6
+ type RemoteAgentHeaders = HeadersInit | (() => HeadersInit | undefined | Promise<HeadersInit | undefined>);
7
+ /** How `createRemoteAgentController` reaches the gateway. */
8
+ interface RemoteAgentOptions {
9
+ /**
10
+ * The gateway's base URL - the routes are appended to it (`<baseUrl>/sessions`, …). Absolute,
11
+ * or relative to the page.
12
+ */
13
+ baseUrl: string;
14
+ /**
15
+ * A session to continue (one `onSessionId` gave before - e.g. kept in `sessionStorage`): its
16
+ * stream is replayed from the start, so the transcript comes back. Without it, the first message
17
+ * starts a new session. A session the gateway no longer knows (404) is forgotten.
18
+ */
19
+ sessionId?: string;
20
+ /**
21
+ * Headers for every request (`Authorization: Bearer …`, a signed visitor token): an object, or a
22
+ * function called before each request - so a token can be refreshed. Nothing else is added but
23
+ * `content-type` / `accept` / `last-event-id`.
24
+ */
25
+ headers?: RemoteAgentHeaders;
26
+ /** `fetch`'s `credentials` (default `'same-origin'`; `'include'` sends a cookie cross-site). */
27
+ credentials?: RequestCredentials;
28
+ /** The `fetch` to use (default the global one). */
29
+ fetch?: typeof fetch;
30
+ /**
31
+ * Told the session's id when it changes: a new session started (the first message), one given
32
+ * that the gateway no longer knows (`undefined`), `reset` (`undefined`), `loadChat`.
33
+ */
34
+ onSessionId?: (sessionId: string | undefined) => void;
35
+ /**
36
+ * Every event, after the reducer folded it: the server agent's, a turn's start as the core's
37
+ * `run.start` and its end as `final` / `stopped` / `error` (as a local run's), the swarm's
38
+ * `turn.started` / `turn.ended` markers as they came. A run's `tool.approval-resolved` that only
39
+ * says it parked is not told.
40
+ */
41
+ onEvent?: (event: AgentEvent) => void;
42
+ /** Cap the retained raw event log (default 200; 0 = unbounded). */
43
+ maxEvents?: number;
44
+ /**
45
+ * The wait before the stream is opened again after a drop: from `minMs` (default 1000, or the
46
+ * gateway's `retry:` if larger) doubled up to `maxMs` (default 30 000); reset by a frame.
47
+ */
48
+ reconnect?: {
49
+ minMs?: number;
50
+ maxMs?: number;
51
+ };
52
+ }
53
+ /** One frame of the gateway's stream: `id:` (the cursor) and the JSON of `data:`. */
54
+ interface RemoteFrame {
55
+ id?: string;
56
+ data: string;
57
+ }
58
+ /**
59
+ * An SSE parser fed chunk by chunk (`text/event-stream`): frames end at a blank line, `data:` lines
60
+ * are joined by `\n`, a `:` line is a comment, `retry:` is reported. Lines may end in `\n`, `\r\n`
61
+ * or `\r`, and a chunk may end anywhere - inside a line, inside a CRLF.
62
+ */
63
+ declare const createSseParser: (onFrame: (frame: RemoteFrame) => void, onRetry?: (ms: number) => void) => {
64
+ push: (chunk: string) => void;
65
+ };
66
+ /** A cursor (`<turn>:<attempt>:<seq>`) as numbers; `undefined` when it is not one. */
67
+ declare const parseRemoteCursor: (raw: string | undefined) => {
68
+ turn: number;
69
+ attempt: number;
70
+ seq: number;
71
+ } | undefined;
72
+ /**
73
+ * What a part of the view an event writes into, so the copy a LATER attempt of the turn writes
74
+ * again replaces the earlier one (delivery is at-least-once: a step a crash interrupted runs again
75
+ * under the next attempt, and a resumed turn opens the step it parked in again). `undefined`: an
76
+ * event that is never written twice (a marker, an approval, usage).
77
+ */
78
+ declare const remoteEventScope: (event: {
79
+ type: string;
80
+ step?: unknown;
81
+ }) => string | undefined;
82
+ /**
83
+ * A server event as the browser's reducer reads it: the Node core's `error` carries an Error,
84
+ * which the stream stores as `{ name, message }` - the reducer wants its text.
85
+ */
86
+ declare const remoteEventOf: (event: Record<string, unknown>) => AgentEvent;
87
+ /** The snapshot of a remote controller before anything happened (what a view shows first). */
88
+ declare const createInitialRemoteSnapshot: (options?: Pick<RemoteAgentOptions, "sessionId">) => AgentControllerSnapshot;
89
+ /**
90
+ * The agent on a server, as a controller: see the module's header. The stream of a session given
91
+ * as `sessionId` is opened at once; otherwise the first `run` starts a session. `dispose` closes
92
+ * the stream and lets everything go.
93
+ *
94
+ * ```js
95
+ * const chat = createRemoteAgentController({
96
+ * baseUrl: 'https://support.example.com/agent',
97
+ * headers: async () => ({ authorization: `Bearer ${await visitorToken()}` }),
98
+ * sessionId: sessionStorage.getItem('chat') ?? undefined,
99
+ * onSessionId: (id) => (id ? sessionStorage.setItem('chat', id) : sessionStorage.removeItem('chat')),
100
+ * })
101
+ * ```
102
+ *
103
+ * What a server agent does not have answers as "not available", as the local controller does
104
+ * before its agent exists: `agent` is `undefined`; `answerQuestion`, `stopSubagent`, `sendRemote`
105
+ * and `forgetSkill` answer `false`; `compact` resolves `undefined`; `approveAppToolCall` and
106
+ * `sampleForApp` throw; `setApprovalMode`, `stopRemote` and `reload` do nothing (`reload` opens
107
+ * the stream again). `run` takes text only (images or files: refused, said as an error). A run's
108
+ * result is the turn's: its answer, `stopped`, its usage.
109
+ */
110
+ declare const createRemoteAgentController: (options: RemoteAgentOptions) => AgentController;
111
+
5
112
  /** How a controller behaves. `useAgent`'s options are these plus `deps`. */
6
113
  interface AgentControllerOptions {
7
114
  /** Invoked for every raw agent event, after the internal reducer folds it. */
@@ -249,5 +356,5 @@ declare const createInitialAgentSnapshot: (config: BrowserAgentConfig) => AgentC
249
356
  */
250
357
  declare const createAgentController: (initialConfig: BrowserAgentConfig, initialOptions?: AgentControllerOptions) => AgentController;
251
358
 
252
- export { createAgentController, createInitialAgentSnapshot };
253
- export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RunGoalOptions };
359
+ export { createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
360
+ export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, RemoteFrame, RunGoalOptions };