@agentuity/react 0.0.5 → 0.0.7

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/AGENTS.md CHANGED
@@ -19,7 +19,7 @@ React hooks and components for building Agentuity web applications. Provides typ
19
19
 
20
20
  ## Structure
21
21
 
22
- ```
22
+ ```text
23
23
  src/
24
24
  ├── index.ts # Main entry point
25
25
  ├── context.tsx # AgentuityProvider and AgentuityContext
package/README.md CHANGED
@@ -29,11 +29,11 @@ Wrap your app with the `AgentuityProvider`:
29
29
  import { AgentuityProvider } from '@agentuity/react';
30
30
 
31
31
  function App() {
32
- return (
33
- <AgentuityProvider baseUrl="http://localhost:3000">
34
- <YourApp />
35
- </AgentuityProvider>
36
- );
32
+ return (
33
+ <AgentuityProvider baseUrl="http://localhost:3000">
34
+ <YourApp />
35
+ </AgentuityProvider>
36
+ );
37
37
  }
38
38
  ```
39
39
 
@@ -45,19 +45,19 @@ Call agents with type-safety using the `useAgent` hook:
45
45
  import { useAgent } from '@agentuity/react';
46
46
 
47
47
  function MyComponent() {
48
- const { data, run } = useAgent('myAgent');
49
-
50
- const handleClick = async () => {
51
- const result = await run({ message: 'Hello' });
52
- console.log(result);
53
- };
54
-
55
- return (
56
- <div>
57
- <button onClick={handleClick}>Call Agent</button>
58
- {data && <div>Response: {JSON.stringify(data)}</div>}
59
- </div>
60
- );
48
+ const { data, run } = useAgent('myAgent');
49
+
50
+ const handleClick = async () => {
51
+ const result = await run({ message: 'Hello' });
52
+ console.log(result);
53
+ };
54
+
55
+ return (
56
+ <div>
57
+ <button onClick={handleClick}>Call Agent</button>
58
+ {data && <div>Response: {JSON.stringify(data)}</div>}
59
+ </div>
60
+ );
61
61
  }
62
62
  ```
63
63
 
@@ -69,26 +69,26 @@ For real-time communication:
69
69
  import { useWebsocket } from '@agentuity/react';
70
70
 
71
71
  function ChatComponent() {
72
- const { connected, send, setHandler } = useWebsocket('/chat');
73
-
74
- useEffect(() => {
75
- setHandler((message) => {
76
- console.log('Received:', message);
77
- });
78
- }, []);
79
-
80
- const sendMessage = () => {
81
- send({ text: 'Hello, agent!' });
82
- };
83
-
84
- return (
85
- <div>
86
- <div>Status: {connected ? 'Connected' : 'Disconnected'}</div>
87
- <button onClick={sendMessage} disabled={!connected}>
88
- Send Message
89
- </button>
90
- </div>
91
- );
72
+ const { connected, send, setHandler } = useWebsocket('/chat');
73
+
74
+ useEffect(() => {
75
+ setHandler((message) => {
76
+ console.log('Received:', message);
77
+ });
78
+ }, []);
79
+
80
+ const sendMessage = () => {
81
+ send({ text: 'Hello, agent!' });
82
+ };
83
+
84
+ return (
85
+ <div>
86
+ <div>Status: {connected ? 'Connected' : 'Disconnected'}</div>
87
+ <button onClick={sendMessage} disabled={!connected}>
88
+ Send Message
89
+ </button>
90
+ </div>
91
+ );
92
92
  }
93
93
  ```
94
94
 
@@ -99,6 +99,7 @@ function ChatComponent() {
99
99
  Context provider for Agentuity configuration.
100
100
 
101
101
  **Props:**
102
+
102
103
  - `baseUrl?: string` - Base URL for agent API calls (defaults to current origin)
103
104
  - `children: ReactNode` - Child components
104
105
 
@@ -111,13 +112,16 @@ const { data, run } = useAgent<TName>(name);
111
112
  ```
112
113
 
113
114
  **Parameters:**
115
+
114
116
  - `name: string` - Agent name
115
117
 
116
118
  **Returns:**
119
+
117
120
  - `data?: TOutput` - Last response data
118
121
  - `run: (input: TInput, options?: RunArgs) => Promise<TOutput>` - Function to invoke the agent
119
122
 
120
123
  **RunArgs:**
124
+
121
125
  - `query?: URLSearchParams` - Query parameters
122
126
  - `headers?: Record<string, string>` - Custom headers
123
127
  - `subpath?: string` - Subpath to append to agent URL
@@ -129,14 +133,19 @@ const { data, run } = useAgent<TName>(name);
129
133
  Hook for WebSocket connections to agents.
130
134
 
131
135
  ```typescript
132
- const { connected, send, setHandler, readyState, close } = useWebsocket<TInput, TOutput>(path, options);
136
+ const { connected, send, setHandler, readyState, close } = useWebsocket<TInput, TOutput>(
137
+ path,
138
+ options
139
+ );
133
140
  ```
134
141
 
135
142
  **Parameters:**
143
+
136
144
  - `path: string` - WebSocket path
