@copilotkit/react-core 1.4.1 → 1.4.2-tyler-reset-chat.1

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-LODRWFMB.mjs → chunk-2JP64U3A.mjs} +10 -2
  3. package/dist/{chunk-LODRWFMB.mjs.map → chunk-2JP64U3A.mjs.map} +1 -1
  4. package/dist/{chunk-XINZBP3J.mjs → chunk-3AYELZJS.mjs} +2 -2
  5. package/dist/{chunk-MWZO6TUR.mjs → chunk-3R4J2TPH.mjs} +2 -2
  6. package/dist/{chunk-V22C3DOQ.mjs → chunk-4Z7QCC6V.mjs} +23 -5
  7. package/dist/{chunk-V22C3DOQ.mjs.map → chunk-4Z7QCC6V.mjs.map} +1 -1
  8. package/dist/{chunk-P6VS7ST4.mjs → chunk-6QKA3SNN.mjs} +12 -3
  9. package/dist/{chunk-P6VS7ST4.mjs.map → chunk-6QKA3SNN.mjs.map} +1 -1
  10. package/dist/{chunk-JDQCJCAQ.mjs → chunk-HECZOHST.mjs} +35 -15
  11. package/dist/chunk-HECZOHST.mjs.map +1 -0
  12. package/dist/{chunk-LMFSB5D5.mjs → chunk-JR55I3FL.mjs} +2 -2
  13. package/dist/{chunk-DT52QX4H.mjs → chunk-RGZ6GR2B.mjs} +36 -6
  14. package/dist/chunk-RGZ6GR2B.mjs.map +1 -0
  15. package/dist/{chunk-QDGDXRRJ.mjs → chunk-USL3EHJB.mjs} +2 -2
  16. package/dist/{chunk-H4VZMKR6.mjs → chunk-XUPO37VH.mjs} +2 -2
  17. package/dist/components/copilot-provider/copilotkit.js +19 -2
  18. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  19. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  20. package/dist/components/copilot-provider/index.js +19 -2
  21. package/dist/components/copilot-provider/index.js.map +1 -1
  22. package/dist/components/copilot-provider/index.mjs +2 -2
  23. package/dist/components/index.js +19 -2
  24. package/dist/components/index.js.map +1 -1
  25. package/dist/components/index.mjs +2 -2
  26. package/dist/context/copilot-context.d.ts +6 -0
  27. package/dist/context/copilot-context.js +9 -1
  28. package/dist/context/copilot-context.js.map +1 -1
  29. package/dist/context/copilot-context.mjs +1 -1
  30. package/dist/context/index.js +9 -1
  31. package/dist/context/index.js.map +1 -1
  32. package/dist/context/index.mjs +1 -1
  33. package/dist/hooks/index.d.ts +2 -1
  34. package/dist/hooks/index.js +97 -18
  35. package/dist/hooks/index.js.map +1 -1
  36. package/dist/hooks/index.mjs +15 -9
  37. package/dist/hooks/use-chat.d.ts +20 -0
  38. package/dist/hooks/use-chat.js +34 -14
  39. package/dist/hooks/use-chat.js.map +1 -1
  40. package/dist/hooks/use-chat.mjs +1 -1
  41. package/dist/hooks/use-coagent-state-render.js +9 -1
  42. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  43. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  44. package/dist/hooks/use-coagent.d.ts +14 -1
  45. package/dist/hooks/use-coagent.js +97 -18
  46. package/dist/hooks/use-coagent.js.map +1 -1
  47. package/dist/hooks/use-coagent.mjs +11 -5
  48. package/dist/hooks/use-copilot-action.js +9 -1
  49. package/dist/hooks/use-copilot-action.js.map +1 -1
  50. package/dist/hooks/use-copilot-action.mjs +2 -2
  51. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  52. package/dist/hooks/use-copilot-chat.js +75 -17
  53. package/dist/hooks/use-copilot-chat.js.map +1 -1
  54. package/dist/hooks/use-copilot-chat.mjs +4 -4
  55. package/dist/hooks/use-copilot-readable.js +9 -1
  56. package/dist/hooks/use-copilot-readable.js.map +1 -1
  57. package/dist/hooks/use-copilot-readable.mjs +2 -2
  58. package/dist/hooks/use-make-copilot-document-readable.js +9 -1
  59. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  60. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +107 -19
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +16 -10
  65. package/dist/lib/copilot-task.js.map +1 -1
  66. package/dist/lib/copilot-task.mjs +3 -3
  67. package/dist/lib/index.js.map +1 -1
  68. package/dist/lib/index.mjs +3 -3
  69. package/dist/utils/extract.js.map +1 -1
  70. package/dist/utils/extract.mjs +2 -2
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/utils/index.mjs +2 -2
  73. package/package.json +3 -3
  74. package/src/components/copilot-provider/copilotkit.tsx +10 -0
  75. package/src/context/copilot-context.tsx +22 -0
  76. package/src/hooks/index.ts +1 -1
  77. package/src/hooks/use-chat.ts +53 -15
  78. package/src/hooks/use-coagent.ts +21 -4
  79. package/src/hooks/use-copilot-chat.ts +36 -3
  80. package/dist/chunk-DT52QX4H.mjs.map +0 -1
  81. package/dist/chunk-JDQCJCAQ.mjs.map +0 -1
  82. /package/dist/{chunk-XINZBP3J.mjs.map → chunk-3AYELZJS.mjs.map} +0 -0
  83. /package/dist/{chunk-MWZO6TUR.mjs.map → chunk-3R4J2TPH.mjs.map} +0 -0
  84. /package/dist/{chunk-LMFSB5D5.mjs.map → chunk-JR55I3FL.mjs.map} +0 -0
  85. /package/dist/{chunk-QDGDXRRJ.mjs.map → chunk-USL3EHJB.mjs.map} +0 -0
  86. /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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A,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"]}
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;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,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"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useMakeCopilotDocumentReadable
3
- } from "../chunk-H4VZMKR6.mjs";
4
- import "../chunk-LODRWFMB.mjs";
3
+ } from "../chunk-XUPO37VH.mjs";
4
+ import "../chunk-2JP64U3A.mjs";
5
5
  import "../chunk-SKC7AJIV.mjs";
