@copilotkit/react-core 1.3.6 → 1.3.7

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 (118) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-4AF3YGMC.mjs → chunk-2MPUQRAY.mjs} +1 -3
  3. package/dist/chunk-2MPUQRAY.mjs.map +1 -0
  4. package/dist/{chunk-KK42A2OC.mjs → chunk-3MDMBUBP.mjs} +10 -6
  5. package/dist/chunk-3MDMBUBP.mjs.map +1 -0
  6. package/dist/{chunk-VZ66ENV7.mjs → chunk-6YEMNWKE.mjs} +41 -31
  7. package/dist/chunk-6YEMNWKE.mjs.map +1 -0
  8. package/dist/{chunk-3CU2I4W2.mjs → chunk-7DFHFZJT.mjs} +3 -4
  9. package/dist/{chunk-3CU2I4W2.mjs.map → chunk-7DFHFZJT.mjs.map} +1 -1
  10. package/dist/{chunk-6VNO5DEJ.mjs → chunk-AKQVU52J.mjs} +7 -9
  11. package/dist/chunk-AKQVU52J.mjs.map +1 -0
  12. package/dist/{chunk-NTNOUYBQ.mjs → chunk-ANOG3W5S.mjs} +2 -2
  13. package/dist/{chunk-ACK2DHWA.mjs → chunk-CQ23Q555.mjs} +2 -2
  14. package/dist/chunk-DCTJZ742.mjs +22 -0
  15. package/dist/chunk-DCTJZ742.mjs.map +1 -0
  16. package/dist/{chunk-2Y3VMFJN.mjs → chunk-OFG2PW2E.mjs} +8 -6
  17. package/dist/chunk-OFG2PW2E.mjs.map +1 -0
  18. package/dist/{chunk-UJWNB2I6.mjs → chunk-RYDEG77L.mjs} +2 -2
  19. package/dist/{chunk-QUCTZQ6X.mjs → chunk-TRXKPXDE.mjs} +2 -2
  20. package/dist/chunk-XXR4QFAQ.mjs +29 -0
  21. package/dist/chunk-XXR4QFAQ.mjs.map +1 -0
  22. package/dist/chunk-YPSGKPDA.mjs +1 -0
  23. package/dist/{chunk-IAS5FL4D.mjs → chunk-ZM6HV22S.mjs} +20 -13
  24. package/dist/chunk-ZM6HV22S.mjs.map +1 -0
  25. package/dist/components/copilot-provider/copilot-messages.d.ts +7 -0
  26. package/dist/components/copilot-provider/copilot-messages.js +80 -0
  27. package/dist/components/copilot-provider/copilot-messages.js.map +1 -0
  28. package/dist/components/copilot-provider/copilot-messages.mjs +9 -0
  29. package/dist/components/copilot-provider/copilot-messages.mjs.map +1 -0
  30. package/dist/components/copilot-provider/copilotkit.js +85 -52
  31. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  32. package/dist/components/copilot-provider/copilotkit.mjs +4 -2
  33. package/dist/components/copilot-provider/index.js +85 -52
  34. package/dist/components/copilot-provider/index.js.map +1 -1
  35. package/dist/components/copilot-provider/index.mjs +4 -2
  36. package/dist/components/index.js +85 -52
  37. package/dist/components/index.js.map +1 -1
  38. package/dist/components/index.mjs +4 -2
  39. package/dist/context/copilot-context.d.ts +0 -3
  40. package/dist/context/copilot-context.js +0 -2
  41. package/dist/context/copilot-context.js.map +1 -1
  42. package/dist/context/copilot-context.mjs +1 -1
  43. package/dist/context/copilot-messages-context.d.ts +15 -0
  44. package/dist/context/copilot-messages-context.js +57 -0
  45. package/dist/context/copilot-messages-context.js.map +1 -0
  46. package/dist/context/copilot-messages-context.mjs +10 -0
  47. package/dist/context/copilot-messages-context.mjs.map +1 -0
  48. package/dist/context/index.d.ts +2 -1
  49. package/dist/context/index.js +23 -4
  50. package/dist/context/index.js.map +1 -1
  51. package/dist/context/index.mjs +9 -3
  52. package/dist/hooks/index.js +57 -40
  53. package/dist/hooks/index.js.map +1 -1
  54. package/dist/hooks/index.mjs +18 -16
  55. package/dist/hooks/use-chat.js +5 -5
  56. package/dist/hooks/use-chat.js.map +1 -1
  57. package/dist/hooks/use-chat.mjs +1 -1
  58. package/dist/hooks/use-coagent-state-render.js +0 -2
  59. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  60. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  61. package/dist/hooks/use-coagent.js +48 -33
  62. package/dist/hooks/use-coagent.js.map +1 -1
  63. package/dist/hooks/use-coagent.mjs +8 -6
  64. package/dist/hooks/use-copilot-action.js +0 -2
  65. package/dist/hooks/use-copilot-action.js.map +1 -1
  66. package/dist/hooks/use-copilot-action.mjs +2 -2
  67. package/dist/hooks/use-copilot-chat.js +37 -21
  68. package/dist/hooks/use-copilot-chat.js.map +1 -1
  69. package/dist/hooks/use-copilot-chat.mjs +7 -4
  70. package/dist/hooks/use-copilot-readable.js +0 -2
  71. package/dist/hooks/use-copilot-readable.js.map +1 -1
  72. package/dist/hooks/use-copilot-readable.mjs +2 -2
  73. package/dist/hooks/use-make-copilot-document-readable.js +0 -2
  74. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  75. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.js +176 -122
  78. package/dist/index.js.map +1 -1
  79. package/dist/index.mjs +26 -19
  80. package/dist/lib/copilot-task.d.ts +0 -1
  81. package/dist/lib/copilot-task.js +1 -1
  82. package/dist/lib/copilot-task.js.map +1 -1
  83. package/dist/lib/copilot-task.mjs +5 -3
  84. package/dist/lib/index.d.ts +0 -1
  85. package/dist/lib/index.js +1 -1
  86. package/dist/lib/index.js.map +1 -1
  87. package/dist/lib/index.mjs +5 -3
  88. package/dist/utils/extract.d.ts +2 -1
  89. package/dist/utils/extract.js +18 -10
  90. package/dist/utils/extract.js.map +1 -1
  91. package/dist/utils/extract.mjs +5 -3
  92. package/dist/utils/index.d.ts +1 -0
  93. package/dist/utils/index.js +18 -10
  94. package/dist/utils/index.js.map +1 -1
  95. package/dist/utils/index.mjs +5 -3
  96. package/package.json +7 -7
  97. package/src/components/copilot-provider/copilot-messages.tsx +23 -0
  98. package/src/components/copilot-provider/copilotkit.tsx +36 -30
  99. package/src/context/copilot-context.tsx +0 -8
  100. package/src/context/copilot-messages-context.tsx +29 -0
  101. package/src/context/index.ts +2 -0
  102. package/src/hooks/use-chat.ts +5 -5
  103. package/src/hooks/use-coagent.ts +11 -4
  104. package/src/hooks/use-copilot-chat.ts +2 -2
  105. package/src/lib/copilot-task.ts +1 -1
  106. package/src/utils/extract.ts +25 -13
  107. package/dist/chunk-2Y3VMFJN.mjs.map +0 -1
  108. package/dist/chunk-4AF3YGMC.mjs.map +0 -1
  109. package/dist/chunk-6VNO5DEJ.mjs.map +0 -1
  110. package/dist/chunk-IAS5FL4D.mjs.map +0 -1
  111. package/dist/chunk-KK42A2OC.mjs.map +0 -1
  112. package/dist/chunk-VNRDQJXW.mjs +0 -1
  113. package/dist/chunk-VZ66ENV7.mjs.map +0 -1
  114. /package/dist/{chunk-NTNOUYBQ.mjs.map → chunk-ANOG3W5S.mjs.map} +0 -0
  115. /package/dist/{chunk-ACK2DHWA.mjs.map → chunk-CQ23Q555.mjs.map} +0 -0
  116. /package/dist/{chunk-UJWNB2I6.mjs.map → chunk-RYDEG77L.mjs.map} +0 -0
  117. /package/dist/{chunk-QUCTZQ6X.mjs.map → chunk-TRXKPXDE.mjs.map} +0 -0
  118. /package/dist/{chunk-VNRDQJXW.mjs.map → chunk-YPSGKPDA.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotContext
3
- } from "./chunk-4AF3YGMC.mjs";
3
+ } from "./chunk-2MPUQRAY.mjs";
4
4
 
