@copilotkit/react-core 1.1.3-feat-runtime-remote-actions.2 → 1.2.0

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 (126) hide show
  1. package/CHANGELOG.md +6 -21
  2. package/dist/chunk-5JB4B2SV.mjs +1 -0
  3. package/dist/{chunk-VCEOT4GG.mjs → chunk-AIW2RAN2.mjs} +6 -35
  4. package/dist/chunk-AIW2RAN2.mjs.map +1 -0
  5. package/dist/{chunk-RBNULK3U.mjs → chunk-CFCRJA63.mjs} +5 -39
  6. package/dist/chunk-CFCRJA63.mjs.map +1 -0
  7. package/dist/{chunk-3U22BXKC.mjs → chunk-EVK5346D.mjs} +3 -4
  8. package/dist/chunk-EVK5346D.mjs.map +1 -0
  9. package/dist/{chunk-A37GANOW.mjs → chunk-GSL4ZHUB.mjs} +4 -4
  10. package/dist/chunk-GSL4ZHUB.mjs.map +1 -0
  11. package/dist/{chunk-TCZBK3HZ.mjs → chunk-HUC6EZVP.mjs} +4 -7
  12. package/dist/chunk-HUC6EZVP.mjs.map +1 -0
  13. package/dist/{chunk-CODXG6KU.mjs → chunk-LB53QWLY.mjs} +2 -2
  14. package/dist/{chunk-J2YXDQHR.mjs → chunk-LB7ULLSU.mjs} +3 -14
  15. package/dist/chunk-LB7ULLSU.mjs.map +1 -0
  16. package/dist/{chunk-RWPGGPW5.mjs → chunk-PZOEBYWP.mjs} +11 -63
  17. package/dist/chunk-PZOEBYWP.mjs.map +1 -0
  18. package/dist/{chunk-326LK7LX.mjs → chunk-QR4XKQOA.mjs} +2 -2
  19. package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -4
  20. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  21. package/dist/components/copilot-provider/copilotkit.js +5 -50
  22. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  23. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  24. package/dist/components/copilot-provider/index.js +5 -50
  25. package/dist/components/copilot-provider/index.js.map +1 -1
  26. package/dist/components/copilot-provider/index.mjs +2 -2
  27. package/dist/components/index.js +5 -50
  28. package/dist/components/index.js.map +1 -1
  29. package/dist/components/index.mjs +2 -2
  30. package/dist/context/copilot-context.d.ts +2 -21
  31. package/dist/context/copilot-context.js +2 -13
  32. package/dist/context/copilot-context.js.map +1 -1
  33. package/dist/context/copilot-context.mjs +1 -1
  34. package/dist/context/index.d.ts +0 -2
  35. package/dist/context/index.js +2 -13
  36. package/dist/context/index.js.map +1 -1
  37. package/dist/context/index.mjs +1 -1
  38. package/dist/hooks/index.d.ts +0 -4
  39. package/dist/hooks/index.js +21 -224
  40. package/dist/hooks/index.js.map +1 -1
  41. package/dist/hooks/index.mjs +8 -17
  42. package/dist/hooks/use-chat.d.ts +4 -26
  43. package/dist/hooks/use-chat.js +9 -58
  44. package/dist/hooks/use-chat.js.map +1 -1
  45. package/dist/hooks/use-chat.mjs +1 -1
  46. package/dist/hooks/use-copilot-action.js +4 -15
  47. package/dist/hooks/use-copilot-action.js.map +1 -1
  48. package/dist/hooks/use-copilot-action.mjs +2 -2
  49. package/dist/hooks/use-copilot-chat.js +13 -101
  50. package/dist/hooks/use-copilot-chat.js.map +1 -1
  51. package/dist/hooks/use-copilot-chat.mjs +4 -4
  52. package/dist/hooks/use-copilot-readable.js +2 -13
  53. package/dist/hooks/use-copilot-readable.js.map +1 -1
  54. package/dist/hooks/use-copilot-readable.mjs +2 -2
  55. package/dist/hooks/use-make-copilot-document-readable.js +2 -13
  56. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  57. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  58. package/dist/index.d.ts +0 -4
  59. package/dist/index.js +31 -268
  60. package/dist/index.js.map +1 -1
  61. package/dist/index.mjs +12 -20
  62. package/dist/lib/copilot-task.d.ts +0 -2
  63. package/dist/lib/copilot-task.js +1 -1
  64. package/dist/lib/copilot-task.js.map +1 -1
  65. package/dist/lib/copilot-task.mjs +3 -3
  66. package/dist/lib/index.d.ts +0 -2
  67. package/dist/lib/index.js +1 -1
  68. package/dist/lib/index.js.map +1 -1
  69. package/dist/lib/index.mjs +3 -3
  70. package/dist/utils/extract.d.ts +0 -2
  71. package/dist/utils/extract.js +1 -1
  72. package/dist/utils/extract.js.map +1 -1
  73. package/dist/utils/extract.mjs +3 -3
  74. package/dist/utils/index.d.ts +0 -2
  75. package/dist/utils/index.js +1 -1
  76. package/dist/utils/index.js.map +1 -1
  77. package/dist/utils/index.mjs +3 -3
  78. package/package.json +5 -5
  79. package/src/components/copilot-provider/copilotkit-props.tsx +0 -5
  80. package/src/components/copilot-provider/copilotkit.tsx +3 -45
  81. package/src/context/copilot-context.tsx +2 -39
  82. package/src/hooks/index.ts +0 -2
  83. package/src/hooks/use-chat.ts +11 -111
  84. package/src/hooks/use-copilot-action.ts +2 -2
  85. package/src/hooks/use-copilot-chat.ts +0 -31
  86. package/src/lib/copilot-task.ts +1 -2
  87. package/src/utils/extract.ts +2 -7
  88. package/dist/chunk-3U22BXKC.mjs.map +0 -1
  89. package/dist/chunk-A37GANOW.mjs.map +0 -1
  90. package/dist/chunk-BWYAGPEF.mjs +0 -1
  91. package/dist/chunk-J2YXDQHR.mjs.map +0 -1
  92. package/dist/chunk-Q4TTTAXQ.mjs +0 -87
  93. package/dist/chunk-Q4TTTAXQ.mjs.map +0 -1
  94. package/dist/chunk-RBNULK3U.mjs.map +0 -1
  95. package/dist/chunk-RWPGGPW5.mjs.map +0 -1
  96. package/dist/chunk-STUXJ3BN.mjs +0 -44
  97. package/dist/chunk-STUXJ3BN.mjs.map +0 -1
  98. package/dist/chunk-TCZBK3HZ.mjs.map +0 -1
  99. package/dist/chunk-VCEOT4GG.mjs.map +0 -1
  100. package/dist/hooks/use-coagent-action.d.ts +0 -5
  101. package/dist/hooks/use-coagent-action.js +0 -156
  102. package/dist/hooks/use-coagent-action.js.map +0 -1
  103. package/dist/hooks/use-coagent-action.mjs +0 -9
  104. package/dist/hooks/use-coagent-action.mjs.map +0 -1
  105. package/dist/hooks/use-coagent.d.ts +0 -27
  106. package/dist/hooks/use-coagent.js +0 -219
  107. package/dist/hooks/use-coagent.js.map +0 -1
  108. package/dist/hooks/use-coagent.mjs +0 -10
  109. package/dist/hooks/use-coagent.mjs.map +0 -1
  110. package/dist/types/coagent-action.d.ts +0 -17
  111. package/dist/types/coagent-action.js +0 -19
  112. package/dist/types/coagent-action.js.map +0 -1
  113. package/dist/types/coagent-action.mjs +0 -1
  114. package/dist/types/coagent-action.mjs.map +0 -1
  115. package/dist/types/coagent-state.d.ts +0 -11
  116. package/dist/types/coagent-state.js +0 -19
  117. package/dist/types/coagent-state.js.map +0 -1
  118. package/dist/types/coagent-state.mjs +0 -1
  119. package/dist/types/coagent-state.mjs.map +0 -1
  120. package/src/hooks/use-coagent-action.ts +0 -44
  121. package/src/hooks/use-coagent.ts +0 -133
  122. package/src/types/coagent-action.ts +0 -17
  123. package/src/types/coagent-state.ts +0 -9
  124. /package/dist/{chunk-BWYAGPEF.mjs.map → chunk-5JB4B2SV.mjs.map} +0 -0
  125. /package/dist/{chunk-CODXG6KU.mjs.map → chunk-LB53QWLY.mjs.map} +0 -0
  126. /package/dist/{chunk-326LK7LX.mjs.map → chunk-QR4XKQOA.mjs.map} +0 -0
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
- var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
36
- };
37
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
- // If the importer is in node compatibility mode or this is not an ESM
39
- // file that has been converted to a CommonJS file using a Babel-
40
- // compatible transform (i.e. "__esModule" has not been set), then set
41
- // "default" to the CommonJS "module.exports" for node compatibility.
42
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
- mod
44
- ));
45
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
- var __async = (__this, __arguments, generator) => {
47
- return new Promise((resolve, reject) => {
48
- var fulfilled = (value) => {
49
- try {
50
- step(generator.next(value));
51
- } catch (e) {
52
- reject(e);
53
- }
54
- };
55
- var rejected = (value) => {
56
- try {
57
- step(generator.throw(value));
58
- } catch (e) {
59
- reject(e);
60
- }
61
- };
62
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
- step((generator = generator.apply(__this, __arguments)).next());
64
- });
65
- };
66
-
67
- // src/hooks/use-coagent.ts
68
- var use_coagent_exports = {};
69
- __export(use_coagent_exports, {
70
- useCoAgent: () => useCoAgent
71
- });
72
- module.exports = __toCommonJS(use_coagent_exports);
73
- var import_react2 = require("react");
74
-
75
- // src/context/copilot-context.tsx
76
- var import_react = __toESM(require("react"));
77
- var emptyCopilotContext = {
78
- actions: {},
79
- setAction: () => {
80
- },
81
- removeAction: () => {
82
- },
83
- coagentActions: {},
84
- setCoagentAction: () => {
85
- },
86
- removeCoagentAction: () => {
87
- },
88
- chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
89
- getContextString: (documents, categories) => returnAndThrowInDebug(""),
90
- addContext: () => "",
91
- removeContext: () => {
92
- },
93
- getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
94
- })),
95
- messages: [],
96
- setMessages: () => returnAndThrowInDebug([]),
97
- isLoading: false,
98
- setIsLoading: () => returnAndThrowInDebug(false),
99
- chatInstructions: "",
100
- setChatInstructions: () => returnAndThrowInDebug(""),
101
- getDocumentsContext: (categories) => returnAndThrowInDebug([]),
102
- addDocumentContext: () => returnAndThrowInDebug(""),
103
- removeDocumentContext: () => {
104
- },
105
- copilotApiConfig: new class {
106
- get chatApiEndpoint() {
107
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
108
- }
109
- get headers() {
110
- return {};
111
- }
112
- get body() {
113
- return {};
114
- }
115
- }(),
116
- chatSuggestionConfiguration: {},
117
- addChatSuggestionConfiguration: () => {
118
- },
119
- removeChatSuggestionConfiguration: () => {
120
- },
121
- showDevConsole: "auto",
122
- coagentStates: {},
123
- setCoagentStates: () => {
124
- },
125
- agentSession: null,
126
- setAgentSession: () => {
127
- }
128
- };
129
- var CopilotContext = import_react.default.createContext(emptyCopilotContext);
130
- function useCopilotContext() {
131
- const context = import_react.default.useContext(CopilotContext);
132
- if (context === emptyCopilotContext) {
133
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
134
- }
135
- return context;
136
- }
137
- function returnAndThrowInDebug(value) {
138
- throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
139
- return value;
140
- }
141
-
142
- // src/hooks/use-coagent.ts
143
- function useCoAgent(options) {
144
- const isExternalStateManagement = (options2) => {
145
- return "state" in options2 && "setState" in options2;
146
- };
147
- const { name } = options;
148
- const isInternalStateManagementWithInitial = (options2) => {
149
- return "initialState" in options2;
150
- };
151
- const { coagentStates, setCoagentStates } = useCopilotContext();
152
- const getCoagentState = (coagentStates2, name2) => {
153
- if (coagentStates2[name2]) {
154
- return coagentStates2[name2];
155
- } else {
156
- return {
157
- name: name2,
158
- state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
159
- running: false,
160
- active: false,
161
- threadId: void 0,
162
- nodeName: void 0,
163
- runId: void 0
164
- };
165
- }
166
- };
167
- const setState = (newState) => {
168
- setCoagentStates((prevAgentStates) => {
169
- let coagentState2 = getCoagentState(prevAgentStates, name);
170
- const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
171
- return __spreadProps(__spreadValues({}, prevAgentStates), {
172
- [name]: __spreadProps(__spreadValues({}, coagentState2), {
173
- state: updatedState
174
- })
175
- });
176
- });
177
- };
178
- const coagentState = getCoagentState(coagentStates, name);
179
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
180
- (0, import_react2.useEffect)(() => {
181
- if (isExternalStateManagement(options)) {
182
- setState(options.state);
183
- } else if (coagentStates[name] === void 0) {
184
- setState(options.initialState === void 0 ? {} : options.initialState);
185
- }
186
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
187
- return {
188
- name,
189
- nodeName: coagentState.nodeName,
190
- state,
191
- setState,
192
- running: coagentState.running,
193
- start: () => {
194
- startAgent(name);
195
- },
196
- stop: () => {
197
- stopAgent(name);
198
- }
199
- };
200
- }
201
- function startAgent(name) {
202
- const { setAgentSession } = useCopilotContext();
203
- setAgentSession({
204
- agentName: name
205
- });
206
- }
207
- function stopAgent(name) {
208
- const { agentSession, setAgentSession } = useCopilotContext();
209
- if (agentSession && agentSession.agentName === name) {
210
- setAgentSession(null);
211
- } else {
212
- console.warn(`No agent session found for ${name}`);
213
- }
214
- }
215
- // Annotate the CommonJS export names for ESM import in node:
216
- 0 && (module.exports = {
217
- useCoAgent
218
- });
219
- //# sourceMappingURL=use-coagent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/hooks/use-coagent.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useCopilotContext } from \"../context\";\nimport { CoagentState } from \"../types/coagent-state\";\n\ninterface WithInternalStateManagementAndInitial<T> {\n name: string;\n initialState: T;\n}\n\ninterface WithInternalStateManagement {\n name: string;\n initialState?: any; // Optional initialState with default type any\n}\n\ninterface WithExternalStateManagement<T> {\n name: string;\n state: T;\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n}\n\ntype UseCoagentOptions<T> =\n | WithInternalStateManagementAndInitial<T>\n | WithInternalStateManagement\n | WithExternalStateManagement<T>;\n\nexport interface UseCoagentReturnType<T> {\n name: string;\n nodeName?: string;\n threadId?: string;\n running: boolean;\n state: T;\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n start: () => void;\n stop: () => void;\n}\n\nexport function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {\n const isExternalStateManagement = (\n options: UseCoagentOptions<T>,\n ): options is WithExternalStateManagement<T> => {\n return \"state\" in options && \"setState\" in options;\n };\n\n const { name } = options;\n\n const isInternalStateManagementWithInitial = (\n options: UseCoagentOptions<T>,\n ): options is WithInternalStateManagementAndInitial<T> => {\n return \"initialState\" in options;\n };\n\n const { coagentStates, setCoagentStates } = useCopilotContext();\n\n const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {\n if (coagentStates[name]) {\n return coagentStates[name];\n } else {\n return {\n name,\n state: isInternalStateManagementWithInitial(options) ? options.initialState : {},\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n };\n }\n };\n\n // if we manage state internally, we need to provide a function to set the state\n const setState = (newState: T | ((prevState: T | undefined) => T)) => {\n setCoagentStates((prevAgentStates) => {\n let coagentState: CoagentState = getCoagentState(prevAgentStates, name);\n\n const updatedState =\n typeof newState === \"function\" ? (newState as Function)(coagentState.state) : newState;\n\n return {\n ...prevAgentStates,\n [name]: {\n ...coagentState,\n state: updatedState,\n },\n };\n });\n };\n\n const coagentState = getCoagentState(coagentStates, name);\n\n const state = isExternalStateManagement(options) ? options.state : coagentState.state;\n\n // Sync internal state with external state if state management is external\n useEffect(() => {\n if (isExternalStateManagement(options)) {\n setState(options.state);\n } else if (coagentStates[name] === undefined) {\n setState(options.initialState === undefined ? {} : options.initialState);\n }\n }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined]);\n\n // Return the state and setState function\n return {\n name,\n nodeName: coagentState.nodeName,\n state,\n setState,\n running: coagentState.running,\n start: () => {\n startAgent(name);\n },\n stop: () => {\n stopAgent(name);\n },\n };\n}\n\nfunction startAgent(name: string) {\n const { setAgentSession } = useCopilotContext();\n setAgentSession({\n agentName: name,\n });\n}\n\nfunction stopAgent(name: string) {\n const { agentSession, setAgentSession } = useCopilotContext();\n if (agentSession && agentSession.agentName === name) {\n setAgentSession(null);\n } else {\n console.warn(`No agent session found for ${name}`);\n }\n}\n\n// <CopilotKit agent=\"lockedInAgentName\" />\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoagentAction, CoagentActionRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n}\n\nexport type InChatRenderFunction = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoagentActionRenderProps<any>,\n) => string | JSX.Element;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coagentActions: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coagentActions: Record<string, CoagentAction<any>>;\n setCoagentAction: (id: string, action: CoagentAction<any>) => void;\n removeCoagentAction: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coagentActions: {},\n setCoagentAction: () => {},\n removeCoagentAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coagentActions: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n\n agentSession: null,\n setAgentSession: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAA0B;;;ACG1B,mBAAkB;AA2IlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,gBAAgB,CAAC;AAAA,EACjB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,qBAAqB,MAAM;AAAA,EAAC;AAAA,EAE5B,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,EAAE,EAAE;AAAA,EACpE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,WAAW;AAAA,EACX,cAAc,M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;AAEA,SAAS,WAAW,MAAc;AAChC,QAAM,EAAE,gBAAgB,IAAI,kBAAkB;AAC9C,kBAAgB;AAAA,IACd,WAAW;AAAA,EACb,CAAC;AACH;AAEA,SAAS,UAAU,MAAc;AAC/B,QAAM,EAAE,cAAc,gBAAgB,IAAI,kBAAkB;AAC5D,MAAI,gBAAgB,aAAa,cAAc,MAAM;AACnD,oBAAgB,IAAI;AAAA,EACtB,OAAO;AACL,YAAQ,KAAK,8BAA8B,MAAM;AAAA,EACnD;AACF;","names":["import_react","React","options","coagentStates","name","coagentState"]}
@@ -1,10 +0,0 @@
1
- import {
2
- useCoAgent
3
- } from "../chunk-Q4TTTAXQ.mjs";
4
- import "../chunk-VNRDQJXW.mjs";
5
- import "../chunk-J2YXDQHR.mjs";
6
- import "../chunk-SKC7AJIV.mjs";
7
- export {
8
- useCoAgent
9
- };
10
- //# sourceMappingURL=use-coagent.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,17 +0,0 @@
1
- type CoagentActionRenderProps<T> = {
2
- state: T;
3
- nodeName: string;
4
- status: "inProgress" | "complete";
5
- };
6
- type CoagentActionHandlerArguments<T> = {
7
- nodeName: string;
8
- state: T;
9
- };
10
- type CoagentAction<T = any> = {
11
- name: string;
12
- nodeName?: string;
13
- handler?: (props: CoagentActionHandlerArguments<T>) => void | Promise<void>;
14
- render?: ((props: CoagentActionRenderProps<T>) => string | React.ReactElement) | string;
15
- };
16
-
17
- export { CoagentAction, CoagentActionHandlerArguments, CoagentActionRenderProps };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/types/coagent-action.ts
17
- var coagent_action_exports = {};
18
- module.exports = __toCommonJS(coagent_action_exports);
19
- //# sourceMappingURL=coagent-action.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/coagent-action.ts"],"sourcesContent":["export type CoagentActionRenderProps<T> = {\n state: T;\n nodeName: string;\n status: \"inProgress\" | \"complete\";\n};\n\nexport type CoagentActionHandlerArguments<T> = {\n nodeName: string;\n state: T;\n};\n\nexport type CoagentAction<T = any> = {\n name: string;\n nodeName?: string;\n handler?: (props: CoagentActionHandlerArguments<T>) => void | Promise<void>;\n render?: ((props: CoagentActionRenderProps<T>) => string | React.ReactElement) | string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=coagent-action.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,11 +0,0 @@
1
- interface CoagentState {
2
- name: string;
3
- state: any;
4
- running: boolean;
5
- active: boolean;
6
- threadId?: string;
7
- nodeName?: string;
8
- runId?: string;
9
- }
10
-
11
- export { CoagentState };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/types/coagent-state.ts
17
- var coagent_state_exports = {};
18
- module.exports = __toCommonJS(coagent_state_exports);
19
- //# sourceMappingURL=coagent-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/coagent-state.ts"],"sourcesContent":["export interface CoagentState {\n name: string;\n state: any;\n running: boolean;\n active: boolean;\n threadId?: string;\n nodeName?: string;\n runId?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=coagent-state.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,44 +0,0 @@
1
- import { useRef, useContext, useEffect } from "react";
2
- import { CopilotContext } from "../context/copilot-context";
3
- import { randomId } from "@copilotkit/shared";
4
- import { CoagentAction } from "../types/coagent-action";
5
-
6
- // We implement useCoAgentAction dependency handling so that
7
- // the developer has the option to not provide any dependencies.
8
- // see useCopilotAction for more details about this approach.
9
- export function useCoAgentAction<T = any>(action: CoagentAction<T>, dependencies?: any[]): void {
10
- const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } =
11
- useContext(CopilotContext);
12
- const idRef = useRef<string>(randomId());
13
-
14
- const key = `${action.name}-${action.nodeName || "global"}`;
15
-
16
- if (dependencies === undefined) {
17
- if (coagentActions[idRef.current]) {
18
- coagentActions[idRef.current].handler = action.handler as any;
19
- if (typeof action.render === "function") {
20
- if (chatComponentsCache.current !== null) {
21
- chatComponentsCache.current.coagentActions[key] = action.render;
22
- }
23
- }
24
- }
25
- }
26
-
27
- useEffect(() => {
28
- setCoagentAction(idRef.current, action as any);
29
- if (chatComponentsCache.current !== null && action.render !== undefined) {
30
- chatComponentsCache.current.coagentActions[key] = action.render;
31
- }
32
- return () => {
33
- removeCoagentAction(idRef.current);
34
- };
35
- }, [
36
- setCoagentAction,
37
- removeCoagentAction,
38
- action.name,
39
- // include render only if it's a string
40
- typeof action.render === "string" ? action.render : undefined,
41
- // dependencies set by the developer
42
- ...(dependencies || []),
43
- ]);
44
- }
@@ -1,133 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useCopilotContext } from "../context";
3
- import { CoagentState } from "../types/coagent-state";
4
-
5
- interface WithInternalStateManagementAndInitial<T> {
6
- name: string;
7
- initialState: T;
8
- }
9
-
10
- interface WithInternalStateManagement {
11
- name: string;
12
- initialState?: any; // Optional initialState with default type any
13
- }
14
-
15
- interface WithExternalStateManagement<T> {
16
- name: string;
17
- state: T;
18
- setState: (newState: T | ((prevState: T | undefined) => T)) => void;
19
- }
20
-
21
- type UseCoagentOptions<T> =
22
- | WithInternalStateManagementAndInitial<T>
23
- | WithInternalStateManagement
24
- | WithExternalStateManagement<T>;
25
-
26
- export interface UseCoagentReturnType<T> {
27
- name: string;
28
- nodeName?: string;
29
- threadId?: string;
30
- running: boolean;
31
- state: T;
32
- setState: (newState: T | ((prevState: T | undefined) => T)) => void;
33
- start: () => void;
34
- stop: () => void;
35
- }
36
-
37
- export function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {
38
- const isExternalStateManagement = (
39
- options: UseCoagentOptions<T>,
40
- ): options is WithExternalStateManagement<T> => {
41
- return "state" in options && "setState" in options;
42
- };
43
-
44
- const { name } = options;
45
-
46
- const isInternalStateManagementWithInitial = (
47
- options: UseCoagentOptions<T>,
48
- ): options is WithInternalStateManagementAndInitial<T> => {
49
- return "initialState" in options;
50
- };
51
-
52
- const { coagentStates, setCoagentStates } = useCopilotContext();
53
-
54
- const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {
55
- if (coagentStates[name]) {
56
- return coagentStates[name];
57
- } else {
58
- return {
59
- name,
60
- state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
61
- running: false,
62
- active: false,
63
- threadId: undefined,
64
- nodeName: undefined,
65
- runId: undefined,
66
- };
67
- }
68
- };
69
-
70
- // if we manage state internally, we need to provide a function to set the state
71
- const setState = (newState: T | ((prevState: T | undefined) => T)) => {
72
- setCoagentStates((prevAgentStates) => {
73
- let coagentState: CoagentState = getCoagentState(prevAgentStates, name);
74
-
75
- const updatedState =
76
- typeof newState === "function" ? (newState as Function)(coagentState.state) : newState;
77
-
78
- return {
79
- ...prevAgentStates,
80
- [name]: {
81
- ...coagentState,
82
- state: updatedState,
83
- },
84
- };
85
- });
86
- };
87
-
88
- const coagentState = getCoagentState(coagentStates, name);
89
-
90
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
91
-
92
- // Sync internal state with external state if state management is external
93
- useEffect(() => {
94
- if (isExternalStateManagement(options)) {
95
- setState(options.state);
96
- } else if (coagentStates[name] === undefined) {
97
- setState(options.initialState === undefined ? {} : options.initialState);
98
- }
99
- }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined]);
100
-
101
- // Return the state and setState function
102
- return {
103
- name,
104
- nodeName: coagentState.nodeName,
105
- state,
106
- setState,
107
- running: coagentState.running,
108
- start: () => {
109
- startAgent(name);
110
- },
111
- stop: () => {
112
- stopAgent(name);
113
- },
114
- };
115
- }
116
-
117
- function startAgent(name: string) {
118
- const { setAgentSession } = useCopilotContext();
119
- setAgentSession({
120
- agentName: name,
121
- });
122
- }
123
-
124
- function stopAgent(name: string) {
125
- const { agentSession, setAgentSession } = useCopilotContext();
126
- if (agentSession && agentSession.agentName === name) {
127
- setAgentSession(null);
128
- } else {
129
- console.warn(`No agent session found for ${name}`);
130
- }
131
- }
132
-
133
- // <CopilotKit agent="lockedInAgentName" />
@@ -1,17 +0,0 @@
1
- export type CoagentActionRenderProps<T> = {
2
- state: T;
3
- nodeName: string;
4
- status: "inProgress" | "complete";
5
- };
6
-
7
- export type CoagentActionHandlerArguments<T> = {
8
- nodeName: string;
9
- state: T;
10
- };
11
-
12
- export type CoagentAction<T = any> = {
13
- name: string;
14
- nodeName?: string;
15
- handler?: (props: CoagentActionHandlerArguments<T>) => void | Promise<void>;
16
- render?: ((props: CoagentActionRenderProps<T>) => string | React.ReactElement) | string;
17
- };
@@ -1,9 +0,0 @@
1
- export interface CoagentState {
2
- name: string;
3
- state: any;
4
- running: boolean;
5
- active: boolean;
6
- threadId?: string;
7
- nodeName?: string;
8
- runId?: string;
9
- }