@copilotkit/react-core 0.25.0 → 0.36.0-mme-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/.turbo/turbo-build.log +184 -165
  2. package/CHANGELOG.md +22 -0
  3. package/dist/{chunk-72BJ3A3S.mjs → chunk-2C4UBKRR.mjs} +2 -2
  4. package/dist/{chunk-KTUNGBJF.mjs → chunk-2DKLSG5S.mjs} +2 -2
  5. package/dist/{chunk-4NNFSZOY.mjs → chunk-32T4S22Q.mjs} +3 -3
  6. package/dist/chunk-32T4S22Q.mjs.map +1 -0
  7. package/dist/{chunk-CGT3AVYT.mjs → chunk-7YTDTTX5.mjs} +6 -4
  8. package/dist/chunk-7YTDTTX5.mjs.map +1 -0
  9. package/dist/{chunk-ZIR7KCEA.mjs → chunk-B5CULQRZ.mjs} +2 -2
  10. package/dist/chunk-B5CULQRZ.mjs.map +1 -0
  11. package/dist/chunk-BTJD4QON.mjs +122 -0
  12. package/dist/chunk-BTJD4QON.mjs.map +1 -0
  13. package/dist/chunk-CYDWEPFL.mjs +1 -0
  14. package/dist/{chunk-6ARSX7BW.mjs → chunk-FHGMPFKO.mjs} +2 -2
  15. package/dist/{chunk-PC6FY3LD.mjs → chunk-GJGYNK46.mjs} +2 -2
  16. package/dist/{chunk-7LVVZQRG.mjs → chunk-JWANHQCM.mjs} +22 -6
  17. package/dist/chunk-JWANHQCM.mjs.map +1 -0
  18. package/dist/{chunk-M6WULIFO.mjs → chunk-L3LL6N7J.mjs} +5 -5
  19. package/dist/{chunk-6VF626RG.mjs → chunk-S2YA76YW.mjs} +5 -5
  20. package/dist/{chunk-MRXNTQOX.mjs → chunk-SKC7AJIV.mjs} +3 -1
  21. package/dist/chunk-SKC7AJIV.mjs.map +1 -0
  22. package/dist/{chunk-OWBDHSLH.mjs → chunk-T6UD6AJ2.mjs} +9 -4
  23. package/dist/chunk-T6UD6AJ2.mjs.map +1 -0
  24. package/dist/{chunk-O35YOIHC.mjs → chunk-TW5FS2QT.mjs} +8 -3
  25. package/dist/chunk-TW5FS2QT.mjs.map +1 -0
  26. package/dist/{chunk-VUY2K2DI.mjs → chunk-YWITCRBI.mjs} +2 -2
  27. package/dist/{chunk-MZ5UN3BY.mjs → chunk-ZFS5SQUT.mjs} +2 -2
  28. package/dist/components/copilot-provider/copilotkit-props.d.ts +18 -12
  29. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  30. package/dist/components/copilot-provider/copilotkit.d.ts +0 -20
  31. package/dist/components/copilot-provider/copilotkit.js +24 -3
  32. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  33. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  34. package/dist/components/copilot-provider/index.js +24 -3
  35. package/dist/components/copilot-provider/index.js.map +1 -1
  36. package/dist/components/copilot-provider/index.mjs +4 -4
  37. package/dist/components/index.js +24 -3
  38. package/dist/components/index.js.map +1 -1
  39. package/dist/components/index.mjs +4 -4
  40. package/dist/context/copilot-context.d.ts +14 -0
  41. package/dist/context/copilot-context.js +6 -1
  42. package/dist/context/copilot-context.js.map +1 -1
  43. package/dist/context/copilot-context.mjs +2 -2
  44. package/dist/context/index.d.ts +1 -0
  45. package/dist/context/index.js +6 -1
  46. package/dist/context/index.js.map +1 -1
  47. package/dist/context/index.mjs +2 -2
  48. package/dist/hooks/index.d.ts +1 -0
  49. package/dist/hooks/index.js +10 -3
  50. package/dist/hooks/index.js.map +1 -1
  51. package/dist/hooks/index.mjs +12 -12
  52. package/dist/hooks/use-chat.d.ts +1 -0
  53. package/dist/hooks/use-chat.js +4 -2
  54. package/dist/hooks/use-chat.js.map +1 -1
  55. package/dist/hooks/use-chat.mjs +3 -3
  56. package/dist/hooks/use-copilot-action.js +6 -1
  57. package/dist/hooks/use-copilot-action.js.map +1 -1
  58. package/dist/hooks/use-copilot-action.mjs +3 -3
  59. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  60. package/dist/hooks/use-copilot-chat.js +10 -3
  61. package/dist/hooks/use-copilot-chat.js.map +1 -1
  62. package/dist/hooks/use-copilot-chat.mjs +7 -7
  63. package/dist/hooks/use-copilot-readable.js +6 -1
  64. package/dist/hooks/use-copilot-readable.js.map +1 -1
  65. package/dist/hooks/use-copilot-readable.mjs +3 -3
  66. package/dist/hooks/use-flat-category-store.mjs +1 -1
  67. package/dist/hooks/use-make-copilot-actionable.js +6 -1
  68. package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
  69. package/dist/hooks/use-make-copilot-actionable.mjs +3 -3
  70. package/dist/hooks/use-make-copilot-document-readable.js +6 -1
  71. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  72. package/dist/hooks/use-make-copilot-document-readable.mjs +3 -3
  73. package/dist/hooks/use-make-copilot-readable.js +6 -1
  74. package/dist/hooks/use-make-copilot-readable.js.map +1 -1
  75. package/dist/hooks/use-make-copilot-readable.mjs +3 -3
  76. package/dist/hooks/use-tree.mjs +2 -2
  77. package/dist/index.d.ts +2 -0
  78. package/dist/index.js +143 -8
  79. package/dist/index.js.map +1 -1
  80. package/dist/index.mjs +20 -15
  81. package/dist/lib/copilot-task.d.ts +98 -1
  82. package/dist/lib/copilot-task.js +9 -2
  83. package/dist/lib/copilot-task.js.map +1 -1
  84. package/dist/lib/copilot-task.mjs +6 -6
  85. package/dist/lib/index.d.ts +1 -0
  86. package/dist/lib/index.js +9 -2
  87. package/dist/lib/index.js.map +1 -1
  88. package/dist/lib/index.mjs +6 -6
  89. package/dist/openai-assistants/hooks/index.js +6 -1
  90. package/dist/openai-assistants/hooks/index.js.map +1 -1
  91. package/dist/openai-assistants/hooks/index.mjs +6 -6
  92. package/dist/openai-assistants/hooks/use-assistants.mjs +2 -2
  93. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js +6 -1
  94. package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
  95. package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +6 -6
  96. package/dist/openai-assistants/index.js +6 -1
  97. package/dist/openai-assistants/index.js.map +1 -1
  98. package/dist/openai-assistants/index.mjs +6 -6
  99. package/dist/openai-assistants/utils/index.mjs +2 -2
  100. package/dist/openai-assistants/utils/process-message-stream.mjs +2 -2
  101. package/dist/types/chat-suggestion-configuration.d.ts +22 -0
  102. package/dist/types/chat-suggestion-configuration.js +19 -0
  103. package/dist/types/chat-suggestion-configuration.js.map +1 -0
  104. package/dist/types/chat-suggestion-configuration.mjs +1 -0
  105. package/dist/types/chat-suggestion-configuration.mjs.map +1 -0
  106. package/dist/types/index.d.ts +1 -0
  107. package/dist/types/index.js.map +1 -1
  108. package/dist/utils/extract.d.ts +37 -0
  109. package/dist/utils/extract.js +245 -0
  110. package/dist/utils/extract.js.map +1 -0
  111. package/dist/utils/extract.mjs +15 -0
  112. package/dist/utils/extract.mjs.map +1 -0
  113. package/dist/utils/fetch-chat-completion.d.ts +8 -1
  114. package/dist/utils/fetch-chat-completion.js +4 -2
  115. package/dist/utils/fetch-chat-completion.js.map +1 -1
  116. package/dist/utils/fetch-chat-completion.mjs +2 -2
  117. package/dist/utils/index.d.ts +9 -0
  118. package/dist/utils/index.js +267 -0
  119. package/dist/utils/index.js.map +1 -0
  120. package/dist/utils/index.mjs +23 -0
  121. package/dist/utils/index.mjs.map +1 -0
  122. package/package.json +4 -4
  123. package/src/components/copilot-provider/copilotkit-props.tsx +20 -12
  124. package/src/components/copilot-provider/copilotkit.tsx +62 -21
  125. package/src/context/copilot-context.tsx +24 -1
  126. package/src/hooks/use-chat.ts +2 -2
  127. package/src/hooks/use-copilot-readable.ts +94 -0
  128. package/src/index.tsx +1 -6
  129. package/src/lib/copilot-task.ts +97 -1
  130. package/src/types/chat-suggestion-configuration.ts +23 -0
  131. package/src/types/index.ts +1 -0
  132. package/src/utils/extract.ts +164 -0
  133. package/src/utils/fetch-chat-completion.ts +5 -1
  134. package/src/utils/index.ts +8 -0
  135. package/typedoc.json +4 -0
  136. package/dist/chunk-4NNFSZOY.mjs.map +0 -1
  137. package/dist/chunk-7LVVZQRG.mjs.map +0 -1
  138. package/dist/chunk-CGT3AVYT.mjs.map +0 -1
  139. package/dist/chunk-O35YOIHC.mjs.map +0 -1
  140. package/dist/chunk-OWBDHSLH.mjs.map +0 -1
  141. package/dist/chunk-ZIR7KCEA.mjs.map +0 -1
  142. /package/dist/{chunk-72BJ3A3S.mjs.map → chunk-2C4UBKRR.mjs.map} +0 -0
  143. /package/dist/{chunk-KTUNGBJF.mjs.map → chunk-2DKLSG5S.mjs.map} +0 -0
  144. /package/dist/{chunk-MRXNTQOX.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
  145. /package/dist/{chunk-6ARSX7BW.mjs.map → chunk-FHGMPFKO.mjs.map} +0 -0
  146. /package/dist/{chunk-PC6FY3LD.mjs.map → chunk-GJGYNK46.mjs.map} +0 -0
  147. /package/dist/{chunk-M6WULIFO.mjs.map → chunk-L3LL6N7J.mjs.map} +0 -0
  148. /package/dist/{chunk-6VF626RG.mjs.map → chunk-S2YA76YW.mjs.map} +0 -0
  149. /package/dist/{chunk-VUY2K2DI.mjs.map → chunk-YWITCRBI.mjs.map} +0 -0
  150. /package/dist/{chunk-MZ5UN3BY.mjs.map → chunk-ZFS5SQUT.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ var __spreadValues = (a, b) => {
23
23
  return a;
24
24
  };
25
25
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __restKey = (key) => typeof key === "symbol" ? key : key + "";
26
27
  var __objRest = (source, exclude) => {
27
28
  var target = {};
28
29
  for (var prop in source)
@@ -84,6 +85,7 @@ __export(src_exports, {
84
85
  CopilotKit: () => CopilotKit,
85
86
  CopilotTask: () => CopilotTask,
86
87
  defaultCopilotContextCategories: () => defaultCopilotContextCategories,
88
+ extract: () => extract,
87
89
  fetchAndDecodeChatCompletion: () => fetchAndDecodeChatCompletion,
88
90
  fetchAndDecodeChatCompletionAsText: () => fetchAndDecodeChatCompletionAsText,
89
91
  fetchChatCompletion: () => fetchChatCompletion,
@@ -137,7 +139,12 @@ var emptyCopilotContext = {
137
139
  get body() {
138
140
  return {};
139
141
  }
140
- }()
142
+ }(),
143
+ chatSuggestionConfiguration: {},
144
+ addChatSuggestionConfiguration: () => {
145
+ },
146
+ removeChatSuggestionConfiguration: () => {
147
+ }
141
148
  };
142
149
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
143
150
  function useCopilotContext() {
@@ -462,8 +469,20 @@ ${nonDocumentStrings}`;
462
469
  chatApiEndpoint,
463
470
  chatApiEndpointV2: `${props.url}/v2`,
464
471
  headers: props.headers || {},
465
- body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps)
472
+ body: __spreadValues(__spreadValues({}, props.body), props.backendOnlyProps),
473
+ transcribeAudioUrl: props.transcribeAudioUrl,
474
+ textToSpeechUrl: props.textToSpeechUrl
466
475
  });
476
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react4.useState)({});
477
+ const addChatSuggestionConfiguration = (id, suggestion) => {
478
+ setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
479
+ };
480
+ const removeChatSuggestionConfiguration = (id) => {
481
+ setChatSuggestionConfiguration((prev) => {
482
+ const _a3 = prev, { [id]: _ } = _a3, rest = __objRest(_a3, [__restKey(id)]);
483
+ return rest;
484
+ });
485
+ };
467
486
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
468
487
  CopilotContext.Provider,
469
488
  {
@@ -482,7 +501,10 @@ ${nonDocumentStrings}`;
482
501
  removeDocumentContext,
483
502
  copilotApiConfig,
484
503
  messages,
485
- setMessages
504
+ setMessages,
505
+ chatSuggestionConfiguration,
506
+ addChatSuggestionConfiguration,
507
+ removeChatSuggestionConfiguration
486
508
  },
487
509
  children
488
510
  }
@@ -528,7 +550,8 @@ function fetchChatCompletion(_0) {
528
550
  temperature,
529
551
  headers,
530
552
  body,
531
- signal
553
+ signal,
554
+ toolChoice
532
555
  }) {
533
556
  temperature || (temperature = 0.5);
534
557
  tools || (tools = []);
@@ -536,6 +559,7 @@ function fetchChatCompletion(_0) {
536
559
  const { content, role, name, function_call } = message;
537
560
  return { content, role, name, function_call };
538
561
  });
562
+ toolChoice || (toolChoice = "auto");
539
563
  const response = yield fetch(copilotConfig.chatApiEndpoint, {
540
564
  method: "POST",
541
565
  headers: __spreadValues(__spreadValues({
@@ -545,7 +569,7 @@ function fetchChatCompletion(_0) {
545
569
  model,
546
570
  messages: cleanedMessages,
547
571
  stream: true
548
- }, 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 } : {})),
572
+ }, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: toolChoice } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), excludeBackendOnlyProps(copilotConfig)), body ? __spreadValues({}, body) : {}), copilotConfig.cloud ? { cloud: copilotConfig.cloud } : {})),
549
573
  signal
