@fencyai/react 0.1.110 → 0.1.111
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.js +669 -575
- package/dist/provider/StreamEventManager.d.ts +36 -0
- package/dist/types/FencyContext.d.ts +4 -1
- package/package.json +6 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FencyInstance } from '@fencyai/js';
|
|
2
|
+
import { StreamCache } from '../types/FencyContext';
|
|
3
|
+
type EventCallback = (data: string, streamId: string) => void;
|
|
4
|
+
type ErrorCallback = (streamId: string) => void;
|
|
5
|
+
interface Subscription {
|
|
6
|
+
onMessage: EventCallback;
|
|
7
|
+
onError: ErrorCallback;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Centralized manager for EventSource connections to streams.
|
|
11
|
+
* Ensures only one connection per stream regardless of how many hooks subscribe.
|
|
12
|
+
*/
|
|
13
|
+
export declare class StreamEventManager {
|
|
14
|
+
private eventSources;
|
|
15
|
+
private subscribers;
|
|
16
|
+
private fency;
|
|
17
|
+
constructor(fency: FencyInstance);
|
|
18
|
+
/**
|
|
19
|
+
* Called by FencyProvider when activeStreams changes.
|
|
20
|
+
* Creates new connections and removes old ones.
|
|
21
|
+
*/
|
|
22
|
+
updateStreams(streams: StreamCache[]): void;
|
|
23
|
+
private connectStream;
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to events from all active streams.
|
|
26
|
+
* Returns an unsubscribe function.
|
|
27
|
+
*/
|
|
28
|
+
subscribe(subscriberId: string, callbacks: Subscription): () => void;
|
|
29
|
+
private broadcast;
|
|
30
|
+
private broadcastError;
|
|
31
|
+
/**
|
|
32
|
+
* Cleanup all connections and subscriptions
|
|
33
|
+
*/
|
|
34
|
+
cleanup(): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FencyInstance, Stream } from '@fencyai/js';
|
|
2
|
+
import { StreamEventManager } from '../provider/StreamEventManager';
|
|
2
3
|
export interface StreamCache {
|
|
3
4
|
stream: Stream;
|
|
4
5
|
createdAt: number;
|
|
@@ -7,7 +8,9 @@ export interface FencyContext {
|
|
|
7
8
|
fency: FencyInstance;
|
|
8
9
|
loading: boolean;
|
|
9
10
|
error: Error | null;
|
|
10
|
-
|
|
11
|
+
activeStreams: StreamCache[];
|
|
12
|
+
latestStream: StreamCache | null;
|
|
13
|
+
eventManager: StreamEventManager | null;
|
|
11
14
|
getOrCreateStream: (fetchTokens: () => Promise<{
|
|
12
15
|
clientToken: string;
|
|
13
16
|
streamToken: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.111",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "staklau <steinaageklaussen@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -35,13 +35,15 @@
|
|
|
35
35
|
"@microsoft/fetch-event-source": "^2.0.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@fencyai/js": "^0.1.
|
|
38
|
+
"@fencyai/js": "^0.1.111",
|
|
39
|
+
"@testing-library/react": "^16.3.2",
|
|
39
40
|
"@types/jest": "^29.5.11",
|
|
40
41
|
"@types/node": "^20.10.5",
|
|
41
42
|
"@types/react": "^18.2.45",
|
|
42
43
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
43
44
|
"@vitejs/plugin-react": "^4.3.4",
|
|
44
45
|
"jest": "^29.7.0",
|
|
46
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
45
47
|
"ts-jest": "^29.1.1",
|
|
46
48
|
"typescript": "^5.3.3",
|
|
47
49
|
"vite": "^5.4.11",
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
},
|
|
51
53
|
"peerDependencies": {
|
|
52
54
|
"@emotion/is-prop-valid": "^1.3.0",
|
|
53
|
-
"@fencyai/js": "^0.1.
|
|
55
|
+
"@fencyai/js": "^0.1.111",
|
|
54
56
|
"@radix-ui/react-popover": "^1.1.15",
|
|
55
57
|
"motion": "^11.15.0",
|
|
56
58
|
"react": ">=16.8.0",
|
|
@@ -65,5 +67,5 @@
|
|
|
65
67
|
"optional": false
|
|
66
68
|
}
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b8f676f55b56f5a6d048cfa33335eb30f67f22bd"
|
|
69
71
|
}
|