5
5
  // src/hooks/use-make-copilot-document-readable.ts
6
6
  import { useEffect, useRef } from "react";
@@ -20,4 +20,4 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
20
20
  export {
21
21
  useMakeCopilotDocumentReadable
22
22
  };
23
- //# sourceMappingURL=chunk-QUCTZQ6X.mjs.map
23
+ //# sourceMappingURL=chunk-TRXKPXDE.mjs.map
@@ -0,0 +1,29 @@
1
+ import {
2
+ CopilotMessagesContext
3
+ } from "./chunk-DCTJZ742.mjs";
4
+ import {
5
+ __objRest
6
+ } from "./chunk-SKC7AJIV.mjs";
7
+
8
+ // src/components/copilot-provider/copilot-messages.tsx
9
+ import { useState } from "react";
10
+ import { jsx } from "react/jsx-runtime";
11
+ function CopilotMessages(_a) {
12
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
13
+ const [messages, setMessages] = useState([]);
14
+ return /* @__PURE__ */ jsx(
15
+ CopilotMessagesContext.Provider,
16
+ {
17
+ value: {
18
+ messages,
19
+ setMessages
20
+ },
21
+ children
22
+ }
23
+ );
24
+ }
25
+
26
+ export {
27
+ CopilotMessages
28
+ };
29
+ //# sourceMappingURL=chunk-XXR4QFAQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/copilot-provider/copilot-messages.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { useState } from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\nexport function CopilotMessages({ children, ...props }: CopilotKitProps) {\n const [messages, setMessages] = useState<Message[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotMessagesContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAIA,SAAS,gBAAgB;AASrB;AAJG,SAAS,gBAAgB,IAAyC;AAAzC,eAAE,WATlC,IASgC,IAAe,kBAAf,IAAe,CAAb;AAChC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AAEtD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YPSGKPDA.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-VZ66ENV7.mjs";
3
+ } from "./chunk-6YEMNWKE.mjs";
4
4
  import {
5
5
  __async,
6
6
  __spreadValues
@@ -12,7 +12,6 @@ import {
12
12
  actionParametersToJsonSchema
13
13
  } from "@copilotkit/shared";
14
14
  import {
15
- ActionExecutionMessage,
16
15
  Role,
17
16
  TextMessage,
18
17
  convertGqlOutputToMessages,
@@ -38,6 +37,7 @@ function extract(_0) {
38
37
  const { messages } = context;
39
38
  const action = {
40
39
  name: "extract",
40
+ description: instructions,
41
41
  parameters,
42
42
  handler: (args) => {
43
43
  }
@@ -55,6 +55,10 @@ function extract(_0) {
55
55
  content: makeSystemMessage(contextString, instructions),
56
56
  role: Role.System
57
57
  });
58
+ const instructionsMessage = new TextMessage({
59
+ content: makeInstructionsMessage(instructions),
60
+ role: Role.User
61
+ });
58
62
  const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
59
63
  const runtimeClient = new CopilotRuntimeClient({
60
64
  url: context.copilotApiConfig.chatApiEndpoint,
@@ -76,7 +80,7 @@ function extract(_0) {
76
80
  url: window.location.href
77
81
  },
78
82
  messages: convertMessagesToGqlInput(
79
- includeMessages ? [systemMessage, ...filterAgentStateMessages(messages)] : [systemMessage]
83
+ includeMessages ? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)] : [systemMessage, instructionsMessage]
80
84
  ),
81
85
  metadata: {
82
86
  requestType
@@ -103,7 +107,7 @@ function extract(_0) {
103
107
  }
104
108
  actionExecutionMessage = convertGqlOutputToMessages(
105
109
  value.generateCopilotResponse.messages
106
- ).find((msg) => msg instanceof ActionExecutionMessage);
110
+ ).find((msg) => msg.isActionExecutionMessage());
107
111
  if (!actionExecutionMessage) {
108
112
  continue;
109
113
  }
@@ -123,6 +127,17 @@ function extract(_0) {
123
127
  return actionExecutionMessage.arguments;
124
128
  });
125
129
  }
130
+ function makeInstructionsMessage(instructions) {
131
+ return `
132
+ The user has given you the following task to complete:
133
+
134
+ \`\`\`
135
+ ${instructions}
136
+ \`\`\`
137
+
138
+ Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
139
+ `;
140
+ }
126
141
  function makeSystemMessage(contextString, instructions) {
127
142
  return `
128
143
  Please act as an efficient, competent, conscientious, and industrious professional assistant.
@@ -140,18 +155,10 @@ They have also provided you with a function called extract you MUST call to init
140
155
  Please assist them as best you can.
141
156
 
142
157
  This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
143
-
144
- The user has given you the following task to complete:
145
-
146
- \`\`\`
147
- ${instructions}
148
- \`\`\`
149
-
150
- Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
151
158
  `;
152
159
  }
153
160
 
154
161
  export {
155
162
  extract
156
163
  };
157
- //# sourceMappingURL=chunk-IAS5FL4D.mjs.map
164
+ //# sourceMappingURL=chunk-ZM6HV22S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/extract.ts"],"sourcesContent":["import {\n Action,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n MappedParameterTypes,\n Parameter,\n actionParametersToJsonSchema,\n} from \"@copilotkit/shared\";\nimport {\n ActionExecutionMessage,\n Message,\n Role,\n TextMessage,\n convertGqlOutputToMessages,\n CopilotRequestType,\n} from \"@copilotkit/runtime-client-gql\";\nimport { CopilotContextParams, CopilotMessagesContextParams } from \"../context\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { CopilotRuntimeClient } from \"@copilotkit/runtime-client-gql\";\nimport {\n convertMessagesToGqlInput,\n filterAgentStateMessages,\n} from \"@copilotkit/runtime-client-gql\";\n\ninterface InitialState<T extends Parameter[] | [] = []> {\n status: \"initial\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface InProgressState<T extends Parameter[] | [] = []> {\n status: \"inProgress\";\n args: Partial<MappedParameterTypes<T>>;\n}\n\ninterface CompleteState<T extends Parameter[] | [] = []> {\n status: \"complete\";\n args: MappedParameterTypes<T>;\n}\n\ntype StreamHandlerArgs<T extends Parameter[] | [] = []> =\n | InitialState<T>\n | InProgressState<T>\n | CompleteState<T>;\n\ninterface ExtractOptions<T extends Parameter[]> {\n context: CopilotContextParams & CopilotMessagesContextParams;\n instructions: string;\n parameters: T;\n include?: IncludeOptions;\n data?: any;\n abortSignal?: AbortSignal;\n stream?: (args: StreamHandlerArgs<T>) => void;\n requestType?: CopilotRequestType;\n}\n\ninterface IncludeOptions {\n readable?: boolean;\n messages?: boolean;\n}\n\nexport async function extract<const T extends Parameter[]>({\n context,\n instructions,\n parameters,\n include,\n data,\n abortSignal,\n stream,\n requestType = CopilotRequestType.Task,\n}: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {\n const { messages } = context;\n\n const action: Action<any> = {\n name: \"extract\",\n description: instructions,\n parameters,\n handler: (args: any) => {},\n };\n\n const includeReadable = include?.readable ?? false;\n const includeMessages = include?.messages ?? false;\n\n let contextString = \"\";\n\n if (data) {\n contextString = (typeof data === \"string\" ? data : JSON.stringify(data)) + \"\\n\\n\";\n }\n\n if (includeReadable) {\n contextString += context.getContextString([], defaultCopilotContextCategories);\n }\n\n const systemMessage: Message = new TextMessage({\n content: makeSystemMessage(contextString, instructions),\n role: Role.System,\n });\n\n const instructionsMessage: Message = new TextMessage({\n content: makeInstructionsMessage(instructions),\n role: Role.User,\n });\n\n const headers = {\n ...(context.copilotApiConfig.headers || {}),\n ...(context.copilotApiConfig.publicApiKey\n ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey }\n : {}),\n };\n\n const runtimeClient = new CopilotRuntimeClient({\n url: context.copilotApiConfig.chatApiEndpoint,\n publicApiKey: context.copilotApiConfig.publicApiKey,\n headers,\n credentials: context.copilotApiConfig.credentials,\n });\n\n const response = CopilotRuntimeClient.asStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: [\n {\n name: action.name,\n description: action.description || \"\",\n jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),\n },\n ],\n url: window.location.href,\n },\n\n messages: convertMessagesToGqlInput(\n includeMessages\n ? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]\n : [systemMessage, instructionsMessage],\n ),\n metadata: {\n requestType: requestType,\n },\n forwardedParameters: {\n toolChoice: \"function\",\n toolChoiceFunctionName: action.name,\n },\n },\n properties: context.copilotApiConfig.properties,\n signal: abortSignal,\n }),\n );\n\n const reader = response.getReader();\n\n let isInitial = true;\n\n let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n if (abortSignal?.aborted) {\n throw new Error(\"Aborted\");\n }\n\n actionExecutionMessage = convertGqlOutputToMessages(\n value.generateCopilotResponse.messages,\n ).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;\n\n if (!actionExecutionMessage) {\n continue;\n }\n\n stream?.({\n status: isInitial ? \"initial\" : \"inProgress\",\n args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,\n });\n\n isInitial = false;\n }\n\n if (!actionExecutionMessage) {\n throw new Error(\"extract() failed: No function call occurred\");\n }\n\n stream?.({\n status: \"complete\",\n args: actionExecutionMessage.arguments as MappedParameterTypes<T>,\n });\n\n return actionExecutionMessage.arguments as MappedParameterTypes<T>;\n}\n\n// We need to put this in a user message since some LLMs need\n// at least one user message to function\nfunction makeInstructionsMessage(instructions: string): string {\n return `\nThe user has given you the following task to complete:\n\n\\`\\`\\`\n${instructions}\n\\`\\`\\`\n\nAny additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.\n`;\n}\n\nfunction makeSystemMessage(contextString: string, instructions: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with a function called extract you MUST call to initiate actions on their behalf.\n\nPlease assist them as best you can.\n\nThis is not a conversation, so please do not ask questions. Just call the function without saying anything else.\n`;\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,7 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CopilotKitProps } from './copilotkit-props.js';
3
+ import 'react';
4
+
5
+ declare function CopilotMessages({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
6
+
7
+ export { CopilotMessages };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __objRest = (source, exclude) => {
11
+ var target = {};
12
+ for (var prop in source)
13
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
14
+ target[prop] = source[prop];
15
+ if (source != null && __getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(source)) {
17
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
18
+ target[prop] = source[prop];
19
+ }
20
+ return target;
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
+
44
+ // src/components/copilot-provider/copilot-messages.tsx
45
+ var copilot_messages_exports = {};
46
+ __export(copilot_messages_exports, {
47
+ CopilotMessages: () => CopilotMessages
48
+ });
49
+ module.exports = __toCommonJS(copilot_messages_exports);
50
+ var import_react2 = require("react");
51
+
52
+ // src/context/copilot-messages-context.tsx
53
+ var import_react = __toESM(require("react"));
54
+ var emptyCopilotContext = {
55
+ messages: [],
56
+ setMessages: () => []
57
+ };
58
+ var CopilotMessagesContext = import_react.default.createContext(emptyCopilotContext);
59
+
60
+ // src/components/copilot-provider/copilot-messages.tsx
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ function CopilotMessages(_a) {
63
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
64
+ const [messages, setMessages] = (0, import_react2.useState)([]);
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
66
+ CopilotMessagesContext.Provider,
67
+ {
68
+ value: {
69
+ messages,
70
+ setMessages
71
+ },
72
+ children
73
+ }
74
+ );
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ CopilotMessages
79
+ });
80
+ //# sourceMappingURL=copilot-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/copilot-provider/copilot-messages.tsx","../../../src/context/copilot-messages-context.tsx"],"sourcesContent":["/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { useState } from \"react\";\nimport { CopilotMessagesContext } from \"../../context/copilot-messages-context\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { CopilotKitProps } from \"./copilotkit-props\";\n\nexport function CopilotMessages({ children, ...props }: CopilotKitProps) {\n const [messages, setMessages] = useState<Message[]>([]);\n\n return (\n <CopilotMessagesContext.Provider\n value={{\n messages,\n setMessages,\n }}\n >\n {children}\n </CopilotMessagesContext.Provider>\n );\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,IAAAA,gBAAyB;;;ACCzB,mBAAkB;AAOlB,IAAM,sBAAoD;AAAA,EACxD,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,CAAC;AACtB;AAEO,IAAM,yBACX,aAAAC,QAAM,cAA4C,mBAAmB;;;ADLnE;AAJG,SAAS,gBAAgB,IAAyC;AAAzC,eAAE,WATlC,IASgC,IAAe,kBAAf,IAAe,CAAb;AAChC,QAAM,CAAC,UAAU,WAAW,QAAI,wBAAoB,CAAC,CAAC;AAEtD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":["import_react","React"]}
@@ -0,0 +1,9 @@
1
+ import {
2
+ CopilotMessages
3
+ } from "../../chunk-XXR4QFAQ.mjs";
4
+ import "../../chunk-DCTJZ742.mjs";
5
+ import "../../chunk-SKC7AJIV.mjs";
6
+ export {
7
+ CopilotMessages
8
+ };
9
+ //# sourceMappingURL=copilot-messages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -84,7 +84,7 @@ __export(copilotkit_exports, {
84
84
  defaultCopilotContextCategories: () => defaultCopilotContextCategories
85
85
  });
