agents 0.32.0 → 0.34.0
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 +1 -1
- package/dist/{agent-routing-vVMA7m8Y.d.ts → agent-routing-BSoZzNiP.d.ts} +537 -373
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-gGXXkf1z.d.ts → agent-tools-Be-hpRpH.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-sdk-Kon40i0q.js → ai-sdk-CRMlEBX7.js} +75 -44
- package/dist/ai-sdk-CRMlEBX7.js.map +1 -0
- package/dist/browser/ai.js +2 -3
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +33 -21
- package/dist/browser/index.js +937 -4
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/tools/ai-sdk.d.ts +4 -4
- package/dist/browser/tools/ai-sdk.js +9 -3
- package/dist/browser/tools/ai-sdk.js.map +1 -1
- package/dist/browser/tools/pi.d.ts +11 -8
- package/dist/browser/tools/pi.js +58 -11
- package/dist/browser/tools/pi.js.map +1 -1
- package/dist/browser/tools/tanstack-ai.d.ts +4 -4
- package/dist/browser/tools/tanstack-ai.js +3 -3
- package/dist/browser/tools/tanstack-ai.js.map +1 -1
- package/dist/{browser-D9RNpJuT.d.ts → browser-C9T74n4c.d.ts} +302 -95
- package/dist/browser-tool-DOqT1oSD.js +360 -0
- package/dist/browser-tool-DOqT1oSD.js.map +1 -0
- package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-DxAYQY9T.d.ts} +2 -2
- package/dist/capability-DBAKc6UZ.js.map +1 -1
- package/dist/{capability-runner-BiVUtjqC.d.ts → capability-runner-uFOdSANC.d.ts} +3 -2
- package/dist/chat/index.d.ts +37 -6
- package/dist/chat/index.js +39 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.js +1 -0
- package/dist/chat/react.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +62 -60
- package/dist/client-CkT8voRY.js +3740 -0
- package/dist/client-CkT8voRY.js.map +1 -0
- package/dist/{client-eSfgYvd3.d.ts → client-DqS6oequ.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-CM-uuxKM.js → connector-Bphz6wIw.js} +414 -3
- package/dist/connector-Bphz6wIw.js.map +1 -0
- package/dist/{conversations-FjHDRZyD.d.ts → conversations-CoAYNW_q.d.ts} +4 -4
- package/dist/{current-agent-CKgT5d1O.d.ts → current-agent-DShbQHDO.d.ts} +24 -3
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{do-oauth-client-provider-DtNqv7oj.d.ts → do-oauth-client-provider-BsT8-vtd.d.ts} +22 -2
- package/dist/{durable-object-lifecycle-DOI_bzCH.d.ts → durable-object-lifecycle-CRCA6O0W.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/{gateway-BFO6vRDn.d.ts → gateway-Dz8zyZBJ.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/pi/index.d.ts +200 -37
- package/dist/harness/pi/index.js +202 -100
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/{images-CfuRCjwq.js → images-D4gtE06D.js} +119 -27
- package/dist/images-D4gtE06D.js.map +1 -0
- package/dist/{index-8k4qsX1T.d.ts → index-BXVgv6tp.d.ts} +4 -4
- package/dist/{index-BEL3ZV-s.d.ts → index-Cs7Ed9la.d.ts} +2 -2
- package/dist/{index-CBt8oRJt.d.ts → index-XiZxauMU.d.ts} +3 -3
- package/dist/index.d.ts +21 -21
- package/dist/index.js +2 -2
- package/dist/{input-schema-BQykTEp_.js → input-schema-D6GilRXI.js} +3 -3
- package/dist/input-schema-D6GilRXI.js.map +1 -0
- package/dist/{input-schema-B0Etuo-o.js → input-schema-y8W5bOdM.js} +3 -3
- package/dist/input-schema-y8W5bOdM.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-v1rKHV2C.js → lifecycle-CB5Dmtrt.js} +126 -38
- package/dist/lifecycle-CB5Dmtrt.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +45 -2
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +42 -36
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/index.d.ts +16 -16
- package/dist/mcp/index.js +2 -2
- package/dist/models/ai-sdk/index.d.ts +9 -5
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +3 -3
- package/dist/models/opencode/index.js +2 -2
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +4 -4
- package/dist/models/pi-ai/index.js +64 -170
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-CiIsJHXR.d.ts → options-CiXaymmZ.d.ts} +2 -2
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-CcIjVYTE.js → queue-B_wl6K0Z.js} +24 -5
- package/dist/queue-B_wl6K0Z.js.map +1 -0
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-BCLESHSC.d.ts → scheduler-CTpR0Ct0.d.ts} +2 -2
- package/dist/{scheduler-FIHv2-kJ.js → scheduler-DGNEmxQR.js} +2 -1
- package/dist/scheduler-DGNEmxQR.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
- package/dist/session-CRY0bGiI.js.map +1 -0
- package/dist/sessions/index.d.ts +1 -1
- package/dist/{settings-Dk2il2Hf.js → settings-D2F_qONv.js} +11 -2
- package/dist/settings-D2F_qONv.js.map +1 -0
- package/dist/{src-DoGNJ4Ud.js → src-BO1FdLK1.js} +145 -86
- package/dist/src-BO1FdLK1.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{streams-vrCtbUIn.d.ts → streams-CAZxZBDg.d.ts} +2 -2
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-BN_5AWqI.js → tasks-Cf_UfEO4.js} +2 -1
- package/dist/{tasks-BN_5AWqI.js.map → tasks-Cf_UfEO4.js.map} +1 -1
- package/dist/{tasks-E89KdwkS.d.ts → tasks-Cs8ilctE.d.ts} +2 -2
- package/dist/{tool-DkT_DJBm.js → tool-CmAGY6Fo.js} +24 -3
- package/dist/tool-CmAGY6Fo.js.map +1 -0
- package/dist/{tool-CxKsvxjm.js → tool-Kxcj8_22.js} +24 -4
- package/dist/tool-Kxcj8_22.js.map +1 -0
- package/dist/{tool-helpers-BI7ifO2S.js → tool-helpers-F3_Wy2YX.js} +2 -2
- package/dist/{tool-helpers-BI7ifO2S.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
- package/dist/{transport-5moD2pW5.d.ts → transport-hV8AW4Bv.d.ts} +45 -12
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.js +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +2 -2
- package/dist/web/fetch/tools/pi.d.ts +9 -7
- package/dist/web/fetch/tools/pi.js +31 -7
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +2 -2
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.d.ts +9 -4
- package/dist/web/search/tools/pi.js +27 -11
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C6SJtWCJ.js → websockets-W4uhRg4-.js} +68 -5
- package/dist/websockets-W4uhRg4-.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +30 -4
- package/docs/browse-the-web.md +50 -3
- package/docs/chat-agents.md +13 -10
- package/docs/client-tools-continuation.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/configuration.md +6 -3
- package/docs/cross-domain-authentication.md +1 -1
- package/docs/fetch-the-web.md +20 -0
- package/docs/harnesses/pi.md +242 -33
- package/docs/harnesses/think.md +1 -1
- package/docs/http-websockets.md +40 -32
- package/docs/human-in-the-loop.md +2 -2
- package/docs/lifecycle.md +56 -0
- package/docs/mcp-client.md +104 -7
- package/docs/models-pi-ai.md +24 -10
- package/docs/models.md +42 -17
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +3 -6
- package/docs/search-the-web.md +10 -0
- package/docs/voice.md +1 -1
- package/package.json +16 -9
- package/dist/ai-sdk-Kon40i0q.js.map +0 -1
- package/dist/browser-1eUbPvC2.js +0 -931
- package/dist/browser-1eUbPvC2.js.map +0 -1
- package/dist/browser-tool-DRan7Lk6.js +0 -497
- package/dist/browser-tool-DRan7Lk6.js.map +0 -1
- package/dist/client-DMWujQJ1.js +0 -2325
- package/dist/client-DMWujQJ1.js.map +0 -1
- package/dist/connector-CM-uuxKM.js.map +0 -1
- package/dist/images-CfuRCjwq.js.map +0 -1
- package/dist/input-schema-B0Etuo-o.js.map +0 -1
- package/dist/input-schema-BQykTEp_.js.map +0 -1
- package/dist/lifecycle-v1rKHV2C.js.map +0 -1
- package/dist/queue-CcIjVYTE.js.map +0 -1
- package/dist/scheduler-FIHv2-kJ.js.map +0 -1
- package/dist/session-7CDgVE0z.js.map +0 -1
- package/dist/settings-Dk2il2Hf.js.map +0 -1
- package/dist/src-DoGNJ4Ud.js.map +0 -1
- package/dist/tool-CxKsvxjm.js.map +0 -1
- package/dist/tool-DkT_DJBm.js.map +0 -1
- package/dist/websockets-C6SJtWCJ.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
d as LifecycleRouteContext,
|
|
3
3
|
s as LifecycleCapability
|
|
4
|
-
} from "./capability-runner-
|
|
4
|
+
} from "./capability-runner-uFOdSANC.js";
|
|
5
5
|
import {
|
|
6
6
|
n as InternalHostInfo,
|
|
7
7
|
r as InternalHostMessage,
|
|
@@ -17,6 +17,70 @@ import {
|
|
|
17
17
|
} from "./session-store-B7Ca-u1t.js";
|
|
18
18
|
|
|
19
19
|
//#region src/browser/spec.d.ts
|
|
20
|
+
/** A parameter, return value, or type property in the raw protocol. */
|
|
21
|
+
interface RawCdpField {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
optional?: boolean;
|
|
25
|
+
experimental?: boolean;
|
|
26
|
+
deprecated?: boolean;
|
|
27
|
+
type?: string;
|
|
28
|
+
$ref?: string;
|
|
29
|
+
enum?: string[];
|
|
30
|
+
items?: {
|
|
31
|
+
type?: string;
|
|
32
|
+
$ref?: string;
|
|
33
|
+
enum?: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface RawCdpCommand {
|
|
37
|
+
name: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
experimental?: boolean;
|
|
40
|
+
deprecated?: boolean;
|
|
41
|
+
parameters?: RawCdpField[];
|
|
42
|
+
returns?: RawCdpField[];
|
|
43
|
+
}
|
|
44
|
+
interface RawCdpEvent {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
experimental?: boolean;
|
|
48
|
+
deprecated?: boolean;
|
|
49
|
+
parameters?: RawCdpField[];
|
|
50
|
+
}
|
|
51
|
+
interface RawCdpType {
|
|
52
|
+
id: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
experimental?: boolean;
|
|
55
|
+
deprecated?: boolean;
|
|
56
|
+
type?: string;
|
|
57
|
+
enum?: string[];
|
|
58
|
+
properties?: RawCdpField[];
|
|
59
|
+
items?: {
|
|
60
|
+
type?: string;
|
|
61
|
+
$ref?: string;
|
|
62
|
+
enum?: string[];
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Raw CDP protocol domain from `/json/protocol` */
|
|
66
|
+
interface RawCdpDomain {
|
|
67
|
+
domain: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
experimental?: boolean;
|
|
70
|
+
deprecated?: boolean;
|
|
71
|
+
commands?: RawCdpCommand[];
|
|
72
|
+
events?: RawCdpEvent[];
|
|
73
|
+
types?: RawCdpType[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The raw Chrome DevTools Protocol: the JSON Chrome serves at
|
|
77
|
+
* `/json/protocol` and publishes as `browser_protocol.json` and
|
|
78
|
+
* `js_protocol.json`. Other top-level fields, such as `version`, are allowed
|
|
79
|
+
* and ignored. `normalizeCdpSpec` turns it into a `SearchableCdpSpec`.
|
|
80
|
+
*/
|
|
81
|
+
interface RawCdpProtocol {
|
|
82
|
+
domains?: RawCdpDomain[];
|
|
83
|
+
}
|
|
20
84
|
/**
|
|
21
85
|
* The element type of an array field or type. `$ref` is always
|
|
22
86
|
* domain-qualified (`"Network.Cookie"`), matching a type's `name`.
|
|
@@ -91,76 +155,21 @@ interface CdpSpecSource {
|
|
|
91
155
|
*/
|
|
92
156
|
sessionId?: string;
|
|
93
157
|
}
|
|
94
|
-
/** Load the (cached) searchable CDP spec for a browser source. */
|
|
95
|
-
declare function loadCdpSpec(source: CdpSpecSource): Promise<SearchableCdpSpec>;
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/browser/providers/browser-run.d.ts
|
|
98
|
-
/**
|
|
99
|
-
* Browser Run settings applied every time a browser is created — including
|
|
100
|
-
* when a lost browser is replaced — so options like guardrails survive a
|
|
101
|
-
* restart.
|
|
102
|
-
*/
|
|
103
|
-
interface BrowserRunOptions<S = Record<string, unknown>> {
|
|
104
|
-
/**
|
|
105
|
-
* Platform `keep_alive` in milliseconds: how long an idle browser lives.
|
|
106
|
-
* Defaults to {@link BROWSER_SESSION_KEEP_ALIVE_DEFAULT_MS} (10 minutes).
|
|
107
|
-
* Browser Run accepts up to {@link BROWSER_SESSION_KEEP_ALIVE_MAX_MS}
|
|
108
|
-
* (20 minutes).
|
|
109
|
-
*/
|
|
110
|
-
keepAliveMs?: number;
|
|
111
|
-
/** Opt into Browser Run session recording (rrweb capture). */
|
|
112
|
-
recording?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Hostname guardrails, fixed at launch for every connection. They don't
|
|
115
|
-
* apply to `internalHosts`: `allowedDomains: []` leaves the browser able
|
|
116
|
-
* to open internal hostnames only.
|
|
117
|
-
*/
|
|
118
|
-
guardrails?: BrowserSessionGuardrails;
|
|
119
|
-
/**
|
|
120
|
-
* Hostnames only this browser can open, served by your agent or a Worker
|
|
121
|
-
* instead of the internet. Plain http on port 80; no HTTPS or WebSockets.
|
|
122
|
-
* Deployed Workers only: in local dev the browser starts without them.
|
|
123
|
-
*
|
|
124
|
-
* Any http page open in the browser can send requests to these hosts, so
|
|
125
|
-
* a host whose requests have side effects should check `Origin` (see
|
|
126
|
-
* `InternalHost.fetch`).
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* browserRun(this.env.BROWSER, {
|
|
131
|
-
* internalHosts: {
|
|
132
|
-
* router: this.ctx.exports.InternalHostRouter,
|
|
133
|
-
* hosts: {
|
|
134
|
-
* "preview.internal": {
|
|
135
|
-
* description: "A dev server in your sandbox",
|
|
136
|
-
* target: z.object({ port: z.number().int() }),
|
|
137
|
-
* fetch: (request, { port }) => this.sandboxPort(port, request)
|
|
138
|
-
* }
|
|
139
|
-
* }
|
|
140
|
-
* }
|
|
141
|
-
* });
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
internalHosts?: InternalHostsOptions<S>;
|
|
145
|
-
}
|
|
146
|
-
/** A {@link Browser} provider backed by Cloudflare Browser Run. */
|
|
147
|
-
interface BrowserRunProvider {
|
|
148
|
-
readonly kind: "browser-run";
|
|
149
|
-
readonly binding: BrowserBinding;
|
|
150
|
-
readonly options: BrowserRunOptions;
|
|
151
|
-
}
|
|
152
158
|
/**
|
|
153
|
-
*
|
|
159
|
+
* Normalize Chrome's raw protocol JSON into the spec a `BrowserSource`
|
|
160
|
+
* connection's `spec()` returns (a `SearchableCdpSpec`): every `$ref`
|
|
161
|
+
* domain-qualified (`"Page.FrameId"`), commands with `method`, events with
|
|
162
|
+
* `event`, types with `name`, and empty arrays where the protocol omits them.
|
|
154
163
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
164
|
+
* Use it for a source that has no `/json/protocol` endpoint or Browser Run
|
|
165
|
+
* binding for `loadCdpSpec`. Chrome publishes the protocol in two files,
|
|
166
|
+
* `browser_protocol.json` and `js_protocol.json`; merge their `domains` into
|
|
167
|
+
* one object before calling. Unlike `loadCdpSpec`, the spec is not cached, so
|
|
168
|
+
* keep it yourself (for example in a module-level constant).
|
|
159
169
|
*/
|
|
160
|
-
declare function
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
): BrowserRunProvider;
|
|
170
|
+
declare function normalizeCdpSpec(protocol: RawCdpProtocol): SearchableCdpSpec;
|
|
171
|
+
/** Load the (cached) searchable CDP spec for a browser source. */
|
|
172
|
+
declare function loadCdpSpec(source: CdpSpecSource): Promise<SearchableCdpSpec>;
|
|
164
173
|
//#endregion
|
|
165
174
|
//#region src/browser/session.d.ts
|
|
166
175
|
/**
|
|
@@ -177,10 +186,10 @@ interface BrowserSource {
|
|
|
177
186
|
*/
|
|
178
187
|
connect(options?: BrowserConnectOptions): Promise<BrowserConnection>;
|
|
179
188
|
/**
|
|
180
|
-
* The browser's internal hostnames, when it has any.
|
|
181
|
-
*
|
|
189
|
+
* The browser's internal hostnames, when it has any. The docs list them,
|
|
190
|
+
* and {@link BrowserSession.functions} adds the hosts functions.
|
|
182
191
|
*/
|
|
183
|
-
readonly internalHosts?: BrowserInternalHosts;
|
|
192
|
+
readonly internalHosts?: BrowserInternalHosts | undefined;
|
|
184
193
|
}
|
|
185
194
|
interface BrowserSessionOptions {
|
|
186
195
|
/**
|
|
@@ -194,6 +203,35 @@ interface BrowserSessionOptions {
|
|
|
194
203
|
* JSON. Defaults to 1,000,000 bytes.
|
|
195
204
|
*/
|
|
196
205
|
maxResultBytes?: number;
|
|
206
|
+
/**
|
|
207
|
+
* Lock the scope on this browser: the session takes the scope's lock at
|
|
208
|
+
* its first call (or at {@link BrowserSession.lock}) and holds it until it
|
|
209
|
+
* closes. Other locking sessions in the scope wait for the lock, in order,
|
|
210
|
+
* rather than fail, so their calls never interleave. Sessions without it
|
|
211
|
+
* don't wait and aren't waited for. Locks are per isolate, which is per
|
|
212
|
+
* Durable Object.
|
|
213
|
+
*
|
|
214
|
+
* Use it when several runs in one scope can start together (parallel
|
|
215
|
+
* tool calls, say) and must not see each other's navigation.
|
|
216
|
+
*
|
|
217
|
+
* Only `close()` releases the lock: not aborting a signal, losing the
|
|
218
|
+
* browser, or dropping the session. Close a locking session in `finally`,
|
|
219
|
+
* even when connecting failed, or its scope stays locked until the
|
|
220
|
+
* isolate restarts.
|
|
221
|
+
*/
|
|
222
|
+
lock?: boolean;
|
|
223
|
+
}
|
|
224
|
+
/** {@link BrowserSession.lock}'s options. */
|
|
225
|
+
interface BrowserLockOptions {
|
|
226
|
+
/**
|
|
227
|
+
* Bounds this call's wait: when it aborts, this call rejects with its
|
|
228
|
+
* reason. The session keeps waiting while other calls still are; once
|
|
229
|
+
* none is, it leaves the queue at once, so it doesn't hold up the
|
|
230
|
+
* sessions behind it. A call without a signal, including the wait a
|
|
231
|
+
* session's first function call makes, never gives up. The signal does
|
|
232
|
+
* nothing once the lock is held: only `close()` releases it.
|
|
233
|
+
*/
|
|
234
|
+
signal?: AbortSignal;
|
|
197
235
|
}
|
|
198
236
|
/** `send`'s input. */
|
|
199
237
|
interface BrowserSendInput {
|
|
@@ -242,6 +280,11 @@ interface BrowserSessionReport {
|
|
|
242
280
|
tabClosed: boolean;
|
|
243
281
|
/** Another scope is working in this scope's active tab too. */
|
|
244
282
|
tabShared: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* The report as sentences for the model, one per thing that happened,
|
|
285
|
+
* empty when nothing did. Show them after the run's result.
|
|
286
|
+
*/
|
|
287
|
+
notices: string[];
|
|
245
288
|
}
|
|
246
289
|
/** `sessionId` value that addresses the tab the agent is working in. */
|
|
247
290
|
declare const ACTIVE_PAGE_SESSION = "active";
|
|
@@ -254,13 +297,42 @@ declare const ACTIVE_PAGE_SESSION = "active";
|
|
|
254
297
|
* usually comes from model-written code.
|
|
255
298
|
*
|
|
256
299
|
* Create one per run with `browser.session({ scope })`, and close it when
|
|
257
|
-
* the run ends. The browser itself stays open.
|
|
300
|
+
* the run ends. The browser itself stays open. Pass `lock: true` when
|
|
301
|
+
* runs in one scope may overlap; see {@link BrowserSessionOptions.lock}.
|
|
258
302
|
*
|
|
259
303
|
* @experimental The API surface may change before stabilizing.
|
|
260
304
|
*/
|
|
261
305
|
declare class BrowserSession {
|
|
262
306
|
#private;
|
|
263
307
|
constructor(browser: BrowserSource, options?: BrowserSessionOptions);
|
|
308
|
+
/**
|
|
309
|
+
* The `browser.*` functions bound to this session, by name: the ones
|
|
310
|
+
* `Browser.functionDocs()` describes. Each takes one input object and
|
|
311
|
+
* validates it, so model-written code can call them directly. Like the
|
|
312
|
+
* session's methods, every one rejects once the session is closed, and
|
|
313
|
+
* waits for the scope's lock when the session locks.
|
|
314
|
+
*/
|
|
315
|
+
get functions(): Readonly<Record<string, BrowserFunction>>;
|
|
316
|
+
/**
|
|
317
|
+
* Take this scope's lock now rather than at the first call, and hold it
|
|
318
|
+
* until {@link close}. For sessions opened with `lock: true`; a
|
|
319
|
+
* caller with its own time limit calls it first, so the wait doesn't count
|
|
320
|
+
* against the limit, or passes `signal` to bound the wait.
|
|
321
|
+
*
|
|
322
|
+
* Resolves once the session holds the lock, after the locking sessions
|
|
323
|
+
* ahead of it close; later and concurrent calls resolve with the same
|
|
324
|
+
* lock. Rejects when the session closes while waiting. Each call's
|
|
325
|
+
* `signal` bounds only that call's wait: it rejects with the signal's
|
|
326
|
+
* reason, and the session leaves the queue once no call is still
|
|
327
|
+
* waiting (see {@link BrowserLockOptions.signal}); a later call or first
|
|
328
|
+
* call waits again.
|
|
329
|
+
*/
|
|
330
|
+
lock(options?: BrowserLockOptions): Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* How long this session waited for its lock, in milliseconds: `0` until
|
|
333
|
+
* it has waited, and for sessions that don't lock.
|
|
334
|
+
*/
|
|
335
|
+
get waitedForLockMs(): number;
|
|
264
336
|
/**
|
|
265
337
|
* Send a CDP command and resolve with its result, without the JSON-RPC
|
|
266
338
|
* envelope. `sessionId: "active"` runs it in the scope's tab.
|
|
@@ -287,16 +359,137 @@ declare class BrowserSession {
|
|
|
287
359
|
* connected. Never rejects: failures to read the browser's state are
|
|
288
360
|
* logged and leave the report incomplete. Later calls resolve with
|
|
289
361
|
* `undefined`, and other methods reject.
|
|
362
|
+
*
|
|
363
|
+
* A locking session releases the lock once the active tab is saved, or
|
|
364
|
+
* stops waiting for it if it was still waiting.
|
|
290
365
|
*/
|
|
291
366
|
close(): Promise<BrowserSessionReport | undefined>;
|
|
292
367
|
}
|
|
293
368
|
//#endregion
|
|
294
|
-
//#region src/browser/browser.d.ts
|
|
369
|
+
//#region src/browser/browser-functions.d.ts
|
|
370
|
+
/**
|
|
371
|
+
* One function on the `browser` object, as the host runs it: it takes one
|
|
372
|
+
* input object (usually from model-written code, so it's validated) and
|
|
373
|
+
* resolves with a JSON-safe result.
|
|
374
|
+
*
|
|
375
|
+
* @experimental The API surface may change before stabilizing.
|
|
376
|
+
*/
|
|
377
|
+
type BrowserFunction = (input: unknown) => Promise<unknown>;
|
|
378
|
+
/**
|
|
379
|
+
* What the model needs to know to use the `browser` object, for a tool or
|
|
380
|
+
* module description. `Browser.functionDocs()` returns it.
|
|
381
|
+
*
|
|
382
|
+
* @experimental The API surface may change before stabilizing.
|
|
383
|
+
*/
|
|
384
|
+
interface BrowserFunctionDocs {
|
|
385
|
+
/**
|
|
386
|
+
* The `browser.*` functions in Markdown, one bullet per function, then the
|
|
387
|
+
* browser's internal sites when it has any.
|
|
388
|
+
*/
|
|
389
|
+
functions: string;
|
|
390
|
+
/**
|
|
391
|
+
* How to use the browser, one rule per entry, without bullets. Rules about
|
|
392
|
+
* how the code runs (timeouts, how screenshots reach the model) belong to
|
|
393
|
+
* whatever runs it, so add those yourself.
|
|
394
|
+
*/
|
|
395
|
+
rules: string[];
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/browser/providers/browser-run.d.ts
|
|
399
|
+
/**
|
|
400
|
+
* Browser Run settings applied every time a browser is created — including
|
|
401
|
+
* when a lost browser is replaced — so options like guardrails survive a
|
|
402
|
+
* restart.
|
|
403
|
+
*/
|
|
404
|
+
interface BrowserRunOptions<S = Record<string, unknown>> {
|
|
405
|
+
/**
|
|
406
|
+
* Platform `keep_alive` in milliseconds: how long an idle browser lives.
|
|
407
|
+
* Defaults to {@link BROWSER_SESSION_KEEP_ALIVE_DEFAULT_MS} (10 minutes).
|
|
408
|
+
* Browser Run accepts up to {@link BROWSER_SESSION_KEEP_ALIVE_MAX_MS}
|
|
409
|
+
* (20 minutes).
|
|
410
|
+
*/
|
|
411
|
+
keepAliveMs?: number;
|
|
412
|
+
/** Opt into Browser Run session recording (rrweb capture). */
|
|
413
|
+
recording?: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Hostname guardrails, fixed at launch for every connection. They don't
|
|
416
|
+
* apply to `internalHosts`: `allowedDomains: []` leaves the browser able
|
|
417
|
+
* to open internal hostnames only.
|
|
418
|
+
*/
|
|
419
|
+
guardrails?: BrowserSessionGuardrails;
|
|
420
|
+
/**
|
|
421
|
+
* Hostnames only this browser can open, served by your agent or a Worker
|
|
422
|
+
* instead of the internet. Plain http on port 80; no HTTPS or WebSockets.
|
|
423
|
+
* Deployed Workers only: in local dev the browser starts without them.
|
|
424
|
+
*
|
|
425
|
+
* Any http page open in the browser can send requests to these hosts, so
|
|
426
|
+
* a host whose requests have side effects should check `Origin` (see
|
|
427
|
+
* `InternalHost.fetch`).
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* browserRun(this.env.BROWSER, {
|
|
432
|
+
* internalHosts: {
|
|
433
|
+
* router: this.ctx.exports.InternalHostRouter,
|
|
434
|
+
* hosts: {
|
|
435
|
+
* "preview.internal": {
|
|
436
|
+
* description: "A dev server in your sandbox",
|
|
437
|
+
* target: z.object({ port: z.number().int() }),
|
|
438
|
+
* fetch: (request, { port }) => this.sandboxPort(port, request)
|
|
439
|
+
* }
|
|
440
|
+
* }
|
|
441
|
+
* }
|
|
442
|
+
* });
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
internalHosts?: InternalHostsOptions<S>;
|
|
446
|
+
}
|
|
447
|
+
/** A {@link Browser} provider backed by Cloudflare Browser Run. */
|
|
448
|
+
interface BrowserRunProvider {
|
|
449
|
+
readonly kind: "browser-run";
|
|
450
|
+
readonly binding: BrowserBinding;
|
|
451
|
+
readonly options: BrowserRunOptions;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Run the browser on Cloudflare Browser Run.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* new Browser({ provider: browserRun(env.BROWSER, { recording: true }) });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
declare function browserRun<const S extends Record<string, unknown> = {}>(
|
|
462
|
+
binding: BrowserBinding,
|
|
463
|
+
options?: BrowserRunOptions<S>
|
|
464
|
+
): BrowserRunProvider;
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/browser/scope.d.ts
|
|
467
|
+
/**
|
|
468
|
+
* Browser scopes: who is driving a shared `Browser`. Sessions with the same
|
|
469
|
+
* scope share an active tab (and, when they lock, a lock); each scope
|
|
470
|
+
* keeps its own. Cookies and logins are shared by every scope.
|
|
471
|
+
*/
|
|
295
472
|
/**
|
|
296
473
|
* The scope used when a caller doesn't pick one: every caller that leaves
|
|
297
|
-
* `scope` out shares this one active tab. See
|
|
474
|
+
* `scope` out shares this one active tab. See `BrowserConnectOptions`.
|
|
298
475
|
*/
|
|
299
476
|
declare const DEFAULT_BROWSER_SCOPE = "shared";
|
|
477
|
+
/**
|
|
478
|
+
* The scope for one conversation: `conversation:<id>`. pi's `browserTool`
|
|
479
|
+
* gives each conversation this scope by default, so app code that opens
|
|
480
|
+
* sessions with the same scope (a Workspace's `codemode:browser`, say) lands
|
|
481
|
+
* in the same tab as the tool. pi's conversation ids are numbers: pass
|
|
482
|
+
* `String(conversationId)`.
|
|
483
|
+
*
|
|
484
|
+
* Throws on a missing or empty id rather than returning
|
|
485
|
+
* `"conversation:undefined"`, which would quietly put every conversation
|
|
486
|
+
* without an id in one tab.
|
|
487
|
+
*
|
|
488
|
+
* @experimental The API surface may change before stabilizing.
|
|
489
|
+
*/
|
|
490
|
+
declare function conversationScope(id: string): string;
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region src/browser/browser.d.ts
|
|
300
493
|
/**
|
|
301
494
|
* Scope records kept per browser. Writing a new one past the cap deletes the
|
|
302
495
|
* least recently used; a scope that comes back afterwards starts fresh.
|
|
@@ -459,6 +652,14 @@ declare class Browser extends LifecycleCapability {
|
|
|
459
652
|
* one per run.
|
|
460
653
|
*/
|
|
461
654
|
session(options?: BrowserSessionOptions): BrowserSession;
|
|
655
|
+
/**
|
|
656
|
+
* What the model needs to know to use this browser's `browser.*`
|
|
657
|
+
* functions ({@link BrowserSession.functions}): the functions in Markdown,
|
|
658
|
+
* including the internal sites and hosts functions this browser has, and
|
|
659
|
+
* the rules for using them. For a tool or module description; add rules
|
|
660
|
+
* about how your code runs (timeouts, screenshots) yourself.
|
|
661
|
+
*/
|
|
662
|
+
functionDocs(): BrowserFunctionDocs;
|
|
462
663
|
/**
|
|
463
664
|
* Close the browser: retire the record (so the next resolve reports
|
|
464
665
|
* `restarted: true`) and close its provider session. Returns `false` when
|
|
@@ -509,31 +710,37 @@ declare class Browser extends LifecycleCapability {
|
|
|
509
710
|
}
|
|
510
711
|
//#endregion
|
|
511
712
|
export {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
713
|
+
SearchableCdpSpec as A,
|
|
714
|
+
BrowserSessionOptions as C,
|
|
715
|
+
CdpItems as D,
|
|
716
|
+
CdpField as E,
|
|
717
|
+
normalizeCdpSpec as M,
|
|
718
|
+
CdpSpecSource as O,
|
|
719
|
+
BrowserSession as S,
|
|
720
|
+
BrowserSource as T,
|
|
721
|
+
BrowserAttachInput as _,
|
|
517
722
|
BrowserOptions as a,
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
723
|
+
BrowserNewTab as b,
|
|
724
|
+
ResolvedBrowser as c,
|
|
725
|
+
BrowserRunOptions as d,
|
|
726
|
+
BrowserRunProvider as f,
|
|
727
|
+
ACTIVE_PAGE_SESSION as g,
|
|
728
|
+
BrowserFunctionDocs as h,
|
|
524
729
|
BrowserInternalHosts as i,
|
|
525
|
-
|
|
526
|
-
|
|
730
|
+
loadCdpSpec as j,
|
|
731
|
+
RawCdpProtocol as k,
|
|
732
|
+
DEFAULT_BROWSER_SCOPE as l,
|
|
733
|
+
BrowserFunction as m,
|
|
527
734
|
BrowserConnectOptions as n,
|
|
528
735
|
BrowserProvider as o,
|
|
529
|
-
|
|
736
|
+
browserRun as p,
|
|
530
737
|
BrowserConnection as r,
|
|
531
|
-
|
|
738
|
+
MAX_BROWSER_SCOPES as s,
|
|
532
739
|
Browser as t,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
740
|
+
conversationScope as u,
|
|
741
|
+
BrowserDebugLogInput as v,
|
|
742
|
+
BrowserSessionReport as w,
|
|
743
|
+
BrowserSendInput as x,
|
|
744
|
+
BrowserLockOptions as y
|
|
538
745
|
};
|
|
539
|
-
//# sourceMappingURL=browser-
|
|
746
|
+
//# sourceMappingURL=browser-C9T74n4c.d.ts.map
|