@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
|
@@ -106,15 +106,7 @@ var emptyCopilotContext = {
|
|
|
106
106
|
},
|
|
107
107
|
agentSession: null,
|
|
108
108
|
setAgentSession: () => {
|
|
109
|
-
}
|
|
110
|
-
agentLock: null,
|
|
111
|
-
threadId: null,
|
|
112
|
-
setThreadId: () => {
|
|
113
|
-
},
|
|
114
|
-
runId: null,
|
|
115
|
-
setRunId: () => {
|
|
116
|
-
},
|
|
117
|
-
chatAbortControllerRef: { current: null }
|
|
109
|
+
}
|
|
118
110
|
};
|
|
119
111
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
120
112
|
function useCopilotContext() {
|
|
@@ -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 { 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/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 { 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,IAAAA,gBAAkC;;;ACElC,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,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;;;ADnMO,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
|
@@ -8,7 +8,7 @@ export { useCoAgentStateRender } from './hooks/use-coagent-state-render.js';
|
|
|
8
8
|
export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
|
|
9
9
|
export { UseChatHelpers } from './hooks/use-chat.js';
|
|
10
10
|
export { useCopilotReadable } from './hooks/use-copilot-readable.js';
|
|
11
|
-
export {
|
|
11
|
+
export { useCoAgent } from './hooks/use-coagent.js';
|
|
12
12
|
export { useCopilotRuntimeClient } from './hooks/use-copilot-runtime-client.js';
|
|
13
13
|
export { DocumentPointer } from './types/document-pointer.js';
|
|
14
14
|
export { SystemMessageFunction } from './types/system-message.js';
|
package/dist/index.js
CHANGED
|
@@ -87,10 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
88
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
89
|
extract: () => extract,
|
|
90
|
-
runAgent: () => runAgent,
|
|
91
90
|
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
92
|
-
startAgent: () => startAgent,
|
|
93
|
-
stopAgent: () => stopAgent,
|
|
94
91
|
useCoAgent: () => useCoAgent,
|
|
95
92
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
96
93
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -157,15 +154,7 @@ var emptyCopilotContext = {
|
|
|
157
154
|
},
|
|
158
155
|
agentSession: null,
|
|
159
156
|
setAgentSession: () => {
|
|
160
|
-
}
|
|
161
|
-
agentLock: null,
|
|
162
|
-
threadId: null,
|
|
163
|
-
setThreadId: () => {
|
|
164
|
-
},
|
|
165
|
-
runId: null,
|
|
166
|
-
setRunId: () => {
|
|
167
|
-
},
|
|
168
|
-
chatAbortControllerRef: { current: null }
|
|
157
|
+
}
|
|
169
158
|
};
|
|
170
159
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
171
160
|
function useCopilotContext() {
|
|
@@ -964,9 +953,6 @@ ${nonDocumentStrings}`;
|
|
|
964
953
|
};
|
|
965
954
|
}
|
|
966
955
|
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
967
|
-
const [threadId, setThreadId] = (0, import_react8.useState)(null);
|
|
968
|
-
const [runId, setRunId] = (0, import_react8.useState)(null);
|
|
969
|
-
const chatAbortControllerRef = (0, import_react8.useRef)(null);
|
|
970
956
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
971
957
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
972
958
|
CopilotContext.Provider,
|
|
@@ -999,13 +985,7 @@ ${nonDocumentStrings}`;
|
|
|
999
985
|
setCoagentStates,
|
|
1000
986
|
agentSession,
|
|
1001
987
|
setAgentSession,
|
|
1002
|
-
runtimeClient
|
|
1003
|
-
agentLock: props.agent || null,
|
|
1004
|
-
threadId,
|
|
1005
|
-
setThreadId,
|
|
1006
|
-
runId,
|
|
1007
|
-
setRunId,
|
|
1008
|
-
chatAbortControllerRef
|
|
988
|
+
runtimeClient
|
|
1009
989
|
},
|
|
1010
990
|
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
1011
991
|
}
|
|
@@ -1061,23 +1041,17 @@ function useChat(options) {
|
|
|
1061
1041
|
setCoagentStates,
|
|
1062
1042
|
coagentStates,
|
|
1063
1043
|
agentSession,
|
|
1064
|
-
setAgentSession
|
|
1065
|
-
threadId,
|
|
1066
|
-
setThreadId,
|
|
1067
|
-
runId,
|
|
1068
|
-
setRunId,
|
|
1069
|
-
chatAbortControllerRef
|
|
1044
|
+
setAgentSession
|
|
1070
1045
|
} = options;
|
|
1046
|
+
const abortControllerRef = (0, import_react9.useRef)();
|
|
1047
|
+
const threadIdRef = (0, import_react9.useRef)(null);
|
|
1048
|
+
const runIdRef = (0, import_react9.useRef)(null);
|
|
1071
1049
|
const { addGraphQLErrorsToast } = useToast();
|
|
1072
1050
|
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1073
1051
|
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
1074
1052
|
coagentStatesRef.current = coagentStates;
|
|
1075
1053
|
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1076
1054
|
agentSessionRef.current = agentSession;
|
|
1077
|
-
const threadIdRef = (0, import_react9.useRef)(threadId);
|
|
1078
|
-
threadIdRef.current = threadId;
|
|
1079
|
-
const runIdRef = (0, import_react9.useRef)(runId);
|
|
1080
|
-
runIdRef.current = runId;
|
|
1081
1055
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1082
1056
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1083
1057
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -1095,7 +1069,8 @@ function useChat(options) {
|
|
|
1095
1069
|
role: import_runtime_client_gql4.Role.Assistant
|
|
1096
1070
|
})
|
|
1097
1071
|
];
|
|
1098
|
-
|
|
1072
|
+
const abortController = new AbortController();
|
|
1073
|
+
abortControllerRef.current = abortController;
|
|
1099
1074
|
setMessages([...previousMessages, ...newMessages]);
|
|
1100
1075
|
const systemMessage = makeSystemMessageCallback();
|
|
1101
1076
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -1148,7 +1123,7 @@ function useChat(options) {
|
|
|
1148
1123
|
}))
|
|
1149
1124
|
}),
|
|
1150
1125
|
properties: copilotConfig.properties,
|
|
1151
|
-
signal: (_d =
|
|
1126
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
1152
1127
|
})
|
|
1153
1128
|
);
|
|
1154
1129
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
@@ -1167,9 +1142,6 @@ function useChat(options) {
|
|
|
1167
1142
|
break;
|
|
1168
1143
|
}
|
|
1169
1144
|
if (done) {
|
|
1170
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1171
|
-
return newMessages.slice();
|
|
1172
|
-
}
|
|
1173
1145
|
break;
|
|
1174
1146
|
}
|
|
1175
1147
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -1177,8 +1149,6 @@ function useChat(options) {
|
|
|
1177
1149
|
}
|
|
1178
1150
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1179
1151
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1180
|
-
setThreadId(threadIdRef.current);
|
|
1181
|
-
setRunId(runIdRef.current);
|
|
1182
1152
|
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1183
1153
|
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1184
1154
|
);
|
|
@@ -1207,22 +1177,12 @@ function useChat(options) {
|
|
|
1207
1177
|
if (action) {
|
|
1208
1178
|
followUp = action.followUp;
|
|
1209
1179
|
}
|
|
1210
|
-
const result = yield
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
new Promise((_, reject) => {
|
|
1217
|
-
var _a2;
|
|
1218
|
-
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
1219
|
-
})
|
|
1220
|
-
]);
|
|
1221
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1222
|
-
actionResults[message.id] = "";
|
|
1223
|
-
} else {
|
|
1224
|
-
actionResults[message.id] = result;
|
|
1225
|
-
}
|
|
1180
|
+
const result = yield onFunctionCall({
|
|
1181
|
+
messages: previousMessages,
|
|
1182
|
+
name: message.name,
|
|
1183
|
+
args: message.arguments
|
|
1184
|
+
});
|
|
1185
|
+
actionResults[message.id] = result;
|
|
1226
1186
|
} catch (e) {
|
|
1227
1187
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
1228
1188
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -1317,12 +1277,13 @@ function useChat(options) {
|
|
|
1317
1277
|
});
|
|
1318
1278
|
const stop = () => {
|
|
1319
1279
|
var _a;
|
|
1320
|
-
(_a =
|
|
1280
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1321
1281
|
};
|
|
1322
1282
|
return {
|
|
1323
1283
|
append,
|
|
1324
1284
|
reload,
|
|
1325
|
-
stop
|
|
1285
|
+
stop,
|
|
1286
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1326
1287
|
};
|
|
1327
1288
|
}
|
|
1328
1289
|
|
|
@@ -1345,13 +1306,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1345
1306
|
setCoagentStates,
|
|
1346
1307
|
coAgentStateRenders,
|
|
1347
1308
|
agentSession,
|
|
1348
|
-
setAgentSession
|
|
1349
|
-
agentLock,
|
|
1350
|
-
threadId,
|
|
1351
|
-
setThreadId,
|
|
1352
|
-
runId,
|
|
1353
|
-
setRunId,
|
|
1354
|
-
chatAbortControllerRef
|
|
1309
|
+
setAgentSession
|
|
1355
1310
|
} = useCopilotContext();
|
|
1356
1311
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1357
1312
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -1387,7 +1342,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1387
1342
|
}),
|
|
1388
1343
|
[coAgentStateRenders]
|
|
1389
1344
|
);
|
|
1390
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1345
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1391
1346
|
actions: Object.values(actions),
|
|
1392
1347
|
copilotConfig: copilotApiConfig,
|
|
1393
1348
|
initialMessages: options.initialMessages || [],
|
|
@@ -1401,12 +1356,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1401
1356
|
coagentStates,
|
|
1402
1357
|
setCoagentStates,
|
|
1403
1358
|
agentSession,
|
|
1404
|
-
setAgentSession
|
|
1405
|
-
threadId,
|
|
1406
|
-
setThreadId,
|
|
1407
|
-
runId,
|
|
1408
|
-
setRunId,
|
|
1409
|
-
chatAbortControllerRef
|
|
1359
|
+
setAgentSession
|
|
1410
1360
|
}));
|
|
1411
1361
|
const latestAppend = useUpdatedRef(append);
|
|
1412
1362
|
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
@@ -1437,32 +1387,18 @@ function useCopilotChat(_a = {}) {
|
|
|
1437
1387
|
},
|
|
1438
1388
|
[latestSetMessages]
|
|
1439
1389
|
);
|
|
1440
|
-
const
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
setRunId(null);
|
|
1445
|
-
setCoagentStates({});
|
|
1446
|
-
let initialAgentSession = null;
|
|
1447
|
-
if (agentLock) {
|
|
1448
|
-
initialAgentSession = {
|
|
1449
|
-
agentName: agentLock
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
setAgentSession(initialAgentSession);
|
|
1453
|
-
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
1454
|
-
const latestReset = useUpdatedRef(reset);
|
|
1455
|
-
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1456
|
-
return latestReset.current();
|
|
1457
|
-
}, [latestReset]);
|
|
1390
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
1391
|
+
const latestRunChatCompletionFunc = (0, import_react10.useCallback)(() => {
|
|
1392
|
+
return latestRunChatCompletion.current();
|
|
1393
|
+
}, [latestRunChatCompletion]);
|
|
1458
1394
|
return {
|
|
1459
1395
|
visibleMessages: messages,
|
|
1460
1396
|
appendMessage: latestAppendFunc,
|
|
1461
1397
|
setMessages: latestSetMessagesFunc,
|
|
1462
1398
|
reloadMessages: latestReloadFunc,
|
|
1463
1399
|
stopGeneration: latestStopFunc,
|
|
1464
|
-
reset: latestResetFunc,
|
|
1465
1400
|
deleteMessage: latestDeleteFunc,
|
|
1401
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
1466
1402
|
isLoading
|
|
1467
1403
|
};
|
|
1468
1404
|
}
|
|
@@ -1654,6 +1590,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1654
1590
|
|
|
1655
1591
|
// src/hooks/use-coagent.ts
|
|
1656
1592
|
var import_react15 = require("react");
|
|
1593
|
+
var import_react_dom2 = require("react-dom");
|
|
1657
1594
|
function useCoAgent(options) {
|
|
1658
1595
|
const isExternalStateManagement = (options2) => {
|
|
1659
1596
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1666,7 +1603,7 @@ function useCoAgent(options) {
|
|
|
1666
1603
|
const messagesContext = useCopilotMessagesContext();
|
|
1667
1604
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1668
1605
|
const { coagentStates, setCoagentStates } = context;
|
|
1669
|
-
const { appendMessage } = useCopilotChat();
|
|
1606
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1670
1607
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1671
1608
|
if (coagentStates2[name2]) {
|
|
1672
1609
|
return coagentStates2[name2];
|
|
@@ -1683,13 +1620,15 @@ function useCoAgent(options) {
|
|
|
1683
1620
|
}
|
|
1684
1621
|
};
|
|
1685
1622
|
const setState = (newState) => {
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1623
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
1624
|
+
setCoagentStates((prevAgentStates) => {
|
|
1625
|
+
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
1626
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1627
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1628
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1629
|
+
state: updatedState
|
|
1630
|
+
})
|
|
1631
|
+
});
|
|
1693
1632
|
});
|
|
1694
1633
|
});
|
|
1695
1634
|
};
|
|
@@ -1701,11 +1640,7 @@ function useCoAgent(options) {
|
|
|
1701
1640
|
} else if (coagentStates[name] === void 0) {
|
|
1702
1641
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1703
1642
|
}
|
|
1704
|
-
}, [
|
|
1705
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1706
|
-
// reset initialstate on reset
|
|
1707
|
-
coagentStates[name] === void 0
|
|
1708
|
-
]);
|
|
1643
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
1709
1644
|
return {
|
|
1710
1645
|
name,
|
|
1711
1646
|
nodeName: coagentState.nodeName,
|
|
@@ -1719,7 +1654,7 @@ function useCoAgent(options) {
|
|
|
1719
1654
|
stopAgent(name, context);
|
|
1720
1655
|
},
|
|
1721
1656
|
run: (hint) => {
|
|
1722
|
-
return runAgent(name, context, appendMessage, hint);
|
|
1657
|
+
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
1723
1658
|
}
|
|
1724
1659
|
};
|
|
1725
1660
|
}
|
|
@@ -1733,22 +1668,11 @@ function stopAgent(name, context) {
|
|
|
1733
1668
|
const { agentSession, setAgentSession } = context;
|
|
1734
1669
|
if (agentSession && agentSession.agentName === name) {
|
|
1735
1670
|
setAgentSession(null);
|
|
1736
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
1737
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1738
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
1739
|
-
running: false,
|
|
1740
|
-
active: false,
|
|
1741
|
-
threadId: void 0,
|
|
1742
|
-
nodeName: void 0,
|
|
1743
|
-
runId: void 0
|
|
1744
|
-
})
|
|
1745
|
-
});
|
|
1746
|
-
});
|
|
1747
1671
|
} else {
|
|
1748
1672
|
console.warn(`No agent session found for ${name}`);
|
|
1749
1673
|
}
|
|
1750
1674
|
}
|
|
1751
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
1675
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
1752
1676
|
return __async(this, null, function* () {
|
|
1753
1677
|
var _a, _b;
|
|
1754
1678
|
const { agentSession, setAgentSession } = context;
|
|
@@ -1769,7 +1693,11 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1769
1693
|
const hintMessage = hint({ previousState, currentState: state });
|
|
1770
1694
|
if (hintMessage) {
|
|
1771
1695
|
yield appendMessage(hintMessage);
|
|
1696
|
+
} else {
|
|
1697
|
+
yield runChatCompletion();
|
|
1772
1698
|
}
|
|
1699
|
+
} else {
|
|
1700
|
+
yield runChatCompletion();
|
|
1773
1701
|
}
|
|
1774
1702
|
});
|
|
1775
1703
|
}
|
|
@@ -1881,10 +1809,7 @@ ${instructions}
|
|
|
1881
1809
|
CopilotTask,
|
|
1882
1810
|
defaultCopilotContextCategories,
|
|
1883
1811
|
extract,
|
|
1884
|
-
runAgent,
|
|
1885
1812
|
shouldShowDevConsole,
|
|
1886
|
-
startAgent,
|
|
1887
|
-
stopAgent,
|
|
1888
1813
|
useCoAgent,
|
|
1889
1814
|
useCoAgentStateRender,
|
|
1890
1815
|
useCopilotAction,
|