agents 0.23.0 → 0.25.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-routing-DE5zmCQ8.d.ts → agent-routing-0DR0Tk2v.d.ts} +270 -190
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-routing.js.map +1 -1
- package/dist/agent-tool-types.d.ts +13 -7
- package/dist/agent-tool-types.js +23 -1
- package/dist/agent-tool-types.js.map +1 -1
- package/dist/{agent-tools-y7zLfw4Q.js → agent-tools-CdJC-8Dc.js} +72 -9
- package/dist/agent-tools-CdJC-8Dc.js.map +1 -0
- package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-YrATZJu2.d.ts} +29 -15
- package/dist/agent-tools.d.ts +6 -4
- package/dist/agent-tools.js.map +1 -1
- package/dist/ai-fm7xx1BK.js +312 -0
- package/dist/ai-fm7xx1BK.js.map +1 -0
- package/dist/base64-redaction-C1Uu29t5.js +59 -0
- package/dist/base64-redaction-C1Uu29t5.js.map +1 -0
- package/dist/browser/ai-sdk.d.ts +90 -0
- package/dist/browser/ai-sdk.js +51 -0
- package/dist/browser/ai-sdk.js.map +1 -0
- package/dist/browser/ai.d.ts +4 -4
- package/dist/browser/ai.js +1 -347
- package/dist/browser/index.d.ts +81 -79
- package/dist/browser/index.js +361 -2
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/tanstack-ai.d.ts +96 -1
- package/dist/browser/tanstack-ai.js +62 -2
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/browser-DE3d-RLk.d.ts +275 -0
- package/dist/browser-tool-CQ10e6Kj.js +480 -0
- package/dist/browser-tool-CQ10e6Kj.js.map +1 -0
- package/dist/browser-tool-DuNdlwZ9.d.ts +73 -0
- package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
- package/dist/capability-B4WbF81e.js.map +1 -0
- package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-DBAnGr6L.d.ts} +45 -15
- package/dist/chat/index.d.ts +341 -232
- package/dist/chat/index.js +602 -72
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +42 -2
- package/dist/chat/react.js +191 -35
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.d.ts +1 -1
- package/dist/chat/transport.js +1 -1
- package/dist/chat-sdk/index.d.ts +17 -3
- package/dist/chat-sdk/index.js +28 -2
- package/dist/chat-sdk/index.js.map +1 -1
- package/dist/client-4OlMIJx-.js +591 -0
- package/dist/client-4OlMIJx-.js.map +1 -0
- package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
- package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
- package/dist/client-je3koD9Z.d.ts +446 -0
- package/dist/client.d.ts +29 -283
- package/dist/client.js +2 -274
- package/dist/{connector-CptFKzRh.js → connector-58XDGvc3.js} +251 -120
- package/dist/connector-58XDGvc3.js.map +1 -0
- package/dist/{connector-CkQD4MK3.d.ts → connector-Cl-VqPmA.d.ts} +244 -146
- package/dist/context/index.d.ts +29 -0
- package/dist/context/index.js +64 -17
- package/dist/context/index.js.map +1 -1
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/current-agent-vAk_5JMt.d.ts +93 -0
- package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-HhgOMWq9.d.ts} +26 -127
- package/dist/harnesses/pi/index.d.ts +348 -0
- package/dist/harnesses/pi/index.js +754 -0
- package/dist/harnesses/pi/index.js.map +1 -0
- package/dist/images-iiTDSyRu.js +1631 -0
- package/dist/images-iiTDSyRu.js.map +1 -0
- package/dist/index-BreL0YrQ.d.ts +78 -0
- package/dist/index-kbSUIer3.d.ts +343 -0
- package/dist/index.d.ts +43 -41
- package/dist/index.js +2 -2
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +19 -17
- package/dist/lifecycle/index.js +2 -2
- package/dist/{lifecycle-CMRGjZdw.js → lifecycle-CFu6OV03.js} +73 -29
- package/dist/lifecycle-CFu6OV03.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/client/x402.js +21 -19
- package/dist/mcp/client/x402.js.map +1 -1
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +2 -2
- package/dist/{message-builder-BymO4N_D.js → message-builder-DAl9AhHH.js} +89 -4
- package/dist/message-builder-DAl9AhHH.js.map +1 -0
- package/dist/models/ai-sdk/index.d.ts +353 -0
- package/dist/models/ai-sdk/index.js +2443 -0
- package/dist/models/ai-sdk/index.js.map +1 -0
- package/dist/models/pi-ai/index.d.ts +313 -0
- package/dist/models/pi-ai/index.js +1795 -0
- package/dist/models/pi-ai/index.js.map +1 -0
- package/dist/observability/ai/index.js +20 -4
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/{protocol-B0nh6KNf.js → protocol-kHsr-f0X.js} +26 -12
- package/dist/{protocol-B0nh6KNf.js.map → protocol-kHsr-f0X.js.map} +1 -1
- package/dist/queue/index.d.ts +123 -0
- package/dist/queue/index.js +2 -0
- package/dist/queue-BB-zfIYF.js +406 -0
- package/dist/queue-BB-zfIYF.js.map +1 -0
- package/dist/react.d.ts +31 -13
- package/dist/react.js +190 -71
- package/dist/react.js.map +1 -1
- package/dist/{retries-D9Ds-1lz.d.ts → retries-CV6AkXmQ.d.ts} +23 -8
- package/dist/retries.d.ts +12 -8
- package/dist/retries.js +19 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +2 -2
- package/dist/routing/index.js +1 -1
- package/dist/{scheduler-DD9NdYbF.js → scheduler-DZ3xQfeK.js} +4 -11
- package/dist/scheduler-DZ3xQfeK.js.map +1 -0
- package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-RdACNXDP.d.ts} +6 -6
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +70 -3
- package/dist/sessions/index.js +276 -67
- package/dist/sessions/index.js.map +1 -1
- package/dist/skills/index.d.ts +29 -314
- package/dist/socket-address.d.ts +16 -0
- package/dist/socket-address.js +19 -0
- package/dist/socket-address.js.map +1 -0
- package/dist/{src-DlSHshb2.js → src-BZeu-SCD.js} +541 -500
- package/dist/src-BZeu-SCD.js.map +1 -0
- package/dist/state/index.d.ts +6 -0
- package/dist/state/index.js +137 -0
- package/dist/state/index.js.map +1 -0
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/{streams-D6tJ0NN9.d.ts → streams-Cmkj9QfW.d.ts} +4 -2
- package/dist/{streams-DZKgAj9b.js → streams-DW-UCOUc.js} +9 -2
- package/dist/streams-DW-UCOUc.js.map +1 -0
- 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-ylZgBjhj.js → tasks-68DESxf0.js} +3 -3
- package/dist/{tasks-ylZgBjhj.js.map → tasks-68DESxf0.js.map} +1 -1
- package/dist/{tasks-BRJ5zgya.d.ts → tasks-9YxYtByh.d.ts} +5 -5
- package/dist/transport-PfFnt-Ld.d.ts +525 -0
- package/dist/transport-protocol-BxyngQ_R.js +25 -0
- package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
- package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
- package/dist/types-BA4anrjI.d.ts +70 -0
- package/dist/voice/index.d.ts +2 -2
- package/dist/websockets/index.d.ts +195 -69
- package/dist/websockets/index.js +3 -2
- package/dist/websockets-Ci-LZFHH.js +1030 -0
- package/dist/websockets-Ci-LZFHH.js.map +1 -0
- package/dist/wire-types-CnMt6_HR.js.map +1 -1
- package/dist/wire-types-CrjKvDyi.d.ts +300 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/dist/{ws-chat-transport-UNRIS2xl.d.ts → ws-chat-transport-BbT1A5Lc.d.ts} +51 -2
- package/dist/{ws-chat-transport-rWwta645.js → ws-chat-transport-cqMKq3IY.js} +143 -16
- package/dist/ws-chat-transport-cqMKq3IY.js.map +1 -0
- package/docs/agent-class.md +2 -2
- package/docs/agent-tools.md +29 -4
- package/docs/browse-the-web.md +87 -5
- package/docs/chat-agents.md +124 -16
- package/docs/client-sdk.md +30 -0
- package/docs/context.md +27 -0
- package/docs/durable-execution.md +2 -0
- package/docs/harnesses/pi.md +91 -0
- package/docs/human-in-the-loop.md +4 -0
- package/docs/index.md +4 -1
- package/docs/lifecycle.md +114 -23
- package/docs/models-pi-ai.md +325 -0
- package/docs/models.md +504 -0
- package/docs/queue.md +135 -241
- package/docs/resumable-streaming.md +2 -0
- package/docs/retries.md +1 -1
- package/docs/routing.md +13 -13
- package/docs/sessions.md +36 -1
- package/docs/state.md +1 -0
- package/docs/sub-agents.md +12 -3
- package/package.json +51 -3
- package/dist/agent-tools-y7zLfw4Q.js.map +0 -1
- package/dist/browser/ai.js.map +0 -1
- package/dist/capability-BjSKYpzg.js.map +0 -1
- package/dist/client-tools-aIBO0Fk7.d.ts +0 -53
- package/dist/client.js.map +0 -1
- package/dist/connector-CptFKzRh.js.map +0 -1
- package/dist/lifecycle-CMRGjZdw.js.map +0 -1
- package/dist/message-builder-BymO4N_D.js.map +0 -1
- package/dist/scheduler-DD9NdYbF.js.map +0 -1
- package/dist/src-DlSHshb2.js.map +0 -1
- package/dist/streams-DZKgAj9b.js.map +0 -1
- package/dist/websockets-DUfRHPRq.js +0 -502
- package/dist/websockets-DUfRHPRq.js.map +0 -1
- package/dist/ws-chat-transport-rWwta645.js.map +0 -1
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
S as ConnectionContext,
|
|
3
|
+
T as WSMessage,
|
|
3
4
|
r as CapabilityWebSocketUpgradeContext,
|
|
4
5
|
s as LifecycleCapability,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
x as Connection
|
|
7
|
+
} from "../capability-runner-DBAnGr6L.js";
|
|
8
|
+
import {
|
|
9
|
+
a as capnWebTransportUrl,
|
|
10
|
+
n as CAPNWEB_TRANSPORT_QUERY,
|
|
11
|
+
o as isCapnWebTransportUpgrade,
|
|
12
|
+
r as CAPNWEB_TRANSPORT_VALUE,
|
|
13
|
+
t as AgentTransport
|
|
14
|
+
} from "../transport-protocol-ZTew5Wso.js";
|
|
8
15
|
import { RpcTarget } from "cloudflare:workers";
|
|
9
16
|
|
|
10
17
|
//#region src/websockets/options.d.ts
|
|
18
|
+
/**
|
|
19
|
+
* The part of a `State` capability the WebSockets capability uses. A
|
|
20
|
+
* structural port, so any `State<T>` fits without a cast and the
|
|
21
|
+
* capability never depends on the class itself.
|
|
22
|
+
*/
|
|
23
|
+
type SyncedState = {
|
|
24
|
+
/** Current state, or `undefined` when nothing is stored. */ get(): unknown /** Validate and persist a change; throws when the host rejects it. */;
|
|
25
|
+
set(nextState: never, source: Connection): void;
|
|
26
|
+
};
|
|
11
27
|
/** A frame delivered on a capability-owned WebSocket connection. */
|
|
12
28
|
type WebSocketMessage = WSMessage;
|
|
13
29
|
/**
|
|
@@ -41,19 +57,63 @@ type WebSocketHandlers = {
|
|
|
41
57
|
*/
|
|
42
58
|
interface WebSocketsOptions {
|
|
43
59
|
/**
|
|
44
|
-
* Connection handlers for WebSocket clients.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
60
|
+
* Connection handlers for WebSocket clients. The capability accepts and
|
|
61
|
+
* tracks every WebSocket upgrade either way; handlers add behavior on
|
|
62
|
+
* connect, message, close and error.
|
|
47
63
|
*/
|
|
48
64
|
readonly handlers?: WebSocketHandlers;
|
|
49
65
|
/**
|
|
50
|
-
* An `RpcTarget` whose methods are
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
66
|
+
* An `RpcTarget` whose prototype methods are the host's complete remote
|
|
67
|
+
* interface, reached through `useAgent().call` and `.stub`. On the
|
|
68
|
+
* `cf-websocket` wire they are answered as JSON `rpc` frames. On the
|
|
69
|
+
* `capnweb` wire they are native Cap'n Web methods on the session root:
|
|
70
|
+
* an `RpcTarget` result becomes a live stub, a `ReadableStream` streams,
|
|
71
|
+
* and calls pipeline. Methods run through the host invocation boundary
|
|
72
|
+
* with the calling connection in scope. `Agent` answers its own
|
|
73
|
+
* decorated methods on the JSON wire and does not set this.
|
|
55
74
|
*/
|
|
56
75
|
readonly callables?: RpcTarget;
|
|
76
|
+
/**
|
|
77
|
+
* Whether a new connection gets the connect-time protocol frames —
|
|
78
|
+
* identity (`cf_agent_identity`), then the current state when `state`
|
|
79
|
+
* is set — and whether protocol frames reach it at all.
|
|
80
|
+
*
|
|
81
|
+
* - `true` (default): every connection.
|
|
82
|
+
* - a function: decided per connection at accept time. `false` marks
|
|
83
|
+
* the connection no-protocol: it gets no protocol text frames, on
|
|
84
|
+
* connect or via `broadcastState()`, but can still send and receive
|
|
85
|
+
* ordinary messages and use callables. For binary-only clients.
|
|
86
|
+
* - `false`: the host drives the connect sequence itself with
|
|
87
|
+
* `sendConnectFrames()` (or `sendIdentity()` and `sendState()`
|
|
88
|
+
* separately), and applies client state frames
|
|
89
|
+
* with `applyStateFrame()` — `Agent` does this, since it must decide
|
|
90
|
+
* whether a connection belongs to a facet before any frame is sent.
|
|
91
|
+
*/
|
|
92
|
+
readonly protocol?:
|
|
93
|
+
| boolean
|
|
94
|
+
| ((connection: Connection, ctx: ConnectionContext) => boolean);
|
|
95
|
+
/**
|
|
96
|
+
* Decide at accept time whether a connection is readonly. A readonly
|
|
97
|
+
* connection's `cf_agent_state` frames are refused with
|
|
98
|
+
* `cf_agent_state_error`; everything else works. Also settable later
|
|
99
|
+
* with `setReadonly()`.
|
|
100
|
+
*/
|
|
101
|
+
readonly readonly?: (
|
|
102
|
+
connection: Connection,
|
|
103
|
+
ctx: ConnectionContext
|
|
104
|
+
) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* A {@link SyncedState} — normally a `State` capability — to sync over
|
|
107
|
+
* connections. The capability pushes the current value to each new
|
|
108
|
+
* connection after identity and applies `cf_agent_state` frames a
|
|
109
|
+
* client sends: a readonly connection is refused, and a change the
|
|
110
|
+
* host's validator rejects is answered with `cf_agent_state_error`.
|
|
111
|
+
* Broadcasting a change is the state owner's call — wire the `State`'s
|
|
112
|
+
* `onChanged` to `broadcastState(source)`. Install the same instance on
|
|
113
|
+
* the lifecycle so it owns storage and validation; without this option
|
|
114
|
+
* state is never sent or accepted over connections.
|
|
115
|
+
*/
|
|
116
|
+
readonly state?: SyncedState;
|
|
57
117
|
/**
|
|
58
118
|
* Tags attached to each accepted connection, queryable through
|
|
59
119
|
* `getConnections(tag)`. The connection id is always the first tag.
|
|
@@ -70,18 +130,16 @@ interface WebSocketsOptions {
|
|
|
70
130
|
*
|
|
71
131
|
* Lifecycle itself does not model WebSockets — hosts that want them
|
|
72
132
|
* install this capability, which owns the connection subsystem end to
|
|
73
|
-
* end: it claims upgrades,
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* `getConnections()`/`getConnection()`.
|
|
133
|
+
* end: it claims upgrades, dispatches `onConnect`/`onMessage`/`onClose`
|
|
134
|
+
* inside the host invocation boundary, reciprocates close handshakes,
|
|
135
|
+
* and answers `getConnections()`/`getConnection()`.
|
|
77
136
|
*
|
|
78
137
|
* ```ts
|
|
79
138
|
* class Room extends DurableObject<Env> {
|
|
80
139
|
* readonly webSockets = new WebSockets({
|
|
81
140
|
* handlers: {
|
|
82
141
|
* onConnect: (connection) => connection.send("welcome"),
|
|
83
|
-
* onMessage: (connection, message) => { ... }
|
|
84
|
-
* onClose: (connection, code) => { ... }
|
|
142
|
+
* onMessage: (connection, message) => { ... }
|
|
85
143
|
* },
|
|
86
144
|
* callables: new RoomCallables()
|
|
87
145
|
* });
|
|
@@ -89,31 +147,44 @@ interface WebSocketsOptions {
|
|
|
89
147
|
* }
|
|
90
148
|
* ```
|
|
91
149
|
*
|
|
92
|
-
*
|
|
93
|
-
* callers over a Cap'n Web session claimed from `?__agents_rpc=capnweb`
|
|
94
|
-
* upgrades. Methods run through the host invocation boundary, may
|
|
95
|
-
* return a `ReadableStream` to stream results, and emit
|
|
96
|
-
* `rpc`/`rpc:error` capability events. Callable sessions are
|
|
97
|
-
* non-hibernating: while a client holds one open, the Durable Object
|
|
98
|
-
* stays pinned in memory.
|
|
150
|
+
* Connections arrive on one of two wires, chosen by the client:
|
|
99
151
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
152
|
+
* - **cf-websocket** (default): accepted with the Hibernation API. Idle
|
|
153
|
+
* clients stay connected while the Durable Object leaves memory.
|
|
154
|
+
* - **capnweb** (`?__agents_transport=capnweb`): protocol frames through
|
|
155
|
+
* one pipe method on a Cap'n Web session whose root also carries the
|
|
156
|
+
* host's callables natively. Non-hibernating — the object stays pinned
|
|
157
|
+
* while the connection is open.
|
|
158
|
+
*
|
|
159
|
+
* Both wires dispatch the same handlers and appear in `getConnections()`.
|
|
160
|
+
* On both, the capability speaks the Agent protocol a plain host needs
|
|
161
|
+
* for `useAgent` and `AgentClient`: it sends the identity frame on
|
|
162
|
+
* connect, and it serves `callables` — as `rpc` JSON frames on the
|
|
163
|
+
* WebSocket wire, and natively on the Cap'n Web session root, where an
|
|
164
|
+
* `RpcTarget` result becomes a live stub and calls pipeline. `call()`
|
|
165
|
+
* and `stub` work against a plain Durable Object exactly as against an
|
|
166
|
+
* `Agent`. Pass a `State` capability as `state` and the hook's
|
|
167
|
+
* `state`/`setState` work too: the current value is pushed on connect
|
|
168
|
+
* and client updates are validated and applied; the state owner
|
|
169
|
+
* broadcasts changes with `broadcastState()`. Per-connection readonly
|
|
170
|
+
* and no-protocol flags live here as well, for every host.
|
|
104
171
|
*
|
|
105
172
|
* @experimental The API surface may change before stabilizing.
|
|
106
173
|
*/
|
|
107
174
|
declare class WebSockets extends LifecycleCapability {
|
|
108
175
|
#private;
|
|
176
|
+
/** Claims every upgrade, so Lifecycle dispatches it after all others. */
|
|
177
|
+
readonly claims = "catch-all";
|
|
109
178
|
constructor(options?: WebSocketsOptions);
|
|
110
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Claim every upgrade, never declining: a Cap'n Web transport upgrade
|
|
181
|
+
* becomes a session, everything else a tracked hibernating connection,
|
|
182
|
+
* whether or not handlers or callables are configured. Handlers only add
|
|
183
|
+
* behavior on connect, message, close, and error.
|
|
184
|
+
*/
|
|
111
185
|
onWebSocketUpgrade({
|
|
112
186
|
request
|
|
113
|
-
}: CapabilityWebSocketUpgradeContext):
|
|
114
|
-
| Promise<Response>
|
|
115
|
-
| Response
|
|
116
|
-
| undefined;
|
|
187
|
+
}: CapabilityWebSocketUpgradeContext): Promise<Response>;
|
|
117
188
|
/** Dispatch a platform message wake for a capability-owned socket. */
|
|
118
189
|
onWebSocketMessage(
|
|
119
190
|
ws: WebSocket,
|
|
@@ -134,59 +205,114 @@ declare class WebSockets extends LifecycleCapability {
|
|
|
134
205
|
* them down.
|
|
135
206
|
*/
|
|
136
207
|
dispose(): void;
|
|
137
|
-
/** Open connections
|
|
208
|
+
/** Open connections on either wire, optionally by tag. */
|
|
138
209
|
getConnections<TState = unknown>(
|
|
139
210
|
tag?: string
|
|
140
211
|
): IterableIterator<Connection<TState>>;
|
|
141
|
-
/** One connection
|
|
212
|
+
/** One connection on either wire, by id. */
|
|
142
213
|
getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Send the connect sequence: the identity frame, then the current state
|
|
216
|
+
* when one is stored. The identity carries `stateFollows` in that case,
|
|
217
|
+
* so clients resolve `ready` only once the state has landed. Nothing is
|
|
218
|
+
* sent to a no-protocol connection. Identity defaults as for
|
|
219
|
+
* `sendIdentity()`.
|
|
220
|
+
*/
|
|
221
|
+
sendConnectFrames(
|
|
222
|
+
connection: Connection,
|
|
223
|
+
identity?: {
|
|
224
|
+
name: string;
|
|
225
|
+
agent: string;
|
|
226
|
+
}
|
|
227
|
+
): void;
|
|
228
|
+
/**
|
|
229
|
+
* Send the identity frame alone, unless the connection is no-protocol.
|
|
230
|
+
* Clients resolve `ready` on it, so a host that also pushes state on
|
|
231
|
+
* connect should use `sendConnectFrames()`. The defaults are the Durable
|
|
232
|
+
* Object's routed name and host class; a host whose public identity
|
|
233
|
+
* differs — an `Agent` facet, whose routed name is an internal encoding
|
|
234
|
+
* of its logical name — passes its own.
|
|
235
|
+
*/
|
|
236
|
+
sendIdentity(
|
|
237
|
+
connection: Connection,
|
|
238
|
+
identity?: {
|
|
239
|
+
name: string;
|
|
240
|
+
agent: string;
|
|
241
|
+
}
|
|
242
|
+
): void;
|
|
243
|
+
/**
|
|
244
|
+
* Send the current state to one connection, unless nothing is stored
|
|
245
|
+
* or the connection is no-protocol. Reading the state may seed the
|
|
246
|
+
* initial value; see `#connecting`.
|
|
247
|
+
*/
|
|
248
|
+
sendState(connection: Connection): void;
|
|
249
|
+
/**
|
|
250
|
+
* Apply a parsed `cf_agent_state` frame from a client. A readonly
|
|
251
|
+
* connection is refused; a change the host's validator rejects is
|
|
252
|
+
* logged in full server-side and answered with a generic
|
|
253
|
+
* `cf_agent_state_error`. Broadcasting the accepted change is the state
|
|
254
|
+
* owner's call, through its `onChanged` hook. Callers that drive the
|
|
255
|
+
* protocol themselves call this inside their own invocation context;
|
|
256
|
+
* the capability's automatic path does so via `runInHostContext`.
|
|
257
|
+
*
|
|
258
|
+
* @returns Whether the frame was a state frame (handled either way).
|
|
259
|
+
*/
|
|
260
|
+
applyStateFrame(connection: Connection, frame: unknown): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Push the current state to every protocol-enabled connection except
|
|
263
|
+
* the one a change came from, which already has the value it sent.
|
|
264
|
+
* Wire a `State`'s `onChanged` to this.
|
|
265
|
+
*/
|
|
266
|
+
broadcastState(except?: Connection | "server"): void;
|
|
267
|
+
/** Whether the connection may update host state over the wire. */
|
|
268
|
+
isReadonly(connection: Connection): boolean;
|
|
269
|
+
/** Mark a connection readonly, or writable again. */
|
|
270
|
+
setReadonly(connection: Connection, readonly?: boolean): void;
|
|
271
|
+
/** Whether protocol text frames reach the connection. */
|
|
272
|
+
isProtocolEnabled(connection: Connection): boolean;
|
|
273
|
+
/** Enable or suppress protocol text frames for a connection. */
|
|
274
|
+
setProtocolEnabled(connection: Connection, enabled: boolean): void;
|
|
143
275
|
}
|
|
144
276
|
//#endregion
|
|
145
|
-
//#region src/websockets/
|
|
277
|
+
//#region src/websockets/connection-flags.d.ts
|
|
146
278
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
279
|
+
* Internal per-connection flags, stored inside the connection's own state
|
|
280
|
+
* under `_cf_`-prefixed keys so they ride the hibernation attachment (or a
|
|
281
|
+
* bridged connection's synced state) and survive a wake. The state wrapper
|
|
282
|
+
* installed by {@link ensureConnectionWrapped} hides them from
|
|
283
|
+
* `connection.state` and preserves them across user `setState` calls.
|
|
150
284
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* Agent RPC protocol's injected `StreamingResponse` and are not exposed
|
|
155
|
-
* here — return a `ReadableStream` from an `RpcTarget` method instead.
|
|
156
|
-
*
|
|
157
|
-
* @param host - The object whose decorated methods form the interface.
|
|
158
|
-
* @returns A target exposing the decorated methods, or `undefined`
|
|
159
|
-
* when the host has none.
|
|
285
|
+
* Owned by the WebSockets capability; `Agent` and framework mixins reach it
|
|
286
|
+
* through the capability or, for their own keys, through
|
|
287
|
+
* {@link registerInternalConnectionKeys}.
|
|
160
288
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//#region src/websockets/protocol.d.ts
|
|
289
|
+
/** A readonly connection may not update host state. */
|
|
290
|
+
declare const CF_READONLY_KEY = "_cf_readonly";
|
|
164
291
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* Imported from browser bundles (via the client) and from the Worker
|
|
168
|
-
* runtime, so it must not import `cloudflare:workers`.
|
|
292
|
+
* A no-protocol connection receives no protocol text frames (identity,
|
|
293
|
+
* state sync, MCP servers) — neither on connect nor via broadcasts.
|
|
169
294
|
*/
|
|
170
|
-
|
|
171
|
-
declare const CALLABLES_RPC_QUERY = "__agents_rpc";
|
|
172
|
-
declare const CALLABLES_RPC_VALUE = "capnweb";
|
|
173
|
-
/** Whether a request is a WebSocket upgrade addressed to callables RPC. */
|
|
174
|
-
declare function isCallablesRpcUpgrade(request: Request): boolean;
|
|
295
|
+
declare const CF_NO_PROTOCOL_KEY = "_cf_no_protocol";
|
|
175
296
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
297
|
+
* Register additional `_cf_`-prefixed keys a host or mixin stores in
|
|
298
|
+
* connection state, so they are hidden from `connection.state` and kept
|
|
299
|
+
* across user `setState` calls like the capability's own flags.
|
|
178
300
|
*/
|
|
179
|
-
declare function
|
|
301
|
+
declare function registerInternalConnectionKeys(...keys: string[]): void;
|
|
180
302
|
//#endregion
|
|
181
303
|
export {
|
|
182
|
-
|
|
183
|
-
|
|
304
|
+
type AgentTransport,
|
|
305
|
+
CAPNWEB_TRANSPORT_QUERY,
|
|
306
|
+
CAPNWEB_TRANSPORT_VALUE,
|
|
307
|
+
CF_NO_PROTOCOL_KEY,
|
|
308
|
+
CF_READONLY_KEY,
|
|
309
|
+
type SyncedState,
|
|
184
310
|
type WebSocketHandlers,
|
|
185
311
|
type WebSocketMessage,
|
|
186
312
|
WebSockets,
|
|
187
313
|
type WebSocketsOptions,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
314
|
+
capnWebTransportUrl,
|
|
315
|
+
isCapnWebTransportUpgrade,
|
|
316
|
+
registerInternalConnectionKeys
|
|
191
317
|
};
|
|
192
318
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/websockets/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { a as isCapnWebTransportUpgrade, i as capnWebTransportUrl, r as CAPNWEB_TRANSPORT_VALUE, t as CAPNWEB_TRANSPORT_QUERY } from "../transport-protocol-BxyngQ_R.js";
|
|
2
|
+
import { l as registerInternalConnectionKeys, n as CF_NO_PROTOCOL_KEY, r as CF_READONLY_KEY, t as WebSockets } from "../websockets-Ci-LZFHH.js";
|
|
3
|
+
export { CAPNWEB_TRANSPORT_QUERY, CAPNWEB_TRANSPORT_VALUE, CF_NO_PROTOCOL_KEY, CF_READONLY_KEY, WebSockets, capnWebTransportUrl, isCapnWebTransportUpgrade, registerInternalConnectionKeys };
|