agents 0.27.0 → 0.28.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/dist/abortable-C1SpfVoi.js +21 -0
- package/dist/abortable-C1SpfVoi.js.map +1 -0
- package/dist/{agent-routing-Bhdbvf7s.d.ts → agent-routing-QDcchcQP.d.ts} +10 -15
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-bJZwBMfq.d.ts → agent-tools-DHL2XI7u.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-ahruGw7e.d.ts +239 -0
- package/dist/{ai-sdk-OoGkFy3s.js → ai-sdk-Bdsf6mSA.js} +2 -2
- package/dist/{ai-sdk-OoGkFy3s.js.map → ai-sdk-Bdsf6mSA.js.map} +1 -1
- package/dist/browser/ai.d.ts +8 -227
- package/dist/browser/ai.js +259 -1
- package/dist/browser/ai.js.map +1 -0
- package/dist/browser/index.d.ts +56 -46
- package/dist/browser/index.js +4 -361
- package/dist/browser/{ai-sdk.d.ts → tools/ai-sdk.d.ts} +7 -7
- package/dist/browser/{ai-sdk.js → tools/ai-sdk.js} +5 -4
- package/dist/browser/tools/ai-sdk.js.map +1 -0
- package/dist/browser/tools/pi.d.ts +111 -0
- package/dist/browser/tools/pi.js +119 -0
- package/dist/browser/tools/pi.js.map +1 -0
- package/dist/browser/{tanstack-ai.d.ts → tools/tanstack-ai.d.ts} +39 -37
- package/dist/browser/{tanstack-ai.js → tools/tanstack-ai.js} +73 -59
- package/dist/browser/tools/tanstack-ai.js.map +1 -0
- package/dist/browser-CEdNlsaD.js +481 -0
- package/dist/browser-CEdNlsaD.js.map +1 -0
- package/dist/{browser-tmkcAAI3.d.ts → browser-D30VlpcA.d.ts} +63 -37
- package/dist/{browser-tool-CBqs6hqa.js → browser-tool-4iomavs_.js} +145 -49
- package/dist/browser-tool-4iomavs_.js.map +1 -0
- package/dist/{browser-tool-Bn-nzJQI.d.ts → browser-tool-vtrPOV8e.d.ts} +24 -5
- package/dist/{capability-B4WbF81e.js → capability-DBAKc6UZ.js} +1 -3
- package/dist/capability-DBAKc6UZ.js.map +1 -0
- package/dist/{capability-runner-O5VbQzqg.d.ts → capability-runner-BiVUtjqC.d.ts} +1 -7
- package/dist/chat/index.d.ts +4 -4
- package/dist/chat/index.js +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/chat-sdk/index.js +1 -1
- package/dist/{client-DS3Dz9l0.d.ts → client-BGIQKJhX.d.ts} +2 -2
- package/dist/{client-1tEQ1Oqz.js → client-BnYbNT3z.js} +3 -4
- package/dist/client-BnYbNT3z.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/{connector-58XDGvc3.js → connector-CtZylXdk.js} +3 -603
- package/dist/connector-CtZylXdk.js.map +1 -0
- package/dist/{connector-Cl-VqPmA.d.ts → connector-DEXzVoaY.d.ts} +9 -374
- package/dist/{conversations-DH0ut_8n.d.ts → conversations-FjHDRZyD.d.ts} +4 -4
- package/dist/{current-agent-C07C5o5Y.d.ts → current-agent-CKgT5d1O.d.ts} +3 -5
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{durable-object-lifecycle-DRqp475_.d.ts → durable-object-lifecycle-DOI_bzCH.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/index.js +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/{gateway-BDC07gYO.d.ts → gateway-BFO6vRDn.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/ai-sdk/index.js +1 -1
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +3 -3
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/opencode/index.js +2 -2
- package/dist/harness/pi/index.d.ts +2 -2
- package/dist/harness/pi/index.js +3 -3
- package/dist/harness/store/index.d.ts +1 -1
- package/dist/harness/store/index.js +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/harness/think/index.js +363 -171
- package/dist/harness/think/index.js.map +1 -1
- package/dist/{index-D0A5tbWu.d.ts → index-BEL3ZV-s.d.ts} +2 -6
- package/dist/{index-Ib_4dwOo.d.ts → index-CBt8oRJt.d.ts} +3 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/input-schema-BQykTEp_.js +20 -0
- package/dist/input-schema-BQykTEp_.js.map +1 -0
- package/dist/{input-schema-DNrpTu49.js → input-schema-D2QAtHZH.js} +3 -3
- package/dist/input-schema-D2QAtHZH.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 +2 -2
- package/dist/{lifecycle-CFu6OV03.js → lifecycle-DGorpAmA.js} +2 -4
- package/dist/lifecycle-DGorpAmA.js.map +1 -0
- package/dist/mcp/client/index.d.ts +1 -1
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.js +1 -1
- package/dist/models/pi-ai/index.js +1 -1
- package/dist/{options-pwTNq9z6.d.ts → options-CiIsJHXR.d.ts} +2 -6
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-BB-zfIYF.js → queue-CcIjVYTE.js} +2 -2
- package/dist/{queue-BB-zfIYF.js.map → queue-CcIjVYTE.js.map} +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/routing/index.js +1 -1
- package/dist/{scheduler-CrFCnv_J.d.ts → scheduler-BCLESHSC.d.ts} +2 -12
- package/dist/{scheduler-DZ3xQfeK.js → scheduler-FIHv2-kJ.js} +2 -4
- package/dist/scheduler-FIHv2-kJ.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-store-Do4xkDcf.js +606 -0
- package/dist/session-store-Do4xkDcf.js.map +1 -0
- package/dist/session-store-DoPY12xM.d.ts +383 -0
- package/dist/sessions/index.d.ts +1 -1
- package/dist/sessions/index.js +1 -1
- package/dist/{sessions-B9pNuxdT.js → sessions-_vN5BEZX.js} +2 -2
- package/dist/{sessions-B9pNuxdT.js.map → sessions-_vN5BEZX.js.map} +1 -1
- package/dist/{src-DgCbZtIR.js → src-CQxJFv4l.js} +8 -8
- package/dist/src-CQxJFv4l.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/state/index.js +1 -3
- package/dist/state/index.js.map +1 -1
- package/dist/{store-DLeqKuj3.d.ts → store-BKM4Xm9M.d.ts} +23 -1
- package/dist/{store-vgcPYo8K.js → store-CslVzfN7.js} +28 -2
- package/dist/store-CslVzfN7.js.map +1 -0
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/{streams-CITClVer.js → streams-lsHMJhRW.js} +2 -2
- package/dist/{streams-CITClVer.js.map → streams-lsHMJhRW.js.map} +1 -1
- package/dist/{streams-fbG61qM8.d.ts → streams-vrCtbUIn.d.ts} +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-CkTZNaV1.js → tasks-BN_5AWqI.js} +2 -2
- package/dist/{tasks-CkTZNaV1.js.map → tasks-BN_5AWqI.js.map} +1 -1
- package/dist/{tasks-PtlB4Uyn.d.ts → tasks-E89KdwkS.d.ts} +2 -2
- package/dist/{tool-BPJEbwaX.d.ts → tool-CTp72Jb_.d.ts} +4 -4
- package/dist/tool-CxKsvxjm.js +1126 -0
- package/dist/tool-CxKsvxjm.js.map +1 -0
- package/dist/tool-DoVberpN.d.ts +301 -0
- package/dist/{tool-3PA8xjB_.js → tool-cQRkwSZZ.js} +6 -17
- package/dist/tool-cQRkwSZZ.js.map +1 -0
- package/dist/tool-helpers-O5BDVEAY.js +58 -0
- package/dist/tool-helpers-O5BDVEAY.js.map +1 -0
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.d.ts +89 -0
- package/dist/web/fetch/index.js +20 -0
- package/dist/web/fetch/index.js.map +1 -0
- package/dist/web/fetch/tools/ai-sdk.d.ts +80 -0
- package/dist/web/fetch/tools/ai-sdk.js +47 -0
- package/dist/web/fetch/tools/ai-sdk.js.map +1 -0
- package/dist/web/fetch/tools/pi.d.ts +84 -0
- package/dist/web/fetch/tools/pi.js +88 -0
- package/dist/web/fetch/tools/pi.js.map +1 -0
- package/dist/web/fetch/tools/tanstack-ai.d.ts +78 -0
- package/dist/web/fetch/tools/tanstack-ai.js +45 -0
- package/dist/web/fetch/tools/tanstack-ai.js.map +1 -0
- package/dist/{websearch → web/search}/index.d.ts +1 -1
- package/dist/{websearch → web/search}/index.js +1 -1
- package/dist/{websearch → web/search}/tools/ai-sdk.d.ts +2 -2
- package/dist/{websearch → web/search}/tools/ai-sdk.js +3 -3
- package/dist/web/search/tools/ai-sdk.js.map +1 -0
- package/dist/{websearch → web/search}/tools/pi.d.ts +3 -3
- package/dist/{websearch → web/search}/tools/pi.js +2 -2
- package/dist/web/search/tools/pi.js.map +1 -0
- package/dist/{websearch → web/search}/tools/tanstack-ai.d.ts +2 -2
- package/dist/{websearch → web/search}/tools/tanstack-ai.js +3 -3
- package/dist/web/search/tools/tanstack-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-CmENGb-Z.js → websockets-C3zy8YR0.js} +3 -5
- package/dist/websockets-C3zy8YR0.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +1 -1
- package/docs/browse-the-web.md +26 -1
- package/docs/fetch-the-web.md +276 -0
- package/docs/harnesses/pi.md +25 -0
- package/docs/index.md +99 -76
- package/docs/lifecycle.md +2 -3
- package/docs/queue.md +2 -3
- package/docs/scheduling.md +2 -6
- package/docs/search-the-web.md +2 -0
- package/package.json +44 -19
- package/dist/ai-fm7xx1BK.js +0 -312
- package/dist/ai-fm7xx1BK.js.map +0 -1
- package/dist/browser/ai-sdk.js.map +0 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/tanstack-ai.js.map +0 -1
- package/dist/browser-tool-CBqs6hqa.js.map +0 -1
- package/dist/capability-B4WbF81e.js.map +0 -1
- package/dist/client-1tEQ1Oqz.js.map +0 -1
- package/dist/connector-58XDGvc3.js.map +0 -1
- package/dist/input-schema-DNrpTu49.js.map +0 -1
- package/dist/lifecycle-CFu6OV03.js.map +0 -1
- package/dist/scheduler-DZ3xQfeK.js.map +0 -1
- package/dist/src-DgCbZtIR.js.map +0 -1
- package/dist/store-vgcPYo8K.js.map +0 -1
- package/dist/tool-3PA8xjB_.js.map +0 -1
- package/dist/websearch/tools/ai-sdk.js.map +0 -1
- package/dist/websearch/tools/pi.js.map +0 -1
- package/dist/websearch/tools/tanstack-ai.js.map +0 -1
- package/dist/websockets-CmENGb-Z.js.map +0 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,81 +1,88 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
A as CdpSendOptions,
|
|
3
|
+
C as createBrowserSession,
|
|
4
|
+
D as CdpAttachOptions,
|
|
5
|
+
E as listBrowserTargets,
|
|
6
|
+
M as connectUrl,
|
|
7
|
+
O as CdpConnection,
|
|
8
|
+
S as connectBrowserSession,
|
|
9
|
+
T as getBrowserRecording,
|
|
10
|
+
_ as ConnectBrowserOptions,
|
|
11
|
+
a as ListableBrowserSessionStore,
|
|
12
|
+
b as ConnectKitesurfBrowserOptions,
|
|
13
|
+
c as BrowserLiveViewTarget,
|
|
14
|
+
d as BrowserBinding,
|
|
15
|
+
f as BrowserRecording,
|
|
16
|
+
g as BrowserTargetInfo,
|
|
17
|
+
h as BrowserSessionInfo,
|
|
18
|
+
i as DurableBrowserSessionStore,
|
|
19
|
+
j as CdpSession,
|
|
20
|
+
k as CdpConnectionOptions,
|
|
21
|
+
l as BrowserLiveViewUrl,
|
|
22
|
+
m as BrowserSessionGuardrails,
|
|
23
|
+
n as BrowserSessionStore,
|
|
24
|
+
o as StoredBrowserSession,
|
|
25
|
+
p as BrowserRenderingError,
|
|
26
|
+
r as DEFAULT_SWEEP_IDLE_MS,
|
|
27
|
+
s as BrowserLiveView,
|
|
28
|
+
t as BrowserSessionLock,
|
|
29
|
+
u as LiveViewMode,
|
|
30
|
+
v as ConnectBrowserSessionOptions,
|
|
31
|
+
w as deleteBrowserSession,
|
|
32
|
+
x as connectBrowser,
|
|
33
|
+
y as ConnectChromiumBrowserOptions
|
|
34
|
+
} from "../session-store-DoPY12xM.js";
|
|
35
|
+
import {
|
|
5
36
|
C as browserScrape,
|
|
6
|
-
D as BrowserSessionLock,
|
|
7
37
|
E as runQuickAction,
|
|
8
|
-
F as LiveViewMode,
|
|
9
|
-
G as ConnectKitesurfBrowserOptions,
|
|
10
|
-
H as ConnectBrowserOptions,
|
|
11
|
-
I as BrowserBinding,
|
|
12
|
-
J as createBrowserSession,
|
|
13
|
-
K as connectBrowser,
|
|
14
|
-
L as BrowserRecording,
|
|
15
|
-
M as BrowserLiveView,
|
|
16
|
-
N as BrowserLiveViewTarget,
|
|
17
|
-
O as BrowserSessionStore,
|
|
18
|
-
P as BrowserLiveViewUrl,
|
|
19
|
-
Q as CdpAttachOptions,
|
|
20
|
-
R as BrowserRenderingError,
|
|
21
38
|
S as browserPdf,
|
|
22
39
|
T as browserSnapshot,
|
|
23
|
-
U as ConnectBrowserSessionOptions,
|
|
24
|
-
V as BrowserTargetInfo,
|
|
25
|
-
W as ConnectChromiumBrowserOptions,
|
|
26
|
-
X as getBrowserRecording,
|
|
27
|
-
Y as deleteBrowserSession,
|
|
28
|
-
Z as listBrowserTargets,
|
|
29
40
|
_ as QuickActionSnapshot,
|
|
30
41
|
a as BrowserConnectorSweepResult,
|
|
31
42
|
b as browserLinks,
|
|
32
43
|
c as QuickActionBinary,
|
|
33
44
|
d as QuickActionExtractInput,
|
|
34
|
-
et as CdpConnectionOptions,
|
|
35
45
|
f as QuickActionInput,
|
|
36
46
|
g as QuickActionScreenshotInput,
|
|
37
47
|
h as QuickActionScrapeResult,
|
|
38
48
|
i as BrowserConnectorSweepOptions,
|
|
39
|
-
j as StoredBrowserSession,
|
|
40
|
-
k as DEFAULT_SWEEP_IDLE_MS,
|
|
41
49
|
l as QuickActionBinding,
|
|
42
50
|
m as QuickActionScrapeInput,
|
|
43
51
|
n as BrowserConnectorOptions,
|
|
44
|
-
nt as CdpSession,
|
|
45
52
|
o as DEFAULT_EXEC_SWEEP_IDLE_MS,
|
|
46
53
|
p as QuickActionPage,
|
|
47
|
-
q as connectBrowserSession,
|
|
48
54
|
r as BrowserConnectorSessionOptions,
|
|
49
|
-
rt as connectUrl,
|
|
50
55
|
s as QuickAction,
|
|
51
56
|
t as BrowserConnector,
|
|
52
|
-
tt as CdpSendOptions,
|
|
53
57
|
u as QuickActionCommonOptions,
|
|
54
58
|
v as browserContent,
|
|
55
59
|
w as browserScreenshot,
|
|
56
60
|
x as browserMarkdown,
|
|
57
|
-
y as browserExtract
|
|
58
|
-
|
|
59
|
-
} from "../connector-Cl-VqPmA.js";
|
|
61
|
+
y as browserExtract
|
|
62
|
+
} from "../connector-DEXzVoaY.js";
|
|
60
63
|
import {
|
|
61
|
-
a as
|
|
62
|
-
c as
|
|
63
|
-
d as
|
|
64
|
-
f as
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
a as BrowserProvider,
|
|
65
|
+
c as DEFAULT_BROWSER_SCOPE,
|
|
66
|
+
d as browserRun,
|
|
67
|
+
f as CdpField,
|
|
68
|
+
g as loadCdpSpec,
|
|
69
|
+
h as SearchableCdpSpec,
|
|
70
|
+
i as BrowserOptions,
|
|
71
|
+
l as MAX_BROWSER_SCOPES,
|
|
72
|
+
m as CdpSpecSource,
|
|
73
|
+
n as BrowserConnectOptions,
|
|
74
|
+
o as BrowserRunOptions,
|
|
75
|
+
p as CdpItems,
|
|
76
|
+
r as BrowserConnection,
|
|
77
|
+
s as BrowserRunProvider,
|
|
72
78
|
t as Browser,
|
|
73
|
-
u as
|
|
74
|
-
} from "../browser-
|
|
79
|
+
u as ResolvedBrowser
|
|
80
|
+
} from "../browser-D30VlpcA.js";
|
|
75
81
|
import { CodemodeRuntime } from "@cloudflare/codemode";
|
|
76
82
|
export {
|
|
77
83
|
Browser,
|
|
78
84
|
type BrowserBinding,
|
|
85
|
+
type BrowserConnectOptions,
|
|
79
86
|
type BrowserConnection,
|
|
80
87
|
BrowserConnector,
|
|
81
88
|
type BrowserConnectorOptions,
|
|
@@ -109,10 +116,13 @@ export {
|
|
|
109
116
|
type ConnectBrowserSessionOptions,
|
|
110
117
|
type ConnectChromiumBrowserOptions,
|
|
111
118
|
type ConnectKitesurfBrowserOptions,
|
|
119
|
+
DEFAULT_BROWSER_SCOPE,
|
|
112
120
|
DEFAULT_EXEC_SWEEP_IDLE_MS,
|
|
113
121
|
DEFAULT_SWEEP_IDLE_MS,
|
|
114
122
|
DurableBrowserSessionStore,
|
|
123
|
+
type ListableBrowserSessionStore,
|
|
115
124
|
type LiveViewMode,
|
|
125
|
+
MAX_BROWSER_SCOPES,
|
|
116
126
|
type QuickAction,
|
|
117
127
|
type QuickActionBinary,
|
|
118
128
|
type QuickActionBinding,
|
package/dist/browser/index.js
CHANGED
|
@@ -1,362 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
import { C as listBrowserTargets, D as CdpSession, O as connectUrl, S as isMissingBrowserSession, T as CdpConnection, _ as connectBrowser, a as loadCdpSpec, b as deleteBrowserSession, c as browserExtract, d as browserPdf, f as browserScrape, g as BrowserRenderingError, h as runQuickAction, i as DurableBrowserSessionStore, l as browserLinks, m as browserSnapshot, n as DEFAULT_EXEC_SWEEP_IDLE_MS, o as createLiveView, p as browserScreenshot, r as DEFAULT_SWEEP_IDLE_MS, s as browserContent, t as BrowserConnector, u as browserMarkdown, v as connectBrowserSession, x as getBrowserRecording, y as createBrowserSession } from "../connector-58XDGvc3.js";
|
|
1
|
+
import { _ as CdpConnection, b as connectUrl, c as BrowserRenderingError, d as createBrowserSession, f as deleteBrowserSession, h as listBrowserTargets, l as connectBrowser, n as DurableBrowserSessionStore, p as getBrowserRecording, r as loadCdpSpec, t as DEFAULT_SWEEP_IDLE_MS, u as connectBrowserSession, y as CdpSession } from "../session-store-Do4xkDcf.js";
|
|
2
|
+
import { a as browserLinks, c as browserScrape, d as runQuickAction, i as browserExtract, l as browserScreenshot, n as DEFAULT_EXEC_SWEEP_IDLE_MS, o as browserMarkdown, r as browserContent, s as browserPdf, t as BrowserConnector, u as browserSnapshot } from "../connector-CtZylXdk.js";
|
|
3
|
+
import { i as browserRun, n as DEFAULT_BROWSER_SCOPE, r as MAX_BROWSER_SCOPES, t as Browser } from "../browser-CEdNlsaD.js";
|
|
5
4
|
import { CodemodeRuntime } from "@cloudflare/codemode";
|
|
6
|
-
|
|
7
|
-
/** The store key holding the named browser's current record. */
|
|
8
|
-
function namedBrowserSessionKey(name) {
|
|
9
|
-
return `${NAMED_SESSION_KEY_PREFIX}${name}`;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Where a closed or lost browser's record moves: permanent evidence that the
|
|
13
|
-
* name once owned a browser, so a later resolve reports `restarted: true`.
|
|
14
|
-
* Kept outside {@link NAMED_SESSION_KEY_PREFIX} so listing that prefix
|
|
15
|
-
* yields only names that currently own a browser. Grows with the number of
|
|
16
|
-
* distinct names the host has ever used.
|
|
17
|
-
*/
|
|
18
|
-
const RETIRED_SESSION_KEY_PREFIX = "browser:retired:";
|
|
19
|
-
function retiredBrowserSessionKey(name) {
|
|
20
|
-
return `${RETIRED_SESSION_KEY_PREFIX}${name}`;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Run the browser on Cloudflare Browser Run.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* new Browser({ provider: browserRun(env.BROWSER, { recording: true }) });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function browserRun(binding, options = {}) {
|
|
31
|
-
return {
|
|
32
|
-
kind: "browser-run",
|
|
33
|
-
binding,
|
|
34
|
-
options
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
var _options = /* @__PURE__ */ new WeakMap();
|
|
38
|
-
var _key = /* @__PURE__ */ new WeakMap();
|
|
39
|
-
var _store = /* @__PURE__ */ new WeakMap();
|
|
40
|
-
var _Browser_brand = /* @__PURE__ */ new WeakSet();
|
|
41
|
-
/**
|
|
42
|
-
* One named, persistent browser.
|
|
43
|
-
*
|
|
44
|
-
* Install it with `Lifecycle.use()` — on an Agent subclass or any Durable
|
|
45
|
-
* Object that composes `Lifecycle` — and it stores its record in the
|
|
46
|
-
* object's own storage. It schedules nothing: Browser Run reclaims idle
|
|
47
|
-
* browsers itself once `keep_alive` elapses, and the next use replaces the
|
|
48
|
-
* lost browser with `restarted: true`.
|
|
49
|
-
*
|
|
50
|
-
* Everything here is host-side. Models never see browser names, Browser Run
|
|
51
|
-
* ids, or Live View URLs through this surface.
|
|
52
|
-
*
|
|
53
|
-
* Store discipline: locks wrap storage operations only — liveness probes and
|
|
54
|
-
* Browser Run create/delete calls always happen outside any lock, with a
|
|
55
|
-
* commit re-check to detect concurrent swaps.
|
|
56
|
-
*
|
|
57
|
-
* @experimental The API surface may change before stabilizing.
|
|
58
|
-
*/
|
|
59
|
-
var Browser = class extends LifecycleCapability {
|
|
60
|
-
constructor(options) {
|
|
61
|
-
const name = options.name ?? "default";
|
|
62
|
-
super(`browser:${name}`);
|
|
63
|
-
_classPrivateMethodInitSpec(this, _Browser_brand);
|
|
64
|
-
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
65
|
-
_classPrivateFieldInitSpec(this, _key, void 0);
|
|
66
|
-
_classPrivateFieldInitSpec(this, _store, void 0);
|
|
67
|
-
if (name.trim() === "") throw new Error("Browser names must be non-empty");
|
|
68
|
-
this.name = name;
|
|
69
|
-
_classPrivateFieldSet2(_options, this, options);
|
|
70
|
-
_classPrivateFieldSet2(_key, this, namedBrowserSessionKey(name));
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Reattach to the browser when it is still alive, otherwise create a fresh
|
|
74
|
-
* one. See {@link ResolvedBrowser.restarted} for the mortality signal.
|
|
75
|
-
*/
|
|
76
|
-
async resolve() {
|
|
77
|
-
const { name } = this;
|
|
78
|
-
const key = _classPrivateFieldGet2(_key, this);
|
|
79
|
-
for (let attempt = 0; attempt < 4; attempt++) {
|
|
80
|
-
const existing = await _assertClassBrand(_Browser_brand, this, _readStored).call(this);
|
|
81
|
-
if (existing === void 0) {
|
|
82
|
-
const { session, restarted } = await _assertClassBrand(_Browser_brand, this, _createAndCommit).call(this);
|
|
83
|
-
return {
|
|
84
|
-
name,
|
|
85
|
-
restarted,
|
|
86
|
-
...session
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const alive = await _assertClassBrand(_Browser_brand, this, _isAlive).call(this, existing);
|
|
90
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(key);
|
|
91
|
-
try {
|
|
92
|
-
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(key);
|
|
93
|
-
if (current?.sessionId !== existing.sessionId) continue;
|
|
94
|
-
if (alive) {
|
|
95
|
-
const refreshed = {
|
|
96
|
-
...current,
|
|
97
|
-
updatedAt: Date.now()
|
|
98
|
-
};
|
|
99
|
-
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(key, refreshed);
|
|
100
|
-
return {
|
|
101
|
-
name,
|
|
102
|
-
restarted: false,
|
|
103
|
-
...refreshed
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
107
|
-
} finally {
|
|
108
|
-
await lock.release();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Browser "${name}" kept changing concurrently — retry`);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Resolve the browser and open a CDP connection to it. Commands sent over
|
|
115
|
-
* the connection refresh the record's `updatedAt` (throttled to
|
|
116
|
-
* {@link SESSION_TOUCH_INTERVAL_MS}), so hosts can tell an actively used
|
|
117
|
-
* browser from one the platform has likely reclaimed.
|
|
118
|
-
*
|
|
119
|
-
* If the browser expires between the liveness probe and the WebSocket
|
|
120
|
-
* upgrade, the record is retired and the browser resolved once more, so
|
|
121
|
-
* the caller gets a fresh browser with `restarted: true` instead of an
|
|
122
|
-
* error.
|
|
123
|
-
*/
|
|
124
|
-
async connect() {
|
|
125
|
-
const resolved = await this.resolve();
|
|
126
|
-
try {
|
|
127
|
-
return await _assertClassBrand(_Browser_brand, this, _attach).call(this, resolved);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (!isMissingBrowserSession(error)) throw error;
|
|
130
|
-
await _assertClassBrand(_Browser_brand, this, _retireIfCurrent).call(this, resolved.sessionId);
|
|
131
|
-
}
|
|
132
|
-
const replaced = await this.resolve();
|
|
133
|
-
return _assertClassBrand(_Browser_brand, this, _attach).call(this, {
|
|
134
|
-
...replaced,
|
|
135
|
-
restarted: true
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Close the browser: retire the record (so the next resolve reports
|
|
140
|
-
* `restarted: true`) and delete its Browser Run session. Returns `false`
|
|
141
|
-
* when there was nothing to close.
|
|
142
|
-
*
|
|
143
|
-
* The platform delete is best-effort: the retired record is the durable
|
|
144
|
-
* outcome, and a browser whose delete failed is unreachable through this
|
|
145
|
-
* store, so the pinned `keep_alive` (≤600s) reclaims it.
|
|
146
|
-
*/
|
|
147
|
-
async close() {
|
|
148
|
-
let stored;
|
|
149
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
150
|
-
try {
|
|
151
|
-
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
152
|
-
if (!current) return false;
|
|
153
|
-
stored = current;
|
|
154
|
-
await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
155
|
-
} finally {
|
|
156
|
-
await lock.release();
|
|
157
|
-
}
|
|
158
|
-
try {
|
|
159
|
-
await deleteBrowserSession(_get_provider.call(_assertClassBrand(_Browser_brand, this)).binding, stored.sessionId);
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.warn(`[agents/browser] Failed to delete closed Browser Run session ${stored.sessionId}`, error);
|
|
162
|
-
}
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Mint Live View URLs for the browser's open tabs, fresh from a target
|
|
167
|
-
* listing. `undefined` when the browser was never created, is closed, or
|
|
168
|
-
* is gone. The URLs are bearer credentials with a short connect window
|
|
169
|
-
* (~5 min) — hand them to a trusted human, never to the model, and never
|
|
170
|
-
* store them: re-mint instead.
|
|
171
|
-
*/
|
|
172
|
-
async liveView(options) {
|
|
173
|
-
const entry = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
174
|
-
if (!entry) return void 0;
|
|
175
|
-
try {
|
|
176
|
-
const targets = await listBrowserTargets(_get_provider.call(_assertClassBrand(_Browser_brand, this)).binding, entry.sessionId);
|
|
177
|
-
try {
|
|
178
|
-
if (!await _assertClassBrand(_Browser_brand, this, _touch).call(this, entry.sessionId)) return void 0;
|
|
179
|
-
} catch (error) {
|
|
180
|
-
console.warn(`[agents/browser] Failed to refresh activity for browser "${this.name}"`, error);
|
|
181
|
-
}
|
|
182
|
-
return createLiveView(entry.sessionId, targets, options?.mode);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
if (isMissingBrowserSession(error)) return void 0;
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
async function _attach(resolved) {
|
|
190
|
-
let lastTouchAt = Date.now();
|
|
191
|
-
let touchInFlight = false;
|
|
192
|
-
const cdp = await connectBrowserSession(_get_provider.call(_assertClassBrand(_Browser_brand, this)).binding, resolved.sessionId, {
|
|
193
|
-
timeoutMs: _classPrivateFieldGet2(_options, this).timeoutMs,
|
|
194
|
-
onActivity: () => {
|
|
195
|
-
const now = Date.now();
|
|
196
|
-
if (touchInFlight || now - lastTouchAt < _get_touchIntervalMs.call(_assertClassBrand(_Browser_brand, this))) return;
|
|
197
|
-
touchInFlight = true;
|
|
198
|
-
lastTouchAt = now;
|
|
199
|
-
_assertClassBrand(_Browser_brand, this, _touch).call(this, resolved.sessionId).catch((error) => {
|
|
200
|
-
console.warn(`[agents/browser] Failed to refresh activity for browser "${this.name}"`, error);
|
|
201
|
-
}).finally(() => {
|
|
202
|
-
touchInFlight = false;
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
const { binding } = _get_provider.call(_assertClassBrand(_Browser_brand, this));
|
|
207
|
-
return {
|
|
208
|
-
name: resolved.name,
|
|
209
|
-
sessionId: resolved.sessionId,
|
|
210
|
-
restarted: resolved.restarted,
|
|
211
|
-
activeTargetId: resolved.activeTargetId,
|
|
212
|
-
cdp,
|
|
213
|
-
setActiveTarget: (targetId) => _assertClassBrand(_Browser_brand, this, _update).call(this, resolved.sessionId, (current) => ({
|
|
214
|
-
...current,
|
|
215
|
-
activeTargetId: targetId,
|
|
216
|
-
updatedAt: Date.now()
|
|
217
|
-
})),
|
|
218
|
-
spec: () => loadCdpSpec({
|
|
219
|
-
browser: binding,
|
|
220
|
-
sessionId: resolved.sessionId
|
|
221
|
-
})
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function _get_provider() {
|
|
225
|
-
return _classPrivateFieldGet2(_options, this).provider;
|
|
226
|
-
}
|
|
227
|
-
/** The platform `keep_alive` every create applies. */
|
|
228
|
-
function _get_keepAliveMs() {
|
|
229
|
-
return _get_provider.call(_assertClassBrand(_Browser_brand, this)).options.keepAliveMs ?? 6e5;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Capped at half the keep-alive window: a browser with continuous CDP
|
|
233
|
-
* traffic must never look older than the window the platform uses to
|
|
234
|
-
* reclaim it.
|
|
235
|
-
*/
|
|
236
|
-
function _get_touchIntervalMs() {
|
|
237
|
-
return Math.min(_classPrivateFieldGet2(_options, this).touchIntervalMs ?? 6e4, Math.floor(_get_keepAliveMs.call(_assertClassBrand(_Browser_brand, this)) / 2));
|
|
238
|
-
}
|
|
239
|
-
/** Lazy: `lifecycle.storage` exists only once `Lifecycle.use()` ran. */
|
|
240
|
-
function _get_sessionStore() {
|
|
241
|
-
_classPrivateFieldGet2(_store, this) ?? _classPrivateFieldSet2(_store, this, _classPrivateFieldGet2(_options, this).store ?? new DurableBrowserSessionStore(this.lifecycle.storage));
|
|
242
|
-
return _classPrivateFieldGet2(_store, this);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Refresh `updatedAt` while the record still holds `sessionId`. Returns
|
|
246
|
-
* false when a concurrent close or replacement already retired it.
|
|
247
|
-
*/
|
|
248
|
-
function _touch(sessionId) {
|
|
249
|
-
return _assertClassBrand(_Browser_brand, this, _update).call(this, sessionId, (current) => ({
|
|
250
|
-
...current,
|
|
251
|
-
updatedAt: Date.now()
|
|
252
|
-
}));
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Rewrite the record only while it still holds `sessionId`: a replaced or
|
|
256
|
-
* retired record is never resurrected.
|
|
257
|
-
*/
|
|
258
|
-
async function _update(sessionId, change) {
|
|
259
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
260
|
-
try {
|
|
261
|
-
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
262
|
-
if (current?.sessionId !== sessionId) return false;
|
|
263
|
-
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(_classPrivateFieldGet2(_key, this), change(current));
|
|
264
|
-
return true;
|
|
265
|
-
} finally {
|
|
266
|
-
await lock.release();
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
/** Retire the record if it still holds `sessionId`. */
|
|
270
|
-
async function _retireIfCurrent(sessionId) {
|
|
271
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
272
|
-
try {
|
|
273
|
-
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
274
|
-
if (current?.sessionId === sessionId) await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
275
|
-
} finally {
|
|
276
|
-
await lock.release();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Move the record to its retired marker. Callers hold the key lock, so a
|
|
281
|
-
* resolver always sees either the record or the marker.
|
|
282
|
-
*/
|
|
283
|
-
async function _retire(current) {
|
|
284
|
-
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(retiredBrowserSessionKey(this.name), {
|
|
285
|
-
...current,
|
|
286
|
-
closedAt: Date.now()
|
|
287
|
-
});
|
|
288
|
-
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).delete(_classPrivateFieldGet2(_key, this));
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Create a Browser Run session (outside any lock) and commit it, applying
|
|
292
|
-
* the provider's creation options. If a concurrent caller committed an
|
|
293
|
-
* entry first, theirs wins and the redundant session is deleted
|
|
294
|
-
* best-effort.
|
|
295
|
-
*
|
|
296
|
-
* `restarted` is read under the commit lock: a retired marker — left by
|
|
297
|
-
* close() or a dead-browser recovery — is evidence a prior browser
|
|
298
|
-
* existed, and only first-ever use of the name is not a restart. Markers
|
|
299
|
-
* are permanent, so reading at commit time also catches a browser that
|
|
300
|
-
* was created and closed while this create was in flight.
|
|
301
|
-
*/
|
|
302
|
-
async function _createAndCommit() {
|
|
303
|
-
const { binding, options } = _get_provider.call(_assertClassBrand(_Browser_brand, this));
|
|
304
|
-
const info = await createBrowserSession(binding, {
|
|
305
|
-
keepAliveMs: _get_keepAliveMs.call(_assertClassBrand(_Browser_brand, this)),
|
|
306
|
-
recording: options.recording,
|
|
307
|
-
guardrails: options.guardrails
|
|
308
|
-
});
|
|
309
|
-
const now = Date.now();
|
|
310
|
-
const stored = {
|
|
311
|
-
sessionId: info.sessionId,
|
|
312
|
-
createdAt: now,
|
|
313
|
-
updatedAt: now
|
|
314
|
-
};
|
|
315
|
-
let winner;
|
|
316
|
-
let restarted;
|
|
317
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
318
|
-
try {
|
|
319
|
-
restarted = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(retiredBrowserSessionKey(this.name)) !== void 0;
|
|
320
|
-
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
321
|
-
if (current === void 0) await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(_classPrivateFieldGet2(_key, this), stored);
|
|
322
|
-
else winner = current;
|
|
323
|
-
} finally {
|
|
324
|
-
await lock.release();
|
|
325
|
-
}
|
|
326
|
-
if (winner) {
|
|
327
|
-
try {
|
|
328
|
-
await deleteBrowserSession(binding, stored.sessionId);
|
|
329
|
-
} catch (error) {
|
|
330
|
-
console.warn(`[agents/browser] Failed to delete redundant Browser Run session ${stored.sessionId}`, error);
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
session: winner,
|
|
334
|
-
restarted
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
return {
|
|
338
|
-
session: stored,
|
|
339
|
-
restarted
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
async function _isAlive(stored) {
|
|
343
|
-
try {
|
|
344
|
-
await listBrowserTargets(_get_provider.call(_assertClassBrand(_Browser_brand, this)).binding, stored.sessionId);
|
|
345
|
-
return true;
|
|
346
|
-
} catch (error) {
|
|
347
|
-
if (isMissingBrowserSession(error)) return false;
|
|
348
|
-
throw error;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async function _readStored() {
|
|
352
|
-
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
353
|
-
try {
|
|
354
|
-
return await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
355
|
-
} finally {
|
|
356
|
-
await lock.release();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
//#endregion
|
|
360
|
-
export { Browser, BrowserConnector, BrowserRenderingError, CdpConnection, CdpSession, CodemodeRuntime, DEFAULT_EXEC_SWEEP_IDLE_MS, DEFAULT_SWEEP_IDLE_MS, DurableBrowserSessionStore, browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserRun, browserScrape, browserScreenshot, browserSnapshot, connectBrowser, connectBrowserSession, connectUrl, createBrowserSession, deleteBrowserSession, getBrowserRecording, listBrowserTargets, loadCdpSpec, runQuickAction };
|
|
361
|
-
|
|
362
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
export { Browser, BrowserConnector, BrowserRenderingError, CdpConnection, CdpSession, CodemodeRuntime, DEFAULT_BROWSER_SCOPE, DEFAULT_EXEC_SWEEP_IDLE_MS, DEFAULT_SWEEP_IDLE_MS, DurableBrowserSessionStore, MAX_BROWSER_SCOPES, browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserRun, browserScrape, browserScreenshot, browserSnapshot, connectBrowser, connectBrowserSession, connectUrl, createBrowserSession, deleteBrowserSession, getBrowserRecording, listBrowserTargets, loadCdpSpec, runQuickAction };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i as QuickActionToolName,
|
|
3
|
+
r as CreateQuickActionToolsOptions,
|
|
4
|
+
s as createQuickActionTools
|
|
5
|
+
} from "../../ai-ahruGw7e.js";
|
|
1
6
|
import {
|
|
2
7
|
a as BrowserSource,
|
|
3
8
|
i as BrowserNewTab,
|
|
4
9
|
n as BrowserToolOptions,
|
|
5
10
|
r as BrowserToolOutput,
|
|
6
11
|
t as BrowserToolInput
|
|
7
|
-
} from "
|
|
8
|
-
import {
|
|
9
|
-
CreateQuickActionToolsOptions,
|
|
10
|
-
QuickActionToolName,
|
|
11
|
-
createQuickActionTools
|
|
12
|
-
} from "./ai.js";
|
|
12
|
+
} from "../../browser-tool-vtrPOV8e.js";
|
|
13
13
|
import { FlexibleSchema, JSONValue } from "ai";
|
|
14
14
|
|
|
15
15
|
//#region src/browser/tool-helpers.d.ts
|
|
@@ -24,7 +24,7 @@ type BrowserModelOutput =
|
|
|
24
24
|
value: JSONValue;
|
|
25
25
|
};
|
|
26
26
|
//#endregion
|
|
27
|
-
//#region src/browser/ai-sdk.d.ts
|
|
27
|
+
//#region src/browser/tools/ai-sdk.d.ts
|
|
28
28
|
/**
|
|
29
29
|
* The AI SDK tool {@link browserTool} returns. Assignable to the AI SDK's
|
|
30
30
|
* `Tool`, and `execute` / `toModelOutput` are always present.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as browserExecuteModelOutput } from "../../tool-helpers-O5BDVEAY.js";
|
|
2
|
+
import { createQuickActionTools } from "../ai.js";
|
|
3
|
+
import { n as createBrowserToolCore, t as browserReportNotes } from "../../browser-tool-4iomavs_.js";
|
|
4
|
+
//#region src/browser/tools/ai-sdk.ts
|
|
4
5
|
/**
|
|
5
6
|
* Create an AI SDK tool that lets the model drive a persistent browser with
|
|
6
7
|
* JavaScript and the Chrome DevTools Protocol.
|
|
@@ -41,7 +42,7 @@ function browserTool(options) {
|
|
|
41
42
|
return {
|
|
42
43
|
description: core.description,
|
|
43
44
|
inputSchema: core.inputSchema,
|
|
44
|
-
execute: core.execute,
|
|
45
|
+
execute: (input) => core.execute(input),
|
|
45
46
|
toModelOutput: ({ output }) => browserExecuteModelOutput(output, browserReportNotes(output))
|
|
46
47
|
};
|
|
47
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","names":[],"sources":["../../../src/browser/tools/ai-sdk.ts"],"sourcesContent":["/**\n * `agents/browser/ai-sdk` — the AI SDK tool for a persistent `Browser`.\n *\n * The older `createBrowserTools` stays in `agents/browser/ai`.\n */\nimport type { FlexibleSchema } from \"ai\";\nimport {\n browserReportNotes,\n createBrowserToolCore,\n type BrowserToolInput,\n type BrowserToolOptions,\n type BrowserToolOutput\n} from \"../browser-tool\";\nimport {\n browserExecuteModelOutput,\n type BrowserModelOutput\n} from \"../tool-helpers\";\n\nexport type {\n BrowserToolInput,\n BrowserToolOptions,\n BrowserToolOutput\n} from \"../browser-tool\";\nexport type { BrowserNewTab, BrowserSource } from \"../session-connector\";\n\n// Stateless Quick Action tools, so one import covers both.\nexport {\n createQuickActionTools,\n type CreateQuickActionToolsOptions,\n type QuickActionToolName\n} from \"../ai\";\n\n/**\n * The AI SDK tool {@link browserTool} returns. Assignable to the AI SDK's\n * `Tool`, and `execute` / `toModelOutput` are always present.\n */\nexport interface BrowserTool {\n description: string;\n inputSchema: FlexibleSchema<BrowserToolInput>;\n execute(\n input: BrowserToolInput,\n options: unknown\n ): Promise<BrowserToolOutput>;\n toModelOutput(options: { output: BrowserToolOutput }): BrowserModelOutput;\n}\n\n/**\n * Create an AI SDK tool that lets the model drive a persistent browser with\n * JavaScript and the Chrome DevTools Protocol.\n *\n * The browser outlives each run: tabs, cookies, and logins carry over. The\n * model never starts, closes, or resets it, and `sessionId: \"active\"`\n * addresses the tab it last worked in. If the browser had to be replaced\n * (it expired or was closed), the code still runs in the new browser and the\n * result says `restarted: true`.\n *\n * Browser Run only (Chromium). Guardrails, `keepAliveMs`, and recording are\n * set on the `Browser`'s provider.\n *\n * @example\n * ```ts\n * import { Browser, browserRun } from \"agents/browser\";\n * import { browserTool } from \"agents/browser/ai-sdk\";\n *\n * export class MyAgent extends Agent<Env> {\n * browser = new Browser({ provider: browserRun(this.env.BROWSER) });\n *\n * constructor(ctx: AgentContext, env: Env) {\n * super(ctx, env);\n * this.lifecycle.use(this.browser);\n * }\n *\n * async onChatMessage() {\n * const tools = {\n * browser: browserTool({ browser: this.browser, loader: this.env.LOADER })\n * };\n * // …pass `tools` to streamText / generateText\n * }\n * }\n * ```\n */\nexport function browserTool(options: BrowserToolOptions): BrowserTool {\n const core = createBrowserToolCore(options, {\n screenshotHint:\n \"To show a screenshot, return { type: 'browser_screenshot', mediaType, data } with data from Page.captureScreenshot and mediaType 'image/png', or 'image/jpeg' if you captured with format: 'jpeg'. The user sees the image; you get a short text summary.\"\n });\n return {\n description: core.description,\n inputSchema: core.inputSchema,\n execute: (input) => core.execute(input),\n toModelOutput: ({ output }) =>\n browserExecuteModelOutput(output, browserReportNotes(output))\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAgB,YAAY,SAA0C;CACpE,MAAM,OAAO,sBAAsB,SAAS,EAC1C,gBACE,4PACJ,CAAC;CACD,OAAO;EACL,aAAa,KAAK;EAClB,aAAa,KAAK;EAClB,UAAU,UAAU,KAAK,QAAQ,KAAK;EACtC,gBAAgB,EAAE,aAChB,0BAA0B,QAAQ,mBAAmB,MAAM,CAAC;CAChE;AACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
a as BrowserSource,
|
|
3
|
+
i as BrowserNewTab,
|
|
4
|
+
n as BrowserToolOptions,
|
|
5
|
+
r as BrowserToolOutput,
|
|
6
|
+
t as BrowserToolInput
|
|
7
|
+
} from "../../browser-tool-vtrPOV8e.js";
|
|
8
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
9
|
+
import { ToolExecutionApi, ToolRegistration } from "@earendil-works/pi-durable";
|
|
10
|
+
|
|
11
|
+
//#region src/browser/tools/pi.d.ts
|
|
12
|
+
interface PiBrowserToolOptions<TName extends string = "browser"> extends Omit<
|
|
13
|
+
BrowserToolOptions,
|
|
14
|
+
"scope"
|
|
15
|
+
> {
|
|
16
|
+
/** The tool's name. Default `"browser"`. */
|
|
17
|
+
name?: TName;
|
|
18
|
+
/**
|
|
19
|
+
* Which calls share an active tab: a string for every call, or a function
|
|
20
|
+
* of the call. Defaults to `conversation:<id>` for the calling
|
|
21
|
+
* conversation, so each
|
|
22
|
+
* conversation (and each fork or subagent) on the Durable Object keeps its
|
|
23
|
+
* own tab, while cookies and logins stay shared.
|
|
24
|
+
*/
|
|
25
|
+
scope?: string | ((api: ToolExecutionApi) => string);
|
|
26
|
+
}
|
|
27
|
+
declare const browserToolParameters: Type.TObject<{
|
|
28
|
+
code: Type.TString;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* What a UI can show about a run without reading the content: the run's
|
|
32
|
+
* outcome and what happened to the browser.
|
|
33
|
+
*/
|
|
34
|
+
type PiBrowserToolDetails = {
|
|
35
|
+
executionId: string;
|
|
36
|
+
status: BrowserToolOutput["status"];
|
|
37
|
+
restarted?: true;
|
|
38
|
+
newTabs?: {
|
|
39
|
+
targetId: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
type PiBrowserTool<TName extends string = "browser"> = ToolRegistration<
|
|
45
|
+
typeof browserToolParameters,
|
|
46
|
+
PiBrowserToolDetails
|
|
47
|
+
> & {
|
|
48
|
+
readonly name: TName;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Create a pi-durable tool that lets the model drive a persistent browser
|
|
52
|
+
* with JavaScript and the Chrome DevTools Protocol.
|
|
53
|
+
*
|
|
54
|
+
* Works like `browserTool` in `agents/browser/ai-sdk`: tabs, cookies, and
|
|
55
|
+
* logins carry over between runs, `sessionId: "active"` addresses the tab the
|
|
56
|
+
* model last worked in, and a replaced browser is reported as
|
|
57
|
+
* `restarted: true`. A returned screenshot comes back as an image part that
|
|
58
|
+
* the model sees, when its model accepts images.
|
|
59
|
+
*
|
|
60
|
+
* Each conversation gets its own active tab (see
|
|
61
|
+
* {@link PiBrowserToolOptions.scope}). A conversation's calls run one at a
|
|
62
|
+
* time, since they share its tab, and the tool doesn't rerun after an
|
|
63
|
+
* eviction (its code may have clicked or
|
|
64
|
+
* submitted something): pi gives the model an interrupted result instead.
|
|
65
|
+
* Pass `ctx` unless the tool is built inside an Agent.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Browser, browserRun } from "agents/browser";
|
|
70
|
+
* import { browserTool } from "agents/browser/pi";
|
|
71
|
+
*
|
|
72
|
+
* export class MyAgent extends DurableObject<Env> {
|
|
73
|
+
* readonly browser = new Browser({ provider: browserRun(this.env.BROWSER) });
|
|
74
|
+
* readonly registry = createRegistry();
|
|
75
|
+
* readonly harness = new PiHarness({
|
|
76
|
+
* harness: ({ storage, context }) => {
|
|
77
|
+
* this.registry.install({
|
|
78
|
+
* name: "browser",
|
|
79
|
+
* tools: [
|
|
80
|
+
* browserTool({
|
|
81
|
+
* ctx: this.ctx,
|
|
82
|
+
* browser: this.browser,
|
|
83
|
+
* loader: this.env.LOADER
|
|
84
|
+
* })
|
|
85
|
+
* ]
|
|
86
|
+
* });
|
|
87
|
+
* return Harness.open(storage, { models, registry: this.registry }, context);
|
|
88
|
+
* }
|
|
89
|
+
* });
|
|
90
|
+
* readonly lifecycle = Lifecycle.install(this)
|
|
91
|
+
* .use(this.browser)
|
|
92
|
+
* .use(this.harness);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare function browserTool<TName extends string = "browser">(
|
|
97
|
+
options: PiBrowserToolOptions<TName>
|
|
98
|
+
): PiBrowserTool<TName>;
|
|
99
|
+
//#endregion
|
|
100
|
+
export {
|
|
101
|
+
type BrowserNewTab,
|
|
102
|
+
type BrowserSource,
|
|
103
|
+
type BrowserToolInput,
|
|
104
|
+
type BrowserToolOptions,
|
|
105
|
+
type BrowserToolOutput,
|
|
106
|
+
PiBrowserTool,
|
|
107
|
+
PiBrowserToolDetails,
|
|
108
|
+
PiBrowserToolOptions,
|
|
109
|
+
browserTool
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=pi.d.ts.map
|