@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/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",
|
|
@@ -135,6 +137,7 @@ __export(src_exports, {
|
|
|
135
137
|
UnknownErrorResponse: () => UnknownErrorResponse,
|
|
136
138
|
buildSchema: () => buildSchema,
|
|
137
139
|
config: () => config,
|
|
140
|
+
copilotKitEndpoint: () => copilotKitEndpoint,
|
|
138
141
|
copilotRuntimeNestEndpoint: () => copilotRuntimeNestEndpoint,
|
|
139
142
|
copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
|
|
140
143
|
copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -142,7 +145,8 @@ __export(src_exports, {
|
|
|
142
145
|
copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
|
|
143
146
|
createContext: () => createContext,
|
|
144
147
|
flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
|
|
145
|
-
getCommonConfig: () => getCommonConfig
|
|
148
|
+
getCommonConfig: () => getCommonConfig,
|
|
149
|
+
langGraphCloudEndpoint: () => langGraphCloudEndpoint
|
|
146
150
|
});
|
|
147
151
|
module.exports = __toCommonJS(src_exports);
|
|
148
152
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -1334,50 +1338,6 @@ var LangGraphEventTypes;
|
|
|
1334
1338
|
var import_shared8 = require("@copilotkit/shared");
|
|
1335
1339
|
var RemoteLangGraphEventSource = class {
|
|
1336
1340
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1337
|
-
async streamResponse(response) {
|
|
1338
|
-
const reader = response.body.getReader();
|
|
1339
|
-
const decoder = new TextDecoder();
|
|
1340
|
-
let buffer = [];
|
|
1341
|
-
const eventStream$ = this.eventStream$;
|
|
1342
|
-
function flushBuffer() {
|
|
1343
|
-
const currentBuffer = buffer.join("");
|
|
1344
|
-
if (currentBuffer.trim().length === 0) {
|
|
1345
|
-
return;
|
|
1346
|
-
}
|
|
1347
|
-
const parts = currentBuffer.split("\n");
|
|
1348
|
-
if (parts.length === 0) {
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
1352
|
-
buffer = [];
|
|
1353
|
-
if (!lastPartIsComplete) {
|
|
1354
|
-
buffer.push(parts.pop());
|
|
1355
|
-
}
|
|
1356
|
-
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
1357
|
-
eventStream$.next(JSON.parse(part));
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
__name(flushBuffer, "flushBuffer");
|
|
1361
|
-
try {
|
|
1362
|
-
while (true) {
|
|
1363
|
-
const { done, value } = await reader.read();
|
|
1364
|
-
if (!done) {
|
|
1365
|
-
buffer.push(decoder.decode(value, {
|
|
1366
|
-
stream: true
|
|
1367
|
-
}));
|
|
1368
|
-
}
|
|
1369
|
-
flushBuffer();
|
|
1370
|
-
if (done) {
|
|
1371
|
-
break;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
} catch (error) {
|
|
1375
|
-
console.error("Error in stream", error);
|
|
1376
|
-
eventStream$.error(error);
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1379
|
-
eventStream$.complete();
|
|
1380
|
-
}
|
|
1381
1341
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
1382
1342
|
if (typeof shouldEmitToolCalls === "boolean") {
|
|
1383
1343
|
return shouldEmitToolCalls;
|
|
@@ -1400,20 +1360,25 @@ var RemoteLangGraphEventSource = class {
|
|
|
1400
1360
|
} else {
|
|
1401
1361
|
acc.content = null;
|
|
1402
1362
|
}
|
|
1403
|
-
|
|
1363
|
+
const toolCallChunks = (
|
|
1364
|
+
// @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
|
|
1365
|
+
((_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)
|
|
1366
|
+
);
|
|
1367
|
+
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);
|
|
1368
|
+
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
1404
1369
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1405
|
-
acc.toolCallMessageId =
|
|
1406
|
-
if ((
|
|
1407
|
-
acc.toolCallName =
|
|
1370
|
+
acc.toolCallMessageId = toolCallMessageId;
|
|
1371
|
+
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1372
|
+
acc.toolCallName = toolCallChunks[0].name;
|
|
1408
1373
|
}
|
|
1409
|
-
if ((
|
|
1410
|
-
acc.toolCallId =
|
|
1374
|
+
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1375
|
+
acc.toolCallId = toolCallChunks[0].id;
|
|
1411
1376
|
}
|
|
1412
1377
|
acc.prevMessageId = acc.messageId;
|
|
1413
|
-
acc.messageId =
|
|
1378
|
+
acc.messageId = toolCallMessageId;
|
|
1414
1379
|
} else if (acc.content && acc.content != "") {
|
|
1415
1380
|
acc.prevMessageId = acc.messageId;
|
|
1416
|
-
acc.messageId =
|
|
1381
|
+
acc.messageId = toolCallMessageId;
|
|
1417
1382
|
} else {
|
|
1418
1383
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1419
1384
|
acc.prevMessageId = acc.messageId;
|
|
@@ -1438,7 +1403,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1438
1403
|
prevMessageId: null,
|
|
1439
1404
|
content: null
|
|
1440
1405
|
}), (0, import_rxjs.mergeMap)((eventWithState) => {
|
|
1441
|
-
var _a, _b, _c, _d, _e;
|
|
1406
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1442
1407
|
const events = [];
|
|
1443
1408
|
let shouldEmitMessages = true;
|
|
1444
1409
|
let shouldEmitToolCalls = false;
|
|
@@ -1521,7 +1486,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1521
1486
|
});
|
|
1522
1487
|
}
|
|
1523
1488
|
}
|
|
1524
|
-
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
|
|
1489
|
+
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
|
|
1490
|
+
((_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);
|
|
1525
1491
|
const content = eventWithState.content;
|
|
1526
1492
|
if (args) {
|
|
1527
1493
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
@@ -1572,70 +1538,441 @@ var RemoteLangGraphEventSource = class {
|
|
|
1572
1538
|
};
|
|
1573
1539
|
__name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
1574
1540
|
|
|
1575
|
-
// src/lib/runtime/remote-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1541
|
+
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1542
|
+
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1543
|
+
var import_node_crypto = require("crypto");
|
|
1544
|
+
var import_partial_json = require("partial-json");
|
|
1545
|
+
|
|
1546
|
+
// src/graphql/types/enums.ts
|
|
1547
|
+
var import_type_graphql = require("type-graphql");
|
|
1548
|
+
var MessageRole;
|
|
1549
|
+
(function(MessageRole2) {
|
|
1550
|
+
MessageRole2["user"] = "user";
|
|
1551
|
+
MessageRole2["assistant"] = "assistant";
|
|
1552
|
+
MessageRole2["system"] = "system";
|
|
1553
|
+
})(MessageRole || (MessageRole = {}));
|
|
1554
|
+
var ActionExecutionScope;
|
|
1555
|
+
(function(ActionExecutionScope2) {
|
|
1556
|
+
ActionExecutionScope2["server"] = "server";
|
|
1557
|
+
ActionExecutionScope2["client"] = "client";
|
|
1558
|
+
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
1559
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1560
|
+
var CopilotRequestType;
|
|
1561
|
+
(function(CopilotRequestType2) {
|
|
1562
|
+
CopilotRequestType2["Chat"] = "Chat";
|
|
1563
|
+
CopilotRequestType2["Task"] = "Task";
|
|
1564
|
+
CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
|
|
1565
|
+
CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
|
|
1566
|
+
CopilotRequestType2["Suggestion"] = "Suggestion";
|
|
1567
|
+
})(CopilotRequestType || (CopilotRequestType = {}));
|
|
1568
|
+
(0, import_type_graphql.registerEnumType)(MessageRole, {
|
|
1569
|
+
name: "MessageRole",
|
|
1570
|
+
description: "The role of the message"
|
|
1571
|
+
});
|
|
1572
|
+
(0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
|
|
1573
|
+
name: "ActionExecutionScope",
|
|
1574
|
+
description: "The scope of the action"
|
|
1575
|
+
});
|
|
1576
|
+
(0, import_type_graphql.registerEnumType)(CopilotRequestType, {
|
|
1577
|
+
name: "CopilotRequestType",
|
|
1578
|
+
description: "The type of Copilot request"
|
|
1579
|
+
});
|
|
1580
|
+
|
|
1581
|
+
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1582
|
+
async function execute(args) {
|
|
1583
|
+
return new ReadableStream({
|
|
1584
|
+
async start(controller) {
|
|
1585
|
+
try {
|
|
1586
|
+
await streamEvents(controller, args);
|
|
1587
|
+
controller.close();
|
|
1588
|
+
} catch (err) {
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1581
1592
|
}
|
|
1582
|
-
__name(
|
|
1583
|
-
function
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1593
|
+
__name(execute, "execute");
|
|
1594
|
+
async function streamEvents(controller, args) {
|
|
1595
|
+
const { threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions } = args;
|
|
1596
|
+
let nodeName = initialNodeName;
|
|
1597
|
+
let state = initialState;
|
|
1598
|
+
const { name, assistantId: initialAssistantId } = agent;
|
|
1599
|
+
const client = new import_langgraph_sdk.Client();
|
|
1600
|
+
let initialThreadId = agrsInitialThreadId;
|
|
1601
|
+
const wasInitiatedWithExistingThread = !!initialThreadId;
|
|
1602
|
+
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1603
|
+
initialThreadId = initialThreadId.substring(3);
|
|
1604
|
+
}
|
|
1605
|
+
const assistants = await client.assistants.search();
|
|
1606
|
+
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1607
|
+
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1608
|
+
if (initialThreadId === threadId) {
|
|
1609
|
+
await client.threads.get(threadId);
|
|
1610
|
+
} else {
|
|
1611
|
+
await client.threads.create({
|
|
1612
|
+
threadId
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
let agentState = {
|
|
1616
|
+
values: {}
|
|
1586
1617
|
};
|
|
1587
|
-
if (
|
|
1588
|
-
|
|
1589
|
-
|
|
1618
|
+
if (wasInitiatedWithExistingThread) {
|
|
1619
|
+
agentState = await client.threads.getState(threadId);
|
|
1620
|
+
}
|
|
1621
|
+
const agentStateValues = agentState.values;
|
|
1622
|
+
state.messages = agentStateValues.messages;
|
|
1623
|
+
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1624
|
+
state = langGraphDefaultMergeState(state, formatMessages(messages), actions);
|
|
1625
|
+
if (mode === "continue") {
|
|
1626
|
+
await client.threads.updateState(threadId, {
|
|
1627
|
+
values: state,
|
|
1628
|
+
asNode: nodeName
|
|
1590
1629
|
});
|
|
1591
|
-
|
|
1592
|
-
|
|
1630
|
+
}
|
|
1631
|
+
const assistantId = initialAssistantId ?? retrievedAssistant.assistant_id;
|
|
1632
|
+
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1633
|
+
const streamInput = mode === "start" ? state : null;
|
|
1634
|
+
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
1635
|
+
let prevNodeName = null;
|
|
1636
|
+
let emitIntermediateStateUntilEnd = null;
|
|
1637
|
+
let shouldExit = null;
|
|
1638
|
+
let externalRunId = null;
|
|
1639
|
+
const streamResponse2 = client.runs.stream(threadId, assistantId, {
|
|
1640
|
+
input: streamInput,
|
|
1641
|
+
streamMode: [
|
|
1642
|
+
"events",
|
|
1643
|
+
"values"
|
|
1644
|
+
]
|
|
1645
|
+
});
|
|
1646
|
+
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1647
|
+
let latestStateValues = {};
|
|
1648
|
+
for await (const chunk of streamResponse2) {
|
|
1649
|
+
if (![
|
|
1650
|
+
"events",
|
|
1651
|
+
"values"
|
|
1652
|
+
].includes(chunk.event))
|
|
1653
|
+
continue;
|
|
1654
|
+
if (chunk.event === "values") {
|
|
1655
|
+
latestStateValues = chunk.data;
|
|
1656
|
+
continue;
|
|
1657
|
+
}
|
|
1658
|
+
const event = chunk.data;
|
|
1659
|
+
const currentNodeName = event.name;
|
|
1660
|
+
const eventType = event.event;
|
|
1661
|
+
const runId = event.metadata.run_id;
|
|
1662
|
+
externalRunId = runId;
|
|
1663
|
+
const metadata = event.metadata;
|
|
1664
|
+
shouldExit = shouldExit != null ? shouldExit : metadata["copilotkit:exit"];
|
|
1665
|
+
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1666
|
+
const forceEmitIntermediateState = metadata["copilotkit:force-emit-intermediate-state"];
|
|
1667
|
+
const manuallyEmitMessage = metadata["copilotkit:manually-emit-messages"];
|
|
1668
|
+
const manuallyEmitToolCall = metadata["copilotkit:manually-emit-tool-calls"];
|
|
1669
|
+
if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
|
|
1670
|
+
nodeName = currentNodeName;
|
|
1593
1671
|
}
|
|
1672
|
+
if (!nodeName) {
|
|
1673
|
+
continue;
|
|
1674
|
+
}
|
|
1675
|
+
if (forceEmitIntermediateState) {
|
|
1676
|
+
if (eventType === "on_chain_end") {
|
|
1677
|
+
state = event.data.output;
|
|
1678
|
+
emit(getStateSyncEvent({
|
|
1679
|
+
threadId,
|
|
1680
|
+
runId,
|
|
1681
|
+
agentName: agent.name,
|
|
1682
|
+
nodeName,
|
|
1683
|
+
state: event.data.output,
|
|
1684
|
+
running: true,
|
|
1685
|
+
active: true
|
|
1686
|
+
}));
|
|
1687
|
+
}
|
|
1688
|
+
continue;
|
|
1689
|
+
}
|
|
1690
|
+
if (manuallyEmitMessage) {
|
|
1691
|
+
if (eventType === "on_chain_end") {
|
|
1692
|
+
state = event.data.output;
|
|
1693
|
+
emit(JSON.stringify({
|
|
1694
|
+
event: "on_copilotkit_emit_message",
|
|
1695
|
+
message: event.data.output,
|
|
1696
|
+
messageId: (0, import_node_crypto.randomUUID)(),
|
|
1697
|
+
role: MessageRole.assistant
|
|
1698
|
+
}) + "\n");
|
|
1699
|
+
}
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
if (manuallyEmitToolCall) {
|
|
1703
|
+
if (eventType === "on_chain_end") {
|
|
1704
|
+
state = event.data.output;
|
|
1705
|
+
emit(JSON.stringify({
|
|
1706
|
+
event: "on_copilotkit_emit_tool_call",
|
|
1707
|
+
name: event.data.output.name,
|
|
1708
|
+
args: event.data.output.args,
|
|
1709
|
+
id: event.data.output.id
|
|
1710
|
+
}) + "\n");
|
|
1711
|
+
}
|
|
1712
|
+
continue;
|
|
1713
|
+
}
|
|
1714
|
+
if (emitIntermediateState && emitIntermediateStateUntilEnd == null) {
|
|
1715
|
+
emitIntermediateStateUntilEnd = nodeName;
|
|
1716
|
+
}
|
|
1717
|
+
if (emitIntermediateState && eventType === "on_chat_model_start") {
|
|
1718
|
+
streamingStateExtractor = new StreamingStateExtractor(emitIntermediateState);
|
|
1719
|
+
}
|
|
1720
|
+
let updatedState = latestStateValues;
|
|
1721
|
+
if (emitIntermediateState && eventType === "on_chat_model_stream") {
|
|
1722
|
+
streamingStateExtractor.bufferToolCalls(event);
|
|
1723
|
+
}
|
|
1724
|
+
if (emitIntermediateStateUntilEnd !== null) {
|
|
1725
|
+
updatedState = {
|
|
1726
|
+
...updatedState,
|
|
1727
|
+
...streamingStateExtractor.extractState()
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === "on_chain_end") {
|
|
1731
|
+
emitIntermediateStateUntilEnd = null;
|
|
1732
|
+
}
|
|
1733
|
+
const exitingNode = nodeName === currentNodeName && eventType === "on_chain_end";
|
|
1734
|
+
if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
|
|
1735
|
+
state = updatedState;
|
|
1736
|
+
prevNodeName = nodeName;
|
|
1737
|
+
emit(getStateSyncEvent({
|
|
1738
|
+
threadId,
|
|
1739
|
+
runId,
|
|
1740
|
+
agentName: agent.name,
|
|
1741
|
+
nodeName,
|
|
1742
|
+
state,
|
|
1743
|
+
running: true,
|
|
1744
|
+
active: !exitingNode
|
|
1745
|
+
}));
|
|
1746
|
+
}
|
|
1747
|
+
emit(JSON.stringify(event) + "\n");
|
|
1594
1748
|
}
|
|
1595
|
-
|
|
1749
|
+
state = await client.threads.getState(threadId);
|
|
1750
|
+
const isEndNode = state.next.length === 0;
|
|
1751
|
+
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1752
|
+
emit(getStateSyncEvent({
|
|
1753
|
+
threadId,
|
|
1754
|
+
runId: externalRunId,
|
|
1755
|
+
agentName: agent.name,
|
|
1756
|
+
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1757
|
+
state: state.values,
|
|
1758
|
+
running: !shouldExit,
|
|
1759
|
+
active: false
|
|
1760
|
+
}));
|
|
1761
|
+
return Promise.resolve();
|
|
1596
1762
|
}
|
|
1597
|
-
__name(
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1763
|
+
__name(streamEvents, "streamEvents");
|
|
1764
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1765
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1766
|
+
if (key !== "messages") {
|
|
1767
|
+
acc[key] = state[key];
|
|
1768
|
+
}
|
|
1769
|
+
return acc;
|
|
1770
|
+
}, {});
|
|
1771
|
+
return JSON.stringify({
|
|
1772
|
+
event: "on_copilotkit_state_sync",
|
|
1773
|
+
thread_id: threadId,
|
|
1774
|
+
run_id: runId,
|
|
1775
|
+
agent_name: agentName,
|
|
1776
|
+
node_name: nodeName,
|
|
1777
|
+
active,
|
|
1778
|
+
state: stateWithoutMessages,
|
|
1779
|
+
running,
|
|
1780
|
+
role: "assistant"
|
|
1781
|
+
}) + "\n";
|
|
1782
|
+
}
|
|
1783
|
+
__name(getStateSyncEvent, "getStateSyncEvent");
|
|
1784
|
+
var StreamingStateExtractor = /* @__PURE__ */ __name(class StreamingStateExtractor2 {
|
|
1785
|
+
emitIntermediateState;
|
|
1786
|
+
toolCallBuffer;
|
|
1787
|
+
currentToolCall;
|
|
1788
|
+
previouslyParsableState;
|
|
1789
|
+
constructor(emitIntermediateState) {
|
|
1790
|
+
this.emitIntermediateState = emitIntermediateState;
|
|
1791
|
+
this.toolCallBuffer = {};
|
|
1792
|
+
this.currentToolCall = null;
|
|
1793
|
+
this.previouslyParsableState = {};
|
|
1794
|
+
}
|
|
1795
|
+
bufferToolCalls(event) {
|
|
1796
|
+
if (event.data.chunk.tool_call_chunks.length > 0) {
|
|
1797
|
+
const chunk = event.data.chunk.tool_call_chunks[0];
|
|
1798
|
+
if (chunk.name !== null) {
|
|
1799
|
+
this.currentToolCall = chunk.name;
|
|
1800
|
+
this.toolCallBuffer[this.currentToolCall] = chunk.args;
|
|
1801
|
+
} else if (this.currentToolCall !== null) {
|
|
1802
|
+
this.toolCallBuffer[this.currentToolCall] += chunk.args;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
getEmitStateConfig(currentToolName) {
|
|
1807
|
+
for (const config2 of this.emitIntermediateState) {
|
|
1808
|
+
const stateKey = config2["state_key"];
|
|
1809
|
+
const tool = config2["tool"];
|
|
1810
|
+
const toolArgument = config2["tool_argument"];
|
|
1811
|
+
if (currentToolName === tool) {
|
|
1812
|
+
return [
|
|
1813
|
+
toolArgument,
|
|
1814
|
+
stateKey
|
|
1815
|
+
];
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return [
|
|
1819
|
+
null,
|
|
1820
|
+
null
|
|
1821
|
+
];
|
|
1822
|
+
}
|
|
1823
|
+
extractState() {
|
|
1824
|
+
const state = {};
|
|
1825
|
+
for (const [key, value] of Object.entries(this.toolCallBuffer)) {
|
|
1826
|
+
const [argumentName, stateKey] = this.getEmitStateConfig(key);
|
|
1827
|
+
if (stateKey === null) {
|
|
1828
|
+
continue;
|
|
1829
|
+
}
|
|
1830
|
+
let parsedValue;
|
|
1831
|
+
try {
|
|
1832
|
+
parsedValue = (0, import_partial_json.parse)(value);
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
if (key in this.previouslyParsableState) {
|
|
1835
|
+
parsedValue = this.previouslyParsableState[key];
|
|
1836
|
+
} else {
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
this.previouslyParsableState[key] = parsedValue;
|
|
1841
|
+
if (!argumentName) {
|
|
1842
|
+
state[stateKey] = parsedValue;
|
|
1843
|
+
} else {
|
|
1844
|
+
state[stateKey] = parsedValue[argumentName];
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
return state;
|
|
1848
|
+
}
|
|
1849
|
+
}, "StreamingStateExtractor");
|
|
1850
|
+
function langGraphDefaultMergeState(state, messages, actions) {
|
|
1851
|
+
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1852
|
+
messages = messages.slice(1);
|
|
1853
|
+
}
|
|
1854
|
+
const mergedMessages = state.messages || [];
|
|
1855
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1856
|
+
for (const message of messages) {
|
|
1857
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1858
|
+
mergedMessages.push(message);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
return deepMerge(state, {
|
|
1862
|
+
messages: mergedMessages,
|
|
1863
|
+
copilotkit: {
|
|
1864
|
+
actions
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1869
|
+
function deepMerge(obj1, obj2) {
|
|
1870
|
+
let result = {
|
|
1871
|
+
...obj1
|
|
1872
|
+
};
|
|
1873
|
+
for (let key in obj2) {
|
|
1874
|
+
if (typeof obj2[key] === "object" && !Array.isArray(obj2[key])) {
|
|
1875
|
+
if (obj1[key]) {
|
|
1876
|
+
result[key] = deepMerge(obj1[key], obj2[key]);
|
|
1877
|
+
} else {
|
|
1878
|
+
result[key] = {
|
|
1879
|
+
...obj2[key]
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
} else {
|
|
1883
|
+
result[key] = obj2[key];
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
return result;
|
|
1887
|
+
}
|
|
1888
|
+
__name(deepMerge, "deepMerge");
|
|
1889
|
+
function formatMessages(messages) {
|
|
1890
|
+
return messages.map((message) => {
|
|
1891
|
+
if ("content" in message) {
|
|
1892
|
+
return message;
|
|
1893
|
+
}
|
|
1894
|
+
if ("arguments" in message) {
|
|
1895
|
+
const toolCall = {
|
|
1896
|
+
name: message["name"],
|
|
1897
|
+
args: message["arguments"],
|
|
1898
|
+
id: message["id"]
|
|
1899
|
+
};
|
|
1618
1900
|
return {
|
|
1619
|
-
|
|
1620
|
-
|
|
1901
|
+
...message,
|
|
1902
|
+
content: "",
|
|
1903
|
+
tool_calls: [
|
|
1904
|
+
toolCall
|
|
1905
|
+
],
|
|
1906
|
+
role: message["role"] ?? MessageRole.assistant
|
|
1621
1907
|
};
|
|
1622
1908
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1632
|
-
return
|
|
1633
|
-
|
|
1634
|
-
agents: []
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1909
|
+
if ("actionExecutionId" in message) {
|
|
1910
|
+
return {
|
|
1911
|
+
...message,
|
|
1912
|
+
content: message["result"],
|
|
1913
|
+
name: message["actionName"],
|
|
1914
|
+
tool_call_id: message["actionExecutionId"],
|
|
1915
|
+
role: message["role"] ?? MessageRole.user
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
return message;
|
|
1919
|
+
});
|
|
1637
1920
|
}
|
|
1638
|
-
__name(
|
|
1921
|
+
__name(formatMessages, "formatMessages");
|
|
1922
|
+
|
|
1923
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1924
|
+
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1925
|
+
const agents = endpoint.agents.map((agent) => ({
|
|
1926
|
+
name: agent.name,
|
|
1927
|
+
description: agent.description,
|
|
1928
|
+
parameters: [],
|
|
1929
|
+
handler: async (_args) => {
|
|
1930
|
+
},
|
|
1931
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1932
|
+
var _a;
|
|
1933
|
+
logger2.debug({
|
|
1934
|
+
actionName: agent.name
|
|
1935
|
+
}, "Executing LangGraph Cloud agent");
|
|
1936
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1937
|
+
let state = {};
|
|
1938
|
+
if (agentStates) {
|
|
1939
|
+
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
1940
|
+
if (jsonState) {
|
|
1941
|
+
state = JSON.parse(jsonState);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
try {
|
|
1945
|
+
const response = await execute({
|
|
1946
|
+
agent,
|
|
1947
|
+
threadId,
|
|
1948
|
+
nodeName,
|
|
1949
|
+
messages,
|
|
1950
|
+
state,
|
|
1951
|
+
properties: graphqlContext.properties,
|
|
1952
|
+
actions: actionInputsWithoutAgents.map((action) => ({
|
|
1953
|
+
name: action.name,
|
|
1954
|
+
description: action.description,
|
|
1955
|
+
parameters: JSON.parse(action.jsonSchema)
|
|
1956
|
+
}))
|
|
1957
|
+
});
|
|
1958
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
1959
|
+
streamResponse(response, eventSource.eventStream$);
|
|
1960
|
+
return eventSource.processLangGraphEvents();
|
|
1961
|
+
} catch (error) {
|
|
1962
|
+
logger2.error({
|
|
1963
|
+
url: endpoint.deploymentUrl,
|
|
1964
|
+
status: 500,
|
|
1965
|
+
body: error.message
|
|
1966
|
+
}, "Failed to execute LangGraph Cloud agent");
|
|
1967
|
+
throw new Error("Failed to execute LangGraph Cloud agent");
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}));
|
|
1971
|
+
return [
|
|
1972
|
+
...agents
|
|
1973
|
+
];
|
|
1974
|
+
}
|
|
1975
|
+
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1639
1976
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1640
1977
|
const actions = json["actions"].map((action) => ({
|
|
1641
1978
|
name: action.name,
|
|
@@ -1727,7 +2064,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1727
2064
|
throw new Error("Failed to execute remote agent");
|
|
1728
2065
|
}
|
|
1729
2066
|
const eventSource = new RemoteLangGraphEventSource();
|
|
1730
|
-
|
|
2067
|
+
streamResponse(response.body, eventSource.eventStream$);
|
|
1731
2068
|
return eventSource.processLangGraphEvents();
|
|
1732
2069
|
}
|
|
1733
2070
|
}));
|
|
@@ -1737,34 +2074,165 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1737
2074
|
];
|
|
1738
2075
|
}
|
|
1739
2076
|
__name(constructRemoteActions, "constructRemoteActions");
|
|
1740
|
-
async function
|
|
2077
|
+
async function streamResponse(response, eventStream$) {
|
|
2078
|
+
const reader = response.getReader();
|
|
2079
|
+
const decoder = new TextDecoder();
|
|
2080
|
+
let buffer = [];
|
|
2081
|
+
function flushBuffer() {
|
|
2082
|
+
const currentBuffer = buffer.join("");
|
|
2083
|
+
if (currentBuffer.trim().length === 0) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
const parts = currentBuffer.split("\n");
|
|
2087
|
+
if (parts.length === 0) {
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
2091
|
+
buffer = [];
|
|
2092
|
+
if (!lastPartIsComplete) {
|
|
2093
|
+
buffer.push(parts.pop());
|
|
2094
|
+
}
|
|
2095
|
+
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
2096
|
+
eventStream$.next(JSON.parse(part));
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
__name(flushBuffer, "flushBuffer");
|
|
2100
|
+
try {
|
|
2101
|
+
while (true) {
|
|
2102
|
+
const { done, value } = await reader.read();
|
|
2103
|
+
if (!done) {
|
|
2104
|
+
buffer.push(decoder.decode(value, {
|
|
2105
|
+
stream: true
|
|
2106
|
+
}));
|
|
2107
|
+
}
|
|
2108
|
+
flushBuffer();
|
|
2109
|
+
if (done) {
|
|
2110
|
+
break;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
} catch (error) {
|
|
2114
|
+
console.error("Error in stream", error);
|
|
2115
|
+
eventStream$.error(error);
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
eventStream$.complete();
|
|
2119
|
+
}
|
|
2120
|
+
__name(streamResponse, "streamResponse");
|
|
2121
|
+
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
2122
|
+
const headers = {
|
|
2123
|
+
"Content-Type": "application/json"
|
|
2124
|
+
};
|
|
2125
|
+
if (onBeforeRequest) {
|
|
2126
|
+
const { headers: additionalHeaders } = onBeforeRequest({
|
|
2127
|
+
ctx: graphqlContext
|
|
2128
|
+
});
|
|
2129
|
+
if (additionalHeaders) {
|
|
2130
|
+
Object.assign(headers, additionalHeaders);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
return headers;
|
|
2134
|
+
}
|
|
2135
|
+
__name(createHeaders, "createHeaders");
|
|
2136
|
+
|
|
2137
|
+
// src/lib/runtime/remote-actions.ts
|
|
2138
|
+
var EndpointType;
|
|
2139
|
+
(function(EndpointType2) {
|
|
2140
|
+
EndpointType2["CopilotKit"] = "copilotKit";
|
|
2141
|
+
EndpointType2["LangGraphCloud"] = "langgraph-cloud";
|
|
2142
|
+
})(EndpointType || (EndpointType = {}));
|
|
2143
|
+
function isLangGraphAgentAction(action) {
|
|
2144
|
+
if (!action) {
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
return typeof action.langGraphAgentHandler === "function";
|
|
2148
|
+
}
|
|
2149
|
+
__name(isLangGraphAgentAction, "isLangGraphAgentAction");
|
|
2150
|
+
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
|
|
2151
|
+
logger2.debug({
|
|
2152
|
+
url
|
|
2153
|
+
}, "Fetching actions from url");
|
|
2154
|
+
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
2155
|
+
try {
|
|
2156
|
+
const response = await fetch(`${url}/info`, {
|
|
2157
|
+
method: "POST",
|
|
2158
|
+
headers,
|
|
2159
|
+
body: JSON.stringify({
|
|
2160
|
+
properties: graphqlContext.properties,
|
|
2161
|
+
frontendUrl
|
|
2162
|
+
})
|
|
2163
|
+
});
|
|
2164
|
+
if (!response.ok) {
|
|
2165
|
+
logger2.error({
|
|
2166
|
+
url,
|
|
2167
|
+
status: response.status,
|
|
2168
|
+
body: await response.text()
|
|
2169
|
+
}, "Failed to fetch actions from url");
|
|
2170
|
+
return {
|
|
2171
|
+
actions: [],
|
|
2172
|
+
agents: []
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
const json = await response.json();
|
|
2176
|
+
logger2.debug({
|
|
2177
|
+
json
|
|
2178
|
+
}, "Fetched actions from url");
|
|
2179
|
+
return json;
|
|
2180
|
+
} catch (error) {
|
|
2181
|
+
logger2.error({
|
|
2182
|
+
error: error.message ? error.message : error + ""
|
|
2183
|
+
}, "Failed to fetch actions from url");
|
|
2184
|
+
return {
|
|
2185
|
+
actions: [],
|
|
2186
|
+
agents: []
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
2191
|
+
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
|
|
1741
2192
|
const logger2 = graphqlContext.logger.child({
|
|
1742
2193
|
component: "remote-actions.fetchRemoteActions"
|
|
1743
2194
|
});
|
|
1744
2195
|
logger2.debug({
|
|
1745
|
-
|
|
1746
|
-
}, "Fetching remote
|
|
1747
|
-
const filtered =
|
|
1748
|
-
|
|
2196
|
+
remoteEndpointDefinitions
|
|
2197
|
+
}, "Fetching from remote endpoints");
|
|
2198
|
+
const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
|
|
2199
|
+
if (value.type === "langgraph-cloud") {
|
|
2200
|
+
return value;
|
|
2201
|
+
}
|
|
2202
|
+
return index === self.findIndex((t) => t.url === value.url);
|
|
2203
|
+
});
|
|
2204
|
+
const result = await Promise.all(filtered.map(async (endpoint) => {
|
|
2205
|
+
if (endpoint.type === "langgraph-cloud") {
|
|
2206
|
+
return constructLGCRemoteAction({
|
|
2207
|
+
endpoint,
|
|
2208
|
+
messages,
|
|
2209
|
+
graphqlContext,
|
|
2210
|
+
logger: logger2.child({
|
|
2211
|
+
component: "remote-actions.constructLGCRemoteAction",
|
|
2212
|
+
endpoint
|
|
2213
|
+
}),
|
|
2214
|
+
agentStates
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
1749
2217
|
const json = await fetchRemoteInfo({
|
|
1750
|
-
url:
|
|
1751
|
-
onBeforeRequest:
|
|
2218
|
+
url: endpoint.url,
|
|
2219
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1752
2220
|
graphqlContext,
|
|
1753
2221
|
logger: logger2.child({
|
|
1754
2222
|
component: "remote-actions.fetchActionsFromUrl",
|
|
1755
|
-
|
|
2223
|
+
endpoint
|
|
1756
2224
|
}),
|
|
1757
2225
|
frontendUrl
|
|
1758
2226
|
});
|
|
1759
2227
|
return constructRemoteActions({
|
|
1760
2228
|
json,
|
|
1761
2229
|
messages,
|
|
1762
|
-
url:
|
|
1763
|
-
onBeforeRequest:
|
|
2230
|
+
url: endpoint.url,
|
|
2231
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1764
2232
|
graphqlContext,
|
|
1765
2233
|
logger: logger2.child({
|
|
1766
2234
|
component: "remote-actions.constructActions",
|
|
1767
|
-
|
|
2235
|
+
endpoint
|
|
1768
2236
|
}),
|
|
1769
2237
|
agentStates
|
|
1770
2238
|
});
|
|
@@ -1956,7 +2424,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1956
2424
|
__name(executeAction, "executeAction");
|
|
1957
2425
|
|
|
1958
2426
|
// src/graphql/types/base/index.ts
|
|
1959
|
-
var
|
|
2427
|
+
var import_type_graphql2 = require("type-graphql");
|
|
1960
2428
|
function _ts_decorate(decorators, target, key, desc) {
|
|
1961
2429
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1962
2430
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1979,15 +2447,15 @@ var BaseMessageInput = class {
|
|
|
1979
2447
|
};
|
|
1980
2448
|
__name(BaseMessageInput, "BaseMessageInput");
|
|
1981
2449
|
_ts_decorate([
|
|
1982
|
-
(0,
|
|
2450
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
1983
2451
|
_ts_metadata("design:type", String)
|
|
1984
2452
|
], BaseMessageInput.prototype, "id", void 0);
|
|
1985
2453
|
_ts_decorate([
|
|
1986
|
-
(0,
|
|
2454
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
1987
2455
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1988
2456
|
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
1989
2457
|
BaseMessageInput = _ts_decorate([
|
|
1990
|
-
(0,
|
|
2458
|
+
(0, import_type_graphql2.InputType)()
|
|
1991
2459
|
], BaseMessageInput);
|
|
1992
2460
|
|
|
1993
2461
|
// src/graphql/types/converted/index.ts
|
|
@@ -2091,7 +2559,7 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
2091
2559
|
var import_rxjs3 = require("rxjs");
|
|
2092
2560
|
var CopilotRuntime = class {
|
|
2093
2561
|
actions;
|
|
2094
|
-
|
|
2562
|
+
remoteEndpointDefinitions;
|
|
2095
2563
|
langserve = [];
|
|
2096
2564
|
onBeforeRequest;
|
|
2097
2565
|
onAfterRequest;
|
|
@@ -2102,7 +2570,7 @@ var CopilotRuntime = class {
|
|
|
2102
2570
|
const remoteChain = new RemoteChain(chain);
|
|
2103
2571
|
this.langserve.push(remoteChain.toAction());
|
|
2104
2572
|
}
|
|
2105
|
-
this.
|
|
2573
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
|
|
2106
2574
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
2107
2575
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2108
2576
|
}
|
|
@@ -2171,7 +2639,7 @@ var CopilotRuntime = class {
|
|
|
2171
2639
|
async processAgentRequest(request) {
|
|
2172
2640
|
var _a;
|
|
2173
2641
|
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
2174
|
-
const { threadId
|
|
2642
|
+
const { threadId, agentName, nodeName } = agentSession;
|
|
2175
2643
|
const serverSideActions = await this.getServerSideActions(request);
|
|
2176
2644
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
2177
2645
|
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
@@ -2243,8 +2711,12 @@ var CopilotRuntime = class {
|
|
|
2243
2711
|
console.error("Error loading langserve chain:", error);
|
|
2244
2712
|
}
|
|
2245
2713
|
}
|
|
2714
|
+
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2715
|
+
...endpoint,
|
|
2716
|
+
type: this.resolveEndpointType(endpoint)
|
|
2717
|
+
}));
|
|
2246
2718
|
const remoteActions = await setupRemoteActions({
|
|
2247
|
-
|
|
2719
|
+
remoteEndpointDefinitions,
|
|
2248
2720
|
graphqlContext,
|
|
2249
2721
|
messages: inputMessages,
|
|
2250
2722
|
agentStates,
|
|
@@ -2260,6 +2732,12 @@ var CopilotRuntime = class {
|
|
|
2260
2732
|
...remoteActions
|
|
2261
2733
|
];
|
|
2262
2734
|
}
|
|
2735
|
+
resolveEndpointType(endpoint) {
|
|
2736
|
+
if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2737
|
+
return EndpointType.LangGraphCloud;
|
|
2738
|
+
}
|
|
2739
|
+
return endpoint.type;
|
|
2740
|
+
}
|
|
2263
2741
|
};
|
|
2264
2742
|
__name(CopilotRuntime, "CopilotRuntime");
|
|
2265
2743
|
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
@@ -2274,6 +2752,20 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
|
2274
2752
|
return allTools;
|
|
2275
2753
|
}
|
|
2276
2754
|
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
2755
|
+
function copilotKitEndpoint(config2) {
|
|
2756
|
+
return {
|
|
2757
|
+
...config2,
|
|
2758
|
+
type: EndpointType.CopilotKit
|
|
2759
|
+
};
|
|
2760
|
+
}
|
|
2761
|
+
__name(copilotKitEndpoint, "copilotKitEndpoint");
|
|
2762
|
+
function langGraphCloudEndpoint(config2) {
|
|
2763
|
+
return {
|
|
2764
|
+
...config2,
|
|
2765
|
+
type: EndpointType.LangGraphCloud
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2768
|
+
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
2277
2769
|
|
|
2278
2770
|
// src/lib/integrations/shared.ts
|
|
2279
2771
|
var import_type_graphql16 = require("type-graphql");
|
|
@@ -2287,43 +2779,6 @@ var import_type_graphql11 = require("type-graphql");
|
|
|
2287
2779
|
|
|
2288
2780
|
// src/graphql/inputs/message.input.ts
|
|
2289
2781
|
var import_type_graphql3 = require("type-graphql");
|
|
2290
|
-
|
|
2291
|
-
// src/graphql/types/enums.ts
|
|
2292
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2293
|
-
var MessageRole;
|
|
2294
|
-
(function(MessageRole2) {
|
|
2295
|
-
MessageRole2["user"] = "user";
|
|
2296
|
-
MessageRole2["assistant"] = "assistant";
|
|
2297
|
-
MessageRole2["system"] = "system";
|
|
2298
|
-
})(MessageRole || (MessageRole = {}));
|
|
2299
|
-
var ActionExecutionScope;
|
|
2300
|
-
(function(ActionExecutionScope2) {
|
|
2301
|
-
ActionExecutionScope2["server"] = "server";
|
|
2302
|
-
ActionExecutionScope2["client"] = "client";
|
|
2303
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
2304
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
2305
|
-
var CopilotRequestType;
|
|
2306
|
-
(function(CopilotRequestType2) {
|
|
2307
|
-
CopilotRequestType2["Chat"] = "Chat";
|
|
2308
|
-
CopilotRequestType2["Task"] = "Task";
|
|
2309
|
-
CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
|
|
2310
|
-
CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
|
|
2311
|
-
CopilotRequestType2["Suggestion"] = "Suggestion";
|
|
2312
|
-
})(CopilotRequestType || (CopilotRequestType = {}));
|
|
2313
|
-
(0, import_type_graphql2.registerEnumType)(MessageRole, {
|
|
2314
|
-
name: "MessageRole",
|
|
2315
|
-
description: "The role of the message"
|
|
2316
|
-
});
|
|
2317
|
-
(0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
|
|
2318
|
-
name: "ActionExecutionScope",
|
|
2319
|
-
description: "The scope of the action"
|
|
2320
|
-
});
|
|
2321
|
-
(0, import_type_graphql2.registerEnumType)(CopilotRequestType, {
|
|
2322
|
-
name: "CopilotRequestType",
|
|
2323
|
-
description: "The type of Copilot request"
|
|
2324
|
-
});
|
|
2325
|
-
|
|
2326
|
-
// src/graphql/inputs/message.input.ts
|
|
2327
2782
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
2328
2783
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2329
2784
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3985,6 +4440,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
3985
4440
|
UnknownErrorResponse,
|
|
3986
4441
|
buildSchema,
|
|
3987
4442
|
config,
|
|
4443
|
+
copilotKitEndpoint,
|
|
3988
4444
|
copilotRuntimeNestEndpoint,
|
|
3989
4445
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
3990
4446
|
copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -3992,6 +4448,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
3992
4448
|
copilotRuntimeNodeHttpEndpoint,
|
|
3993
4449
|
createContext,
|
|
3994
4450
|
flattenToolCallsNoDuplicates,
|
|
3995
|
-
getCommonConfig
|
|
4451
|
+
getCommonConfig,
|
|
4452
|
+
langGraphCloudEndpoint
|
|
3996
4453
|
});
|
|
3997
4454
|
//# sourceMappingURL=index.js.map
|