6
6
  export {
7
7
  useMakeCopilotDocumentReadable
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,23 @@ 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 abortControllerRef = (0, import_react9.useRef)();
1047
- const threadIdRef = (0, import_react9.useRef)(null);
1048
- const runIdRef = (0, import_react9.useRef)(null);
1049
1071
  const { addGraphQLErrorsToast } = useToast();
1050
1072
  const runChatCompletionRef = (0, import_react9.useRef)();
1051
1073
  const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
1052
1074
  coagentStatesRef.current = coagentStates;
1053
1075
  const agentSessionRef = (0, import_react9.useRef)(agentSession);
1054
1076
  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;
1055
1081
  const publicApiKey = copilotConfig.publicApiKey;
1056
1082
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1057
1083
  const runtimeClient = useCopilotRuntimeClient({
@@ -1069,8 +1095,7 @@ function useChat(options) {
1069
1095
  role: import_runtime_client_gql4.Role.Assistant
1070
1096
  })
1071
1097
  ];
1072
- const abortController = new AbortController();
1073
- abortControllerRef.current = abortController;
1098
+ chatAbortControllerRef.current = new AbortController();
1074
1099
  setMessages([...previousMessages, ...newMessages]);
1075
1100
  const systemMessage = makeSystemMessageCallback();
1076
1101
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
@@ -1123,7 +1148,7 @@ function useChat(options) {
1123
1148
  }))
1124
1149
  }),
1125
1150
  properties: copilotConfig.properties,
1126
- signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
1151
+ signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
1127
1152
  })
1128
1153
  );
1129
1154
  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 +1167,9 @@ function useChat(options) {
1142
1167
  break;
1143
1168
  }
1144
1169
  if (done) {
1170
+ if (chatAbortControllerRef.current.signal.aborted) {
1171
+ return newMessages.slice();
1172
+ }
1145
1173
  break;
1146
1174
  }
