@economic/agents-react 1.6.5 → 1.7.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/dist/index.d.mts CHANGED
@@ -27,6 +27,12 @@ type MessageFeedback = {
27
27
  };
28
28
  type MessageFeedbackHandler = (messageId: string, rating: number, comment?: string) => Promise<void>;
29
29
  type GetMessageFeedbackHandler = () => Promise<Record<string, MessageFeedback>>;
30
+ type InvocableSkill = {
31
+ command: string;
32
+ name: string;
33
+ description: string;
34
+ };
35
+ type GetInvocableSkillsHandler = () => Promise<InvocableSkill[]>;
30
36
  type GetChatsHandler = () => Promise<ChatSummary[]>;
31
37
  type CreateChatHandler = () => Promise<string>;
32
38
  type OpenChatHandler = (chatId: string) => void;
@@ -62,6 +68,7 @@ interface UseChatReturn {
62
68
  status: AgentConnectionStatus;
63
69
  agent: Agent;
64
70
  chat: Chat;
71
+ getInvocableSkills: GetInvocableSkillsHandler;
65
72
  submitMessageFeedback: MessageFeedbackHandler;
66
73
  getMessageFeedback: GetMessageFeedbackHandler;
67
74
  }
@@ -95,4 +102,4 @@ interface UseAssistantOptions<ToolContext extends Record<string, unknown> = Reco
95
102
  }
96
103
  declare function useAssistant<ToolContext extends Record<string, unknown>>(options: UseAssistantOptions<ToolContext>): UseAssistantReturn;
97
104
  //#endregion
98
- 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 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, useAgent, useAssistant, useChat };
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ 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";
5
6
  //#region src/useAgent.ts
6
7
  function getAgentConnectionStatus(state, connectionId) {
7
8
  return state.connectionId === connectionId ? state.status : "connecting";
@@ -203,6 +204,19 @@ function useAgent(options) {
203
204
  }
204
205
  //#endregion
205
206
  //#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
+ }
206
220
  function useChat(options) {
207
221
  const { toolContext, welcomeMessage, showInternalMessages = false, ...agentOptions } = options;
208
222
  const { agent, status } = useAgent({
@@ -214,6 +228,7 @@ function useChat(options) {
214
228
  body: toolContext ?? {},
215
229
  getInitialMessages: !!agentOptions.name && status === "connected" ? void 0 : null
216
230
  });
231
+ const getInvocableSkills = useCallback(() => fetchInvocableSkills(agent), [agent]);
217
232
  const hasSentWelcome = useRef(false);
218
233
  useEffect(() => {
219
234
  if (welcomeMessage && status === "connected" && chat.messages.length === 0 && !hasSentWelcome.current) {
@@ -249,6 +264,7 @@ function useChat(options) {
249
264
  ...chat,
250
265
  messages: visibleChatMessages(chat.messages, showInternalMessages)
251
266
  },
267
+ getInvocableSkills,
252
268
  submitMessageFeedback,
253
269
  getMessageFeedback
254
270
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents-react",
3
- "version": "1.6.5",
3
+ "version": "1.7.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@ai-sdk/react": "^3.0.182",
24
- "@cloudflare/ai-chat": "^0.9.3",
25
- "agents": "^0.17.3",
24
+ "@cloudflare/ai-chat": "^0.11.0",
25
+ "agents": "^0.22.0",
26
26
  "ai": "^6.0.180",
27
27
  "zod": "^4.4.3"
28
28
  },