@copilotkit/react-core 1.4.1-pre.2 → 1.4.1-pre.6
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 +45 -3
- package/dist/chunk-2KCEHGSI.mjs +192 -0
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-MX2OYLRS.mjs → chunk-DT52QX4H.mjs} +4 -4
- package/dist/{chunk-TRXKPXDE.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-G2K6T2QU.mjs → chunk-JDQCJCAQ.mjs} +38 -11
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/chunk-L34MHAXR.mjs +1 -0
- package/dist/{chunk-7DFHFZJT.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/chunk-LMFSB5D5.mjs.map +1 -0
- 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-7LKXEJXM.mjs → chunk-MWZO6TUR.mjs} +3 -2
- package/dist/chunk-MWZO6TUR.mjs.map +1 -0
- 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-K4HZL7SA.mjs → chunk-V22C3DOQ.mjs} +3 -3
- package/dist/{chunk-27IPQFJP.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/chunk-XINZBP3J.mjs.map +1 -0
- 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 +118 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -12
- package/dist/hooks/use-chat.js +78 -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.d.ts +1 -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 +96 -43
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -7
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +2 -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 +98 -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 +513 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -19
- package/dist/lib/copilot-task.d.ts +2 -5
- 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/types/frontend-action.d.ts +8 -1
- package/dist/types/frontend-action.js.map +1 -1
- 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 +36 -12
- package/src/hooks/use-coagent-state-render.ts +1 -1
- package/src/hooks/use-copilot-action.ts +2 -1
- package/src/hooks/use-copilot-runtime-client.ts +24 -0
- package/src/lib/copilot-task.ts +1 -5
- package/src/types/frontend-action.ts +8 -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-27IPQFJP.mjs.map +0 -1
- package/dist/chunk-2MPUQRAY.mjs.map +0 -1
- package/dist/chunk-6YEMNWKE.mjs.map +0 -1
- package/dist/chunk-7DFHFZJT.mjs.map +0 -1
- package/dist/chunk-7LKXEJXM.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-G2K6T2QU.mjs.map +0 -1
- package/dist/chunk-JD7BAH7U.mjs +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-MX2OYLRS.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-ANOG3W5S.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-K4HZL7SA.mjs.map → chunk-V22C3DOQ.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,33 @@ 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
|
-
actions: actions.filter(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
251
|
+
actions: actions.filter(
|
|
252
|
+
(action) => action.available !== import_runtime_client_gql2.ActionInputAvailability.Disabled || !action.disabled
|
|
253
|
+
).map((action) => {
|
|
254
|
+
let available = import_runtime_client_gql2.ActionInputAvailability.Enabled;
|
|
255
|
+
if (action.disabled) {
|
|
256
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
257
|
+
} else if (action.available === "disabled") {
|
|
258
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Disabled;
|
|
259
|
+
} else if (action.available === "remote") {
|
|
260
|
+
available = import_runtime_client_gql2.ActionInputAvailability.Remote;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
name: action.name,
|
|
264
|
+
description: action.description || "",
|
|
265
|
+
jsonSchema: JSON.stringify((0, import_shared.actionParametersToJsonSchema)(action.parameters || [])),
|
|
266
|
+
available
|
|
267
|
+
};
|
|
268
|
+
}),
|
|
222
269
|
url: window.location.href
|
|
223
270
|
},
|
|
224
271
|
threadId: threadIdRef.current,
|
|
225
272
|
runId: runIdRef.current,
|
|
226
|
-
messages: (0,
|
|
273
|
+
messages: (0, import_runtime_client_gql2.convertMessagesToGqlInput)((0, import_runtime_client_gql2.filterAgentStateMessages)(messagesWithContext))
|
|
227
274
|
}, copilotConfig.cloud ? {
|
|
228
275
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
229
276
|
guardrails: {
|
|
@@ -235,7 +282,7 @@ function useChat(options) {
|
|
|
235
282
|
} : {})
|
|
236
283
|
} : {}), {
|
|
237
284
|
metadata: {
|
|
238
|
-
requestType:
|
|
285
|
+
requestType: import_runtime_client_gql2.CopilotRequestType.Chat
|
|
239
286
|
}
|
|
240
287
|
}), agentSessionRef.current ? {
|
|
241
288
|
agentSession: agentSessionRef.current
|
|
@@ -256,7 +303,14 @@ function useChat(options) {
|
|
|
256
303
|
let followUp = void 0;
|
|
257
304
|
try {
|
|
258
305
|
while (true) {
|
|
259
|
-
|
|
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
|
+
}
|
|
260
314
|
if (done) {
|
|
261
315
|
break;
|
|
262
316
|
}
|
|
@@ -265,8 +319,8 @@ function useChat(options) {
|
|
|
265
319
|
}
|
|
266
320
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
267
321
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
268
|
-
const messages2 = (0,
|
|
269
|
-
(0,
|
|
322
|
+
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
323
|
+
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
270
324
|
);
|
|
271
325
|
if (messages2.length === 0) {
|
|
272
326
|
continue;
|
|
@@ -274,15 +328,15 @@ function useChat(options) {
|
|
|
274
328
|
newMessages = [];
|
|
275
329
|
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
276
330
|
newMessages = [
|
|
277
|
-
new
|
|
278
|
-
role:
|
|
331
|
+
new import_runtime_client_gql2.TextMessage({
|
|
332
|
+
role: import_runtime_client_gql2.MessageRole.Assistant,
|
|
279
333
|
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
280
334
|
})
|
|
281
335
|
];
|
|
282
336
|
} else {
|
|
283
337
|
for (const message of messages2) {
|
|
284
338
|
newMessages.push(message);
|
|
285
|
-
if (message.isActionExecutionMessage() && message.status.code !==
|
|
339
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql2.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
286
340
|
if (!(message.id in actionResults)) {
|
|
287
341
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
288
342
|
break;
|
|
@@ -305,8 +359,8 @@ function useChat(options) {
|
|
|
305
359
|
}
|
|
306
360
|
}
|
|
307
361
|
newMessages.push(
|
|
308
|
-
new
|
|
309
|
-
result:
|
|
362
|
+
new import_runtime_client_gql2.ResultMessage({
|
|
363
|
+
result: import_runtime_client_gql2.ResultMessage.encodeResult(actionResults[message.id]),
|
|
310
364
|
actionExecutionId: message.id,
|
|
311
365
|
actionName: message.name
|
|
312
366
|
})
|
|
@@ -403,19 +457,19 @@ function useChat(options) {
|
|
|
403
457
|
}
|
|
404
458
|
|
|
405
459
|
// src/components/copilot-provider/copilotkit.tsx
|
|
406
|
-
var
|
|
460
|
+
var import_react6 = require("react");
|
|
407
461
|
var import_react_dom = require("react-dom");
|
|
408
462
|
var import_shared2 = require("@copilotkit/shared");
|
|
409
463
|
|
|
410
464
|
// src/context/copilot-messages-context.tsx
|
|
411
|
-
var
|
|
465
|
+
var import_react5 = __toESM(require("react"));
|
|
412
466
|
var emptyCopilotContext2 = {
|
|
413
467
|
messages: [],
|
|
414
468
|
setMessages: () => []
|
|
415
469
|
};
|
|
416
|
-
var CopilotMessagesContext =
|
|
470
|
+
var CopilotMessagesContext = import_react5.default.createContext(emptyCopilotContext2);
|
|
417
471
|
function useCopilotMessagesContext() {
|
|
418
|
-
const context =
|
|
472
|
+
const context = import_react5.default.useContext(CopilotMessagesContext);
|
|
419
473
|
if (context === emptyCopilotContext2) {
|
|
420
474
|
throw new Error(
|
|
421
475
|
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
@@ -425,7 +479,7 @@ function useCopilotMessagesContext() {
|
|
|
425
479
|
}
|
|
426
480
|
|
|
427
481
|
// src/components/copilot-provider/copilotkit.tsx
|
|
428
|
-
var
|
|
482
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
429
483
|
var defaultCopilotContextCategories = ["global"];
|
|
430
484
|
|
|
431
485
|
// src/hooks/use-copilot-chat.ts
|
|
@@ -451,21 +505,21 @@ function useCopilotChat(_a = {}) {
|
|
|
451
505
|
} = useCopilotContext();
|
|
452
506
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
453
507
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
454
|
-
const deleteMessage = (0,
|
|
508
|
+
const deleteMessage = (0, import_react7.useCallback)(
|
|
455
509
|
(messageId) => {
|
|
456
510
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
457
511
|
},
|
|
458
512
|
[setMessages]
|
|
459
513
|
);
|
|
460
|
-
const makeSystemMessageCallback = (0,
|
|
514
|
+
const makeSystemMessageCallback = (0, import_react7.useCallback)(() => {
|
|
461
515
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
462
516
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
463
|
-
return new
|
|
517
|
+
return new import_runtime_client_gql3.TextMessage({
|
|
464
518
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
465
|
-
role:
|
|
519
|
+
role: import_runtime_client_gql3.Role.System
|
|
466
520
|
});
|
|
467
521
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
468
|
-
const onCoAgentStateRender = (0,
|
|
522
|
+
const onCoAgentStateRender = (0, import_react7.useCallback)(
|
|
469
523
|
(args) => __async(this, null, function* () {
|
|
470
524
|
var _a2;
|
|
471
525
|
const { name, nodeName, state } = args;
|
|
@@ -500,29 +554,29 @@ function useCopilotChat(_a = {}) {
|
|
|
500
554
|
setAgentSession
|
|
501
555
|
}));
|
|
502
556
|
const latestAppend = useUpdatedRef(append);
|
|
503
|
-
const latestAppendFunc = (0,
|
|
557
|
+
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
504
558
|
(message) => {
|
|
505
559
|
return latestAppend.current(message);
|
|
506
560
|
},
|
|
507
561
|
[latestAppend]
|
|
508
562
|
);
|
|
509
563
|
const latestReload = useUpdatedRef(reload);
|
|
510
|
-
const latestReloadFunc = (0,
|
|
564
|
+
const latestReloadFunc = (0, import_react7.useCallback)(() => {
|
|
511
565
|
return latestReload.current();
|
|
512
566
|
}, [latestReload]);
|
|
513
567
|
const latestStop = useUpdatedRef(stop);
|
|
514
|
-
const latestStopFunc = (0,
|
|
568
|
+
const latestStopFunc = (0, import_react7.useCallback)(() => {
|
|
515
569
|
return latestStop.current();
|
|
516
570
|
}, [latestStop]);
|
|
517
571
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
518
|
-
const latestDeleteFunc = (0,
|
|
572
|
+
const latestDeleteFunc = (0, import_react7.useCallback)(
|
|
519
573
|
(messageId) => {
|
|
520
574
|
return latestDelete.current(messageId);
|
|
521
575
|
},
|
|
522
576
|
[latestDelete]
|
|
523
577
|
);
|
|
524
578
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
525
|
-
const latestSetMessagesFunc = (0,
|
|
579
|
+
const latestSetMessagesFunc = (0, import_react7.useCallback)(
|
|
526
580
|
(messages2) => {
|
|
527
581
|
return latestSetMessages.current(messages2);
|
|
528
582
|
},
|
|
@@ -539,8 +593,8 @@ function useCopilotChat(_a = {}) {
|
|
|
539
593
|
};
|
|
540
594
|
}
|
|
541
595
|
function useUpdatedRef(value) {
|
|
542
|
-
const ref = (0,
|
|
543
|
-
(0,
|
|
596
|
+
const ref = (0, import_react7.useRef)(value);
|
|
597
|
+
(0, import_react7.useEffect)(() => {
|
|
544
598
|
ref.current = value;
|
|
545
599
|
}, [value]);
|
|
546
600
|
return ref;
|
|
@@ -571,11 +625,11 @@ ${additionalInstructions}` : "");
|
|
|
571
625
|
|
|
572
626
|
// src/hooks/use-copilot-action.ts
|
|
573
627
|
var import_shared3 = require("@copilotkit/shared");
|
|
574
|
-
var
|
|
628
|
+
var import_react8 = require("react");
|
|
575
629
|
function useCopilotAction(action, dependencies) {
|
|
576
630
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
577
|
-
const idRef = (0,
|
|
578
|
-
const renderAndWaitRef = (0,
|
|
631
|
+
const idRef = (0, import_react8.useRef)((0, import_shared3.randomId)());
|
|
632
|
+
const renderAndWaitRef = (0, import_react8.useRef)(null);
|
|
579
633
|
action = __spreadValues({}, action);
|
|
580
634
|
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
581
635
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
@@ -610,7 +664,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
610
664
|
return renderAndWait(waitProps);
|
|
611
665
|
}
|
|
612
666
|
}
|
|
613
|
-
return (0,
|
|
667
|
+
return (0, import_react8.createElement)(import_react8.Fragment);
|
|
614
668
|
};
|
|
615
669
|
}
|
|
616
670
|
if (dependencies === void 0) {
|
|
@@ -623,7 +677,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
623
677
|
}
|
|
624
678
|
}
|
|
625
679
|
}
|
|
626
|
-
(0,
|
|
680
|
+
(0, import_react8.useEffect)(() => {
|
|
627
681
|
setAction(idRef.current, action);
|
|
628
682
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
629
683
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -637,6 +691,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
637
691
|
action.description,
|
|
638
692
|
action.name,
|
|
639
693
|
action.disabled,
|
|
694
|
+
action.available,
|
|
640
695
|
// This should be faster than deep equality checking
|
|
641
696
|
// In addition, all major JS engines guarantee the order of object keys
|
|
642
697
|
JSON.stringify(action.parameters),
|
|
@@ -648,7 +703,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
648
703
|
}
|
|
649
704
|
|
|
650
705
|
// src/hooks/use-coagent-state-render.ts
|
|
651
|
-
var
|
|
706
|
+
var import_react9 = require("react");
|
|
652
707
|
var import_shared4 = require("@copilotkit/shared");
|
|
653
708
|
function useCoAgentStateRender(action, dependencies) {
|
|
654
709
|
const {
|
|
@@ -656,8 +711,8 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
656
711
|
removeCoAgentStateRender,
|
|
657
712
|
coAgentStateRenders,
|
|
658
713
|
chatComponentsCache
|
|
659
|
-
} = (0,
|
|
660
|
-
const idRef = (0,
|
|
714
|
+
} = (0, import_react9.useContext)(CopilotContext);
|
|
715
|
+
const idRef = (0, import_react9.useRef)((0, import_shared4.randomId)());
|
|
661
716
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
662
717
|
if (dependencies === void 0) {
|
|
663
718
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -669,7 +724,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
669
724
|
}
|
|
670
725
|
}
|
|
671
726
|
}
|
|
672
|
-
(0,
|
|
727
|
+
(0, import_react9.useEffect)(() => {
|
|
673
728
|
setCoAgentStateRender(idRef.current, action);
|
|
674
729
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
675
730
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -689,11 +744,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
689
744
|
}
|
|
690
745
|
|
|
691
746
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
692
|
-
var
|
|
747
|
+
var import_react10 = require("react");
|
|
693
748
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
694
749
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
695
|
-
const idRef = (0,
|
|
696
|
-
(0,
|
|
750
|
+
const idRef = (0, import_react10.useRef)();
|
|
751
|
+
(0, import_react10.useEffect)(() => {
|
|
697
752
|
const id = addDocumentContext(document, categories);
|
|
698
753
|
idRef.current = id;
|
|
699
754
|
return () => {
|
|
@@ -704,16 +759,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
704
759
|
}
|
|
705
760
|
|
|
706
761
|
// src/hooks/use-copilot-readable.ts
|
|
707
|
-
var
|
|
762
|
+
var import_react11 = require("react");
|
|
708
763
|
function convertToJSON(description, value) {
|
|
709
764
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
710
765
|
}
|
|
711
766
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
712
767
|
const { addContext, removeContext } = useCopilotContext();
|
|
713
|
-
const idRef = (0,
|
|
768
|
+
const idRef = (0, import_react11.useRef)();
|
|
714
769
|
convert = convert || convertToJSON;
|
|
715
770
|
const information = convert(description, value);
|
|
716
|
-
(0,
|
|
771
|
+
(0, import_react11.useEffect)(() => {
|
|
717
772
|
const id = addContext(information, parentId, categories);
|
|
718
773
|
idRef.current = id;
|
|
719
774
|
return () => {
|
|
@@ -724,7 +779,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
724
779
|
}
|
|
725
780
|
|
|
726
781
|
// src/hooks/use-coagent.ts
|
|
727
|
-
var
|
|
782
|
+
var import_react12 = require("react");
|
|
728
783
|
function useCoAgent(options) {
|
|
729
784
|
const isExternalStateManagement = (options2) => {
|
|
730
785
|
return "state" in options2 && "setState" in options2;
|
|
@@ -766,7 +821,7 @@ function useCoAgent(options) {
|
|
|
766
821
|
};
|
|
767
822
|
const coagentState = getCoagentState(coagentStates, name);
|
|
768
823
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
769
|
-
(0,
|
|
824
|
+
(0, import_react12.useEffect)(() => {
|
|
770
825
|
if (isExternalStateManagement(options)) {
|
|
771
826
|
setState(options.state);
|
|
772
827
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -836,6 +891,7 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
836
891
|
useCopilotAction,
|
|
837
892
|
useCopilotChat,
|
|
838
893
|
useCopilotReadable,
|
|
894
|
+
useCopilotRuntimeClient,
|
|
839
895
|
useMakeCopilotDocumentReadable
|
|
840
896
|
});
|
|
841
897
|
//# sourceMappingURL=index.js.map
|