@copilotkit/react-core 0.25.0-mme-cloud.4 → 0.25.0-multi-feature-usecopilotreadable.3

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 (137) hide show
  1. package/.turbo/turbo-build.log +237 -216
  2. package/CHANGELOG.md +12 -23
  3. package/dist/{chunk-CGT3AVYT.mjs → chunk-3WKJ25L3.mjs} +3 -3
  4. package/dist/chunk-3WKJ25L3.mjs.map +1 -0
  5. package/dist/chunk-5L5PJJNT.mjs +28 -0
  6. package/dist/chunk-5L5PJJNT.mjs.map +1 -0
  7. package/dist/{chunk-IR5I4Q6R.mjs → chunk-75RLNHDB.mjs} +5 -5
  8. package/dist/chunk-75RLNHDB.mjs.map +1 -0
  9. package/dist/{chunk-SFV4PSJM.mjs → chunk-BCKOSVRB.mjs} +7 -11
  10. package/dist/chunk-BCKOSVRB.mjs.map +1 -0
  11. package/dist/{chunk-6ARSX7BW.mjs → chunk-BGB5G33N.mjs} +2 -2
  12. package/dist/{chunk-NQKBX6UJ.mjs → chunk-EABGYUTZ.mjs} +2 -2
  13. package/dist/chunk-EABGYUTZ.mjs.map +1 -0
  14. package/dist/chunk-EYKDJBDE.mjs +1 -0
  15. package/dist/chunk-F2JIAPZQ.mjs +14 -0
  16. package/dist/chunk-F2JIAPZQ.mjs.map +1 -0
  17. package/dist/{chunk-DW3HRHJB.mjs → chunk-FCEPEM4B.mjs} +3 -3
  18. package/dist/{chunk-VYD7RO32.mjs → chunk-H3FQWB4B.mjs} +13 -44
  19. package/dist/chunk-H3FQWB4B.mjs.map +1 -0
  20. package/dist/{chunk-PC6FY3LD.mjs → chunk-H6V2C2AN.mjs} +2 -2
  21. package/dist/chunk-ISKBWE4O.mjs +13 -0
  22. package/dist/chunk-ISKBWE4O.mjs.map +1 -0
  23. package/dist/{chunk-O35YOIHC.mjs → chunk-KIKHLN4X.mjs} +1 -3
  24. package/dist/chunk-KIKHLN4X.mjs.map +1 -0
  25. package/dist/{chunk-UNYZRMB2.mjs → chunk-L45P674M.mjs} +6 -6
  26. package/dist/chunk-L45P674M.mjs.map +1 -0
  27. package/dist/{chunk-MESZST5T.mjs → chunk-X3FZ6GTK.mjs} +16 -8
  28. package/dist/chunk-X3FZ6GTK.mjs.map +1 -0
  29. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -12
  30. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  31. package/dist/components/copilot-provider/copilotkit.d.ts +17 -0
  32. package/dist/components/copilot-provider/copilotkit.js +17 -40
  33. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  34. package/dist/components/copilot-provider/copilotkit.mjs +3 -2
  35. package/dist/components/copilot-provider/index.js +17 -40
  36. package/dist/components/copilot-provider/index.js.map +1 -1
  37. package/dist/components/copilot-provider/index.mjs +3 -2
  38. package/dist/components/copilot-provider/standard-copilot-api-config.d.ts +23 -0
  39. package/dist/components/copilot-provider/standard-copilot-api-config.js +38 -0
  40. package/dist/components/copilot-provider/standard-copilot-api-config.js.map +1 -0
  41. package/dist/components/copilot-provider/standard-copilot-api-config.mjs +8 -0
  42. package/dist/components/copilot-provider/standard-copilot-api-config.mjs.map +1 -0
  43. package/dist/components/index.js +17 -40
  44. package/dist/components/index.js.map +1 -1
  45. package/dist/components/index.mjs +3 -2
  46. package/dist/context/copilot-context.d.ts +1 -11
  47. package/dist/context/copilot-context.js +0 -2
  48. package/dist/context/copilot-context.js.map +1 -1
  49. package/dist/context/copilot-context.mjs +1 -1
  50. package/dist/context/index.js +0 -2
  51. package/dist/context/index.js.map +1 -1
  52. package/dist/context/index.mjs +1 -1
  53. package/dist/hooks/index.d.ts +1 -0
  54. package/dist/hooks/index.js +47 -17
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/index.mjs +20 -14
  57. package/dist/hooks/use-chat.d.ts +2 -8
  58. package/dist/hooks/use-chat.js +15 -6
  59. package/dist/hooks/use-chat.js.map +1 -1
  60. package/dist/hooks/use-chat.mjs +2 -2
  61. package/dist/hooks/use-copilot-action-implementation.d.ts +7 -0
  62. package/dist/hooks/use-copilot-action-implementation.js +140 -0
  63. package/dist/hooks/use-copilot-action-implementation.js.map +1 -0
  64. package/dist/hooks/use-copilot-action-implementation.mjs +9 -0
  65. package/dist/hooks/use-copilot-action-implementation.mjs.map +1 -0
  66. package/dist/hooks/use-copilot-action.d.ts +1 -1
  67. package/dist/hooks/use-copilot-action.js +9 -4
  68. package/dist/hooks/use-copilot-action.js.map +1 -1
  69. package/dist/hooks/use-copilot-action.mjs +3 -2
  70. package/dist/hooks/use-copilot-chat.js +18 -15
  71. package/dist/hooks/use-copilot-chat.js.map +1 -1
  72. package/dist/hooks/use-copilot-chat.mjs +6 -5
  73. package/dist/hooks/use-copilot-readable.d.ts +33 -0
  74. package/dist/hooks/use-copilot-readable.js +121 -0
  75. package/dist/hooks/use-copilot-readable.js.map +1 -0
  76. package/dist/hooks/use-copilot-readable.mjs +9 -0
  77. package/dist/hooks/use-copilot-readable.mjs.map +1 -0
  78. package/dist/hooks/use-make-copilot-actionable.js +0 -2
  79. package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
  80. package/dist/hooks/use-make-copilot-actionable.mjs +2 -2
  81. package/dist/hooks/use-make-copilot-document-readable.js +0 -2
  82. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  83. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  84. package/dist/hooks/use-make-copilot-readable.d.ts +1 -5
  85. package/dist/hooks/use-make-copilot-readable.js +0 -2
  86. package/dist/hooks/use-make-copilot-readable.js.map +1 -1
  87. package/dist/hooks/use-make-copilot-readable.mjs +2 -2
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.js +75 -66
  90. package/dist/index.js.map +1 -1
  91. package/dist/index.mjs +25 -19
  92. package/dist/lib/copilot-task.d.ts +7 -2
  93. package/dist/lib/copilot-task.js +5 -5
  94. package/dist/lib/copilot-task.js.map +1 -1
  95. package/dist/lib/copilot-task.mjs +5 -4
  96. package/dist/lib/index.js +5 -5
  97. package/dist/lib/index.js.map +1 -1
  98. package/dist/lib/index.mjs +5 -4
  99. package/dist/openai-assistants/hooks/index.js +0 -2
  100. package/dist/openai-assistants/hooks/index.js.map +1 -1
  101. package/dist/openai-assistants/hooks/index.mjs +4 -3
  102. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +0 -2
  103. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
  104. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +4 -3
  105. package/dist/openai-assistants/index.js +0 -2
  106. package/dist/openai-assistants/index.js.map +1 -1
  107. package/dist/openai-assistants/index.mjs +4 -3
  108. package/dist/utils/fetch-chat-completion.js +2 -2
  109. package/dist/utils/fetch-chat-completion.js.map +1 -1
  110. package/dist/utils/fetch-chat-completion.mjs +1 -1
  111. package/package.json +4 -4
  112. package/src/components/copilot-provider/copilotkit-props.tsx +1 -14
  113. package/src/components/copilot-provider/copilotkit.tsx +25 -47
  114. package/src/components/copilot-provider/standard-copilot-api-config.tsx +28 -0
  115. package/src/context/copilot-context.tsx +1 -21
  116. package/src/hooks/index.ts +1 -0
  117. package/src/hooks/use-chat.ts +15 -16
  118. package/src/hooks/use-copilot-action-implementation.ts +60 -0
  119. package/src/hooks/use-copilot-action.ts +10 -58
  120. package/src/hooks/use-copilot-chat.ts +1 -5
  121. package/src/hooks/use-copilot-readable.ts +60 -0
  122. package/src/hooks/use-make-copilot-readable.ts +1 -5
  123. package/src/lib/copilot-task.ts +12 -5
  124. package/src/utils/fetch-chat-completion.ts +0 -1
  125. package/dist/chunk-CGT3AVYT.mjs.map +0 -1
  126. package/dist/chunk-IOP6JX34.mjs +0 -1
  127. package/dist/chunk-IR5I4Q6R.mjs.map +0 -1
  128. package/dist/chunk-MESZST5T.mjs.map +0 -1
  129. package/dist/chunk-NQKBX6UJ.mjs.map +0 -1
  130. package/dist/chunk-O35YOIHC.mjs.map +0 -1
  131. package/dist/chunk-SFV4PSJM.mjs.map +0 -1
  132. package/dist/chunk-UNYZRMB2.mjs.map +0 -1
  133. package/dist/chunk-VYD7RO32.mjs.map +0 -1
  134. /package/dist/{chunk-6ARSX7BW.mjs.map → chunk-BGB5G33N.mjs.map} +0 -0
  135. /package/dist/{chunk-IOP6JX34.mjs.map → chunk-EYKDJBDE.mjs.map} +0 -0
  136. /package/dist/{chunk-DW3HRHJB.mjs.map → chunk-FCEPEM4B.mjs.map} +0 -0
  137. /package/dist/{chunk-PC6FY3LD.mjs.map → chunk-H6V2C2AN.mjs.map} +0 -0
