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.
Files changed (187) hide show
  1. package/dist/{agent-routing-DE5zmCQ8.d.ts → agent-routing-0DR0Tk2v.d.ts} +270 -190
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-routing.js.map +1 -1
  4. package/dist/agent-tool-types.d.ts +13 -7
  5. package/dist/agent-tool-types.js +23 -1
  6. package/dist/agent-tool-types.js.map +1 -1
  7. package/dist/{agent-tools-y7zLfw4Q.js → agent-tools-CdJC-8Dc.js} +72 -9
  8. package/dist/agent-tools-CdJC-8Dc.js.map +1 -0
  9. package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-YrATZJu2.d.ts} +29 -15
  10. package/dist/agent-tools.d.ts +6 -4
  11. package/dist/agent-tools.js.map +1 -1
  12. package/dist/ai-fm7xx1BK.js +312 -0
  13. package/dist/ai-fm7xx1BK.js.map +1 -0
  14. package/dist/base64-redaction-C1Uu29t5.js +59 -0
  15. package/dist/base64-redaction-C1Uu29t5.js.map +1 -0
  16. package/dist/browser/ai-sdk.d.ts +90 -0
  17. package/dist/browser/ai-sdk.js +51 -0
  18. package/dist/browser/ai-sdk.js.map +1 -0
  19. package/dist/browser/ai.d.ts +4 -4
  20. package/dist/browser/ai.js +1 -347
  21. package/dist/browser/index.d.ts +81 -79
  22. package/dist/browser/index.js +361 -2
  23. package/dist/browser/index.js.map +1 -0
  24. package/dist/browser/tanstack-ai.d.ts +96 -1
  25. package/dist/browser/tanstack-ai.js +62 -2
  26. package/dist/browser/tanstack-ai.js.map +1 -1
  27. package/dist/browser-DE3d-RLk.d.ts +275 -0
  28. package/dist/browser-tool-CQ10e6Kj.js +480 -0
  29. package/dist/browser-tool-CQ10e6Kj.js.map +1 -0
  30. package/dist/browser-tool-DuNdlwZ9.d.ts +73 -0
  31. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  32. package/dist/capability-B4WbF81e.js.map +1 -0
  33. package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-DBAnGr6L.d.ts} +45 -15
  34. package/dist/chat/index.d.ts +341 -232
  35. package/dist/chat/index.js +602 -72
  36. package/dist/chat/index.js.map +1 -1
  37. package/dist/chat/react.d.ts +42 -2
  38. package/dist/chat/react.js +191 -35
  39. package/dist/chat/react.js.map +1 -1
  40. package/dist/chat/transport.d.ts +1 -1
  41. package/dist/chat/transport.js +1 -1
  42. package/dist/chat-sdk/index.d.ts +17 -3
  43. package/dist/chat-sdk/index.js +28 -2
  44. package/dist/chat-sdk/index.js.map +1 -1
  45. package/dist/client-4OlMIJx-.js +591 -0
  46. package/dist/client-4OlMIJx-.js.map +1 -0
  47. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  48. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  49. package/dist/client-je3koD9Z.d.ts +446 -0
  50. package/dist/client.d.ts +29 -283
  51. package/dist/client.js +2 -274
  52. package/dist/{connector-CptFKzRh.js → connector-58XDGvc3.js} +251 -120
  53. package/dist/connector-58XDGvc3.js.map +1 -0
  54. package/dist/{connector-CkQD4MK3.d.ts → connector-Cl-VqPmA.d.ts} +244 -146
  55. package/dist/context/index.d.ts +29 -0
  56. package/dist/context/index.js +64 -17
  57. package/dist/context/index.js.map +1 -1
  58. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  59. package/dist/current-agent-vAk_5JMt.d.ts +93 -0
  60. package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-HhgOMWq9.d.ts} +26 -127
  61. package/dist/harnesses/pi/index.d.ts +348 -0
  62. package/dist/harnesses/pi/index.js +754 -0
  63. package/dist/harnesses/pi/index.js.map +1 -0
  64. package/dist/images-iiTDSyRu.js +1631 -0
  65. package/dist/images-iiTDSyRu.js.map +1 -0
  66. package/dist/index-BreL0YrQ.d.ts +78 -0
  67. package/dist/index-kbSUIer3.d.ts +343 -0
  68. package/dist/index.d.ts +43 -41
  69. package/dist/index.js +2 -2
  70. package/dist/internal_context.d.ts +1 -1
  71. package/dist/lifecycle/index.d.ts +19 -17
  72. package/dist/lifecycle/index.js +2 -2
  73. package/dist/{lifecycle-CMRGjZdw.js → lifecycle-CFu6OV03.js} +73 -29
  74. package/dist/lifecycle-CFu6OV03.js.map +1 -0
  75. package/dist/mcp/client/index.d.ts +20 -20
  76. package/dist/mcp/client/index.js +1 -1
  77. package/dist/mcp/client/x402.js +21 -19
  78. package/dist/mcp/client/x402.js.map +1 -1
  79. package/dist/mcp/index.d.ts +35 -35
  80. package/dist/mcp/index.js +2 -2
  81. package/dist/{message-builder-BymO4N_D.js → message-builder-DAl9AhHH.js} +89 -4
  82. package/dist/message-builder-DAl9AhHH.js.map +1 -0
  83. package/dist/models/ai-sdk/index.d.ts +353 -0
  84. package/dist/models/ai-sdk/index.js +2443 -0
  85. package/dist/models/ai-sdk/index.js.map +1 -0
  86. package/dist/models/pi-ai/index.d.ts +313 -0
  87. package/dist/models/pi-ai/index.js +1795 -0
  88. package/dist/models/pi-ai/index.js.map +1 -0
  89. package/dist/observability/ai/index.js +20 -4
  90. package/dist/observability/ai/index.js.map +1 -1
  91. package/dist/{protocol-B0nh6KNf.js → protocol-kHsr-f0X.js} +26 -12
  92. package/dist/{protocol-B0nh6KNf.js.map → protocol-kHsr-f0X.js.map} +1 -1
  93. package/dist/queue/index.d.ts +123 -0
  94. package/dist/queue/index.js +2 -0
  95. package/dist/queue-BB-zfIYF.js +406 -0
  96. package/dist/queue-BB-zfIYF.js.map +1 -0
  97. package/dist/react.d.ts +31 -13
  98. package/dist/react.js +190 -71
  99. package/dist/react.js.map +1 -1
  100. package/dist/{retries-D9Ds-1lz.d.ts → retries-CV6AkXmQ.d.ts} +23 -8
  101. package/dist/retries.d.ts +12 -8
  102. package/dist/retries.js +19 -1
  103. package/dist/retries.js.map +1 -1
  104. package/dist/routing/index.d.ts +2 -2
  105. package/dist/routing/index.js +1 -1
  106. package/dist/{scheduler-DD9NdYbF.js → scheduler-DZ3xQfeK.js} +4 -11
  107. package/dist/scheduler-DZ3xQfeK.js.map +1 -0
  108. package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-RdACNXDP.d.ts} +6 -6
  109. package/dist/schedules/index.d.ts +1 -1
  110. package/dist/schedules/index.js +1 -1
  111. package/dist/serializable.d.ts +1 -1
  112. package/dist/sessions/index.d.ts +70 -3
  113. package/dist/sessions/index.js +276 -67
  114. package/dist/sessions/index.js.map +1 -1
  115. package/dist/skills/index.d.ts +29 -314
  116. package/dist/socket-address.d.ts +16 -0
  117. package/dist/socket-address.js +19 -0
  118. package/dist/socket-address.js.map +1 -0
  119. package/dist/{src-DlSHshb2.js → src-BZeu-SCD.js} +541 -500
  120. package/dist/src-BZeu-SCD.js.map +1 -0
  121. package/dist/state/index.d.ts +6 -0
  122. package/dist/state/index.js +137 -0
  123. package/dist/state/index.js.map +1 -0
  124. package/dist/streams/index.d.ts +1 -1
  125. package/dist/streams/index.js +1 -1
  126. package/dist/{streams-D6tJ0NN9.d.ts → streams-Cmkj9QfW.d.ts} +4 -2
  127. package/dist/{streams-DZKgAj9b.js → streams-DW-UCOUc.js} +9 -2
  128. package/dist/streams-DW-UCOUc.js.map +1 -0
  129. package/dist/sub-routing.d.ts +12 -12
  130. package/dist/tasks/index.d.ts +1 -1
  131. package/dist/tasks/index.js +1 -1
  132. package/dist/{tasks-ylZgBjhj.js → tasks-68DESxf0.js} +3 -3
  133. package/dist/{tasks-ylZgBjhj.js.map → tasks-68DESxf0.js.map} +1 -1
  134. package/dist/{tasks-BRJ5zgya.d.ts → tasks-9YxYtByh.d.ts} +5 -5
  135. package/dist/transport-PfFnt-Ld.d.ts +525 -0
  136. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  137. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  138. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  139. package/dist/types-BA4anrjI.d.ts +70 -0
  140. package/dist/voice/index.d.ts +2 -2
  141. package/dist/websockets/index.d.ts +195 -69
  142. package/dist/websockets/index.js +3 -2
  143. package/dist/websockets-Ci-LZFHH.js +1030 -0
  144. package/dist/websockets-Ci-LZFHH.js.map +1 -0
  145. package/dist/wire-types-CnMt6_HR.js.map +1 -1
  146. package/dist/wire-types-CrjKvDyi.d.ts +300 -0
  147. package/dist/workflow-types.d.ts +25 -25
  148. package/dist/workflows.d.ts +21 -21
  149. package/dist/workflows.js +1 -1
  150. package/dist/{ws-chat-transport-UNRIS2xl.d.ts → ws-chat-transport-BbT1A5Lc.d.ts} +51 -2
  151. package/dist/{ws-chat-transport-rWwta645.js → ws-chat-transport-cqMKq3IY.js} +143 -16
  152. package/dist/ws-chat-transport-cqMKq3IY.js.map +1 -0
  153. package/docs/agent-class.md +2 -2
  154. package/docs/agent-tools.md +29 -4
  155. package/docs/browse-the-web.md +87 -5
  156. package/docs/chat-agents.md +124 -16
  157. package/docs/client-sdk.md +30 -0
  158. package/docs/context.md +27 -0
  159. package/docs/durable-execution.md +2 -0
  160. package/docs/harnesses/pi.md +91 -0
  161. package/docs/human-in-the-loop.md +4 -0
  162. package/docs/index.md +4 -1
  163. package/docs/lifecycle.md +114 -23
  164. package/docs/models-pi-ai.md +325 -0
  165. package/docs/models.md +504 -0
  166. package/docs/queue.md +135 -241
  167. package/docs/resumable-streaming.md +2 -0
  168. package/docs/retries.md +1 -1
  169. package/docs/routing.md +13 -13
  170. package/docs/sessions.md +36 -1
  171. package/docs/state.md +1 -0
  172. package/docs/sub-agents.md +12 -3
  173. package/package.json +51 -3
  174. package/dist/agent-tools-y7zLfw4Q.js.map +0 -1
  175. package/dist/browser/ai.js.map +0 -1
  176. package/dist/capability-BjSKYpzg.js.map +0 -1
  177. package/dist/client-tools-aIBO0Fk7.d.ts +0 -53
  178. package/dist/client.js.map +0 -1
  179. package/dist/connector-CptFKzRh.js.map +0 -1
  180. package/dist/lifecycle-CMRGjZdw.js.map +0 -1
  181. package/dist/message-builder-BymO4N_D.js.map +0 -1
  182. package/dist/scheduler-DD9NdYbF.js.map +0 -1
  183. package/dist/src-DlSHshb2.js.map +0 -1
  184. package/dist/streams-DZKgAj9b.js.map +0 -1
  185. package/dist/websockets-DUfRHPRq.js +0 -502
  186. package/dist/websockets-DUfRHPRq.js.map +0 -1
  187. package/dist/ws-chat-transport-rWwta645.js.map +0 -1
