()
| 26 | ); |
| 27 | |
| 28 | export const useCopilotKit = (): CopilotKitContextValue => { |
| 29 | const context = useContext(CopilotKitContext); |
| 30 | const [, forceUpdate] = useReducer((x: number) => x + 1, 0); |
| 31 | |
| 32 | if (!context) { |
| 33 | throw new Error("useCopilotKit must be used within CopilotKitProvider"); |
| 34 | } |
| 35 | useEffect(() => { |
| 36 | const subscription = context.copilotkit.subscribe({ |
| 37 | onRuntimeConnectionStatusChanged: () => { |
| 38 | forceUpdate(); |
| 39 | }, |
| 40 | onHeadersChanged: () => { |
| 41 | forceUpdate(); |
| 42 | }, |
| 43 | }); |
| 44 | return () => { |
| 45 | subscription.unsubscribe(); |
| 46 | }; |
| 47 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 48 | }, []); |
| 49 | |
| 50 | return context; |
| 51 | }; |
| 52 | |
| 53 | // License context — shared between web and RN providers. |
| 54 | // Default is permissive (all features allowed) — providers override via createLicenseContextValue. |
searching dependent graphs…