@copilotkit/runtime 1.3.11 → 1.3.12-feat-langgraph-cloud-release-alpha.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.
- package/CHANGELOG.md +8 -0
- package/dist/{chunk-REA4Z4VP.mjs → chunk-6A7HQSQE.mjs} +2 -2
- package/dist/{chunk-ZSMR26MX.mjs → chunk-BPLF4QB2.mjs} +2 -2
- package/dist/{chunk-BYL3ABWM.mjs → chunk-IPCABAGS.mjs} +2 -2
- package/dist/{chunk-AP2CCJ3J.mjs → chunk-RKGJG3QX.mjs} +552 -122
- package/dist/chunk-RKGJG3QX.mjs.map +1 -0
- package/dist/{chunk-ZUQH5YKI.mjs → chunk-Z5LICW7Z.mjs} +35 -8
- package/dist/chunk-Z5LICW7Z.mjs.map +1 -0
- package/dist/{copilot-runtime-df3527ad.d.ts → copilot-runtime-aba7d4b4.d.ts} +27 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +625 -168
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -7
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +625 -168
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -7
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +3 -1
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +3 -1
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +3 -1
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +3 -1
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/package.json +6 -4
- package/src/agents/langgraph/event-source.ts +22 -67
- package/src/lib/runtime/copilot-runtime.ts +58 -11
- package/src/lib/runtime/remote-action-constructors.ts +281 -0
- package/src/lib/runtime/remote-actions.ts +65 -159
- package/src/lib/runtime/remote-lg-cloud-action.ts +438 -0
- package/dist/chunk-AP2CCJ3J.mjs.map +0 -1
- package/dist/chunk-ZUQH5YKI.mjs.map +0 -1
- /package/dist/{chunk-REA4Z4VP.mjs.map → chunk-6A7HQSQE.mjs.map} +0 -0
- /package/dist/{chunk-ZSMR26MX.mjs.map → chunk-BPLF4QB2.mjs.map} +0 -0
- /package/dist/{chunk-BYL3ABWM.mjs.map → chunk-IPCABAGS.mjs.map} +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.3.
|
|
47
|
+
version: "1.3.12-feat-langgraph-cloud-release-alpha.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -86,6 +86,7 @@ var require_package = __commonJS({
|
|
|
86
86
|
"@graphql-yoga/plugin-defer-stream": "^3.3.1",
|
|
87
87
|
"@langchain/community": "^0.0.53",
|
|
88
88
|
"@langchain/core": "^0.3.13",
|
|
89
|
+
"@langchain/langgraph-sdk": "^0.0.16",
|
|
89
90
|
"@langchain/openai": "^0.0.28",
|
|
90
91
|
"class-transformer": "^0.5.1",
|
|
91
92
|
express: "^4.19.2",
|
|
@@ -95,6 +96,7 @@ var require_package = __commonJS({
|
|
|
95
96
|
"groq-sdk": "^0.5.0",
|
|
96
97
|
langchain: "^0.3.3",
|
|
97
98
|
openai: "^4.50.0",
|
|
99
|
+
"partial-json": "^0.1.7",
|
|
98
100
|
pino: "^9.2.0",
|
|
99
101
|
"pino-pretty": "^11.2.1",
|
|
100
102
|
"reflect-metadata": "^0.2.2",
|
|
@@ -130,6 +132,7 @@ __export(lib_exports, {
|
|
|
130
132
|
UnifyAdapter: () => UnifyAdapter,
|
|
131
133
|
buildSchema: () => buildSchema,
|
|
132
134
|
config: () => config,
|
|
135
|
+
copilotKitEndpoint: () => copilotKitEndpoint,
|
|
133
136
|
copilotRuntimeNestEndpoint: () => copilotRuntimeNestEndpoint,
|
|
134
137
|
copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
|
|
135
138
|
copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -137,7 +140,8 @@ __export(lib_exports, {
|
|
|
137
140
|
copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
|
|
138
141
|
createContext: () => createContext,
|
|
139
142
|
flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
|
|
140
|
-
getCommonConfig: () => getCommonConfig
|
|
143
|
+
getCommonConfig: () => getCommonConfig,
|
|
144
|
+
langGraphCloudEndpoint: () => langGraphCloudEndpoint
|
|
141
145
|
});
|
|
142
146
|
module.exports = __toCommonJS(lib_exports);
|
|
143
147
|
|
|
@@ -1064,50 +1068,6 @@ var LangGraphEventTypes;
|
|
|
1064
1068
|
var import_shared7 = require("@copilotkit/shared");
|
|
1065
1069
|
var RemoteLangGraphEventSource = class {
|
|
1066
1070
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1067
|
-
async streamResponse(response) {
|
|
1068
|
-
const reader = response.body.getReader();
|
|
1069
|
-
const decoder = new TextDecoder();
|
|
1070
|
-
let buffer = [];
|
|
1071
|
-
const eventStream$ = this.eventStream$;
|
|
1072
|
-
function flushBuffer() {
|
|
1073
|
-
const currentBuffer = buffer.join("");
|
|
1074
|
-
if (currentBuffer.trim().length === 0) {
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
const parts = currentBuffer.split("\n");
|
|
1078
|
-
if (parts.length === 0) {
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
1082
|
-
buffer = [];
|
|
1083
|
-
if (!lastPartIsComplete) {
|
|
1084
|
-
buffer.push(parts.pop());
|
|
1085
|
-
}
|
|
1086
|
-
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
1087
|
-
eventStream$.next(JSON.parse(part));
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
__name(flushBuffer, "flushBuffer");
|
|
1091
|
-
try {
|
|
1092
|
-
while (true) {
|
|
1093
|
-
const { done, value } = await reader.read();
|
|
1094
|
-
if (!done) {
|
|
1095
|
-
buffer.push(decoder.decode(value, {
|
|
1096
|
-
stream: true
|
|
1097
|
-
}));
|
|
1098
|
-
}
|
|
1099
|
-
flushBuffer();
|
|
1100
|
-
if (done) {
|
|
1101
|
-
break;
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
} catch (error) {
|
|
1105
|
-
console.error("Error in stream", error);
|
|
1106
|
-
eventStream$.error(error);
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
eventStream$.complete();
|
|
1110
|
-
}
|
|
1111
1071
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
1112
1072
|
if (typeof shouldEmitToolCalls === "boolean") {
|
|
1113
1073
|
return shouldEmitToolCalls;
|
|
@@ -1130,20 +1090,25 @@ var RemoteLangGraphEventSource = class {
|
|
|
1130
1090
|
} else {
|
|
1131
1091
|
acc.content = null;
|
|
1132
1092
|
}
|
|
1133
|
-
|
|
1093
|
+
const toolCallChunks = (
|
|
1094
|
+
// @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
|
|
1095
|
+
((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
|
|
1096
|
+
);
|
|
1097
|
+
const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
|
|
1098
|
+
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
1134
1099
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1135
|
-
acc.toolCallMessageId =
|
|
1136
|
-
if ((
|
|
1137
|
-
acc.toolCallName =
|
|
1100
|
+
acc.toolCallMessageId = toolCallMessageId;
|
|
1101
|
+
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1102
|
+
acc.toolCallName = toolCallChunks[0].name;
|
|
1138
1103
|
}
|
|
1139
|
-
if ((
|
|
1140
|
-
acc.toolCallId =
|
|
1104
|
+
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1105
|
+
acc.toolCallId = toolCallChunks[0].id;
|
|
1141
1106
|
}
|
|
1142
1107
|
acc.prevMessageId = acc.messageId;
|
|
1143
|
-
acc.messageId =
|
|
1108
|
+
acc.messageId = toolCallMessageId;
|
|
1144
1109
|
} else if (acc.content && acc.content != "") {
|
|
1145
1110
|
acc.prevMessageId = acc.messageId;
|
|
1146
|
-
acc.messageId =
|
|
1111
|
+
acc.messageId = toolCallMessageId;
|
|
1147
1112
|
} else {
|
|
1148
1113
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1149
1114
|
acc.prevMessageId = acc.messageId;
|
|
@@ -1168,7 +1133,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1168
1133
|
prevMessageId: null,
|
|
1169
1134
|
content: null
|
|
1170
1135
|
}), (0, import_rxjs.mergeMap)((eventWithState) => {
|
|
1171
|
-
var _a, _b, _c, _d, _e;
|
|
1136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1172
1137
|
const events = [];
|
|
1173
1138
|
let shouldEmitMessages = true;
|
|
1174
1139
|
let shouldEmitToolCalls = false;
|
|
@@ -1251,7 +1216,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1251
1216
|
});
|
|
1252
1217
|
}
|
|
1253
1218
|
}
|
|
1254
|
-
const args = (_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args
|
|
1219
|
+
const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
|
|
1220
|
+
((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
|
|
1255
1221
|
const content = eventWithState.content;
|
|
1256
1222
|
if (args) {
|
|
1257
1223
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
@@ -1302,70 +1268,441 @@ var RemoteLangGraphEventSource = class {
|
|
|
1302
1268
|
};
|
|
1303
1269
|
__name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
1304
1270
|
|
|
1305
|
-
// src/lib/runtime/remote-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1271
|
+
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1272
|
+
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1273
|
+
var import_node_crypto = require("crypto");
|
|
1274
|
+
var import_partial_json = require("partial-json");
|
|
1275
|
+
|
|
1276
|
+
// src/graphql/types/enums.ts
|
|
1277
|
+
var import_type_graphql = require("type-graphql");
|
|
1278
|
+
var MessageRole;
|
|
1279
|
+
(function(MessageRole2) {
|
|
1280
|
+
MessageRole2["user"] = "user";
|
|
1281
|
+
MessageRole2["assistant"] = "assistant";
|
|
1282
|
+
MessageRole2["system"] = "system";
|
|
1283
|
+
})(MessageRole || (MessageRole = {}));
|
|
1284
|
+
var ActionExecutionScope;
|
|
1285
|
+
(function(ActionExecutionScope2) {
|
|
1286
|
+
ActionExecutionScope2["server"] = "server";
|
|
1287
|
+
ActionExecutionScope2["client"] = "client";
|
|
1288
|
+
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1289
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1290
|
+
var CopilotRequestType;
|
|
1291
|
+
(function(CopilotRequestType2) {
|
|
1292
|
+
CopilotRequestType2["Chat"] = "Chat";
|
|
1293
|
+
CopilotRequestType2["Task"] = "Task";
|
|
1294
|
+
CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
|
|
1295
|
+
CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
|
|
1296
|
+
CopilotRequestType2["Suggestion"] = "Suggestion";
|
|
1297
|
+
})(CopilotRequestType || (CopilotRequestType = {}));
|
|
1298
|
+
(0, import_type_graphql.registerEnumType)(MessageRole, {
|
|
1299
|
+
name: "MessageRole",
|
|
1300
|
+
description: "The role of the message"
|
|
1301
|
+
});
|
|
1302
|
+
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1303
|
+
name: "ActionExecutionScope",
|
|
1304
|
+
description: "The scope of the action"
|
|
1305
|
+
});
|
|
1306
|
+
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1307
|
+
name: "CopilotRequestType",
|
|
1308
|
+
description: "The type of Copilot request"
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1312
|
+
async function execute(args) {
|
|
1313
|
+
return new ReadableStream({
|
|
1314
|
+
async start(controller) {
|
|
1315
|
+
try {
|
|
1316
|
+
await streamEvents(controller, args);
|
|
1317
|
+
controller.close();
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1311
1322
|
}
|
|
1312
|
-
__name(
|
|
1313
|
-
function
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1323
|
+
__name(execute, "execute");
|
|
1324
|
+
async function streamEvents(controller, args) {
|
|
1325
|
+
const { threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions } = args;
|
|
1326
|
+
let nodeName = initialNodeName;
|
|
1327
|
+
let state = initialState;
|
|
1328
|
+
const { name, assistantId: initialAssistantId } = agent;
|
|
1329
|
+
const client = new import_langgraph_sdk.Client();
|
|
1330
|
+
let initialThreadId = agrsInitialThreadId;
|
|
1331
|
+
const wasInitiatedWithExistingThread = !!initialThreadId;
|
|
1332
|
+
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1333
|
+
initialThreadId = initialThreadId.substring(3);
|
|
1334
|
+
}
|
|
1335
|
+
const assistants = await client.assistants.search();
|
|
1336
|
+
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1337
|
+
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1338
|
+
if (initialThreadId === threadId) {
|
|
1339
|
+
await client.threads.get(threadId);
|
|
1340
|
+
} else {
|
|
1341
|
+
await client.threads.create({
|
|
1342
|
+
threadId
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
let agentState = {
|
|
1346
|
+
values: {}
|
|
1316
1347
|
};
|
|
1317
|
-
if (
|
|
1318
|
-
|
|
1319
|
-
|
|
1348
|
+
if (wasInitiatedWithExistingThread) {
|
|
1349
|
+
agentState = await client.threads.getState(threadId);
|
|
1350
|
+
}
|
|
1351
|
+
const agentStateValues = agentState.values;
|
|
1352
|
+
state.messages = agentStateValues.messages;
|
|
1353
|
+
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1354
|
+
state = langGraphDefaultMergeState(state, formatMessages(messages), actions);
|
|
1355
|
+
if (mode === "continue") {
|
|
1356
|
+
await client.threads.updateState(threadId, {
|
|
1357
|
+
values: state,
|
|
1358
|
+
asNode: nodeName
|
|
1320
1359
|
});
|
|
1321
|
-
|
|
1322
|
-
|
|
1360
|
+
}
|
|
1361
|
+
const assistantId = initialAssistantId ?? retrievedAssistant.assistant_id;
|
|
1362
|
+
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1363
|
+
const streamInput = mode === "start" ? state : null;
|
|
1364
|
+
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
1365
|
+
let prevNodeName = null;
|
|
1366
|
+
let emitIntermediateStateUntilEnd = null;
|
|
1367
|
+
let shouldExit = null;
|
|
1368
|
+
let externalRunId = null;
|
|
1369
|
+
const streamResponse2 = client.runs.stream(threadId, assistantId, {
|
|
1370
|
+
input: streamInput,
|
|
1371
|
+
streamMode: [
|
|
1372
|
+
"events",
|
|
1373
|
+
"values"
|
|
1374
|
+
]
|
|
1375
|
+
});
|
|
1376
|
+
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1377
|
+
let latestStateValues = {};
|
|
1378
|
+
for await (const chunk of streamResponse2) {
|
|
1379
|
+
if (![
|
|
1380
|
+
"events",
|
|
1381
|
+
"values"
|
|
1382
|
+
].includes(chunk.event))
|
|
1383
|
+
continue;
|
|
1384
|
+
if (chunk.event === "values") {
|
|
1385
|
+
latestStateValues = chunk.data;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
const event = chunk.data;
|
|
1389
|
+
const currentNodeName = event.name;
|
|
1390
|
+
const eventType = event.event;
|
|
1391
|
+
const runId = event.metadata.run_id;
|
|
1392
|
+
externalRunId = runId;
|
|
1393
|
+
const metadata = event.metadata;
|
|
1394
|
+
shouldExit = shouldExit != null ? shouldExit : metadata["copilotkit:exit"];
|
|
1395
|
+
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1396
|
+
const forceEmitIntermediateState = metadata["copilotkit:force-emit-intermediate-state"];
|
|
1397
|
+
const manuallyEmitMessage = metadata["copilotkit:manually-emit-messages"];
|
|
1398
|
+
const manuallyEmitToolCall = metadata["copilotkit:manually-emit-tool-calls"];
|
|
1399
|
+
if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
|
|
1400
|
+
nodeName = currentNodeName;
|
|
1401
|
+
}
|
|
1402
|
+
if (!nodeName) {
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
if (forceEmitIntermediateState) {
|
|
1406
|
+
if (eventType === "on_chain_end") {
|
|
1407
|
+
state = event.data.output;
|
|
1408
|
+
emit(getStateSyncEvent({
|
|
1409
|
+
threadId,
|
|
1410
|
+
runId,
|
|
1411
|
+
agentName: agent.name,
|
|
1412
|
+
nodeName,
|
|
1413
|
+
state: event.data.output,
|
|
1414
|
+
running: true,
|
|
1415
|
+
active: true
|
|
1416
|
+
}));
|
|
1417
|
+
}
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1420
|
+
if (manuallyEmitMessage) {
|
|
1421
|
+
if (eventType === "on_chain_end") {
|
|
1422
|
+
state = event.data.output;
|
|
1423
|
+
emit(JSON.stringify({
|
|
1424
|
+
event: "on_copilotkit_emit_message",
|
|
1425
|
+
message: event.data.output,
|
|
1426
|
+
messageId: (0, import_node_crypto.randomUUID)(),
|
|
1427
|
+
role: MessageRole.assistant
|
|
1428
|
+
}) + "\n");
|
|
1429
|
+
}
|
|
1430
|
+
continue;
|
|
1323
1431
|
}
|
|
1432
|
+
if (manuallyEmitToolCall) {
|
|
1433
|
+
if (eventType === "on_chain_end") {
|
|
1434
|
+
state = event.data.output;
|
|
1435
|
+
emit(JSON.stringify({
|
|
1436
|
+
event: "on_copilotkit_emit_tool_call",
|
|
1437
|
+
name: event.data.output.name,
|
|
1438
|
+
args: event.data.output.args,
|
|
1439
|
+
id: event.data.output.id
|
|
1440
|
+
}) + "\n");
|
|
1441
|
+
}
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
if (emitIntermediateState && emitIntermediateStateUntilEnd == null) {
|
|
1445
|
+
emitIntermediateStateUntilEnd = nodeName;
|
|
1446
|
+
}
|
|
1447
|
+
if (emitIntermediateState && eventType === "on_chat_model_start") {
|
|
1448
|
+
streamingStateExtractor = new StreamingStateExtractor(emitIntermediateState);
|
|
1449
|
+
}
|
|
1450
|
+
let updatedState = latestStateValues;
|
|
1451
|
+
if (emitIntermediateState && eventType === "on_chat_model_stream") {
|
|
1452
|
+
streamingStateExtractor.bufferToolCalls(event);
|
|
1453
|
+
}
|
|
1454
|
+
if (emitIntermediateStateUntilEnd !== null) {
|
|
1455
|
+
updatedState = {
|
|
1456
|
+
...updatedState,
|
|
1457
|
+
...streamingStateExtractor.extractState()
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === "on_chain_end") {
|
|
1461
|
+
emitIntermediateStateUntilEnd = null;
|
|
1462
|
+
}
|
|
1463
|
+
const exitingNode = nodeName === currentNodeName && eventType === "on_chain_end";
|
|
1464
|
+
if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
|
|
1465
|
+
state = updatedState;
|
|
1466
|
+
prevNodeName = nodeName;
|
|
1467
|
+
emit(getStateSyncEvent({
|
|
1468
|
+
threadId,
|
|
1469
|
+
runId,
|
|
1470
|
+
agentName: agent.name,
|
|
1471
|
+
nodeName,
|
|
1472
|
+
state,
|
|
1473
|
+
running: true,
|
|
1474
|
+
active: !exitingNode
|
|
1475
|
+
}));
|
|
1476
|
+
}
|
|
1477
|
+
emit(JSON.stringify(event) + "\n");
|
|
1324
1478
|
}
|
|
1325
|
-
|
|
1479
|
+
state = await client.threads.getState(threadId);
|
|
1480
|
+
const isEndNode = state.next.length === 0;
|
|
1481
|
+
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1482
|
+
emit(getStateSyncEvent({
|
|
1483
|
+
threadId,
|
|
1484
|
+
runId: externalRunId,
|
|
1485
|
+
agentName: agent.name,
|
|
1486
|
+
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1487
|
+
state: state.values,
|
|
1488
|
+
running: !shouldExit,
|
|
1489
|
+
active: false
|
|
1490
|
+
}));
|
|
1491
|
+
return Promise.resolve();
|
|
1326
1492
|
}
|
|
1327
|
-
__name(
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1493
|
+
__name(streamEvents, "streamEvents");
|
|
1494
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1495
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1496
|
+
if (key !== "messages") {
|
|
1497
|
+
acc[key] = state[key];
|
|
1498
|
+
}
|
|
1499
|
+
return acc;
|
|
1500
|
+
}, {});
|
|
1501
|
+
return JSON.stringify({
|
|
1502
|
+
event: "on_copilotkit_state_sync",
|
|
1503
|
+
thread_id: threadId,
|
|
1504
|
+
run_id: runId,
|
|
1505
|
+
agent_name: agentName,
|
|
1506
|
+
node_name: nodeName,
|
|
1507
|
+
active,
|
|
1508
|
+
state: stateWithoutMessages,
|
|
1509
|
+
running,
|
|
1510
|
+
role: "assistant"
|
|
1511
|
+
}) + "\n";
|
|
1512
|
+
}
|
|
1513
|
+
__name(getStateSyncEvent, "getStateSyncEvent");
|
|
1514
|
+
var StreamingStateExtractor = /* @__PURE__ */ __name(class StreamingStateExtractor2 {
|
|
1515
|
+
emitIntermediateState;
|
|
1516
|
+
toolCallBuffer;
|
|
1517
|
+
currentToolCall;
|
|
1518
|
+
previouslyParsableState;
|
|
1519
|
+
constructor(emitIntermediateState) {
|
|
1520
|
+
this.emitIntermediateState = emitIntermediateState;
|
|
1521
|
+
this.toolCallBuffer = {};
|
|
1522
|
+
this.currentToolCall = null;
|
|
1523
|
+
this.previouslyParsableState = {};
|
|
1524
|
+
}
|
|
1525
|
+
bufferToolCalls(event) {
|
|
1526
|
+
if (event.data.chunk.tool_call_chunks.length > 0) {
|
|
1527
|
+
const chunk = event.data.chunk.tool_call_chunks[0];
|
|
1528
|
+
if (chunk.name !== null) {
|
|
1529
|
+
this.currentToolCall = chunk.name;
|
|
1530
|
+
this.toolCallBuffer[this.currentToolCall] = chunk.args;
|
|
1531
|
+
} else if (this.currentToolCall !== null) {
|
|
1532
|
+
this.toolCallBuffer[this.currentToolCall] += chunk.args;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
getEmitStateConfig(currentToolName) {
|
|
1537
|
+
for (const config2 of this.emitIntermediateState) {
|
|
1538
|
+
const stateKey = config2["state_key"];
|
|
1539
|
+
const tool = config2["tool"];
|
|
1540
|
+
const toolArgument = config2["tool_argument"];
|
|
1541
|
+
if (currentToolName === tool) {
|
|
1542
|
+
return [
|
|
1543
|
+
toolArgument,
|
|
1544
|
+
stateKey
|
|
1545
|
+
];
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
return [
|
|
1549
|
+
null,
|
|
1550
|
+
null
|
|
1551
|
+
];
|
|
1552
|
+
}
|
|
1553
|
+
extractState() {
|
|
1554
|
+
const state = {};
|
|
1555
|
+
for (const [key, value] of Object.entries(this.toolCallBuffer)) {
|
|
1556
|
+
const [argumentName, stateKey] = this.getEmitStateConfig(key);
|
|
1557
|
+
if (stateKey === null) {
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
let parsedValue;
|
|
1561
|
+
try {
|
|
1562
|
+
parsedValue = (0, import_partial_json.parse)(value);
|
|
1563
|
+
} catch (error) {
|
|
1564
|
+
if (key in this.previouslyParsableState) {
|
|
1565
|
+
parsedValue = this.previouslyParsableState[key];
|
|
1566
|
+
} else {
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
this.previouslyParsableState[key] = parsedValue;
|
|
1571
|
+
if (!argumentName) {
|
|
1572
|
+
state[stateKey] = parsedValue;
|
|
1573
|
+
} else {
|
|
1574
|
+
state[stateKey] = parsedValue[argumentName];
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return state;
|
|
1578
|
+
}
|
|
1579
|
+
}, "StreamingStateExtractor");
|
|
1580
|
+
function langGraphDefaultMergeState(state, messages, actions) {
|
|
1581
|
+
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1582
|
+
messages = messages.slice(1);
|
|
1583
|
+
}
|
|
1584
|
+
const mergedMessages = state.messages || [];
|
|
1585
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1586
|
+
for (const message of messages) {
|
|
1587
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1588
|
+
mergedMessages.push(message);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
return deepMerge(state, {
|
|
1592
|
+
messages: mergedMessages,
|
|
1593
|
+
copilotkit: {
|
|
1594
|
+
actions
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1599
|
+
function deepMerge(obj1, obj2) {
|
|
1600
|
+
let result = {
|
|
1601
|
+
...obj1
|
|
1602
|
+
};
|
|
1603
|
+
for (let key in obj2) {
|
|
1604
|
+
if (typeof obj2[key] === "object" && !Array.isArray(obj2[key])) {
|
|
1605
|
+
if (obj1[key]) {
|
|
1606
|
+
result[key] = deepMerge(obj1[key], obj2[key]);
|
|
1607
|
+
} else {
|
|
1608
|
+
result[key] = {
|
|
1609
|
+
...obj2[key]
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
} else {
|
|
1613
|
+
result[key] = obj2[key];
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
return result;
|
|
1617
|
+
}
|
|
1618
|
+
__name(deepMerge, "deepMerge");
|
|
1619
|
+
function formatMessages(messages) {
|
|
1620
|
+
return messages.map((message) => {
|
|
1621
|
+
if ("content" in message) {
|
|
1622
|
+
return message;
|
|
1623
|
+
}
|
|
1624
|
+
if ("arguments" in message) {
|
|
1625
|
+
const toolCall = {
|
|
1626
|
+
name: message["name"],
|
|
1627
|
+
args: message["arguments"],
|
|
1628
|
+
id: message["id"]
|
|
1629
|
+
};
|
|
1348
1630
|
return {
|
|
1349
|
-
|
|
1350
|
-
|
|
1631
|
+
...message,
|
|
1632
|
+
content: "",
|
|
1633
|
+
tool_calls: [
|
|
1634
|
+
toolCall
|
|
1635
|
+
],
|
|
1636
|
+
role: message["role"] ?? MessageRole.assistant
|
|
1351
1637
|
};
|
|
1352
1638
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
}
|
|
1362
|
-
return
|
|
1363
|
-
|
|
1364
|
-
agents: []
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1639
|
+
if ("actionExecutionId" in message) {
|
|
1640
|
+
return {
|
|
1641
|
+
...message,
|
|
1642
|
+
content: message["result"],
|
|
1643
|
+
name: message["actionName"],
|
|
1644
|
+
tool_call_id: message["actionExecutionId"],
|
|
1645
|
+
role: message["role"] ?? MessageRole.user
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
return message;
|
|
1649
|
+
});
|
|
1367
1650
|
}
|
|
1368
|
-
__name(
|
|
1651
|
+
__name(formatMessages, "formatMessages");
|
|
1652
|
+
|
|
1653
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1654
|
+
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1655
|
+
const agents = endpoint.agents.map((agent) => ({
|
|
1656
|
+
name: agent.name,
|
|
1657
|
+
description: agent.description,
|
|
1658
|
+
parameters: [],
|
|
1659
|
+
handler: async (_args) => {
|
|
1660
|
+
},
|
|
1661
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1662
|
+
var _a;
|
|
1663
|
+
logger2.debug({
|
|
1664
|
+
actionName: agent.name
|
|
1665
|
+
}, "Executing LangGraph Cloud agent");
|
|
1666
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1667
|
+
let state = {};
|
|
1668
|
+
if (agentStates) {
|
|
1669
|
+
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
1670
|
+
if (jsonState) {
|
|
1671
|
+
state = JSON.parse(jsonState);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
try {
|
|
1675
|
+
const response = await execute({
|
|
1676
|
+
agent,
|
|
1677
|
+
threadId,
|
|
1678
|
+
nodeName,
|
|
1679
|
+
messages,
|
|
1680
|
+
state,
|
|
1681
|
+
properties: graphqlContext.properties,
|
|
1682
|
+
actions: actionInputsWithoutAgents.map((action) => ({
|
|
1683
|
+
name: action.name,
|
|
1684
|
+
description: action.description,
|
|
1685
|
+
parameters: JSON.parse(action.jsonSchema)
|
|
1686
|
+
}))
|
|
1687
|
+
});
|
|
1688
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
1689
|
+
streamResponse(response, eventSource.eventStream$);
|
|
1690
|
+
return eventSource.processLangGraphEvents();
|
|
1691
|
+
} catch (error) {
|
|
1692
|
+
logger2.error({
|
|
1693
|
+
url: endpoint.deploymentUrl,
|
|
1694
|
+
status: 500,
|
|
1695
|
+
body: error.message
|
|
1696
|
+
}, "Failed to execute LangGraph Cloud agent");
|
|
1697
|
+
throw new Error("Failed to execute LangGraph Cloud agent");
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}));
|
|
1701
|
+
return [
|
|
1702
|
+
...agents
|
|
1703
|
+
];
|
|
1704
|
+
}
|
|
1705
|
+
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1369
1706
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1370
1707
|
const actions = json["actions"].map((action) => ({
|
|
1371
1708
|
name: action.name,
|
|
@@ -1457,7 +1794,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1457
1794
|
throw new Error("Failed to execute remote agent");
|
|
1458
1795
|
}
|
|
1459
1796
|
const eventSource = new RemoteLangGraphEventSource();
|
|
1460
|
-
|
|
1797
|
+
streamResponse(response.body, eventSource.eventStream$);
|
|
1461
1798
|
return eventSource.processLangGraphEvents();
|
|
1462
1799
|
}
|
|
1463
1800
|
}));
|
|
@@ -1467,34 +1804,165 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1467
1804
|
];
|
|
1468
1805
|
}
|
|
1469
1806
|
__name(constructRemoteActions, "constructRemoteActions");
|
|
1470
|
-
async function
|
|
1807
|
+
async function streamResponse(response, eventStream$) {
|
|
1808
|
+
const reader = response.getReader();
|
|
1809
|
+
const decoder = new TextDecoder();
|
|
1810
|
+
let buffer = [];
|
|
1811
|
+
function flushBuffer() {
|
|
1812
|
+
const currentBuffer = buffer.join("");
|
|
1813
|
+
if (currentBuffer.trim().length === 0) {
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
const parts = currentBuffer.split("\n");
|
|
1817
|
+
if (parts.length === 0) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
1821
|
+
buffer = [];
|
|
1822
|
+
if (!lastPartIsComplete) {
|
|
1823
|
+
buffer.push(parts.pop());
|
|
1824
|
+
}
|
|
1825
|
+
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
1826
|
+
eventStream$.next(JSON.parse(part));
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
__name(flushBuffer, "flushBuffer");
|
|
1830
|
+
try {
|
|
1831
|
+
while (true) {
|
|
1832
|
+
const { done, value } = await reader.read();
|
|
1833
|
+
if (!done) {
|
|
1834
|
+
buffer.push(decoder.decode(value, {
|
|
1835
|
+
stream: true
|
|
1836
|
+
}));
|
|
1837
|
+
}
|
|
1838
|
+
flushBuffer();
|
|
1839
|
+
if (done) {
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
} catch (error) {
|
|
1844
|
+
console.error("Error in stream", error);
|
|
1845
|
+
eventStream$.error(error);
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
eventStream$.complete();
|
|
1849
|
+
}
|
|
1850
|
+
__name(streamResponse, "streamResponse");
|
|
1851
|
+
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
1852
|
+
const headers = {
|
|
1853
|
+
"Content-Type": "application/json"
|
|
1854
|
+
};
|
|
1855
|
+
if (onBeforeRequest) {
|
|
1856
|
+
const { headers: additionalHeaders } = onBeforeRequest({
|
|
1857
|
+
ctx: graphqlContext
|
|
1858
|
+
});
|
|
1859
|
+
if (additionalHeaders) {
|
|
1860
|
+
Object.assign(headers, additionalHeaders);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return headers;
|
|
1864
|
+
}
|
|
1865
|
+
__name(createHeaders, "createHeaders");
|
|
1866
|
+
|
|
1867
|
+
// src/lib/runtime/remote-actions.ts
|
|
1868
|
+
var EndpointType;
|
|
1869
|
+
(function(EndpointType2) {
|
|
1870
|
+
EndpointType2["CopilotKit"] = "copilotKit";
|
|
1871
|
+
EndpointType2["LangGraphCloud"] = "langgraph-cloud";
|
|
1872
|
+
})(EndpointType || (EndpointType = {}));
|
|
1873
|
+
function isLangGraphAgentAction(action) {
|
|
1874
|
+
if (!action) {
|
|
1875
|
+
return false;
|
|
1876
|
+
}
|
|
1877
|
+
return typeof action.langGraphAgentHandler === "function";
|
|
1878
|
+
}
|
|
1879
|
+
__name(isLangGraphAgentAction, "isLangGraphAgentAction");
|
|
1880
|
+
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
|
|
1881
|
+
logger2.debug({
|
|
1882
|
+
url
|
|
1883
|
+
}, "Fetching actions from url");
|
|
1884
|
+
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1885
|
+
try {
|
|
1886
|
+
const response = await fetch(`${url}/info`, {
|
|
1887
|
+
method: "POST",
|
|
1888
|
+
headers,
|
|
1889
|
+
body: JSON.stringify({
|
|
1890
|
+
properties: graphqlContext.properties,
|
|
1891
|
+
frontendUrl
|
|
1892
|
+
})
|
|
1893
|
+
});
|
|
1894
|
+
if (!response.ok) {
|
|
1895
|
+
logger2.error({
|
|
1896
|
+
url,
|
|
1897
|
+
status: response.status,
|
|
1898
|
+
body: await response.text()
|
|
1899
|
+
}, "Failed to fetch actions from url");
|
|
1900
|
+
return {
|
|
1901
|
+
actions: [],
|
|
1902
|
+
agents: []
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
const json = await response.json();
|
|
1906
|
+
logger2.debug({
|
|
1907
|
+
json
|
|
1908
|
+
}, "Fetched actions from url");
|
|
1909
|
+
return json;
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
logger2.error({
|
|
1912
|
+
error: error.message ? error.message : error + ""
|
|
1913
|
+
}, "Failed to fetch actions from url");
|
|
1914
|
+
return {
|
|
1915
|
+
actions: [],
|
|
1916
|
+
agents: []
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
1921
|
+
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
|
|
1471
1922
|
const logger2 = graphqlContext.logger.child({
|
|
1472
1923
|
component: "remote-actions.fetchRemoteActions"
|
|
1473
1924
|
});
|
|
1474
1925
|
logger2.debug({
|
|
1475
|
-
|
|
1476
|
-
}, "Fetching remote
|
|
1477
|
-
const filtered =
|
|
1478
|
-
|
|
1926
|
+
remoteEndpointDefinitions
|
|
1927
|
+
}, "Fetching from remote endpoints");
|
|
1928
|
+
const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
|
|
1929
|
+
if (value.type === "langgraph-cloud") {
|
|
1930
|
+
return value;
|
|
1931
|
+
}
|
|
1932
|
+
return index === self.findIndex((t) => t.url === value.url);
|
|
1933
|
+
});
|
|
1934
|
+
const result = await Promise.all(filtered.map(async (endpoint) => {
|
|
1935
|
+
if (endpoint.type === "langgraph-cloud") {
|
|
1936
|
+
return constructLGCRemoteAction({
|
|
1937
|
+
endpoint,
|
|
1938
|
+
messages,
|
|
1939
|
+
graphqlContext,
|
|
1940
|
+
logger: logger2.child({
|
|
1941
|
+
component: "remote-actions.constructLGCRemoteAction",
|
|
1942
|
+
endpoint
|
|
1943
|
+
}),
|
|
1944
|
+
agentStates
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1479
1947
|
const json = await fetchRemoteInfo({
|
|
1480
|
-
url:
|
|
1481
|
-
onBeforeRequest:
|
|
1948
|
+
url: endpoint.url,
|
|
1949
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1482
1950
|
graphqlContext,
|
|
1483
1951
|
logger: logger2.child({
|
|
1484
1952
|
component: "remote-actions.fetchActionsFromUrl",
|
|
1485
|
-
|
|
1953
|
+
endpoint
|
|
1486
1954
|
}),
|
|
1487
1955
|
frontendUrl
|
|
1488
1956
|
});
|
|
1489
1957
|
return constructRemoteActions({
|
|
1490
1958
|
json,
|
|
1491
1959
|
messages,
|
|
1492
|
-
url:
|
|
1493
|
-
onBeforeRequest:
|
|
1960
|
+
url: endpoint.url,
|
|
1961
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1494
1962
|
graphqlContext,
|
|
1495
1963
|
logger: logger2.child({
|
|
1496
1964
|
component: "remote-actions.constructActions",
|
|
1497
|
-
|
|
1965
|
+
endpoint
|
|
1498
1966
|
}),
|
|
1499
1967
|
agentStates
|
|
1500
1968
|
});
|
|
@@ -1686,7 +2154,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1686
2154
|
__name(executeAction, "executeAction");
|
|
1687
2155
|
|
|
1688
2156
|
// src/graphql/types/base/index.ts
|
|
1689
|
-
var
|
|
2157
|
+
var import_type_graphql2 = require("type-graphql");
|
|
1690
2158
|
function _ts_decorate(decorators, target, key, desc) {
|
|
1691
2159
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1692
2160
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1709,15 +2177,15 @@ var BaseMessageInput = class {
|
|
|
1709
2177
|
};
|
|
1710
2178
|
__name(BaseMessageInput, "BaseMessageInput");
|
|
1711
2179
|
_ts_decorate([
|
|
1712
|
-
(0,
|
|
2180
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
1713
2181
|
_ts_metadata("design:type", String)
|
|
1714
2182
|
], BaseMessageInput.prototype, "id", void 0);
|
|
1715
2183
|
_ts_decorate([
|
|
1716
|
-
(0,
|
|
2184
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
1717
2185
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1718
2186
|
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
1719
2187
|
BaseMessageInput = _ts_decorate([
|
|
1720
|
-
(0,
|
|
2188
|
+
(0, import_type_graphql2.InputType)()
|
|
1721
2189
|
], BaseMessageInput);
|
|
1722
2190
|
|
|
1723
2191
|
// src/graphql/types/converted/index.ts
|
|
@@ -1821,7 +2289,7 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
1821
2289
|
var import_rxjs3 = require("rxjs");
|
|
1822
2290
|
var CopilotRuntime = class {
|
|
1823
2291
|
actions;
|
|
1824
|
-
|
|
2292
|
+
remoteEndpointDefinitions;
|
|
1825
2293
|
langserve = [];
|
|
1826
2294
|
onBeforeRequest;
|
|
1827
2295
|
onAfterRequest;
|
|
@@ -1832,7 +2300,7 @@ var CopilotRuntime = class {
|
|
|
1832
2300
|
const remoteChain = new RemoteChain(chain);
|
|
1833
2301
|
this.langserve.push(remoteChain.toAction());
|
|
1834
2302
|
}
|
|
1835
|
-
this.
|
|
2303
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
|
|
1836
2304
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
1837
2305
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
1838
2306
|
}
|
|
@@ -1901,7 +2369,7 @@ var CopilotRuntime = class {
|
|
|
1901
2369
|
async processAgentRequest(request) {
|
|
1902
2370
|
var _a;
|
|
1903
2371
|
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
1904
|
-
const { threadId
|
|
2372
|
+
const { threadId, agentName, nodeName } = agentSession;
|
|
1905
2373
|
const serverSideActions = await this.getServerSideActions(request);
|
|
1906
2374
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
1907
2375
|
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
@@ -1973,8 +2441,12 @@ var CopilotRuntime = class {
|
|
|
1973
2441
|
console.error("Error loading langserve chain:", error);
|
|
1974
2442
|
}
|
|
1975
2443
|
}
|
|
2444
|
+
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2445
|
+
...endpoint,
|
|
2446
|
+
type: this.resolveEndpointType(endpoint)
|
|
2447
|
+
}));
|
|
1976
2448
|
const remoteActions = await setupRemoteActions({
|
|
1977
|
-
|
|
2449
|
+
remoteEndpointDefinitions,
|
|
1978
2450
|
graphqlContext,
|
|
1979
2451
|
messages: inputMessages,
|
|
1980
2452
|
agentStates,
|
|
@@ -1990,6 +2462,12 @@ var CopilotRuntime = class {
|
|
|
1990
2462
|
...remoteActions
|
|
1991
2463
|
];
|
|
1992
2464
|
}
|
|
2465
|
+
resolveEndpointType(endpoint) {
|
|
2466
|
+
if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2467
|
+
return EndpointType.LangGraphCloud;
|
|
2468
|
+
}
|
|
2469
|
+
return endpoint.type;
|
|
2470
|
+
}
|
|
1993
2471
|
};
|
|
1994
2472
|
__name(CopilotRuntime, "CopilotRuntime");
|
|
1995
2473
|
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
@@ -2004,6 +2482,20 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
|
2004
2482
|
return allTools;
|
|
2005
2483
|
}
|
|
2006
2484
|
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
2485
|
+
function copilotKitEndpoint(config2) {
|
|
2486
|
+
return {
|
|
2487
|
+
...config2,
|
|
2488
|
+
type: EndpointType.CopilotKit
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
__name(copilotKitEndpoint, "copilotKitEndpoint");
|
|
2492
|
+
function langGraphCloudEndpoint(config2) {
|
|
2493
|
+
return {
|
|
2494
|
+
...config2,
|
|
2495
|
+
type: EndpointType.LangGraphCloud
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2498
|
+
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
2007
2499
|
|
|
2008
2500
|
// src/lib/integrations/shared.ts
|
|
2009
2501
|
var import_type_graphql16 = require("type-graphql");
|
|
@@ -2017,43 +2509,6 @@ var import_type_graphql11 = require("type-graphql");
|
|
|
2017
2509
|
|
|
2018
2510
|
// src/graphql/inputs/message.input.ts
|
|
2019
2511
|
var import_type_graphql3 = require("type-graphql");
|
|
2020
|
-
|
|
2021
|
-
// src/graphql/types/enums.ts
|
|
2022
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2023
|
-
var MessageRole;
|
|
2024
|
-
(function(MessageRole2) {
|
|
2025
|
-
MessageRole2["user"] = "user";
|
|
2026
|
-
MessageRole2["assistant"] = "assistant";
|
|
2027
|
-
MessageRole2["system"] = "system";
|
|
2028
|
-
})(MessageRole || (MessageRole = {}));
|
|
2029
|
-
var ActionExecutionScope;
|
|
2030
|
-
(function(ActionExecutionScope2) {
|
|
2031
|
-
ActionExecutionScope2["server"] = "server";
|
|
2032
|
-
ActionExecutionScope2["client"] = "client";
|
|
2033
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
2034
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
2035
|
-
var CopilotRequestType;
|
|
2036
|
-
(function(CopilotRequestType2) {
|
|
2037
|
-
CopilotRequestType2["Chat"] = "Chat";
|
|
2038
|
-
CopilotRequestType2["Task"] = "Task";
|
|
2039
|
-
CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
|
|
2040
|
-
CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
|
|
2041
|
-
CopilotRequestType2["Suggestion"] = "Suggestion";
|
|
2042
|
-
})(CopilotRequestType || (CopilotRequestType = {}));
|
|
2043
|
-
(0, import_type_graphql2.registerEnumType)(MessageRole, {
|
|
2044
|
-
name: "MessageRole",
|
|
2045
|
-
description: "The role of the message"
|
|
2046
|
-
});
|
|
2047
|
-
(0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
|
|
2048
|
-
name: "ActionExecutionScope",
|
|
2049
|
-
description: "The scope of the action"
|
|
2050
|
-
});
|
|
2051
|
-
(0, import_type_graphql2.registerEnumType)(CopilotRequestType, {
|
|
2052
|
-
name: "CopilotRequestType",
|
|
2053
|
-
description: "The type of Copilot request"
|
|
2054
|
-
});
|
|
2055
|
-
|
|
2056
|
-
// src/graphql/inputs/message.input.ts
|
|
2057
2512
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
2058
2513
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2059
2514
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3710,6 +4165,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
3710
4165
|
UnifyAdapter,
|
|
3711
4166
|
buildSchema,
|
|
3712
4167
|
config,
|
|
4168
|
+
copilotKitEndpoint,
|
|
3713
4169
|
copilotRuntimeNestEndpoint,
|
|
3714
4170
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
3715
4171
|
copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -3717,6 +4173,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
3717
4173
|
copilotRuntimeNodeHttpEndpoint,
|
|
3718
4174
|
createContext,
|
|
3719
4175
|
flattenToolCallsNoDuplicates,
|
|
3720
|
-
getCommonConfig
|
|
4176
|
+
getCommonConfig,
|
|
4177
|
+
langGraphCloudEndpoint
|
|
3721
4178
|
});
|
|
3722
4179
|
//# sourceMappingURL=index.js.map
|