@agentuity/react 1.0.47 → 2.0.0-beta.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/AGENTS.md +26 -45
- package/README.md +28 -182
- package/dist/client-entrypoint.d.ts +8 -12
- package/dist/client-entrypoint.d.ts.map +1 -1
- package/dist/client-entrypoint.js +8 -15
- package/dist/client-entrypoint.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -12
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +6 -14
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -10
- package/dist/server.js.map +1 -1
- package/dist/webrtc.d.ts.map +1 -1
- package/dist/webrtc.js +2 -2
- package/dist/webrtc.js.map +1 -1
- package/package.json +5 -5
- package/src/client-entrypoint.tsx +8 -22
- package/src/context.tsx +3 -14
- package/src/index.ts +1 -52
- package/src/server.ts +5 -43
- package/src/webrtc.tsx +2 -1
- package/dist/api.d.ts +0 -302
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -487
- package/dist/api.js.map +0 -1
- package/dist/client.d.ts +0 -75
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -102
- package/dist/client.js.map +0 -1
- package/dist/eventstream.d.ts +0 -79
- package/dist/eventstream.d.ts.map +0 -1
- package/dist/eventstream.js +0 -122
- package/dist/eventstream.js.map +0 -1
- package/dist/types.d.ts +0 -18
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -18
- package/dist/types.js.map +0 -1
- package/dist/websocket.d.ts +0 -88
- package/dist/websocket.d.ts.map +0 -1
- package/dist/websocket.js +0 -151
- package/dist/websocket.js.map +0 -1
- package/src/api.ts +0 -954
- package/src/client.ts +0 -136
- package/src/eventstream.ts +0 -188
- package/src/types.ts +0 -23
- package/src/websocket.ts +0 -241
package/dist/client.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { createClient as coreCreateClient, } from '@agentuity/frontend';
|
|
2
|
-
let globalBaseUrl;
|
|
3
|
-
let globalAuthHeader;
|
|
4
|
-
/**
|
|
5
|
-
* Set the global base URL for RPC clients.
|
|
6
|
-
* This is automatically called by AgentuityProvider.
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export function setGlobalBaseUrl(url) {
|
|
10
|
-
globalBaseUrl = url;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get the global base URL for RPC clients.
|
|
14
|
-
* Returns the configured base URL or falls back to window.location.origin.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export function getGlobalBaseUrl() {
|
|
18
|
-
return globalBaseUrl || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Set the global auth header for RPC clients.
|
|
22
|
-
* This is automatically called by AgentuityProvider when auth state changes.
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export function setGlobalAuthHeader(authHeader) {
|
|
26
|
-
globalAuthHeader = authHeader;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get the global auth header for RPC clients.
|
|
30
|
-
* Returns the current auth header or undefined if not set.
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export function getGlobalAuthHeader() {
|
|
34
|
-
return globalAuthHeader;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Create a type-safe RPC client for React applications.
|
|
38
|
-
*
|
|
39
|
-
* This is a React-specific wrapper around @agentuity/core's createClient that
|
|
40
|
-
* automatically uses the baseUrl and auth headers from AgentuityProvider context.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* import { createClient } from '@agentuity/react';
|
|
45
|
-
* import type { RPCRouteRegistry } from '@agentuity/react';
|
|
46
|
-
*
|
|
47
|
-
* const client = createClient<RPCRouteRegistry>();
|
|
48
|
-
*
|
|
49
|
-
* // Inside component
|
|
50
|
-
* const result = await client.hello.post({ name: 'World' });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function createClient(options, metadata) {
|
|
54
|
-
// Merge user headers with auth headers
|
|
55
|
-
// User-provided headers take precedence over global auth header
|
|
56
|
-
const mergedHeaders = () => {
|
|
57
|
-
const authHeader = getGlobalAuthHeader();
|
|
58
|
-
const userHeaders = typeof options?.headers === 'function' ? options.headers() : options?.headers || {};
|
|
59
|
-
const headers = {};
|
|
60
|
-
// Add global auth header first (lower priority)
|
|
61
|
-
if (authHeader) {
|
|
62
|
-
headers.Authorization = authHeader;
|
|
63
|
-
}
|
|
64
|
-
// User headers override global auth
|
|
65
|
-
return { ...headers, ...userHeaders };
|
|
66
|
-
};
|
|
67
|
-
return coreCreateClient({
|
|
68
|
-
...options,
|
|
69
|
-
baseUrl: (options?.baseUrl || getGlobalBaseUrl),
|
|
70
|
-
headers: mergedHeaders,
|
|
71
|
-
}, metadata);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Create a type-safe API client with optional configuration.
|
|
75
|
-
*
|
|
76
|
-
* This is the recommended way to create an API client in React applications.
|
|
77
|
-
* It automatically includes auth headers from AgentuityProvider and allows
|
|
78
|
-
* custom headers to be passed.
|
|
79
|
-
*
|
|
80
|
-
* The generic type parameter defaults to RPCRouteRegistry which is augmented
|
|
81
|
-
* by generated code, so you don't need to specify it manually.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* import { createAPIClient } from '@agentuity/react';
|
|
86
|
-
*
|
|
87
|
-
* // Types are automatically inferred from generated routes
|
|
88
|
-
* const api = createAPIClient();
|
|
89
|
-
* await api.hello.post({ name: 'World' });
|
|
90
|
-
*
|
|
91
|
-
* // With custom headers
|
|
92
|
-
* const api = createAPIClient({ headers: { 'X-Custom': 'value' } });
|
|
93
|
-
* await api.hello.post({ name: 'World' });
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export function createAPIClient(options) {
|
|
97
|
-
// This function is designed to be used with generated metadata
|
|
98
|
-
// The metadata will be provided by the code generator
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
return createClient(options, globalThis.__rpcRouteMetadata);
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,gBAAgB,GAIhC,MAAM,qBAAqB,CAAC;AAM7B,IAAI,aAAiC,CAAC;AACtC,IAAI,gBAA2C,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,aAAa,GAAG,GAAG,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC/B,OAAO,aAAa,IAAI,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAyB;IAC5D,gBAAgB,GAAG,UAAU,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IAClC,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAC3B,OAGC,EACD,QAAkB;IAElB,uCAAuC;IACvC,gEAAgE;IAChE,MAAM,aAAa,GAAG,GAA2B,EAAE;QAClD,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAC;QACzC,MAAM,WAAW,GAChB,OAAO,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;QAErF,MAAM,OAAO,GAA2B,EAAE,CAAC;QAE3C,gDAAgD;QAChD,IAAI,UAAU,EAAE,CAAC;YAChB,OAAO,CAAC,aAAa,GAAG,UAAU,CAAC;QACpC,CAAC;QAED,oCAAoC;QACpC,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,WAAW,EAAE,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,gBAAgB,CACtB;QACC,GAAG,OAAO;QACV,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,IAAI,gBAAgB,CAA4B;QAC1E,OAAO,EAAE,aAAa;KACL,EAClB,QAAQ,CACR,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,CAC9B,OAGC;IAED,+DAA+D;IAC/D,sDAAsD;IACtD,8DAA8D;IAC9D,OAAO,YAAY,CAAI,OAAO,EAAG,UAAkB,CAAC,kBAAkB,CAAC,CAAC;AACzE,CAAC"}
|
package/dist/eventstream.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { InferOutput } from '@agentuity/core';
|
|
2
|
-
import { type SSERouteRegistry } from '@agentuity/frontend';
|
|
3
|
-
/**
|
|
4
|
-
* Extract SSE route keys (e.g., '/events', '/notifications')
|
|
5
|
-
*/
|
|
6
|
-
export type SSERouteKey = keyof SSERouteRegistry;
|
|
7
|
-
/**
|
|
8
|
-
* Extract output type for an SSE route (SSE is typically one-way server->client)
|
|
9
|
-
*/
|
|
10
|
-
export type SSERouteOutput<TRoute extends SSERouteKey> = TRoute extends keyof SSERouteRegistry ? SSERouteRegistry[TRoute] extends {
|
|
11
|
-
outputSchema: infer TSchema;
|
|
12
|
-
} ? TSchema extends undefined | never ? void : InferOutput<TSchema> : void : void;
|
|
13
|
-
/**
|
|
14
|
-
* Options for EventStream hooks
|
|
15
|
-
*/
|
|
16
|
-
export interface EventStreamOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Optional query parameters to append to the EventStream URL
|
|
19
|
-
*/
|
|
20
|
-
query?: URLSearchParams;
|
|
21
|
-
/**
|
|
22
|
-
* Optional subpath to append to the EventStream path
|
|
23
|
-
*/
|
|
24
|
-
subpath?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Optional AbortSignal to cancel the EventStream connection
|
|
27
|
-
*/
|
|
28
|
-
signal?: AbortSignal;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Type-safe EventStream (SSE) hook for connecting to SSE routes.
|
|
32
|
-
*
|
|
33
|
-
* Provides automatic type inference for route outputs based on
|
|
34
|
-
* the SSERouteRegistry generated from your routes.
|
|
35
|
-
*
|
|
36
|
-
* @template TRoute - SSE route key from SSERouteRegistry (e.g., '/events', '/notifications')
|
|
37
|
-
* @template TOutput - Optional type override for SSE event data. When provided, this type
|
|
38
|
-
* is used instead of the inferred type from the route registry. This is useful for SSE
|
|
39
|
-
* routes where outputSchema is `never` in the generated types.
|
|
40
|
-
*
|
|
41
|
-
* @example Simple SSE connection
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const { isConnected, data } = useEventStream('/events');
|
|
44
|
-
*
|
|
45
|
-
* // data is fully typed based on route output schema!
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example SSE with query parameters
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const { isConnected, data } = useEventStream('/notifications', {
|
|
51
|
-
* query: new URLSearchParams({ userId: '123' })
|
|
52
|
-
* });
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @example SSE with custom output type (when registry has outputSchema: never)
|
|
56
|
-
* ```typescript
|
|
57
|
-
* interface StreamMessage {
|
|
58
|
-
* type: 'token' | 'complete';
|
|
59
|
-
* content?: string;
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* const { isConnected, data } = useEventStream<'/api/search', StreamMessage>('/api/search');
|
|
63
|
-
*
|
|
64
|
-
* // data is typed as StreamMessage | undefined
|
|
65
|
-
* if (data?.type === 'token') {
|
|
66
|
-
* console.log(data.content);
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export declare function useEventStream<TRoute extends SSERouteKey, TOutput = SSERouteOutput<TRoute>>(route: TRoute, options?: EventStreamOptions): {
|
|
71
|
-
isConnected: boolean;
|
|
72
|
-
close: () => void;
|
|
73
|
-
data?: TOutput;
|
|
74
|
-
error: Error | null;
|
|
75
|
-
isError: boolean;
|
|
76
|
-
reset: () => void;
|
|
77
|
-
readyState: number;
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=eventstream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eventstream.d.ts","sourceRoot":"","sources":["../src/eventstream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,qBAAqB,CAAC;AAI7B;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,WAAW,IAAI,MAAM,SAAS,MAAM,gBAAgB,GAC3F,gBAAgB,CAAC,MAAM,CAAC,SAAS;IAAE,YAAY,EAAE,MAAM,OAAO,CAAA;CAAE,GAC/D,OAAO,SAAS,SAAS,GAAG,KAAK,GAChC,IAAI,GACJ,WAAW,CAAC,OAAO,CAAC,GACrB,IAAI,GACL,IAAI,CAAC;AAER;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,WAAW,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,EAC1F,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,kBAAkB,GAC1B;IACF,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACnB,CA4FA"}
|
package/dist/eventstream.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { buildUrl, EventStreamManager, jsonEqual, } from '@agentuity/frontend';
|
|
2
|
-
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { AgentuityContext } from './context';
|
|
4
|
-
/**
|
|
5
|
-
* Type-safe EventStream (SSE) hook for connecting to SSE routes.
|
|
6
|
-
*
|
|
7
|
-
* Provides automatic type inference for route outputs based on
|
|
8
|
-
* the SSERouteRegistry generated from your routes.
|
|
9
|
-
*
|
|
10
|
-
* @template TRoute - SSE route key from SSERouteRegistry (e.g., '/events', '/notifications')
|
|
11
|
-
* @template TOutput - Optional type override for SSE event data. When provided, this type
|
|
12
|
-
* is used instead of the inferred type from the route registry. This is useful for SSE
|
|
13
|
-
* routes where outputSchema is `never` in the generated types.
|
|
14
|
-
*
|
|
15
|
-
* @example Simple SSE connection
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const { isConnected, data } = useEventStream('/events');
|
|
18
|
-
*
|
|
19
|
-
* // data is fully typed based on route output schema!
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example SSE with query parameters
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const { isConnected, data } = useEventStream('/notifications', {
|
|
25
|
-
* query: new URLSearchParams({ userId: '123' })
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example SSE with custom output type (when registry has outputSchema: never)
|
|
30
|
-
* ```typescript
|
|
31
|
-
* interface StreamMessage {
|
|
32
|
-
* type: 'token' | 'complete';
|
|
33
|
-
* content?: string;
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* const { isConnected, data } = useEventStream<'/api/search', StreamMessage>('/api/search');
|
|
37
|
-
*
|
|
38
|
-
* // data is typed as StreamMessage | undefined
|
|
39
|
-
* if (data?.type === 'token') {
|
|
40
|
-
* console.log(data.content);
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export function useEventStream(route, options) {
|
|
45
|
-
const context = useContext(AgentuityContext);
|
|
46
|
-
if (!context) {
|
|
47
|
-
throw new Error('useEventStream must be used within a AgentuityProvider');
|
|
48
|
-
}
|
|
49
|
-
const managerRef = useRef(null);
|
|
50
|
-
const [data, setData] = useState();
|
|
51
|
-
const [error, setError] = useState(null);
|
|
52
|
-
const [isError, setIsError] = useState(false);
|
|
53
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
54
|
-
const [readyState, setReadyState] = useState(2); // EventSource.CLOSED = 2
|
|
55
|
-
// Build EventStream URL
|
|
56
|
-
// Track both query object and its string representation to detect mutations.
|
|
57
|
-
// URLSearchParams can be mutated in-place without changing object identity,
|
|
58
|
-
// so we compare the string value to trigger recomputation when params change.
|
|
59
|
-
const _queryString = options?.query?.toString();
|
|
60
|
-
const esUrl = useMemo(() => buildUrl(context.baseUrl, route, options?.subpath, options?.query), [context.baseUrl, route, options?.subpath, options?.query]);
|
|
61
|
-
// Initialize manager and connect
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
const manager = new EventStreamManager({
|
|
64
|
-
url: esUrl,
|
|
65
|
-
callbacks: {
|
|
66
|
-
onConnect: () => {
|
|
67
|
-
setIsConnected(true);
|
|
68
|
-
setError(null);
|
|
69
|
-
setIsError(false);
|
|
70
|
-
setReadyState(1); // EventSource.OPEN = 1
|
|
71
|
-
},
|
|
72
|
-
onDisconnect: () => {
|
|
73
|
-
setIsConnected(false);
|
|
74
|
-
setReadyState(2); // EventSource.CLOSED = 2
|
|
75
|
-
},
|
|
76
|
-
onError: (err) => {
|
|
77
|
-
setError(err);
|
|
78
|
-
setIsError(true);
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
// Set message handler with JSON memoization
|
|
83
|
-
manager.setMessageHandler((message) => {
|
|
84
|
-
setData((prev) => (prev !== undefined && jsonEqual(prev, message) ? prev : message));
|
|
85
|
-
});
|
|
86
|
-
manager.connect();
|
|
87
|
-
managerRef.current = manager;
|
|
88
|
-
return () => {
|
|
89
|
-
manager.dispose();
|
|
90
|
-
managerRef.current = null;
|
|
91
|
-
};
|
|
92
|
-
}, [esUrl]);
|
|
93
|
-
// Handle abort signal
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (options?.signal) {
|
|
96
|
-
const listener = () => {
|
|
97
|
-
managerRef.current?.close();
|
|
98
|
-
};
|
|
99
|
-
options.signal.addEventListener('abort', listener);
|
|
100
|
-
return () => {
|
|
101
|
-
options.signal?.removeEventListener('abort', listener);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}, [options?.signal]);
|
|
105
|
-
const reset = useCallback(() => {
|
|
106
|
-
setError(null);
|
|
107
|
-
setIsError(false);
|
|
108
|
-
}, []);
|
|
109
|
-
const close = useCallback(() => {
|
|
110
|
-
managerRef.current?.close();
|
|
111
|
-
}, []);
|
|
112
|
-
return {
|
|
113
|
-
isConnected,
|
|
114
|
-
close,
|
|
115
|
-
data,
|
|
116
|
-
error,
|
|
117
|
-
isError,
|
|
118
|
-
reset,
|
|
119
|
-
readyState,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=eventstream.js.map
|
package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G,EAAE;YACX,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC3B,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,sBAAsB;IACtB,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,QAAQ,GAAG,GAAG,EAAE;gBACrB,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAC7B,CAAC,CAAC;YACF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACnD,OAAO,GAAG,EAAE;gBACX,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACxD,CAAC,CAAC;QACH,CAAC;IACF,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAEtB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,UAAU,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACN,WAAW;QACX,KAAK;QACL,IAAI;QACJ,KAAK;QACL,OAAO;QACP,KAAK;QACL,UAAU;KACV,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route Registry Types for @agentuity/react
|
|
3
|
-
*
|
|
4
|
-
* These interfaces are re-exported from @agentuity/frontend and augmented by
|
|
5
|
-
* generated code (src/generated/routes.ts) to provide type-safe routing for
|
|
6
|
-
* useAPI, useWebsocket, useEventStream, and createAPIClient.
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* The generated code uses `declare module '@agentuity/frontend'` to augment
|
|
10
|
-
* these interfaces. Since @agentuity/react re-exports them, the augmented
|
|
11
|
-
* types are available when importing from either package.
|
|
12
|
-
*
|
|
13
|
-
* This design ensures that in monorepo setups with multiple node_modules,
|
|
14
|
-
* TypeScript sees consistent types as long as @agentuity/frontend is properly
|
|
15
|
-
* resolved (via hoisting or tsconfig paths).
|
|
16
|
-
*/
|
|
17
|
-
export type { RouteRegistry, WebSocketRouteRegistry, SSERouteRegistry, RPCRouteRegistry, } from '@agentuity/frontend';
|
|
18
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,YAAY,EACX,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,qBAAqB,CAAC"}
|
package/dist/types.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route Registry Types for @agentuity/react
|
|
3
|
-
*
|
|
4
|
-
* These interfaces are re-exported from @agentuity/frontend and augmented by
|
|
5
|
-
* generated code (src/generated/routes.ts) to provide type-safe routing for
|
|
6
|
-
* useAPI, useWebsocket, useEventStream, and createAPIClient.
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* The generated code uses `declare module '@agentuity/frontend'` to augment
|
|
10
|
-
* these interfaces. Since @agentuity/react re-exports them, the augmented
|
|
11
|
-
* types are available when importing from either package.
|
|
12
|
-
*
|
|
13
|
-
* This design ensures that in monorepo setups with multiple node_modules,
|
|
14
|
-
* TypeScript sees consistent types as long as @agentuity/frontend is properly
|
|
15
|
-
* resolved (via hoisting or tsconfig paths).
|
|
16
|
-
*/
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
package/dist/websocket.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { InferInput, InferOutput } from '@agentuity/core';
|
|
2
|
-
import { type WebSocketRouteRegistry } from '@agentuity/frontend';
|
|
3
|
-
/**
|
|
4
|
-
* Extract WebSocket route keys (e.g., '/ws', '/chat')
|
|
5
|
-
*/
|
|
6
|
-
export type WebSocketRouteKey = keyof WebSocketRouteRegistry;
|
|
7
|
-
/**
|
|
8
|
-
* Extract input type for a WebSocket route
|
|
9
|
-
*/
|
|
10
|
-
export type WebSocketRouteInput<TRoute extends WebSocketRouteKey> = TRoute extends keyof WebSocketRouteRegistry ? WebSocketRouteRegistry[TRoute] extends {
|
|
11
|
-
inputSchema: infer TSchema;
|
|
12
|
-
} ? TSchema extends undefined | never ? never : InferInput<TSchema> : never : never;
|
|
13
|
-
/**
|
|
14
|
-
* Extract output type for a WebSocket route
|
|
15
|
-
*/
|
|
16
|
-
export type WebSocketRouteOutput<TRoute extends WebSocketRouteKey> = TRoute extends keyof WebSocketRouteRegistry ? WebSocketRouteRegistry[TRoute] extends {
|
|
17
|
-
outputSchema: infer TSchema;
|
|
18
|
-
} ? TSchema extends undefined | never ? void : InferOutput<TSchema> : void : void;
|
|
19
|
-
/**
|
|
20
|
-
* Options for WebSocket hooks
|
|
21
|
-
*/
|
|
22
|
-
export interface WebsocketOptions {
|
|
23
|
-
/**
|
|
24
|
-
* Optional query parameters to append to the websocket URL
|
|
25
|
-
*/
|
|
26
|
-
query?: URLSearchParams;
|
|
27
|
-
/**
|
|
28
|
-
* Optional subpath to append to the websocket path
|
|
29
|
-
*/
|
|
30
|
-
subpath?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Optional AbortSignal to cancel the websocket connection
|
|
33
|
-
*/
|
|
34
|
-
signal?: AbortSignal;
|
|
35
|
-
/**
|
|
36
|
-
* Maximum number of messages to keep in the messages array.
|
|
37
|
-
* When exceeded, oldest messages are removed.
|
|
38
|
-
* @default undefined (no limit)
|
|
39
|
-
*/
|
|
40
|
-
maxMessages?: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Type-safe WebSocket hook for connecting to WebSocket routes.
|
|
44
|
-
*
|
|
45
|
-
* Provides automatic type inference for route inputs and outputs based on
|
|
46
|
-
* the WebSocketRouteRegistry generated from your routes.
|
|
47
|
-
*
|
|
48
|
-
* @template TRoute - WebSocket route key from WebSocketRouteRegistry (e.g., '/ws', '/chat')
|
|
49
|
-
*
|
|
50
|
-
* @example Simple WebSocket connection
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const { isConnected, data, send } = useWebsocket('/ws');
|
|
53
|
-
*
|
|
54
|
-
* // Send typed data
|
|
55
|
-
* send({ message: 'Hello' }); // Fully typed based on route schema!
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example WebSocket with query parameters
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const { isConnected, data, send } = useWebsocket('/chat', {
|
|
61
|
-
* query: new URLSearchParams({ room: 'general' })
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* @example Access all messages (prevents message loss in rapid succession)
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const { messages, clearMessages } = useWebsocket('/chat');
|
|
68
|
-
*
|
|
69
|
-
* // messages array contains ALL received messages
|
|
70
|
-
* messages.forEach(msg => console.log(msg));
|
|
71
|
-
*
|
|
72
|
-
* // Clear messages when needed
|
|
73
|
-
* clearMessages();
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export declare function useWebsocket<TRoute extends WebSocketRouteKey>(route: TRoute, options?: WebsocketOptions): {
|
|
77
|
-
isConnected: boolean;
|
|
78
|
-
close: () => void;
|
|
79
|
-
data?: WebSocketRouteOutput<TRoute>;
|
|
80
|
-
messages: WebSocketRouteOutput<TRoute>[];
|
|
81
|
-
clearMessages: () => void;
|
|
82
|
-
error: Error | null;
|
|
83
|
-
isError: boolean;
|
|
84
|
-
reset: () => void;
|
|
85
|
-
send: (data: WebSocketRouteInput<TRoute>) => void;
|
|
86
|
-
readyState: WebSocket['readyState'];
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=websocket.d.ts.map
|
package/dist/websocket.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAA8B,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAQ9F;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,iBAAiB,IAC/D,MAAM,SAAS,MAAM,sBAAsB,GACxC,sBAAsB,CAAC,MAAM,CAAC,SAAS;IAAE,WAAW,EAAE,MAAM,OAAO,CAAA;CAAE,GACpE,OAAO,SAAS,SAAS,GAAG,KAAK,GAChC,KAAK,GACL,UAAU,CAAC,OAAO,CAAC,GACpB,KAAK,GACN,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,MAAM,SAAS,iBAAiB,IAChE,MAAM,SAAS,MAAM,sBAAsB,GACxC,sBAAsB,CAAC,MAAM,CAAC,SAAS;IAAE,YAAY,EAAE,MAAM,OAAO,CAAA;CAAE,GACrE,OAAO,SAAS,SAAS,GAAG,KAAK,GAChC,IAAI,GACJ,WAAW,CAAC,OAAO,CAAC,GACrB,IAAI,GACL,IAAI,CAAC;AAET;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,iBAAiB,EAC5D,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,gBAAgB,GACxB;IACF,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;IACzC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAClD,UAAU,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;CACpC,CAiIA"}
|
package/dist/websocket.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { buildUrl, WebSocketManager } from '@agentuity/frontend';
|
|
3
|
-
import { AgentuityContext } from './context';
|
|
4
|
-
// WebSocket ready state constants for SSR compatibility
|
|
5
|
-
// (WebSocket global may not exist during SSR)
|
|
6
|
-
const WS_OPEN = 1;
|
|
7
|
-
const WS_CLOSED = 3;
|
|
8
|
-
/**
|
|
9
|
-
* Type-safe WebSocket hook for connecting to WebSocket routes.
|
|
10
|
-
*
|
|
11
|
-
* Provides automatic type inference for route inputs and outputs based on
|
|
12
|
-
* the WebSocketRouteRegistry generated from your routes.
|
|
13
|
-
*
|
|
14
|
-
* @template TRoute - WebSocket route key from WebSocketRouteRegistry (e.g., '/ws', '/chat')
|
|
15
|
-
*
|
|
16
|
-
* @example Simple WebSocket connection
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { isConnected, data, send } = useWebsocket('/ws');
|
|
19
|
-
*
|
|
20
|
-
* // Send typed data
|
|
21
|
-
* send({ message: 'Hello' }); // Fully typed based on route schema!
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example WebSocket with query parameters
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const { isConnected, data, send } = useWebsocket('/chat', {
|
|
27
|
-
* query: new URLSearchParams({ room: 'general' })
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example Access all messages (prevents message loss in rapid succession)
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const { messages, clearMessages } = useWebsocket('/chat');
|
|
34
|
-
*
|
|
35
|
-
* // messages array contains ALL received messages
|
|
36
|
-
* messages.forEach(msg => console.log(msg));
|
|
37
|
-
*
|
|
38
|
-
* // Clear messages when needed
|
|
39
|
-
* clearMessages();
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export function useWebsocket(route, options) {
|
|
43
|
-
const context = useContext(AgentuityContext);
|
|
44
|
-
if (!context) {
|
|
45
|
-
throw new Error('useWebsocket must be used within a AgentuityProvider');
|
|
46
|
-
}
|
|
47
|
-
const managerRef = useRef(null);
|
|
48
|
-
const [data, setData] = useState();
|
|
49
|
-
const [messages, setMessages] = useState([]);
|
|
50
|
-
const [error, setError] = useState(null);
|
|
51
|
-
const [isError, setIsError] = useState(false);
|
|
52
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
53
|
-
const [readyState, setReadyState] = useState(WS_CLOSED);
|
|
54
|
-
// Build WebSocket URL
|
|
55
|
-
const wsUrl = useMemo(() => {
|
|
56
|
-
const base = context.baseUrl;
|
|
57
|
-
const wsBase = base.replace(/^http(s?):/, 'ws$1:');
|
|
58
|
-
// Add auth token to query params if present
|
|
59
|
-
// (WebSocket doesn't support custom headers, so we pass via query string)
|
|
60
|
-
let queryParams = options?.query;
|
|
61
|
-
if (context.authHeader) {
|
|
62
|
-
const token = context.authHeader.replace(/^Bearer\s+/i, '');
|
|
63
|
-
const authQuery = new URLSearchParams({ token });
|
|
64
|
-
if (queryParams) {
|
|
65
|
-
queryParams = new URLSearchParams([...queryParams, ...authQuery]);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
queryParams = authQuery;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return buildUrl(wsBase, route, options?.subpath, queryParams);
|
|
72
|
-
}, [context.baseUrl, context.authHeader, route, options?.subpath, options?.query]);
|
|
73
|
-
// Initialize manager and connect
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
const manager = new WebSocketManager({
|
|
76
|
-
url: wsUrl,
|
|
77
|
-
callbacks: {
|
|
78
|
-
onConnect: () => {
|
|
79
|
-
setIsConnected(true);
|
|
80
|
-
setError(null);
|
|
81
|
-
setIsError(false);
|
|
82
|
-
setReadyState(WS_OPEN);
|
|
83
|
-
},
|
|
84
|
-
onDisconnect: () => {
|
|
85
|
-
setIsConnected(false);
|
|
86
|
-
setReadyState(WS_CLOSED);
|
|
87
|
-
},
|
|
88
|
-
onError: (err) => {
|
|
89
|
-
setError(err);
|
|
90
|
-
setIsError(true);
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
// Set message handler
|
|
95
|
-
manager.setMessageHandler((message) => {
|
|
96
|
-
setData(message);
|
|
97
|
-
setMessages((prev) => {
|
|
98
|
-
const newMessages = [...prev, message];
|
|
99
|
-
// Enforce maxMessages limit if specified
|
|
100
|
-
if (options?.maxMessages && newMessages.length > options.maxMessages) {
|
|
101
|
-
return newMessages.slice(-options.maxMessages);
|
|
102
|
-
}
|
|
103
|
-
return newMessages;
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
manager.connect();
|
|
107
|
-
managerRef.current = manager;
|
|
108
|
-
return () => {
|
|
109
|
-
manager.dispose();
|
|
110
|
-
managerRef.current = null;
|
|
111
|
-
};
|
|
112
|
-
}, [wsUrl, options?.maxMessages]);
|
|
113
|
-
// Handle abort signal
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
if (options?.signal) {
|
|
116
|
-
const listener = () => {
|
|
117
|
-
managerRef.current?.close();
|
|
118
|
-
};
|
|
119
|
-
options.signal.addEventListener('abort', listener);
|
|
120
|
-
return () => {
|
|
121
|
-
options.signal?.removeEventListener('abort', listener);
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}, [options?.signal]);
|
|
125
|
-
const reset = useCallback(() => {
|
|
126
|
-
setError(null);
|
|
127
|
-
setIsError(false);
|
|
128
|
-
}, []);
|
|
129
|
-
const send = useCallback((sendData) => {
|
|
130
|
-
managerRef.current?.send(sendData);
|
|
131
|
-
}, []);
|
|
132
|
-
const close = useCallback(() => {
|
|
133
|
-
managerRef.current?.close();
|
|
134
|
-
}, []);
|
|
135
|
-
const clearMessages = useCallback(() => {
|
|
136
|
-
setMessages([]);
|
|
137
|
-
}, []);
|
|
138
|
-
return {
|
|
139
|
-
isConnected,
|
|
140
|
-
close,
|
|
141
|
-
data,
|
|
142
|
-
messages,
|
|
143
|
-
clearMessages,
|
|
144
|
-
error,
|
|
145
|
-
isError,
|
|
146
|
-
reset,
|
|
147
|
-
send,
|
|
148
|
-
readyState,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=websocket.js.map
|
package/dist/websocket.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,E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