@copilotkit/react-core 1.0.3 → 1.0.4-mme-pre-flush-sync.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 (59) hide show
  1. package/.turbo/turbo-build.log +85 -85
  2. package/CHANGELOG.md +18 -0
  3. package/dist/{chunk-YULKJPY3.mjs → chunk-5FHSUKQL.mjs} +3 -3
  4. package/dist/chunk-5FHSUKQL.mjs.map +1 -0
  5. package/dist/{chunk-YWITCRBI.mjs → chunk-6U3UH3KO.mjs} +3 -3
  6. package/dist/chunk-6U3UH3KO.mjs.map +1 -0
  7. package/dist/{chunk-UMJ5P6TZ.mjs → chunk-CSUYHSF7.mjs} +3 -3
  8. package/dist/chunk-CSUYHSF7.mjs.map +1 -0
  9. package/dist/{chunk-SSQGTCDU.mjs → chunk-GJGTCQJX.mjs} +2 -2
  10. package/dist/{chunk-UJNVZO2U.mjs → chunk-HMSVJLX3.mjs} +2 -2
  11. package/dist/{chunk-UTRWUF3Y.mjs → chunk-LEANZXY5.mjs} +2 -2
  12. package/dist/{chunk-LYC2GBBA.mjs → chunk-QZFDCASV.mjs} +7 -4
  13. package/dist/chunk-QZFDCASV.mjs.map +1 -0
  14. package/dist/components/copilot-provider/copilotkit.js +10 -7
  15. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  16. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  17. package/dist/components/copilot-provider/index.js +10 -7
  18. package/dist/components/copilot-provider/index.js.map +1 -1
  19. package/dist/components/copilot-provider/index.mjs +3 -3
  20. package/dist/components/index.js +10 -7
  21. package/dist/components/index.js.map +1 -1
  22. package/dist/components/index.mjs +3 -3
  23. package/dist/hooks/index.js +2 -2
  24. package/dist/hooks/index.js.map +1 -1
  25. package/dist/hooks/index.mjs +5 -5
  26. package/dist/hooks/use-copilot-action.js +2 -2
  27. package/dist/hooks/use-copilot-action.js.map +1 -1
  28. package/dist/hooks/use-copilot-action.mjs +1 -1
  29. package/dist/hooks/use-copilot-chat.js.map +1 -1
  30. package/dist/hooks/use-copilot-chat.mjs +4 -4
  31. package/dist/hooks/use-flat-category-store.js +2 -2
  32. package/dist/hooks/use-flat-category-store.js.map +1 -1
  33. package/dist/hooks/use-flat-category-store.mjs +1 -1
  34. package/dist/hooks/use-tree.js +2 -2
  35. package/dist/hooks/use-tree.js.map +1 -1
  36. package/dist/hooks/use-tree.mjs +1 -1
  37. package/dist/index.js +20 -17
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +7 -7
  40. package/dist/lib/copilot-task.js.map +1 -1
  41. package/dist/lib/copilot-task.mjs +4 -4
  42. package/dist/lib/index.js.map +1 -1
  43. package/dist/lib/index.mjs +4 -4
  44. package/dist/utils/extract.js.map +1 -1
  45. package/dist/utils/extract.mjs +4 -4
  46. package/dist/utils/index.js.map +1 -1
  47. package/dist/utils/index.mjs +4 -4
  48. package/package.json +5 -6
  49. package/src/components/copilot-provider/copilotkit.tsx +4 -2
  50. package/src/hooks/use-copilot-action.ts +2 -3
  51. package/src/hooks/use-flat-category-store.ts +2 -2
  52. package/src/hooks/use-tree.ts +2 -2
  53. package/dist/chunk-LYC2GBBA.mjs.map +0 -1
  54. package/dist/chunk-UMJ5P6TZ.mjs.map +0 -1
  55. package/dist/chunk-YULKJPY3.mjs.map +0 -1
  56. package/dist/chunk-YWITCRBI.mjs.map +0 -1
  57. /package/dist/{chunk-SSQGTCDU.mjs.map → chunk-GJGTCQJX.mjs.map} +0 -0
  58. /package/dist/{chunk-UJNVZO2U.mjs.map → chunk-HMSVJLX3.mjs.map} +0 -0
  59. /package/dist/{chunk-UTRWUF3Y.mjs.map → chunk-LEANZXY5.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  use_flat_category_store_default
3
- } from "../chunk-YULKJPY3.mjs";
3
+ } from "../chunk-5FHSUKQL.mjs";
4
4
  import "../chunk-SKC7AJIV.mjs";