@@ -0,0 +1,9 @@
1
+ import {
2
+ useCopilotReadable
3
+ } from "../chunk-5L5PJJNT.mjs";
4
+ import "../chunk-KIKHLN4X.mjs";
5
+ import "../chunk-MRXNTQOX.mjs";
6
+ export {
7
+ useCopilotReadable
8
+ };
9
+ //# sourceMappingURL=use-copilot-readable.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
71
71
  addContext: () => "",
72
72
  removeContext: () => {
73
73
  },
74
- messages: [],
75
- setMessages: () => returnAndThrowInDebug([]),
76
74
  getDocumentsContext: (categories) => returnAndThrowInDebug([]),
77
75
  addDocumentContext: () => returnAndThrowInDebug(""),
78
76
  removeDocumentContext: () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\nimport { annotatedFunctionToAction } from \"@copilotkit/shared\";\n\n/**\n * @deprecated Use the useCopilotAction function instead.\n */\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n const action = annotatedFunctionToAction(memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n setEntryPoint(idRef.current, action);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n ToolDefinition,\n} from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\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 chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAAuD;;;ACOvD,mBAA2B;AAiG3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADhJA,oBAAuB;AACvB,oBAA0C;AAKnC,SAAS,yBACd,mBACA,cACA;AACA,QAAM,YAAQ,0BAAO,sBAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,QAAI,0BAAW,cAAc;AAErE,QAAM,gCAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,+BAAU,MAAM;AACd,UAAM,aAAS,yCAA0B,yBAAqD;AAC9F,kBAAc,MAAM,SAAS,MAAM;AAEnC,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE;","names":["import_react","React"]}
