@copilotkit/react-core 1.4.2-tyler-reset-chat.1 → 1.4.2
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 +5 -13
- package/dist/{chunk-4Z7QCC6V.mjs → chunk-A5ZAEL2W.mjs} +22 -33
- package/dist/chunk-A5ZAEL2W.mjs.map +1 -0
- package/dist/{chunk-RGZ6GR2B.mjs → chunk-BUWNIMNK.mjs} +12 -37
- package/dist/chunk-BUWNIMNK.mjs.map +1 -0
- package/dist/{chunk-XUPO37VH.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-HECZOHST.mjs → chunk-HZIY4NDC.mjs} +17 -36
- package/dist/chunk-HZIY4NDC.mjs.map +1 -0
- package/dist/{chunk-JR55I3FL.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/{chunk-2JP64U3A.mjs → chunk-LODRWFMB.mjs} +2 -10
- package/dist/{chunk-2JP64U3A.mjs.map → chunk-LODRWFMB.mjs.map} +1 -1
- package/dist/{chunk-3R4J2TPH.mjs → chunk-MWZO6TUR.mjs} +2 -2
- package/dist/{chunk-6QKA3SNN.mjs → chunk-P6VS7ST4.mjs} +3 -12
- package/dist/{chunk-6QKA3SNN.mjs.map → chunk-P6VS7ST4.mjs.map} +1 -1
- package/dist/{chunk-USL3EHJB.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-3AYELZJS.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +2 -19
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +2 -19
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +2 -19
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +0 -6
- package/dist/context/copilot-context.js +1 -9
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +1 -9
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +43 -109
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +9 -15
- package/dist/hooks/use-chat.d.ts +4 -20
- package/dist/hooks/use-chat.js +16 -35
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.js +1 -9
- 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.d.ts +1 -14
- package/dist/hooks/use-coagent.js +43 -109
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +5 -11
- package/dist/hooks/use-copilot-action.js +1 -9
- 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.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +25 -77
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -4
- package/dist/hooks/use-copilot-readable.js +1 -9
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -9
- 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 +1 -1
- package/dist/index.js +44 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -16
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +3 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +2 -2
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +0 -10
- package/src/context/copilot-context.tsx +0 -22
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +21 -53
- package/src/hooks/use-coagent.ts +26 -35
- package/src/hooks/use-copilot-chat.ts +10 -37
- package/dist/chunk-4Z7QCC6V.mjs.map +0 -1
- package/dist/chunk-HECZOHST.mjs.map +0 -1
- package/dist/chunk-RGZ6GR2B.mjs.map +0 -1
- /package/dist/{chunk-XUPO37VH.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-JR55I3FL.mjs.map → chunk-LMFSB5D5.mjs.map} +0 -0
- /package/dist/{chunk-3R4J2TPH.mjs.map → chunk-MWZO6TUR.mjs.map} +0 -0
- /package/dist/{chunk-USL3EHJB.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-3AYELZJS.mjs.map → chunk-XINZBP3J.mjs.map} +0 -0
|
@@ -104,15 +104,7 @@ var emptyCopilotContext = {
|
|
|
104
104
|
},
|
|
105
105
|
agentSession: null,
|
|
106
106
|
setAgentSession: () => {
|
|
107
|
-
}
|
|
108
|
-
agentLock: null,
|
|
109
|
-
threadId: null,
|
|
110
|
-
setThreadId: () => {
|
|
111
|
-
},
|
|
112
|
-
runId: null,
|
|
113
|
-
setRunId: () => {
|
|
114
|
-
},
|
|
115
|
-
chatAbortControllerRef: { current: null }
|
|
107
|
+
}
|
|
116
108
|
};
|
|
117
109
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
118
110
|
function useCopilotContext() {
|
|
@@ -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\";\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
|
|
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
|
@@ -108,15 +108,7 @@ var emptyCopilotContext = {
|
|
|
108
108
|
},
|
|
109
109
|
agentSession: null,
|
|
110
110
|
setAgentSession: () => {
|
|
111
|
-
}
|
|
112
|
-
agentLock: null,
|
|
113
|
-
threadId: null,
|
|
114
|
-
setThreadId: () => {
|
|
115
|
-
},
|
|
116
|
-
runId: null,
|
|
117
|
-
setRunId: () => {
|
|
118
|
-
},
|
|
119
|
-
chatAbortControllerRef: { current: null }
|
|
111
|
+
}
|
|
120
112
|
};
|
|
121
113
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
122
114
|
function useCopilotContext() {
|
|
@@ -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\";\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 agentLock: string | null;\n\n threadId: string | null;\n setThreadId: React.Dispatch<React.SetStateAction<string | null>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | 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 agentLock: null,\n\n threadId: null,\n setThreadId: () => {},\n\n runId: null,\n setRunId: () => {},\n\n chatAbortControllerRef: { current: null },\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;AAuJlB,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;AAAA,EAExB,WAAW;AAAA,EAEX,UAAU;AAAA,EACV,aAAa,MAAM;AAAA,EAAC;AAAA,EAEpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EAEjB,wBAAwB,EAAE,SAAS,KAAK;AAC1C;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;;;AC/NA,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"]}
|
|
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
|
@@ -4,7 +4,7 @@ export { useCoAgentStateRender } from './use-coagent-state-render.js';
|
|
|
4
4
|
export { useMakeCopilotDocumentReadable } from './use-make-copilot-document-readable.js';
|
|
5
5
|
export { UseChatHelpers } from './use-chat.js';
|
|
6
6
|
export { useCopilotReadable } from './use-copilot-readable.js';
|
|
7
|
-
export {
|
|
7
|
+
export { useCoAgent } from './use-coagent.js';
|
|
8
8
|
export { useCopilotRuntimeClient } from './use-copilot-runtime-client.js';
|
|
9
9
|
import '@copilotkit/runtime-client-gql';
|
|
10
10
|
import '../types/system-message.js';
|
|
@@ -17,4 +17,3 @@ import '../context/copilot-context.js';
|
|
|
17
17
|
import './use-tree.js';
|
|
18
18
|
import '../types/chat-suggestion-configuration.js';
|
|
19
19
|
import '../types/coagent-state.js';
|
|
20
|
-
import '../context/copilot-messages-context.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -79,9 +79,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
79
79
|
// src/hooks/index.ts
|
|
80
80
|
var hooks_exports = {};
|
|
81
81
|
__export(hooks_exports, {
|
|
82
|
-
runAgent: () => runAgent,
|
|
83
|
-
startAgent: () => startAgent,
|
|
84
|
-
stopAgent: () => stopAgent,
|
|
85
82
|
useCoAgent: () => useCoAgent,
|
|
86
83
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
87
84
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -146,15 +143,7 @@ var emptyCopilotContext = {
|
|
|
146
143
|
},
|
|
147
144
|
agentSession: null,
|
|
148
145
|
setAgentSession: () => {
|
|
149
|
-
}
|
|
150
|
-
agentLock: null,
|
|
151
|
-
threadId: null,
|
|
152
|
-
setThreadId: () => {
|
|
153
|
-
},
|
|
154
|
-
runId: null,
|
|
155
|
-
setRunId: () => {
|
|
156
|
-
},
|
|
157
|
-
chatAbortControllerRef: { current: null }
|
|
146
|
+
}
|
|
158
147
|
};
|
|
159
148
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
160
149
|
function useCopilotContext() {
|
|
@@ -222,23 +211,17 @@ function useChat(options) {
|
|
|
222
211
|
setCoagentStates,
|
|
223
212
|
coagentStates,
|
|
224
213
|
agentSession,
|
|
225
|
-
setAgentSession
|
|
226
|
-
threadId,
|
|
227
|
-
setThreadId,
|
|
228
|
-
runId,
|
|
229
|
-
setRunId,
|
|
230
|
-
chatAbortControllerRef
|
|
214
|
+
setAgentSession
|
|
231
215
|
} = options;
|
|
216
|
+
const abortControllerRef = (0, import_react4.useRef)();
|
|
217
|
+
const threadIdRef = (0, import_react4.useRef)(null);
|
|
218
|
+
const runIdRef = (0, import_react4.useRef)(null);
|
|
232
219
|
const { addGraphQLErrorsToast } = useToast();
|
|
233
220
|
const runChatCompletionRef = (0, import_react4.useRef)();
|
|
234
221
|
const coagentStatesRef = (0, import_react4.useRef)(coagentStates);
|
|
235
222
|
coagentStatesRef.current = coagentStates;
|
|
236
223
|
const agentSessionRef = (0, import_react4.useRef)(agentSession);
|
|
237
224
|
agentSessionRef.current = agentSession;
|
|
238
|
-
const threadIdRef = (0, import_react4.useRef)(threadId);
|
|
239
|
-
threadIdRef.current = threadId;
|
|
240
|
-
const runIdRef = (0, import_react4.useRef)(runId);
|
|
241
|
-
runIdRef.current = runId;
|
|
242
225
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
243
226
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
244
227
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -256,7 +239,8 @@ function useChat(options) {
|
|
|
256
239
|
role: import_runtime_client_gql2.Role.Assistant
|
|
257
240
|
})
|
|
258
241
|
];
|
|
259
|
-
|
|
242
|
+
const abortController = new AbortController();
|
|
243
|
+
abortControllerRef.current = abortController;
|
|
260
244
|
setMessages([...previousMessages, ...newMessages]);
|
|
261
245
|
const systemMessage = makeSystemMessageCallback();
|
|
262
246
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -309,7 +293,7 @@ function useChat(options) {
|
|
|
309
293
|
}))
|
|
310
294
|
}),
|
|
311
295
|
properties: copilotConfig.properties,
|
|
312
|
-
signal: (_d =
|
|
296
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
313
297
|
})
|
|
314
298
|
);
|
|
315
299
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
@@ -328,9 +312,6 @@ function useChat(options) {
|
|
|
328
312
|
break;
|
|
329
313
|
}
|
|
330
314
|
if (done) {
|
|
331
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
332
|
-
return newMessages.slice();
|
|
333
|
-
}
|
|
334
315
|
break;
|
|
335
316
|
}
|
|
336
317
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -338,8 +319,6 @@ function useChat(options) {
|
|
|
338
319
|
}
|
|
339
320
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
340
321
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
341
|
-
setThreadId(threadIdRef.current);
|
|
342
|
-
setRunId(runIdRef.current);
|
|
343
322
|
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
344
323
|
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
345
324
|
);
|
|
@@ -368,22 +347,12 @@ function useChat(options) {
|
|
|
368
347
|
if (action) {
|
|
369
348
|
followUp = action.followUp;
|
|
370
349
|
}
|
|
371
|
-
const result = yield
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
new Promise((_, reject) => {
|
|
378
|
-
var _a2;
|
|
379
|
-
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
380
|
-
})
|
|
381
|
-
]);
|
|
382
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
383
|
-
actionResults[message.id] = "";
|
|
384
|
-
} else {
|
|
385
|
-
actionResults[message.id] = result;
|
|
386
|
-
}
|
|
350
|
+
const result = yield onFunctionCall({
|
|
351
|
+
messages: previousMessages,
|
|
352
|
+
name: message.name,
|
|
353
|
+
args: message.arguments
|
|
354
|
+
});
|
|
355
|
+
actionResults[message.id] = result;
|
|
387
356
|
} catch (e) {
|
|
388
357
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
389
358
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -478,12 +447,13 @@ function useChat(options) {
|
|
|
478
447
|
});
|
|
479
448
|
const stop = () => {
|
|
480
449
|
var _a;
|
|
481
|
-
(_a =
|
|
450
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
482
451
|
};
|
|
483
452
|
return {
|
|
484
453
|
append,
|
|
485
454
|
reload,
|
|
486
|
-
stop
|
|
455
|
+
stop,
|
|
456
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
487
457
|
};
|
|
488
458
|
}
|
|
489
459
|
|
|
@@ -532,13 +502,7 @@ function useCopilotChat(_a = {}) {
|
|
|
532
502
|
setCoagentStates,
|
|
533
503
|
coAgentStateRenders,
|
|
534
504
|
agentSession,
|
|
535
|
-
setAgentSession
|
|
536
|
-
agentLock,
|
|
537
|
-
threadId,
|
|
538
|
-
setThreadId,
|
|
539
|
-
runId,
|
|
540
|
-
setRunId,
|
|
541
|
-
chatAbortControllerRef
|
|
505
|
+
setAgentSession
|
|
542
506
|
} = useCopilotContext();
|
|
543
507
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
544
508
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -574,7 +538,7 @@ function useCopilotChat(_a = {}) {
|
|
|
574
538
|
}),
|
|
575
539
|
[coAgentStateRenders]
|
|
576
540
|
);
|
|
577
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
541
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
578
542
|
actions: Object.values(actions),
|
|
579
543
|
copilotConfig: copilotApiConfig,
|
|
580
544
|
initialMessages: options.initialMessages || [],
|
|
@@ -588,12 +552,7 @@ function useCopilotChat(_a = {}) {
|
|
|
588
552
|
coagentStates,
|
|
589
553
|
setCoagentStates,
|
|
590
554
|
agentSession,
|
|
591
|
-
setAgentSession
|
|
592
|
-
threadId,
|
|
593
|
-
setThreadId,
|
|
594
|
-
runId,
|
|
595
|
-
setRunId,
|
|
596
|
-
chatAbortControllerRef
|
|
555
|
+
setAgentSession
|
|
597
556
|
}));
|
|
598
557
|
const latestAppend = useUpdatedRef(append);
|
|
599
558
|
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
@@ -624,32 +583,18 @@ function useCopilotChat(_a = {}) {
|
|
|
624
583
|
},
|
|
625
584
|
[latestSetMessages]
|
|
626
585
|
);
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
setRunId(null);
|
|
632
|
-
setCoagentStates({});
|
|
633
|
-
let initialAgentSession = null;
|
|
634
|
-
if (agentLock) {
|
|
635
|
-
initialAgentSession = {
|
|
636
|
-
agentName: agentLock
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
setAgentSession(initialAgentSession);
|
|
640
|
-
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
641
|
-
const latestReset = useUpdatedRef(reset);
|
|
642
|
-
const latestResetFunc = (0, import_react7.useCallback)(() => {
|
|
643
|
-
return latestReset.current();
|
|
644
|
-
}, [latestReset]);
|
|
586
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
587
|
+
const latestRunChatCompletionFunc = (0, import_react7.useCallback)(() => {
|
|
588
|
+
return latestRunChatCompletion.current();
|
|
589
|
+
}, [latestRunChatCompletion]);
|
|
645
590
|
return {
|
|
646
591
|
visibleMessages: messages,
|
|
647
592
|
appendMessage: latestAppendFunc,
|
|
648
593
|
setMessages: latestSetMessagesFunc,
|
|
649
594
|
reloadMessages: latestReloadFunc,
|
|
650
595
|
stopGeneration: latestStopFunc,
|
|
651
|
-
reset: latestResetFunc,
|
|
652
596
|
deleteMessage: latestDeleteFunc,
|
|
597
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
653
598
|
isLoading
|
|
654
599
|
};
|
|
655
600
|
}
|
|
@@ -841,6 +786,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
841
786
|
|
|
842
787
|
// src/hooks/use-coagent.ts
|
|
843
788
|
var import_react12 = require("react");
|
|
789
|
+
var import_react_dom2 = require("react-dom");
|
|
844
790
|
function useCoAgent(options) {
|
|
845
791
|
const isExternalStateManagement = (options2) => {
|
|
846
792
|
return "state" in options2 && "setState" in options2;
|
|
@@ -853,7 +799,7 @@ function useCoAgent(options) {
|
|
|
853
799
|
const messagesContext = useCopilotMessagesContext();
|
|
854
800
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
855
801
|
const { coagentStates, setCoagentStates } = context;
|
|
856
|
-
const { appendMessage } = useCopilotChat();
|
|
802
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
857
803
|
const getCoagentState = (coagentStates2, name2) => {
|
|
858
804
|
if (coagentStates2[name2]) {
|
|
859
805
|
return coagentStates2[name2];
|
|
@@ -870,13 +816,15 @@ function useCoAgent(options) {
|
|
|
870
816
|
}
|
|
871
817
|
};
|
|
872
818
|
const setState = (newState) => {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
819
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
820
|
+
setCoagentStates((prevAgentStates) => {
|
|
821
|
+
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
822
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
823
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
824
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
825
|
+
state: updatedState
|
|
826
|
+
})
|
|
827
|
+
});
|
|
880
828
|
});
|
|
881
829
|
});
|
|
882
830
|
};
|
|
@@ -888,11 +836,7 @@ function useCoAgent(options) {
|
|
|
888
836
|
} else if (coagentStates[name] === void 0) {
|
|
889
837
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
890
838
|
}
|
|
891
|
-
}, [
|
|
892
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
893
|
-
// reset initialstate on reset
|
|
894
|
-
coagentStates[name] === void 0
|
|
895
|
-
]);
|
|
839
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
896
840
|
return {
|
|
897
841
|
name,
|
|
898
842
|
nodeName: coagentState.nodeName,
|
|
@@ -906,7 +850,7 @@ function useCoAgent(options) {
|
|
|
906
850
|
stopAgent(name, context);
|
|
907
851
|
},
|
|
908
852
|
run: (hint) => {
|
|
909
|
-
return runAgent(name, context, appendMessage, hint);
|
|
853
|
+
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
910
854
|
}
|
|
911
855
|
};
|
|
912
856
|
}
|
|
@@ -920,22 +864,11 @@ function stopAgent(name, context) {
|
|
|
920
864
|
const { agentSession, setAgentSession } = context;
|
|
921
865
|
if (agentSession && agentSession.agentName === name) {
|
|
922
866
|
setAgentSession(null);
|
|
923
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
924
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
925
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
926
|
-
running: false,
|
|
927
|
-
active: false,
|
|
928
|
-
threadId: void 0,
|
|
929
|
-
nodeName: void 0,
|
|
930
|
-
runId: void 0
|
|
931
|
-
})
|
|
932
|
-
});
|
|
933
|
-
});
|
|
934
867
|
} else {
|
|
935
868
|
console.warn(`No agent session found for ${name}`);
|
|
936
869
|
}
|
|
937
870
|
}
|
|
938
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
871
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
939
872
|
return __async(this, null, function* () {
|
|
940
873
|
var _a, _b;
|
|
941
874
|
const { agentSession, setAgentSession } = context;
|
|
@@ -956,15 +889,16 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
956
889
|
const hintMessage = hint({ previousState, currentState: state });
|
|
957
890
|
if (hintMessage) {
|
|
958
891
|
yield appendMessage(hintMessage);
|
|
892
|
+
} else {
|
|
893
|
+
yield runChatCompletion();
|
|
959
894
|
}
|
|
895
|
+
} else {
|
|
896
|
+
yield runChatCompletion();
|
|
960
897
|
}
|
|
961
898
|
});
|
|
962
899
|
}
|
|
963
900
|
// Annotate the CommonJS export names for ESM import in node:
|
|
964
901
|
0 && (module.exports = {
|
|
965
|
-
runAgent,
|
|
966
|
-
startAgent,
|
|
967
|
-
stopAgent,
|
|
968
902
|
useCoAgent,
|
|
969
903
|
useCoAgentStateRender,
|
|
970
904
|
useCopilotAction,
|