@copilotkit/sdk-js 1.9.2-next.10 → 1.9.2-next.2
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.
- package/CHANGELOG.md +0 -52
- package/dist/chunk-PMVIZ7R2.mjs +140 -0
- package/dist/chunk-PMVIZ7R2.mjs.map +1 -0
- package/dist/langchain.js +43 -191
- package/dist/langchain.js.map +1 -1
- package/dist/langchain.mjs +1 -1
- package/dist/langgraph.js +74 -245
- package/dist/langgraph.js.map +1 -1
- package/dist/langgraph.mjs +1 -1
- package/package.json +3 -3
- package/src/langgraph.ts +68 -265
- package/dist/chunk-Q5S2AURJ.mjs +0 -311
- package/dist/chunk-Q5S2AURJ.mjs.map +0 -1
- package/src/__tests__/error-handling.test.ts +0 -207
package/dist/chunk-Q5S2AURJ.mjs
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/langgraph.ts
|
|
5
|
-
import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
|
|
6
|
-
import { convertJsonSchemaToZodSchema, randomId, CopilotKitMisuseError } from "@copilotkit/shared";
|
|
7
|
-
import { Annotation, MessagesAnnotation, interrupt } from "@langchain/langgraph";
|
|
8
|
-
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
9
|
-
import { AIMessage } from "@langchain/core/messages";
|
|
10
|
-
var CopilotKitPropertiesAnnotation = Annotation.Root({
|
|
11
|
-
actions: Annotation
|
|
12
|
-
});
|
|
13
|
-
var CopilotKitStateAnnotation = Annotation.Root({
|
|
14
|
-
copilotkit: Annotation,
|
|
15
|
-
...MessagesAnnotation.spec
|
|
16
|
-
});
|
|
17
|
-
function copilotkitCustomizeConfig(baseConfig, options) {
|
|
18
|
-
if (baseConfig && typeof baseConfig !== "object") {
|
|
19
|
-
throw new CopilotKitMisuseError({
|
|
20
|
-
message: "baseConfig must be an object or null/undefined"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (options && typeof options !== "object") {
|
|
24
|
-
throw new CopilotKitMisuseError({
|
|
25
|
-
message: "options must be an object when provided"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
if (options == null ? void 0 : options.emitIntermediateState) {
|
|
29
|
-
if (!Array.isArray(options.emitIntermediateState)) {
|
|
30
|
-
throw new CopilotKitMisuseError({
|
|
31
|
-
message: "emitIntermediateState must be an array when provided"
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
options.emitIntermediateState.forEach((state, index) => {
|
|
35
|
-
if (!state || typeof state !== "object") {
|
|
36
|
-
throw new CopilotKitMisuseError({
|
|
37
|
-
message: `emitIntermediateState[${index}] must be an object`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (!state.stateKey || typeof state.stateKey !== "string") {
|
|
41
|
-
throw new CopilotKitMisuseError({
|
|
42
|
-
message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
if (!state.tool || typeof state.tool !== "string") {
|
|
46
|
-
throw new CopilotKitMisuseError({
|
|
47
|
-
message: `emitIntermediateState[${index}] must have a valid 'tool' string property`
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (state.toolArgument && typeof state.toolArgument !== "string") {
|
|
51
|
-
throw new CopilotKitMisuseError({
|
|
52
|
-
message: `emitIntermediateState[${index}].toolArgument must be a string when provided`
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
|
|
59
|
-
if (options == null ? void 0 : options.emitAll) {
|
|
60
|
-
metadata["copilotkit:emit-tool-calls"] = true;
|
|
61
|
-
metadata["copilotkit:emit-messages"] = true;
|
|
62
|
-
} else {
|
|
63
|
-
if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
|
|
64
|
-
metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
|
|
65
|
-
}
|
|
66
|
-
if ((options == null ? void 0 : options.emitMessages) !== void 0) {
|
|
67
|
-
metadata["copilotkit:emit-messages"] = options.emitMessages;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (options == null ? void 0 : options.emitIntermediateState) {
|
|
71
|
-
const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
|
|
72
|
-
tool: state.tool,
|
|
73
|
-
tool_argument: state.toolArgument,
|
|
74
|
-
state_key: state.stateKey
|
|
75
|
-
}));
|
|
76
|
-
metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
|
|
77
|
-
}
|
|
78
|
-
baseConfig = baseConfig || {};
|
|
79
|
-
return {
|
|
80
|
-
...baseConfig,
|
|
81
|
-
metadata
|
|
82
|
-
};
|
|
83
|
-
} catch (error) {
|
|
84
|
-
throw new CopilotKitMisuseError({
|
|
85
|
-
message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
__name(copilotkitCustomizeConfig, "copilotkitCustomizeConfig");
|
|
90
|
-
async function copilotkitExit(config) {
|
|
91
|
-
if (!config) {
|
|
92
|
-
throw new CopilotKitMisuseError({
|
|
93
|
-
message: "LangGraph configuration is required for copilotkitExit"
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
await dispatchCustomEvent("copilotkit_exit", {}, config);
|
|
98
|
-
} catch (error) {
|
|
99
|
-
throw new CopilotKitMisuseError({
|
|
100
|
-
message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
__name(copilotkitExit, "copilotkitExit");
|
|
105
|
-
async function copilotkitEmitState(config, state) {
|
|
106
|
-
if (!config) {
|
|
107
|
-
throw new CopilotKitMisuseError({
|
|
108
|
-
message: "LangGraph configuration is required for copilotkitEmitState"
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (state === void 0) {
|
|
112
|
-
throw new CopilotKitMisuseError({
|
|
113
|
-
message: "State is required for copilotkitEmitState"
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
await dispatchCustomEvent("copilotkit_manually_emit_intermediate_state", state, config);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
throw new CopilotKitMisuseError({
|
|
120
|
-
message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
__name(copilotkitEmitState, "copilotkitEmitState");
|
|
125
|
-
async function copilotkitEmitMessage(config, message) {
|
|
126
|
-
if (!config) {
|
|
127
|
-
throw new CopilotKitMisuseError({
|
|
128
|
-
message: "LangGraph configuration is required for copilotkitEmitMessage"
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if (!message || typeof message !== "string") {
|
|
132
|
-
throw new CopilotKitMisuseError({
|
|
133
|
-
message: "Message must be a non-empty string for copilotkitEmitMessage"
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
await dispatchCustomEvent("copilotkit_manually_emit_message", {
|
|
138
|
-
message,
|
|
139
|
-
message_id: randomId(),
|
|
140
|
-
role: "assistant"
|
|
141
|
-
}, config);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
throw new CopilotKitMisuseError({
|
|
144
|
-
message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
__name(copilotkitEmitMessage, "copilotkitEmitMessage");
|
|
149
|
-
async function copilotkitEmitToolCall(config, name, args) {
|
|
150
|
-
if (!config) {
|
|
151
|
-
throw new CopilotKitMisuseError({
|
|
152
|
-
message: "LangGraph configuration is required for copilotkitEmitToolCall"
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
if (!name || typeof name !== "string") {
|
|
156
|
-
throw new CopilotKitMisuseError({
|
|
157
|
-
message: "Tool name must be a non-empty string for copilotkitEmitToolCall"
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (args === void 0) {
|
|
161
|
-
throw new CopilotKitMisuseError({
|
|
162
|
-
message: "Tool arguments are required for copilotkitEmitToolCall"
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
await dispatchCustomEvent("copilotkit_manually_emit_tool_call", {
|
|
167
|
-
name,
|
|
168
|
-
args,
|
|
169
|
-
id: randomId()
|
|
170
|
-
}, config);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
throw new CopilotKitMisuseError({
|
|
173
|
-
message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}`
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
__name(copilotkitEmitToolCall, "copilotkitEmitToolCall");
|
|
178
|
-
function convertActionToDynamicStructuredTool(actionInput) {
|
|
179
|
-
if (!actionInput) {
|
|
180
|
-
throw new CopilotKitMisuseError({
|
|
181
|
-
message: "Action input is required but was not provided"
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (!actionInput.name || typeof actionInput.name !== "string") {
|
|
185
|
-
throw new CopilotKitMisuseError({
|
|
186
|
-
message: "Action must have a valid 'name' property of type string"
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (!actionInput.description || typeof actionInput.description !== "string") {
|
|
190
|
-
throw new CopilotKitMisuseError({
|
|
191
|
-
message: `Action '${actionInput.name}' must have a valid 'description' property of type string`
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
if (!actionInput.parameters) {
|
|
195
|
-
throw new CopilotKitMisuseError({
|
|
196
|
-
message: `Action '${actionInput.name}' must have a 'parameters' property`
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
try {
|
|
200
|
-
return new DynamicStructuredTool({
|
|
201
|
-
name: actionInput.name,
|
|
202
|
-
description: actionInput.description,
|
|
203
|
-
schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),
|
|
204
|
-
func: async () => {
|
|
205
|
-
return "";
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
} catch (error) {
|
|
209
|
-
throw new CopilotKitMisuseError({
|
|
210
|
-
message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
__name(convertActionToDynamicStructuredTool, "convertActionToDynamicStructuredTool");
|
|
215
|
-
function convertActionsToDynamicStructuredTools(actions) {
|
|
216
|
-
if (!Array.isArray(actions)) {
|
|
217
|
-
throw new CopilotKitMisuseError({
|
|
218
|
-
message: "Actions must be an array"
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
return actions.map((action, index) => {
|
|
222
|
-
try {
|
|
223
|
-
return convertActionToDynamicStructuredTool(action);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
throw new CopilotKitMisuseError({
|
|
226
|
-
message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
__name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
|
|
232
|
-
function copilotKitInterrupt({ message, action, args }) {
|
|
233
|
-
if (!message && !action) {
|
|
234
|
-
throw new CopilotKitMisuseError({
|
|
235
|
-
message: "Either message or action (and optional arguments) must be provided for copilotKitInterrupt"
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
if (action && typeof action !== "string") {
|
|
239
|
-
throw new CopilotKitMisuseError({
|
|
240
|
-
message: "Action must be a string when provided to copilotKitInterrupt"
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
if (message && typeof message !== "string") {
|
|
244
|
-
throw new CopilotKitMisuseError({
|
|
245
|
-
message: "Message must be a string when provided to copilotKitInterrupt"
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
if (args && typeof args !== "object") {
|
|
249
|
-
throw new CopilotKitMisuseError({
|
|
250
|
-
message: "Args must be an object when provided to copilotKitInterrupt"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
let interruptValues = null;
|
|
254
|
-
let interruptMessage = null;
|
|
255
|
-
let answer = null;
|
|
256
|
-
try {
|
|
257
|
-
if (message) {
|
|
258
|
-
interruptValues = message;
|
|
259
|
-
interruptMessage = new AIMessage({
|
|
260
|
-
content: message,
|
|
261
|
-
id: randomId()
|
|
262
|
-
});
|
|
263
|
-
} else {
|
|
264
|
-
const toolId = randomId();
|
|
265
|
-
interruptMessage = new AIMessage({
|
|
266
|
-
content: "",
|
|
267
|
-
tool_calls: [
|
|
268
|
-
{
|
|
269
|
-
id: toolId,
|
|
270
|
-
name: action,
|
|
271
|
-
args: args ?? {}
|
|
272
|
-
}
|
|
273
|
-
]
|
|
274
|
-
});
|
|
275
|
-
interruptValues = {
|
|
276
|
-
action,
|
|
277
|
-
args: args ?? {}
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
const response = interrupt({
|
|
281
|
-
__copilotkit_interrupt_value__: interruptValues,
|
|
282
|
-
__copilotkit_messages__: [
|
|
283
|
-
interruptMessage
|
|
284
|
-
]
|
|
285
|
-
});
|
|
286
|
-
answer = response[response.length - 1].content;
|
|
287
|
-
return {
|
|
288
|
-
answer,
|
|
289
|
-
messages: response
|
|
290
|
-
};
|
|
291
|
-
} catch (error) {
|
|
292
|
-
throw new CopilotKitMisuseError({
|
|
293
|
-
message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}`
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
__name(copilotKitInterrupt, "copilotKitInterrupt");
|
|
298
|
-
|
|
299
|
-
export {
|
|
300
|
-
CopilotKitPropertiesAnnotation,
|
|
301
|
-
CopilotKitStateAnnotation,
|
|
302
|
-
copilotkitCustomizeConfig,
|
|
303
|
-
copilotkitExit,
|
|
304
|
-
copilotkitEmitState,
|
|
305
|
-
copilotkitEmitMessage,
|
|
306
|
-
copilotkitEmitToolCall,
|
|
307
|
-
convertActionToDynamicStructuredTool,
|
|
308
|
-
convertActionsToDynamicStructuredTools,
|
|
309
|
-
copilotKitInterrupt
|
|
310
|
-
};
|
|
311
|
-
//# sourceMappingURL=chunk-Q5S2AURJ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/langgraph.ts"],"sourcesContent":["import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport { convertJsonSchemaToZodSchema, randomId, CopilotKitMisuseError } from \"@copilotkit/shared\";\nimport { Annotation, MessagesAnnotation, interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\n\ninterface IntermediateStateConfig {\n stateKey: string;\n tool: string;\n toolArgument?: string;\n}\n\ninterface OptionsConfig {\n emitToolCalls?: boolean | string | string[];\n emitMessages?: boolean;\n emitAll?: boolean;\n emitIntermediateState?: IntermediateStateConfig[];\n}\n\nexport const CopilotKitPropertiesAnnotation = Annotation.Root({\n actions: Annotation<any[]>,\n});\n\nexport const CopilotKitStateAnnotation = Annotation.Root({\n copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,\n ...MessagesAnnotation.spec,\n});\n\nexport type CopilotKitState = typeof CopilotKitStateAnnotation.State;\nexport type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;\n\n/**\n * Customize the LangGraph configuration for use in CopilotKit.\n *\n * To the CopilotKit SDK, run:\n *\n * ```bash\n * npm install @copilotkit/sdk-js\n * ```\n *\n * ### Examples\n *\n * Disable emitting messages and tool calls:\n *\n * ```typescript\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js\";\n *\n * config = copilotkitCustomizeConfig(\n * config,\n * emitMessages=false,\n * emitToolCalls=false\n * )\n * ```\n *\n * To emit a tool call as streaming LangGraph state, pass the destination key in state,\n * the tool name and optionally the tool argument. (If you don't pass the argument name,\n * all arguments are emitted under the state key.)\n *\n * ```typescript\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js\";\n *\n * config = copilotkitCustomizeConfig(\n * config,\n * emitIntermediateState=[\n * {\n * \"stateKey\": \"steps\",\n * \"tool\": \"SearchTool\",\n * \"toolArgument\": \"steps\",\n * },\n * ],\n * )\n * ```\n */\nexport function copilotkitCustomizeConfig(\n /**\n * The LangChain/LangGraph configuration to customize.\n */\n baseConfig: RunnableConfig,\n /**\n * Configuration options:\n * - `emitMessages: boolean?`\n * Configure how messages are emitted. By default, all messages are emitted. Pass false to\n * disable emitting messages.\n * - `emitToolCalls: boolean | string | string[]?`\n * Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to\n * disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.\n * - `emitIntermediateState: IntermediateStateConfig[]?`\n * Lets you emit tool calls as streaming LangGraph state.\n */\n options?: OptionsConfig,\n): RunnableConfig {\n if (baseConfig && typeof baseConfig !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"baseConfig must be an object or null/undefined\",\n });\n }\n\n if (options && typeof options !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"options must be an object when provided\",\n });\n }\n\n // Validate emitIntermediateState structure\n if (options?.emitIntermediateState) {\n if (!Array.isArray(options.emitIntermediateState)) {\n throw new CopilotKitMisuseError({\n message: \"emitIntermediateState must be an array when provided\",\n });\n }\n\n options.emitIntermediateState.forEach((state, index) => {\n if (!state || typeof state !== \"object\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must be an object`,\n });\n }\n\n if (!state.stateKey || typeof state.stateKey !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`,\n });\n }\n\n if (!state.tool || typeof state.tool !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'tool' string property`,\n });\n }\n\n if (state.toolArgument && typeof state.toolArgument !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}].toolArgument must be a string when provided`,\n });\n }\n });\n }\n\n try {\n const metadata = baseConfig?.metadata || {};\n\n if (options?.emitAll) {\n metadata[\"copilotkit:emit-tool-calls\"] = true;\n metadata[\"copilotkit:emit-messages\"] = true;\n } else {\n if (options?.emitToolCalls !== undefined) {\n metadata[\"copilotkit:emit-tool-calls\"] = options.emitToolCalls;\n }\n if (options?.emitMessages !== undefined) {\n metadata[\"copilotkit:emit-messages\"] = options.emitMessages;\n }\n }\n\n if (options?.emitIntermediateState) {\n const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }));\n\n metadata[\"copilotkit:emit-intermediate-state\"] = snakeCaseIntermediateState;\n }\n\n baseConfig = baseConfig || {};\n\n return {\n ...baseConfig,\n metadata: metadata,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Exits the current agent after the run completes. Calling copilotkit_exit() will\n * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after\n * the run completes.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitExit } from \"@copilotkit/sdk-js\";\n *\n * async function myNode(state: Any):\n * await copilotkitExit(config)\n * return state\n * ```\n */\nexport async function copilotkitExit(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitExit\",\n });\n }\n\n try {\n await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to\n * update the user with the current state of the node.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitState } from \"@copilotkit/sdk-js\";\n *\n * for (let i = 0; i < 10; i++) {\n * await someLongRunningOperation(i);\n * await copilotkitEmitState(config, { progress: i });\n * }\n * ```\n */\nexport async function copilotkitEmitState(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The state to emit.\n */\n state: any,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitState\",\n });\n }\n\n if (state === undefined) {\n throw new CopilotKitMisuseError({\n message: \"State is required for copilotkitEmitState\",\n });\n }\n\n try {\n await dispatchCustomEvent(\"copilotkit_manually_emit_intermediate_state\", state, config);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.\n * Important: You still need to return the messages from the node.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitMessage } from \"@copilotkit/sdk-js\";\n *\n * const message = \"Step 1 of 10 complete\";\n * await copilotkitEmitMessage(config, message);\n *\n * // Return the message from the node\n * return {\n * \"messages\": [AIMessage(content=message)]\n * }\n * ```\n */\nexport async function copilotkitEmitMessage(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The message to emit.\n */\n message: string,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitMessage\",\n });\n }\n\n if (!message || typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a non-empty string for copilotkitEmitMessage\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a tool call to CopilotKit.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitToolCall } from \"@copilotkit/sdk-js\";\n *\n * await copilotkitEmitToolCall(config, name=\"SearchTool\", args={\"steps\": 10})\n * ```\n */\nexport async function copilotkitEmitToolCall(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The name of the tool to emit.\n */\n name: string,\n /**\n * The arguments to emit.\n */\n args: any,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitToolCall\",\n });\n }\n\n if (!name || typeof name !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Tool name must be a non-empty string for copilotkitEmitToolCall\",\n });\n }\n\n if (args === undefined) {\n throw new CopilotKitMisuseError({\n message: \"Tool arguments are required for copilotkitEmitToolCall\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_tool_call\",\n { name, args, id: randomId() },\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n\nexport function convertActionToDynamicStructuredTool(actionInput: any): DynamicStructuredTool<any> {\n if (!actionInput) {\n throw new CopilotKitMisuseError({\n message: \"Action input is required but was not provided\",\n });\n }\n\n if (!actionInput.name || typeof actionInput.name !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must have a valid 'name' property of type string\",\n });\n }\n\n if (!actionInput.description || typeof actionInput.description !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a valid 'description' property of type string`,\n });\n }\n\n if (!actionInput.parameters) {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a 'parameters' property`,\n });\n }\n\n try {\n return new DynamicStructuredTool({\n name: actionInput.name,\n description: actionInput.description,\n schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),\n func: async () => {\n return \"\";\n },\n });\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Use this function to convert a list of actions you get from state\n * to a list of dynamic structured tools.\n *\n * ### Examples\n *\n * ```typescript\n * import { convertActionsToDynamicStructuredTools } from \"@copilotkit/sdk-js\";\n *\n * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);\n * ```\n */\nexport function convertActionsToDynamicStructuredTools(\n /**\n * The list of actions to convert.\n */\n actions: any[],\n): DynamicStructuredTool<any>[] {\n if (!Array.isArray(actions)) {\n throw new CopilotKitMisuseError({\n message: \"Actions must be an array\",\n });\n }\n\n return actions.map((action, index) => {\n try {\n return convertActionToDynamicStructuredTool(action);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n });\n}\n\nexport function copilotKitInterrupt({\n message,\n action,\n args,\n}: {\n message?: string;\n action?: string;\n args?: Record<string, any>;\n}) {\n if (!message && !action) {\n throw new CopilotKitMisuseError({\n message:\n \"Either message or action (and optional arguments) must be provided for copilotKitInterrupt\",\n });\n }\n\n if (action && typeof action !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (message && typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (args && typeof args !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"Args must be an object when provided to copilotKitInterrupt\",\n });\n }\n\n let interruptValues = null;\n let interruptMessage = null;\n let answer = null;\n\n try {\n if (message) {\n interruptValues = message;\n interruptMessage = new AIMessage({ content: message, id: randomId() });\n } else {\n const toolId = randomId();\n interruptMessage = new AIMessage({\n content: \"\",\n tool_calls: [{ id: toolId, name: action, args: args ?? {} }],\n });\n interruptValues = {\n action,\n args: args ?? {},\n };\n }\n\n const response = interrupt({\n __copilotkit_interrupt_value__: interruptValues,\n __copilotkit_messages__: [interruptMessage],\n });\n answer = response[response.length - 1].content;\n\n return {\n answer,\n messages: response,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"],"mappings":";;;;AACA,SAASA,2BAA2B;AACpC,SAASC,8BAA8BC,UAAUC,6BAA6B;AAC9E,SAASC,YAAYC,oBAAoBC,iBAAiB;AAC1D,SAASC,6BAA6B;AACtC,SAASC,iBAAiB;AAenB,IAAMC,iCAAiCC,WAAWC,KAAK;EAC5DC,SAASF;AACX,CAAA;AAEO,IAAMG,4BAA4BH,WAAWC,KAAK;EACvDG,YAAYJ;EACZ,GAAGK,mBAAmBC;AACxB,CAAA;AA+CO,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,MAAID,cAAc,OAAOA,eAAe,UAAU;AAChD,UAAM,IAAIE,sBAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAEA,MAAIF,WAAW,OAAOA,YAAY,UAAU;AAC1C,UAAM,IAAIC,sBAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAGA,MAAIF,mCAASG,uBAAuB;AAClC,QAAI,CAACC,MAAMC,QAAQL,QAAQG,qBAAqB,GAAG;AACjD,YAAM,IAAIF,sBAAsB;QAC9BC,SAAS;MACX,CAAA;IACF;AAEAF,YAAQG,sBAAsBG,QAAQ,CAACC,OAAOC,UAAAA;AAC5C,UAAI,CAACD,SAAS,OAAOA,UAAU,UAAU;AACvC,cAAM,IAAIN,sBAAsB;UAC9BC,SAAS,yBAAyBM;QACpC,CAAA;MACF;AAEA,UAAI,CAACD,MAAME,YAAY,OAAOF,MAAME,aAAa,UAAU;AACzD,cAAM,IAAIR,sBAAsB;UAC9BC,SAAS,yBAAyBM;QACpC,CAAA;MACF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AEA,UAAMoB,WAAWC,UAAU;MACzBC,gCAAgCT;MAChCU,yBAAyB;QAACT;;IAC5B,CAAA;AACAC,aAASK,SAASA,SAASI,SAAS,CAAA,EAAGP;AAEvC,WAAO;MACLF;MACAU,UAAUL;IACZ;EACF,SAASjC,OAAP;AACA,UAAM,IAAIpB,sBAAsB;MAC9BC,SAAS,+BAA+BmB,iBAAiBC,QAAQD,MAAMnB,UAAUqB,OAAOF,KAAAA;IAC1F,CAAA;EACF;AACF;AArEgByB;","names":["dispatchCustomEvent","convertJsonSchemaToZodSchema","randomId","CopilotKitMisuseError","Annotation","MessagesAnnotation","interrupt","DynamicStructuredTool","AIMessage","CopilotKitPropertiesAnnotation","Annotation","Root","actions","CopilotKitStateAnnotation","copilotkit","MessagesAnnotation","spec","copilotkitCustomizeConfig","baseConfig","options","CopilotKitMisuseError","message","emitIntermediateState","Array","isArray","forEach","state","index","stateKey","tool","toolArgument","metadata","emitAll","emitToolCalls","undefined","emitMessages","snakeCaseIntermediateState","map","tool_argument","state_key","error","Error","String","copilotkitExit","config","dispatchCustomEvent","copilotkitEmitState","copilotkitEmitMessage","message_id","randomId","role","copilotkitEmitToolCall","name","args","id","convertActionToDynamicStructuredTool","actionInput","description","parameters","DynamicStructuredTool","schema","convertJsonSchemaToZodSchema","func","convertActionsToDynamicStructuredTools","action","copilotKitInterrupt","interruptValues","interruptMessage","answer","AIMessage","content","toolId","tool_calls","response","interrupt","__copilotkit_interrupt_value__","__copilotkit_messages__","length","messages"]}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { CopilotKitMisuseError } from "@copilotkit/shared";
|
|
2
|
-
import {
|
|
3
|
-
copilotKitInterrupt,
|
|
4
|
-
convertActionToDynamicStructuredTool,
|
|
5
|
-
convertActionsToDynamicStructuredTools,
|
|
6
|
-
copilotkitCustomizeConfig,
|
|
7
|
-
copilotkitEmitMessage,
|
|
8
|
-
copilotkitEmitState,
|
|
9
|
-
copilotkitEmitToolCall,
|
|
10
|
-
copilotkitExit,
|
|
11
|
-
} from "../langgraph";
|
|
12
|
-
|
|
13
|
-
describe("SDK-JS Error Handling", () => {
|
|
14
|
-
describe("copilotKitInterrupt", () => {
|
|
15
|
-
it("should throw CopilotKitMisuseError when neither message nor action provided", () => {
|
|
16
|
-
expect(() => {
|
|
17
|
-
copilotKitInterrupt({});
|
|
18
|
-
}).toThrow(CopilotKitMisuseError);
|
|
19
|
-
|
|
20
|
-
expect(() => {
|
|
21
|
-
copilotKitInterrupt({});
|
|
22
|
-
}).toThrow(
|
|
23
|
-
"Either message or action (and optional arguments) must be provided for copilotKitInterrupt",
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should throw CopilotKitMisuseError when action is not a string", () => {
|
|
28
|
-
expect(() => {
|
|
29
|
-
copilotKitInterrupt({ action: 123 as any });
|
|
30
|
-
}).toThrow(CopilotKitMisuseError);
|
|
31
|
-
|
|
32
|
-
expect(() => {
|
|
33
|
-
copilotKitInterrupt({ action: 123 as any });
|
|
34
|
-
}).toThrow("Action must be a string when provided to copilotKitInterrupt");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should throw CopilotKitMisuseError when message is not a string", () => {
|
|
38
|
-
expect(() => {
|
|
39
|
-
copilotKitInterrupt({ message: 123 as any });
|
|
40
|
-
}).toThrow(CopilotKitMisuseError);
|
|
41
|
-
|
|
42
|
-
expect(() => {
|
|
43
|
-
copilotKitInterrupt({ message: 123 as any });
|
|
44
|
-
}).toThrow("Message must be a string when provided to copilotKitInterrupt");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should throw CopilotKitMisuseError when args is not an object", () => {
|
|
48
|
-
expect(() => {
|
|
49
|
-
copilotKitInterrupt({ action: "test", args: "invalid" as any });
|
|
50
|
-
}).toThrow(CopilotKitMisuseError);
|
|
51
|
-
|
|
52
|
-
expect(() => {
|
|
53
|
-
copilotKitInterrupt({ action: "test", args: "invalid" as any });
|
|
54
|
-
}).toThrow("Args must be an object when provided to copilotKitInterrupt");
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("convertActionToDynamicStructuredTool", () => {
|
|
59
|
-
it("should throw CopilotKitMisuseError when actionInput is null/undefined", () => {
|
|
60
|
-
expect(() => {
|
|
61
|
-
convertActionToDynamicStructuredTool(null);
|
|
62
|
-
}).toThrow(CopilotKitMisuseError);
|
|
63
|
-
|
|
64
|
-
expect(() => {
|
|
65
|
-
convertActionToDynamicStructuredTool(null);
|
|
66
|
-
}).toThrow("Action input is required but was not provided");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should throw CopilotKitMisuseError when name is missing", () => {
|
|
70
|
-
expect(() => {
|
|
71
|
-
convertActionToDynamicStructuredTool({ description: "test" });
|
|
72
|
-
}).toThrow(CopilotKitMisuseError);
|
|
73
|
-
|
|
74
|
-
expect(() => {
|
|
75
|
-
convertActionToDynamicStructuredTool({ description: "test" });
|
|
76
|
-
}).toThrow("Action must have a valid 'name' property of type string");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should throw CopilotKitMisuseError when description is missing", () => {
|
|
80
|
-
expect(() => {
|
|
81
|
-
convertActionToDynamicStructuredTool({ name: "test" });
|
|
82
|
-
}).toThrow(CopilotKitMisuseError);
|
|
83
|
-
|
|
84
|
-
expect(() => {
|
|
85
|
-
convertActionToDynamicStructuredTool({ name: "test" });
|
|
86
|
-
}).toThrow("Action 'test' must have a valid 'description' property of type string");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should throw CopilotKitMisuseError when parameters is missing", () => {
|
|
90
|
-
expect(() => {
|
|
91
|
-
convertActionToDynamicStructuredTool({ name: "test", description: "test desc" });
|
|
92
|
-
}).toThrow(CopilotKitMisuseError);
|
|
93
|
-
|
|
94
|
-
expect(() => {
|
|
95
|
-
convertActionToDynamicStructuredTool({ name: "test", description: "test desc" });
|
|
96
|
-
}).toThrow("Action 'test' must have a 'parameters' property");
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("convertActionsToDynamicStructuredTools", () => {
|
|
101
|
-
it("should throw CopilotKitMisuseError when actions is not an array", () => {
|
|
102
|
-
expect(() => {
|
|
103
|
-
convertActionsToDynamicStructuredTools("not an array" as any);
|
|
104
|
-
}).toThrow(CopilotKitMisuseError);
|
|
105
|
-
|
|
106
|
-
expect(() => {
|
|
107
|
-
convertActionsToDynamicStructuredTools("not an array" as any);
|
|
108
|
-
}).toThrow("Actions must be an array");
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe("copilotkitCustomizeConfig", () => {
|
|
113
|
-
it("should throw CopilotKitMisuseError when baseConfig is not an object", () => {
|
|
114
|
-
expect(() => {
|
|
115
|
-
copilotkitCustomizeConfig("invalid" as any);
|
|
116
|
-
}).toThrow(CopilotKitMisuseError);
|
|
117
|
-
|
|
118
|
-
expect(() => {
|
|
119
|
-
copilotkitCustomizeConfig("invalid" as any);
|
|
120
|
-
}).toThrow("baseConfig must be an object or null/undefined");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should throw CopilotKitMisuseError when options is not an object", () => {
|
|
124
|
-
expect(() => {
|
|
125
|
-
copilotkitCustomizeConfig({}, "invalid" as any);
|
|
126
|
-
}).toThrow(CopilotKitMisuseError);
|
|
127
|
-
|
|
128
|
-
expect(() => {
|
|
129
|
-
copilotkitCustomizeConfig({}, "invalid" as any);
|
|
130
|
-
}).toThrow("options must be an object when provided");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should throw CopilotKitMisuseError when emitIntermediateState is not an array", () => {
|
|
134
|
-
expect(() => {
|
|
135
|
-
copilotkitCustomizeConfig({}, { emitIntermediateState: "invalid" as any });
|
|
136
|
-
}).toThrow(CopilotKitMisuseError);
|
|
137
|
-
|
|
138
|
-
expect(() => {
|
|
139
|
-
copilotkitCustomizeConfig({}, { emitIntermediateState: "invalid" as any });
|
|
140
|
-
}).toThrow("emitIntermediateState must be an array when provided");
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("should throw CopilotKitMisuseError when emitIntermediateState item is invalid", () => {
|
|
144
|
-
expect(() => {
|
|
145
|
-
copilotkitCustomizeConfig({}, { emitIntermediateState: [{ invalidKey: "value" }] as any });
|
|
146
|
-
}).toThrow(CopilotKitMisuseError);
|
|
147
|
-
|
|
148
|
-
expect(() => {
|
|
149
|
-
copilotkitCustomizeConfig({}, { emitIntermediateState: [{ invalidKey: "value" }] as any });
|
|
150
|
-
}).toThrow("emitIntermediateState[0] must have a valid 'stateKey' string property");
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe("emit functions", () => {
|
|
155
|
-
const mockConfig = { metadata: {} };
|
|
156
|
-
|
|
157
|
-
it("should throw CopilotKitMisuseError when config is missing for copilotkitExit", async () => {
|
|
158
|
-
await expect(copilotkitExit(null as any)).rejects.toThrow(CopilotKitMisuseError);
|
|
159
|
-
await expect(copilotkitExit(null as any)).rejects.toThrow(
|
|
160
|
-
"LangGraph configuration is required for copilotkitExit",
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should throw CopilotKitMisuseError when config is missing for copilotkitEmitState", async () => {
|
|
165
|
-
await expect(copilotkitEmitState(null as any, {})).rejects.toThrow(CopilotKitMisuseError);
|
|
166
|
-
await expect(copilotkitEmitState(null as any, {})).rejects.toThrow(
|
|
167
|
-
"LangGraph configuration is required for copilotkitEmitState",
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("should throw CopilotKitMisuseError when state is undefined for copilotkitEmitState", async () => {
|
|
172
|
-
await expect(copilotkitEmitState(mockConfig, undefined)).rejects.toThrow(
|
|
173
|
-
CopilotKitMisuseError,
|
|
174
|
-
);
|
|
175
|
-
await expect(copilotkitEmitState(mockConfig, undefined)).rejects.toThrow(
|
|
176
|
-
"State is required for copilotkitEmitState",
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("should throw CopilotKitMisuseError when message is invalid for copilotkitEmitMessage", async () => {
|
|
181
|
-
await expect(copilotkitEmitMessage(mockConfig, "" as any)).rejects.toThrow(
|
|
182
|
-
CopilotKitMisuseError,
|
|
183
|
-
);
|
|
184
|
-
await expect(copilotkitEmitMessage(mockConfig, "" as any)).rejects.toThrow(
|
|
185
|
-
"Message must be a non-empty string for copilotkitEmitMessage",
|
|
186
|
-
);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should throw CopilotKitMisuseError when tool name is invalid for copilotkitEmitToolCall", async () => {
|
|
190
|
-
await expect(copilotkitEmitToolCall(mockConfig, "", {})).rejects.toThrow(
|
|
191
|
-
CopilotKitMisuseError,
|
|
192
|
-
);
|
|
193
|
-
await expect(copilotkitEmitToolCall(mockConfig, "", {})).rejects.toThrow(
|
|
194
|
-
"Tool name must be a non-empty string for copilotkitEmitToolCall",
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("should throw CopilotKitMisuseError when args is undefined for copilotkitEmitToolCall", async () => {
|
|
199
|
-
await expect(copilotkitEmitToolCall(mockConfig, "testTool", undefined)).rejects.toThrow(
|
|
200
|
-
CopilotKitMisuseError,
|
|
201
|
-
);
|
|
202
|
-
await expect(copilotkitEmitToolCall(mockConfig, "testTool", undefined)).rejects.toThrow(
|
|
203
|
-
"Tool arguments are required for copilotkitEmitToolCall",
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
});
|