@@ -0,0 +1,446 @@
1
+ import { c as Agent } from "./agent-routing-0DR0Tk2v.js";
2
+ import {
3
+ ClientParameters,
4
+ Method,
5
+ RPCMethod,
6
+ SerializableReturnValue,
7
+ SerializableValue
8
+ } from "./serializable.js";
9
+ import {
10
+ i as TransportMessage,
11
+ t as AgentTransport
12
+ } from "./transport-protocol-ZTew5Wso.js";
13
+ import {
14
+ PartyFetchOptions,
15
+ PartySocket,
16
+ PartySocketOptions
17
+ } from "partysocket";
18
+
19
+ //#region src/websockets/capnweb-socket.d.ts
20
+ /**
21
+ * A WebSocket-shaped client for the Cap'n Web connection transport.
22
+ *
23
+ * It has the constructor, `readyState`, `send()`, `close()`, and events of
24
+ * a `WebSocket`, so PartySocket (and therefore `useAgent` and
25
+ * `AgentClient`) can drive it as a drop-in socket implementation and keep
26
+ * owning reconnection, buffering, and backoff. Frames sent here travel
27
+ * through the host's pipe method; frames from the host arrive as
28
+ * `message` events.
29
+ *
30
+ * @experimental The transport is experimental.
31
+ */
32
+ declare class CapnWebSocket extends EventTarget {
33
+ #private;
34
+ static readonly CONNECTING = 0;
35
+ static readonly OPEN = 1;
36
+ static readonly CLOSING = 2;
37
+ static readonly CLOSED = 3;
38
+ readonly CONNECTING = 0;
39
+ readonly OPEN = 1;
40
+ readonly CLOSING = 2;
41
+ readonly CLOSED = 3;
42
+ readonly url: string;
43
+ readyState: number;
44
+ binaryType: BinaryType;
45
+ bufferedAmount: number;
46
+ extensions: string;
47
+ protocol: string;
48
+ onopen: ((event: Event) => void) | null;
49
+ onmessage: ((event: MessageEvent) => void) | null;
50
+ onclose: ((event: CloseEvent) => void) | null;
51
+ onerror: ((event: Event) => void) | null;
52
+ constructor(url: string | URL, protocols?: string | string[]);
53
+ dispatchEvent(event: Event): boolean;
54
+ /**
55
+ * Invoke one of the host's native callables on the session root. The
56
+ * result keeps Cap'n Web semantics: an `RpcTarget` arrives as a live
57
+ * stub, a `ReadableStream` streams, and chained calls pipeline.
58
+ */
59
+ invoke(method: string, args: unknown[]): Promise<unknown>;
60
+ send(data: TransportMessage): void;
61
+ close(code?: number, reason?: string): void;
62
+ }
63
+ //#endregion
64
+ //#region src/client.d.ts
65
+ declare class AgentConnectionError extends Error {
66
+ code: number;
67
+ reason: string;
68
+ wasClean: boolean;
69
+ constructor(event: CloseEvent);
70
+ }
71
+ declare function isTerminalCloseEvent(event: CloseEvent): boolean;
72
+ type ReconnectingSocket = {
73
+ shouldReconnect: boolean;
74
+ retryCount: number;
75
+ };
76
+ /**
77
+ * PartySocket's `shouldReconnectOnClose`, plus a record of whether that
78
+ * decision ended reconnection so the close can surface a connection error.
79
+ *
80
+ * Reconnection ends on a terminal close code, when the caller's
81
+ * `shouldReconnectOnClose` declines, or when `maxRetries` is spent (a
82
+ * failed handshake never reaches the server's close codes, so it only
83
+ * stops this way). An explicit `close()` has already cleared
84
+ * `shouldReconnect` by the time PartySocket asks, and is not an error.
85
+ * PartySocket asks before it schedules the next attempt, so `retryCount`
86
+ * still counts the attempt that just closed.
87
+ * @internal
88
+ */
89
+ declare function createCloseClassifier(options: {
90
+ socket: () => ReconnectingSocket | null | undefined;
91
+ shouldReconnectOnClose: () => ((event: CloseEvent) => boolean) | undefined;
92
+ maxRetries: () => number | undefined;
93
+ }): {
94
+ shouldReconnectOnClose: (event: CloseEvent) => boolean;
95
+ takeFinalClose: () => boolean;
96
+ };
97
+ type TerminalReconnectOptions = {
98
+ shouldReconnectOnClose?: (event: CloseEvent) => boolean;
99
+ };
100
+ /**
101
+ * Options for creating an AgentClient
102
+ */
103
+ type AgentClientOptions<State = unknown> = Omit<
104
+ PartySocketOptions,
105
+ "party" | "room"
106
+ > &
107
+ TerminalReconnectOptions & {
108
+ /**
109
+ * Wire the connection travels on. `"cf-websocket"` (default) is a
110
+ * hibernating WebSocket where `call()` sends JSON `rpc` frames.
111
+ * `"capnweb"` carries protocol frames over a Cap'n Web session whose
112
+ * root also serves the host's `callables` natively, so `call()` and
113
+ * `stub` invoke them directly and an `RpcTarget` result is a live stub.
114
+ * The Durable Object stays in memory while a capnweb connection is open.
115
+ * @experimental The `"capnweb"` transport is experimental.
116
+ */
117
+ transport?: AgentTransport /** Name of the agent to connect to (ignored if basePath is set) */;
118
+ agent: string /** Name of the specific Agent instance (ignored if basePath is set) */;
119
+ name?: string;
120
+ /**
121
+ * Full URL path - bypasses agent/name URL construction.
122
+ * When set, the client connects to this path directly.
123
+ * Server must handle routing manually (e.g., with getAgentByName + fetch).
124
+ * @example
125
+ * // Client connects to /user, server routes based on session
126
+ * useAgent({ agent: "UserAgent", basePath: "user" })
127
+ */
128
+ basePath?: string /** Called when the Agent's state is updated */;
129
+ onStateUpdate?: (
130
+ state: State,
131
+ source: "server" | "client"
132
+ ) => void /** Called when a state update fails (e.g., connection is readonly) */;
133
+ onStateUpdateError?: (error: string) => void;
134
+ /**
135
+ * Called when the server sends the agent's identity on connect.
136
+ * Useful when using basePath, as the actual instance name is determined server-side.
137
+ * @param name The actual agent instance name
138
+ * @param agent The agent class name (kebab-case)
139
+ */
140
+ onIdentity?: (name: string, agent: string) => void;
141
+ /**
142
+ * Called when identity changes on reconnect (different instance than before).
143
+ * If not provided and identity changes, a warning will be logged.
144
+ * @param oldName Previous instance name
145
+ * @param newName New instance name
146
+ * @param oldAgent Previous agent class name
147
+ * @param newAgent New agent class name
148
+ */
149
+ onIdentityChange?: (
150
+ oldName: string,
151
+ newName: string,
152
+ oldAgent: string,
153
+ newAgent: string
154
+ ) => void;
155
+ /**
156
+ * Additional path to append to the URL.
157
+ * Works with both standard routing and basePath.
158
+ * @example
159
+ * // With basePath: /user/settings
160
+ * { basePath: "user", path: "settings" }
161
+ * // Standard: /agents/my-agent/room/settings
162
+ * { agent: "MyAgent", name: "room", path: "settings" }
163
+ */
164
+ path?: string;
165
+ /**
166
+ * Default timeout (in milliseconds) applied to non-streaming `call()`s
167
+ * that don't pass an explicit `timeout`. Defaults to 30 000 ms.
168
+ * Set to `0` to disable. Streaming calls never get a default timeout.
169
+ */
170
+ defaultCallTimeout?: number;
171
+ /**
172
+ * Called when the connection closes and will not reconnect on its own: a
173
+ * terminal close code (1008 or 4000-4999), `shouldReconnectOnClose`
174
+ * returning false, or `maxRetries` spent.
175
+ */
176
+ onConnectionError?: (error: AgentConnectionError) => void;
177
+ };
178
+ /**
179
+ * Default timeout (in milliseconds) applied to non-streaming RPC calls
180
+ * that don't pass an explicit `timeout`. Acts as a backstop so calls
181
+ * whose response is lost (e.g. the connection drops mid-flight) reject
182
+ * instead of hanging forever. Override per client via
183
+ * `defaultCallTimeout`, or per call via `timeout` (0 disables).
184
+ */
185
+ declare const DEFAULT_CALL_TIMEOUT_MS = 30000;
186
+ /**
187
+ * Options for streaming RPC calls
188
+ */
189
+ type StreamOptions = {
190
+ /** Called when a chunk of data is received */ onChunk?: (
191
+ chunk: unknown
192
+ ) => void /** Called when the stream ends */;
193
+ onDone?: (finalChunk: unknown) => void /** Called when an error occurs */;
194
+ onError?: (error: string) => void;
195
+ };
196
+ /**
197
+ * Options for RPC calls
198
+ */
199
+ type CallOptions = {
200
+ /** Timeout in milliseconds. If the call doesn't complete within this time, it will be rejected. */ timeout?: number /** Streaming options for handling streaming responses */;
201
+ stream?: StreamOptions;
202
+ };
203
+ /**
204
+ * Normalize `call()` options. The legacy shape is the stream callbacks
205
+ * themselves (`{ onChunk, onDone, onError }`); the current shape nests
206
+ * them under `stream` beside `timeout`.
207
+ */
208
+ declare function splitCallOptions(
209
+ options: CallOptions | StreamOptions | undefined
210
+ ): {
211
+ stream: StreamOptions | undefined;
212
+ timeout: number | undefined;
213
+ };
214
+ /**
215
+ * One native call on the Cap'n Web transport, with the timeout and
216
+ * stream-callback contract `call()` has on the JSON wire. The timeout
217
+ * covers the whole call, draining included: on expiry the stream reader is
218
+ * cancelled and the promise rejects once. A `ReadableStream` result is
219
+ * drained into the stream callbacks when they are given; any other value,
220
+ * live stubs included, passes straight through.
221
+ */
222
+ declare function nativeCall<T>(
223
+ socket: CapnWebSocket,
224
+ method: string,
225
+ args: unknown[],
226
+ options: CallOptions | StreamOptions | undefined,
227
+ defaultTimeout: number
228
+ ): Promise<T>;
229
+ /**
230
+ * Native calls issued while the Cap'n Web socket is still connecting or
231
+ * between reconnects. They must not fall back to JSON frames — that would
232
+ * change which methods are reachable and lose return-by-reference — so
233
+ * they wait here and run on the next open socket, or reject when the
234
+ * connection ends for good. Their timeout starts when they are issued.
235
+ */
236
+ declare class NativeCallQueue {
237
+ #private;
238
+ enqueue<T>(
239
+ method: string,
240
+ args: unknown[],
241
+ options: CallOptions | StreamOptions | undefined,
242
+ defaultTimeout: number
243
+ ): Promise<T>;
244
+ /** Run everything queued on a socket that just opened. */
245
+ flush(socket: CapnWebSocket): void;
246
+ /** Reject everything queued; the connection will not come back. */
247
+ rejectAll(reason: string): void;
248
+ }
249
+ /**
250
+ * Options for the agentFetch function
251
+ */
252
+ type AgentClientFetchOptions = Omit<PartyFetchOptions, "party" | "room"> & {
253
+ /** Name of the agent to connect to (ignored if basePath is set) */ agent: string /** Name of the specific Agent instance (ignored if basePath is set) */;
254
+ name?: string;
255
+ /**
256
+ * Full URL path - bypasses agent/name URL construction.
257
+ * When set, the request is made to this path directly.
258
+ */
259
+ basePath?: string;
260
+ };
261
+ type AllOptional<T> = T extends [infer A, ...infer R]
262
+ ? undefined extends A
263
+ ? AllOptional<R>
264
+ : false
265
+ : true;
266
+ type RPCMethods<T> = {
267
+ [K in keyof T as T[K] extends RPCMethod<T[K]> ? K : never]: RPCMethod<T[K]>;
268
+ };
269
+ type OptionalParametersMethod<T extends RPCMethod> =
270
+ AllOptional<ClientParameters<T>> extends true ? T : never;
271
+ type AgentMethods<T> = Omit<RPCMethods<T>, keyof Agent<any, any>>;
272
+ type OptionalAgentMethods<T> = {
273
+ [K in keyof AgentMethods<T> as AgentMethods<T>[K] extends OptionalParametersMethod<
274
+ AgentMethods<T>[K]
275
+ >
276
+ ? K
277
+ : never]: OptionalParametersMethod<AgentMethods<T>[K]>;
278
+ };
279
+ type RequiredAgentMethods<T> = Omit<
280
+ AgentMethods<T>,
281
+ keyof OptionalAgentMethods<T>
282
+ >;
283
+ type AgentPromiseReturnType<T, K extends keyof AgentMethods<T>> =
284
+ ReturnType<AgentMethods<T>[K]> extends Promise<any>
285
+ ? ReturnType<AgentMethods<T>[K]>
286
+ : Promise<ReturnType<AgentMethods<T>[K]>>;
287
+ type AgentStub<T> = {
288
+ [K in keyof AgentMethods<T>]: (
289
+ ...args: ClientParameters<AgentMethods<T>[K]>
290
+ ) => AgentPromiseReturnType<AgentMethods<T>, K>;
291
+ };
292
+ type UntypedAgentStub = Record<string, Method>;
293
+ type AgentClientStub<AgentT> = keyof AgentMethods<AgentT> extends never
294
+ ? UntypedAgentStub
295
+ : AgentStub<AgentT>;
296
+ type OptionalArgsAgentClientCall<AgentT> = <
297
+ K extends keyof OptionalAgentMethods<AgentT>
298
+ >(
299
+ method: K,
300
+ args?: ClientParameters<OptionalAgentMethods<AgentT>[K]>,
301
+ options?: CallOptions | StreamOptions
302
+ ) => AgentPromiseReturnType<AgentT, K>;
303
+ type RequiredArgsAgentClientCall<AgentT> = <
304
+ K extends keyof RequiredAgentMethods<AgentT>
305
+ >(
306
+ method: K,
307
+ args: ClientParameters<RequiredAgentMethods<AgentT>[K]>,
308
+ options?: CallOptions | StreamOptions
309
+ ) => AgentPromiseReturnType<AgentT, K>;
310
+ type TypedAgentClientCall<AgentT> = OptionalArgsAgentClientCall<AgentT> &
311
+ RequiredArgsAgentClientCall<AgentT>;
312
+ type UntypedAgentClientCall = {
313
+ <T extends SerializableReturnValue>(
314
+ method: string,
315
+ args?: SerializableValue[],
316
+ options?: CallOptions | StreamOptions
317
+ ): Promise<T>;
318
+ <T = unknown>(
319
+ method: string,
320
+ args?: unknown[],
321
+ options?: CallOptions | StreamOptions
322
+ ): Promise<T>;
323
+ };
324
+ type AgentClientCall<AgentT> = keyof AgentMethods<AgentT> extends never
325
+ ? UntypedAgentClientCall
326
+ : TypedAgentClientCall<AgentT>;
327
+ /**
328
+ * Creates a proxy that wraps RPC method calls.
329
+ * Internal JS methods (toJSON, then, etc.) return undefined to avoid
330
+ * triggering RPC calls during serialization (e.g., console.log)
331
+ */
332
+ declare function createStubProxy<T = Record<string, Method>>(
333
+ call: (method: string, args: unknown[]) => unknown
334
+ ): T;
335
+ /**
336
+ * WebSocket client for connecting to an Agent
337
+ */
338
+ declare class AgentClient<
339
+ AgentT = unknown,
340
+ State = AgentT extends {
341
+ get state(): infer S;
342
+ }
343
+ ? S
344
+ : AgentT
345
+ > extends PartySocket {
346
+ #private;
347
+ /**
348
+ * @deprecated Use agentFetch instead
349
+ */
350
+ static fetch(_opts: PartyFetchOptions): Promise<Response>;
351
+ agent: string;
352
+ name: string;
353
+ call: AgentClientCall<AgentT>;
354
+ stub: AgentClientStub<AgentT>;
355
+ /**
356
+ * The current agent state, updated on server broadcasts and client setState calls.
357
+ * Starts as undefined until the first state message is received from the server.
358
+ */
359
+ state: State | undefined;
360
+ /**
361
+ * Whether the client has received identity from the server.
362
+ * Becomes true with `ready`: after the identity message, or after the
363
+ * initial state message when the server sends one.
364
+ * Resets to false on connection close.
365
+ */
366
+ identified: boolean;
367
+ /**
368
+ * Set when the connection closed and will not reconnect on its own (see
369
+ * `onConnectionError`). Cleared when a connection opens.
370
+ */
371
+ connectionError: AgentConnectionError | null;
372
+ /**
373
+ * Promise that resolves when identity has been received from the server.
374
+ * When the server also sends the stored state on connect, it resolves only
375
+ * after that state has been applied, so `state` is current once it settles.
376
+ * Servers without that signal resolve on identity alone.
377
+ * Useful for waiting before making calls that depend on knowing the instance.
378
+ * Resets on connection close so it can be awaited again after reconnect.
379
+ */
380
+ get ready(): Promise<void>;
381
+ private options;
382
+ private _pendingCalls;
383
+ private _readyPromise;
384
+ private _resolveReady;
385
+ private _previousName;
386
+ private _previousAgent;
387
+ private _resetReady;
388
+ constructor(options: AgentClientOptions<State>);
389
+ /**
390
+ * Reject pending RPC calls with the given reason.
391
+ * With `onlyTransmitted`, calls still sitting in the send buffer are
392
+ * kept pending (they'll be flushed on reconnect).
393
+ */
394
+ private _rejectPendingCalls;
395
+ setState(state: State): void;
396
+ /**
397
+ * Close the connection and immediately reject all pending RPC calls.
398
+ * This provides immediate feedback on intentional close rather than
399
+ * waiting for the WebSocket close handshake to complete.
400
+ *
401
+ * Note: Any calls made after `close()` will be rejected when the
402
+ * underlying WebSocket close event fires.
403
+ */
404
+ close(code?: number, reason?: string): void;
405
+ /**
406
+ * Call a method on the Agent.
407
+ * When AgentT is provided, method names are inferred from the agent's methods.
408
+ * Falls back to untyped string-based calls when AgentT is not provided.
409
+ */
410
+ private _callImpl;
411
+ }
412
+ /**
413
+ * Make an HTTP request to an Agent
414
+ * @param opts Connection options
415
+ * @param init Request initialization options
416
+ * @returns Promise resolving to a Response
417
+ */
418
+ declare function agentFetch(
419
+ opts: AgentClientFetchOptions,
420
+ init?: RequestInit
421
+ ): Promise<Response>;
422
+ //#endregion
423
+ export {
424
+ createCloseClassifier as _,
425
+ AgentMethods as a,
426
+ nativeCall as b,
427
+ CallOptions as c,
428
+ OptionalAgentMethods as d,
429
+ RPCMethods as f,
430
+ agentFetch as g,
431
+ UntypedAgentStub as h,
432
+ AgentConnectionError as i,
433
+ DEFAULT_CALL_TIMEOUT_MS as l,
434
+ StreamOptions as m,
435
+ AgentClientFetchOptions as n,
436
+ AgentPromiseReturnType as o,
437
+ RequiredAgentMethods as p,
438
+ AgentClientOptions as r,
439
+ AgentStub as s,
440
+ AgentClient as t,
441
+ NativeCallQueue as u,
442
+ createStubProxy as v,
443
+ splitCallOptions as x,
444
+ isTerminalCloseEvent as y
445
+ };
446
+ //# sourceMappingURL=client-je3koD9Z.d.ts.map