550
574
  });
551
575
  return response;
@@ -780,7 +804,7 @@ function useChat(options) {
780
804
  // src/hooks/use-copilot-chat.ts
781
805
  function useCopilotChat(_a) {
782
806
  var _b = _a, {
783
- makeSystemMessage,
807
+ makeSystemMessage: makeSystemMessage2,
784
808
  additionalInstructions
785
809
  } = _b, options = __objRest(_b, [
786
810
  "makeSystemMessage",
@@ -795,14 +819,14 @@ function useCopilotChat(_a) {
795
819
  setMessages
796
820
  } = (0, import_react6.useContext)(CopilotContext);
797
821
  const systemMessage = (0, import_react6.useMemo)(() => {
798
- const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
822
+ const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
799
823
  const contextString = getContextString([], defaultCopilotContextCategories);
800
824
  return {
801
825
  id: "system",
802
826
  content: systemMessageMaker(contextString, additionalInstructions),
803
827
  role: "system"
804
828
  };
805
- }, [getContextString, makeSystemMessage, additionalInstructions]);
829
+ }, [getContextString, makeSystemMessage2, additionalInstructions]);
806
830
  const functionDescriptions = (0, import_react6.useMemo)(() => {
807
831
  return getChatCompletionFunctionDescriptions();
808
832
  }, [getChatCompletionFunctionDescriptions]);
@@ -1119,6 +1143,11 @@ var CopilotTask = class {
1119
1143
  this.includeCopilotReadable = config.includeCopilotReadable !== false;
1120
1144
  this.includeCopilotActions = config.includeCopilotActions !== false && config.includeCopilotActionable !== false;
1121
1145
  }
1146
+ /**
1147
+ * Run the task.
1148
+ * @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
1149
+ * @param data The data to use for the task.
1150
+ */
1122
1151
  run(context, data) {
1123
1152
  return __async(this, null, function* () {
1124
1153
  const entryPoints = this.includeCopilotActions ? Object.assign({}, context.entryPoints) : {};
@@ -1198,12 +1227,118 @@ ${instructions}
1198
1227
  \`\`\`
1199
1228
  `;
1200
1229
  }
1230
+
1231
+ // src/utils/extract.ts
1232
+ var import_shared6 = require("@copilotkit/shared");
1233
+ var import_untruncate_json2 = __toESM(require("untruncate-json"));
1234
+ function extract(_0) {
1235
+ return __async(this, arguments, function* ({
1236
+ context,
1237
+ instructions,
1238
+ parameters,
1239
+ include,
1240
+ data,
1241
+ abortSignal,
1242
+ stream
1243
+ }) {
1244
+ var _a, _b;
1245
+ const { messages } = context;
1246
+ const action = {
1247
+ name: "extract",
1248
+ parameters,
1249
+ handler: (args) => {
1250
+ }
1251
+ };
1252
+ const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
1253
+ const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
1254
+ let contextString = "";
1255
+ if (data) {
1256
+ contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
1257
+ }
1258
+ if (includeReadable) {
1259
+ contextString += context.getContextString([], defaultCopilotContextCategories);
1260
+ }
1261
+ const systemMessage = {
1262
+ id: "system",
1263
+ content: makeSystemMessage(contextString, instructions),
1264
+ role: "system"
1265
+ };
1266
+ const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
1267
+ const response = yield fetchAndDecodeChatCompletion({
1268
+ copilotConfig: context.copilotApiConfig,
1269
+ messages: includeMessages ? [systemMessage, ...messages] : [systemMessage],
1270
+ tools: context.getChatCompletionFunctionDescriptions({ extract: action }),
1271
+ headers,
1272
+ body: context.copilotApiConfig.body,
1273
+ toolChoice: { type: "function", function: { name: "extract" } },
1274
+ signal: abortSignal
1275
+ });
1276
+ if (!response.events) {
1277
+ throw new Error("extract() failed: Could not fetch chat completion");
1278
+ }
1279
+ const reader = response.events.getReader();
1280
+ let isInitial = true;
1281
+ while (true) {
1282
+ const { done, value } = yield reader.read();
1283
+ if (done) {
1284
+ break;
1285
+ }
1286
+ if (value.type === "partial") {
1287
+ try {
1288
+ let partialArguments = JSON.parse((0, import_untruncate_json2.default)(value.arguments));
1289
+ stream == null ? void 0 : stream({
1290
+ status: isInitial ? "initial" : "inProgress",
1291
+ args: partialArguments
1292
+ });
1293
+ isInitial = false;
1294
+ } catch (e) {
1295
+ }
1296
+ }
1297
+ if (value.type === "function") {
1298
+ stream == null ? void 0 : stream({
1299
+ status: "complete",
1300
+ args: value.arguments
1301
+ });
1302
+ return value.arguments;
1303
+ }
1304
+ }
1305
+ throw new Error("extract() failed: No function call occurred");
1306
+ });
1307
+ }
1308
+ function makeSystemMessage(contextString, instructions) {
1309
+ return `
1310
+ Please act as an efficient, competent, conscientious, and industrious professional assistant.
1311
+
1312
+ Help 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.
1313
+ Always be polite and respectful, and prefer brevity over verbosity.
1314
+
1315
+ The user has provided you with the following context:
1316
+ \`\`\`
1317
+ ${contextString}
1318
+ \`\`\`
1319
+
1320
+ They have also provided you with a function you MUST call to initiate actions on their behalf.
1321
+
1322
+ Please assist them as best you can.
1323
+
1324
+ This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
1325
+
1326
+ The user has given you the following task to complete:
1327
+
1328
+ \`\`\`
1329
+ ${instructions}
1330
+ \`\`\`
1331
+
1332
+ Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
1333
+ `;
1334
+ }
1201
1335
  // Annotate the CommonJS export names for ESM import in node:
1202
1336
  0 && (module.exports = {
1203
1337
  CopilotContext,
1204
1338
  CopilotKit,
1205
1339
  CopilotTask,
1206
1340
  defaultCopilotContextCategories,
1341
+ extract,
1207
1342
  fetchAndDecodeChatCompletion,
1208
1343
  fetchAndDecodeChatCompletionAsText,
1209
1344
  fetchChatCompletion,