@dudko.dev/agent-web-ui 0.0.5 → 0.0.7
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 +81 -3
- package/dist/{chunk-NHU6WQM5.js → chunk-3TMUUU3O.js} +424 -0
- package/dist/{chunk-627OXMFG.js → chunk-HIHUK7YA.js} +5 -0
- package/dist/{chunk-S5AHUAFG.js → chunk-JEW2ZWYX.js} +4 -0
- package/dist/{chunk-VZCQXE3P.js → chunk-UO2Q7AIV.js} +4 -0
- package/dist/{chunk-V33T6VX3.js → chunk-VG5NLFI5.js} +4 -0
- package/dist/controller.cjs +460 -16
- package/dist/controller.d.cts +53 -5
- package/dist/controller.d.ts +53 -5
- package/dist/controller.js +58 -17
- package/dist/{en-Dg2MtzcJ.d.cts → en-CPCAidve.d.cts} +4 -0
- package/dist/{en-Dg2MtzcJ.d.ts → en-CPCAidve.d.ts} +4 -0
- package/dist/index.cjs +447 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +37 -1
- package/dist/{labels-ipy-ydkp.d.cts → labels-Dnh2tn8S.d.cts} +8 -0
- package/dist/{labels-CCPL7t17.d.ts → labels-h-grbo5N.d.ts} +8 -0
- package/dist/locales/be.cjs +9 -0
- package/dist/locales/be.d.cts +1 -1
- package/dist/locales/be.d.ts +1 -1
- package/dist/locales/be.js +5 -1
- package/dist/locales/bg.cjs +9 -0
- package/dist/locales/bg.d.cts +1 -1
- package/dist/locales/bg.d.ts +1 -1
- package/dist/locales/bg.js +5 -1
- package/dist/locales/ca.cjs +9 -0
- package/dist/locales/ca.d.cts +1 -1
- package/dist/locales/ca.d.ts +1 -1
- package/dist/locales/ca.js +5 -1
- package/dist/locales/cs.cjs +9 -0
- package/dist/locales/cs.d.cts +1 -1
- package/dist/locales/cs.d.ts +1 -1
- package/dist/locales/cs.js +5 -1
- package/dist/locales/da.cjs +9 -0
- package/dist/locales/da.d.cts +1 -1
- package/dist/locales/da.d.ts +1 -1
- package/dist/locales/da.js +5 -1
- package/dist/locales/de.cjs +9 -0
- package/dist/locales/de.d.cts +1 -1
- package/dist/locales/de.d.ts +1 -1
- package/dist/locales/de.js +5 -1
- package/dist/locales/el.cjs +9 -0
- package/dist/locales/el.d.cts +1 -1
- package/dist/locales/el.d.ts +1 -1
- package/dist/locales/el.js +5 -1
- package/dist/locales/en.cjs +9 -0
- package/dist/locales/en.d.cts +1 -1
- package/dist/locales/en.d.ts +1 -1
- package/dist/locales/en.js +5 -1
- package/dist/locales/es-419.cjs +9 -0
- package/dist/locales/es-419.d.cts +1 -1
- package/dist/locales/es-419.d.ts +1 -1
- package/dist/locales/es-419.js +2 -2
- package/dist/locales/es.cjs +9 -0
- package/dist/locales/es.d.cts +1 -1
- package/dist/locales/es.d.ts +1 -1
- package/dist/locales/es.js +2 -2
- package/dist/locales/fi.cjs +9 -0
- package/dist/locales/fi.d.cts +1 -1
- package/dist/locales/fi.d.ts +1 -1
- package/dist/locales/fi.js +5 -1
- package/dist/locales/fr-CA.cjs +9 -0
- package/dist/locales/fr-CA.d.cts +1 -1
- package/dist/locales/fr-CA.d.ts +1 -1
- package/dist/locales/fr-CA.js +2 -2
- package/dist/locales/fr.cjs +9 -0
- package/dist/locales/fr.d.cts +1 -1
- package/dist/locales/fr.d.ts +1 -1
- package/dist/locales/fr.js +2 -2
- package/dist/locales/gn.cjs +9 -0
- package/dist/locales/gn.d.cts +1 -1
- package/dist/locales/gn.d.ts +1 -1
- package/dist/locales/gn.js +5 -1
- package/dist/locales/hr.cjs +9 -0
- package/dist/locales/hr.d.cts +1 -1
- package/dist/locales/hr.d.ts +1 -1
- package/dist/locales/hr.js +5 -1
- package/dist/locales/ht.cjs +9 -0
- package/dist/locales/ht.d.cts +1 -1
- package/dist/locales/ht.d.ts +1 -1
- package/dist/locales/ht.js +5 -1
- package/dist/locales/hu.cjs +9 -0
- package/dist/locales/hu.d.cts +1 -1
- package/dist/locales/hu.d.ts +1 -1
- package/dist/locales/hu.js +5 -1
- package/dist/locales/index.cjs +5 -0
- package/dist/locales/index.d.cts +3 -3
- package/dist/locales/index.d.ts +3 -3
- package/dist/locales/index.js +1 -1
- package/dist/locales/it.cjs +9 -0
- package/dist/locales/it.d.cts +1 -1
- package/dist/locales/it.d.ts +1 -1
- package/dist/locales/it.js +5 -1
- package/dist/locales/nb.cjs +9 -0
- package/dist/locales/nb.d.cts +1 -1
- package/dist/locales/nb.d.ts +1 -1
- package/dist/locales/nb.js +5 -1
- package/dist/locales/nl.cjs +9 -0
- package/dist/locales/nl.d.cts +1 -1
- package/dist/locales/nl.d.ts +1 -1
- package/dist/locales/nl.js +5 -1
- package/dist/locales/pl.cjs +9 -0
- package/dist/locales/pl.d.cts +1 -1
- package/dist/locales/pl.d.ts +1 -1
- package/dist/locales/pl.js +5 -1
- package/dist/locales/pt-BR.cjs +9 -0
- package/dist/locales/pt-BR.d.cts +1 -1
- package/dist/locales/pt-BR.d.ts +1 -1
- package/dist/locales/pt-BR.js +5 -1
- package/dist/locales/pt.cjs +9 -0
- package/dist/locales/pt.d.cts +1 -1
- package/dist/locales/pt.d.ts +1 -1
- package/dist/locales/pt.js +5 -1
- package/dist/locales/qu.cjs +9 -0
- package/dist/locales/qu.d.cts +1 -1
- package/dist/locales/qu.d.ts +1 -1
- package/dist/locales/qu.js +5 -1
- package/dist/locales/ro.cjs +9 -0
- package/dist/locales/ro.d.cts +1 -1
- package/dist/locales/ro.d.ts +1 -1
- package/dist/locales/ro.js +5 -1
- package/dist/locales/ru.cjs +9 -0
- package/dist/locales/ru.d.cts +1 -1
- package/dist/locales/ru.d.ts +1 -1
- package/dist/locales/ru.js +5 -1
- package/dist/locales/sk.cjs +9 -0
- package/dist/locales/sk.d.cts +1 -1
- package/dist/locales/sk.d.ts +1 -1
- package/dist/locales/sk.js +5 -1
- package/dist/locales/sq.cjs +9 -0
- package/dist/locales/sq.d.cts +1 -1
- package/dist/locales/sq.d.ts +1 -1
- package/dist/locales/sq.js +5 -1
- package/dist/locales/sr-Latn.cjs +9 -0
- package/dist/locales/sr-Latn.d.cts +1 -1
- package/dist/locales/sr-Latn.d.ts +1 -1
- package/dist/locales/sr-Latn.js +2 -2
- package/dist/locales/sr.cjs +9 -0
- package/dist/locales/sr.d.cts +1 -1
- package/dist/locales/sr.d.ts +1 -1
- package/dist/locales/sr.js +2 -2
- package/dist/locales/sv.cjs +9 -0
- package/dist/locales/sv.d.cts +1 -1
- package/dist/locales/sv.d.ts +1 -1
- package/dist/locales/sv.js +5 -1
- package/dist/locales/tr.cjs +9 -0
- package/dist/locales/tr.d.cts +1 -1
- package/dist/locales/tr.d.ts +1 -1
- package/dist/locales/tr.js +5 -1
- package/dist/locales/uk.cjs +9 -0
- package/dist/locales/uk.d.cts +1 -1
- package/dist/locales/uk.d.ts +1 -1
- package/dist/locales/uk.js +5 -1
- package/dist/page-context-BAmw4p6d.d.cts +244 -0
- package/dist/page-context-BAmw4p6d.d.ts +244 -0
- package/dist/pipeline-format.cjs +842 -0
- package/dist/pipeline-format.d.cts +512 -0
- package/dist/pipeline-format.d.ts +512 -0
- package/dist/pipeline-format.js +788 -0
- package/dist/styles.css +55 -0
- package/dist/{types-CQquuZpl.d.cts → types-B5cyqkWY.d.cts} +1 -1
- package/dist/{types-CXZfZVP5.d.ts → types-BgNjWN5Z.d.ts} +1 -1
- package/package.json +12 -2
package/dist/controller.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { P as PageContextOptions, a as PageContext, b as PageContextCollector } from './page-context-BAmw4p6d.cjs';
|
|
2
|
+
export { c as createPageContextCollector, t as trackPageFocus } from './page-context-BAmw4p6d.cjs';
|
|
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.cjs';
|
|
3
5
|
import { ChatAttachment, ChatMessage, AgentUiState, ApprovalView } from './index.cjs';
|
|
@@ -36,9 +38,9 @@ interface RemoteAgentOptions {
|
|
|
36
38
|
* Every event, after the reducer folded it: the server agent's, a turn's start as the core's
|
|
37
39
|
* `run.start` and its end as `final` / `stopped` / `error` (as a local run's), the swarm's
|
|
38
40
|
* `turn.started` / `turn.ended` markers as they came. A run's `tool.approval-resolved` that only
|
|
39
|
-
* says it parked is not told.
|
|
41
|
+
* says it parked is not told. `info` says whether it is LIVE - see {@link RemoteEventInfo}.
|
|
40
42
|
*/
|
|
41
|
-
onEvent?: (event: AgentEvent) => void;
|
|
43
|
+
onEvent?: (event: AgentEvent, info: RemoteEventInfo) => void;
|
|
42
44
|
/** Cap the retained raw event log (default 200; 0 = unbounded). */
|
|
43
45
|
maxEvents?: number;
|
|
44
46
|
/**
|
|
@@ -49,6 +51,24 @@ 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;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What `onEvent` is told with an event. `live`: the event belongs to a turn that a message sent
|
|
63
|
+
* THROUGH THIS CONTROLLER started (`run` / `send`), as it happens - not a turn replayed from the
|
|
64
|
+
* session's log (a reload, `loadChat`, a session given at start), nor one another tab or client
|
|
65
|
+
* started on the same session. An event of the controller's own (a request that failed) is live.
|
|
66
|
+
* `id`: the event's cursor on the gateway's stream (`<turn>:<attempt>:<seq>`), unique in the
|
|
67
|
+
* session; absent for the controller's own events.
|
|
68
|
+
*/
|
|
69
|
+
interface RemoteEventInfo {
|
|
70
|
+
live: boolean;
|
|
71
|
+
id?: string;
|
|
52
72
|
}
|
|
53
73
|
/** One frame of the gateway's stream: `id:` (the cursor) and the JSON of `data:`. */
|
|
54
74
|
interface RemoteFrame {
|
|
@@ -157,6 +177,13 @@ interface AgentControllerOptions {
|
|
|
157
177
|
* stopping it is explicit: `sendRemote` / `stopRemote`. Consent requests stay in that tab.
|
|
158
178
|
*/
|
|
159
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;
|
|
160
187
|
}
|
|
161
188
|
interface ApproveOptions {
|
|
162
189
|
/** Also allow this tool for the rest of the agent's life ("always allow"). */
|
|
@@ -175,6 +202,16 @@ interface RunGoalOptions {
|
|
|
175
202
|
files?: RunFile[];
|
|
176
203
|
/** What the transcript shows as attached to this turn (thumbnails, chips). */
|
|
177
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;
|
|
178
215
|
}
|
|
179
216
|
/**
|
|
180
217
|
* A tool call an MCP App asks for, as `approveAppToolCall` takes it: the core's request, plus
|
|
@@ -250,7 +287,18 @@ interface AgentControllerActions {
|
|
|
250
287
|
* flight or the text is empty — then use `run`. Watch `queued` / `notes`. Only this tab's run:
|
|
251
288
|
* for the conversation's run in another tab, `sendRemote`.
|
|
252
289
|
*/
|
|
253
|
-
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;
|
|
254
302
|
/** Stop ONE running subagent (`SubagentView.id`); the run and its siblings go on. */
|
|
255
303
|
stopSubagent: (id: string) => boolean;
|
|
256
304
|
/**
|
|
@@ -356,5 +404,5 @@ declare const createInitialAgentSnapshot: (config: BrowserAgentConfig) => AgentC
|
|
|
356
404
|
*/
|
|
357
405
|
declare const createAgentController: (initialConfig: BrowserAgentConfig, initialOptions?: AgentControllerOptions) => AgentController;
|
|
358
406
|
|
|
359
|
-
export { createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
|
|
360
|
-
export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, 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 };
|
package/dist/controller.d.ts
CHANGED
|
@@ -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';
|
|
@@ -36,9 +38,9 @@ interface RemoteAgentOptions {
|
|
|
36
38
|
* Every event, after the reducer folded it: the server agent's, a turn's start as the core's
|
|
37
39
|
* `run.start` and its end as `final` / `stopped` / `error` (as a local run's), the swarm's
|
|
38
40
|
* `turn.started` / `turn.ended` markers as they came. A run's `tool.approval-resolved` that only
|
|
39
|
-
* says it parked is not told.
|
|
41
|
+
* says it parked is not told. `info` says whether it is LIVE - see {@link RemoteEventInfo}.
|
|
40
42
|
*/
|
|
41
|
-
onEvent?: (event: AgentEvent) => void;
|
|
43
|
+
onEvent?: (event: AgentEvent, info: RemoteEventInfo) => void;
|
|
42
44
|
/** Cap the retained raw event log (default 200; 0 = unbounded). */
|
|
43
45
|
maxEvents?: number;
|
|
44
46
|
/**
|
|
@@ -49,6 +51,24 @@ 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;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What `onEvent` is told with an event. `live`: the event belongs to a turn that a message sent
|
|
63
|
+
* THROUGH THIS CONTROLLER started (`run` / `send`), as it happens - not a turn replayed from the
|
|
64
|
+
* session's log (a reload, `loadChat`, a session given at start), nor one another tab or client
|
|
65
|
+
* started on the same session. An event of the controller's own (a request that failed) is live.
|
|
66
|
+
* `id`: the event's cursor on the gateway's stream (`<turn>:<attempt>:<seq>`), unique in the
|
|
67
|
+
* session; absent for the controller's own events.
|
|
68
|
+
*/
|
|
69
|
+
interface RemoteEventInfo {
|
|
70
|
+
live: boolean;
|
|
71
|
+
id?: string;
|
|
52
72
|
}
|
|
53
73
|
/** One frame of the gateway's stream: `id:` (the cursor) and the JSON of `data:`. */
|
|
54
74
|
interface RemoteFrame {
|
|
@@ -157,6 +177,13 @@ interface AgentControllerOptions {
|
|
|
157
177
|
* stopping it is explicit: `sendRemote` / `stopRemote`. Consent requests stay in that tab.
|
|
158
178
|
*/
|
|
159
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;
|
|
160
187
|
}
|
|
161
188
|
interface ApproveOptions {
|
|
162
189
|
/** Also allow this tool for the rest of the agent's life ("always allow"). */
|
|
@@ -175,6 +202,16 @@ interface RunGoalOptions {
|
|
|
175
202
|
files?: RunFile[];
|
|
176
203
|
/** What the transcript shows as attached to this turn (thumbnails, chips). */
|
|
177
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;
|
|
178
215
|
}
|
|
179
216
|
/**
|
|
180
217
|
* A tool call an MCP App asks for, as `approveAppToolCall` takes it: the core's request, plus
|
|
@@ -250,7 +287,18 @@ interface AgentControllerActions {
|
|
|
250
287
|
* flight or the text is empty — then use `run`. Watch `queued` / `notes`. Only this tab's run:
|
|
251
288
|
* for the conversation's run in another tab, `sendRemote`.
|
|
252
289
|
*/
|
|
253
|
-
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;
|
|
254
302
|
/** Stop ONE running subagent (`SubagentView.id`); the run and its siblings go on. */
|
|
255
303
|
stopSubagent: (id: string) => boolean;
|
|
256
304
|
/**
|
|
@@ -356,5 +404,5 @@ declare const createInitialAgentSnapshot: (config: BrowserAgentConfig) => AgentC
|
|
|
356
404
|
*/
|
|
357
405
|
declare const createAgentController: (initialConfig: BrowserAgentConfig, initialOptions?: AgentControllerOptions) => AgentController;
|
|
358
406
|
|
|
359
|
-
export { createAgentController, createInitialAgentSnapshot, createInitialRemoteSnapshot, createRemoteAgentController, createSseParser, parseRemoteCursor, remoteEventOf, remoteEventScope };
|
|
360
|
-
export type { AgentController, AgentControllerActions, AgentControllerOptions, AgentControllerSnapshot, AgentControllerUpdate, AppToolCall, ApproveOptions, RemoteAgentHeaders, RemoteAgentOptions, 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 };
|
package/dist/controller.js
CHANGED
|
@@ -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
|
-
|
|
16
|
+
remoteAnswerOf,
|
|
17
|
+
trackPageFocus,
|
|
18
|
+
withoutAskOnSend
|
|
19
|
+
} from "./chunk-3TMUUU3O.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);
|
|
@@ -141,6 +145,9 @@ var createRemoteAgentController = (options) => {
|
|
|
141
145
|
let turnIds = [];
|
|
142
146
|
let turnFinal = false;
|
|
143
147
|
let waiting = [];
|
|
148
|
+
const sentHere = /* @__PURE__ */ new Set();
|
|
149
|
+
let frameInfo;
|
|
150
|
+
const turnIsOurs = () => turnIds.some((id) => sentHere.has(id));
|
|
144
151
|
const runs = /* @__PURE__ */ new Map();
|
|
145
152
|
const fold = (action, attempt = 0, scope) => {
|
|
146
153
|
if (turn) {
|
|
@@ -158,7 +165,7 @@ var createRemoteAgentController = (options) => {
|
|
|
158
165
|
};
|
|
159
166
|
const tell = (e) => {
|
|
160
167
|
try {
|
|
161
|
-
options.onEvent?.(e);
|
|
168
|
+
options.onEvent?.(e, frameInfo ?? { live: true });
|
|
162
169
|
} catch {
|
|
163
170
|
}
|
|
164
171
|
};
|
|
@@ -214,13 +221,26 @@ var createRemoteAgentController = (options) => {
|
|
|
214
221
|
}
|
|
215
222
|
const raw = parsed?.event;
|
|
216
223
|
if (!raw || typeof raw !== "object" || typeof raw.type !== "string") return;
|
|
224
|
+
try {
|
|
225
|
+
foldFrame(frame, raw);
|
|
226
|
+
} finally {
|
|
227
|
+
frameInfo = void 0;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const foldFrame = (frame, raw) => {
|
|
217
231
|
const cursor2 = parseRemoteCursor(frame.id);
|
|
232
|
+
const info = () => ({
|
|
233
|
+
live: turnIsOurs(),
|
|
234
|
+
...frame.id !== void 0 ? { id: frame.id } : {}
|
|
235
|
+
});
|
|
236
|
+
frameInfo = info();
|
|
218
237
|
const attempt = cursor2?.attempt ?? 0;
|
|
219
238
|
const shown = remoteEventOf(raw);
|
|
220
239
|
if (raw.type === "turn.started") {
|
|
221
240
|
const ids = Array.isArray(raw.messageIds) ? raw.messageIds.filter((x) => typeof x === "string") : [];
|
|
222
241
|
waiting = waiting.filter((w) => !ids.includes(w.id));
|
|
223
242
|
turnIds = ids;
|
|
243
|
+
frameInfo = info();
|
|
224
244
|
turnFinal = false;
|
|
225
245
|
apply({ type: "status", status: "running" });
|
|
226
246
|
turn = { number: cursor2?.turn ?? 0, start: state, entries: [] };
|
|
@@ -389,9 +409,11 @@ var createRemoteAgentController = (options) => {
|
|
|
389
409
|
apply({ type: "status", status: "running" });
|
|
390
410
|
apply({ type: "submitted", goal: shown });
|
|
391
411
|
waiting.push({ id, text });
|
|
412
|
+
sentHere.add(id);
|
|
392
413
|
const ended = new Promise((resolve) => runs.set(id, resolve));
|
|
393
414
|
try {
|
|
394
|
-
await
|
|
415
|
+
const context = runOptions?.context === false ? void 0 : runOptions?.context ?? await pageContexts.collect({ ask: true });
|
|
416
|
+
await sendMessage(id, text, context);
|
|
395
417
|
} catch (err) {
|
|
396
418
|
runs.delete(id);
|
|
397
419
|
waiting = waiting.filter((w) => w.id !== id);
|
|
@@ -403,11 +425,12 @@ var createRemoteAgentController = (options) => {
|
|
|
403
425
|
}
|
|
404
426
|
return ended;
|
|
405
427
|
};
|
|
406
|
-
const sendMessage = async (id, text) => {
|
|
428
|
+
const sendMessage = async (id, text, context) => {
|
|
407
429
|
const sid = sessionId;
|
|
430
|
+
const withContext = context && Object.keys(context).length ? { context } : {};
|
|
408
431
|
if (sid) {
|
|
409
432
|
try {
|
|
410
|
-
await post(`/sessions/${encodeURIComponent(sid)}/messages`, { text, id });
|
|
433
|
+
await post(`/sessions/${encodeURIComponent(sid)}/messages`, { text, id, ...withContext });
|
|
411
434
|
return;
|
|
412
435
|
} catch (err) {
|
|
413
436
|
const gone = err instanceof GatewayError && (err.status === 404 || err.status === 409 && err.code === "session_ended");
|
|
@@ -415,7 +438,7 @@ var createRemoteAgentController = (options) => {
|
|
|
415
438
|
forgetSession();
|
|
416
439
|
}
|
|
417
440
|
}
|
|
418
|
-
const made = await post("/sessions", { message: text, id });
|
|
441
|
+
const made = await post("/sessions", { message: text, id, ...withContext });
|
|
419
442
|
if (disposed) return;
|
|
420
443
|
if (typeof made?.sessionId !== "string")
|
|
421
444
|
throw new Error("the agent’s server started no session");
|
|
@@ -426,19 +449,23 @@ var createRemoteAgentController = (options) => {
|
|
|
426
449
|
setSession(made.sessionId);
|
|
427
450
|
void openStream();
|
|
428
451
|
};
|
|
429
|
-
const send = (text) => {
|
|
452
|
+
const send = (text, sendOptions) => {
|
|
430
453
|
const clean = typeof text === "string" ? text.trim() : "";
|
|
431
454
|
if (disposed || state.status !== "running" || !clean || !sessionId) return false;
|
|
432
455
|
const id = newMessageId();
|
|
433
456
|
waiting.push({ id, text: clean });
|
|
457
|
+
sentHere.add(id);
|
|
434
458
|
fold(event({ type: "message.queued", id, text: clean }));
|
|
435
|
-
void
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
+
});
|
|
442
469
|
return true;
|
|
443
470
|
};
|
|
444
471
|
const stop = () => {
|
|
@@ -527,6 +554,8 @@ var createRemoteAgentController = (options) => {
|
|
|
527
554
|
stopRemote: () => {
|
|
528
555
|
},
|
|
529
556
|
send,
|
|
557
|
+
previewPageContext: () => pageContexts.preview(),
|
|
558
|
+
pageContextCollector: () => pageContexts,
|
|
530
559
|
sendRemote: () => false,
|
|
531
560
|
stopSubagent: () => false,
|
|
532
561
|
forgetSkill: async () => false,
|
|
@@ -588,6 +617,7 @@ var createInitialAgentSnapshot = (config) => snapshotOf2(createInitialAgentState
|
|
|
588
617
|
var createAgentController = (initialConfig, initialOptions = {}) => {
|
|
589
618
|
let config = initialConfig;
|
|
590
619
|
let options = initialOptions;
|
|
620
|
+
const pageContexts = createPageContextCollector(() => options.pageContext);
|
|
591
621
|
let disposed = false;
|
|
592
622
|
let state = createInitialAgentState();
|
|
593
623
|
let pendingQuestions = [];
|
|
@@ -771,10 +801,12 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
|
|
|
771
801
|
});
|
|
772
802
|
}
|
|
773
803
|
try {
|
|
804
|
+
const context = runOptions?.context === false ? void 0 : runOptions?.context ?? await pageContexts.collect({ ask: true });
|
|
774
805
|
const result = await current.run(goal, {
|
|
775
806
|
signal: controller.signal,
|
|
776
807
|
control: runControl,
|
|
777
808
|
sessionId,
|
|
809
|
+
...context && Object.keys(context).length ? { context } : {},
|
|
778
810
|
...runOptions?.images?.length ? { images: runOptions.images } : {},
|
|
779
811
|
...runOptions?.files?.length ? { files: runOptions.files } : {},
|
|
780
812
|
onEvent: (event) => {
|
|
@@ -832,7 +864,12 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
|
|
|
832
864
|
}
|
|
833
865
|
}
|
|
834
866
|
};
|
|
835
|
-
const send = (text) =>
|
|
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();
|
|
836
873
|
let remoteSends = 0;
|
|
837
874
|
const sendRemote = (text) => {
|
|
838
875
|
const current = watch;
|
|
@@ -1010,6 +1047,8 @@ var createAgentController = (initialConfig, initialOptions = {}) => {
|
|
|
1010
1047
|
stop,
|
|
1011
1048
|
stopRemote,
|
|
1012
1049
|
send,
|
|
1050
|
+
previewPageContext,
|
|
1051
|
+
pageContextCollector: () => pageContexts,
|
|
1013
1052
|
sendRemote,
|
|
1014
1053
|
stopSubagent,
|
|
1015
1054
|
forgetSkill,
|
|
@@ -1031,9 +1070,11 @@ export {
|
|
|
1031
1070
|
createAgentController,
|
|
1032
1071
|
createInitialAgentSnapshot,
|
|
1033
1072
|
createInitialRemoteSnapshot,
|
|
1073
|
+
createPageContextCollector,
|
|
1034
1074
|
createRemoteAgentController,
|
|
1035
1075
|
createSseParser,
|
|
1036
1076
|
parseRemoteCursor,
|
|
1037
1077
|
remoteEventOf,
|
|
1038
|
-
remoteEventScope
|
|
1078
|
+
remoteEventScope,
|
|
1079
|
+
trackPageFocus
|
|
1039
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;
|