@copilotkit/react-core 1.4.1-pre.6 → 1.4.2-tyler-reset-chat.0
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 +57 -0
- package/dist/{chunk-LODRWFMB.mjs → chunk-2JP64U3A.mjs} +10 -2
- package/dist/{chunk-LODRWFMB.mjs.map → chunk-2JP64U3A.mjs.map} +1 -1
- package/dist/{chunk-XINZBP3J.mjs → chunk-3AYELZJS.mjs} +2 -2
- package/dist/{chunk-MWZO6TUR.mjs → chunk-3R4J2TPH.mjs} +2 -2
- package/dist/{chunk-JDQCJCAQ.mjs → chunk-6EN7J4V2.mjs} +37 -15
- package/dist/chunk-6EN7J4V2.mjs.map +1 -0
- package/dist/{chunk-P6VS7ST4.mjs → chunk-6QKA3SNN.mjs} +12 -3
- package/dist/{chunk-P6VS7ST4.mjs.map → chunk-6QKA3SNN.mjs.map} +1 -1
- package/dist/{chunk-DT52QX4H.mjs → chunk-CZMEZR6F.mjs} +36 -6
- package/dist/chunk-CZMEZR6F.mjs.map +1 -0
- package/dist/{chunk-LMFSB5D5.mjs → chunk-JR55I3FL.mjs} +2 -2
- package/dist/{chunk-V22C3DOQ.mjs → chunk-SEPYQHH7.mjs} +23 -5
- package/dist/{chunk-V22C3DOQ.mjs.map → chunk-SEPYQHH7.mjs.map} +1 -1
- package/dist/{chunk-QDGDXRRJ.mjs → chunk-USL3EHJB.mjs} +2 -2
- package/dist/{chunk-H4VZMKR6.mjs → chunk-XUPO37VH.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +19 -2
- 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 +19 -2
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +19 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +6 -0
- package/dist/context/copilot-context.js +9 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +9 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +99 -18
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +15 -9
- package/dist/hooks/use-chat.d.ts +20 -0
- package/dist/hooks/use-chat.js +36 -14
- 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 +9 -1
- 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 +14 -1
- package/dist/hooks/use-coagent.js +99 -18
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +11 -5
- package/dist/hooks/use-copilot-action.js +9 -1
- 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 -0
- package/dist/hooks/use-copilot-chat.js +77 -17
- 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 +9 -1
- 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 +9 -1
- 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 +109 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -10
- 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 +10 -0
- package/src/context/copilot-context.tsx +22 -0
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +56 -13
- package/src/hooks/use-coagent.ts +21 -4
- package/src/hooks/use-copilot-chat.ts +36 -3
- package/dist/chunk-DT52QX4H.mjs.map +0 -1
- package/dist/chunk-JDQCJCAQ.mjs.map +0 -1
- /package/dist/{chunk-XINZBP3J.mjs.map → chunk-3AYELZJS.mjs.map} +0 -0
- /package/dist/{chunk-MWZO6TUR.mjs.map → chunk-3R4J2TPH.mjs.map} +0 -0
- /package/dist/{chunk-LMFSB5D5.mjs.map → chunk-JR55I3FL.mjs.map} +0 -0
- /package/dist/{chunk-QDGDXRRJ.mjs.map → chunk-USL3EHJB.mjs.map} +0 -0
- /package/dist/{chunk-H4VZMKR6.mjs.map → chunk-XUPO37VH.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 { 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;
|
|
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 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkC;;;ACElC,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,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;;;ADzNO,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 { useCoAgent } from './hooks/use-coagent.js';
|
|
11
|
+
export { HintFunction, runAgent, startAgent, stopAgent, 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,7 +87,10 @@ __export(src_exports, {
|
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
88
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
89
|
extract: () => extract,
|
|
90
|
+
runAgent: () => runAgent,
|
|
90
91
|
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
92
|
+
startAgent: () => startAgent,
|
|
93
|
+
stopAgent: () => stopAgent,
|
|
91
94
|
useCoAgent: () => useCoAgent,
|
|
92
95
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
93
96
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -154,7 +157,15 @@ var emptyCopilotContext = {
|
|
|
154
157
|
},
|
|
155
158
|
agentSession: null,
|
|
156
159
|
setAgentSession: () => {
|
|
157
|
-
}
|
|
160
|
+
},
|
|
161
|
+
agentLock: null,
|
|
162
|
+
threadId: null,
|
|
163
|
+
setThreadId: () => {
|
|
164
|
+
},
|
|
165
|
+
runId: null,
|
|
166
|
+
setRunId: () => {
|
|
167
|
+
},
|
|
168
|
+
chatAbortControllerRef: { current: null }
|
|
158
169
|
};
|
|
159
170
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
160
171
|
function useCopilotContext() {
|
|
@@ -953,6 +964,9 @@ ${nonDocumentStrings}`;
|
|
|
953
964
|
};
|
|
954
965
|
}
|
|
955
966
|
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);
|
|
956
970
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
957
971
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
958
972
|
CopilotContext.Provider,
|
|
@@ -985,7 +999,13 @@ ${nonDocumentStrings}`;
|
|
|
985
999
|
setCoagentStates,
|
|
986
1000
|
agentSession,
|
|
987
1001
|
setAgentSession,
|
|
988
|
-
runtimeClient
|
|
1002
|
+
runtimeClient,
|
|
1003
|
+
agentLock: props.agent || null,
|
|
1004
|
+
threadId,
|
|
1005
|
+
setThreadId,
|
|
1006
|
+
runId,
|
|
1007
|
+
setRunId,
|
|
1008
|
+
chatAbortControllerRef
|
|
989
1009
|
},
|
|
990
1010
|
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
991
1011
|
}
|
|
@@ -1041,17 +1061,25 @@ function useChat(options) {
|
|
|
1041
1061
|
setCoagentStates,
|
|
1042
1062
|
coagentStates,
|
|
1043
1063
|
agentSession,
|
|
1044
|
-
setAgentSession
|
|
1064
|
+
setAgentSession,
|
|
1065
|
+
threadId,
|
|
1066
|
+
setThreadId,
|
|
1067
|
+
runId,
|
|
1068
|
+
setRunId,
|
|
1069
|
+
chatAbortControllerRef
|
|
1045
1070
|
} = options;
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
const runIdRef = (0, import_react9.useRef)(null);
|
|
1071
|
+
const abortController = new AbortController();
|
|
1072
|
+
chatAbortControllerRef.current = abortController;
|
|
1049
1073
|
const { addGraphQLErrorsToast } = useToast();
|
|
1050
1074
|
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1051
1075
|
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
1052
1076
|
coagentStatesRef.current = coagentStates;
|
|
1053
1077
|
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1054
1078
|
agentSessionRef.current = agentSession;
|
|
1079
|
+
const threadIdRef = (0, import_react9.useRef)(threadId);
|
|
1080
|
+
threadIdRef.current = threadId;
|
|
1081
|
+
const runIdRef = (0, import_react9.useRef)(runId);
|
|
1082
|
+
runIdRef.current = runId;
|
|
1055
1083
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1056
1084
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1057
1085
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -1069,8 +1097,7 @@ function useChat(options) {
|
|
|
1069
1097
|
role: import_runtime_client_gql4.Role.Assistant
|
|
1070
1098
|
})
|
|
1071
1099
|
];
|
|
1072
|
-
|
|
1073
|
-
abortControllerRef.current = abortController;
|
|
1100
|
+
chatAbortControllerRef.current = new AbortController();
|
|
1074
1101
|
setMessages([...previousMessages, ...newMessages]);
|
|
1075
1102
|
const systemMessage = makeSystemMessageCallback();
|
|
1076
1103
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -1123,7 +1150,7 @@ function useChat(options) {
|
|
|
1123
1150
|
}))
|
|
1124
1151
|
}),
|
|
1125
1152
|
properties: copilotConfig.properties,
|
|
1126
|
-
signal: (_d =
|
|
1153
|
+
signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
|
|
1127
1154
|
})
|
|
1128
1155
|
);
|
|
1129
1156
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
@@ -1142,6 +1169,9 @@ function useChat(options) {
|
|
|
1142
1169
|
break;
|
|
1143
1170
|
}
|
|
1144
1171
|
if (done) {
|
|
1172
|
+
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1173
|
+
return newMessages.slice();
|
|
1174
|
+
}
|
|
1145
1175
|
break;
|
|
1146
1176
|
}
|
|
1147
1177
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -1149,6 +1179,8 @@ function useChat(options) {
|
|
|
1149
1179
|
}
|
|
1150
1180
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1151
1181
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1182
|
+
setThreadId(threadIdRef.current);
|
|
1183
|
+
setRunId(runIdRef.current);
|
|
1152
1184
|
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1153
1185
|
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1154
1186
|
);
|
|
@@ -1177,12 +1209,22 @@ function useChat(options) {
|
|
|
1177
1209
|
if (action) {
|
|
1178
1210
|
followUp = action.followUp;
|
|
1179
1211
|
}
|
|
1180
|
-
const result = yield
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1212
|
+
const result = yield Promise.race([
|
|
1213
|
+
onFunctionCall({
|
|
1214
|
+
messages: previousMessages,
|
|
1215
|
+
name: message.name,
|
|
1216
|
+
args: message.arguments
|
|
1217
|
+
}),
|
|
1218
|
+
new Promise((_, reject) => {
|
|
1219
|
+
var _a2;
|
|
1220
|
+
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
1221
|
+
})
|
|
1222
|
+
]);
|
|
1223
|
+
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1224
|
+
actionResults[message.id] = "";
|
|
1225
|
+
} else {
|
|
1226
|
+
actionResults[message.id] = result;
|
|
1227
|
+
}
|
|
1186
1228
|
} catch (e) {
|
|
1187
1229
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
1188
1230
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -1277,7 +1319,7 @@ function useChat(options) {
|
|
|
1277
1319
|
});
|
|
1278
1320
|
const stop = () => {
|
|
1279
1321
|
var _a;
|
|
1280
|
-
(_a =
|
|
1322
|
+
(_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
|
|
1281
1323
|
};
|
|
1282
1324
|
return {
|
|
1283
1325
|
append,
|
|
@@ -1305,7 +1347,13 @@ function useCopilotChat(_a = {}) {
|
|
|
1305
1347
|
setCoagentStates,
|
|
1306
1348
|
coAgentStateRenders,
|
|
1307
1349
|
agentSession,
|
|
1308
|
-
setAgentSession
|
|
1350
|
+
setAgentSession,
|
|
1351
|
+
agentLock,
|
|
1352
|
+
threadId,
|
|
1353
|
+
setThreadId,
|
|
1354
|
+
runId,
|
|
1355
|
+
setRunId,
|
|
1356
|
+
chatAbortControllerRef
|
|
1309
1357
|
} = useCopilotContext();
|
|
1310
1358
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1311
1359
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -1355,7 +1403,12 @@ function useCopilotChat(_a = {}) {
|
|
|
1355
1403
|
coagentStates,
|
|
1356
1404
|
setCoagentStates,
|
|
1357
1405
|
agentSession,
|
|
1358
|
-
setAgentSession
|
|
1406
|
+
setAgentSession,
|
|
1407
|
+
threadId,
|
|
1408
|
+
setThreadId,
|
|
1409
|
+
runId,
|
|
1410
|
+
setRunId,
|
|
1411
|
+
chatAbortControllerRef
|
|
1359
1412
|
}));
|
|
1360
1413
|
const latestAppend = useUpdatedRef(append);
|
|
1361
1414
|
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
@@ -1386,12 +1439,31 @@ function useCopilotChat(_a = {}) {
|
|
|
1386
1439
|
},
|
|
1387
1440
|
[latestSetMessages]
|
|
1388
1441
|
);
|
|
1442
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
1443
|
+
latestStopFunc();
|
|
1444
|
+
setMessages([]);
|
|
1445
|
+
setThreadId(null);
|
|
1446
|
+
setRunId(null);
|
|
1447
|
+
setCoagentStates({});
|
|
1448
|
+
let initialAgentSession = null;
|
|
1449
|
+
if (agentLock) {
|
|
1450
|
+
initialAgentSession = {
|
|
1451
|
+
agentName: agentLock
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
setAgentSession(initialAgentSession);
|
|
1455
|
+
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
1456
|
+
const latestReset = useUpdatedRef(reset);
|
|
1457
|
+
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1458
|
+
return latestReset.current();
|
|
1459
|
+
}, [latestReset]);
|
|
1389
1460
|
return {
|
|
1390
1461
|
visibleMessages: messages,
|
|
1391
1462
|
appendMessage: latestAppendFunc,
|
|
1392
1463
|
setMessages: latestSetMessagesFunc,
|
|
1393
1464
|
reloadMessages: latestReloadFunc,
|
|
1394
1465
|
stopGeneration: latestStopFunc,
|
|
1466
|
+
reset: latestResetFunc,
|
|
1395
1467
|
deleteMessage: latestDeleteFunc,
|
|
1396
1468
|
isLoading
|
|
1397
1469
|
};
|
|
@@ -1631,7 +1703,11 @@ function useCoAgent(options) {
|
|
|
1631
1703
|
} else if (coagentStates[name] === void 0) {
|
|
1632
1704
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1633
1705
|
}
|
|
1634
|
-
}, [
|
|
1706
|
+
}, [
|
|
1707
|
+
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1708
|
+
// reset initialstate on reset
|
|
1709
|
+
coagentStates === void 0
|
|
1710
|
+
]);
|
|
1635
1711
|
return {
|
|
1636
1712
|
name,
|
|
1637
1713
|
nodeName: coagentState.nodeName,
|
|
@@ -1659,6 +1735,17 @@ function stopAgent(name, context) {
|
|
|
1659
1735
|
const { agentSession, setAgentSession } = context;
|
|
1660
1736
|
if (agentSession && agentSession.agentName === name) {
|
|
1661
1737
|
setAgentSession(null);
|
|
1738
|
+
context.setCoagentStates((prevAgentStates) => {
|
|
1739
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1740
|
+
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
1741
|
+
running: false,
|
|
1742
|
+
active: false,
|
|
1743
|
+
threadId: void 0,
|
|
1744
|
+
nodeName: void 0,
|
|
1745
|
+
runId: void 0
|
|
1746
|
+
})
|
|
1747
|
+
});
|
|
1748
|
+
});
|
|
1662
1749
|
} else {
|
|
1663
1750
|
console.warn(`No agent session found for ${name}`);
|
|
1664
1751
|
}
|
|
@@ -1796,7 +1883,10 @@ ${instructions}
|
|
|
1796
1883
|
CopilotTask,
|
|
1797
1884
|
defaultCopilotContextCategories,
|
|
1798
1885
|
extract,
|
|
1886
|
+
runAgent,
|
|
1799
1887
|
shouldShowDevConsole,
|
|
1888
|
+
startAgent,
|
|
1889
|
+
stopAgent,
|
|
1800
1890
|
useCoAgent,
|
|
1801
1891
|
useCoAgentStateRender,
|
|
1802
1892
|
useCopilotAction,
|