@economic/agents-react 1.1.1 → 1.1.2
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 +30 -34
- package/dist/index.mjs +18 -17
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -219,13 +219,17 @@ type AgentConnectionState = {
|
|
|
219
219
|
interface UseAgentOptions {
|
|
220
220
|
host: string;
|
|
221
221
|
agentName: string;
|
|
222
|
-
id: string;
|
|
223
222
|
enabled?: boolean;
|
|
224
223
|
sub?: {
|
|
225
224
|
agent: string;
|
|
226
225
|
name: string;
|
|
227
226
|
}[];
|
|
227
|
+
onOpen?: () => void;
|
|
228
|
+
onClose?: () => void;
|
|
229
|
+
onError?: (error: Event) => void;
|
|
228
230
|
authToken?: string;
|
|
231
|
+
userId?: string;
|
|
232
|
+
id: string;
|
|
229
233
|
}
|
|
230
234
|
declare function useAgent<T extends AgentConnectionState>(options: UseAgentOptions): Omit<PartySocket, "path"> & {
|
|
231
235
|
agent: string;
|
|
@@ -243,30 +247,12 @@ declare function useAgent<T extends AgentConnectionState>(options: UseAgentOptio
|
|
|
243
247
|
getHttpUrl: () => string;
|
|
244
248
|
};
|
|
245
249
|
//#endregion
|
|
246
|
-
//#region src/
|
|
247
|
-
|
|
248
|
-
type Conversation = {
|
|
249
|
-
durable_object_name: string;
|
|
250
|
-
title?: string;
|
|
251
|
-
summary?: string;
|
|
252
|
-
created_at: number;
|
|
253
|
-
updated_at: number;
|
|
254
|
-
};
|
|
255
|
-
interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Record<string, unknown>> {
|
|
256
|
-
host: string;
|
|
257
|
-
assistantName: string;
|
|
258
|
-
userId: string;
|
|
259
|
-
chatId?: string;
|
|
260
|
-
authToken?: string;
|
|
250
|
+
//#region src/useChatAgent.d.ts
|
|
251
|
+
interface UseChatOptions<ToolContext extends Record<string, unknown>> extends UseAgentOptions {
|
|
261
252
|
toolContext?: ToolContext;
|
|
262
253
|
}
|
|
263
|
-
declare function
|
|
264
|
-
chatId: string | undefined;
|
|
254
|
+
declare function useChatAgent<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): {
|
|
265
255
|
status: AgentConnectionStatus;
|
|
266
|
-
getConversations: () => Promise<Conversation[]>;
|
|
267
|
-
createConversation: () => Promise<string>;
|
|
268
|
-
openConversation: (chatId: string) => void;
|
|
269
|
-
deleteConversation: (chatId: string) => Promise<void>;
|
|
270
256
|
agent: Omit<PartySocket, "path"> & {
|
|
271
257
|
agent: string;
|
|
272
258
|
name: string;
|
|
@@ -282,7 +268,7 @@ declare function useAssistant<ToolContext extends Record<string, unknown>>(optio
|
|
|
282
268
|
stub: _$agents_client0.UntypedAgentStub;
|
|
283
269
|
getHttpUrl: () => string;
|
|
284
270
|
};
|
|
285
|
-
chat:
|
|
271
|
+
chat: Omit<_$_ai_sdk_react0.UseChatHelpers<_$ai.UIMessage<unknown, _$ai.UIDataTypes, _$ai.UITools>>, "addToolOutput"> & {
|
|
286
272
|
clearHistory: () => void;
|
|
287
273
|
addToolOutput: (opts: {
|
|
288
274
|
toolCallId: string;
|
|
@@ -294,19 +280,29 @@ declare function useAssistant<ToolContext extends Record<string, unknown>>(optio
|
|
|
294
280
|
isServerStreaming: boolean;
|
|
295
281
|
isStreaming: boolean;
|
|
296
282
|
isToolContinuation: boolean;
|
|
297
|
-
}
|
|
283
|
+
};
|
|
298
284
|
};
|
|
299
285
|
//#endregion
|
|
300
|
-
//#region src/
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
286
|
+
//#region src/useAssistant.d.ts
|
|
287
|
+
/** Conversation summary returned by the assistant's `getConversations` RPC. */
|
|
288
|
+
type Conversation = {
|
|
289
|
+
durable_object_name: string;
|
|
290
|
+
title?: string;
|
|
291
|
+
summary?: string;
|
|
292
|
+
created_at: number;
|
|
293
|
+
updated_at: number;
|
|
294
|
+
};
|
|
295
|
+
interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Record<string, unknown>> extends Omit<UseChatOptions<ToolContext>, "id" | "userId"> {
|
|
296
|
+
userId: string;
|
|
297
|
+
initialChatId?: string;
|
|
307
298
|
}
|
|
308
|
-
declare function
|
|
299
|
+
declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): {
|
|
300
|
+
chatId: string | undefined;
|
|
309
301
|
status: AgentConnectionStatus;
|
|
302
|
+
getConversations: () => Promise<Conversation[]>;
|
|
303
|
+
createConversation: () => Promise<string>;
|
|
304
|
+
openConversation: (chatId: string) => void;
|
|
305
|
+
deleteConversation: (chatId: string) => Promise<void>;
|
|
310
306
|
agent: Omit<PartySocket, "path"> & {
|
|
311
307
|
agent: string;
|
|
312
308
|
name: string;
|
|
@@ -322,7 +318,7 @@ declare function useChatAgent<ToolContext extends Record<string, unknown>>(optio
|
|
|
322
318
|
stub: _$agents_client0.UntypedAgentStub;
|
|
323
319
|
getHttpUrl: () => string;
|
|
324
320
|
};
|
|
325
|
-
chat: Omit<_$_ai_sdk_react0.UseChatHelpers<_$ai.UIMessage<unknown, _$ai.UIDataTypes, _$ai.UITools>>, "addToolOutput"> & {
|
|
321
|
+
chat: (Omit<_$_ai_sdk_react0.UseChatHelpers<_$ai.UIMessage<unknown, _$ai.UIDataTypes, _$ai.UITools>>, "addToolOutput"> & {
|
|
326
322
|
clearHistory: () => void;
|
|
327
323
|
addToolOutput: (opts: {
|
|
328
324
|
toolCallId: string;
|
|
@@ -334,7 +330,7 @@ declare function useChatAgent<ToolContext extends Record<string, unknown>>(optio
|
|
|
334
330
|
isServerStreaming: boolean;
|
|
335
331
|
isStreaming: boolean;
|
|
336
332
|
isToolContinuation: boolean;
|
|
337
|
-
};
|
|
333
|
+
}) | undefined;
|
|
338
334
|
};
|
|
339
335
|
//#endregion
|
|
340
336
|
export { AgentConnectionState, AgentConnectionStatus, AgentConnectionType, Conversation, UseAgentOptions, UseAssistantOptions, UseChatOptions, useAgent, useAssistant, useChatAgent };
|
package/dist/index.mjs
CHANGED
|
@@ -12,28 +12,30 @@ function getTokenArgs(authToken) {
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/useAgent.ts
|
|
14
14
|
function useAgent(options) {
|
|
15
|
-
const { host, agentName, id, enabled, sub, authToken } = options;
|
|
15
|
+
const { host, agentName, userId, id, enabled, sub, authToken, onError, onOpen, onClose } = options;
|
|
16
16
|
return useAgent$1({
|
|
17
17
|
enabled,
|
|
18
18
|
host,
|
|
19
19
|
agent: agentName,
|
|
20
|
-
name: id,
|
|
20
|
+
name: userId ? `${userId}:${id}` : id,
|
|
21
21
|
sub,
|
|
22
|
+
onOpen,
|
|
23
|
+
onClose,
|
|
24
|
+
onError,
|
|
22
25
|
...getTokenArgs(authToken)
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
//#endregion
|
|
26
29
|
//#region src/useAssistant.ts
|
|
27
30
|
function useAssistant(options) {
|
|
28
|
-
const { host,
|
|
29
|
-
const
|
|
31
|
+
const { host, agentName, userId, authToken, toolContext, ...agentOptions } = options;
|
|
32
|
+
const [chatId, setChatId] = useState();
|
|
33
|
+
const assistant = useAgent({
|
|
30
34
|
host,
|
|
31
|
-
agentName
|
|
35
|
+
agentName,
|
|
32
36
|
id: userId,
|
|
33
37
|
authToken
|
|
34
|
-
};
|
|
35
|
-
const [chatId, setChatId] = useState(initialChatId);
|
|
36
|
-
const assistant = useAgent(config);
|
|
38
|
+
});
|
|
37
39
|
const getConversations = async () => {
|
|
38
40
|
return await assistant.call("getConversations");
|
|
39
41
|
};
|
|
@@ -52,12 +54,16 @@ function useAssistant(options) {
|
|
|
52
54
|
await getConversations();
|
|
53
55
|
};
|
|
54
56
|
const agent = useAgent({
|
|
55
|
-
...config,
|
|
56
57
|
enabled: !!chatId,
|
|
58
|
+
host,
|
|
59
|
+
agentName,
|
|
60
|
+
id: userId,
|
|
61
|
+
authToken,
|
|
57
62
|
sub: chatId ? [{
|
|
58
63
|
agent: assistant.state?.subAgentName ?? "",
|
|
59
64
|
name: chatId
|
|
60
|
-
}] : void 0
|
|
65
|
+
}] : void 0,
|
|
66
|
+
...agentOptions
|
|
61
67
|
});
|
|
62
68
|
const isChatReady = !!chatId && agent.state?.status === "connected";
|
|
63
69
|
const chat = useAgentChat({
|
|
@@ -79,13 +85,8 @@ function useAssistant(options) {
|
|
|
79
85
|
//#endregion
|
|
80
86
|
//#region src/useChatAgent.ts
|
|
81
87
|
function useChatAgent(options) {
|
|
82
|
-
const {
|
|
83
|
-
const agent = useAgent(
|
|
84
|
-
host,
|
|
85
|
-
agentName,
|
|
86
|
-
id,
|
|
87
|
-
authToken
|
|
88
|
-
});
|
|
88
|
+
const { toolContext, ...agentOptions } = options;
|
|
89
|
+
const agent = useAgent(agentOptions);
|
|
89
90
|
const chat = useAgentChat({
|
|
90
91
|
agent,
|
|
91
92
|
body: toolContext ?? {}
|