@copilotkit/sdk-js 1.51.5-next.0 → 1.51.5-next.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.
- package/CHANGELOG.md +6 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/langchain.cjs +18 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +3 -0
- package/dist/langchain.d.mts +4 -0
- package/dist/langchain.mjs +6 -23
- package/dist/langchain.mjs.map +1 -1
- package/dist/langgraph/middleware.cjs +139 -0
- package/dist/langgraph/middleware.cjs.map +1 -0
- package/dist/langgraph/middleware.d.cts +8 -0
- package/dist/langgraph/middleware.d.cts.map +1 -0
- package/dist/langgraph/middleware.d.mts +8 -0
- package/dist/langgraph/middleware.d.mts.map +1 -0
- package/dist/langgraph/middleware.mjs +137 -0
- package/dist/langgraph/middleware.mjs.map +1 -0
- package/dist/langgraph/types.cjs +19 -0
- package/dist/langgraph/types.cjs.map +1 -0
- package/dist/langgraph/types.d.cts +246 -0
- package/dist/langgraph/types.d.cts.map +1 -0
- package/dist/langgraph/types.d.mts +246 -0
- package/dist/langgraph/types.d.mts.map +1 -0
- package/dist/langgraph/types.mjs +17 -0
- package/dist/langgraph/types.mjs.map +1 -0
- package/dist/langgraph/utils.cjs +281 -0
- package/dist/langgraph/utils.cjs.map +1 -0
- package/dist/langgraph/utils.d.cts +192 -0
- package/dist/langgraph/utils.d.cts.map +1 -0
- package/dist/langgraph/utils.d.mts +192 -0
- package/dist/langgraph/utils.d.mts.map +1 -0
- package/dist/langgraph/utils.mjs +273 -0
- package/dist/langgraph/utils.mjs.map +1 -0
- package/dist/langgraph.cjs +16 -0
- package/dist/langgraph.d.cts +4 -0
- package/dist/langgraph.d.mts +4 -0
- package/dist/langgraph.mjs +5 -27
- package/package.json +22 -22
- package/tsdown.config.ts +17 -0
- package/vitest.config.mjs +11 -0
- package/dist/chunk-A7ZQHBQI.mjs +0 -505
- package/dist/chunk-A7ZQHBQI.mjs.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/langchain-db7cb6cb.d.ts +0 -427
- package/dist/langchain.d.ts +0 -6
- package/dist/langchain.js +0 -284
- package/dist/langchain.js.map +0 -1
- package/dist/langgraph/index.d.ts +0 -10
- package/dist/langgraph.js +0 -548
- package/dist/langgraph.js.map +0 -1
- package/dist/langgraph.mjs.map +0 -1
- package/jest.config.js +0 -5
- package/tsup.config.ts +0 -23
package/dist/langgraph.js
DELETED
|
@@ -1,548 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/langgraph/index.ts
|
|
31
|
-
var langgraph_exports = {};
|
|
32
|
-
__export(langgraph_exports, {
|
|
33
|
-
CopilotKitPropertiesAnnotation: () => CopilotKitPropertiesAnnotation,
|
|
34
|
-
CopilotKitStateAnnotation: () => CopilotKitStateAnnotation,
|
|
35
|
-
convertActionToDynamicStructuredTool: () => convertActionToDynamicStructuredTool,
|
|
36
|
-
convertActionsToDynamicStructuredTools: () => convertActionsToDynamicStructuredTools,
|
|
37
|
-
copilotKitInterrupt: () => copilotKitInterrupt,
|
|
38
|
-
copilotkitCustomizeConfig: () => copilotkitCustomizeConfig,
|
|
39
|
-
copilotkitEmitMessage: () => copilotkitEmitMessage,
|
|
40
|
-
copilotkitEmitState: () => copilotkitEmitState,
|
|
41
|
-
copilotkitEmitToolCall: () => copilotkitEmitToolCall,
|
|
42
|
-
copilotkitExit: () => copilotkitExit,
|
|
43
|
-
copilotkitMiddleware: () => copilotkitMiddleware
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(langgraph_exports);
|
|
46
|
-
|
|
47
|
-
// src/langgraph/types.ts
|
|
48
|
-
var import_langgraph = require("@langchain/langgraph");
|
|
49
|
-
var CopilotKitPropertiesAnnotation = import_langgraph.Annotation.Root({
|
|
50
|
-
actions: import_langgraph.Annotation,
|
|
51
|
-
context: import_langgraph.Annotation,
|
|
52
|
-
interceptedToolCalls: import_langgraph.Annotation,
|
|
53
|
-
originalAIMessageId: import_langgraph.Annotation
|
|
54
|
-
});
|
|
55
|
-
var CopilotKitStateAnnotation = import_langgraph.Annotation.Root({
|
|
56
|
-
copilotkit: import_langgraph.Annotation,
|
|
57
|
-
...import_langgraph.MessagesAnnotation.spec
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// src/langgraph/utils.ts
|
|
61
|
-
var import_dispatch = require("@langchain/core/callbacks/dispatch");
|
|
62
|
-
var import_shared = require("@copilotkit/shared");
|
|
63
|
-
var import_langgraph2 = require("@langchain/langgraph");
|
|
64
|
-
var import_tools = require("@langchain/core/tools");
|
|
65
|
-
var import_messages = require("@langchain/core/messages");
|
|
66
|
-
function copilotkitCustomizeConfig(baseConfig, options) {
|
|
67
|
-
if (baseConfig && typeof baseConfig !== "object") {
|
|
68
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
69
|
-
message: "baseConfig must be an object or null/undefined"
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (options && typeof options !== "object") {
|
|
73
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
74
|
-
message: "options must be an object when provided"
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (options == null ? void 0 : options.emitIntermediateState) {
|
|
78
|
-
if (!Array.isArray(options.emitIntermediateState)) {
|
|
79
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
80
|
-
message: "emitIntermediateState must be an array when provided"
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
options.emitIntermediateState.forEach((state, index) => {
|
|
84
|
-
if (!state || typeof state !== "object") {
|
|
85
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
86
|
-
message: `emitIntermediateState[${index}] must be an object`
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (!state.stateKey || typeof state.stateKey !== "string") {
|
|
90
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
91
|
-
message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
if (!state.tool || typeof state.tool !== "string") {
|
|
95
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
96
|
-
message: `emitIntermediateState[${index}] must have a valid 'tool' string property`
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (state.toolArgument && typeof state.toolArgument !== "string") {
|
|
100
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
101
|
-
message: `emitIntermediateState[${index}].toolArgument must be a string when provided`
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
|
|
108
|
-
if (options == null ? void 0 : options.emitAll) {
|
|
109
|
-
metadata["copilotkit:emit-tool-calls"] = true;
|
|
110
|
-
metadata["copilotkit:emit-messages"] = true;
|
|
111
|
-
} else {
|
|
112
|
-
if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
|
|
113
|
-
metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
|
|
114
|
-
}
|
|
115
|
-
if ((options == null ? void 0 : options.emitMessages) !== void 0) {
|
|
116
|
-
metadata["copilotkit:emit-messages"] = options.emitMessages;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (options == null ? void 0 : options.emitIntermediateState) {
|
|
120
|
-
const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
|
|
121
|
-
tool: state.tool,
|
|
122
|
-
tool_argument: state.toolArgument,
|
|
123
|
-
state_key: state.stateKey
|
|
124
|
-
}));
|
|
125
|
-
metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
|
|
126
|
-
}
|
|
127
|
-
baseConfig = baseConfig || {};
|
|
128
|
-
return {
|
|
129
|
-
...baseConfig,
|
|
130
|
-
metadata
|
|
131
|
-
};
|
|
132
|
-
} catch (error) {
|
|
133
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
134
|
-
message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
__name(copilotkitCustomizeConfig, "copilotkitCustomizeConfig");
|
|
139
|
-
async function copilotkitExit(config) {
|
|
140
|
-
if (!config) {
|
|
141
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
142
|
-
message: "LangGraph configuration is required for copilotkitExit"
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
await (0, import_dispatch.dispatchCustomEvent)("copilotkit_exit", {}, config);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
149
|
-
message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
__name(copilotkitExit, "copilotkitExit");
|
|
154
|
-
async function copilotkitEmitState(config, state) {
|
|
155
|
-
if (!config) {
|
|
156
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
157
|
-
message: "LangGraph configuration is required for copilotkitEmitState"
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (state === void 0) {
|
|
161
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
162
|
-
message: "State is required for copilotkitEmitState"
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_intermediate_state", state, config);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
169
|
-
message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
__name(copilotkitEmitState, "copilotkitEmitState");
|
|
174
|
-
async function copilotkitEmitMessage(config, message) {
|
|
175
|
-
if (!config) {
|
|
176
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
177
|
-
message: "LangGraph configuration is required for copilotkitEmitMessage"
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
if (!message || typeof message !== "string") {
|
|
181
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
182
|
-
message: "Message must be a non-empty string for copilotkitEmitMessage"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_message", {
|
|
187
|
-
message,
|
|
188
|
-
message_id: (0, import_shared.randomId)(),
|
|
189
|
-
role: "assistant"
|
|
190
|
-
}, config);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
193
|
-
message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
__name(copilotkitEmitMessage, "copilotkitEmitMessage");
|
|
198
|
-
async function copilotkitEmitToolCall(config, name, args) {
|
|
199
|
-
if (!config) {
|
|
200
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
201
|
-
message: "LangGraph configuration is required for copilotkitEmitToolCall"
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if (!name || typeof name !== "string") {
|
|
205
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
206
|
-
message: "Tool name must be a non-empty string for copilotkitEmitToolCall"
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
if (args === void 0) {
|
|
210
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
211
|
-
message: "Tool arguments are required for copilotkitEmitToolCall"
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_tool_call", {
|
|
216
|
-
name,
|
|
217
|
-
args,
|
|
218
|
-
id: (0, import_shared.randomId)()
|
|
219
|
-
}, config);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
222
|
-
message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}`
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
__name(copilotkitEmitToolCall, "copilotkitEmitToolCall");
|
|
227
|
-
function convertActionToDynamicStructuredTool(actionInput) {
|
|
228
|
-
if (!actionInput) {
|
|
229
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
230
|
-
message: "Action input is required but was not provided"
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (!actionInput.name || typeof actionInput.name !== "string") {
|
|
234
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
235
|
-
message: "Action must have a valid 'name' property of type string"
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
if (actionInput.description == void 0 || actionInput.description == null || typeof actionInput.description !== "string") {
|
|
239
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
240
|
-
message: `Action '${actionInput.name}' must have a valid 'description' property of type string`
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
if (!actionInput.parameters) {
|
|
244
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
245
|
-
message: `Action '${actionInput.name}' must have a 'parameters' property`
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
try {
|
|
249
|
-
return new import_tools.DynamicStructuredTool({
|
|
250
|
-
name: actionInput.name,
|
|
251
|
-
description: actionInput.description,
|
|
252
|
-
schema: (0, import_shared.convertJsonSchemaToZodSchema)(actionInput.parameters, true),
|
|
253
|
-
func: async () => {
|
|
254
|
-
return "";
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
} catch (error) {
|
|
258
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
259
|
-
message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
__name(convertActionToDynamicStructuredTool, "convertActionToDynamicStructuredTool");
|
|
264
|
-
function convertActionsToDynamicStructuredTools(actions) {
|
|
265
|
-
if (!Array.isArray(actions)) {
|
|
266
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
267
|
-
message: "Actions must be an array"
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
return actions.map((action, index) => {
|
|
271
|
-
try {
|
|
272
|
-
return convertActionToDynamicStructuredTool(action.type === "function" ? action.function : action);
|
|
273
|
-
} catch (error) {
|
|
274
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
275
|
-
message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
__name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
|
|
281
|
-
function copilotKitInterrupt({ message, action, args }) {
|
|
282
|
-
if (!message && !action) {
|
|
283
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
284
|
-
message: "Either message or action (and optional arguments) must be provided for copilotKitInterrupt"
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
if (action && typeof action !== "string") {
|
|
288
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
289
|
-
message: "Action must be a string when provided to copilotKitInterrupt"
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
if (message && typeof message !== "string") {
|
|
293
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
294
|
-
message: "Message must be a string when provided to copilotKitInterrupt"
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
if (args && typeof args !== "object") {
|
|
298
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
299
|
-
message: "Args must be an object when provided to copilotKitInterrupt"
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
let interruptValues = null;
|
|
303
|
-
let interruptMessage = null;
|
|
304
|
-
let answer = null;
|
|
305
|
-
try {
|
|
306
|
-
if (message) {
|
|
307
|
-
interruptValues = message;
|
|
308
|
-
interruptMessage = new import_messages.AIMessage({
|
|
309
|
-
content: message,
|
|
310
|
-
id: (0, import_shared.randomId)()
|
|
311
|
-
});
|
|
312
|
-
} else {
|
|
313
|
-
const toolId = (0, import_shared.randomId)();
|
|
314
|
-
interruptMessage = new import_messages.AIMessage({
|
|
315
|
-
content: "",
|
|
316
|
-
tool_calls: [
|
|
317
|
-
{
|
|
318
|
-
id: toolId,
|
|
319
|
-
name: action,
|
|
320
|
-
args: args ?? {}
|
|
321
|
-
}
|
|
322
|
-
]
|
|
323
|
-
});
|
|
324
|
-
interruptValues = {
|
|
325
|
-
action,
|
|
326
|
-
args: args ?? {}
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
const response = (0, import_langgraph2.interrupt)({
|
|
330
|
-
__copilotkit_interrupt_value__: interruptValues,
|
|
331
|
-
__copilotkit_messages__: [
|
|
332
|
-
interruptMessage
|
|
333
|
-
]
|
|
334
|
-
});
|
|
335
|
-
answer = response[response.length - 1].content;
|
|
336
|
-
return {
|
|
337
|
-
answer,
|
|
338
|
-
messages: response
|
|
339
|
-
};
|
|
340
|
-
} catch (error) {
|
|
341
|
-
throw new import_shared.CopilotKitMisuseError({
|
|
342
|
-
message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}`
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
__name(copilotKitInterrupt, "copilotKitInterrupt");
|
|
347
|
-
|
|
348
|
-
// src/langgraph/middleware.ts
|
|
349
|
-
var import_langchain = require("langchain");
|
|
350
|
-
var z = __toESM(require("zod"));
|
|
351
|
-
var createAppContextBeforeAgent = /* @__PURE__ */ __name((state, runtime) => {
|
|
352
|
-
var _a, _b, _c;
|
|
353
|
-
const messages = state.messages;
|
|
354
|
-
if (!messages || messages.length === 0) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
const appContext = ((_a = state["copilotkit"]) == null ? void 0 : _a.context) ?? (runtime == null ? void 0 : runtime.context);
|
|
358
|
-
const isEmptyContext = !appContext || typeof appContext === "string" && appContext.trim() === "" || typeof appContext === "object" && Object.keys(appContext).length === 0;
|
|
359
|
-
if (isEmptyContext) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const contextContent = typeof appContext === "string" ? appContext : JSON.stringify(appContext, null, 2);
|
|
363
|
-
const contextMessageContent = `App Context:
|
|
364
|
-
${contextContent}`;
|
|
365
|
-
const contextMessagePrefix = "App Context:\n";
|
|
366
|
-
const getContentString = /* @__PURE__ */ __name((msg) => {
|
|
367
|
-
var _a2;
|
|
368
|
-
if (typeof msg.content === "string")
|
|
369
|
-
return msg.content;
|
|
370
|
-
if (Array.isArray(msg.content) && ((_a2 = msg.content[0]) == null ? void 0 : _a2.text))
|
|
371
|
-
return msg.content[0].text;
|
|
372
|
-
return null;
|
|
373
|
-
}, "getContentString");
|
|
374
|
-
let firstSystemIndex = -1;
|
|
375
|
-
for (let i = 0; i < messages.length; i++) {
|
|
376
|
-
const msg = messages[i];
|
|
377
|
-
const type = (_b = msg._getType) == null ? void 0 : _b.call(msg);
|
|
378
|
-
if (type === "system" || type === "developer") {
|
|
379
|
-
const content = getContentString(msg);
|
|
380
|
-
if (content == null ? void 0 : content.startsWith(contextMessagePrefix)) {
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
firstSystemIndex = i;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
let existingContextIndex = -1;
|
|
388
|
-
for (let i = 0; i < messages.length; i++) {
|
|
389
|
-
const msg = messages[i];
|
|
390
|
-
const type = (_c = msg._getType) == null ? void 0 : _c.call(msg);
|
|
391
|
-
if (type === "system" || type === "developer") {
|
|
392
|
-
const content = getContentString(msg);
|
|
393
|
-
if (content == null ? void 0 : content.startsWith(contextMessagePrefix)) {
|
|
394
|
-
existingContextIndex = i;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
const contextMessage = new import_langchain.SystemMessage({
|
|
400
|
-
content: contextMessageContent
|
|
401
|
-
});
|
|
402
|
-
let updatedMessages;
|
|
403
|
-
if (existingContextIndex !== -1) {
|
|
404
|
-
updatedMessages = [
|
|
405
|
-
...messages
|
|
406
|
-
];
|
|
407
|
-
updatedMessages[existingContextIndex] = contextMessage;
|
|
408
|
-
} else {
|
|
409
|
-
const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;
|
|
410
|
-
updatedMessages = [
|
|
411
|
-
...messages.slice(0, insertIndex),
|
|
412
|
-
contextMessage,
|
|
413
|
-
...messages.slice(insertIndex)
|
|
414
|
-
];
|
|
415
|
-
}
|
|
416
|
-
return {
|
|
417
|
-
...state,
|
|
418
|
-
messages: updatedMessages
|
|
419
|
-
};
|
|
420
|
-
}, "createAppContextBeforeAgent");
|
|
421
|
-
var copilotKitStateSchema = z.object({
|
|
422
|
-
copilotkit: z.object({
|
|
423
|
-
actions: z.array(z.any()),
|
|
424
|
-
context: z.any().optional(),
|
|
425
|
-
interceptedToolCalls: z.array(z.any()).optional(),
|
|
426
|
-
originalAIMessageId: z.string().optional()
|
|
427
|
-
}).optional()
|
|
428
|
-
});
|
|
429
|
-
var middlewareInput = {
|
|
430
|
-
name: "CopilotKitMiddleware",
|
|
431
|
-
stateSchema: copilotKitStateSchema,
|
|
432
|
-
// Inject frontend tools before model call
|
|
433
|
-
wrapModelCall: async (request, handler) => {
|
|
434
|
-
var _a;
|
|
435
|
-
const frontendTools = ((_a = request.state["copilotkit"]) == null ? void 0 : _a.actions) ?? [];
|
|
436
|
-
if (frontendTools.length === 0) {
|
|
437
|
-
return handler(request);
|
|
438
|
-
}
|
|
439
|
-
const existingTools = request.tools || [];
|
|
440
|
-
const mergedTools = [
|
|
441
|
-
...existingTools,
|
|
442
|
-
...frontendTools
|
|
443
|
-
];
|
|
444
|
-
return handler({
|
|
445
|
-
...request,
|
|
446
|
-
tools: mergedTools
|
|
447
|
-
});
|
|
448
|
-
},
|
|
449
|
-
beforeAgent: createAppContextBeforeAgent,
|
|
450
|
-
// Restore frontend tool calls to AIMessage before agent exits
|
|
451
|
-
afterAgent: (state) => {
|
|
452
|
-
var _a, _b;
|
|
453
|
-
const interceptedToolCalls = (_a = state["copilotkit"]) == null ? void 0 : _a.interceptedToolCalls;
|
|
454
|
-
const originalMessageId = (_b = state["copilotkit"]) == null ? void 0 : _b.originalAIMessageId;
|
|
455
|
-
if (!(interceptedToolCalls == null ? void 0 : interceptedToolCalls.length) || !originalMessageId) {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
let messageFound = false;
|
|
459
|
-
const updatedMessages = state.messages.map((msg) => {
|
|
460
|
-
if (import_langchain.AIMessage.isInstance(msg) && msg.id === originalMessageId) {
|
|
461
|
-
messageFound = true;
|
|
462
|
-
const existingToolCalls = msg.tool_calls || [];
|
|
463
|
-
return new import_langchain.AIMessage({
|
|
464
|
-
content: msg.content,
|
|
465
|
-
tool_calls: [
|
|
466
|
-
...existingToolCalls,
|
|
467
|
-
...interceptedToolCalls
|
|
468
|
-
],
|
|
469
|
-
id: msg.id
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
return msg;
|
|
473
|
-
});
|
|
474
|
-
if (!messageFound) {
|
|
475
|
-
console.warn(`CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`);
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
return {
|
|
479
|
-
messages: updatedMessages,
|
|
480
|
-
copilotkit: {
|
|
481
|
-
...state["copilotkit"] ?? {},
|
|
482
|
-
interceptedToolCalls: void 0,
|
|
483
|
-
originalAIMessageId: void 0
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
},
|
|
487
|
-
// Intercept frontend tool calls after model returns, before ToolNode executes
|
|
488
|
-
afterModel: (state) => {
|
|
489
|
-
var _a, _b;
|
|
490
|
-
const frontendTools = ((_a = state["copilotkit"]) == null ? void 0 : _a.actions) ?? [];
|
|
491
|
-
if (frontendTools.length === 0)
|
|
492
|
-
return;
|
|
493
|
-
const frontendToolNames = new Set(frontendTools.map((t) => {
|
|
494
|
-
var _a2;
|
|
495
|
-
return ((_a2 = t.function) == null ? void 0 : _a2.name) || t.name;
|
|
496
|
-
}));
|
|
497
|
-
const lastMessage = state.messages[state.messages.length - 1];
|
|
498
|
-
if (!import_langchain.AIMessage.isInstance(lastMessage) || !((_b = lastMessage.tool_calls) == null ? void 0 : _b.length)) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const backendToolCalls = [];
|
|
502
|
-
const frontendToolCalls = [];
|
|
503
|
-
for (const call of lastMessage.tool_calls) {
|
|
504
|
-
if (frontendToolNames.has(call.name)) {
|
|
505
|
-
frontendToolCalls.push(call);
|
|
506
|
-
} else {
|
|
507
|
-
backendToolCalls.push(call);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (frontendToolCalls.length === 0)
|
|
511
|
-
return;
|
|
512
|
-
const updatedAIMessage = new import_langchain.AIMessage({
|
|
513
|
-
content: lastMessage.content,
|
|
514
|
-
tool_calls: backendToolCalls,
|
|
515
|
-
id: lastMessage.id
|
|
516
|
-
});
|
|
517
|
-
return {
|
|
518
|
-
messages: [
|
|
519
|
-
...state.messages.slice(0, -1),
|
|
520
|
-
updatedAIMessage
|
|
521
|
-
],
|
|
522
|
-
copilotkit: {
|
|
523
|
-
...state["copilotkit"] ?? {},
|
|
524
|
-
interceptedToolCalls: frontendToolCalls,
|
|
525
|
-
originalAIMessageId: lastMessage.id
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
var createCopilotKitMiddleware = /* @__PURE__ */ __name(() => {
|
|
531
|
-
return (0, import_langchain.createMiddleware)(middlewareInput);
|
|
532
|
-
}, "createCopilotKitMiddleware");
|
|
533
|
-
var copilotkitMiddleware = createCopilotKitMiddleware();
|
|
534
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
535
|
-
0 && (module.exports = {
|
|
536
|
-
CopilotKitPropertiesAnnotation,
|
|
537
|
-
CopilotKitStateAnnotation,
|
|
538
|
-
convertActionToDynamicStructuredTool,
|
|
539
|
-
convertActionsToDynamicStructuredTools,
|
|
540
|
-
copilotKitInterrupt,
|
|
541
|
-
copilotkitCustomizeConfig,
|
|
542
|
-
copilotkitEmitMessage,
|
|
543
|
-
copilotkitEmitState,
|
|
544
|
-
copilotkitEmitToolCall,
|
|
545
|
-
copilotkitExit,
|
|
546
|
-
copilotkitMiddleware
|
|
547
|
-
});
|
|
548
|
-
//# sourceMappingURL=langgraph.js.map
|
package/dist/langgraph.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/langgraph/index.ts","../src/langgraph/types.ts","../src/langgraph/utils.ts","../src/langgraph/middleware.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./utils\";\nexport * from \"./middleware\";\n","import { Annotation, MessagesAnnotation } from \"@langchain/langgraph\";\n\nexport const CopilotKitPropertiesAnnotation = Annotation.Root({\n actions: Annotation<any[]>,\n context: Annotation<{ description: string; value: string }[]>,\n interceptedToolCalls: Annotation<any[]>,\n originalAIMessageId: Annotation<string>,\n});\n\nexport const CopilotKitStateAnnotation = Annotation.Root({\n copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,\n ...MessagesAnnotation.spec,\n});\n\nexport interface IntermediateStateConfig {\n stateKey: string;\n tool: string;\n toolArgument?: string;\n}\n\nexport interface OptionsConfig {\n emitToolCalls?: boolean | string | string[];\n emitMessages?: boolean;\n emitAll?: boolean;\n emitIntermediateState?: IntermediateStateConfig[];\n}\n\nexport type CopilotKitState = typeof CopilotKitStateAnnotation.State;\nexport type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;\n","import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport {\n convertJsonSchemaToZodSchema,\n randomId,\n CopilotKitMisuseError,\n} from \"@copilotkit/shared\";\nimport { interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\nimport { OptionsConfig } from \"./types\";\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(\n (state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }),\n );\n\n metadata[\"copilotkit:emit-intermediate-state\"] =\n 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(\n \"copilotkit_manually_emit_intermediate_state\",\n state,\n config,\n );\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:\n \"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(\n actionInput: any,\n): 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 (\n actionInput.description == undefined ||\n actionInput.description == null ||\n typeof actionInput.description !== \"string\"\n ) {\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(\n action.type === \"function\" ? action.function : action,\n );\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","import { createMiddleware, AIMessage, SystemMessage } from \"langchain\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport * as z from \"zod\";\n\nconst createAppContextBeforeAgent = (state, runtime) => {\n const messages = state.messages;\n\n if (!messages || messages.length === 0) {\n return;\n }\n\n // Get app context from runtime\n const appContext = state[\"copilotkit\"]?.context ?? runtime?.context;\n\n // Check if appContext is missing or empty\n const isEmptyContext =\n !appContext ||\n (typeof appContext === \"string\" && appContext.trim() === \"\") ||\n (typeof appContext === \"object\" && Object.keys(appContext).length === 0);\n\n if (isEmptyContext) {\n return;\n }\n\n // Create the context content\n const contextContent =\n typeof appContext === \"string\"\n ? appContext\n : JSON.stringify(appContext, null, 2);\n const contextMessageContent = `App Context:\\n${contextContent}`;\n const contextMessagePrefix = \"App Context:\\n\";\n\n // Helper to get message content as string\n const getContentString = (msg: any): string | null => {\n if (typeof msg.content === \"string\") return msg.content;\n if (Array.isArray(msg.content) && msg.content[0]?.text)\n return msg.content[0].text;\n return null;\n };\n\n // Find the first system/developer message (not our context message) to determine\n // where to insert our context message (right after it)\n let firstSystemIndex = -1;\n\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n // Skip if this is our own context message\n if (content?.startsWith(contextMessagePrefix)) {\n continue;\n }\n firstSystemIndex = i;\n break;\n }\n }\n\n // Check if our context message already exists\n let existingContextIndex = -1;\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n if (content?.startsWith(contextMessagePrefix)) {\n existingContextIndex = i;\n break;\n }\n }\n }\n\n // Create the context message\n const contextMessage = new SystemMessage({ content: contextMessageContent });\n\n let updatedMessages;\n\n if (existingContextIndex !== -1) {\n // Replace existing context message\n updatedMessages = [...messages];\n updatedMessages[existingContextIndex] = contextMessage;\n } else {\n // Insert after the first system message, or at position 0 if no system message\n const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;\n updatedMessages = [\n ...messages.slice(0, insertIndex),\n contextMessage,\n ...messages.slice(insertIndex),\n ];\n }\n\n return {\n ...state,\n messages: updatedMessages,\n };\n};\n\n/**\n * CopilotKit Middleware for LangGraph agents.\n *\n * Enables:\n * - Dynamic frontend tools from state.tools\n * - Context provided from CopilotKit useCopilotReadable\n *\n * Works with any agent (prebuilt or custom).\n *\n * @example\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { copilotkitMiddleware } from \"@copilotkit/sdk-js/langgraph\";\n *\n * const agent = createAgent({\n * model: \"gpt-4o\",\n * tools: [backendTool],\n * middleware: [copilotkitMiddleware],\n * });\n * ```\n */\nconst copilotKitStateSchema = z.object({\n copilotkit: z\n .object({\n actions: z.array(z.any()),\n context: z.any().optional(),\n interceptedToolCalls: z.array(z.any()).optional(),\n originalAIMessageId: z.string().optional(),\n })\n .optional(),\n});\n\nconst middlewareInput = {\n name: \"CopilotKitMiddleware\",\n\n stateSchema: copilotKitStateSchema as unknown as InteropZodObject,\n\n // Inject frontend tools before model call\n wrapModelCall: async (request, handler) => {\n const frontendTools = request.state[\"copilotkit\"]?.actions ?? [];\n\n if (frontendTools.length === 0) {\n return handler(request);\n }\n\n const existingTools = request.tools || [];\n const mergedTools = [...existingTools, ...frontendTools];\n\n return handler({\n ...request,\n tools: mergedTools,\n });\n },\n\n beforeAgent: createAppContextBeforeAgent,\n\n // Restore frontend tool calls to AIMessage before agent exits\n afterAgent: (state) => {\n const interceptedToolCalls = state[\"copilotkit\"]?.interceptedToolCalls;\n const originalMessageId = state[\"copilotkit\"]?.originalAIMessageId;\n\n if (!interceptedToolCalls?.length || !originalMessageId) {\n return;\n }\n\n let messageFound = false;\n const updatedMessages = state.messages.map((msg: any) => {\n if (AIMessage.isInstance(msg) && msg.id === originalMessageId) {\n messageFound = true;\n const existingToolCalls = msg.tool_calls || [];\n return new AIMessage({\n content: msg.content,\n tool_calls: [...existingToolCalls, ...interceptedToolCalls],\n id: msg.id,\n });\n }\n return msg;\n });\n\n // Only clear intercepted state if we successfully restored the tool calls\n if (!messageFound) {\n console.warn(\n `CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`,\n );\n return;\n }\n\n return {\n messages: updatedMessages,\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: undefined,\n originalAIMessageId: undefined,\n },\n };\n },\n\n // Intercept frontend tool calls after model returns, before ToolNode executes\n afterModel: (state) => {\n const frontendTools = state[\"copilotkit\"]?.actions ?? [];\n if (frontendTools.length === 0) return;\n\n const frontendToolNames = new Set(\n frontendTools.map((t: any) => t.function?.name || t.name),\n );\n\n const lastMessage = state.messages[state.messages.length - 1];\n if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls?.length) {\n return;\n }\n\n const backendToolCalls: any[] = [];\n const frontendToolCalls: any[] = [];\n\n for (const call of lastMessage.tool_calls) {\n if (frontendToolNames.has(call.name)) {\n frontendToolCalls.push(call);\n } else {\n backendToolCalls.push(call);\n }\n }\n\n if (frontendToolCalls.length === 0) return;\n\n const updatedAIMessage = new AIMessage({\n content: lastMessage.content,\n tool_calls: backendToolCalls,\n id: lastMessage.id,\n });\n\n return {\n messages: [...state.messages.slice(0, -1), updatedAIMessage],\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: frontendToolCalls,\n originalAIMessageId: lastMessage.id,\n },\n };\n },\n} as any;\nconst createCopilotKitMiddleware = () => {\n return createMiddleware(middlewareInput);\n};\n\nexport const copilotkitMiddleware = createCopilotKitMiddleware();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;ACAA,uBAA+C;AAExC,IAAMA,iCAAiCC,4BAAWC,KAAK;EAC5DC,SAASF;EACTG,SAASH;EACTI,sBAAsBJ;EACtBK,qBAAqBL;AACvB,CAAA;AAEO,IAAMM,4BAA4BN,4BAAWC,KAAK;EACvDM,YAAYP;EACZ,GAAGQ,oCAAmBC;AACxB,CAAA;;;ACXA,sBAAoC;AACpC,oBAIO;AACP,IAAAC,oBAA0B;AAC1B,mBAAsC;AACtC,sBAA0B;AA6CnB,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,MAAID,cAAc,OAAOA,eAAe,UAAU;AAChD,UAAM,IAAIE,oCAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAEA,MAAIF,WAAW,OAAOA,YAAY,UAAU;AAC1C,UAAM,IAAIC,oCAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAGA,MAAIF,mCAASG,uBAAuB;AAClC,QAAI,CAACC,MAAMC,QAAQL,QAAQG,qBAAqB,GAAG;AACjD,YAAM,IAAIF,oCAAsB;QAC9BC,SAAS;MACX,CAAA;IACF;AAEAF,YAAQG,sBAAsBG,QAAQ,CAACC,OAAOC,UAAAA;AAC5C,UAAI,CAACD,SAAS,OAAOA,UAAU,UAAU;AACvC,cAAM,IAAIN,oCAAsB;UAC9BC,SAAS,yBAAy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alls","originalAIMessageId","CopilotKitStateAnnotation","copilotkit","MessagesAnnotation","spec","import_langgraph","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","actions","action","type","function","copilotKitInterrupt","interruptValues","interruptMessage","answer","AIMessage","content","toolId","tool_calls","response","interrupt","__copilotkit_interrupt_value__","__copilotkit_messages__","length","messages","createAppContextBeforeAgent","state","runtime","messages","length","appContext","context","isEmptyContext","trim","Object","keys","contextContent","JSON","stringify","contextMessageContent","contextMessagePrefix","getContentString","msg","_a","content","Array","isArray","text","firstSystemIndex","i","type","_getType","startsWith","existingContextIndex","contextMessage","SystemMessage","updatedMessages","insertIndex","slice","copilotKitStateSchema","object","copilotkit","actions","array","any","optional","interceptedToolCalls","originalAIMessageId","string","middlewareInput","name","stateSchema","wrapModelCall","request","handler","frontendTools","existingTools","tools","mergedTools","beforeAgent","afterAgent","originalMessageId","messageFound","map","AIMessage","isInstance","id","existingToolCalls","tool_calls","console","warn","undefined","afterModel","frontendToolNames","Set","t","function","lastMessage","backendToolCalls","frontendToolCalls","call","has","push","updatedAIMessage","createCopilotKitMiddleware","createMiddleware","copilotkitMiddleware"]}
|
package/dist/langgraph.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/jest.config.js
DELETED
package/tsup.config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineConfig, Options } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig((options: Options) => ({
|
|
4
|
-
...options,
|
|
5
|
-
entry: {
|
|
6
|
-
index: "src/index.ts",
|
|
7
|
-
langchain: "src/langchain.ts",
|
|
8
|
-
langgraph: "src/langgraph/index.ts",
|
|
9
|
-
},
|
|
10
|
-
format: ["esm", "cjs"],
|
|
11
|
-
dts: {
|
|
12
|
-
entry: ["src/index.ts", "src/langchain.ts", "src/langgraph/index.ts"],
|
|
13
|
-
},
|
|
14
|
-
minify: false,
|
|
15
|
-
external: [],
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
entryNames: "[name]",
|
|
18
|
-
exclude: [
|
|
19
|
-
"**/*.test.ts", // Exclude TypeScript test files
|
|
20
|
-
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
21
|
-
"**/__tests__/*", // Exclude any files inside a __tests__ directory
|
|
22
|
-
],
|
|
23
|
-
}));
|