agents 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/browser/ai.js +4 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
- package/dist/callable-decorator.d.ts +18 -0
- package/dist/callable-decorator.js +71 -0
- package/dist/callable-decorator.js.map +1 -0
- package/dist/capability-BjSKYpzg.js.map +1 -1
- package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
- package/dist/channel-Bnm4S7T2.d.ts +491 -0
- package/dist/channels/ai-sdk.d.ts +46 -0
- package/dist/channels/ai-sdk.js +120 -0
- package/dist/channels/ai-sdk.js.map +1 -0
- package/dist/channels/email.d.ts +95 -0
- package/dist/channels/email.js +323 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/index.d.ts +233 -0
- package/dist/channels/index.js +608 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/slack.d.ts +140 -0
- package/dist/channels/slack.js +614 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/tanstack-ai.d.ts +39 -0
- package/dist/channels/tanstack-ai.js +17 -0
- package/dist/channels/tanstack-ai.js.map +1 -0
- package/dist/channels/telegram.d.ts +106 -0
- package/dist/channels/telegram.js +427 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/voice.d.ts +45 -0
- package/dist/channels/voice.js +122 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/chat/index.d.ts +2325 -2019
- package/dist/chat/index.js +888 -518
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +7 -7
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/context/index.d.ts +216 -0
- package/dist/context/index.js +454 -0
- package/dist/context/index.js.map +1 -0
- package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
- package/dist/diagnostics-BzvaX2UT.js.map +1 -0
- package/dist/diagnostics-C4jcz3VK.js +360 -0
- package/dist/diagnostics-C4jcz3VK.js.map +1 -0
- package/dist/index-BB0kqhIz.d.ts +101 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-XDkuQ7zm.d.ts +89 -0
- package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
- package/dist/index.d.ts +91 -82
- package/dist/index.js +3 -2
- package/dist/ingress-BfetZbMO.js +83 -0
- package/dist/ingress-BfetZbMO.js.map +1 -0
- package/dist/internal-CYlgHl1l.js +59 -0
- package/dist/internal-CYlgHl1l.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +35 -17
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle-CMRGjZdw.js +1299 -0
- package/dist/lifecycle-CMRGjZdw.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +13 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +137 -0
- package/dist/routing/index.js +244 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sanitize-D9TujEK8.js +79 -0
- package/dist/sanitize-D9TujEK8.js.map +1 -0
- package/dist/scheduler-DD9NdYbF.js +665 -0
- package/dist/scheduler-DD9NdYbF.js.map +1 -0
- package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +441 -0
- package/dist/sessions/index.js +2063 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/skills/index.d.ts +99 -0
- package/dist/skills/index.js +254 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
- package/dist/src-DlSHshb2.js.map +1 -0
- package/dist/streams/index.d.ts +120 -0
- package/dist/streams/index.js +107 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams-D6tJ0NN9.d.ts +370 -0
- package/dist/streams-DZKgAj9b.js +709 -0
- package/dist/streams-DZKgAj9b.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/surface-bZZJqBka.js +17 -0
- package/dist/surface-bZZJqBka.js.map +1 -0
- package/dist/tasks/index.d.ts +64 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks-BRJ5zgya.d.ts +517 -0
- package/dist/tasks-ylZgBjhj.js +1656 -0
- package/dist/tasks-ylZgBjhj.js.map +1 -0
- package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
- package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
- package/dist/text-stream-CpdiKrJB.js +272 -0
- package/dist/text-stream-CpdiKrJB.js.map +1 -0
- package/dist/tokens-nHAKcN6M.js +52 -0
- package/dist/tokens-nHAKcN6M.js.map +1 -0
- package/dist/tool-schema-CBjGPrsQ.js +31 -0
- package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
- package/dist/types-B7LojTe4.d.ts +202 -0
- package/dist/types-_Faxb570.d.ts +439 -0
- package/dist/voice/client.d.ts +226 -0
- package/dist/voice/client.js +932 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/errors.d.ts +43 -0
- package/dist/voice/errors.js +41 -0
- package/dist/voice/errors.js.map +1 -0
- package/dist/voice/index.d.ts +271 -0
- package/dist/voice/index.js +1812 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/react.d.ts +167 -0
- package/dist/voice/react.js +234 -0
- package/dist/voice/react.js.map +1 -0
- package/dist/voice/sfu.d.ts +71 -0
- package/dist/voice/sfu.js +157 -0
- package/dist/voice/sfu.js.map +1 -0
- package/dist/voice/text.d.ts +6 -0
- package/dist/voice/text.js +2 -0
- package/dist/voice/types.d.ts +58 -0
- package/dist/voice/types.js +18 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/workers-ai.d.ts +136 -0
- package/dist/voice/workers-ai.js +568 -0
- package/dist/voice/workers-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +192 -0
- package/dist/websockets/index.js +2 -0
- package/dist/websockets-DUfRHPRq.js +502 -0
- package/dist/websockets-DUfRHPRq.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/docs/agent-class.md +2 -2
- package/docs/agent-tools.md +2 -1
- package/docs/channels.md +323 -0
- package/docs/chat-agents.md +6 -13
- package/docs/context.md +131 -0
- package/docs/index.md +15 -12
- package/docs/lifecycle.md +102 -55
- package/docs/long-running-agents.md +2 -2
- package/docs/mcp-servers.md +5 -1
- package/docs/resumable-streaming.md +1 -1
- package/docs/routing.md +105 -0
- package/docs/sessions.md +237 -871
- package/docs/streams.md +213 -0
- package/docs/sub-agents.md +184 -124
- package/docs/tasks.md +246 -0
- package/docs/voice.md +745 -0
- package/package.json +115 -13
- package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
- package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
- package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
- package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
- package/dist/diagnostics-CaBjfz4J.js.map +0 -1
- package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
- package/dist/experimental/memory/session/index.d.ts +0 -671
- package/dist/experimental/memory/session/index.js +0 -2379
- package/dist/experimental/memory/session/index.js.map +0 -1
- package/dist/experimental/memory/utils/index.d.ts +0 -96
- package/dist/experimental/memory/utils/index.js +0 -79
- package/dist/experimental/memory/utils/index.js.map +0 -1
- package/dist/scheduler-CR9RHGos.js +0 -857
- package/dist/scheduler-CR9RHGos.js.map +0 -1
- package/dist/src-5W6JNKVb.js.map +0 -1
- package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
- package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { decoratedMethods } from "./callable-decorator.js";
|
|
2
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
|
|
3
|
+
import { t as LifecycleCapability } from "./capability-BjSKYpzg.js";
|
|
4
|
+
import { t as _classPrivateMethodInitSpec } from "./classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
5
|
+
import "./lifecycle-CMRGjZdw.js";
|
|
6
|
+
import { RpcTarget } from "cloudflare:workers";
|
|
7
|
+
import { nanoid } from "nanoid";
|
|
8
|
+
import { newWorkersWebSocketRpcResponse } from "capnweb";
|
|
9
|
+
//#region src/websockets/connection.ts
|
|
10
|
+
let _Symbol$iterator;
|
|
11
|
+
if (!("OPEN" in WebSocket)) {
|
|
12
|
+
const WebSocketStatus = {
|
|
13
|
+
CONNECTING: WebSocket.READY_STATE_CONNECTING,
|
|
14
|
+
OPEN: WebSocket.READY_STATE_OPEN,
|
|
15
|
+
CLOSING: WebSocket.READY_STATE_CLOSING,
|
|
16
|
+
CLOSED: WebSocket.READY_STATE_CLOSED
|
|
17
|
+
};
|
|
18
|
+
Object.assign(WebSocket, WebSocketStatus);
|
|
19
|
+
Object.assign(WebSocket.prototype, WebSocketStatus);
|
|
20
|
+
}
|
|
21
|
+
function tryGetManagedWebSocketMeta(ws) {
|
|
22
|
+
try {
|
|
23
|
+
const attachment = WebSocket.prototype.deserializeAttachment.call(ws);
|
|
24
|
+
if (!attachment || typeof attachment !== "object") return null;
|
|
25
|
+
if (!("__pk" in attachment)) return null;
|
|
26
|
+
const pk = attachment.__pk;
|
|
27
|
+
if (!pk || typeof pk !== "object") return null;
|
|
28
|
+
const { id, tags } = pk;
|
|
29
|
+
if (typeof id !== "string") return null;
|
|
30
|
+
const { uri } = pk;
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
tags: Array.isArray(tags) ? tags : [],
|
|
34
|
+
uri: typeof uri === "string" ? uri : void 0
|
|
35
|
+
};
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isManagedWebSocket(ws) {
|
|
41
|
+
return tryGetManagedWebSocketMeta(ws) !== null;
|
|
42
|
+
}
|
|
43
|
+
var _cache = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
/**
|
|
45
|
+
* Cache websocket attachments to avoid having to rehydrate them on every property access.
|
|
46
|
+
*/
|
|
47
|
+
var AttachmentCache = class {
|
|
48
|
+
constructor() {
|
|
49
|
+
_classPrivateFieldInitSpec(this, _cache, /* @__PURE__ */ new WeakMap());
|
|
50
|
+
}
|
|
51
|
+
get(ws) {
|
|
52
|
+
let attachment = _classPrivateFieldGet2(_cache, this).get(ws);
|
|
53
|
+
if (!attachment) {
|
|
54
|
+
attachment = WebSocket.prototype.deserializeAttachment.call(ws);
|
|
55
|
+
if (attachment !== void 0) _classPrivateFieldGet2(_cache, this).set(ws, attachment);
|
|
56
|
+
else throw new Error("Missing managed WebSocket lifecycle attachment");
|
|
57
|
+
}
|
|
58
|
+
return attachment;
|
|
59
|
+
}
|
|
60
|
+
set(ws, attachment) {
|
|
61
|
+
_classPrivateFieldGet2(_cache, this).set(ws, attachment);
|
|
62
|
+
WebSocket.prototype.serializeAttachment.call(ws, attachment);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const attachments = new AttachmentCache();
|
|
66
|
+
const connections = /* @__PURE__ */ new WeakSet();
|
|
67
|
+
const isWrapped = (ws) => {
|
|
68
|
+
return connections.has(ws);
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Wraps a WebSocket with Connection fields that rehydrate the
|
|
72
|
+
* socket attachments lazily only when requested.
|
|
73
|
+
*/
|
|
74
|
+
const createConnection = (ws) => {
|
|
75
|
+
if (isWrapped(ws)) return ws;
|
|
76
|
+
let initialState;
|
|
77
|
+
if ("state" in ws) {
|
|
78
|
+
initialState = ws.state;
|
|
79
|
+
delete ws.state;
|
|
80
|
+
}
|
|
81
|
+
const connection = Object.defineProperties(ws, {
|
|
82
|
+
id: {
|
|
83
|
+
configurable: true,
|
|
84
|
+
get() {
|
|
85
|
+
return attachments.get(ws).__pk.id;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
uri: {
|
|
89
|
+
configurable: true,
|
|
90
|
+
get() {
|
|
91
|
+
return attachments.get(ws).__pk.uri ?? null;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
tags: {
|
|
95
|
+
configurable: true,
|
|
96
|
+
get() {
|
|
97
|
+
return attachments.get(ws).__pk.tags ?? [];
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
state: {
|
|
101
|
+
configurable: true,
|
|
102
|
+
get() {
|
|
103
|
+
return attachments.get(ws).__user ?? null;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
setState: {
|
|
107
|
+
configurable: true,
|
|
108
|
+
value: function setState(setState) {
|
|
109
|
+
const state = setState instanceof Function ? setState(this.state) : setState;
|
|
110
|
+
attachments.set(ws, {
|
|
111
|
+
...attachments.get(ws),
|
|
112
|
+
__user: state ?? null
|
|
113
|
+
});
|
|
114
|
+
return state;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (initialState) connection.setState(initialState);
|
|
119
|
+
connections.add(connection);
|
|
120
|
+
return connection;
|
|
121
|
+
};
|
|
122
|
+
var _sockets = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
_Symbol$iterator = Symbol.iterator;
|
|
124
|
+
var ConnectionIterator = class {
|
|
125
|
+
constructor(sockets, tag) {
|
|
126
|
+
this.sockets = sockets;
|
|
127
|
+
this.tag = tag;
|
|
128
|
+
this.index = 0;
|
|
129
|
+
_classPrivateFieldInitSpec(this, _sockets, void 0);
|
|
130
|
+
}
|
|
131
|
+
[_Symbol$iterator]() {
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
next() {
|
|
135
|
+
const sockets = _classPrivateFieldGet2(_sockets, this) ?? _classPrivateFieldSet2(_sockets, this, this.sockets.get(this.tag));
|
|
136
|
+
let socket;
|
|
137
|
+
while (socket = sockets[this.index++]) if (socket.readyState === WebSocket.OPEN) {
|
|
138
|
+
if (!isManagedWebSocket(socket)) continue;
|
|
139
|
+
return {
|
|
140
|
+
done: false,
|
|
141
|
+
value: createConnection(socket)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
done: true,
|
|
146
|
+
value: void 0
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Deduplicate and validate connection tags.
|
|
152
|
+
* Returns the final tag array (always includes the connection id as the first tag).
|
|
153
|
+
*/
|
|
154
|
+
function prepareTags(connectionId, userTags) {
|
|
155
|
+
const tags = [connectionId, ...userTags.filter((t) => t !== connectionId)];
|
|
156
|
+
if (tags.length > 10) throw new Error("A connection can only have 10 tags, including the default id tag.");
|
|
157
|
+
for (const tag of tags) {
|
|
158
|
+
if (typeof tag !== "string") throw new Error(`A connection tag must be a string. Received: ${tag}`);
|
|
159
|
+
if (tag === "") throw new Error("A connection tag must not be an empty string.");
|
|
160
|
+
if (tag.length > 256) throw new Error("A connection tag must not exceed 256 characters");
|
|
161
|
+
}
|
|
162
|
+
return tags;
|
|
163
|
+
}
|
|
164
|
+
/** The platform-backed manager for hibernating WebSockets. */
|
|
165
|
+
var ConnectionManager = class {
|
|
166
|
+
constructor(controller) {
|
|
167
|
+
this.controller = controller;
|
|
168
|
+
}
|
|
169
|
+
getConnection(id) {
|
|
170
|
+
const matching = this.controller.get(id).filter((ws) => {
|
|
171
|
+
return tryGetManagedWebSocketMeta(ws)?.id === id;
|
|
172
|
+
});
|
|
173
|
+
if (matching.length === 0) return void 0;
|
|
174
|
+
if (matching.length === 1) return createConnection(matching[0]);
|
|
175
|
+
throw new Error(`More than one connection found for id ${id}. Did you mean to use getConnections(tag) instead?`);
|
|
176
|
+
}
|
|
177
|
+
getConnections(tag) {
|
|
178
|
+
return new ConnectionIterator(this.controller, tag);
|
|
179
|
+
}
|
|
180
|
+
accept(connection, options) {
|
|
181
|
+
const tags = prepareTags(connection.id, options.tags);
|
|
182
|
+
this.controller.accept(connection, tags);
|
|
183
|
+
attachments.set(connection, {
|
|
184
|
+
__pk: {
|
|
185
|
+
id: connection.id,
|
|
186
|
+
tags,
|
|
187
|
+
uri: connection.uri ?? void 0
|
|
188
|
+
},
|
|
189
|
+
__user: null
|
|
190
|
+
});
|
|
191
|
+
return createConnection(connection);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/websockets/callables-target.ts
|
|
196
|
+
/**
|
|
197
|
+
* The single exposure policy for callable names. `Object.prototype` and
|
|
198
|
+
* `RpcTarget.prototype` members are unreachable over Cap'n Web anyway
|
|
199
|
+
* and are silently excluded; `then` is rejected loudly because exposing
|
|
200
|
+
* it would make the remote stub thenable.
|
|
201
|
+
*/
|
|
202
|
+
function assertExposable(name) {
|
|
203
|
+
if (name === "then") throw new Error("A callables target cannot expose a method named \"then\" — it would make the remote stub thenable");
|
|
204
|
+
return !(name === "constructor" || name in Object.prototype || name in RpcTarget.prototype);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The exposable prototype methods of a callables target, each bound to
|
|
208
|
+
* invoke on the real instance (so private fields and `this` behave).
|
|
209
|
+
*
|
|
210
|
+
* Cap'n Web resolves methods on the prototype chain and rejects own
|
|
211
|
+
* instance properties, so only prototype methods participate. The
|
|
212
|
+
* nearest declaration wins for overridden names.
|
|
213
|
+
*
|
|
214
|
+
* @param target - The callables target to enumerate.
|
|
215
|
+
* @returns Method names mapped to invokers on the target.
|
|
216
|
+
*/
|
|
217
|
+
function exposableMethods(target) {
|
|
218
|
+
const methods = /* @__PURE__ */ new Map();
|
|
219
|
+
const seen = /* @__PURE__ */ new Set();
|
|
220
|
+
let prototype = Object.getPrototypeOf(target);
|
|
221
|
+
while (prototype && prototype !== RpcTarget.prototype && prototype !== Object.prototype) {
|
|
222
|
+
for (const name of Object.getOwnPropertyNames(prototype)) {
|
|
223
|
+
if (seen.has(name)) continue;
|
|
224
|
+
seen.add(name);
|
|
225
|
+
if (!assertExposable(name)) continue;
|
|
226
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
227
|
+
if (!descriptor || typeof descriptor.value !== "function") continue;
|
|
228
|
+
const method = descriptor.value;
|
|
229
|
+
methods.set(name, (...args) => Reflect.apply(method, target, args));
|
|
230
|
+
}
|
|
231
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
232
|
+
}
|
|
233
|
+
return methods;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Build a Cap'n Web session root exposing exactly the given methods.
|
|
237
|
+
*
|
|
238
|
+
* Cap'n Web resolves methods on the prototype chain, rejects own
|
|
239
|
+
* instance properties, and breaks on Proxy-wrapped roots — so the root
|
|
240
|
+
* is a private `RpcTarget` subclass whose prototype carries the
|
|
241
|
+
* methods and nothing else.
|
|
242
|
+
*
|
|
243
|
+
* @param methods - Method names mapped to their invokers.
|
|
244
|
+
* @returns A root suitable as a Cap'n Web session's local main.
|
|
245
|
+
*/
|
|
246
|
+
function buildCallablesRoot(methods) {
|
|
247
|
+
class CallablesRoot extends RpcTarget {}
|
|
248
|
+
for (const [name, invoke] of methods) Object.defineProperty(CallablesRoot.prototype, name, {
|
|
249
|
+
value: invoke,
|
|
250
|
+
writable: true,
|
|
251
|
+
configurable: true,
|
|
252
|
+
enumerable: false
|
|
253
|
+
});
|
|
254
|
+
return new CallablesRoot();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Build a callables target from a host's `@callable()`-decorated
|
|
258
|
+
* methods — the fallback interface source when no `RpcTarget` is
|
|
259
|
+
* configured (an explicit target is preferred and wins).
|
|
260
|
+
*
|
|
261
|
+
* Methods are resolved on the host at call time, so framework wrapping
|
|
262
|
+
* applied after construction (e.g. Agent's context auto-wrapping) is
|
|
263
|
+
* honored. Methods registered with `streaming: true` expect the legacy
|
|
264
|
+
* Agent RPC protocol's injected `StreamingResponse` and are not exposed
|
|
265
|
+
* here — return a `ReadableStream` from an `RpcTarget` method instead.
|
|
266
|
+
*
|
|
267
|
+
* @param host - The object whose decorated methods form the interface.
|
|
268
|
+
* @returns A target exposing the decorated methods, or `undefined`
|
|
269
|
+
* when the host has none.
|
|
270
|
+
*/
|
|
271
|
+
function callablesFromDecorated(host) {
|
|
272
|
+
const methods = /* @__PURE__ */ new Map();
|
|
273
|
+
for (const [name, metadata] of decoratedMethods(host)) {
|
|
274
|
+
if (metadata.streaming || !assertExposable(name)) continue;
|
|
275
|
+
methods.set(name, (...args) => {
|
|
276
|
+
const method = Reflect.get(host, name);
|
|
277
|
+
if (typeof method !== "function") throw new Error(`Method ${name} is not callable`);
|
|
278
|
+
return Reflect.apply(method, host, args);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (methods.size === 0) return void 0;
|
|
282
|
+
return buildCallablesRoot(methods);
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/websockets/protocol.ts
|
|
286
|
+
/**
|
|
287
|
+
* Isomorphic pieces of the callables RPC wire contract.
|
|
288
|
+
*
|
|
289
|
+
* Imported from browser bundles (via the client) and from the Worker
|
|
290
|
+
* runtime, so it must not import `cloudflare:workers`.
|
|
291
|
+
*/
|
|
292
|
+
/** Query parameter selecting the callables Cap'n Web RPC endpoint. */
|
|
293
|
+
const CALLABLES_RPC_QUERY = "__agents_rpc";
|
|
294
|
+
const CALLABLES_RPC_VALUE = "capnweb";
|
|
295
|
+
/** Whether a request is a WebSocket upgrade addressed to callables RPC. */
|
|
296
|
+
function isCallablesRpcUpgrade(request) {
|
|
297
|
+
return request.headers.get("Upgrade")?.toLowerCase() === "websocket" && new URL(request.url).searchParams.get("__agents_rpc") === "capnweb";
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Derive the callables RPC socket URL from a host route. Accepts http(s)
|
|
301
|
+
* or ws(s) URLs and returns a ws(s) URL with the RPC query parameter set.
|
|
302
|
+
*/
|
|
303
|
+
function callablesRpcUrl(url) {
|
|
304
|
+
const resolved = new URL(url);
|
|
305
|
+
if (resolved.protocol === "http:") resolved.protocol = "ws:";
|
|
306
|
+
if (resolved.protocol === "https:") resolved.protocol = "wss:";
|
|
307
|
+
resolved.searchParams.set(CALLABLES_RPC_QUERY, CALLABLES_RPC_VALUE);
|
|
308
|
+
return resolved.toString();
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/websockets/websockets.ts
|
|
312
|
+
/**
|
|
313
|
+
* Reserved close codes the runtime synthesizes when there was no real
|
|
314
|
+
* Close frame from the peer (1005 NoStatusReceived, 1006 AbnormalClosure,
|
|
315
|
+
* 1015 TLSHandshake). They cannot appear in an outgoing Close frame, and
|
|
316
|
+
* there is no peer left to receive a reciprocation.
|
|
317
|
+
*/
|
|
318
|
+
function isReservedCloseCode(code) {
|
|
319
|
+
return code === 1005 || code === 1006 || code === 1015;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Reciprocate a peer-initiated Close frame to complete the handshake, as
|
|
323
|
+
* the Hibernation API contract requires. Best-effort: swallows errors
|
|
324
|
+
* from already-closed sockets or invalid codes/reasons, and skips
|
|
325
|
+
* reciprocation entirely for reserved codes (dead transport).
|
|
326
|
+
*/
|
|
327
|
+
function reciprocateClose(ws, code, reason) {
|
|
328
|
+
if (isReservedCloseCode(code)) return;
|
|
329
|
+
try {
|
|
330
|
+
ws.close(code, reason);
|
|
331
|
+
} catch {}
|
|
332
|
+
}
|
|
333
|
+
var _handlers = /* @__PURE__ */ new WeakMap();
|
|
334
|
+
var _getConnectionTags = /* @__PURE__ */ new WeakMap();
|
|
335
|
+
var _callablesTarget = /* @__PURE__ */ new WeakMap();
|
|
336
|
+
var _manager = /* @__PURE__ */ new WeakMap();
|
|
337
|
+
var _WebSockets_brand = /* @__PURE__ */ new WeakSet();
|
|
338
|
+
/**
|
|
339
|
+
* Opt-in WebSocket support for Lifecycle Objects.
|
|
340
|
+
*
|
|
341
|
+
* Lifecycle itself does not model WebSockets — hosts that want them
|
|
342
|
+
* install this capability, which owns the connection subsystem end to
|
|
343
|
+
* end: it claims upgrades, accepts hibernating sockets, dispatches
|
|
344
|
+
* `onConnect`/`onMessage`/`onClose` inside the host invocation
|
|
345
|
+
* boundary, reciprocates close handshakes, and answers
|
|
346
|
+
* `getConnections()`/`getConnection()`.
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* class Room extends DurableObject<Env> {
|
|
350
|
+
* readonly webSockets = new WebSockets({
|
|
351
|
+
* handlers: {
|
|
352
|
+
* onConnect: (connection) => connection.send("welcome"),
|
|
353
|
+
* onMessage: (connection, message) => { ... },
|
|
354
|
+
* onClose: (connection, code) => { ... }
|
|
355
|
+
* },
|
|
356
|
+
* callables: new RoomCallables()
|
|
357
|
+
* });
|
|
358
|
+
* readonly lifecycle = Lifecycle.install(this).use(this.webSockets);
|
|
359
|
+
* }
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* `callables` exposes an `RpcTarget`'s prototype methods to remote
|
|
363
|
+
* callers over a Cap'n Web session claimed from `?__agents_rpc=capnweb`
|
|
364
|
+
* upgrades. Methods run through the host invocation boundary, may
|
|
365
|
+
* return a `ReadableStream` to stream results, and emit
|
|
366
|
+
* `rpc`/`rpc:error` capability events. Callable sessions are
|
|
367
|
+
* non-hibernating: while a client holds one open, the Durable Object
|
|
368
|
+
* stays pinned in memory.
|
|
369
|
+
*
|
|
370
|
+
* There is no separate browser client: against an `Agent`, the
|
|
371
|
+
* `useAgent` hook's `stub`/`call` reach the same interface over the
|
|
372
|
+
* protocol socket. A plain host's endpoint is reached with capnweb
|
|
373
|
+
* directly — `newWebSocketRpcSession(new WebSocket(callablesRpcUrl(url)))`.
|
|
374
|
+
*
|
|
375
|
+
* @experimental The API surface may change before stabilizing.
|
|
376
|
+
*/
|
|
377
|
+
var WebSockets = class extends LifecycleCapability {
|
|
378
|
+
constructor(options = {}) {
|
|
379
|
+
super("websockets");
|
|
380
|
+
_classPrivateMethodInitSpec(this, _WebSockets_brand);
|
|
381
|
+
_classPrivateFieldInitSpec(this, _handlers, void 0);
|
|
382
|
+
_classPrivateFieldInitSpec(this, _getConnectionTags, void 0);
|
|
383
|
+
_classPrivateFieldInitSpec(this, _callablesTarget, void 0);
|
|
384
|
+
_classPrivateFieldInitSpec(this, _manager, void 0);
|
|
385
|
+
_classPrivateFieldSet2(_handlers, this, options.handlers);
|
|
386
|
+
_classPrivateFieldSet2(_getConnectionTags, this, options.getConnectionTags);
|
|
387
|
+
_classPrivateFieldSet2(_callablesTarget, this, options.callables ? _assertClassBrand(_WebSockets_brand, this, _buildCallablesTarget).call(this, options.callables) : void 0);
|
|
388
|
+
}
|
|
389
|
+
/** Claim callables RPC upgrades and, with handlers, plain upgrades. */
|
|
390
|
+
onWebSocketUpgrade({ request }) {
|
|
391
|
+
if (isCallablesRpcUpgrade(request)) {
|
|
392
|
+
if (!_classPrivateFieldGet2(_callablesTarget, this)) return void 0;
|
|
393
|
+
return newWorkersWebSocketRpcResponse(request, _classPrivateFieldGet2(_callablesTarget, this));
|
|
394
|
+
}
|
|
395
|
+
if (!_classPrivateFieldGet2(_handlers, this)) return void 0;
|
|
396
|
+
return _assertClassBrand(_WebSockets_brand, this, _acceptConnection).call(this, request);
|
|
397
|
+
}
|
|
398
|
+
/** Dispatch a platform message wake for a capability-owned socket. */
|
|
399
|
+
async onWebSocketMessage(ws, message) {
|
|
400
|
+
if (!isManagedWebSocket(ws)) return false;
|
|
401
|
+
const connection = createConnection(ws);
|
|
402
|
+
await this.lifecycle.runInHostContext(() => _classPrivateFieldGet2(_handlers, this)?.onMessage?.(connection, message), { connection });
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
/** Dispatch and reciprocate a close wake for an owned socket. */
|
|
406
|
+
async onWebSocketClose(ws, code, reason, wasClean) {
|
|
407
|
+
if (!isManagedWebSocket(ws)) return false;
|
|
408
|
+
const connection = createConnection(ws);
|
|
409
|
+
try {
|
|
410
|
+
await this.lifecycle.runInHostContext(() => _classPrivateFieldGet2(_handlers, this)?.onClose?.(connection, code, reason, wasClean), { connection });
|
|
411
|
+
} finally {
|
|
412
|
+
reciprocateClose(ws, code, reason);
|
|
413
|
+
}
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
/** Dispatch an error wake for an owned socket. */
|
|
417
|
+
async onWebSocketError(ws, error) {
|
|
418
|
+
if (!isManagedWebSocket(ws)) return false;
|
|
419
|
+
const connection = createConnection(ws);
|
|
420
|
+
await this.lifecycle.runInHostContext(() => _classPrivateFieldGet2(_handlers, this)?.onError?.(connection, error), { connection });
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Close every owned connection during explicit host destruction. The
|
|
425
|
+
* capability owns its sockets' lifetimes, so it also owns tearing
|
|
426
|
+
* them down.
|
|
427
|
+
*/
|
|
428
|
+
dispose() {
|
|
429
|
+
for (const connection of this.getConnections()) try {
|
|
430
|
+
connection.close(1001, "Durable Object destroyed");
|
|
431
|
+
} catch {}
|
|
432
|
+
}
|
|
433
|
+
/** Open connections accepted by this capability, optionally by tag. */
|
|
434
|
+
getConnections(tag) {
|
|
435
|
+
return _get_connectionManager.call(_assertClassBrand(_WebSockets_brand, this)).getConnections(tag);
|
|
436
|
+
}
|
|
437
|
+
/** One connection accepted by this capability, by id. */
|
|
438
|
+
getConnection(id) {
|
|
439
|
+
return _get_connectionManager.call(_assertClassBrand(_WebSockets_brand, this)).getConnection(id);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
function _get_connectionManager() {
|
|
443
|
+
_classPrivateFieldGet2(_manager, this) ?? _classPrivateFieldSet2(_manager, this, new ConnectionManager(this.lifecycle.sockets));
|
|
444
|
+
return _classPrivateFieldGet2(_manager, this);
|
|
445
|
+
}
|
|
446
|
+
async function _acceptConnection(request) {
|
|
447
|
+
const { 0: clientWebSocket, 1: serverWebSocket } = new WebSocketPair();
|
|
448
|
+
const connectionId = new URL(request.url).searchParams.get("_pk") || nanoid();
|
|
449
|
+
let connection = Object.assign(serverWebSocket, {
|
|
450
|
+
id: connectionId,
|
|
451
|
+
uri: request.url,
|
|
452
|
+
tags: [],
|
|
453
|
+
state: null,
|
|
454
|
+
setState(setState) {
|
|
455
|
+
const state = setState instanceof Function ? setState(this.state) : setState;
|
|
456
|
+
this.state = state;
|
|
457
|
+
return this.state;
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
const ctx = { request };
|
|
461
|
+
const tags = _classPrivateFieldGet2(_getConnectionTags, this) ? await _classPrivateFieldGet2(_getConnectionTags, this).call(this, connection, ctx) : [];
|
|
462
|
+
connection = _get_connectionManager.call(_assertClassBrand(_WebSockets_brand, this)).accept(connection, { tags });
|
|
463
|
+
await this.lifecycle.runInHostContext(() => _classPrivateFieldGet2(_handlers, this)?.onConnect?.(connection, ctx), {
|
|
464
|
+
connection,
|
|
465
|
+
request
|
|
466
|
+
});
|
|
467
|
+
return new Response(null, {
|
|
468
|
+
status: 101,
|
|
469
|
+
webSocket: clientWebSocket
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Wrap a callables target for serving: every exposable method
|
|
474
|
+
* dispatches through the host invocation boundary and emits
|
|
475
|
+
* `rpc`/`rpc:error` events.
|
|
476
|
+
*/
|
|
477
|
+
function _buildCallablesTarget(target) {
|
|
478
|
+
const dispatching = /* @__PURE__ */ new Map();
|
|
479
|
+
for (const [name, invoke] of exposableMethods(target)) dispatching.set(name, (...args) => _assertClassBrand(_WebSockets_brand, this, _dispatchCallable).call(this, name, () => invoke(...args)));
|
|
480
|
+
return buildCallablesRoot(dispatching);
|
|
481
|
+
}
|
|
482
|
+
async function _dispatchCallable(name, invoke) {
|
|
483
|
+
const services = this.lifecycle;
|
|
484
|
+
try {
|
|
485
|
+
const result = await services.runInHostContext(invoke);
|
|
486
|
+
services.events.emit("rpc", {
|
|
487
|
+
method: name,
|
|
488
|
+
streaming: result instanceof ReadableStream
|
|
489
|
+
});
|
|
490
|
+
return result;
|
|
491
|
+
} catch (error) {
|
|
492
|
+
services.events.emit("rpc:error", {
|
|
493
|
+
method: name,
|
|
494
|
+
error: error instanceof Error ? error.message : String(error)
|
|
495
|
+
});
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
export { isCallablesRpcUpgrade as a, callablesRpcUrl as i, CALLABLES_RPC_QUERY as n, callablesFromDecorated as o, CALLABLES_RPC_VALUE as r, WebSockets as t };
|
|
501
|
+
|
|
502
|
+
//# sourceMappingURL=websockets-DUfRHPRq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websockets-DUfRHPRq.js","names":[],"sources":["../src/websockets/connection.ts","../src/websockets/callables-target.ts","../src/websockets/protocol.ts","../src/websockets/websockets.ts"],"sourcesContent":["// Polyfill WebSocket status code constants for environments that don't have them\n// in order to support libraries that expect standards-compatible WebSocket\n// implementations (e.g. PartySocket)\n\nimport type {\n Connection,\n ConnectionSetStateFn,\n ConnectionState,\n LifecycleSockets\n} from \"../lifecycle\";\n\nif (!(\"OPEN\" in WebSocket)) {\n const WebSocketStatus = {\n // @ts-expect-error\n CONNECTING: WebSocket.READY_STATE_CONNECTING,\n // @ts-expect-error\n OPEN: WebSocket.READY_STATE_OPEN,\n // @ts-expect-error\n CLOSING: WebSocket.READY_STATE_CLOSING,\n // @ts-expect-error\n CLOSED: WebSocket.READY_STATE_CLOSED\n };\n\n Object.assign(WebSocket, WebSocketStatus);\n // @ts-expect-error\n Object.assign(WebSocket.prototype, WebSocketStatus);\n}\n\n/**\n * Store both platform attachments and user attachments in different namespaces\n */\ntype ConnectionAttachments = {\n __pk: {\n id: string;\n tags: string[];\n uri?: string;\n };\n __user?: unknown;\n};\n\nfunction tryGetManagedWebSocketMeta(\n ws: WebSocket\n): ConnectionAttachments[\"__pk\"] | null {\n try {\n // Avoid AttachmentCache.get() here: externally accepted sockets\n // can have an attachment without the managed __pk namespace.\n const attachment = WebSocket.prototype.deserializeAttachment.call(\n ws\n ) as unknown;\n if (!attachment || typeof attachment !== \"object\") {\n return null;\n }\n if (!(\"__pk\" in attachment)) {\n return null;\n }\n const pk = (attachment as ConnectionAttachments).__pk as unknown;\n if (!pk || typeof pk !== \"object\") {\n return null;\n }\n const { id, tags } = pk as {\n id?: unknown;\n tags?: unknown;\n };\n if (typeof id !== \"string\") {\n return null;\n }\n const { uri } = pk as { uri?: unknown };\n return {\n id,\n tags: Array.isArray(tags) ? tags : [],\n uri: typeof uri === \"string\" ? uri : undefined\n } satisfies ConnectionAttachments[\"__pk\"];\n } catch {\n return null;\n }\n}\n\nexport function isManagedWebSocket(ws: WebSocket): boolean {\n return tryGetManagedWebSocketMeta(ws) !== null;\n}\n\n/**\n * Cache websocket attachments to avoid having to rehydrate them on every property access.\n */\nclass AttachmentCache {\n #cache = new WeakMap<WebSocket, ConnectionAttachments>();\n\n get(ws: WebSocket): ConnectionAttachments {\n let attachment = this.#cache.get(ws);\n if (!attachment) {\n attachment = WebSocket.prototype.deserializeAttachment.call(\n ws\n ) as ConnectionAttachments;\n if (attachment !== undefined) {\n this.#cache.set(ws, attachment);\n } else {\n throw new Error(\"Missing managed WebSocket lifecycle attachment\");\n }\n }\n\n return attachment;\n }\n\n set(ws: WebSocket, attachment: ConnectionAttachments) {\n this.#cache.set(ws, attachment);\n WebSocket.prototype.serializeAttachment.call(ws, attachment);\n }\n}\n\nconst attachments = new AttachmentCache();\nconst connections = new WeakSet<Connection>();\nconst isWrapped = (ws: WebSocket): ws is Connection => {\n return connections.has(ws as Connection);\n};\n\n/**\n * Wraps a WebSocket with Connection fields that rehydrate the\n * socket attachments lazily only when requested.\n */\nexport const createConnection = (ws: WebSocket | Connection): Connection => {\n if (isWrapped(ws)) {\n return ws;\n }\n\n // if state was set on the socket before initializing the connection,\n // capture it here so we can persist it again\n let initialState;\n if (\"state\" in ws) {\n initialState = ws.state;\n delete ws.state;\n }\n\n const connection = Object.defineProperties(ws, {\n id: {\n configurable: true,\n get() {\n return attachments.get(ws).__pk.id;\n }\n },\n uri: {\n configurable: true,\n get() {\n return attachments.get(ws).__pk.uri ?? null;\n }\n },\n tags: {\n configurable: true,\n get() {\n // Default to [] for connections accepted before tags were stored\n return attachments.get(ws).__pk.tags ?? [];\n }\n },\n state: {\n configurable: true,\n get() {\n const attachment = attachments.get(ws);\n return (attachment.__user ?? null) as ConnectionState<unknown>;\n }\n },\n setState: {\n configurable: true,\n value: function setState<T>(setState: T | ConnectionSetStateFn<T>) {\n const state =\n setState instanceof Function\n ? setState((this as Connection<T>).state)\n : setState;\n attachments.set(ws, {\n ...attachments.get(ws),\n __user: state ?? null\n });\n return state as ConnectionState<T>;\n }\n }\n }) as Connection;\n\n if (initialState) {\n connection.setState(initialState);\n }\n\n connections.add(connection);\n return connection;\n};\n\nclass ConnectionIterator<T> implements IterableIterator<Connection<T>> {\n private index = 0;\n #sockets: WebSocket[] | undefined;\n constructor(\n private sockets: LifecycleSockets,\n private tag?: string\n ) {}\n\n [Symbol.iterator](): IterableIterator<Connection<T>> {\n return this;\n }\n\n next(): IteratorResult<Connection<T>, number | undefined> {\n const sockets =\n this.#sockets ?? (this.#sockets = this.sockets.get(this.tag));\n\n let socket: WebSocket;\n while ((socket = sockets[this.index++])) {\n // Only yield open sockets.\n if (socket.readyState === WebSocket.OPEN) {\n // Durable Objects hibernation APIs allow storing arbitrary sockets via\n // `state.acceptWebSocket()`. Ignore sockets without our attachment.\n if (!isManagedWebSocket(socket)) {\n continue;\n }\n const value = createConnection(socket) as Connection<T>;\n return { done: false, value };\n }\n }\n\n // reached the end of the iteratee\n return { done: true, value: undefined };\n }\n}\n\n/**\n * Deduplicate and validate connection tags.\n * Returns the final tag array (always includes the connection id as the first tag).\n */\nfunction prepareTags(connectionId: string, userTags: string[]): string[] {\n const tags = [connectionId, ...userTags.filter((t) => t !== connectionId)];\n\n // validate tags against documented restrictions\n // https://developers.cloudflare.com/durable-objects/api/hibernatable-websockets-api/#state-methods-for-websockets\n if (tags.length > 10) {\n throw new Error(\n \"A connection can only have 10 tags, including the default id tag.\"\n );\n }\n\n for (const tag of tags) {\n if (typeof tag !== \"string\") {\n throw new Error(`A connection tag must be a string. Received: ${tag}`);\n }\n if (tag === \"\") {\n throw new Error(\"A connection tag must not be an empty string.\");\n }\n if (tag.length > 256) {\n throw new Error(\"A connection tag must not exceed 256 characters\");\n }\n }\n\n return tags;\n}\n\n/** The platform-backed manager for hibernating WebSockets. */\nexport class ConnectionManager<TState = unknown> {\n constructor(private controller: LifecycleSockets) {}\n\n getConnection<T = TState>(id: string) {\n // TODO: Should we cache the connections?\n const sockets = this.controller.get(id);\n const matching = sockets.filter((ws) => {\n return tryGetManagedWebSocketMeta(ws)?.id === id;\n });\n\n if (matching.length === 0) return undefined;\n if (matching.length === 1)\n return createConnection(matching[0]) as Connection<T>;\n\n throw new Error(\n `More than one connection found for id ${id}. Did you mean to use getConnections(tag) instead?`\n );\n }\n\n getConnections<T = TState>(tag?: string | undefined) {\n return new ConnectionIterator<T>(this.controller, tag);\n }\n\n accept(connection: Connection, options: { tags: string[] }) {\n const tags = prepareTags(connection.id, options.tags);\n\n this.controller.accept(connection, tags);\n attachments.set(connection, {\n __pk: {\n id: connection.id,\n tags,\n uri: connection.uri ?? undefined\n },\n __user: null\n });\n\n return createConnection(connection);\n }\n}\n","import { RpcTarget } from \"cloudflare:workers\";\nimport { decoratedMethods } from \"../callable-decorator\";\n\n/** A named remote method ready to be exposed on a callables root. */\nexport type CallableInvoker = (...args: unknown[]) => unknown;\n\n/**\n * The single exposure policy for callable names. `Object.prototype` and\n * `RpcTarget.prototype` members are unreachable over Cap'n Web anyway\n * and are silently excluded; `then` is rejected loudly because exposing\n * it would make the remote stub thenable.\n */\nfunction assertExposable(name: string): boolean {\n if (name === \"then\") {\n throw new Error(\n 'A callables target cannot expose a method named \"then\" — it would make the remote stub thenable'\n );\n }\n return !(\n name === \"constructor\" ||\n name in Object.prototype ||\n name in RpcTarget.prototype\n );\n}\n\n/**\n * The exposable prototype methods of a callables target, each bound to\n * invoke on the real instance (so private fields and `this` behave).\n *\n * Cap'n Web resolves methods on the prototype chain and rejects own\n * instance properties, so only prototype methods participate. The\n * nearest declaration wins for overridden names.\n *\n * @param target - The callables target to enumerate.\n * @returns Method names mapped to invokers on the target.\n */\nexport function exposableMethods(\n target: RpcTarget\n): ReadonlyMap<string, CallableInvoker> {\n const methods = new Map<string, CallableInvoker>();\n const seen = new Set<string>();\n let prototype: object | null = Object.getPrototypeOf(target);\n while (\n prototype &&\n prototype !== RpcTarget.prototype &&\n prototype !== Object.prototype\n ) {\n for (const name of Object.getOwnPropertyNames(prototype)) {\n if (seen.has(name)) continue;\n seen.add(name);\n if (!assertExposable(name)) continue;\n const descriptor = Object.getOwnPropertyDescriptor(prototype, name);\n if (!descriptor || typeof descriptor.value !== \"function\") continue;\n // SAFETY: `typeof descriptor.value === \"function\"` was checked\n // above; TypeScript cannot narrow a descriptor's `value` field.\n const method = descriptor.value as CallableInvoker;\n methods.set(name, (...args) => Reflect.apply(method, target, args));\n }\n prototype = Object.getPrototypeOf(prototype);\n }\n return methods;\n}\n\n/**\n * Build a Cap'n Web session root exposing exactly the given methods.\n *\n * Cap'n Web resolves methods on the prototype chain, rejects own\n * instance properties, and breaks on Proxy-wrapped roots — so the root\n * is a private `RpcTarget` subclass whose prototype carries the\n * methods and nothing else.\n *\n * @param methods - Method names mapped to their invokers.\n * @returns A root suitable as a Cap'n Web session's local main.\n */\nexport function buildCallablesRoot(\n methods: ReadonlyMap<string, CallableInvoker>\n): RpcTarget {\n class CallablesRoot extends RpcTarget {}\n for (const [name, invoke] of methods) {\n Object.defineProperty(CallablesRoot.prototype, name, {\n value: invoke,\n writable: true,\n configurable: true,\n enumerable: false\n });\n }\n return new CallablesRoot();\n}\n\n/**\n * Build a callables target from a host's `@callable()`-decorated\n * methods — the fallback interface source when no `RpcTarget` is\n * configured (an explicit target is preferred and wins).\n *\n * Methods are resolved on the host at call time, so framework wrapping\n * applied after construction (e.g. Agent's context auto-wrapping) is\n * honored. Methods registered with `streaming: true` expect the legacy\n * Agent RPC protocol's injected `StreamingResponse` and are not exposed\n * here — return a `ReadableStream` from an `RpcTarget` method instead.\n *\n * @param host - The object whose decorated methods form the interface.\n * @returns A target exposing the decorated methods, or `undefined`\n * when the host has none.\n */\nexport function callablesFromDecorated(host: object): RpcTarget | undefined {\n const methods = new Map<string, CallableInvoker>();\n for (const [name, metadata] of decoratedMethods(host)) {\n if (metadata.streaming || !assertExposable(name)) continue;\n methods.set(name, (...args) => {\n const method = Reflect.get(host, name) as unknown;\n if (typeof method !== \"function\") {\n throw new Error(`Method ${name} is not callable`);\n }\n return Reflect.apply(method, host, args);\n });\n }\n if (methods.size === 0) return undefined;\n return buildCallablesRoot(methods);\n}\n","/**\n * Isomorphic pieces of the callables RPC wire contract.\n *\n * Imported from browser bundles (via the client) and from the Worker\n * runtime, so it must not import `cloudflare:workers`.\n */\n\n/** Query parameter selecting the callables Cap'n Web RPC endpoint. */\nexport const CALLABLES_RPC_QUERY = \"__agents_rpc\";\nexport const CALLABLES_RPC_VALUE = \"capnweb\";\n\n/** Whether a request is a WebSocket upgrade addressed to callables RPC. */\nexport function isCallablesRpcUpgrade(request: Request): boolean {\n return (\n request.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\" &&\n new URL(request.url).searchParams.get(CALLABLES_RPC_QUERY) ===\n CALLABLES_RPC_VALUE\n );\n}\n\n/**\n * Derive the callables RPC socket URL from a host route. Accepts http(s)\n * or ws(s) URLs and returns a ws(s) URL with the RPC query parameter set.\n */\nexport function callablesRpcUrl(url: string | URL): string {\n const resolved = new URL(url);\n if (resolved.protocol === \"http:\") resolved.protocol = \"ws:\";\n if (resolved.protocol === \"https:\") resolved.protocol = \"wss:\";\n resolved.searchParams.set(CALLABLES_RPC_QUERY, CALLABLES_RPC_VALUE);\n return resolved.toString();\n}\n","import { RpcTarget } from \"cloudflare:workers\";\nimport { newWorkersWebSocketRpcResponse } from \"capnweb\";\nimport { nanoid } from \"nanoid\";\nimport {\n LifecycleCapability,\n type CapabilityWebSocketUpgradeContext,\n type Connection,\n type ConnectionSetStateFn,\n type ConnectionState\n} from \"../lifecycle\";\nimport {\n ConnectionManager,\n createConnection,\n isManagedWebSocket\n} from \"./connection\";\nimport {\n buildCallablesRoot,\n exposableMethods,\n type CallableInvoker\n} from \"./callables-target\";\nimport type {\n WebSocketHandlers,\n WebSocketMessage,\n WebSocketsOptions\n} from \"./options\";\nimport { isCallablesRpcUpgrade } from \"./protocol\";\n\n/**\n * Reserved close codes the runtime synthesizes when there was no real\n * Close frame from the peer (1005 NoStatusReceived, 1006 AbnormalClosure,\n * 1015 TLSHandshake). They cannot appear in an outgoing Close frame, and\n * there is no peer left to receive a reciprocation.\n */\nfunction isReservedCloseCode(code: number): boolean {\n return code === 1005 || code === 1006 || code === 1015;\n}\n\n/**\n * Reciprocate a peer-initiated Close frame to complete the handshake, as\n * the Hibernation API contract requires. Best-effort: swallows errors\n * from already-closed sockets or invalid codes/reasons, and skips\n * reciprocation entirely for reserved codes (dead transport).\n */\nfunction reciprocateClose(ws: WebSocket, code: number, reason: string): void {\n if (isReservedCloseCode(code)) return;\n try {\n ws.close(code, reason);\n } catch {\n // Already closed, oversize reason, or another unrecoverable\n // invariant — the handshake is either done or out of our control.\n }\n}\n\n/**\n * Opt-in WebSocket support for Lifecycle Objects.\n *\n * Lifecycle itself does not model WebSockets — hosts that want them\n * install this capability, which owns the connection subsystem end to\n * end: it claims upgrades, accepts hibernating sockets, dispatches\n * `onConnect`/`onMessage`/`onClose` inside the host invocation\n * boundary, reciprocates close handshakes, and answers\n * `getConnections()`/`getConnection()`.\n *\n * ```ts\n * class Room extends DurableObject<Env> {\n * readonly webSockets = new WebSockets({\n * handlers: {\n * onConnect: (connection) => connection.send(\"welcome\"),\n * onMessage: (connection, message) => { ... },\n * onClose: (connection, code) => { ... }\n * },\n * callables: new RoomCallables()\n * });\n * readonly lifecycle = Lifecycle.install(this).use(this.webSockets);\n * }\n * ```\n *\n * `callables` exposes an `RpcTarget`'s prototype methods to remote\n * callers over a Cap'n Web session claimed from `?__agents_rpc=capnweb`\n * upgrades. Methods run through the host invocation boundary, may\n * return a `ReadableStream` to stream results, and emit\n * `rpc`/`rpc:error` capability events. Callable sessions are\n * non-hibernating: while a client holds one open, the Durable Object\n * stays pinned in memory.\n *\n * There is no separate browser client: against an `Agent`, the\n * `useAgent` hook's `stub`/`call` reach the same interface over the\n * protocol socket. A plain host's endpoint is reached with capnweb\n * directly — `newWebSocketRpcSession(new WebSocket(callablesRpcUrl(url)))`.\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport class WebSockets extends LifecycleCapability {\n readonly #handlers: WebSocketHandlers | undefined;\n readonly #getConnectionTags: WebSocketsOptions[\"getConnectionTags\"];\n readonly #callablesTarget: RpcTarget | undefined;\n #manager: ConnectionManager | undefined;\n\n constructor(options: WebSocketsOptions = {}) {\n super(\"websockets\");\n this.#handlers = options.handlers;\n this.#getConnectionTags = options.getConnectionTags;\n this.#callablesTarget = options.callables\n ? this.#buildCallablesTarget(options.callables)\n : undefined;\n }\n\n // ── Lifecycle capability hooks ─────────────────────────────────────────\n\n /** Claim callables RPC upgrades and, with handlers, plain upgrades. */\n onWebSocketUpgrade({\n request\n }: CapabilityWebSocketUpgradeContext):\n | Promise<Response>\n | Response\n | undefined {\n if (isCallablesRpcUpgrade(request)) {\n if (!this.#callablesTarget) return undefined;\n return newWorkersWebSocketRpcResponse(request, this.#callablesTarget);\n }\n if (!this.#handlers) return undefined;\n return this.#acceptConnection(request);\n }\n\n /** Dispatch a platform message wake for a capability-owned socket. */\n async onWebSocketMessage(\n ws: WebSocket,\n message: WebSocketMessage\n ): Promise<boolean> {\n if (!isManagedWebSocket(ws)) return false;\n const connection = createConnection(ws);\n await this.lifecycle.runInHostContext(\n () => this.#handlers?.onMessage?.(connection, message),\n { connection }\n );\n return true;\n }\n\n /** Dispatch and reciprocate a close wake for an owned socket. */\n async onWebSocketClose(\n ws: WebSocket,\n code: number,\n reason: string,\n wasClean: boolean\n ): Promise<boolean> {\n if (!isManagedWebSocket(ws)) return false;\n const connection = createConnection(ws);\n try {\n await this.lifecycle.runInHostContext(\n () => this.#handlers?.onClose?.(connection, code, reason, wasClean),\n { connection }\n );\n } finally {\n reciprocateClose(ws, code, reason);\n }\n return true;\n }\n\n /** Dispatch an error wake for an owned socket. */\n async onWebSocketError(ws: WebSocket, error: unknown): Promise<boolean> {\n if (!isManagedWebSocket(ws)) return false;\n const connection = createConnection(ws);\n await this.lifecycle.runInHostContext(\n () => this.#handlers?.onError?.(connection, error),\n { connection }\n );\n return true;\n }\n\n /**\n * Close every owned connection during explicit host destruction. The\n * capability owns its sockets' lifetimes, so it also owns tearing\n * them down.\n */\n dispose(): void {\n for (const connection of this.getConnections()) {\n try {\n connection.close(1001, \"Durable Object destroyed\");\n } catch {\n // Already closed or mid-handshake — nothing left to tear down.\n }\n }\n }\n\n // ── Connections ────────────────────────────────────────────────────────\n\n /** Open connections accepted by this capability, optionally by tag. */\n getConnections<TState = unknown>(\n tag?: string\n ): IterableIterator<Connection<TState>> {\n return this.#connectionManager.getConnections<TState>(tag);\n }\n\n /** One connection accepted by this capability, by id. */\n getConnection<TState = unknown>(id: string): Connection<TState> | undefined {\n return this.#connectionManager.getConnection<TState>(id);\n }\n\n get #connectionManager(): ConnectionManager {\n this.#manager ??= new ConnectionManager(this.lifecycle.sockets);\n return this.#manager;\n }\n\n async #acceptConnection(request: Request): Promise<Response> {\n const { 0: clientWebSocket, 1: serverWebSocket } = new WebSocketPair();\n const url = new URL(request.url);\n // `||`, not `??`: an empty `?_pk=` value must fall back to a\n // generated id — an empty connection id would later throw in tag\n // validation and reject the upgrade.\n const connectionId = url.searchParams.get(\"_pk\") || nanoid();\n\n let connection: Connection = Object.assign(serverWebSocket, {\n id: connectionId,\n uri: request.url,\n tags: [] as string[],\n state: null as unknown as ConnectionState<unknown>,\n setState<T = unknown>(setState: T | ConnectionSetStateFn<T>) {\n // Pre-accept shim: hold state on the socket until accept()\n // persists it into the hibernation attachment.\n const state =\n setState instanceof Function\n ? setState(this.state as ConnectionState<T>)\n : setState;\n this.state = state as ConnectionState<T>;\n return this.state as ConnectionState<T>;\n }\n });\n\n const ctx = { request };\n const tags = this.#getConnectionTags\n ? await this.#getConnectionTags(connection, ctx)\n : [];\n\n // Hibernating WebSockets remain connected while the object is evicted.\n connection = this.#connectionManager.accept(connection, { tags });\n await this.lifecycle.runInHostContext(\n () => this.#handlers?.onConnect?.(connection, ctx),\n { connection, request }\n );\n\n return new Response(null, { status: 101, webSocket: clientWebSocket });\n }\n\n // ── Callables ──────────────────────────────────────────────────────────\n\n /**\n * Wrap a callables target for serving: every exposable method\n * dispatches through the host invocation boundary and emits\n * `rpc`/`rpc:error` events.\n */\n #buildCallablesTarget(target: RpcTarget): RpcTarget {\n const dispatching = new Map<string, CallableInvoker>();\n for (const [name, invoke] of exposableMethods(target)) {\n dispatching.set(name, (...args) =>\n this.#dispatchCallable(name, () => invoke(...args))\n );\n }\n return buildCallablesRoot(dispatching);\n }\n\n async #dispatchCallable(\n name: string,\n invoke: () => unknown\n ): Promise<unknown> {\n // Throws with installation guidance when the capability was never\n // installed with Lifecycle.use().\n const services = this.lifecycle;\n try {\n const result = await services.runInHostContext(invoke);\n services.events.emit(\"rpc\", {\n method: name,\n streaming: result instanceof ReadableStream\n });\n return result;\n } catch (error) {\n services.events.emit(\"rpc:error\", {\n method: name,\n error: error instanceof Error ? error.message : String(error)\n });\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAI,EAAE,UAAU,YAAY;CAC1B,MAAM,kBAAkB;EAEtB,YAAY,UAAU;EAEtB,MAAM,UAAU;EAEhB,SAAS,UAAU;EAEnB,QAAQ,UAAU;CACpB;CAEA,OAAO,OAAO,WAAW,eAAe;CAExC,OAAO,OAAO,UAAU,WAAW,eAAe;AACpD;AAcA,SAAS,2BACP,IACsC;CACtC,IAAI;EAGF,MAAM,aAAa,UAAU,UAAU,sBAAsB,KAC3D,EACF;EACA,IAAI,CAAC,cAAc,OAAO,eAAe,UACvC,OAAO;EAET,IAAI,EAAE,UAAU,aACd,OAAO;EAET,MAAM,KAAM,WAAqC;EACjD,IAAI,CAAC,MAAM,OAAO,OAAO,UACvB,OAAO;EAET,MAAM,EAAE,IAAI,SAAS;EAIrB,IAAI,OAAO,OAAO,UAChB,OAAO;EAET,MAAM,EAAE,QAAQ;EAChB,OAAO;GACL;GACA,MAAM,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;GACpC,KAAK,OAAO,QAAQ,WAAW,MAAM,KAAA;EACvC;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,mBAAmB,IAAwB;CACzD,OAAO,2BAA2B,EAAE,MAAM;AAC5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;AACF"}
|
package/dist/workflow-types.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ut as
|
|
22
|
-
vt as
|
|
23
|
-
wt as
|
|
24
|
-
xt as
|
|
25
|
-
yt as
|
|
26
|
-
} from "./agent-routing-
|
|
2
|
+
Ct as WorkflowProgressCallback,
|
|
3
|
+
Dt as WorkflowTrackingRow,
|
|
4
|
+
Et as WorkflowStatus,
|
|
5
|
+
St as WorkflowPage,
|
|
6
|
+
Tt as WorkflowRejectedError,
|
|
7
|
+
_t as WorkflowCompleteCallback,
|
|
8
|
+
at as AgentWorkflowInternalParams,
|
|
9
|
+
bt as WorkflowEventPayload,
|
|
10
|
+
ct as AgentWorkflowPathStep,
|
|
11
|
+
dt as DefaultProgress,
|
|
12
|
+
ft as RunWorkflowOptions,
|
|
13
|
+
gt as WorkflowCallbackType,
|
|
14
|
+
ht as WorkflowCallbackBase,
|
|
15
|
+
it as AgentWorkflowEvent,
|
|
16
|
+
lt as AgentWorkflowStep,
|
|
17
|
+
mt as WorkflowCallback,
|
|
18
|
+
ot as AgentWorkflowOrigin,
|
|
19
|
+
pt as WaitForApprovalOptions,
|
|
20
|
+
st as AgentWorkflowParams,
|
|
21
|
+
ut as ApprovalEventPayload,
|
|
22
|
+
vt as WorkflowErrorCallback,
|
|
23
|
+
wt as WorkflowQueryCriteria,
|
|
24
|
+
xt as WorkflowInfo,
|
|
25
|
+
yt as WorkflowEventCallback
|
|
26
|
+
} from "./agent-routing-DE5zmCQ8.js";
|
|
27
27
|
export {
|
|
28
28
|
AgentWorkflowEvent,
|
|
29
29
|
AgentWorkflowInternalParams,
|