@agentuity/react 0.0.69 → 0.0.70

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/run.js DELETED
@@ -1,68 +0,0 @@
1
- import { useContext, useState } from 'react';
2
- import { buildUrl } from './url';
3
- import { AgentuityContext } from './context';
4
- export const useAgent = (name) => {
5
- const context = useContext(AgentuityContext);
6
- const [data, setData] = useState();
7
- const [error, setError] = useState(null);
8
- const [running, setRunning] = useState(false);
9
- if (!context) {
10
- throw new Error('useAgent must be used within a AgentuityProvider');
11
- }
12
- // Reset error (for now)
13
- const reset = () => setError(null);
14
- const run = async (input, options) => {
15
- setRunning(true);
16
- setError(null);
17
- try {
18
- const url = buildUrl(context.baseUrl, `/agent/${name}`, options?.subpath, options?.query);
19
- const signal = options?.signal ?? new AbortController().signal;
20
- const response = await fetch(url, {
21
- method: options?.method ?? 'POST',
22
- headers: {
23
- 'Content-Type': 'application/json',
24
- ...(options?.headers ?? {}),
25
- },
26
- signal,
27
- body: input && typeof input === 'object' && (options?.method ?? 'POST') !== 'GET'
28
- ? JSON.stringify(input)
29
- : undefined,
30
- });
31
- if (!response.ok) {
32
- const err = new Error(`Error invoking agent ${name}: ${response.status} ${response.statusText}`);
33
- setError(err);
34
- throw err;
35
- }
36
- // TODO: handle streams
37
- const ct = response.headers.get('Content-Type') || '';
38
- if (ct.includes('text/')) {
39
- const text = await response.text();
40
- const _data = text;
41
- setData(_data);
42
- return _data;
43
- }
44
- if (ct.includes('/json')) {
45
- const json = await response.json();
46
- const _data = json;
47
- setData(_data);
48
- return _data;
49
- }
50
- const err = new Error(`Unsupported content type: ${ct}`);
51
- setError(err);
52
- throw err;
53
- }
54
- catch (e) {
55
- if (e instanceof Error && e.name === 'AbortError') {
56
- throw e;
57
- }
58
- const err = e instanceof Error ? e : new Error(String(e));
59
- setError(err);
60
- throw err;
61
- }
62
- finally {
63
- setRunning(false);
64
- }
65
- };
66
- return { data, error, run, reset, running };
67
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CAAC;YAED,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,6BAA6B,EAAE,EAAE,CAAC,CAAC;YACzD,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,MAAM,GAAG,CAAC;QACX,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBACnD,MAAM,CAAC,CAAC;YACT,CAAC;YACD,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1D,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,MAAM,GAAG,CAAC;QACX,CAAC;gBAAS,CAAC;YACV,UAAU,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACF,CAAC,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC7C,CAAC,CAAC"}
package/src/run.ts DELETED
@@ -1,119 +0,0 @@
1
- import { useContext, useState } from 'react';
2
- import type { InferInput, InferOutput } from '@agentuity/core';
3
- import { buildUrl } from './url';
4
- import { AgentuityContext } from './context';
5
- import type { AgentName, AgentRegistry } from './types';
6
-
7
- interface RunArgs {
8
- /**
9
- * Optional query parameters to append to the URL
10
- */
11
- query?: URLSearchParams;
12
- /**
13
- * Optional headers to send with the request
14
- */
15
- headers?: Record<string, string>;
16
- /**
17
- * Optional subpath to append to the agent path (such as /agent/:agent_name/:subpath)
18
- */
19
- subpath?: string;
20
- /**
21
- * HTTP method to use (default: POST)
22
- */
23
- method?: string;
24
- /**
25
- * Optional AbortSignal to cancel the request
26
- */
27
- signal?: AbortSignal;
28
- }
29
-
30
- interface UseAgentResponse<TInput, TOutput> {
31
- data?: TOutput;
32
- error: Error | null;
33
- run: (input: TInput, options?: RunArgs) => Promise<TOutput>;
34
- reset: () => void;
35
- running: boolean;
36
- }
37
-
38
- export const useAgent = <
39
- TName extends AgentName,
40
- TInput = TName extends keyof AgentRegistry
41
- ? InferInput<AgentRegistry[TName]['inputSchema']>
42
- : never,
43
- TOutput = TName extends keyof AgentRegistry
44
- ? InferOutput<AgentRegistry[TName]['outputSchema']>
45
- : never,
46
- >(
47
- name: TName
48
- ): UseAgentResponse<TInput, TOutput> => {
49
- const context = useContext(AgentuityContext);
50
- const [data, setData] = useState<TOutput>();
51
- const [error, setError] = useState<Error | null>(null);
52
- const [running, setRunning] = useState(false);
53
-
54
- if (!context) {
55
- throw new Error('useAgent must be used within a AgentuityProvider');
56
- }
57
-
58
- // Reset error (for now)
59
- const reset = () => setError(null);
60
-
61
- const run = async (input: TInput, options?: RunArgs): Promise<TOutput> => {
62
- setRunning(true);
63
- setError(null);
64
- try {
65
- const url = buildUrl(context.baseUrl!, `/agent/${name}`, options?.subpath, options?.query);
66
- const signal = options?.signal ?? new AbortController().signal;
67
- const response = await fetch(url, {
68
- method: options?.method ?? 'POST',
69
- headers: {
70
- 'Content-Type': 'application/json',
71
- ...(options?.headers ?? {}),
72
- },
73
- signal,
74
- body:
75
- input && typeof input === 'object' && (options?.method ?? 'POST') !== 'GET'
76
- ? JSON.stringify(input)
77
- : undefined,
78
- });
79
-
80
- if (!response.ok) {
81
- const err = new Error(
82
- `Error invoking agent ${name}: ${response.status} ${response.statusText}`
83
- );
84
- setError(err);
85
- throw err;
86
- }
87
-
88
- // TODO: handle streams
89
- const ct = response.headers.get('Content-Type') || '';
90
- if (ct.includes('text/')) {
91
- const text = await response.text();
92
- const _data = text as TOutput;
93
- setData(_data);
94
- return _data;
95
- }
96
- if (ct.includes('/json')) {
97
- const json = await response.json();
98
- const _data = json as TOutput;
99
- setData(_data);
100
- return _data;
101
- }
102
-
103
- const err = new Error(`Unsupported content type: ${ct}`);
104
- setError(err);
105
- throw err;
106
- } catch (e) {
107
- if (e instanceof Error && e.name === 'AbortError') {
108
- throw e;
109
- }
110
- const err = e instanceof Error ? e : new Error(String(e));
111
- setError(err);
112
- throw err;
113
- } finally {
114
- setRunning(false);
115
- }
116
- };
117
-
118
- return { data, error, run, reset, running };
119
- };