@copilotkit/react-core 1.4.1-pre.5 → 1.4.1
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/CHANGELOG.md +63 -0
- package/dist/chunk-2KCEHGSI.mjs +192 -0
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-IIGBMHZI.mjs → chunk-DT52QX4H.mjs} +4 -4
- package/dist/{chunk-TRXKPXDE.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-OQ326E7V.mjs → chunk-JDQCJCAQ.mjs} +18 -5
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/chunk-L34MHAXR.mjs +1 -0
- package/dist/{chunk-HVWV4SDG.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/{chunk-2MPUQRAY.mjs → chunk-LODRWFMB.mjs} +2 -1
- package/dist/chunk-LODRWFMB.mjs.map +1 -0
- package/dist/chunk-MLAS4QUR.mjs +18 -0
- package/dist/chunk-MLAS4QUR.mjs.map +1 -0
- package/dist/{chunk-K76NL2VN.mjs → chunk-MWZO6TUR.mjs} +2 -2
- package/dist/chunk-O7ARI5CV.mjs +31 -0
- package/dist/chunk-O7ARI5CV.mjs.map +1 -0
- package/dist/chunk-ODN4H66E.mjs +31 -0
- package/dist/chunk-ODN4H66E.mjs.map +1 -0
- package/dist/{chunk-6YEMNWKE.mjs → chunk-P6VS7ST4.mjs} +177 -5
- package/dist/chunk-P6VS7ST4.mjs.map +1 -0
- package/dist/{chunk-ANOG3W5S.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-VE63DJCR.mjs → chunk-V22C3DOQ.mjs} +3 -3
- package/dist/{chunk-MTVKTUZD.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +283 -26
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -2
- package/dist/components/copilot-provider/index.js +281 -26
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +6 -3
- package/dist/components/index.js +281 -26
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -4
- package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
- package/dist/components/toast/exclamation-mark-icon.js +55 -0
- package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
- package/dist/components/toast/toast-provider.d.ts +29 -0
- package/dist/components/toast/toast-provider.js +255 -0
- package/dist/components/toast/toast-provider.js.map +1 -0
- package/dist/components/toast/toast-provider.mjs +11 -0
- package/dist/context/copilot-context.d.ts +2 -0
- package/dist/context/copilot-context.js +1 -0
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +104 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -12
- package/dist/hooks/use-chat.js +65 -26
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -1
- package/dist/hooks/use-coagent-state-render.js +1 -0
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +83 -43
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -7
- package/dist/hooks/use-copilot-action.js +1 -0
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +85 -45
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +8 -6
- package/dist/hooks/use-copilot-readable.js +1 -0
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +5 -0
- package/dist/hooks/use-copilot-runtime-client.js +76 -0
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
- package/dist/hooks/use-make-copilot-document-readable.js +1 -0
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +500 -241
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -19
- package/dist/lib/copilot-task.d.ts +1 -0
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -5
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -5
- package/dist/utils/dev-console.d.ts +3 -0
- package/dist/utils/dev-console.js +42 -0
- package/dist/utils/dev-console.js.map +1 -0
- package/dist/utils/dev-console.mjs +8 -0
- package/dist/utils/dev-console.mjs.map +1 -0
- package/dist/utils/extract.js +4 -26
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +6 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +22 -28
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -7
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +32 -1
- package/src/components/toast/exclamation-mark-icon.tsx +27 -0
- package/src/components/toast/toast-provider.tsx +209 -0
- package/src/context/copilot-context.tsx +5 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +14 -6
- package/src/hooks/use-copilot-runtime-client.ts +24 -0
- package/src/utils/dev-console.ts +18 -0
- package/src/utils/extract.ts +2 -16
- package/src/utils/index.ts +1 -0
- package/dist/chunk-2MPUQRAY.mjs.map +0 -1
- package/dist/chunk-6YEMNWKE.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -1
- package/dist/chunk-OQ326E7V.mjs.map +0 -1
- package/dist/chunk-SPCZTZCY.mjs +0 -1
- package/dist/chunk-YJLRG5U3.mjs +0 -1
- package/dist/chunk-ZM6HV22S.mjs +0 -164
- package/dist/chunk-ZM6HV22S.mjs.map +0 -1
- /package/dist/{chunk-IIGBMHZI.mjs.map → chunk-DT52QX4H.mjs.map} +0 -0
- /package/dist/{chunk-TRXKPXDE.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-BWYAGPEF.mjs.map → chunk-L34MHAXR.mjs.map} +0 -0
- /package/dist/{chunk-HVWV4SDG.mjs.map → chunk-LMFSB5D5.mjs.map} +0 -0
- /package/dist/{chunk-K76NL2VN.mjs.map → chunk-MWZO6TUR.mjs.map} +0 -0
- /package/dist/{chunk-ANOG3W5S.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-VE63DJCR.mjs.map → chunk-V22C3DOQ.mjs.map} +0 -0
- /package/dist/{chunk-MTVKTUZD.mjs.map → chunk-XINZBP3J.mjs.map} +0 -0
- /package/dist/{chunk-JD7BAH7U.mjs.map → components/toast/exclamation-mark-icon.mjs.map} +0 -0
- /package/dist/{chunk-SPCZTZCY.mjs.map → components/toast/toast-provider.mjs.map} +0 -0
- /package/dist/{chunk-YJLRG5U3.mjs.map → hooks/use-copilot-runtime-client.mjs.map} +0 -0
|
@@ -6,6 +6,7 @@ import { DocumentPointer } from '../types/document-pointer.js';
|
|
|
6
6
|
import { CopilotChatSuggestionConfiguration } from '../types/chat-suggestion-configuration.js';
|
|
7
7
|
import { CoAgentStateRenderProps, CoAgentStateRender } from '../types/coagent-action.js';
|
|
8
8
|
import { CoagentState } from '../types/coagent-state.js';
|
|
9
|
+
import { CopilotRuntimeClient } from '@copilotkit/runtime-client-gql';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Interface for the configuration of the Copilot API.
|
|
@@ -100,6 +101,7 @@ interface CopilotContextParams {
|
|
|
100
101
|
setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;
|
|
101
102
|
agentSession: AgentSession | null;
|
|
102
103
|
setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;
|
|
104
|
+
runtimeClient: CopilotRuntimeClient;
|
|
103
105
|
}
|
|
104
106
|
declare const CopilotContext: React.Context<CopilotContextParams>;
|
|
105
107
|
declare function useCopilotContext(): CopilotContextParams;
|
|
@@ -81,6 +81,7 @@ var emptyCopilotContext = {
|
|
|
81
81
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
82
82
|
removeDocumentContext: () => {
|
|
83
83
|
},
|
|
84
|
+
runtimeClient: {},
|
|
84
85
|
copilotApiConfig: new class {
|
|
85
86
|
get chatApiEndpoint() {
|
|
86
87
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/copilot-context.tsx"],"sourcesContent":["import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/context/copilot-context.tsx"],"sourcesContent":["import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AA2IlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,eAAe,CAAC;AAAA,EAEhB,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IAEA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EAEzB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
|
package/dist/context/index.js
CHANGED
|
@@ -85,6 +85,7 @@ var emptyCopilotContext = {
|
|
|
85
85
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
86
86
|
removeDocumentContext: () => {
|
|
87
87
|
},
|
|
88
|
+
runtimeClient: {},
|
|
88
89
|
copilotApiConfig: new class {
|
|
89
90
|
get chatApiEndpoint() {
|
|
90
91
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAkB;AA2IlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,eAAe,CAAC;AAAA,EAEhB,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IAEA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EAEzB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ACzMA,IAAAC,gBAAkB;AAOlB,IAAMC,uBAAoD;AAAA,EACxD,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,CAAC;AACtB;AAEO,IAAM,yBACX,cAAAC,QAAM,cAA4CD,oBAAmB;AAEhE,SAAS,4BAA0D;AACxE,QAAM,UAAU,cAAAC,QAAM,WAAW,sBAAsB;AACvD,MAAI,YAAYD,sBAAqB;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["React","import_react","emptyCopilotContext","React"]}
|
package/dist/context/index.mjs
CHANGED
package/dist/hooks/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { useMakeCopilotDocumentReadable } from './use-make-copilot-document-read
|
|
|
5
5
|
export { UseChatHelpers } from './use-chat.js';
|
|
6
6
|
export { useCopilotReadable } from './use-copilot-readable.js';
|
|
7
7
|
export { useCoAgent } from './use-coagent.js';
|
|
8
|
+
export { useCopilotRuntimeClient } from './use-copilot-runtime-client.js';
|
|
8
9
|
import '@copilotkit/runtime-client-gql';
|
|
9
10
|
import '../types/system-message.js';
|
|
10
11
|
import '@copilotkit/shared';
|
package/dist/hooks/index.js
CHANGED
|
@@ -84,12 +84,13 @@ __export(hooks_exports, {
|
|
|
84
84
|
useCopilotAction: () => useCopilotAction,
|
|
85
85
|
useCopilotChat: () => useCopilotChat,
|
|
86
86
|
useCopilotReadable: () => useCopilotReadable,
|
|
87
|
+
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
87
88
|
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable
|
|
88
89
|
});
|
|
89
90
|
module.exports = __toCommonJS(hooks_exports);
|
|
90
91
|
|
|
91
92
|
// src/hooks/use-copilot-chat.ts
|
|
92
|
-
var
|
|
93
|
+
var import_react7 = require("react");
|
|
93
94
|
|
|
94
95
|
// src/context/copilot-context.tsx
|
|
95
96
|
var import_react = __toESM(require("react"));
|
|
@@ -119,6 +120,7 @@ var emptyCopilotContext = {
|
|
|
119
120
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
120
121
|
removeDocumentContext: () => {
|
|
121
122
|
},
|
|
123
|
+
runtimeClient: {},
|
|
122
124
|
copilotApiConfig: new class {
|
|
123
125
|
get chatApiEndpoint() {
|
|
124
126
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -157,12 +159,43 @@ function returnAndThrowInDebug(value) {
|
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
// src/hooks/use-copilot-chat.ts
|
|
160
|
-
var
|
|
162
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
161
163
|
|
|
162
164
|
// src/hooks/use-chat.ts
|
|
163
|
-
var
|
|
165
|
+
var import_react4 = require("react");
|
|
164
166
|
var import_shared = require("@copilotkit/shared");
|
|
167
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
168
|
+
|
|
169
|
+
// src/components/toast/toast-provider.tsx
|
|
170
|
+
var import_react2 = require("react");
|
|
171
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
172
|
+
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
173
|
+
function useToast() {
|
|
174
|
+
const context = (0, import_react2.useContext)(ToastContext);
|
|
175
|
+
if (!context) {
|
|
176
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
177
|
+
}
|
|
178
|
+
return context;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
165
182
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
183
|
+
var import_react3 = require("react");
|
|
184
|
+
var useCopilotRuntimeClient = (options) => {
|
|
185
|
+
const { addGraphQLErrorsToast } = useToast();
|
|
186
|
+
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
187
|
+
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
188
|
+
handleGQLErrors: (error) => {
|
|
189
|
+
if (error.graphQLErrors.length) {
|
|
190
|
+
addGraphQLErrorsToast(error.graphQLErrors);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
}, [options, addGraphQLErrorsToast]);
|
|
195
|
+
return runtimeClient;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/hooks/use-chat.ts
|
|
166
199
|
function useChat(options) {
|
|
167
200
|
const {
|
|
168
201
|
messages,
|
|
@@ -180,17 +213,18 @@ function useChat(options) {
|
|
|
180
213
|
agentSession,
|
|
181
214
|
setAgentSession
|
|
182
215
|
} = options;
|
|
183
|
-
const abortControllerRef = (0,
|
|
184
|
-
const threadIdRef = (0,
|
|
185
|
-
const runIdRef = (0,
|
|
186
|
-
const
|
|
187
|
-
const
|
|
216
|
+
const abortControllerRef = (0, import_react4.useRef)();
|
|
217
|
+
const threadIdRef = (0, import_react4.useRef)(null);
|
|
218
|
+
const runIdRef = (0, import_react4.useRef)(null);
|
|
219
|
+
const { addGraphQLErrorsToast } = useToast();
|
|
220
|
+
const runChatCompletionRef = (0, import_react4.useRef)();
|
|
221
|
+
const coagentStatesRef = (0, import_react4.useRef)(coagentStates);
|
|
188
222
|
coagentStatesRef.current = coagentStates;
|
|
189
|
-
const agentSessionRef = (0,
|
|
223
|
+
const agentSessionRef = (0, import_react4.useRef)(agentSession);
|
|
190
224
|
agentSessionRef.current = agentSession;
|
|
191
225
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
192
226
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
193
|
-
const runtimeClient =
|
|
227
|
+
const runtimeClient = useCopilotRuntimeClient({
|
|
194
228
|
url: copilotConfig.chatApiEndpoint,
|
|
195
229
|
publicApiKey: copilotConfig.publicApiKey,
|
|
196
230
|
headers,
|
|
@@ -200,9 +234,9 @@ function useChat(options) {
|
|
|
200
234
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
201
235
|
setIsLoading(true);
|
|
202
236
|
let newMessages = [
|
|
203
|
-
new
|
|
237
|
+
new import_runtime_client_gql2.TextMessage({
|
|
204
238
|
content: "",
|
|
205
|
-
role:
|
|
239
|
+
role: import_runtime_client_gql2.Role.Assistant
|
|
206
240
|
})
|
|
207
241
|
];
|
|
208
242
|
const abortController = new AbortController();
|
|
@@ -210,20 +244,20 @@ function useChat(options) {
|
|
|
210
244
|
setMessages([...previousMessages, ...newMessages]);
|
|
211
245
|
const systemMessage = makeSystemMessageCallback();
|
|
212
246
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
213
|
-
const stream =
|
|
247
|
+
const stream = runtimeClient.asStream(
|
|
214
248
|
runtimeClient.generateCopilotResponse({
|
|
215
249
|
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
216
250
|
frontend: {
|
|
217
251
|
actions: actions.filter(
|
|
218
|
-
(action) => action.available !==
|
|
252
|
+
(action) => action.available !== import_runtime_client_gql2.ActionInputAvailability.Disabled || !action.disabled
|
|
219
253
|
).map((action) => {
|
|
220
|
-
let available =
|
|
254
|
+
let available = import_runtime_client_gql2.ActionInputAvailability.Enabled;
|
|
221
255
|
if (action.disabled) {
|
|
222
|
-
available =
|
|
256
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
223
257
|
} else if (action.available === "disabled") {
|
|
224
|
-
available =
|
|
258
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
225
259
|
} else if (action.available === "remote") {
|
|
226
|
-
available =
|
|
260
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Remote;
|
|
227
261
|
}
|
|
228
262
|
return {
|
|
229
263
|
name: action.name,
|
|
@@ -236,7 +270,7 @@ function useChat(options) {
|
|
|
236
270
|
},
|
|
237
271
|
threadId: threadIdRef.current,
|
|
238
272
|
runId: runIdRef.current,
|
|
239
|
-
messages: (0,
|
|
273
|
+
messages: (0, import_runtime_client_gql2.convertMessagesToGqlInput)((0, import_runtime_client_gql2.filterAgentStateMessages)(messagesWithContext))
|
|
240
274
|
}, copilotConfig.cloud ? {
|
|
241
275
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
242
276
|
guardrails: {
|
|
@@ -248,7 +282,7 @@ function useChat(options) {
|
|
|
248
282
|
} : {})
|
|
249
283
|
} : {}), {
|
|
250
284
|
metadata: {
|
|
251
|
-
requestType:
|
|
285
|
+
requestType: import_runtime_client_gql2.CopilotRequestType.Chat
|
|
252
286
|
}
|
|
253
287
|
}), agentSessionRef.current ? {
|
|
254
288
|
agentSession: agentSessionRef.current
|
|
@@ -269,7 +303,14 @@ function useChat(options) {
|
|
|
269
303
|
let followUp = void 0;
|
|
270
304
|
try {
|
|
271
305
|
while (true) {
|
|
272
|
-
|
|
306
|
+
let done, value;
|
|
307
|
+
try {
|
|
308
|
+
const readResult = yield reader.read();
|
|
309
|
+
done = readResult.done;
|
|
310
|
+
value = readResult.value;
|
|
311
|
+
} catch (readError) {
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
273
314
|
if (done) {
|
|
274
315
|
break;
|
|
275
316
|
}
|
|
@@ -278,8 +319,8 @@ function useChat(options) {
|
|
|
278
319
|
}
|
|
279
320
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
280
321
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
281
|
-
const messages2 = (0,
|
|
282
|
-
(0,
|
|
322
|
+
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
323
|
+
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
283
324
|
);
|
|
284
325
|
if (messages2.length === 0) {
|
|
285
326
|
continue;
|
|
@@ -287,15 +328,15 @@ function useChat(options) {
|
|
|
287
328
|
newMessages = [];
|
|
288
329
|
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
289
330
|
newMessages = [
|
|
290
|
-
new
|
|
291
|
-
role:
|
|
331
|
+
new import_runtime_client_gql2.TextMessage({
|
|
332
|
+
role: import_runtime_client_gql2.MessageRole.Assistant,
|
|
292
333
|
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
293
334
|
})
|
|
294
335
|
];
|
|
295
336
|
} else {
|
|
296
337
|
for (const message of messages2) {
|
|
297
338
|
newMessages.push(message);
|
|
298
|
-
if (message.isActionExecutionMessage() && message.status.code !==
|
|
339
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
299
340
|
if (!(message.id in actionResults)) {
|
|
300
341
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
301
342
|
break;
|
|
@@ -318,8 +359,8 @@ function useChat(options) {
|
|
|
318
359
|
}
|
|
319
360
|
}
|
|
320
361
|
newMessages.push(
|
|
321
|
-
new
|
|
322
|
-
result:
|
|
362
|
+
new import_runtime_client_gql2.ResultMessage({
|
|
363
|
+
result: import_runtime_client_gql2.ResultMessage.encodeResult(actionResults[message.id]),
|
|
323
364
|
actionExecutionId: message.id,
|
|
324
365
|
actionName: message.name
|
|
325
366
|
})
|
|
@@ -416,19 +457,19 @@ function useChat(options) {
|
|
|
416
457
|
}
|
|
417
458
|
|
|
418
459
|
// src/components/copilot-provider/copilotkit.tsx
|
|
419
|
-
var
|
|
460
|
+
var import_react6 = require("react");
|
|
420
461
|
var import_react_dom = require("react-dom");
|
|
421
462
|
var import_shared2 = require("@copilotkit/shared");
|
|
422
463
|
|
|
423
464
|
// src/context/copilot-messages-context.tsx
|
|
424
|
-
var
|
|
465
|
+
var import_react5 = __toESM(require("react"));
|
|
425
466
|
var emptyCopilotContext2 = {
|
|
426
467
|
messages: [],
|
|
427
468
|
setMessages: () => []
|
|
428
469
|
};
|
|
429
|
-
var CopilotMessagesContext =
|
|
470
|
+
var CopilotMessagesContext = import_react5.default.createContext(emptyCopilotContext2);
|
|
430
471
|
function useCopilotMessagesContext() {
|
|
431
|
-
const context =
|
|
472
|
+
const context = import_react5.default.useContext(CopilotMessagesContext);
|
|
432
473
|
if (context === emptyCopilotContext2) {
|
|
433
474
|
throw new Error(
|
|
434
475
|
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
@@ -438,7 +479,7 @@ function useCopilotMessagesContext() {
|
|
|
438
479
|
}
|
|
439
480
|
|
|
440
481
|
// src/components/copilot-provider/copilotkit.tsx
|
|
441
|
-
var
|
|
482
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
442
483
|
var defaultCopilotContextCategories = ["global"];
|
|
443
484
|
|
|
444
485
|
// src/hooks/use-copilot-chat.ts
|
|
@@ -464,21 +505,21 @@ function useCopilotChat(_a = {}) {
|
|
|
464
505
|
} = useCopilotContext();
|
|
465
506
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
466
507
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
467
|
-
const deleteMessage = (0,
|
|
508
|
+
const deleteMessage = (0, import_react7.useCallback)(
|
|
468
509
|
(messageId) => {
|
|
469
510
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
470
511
|
},
|
|
471
512
|
[setMessages]
|
|
472
513
|
);
|
|
473
|
-
const makeSystemMessageCallback = (0,
|
|
514
|
+
const makeSystemMessageCallback = (0, import_react7.useCallback)(() => {
|
|
474
515
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
475
516
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
476
|
-
return new
|
|
517
|
+
return new import_runtime_client_gql3.TextMessage({
|
|
477
518
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
478
|
-
role:
|
|
519
|
+
role: import_runtime_client_gql3.Role.System
|
|
479
520
|
});
|
|
480
521
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
481
|
-
const onCoAgentStateRender = (0,
|
|
522
|
+
const onCoAgentStateRender = (0, import_react7.useCallback)(
|
|
482
523
|
(args) => __async(this, null, function* () {
|
|
483
524
|
var _a2;
|
|
484
525
|
const { name, nodeName, state } = args;
|
|
@@ -513,29 +554,29 @@ function useCopilotChat(_a = {}) {
|
|
|
513
554
|
setAgentSession
|
|
514
555
|
}));
|
|
515
556
|
const latestAppend = useUpdatedRef(append);
|
|
516
|
-
const latestAppendFunc = (0,
|
|
557
|
+
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
517
558
|
(message) => {
|
|
518
559
|
return latestAppend.current(message);
|
|
519
560
|
},
|
|
520
561
|
[latestAppend]
|
|
521
562
|
);
|
|
522
563
|
const latestReload = useUpdatedRef(reload);
|
|
523
|
-
const latestReloadFunc = (0,
|
|
564
|
+
const latestReloadFunc = (0, import_react7.useCallback)(() => {
|
|
524
565
|
return latestReload.current();
|
|
525
566
|
}, [latestReload]);
|
|
526
567
|
const latestStop = useUpdatedRef(stop);
|
|
527
|
-
const latestStopFunc = (0,
|
|
568
|
+
const latestStopFunc = (0, import_react7.useCallback)(() => {
|
|
528
569
|
return latestStop.current();
|
|
529
570
|
}, [latestStop]);
|
|
530
571
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
531
|
-
const latestDeleteFunc = (0,
|
|
572
|
+
const latestDeleteFunc = (0, import_react7.useCallback)(
|
|
532
573
|
(messageId) => {
|
|
533
574
|
return latestDelete.current(messageId);
|
|
534
575
|
},
|
|
535
576
|
[latestDelete]
|
|
536
577
|
);
|
|
537
578
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
538
|
-
const latestSetMessagesFunc = (0,
|
|
579
|
+
const latestSetMessagesFunc = (0, import_react7.useCallback)(
|
|
539
580
|
(messages2) => {
|
|
540
581
|
return latestSetMessages.current(messages2);
|
|
541
582
|
},
|
|
@@ -552,8 +593,8 @@ function useCopilotChat(_a = {}) {
|
|
|
552
593
|
};
|
|
553
594
|
}
|
|
554
595
|
function useUpdatedRef(value) {
|
|
555
|
-
const ref = (0,
|
|
556
|
-
(0,
|
|
596
|
+
const ref = (0, import_react7.useRef)(value);
|
|
597
|
+
(0, import_react7.useEffect)(() => {
|
|
557
598
|
ref.current = value;
|
|
558
599
|
}, [value]);
|
|
559
600
|
return ref;
|
|
@@ -584,11 +625,11 @@ ${additionalInstructions}` : "");
|
|
|
584
625
|
|
|
585
626
|
// src/hooks/use-copilot-action.ts
|
|
586
627
|
var import_shared3 = require("@copilotkit/shared");
|
|
587
|
-
var
|
|
628
|
+
var import_react8 = require("react");
|
|
588
629
|
function useCopilotAction(action, dependencies) {
|
|
589
630
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
590
|
-
const idRef = (0,
|
|
591
|
-
const renderAndWaitRef = (0,
|
|
631
|
+
const idRef = (0, import_react8.useRef)((0, import_shared3.randomId)());
|
|
632
|
+
const renderAndWaitRef = (0, import_react8.useRef)(null);
|
|
592
633
|
action = __spreadValues({}, action);
|
|
593
634
|
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
594
635
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
@@ -623,7 +664,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
623
664
|
return renderAndWait(waitProps);
|
|
624
665
|
}
|
|
625
666
|
}
|
|
626
|
-
return (0,
|
|
667
|
+
return (0, import_react8.createElement)(import_react8.Fragment);
|
|
627
668
|
};
|
|
628
669
|
}
|
|
629
670
|
if (dependencies === void 0) {
|
|
@@ -636,7 +677,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
636
677
|
}
|
|
637
678
|
}
|
|
638
679
|
}
|
|
639
|
-
(0,
|
|
680
|
+
(0, import_react8.useEffect)(() => {
|
|
640
681
|
setAction(idRef.current, action);
|
|
641
682
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
642
683
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -662,7 +703,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
662
703
|
}
|
|
663
704
|
|
|
664
705
|
// src/hooks/use-coagent-state-render.ts
|
|
665
|
-
var
|
|
706
|
+
var import_react9 = require("react");
|
|
666
707
|
var import_shared4 = require("@copilotkit/shared");
|
|
667
708
|
function useCoAgentStateRender(action, dependencies) {
|
|
668
709
|
const {
|
|
@@ -670,8 +711,8 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
670
711
|
removeCoAgentStateRender,
|
|
671
712
|
coAgentStateRenders,
|
|
672
713
|
chatComponentsCache
|
|
673
|
-
} = (0,
|
|
674
|
-
const idRef = (0,
|
|
714
|
+
} = (0, import_react9.useContext)(CopilotContext);
|
|
715
|
+
const idRef = (0, import_react9.useRef)((0, import_shared4.randomId)());
|
|
675
716
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
676
717
|
if (dependencies === void 0) {
|
|
677
718
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -683,7 +724,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
683
724
|
}
|
|
684
725
|
}
|
|
685
726
|
}
|
|
686
|
-
(0,
|
|
727
|
+
(0, import_react9.useEffect)(() => {
|
|
687
728
|
setCoAgentStateRender(idRef.current, action);
|
|
688
729
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
689
730
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -703,11 +744,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
703
744
|
}
|
|
704
745
|
|
|
705
746
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
706
|
-
var
|
|
747
|
+
var import_react10 = require("react");
|
|
707
748
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
708
749
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
709
|
-
const idRef = (0,
|
|
710
|
-
(0,
|
|
750
|
+
const idRef = (0, import_react10.useRef)();
|
|
751
|
+
(0, import_react10.useEffect)(() => {
|
|
711
752
|
const id = addDocumentContext(document, categories);
|
|
712
753
|
idRef.current = id;
|
|
713
754
|
return () => {
|
|
@@ -718,16 +759,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
718
759
|
}
|
|
719
760
|
|
|
720
761
|
// src/hooks/use-copilot-readable.ts
|
|
721
|
-
var
|
|
762
|
+
var import_react11 = require("react");
|
|
722
763
|
function convertToJSON(description, value) {
|
|
723
764
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
724
765
|
}
|
|
725
766
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
726
767
|
const { addContext, removeContext } = useCopilotContext();
|
|
727
|
-
const idRef = (0,
|
|
768
|
+
const idRef = (0, import_react11.useRef)();
|
|
728
769
|
convert = convert || convertToJSON;
|
|
729
770
|
const information = convert(description, value);
|
|
730
|
-
(0,
|
|
771
|
+
(0, import_react11.useEffect)(() => {
|
|
731
772
|
const id = addContext(information, parentId, categories);
|
|
732
773
|
idRef.current = id;
|
|
733
774
|
return () => {
|
|
@@ -738,7 +779,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
738
779
|
}
|
|
739
780
|
|
|
740
781
|
// src/hooks/use-coagent.ts
|
|
741
|
-
var
|
|
782
|
+
var import_react12 = require("react");
|
|
742
783
|
function useCoAgent(options) {
|
|
743
784
|
const isExternalStateManagement = (options2) => {
|
|
744
785
|
return "state" in options2 && "setState" in options2;
|
|
@@ -780,7 +821,7 @@ function useCoAgent(options) {
|
|
|
780
821
|
};
|
|
781
822
|
const coagentState = getCoagentState(coagentStates, name);
|
|
782
823
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
783
|
-
(0,
|
|
824
|
+
(0, import_react12.useEffect)(() => {
|
|
784
825
|
if (isExternalStateManagement(options)) {
|
|
785
826
|
setState(options.state);
|
|
786
827
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -850,6 +891,7 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
850
891
|
useCopilotAction,
|
|
851
892
|
useCopilotChat,
|
|
852
893
|
useCopilotReadable,
|
|
894
|
+
useCopilotRuntimeClient,
|
|
853
895
|
useMakeCopilotDocumentReadable
|
|
854
896
|
});
|
|
855
897
|
//# sourceMappingURL=index.js.map
|