@economic/agents-react 1.7.0 → 2.0.0-alpha.38232858664.1.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 CHANGED
@@ -212,4 +212,4 @@ The package also exports the handler types `AssistantActions`, `GetChatsHandler`
212
212
 
213
213
  ## Authentication
214
214
 
215
- Pass a JWT as `authToken`. It is sent both as an `Authorization: Bearer …` header and as a WebSocket subprotocol (`["bearer", token]`), matching the server-side [`getJwtAuthConfig`](../agents/README.md#authentication). When verification fails, the connection status becomes `"unauthorized"`.
215
+ Pass a JWT as `authToken`. It is sent both as an `Authorization: Bearer …` header and as a WebSocket subprotocol (`["bearer", token]`), matching the server-side [`getAuthenticator(env)`](../agents/README.md#authentication). When verification fails, the connection status becomes `"unauthorized"`.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { useAgent as useAgent$1 } from "agents/react";
2
2
  import { getToolApproval, getToolCallId, getToolPartState, useAgentChat } from "@cloudflare/ai-chat/react";
3
-
4
3
  //#region src/types.d.ts
5
4
  type _CfAgent = ReturnType<typeof useAgent$1>;
6
5
  type Agent = Omit<_CfAgent, "call"> & {
@@ -10,7 +9,8 @@ type Chat = ReturnType<typeof useAgentChat>;
10
9
  type AgentConnectionStatus = "connecting" | "reconnecting" | "connected" | "disconnected" | "unauthorized" | "error";
11
10
  type AgentConnectionType = "agent" | "chat" | "assistant";
12
11
  type ChatSummary = {
13
- name: string; /** True when this entry only represents the active, unregistered chat facet. */
12
+ name: string;
13
+ /** True when this entry only represents the active, unregistered chat facet. */
14
14
  isTemporary?: boolean;
15
15
  title?: string;
16
16
  summary?: string;
@@ -61,7 +61,7 @@ interface UseAgentOptions {
61
61
  onError?: (event: ErrorEvent) => void;
62
62
  onMessage?: (event: MessageEvent) => void;
63
63
  }
64
- declare function useAgent(options: UseAgentOptions): UseAgentReturn;
64
+ export declare function useAgent(options: UseAgentOptions): UseAgentReturn;
65
65
  //#endregion
66
66
  //#region src/useChat.d.ts
67
67
  interface UseChatReturn {
@@ -79,7 +79,7 @@ interface UseChatOptions<ToolContext extends Record<string, unknown>> extends Us
79
79
  /** Include internal SDK messages such as compaction summaries. Defaults to false. */
80
80
  showInternalMessages?: boolean;
81
81
  }
82
- declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
82
+ export declare function useChat<ToolContext extends Record<string, unknown>>(options: UseChatOptions<ToolContext>): UseChatReturn;
83
83
  //#endregion
84
84
  //#region src/useAssistant.d.ts
85
85
  interface Assistant {
@@ -100,6 +100,6 @@ interface UseAssistantReturn {
100
100
  interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Record<string, unknown>> extends Omit<UseChatOptions<ToolContext>, "actorId" | "getInitialMessages"> {
101
101
  initialChatId?: string;
102
102
  }
103
- declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
103
+ export declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
104
104
  //#endregion
105
- export { type Agent, type AgentConnectionStatus, type AgentConnectionType, type Assistant, type Chat, type ChatSummary, type CreateChatHandler, type DeleteChatHandler, type GetChatsHandler, type GetInvocableSkillsHandler, type GetMessageFeedbackHandler, type InvocableSkill, type MessageFeedback, type MessageFeedbackHandler, type OpenChatHandler, type RenameChatHandler, type UseAgentReturn, type UseAssistantReturn, type UseChatReturn, getToolApproval, getToolCallId, getToolPartState, useAgent, useAssistant, useChat };
105
+ export { type Agent, type AgentConnectionStatus, type AgentConnectionType, type Assistant, type Chat, type ChatSummary, type CreateChatHandler, type DeleteChatHandler, type GetChatsHandler, type GetInvocableSkillsHandler, type GetMessageFeedbackHandler, type InvocableSkill, type MessageFeedback, type MessageFeedbackHandler, type OpenChatHandler, type RenameChatHandler, type UseAgentReturn, type UseAssistantReturn, type UseChatReturn, getToolApproval, getToolCallId, getToolPartState };
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ import { n as visibleChatMessages, t as getTokenArgs } from "./util-tBvVuxIJ.mjs
2
2
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
3
3
  import { useAgent as useAgent$1 } from "agents/react";
4
4
  import { getToolApproval, getToolCallId, getToolPartState, useAgentChat } from "@cloudflare/ai-chat/react";
5
- import { agentFetch } from "agents/client";
6
5
  //#region src/useAgent.ts
7
6
  function getAgentConnectionStatus(state, connectionId) {
8
7
  return state.connectionId === connectionId ? state.status : "connecting";
@@ -204,19 +203,6 @@ function useAgent(options) {
204
203
  }
205
204
  //#endregion
206
205
  //#region src/useChat.ts
207
- async function fetchInvocableSkills(agent) {
208
- const target = getAgentSocketTarget(agent);
209
- if (!target) throw new Error("Cannot determine the connected agent");
210
- const path = target.subPath ? `${target.subPath}/getInvocableSkills` : "getInvocableSkills";
211
- const response = await agentFetch({
212
- agent: target.agentName,
213
- host: target.host,
214
- name: target.name,
215
- path
216
- }, { headers: target.authToken ? { Authorization: `Bearer ${target.authToken}` } : void 0 });
217
- if (!response.ok) throw new Error(`Failed to get invocable skills (${response.status})`);
218
- return response.json();
219
- }
220
206
  function useChat(options) {
221
207
  const { toolContext, welcomeMessage, showInternalMessages = false, ...agentOptions } = options;
222
208
  const { agent, status } = useAgent({
@@ -226,9 +212,10 @@ function useChat(options) {
226
212
  const chat = useAgentChat({
227
213
  agent,
228
214
  body: toolContext ?? {},
215
+ headers: agentOptions.authToken ? { Authorization: `Bearer ${agentOptions.authToken}` } : void 0,
229
216
  getInitialMessages: !!agentOptions.name && status === "connected" ? void 0 : null
230
217
  });
231
- const getInvocableSkills = useCallback(() => fetchInvocableSkills(agent), [agent]);
218
+ const getInvocableSkills = useCallback(async () => await agent.call("getInvocableSkills"), [agent]);
232
219
  const hasSentWelcome = useRef(false);
233
220
  useEffect(() => {
234
221
  if (welcomeMessage && status === "connected" && chat.messages.length === 0 && !hasSentWelcome.current) {
package/dist/v1.d.mts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { useAgent } from "agents/react";
2
2
  import { useAgentChat } from "@cloudflare/ai-chat/react";
3
-
4
3
  //#region src/v1/index.d.ts
5
- type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
6
- interface UseAIChatAgentOptions {
4
+ export type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
5
+ export interface UseAIChatAgentOptions {
7
6
  agent: string;
8
7
  host: string;
9
8
  basePath?: string;
@@ -27,6 +26,5 @@ type UseAIChatAgentResult = {
27
26
  chat: ReturnType<typeof useAgentChat>;
28
27
  connectionStatus: AgentConnectionStatus;
29
28
  };
30
- declare function useAIChatAgent(options: UseAIChatAgentOptions): UseAIChatAgentResult;
31
- //#endregion
32
- export { AgentConnectionStatus, UseAIChatAgentOptions, useAIChatAgent };
29
+ export declare function useAIChatAgent(options: UseAIChatAgentOptions): UseAIChatAgentResult;
30
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents-react",
3
- "version": "1.7.0",
3
+ "version": "2.0.0-alpha.38232858664.1.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -20,18 +20,18 @@
20
20
  "prepublishOnly": "npm run build"
21
21
  },
22
22
  "dependencies": {
23
- "@ai-sdk/react": "^3.0.182",
24
- "@cloudflare/ai-chat": "^0.11.0",
25
- "agents": "^0.22.0",
26
- "ai": "^6.0.180",
27
- "zod": "^4.4.3"
23
+ "@ai-sdk/react": "^4.0.140",
24
+ "@cloudflare/ai-chat": "^0.12.1",
25
+ "agents": "^0.28.0",
26
+ "ai": "^7.0.137",
27
+ "zod": "^4.6.5"
28
28
  },
29
29
  "devDependencies": {
30
- "@cloudflare/workers-types": "^4.20260702.1",
31
- "@types/node": "^25.6.0",
32
- "@typescript/native-preview": "7.0.0-dev.20260412.1",
33
- "tsdown": "^0.22.0",
34
- "typescript": "^6.0.2",
30
+ "@cloudflare/workers-types": "^5.20261009.1",
31
+ "@types/node": "^26.6.4",
32
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
33
+ "tsdown": "^0.23.0",
34
+ "typescript": "^7.0.2",
35
35
  "vitest": "^4.1.4"
36
36
  },
37
37
  "peerDependencies": {