5
5
  export {
6
6
  use_flat_category_store_default as default
@@ -40,7 +40,7 @@ __export(use_tree_exports, {
40
40
  default: () => use_tree_default
41
41
  });
42
42
  module.exports = __toCommonJS(use_tree_exports);
43
- var import_nanoid = require("nanoid");
43
+ var import_shared = require("@copilotkit/shared");
44
44
  var import_react = require("react");
45
45
  var removeNode = (nodes, id) => {
46
46
  return nodes.reduce((result, node) => {
@@ -125,7 +125,7 @@ var useTree = () => {
125
125
  const [tree, dispatch] = (0, import_react.useReducer)(treeReducer, []);
126
126
  const addElement = (0, import_react.useCallback)(
127
127
  (value, categories, parentId) => {
128
- const newNodeId = (0, import_nanoid.nanoid)();
128
+ const newNodeId = (0, import_shared.randomId)();
129
129
  dispatch({
130
130
  type: "ADD_NODE",
131
131
  value,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-tree.ts"],"sourcesContent":["import { nanoid } from \"nanoid\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, categories: string[], parentId?: TreeNodeId) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (index: number, indentLevel: number): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,\n indentLevel + 1,\n )),\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = nanoid(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n [],\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);\n });\n return output;\n },\n [tree],\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,mBAAwC;AAkCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CAAC,OAAa,SAAmB,aAAgC;AAC/E,MAAI,CAAC,UAAU;AACb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AAU,GAAG;AACf,oBAAU;AAAA,QACZ;AAEA,kBAAU,UAAU,MAAM,GAAG,8BAA8B,OAAO,CAAC,KAAK;AAAA,MAC1E,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO,EAAE,MAAM,YAAY,WAAW,cAAc;AACtD;AAEA,IAAO,mBAAQ;AAEf,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/hooks/use-tree.ts"],"sourcesContent":["import { randomId } from \"@copilotkit/shared\";\nimport { useCallback, useReducer } from \"react\";\n\nexport type TreeNodeId = string;\n\nexport interface TreeNode {\n id: TreeNodeId;\n value: string;\n children: TreeNode[];\n parentId?: TreeNodeId;\n categories: Set<string>;\n}\n\nexport type Tree = TreeNode[];\n\nexport interface UseTreeReturn {\n tree: Tree;\n addElement: (value: string, categories: string[], parentId?: TreeNodeId) => TreeNodeId;\n printTree: (categories: string[]) => string;\n removeElement: (id: TreeNodeId) => void;\n}\n\nconst findNode = (nodes: Tree, id: TreeNodeId): TreeNode | undefined => {\n for (const node of nodes) {\n if (node.id === id) {\n return node;\n }\n const result = findNode(node.children, id);\n if (result) {\n return result;\n }\n }\n return undefined;\n};\n\nconst removeNode = (nodes: Tree, id: TreeNodeId): Tree => {\n return nodes.reduce((result: Tree, node) => {\n if (node.id !== id) {\n const newNode = { ...node, children: removeNode(node.children, id) };\n result.push(newNode);\n }\n return result;\n }, []);\n};\n\nconst addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): Tree => {\n if (!parentId) {\n return [...nodes, newNode];\n }\n return nodes.map((node) => {\n if (node.id === parentId) {\n return { ...node, children: [...node.children, newNode] };\n } else if (node.children.length) {\n return { ...node, children: addNode(node.children, newNode, parentId) };\n }\n return node;\n });\n};\n\nconst treeIndentationRepresentation = (index: number, indentLevel: number): string => {\n if (indentLevel === 0) {\n return (index + 1).toString();\n } else if (indentLevel === 1) {\n return String.fromCharCode(65 + index); // 65 is the ASCII value for 'A'\n } else if (indentLevel === 2) {\n return String.fromCharCode(97 + index); // 97 is the ASCII value for 'a'\n } else {\n return \"-\";\n }\n};\n\nconst printNode = (node: TreeNode, prefix = \"\", indentLevel = 0): string => {\n const indent = \" \".repeat(3).repeat(indentLevel);\n\n const prefixPlusIndentLength = prefix.length + indent.length;\n const subsequentLinesPrefix = \" \".repeat(prefixPlusIndentLength);\n\n const valueLines = node.value.split(\"\\n\");\n\n const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;\n const outputSubsequentLines = valueLines\n .slice(1)\n .map((line) => `${subsequentLinesPrefix}${line}`)\n .join(\"\\n\");\n\n let output = `${outputFirstLine}\\n`;\n if (outputSubsequentLines) {\n output += `${outputSubsequentLines}\\n`;\n }\n\n const childPrePrefix = \" \".repeat(prefix.length);\n\n node.children.forEach(\n (child, index) =>\n (output += printNode(\n child,\n `${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,\n indentLevel + 1,\n )),\n );\n return output;\n};\n\n// Action types\ntype Action =\n | {\n type: \"ADD_NODE\";\n value: string;\n parentId?: string;\n id: string;\n categories: string[];\n }\n | { type: \"REMOVE_NODE\"; id: string };\n\n// Reducer function\nfunction treeReducer(state: Tree, action: Action): Tree {\n switch (action.type) {\n case \"ADD_NODE\": {\n const { value, parentId, id: newNodeId } = action;\n const newNode: TreeNode = {\n id: newNodeId,\n value,\n children: [],\n categories: new Set(action.categories),\n };\n\n try {\n return addNode(state, newNode, parentId);\n } catch (error) {\n console.error(`Error while adding node with id ${newNodeId}: ${error}`);\n return state;\n }\n }\n case \"REMOVE_NODE\":\n return removeNode(state, action.id);\n default:\n return state;\n }\n}\n\n// useTree hook\nconst useTree = (): UseTreeReturn => {\n const [tree, dispatch] = useReducer(treeReducer, []);\n\n const addElement = useCallback(\n (value: string, categories: string[], parentId?: string): TreeNodeId => {\n const newNodeId = randomId(); // Generate new ID outside of dispatch\n dispatch({\n type: \"ADD_NODE\",\n value,\n parentId,\n id: newNodeId,\n categories: categories,\n });\n return newNodeId; // Return the new ID\n },\n [],\n );\n\n const removeElement = useCallback((id: TreeNodeId): void => {\n dispatch({ type: \"REMOVE_NODE\", id });\n }, []);\n\n const printTree = useCallback(\n (categories: string[]): string => {\n const categoriesSet = new Set(categories);\n\n let output = \"\";\n tree.forEach((node, index) => {\n // if the node does not have any of the desired categories, continue to the next node\n if (!setsHaveIntersection(categoriesSet, node.categories)) {\n return;\n }\n\n // add a new line before each node except the first one\n if (index !== 0) {\n output += \"\\n\";\n }\n\n output += printNode(node, `${treeIndentationRepresentation(index, 0)}. `);\n });\n return output;\n },\n [tree],\n );\n\n return { tree, addElement, printTree, removeElement };\n};\n\nexport default useTree;\n\nfunction setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {\n const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];\n\n for (let item of smallerSet) {\n if (largerSet.has(item)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,mBAAwC;AAkCxC,IAAM,aAAa,CAAC,OAAa,OAAyB;AACxD,SAAO,MAAM,OAAO,CAAC,QAAc,SAAS;AAC1C,QAAI,KAAK,OAAO,IAAI;AAClB,YAAM,UAAU,iCAAK,OAAL,EAAW,UAAU,WAAW,KAAK,UAAU,EAAE,EAAE;AACnE,aAAO,KAAK,OAAO;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEA,IAAM,UAAU,CAAC,O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,KAAK,UAAU,GAAG;AACzD;AAAA,QACF;AAGA,YAAI,UAAU,GAAG;AACf,oBAAU;AAAA,QACZ;AAEA,kBAAU,UAAU,MAAM,GAAG,8BAA8B,OAAO,CAAC,KAAK;AAAA,MAC1E,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO,EAAE,MAAM,YAAY,WAAW,cAAc;AACtD;AAEA,IAAO,mBAAQ;AAEf,SAAS,qBAAwB,MAAc,MAAuB;AACpE,QAAM,CAAC,YAAY,SAAS,IAAI,KAAK,QAAQ,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI;AAEnF,WAAS,QAAQ,YAAY;AAC3B,QAAI,UAAU,IAAI,IAAI,GAAG;AACvB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  use_tree_default
3
- } from "../chunk-YWITCRBI.mjs";
3
+ } from "../chunk-6U3UH3KO.mjs";
4
4
  import "../chunk-SKC7AJIV.mjs";
5
5
  export {
6
6
  use_tree_default as default
package/dist/index.js CHANGED
@@ -149,7 +149,7 @@ function returnAndThrowInDebug(value) {
149
149
  }
150
150
 
151
151
  // src/hooks/use-tree.ts
152
- var import_nanoid = require("nanoid");
152
+ var import_shared = require("@copilotkit/shared");
153
153
  var import_react2 = require("react");
154
154
  var removeNode = (nodes, id) => {
155
155
  return nodes.reduce((result, node) => {
@@ -234,7 +234,7 @@ var useTree = () => {
234
234
  const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
235
235
  const addElement = (0, import_react2.useCallback)(
236
236
  (value, categories, parentId) => {
237
- const newNodeId = (0, import_nanoid.nanoid)();
237
+ const newNodeId = (0, import_shared.randomId)();
238
238
  dispatch({
239
239
  type: "ADD_NODE",
240
240
  value,
@@ -280,15 +280,15 @@ function setsHaveIntersection(setA, setB) {
280
280
  }
281
281
 
282
282
  // src/components/copilot-provider/copilotkit.tsx
283
- var import_shared = require("@copilotkit/shared");
283
+ var import_shared3 = require("@copilotkit/shared");
284
284
 
285
285
  // src/hooks/use-flat-category-store.ts
286
- var import_nanoid2 = require("nanoid");
287
286
  var import_react3 = require("react");
287
+ var import_shared2 = require("@copilotkit/shared");
288
288
  var useFlatCategoryStore = () => {
289
289
  const [elements, dispatch] = (0, import_react3.useReducer)(flatCategoryStoreReducer, /* @__PURE__ */ new Map());
290
290
  const addElement = (0, import_react3.useCallback)((value, categories) => {
291
- const newId = (0, import_nanoid2.nanoid)();
291
+ const newId = (0, import_shared2.randomId)();
292
292
  dispatch({
293
293
  type: "ADD_ELEMENT",
294
294
  value,
@@ -358,7 +358,7 @@ function CopilotKit(_a) {
358
358
  "Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
359
359
  );
360
360
  }
361
- const chatApiEndpoint = props.runtimeUrl || import_shared.COPILOT_CLOUD_CHAT_URL;
361
+ const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
362
362
  const [actions, setActions] = (0, import_react4.useState)({});
363
363
  const chatComponentsCache = (0, import_react4.useRef)({});
364
364
  const { addElement, removeElement, printTree } = use_tree_default();
@@ -512,9 +512,12 @@ function entryPointsToFunctionCallHandler(actions) {
512
512
  actionsByFunctionName[action2.name] = action2;
513
513
  }
514
514
  const action = actionsByFunctionName[name];
515
+ let result = void 0;
515
516
  if (action) {
516
- return yield action.handler(args);
517
+ result = yield action.handler(args);
518
+ yield new Promise((resolve) => setTimeout(resolve, 20));
517
519
  }
520
+ return result;
518
521
  });
519
522
  }
520
523
 
@@ -524,7 +527,7 @@ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
524
527
 
525
528
  // src/hooks/use-chat.ts
526
529
  var import_react5 = require("react");
527
- var import_shared2 = require("@copilotkit/shared");
530
+ var import_shared4 = require("@copilotkit/shared");
528
531
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
529
532
  function useChat(options) {
530
533
  const {
@@ -542,7 +545,7 @@ function useChat(options) {
542
545
  const threadIdRef = (0, import_react5.useRef)(null);
543
546
  const runIdRef = (0, import_react5.useRef)(null);
544
547
  const publicApiKey = copilotConfig.publicApiKey;
545
- const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared2.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
548
+ const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
546
549
  const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
547
550
  url: copilotConfig.chatApiEndpoint,
548
551
  publicApiKey: copilotConfig.publicApiKey,
@@ -569,7 +572,7 @@ function useChat(options) {
569
572
  actions: actions.map((action) => ({
570
573
  name: action.name,
571
574
  description: action.description || "",
572
- jsonSchema: JSON.stringify((0, import_shared2.actionParametersToJsonSchema)(action.parameters || []))
575
+ jsonSchema: JSON.stringify((0, import_shared4.actionParametersToJsonSchema)(action.parameters || []))
573
576
  }))
574
577
  },
575
578
  threadId: threadIdRef.current,
@@ -783,10 +786,10 @@ ${additionalInstructions}` : "");
783
786
 
784
787
  // src/hooks/use-copilot-action.ts
785
788
  var import_react7 = require("react");
786
- var import_nanoid3 = require("nanoid");
789
+ var import_shared5 = require("@copilotkit/shared");
787
790
  function useCopilotAction(action, dependencies) {
788
791
  const { setAction, removeAction, actions, chatComponentsCache } = (0, import_react7.useContext)(CopilotContext);
789
- const idRef = (0, import_react7.useRef)((0, import_nanoid3.nanoid)());
792
+ const idRef = (0, import_react7.useRef)((0, import_shared5.randomId)());
790
793
  if (dependencies === void 0) {
791
794
  if (actions[idRef.current]) {
792
795
  actions[idRef.current].handler = action.handler;
@@ -857,7 +860,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
857
860
 
858
861
  // src/lib/copilot-task.ts
859
862
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
860
- var import_shared3 = require("@copilotkit/shared");
863
+ var import_shared6 = require("@copilotkit/shared");
861
864
  var CopilotTask = class {
862
865
  constructor(config) {
863
866
  this.instructions = config.instructions;
@@ -900,7 +903,7 @@ var CopilotTask = class {
900
903
  actions: Object.values(actions).map((action) => ({
901
904
  name: action.name,
902
905
  description: action.description || "",
903
- jsonSchema: JSON.stringify((0, import_shared3.actionParametersToJsonSchema)(action.parameters || []))
906
+ jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
904
907
  }))
905
908
  },
906
909
  messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(messages),
@@ -951,7 +954,7 @@ ${instructions}
951
954
  }
952
955
 
953
956
  // src/utils/extract.ts
954
- var import_shared4 = require("@copilotkit/shared");
957
+ var import_shared7 = require("@copilotkit/shared");
955
958
  var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
956
959
  var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
957
960
  var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
@@ -987,7 +990,7 @@ function extract(_0) {
987
990
  content: makeSystemMessage(contextString, instructions),
988
991
  role: import_runtime_client_gql4.Role.System
989
992
  });
990
- const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
993
+ const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
991
994
  const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
992
995
  url: context.copilotApiConfig.chatApiEndpoint,
993
996
  publicApiKey: context.copilotApiConfig.publicApiKey,
@@ -1001,7 +1004,7 @@ function extract(_0) {
1001
1004
  {
1002
1005
  name: action.name,
1003
1006
  description: action.description || "",
1004
- jsonSchema: JSON.stringify((0, import_shared4.actionParametersToJsonSchema)(action.parameters || []))
1007
+ jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters || []))
1005
1008
  }
1006
1009
  ]
1007
1010
  },