86
86
  module.exports = __toCommonJS(copilotkit_exports);
87
- var import_react4 = require("react");
87
+ var import_react6 = require("react");
88
88
 
89
89
  // src/context/copilot-context.tsx
90
90
  var import_react = __toESM(require("react"));
@@ -106,8 +106,6 @@ var emptyCopilotContext = {
106
106
  },
107
107
  getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
108
108
  })),
109
- messages: [],
110
- setMessages: () => returnAndThrowInDebug([]),
111
109
  isLoading: false,
112
110
  setIsLoading: () => returnAndThrowInDebug(false),
113
111
  chatInstructions: "",
@@ -347,61 +345,87 @@ function setsHaveIntersection2(setA, setB) {
347
345
  return false;
348
346
  }
349
347
 
350
- // src/components/copilot-provider/copilotkit.tsx
348
+ // src/components/copilot-provider/copilot-messages.tsx
349
+ var import_react5 = require("react");
350
+
351
+ // src/context/copilot-messages-context.tsx
352
+ var import_react4 = __toESM(require("react"));
353
+ var emptyCopilotContext2 = {
354
+ messages: [],
355
+ setMessages: () => []
356
+ };
357
+ var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
358
+
359
+ // src/components/copilot-provider/copilot-messages.tsx
351
360
  var import_jsx_runtime = require("react/jsx-runtime");
