@dudko.dev/agent-web-ui 0.0.2 → 0.0.4
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/README.md +83 -4
- package/dist/canvas.cjs +0 -1
- package/dist/canvas.js +1 -2
- package/dist/{chunk-WFM6B7CL.js → chunk-627OXMFG.js} +2 -1
- package/dist/{chunk-EL2YCROY.js → chunk-D64VLIRY.js} +0 -1
- package/dist/{chunk-ZBHESK6V.js → chunk-G7LQTOA2.js} +0 -1
- package/dist/{chunk-SVYHDLAZ.js → chunk-S5AHUAFG.js} +0 -1
- package/dist/{chunk-7O64ZI6Z.js → chunk-TJBGZM6D.js} +0 -1
- package/dist/{chunk-VCR7LU7J.js → chunk-V33T6VX3.js} +0 -1
- package/dist/{chunk-WZ7K7JIP.js → chunk-VZCQXE3P.js} +0 -1
- package/dist/{chunk-GB7RZJMG.js → chunk-WEYQMUKY.js} +0 -1
- package/dist/{chunk-KZQB35LS.js → chunk-Y6QYUFSC.js} +0 -1
- package/dist/controller.cjs +560 -6
- package/dist/controller.d.cts +110 -3
- package/dist/controller.d.ts +110 -3
- package/dist/controller.js +556 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/{labels-DH1ESUtm.d.ts → labels-BJMtk5Fw.d.ts} +2 -0
- package/dist/{labels-CmiTBLWD.d.cts → labels-B_y8F1GW.d.cts} +2 -0
- package/dist/locales/be.cjs +2 -1
- package/dist/locales/be.js +1 -2
- package/dist/locales/bg.cjs +2 -1
- package/dist/locales/bg.js +1 -2
- package/dist/locales/ca.cjs +2 -1
- package/dist/locales/ca.js +1 -2
- package/dist/locales/cs.cjs +2 -1
- package/dist/locales/cs.js +1 -2
- package/dist/locales/da.cjs +2 -1
- package/dist/locales/da.js +1 -2
- package/dist/locales/de.cjs +2 -1
- package/dist/locales/de.js +1 -2
- package/dist/locales/el.cjs +2 -1
- package/dist/locales/el.js +1 -2
- package/dist/locales/en.cjs +2 -1
- package/dist/locales/en.js +1 -2
- package/dist/locales/es-419.cjs +2 -1
- package/dist/locales/es-419.js +2 -3
- package/dist/locales/es.cjs +2 -1
- package/dist/locales/es.js +2 -3
- package/dist/locales/fi.cjs +2 -1
- package/dist/locales/fi.js +1 -2
- package/dist/locales/fr-CA.cjs +2 -1
- package/dist/locales/fr-CA.js +2 -3
- package/dist/locales/fr.cjs +2 -1
- package/dist/locales/fr.js +2 -3
- package/dist/locales/gn.cjs +2 -1
- package/dist/locales/gn.js +1 -2
- package/dist/locales/hr.cjs +2 -1
- package/dist/locales/hr.js +1 -2
- package/dist/locales/ht.cjs +2 -1
- package/dist/locales/ht.js +1 -2
- package/dist/locales/hu.cjs +2 -1
- package/dist/locales/hu.js +1 -2
- package/dist/locales/index.cjs +2 -1
- package/dist/locales/index.js +1 -2
- package/dist/locales/it.cjs +2 -1
- package/dist/locales/it.js +1 -2
- package/dist/locales/nb.cjs +2 -1
- package/dist/locales/nb.js +1 -2
- package/dist/locales/nl.cjs +2 -1
- package/dist/locales/nl.js +1 -2
- package/dist/locales/pl.cjs +2 -1
- package/dist/locales/pl.js +1 -2
- package/dist/locales/pt-BR.cjs +2 -1
- package/dist/locales/pt-BR.js +1 -2
- package/dist/locales/pt.cjs +2 -1
- package/dist/locales/pt.js +1 -2
- package/dist/locales/qu.cjs +2 -1
- package/dist/locales/qu.js +1 -2
- package/dist/locales/ro.cjs +2 -1
- package/dist/locales/ro.js +1 -2
- package/dist/locales/ru.cjs +2 -1
- package/dist/locales/ru.js +1 -2
- package/dist/locales/sk.cjs +2 -1
- package/dist/locales/sk.js +1 -2
- package/dist/locales/sq.cjs +2 -1
- package/dist/locales/sq.js +1 -2
- package/dist/locales/sr-Latn.cjs +2 -1
- package/dist/locales/sr-Latn.js +2 -3
- package/dist/locales/sr.cjs +2 -1
- package/dist/locales/sr.js +2 -3
- package/dist/locales/sv.cjs +2 -1
- package/dist/locales/sv.js +1 -2
- package/dist/locales/tr.cjs +2 -1
- package/dist/locales/tr.js +1 -2
- package/dist/locales/uk.cjs +2 -1
- package/dist/locales/uk.js +1 -2
- package/dist/markdown.cjs +36 -1
- package/dist/markdown.d.cts +27 -1
- package/dist/markdown.d.ts +27 -1
- package/dist/markdown.js +34 -2
- package/dist/mcp-app-sandbox.cjs +0 -1
- package/dist/mcp-app-sandbox.js +1 -2
- package/dist/mcp-app.cjs +0 -1
- package/dist/mcp-app.js +2 -3
- package/dist/pipeline.cjs +0 -1
- package/dist/pipeline.js +1 -2
- package/package.json +3 -3
- package/dist/canvas.cjs.map +0 -1
- package/dist/canvas.js.map +0 -1
- package/dist/chunk-7O64ZI6Z.js.map +0 -1
- package/dist/chunk-EL2YCROY.js.map +0 -1
- package/dist/chunk-GB7RZJMG.js.map +0 -1
- package/dist/chunk-KZQB35LS.js.map +0 -1
- package/dist/chunk-SVYHDLAZ.js.map +0 -1
- package/dist/chunk-VCR7LU7J.js.map +0 -1
- package/dist/chunk-WFM6B7CL.js.map +0 -1
- package/dist/chunk-WZ7K7JIP.js.map +0 -1
- package/dist/chunk-ZBHESK6V.js.map +0 -1
- package/dist/controller.cjs.map +0 -1
- package/dist/controller.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locales/be.cjs.map +0 -1
- package/dist/locales/be.js.map +0 -1
- package/dist/locales/bg.cjs.map +0 -1
- package/dist/locales/bg.js.map +0 -1
- package/dist/locales/ca.cjs.map +0 -1
- package/dist/locales/ca.js.map +0 -1
- package/dist/locales/cs.cjs.map +0 -1
- package/dist/locales/cs.js.map +0 -1
- package/dist/locales/da.cjs.map +0 -1
- package/dist/locales/da.js.map +0 -1
- package/dist/locales/de.cjs.map +0 -1
- package/dist/locales/de.js.map +0 -1
- package/dist/locales/el.cjs.map +0 -1
- package/dist/locales/el.js.map +0 -1
- package/dist/locales/en.cjs.map +0 -1
- package/dist/locales/en.js.map +0 -1
- package/dist/locales/es-419.cjs.map +0 -1
- package/dist/locales/es-419.js.map +0 -1
- package/dist/locales/es.cjs.map +0 -1
- package/dist/locales/es.js.map +0 -1
- package/dist/locales/fi.cjs.map +0 -1
- package/dist/locales/fi.js.map +0 -1
- package/dist/locales/fr-CA.cjs.map +0 -1
- package/dist/locales/fr-CA.js.map +0 -1
- package/dist/locales/fr.cjs.map +0 -1
- package/dist/locales/fr.js.map +0 -1
- package/dist/locales/gn.cjs.map +0 -1
- package/dist/locales/gn.js.map +0 -1
- package/dist/locales/hr.cjs.map +0 -1
- package/dist/locales/hr.js.map +0 -1
- package/dist/locales/ht.cjs.map +0 -1
- package/dist/locales/ht.js.map +0 -1
- package/dist/locales/hu.cjs.map +0 -1
- package/dist/locales/hu.js.map +0 -1
- package/dist/locales/index.cjs.map +0 -1
- package/dist/locales/index.js.map +0 -1
- package/dist/locales/it.cjs.map +0 -1
- package/dist/locales/it.js.map +0 -1
- package/dist/locales/nb.cjs.map +0 -1
- package/dist/locales/nb.js.map +0 -1
- package/dist/locales/nl.cjs.map +0 -1
- package/dist/locales/nl.js.map +0 -1
- package/dist/locales/pl.cjs.map +0 -1
- package/dist/locales/pl.js.map +0 -1
- package/dist/locales/pt-BR.cjs.map +0 -1
- package/dist/locales/pt-BR.js.map +0 -1
- package/dist/locales/pt.cjs.map +0 -1
- package/dist/locales/pt.js.map +0 -1
- package/dist/locales/qu.cjs.map +0 -1
- package/dist/locales/qu.js.map +0 -1
- package/dist/locales/ro.cjs.map +0 -1
- package/dist/locales/ro.js.map +0 -1
- package/dist/locales/ru.cjs.map +0 -1
- package/dist/locales/ru.js.map +0 -1
- package/dist/locales/sk.cjs.map +0 -1
- package/dist/locales/sk.js.map +0 -1
- package/dist/locales/sq.cjs.map +0 -1
- package/dist/locales/sq.js.map +0 -1
- package/dist/locales/sr-Latn.cjs.map +0 -1
- package/dist/locales/sr-Latn.js.map +0 -1
- package/dist/locales/sr.cjs.map +0 -1
- package/dist/locales/sr.js.map +0 -1
- package/dist/locales/sv.cjs.map +0 -1
- package/dist/locales/sv.js.map +0 -1
- package/dist/locales/tr.cjs.map +0 -1
- package/dist/locales/tr.js.map +0 -1
- package/dist/locales/uk.cjs.map +0 -1
- package/dist/locales/uk.js.map +0 -1
- package/dist/markdown.cjs.map +0 -1
- package/dist/markdown.js.map +0 -1
- package/dist/mcp-app-sandbox.cjs.map +0 -1
- package/dist/mcp-app-sandbox.js.map +0 -1
- package/dist/mcp-app.cjs.map +0 -1
- package/dist/mcp-app.js.map +0 -1
- package/dist/pipeline.cjs.map +0 -1
- package/dist/pipeline.js.map +0 -1
package/dist/controller.d.cts
CHANGED
|
@@ -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 };
|
package/dist/controller.d.ts
CHANGED
|
@@ -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 };
|