1147
1175
  if (!(value == null ? void 0 : value.generateCopilotResponse)) {
@@ -1149,6 +1177,8 @@ function useChat(options) {
1149
1177
  }
1150
1178
  threadIdRef.current = value.generateCopilotResponse.threadId || null;
1151
1179
  runIdRef.current = value.generateCopilotResponse.runId || null;
1180
+ setThreadId(threadIdRef.current);
1181
+ setRunId(runIdRef.current);
1152
1182
  const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
1153
1183
  (0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
1154
1184
  );
@@ -1177,12 +1207,22 @@ function useChat(options) {
1177
1207
  if (action) {
1178
1208
  followUp = action.followUp;
1179
1209
  }
1180
- const result = yield onFunctionCall({
1181
- messages: previousMessages,
1182
- name: message.name,
1183
- args: message.arguments
1184
- });
1185
- actionResults[message.id] = result;
1210
+ const result = yield Promise.race([
1211
+ onFunctionCall({
1212
+ messages: previousMessages,
1213
+ name: message.name,
1214
+ args: message.arguments
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
+ }
1186
1226
  } catch (e) {
1187
1227
  actionResults[message.id] = `Failed to execute action ${message.name}`;
1188
1228
  console.error(`Failed to execute action ${message.name}: ${e}`);
@@ -1277,7 +1317,7 @@ function useChat(options) {
1277
1317
  });
1278
1318
  const stop = () => {
1279
1319
  var _a;
1280
- (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
1320
+ (_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
1281
1321
  };
1282
1322
  return {
1283
1323
  append,
@@ -1305,7 +1345,13 @@ function useCopilotChat(_a = {}) {
1305
1345
  setCoagentStates,
1306
1346
  coAgentStateRenders,
1307
1347
  agentSession,
1308
- setAgentSession
1348
+ setAgentSession,
1349
+ agentLock,
1350
+ threadId,
1351
+ setThreadId,
1352
+ runId,
1353
+ setRunId,
1354
+ chatAbortControllerRef
1309
1355
  } = useCopilotContext();
1310
1356
  const { messages, setMessages } = useCopilotMessagesContext();
1311
1357
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -1355,7 +1401,12 @@ function useCopilotChat(_a = {}) {
1355
1401
  coagentStates,
1356
1402
  setCoagentStates,
1357
1403
  agentSession,
1358
- setAgentSession
1404
+ setAgentSession,
1405
+ threadId,
1406
+ setThreadId,
1407
+ runId,
1408
+ setRunId,
1409
+ chatAbortControllerRef
1359
1410
  }));
1360
1411
  const latestAppend = useUpdatedRef(append);
1361
1412
  const latestAppendFunc = (0, import_react10.useCallback)(
@@ -1386,12 +1437,31 @@ function useCopilotChat(_a = {}) {
1386
1437
  },
1387
1438
  [latestSetMessages]
1388
1439
  );
1440
+ const reset = (0, import_react10.useCallback)(() => {
1441
+ latestStopFunc();
1442
+ setMessages([]);
1443
+ setThreadId(null);
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]);
1389
1458
  return {
1390
1459
  visibleMessages: messages,
1391
1460
  appendMessage: latestAppendFunc,
1392
1461
  setMessages: latestSetMessagesFunc,
1393
1462
  reloadMessages: latestReloadFunc,
1394
1463
  stopGeneration: latestStopFunc,
1464
+ reset: latestResetFunc,
1395
1465
  deleteMessage: latestDeleteFunc,
1396
1466
  isLoading
1397
1467
  };
@@ -1631,7 +1701,11 @@ function useCoAgent(options) {
1631
1701
  } else if (coagentStates[name] === void 0) {
1632
1702
  setState(options.initialState === void 0 ? {} : options.initialState);
1633
1703
  }
1634
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
1704
+ }, [
1705
+ isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
1706
+ // reset initialstate on reset
1707
+ coagentStates[name] === void 0
1708
+ ]);
1635
1709
  return {
1636
1710
  name,
1637
1711
  nodeName: coagentState.nodeName,
@@ -1659,6 +1733,17 @@ function stopAgent(name, context) {
1659
1733
  const { agentSession, setAgentSession } = context;
1660
1734
  if (agentSession && agentSession.agentName === name) {
1661
1735
  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
+ });
1662
1747
  } else {
1663
1748
  console.warn(`No agent session found for ${name}`);
1664
1749
  }
@@ -1796,7 +1881,10 @@ ${instructions}
1796
1881
  CopilotTask,
1797
1882
  defaultCopilotContextCategories,
1798
1883
  extract,
1884
+ runAgent,
1799
1885
  shouldShowDevConsole,
1886
+ startAgent,
1887
+ stopAgent,
1800
1888
  useCoAgent,
1801
1889
  useCoAgentStateRender,
1802
1890
  useCopilotAction,