1
+ {"version":3,"sources":["../../src/hooks/use-make-copilot-actionable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useRef, useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { AnnotatedFunction } from \"@copilotkit/shared\";\nimport { nanoid } from \"nanoid\";\nimport { annotatedFunctionToAction } from \"@copilotkit/shared\";\n\n/**\n * @deprecated Use the useCopilotAction function instead.\n */\nexport function useMakeCopilotActionable<ActionInput extends any[]>(\n annotatedFunction: AnnotatedFunction<ActionInput>,\n dependencies: any[],\n) {\n const idRef = useRef(nanoid()); // generate a unique id\n const { setEntryPoint, removeEntryPoint } = useContext(CopilotContext);\n\n const memoizedAnnotatedFunction: AnnotatedFunction<ActionInput> = useMemo(\n () => ({\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n argumentAnnotations: annotatedFunction.argumentAnnotations,\n implementation: annotatedFunction.implementation,\n }),\n dependencies,\n );\n\n useEffect(() => {\n const action = annotatedFunctionToAction(memoizedAnnotatedFunction as AnnotatedFunction<any[]>);\n setEntryPoint(idRef.current, action);\n\n return () => {\n removeEntryPoint(idRef.current);\n };\n }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAAuD;;;ACEvD,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;AD5HA,oBAAuB;AACvB,oBAA0C;AAKnC,SAAS,yBACd,mBACA,cACA;AACA,QAAM,YAAQ,0BAAO,sBAAO,CAAC;AAC7B,QAAM,EAAE,eAAe,iBAAiB,QAAI,0BAAW,cAAc;AAErE,QAAM,gCAA4D;AAAA,IAChE,OAAO;AAAA,MACL,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,qBAAqB,kBAAkB;AAAA,MACvC,gBAAgB,kBAAkB;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AAEA,+BAAU,MAAM;AACd,UAAM,aAAS,yCAA0B,yBAAqD;AAC9F,kBAAc,MAAM,SAAS,MAAM;AAEnC,WAAO,MAAM;AACX,uBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,2BAA2B,eAAe,gBAAgB,CAAC;AACjE;","names":["import_react","React"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useMakeCopilotActionable
3
- } from "../chunk-6ARSX7BW.mjs";
4
- import "../chunk-O35YOIHC.mjs";
3
+ } from "../chunk-BGB5G33N.mjs";
4
+ import "../chunk-KIKHLN4X.mjs";
5
5
  import "../chunk-MRXNTQOX.mjs";
6
6
  export {
7
7
  useMakeCopilotActionable
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
71
71
  addContext: () => "",
72
72
  removeContext: () => {
73
73
  },
74
- messages: [],
75
- setMessages: () => returnAndThrowInDebug([]),
76
74
  getDocumentsContext: (categories) => returnAndThrowInDebug([]),
77
75
  addDocumentContext: () => returnAndThrowInDebug(""),
78
76
  removeDocumentContext: () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } 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 } = useContext(CopilotContext);\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 {\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n ToolDefinition,\n} from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\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 chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAA8C;;;ACO9C,mBAA2B;AAiG3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADxIO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,QAAI,0BAAW,cAAc;AAC/E,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 { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } 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 } = useContext(CopilotContext);\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 { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAA8C;;;ACE9C,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADpHO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,QAAI,0BAAW,cAAc;AAC/E,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-PC6FY3LD.mjs";
4
- import "../chunk-O35YOIHC.mjs";
3
+ } from "../chunk-H6V2C2AN.mjs";
4
+ import "../chunk-KIKHLN4X.mjs";
5
5
  import "../chunk-MRXNTQOX.mjs";
