agents 0.14.5 → 0.16.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/{agent-tool-types-V25Z_HcX.d.ts → agent-tool-types-NofdbL9X.d.ts} +182 -112
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-C-9s151X.d.ts → agent-tools-DLquv-dp.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/browser/ai.d.ts +126 -7
- package/dist/browser/ai.js +73 -29
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +81 -69
- package/dist/browser/index.js +3 -2
- package/dist/browser/tanstack-ai.d.ts +13 -7
- package/dist/browser/tanstack-ai.js +18 -19
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/chat/index.d.ts +111 -5
- package/dist/chat/index.js +207 -35
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/{classPrivateFieldGet2-Beqsfu2Z.js → classPrivateFieldGet2-CZ7QjTXN.js} +5 -5
- package/dist/{classPrivateMethodInitSpec-B5ko1s2R.js → classPrivateMethodInitSpec-D-0__zd9.js} +2 -2
- package/dist/client.d.ts +19 -2
- package/dist/client.js +31 -11
- package/dist/client.js.map +1 -1
- package/dist/{compaction-helpers-BEUILPss.d.ts → compaction-helpers-DVcu5lPN.d.ts} +91 -12
- package/dist/connector-D6yYzYHg.js +1080 -0
- package/dist/connector-D6yYzYHg.js.map +1 -0
- package/dist/connector-DXursxV5.d.ts +340 -0
- package/dist/experimental/memory/session/index.d.ts +75 -12
- package/dist/experimental/memory/session/index.js +226 -21
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +2 -2
- package/dist/{index-CPe1OtI0.d.ts → index-B7IbEeze.d.ts} +32 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +116 -45
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +262 -487
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/react.d.ts +12 -1
- package/dist/react.js +101 -30
- package/dist/react.js.map +1 -1
- package/dist/{retries-CF_HKSlJ.d.ts → retries-CwlpAGet.d.ts} +35 -5
- package/dist/retries.d.ts +9 -5
- package/dist/retries.js +87 -1
- package/dist/retries.js.map +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/skills/index.js +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/package.json +10 -10
- package/dist/shared-4CAYLCTO.d.ts +0 -34
- package/dist/shared-wyII629d.js +0 -432
- package/dist/shared-wyII629d.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { n as AgentEmail } from "./internal_context-Dg4Cgjcu.js";
|
|
2
|
-
import { t as RetryOptions } from "./retries-
|
|
2
|
+
import { t as RetryOptions } from "./retries-CwlpAGet.js";
|
|
3
3
|
import {
|
|
4
4
|
n as Observability,
|
|
5
5
|
r as ObservabilityEvent,
|
|
6
6
|
s as MCPObservabilityEvent
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-B7IbEeze.js";
|
|
8
8
|
import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-D4ZwyBDu.js";
|
|
9
9
|
import {
|
|
10
10
|
_ as WorkflowPage,
|
|
@@ -60,6 +60,12 @@ import {
|
|
|
60
60
|
Tool as Tool$1
|
|
61
61
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
62
62
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
63
|
+
import {
|
|
64
|
+
EventStore as EventStore$1,
|
|
65
|
+
StreamId as StreamId$1,
|
|
66
|
+
WebStandardStreamableHTTPServerTransport,
|
|
67
|
+
WebStandardStreamableHTTPServerTransportOptions
|
|
68
|
+
} from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
63
69
|
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
64
70
|
import {
|
|
65
71
|
Transport,
|
|
@@ -72,10 +78,7 @@ import {
|
|
|
72
78
|
EventStore,
|
|
73
79
|
StreamId
|
|
74
80
|
} from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
75
|
-
import {
|
|
76
|
-
EventStore as EventStore$1,
|
|
77
|
-
StreamId as StreamId$1
|
|
78
|
-
} from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
81
|
+
import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
79
82
|
|
|
80
83
|
//#region src/sub-routing.d.ts
|
|
81
84
|
/**
|
|
@@ -240,136 +243,150 @@ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTran
|
|
|
240
243
|
}
|
|
241
244
|
//#endregion
|
|
242
245
|
//#region src/mcp/worker-transport.d.ts
|
|
246
|
+
/**
|
|
247
|
+
* Pluggable storage adapter for persisting `WorkerTransport` state across
|
|
248
|
+
* Durable Object hibernation / restart cycles.
|
|
249
|
+
*
|
|
250
|
+
* A typical implementation reads/writes a single key on `this.ctx.storage`
|
|
251
|
+
* inside a Durable Object or Agent.
|
|
252
|
+
*/
|
|
243
253
|
interface MCPStorageApi {
|
|
244
254
|
get(): Promise<TransportState | undefined> | TransportState | undefined;
|
|
245
255
|
set(state: TransportState): Promise<void> | void;
|
|
246
256
|
}
|
|
257
|
+
/** Shape of the persisted transport state. */
|
|
247
258
|
interface TransportState {
|
|
248
259
|
sessionId?: string;
|
|
249
260
|
initialized: boolean;
|
|
250
261
|
initializeParams?: InitializeRequestParams;
|
|
251
262
|
}
|
|
252
|
-
interface WorkerTransportOptions {
|
|
253
|
-
/**
|
|
254
|
-
* Function that generates a session ID for the transport.
|
|
255
|
-
* The session ID SHOULD be globally unique and cryptographically secure.
|
|
256
|
-
* Return undefined to disable session management (stateless mode).
|
|
257
|
-
*/
|
|
258
|
-
sessionIdGenerator?: () => string;
|
|
263
|
+
interface WorkerTransportOptions extends WebStandardStreamableHTTPServerTransportOptions {
|
|
259
264
|
/**
|
|
260
|
-
*
|
|
265
|
+
* CORS options applied to every response and to OPTIONS preflight.
|
|
266
|
+
* Defaults: `origin: *`, expose `mcp-session-id`, allow the standard MCP
|
|
267
|
+
* methods/headers, max-age 86400.
|
|
261
268
|
*/
|
|
262
|
-
enableJsonResponse?: boolean;
|
|
263
|
-
/**
|
|
264
|
-
* Callback fired when a new session is initialized.
|
|
265
|
-
*/
|
|
266
|
-
onsessioninitialized?: (sessionId: string) => void;
|
|
267
|
-
/**
|
|
268
|
-
* Callback fired when a session is closed via DELETE request.
|
|
269
|
-
*/
|
|
270
|
-
onsessionclosed?: (sessionId: string) => void;
|
|
271
269
|
corsOptions?: CORSOptions;
|
|
272
270
|
/**
|
|
273
|
-
* Optional storage
|
|
274
|
-
* Use this to
|
|
275
|
-
*
|
|
271
|
+
* Optional storage adapter for persisting transport state across DO
|
|
272
|
+
* hibernation / restart. Use this to keep an MCP session alive across
|
|
273
|
+
* Durable Object wake-ups.
|
|
276
274
|
*/
|
|
277
275
|
storage?: MCPStorageApi;
|
|
278
|
-
/**
|
|
279
|
-
* Event store for SSE resumability.
|
|
280
|
-
*
|
|
281
|
-
* When set, the transport assigns a globally-unique `id:` to each SSE
|
|
282
|
-
* event and replays missed events when a client reconnects with the
|
|
283
|
-
* `Last-Event-ID` header. Both GET (standalone listen stream) and POST
|
|
284
|
-
* (tool response stream) events are stored and replayable per the
|
|
285
|
-
* MCP 2025-03-26 spec.
|
|
286
|
-
*
|
|
287
|
-
* Configuring an event store **disables the server-side keepalive**
|
|
288
|
-
* on the standalone GET stream — idle drops are recovered by
|
|
289
|
-
* reconnect rather than prevented by writing bytes. Without an event
|
|
290
|
-
* store, the GET stream still gets the 25s comment-frame keepalive
|
|
291
|
-
* so long-lived idle listeners aren't closed by the Cloudflare edge
|
|
292
|
-
* ~5min watchdog.
|
|
293
|
-
*
|
|
294
|
-
* POST response streams always get the keepalive regardless of this
|
|
295
|
-
* setting: in-progress tool calls have no way to recover
|
|
296
|
-
* mid-execution without staying connected, so we don't let the
|
|
297
|
-
* stream drop in the first place.
|
|
298
|
-
*
|
|
299
|
-
* Bring your own {@link EventStore} implementation — e.g.
|
|
300
|
-
* `new DurableObjectEventStore(this.ctx.storage)` when embedding
|
|
301
|
-
* `WorkerTransport` inside a Durable Object / Agent. See
|
|
302
|
-
* cloudflare/agents#1583.
|
|
303
|
-
*/
|
|
304
|
-
eventStore?: EventStore;
|
|
305
|
-
/**
|
|
306
|
-
* Retry interval in milliseconds to suggest to clients in SSE retry field.
|
|
307
|
-
* Controls client reconnection timing for polling behavior.
|
|
308
|
-
*/
|
|
309
|
-
retryInterval?: number;
|
|
310
276
|
}
|
|
311
|
-
declare class WorkerTransport
|
|
312
|
-
|
|
313
|
-
private
|
|
314
|
-
private
|
|
315
|
-
private
|
|
316
|
-
private
|
|
317
|
-
private
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
private
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
277
|
+
declare class WorkerTransport extends WebStandardStreamableHTTPServerTransport {
|
|
278
|
+
private readonly _corsOptions?;
|
|
279
|
+
private readonly _storage?;
|
|
280
|
+
private _stateRestored;
|
|
281
|
+
private _capturedInitializeParams?;
|
|
282
|
+
private _userOnSessionInitialized?;
|
|
283
|
+
private _bridgeInstalled;
|
|
284
|
+
/**
|
|
285
|
+
* Tracks keepalive interval cleanups so we can fire them eagerly when the
|
|
286
|
+
* SDK closes the underlying SSE stream via `closeSSEStream(requestId)` or
|
|
287
|
+
* `closeStandaloneSSEStream()`. Keyed by the JSON-RPC request id that
|
|
288
|
+
* triggered the stream, or the sentinel for the standalone GET stream.
|
|
289
|
+
*/
|
|
290
|
+
private readonly _keepaliveCleanups;
|
|
291
|
+
/**
|
|
292
|
+
* Most recent JSON-RPC request id seen on an incoming POST. Used to key
|
|
293
|
+
* keepalive cleanups when the response is an SSE stream tied to that
|
|
294
|
+
* request (so `closeSSEStream(id)` can find and clear the interval).
|
|
295
|
+
*/
|
|
296
|
+
private _pendingRequestId?;
|
|
297
|
+
/**
|
|
298
|
+
* Request ids whose SSE stream was deliberately torn down via
|
|
299
|
+
* `closeSSEStream`. The SDK's `send()` throws "No connection established"
|
|
300
|
+
* when a request id has no stream — a race that surfaces whenever the
|
|
301
|
+
* server's tool handler resolves *after* the caller closed the stream
|
|
302
|
+
* (e.g. polling-style early-close, or test fixtures closing mid-flight).
|
|
303
|
+
* We swallow `send()` for these ids so the rejection doesn't bubble out
|
|
304
|
+
* of the protocol layer as an unhandled rejection. Mirrors the
|
|
305
|
+
* silent-noop behaviour of the pre-refactor `WorkerTransport`.
|
|
306
|
+
*/
|
|
307
|
+
private readonly _closedRequestIds;
|
|
332
308
|
constructor(options?: WorkerTransportOptions);
|
|
333
309
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
310
|
+
* Backwards-compatible alias for the SDK's internal `_started` flag.
|
|
311
|
+
* Several callers and tests check `transport.started` directly.
|
|
336
312
|
*/
|
|
337
|
-
|
|
313
|
+
get started(): boolean;
|
|
338
314
|
/**
|
|
339
|
-
*
|
|
315
|
+
* Top-level request entry point. Handles CORS preflight, restores any
|
|
316
|
+
* persisted state on first invocation, then delegates to the SDK transport
|
|
317
|
+
* and finally appends CORS headers + keepalive to whatever response comes
|
|
318
|
+
* back.
|
|
340
319
|
*/
|
|
341
|
-
|
|
342
|
-
|
|
320
|
+
handleRequest(
|
|
321
|
+
request: Request,
|
|
322
|
+
options?: {
|
|
323
|
+
parsedBody?: unknown;
|
|
324
|
+
authInfo?: AuthInfo;
|
|
325
|
+
}
|
|
326
|
+
): Promise<Response>;
|
|
343
327
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
*
|
|
352
|
-
* - Header present and supported: Accept
|
|
353
|
-
* - Header present and unsupported: 400 Bad Request
|
|
354
|
-
* - Header missing: Accept (version validation is optional)
|
|
355
|
-
*/
|
|
356
|
-
private validateProtocolVersion;
|
|
357
|
-
private getHeaders;
|
|
358
|
-
handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
|
|
359
|
-
private handleGetRequest;
|
|
360
|
-
private handlePostRequest;
|
|
361
|
-
private handleDeleteRequest;
|
|
362
|
-
private handleOptionsRequest;
|
|
363
|
-
private handleUnsupportedRequest;
|
|
364
|
-
private validateSession;
|
|
328
|
+
* The SDK's 405 responses advertise `Allow: GET, POST, DELETE` because
|
|
329
|
+
* OPTIONS is handled outside the SDK. Since our wrapper *does* handle
|
|
330
|
+
* OPTIONS, advertise it in `Allow` so clients can probe accurately.
|
|
331
|
+
*/
|
|
332
|
+
private normalizeAllowHeader;
|
|
333
|
+
closeSSEStream(requestId: RequestId): void;
|
|
334
|
+
closeStandaloneSSEStream(): void;
|
|
365
335
|
close(): Promise<void>;
|
|
366
336
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
337
|
+
* Swallow two classes of message that would otherwise surface as
|
|
338
|
+
* unhandled rejections from the SDK transport's `send()`:
|
|
339
|
+
*
|
|
340
|
+
* 1. Replayed initialize responses (the `RESTORE_REQUEST_ID` sentinel)
|
|
341
|
+
* — we synthesise these in `restoreState()` to rebuild server
|
|
342
|
+
* capabilities; there's no real client waiting for the response.
|
|
343
|
+
* 2. Sends for a request id whose SSE stream has been deliberately
|
|
344
|
+
* closed via `closeSSEStream`. The protocol layer's tool-handler
|
|
345
|
+
* promise may settle after the close, and the SDK's `send()` throws
|
|
346
|
+
* "No connection established" — a race the pre-refactor transport
|
|
347
|
+
* silently swallowed.
|
|
348
|
+
*
|
|
349
|
+
* Everything else is delegated. We use `await super.send(...)` rather
|
|
350
|
+
* than `return super.send(...)` so any rejection is observed inside this
|
|
351
|
+
* async frame; without the await, the test runner's
|
|
352
|
+
* unhandled-rejection tracker can fire before the caller's own `await`
|
|
353
|
+
* observes it.
|
|
370
354
|
*/
|
|
371
|
-
closeSSEStream(requestId: RequestId): void;
|
|
372
355
|
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* If the response is an SSE stream, tee the body through a TransformStream
|
|
358
|
+
* that injects a `: keepalive\n\n` comment frame every 25s. The interval
|
|
359
|
+
* is cleared when the wrapped stream closes — which happens both when the
|
|
360
|
+
* SDK ends the underlying stream naturally and when `closeSSEStream` is
|
|
361
|
+
* called.
|
|
362
|
+
*
|
|
363
|
+
* Keepalive policy:
|
|
364
|
+
* - POST response streams (`key` is a request id): always keepalive.
|
|
365
|
+
* In-progress tool calls have no recovery path — if the stream drops
|
|
366
|
+
* mid-execution the result is lost — so we keep it under the
|
|
367
|
+
* Cloudflare edge ~5min idle watchdog.
|
|
368
|
+
* - Standalone GET stream (`key === "_standalone"`): keepalive only
|
|
369
|
+
* when no `eventStore` is configured. When resumability is enabled,
|
|
370
|
+
* clients reconnect with `Last-Event-ID` after an idle drop, so we
|
|
371
|
+
* skip the keepalive and let the DO hibernate.
|
|
372
|
+
*
|
|
373
|
+
* Uses the shared `sse-keepalive` constants so both this wrapper and
|
|
374
|
+
* `McpAgent.serve()` write identical frames at the same cadence.
|
|
375
|
+
* See cloudflare/agents#1583.
|
|
376
|
+
*/
|
|
377
|
+
private withKeepalive;
|
|
378
|
+
/**
|
|
379
|
+
* Does the SDK transport have an `eventStore`? Reaches into the SDK's
|
|
380
|
+
* private field because the option isn't surfaced on the public API —
|
|
381
|
+
* we only need a yes/no for keepalive policy.
|
|
382
|
+
*/
|
|
383
|
+
private eventStoreConfigured;
|
|
384
|
+
private getCorsHeaders;
|
|
385
|
+
private withCorsHeaders;
|
|
386
|
+
private installOnSessionInitializedBridge;
|
|
387
|
+
private captureInitializeParams;
|
|
388
|
+
private restoreState;
|
|
389
|
+
private saveState;
|
|
373
390
|
}
|
|
374
391
|
//#endregion
|
|
375
392
|
//#region src/mcp/auth-context.d.ts
|
|
@@ -2326,7 +2343,15 @@ interface AgentStaticOptions {
|
|
|
2326
2343
|
/**
|
|
2327
2344
|
* Maximum age in milliseconds of an unmanaged interrupted-fiber row before
|
|
2328
2345
|
* recovery stops retrying a repeatedly-throwing `onFiberRecovered()` hook
|
|
2329
|
-
* and discards the row
|
|
2346
|
+
* and discards the row (emitting `fiber:recovery:skipped` with reason
|
|
2347
|
+
* `max_age_exceeded`). Defaults to 24h.
|
|
2348
|
+
*
|
|
2349
|
+
* Set to `0` to retain rows indefinitely. NOTE: with `0`, a hook that keeps
|
|
2350
|
+
* throwing is retried forever — the recovery alarm backs off exponentially
|
|
2351
|
+
* (capped at 5 minutes) so it is not a busy-loop, but the Durable Object
|
|
2352
|
+
* stays warm (never idle-evicts) for as long as the un-recoverable row
|
|
2353
|
+
* exists. Prefer a finite age unless you intend to inspect/clear such rows
|
|
2354
|
+
* yourself.
|
|
2330
2355
|
*/
|
|
2331
2356
|
fiberRecoveryMaxAgeMs?: number;
|
|
2332
2357
|
/**
|
|
@@ -2450,6 +2475,13 @@ declare class Agent<
|
|
|
2450
2475
|
private _managedFiberTerminalWaiters;
|
|
2451
2476
|
/** @internal Prevents re-entrant recovery from overlapping alarm ticks. */
|
|
2452
2477
|
private _runFiberRecoveryInProgress;
|
|
2478
|
+
/**
|
|
2479
|
+
* @internal Consecutive runFiber-recovery scans that made NO forward progress
|
|
2480
|
+
* while work was still pending. Drives the exponential backoff of the
|
|
2481
|
+
* recovery follow-up alarm so a repeatedly-throwing recovery hook does not
|
|
2482
|
+
* busy-loop the DO. Reset to 0 whenever a scan recovers anything.
|
|
2483
|
+
*/
|
|
2484
|
+
private _recoveryNoProgressScans;
|
|
2453
2485
|
/** @internal Single-flight background recovery for parent agent-tool rows. */
|
|
2454
2486
|
private _agentToolRunRecoveryPromise;
|
|
2455
2487
|
private _ParentClass;
|
|
@@ -3279,6 +3311,18 @@ declare class Agent<
|
|
|
3279
3311
|
targetPath: ReadonlyArray<AgentPathStep>
|
|
3280
3312
|
): Promise<void>;
|
|
3281
3313
|
private _executeScheduleCallback;
|
|
3314
|
+
/**
|
|
3315
|
+
* Whether any runFiber recovery work is still outstanding: orphaned
|
|
3316
|
+
* `cf_agents_runs` rows left by a dead process (excluding fibers currently
|
|
3317
|
+
* executing in memory, which already hold a keepAlive ref) or managed
|
|
3318
|
+
* ledger fibers stuck in a non-terminal state with no live run row.
|
|
3319
|
+
*
|
|
3320
|
+
* Used by `_scheduleNextAlarm` to arm a follow-up alarm so multi-pass
|
|
3321
|
+
* recovery (e.g. after a scan-deadline yield, or while retrying a throwing
|
|
3322
|
+
* recovery hook) resumes instead of starving.
|
|
3323
|
+
* @internal
|
|
3324
|
+
*/
|
|
3325
|
+
private _hasPendingFiberRecovery;
|
|
3282
3326
|
private _scheduleNextAlarm;
|
|
3283
3327
|
/**
|
|
3284
3328
|
* Override PartyServer's onAlarm hook as a no-op.
|
|
@@ -3844,6 +3888,32 @@ declare class Agent<
|
|
|
3844
3888
|
* callers should treat it as fire-and-forget.
|
|
3845
3889
|
*/
|
|
3846
3890
|
destroy(): Promise<void>;
|
|
3891
|
+
/**
|
|
3892
|
+
* @internal Defer this agent's destruction to its own alarm invocation
|
|
3893
|
+
* instead of running it inline (#1625).
|
|
3894
|
+
*
|
|
3895
|
+
* `destroy()` is a multi-step I/O sequence (drop tables, delete alarm,
|
|
3896
|
+
* delete all storage, dispose connections). Running it on the `waitUntil`
|
|
3897
|
+
* of a request whose client has already disconnected — the MCP
|
|
3898
|
+
* Streamable-HTTP session-DELETE path — gives it little to no
|
|
3899
|
+
* post-invocation grace, so the runtime routinely cancels it mid-flight.
|
|
3900
|
+
* This method instead performs two fast storage writes (a durable
|
|
3901
|
+
* "condemned" marker and an immediate alarm) that the caller can await
|
|
3902
|
+
* before responding; the alarm then fires as a fresh invocation with its
|
|
3903
|
+
* own full execution budget and runs `destroy()` there. If even that
|
|
3904
|
+
* invocation is interrupted, the marker survives and the next wake
|
|
3905
|
+
* finishes teardown — see the `alarm()` preamble.
|
|
3906
|
+
*
|
|
3907
|
+
* Unlike `destroy()`, this method does not abort the isolate, so RPC
|
|
3908
|
+
* callers don't need to swallow an abort error.
|
|
3909
|
+
*/
|
|
3910
|
+
_cf_scheduleDestroy(): Promise<void>;
|
|
3911
|
+
/**
|
|
3912
|
+
* Whether a (deferred or interrupted) destroy is pending. Reads the
|
|
3913
|
+
* durable marker directly — the in-memory `_isFacet` flag may not be
|
|
3914
|
+
* hydrated yet at the call sites, but facets never write the marker.
|
|
3915
|
+
*/
|
|
3916
|
+
private _hasPendingDestroy;
|
|
3847
3917
|
/** @internal Drop every internal Agents SDK table during top-level destroy. */
|
|
3848
3918
|
protected _dropInternalTablesForDestroy(): void;
|
|
3849
3919
|
/**
|
|
@@ -4777,4 +4847,4 @@ export {
|
|
|
4777
4847
|
MCPServer as z,
|
|
4778
4848
|
WorkerTransport as zt
|
|
4779
4849
|
};
|
|
4780
|
-
//# sourceMappingURL=agent-tool-types-
|
|
4850
|
+
//# sourceMappingURL=agent-tool-types-NofdbL9X.d.ts.map
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
s as AgentToolInterruptedReason,
|
|
17
17
|
t as AgentToolChildAdapter,
|
|
18
18
|
u as AgentToolRunInspection
|
|
19
|
-
} from "./agent-tool-types-
|
|
19
|
+
} from "./agent-tool-types-NofdbL9X.js";
|
|
20
20
|
export {
|
|
21
21
|
AgentToolChildAdapter,
|
|
22
22
|
AgentToolDisplayMetadata,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
a as AgentToolEventState,
|
|
3
3
|
i as AgentToolEventMessage
|
|
4
|
-
} from "./agent-tool-types-
|
|
4
|
+
} from "./agent-tool-types-NofdbL9X.js";
|
|
5
5
|
|
|
6
6
|
//#region src/chat/agent-tools.d.ts
|
|
7
7
|
declare function createAgentToolEventState(): AgentToolEventState;
|
|
@@ -11,4 +11,4 @@ declare function applyAgentToolEvent(
|
|
|
11
11
|
): AgentToolEventState;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { createAgentToolEventState as n, applyAgentToolEvent as t };
|
|
14
|
-
//# sourceMappingURL=agent-tools-
|
|
14
|
+
//# sourceMappingURL=agent-tools-DLquv-dp.d.ts.map
|
package/dist/agent-tools.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
s as AgentToolInterruptedReason,
|
|
17
17
|
t as AgentToolChildAdapter,
|
|
18
18
|
u as AgentToolRunInspection
|
|
19
|
-
} from "./agent-tool-types-
|
|
19
|
+
} from "./agent-tool-types-NofdbL9X.js";
|
|
20
20
|
import { Tool } from "ai";
|
|
21
21
|
|
|
22
22
|
//#region src/agent-tools.d.ts
|
package/dist/browser/ai.d.ts
CHANGED
|
@@ -1,21 +1,133 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
c as BrowserSessionStore,
|
|
3
|
+
f as BrowserBinding,
|
|
4
|
+
r as BrowserConnectorSessionOptions,
|
|
5
|
+
t as BrowserConnector
|
|
6
|
+
} from "../connector-DXursxV5.js";
|
|
2
7
|
import { ToolSet } from "ai";
|
|
8
|
+
import { CodemodeRuntimeHandle } from "@cloudflare/codemode";
|
|
3
9
|
|
|
4
10
|
//#region src/browser/ai.d.ts
|
|
11
|
+
interface CreateBrowserToolsOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Durable Object state. The codemode runtime that backs the browser tool
|
|
14
|
+
* lives in a facet of this DO, and browser session ids are stored in its
|
|
15
|
+
* storage — so the tool must be created from inside a Durable Object
|
|
16
|
+
* (e.g. an Agent).
|
|
17
|
+
*
|
|
18
|
+
* The worker must export the `CodemodeRuntime` class (the
|
|
19
|
+
* `@cloudflare/codemode/vite` plugin does this automatically, or add
|
|
20
|
+
* `export { CodemodeRuntime } from "@cloudflare/codemode"` to your entry).
|
|
21
|
+
*/
|
|
22
|
+
ctx: DurableObjectState;
|
|
23
|
+
/**
|
|
24
|
+
* WorkerLoader binding for sandboxed code execution.
|
|
25
|
+
*
|
|
26
|
+
* Requires `"worker_loaders": [{ "binding": "LOADER" }]` in wrangler.jsonc.
|
|
27
|
+
*/
|
|
28
|
+
loader: WorkerLoader;
|
|
29
|
+
/**
|
|
30
|
+
* Browser Rendering binding (Fetcher).
|
|
31
|
+
*
|
|
32
|
+
* This is the primary way to connect — works both locally in
|
|
33
|
+
* `wrangler dev` and when deployed to Cloudflare Workers.
|
|
34
|
+
*
|
|
35
|
+
* Requires `"browser": { "binding": "BROWSER" }` in wrangler.jsonc.
|
|
36
|
+
*/
|
|
37
|
+
browser?: BrowserBinding;
|
|
38
|
+
/**
|
|
39
|
+
* Optional CDP base URL override (e.g. `http://localhost:9222`).
|
|
40
|
+
*
|
|
41
|
+
* Use when connecting to a manually managed Chrome instance or
|
|
42
|
+
* a remote CDP endpoint behind a tunnel.
|
|
43
|
+
*/
|
|
44
|
+
cdpUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Headers to send with CDP URL discovery requests.
|
|
47
|
+
* Useful when the CDP endpoint requires authentication
|
|
48
|
+
* (e.g. Cloudflare Access headers).
|
|
49
|
+
*/
|
|
50
|
+
cdpHeaders?: Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Browser session lifecycle (binding-backed only). Defaults to one fresh
|
|
53
|
+
* session per codemode execution (`one-shot`).
|
|
54
|
+
*/
|
|
55
|
+
session?: BrowserConnectorSessionOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Durable store for Browser Run session ids. Defaults to a
|
|
58
|
+
* {@link DurableBrowserSessionStore} over `ctx.storage`.
|
|
59
|
+
*/
|
|
60
|
+
store?: BrowserSessionStore;
|
|
61
|
+
/**
|
|
62
|
+
* Sandbox execution timeout in milliseconds. Defaults to 30000 (30s).
|
|
63
|
+
* Also used as the per-CDP-command timeout.
|
|
64
|
+
*/
|
|
65
|
+
timeout?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Codemode runtime name — the durable identity of the tool's executions
|
|
68
|
+
* and snippets. Defaults to `"browser"`.
|
|
69
|
+
*/
|
|
70
|
+
name?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The browser tool's moving parts, for hosts that need more than the tools:
|
|
74
|
+
*
|
|
75
|
+
* - `runtime` — the codemode runtime handle (approve/reject paused runs,
|
|
76
|
+
* `expirePaused`, audit via `executions()`, snippets).
|
|
77
|
+
* - `connector` — host-side session helpers: `sessionInfo()`,
|
|
78
|
+
* `closeSession()`, and `sweep()` for a recurring cleanup task.
|
|
79
|
+
* - `tools` — what `createBrowserTools` returns.
|
|
80
|
+
*/
|
|
81
|
+
interface BrowserRuntime {
|
|
82
|
+
runtime: CodemodeRuntimeHandle;
|
|
83
|
+
connector: BrowserConnector;
|
|
84
|
+
tools: ToolSet;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create the browser codemode runtime: the `browser_execute` tool plus the
|
|
88
|
+
* runtime handle and connector for host-side wiring (approvals, session info,
|
|
89
|
+
* sweeps).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* export class MyAgent extends Agent<Env> {
|
|
94
|
+
* get browser() {
|
|
95
|
+
* return createBrowserRuntime({
|
|
96
|
+
* ctx: this.ctx,
|
|
97
|
+
* browser: this.env.BROWSER,
|
|
98
|
+
* loader: this.env.LOADER,
|
|
99
|
+
* session: { mode: "dynamic" }
|
|
100
|
+
* });
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* @callable()
|
|
104
|
+
* async closeBrowserSession() {
|
|
105
|
+
* await this.browser.connector.closeSession();
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare function createBrowserRuntime(
|
|
111
|
+
options: CreateBrowserToolsOptions
|
|
112
|
+
): BrowserRuntime;
|
|
5
113
|
/**
|
|
6
114
|
* Create AI SDK tools for browser automation via CDP code mode.
|
|
7
115
|
*
|
|
8
|
-
* Returns a `ToolSet` with `
|
|
9
|
-
*
|
|
116
|
+
* Returns a `ToolSet` with a single durable `browser_execute` tool backed by
|
|
117
|
+
* a codemode runtime: the model writes TypeScript against the `cdp` connector
|
|
118
|
+
* (`cdp.send`, `cdp.attachToTarget`, `cdp.spec`, …), executions are recorded
|
|
119
|
+
* for abort-and-replay, and browser sessions survive pauses.
|
|
10
120
|
*
|
|
11
121
|
* @example
|
|
12
122
|
* ```ts
|
|
13
123
|
* import { createBrowserTools } from "agents/browser/ai";
|
|
14
124
|
* import { generateText } from "ai";
|
|
15
125
|
*
|
|
126
|
+
* // inside a Durable Object / Agent:
|
|
16
127
|
* const browserTools = createBrowserTools({
|
|
17
|
-
*
|
|
18
|
-
*
|
|
128
|
+
* ctx: this.ctx,
|
|
129
|
+
* browser: this.env.BROWSER,
|
|
130
|
+
* loader: this.env.LOADER,
|
|
19
131
|
* });
|
|
20
132
|
*
|
|
21
133
|
* const result = await generateText({
|
|
@@ -25,7 +137,14 @@ import { ToolSet } from "ai";
|
|
|
25
137
|
* });
|
|
26
138
|
* ```
|
|
27
139
|
*/
|
|
28
|
-
declare function createBrowserTools(
|
|
140
|
+
declare function createBrowserTools(
|
|
141
|
+
options: CreateBrowserToolsOptions
|
|
142
|
+
): ToolSet;
|
|
29
143
|
//#endregion
|
|
30
|
-
export {
|
|
144
|
+
export {
|
|
145
|
+
BrowserRuntime,
|
|
146
|
+
CreateBrowserToolsOptions,
|
|
147
|
+
createBrowserRuntime,
|
|
148
|
+
createBrowserTools
|
|
149
|
+
};
|
|
31
150
|
//# sourceMappingURL=ai.d.ts.map
|