@economic/agents-react 1.3.4 → 1.3.6
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/index.d.mts +37 -310
- package/dist/index.mjs +1 -1
- package/package.json +1 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,208 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
new (): IntermediateEventTarget<EventMap>;
|
|
5
|
-
};
|
|
6
|
-
interface IntermediateEventTarget<EventMap> extends EventTarget {
|
|
7
|
-
addEventListener<K extends keyof EventMap>(type: K, callback: (event: EventMap[K] extends Event ? EventMap[K] : never) => EventMap[K] extends Event ? void : never, options?: boolean | AddEventListenerOptions): void;
|
|
8
|
-
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
9
|
-
removeEventListener<K extends keyof EventMap>(type: K, callback: (event: EventMap[K] extends Event ? EventMap[K] : never) => EventMap[K] extends Event ? void : never, options?: boolean | AddEventListenerOptions): void;
|
|
10
|
-
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
11
|
-
} //#endregion
|
|
12
|
-
//#region src/ws.d.ts
|
|
13
|
-
declare class ErrorEvent$1 extends Event {
|
|
14
|
-
message: string;
|
|
15
|
-
error: Error;
|
|
16
|
-
constructor(error: Error, target: any);
|
|
17
|
-
}
|
|
18
|
-
declare class CloseEvent$1 extends Event {
|
|
19
|
-
code: number;
|
|
20
|
-
reason: string;
|
|
21
|
-
wasClean: boolean;
|
|
22
|
-
constructor(code: number | undefined, reason: string | undefined, target: any);
|
|
23
|
-
}
|
|
24
|
-
interface WebSocketEventMap {
|
|
25
|
-
close: CloseEvent$1;
|
|
26
|
-
error: ErrorEvent$1;
|
|
27
|
-
message: MessageEvent;
|
|
28
|
-
open: Event;
|
|
29
|
-
}
|
|
30
|
-
type Options = {
|
|
31
|
-
WebSocket?: any;
|
|
32
|
-
maxReconnectionDelay?: number;
|
|
33
|
-
minReconnectionDelay?: number;
|
|
34
|
-
reconnectionDelayGrowFactor?: number;
|
|
35
|
-
minUptime?: number;
|
|
36
|
-
connectionTimeout?: number;
|
|
37
|
-
maxRetries?: number;
|
|
38
|
-
maxEnqueuedMessages?: number;
|
|
39
|
-
startClosed?: boolean;
|
|
40
|
-
debug?: boolean;
|
|
41
|
-
debugLogger?: (...args: any[]) => void;
|
|
42
|
-
};
|
|
43
|
-
type UrlProvider = string | (() => string) | (() => Promise<string>);
|
|
44
|
-
type ProtocolsProvider = null | string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>);
|
|
45
|
-
type Message = string | ArrayBuffer | Blob | ArrayBufferView<ArrayBuffer>;
|
|
46
|
-
declare const ReconnectingWebSocket_base: TypedEventTarget<WebSocketEventMap>;
|
|
47
|
-
declare class ReconnectingWebSocket extends ReconnectingWebSocket_base {
|
|
48
|
-
private _ws;
|
|
49
|
-
private _retryCount;
|
|
50
|
-
private _uptimeTimeout;
|
|
51
|
-
private _connectTimeout;
|
|
52
|
-
private _shouldReconnect;
|
|
53
|
-
private _connectLock;
|
|
54
|
-
private _binaryType;
|
|
55
|
-
private _closeCalled;
|
|
56
|
-
private _messageQueue;
|
|
57
|
-
private _debugLogger;
|
|
58
|
-
protected _url: UrlProvider;
|
|
59
|
-
protected _protocols?: ProtocolsProvider;
|
|
60
|
-
protected _options: Options;
|
|
61
|
-
constructor(url: UrlProvider, protocols?: ProtocolsProvider, options?: Options);
|
|
62
|
-
static get CONNECTING(): number;
|
|
63
|
-
static get OPEN(): number;
|
|
64
|
-
static get CLOSING(): number;
|
|
65
|
-
static get CLOSED(): number;
|
|
66
|
-
get CONNECTING(): number;
|
|
67
|
-
get OPEN(): number;
|
|
68
|
-
get CLOSING(): number;
|
|
69
|
-
get CLOSED(): number;
|
|
70
|
-
get binaryType(): BinaryType;
|
|
71
|
-
set binaryType(value: BinaryType);
|
|
72
|
-
/**
|
|
73
|
-
* Returns the number or connection retries
|
|
74
|
-
*/
|
|
75
|
-
get retryCount(): number;
|
|
76
|
-
/**
|
|
77
|
-
* The number of bytes of data that have been queued using calls to send() but not yet
|
|
78
|
-
* transmitted to the network. This value resets to zero once all queued data has been sent.
|
|
79
|
-
* This value does not reset to zero when the connection is closed; if you keep calling send(),
|
|
80
|
-
* this will continue to climb. Read only
|
|
81
|
-
*/
|
|
82
|
-
get bufferedAmount(): number;
|
|
83
|
-
/**
|
|
84
|
-
* The extensions selected by the server. This is currently only the empty string or a list of
|
|
85
|
-
* extensions as negotiated by the connection
|
|
86
|
-
*/
|
|
87
|
-
get extensions(): string;
|
|
88
|
-
/**
|
|
89
|
-
* A string indicating the name of the sub-protocol the server selected;
|
|
90
|
-
* this will be one of the strings specified in the protocols parameter when creating the
|
|
91
|
-
* WebSocket object
|
|
92
|
-
*/
|
|
93
|
-
get protocol(): string;
|
|
94
|
-
/**
|
|
95
|
-
* The current state of the connection; this is one of the Ready state constants
|
|
96
|
-
*/
|
|
97
|
-
get readyState(): number;
|
|
98
|
-
/**
|
|
99
|
-
* The URL as resolved by the constructor
|
|
100
|
-
*/
|
|
101
|
-
get url(): string;
|
|
102
|
-
/**
|
|
103
|
-
* Whether the websocket object is now in reconnectable state
|
|
104
|
-
*/
|
|
105
|
-
get shouldReconnect(): boolean;
|
|
106
|
-
/**
|
|
107
|
-
* An event listener to be called when the WebSocket connection's readyState changes to CLOSED
|
|
108
|
-
*/
|
|
109
|
-
onclose: ((event: CloseEvent$1) => void) | null;
|
|
110
|
-
/**
|
|
111
|
-
* An event listener to be called when an error occurs
|
|
112
|
-
*/
|
|
113
|
-
onerror: ((event: ErrorEvent$1) => void) | null;
|
|
114
|
-
/**
|
|
115
|
-
* An event listener to be called when a message is received from the server
|
|
116
|
-
*/
|
|
117
|
-
onmessage: ((event: MessageEvent) => void) | null;
|
|
118
|
-
/**
|
|
119
|
-
* An event listener to be called when the WebSocket connection's readyState changes to OPEN;
|
|
120
|
-
* this indicates that the connection is ready to send and receive data
|
|
121
|
-
*/
|
|
122
|
-
onopen: ((event: Event) => void) | null;
|
|
123
|
-
/**
|
|
124
|
-
* Closes the WebSocket connection or connection attempt, if any. If the connection is already
|
|
125
|
-
* CLOSED, this method does nothing
|
|
126
|
-
*/
|
|
127
|
-
close(code?: number, reason?: string): void;
|
|
128
|
-
/**
|
|
129
|
-
* Closes the WebSocket connection or connection attempt and connects again.
|
|
130
|
-
* Resets retry counter;
|
|
131
|
-
*/
|
|
132
|
-
reconnect(code?: number, reason?: string): void;
|
|
133
|
-
/**
|
|
134
|
-
* Enqueue specified data to be transmitted to the server over the WebSocket connection
|
|
135
|
-
*/
|
|
136
|
-
send(data: Message): void;
|
|
137
|
-
private _debug;
|
|
138
|
-
private _getNextDelay;
|
|
139
|
-
private _wait;
|
|
140
|
-
private _getNextProtocols;
|
|
141
|
-
private _getNextUrl;
|
|
142
|
-
private _connect;
|
|
143
|
-
private _handleTimeout;
|
|
144
|
-
private _disconnect;
|
|
145
|
-
private _acceptOpen;
|
|
146
|
-
private _handleOpen;
|
|
147
|
-
private _handleMessage;
|
|
148
|
-
private _handleError;
|
|
149
|
-
private _handleClose;
|
|
150
|
-
private _removeListeners;
|
|
151
|
-
private _addListeners;
|
|
152
|
-
private _clearTimeouts;
|
|
153
|
-
} //#endregion
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region ../../node_modules/partysocket/index.d.ts
|
|
156
|
-
//#region src/index.d.ts
|
|
157
|
-
type Maybe<T> = T | null | undefined;
|
|
158
|
-
type Params = Record<string, Maybe<string>>;
|
|
159
|
-
type PartySocketOptions = Omit<Options, "constructor"> & {
|
|
160
|
-
id?: string;
|
|
161
|
-
host: string;
|
|
162
|
-
room?: string;
|
|
163
|
-
party?: string;
|
|
164
|
-
basePath?: string;
|
|
165
|
-
prefix?: string;
|
|
166
|
-
protocol?: "ws" | "wss";
|
|
167
|
-
protocols?: ProtocolsProvider;
|
|
168
|
-
path?: string;
|
|
169
|
-
query?: Params | (() => Params | Promise<Params>);
|
|
170
|
-
disableNameValidation?: boolean;
|
|
171
|
-
};
|
|
172
|
-
type PartyFetchOptions = {
|
|
173
|
-
host: string;
|
|
174
|
-
room: string;
|
|
175
|
-
party?: string;
|
|
176
|
-
basePath?: string;
|
|
177
|
-
prefix?: string;
|
|
178
|
-
path?: string;
|
|
179
|
-
protocol?: "http" | "https";
|
|
180
|
-
query?: Params | (() => Params | Promise<Params>);
|
|
181
|
-
fetch?: typeof fetch;
|
|
182
|
-
};
|
|
183
|
-
declare class PartySocket extends ReconnectingWebSocket {
|
|
184
|
-
readonly partySocketOptions: PartySocketOptions;
|
|
185
|
-
_pk: string;
|
|
186
|
-
_pkurl: string;
|
|
187
|
-
name: string;
|
|
188
|
-
room?: string;
|
|
189
|
-
host: string;
|
|
190
|
-
path: string;
|
|
191
|
-
basePath?: string;
|
|
192
|
-
constructor(partySocketOptions: PartySocketOptions);
|
|
193
|
-
updateProperties(partySocketOptions: Partial<PartySocketOptions>): void;
|
|
194
|
-
private setWSProperties;
|
|
195
|
-
reconnect(code?: number | undefined, reason?: string | undefined): void;
|
|
196
|
-
get id(): string;
|
|
197
|
-
/**
|
|
198
|
-
* Exposes the static PartyKit room URL without applying query parameters.
|
|
199
|
-
* To access the currently connected WebSocket url, use PartySocket#url.
|
|
200
|
-
*/
|
|
201
|
-
get roomUrl(): string;
|
|
202
|
-
static fetch(options: PartyFetchOptions, init?: RequestInit): Promise<Response>;
|
|
203
|
-
} //#endregion
|
|
204
|
-
//#endregion
|
|
1
|
+
import { useAgent as useAgent$1 } from "agents/react";
|
|
2
|
+
import { useAgentChat } from "@cloudflare/ai-chat/react";
|
|
3
|
+
|
|
205
4
|
//#region src/types.d.ts
|
|
5
|
+
type _CfAgent = ReturnType<typeof useAgent$1>;
|
|
6
|
+
type Agent = Omit<_CfAgent, "call"> & {
|
|
7
|
+
call(method: string, args?: unknown[], options?: unknown): Promise<unknown>;
|
|
8
|
+
};
|
|
9
|
+
type Chat = ReturnType<typeof useAgentChat>;
|
|
206
10
|
type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
|
|
207
11
|
type AgentConnectionType = "agent" | "chat" | "assistant";
|
|
208
12
|
type ChatSummary = {
|
|
@@ -225,15 +29,13 @@ type GetChatsHandler = () => Promise<ChatSummary[]>;
|
|
|
225
29
|
type CreateChatHandler = () => Promise<string>;
|
|
226
30
|
type OpenChatHandler = (chatId: string) => void;
|
|
227
31
|
type DeleteChatHandler = (chatId: string) => Promise<void>;
|
|
228
|
-
interface AssistantActions {
|
|
229
|
-
state: unknown;
|
|
230
|
-
getChats: GetChatsHandler;
|
|
231
|
-
createChat: CreateChatHandler;
|
|
232
|
-
openChat: OpenChatHandler;
|
|
233
|
-
deleteChat: DeleteChatHandler;
|
|
234
|
-
}
|
|
235
32
|
//#endregion
|
|
236
33
|
//#region src/useAgent.d.ts
|
|
34
|
+
interface UseAgentReturn {
|
|
35
|
+
agent: Agent;
|
|
36
|
+
status: AgentConnectionStatus;
|
|
37
|
+
type: AgentConnectionType | undefined;
|
|
38
|
+
}
|
|
237
39
|
interface UseAgentOptions {
|
|
238
40
|
enabled?: boolean;
|
|
239
41
|
host: string;
|
|
@@ -250,116 +52,41 @@ interface UseAgentOptions {
|
|
|
250
52
|
onError?: (event: ErrorEvent) => void;
|
|
251
53
|
onMessage?: (event: MessageEvent) => void;
|
|
252
54
|
}
|
|
253
|
-
declare function useAgent(options: UseAgentOptions):
|
|
254
|
-
agent: Omit<PartySocket, "path"> & {
|
|
255
|
-
agent: string;
|
|
256
|
-
name: string;
|
|
257
|
-
path: ReadonlyArray<{
|
|
258
|
-
agent: string;
|
|
259
|
-
name: string;
|
|
260
|
-
}>;
|
|
261
|
-
identified: boolean;
|
|
262
|
-
ready: Promise<void>;
|
|
263
|
-
state: unknown;
|
|
264
|
-
setState: (state: unknown) => void;
|
|
265
|
-
call: <T = unknown>(method: string, args?: unknown[], options?: import("agents/client").CallOptions | import("agents/client").StreamOptions) => Promise<T>;
|
|
266
|
-
stub: import("agents/client").UntypedAgentStub;
|
|
267
|
-
getHttpUrl: () => string;
|
|
268
|
-
};
|
|
269
|
-
status: AgentConnectionStatus;
|
|
270
|
-
type: AgentConnectionType | undefined;
|
|
271
|
-
};
|
|
55
|
+
declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
272
56
|
//#endregion
|
|
273
57
|
//#region src/useChat.d.ts
|
|
58
|
+
interface UseChatReturn {
|
|
59
|
+
status: AgentConnectionStatus;
|
|
60
|
+
agent: Agent;
|
|
61
|
+
chat: Chat;
|
|
62
|
+
submitMessageFeedback: MessageFeedbackHandler;
|
|
63
|
+
getMessageFeedback: GetMessageFeedbackHandler;
|
|
64
|
+
}
|
|
274
65
|
interface UseChatOptions<ToolContext extends Record<string, unknown>> extends UseAgentOptions {
|
|
275
66
|
getInitialMessages?: undefined | null;
|
|
276
67
|
toolContext?: ToolContext;
|
|
277
68
|
welcomeMessage?: string;
|
|
278
69
|
}
|
|
279
|
-
declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>):
|
|
280
|
-
status: AgentConnectionStatus;
|
|
281
|
-
agent: Omit<PartySocket, "path"> & {
|
|
282
|
-
agent: string;
|
|
283
|
-
name: string;
|
|
284
|
-
path: ReadonlyArray<{
|
|
285
|
-
agent: string;
|
|
286
|
-
name: string;
|
|
287
|
-
}>;
|
|
288
|
-
identified: boolean;
|
|
289
|
-
ready: Promise<void>;
|
|
290
|
-
state: unknown;
|
|
291
|
-
setState: (state: unknown) => void;
|
|
292
|
-
call: <T = unknown>(method: string, args?: unknown[], options?: import("agents/client").CallOptions | import("agents/client").StreamOptions) => Promise<T>;
|
|
293
|
-
stub: import("agents/client").UntypedAgentStub;
|
|
294
|
-
getHttpUrl: () => string;
|
|
295
|
-
};
|
|
296
|
-
chat: Omit<import("@ai-sdk/react").UseChatHelpers<import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>, "addToolOutput"> & {
|
|
297
|
-
clearHistory: () => void;
|
|
298
|
-
addToolOutput: (opts: {
|
|
299
|
-
toolCallId: string;
|
|
300
|
-
toolName?: string;
|
|
301
|
-
output?: unknown;
|
|
302
|
-
state?: "output-available" | "output-error";
|
|
303
|
-
errorText?: string;
|
|
304
|
-
}) => void;
|
|
305
|
-
isServerStreaming: boolean;
|
|
306
|
-
isStreaming: boolean;
|
|
307
|
-
isRecovering: boolean;
|
|
308
|
-
isToolContinuation: boolean;
|
|
309
|
-
};
|
|
310
|
-
submitMessageFeedback: MessageFeedbackHandler;
|
|
311
|
-
getMessageFeedback: GetMessageFeedbackHandler;
|
|
312
|
-
};
|
|
70
|
+
declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
|
|
313
71
|
//#endregion
|
|
314
72
|
//#region src/useAssistant.d.ts
|
|
315
|
-
interface
|
|
316
|
-
|
|
73
|
+
interface Assistant {
|
|
74
|
+
agent: Agent;
|
|
75
|
+
getChats: GetChatsHandler;
|
|
76
|
+
createChat: CreateChatHandler;
|
|
77
|
+
openChat: OpenChatHandler;
|
|
78
|
+
deleteChat: DeleteChatHandler;
|
|
317
79
|
}
|
|
318
|
-
|
|
80
|
+
interface UseAssistantReturn {
|
|
319
81
|
currentChatName: string | undefined;
|
|
320
82
|
chats: ChatSummary[];
|
|
321
83
|
status: AgentConnectionStatus;
|
|
322
|
-
assistant:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
chat: {
|
|
330
|
-
status: AgentConnectionStatus;
|
|
331
|
-
agent: Omit<PartySocket, "path"> & {
|
|
332
|
-
agent: string;
|
|
333
|
-
name: string;
|
|
334
|
-
path: ReadonlyArray<{
|
|
335
|
-
agent: string;
|
|
336
|
-
name: string;
|
|
337
|
-
}>;
|
|
338
|
-
identified: boolean;
|
|
339
|
-
ready: Promise<void>;
|
|
340
|
-
state: unknown;
|
|
341
|
-
setState: (state: unknown) => void;
|
|
342
|
-
call: <T = unknown>(method: string, args?: unknown[], options?: import("agents/client").CallOptions | import("agents/client").StreamOptions) => Promise<T>;
|
|
343
|
-
stub: import("agents/client").UntypedAgentStub;
|
|
344
|
-
getHttpUrl: () => string;
|
|
345
|
-
};
|
|
346
|
-
chat: Omit<import("@ai-sdk/react").UseChatHelpers<import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>, "addToolOutput"> & {
|
|
347
|
-
clearHistory: () => void;
|
|
348
|
-
addToolOutput: (opts: {
|
|
349
|
-
toolCallId: string;
|
|
350
|
-
toolName?: string;
|
|
351
|
-
output?: unknown;
|
|
352
|
-
state?: "output-available" | "output-error";
|
|
353
|
-
errorText?: string;
|
|
354
|
-
}) => void;
|
|
355
|
-
isServerStreaming: boolean;
|
|
356
|
-
isStreaming: boolean;
|
|
357
|
-
isRecovering: boolean;
|
|
358
|
-
isToolContinuation: boolean;
|
|
359
|
-
};
|
|
360
|
-
submitMessageFeedback: MessageFeedbackHandler;
|
|
361
|
-
getMessageFeedback: GetMessageFeedbackHandler;
|
|
362
|
-
};
|
|
363
|
-
};
|
|
84
|
+
assistant: Assistant;
|
|
85
|
+
chat: UseChatReturn;
|
|
86
|
+
}
|
|
87
|
+
interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Record<string, unknown>> extends Omit<UseChatOptions<ToolContext>, "actorId" | "getInitialMessages"> {
|
|
88
|
+
initialChatId?: string;
|
|
89
|
+
}
|
|
90
|
+
declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
|
|
364
91
|
//#endregion
|
|
365
|
-
export { type AgentConnectionStatus, type AgentConnectionType, type
|
|
92
|
+
export { type Agent, type AgentConnectionStatus, type AgentConnectionType, type Assistant, type Chat, type ChatSummary, type CreateChatHandler, type DeleteChatHandler, type GetChatsHandler, type GetMessageFeedbackHandler, type MessageFeedback, type MessageFeedbackHandler, type OpenChatHandler, type UseAgentReturn, type UseAssistantReturn, type UseChatReturn, useAgent, useAssistant, useChat };
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/agents-react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -36,8 +36,5 @@
|
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "^19"
|
|
39
|
-
},
|
|
40
|
-
"inlinedDependencies": {
|
|
41
|
-
"partysocket": "1.1.19"
|
|
42
39
|
}
|
|
43
40
|
}
|