6
6
  export {
7
7
  useMakeCopilotDocumentReadable
@@ -1,9 +1,5 @@
1
1
  /**
2
- * Adds the given information to the Copilot context to make it readable by Copilot.
3
- * @param information - The information to be added to the Copilot context.
4
- * @param parentId - The ID of the parent context, if any.
5
- * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)
6
- * @returns The ID of the added context.
2
+ * @deprecated Use the useCopilotReadable function instead.
7
3
  */
8
4
  declare function useMakeCopilotReadable(information: string, parentId?: string, categories?: string[]): string | undefined;
9
5
 
@@ -71,8 +71,6 @@ var emptyCopilotContext = {
71
71
  addContext: () => "",
72
72
  removeContext: () => {
73
73
  },
74
- messages: [],
75
- setMessages: () => returnAndThrowInDebug([]),
76
74
  getDocumentsContext: (categories) => returnAndThrowInDebug([]),
77
75
  addDocumentContext: () => returnAndThrowInDebug(""),
78
76
  removeDocumentContext: () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n * @param information - The information to be added to the Copilot context.\n * @param parentId - The ID of the parent context, if any.\n * @param categories - An array of categories to control which context are visible where. Particularly useful with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n * @returns The ID of the added context.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n Message,\n ToolDefinition,\n} from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\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 chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAA8C;;;ACO9C,mBAA2B;AAiG3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADzIO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,QAAI,0BAAW,cAAc;AAC/D,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf;","names":["import_react","React"]}
1
+ {"version":3,"sources":["../../src/hooks/use-make-copilot-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\n\n/**\n * @deprecated Use the useCopilotReadable function instead.\n */\nexport function useMakeCopilotReadable(\n information: string,\n parentId?: string,\n categories?: string[],\n): string | undefined {\n const { addContext, removeContext } = useContext(CopilotContext);\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addContext(information, parentId, categories);\n idRef.current = id;\n\n return () => {\n removeContext(id);\n };\n }, [information, parentId, addContext, removeContext]);\n\n return idRef.current;\n}\n","import { FunctionCallHandler, ToolDefinition } from \"@copilotkit/shared\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React, { Ref } from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the chat API v2.\n */\n chatApiEndpointV2: 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 * Additional body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'message': 'Hello, world!'\n * }\n * ```\n */\n body: Record<string, any>;\n\n /**\n * Backend only props that will be combined to body params to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n backendOnlyProps?: Record<string, any>;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\n\nexport interface CopilotContextParams {\n // function-calling\n entryPoints: Record<string, FrontendAction<any>>;\n setEntryPoint: (id: string, entryPoint: FrontendAction<any>) => void;\n removeEntryPoint: (id: string) => void;\n chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\n getChatCompletionFunctionDescriptions: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => ToolDefinition[];\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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n entryPoints: {},\n setEntryPoint: () => {},\n removeEntryPoint: () => {},\n getChatCompletionFunctionDescriptions: () => returnAndThrowInDebug([]),\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get chatApiEndpointV2(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n return React.useContext(CopilotContext);\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,gBAA8C;;;ACE9C,mBAA2B;AAoF3B,IAAM,sBAA4C;AAAA,EAChD,aAAa,CAAC;AAAA,EACd,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,uCAAuC,MAAM,sBAAsB,CAAC,CAAC;AAAA,EACrE,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAClE,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAE9B,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,oBAA4B;AAC9B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IACA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AACL;AAEO,IAAM,iBAAiB,aAAAC,QAAM,cAAoC,mBAAmB;AAM3F,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;;;ADzHO,SAAS,uBACd,aACA,UACA,YACoB;AACpB,QAAM,EAAE,YAAY,cAAc,QAAI,0BAAW,cAAc;AAC/D,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,MAAM;AACd,UAAM,KAAK,WAAW,aAAa,UAAU,UAAU;AACvD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,oBAAc,EAAE;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,YAAY,aAAa,CAAC;AAErD,SAAO,MAAM;AACf;","names":["import_react","React"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useMakeCopilotReadable
3
- } from "../chunk-NQKBX6UJ.mjs";
4
- import "../chunk-O35YOIHC.mjs";
3
+ } from "../chunk-EABGYUTZ.mjs";
4
+ import "../chunk-KIKHLN4X.mjs";
5
5
  import "../chunk-MRXNTQOX.mjs";
6
6
  export {
7
7
  useMakeCopilotReadable
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { useCopilotAction } from './hooks/use-copilot-action.js';
7
7
  export { useMakeCopilotReadable } from './hooks/use-make-copilot-readable.js';
8
8
  export { useMakeCopilotDocumentReadable } from './hooks/use-make-copilot-document-readable.js';
9
9
  export { UseChatHelpers } from './hooks/use-chat.js';
10
+ export { useCopilotReadable } from './hooks/use-copilot-readable.js';
10
11
  export { DocumentPointer } from './types/document-pointer.js';
11
12
  export { SystemMessageFunction } from './types/system-message.js';
12
13
  export { ActionRenderProps, RenderFunctionStatus } from './types/frontend-action.js';
package/dist/index.js CHANGED
@@ -92,6 +92,7 @@ __export(src_exports, {
92
92
  useCopilotChat: () => useCopilotChat,
93
93
  useCopilotChatV2: () => useCopilotChatV2,
94
94
  useCopilotContext: () => useCopilotContext,
95
+ useCopilotReadable: () => useCopilotReadable,
95
96
  useMakeCopilotActionable: () => useMakeCopilotActionable,
96
97
  useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
97
98
  useMakeCopilotReadable: () => useMakeCopilotReadable
@@ -117,8 +118,6 @@ var emptyCopilotContext = {
117
118
  addContext: () => "",
118
119
  removeContext: () => {
119
120
  },
120
- messages: [],
121
- setMessages: () => returnAndThrowInDebug([]),
122
121
  getDocumentsContext: (categories) => returnAndThrowInDebug([]),
123
122
  addDocumentContext: () => returnAndThrowInDebug(""),
124
123
  removeDocumentContext: () => {
@@ -347,19 +346,23 @@ function setsHaveIntersection2(setA, setB) {
347
346
  return false;
348
347
  }
349
348
 
349
+ // src/components/copilot-provider/standard-copilot-api-config.tsx
350
+ var StandardCopilotApiConfig = class {
351
+ constructor(chatApiEndpoint, chatApiEndpointV2, headers, body) {
352
+ this.chatApiEndpoint = chatApiEndpoint;
353
+ this.chatApiEndpointV2 = chatApiEndpointV2;
354
+ this.headers = headers;
355
+ this.body = body;
356
+ }
357
+ };
358
+
350
359
  // src/components/copilot-provider/copilotkit.tsx
351
360
  var import_jsx_runtime = require("react/jsx-runtime");
352
361
  function CopilotKit(_a) {
353
362
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
354
- var _a2, _b2;
355
- if (!props.url && !props.publicApiKey) {
356
- throw new Error("Please provide either a url or a publicApiKey to the CopilotKit component.");
357
- }
358
- const chatApiEndpoint = props.url || import_shared.COPILOT_CLOUD_CHAT_URL;
359
363
  const [entryPoints, setEntryPoints] = (0, import_react4.useState)({});
360
364
  const chatComponentsCache = (0, import_react4.useRef)({});
361
365
  const { addElement, removeElement, printTree } = use_tree_default();
362
- const [messages, setMessages] = (0, import_react4.useState)([]);
363
366
  const {
364
367
  addElement: addDocument,
365
368
  removeElement: removeDocument,
@@ -434,35 +437,12 @@ ${nonDocumentStrings}`;
434
437
  },
435
438
  [removeDocument]
436
439
  );
437
- if (!props.publicApiKey) {
438
- if (props.cloudRestrictToTopic) {
439
- throw new Error(
440
- "To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
441
- );
442
- }
443
- }
444
- let cloud = void 0;
445
- if (props.publicApiKey) {
446
- cloud = {
447
- guardrails: {
448
- input: {
449
- restrictToTopic: {
450
- enabled: props.cloudRestrictToTopic ? true : false,
451
- validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
452
- invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
453
- }
454
- }
455
- }
456
- };
457
- }
458
- const copilotApiConfig = __spreadProps(__spreadValues({
459
- publicApiKey: props.publicApiKey
460
- }, cloud ? { cloud } : {}), {
461
- chatApiEndpoint,
462
- chatApiEndpointV2: `${props.url}/v2`,
463
- headers: props.headers || {},
464
- body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
465
- });
440
+ const copilotApiConfig = new StandardCopilotApiConfig(
441
+ props.url,
442
+ `${props.url}/v2`,
443
+ props.headers || {},
444
+ __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
445
+ );
466
446
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
467
447
  CopilotContext.Provider,
468
448
  {
@@ -479,9 +459,7 @@ ${nonDocumentStrings}`;
479
459
  getDocumentsContext,
480
460
  addDocumentContext,
481
461
  removeDocumentContext,
482
- copilotApiConfig,
483
- messages,
484
- setMessages
462
+ copilotApiConfig
485
463
  },
486
464
  children
487
465
  }
@@ -540,11 +518,11 @@ function fetchChatCompletion(_0) {
540
518
  headers: __spreadValues(__spreadValues({
541
519
  "Content-Type": "application/json"
542
520
  }, copilotConfig.headers), headers ? __spreadValues({}, headers) : {}),
543
- body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
521
+ body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
544
522
  model,
545
523
  messages: cleanedMessages,
546
524
  stream: true
547
- }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {}), copilotConfig.cloud ? { cloud: copilotConfig.cloud } : {})),
525
+ }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {})),
548
526
  signal
549
527
  });