137
145
  - `options?: WebsocketArgs` - Connection options
138
146
 
139
147
  **Returns:**
148
+
140
149
  - `connected: boolean` - Connection status
141
150
  - `send: (data: TInput) => void` - Send data to server
142
151
  - `setHandler: (handler: (data: TOutput) => void) => void` - Set message handler
package/dist/index.js CHANGED
@@ -1112,40 +1112,46 @@ var import_react2 = __toESM(require_react(), 1);
1112
1112
  var useAgent = (name) => {
1113
1113
  const context = import_react2.useContext(AgentuityContext);
1114
1114
  const [data, setData] = import_react2.useState();
1115
+ const [running, setRunning] = import_react2.useState(false);
1115
1116
  if (!context) {
1116
1117
  throw new Error("useAgent must be used within a AgentuityProvider");
1117
1118
  }
1118
1119
  const run = async (input, options) => {
1119
- const url = buildUrl(context.baseUrl, `/agent/${name}`, options?.subpath, options?.query);
1120
- const signal = options?.signal ?? new AbortController().signal;
1121
- const response = await fetch(url, {
1122
- method: options?.method ?? "POST",
1123
- headers: {
1124
- "Content-Type": "application/json",
1125
- ...options?.headers ?? ""
1126
- },
1127
- signal,
1128
- body: input && typeof input === "object" && options?.method !== "GET" ? JSON.stringify(input) : undefined
1129
- });
1130
- if (!response.ok) {
1131
- throw new Error(`Error invoking agent ${name}: ${response.statusText}`);
1132
- }
1133
- const ct = response.headers.get("Content-Type") || "";
1134
- if (ct.includes("text/")) {
1135
- const text = await response.text();
1136
- const _data = text;
1137
- setData(_data);
1138
- return _data;
1139
- }
1140
- if (ct.includes("/json")) {
1141
- const data2 = await response.json();
1142
- const _data = data2;
1143
- setData(_data);
1144
- return _data;
1120
+ setRunning(true);
1121
+ try {
1122
+ const url = buildUrl(context.baseUrl, `/agent/${name}`, options?.subpath, options?.query);
1123
+ const signal = options?.signal ?? new AbortController().signal;
1124
+ const response = await fetch(url, {
1125
+ method: options?.method ?? "POST",
1126
+ headers: {
1127
+ "Content-Type": "application/json",
1128
+ ...options?.headers ?? ""
1129
+ },
1130
+ signal,
1131
+ body: input && typeof input === "object" && options?.method !== "GET" ? JSON.stringify(input) : undefined
1132
+ });
1133
+ if (!response.ok) {
1134
+ throw new Error(`Error invoking agent ${name}: ${response.statusText}`);
1135
+ }
1136
+ const ct = response.headers.get("Content-Type") || "";
1137
+ if (ct.includes("text/")) {
1138
+ const text = await response.text();
1139
+ const _data = text;
1140
+ setData(_data);
1141
+ return _data;
1142
+ }
1143
+ if (ct.includes("/json")) {
1144
+ const data2 = await response.json();
1145
+ const _data = data2;
1146
+ setData(_data);
1147
+ return _data;
1148
+ }
1149
+ throw new Error(`Unsupported content type: ${ct}`);
1150
+ } finally {
1151
+ setRunning(false);
1145
1152
  }
1146
- throw new Error(`Unsupported content type: ${ct}`);
1147
1153
  };
1148
- return { run, data };
1154
+ return { data, run, running };
1149
1155
  };
1150
1156
  // src/websocket.ts
1151
1157
  var import_react3 = __toESM(require_react(), 1);
package/dist/run.d.ts CHANGED
@@ -25,6 +25,7 @@ interface RunArgs {
25
25
  interface UseAgentResponse<TInput, TOutput> {
26
26
  data?: TOutput;
27
27
  run: (input: TInput, options?: RunArgs) => Promise<TOutput>;
28
+ running: boolean;
28
29
  }
29
30
  export declare const useAgent: <TName extends AgentName, TInput = TName extends keyof AgentRegistry ? InferInput<AgentRegistry[TName]["inputSchema"]> : never, TOutput = TName extends keyof AgentRegistry ? InferOutput<AgentRegistry[TName]["outputSchema"]> : never>(name: TName) => UseAgentResponse<TInput, TOutput>;
30
31
  export {};
package/dist/run.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExD,UAAU,OAAO;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,O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,EAAE,WAAW,CAAC;CACrB;AAED,UAAU,gBAAgB,CAAC,MAAM,EAAE,OAAO;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,QAAQ,GACpB,KAAK,SAAS,SAAS,EACvB,MAAM,GAAG,KAAK,SAAS,MAAM,aAAa,GACvC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,CAAC,GAC/C,KAAK,EACR,OAAO,GAAG,KAAK,SAAS,MAAM,aAAa,GACxC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC,GACjD,KAAK,EAER,MAAM,KAAK,KACT,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAkDlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/react",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "prepublishOnly": "bun run clean && bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@agentuity/core": "0.0.1"
25
+ "@agentuity/core": "0.0.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/react": "^19.0.0",