@copilotkit/react-core 1.3.5 → 1.3.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 +11 -0
- package/dist/{chunk-OPUQWTF5.mjs → chunk-2Y3VMFJN.mjs} +10 -10
- package/dist/chunk-2Y3VMFJN.mjs.map +1 -0
- package/dist/{chunk-ZTZEKOR7.mjs → chunk-3CU2I4W2.mjs} +2 -2
- package/dist/{chunk-VWJ3BWCJ.mjs → chunk-4AF3YGMC.mjs} +5 -5
- package/dist/chunk-4AF3YGMC.mjs.map +1 -0
- package/dist/{chunk-LT5NO6O6.mjs → chunk-6VNO5DEJ.mjs} +6 -6
- package/dist/chunk-6VNO5DEJ.mjs.map +1 -0
- package/dist/{chunk-JE7SHBT3.mjs → chunk-ACK2DHWA.mjs} +18 -13
- package/dist/chunk-ACK2DHWA.mjs.map +1 -0
- package/dist/{chunk-CTATHNXD.mjs → chunk-IAS5FL4D.mjs} +2 -2
- package/dist/{chunk-W2GTFMIK.mjs → chunk-KK42A2OC.mjs} +3 -3
- package/dist/{chunk-VAAJZGFF.mjs → chunk-NTNOUYBQ.mjs} +2 -2
- package/dist/{chunk-LCRACIIO.mjs → chunk-QUCTZQ6X.mjs} +2 -2
- package/dist/{chunk-FTTFXKE4.mjs → chunk-UJWNB2I6.mjs} +2 -2
- package/dist/{chunk-PDJXYJ5N.mjs → chunk-VZ66ENV7.mjs} +12 -12
- package/dist/chunk-VZ66ENV7.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.js +14 -14
- 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 +14 -14
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +14 -14
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +6 -6
- package/dist/context/copilot-context.js +4 -4
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +4 -4
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +32 -27
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +11 -11
- package/dist/hooks/use-chat.d.ts +2 -2
- package/dist/hooks/use-chat.js +5 -5
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.d.ts +3 -3
- package/dist/hooks/use-coagent-state-render.js +21 -16
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +4 -4
- package/dist/hooks/use-coagent.js +15 -15
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +5 -5
- package/dist/hooks/use-copilot-action.js +4 -4
- 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 +15 -15
- 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 +4 -4
- 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 +4 -4
- 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 +42 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- 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/types/coagent-action.d.ts +6 -6
- package/dist/types/coagent-action.js.map +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +13 -11
- package/src/context/copilot-context.tsx +10 -10
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +8 -8
- package/src/hooks/use-coagent-state-render.ts +18 -14
- package/src/hooks/use-copilot-chat.ts +8 -8
- package/src/types/coagent-action.ts +5 -5
- package/dist/chunk-JE7SHBT3.mjs.map +0 -1
- package/dist/chunk-LT5NO6O6.mjs.map +0 -1
- package/dist/chunk-OPUQWTF5.mjs.map +0 -1
- package/dist/chunk-PDJXYJ5N.mjs.map +0 -1
- package/dist/chunk-VWJ3BWCJ.mjs.map +0 -1
- /package/dist/{chunk-ZTZEKOR7.mjs.map → chunk-3CU2I4W2.mjs.map} +0 -0
- /package/dist/{chunk-CTATHNXD.mjs.map → chunk-IAS5FL4D.mjs.map} +0 -0
- /package/dist/{chunk-W2GTFMIK.mjs.map → chunk-KK42A2OC.mjs.map} +0 -0
- /package/dist/{chunk-VAAJZGFF.mjs.map → chunk-NTNOUYBQ.mjs.map} +0 -0
- /package/dist/{chunk-LCRACIIO.mjs.map → chunk-QUCTZQ6X.mjs.map} +0 -0
- /package/dist/{chunk-FTTFXKE4.mjs.map → chunk-UJWNB2I6.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\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 {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\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 // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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,IAAAA,gBAAkC;;;ACGlC,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,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,EAE9B,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,aAAAC,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;;;ADtMO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,kBAAkB;AACxE,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":["import_react","React"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { CopilotKitProps } from './components/copilot-provider/copilotkit-props.
|
|
|
3
3
|
export { CoagentInChatRenderFunction, CopilotApiConfig, CopilotContext, CopilotContextParams, useCopilotContext } from './context/copilot-context.js';
|
|
4
4
|
export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
|
|
5
5
|
export { useCopilotAction } from './hooks/use-copilot-action.js';
|
|
6
|
-
export {
|
|
6
|
+
export { useCoAgentStateRender } from './hooks/use-coagent-state-render.js';
|
|
7
7
|
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
8
8
|
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
9
9
|
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
package/dist/index.js
CHANGED
|
@@ -87,7 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
88
88
|
extract: () => extract,
|
|
89
89
|
useCoAgent: () => useCoAgent,
|
|
90
|
-
|
|
90
|
+
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
91
91
|
useCopilotAction: () => useCopilotAction,
|
|
92
92
|
useCopilotChat: () => useCopilotChat,
|
|
93
93
|
useCopilotContext: () => useCopilotContext,
|
|
@@ -107,12 +107,12 @@ var emptyCopilotContext = {
|
|
|
107
107
|
},
|
|
108
108
|
removeAction: () => {
|
|
109
109
|
},
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
coAgentStateRenders: {},
|
|
111
|
+
setCoAgentStateRender: () => {
|
|
112
112
|
},
|
|
113
|
-
|
|
113
|
+
removeCoAgentStateRender: () => {
|
|
114
114
|
},
|
|
115
|
-
chatComponentsCache: { current: { actions: {},
|
|
115
|
+
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
116
116
|
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
117
117
|
addContext: () => "",
|
|
118
118
|
removeContext: () => {
|
|
@@ -379,10 +379,10 @@ function CopilotKit(_a) {
|
|
|
379
379
|
}
|
|
380
380
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
381
381
|
const [actions, setActions] = (0, import_react4.useState)({});
|
|
382
|
-
const [
|
|
382
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react4.useState)({});
|
|
383
383
|
const chatComponentsCache = (0, import_react4.useRef)({
|
|
384
384
|
actions: {},
|
|
385
|
-
|
|
385
|
+
coAgentStateRenders: {}
|
|
386
386
|
});
|
|
387
387
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
388
388
|
const [messages, setMessages] = (0, import_react4.useState)([]);
|
|
@@ -407,15 +407,15 @@ function CopilotKit(_a) {
|
|
|
407
407
|
return newPoints;
|
|
408
408
|
});
|
|
409
409
|
}, []);
|
|
410
|
-
const
|
|
411
|
-
|
|
410
|
+
const setCoAgentStateRender = (0, import_react4.useCallback)((id, stateRender) => {
|
|
411
|
+
setCoAgentStateRenders((prevPoints) => {
|
|
412
412
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
413
|
-
[id]:
|
|
413
|
+
[id]: stateRender
|
|
414
414
|
});
|
|
415
415
|
});
|
|
416
416
|
}, []);
|
|
417
|
-
const
|
|
418
|
-
|
|
417
|
+
const removeCoAgentStateRender = (0, import_react4.useCallback)((id) => {
|
|
418
|
+
setCoAgentStateRenders((prevPoints) => {
|
|
419
419
|
const newPoints = __spreadValues({}, prevPoints);
|
|
420
420
|
delete newPoints[id];
|
|
421
421
|
return newPoints;
|
|
@@ -528,9 +528,9 @@ ${nonDocumentStrings}`;
|
|
|
528
528
|
getFunctionCallHandler,
|
|
529
529
|
setAction,
|
|
530
530
|
removeAction,
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
531
|
+
coAgentStateRenders,
|
|
532
|
+
setCoAgentStateRender,
|
|
533
|
+
removeCoAgentStateRender,
|
|
534
534
|
getContextString,
|
|
535
535
|
addContext,
|
|
536
536
|
removeContext,
|
|
@@ -603,7 +603,7 @@ function useChat(options) {
|
|
|
603
603
|
isLoading,
|
|
604
604
|
actions,
|
|
605
605
|
onFunctionCall,
|
|
606
|
-
|
|
606
|
+
onCoAgentStateRender,
|
|
607
607
|
setCoagentStates,
|
|
608
608
|
coagentStates,
|
|
609
609
|
agentSession,
|
|
@@ -681,7 +681,7 @@ function useChat(options) {
|
|
|
681
681
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
682
682
|
const reader = stream.getReader();
|
|
683
683
|
let actionResults = {};
|
|
684
|
-
let
|
|
684
|
+
let executedCoAgentStateRenders = [];
|
|
685
685
|
let followUp = void 0;
|
|
686
686
|
try {
|
|
687
687
|
while (true) {
|
|
@@ -741,16 +741,16 @@ function useChat(options) {
|
|
|
741
741
|
})
|
|
742
742
|
);
|
|
743
743
|
}
|
|
744
|
-
if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !
|
|
744
|
+
if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
745
745
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
746
746
|
break;
|
|
747
747
|
}
|
|
748
|
-
yield
|
|
748
|
+
yield onCoAgentStateRender({
|
|
749
749
|
name: message.agentName,
|
|
750
750
|
nodeName: message.nodeName,
|
|
751
751
|
state: message.state
|
|
752
752
|
});
|
|
753
|
-
|
|
753
|
+
executedCoAgentStateRenders.push(message.id);
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
756
|
const lastAgentStateMessage = [...messages2].reverse().find((message) => message instanceof import_runtime_client_gql.AgentStateMessage);
|
|
@@ -850,7 +850,7 @@ function useCopilotChat(_a = {}) {
|
|
|
850
850
|
actions,
|
|
851
851
|
coagentStates,
|
|
852
852
|
setCoagentStates,
|
|
853
|
-
|
|
853
|
+
coAgentStateRenders,
|
|
854
854
|
agentSession,
|
|
855
855
|
setAgentSession
|
|
856
856
|
} = useCopilotContext();
|
|
@@ -869,15 +869,15 @@ function useCopilotChat(_a = {}) {
|
|
|
869
869
|
role: import_runtime_client_gql2.Role.System
|
|
870
870
|
});
|
|
871
871
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
872
|
-
const
|
|
872
|
+
const onCoAgentStateRender = (0, import_react6.useCallback)(
|
|
873
873
|
(args) => __async(this, null, function* () {
|
|
874
874
|
var _a2;
|
|
875
875
|
const { name, nodeName, state } = args;
|
|
876
|
-
let action = Object.values(
|
|
876
|
+
let action = Object.values(coAgentStateRenders).find(
|
|
877
877
|
(action2) => action2.name === name && action2.nodeName === nodeName
|
|
878
878
|
);
|
|
879
879
|
if (!action) {
|
|
880
|
-
action = Object.values(
|
|
880
|
+
action = Object.values(coAgentStateRenders).find(
|
|
881
881
|
(action2) => action2.name === name && !action2.nodeName
|
|
882
882
|
);
|
|
883
883
|
}
|
|
@@ -885,14 +885,14 @@ function useCopilotChat(_a = {}) {
|
|
|
885
885
|
yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
|
|
886
886
|
}
|
|
887
887
|
}),
|
|
888
|
-
[
|
|
888
|
+
[coAgentStateRenders]
|
|
889
889
|
);
|
|
890
890
|
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
891
891
|
actions: Object.values(actions),
|
|
892
892
|
copilotConfig: copilotApiConfig,
|
|
893
893
|
initialMessages: options.initialMessages || [],
|
|
894
894
|
onFunctionCall: getFunctionCallHandler(),
|
|
895
|
-
|
|
895
|
+
onCoAgentStateRender,
|
|
896
896
|
messages,
|
|
897
897
|
setMessages,
|
|
898
898
|
makeSystemMessageCallback,
|
|
@@ -1041,31 +1041,36 @@ function useCopilotAction(action, dependencies) {
|
|
|
1041
1041
|
// src/hooks/use-coagent-state-render.ts
|
|
1042
1042
|
var import_react8 = require("react");
|
|
1043
1043
|
var import_shared6 = require("@copilotkit/shared");
|
|
1044
|
-
function
|
|
1045
|
-
const {
|
|
1044
|
+
function useCoAgentStateRender(action, dependencies) {
|
|
1045
|
+
const {
|
|
1046
|
+
setCoAgentStateRender,
|
|
1047
|
+
removeCoAgentStateRender,
|
|
1048
|
+
coAgentStateRenders,
|
|
1049
|
+
chatComponentsCache
|
|
1050
|
+
} = (0, import_react8.useContext)(CopilotContext);
|
|
1046
1051
|
const idRef = (0, import_react8.useRef)((0, import_shared6.randomId)());
|
|
1047
1052
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1048
1053
|
if (dependencies === void 0) {
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1054
|
+
if (coAgentStateRenders[idRef.current]) {
|
|
1055
|
+
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
1051
1056
|
if (typeof action.render === "function") {
|
|
1052
1057
|
if (chatComponentsCache.current !== null) {
|
|
1053
|
-
chatComponentsCache.current.
|
|
1058
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1054
1059
|
}
|
|
1055
1060
|
}
|
|
1056
1061
|
}
|
|
1057
1062
|
}
|
|
1058
1063
|
(0, import_react8.useEffect)(() => {
|
|
1059
|
-
|
|
1064
|
+
setCoAgentStateRender(idRef.current, action);
|
|
1060
1065
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1061
|
-
chatComponentsCache.current.
|
|
1066
|
+
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1062
1067
|
}
|
|
1063
1068
|
return () => {
|
|
1064
|
-
|
|
1069
|
+
removeCoAgentStateRender(idRef.current);
|
|
1065
1070
|
};
|
|
1066
1071
|
}, [
|
|
1067
|
-
|
|
1068
|
-
|
|
1072
|
+
setCoAgentStateRender,
|
|
1073
|
+
removeCoAgentStateRender,
|
|
1069
1074
|
action.name,
|
|
1070
1075
|
// include render only if it's a string
|
|
1071
1076
|
typeof action.render === "string" ? action.render : void 0,
|
|
@@ -1455,7 +1460,7 @@ Any additional messages provided are for providing context only and should not b
|
|
|
1455
1460
|
defaultCopilotContextCategories,
|
|
1456
1461
|
extract,
|
|
1457
1462
|
useCoAgent,
|
|
1458
|
-
|
|
1463
|
+
useCoAgentStateRender,
|
|
1459
1464
|
useCopilotAction,
|
|
1460
1465
|
useCopilotChat,
|
|
1461
1466
|
useCopilotContext,
|