550
528
  return response;
@@ -591,14 +569,12 @@ function fetchAndDecodeChatCompletionAsText(params) {
591
569
  // src/hooks/use-chat.ts
592
570
  var import_untruncate_json = __toESM(require("untruncate-json"));
593
571
  function useChat(options) {
594
- const { messages, setMessages } = options;
572
+ const [messages, setMessages] = (0, import_react5.useState)([]);
595
573
  const [input, setInput] = (0, import_react5.useState)("");
596
574
  const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
597
575
  const abortControllerRef = (0, import_react5.useRef)();
598
576
  const threadIdRef = (0, import_react5.useRef)(null);
599
577
  const runIdRef = (0, import_react5.useRef)(null);
600
- const publicApiKey = options.copilotConfig.publicApiKey;
601
- const headers = __spreadValues(__spreadValues({}, options.headers || {}), publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
602
578
  const runChatCompletion = (messages2) => __async(this, null, function* () {
603
579
  setIsLoading(true);
604
580
  const newMessages = [
@@ -624,7 +600,7 @@ function useChat(options) {
624
600
  copilotConfig: __spreadProps(__spreadValues({}, options.copilotConfig), { body: copilotConfigBody }),
625
601
  messages: messagesWithContext,
626
602
  tools: options.tools,
627
- headers,
603
+ headers: options.headers,
628
604
  signal: abortController.signal
629
605
  });
630
606
  if (response.headers.get("threadid")) {
@@ -634,6 +610,16 @@ function useChat(options) {
634
610
  runIdRef.current = response.headers.get("runid");
635
611
  }
636
612
  if (!response.events) {
613
+ setMessages([
614
+ ...messages2,
615
+ {
616
+ id: (0, import_nanoid3.nanoid)(),
617
+ createdAt: /* @__PURE__ */ new Date(),
618
+ content: response.statusText,
619
+ role: "assistant"
620
+ }
621
+ ]);
622
+ setIsLoading(false);
637
623
  throw new Error("Failed to fetch chat completion");
638
624
  }
639
625
  const reader = response.events.getReader();
@@ -757,6 +743,7 @@ function useChat(options) {
757
743
  (_a = abortControllerRef.current) == null ? void 0 : _a.abort();
758
744
  };
759
745
  return {
746
+ messages,
760
747
  append,
761
748
  reload,
762
749
  stop,
@@ -779,9 +766,7 @@ function useCopilotChat(_a) {
779
766
  getContextString,
780
767
  getChatCompletionFunctionDescriptions,
781
768
  getFunctionCallHandler,
782
- copilotApiConfig,
783
- messages,
784
- setMessages
769
+ copilotApiConfig
785
770
  } = (0, import_react6.useContext)(CopilotContext);
786
771
  const systemMessage = (0, import_react6.useMemo)(() => {
787
772
  const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
@@ -795,16 +780,14 @@ function useCopilotChat(_a) {
795
780
  const functionDescriptions = (0, import_react6.useMemo)(() => {
796
781
  return getChatCompletionFunctionDescriptions();
797
782
  }, [getChatCompletionFunctionDescriptions]);
798
- const { append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
783
+ const { messages, append, reload, stop, isLoading, input, setInput } = useChat(__spreadProps(__spreadValues({}, options), {
799
784
  copilotConfig: copilotApiConfig,
800
785
  id: options.id,
801
786
  initialMessages: [systemMessage].concat(options.initialMessages || []),
802
787
  tools: functionDescriptions,
803
788
  onFunctionCall: getFunctionCallHandler(),
804
789
  headers: __spreadValues({}, options.headers),
805
- body: __spreadValues({}, options.body),
806
- messages,
807
- setMessages
790
+ body: __spreadValues({}, options.body)
808
791
  }));
809
792
  const visibleMessages = messages.filter(
810
793
  (message) => message.role === "user" || message.role === "assistant" || message.role === "function"
@@ -868,10 +851,10 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
868
851
  }, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
869
852
  }
870
853
 
871
- // src/hooks/use-copilot-action.ts
854
+ // src/hooks/use-copilot-action-implementation.ts
872
855
  var import_react8 = require("react");
873
856
  var import_nanoid5 = require("nanoid");
874
- function useCopilotAction(action, dependencies) {
857
+ function useCopilotActionImplementation(action, dependencies) {
875
858
  const { setEntryPoint, removeEntryPoint, entryPoints, chatComponentsCache } = (0, import_react8.useContext)(CopilotContext);
876
859
  const idRef = (0, import_react8.useRef)((0, import_nanoid5.nanoid)());
877
860
  if (dependencies === void 0) {
@@ -907,6 +890,11 @@ function useCopilotAction(action, dependencies) {
907
890
  ]);
908
891
  }
909
892
 
893
+ // src/hooks/use-copilot-action.ts
894
+ function useCopilotAction(action, dependencies) {
895
+ return useCopilotActionImplementation(action, dependencies);
896
+ }
897
+
910
898
  // src/hooks/use-make-copilot-readable.ts
911
899
  var import_react9 = require("react");
912
900
  function useMakeCopilotReadable(information, parentId, categories) {
@@ -937,8 +925,28 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
937
925
  return idRef.current;
938
926
  }
939
927
 
940
- // src/openai-assistants/hooks/use-copilot-chat-v2.ts
928
+ // src/hooks/use-copilot-readable.ts
941
929
  var import_react11 = require("react");
930
+ function convertToJSON(description, value) {
931
+ return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
932
+ }
933
+ function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
934
+ const { addContext, removeContext } = (0, import_react11.useContext)(CopilotContext);
935
+ const idRef = (0, import_react11.useRef)();
936
+ convert = convert || convertToJSON;
937
+ const information = convert(description, value);
938
+ (0, import_react11.useEffect)(() => {
939
+ const id = addContext(information, parentId, categories);
940
+ idRef.current = id;
941
+ return () => {
942
+ removeContext(id);
943
+ };
944
+ }, [information, parentId, addContext, removeContext, ...dependencies || []]);
945
+ return idRef.current;
946
+ }
947
+
948
+ // src/openai-assistants/hooks/use-copilot-chat-v2.ts
949
+ var import_react12 = require("react");
942
950
 
943
951
  // src/openai-assistants/utils/process-message-stream.ts
944
952
  function processMessageStream(reader, processMessage) {
@@ -971,13 +979,13 @@ function useCopilotChatV2(options) {
971
979
  getChatCompletionFunctionDescriptions,
972
980
  getFunctionCallHandler,
973
981
  copilotApiConfig
974
- } = (0, import_react11.useContext)(CopilotContext);
975
- const [messages, setMessages] = (0, import_react11.useState)([]);
976
- const [input, setInput] = (0, import_react11.useState)("");
977
- const [threadId, setThreadId] = (0, import_react11.useState)(void 0);
978
- const [status, setStatus] = (0, import_react11.useState)("awaiting_message");
979
- const [error, setError] = (0, import_react11.useState)(void 0);
980
- const systemMessage = (0, import_react11.useMemo)(() => {
982
+ } = (0, import_react12.useContext)(CopilotContext);
983
+ const [messages, setMessages] = (0, import_react12.useState)([]);
984
+ const [input, setInput] = (0, import_react12.useState)("");
985
+ const [threadId, setThreadId] = (0, import_react12.useState)(void 0);
986
+ const [status, setStatus] = (0, import_react12.useState)("awaiting_message");
987
+ const [error, setError] = (0, import_react12.useState)(void 0);
988
+ const systemMessage = (0, import_react12.useMemo)(() => {
981
989
  const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage2;
982
990
  const contextString = getContextString([], defaultCopilotContextCategories);
983
991
  return {
@@ -1085,12 +1093,12 @@ var CopilotTask = class {
1085
1093
  constructor(config) {
1086
1094
  this.instructions = config.instructions;
1087
1095
  this.actions = config.actions || [];
1088
- this.includeCopilotReadable = config.includeCopilotReadable || true;
1089
- this.includeCopilotActionable = config.includeCopilotActionable || true;
1096
+ this.includeCopilotReadable = config.includeCopilotReadable !== false;
1097
+ this.includeCopilotActions = config.includeCopilotActions !== false && config.includeCopilotActionable !== false;
1090
1098
  }
1091
1099
  run(context, data) {
1092
1100
  return __async(this, null, function* () {
1093
- const entryPoints = this.includeCopilotActionable ? Object.assign({}, context.entryPoints) : {};
1101
+ const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};
1094
1102
  for (const fn of this.actions) {
1095
1103
  entryPoints[fn.name] = fn;
1096
1104
  }
@@ -1181,6 +1189,7 @@ ${instructions}
1181
1189
  useCopilotChat,
1182
1190
  useCopilotChatV2,
1183
1191
  useCopilotContext,
1192
+ useCopilotReadable,
1184
1193
  useMakeCopilotActionable,
1185
1194
  useMakeCopilotDocumentReadable,
1186
1195
  useMakeCopilotReadable