@copilotkit/runtime 1.3.12-fix-tool-call-dynamic-parameters.0 → 1.3.12-lgc-alpha-1.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 +3 -4
- package/dist/{chunk-SIMJ6TZU.mjs → chunk-6B3NPPSR.mjs} +2 -2
- package/dist/{chunk-OSJXQNII.mjs → chunk-6HXQC7IT.mjs} +36 -9
- package/dist/chunk-6HXQC7IT.mjs.map +1 -0
- package/dist/{chunk-24WEOOFX.mjs → chunk-7MQDBRXJ.mjs} +2 -2
- package/dist/{chunk-AOYYOKTP.mjs → chunk-E6ZFCM3B.mjs} +561 -133
- package/dist/chunk-E6ZFCM3B.mjs.map +1 -0
- package/dist/{chunk-UYORVPCQ.mjs → chunk-TM7ZRU3M.mjs} +2 -2
- package/dist/{chunk-ZEHCLFJ2.mjs → chunk-V7SK6QZN.mjs} +6 -9
- package/dist/chunk-V7SK6QZN.mjs.map +1 -0
- package/dist/{chunk-HKLL7TTP.mjs → chunk-XMDH5MKI.mjs} +2 -2
- 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 +638 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -9
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +638 -186
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +13 -9
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +5 -4
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +5 -4
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +5 -4
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +5 -4
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.js +5 -8
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +2 -2
- package/package.json +7 -6
- 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 +283 -0
- package/src/lib/runtime/remote-actions.ts +65 -159
- package/src/lib/runtime/remote-lg-cloud-action.ts +441 -0
- package/src/service-adapters/events.ts +1 -5
- package/src/service-adapters/langchain/utils.ts +5 -10
- package/dist/chunk-AOYYOKTP.mjs.map +0 -1
- package/dist/chunk-OSJXQNII.mjs.map +0 -1
- package/dist/chunk-ZEHCLFJ2.mjs.map +0 -1
- package/src/service-adapters/langchain/utils.test.ts +0 -169
- /package/dist/{chunk-SIMJ6TZU.mjs.map → chunk-6B3NPPSR.mjs.map} +0 -0
- /package/dist/{chunk-24WEOOFX.mjs.map → chunk-7MQDBRXJ.mjs.map} +0 -0
- /package/dist/{chunk-UYORVPCQ.mjs.map → chunk-TM7ZRU3M.mjs.map} +0 -0
- /package/dist/{chunk-HKLL7TTP.mjs.map → chunk-XMDH5MKI.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.12-
|
|
47
|
+
version: "1.3.12-lgc-alpha-1.0",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -77,16 +77,16 @@ var require_package = __commonJS({
|
|
|
77
77
|
"ts-node": "^10.9.2",
|
|
78
78
|
tsconfig: "workspace:*",
|
|
79
79
|
tsup: "^6.7.0",
|
|
80
|
-
typescript: "^5.2.3"
|
|
81
|
-
"zod-to-json-schema": "^3.23.5"
|
|
80
|
+
typescript: "^5.2.3"
|
|
82
81
|
},
|
|
83
82
|
dependencies: {
|
|
84
83
|
"@anthropic-ai/sdk": "^0.27.3",
|
|
85
84
|
"@copilotkit/shared": "workspace:*",
|
|
85
|
+
"@langchain/google-gauth": "^0.1.0",
|
|
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/
|
|
89
|
+
"@langchain/langgraph-sdk": "^0.0.16",
|
|
90
90
|
"@langchain/openai": "^0.0.28",
|
|
91
91
|
"class-transformer": "^0.5.1",
|
|
92
92
|
express: "^4.19.2",
|
|
@@ -96,6 +96,7 @@ var require_package = __commonJS({
|
|
|
96
96
|
"groq-sdk": "^0.5.0",
|
|
97
97
|
langchain: "^0.3.3",
|
|
98
98
|
openai: "^4.50.0",
|
|
99
|
+
"partial-json": "^0.1.7",
|
|
99
100
|
pino: "^9.2.0",
|
|
100
101
|
"pino-pretty": "^11.2.1",
|
|
101
102
|
"reflect-metadata": "^0.2.2",
|
|
@@ -136,6 +137,7 @@ __export(src_exports, {
|
|
|
136
137
|
UnknownErrorResponse: () => UnknownErrorResponse,
|
|
137
138
|
buildSchema: () => buildSchema,
|
|
138
139
|
config: () => config,
|
|
140
|
+
copilotKitEndpoint: () => copilotKitEndpoint,
|
|
139
141
|
copilotRuntimeNestEndpoint: () => copilotRuntimeNestEndpoint,
|
|
140
142
|
copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
|
|
141
143
|
copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -143,7 +145,8 @@ __export(src_exports, {
|
|
|
143
145
|
copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
|
|
144
146
|
createContext: () => createContext,
|
|
145
147
|
flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
|
|
146
|
-
getCommonConfig: () => getCommonConfig
|
|
148
|
+
getCommonConfig: () => getCommonConfig,
|
|
149
|
+
langGraphCloudEndpoint: () => langGraphCloudEndpoint
|
|
147
150
|
});
|
|
148
151
|
module.exports = __toCommonJS(src_exports);
|
|
149
152
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -500,27 +503,24 @@ __name(convertMessageToLangChainMessage, "convertMessageToLangChainMessage");
|
|
|
500
503
|
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
501
504
|
if (jsonSchema.type === "object") {
|
|
502
505
|
const spec = {};
|
|
503
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
504
|
-
return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
|
|
505
|
-
}
|
|
506
506
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
507
507
|
spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
|
|
508
508
|
}
|
|
509
509
|
let schema = import_zod.z.object(spec);
|
|
510
|
-
return required ? schema : schema
|
|
510
|
+
return !required ? schema.optional() : schema;
|
|
511
511
|
} else if (jsonSchema.type === "string") {
|
|
512
512
|
let schema = import_zod.z.string().describe(jsonSchema.description);
|
|
513
|
-
return required ? schema : schema
|
|
513
|
+
return !required ? schema.optional() : schema;
|
|
514
514
|
} else if (jsonSchema.type === "number") {
|
|
515
515
|
let schema = import_zod.z.number().describe(jsonSchema.description);
|
|
516
|
-
return required ? schema : schema
|
|
516
|
+
return !required ? schema.optional() : schema;
|
|
517
517
|
} else if (jsonSchema.type === "boolean") {
|
|
518
518
|
let schema = import_zod.z.boolean().describe(jsonSchema.description);
|
|
519
|
-
return required ? schema : schema
|
|
519
|
+
return !required ? schema.optional() : schema;
|
|
520
520
|
} else if (jsonSchema.type === "array") {
|
|
521
521
|
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
522
522
|
let schema = import_zod.z.array(itemSchema);
|
|
523
|
-
return required ? schema : schema
|
|
523
|
+
return !required ? schema.optional() : schema;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
__name(convertJsonSchemaToZodSchema, "convertJsonSchemaToZodSchema");
|
|
@@ -1338,50 +1338,6 @@ var LangGraphEventTypes;
|
|
|
1338
1338
|
var import_shared8 = require("@copilotkit/shared");
|
|
1339
1339
|
var RemoteLangGraphEventSource = class {
|
|
1340
1340
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1341
|
-
async streamResponse(response) {
|
|
1342
|
-
const reader = response.body.getReader();
|
|
1343
|
-
const decoder = new TextDecoder();
|
|
1344
|
-
let buffer = [];
|
|
1345
|
-
const eventStream$ = this.eventStream$;
|
|
1346
|
-
function flushBuffer() {
|
|
1347
|
-
const currentBuffer = buffer.join("");
|
|
1348
|
-
if (currentBuffer.trim().length === 0) {
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
const parts = currentBuffer.split("\n");
|
|
1352
|
-
if (parts.length === 0) {
|
|
1353
|
-
return;
|
|
1354
|
-
}
|
|
1355
|
-
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
1356
|
-
buffer = [];
|
|
1357
|
-
if (!lastPartIsComplete) {
|
|
1358
|
-
buffer.push(parts.pop());
|
|
1359
|
-
}
|
|
1360
|
-
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
1361
|
-
eventStream$.next(JSON.parse(part));
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
__name(flushBuffer, "flushBuffer");
|
|
1365
|
-
try {
|
|
1366
|
-
while (true) {
|
|
1367
|
-
const { done, value } = await reader.read();
|
|
1368
|
-
if (!done) {
|
|
1369
|
-
buffer.push(decoder.decode(value, {
|
|
1370
|
-
stream: true
|
|
1371
|
-
}));
|
|
1372
|
-
}
|
|
1373
|
-
flushBuffer();
|
|
1374
|
-
if (done) {
|
|
1375
|
-
break;
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
} catch (error) {
|
|
1379
|
-
console.error("Error in stream", error);
|
|
1380
|
-
eventStream$.error(error);
|
|
1381
|
-
return;
|
|
1382
|
-
}
|
|
1383
|
-
eventStream$.complete();
|
|
1384
|
-
}
|
|
1385
1341
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
1386
1342
|
if (typeof shouldEmitToolCalls === "boolean") {
|
|
1387
1343
|
return shouldEmitToolCalls;
|
|
@@ -1404,20 +1360,25 @@ var RemoteLangGraphEventSource = class {
|
|
|
1404
1360
|
} else {
|
|
1405
1361
|
acc.content = null;
|
|
1406
1362
|
}
|
|
1407
|
-
|
|
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) {
|
|
1408
1369
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1409
|
-
acc.toolCallMessageId =
|
|
1410
|
-
if ((
|
|
1411
|
-
acc.toolCallName =
|
|
1370
|
+
acc.toolCallMessageId = toolCallMessageId;
|
|
1371
|
+
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1372
|
+
acc.toolCallName = toolCallChunks[0].name;
|
|
1412
1373
|
}
|
|
1413
|
-
if ((
|
|
1414
|
-
acc.toolCallId =
|
|
1374
|
+
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1375
|
+
acc.toolCallId = toolCallChunks[0].id;
|
|
1415
1376
|
}
|
|
1416
1377
|
acc.prevMessageId = acc.messageId;
|
|
1417
|
-
acc.messageId =
|
|
1378
|
+
acc.messageId = toolCallMessageId;
|
|
1418
1379
|
} else if (acc.content && acc.content != "") {
|
|
1419
1380
|
acc.prevMessageId = acc.messageId;
|
|
1420
|
-
acc.messageId =
|
|
1381
|
+
acc.messageId = toolCallMessageId;
|
|
1421
1382
|
} else {
|
|
1422
1383
|
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1423
1384
|
acc.prevMessageId = acc.messageId;
|
|
@@ -1442,7 +1403,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1442
1403
|
prevMessageId: null,
|
|
1443
1404
|
content: null
|
|
1444
1405
|
}), (0, import_rxjs.mergeMap)((eventWithState) => {
|
|
1445
|
-
var _a, _b, _c, _d, _e;
|
|
1406
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1446
1407
|
const events = [];
|
|
1447
1408
|
let shouldEmitMessages = true;
|
|
1448
1409
|
let shouldEmitToolCalls = false;
|
|
@@ -1525,7 +1486,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1525
1486
|
});
|
|
1526
1487
|
}
|
|
1527
1488
|
}
|
|
1528
|
-
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);
|
|
1529
1491
|
const content = eventWithState.content;
|
|
1530
1492
|
if (args) {
|
|
1531
1493
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
@@ -1576,70 +1538,446 @@ var RemoteLangGraphEventSource = class {
|
|
|
1576
1538
|
};
|
|
1577
1539
|
__name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
1578
1540
|
|
|
1579
|
-
// src/lib/runtime/remote-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
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
|
+
});
|
|
1585
1592
|
}
|
|
1586
|
-
__name(
|
|
1587
|
-
function
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1593
|
+
__name(execute, "execute");
|
|
1594
|
+
async function streamEvents(controller, args) {
|
|
1595
|
+
const { deploymentUrl, langsmithApiKey, 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
|
+
apiUrl: deploymentUrl,
|
|
1601
|
+
apiKey: langsmithApiKey
|
|
1602
|
+
});
|
|
1603
|
+
let initialThreadId = agrsInitialThreadId;
|
|
1604
|
+
const wasInitiatedWithExistingThread = !!initialThreadId;
|
|
1605
|
+
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1606
|
+
initialThreadId = initialThreadId.substring(3);
|
|
1607
|
+
}
|
|
1608
|
+
const assistants = await client.assistants.search();
|
|
1609
|
+
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1610
|
+
const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
|
|
1611
|
+
if (initialThreadId === threadId) {
|
|
1612
|
+
await client.threads.get(threadId);
|
|
1613
|
+
} else {
|
|
1614
|
+
await client.threads.create({
|
|
1615
|
+
threadId
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
let agentState = {
|
|
1619
|
+
values: {}
|
|
1590
1620
|
};
|
|
1591
|
-
if (
|
|
1592
|
-
|
|
1593
|
-
|
|
1621
|
+
if (wasInitiatedWithExistingThread) {
|
|
1622
|
+
agentState = await client.threads.getState(threadId);
|
|
1623
|
+
}
|
|
1624
|
+
const agentStateValues = agentState.values;
|
|
1625
|
+
state.messages = agentStateValues.messages;
|
|
1626
|
+
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1627
|
+
state = langGraphDefaultMergeState(state, formatMessages(messages), actions);
|
|
1628
|
+
if (mode === "continue") {
|
|
1629
|
+
await client.threads.updateState(threadId, {
|
|
1630
|
+
values: state,
|
|
1631
|
+
asNode: nodeName
|
|
1594
1632
|
});
|
|
1595
|
-
|
|
1596
|
-
|
|
1633
|
+
}
|
|
1634
|
+
const assistantId = initialAssistantId ?? retrievedAssistant.assistant_id;
|
|
1635
|
+
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1636
|
+
const streamInput = mode === "start" ? state : null;
|
|
1637
|
+
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
1638
|
+
let prevNodeName = null;
|
|
1639
|
+
let emitIntermediateStateUntilEnd = null;
|
|
1640
|
+
let shouldExit = null;
|
|
1641
|
+
let externalRunId = null;
|
|
1642
|
+
const streamResponse2 = client.runs.stream(threadId, assistantId, {
|
|
1643
|
+
input: streamInput,
|
|
1644
|
+
streamMode: [
|
|
1645
|
+
"events",
|
|
1646
|
+
"values"
|
|
1647
|
+
]
|
|
1648
|
+
});
|
|
1649
|
+
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1650
|
+
let latestStateValues = {};
|
|
1651
|
+
for await (const chunk of streamResponse2) {
|
|
1652
|
+
if (![
|
|
1653
|
+
"events",
|
|
1654
|
+
"values"
|
|
1655
|
+
].includes(chunk.event))
|
|
1656
|
+
continue;
|
|
1657
|
+
if (chunk.event === "values") {
|
|
1658
|
+
latestStateValues = chunk.data;
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
const event = chunk.data;
|
|
1662
|
+
const currentNodeName = event.name;
|
|
1663
|
+
const eventType = event.event;
|
|
1664
|
+
const runId = event.metadata.run_id;
|
|
1665
|
+
externalRunId = runId;
|
|
1666
|
+
const metadata = event.metadata;
|
|
1667
|
+
shouldExit = shouldExit != null ? shouldExit : metadata["copilotkit:exit"];
|
|
1668
|
+
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1669
|
+
const forceEmitIntermediateState = metadata["copilotkit:force-emit-intermediate-state"];
|
|
1670
|
+
const manuallyEmitMessage = metadata["copilotkit:manually-emit-messages"];
|
|
1671
|
+
const manuallyEmitToolCall = metadata["copilotkit:manually-emit-tool-calls"];
|
|
1672
|
+
if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
|
|
1673
|
+
nodeName = currentNodeName;
|
|
1674
|
+
}
|
|
1675
|
+
if (!nodeName) {
|
|
1676
|
+
continue;
|
|
1677
|
+
}
|
|
1678
|
+
if (forceEmitIntermediateState) {
|
|
1679
|
+
if (eventType === "on_chain_end") {
|
|
1680
|
+
state = event.data.output;
|
|
1681
|
+
emit(getStateSyncEvent({
|
|
1682
|
+
threadId,
|
|
1683
|
+
runId,
|
|
1684
|
+
agentName: agent.name,
|
|
1685
|
+
nodeName,
|
|
1686
|
+
state: event.data.output,
|
|
1687
|
+
running: true,
|
|
1688
|
+
active: true
|
|
1689
|
+
}));
|
|
1690
|
+
}
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
if (manuallyEmitMessage) {
|
|
1694
|
+
if (eventType === "on_chain_end") {
|
|
1695
|
+
state = event.data.output;
|
|
1696
|
+
emit(JSON.stringify({
|
|
1697
|
+
event: "on_copilotkit_emit_message",
|
|
1698
|
+
message: event.data.output,
|
|
1699
|
+
messageId: (0, import_node_crypto.randomUUID)(),
|
|
1700
|
+
role: MessageRole.assistant
|
|
1701
|
+
}) + "\n");
|
|
1702
|
+
}
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
if (manuallyEmitToolCall) {
|
|
1706
|
+
if (eventType === "on_chain_end") {
|
|
1707
|
+
state = event.data.output;
|
|
1708
|
+
emit(JSON.stringify({
|
|
1709
|
+
event: "on_copilotkit_emit_tool_call",
|
|
1710
|
+
name: event.data.output.name,
|
|
1711
|
+
args: event.data.output.args,
|
|
1712
|
+
id: event.data.output.id
|
|
1713
|
+
}) + "\n");
|
|
1714
|
+
}
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
if (emitIntermediateState && emitIntermediateStateUntilEnd == null) {
|
|
1718
|
+
emitIntermediateStateUntilEnd = nodeName;
|
|
1597
1719
|
}
|
|
1720
|
+
if (emitIntermediateState && eventType === "on_chat_model_start") {
|
|
1721
|
+
streamingStateExtractor = new StreamingStateExtractor(emitIntermediateState);
|
|
1722
|
+
}
|
|
1723
|
+
let updatedState = latestStateValues;
|
|
1724
|
+
if (emitIntermediateState && eventType === "on_chat_model_stream") {
|
|
1725
|
+
streamingStateExtractor.bufferToolCalls(event);
|
|
1726
|
+
}
|
|
1727
|
+
if (emitIntermediateStateUntilEnd !== null) {
|
|
1728
|
+
updatedState = {
|
|
1729
|
+
...updatedState,
|
|
1730
|
+
...streamingStateExtractor.extractState()
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === "on_chain_end") {
|
|
1734
|
+
emitIntermediateStateUntilEnd = null;
|
|
1735
|
+
}
|
|
1736
|
+
const exitingNode = nodeName === currentNodeName && eventType === "on_chain_end";
|
|
1737
|
+
if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
|
|
1738
|
+
state = updatedState;
|
|
1739
|
+
prevNodeName = nodeName;
|
|
1740
|
+
emit(getStateSyncEvent({
|
|
1741
|
+
threadId,
|
|
1742
|
+
runId,
|
|
1743
|
+
agentName: agent.name,
|
|
1744
|
+
nodeName,
|
|
1745
|
+
state,
|
|
1746
|
+
running: true,
|
|
1747
|
+
active: !exitingNode
|
|
1748
|
+
}));
|
|
1749
|
+
}
|
|
1750
|
+
emit(JSON.stringify(event) + "\n");
|
|
1598
1751
|
}
|
|
1599
|
-
|
|
1752
|
+
state = await client.threads.getState(threadId);
|
|
1753
|
+
const isEndNode = state.next.length === 0;
|
|
1754
|
+
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1755
|
+
emit(getStateSyncEvent({
|
|
1756
|
+
threadId,
|
|
1757
|
+
runId: externalRunId,
|
|
1758
|
+
agentName: agent.name,
|
|
1759
|
+
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1760
|
+
state: state.values,
|
|
1761
|
+
running: !shouldExit,
|
|
1762
|
+
active: false
|
|
1763
|
+
}));
|
|
1764
|
+
return Promise.resolve();
|
|
1600
1765
|
}
|
|
1601
|
-
__name(
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1766
|
+
__name(streamEvents, "streamEvents");
|
|
1767
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1768
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1769
|
+
if (key !== "messages") {
|
|
1770
|
+
acc[key] = state[key];
|
|
1771
|
+
}
|
|
1772
|
+
return acc;
|
|
1773
|
+
}, {});
|
|
1774
|
+
return JSON.stringify({
|
|
1775
|
+
event: "on_copilotkit_state_sync",
|
|
1776
|
+
thread_id: threadId,
|
|
1777
|
+
run_id: runId,
|
|
1778
|
+
agent_name: agentName,
|
|
1779
|
+
node_name: nodeName,
|
|
1780
|
+
active,
|
|
1781
|
+
state: stateWithoutMessages,
|
|
1782
|
+
running,
|
|
1783
|
+
role: "assistant"
|
|
1784
|
+
}) + "\n";
|
|
1785
|
+
}
|
|
1786
|
+
__name(getStateSyncEvent, "getStateSyncEvent");
|
|
1787
|
+
var StreamingStateExtractor = /* @__PURE__ */ __name(class StreamingStateExtractor2 {
|
|
1788
|
+
emitIntermediateState;
|
|
1789
|
+
toolCallBuffer;
|
|
1790
|
+
currentToolCall;
|
|
1791
|
+
previouslyParsableState;
|
|
1792
|
+
constructor(emitIntermediateState) {
|
|
1793
|
+
this.emitIntermediateState = emitIntermediateState;
|
|
1794
|
+
this.toolCallBuffer = {};
|
|
1795
|
+
this.currentToolCall = null;
|
|
1796
|
+
this.previouslyParsableState = {};
|
|
1797
|
+
}
|
|
1798
|
+
bufferToolCalls(event) {
|
|
1799
|
+
if (event.data.chunk.tool_call_chunks.length > 0) {
|
|
1800
|
+
const chunk = event.data.chunk.tool_call_chunks[0];
|
|
1801
|
+
if (chunk.name !== null) {
|
|
1802
|
+
this.currentToolCall = chunk.name;
|
|
1803
|
+
this.toolCallBuffer[this.currentToolCall] = chunk.args;
|
|
1804
|
+
} else if (this.currentToolCall !== null) {
|
|
1805
|
+
this.toolCallBuffer[this.currentToolCall] += chunk.args;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
getEmitStateConfig(currentToolName) {
|
|
1810
|
+
for (const config2 of this.emitIntermediateState) {
|
|
1811
|
+
const stateKey = config2["state_key"];
|
|
1812
|
+
const tool = config2["tool"];
|
|
1813
|
+
const toolArgument = config2["tool_argument"];
|
|
1814
|
+
if (currentToolName === tool) {
|
|
1815
|
+
return [
|
|
1816
|
+
toolArgument,
|
|
1817
|
+
stateKey
|
|
1818
|
+
];
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
return [
|
|
1822
|
+
null,
|
|
1823
|
+
null
|
|
1824
|
+
];
|
|
1825
|
+
}
|
|
1826
|
+
extractState() {
|
|
1827
|
+
const state = {};
|
|
1828
|
+
for (const [key, value] of Object.entries(this.toolCallBuffer)) {
|
|
1829
|
+
const [argumentName, stateKey] = this.getEmitStateConfig(key);
|
|
1830
|
+
if (stateKey === null) {
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1833
|
+
let parsedValue;
|
|
1834
|
+
try {
|
|
1835
|
+
parsedValue = (0, import_partial_json.parse)(value);
|
|
1836
|
+
} catch (error) {
|
|
1837
|
+
if (key in this.previouslyParsableState) {
|
|
1838
|
+
parsedValue = this.previouslyParsableState[key];
|
|
1839
|
+
} else {
|
|
1840
|
+
continue;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
this.previouslyParsableState[key] = parsedValue;
|
|
1844
|
+
if (!argumentName) {
|
|
1845
|
+
state[stateKey] = parsedValue;
|
|
1846
|
+
} else {
|
|
1847
|
+
state[stateKey] = parsedValue[argumentName];
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return state;
|
|
1851
|
+
}
|
|
1852
|
+
}, "StreamingStateExtractor");
|
|
1853
|
+
function langGraphDefaultMergeState(state, messages, actions) {
|
|
1854
|
+
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1855
|
+
messages = messages.slice(1);
|
|
1856
|
+
}
|
|
1857
|
+
const mergedMessages = state.messages || [];
|
|
1858
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1859
|
+
for (const message of messages) {
|
|
1860
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1861
|
+
mergedMessages.push(message);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
return deepMerge(state, {
|
|
1865
|
+
messages: mergedMessages,
|
|
1866
|
+
copilotkit: {
|
|
1867
|
+
actions
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1872
|
+
function deepMerge(obj1, obj2) {
|
|
1873
|
+
let result = {
|
|
1874
|
+
...obj1
|
|
1875
|
+
};
|
|
1876
|
+
for (let key in obj2) {
|
|
1877
|
+
if (typeof obj2[key] === "object" && !Array.isArray(obj2[key])) {
|
|
1878
|
+
if (obj1[key]) {
|
|
1879
|
+
result[key] = deepMerge(obj1[key], obj2[key]);
|
|
1880
|
+
} else {
|
|
1881
|
+
result[key] = {
|
|
1882
|
+
...obj2[key]
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
} else {
|
|
1886
|
+
result[key] = obj2[key];
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
return result;
|
|
1890
|
+
}
|
|
1891
|
+
__name(deepMerge, "deepMerge");
|
|
1892
|
+
function formatMessages(messages) {
|
|
1893
|
+
return messages.map((message) => {
|
|
1894
|
+
if ("content" in message) {
|
|
1895
|
+
return message;
|
|
1896
|
+
}
|
|
1897
|
+
if ("arguments" in message) {
|
|
1898
|
+
const toolCall = {
|
|
1899
|
+
name: message["name"],
|
|
1900
|
+
args: message["arguments"],
|
|
1901
|
+
id: message["id"]
|
|
1902
|
+
};
|
|
1622
1903
|
return {
|
|
1623
|
-
|
|
1624
|
-
|
|
1904
|
+
...message,
|
|
1905
|
+
content: "",
|
|
1906
|
+
tool_calls: [
|
|
1907
|
+
toolCall
|
|
1908
|
+
],
|
|
1909
|
+
role: message["role"] ?? MessageRole.assistant
|
|
1625
1910
|
};
|
|
1626
1911
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
return
|
|
1637
|
-
|
|
1638
|
-
agents: []
|
|
1639
|
-
};
|
|
1640
|
-
}
|
|
1912
|
+
if ("actionExecutionId" in message) {
|
|
1913
|
+
return {
|
|
1914
|
+
...message,
|
|
1915
|
+
content: message["result"],
|
|
1916
|
+
name: message["actionName"],
|
|
1917
|
+
tool_call_id: message["actionExecutionId"],
|
|
1918
|
+
role: message["role"] ?? MessageRole.user
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
return message;
|
|
1922
|
+
});
|
|
1641
1923
|
}
|
|
1642
|
-
__name(
|
|
1924
|
+
__name(formatMessages, "formatMessages");
|
|
1925
|
+
|
|
1926
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1927
|
+
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1928
|
+
const agents = endpoint.agents.map((agent) => ({
|
|
1929
|
+
name: agent.name,
|
|
1930
|
+
description: agent.description,
|
|
1931
|
+
parameters: [],
|
|
1932
|
+
handler: async (_args) => {
|
|
1933
|
+
},
|
|
1934
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1935
|
+
var _a;
|
|
1936
|
+
logger2.debug({
|
|
1937
|
+
actionName: agent.name
|
|
1938
|
+
}, "Executing LangGraph Cloud agent");
|
|
1939
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1940
|
+
let state = {};
|
|
1941
|
+
if (agentStates) {
|
|
1942
|
+
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
1943
|
+
if (jsonState) {
|
|
1944
|
+
state = JSON.parse(jsonState);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
try {
|
|
1948
|
+
const response = await execute({
|
|
1949
|
+
deploymentUrl: endpoint.deploymentUrl,
|
|
1950
|
+
langsmithApiKey: endpoint.langsmithApiKey,
|
|
1951
|
+
agent,
|
|
1952
|
+
threadId,
|
|
1953
|
+
nodeName,
|
|
1954
|
+
messages,
|
|
1955
|
+
state,
|
|
1956
|
+
properties: graphqlContext.properties,
|
|
1957
|
+
actions: actionInputsWithoutAgents.map((action) => ({
|
|
1958
|
+
name: action.name,
|
|
1959
|
+
description: action.description,
|
|
1960
|
+
parameters: JSON.parse(action.jsonSchema)
|
|
1961
|
+
}))
|
|
1962
|
+
});
|
|
1963
|
+
const eventSource = new RemoteLangGraphEventSource();
|
|
1964
|
+
streamResponse(response, eventSource.eventStream$);
|
|
1965
|
+
return eventSource.processLangGraphEvents();
|
|
1966
|
+
} catch (error) {
|
|
1967
|
+
logger2.error({
|
|
1968
|
+
url: endpoint.deploymentUrl,
|
|
1969
|
+
status: 500,
|
|
1970
|
+
body: error.message
|
|
1971
|
+
}, "Failed to execute LangGraph Cloud agent");
|
|
1972
|
+
throw new Error("Failed to execute LangGraph Cloud agent");
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
}));
|
|
1976
|
+
return [
|
|
1977
|
+
...agents
|
|
1978
|
+
];
|
|
1979
|
+
}
|
|
1980
|
+
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1643
1981
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1644
1982
|
const actions = json["actions"].map((action) => ({
|
|
1645
1983
|
name: action.name,
|
|
@@ -1731,7 +2069,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1731
2069
|
throw new Error("Failed to execute remote agent");
|
|
1732
2070
|
}
|
|
1733
2071
|
const eventSource = new RemoteLangGraphEventSource();
|
|
1734
|
-
|
|
2072
|
+
streamResponse(response.body, eventSource.eventStream$);
|
|
1735
2073
|
return eventSource.processLangGraphEvents();
|
|
1736
2074
|
}
|
|
1737
2075
|
}));
|
|
@@ -1741,34 +2079,165 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1741
2079
|
];
|
|
1742
2080
|
}
|
|
1743
2081
|
__name(constructRemoteActions, "constructRemoteActions");
|
|
1744
|
-
async function
|
|
2082
|
+
async function streamResponse(response, eventStream$) {
|
|
2083
|
+
const reader = response.getReader();
|
|
2084
|
+
const decoder = new TextDecoder();
|
|
2085
|
+
let buffer = [];
|
|
2086
|
+
function flushBuffer() {
|
|
2087
|
+
const currentBuffer = buffer.join("");
|
|
2088
|
+
if (currentBuffer.trim().length === 0) {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
const parts = currentBuffer.split("\n");
|
|
2092
|
+
if (parts.length === 0) {
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
const lastPartIsComplete = currentBuffer.endsWith("\n");
|
|
2096
|
+
buffer = [];
|
|
2097
|
+
if (!lastPartIsComplete) {
|
|
2098
|
+
buffer.push(parts.pop());
|
|
2099
|
+
}
|
|
2100
|
+
parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
|
|
2101
|
+
eventStream$.next(JSON.parse(part));
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
__name(flushBuffer, "flushBuffer");
|
|
2105
|
+
try {
|
|
2106
|
+
while (true) {
|
|
2107
|
+
const { done, value } = await reader.read();
|
|
2108
|
+
if (!done) {
|
|
2109
|
+
buffer.push(decoder.decode(value, {
|
|
2110
|
+
stream: true
|
|
2111
|
+
}));
|
|
2112
|
+
}
|
|
2113
|
+
flushBuffer();
|
|
2114
|
+
if (done) {
|
|
2115
|
+
break;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
} catch (error) {
|
|
2119
|
+
console.error("Error in stream", error);
|
|
2120
|
+
eventStream$.error(error);
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
eventStream$.complete();
|
|
2124
|
+
}
|
|
2125
|
+
__name(streamResponse, "streamResponse");
|
|
2126
|
+
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
2127
|
+
const headers = {
|
|
2128
|
+
"Content-Type": "application/json"
|
|
2129
|
+
};
|
|
2130
|
+
if (onBeforeRequest) {
|
|
2131
|
+
const { headers: additionalHeaders } = onBeforeRequest({
|
|
2132
|
+
ctx: graphqlContext
|
|
2133
|
+
});
|
|
2134
|
+
if (additionalHeaders) {
|
|
2135
|
+
Object.assign(headers, additionalHeaders);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
return headers;
|
|
2139
|
+
}
|
|
2140
|
+
__name(createHeaders, "createHeaders");
|
|
2141
|
+
|
|
2142
|
+
// src/lib/runtime/remote-actions.ts
|
|
2143
|
+
var EndpointType;
|
|
2144
|
+
(function(EndpointType2) {
|
|
2145
|
+
EndpointType2["CopilotKit"] = "copilotKit";
|
|
2146
|
+
EndpointType2["LangGraphCloud"] = "langgraph-cloud";
|
|
2147
|
+
})(EndpointType || (EndpointType = {}));
|
|
2148
|
+
function isLangGraphAgentAction(action) {
|
|
2149
|
+
if (!action) {
|
|
2150
|
+
return false;
|
|
2151
|
+
}
|
|
2152
|
+
return typeof action.langGraphAgentHandler === "function";
|
|
2153
|
+
}
|
|
2154
|
+
__name(isLangGraphAgentAction, "isLangGraphAgentAction");
|
|
2155
|
+
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
|
|
2156
|
+
logger2.debug({
|
|
2157
|
+
url
|
|
2158
|
+
}, "Fetching actions from url");
|
|
2159
|
+
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
2160
|
+
try {
|
|
2161
|
+
const response = await fetch(`${url}/info`, {
|
|
2162
|
+
method: "POST",
|
|
2163
|
+
headers,
|
|
2164
|
+
body: JSON.stringify({
|
|
2165
|
+
properties: graphqlContext.properties,
|
|
2166
|
+
frontendUrl
|
|
2167
|
+
})
|
|
2168
|
+
});
|
|
2169
|
+
if (!response.ok) {
|
|
2170
|
+
logger2.error({
|
|
2171
|
+
url,
|
|
2172
|
+
status: response.status,
|
|
2173
|
+
body: await response.text()
|
|
2174
|
+
}, "Failed to fetch actions from url");
|
|
2175
|
+
return {
|
|
2176
|
+
actions: [],
|
|
2177
|
+
agents: []
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2180
|
+
const json = await response.json();
|
|
2181
|
+
logger2.debug({
|
|
2182
|
+
json
|
|
2183
|
+
}, "Fetched actions from url");
|
|
2184
|
+
return json;
|
|
2185
|
+
} catch (error) {
|
|
2186
|
+
logger2.error({
|
|
2187
|
+
error: error.message ? error.message : error + ""
|
|
2188
|
+
}, "Failed to fetch actions from url");
|
|
2189
|
+
return {
|
|
2190
|
+
actions: [],
|
|
2191
|
+
agents: []
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
2196
|
+
async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
|
|
1745
2197
|
const logger2 = graphqlContext.logger.child({
|
|
1746
2198
|
component: "remote-actions.fetchRemoteActions"
|
|
1747
2199
|
});
|
|
1748
2200
|
logger2.debug({
|
|
1749
|
-
|
|
1750
|
-
}, "Fetching remote
|
|
1751
|
-
const filtered =
|
|
1752
|
-
|
|
2201
|
+
remoteEndpointDefinitions
|
|
2202
|
+
}, "Fetching from remote endpoints");
|
|
2203
|
+
const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
|
|
2204
|
+
if (value.type === "langgraph-cloud") {
|
|
2205
|
+
return value;
|
|
2206
|
+
}
|
|
2207
|
+
return index === self.findIndex((t) => t.url === value.url);
|
|
2208
|
+
});
|
|
2209
|
+
const result = await Promise.all(filtered.map(async (endpoint) => {
|
|
2210
|
+
if (endpoint.type === "langgraph-cloud") {
|
|
2211
|
+
return constructLGCRemoteAction({
|
|
2212
|
+
endpoint,
|
|
2213
|
+
messages,
|
|
2214
|
+
graphqlContext,
|
|
2215
|
+
logger: logger2.child({
|
|
2216
|
+
component: "remote-actions.constructLGCRemoteAction",
|
|
2217
|
+
endpoint
|
|
2218
|
+
}),
|
|
2219
|
+
agentStates
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
1753
2222
|
const json = await fetchRemoteInfo({
|
|
1754
|
-
url:
|
|
1755
|
-
onBeforeRequest:
|
|
2223
|
+
url: endpoint.url,
|
|
2224
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1756
2225
|
graphqlContext,
|
|
1757
2226
|
logger: logger2.child({
|
|
1758
2227
|
component: "remote-actions.fetchActionsFromUrl",
|
|
1759
|
-
|
|
2228
|
+
endpoint
|
|
1760
2229
|
}),
|
|
1761
2230
|
frontendUrl
|
|
1762
2231
|
});
|
|
1763
2232
|
return constructRemoteActions({
|
|
1764
2233
|
json,
|
|
1765
2234
|
messages,
|
|
1766
|
-
url:
|
|
1767
|
-
onBeforeRequest:
|
|
2235
|
+
url: endpoint.url,
|
|
2236
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
1768
2237
|
graphqlContext,
|
|
1769
2238
|
logger: logger2.child({
|
|
1770
2239
|
component: "remote-actions.constructActions",
|
|
1771
|
-
|
|
2240
|
+
endpoint
|
|
1772
2241
|
}),
|
|
1773
2242
|
agentStates
|
|
1774
2243
|
});
|
|
@@ -1932,13 +2401,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1932
2401
|
}
|
|
1933
2402
|
let args = [];
|
|
1934
2403
|
if (actionArguments) {
|
|
1935
|
-
|
|
1936
|
-
args = JSON.parse(actionArguments);
|
|
1937
|
-
} catch (e) {
|
|
1938
|
-
console.warn("Action argument unparsable", {
|
|
1939
|
-
actionArguments
|
|
1940
|
-
});
|
|
1941
|
-
}
|
|
2404
|
+
args = JSON.parse(actionArguments);
|
|
1942
2405
|
}
|
|
1943
2406
|
if (isLangGraphAgentAction(action)) {
|
|
1944
2407
|
eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
|
|
@@ -1966,7 +2429,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1966
2429
|
__name(executeAction, "executeAction");
|
|
1967
2430
|
|
|
1968
2431
|
// src/graphql/types/base/index.ts
|
|
1969
|
-
var
|
|
2432
|
+
var import_type_graphql2 = require("type-graphql");
|
|
1970
2433
|
function _ts_decorate(decorators, target, key, desc) {
|
|
1971
2434
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1972
2435
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1989,15 +2452,15 @@ var BaseMessageInput = class {
|
|
|
1989
2452
|
};
|
|
1990
2453
|
__name(BaseMessageInput, "BaseMessageInput");
|
|
1991
2454
|
_ts_decorate([
|
|
1992
|
-
(0,
|
|
2455
|
+
(0, import_type_graphql2.Field)(() => String),
|
|
1993
2456
|
_ts_metadata("design:type", String)
|
|
1994
2457
|
], BaseMessageInput.prototype, "id", void 0);
|
|
1995
2458
|
_ts_decorate([
|
|
1996
|
-
(0,
|
|
2459
|
+
(0, import_type_graphql2.Field)(() => Date),
|
|
1997
2460
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1998
2461
|
], BaseMessageInput.prototype, "createdAt", void 0);
|
|
1999
2462
|
BaseMessageInput = _ts_decorate([
|
|
2000
|
-
(0,
|
|
2463
|
+
(0, import_type_graphql2.InputType)()
|
|
2001
2464
|
], BaseMessageInput);
|
|
2002
2465
|
|
|
2003
2466
|
// src/graphql/types/converted/index.ts
|
|
@@ -2101,7 +2564,7 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
|
2101
2564
|
var import_rxjs3 = require("rxjs");
|
|
2102
2565
|
var CopilotRuntime = class {
|
|
2103
2566
|
actions;
|
|
2104
|
-
|
|
2567
|
+
remoteEndpointDefinitions;
|
|
2105
2568
|
langserve = [];
|
|
2106
2569
|
onBeforeRequest;
|
|
2107
2570
|
onAfterRequest;
|
|
@@ -2112,7 +2575,7 @@ var CopilotRuntime = class {
|
|
|
2112
2575
|
const remoteChain = new RemoteChain(chain);
|
|
2113
2576
|
this.langserve.push(remoteChain.toAction());
|
|
2114
2577
|
}
|
|
2115
|
-
this.
|
|
2578
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
|
|
2116
2579
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
2117
2580
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2118
2581
|
}
|
|
@@ -2181,7 +2644,7 @@ var CopilotRuntime = class {
|
|
|
2181
2644
|
async processAgentRequest(request) {
|
|
2182
2645
|
var _a;
|
|
2183
2646
|
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
2184
|
-
const { threadId
|
|
2647
|
+
const { threadId, agentName, nodeName } = agentSession;
|
|
2185
2648
|
const serverSideActions = await this.getServerSideActions(request);
|
|
2186
2649
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
2187
2650
|
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
@@ -2253,8 +2716,12 @@ var CopilotRuntime = class {
|
|
|
2253
2716
|
console.error("Error loading langserve chain:", error);
|
|
2254
2717
|
}
|
|
2255
2718
|
}
|
|
2719
|
+
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2720
|
+
...endpoint,
|
|
2721
|
+
type: this.resolveEndpointType(endpoint)
|
|
2722
|
+
}));
|
|
2256
2723
|
const remoteActions = await setupRemoteActions({
|
|
2257
|
-
|
|
2724
|
+
remoteEndpointDefinitions,
|
|
2258
2725
|
graphqlContext,
|
|
2259
2726
|
messages: inputMessages,
|
|
2260
2727
|
agentStates,
|
|
@@ -2270,6 +2737,12 @@ var CopilotRuntime = class {
|
|
|
2270
2737
|
...remoteActions
|
|
2271
2738
|
];
|
|
2272
2739
|
}
|
|
2740
|
+
resolveEndpointType(endpoint) {
|
|
2741
|
+
if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2742
|
+
return EndpointType.LangGraphCloud;
|
|
2743
|
+
}
|
|
2744
|
+
return endpoint.type;
|
|
2745
|
+
}
|
|
2273
2746
|
};
|
|
2274
2747
|
__name(CopilotRuntime, "CopilotRuntime");
|
|
2275
2748
|
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
@@ -2284,6 +2757,20 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
|
2284
2757
|
return allTools;
|
|
2285
2758
|
}
|
|
2286
2759
|
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
2760
|
+
function copilotKitEndpoint(config2) {
|
|
2761
|
+
return {
|
|
2762
|
+
...config2,
|
|
2763
|
+
type: EndpointType.CopilotKit
|
|
2764
|
+
};
|
|
2765
|
+
}
|
|
2766
|
+
__name(copilotKitEndpoint, "copilotKitEndpoint");
|
|
2767
|
+
function langGraphCloudEndpoint(config2) {
|
|
2768
|
+
return {
|
|
2769
|
+
...config2,
|
|
2770
|
+
type: EndpointType.LangGraphCloud
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
2287
2774
|
|
|
2288
2775
|
// src/lib/integrations/shared.ts
|
|
2289
2776
|
var import_type_graphql16 = require("type-graphql");
|
|
@@ -2297,43 +2784,6 @@ var import_type_graphql11 = require("type-graphql");
|
|
|
2297
2784
|
|
|
2298
2785
|
// src/graphql/inputs/message.input.ts
|
|
2299
2786
|
var import_type_graphql3 = require("type-graphql");
|
|
2300
|
-
|
|
2301
|
-
// src/graphql/types/enums.ts
|
|
2302
|
-
var import_type_graphql2 = require("type-graphql");
|
|
2303
|
-
var MessageRole;
|
|
2304
|
-
(function(MessageRole2) {
|
|
2305
|
-
MessageRole2["user"] = "user";
|
|
2306
|
-
MessageRole2["assistant"] = "assistant";
|
|
2307
|
-
MessageRole2["system"] = "system";
|
|
2308
|
-
})(MessageRole || (MessageRole = {}));
|
|
2309
|
-
var ActionExecutionScope;
|
|
2310
|
-
(function(ActionExecutionScope2) {
|
|
2311
|
-
ActionExecutionScope2["server"] = "server";
|
|
2312
|
-
ActionExecutionScope2["client"] = "client";
|
|
2313
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
2314
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
2315
|
-
var CopilotRequestType;
|
|
2316
|
-
(function(CopilotRequestType2) {
|
|
2317
|
-
CopilotRequestType2["Chat"] = "Chat";
|
|
2318
|
-
CopilotRequestType2["Task"] = "Task";
|
|
2319
|
-
CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
|
|
2320
|
-
CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
|
|
2321
|
-
CopilotRequestType2["Suggestion"] = "Suggestion";
|
|
2322
|
-
})(CopilotRequestType || (CopilotRequestType = {}));
|
|
2323
|
-
(0, import_type_graphql2.registerEnumType)(MessageRole, {
|
|
2324
|
-
name: "MessageRole",
|
|
2325
|
-
description: "The role of the message"
|
|
2326
|
-
});
|
|
2327
|
-
(0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
|
|
2328
|
-
name: "ActionExecutionScope",
|
|
2329
|
-
description: "The scope of the action"
|
|
2330
|
-
});
|
|
2331
|
-
(0, import_type_graphql2.registerEnumType)(CopilotRequestType, {
|
|
2332
|
-
name: "CopilotRequestType",
|
|
2333
|
-
description: "The type of Copilot request"
|
|
2334
|
-
});
|
|
2335
|
-
|
|
2336
|
-
// src/graphql/inputs/message.input.ts
|
|
2337
2787
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
2338
2788
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2339
2789
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3995,6 +4445,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
3995
4445
|
UnknownErrorResponse,
|
|
3996
4446
|
buildSchema,
|
|
3997
4447
|
config,
|
|
4448
|
+
copilotKitEndpoint,
|
|
3998
4449
|
copilotRuntimeNestEndpoint,
|
|
3999
4450
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
4000
4451
|
copilotRuntimeNextJSPagesRouterEndpoint,
|
|
@@ -4002,6 +4453,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
|
|
|
4002
4453
|
copilotRuntimeNodeHttpEndpoint,
|
|
4003
4454
|
createContext,
|
|
4004
4455
|
flattenToolCallsNoDuplicates,
|
|
4005
|
-
getCommonConfig
|
|
4456
|
+
getCommonConfig,
|
|
4457
|
+
langGraphCloudEndpoint
|
|
4006
4458
|
});
|
|
4007
4459
|
//# sourceMappingURL=index.js.map
|