361
+ function CopilotMessages(_a) {
362
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
363
+ const [messages, setMessages] = (0, import_react5.useState)([]);
364
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
365
+ CopilotMessagesContext.Provider,
366
+ {
367
+ value: {
368
+ messages,
369
+ setMessages
370
+ },
371
+ children
372
+ }
373
+ );
374
+ }
375
+
376
+ // src/components/copilot-provider/copilotkit.tsx
377
+ var import_jsx_runtime2 = require("react/jsx-runtime");
352
378
  function CopilotKit(_a) {
353
379
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
354
- var _a2, _b2;
355
380
  if (!props.runtimeUrl && !props.publicApiKey) {
356
381
  throw new Error(
357
382
  "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
358
383
  );
359
384
  }
360
385
  const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
361
- const [actions, setActions] = (0, import_react4.useState)({});
362
- const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react4.useState)({});
363
- const chatComponentsCache = (0, import_react4.useRef)({
386
+ const [actions, setActions] = (0, import_react6.useState)({});
387
+ const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react6.useState)({});
388
+ const chatComponentsCache = (0, import_react6.useRef)({
364
389
  actions: {},
365
390
  coAgentStateRenders: {}
366
391
  });
367
392
  const { addElement, removeElement, printTree } = use_tree_default();
368
- const [messages, setMessages] = (0, import_react4.useState)([]);
369
- const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
370
- const [chatInstructions, setChatInstructions] = (0, import_react4.useState)("");
393
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
394
+ const [chatInstructions, setChatInstructions] = (0, import_react6.useState)("");
371
395
  const {
372
396
  addElement: addDocument,
373
397
  removeElement: removeDocument,
374
398
  allElements: allDocuments
375
399
  } = use_flat_category_store_default();
376
- const setAction = (0, import_react4.useCallback)((id, action) => {
400
+ const setAction = (0, import_react6.useCallback)((id, action) => {
377
401
  setActions((prevPoints) => {
378
402
  return __spreadProps(__spreadValues({}, prevPoints), {
379
403
  [id]: action
380
404
  });
381
405
  });
382
406
  }, []);
383
- const removeAction = (0, import_react4.useCallback)((id) => {
407
+ const removeAction = (0, import_react6.useCallback)((id) => {
384
408
  setActions((prevPoints) => {
385
409
  const newPoints = __spreadValues({}, prevPoints);
386
410
  delete newPoints[id];
387
411
  return newPoints;
388
412
  });
389
413
  }, []);
390
- const setCoAgentStateRender = (0, import_react4.useCallback)((id, stateRender) => {
414
+ const setCoAgentStateRender = (0, import_react6.useCallback)((id, stateRender) => {
391
415
  setCoAgentStateRenders((prevPoints) => {
392
416
  return __spreadProps(__spreadValues({}, prevPoints), {
393
417
  [id]: stateRender
394
418
  });
395
419
  });
396
420
  }, []);
397
- const removeCoAgentStateRender = (0, import_react4.useCallback)((id) => {
421
+ const removeCoAgentStateRender = (0, import_react6.useCallback)((id) => {
398
422
  setCoAgentStateRenders((prevPoints) => {
399
423
  const newPoints = __spreadValues({}, prevPoints);
400
424
  delete newPoints[id];
401
425
  return newPoints;
402
426
  });
403
427
  }, []);
404
- const getContextString = (0, import_react4.useCallback)(
428
+ const getContextString = (0, import_react6.useCallback)(
405
429
  (documents, categories) => {
406
430
  const documentsString = documents.map((document) => {
407
431
  return `${document.name} (${document.sourceApplication}):
@@ -414,37 +438,37 @@ ${nonDocumentStrings}`;
414
438
  },
415
439
  [printTree]
416
440
  );
417
- const addContext = (0, import_react4.useCallback)(
441
+ const addContext = (0, import_react6.useCallback)(
418
442
  (context, parentId, categories = defaultCopilotContextCategories) => {
419
443
  return addElement(context, categories, parentId);
420
444
  },
421
445
  [addElement]
422
446
  );
423
- const removeContext = (0, import_react4.useCallback)(
447
+ const removeContext = (0, import_react6.useCallback)(
424
448
  (id) => {
425
449
  removeElement(id);
426
450
  },
427
451
  [removeElement]
428
452
  );
429
- const getFunctionCallHandler = (0, import_react4.useCallback)(
453
+ const getFunctionCallHandler = (0, import_react6.useCallback)(
430
454
  (customEntryPoints) => {
431
455
  return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
432
456
  },
433
457
  [actions]
434
458
  );
435
- const getDocumentsContext = (0, import_react4.useCallback)(
459
+ const getDocumentsContext = (0, import_react6.useCallback)(
436
460
  (categories) => {
437
461
  return allDocuments(categories);
438
462
  },
439
463
  [allDocuments]
440
464
  );
441
- const addDocumentContext = (0, import_react4.useCallback)(
465
+ const addDocumentContext = (0, import_react6.useCallback)(
442
466
  (documentPointer, categories = defaultCopilotContextCategories) => {
443
467
  return addDocument(documentPointer, categories);
444
468
  },
445
469
  [addDocument]
446
470
  );
447
- const removeDocumentContext = (0, import_react4.useCallback)(
471
+ const removeDocumentContext = (0, import_react6.useCallback)(
448
472
  (documentId) => {
449
473
  removeDocument(documentId);
450
474
  },
@@ -457,49 +481,60 @@ ${nonDocumentStrings}`;
457
481
  );
458
482
  }
459
483
  }
460
- let cloud = void 0;
461
- if (props.publicApiKey) {
462
- cloud = {
463
- guardrails: {
464
- input: {
465
- restrictToTopic: {
466
- enabled: props.cloudRestrictToTopic ? true : false,
467
- validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
468
- invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
484
+ const copilotApiConfig = (0, import_react6.useMemo)(() => {
485
+ var _a2, _b2;
486
+ let cloud = void 0;
487
+ if (props.publicApiKey) {
488
+ cloud = {
489
+ guardrails: {
490
+ input: {
491
+ restrictToTopic: {
492
+ enabled: props.cloudRestrictToTopic ? true : false,
493
+ validTopics: ((_a2 = props.cloudRestrictToTopic) == null ? void 0 : _a2.validTopics) || [],
494
+ invalidTopics: ((_b2 = props.cloudRestrictToTopic) == null ? void 0 : _b2.invalidTopics) || []
495
+ }
469
496
  }
470
497
  }
471
- }
472
- };
473
- }
474
- const copilotApiConfig = __spreadProps(__spreadValues({
475
- publicApiKey: props.publicApiKey
476
- }, cloud ? { cloud } : {}), {
477
- chatApiEndpoint,
478
- headers: props.headers || {},
479
- properties: props.properties || {},
480
- transcribeAudioUrl: props.transcribeAudioUrl,
481
- textToSpeechUrl: props.textToSpeechUrl,
482
- credentials: props.credentials
483
- });
484
- const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react4.useState)({});
498
+ };
499
+ }
500
+ return __spreadProps(__spreadValues({
501
+ publicApiKey: props.publicApiKey
502
+ }, cloud ? { cloud } : {}), {
503
+ chatApiEndpoint,
504
+ headers: props.headers || {},
505
+ properties: props.properties || {},
506
+ transcribeAudioUrl: props.transcribeAudioUrl,
507
+ textToSpeechUrl: props.textToSpeechUrl,
508
+ credentials: props.credentials
509
+ });
510
+ }, [
511
+ props.publicApiKey,
512
+ props.headers,
513
+ props.properties,
514
+ props.transcribeAudioUrl,
515
+ props.textToSpeechUrl,
516
+ props.credentials,
517
+ props.cloudRestrictToTopic
518
+ ]);
519
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react6.useState)({});
485
520
  const addChatSuggestionConfiguration = (id, suggestion) => {
486
521
  setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
487
522
  };
488
523
  const removeChatSuggestionConfiguration = (id) => {
489
524
  setChatSuggestionConfiguration((prev) => {
490
- const _a3 = prev, { [id]: _ } = _a3, rest = __objRest(_a3, [__restKey(id)]);
525
+ const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
491
526
  return rest;
492
527
  });
493
528
  };
494
- const [coagentStates, setCoagentStates] = (0, import_react4.useState)({});
529
+ const [coagentStates, setCoagentStates] = (0, import_react6.useState)({});
495
530
  let initialAgentSession = null;
496
531
  if (props.agent) {
497
532
  initialAgentSession = {
498
533
  agentName: props.agent
499
534
  };
500
535
  }
501
- const [agentSession, setAgentSession] = (0, import_react4.useState)(initialAgentSession);
502
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
536
+ const [agentSession, setAgentSession] = (0, import_react6.useState)(initialAgentSession);
537
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
503
538
  CopilotContext.Provider,
504
539
  {
505
540
  value: {
@@ -518,8 +553,6 @@ ${nonDocumentStrings}`;
518
553
  addDocumentContext,
519
554
  removeDocumentContext,
520
555
  copilotApiConfig,
521
- messages,
522
- setMessages,
523
556
  isLoading,
524
557
  setIsLoading,
525
558
  chatSuggestionConfiguration,
@@ -533,7 +566,7 @@ ${nonDocumentStrings}`;
533
566
  agentSession,
534
567
  setAgentSession
535
568
  },
536
- children
569
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopilotMessages, { children })
537
570
  }
538
571
  );
539
572
  }