@copilotkit/runtime 1.6.0-next.2 → 1.6.0-next.4
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 +14 -0
- package/dist/{chunk-CNE5TM3A.mjs → chunk-4FCUC27H.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-7EXH7PVD.mjs} +3 -2
- package/dist/chunk-7EXH7PVD.mjs.map +1 -0
- package/dist/{chunk-O7ERQQ2G.mjs → chunk-ROFUPT7E.mjs} +2 -2
- package/dist/{chunk-6BXTXLGY.mjs → chunk-YUCVJM6E.mjs} +23 -25
- package/dist/chunk-YUCVJM6E.mjs.map +1 -0
- package/dist/{chunk-DDOT5G7D.mjs → chunk-Z5VUD7NL.mjs} +2 -2
- package/dist/index.js +89 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/lib/index.js +82 -83
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.js +3 -2
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.js +3 -2
- 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.js +3 -2
- 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.js +3 -2
- 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 +28 -27
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +4 -3
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +236 -0
- package/src/lib/runtime/remote-action-constructors.ts +7 -6
- package/src/lib/runtime/remote-lg-action.ts +2 -6
- package/src/service-adapters/conversion.ts +3 -2
- package/src/service-adapters/openai/utils.ts +2 -1
- package/tsconfig.json +3 -2
- package/dist/chunk-6BXTXLGY.mjs.map +0 -1
- package/dist/chunk-OS5YD32G.mjs.map +0 -1
- /package/dist/{chunk-CNE5TM3A.mjs.map → chunk-4FCUC27H.mjs.map} +0 -0
- /package/dist/{chunk-O7ERQQ2G.mjs.map → chunk-ROFUPT7E.mjs.map} +0 -0
- /package/dist/{chunk-DDOT5G7D.mjs.map → chunk-Z5VUD7NL.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.6.0-next.
|
|
47
|
+
version: "1.6.0-next.4",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -66,7 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
devDependencies: {
|
|
67
67
|
"@swc/core": "1.5.28",
|
|
68
68
|
"@types/express": "^4.17.21",
|
|
69
|
-
"@types/jest": "^29.5.
|
|
69
|
+
"@types/jest": "^29.5.12",
|
|
70
70
|
"@types/node": "^18.11.17",
|
|
71
71
|
"@whatwg-node/server": "^0.9.34",
|
|
72
72
|
eslint: "^8.56.0",
|
|
@@ -90,6 +90,7 @@ var require_package = __commonJS({
|
|
|
90
90
|
"@langchain/langgraph-sdk": "^0.0.36",
|
|
91
91
|
"@langchain/openai": "^0.4.2",
|
|
92
92
|
"class-transformer": "^0.5.1",
|
|
93
|
+
"class-validator": "^0.14.1",
|
|
93
94
|
express: "^4.19.2",
|
|
94
95
|
graphql: "^16.8.1",
|
|
95
96
|
"graphql-scalars": "^1.23.0",
|
|
@@ -158,7 +159,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
158
159
|
var import_reflect_metadata = require("reflect-metadata");
|
|
159
160
|
|
|
160
161
|
// src/lib/runtime/copilot-runtime.ts
|
|
161
|
-
var
|
|
162
|
+
var import_shared20 = require("@copilotkit/shared");
|
|
162
163
|
|
|
163
164
|
// src/service-adapters/langchain/langserve.ts
|
|
164
165
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -242,6 +243,7 @@ __name(RemoteChain, "RemoteChain");
|
|
|
242
243
|
var import_openai = __toESM(require("openai"));
|
|
243
244
|
|
|
244
245
|
// src/service-adapters/openai/utils.ts
|
|
246
|
+
var import_shared = require("@copilotkit/shared");
|
|
245
247
|
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
246
248
|
maxTokens || (maxTokens = maxTokensForOpenAIModel(model));
|
|
247
249
|
const result = [];
|
|
@@ -335,7 +337,7 @@ function convertActionInputToOpenAITool(action) {
|
|
|
335
337
|
function: {
|
|
336
338
|
name: action.name,
|
|
337
339
|
description: action.description,
|
|
338
|
-
parameters:
|
|
340
|
+
parameters: (0, import_shared.parseJson)(action.jsonSchema, {})
|
|
339
341
|
}
|
|
340
342
|
};
|
|
341
343
|
}
|
|
@@ -381,7 +383,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
381
383
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
382
384
|
|
|
383
385
|
// src/service-adapters/openai/openai-adapter.ts
|
|
384
|
-
var
|
|
386
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
385
387
|
var DEFAULT_MODEL = "gpt-4o";
|
|
386
388
|
var OpenAIAdapter = class {
|
|
387
389
|
model = DEFAULT_MODEL;
|
|
@@ -400,7 +402,7 @@ var OpenAIAdapter = class {
|
|
|
400
402
|
async process(request) {
|
|
401
403
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
402
404
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
403
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
405
|
+
const threadId = threadIdFromRequest ?? (0, import_shared2.randomUUID)();
|
|
404
406
|
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
405
407
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
406
408
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
@@ -507,7 +509,7 @@ __name(OpenAIAdapter, "OpenAIAdapter");
|
|
|
507
509
|
// src/service-adapters/langchain/utils.ts
|
|
508
510
|
var import_messages = require("@langchain/core/messages");
|
|
509
511
|
var import_tools = require("@langchain/core/tools");
|
|
510
|
-
var
|
|
512
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
511
513
|
function convertMessageToLangChainMessage(message) {
|
|
512
514
|
if (message.isTextMessage()) {
|
|
513
515
|
if (message.role == "user") {
|
|
@@ -540,7 +542,7 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
540
542
|
return new import_tools.DynamicStructuredTool({
|
|
541
543
|
name: actionInput.name,
|
|
542
544
|
description: actionInput.description,
|
|
543
|
-
schema: (0,
|
|
545
|
+
schema: (0, import_shared3.convertJsonSchemaToZodSchema)(JSON.parse(actionInput.jsonSchema), true),
|
|
544
546
|
func: async () => {
|
|
545
547
|
return "";
|
|
546
548
|
}
|
|
@@ -573,7 +575,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
573
575
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
574
576
|
if (typeof result === "string") {
|
|
575
577
|
if (!actionExecution) {
|
|
576
|
-
eventStream$.sendTextMessage((0,
|
|
578
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result);
|
|
577
579
|
} else {
|
|
578
580
|
eventStream$.sendActionExecutionResult({
|
|
579
581
|
actionExecutionId: actionExecution.id,
|
|
@@ -584,11 +586,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
584
586
|
} else if (isAIMessage(result)) {
|
|
585
587
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
586
588
|
if (result.content) {
|
|
587
|
-
eventStream$.sendTextMessage((0,
|
|
589
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
588
590
|
}
|
|
589
591
|
for (const toolCall of result.tool_calls) {
|
|
590
592
|
eventStream$.sendActionExecution({
|
|
591
|
-
actionExecutionId: toolCall.id || (0,
|
|
593
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
592
594
|
actionName: toolCall.name,
|
|
593
595
|
args: JSON.stringify(toolCall.args)
|
|
594
596
|
});
|
|
@@ -596,12 +598,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
596
598
|
} else if (isBaseMessageChunk(result)) {
|
|
597
599
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
598
600
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
599
|
-
eventStream$.sendTextMessage((0,
|
|
601
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
600
602
|
}
|
|
601
603
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
602
604
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
603
605
|
eventStream$.sendActionExecution({
|
|
604
|
-
actionExecutionId: toolCall.id || (0,
|
|
606
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
605
607
|
actionName: toolCall.name,
|
|
606
608
|
args: JSON.stringify(toolCall.args)
|
|
607
609
|
});
|
|
@@ -675,7 +677,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
675
677
|
});
|
|
676
678
|
} else if (content) {
|
|
677
679
|
mode = "message";
|
|
678
|
-
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0,
|
|
680
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared3.randomId)();
|
|
679
681
|
eventStream$.sendTextMessageStart({
|
|
680
682
|
messageId: currentMessageId
|
|
681
683
|
});
|
|
@@ -732,7 +734,7 @@ function encodeResult(result) {
|
|
|
732
734
|
__name(encodeResult, "encodeResult");
|
|
733
735
|
|
|
734
736
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
735
|
-
var
|
|
737
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
736
738
|
var import_promises = require("@langchain/core/callbacks/promises");
|
|
737
739
|
var LangChainAdapter = class {
|
|
738
740
|
options;
|
|
@@ -745,7 +747,7 @@ var LangChainAdapter = class {
|
|
|
745
747
|
async process(request) {
|
|
746
748
|
try {
|
|
747
749
|
const { eventSource, model, actions, messages, runId, threadId: threadIdFromRequest } = request;
|
|
748
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
750
|
+
const threadId = threadIdFromRequest ?? (0, import_shared4.randomUUID)();
|
|
749
751
|
const result = await this.options.chainFn({
|
|
750
752
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
751
753
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -989,7 +991,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
|
|
|
989
991
|
|
|
990
992
|
// src/service-adapters/unify/unify-adapter.ts
|
|
991
993
|
var import_openai3 = __toESM(require("openai"));
|
|
992
|
-
var
|
|
994
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
993
995
|
var UnifyAdapter = class {
|
|
994
996
|
apiKey;
|
|
995
997
|
model;
|
|
@@ -1031,7 +1033,7 @@ var UnifyAdapter = class {
|
|
|
1031
1033
|
for await (const chunk of stream) {
|
|
1032
1034
|
if (this.start) {
|
|
1033
1035
|
model = chunk.model;
|
|
1034
|
-
currentMessageId = (0,
|
|
1036
|
+
currentMessageId = (0, import_shared5.randomId)();
|
|
1035
1037
|
eventStream$.sendTextMessageStart({
|
|
1036
1038
|
messageId: currentMessageId
|
|
1037
1039
|
});
|
|
@@ -1098,7 +1100,7 @@ var UnifyAdapter = class {
|
|
|
1098
1100
|
eventStream$.complete();
|
|
1099
1101
|
});
|
|
1100
1102
|
return {
|
|
1101
|
-
threadId: request.threadId || (0,
|
|
1103
|
+
threadId: request.threadId || (0, import_shared5.randomUUID)()
|
|
1102
1104
|
};
|
|
1103
1105
|
}
|
|
1104
1106
|
};
|
|
@@ -1106,7 +1108,7 @@ __name(UnifyAdapter, "UnifyAdapter");
|
|
|
1106
1108
|
|
|
1107
1109
|
// src/service-adapters/groq/groq-adapter.ts
|
|
1108
1110
|
var import_groq_sdk = require("groq-sdk");
|
|
1109
|
-
var
|
|
1111
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1110
1112
|
var DEFAULT_MODEL2 = "llama3-groq-70b-8192-tool-use-preview";
|
|
1111
1113
|
var GroqAdapter = class {
|
|
1112
1114
|
model = DEFAULT_MODEL2;
|
|
@@ -1219,7 +1221,7 @@ var GroqAdapter = class {
|
|
|
1219
1221
|
eventStream$.complete();
|
|
1220
1222
|
});
|
|
1221
1223
|
return {
|
|
1222
|
-
threadId: request.threadId || (0,
|
|
1224
|
+
threadId: request.threadId || (0, import_shared6.randomUUID)()
|
|
1223
1225
|
};
|
|
1224
1226
|
}
|
|
1225
1227
|
};
|
|
@@ -1361,7 +1363,7 @@ function groupAnthropicMessagesByRole(messageParams) {
|
|
|
1361
1363
|
__name(groupAnthropicMessagesByRole, "groupAnthropicMessagesByRole");
|
|
1362
1364
|
|
|
1363
1365
|
// src/service-adapters/anthropic/anthropic-adapter.ts
|
|
1364
|
-
var
|
|
1366
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1365
1367
|
var DEFAULT_MODEL3 = "claude-3-sonnet-20240229";
|
|
1366
1368
|
var AnthropicAdapter = class {
|
|
1367
1369
|
model = DEFAULT_MODEL3;
|
|
@@ -1412,8 +1414,8 @@ var AnthropicAdapter = class {
|
|
|
1412
1414
|
eventSource.stream(async (eventStream$) => {
|
|
1413
1415
|
let mode = null;
|
|
1414
1416
|
let didOutputText = false;
|
|
1415
|
-
let currentMessageId = (0,
|
|
1416
|
-
let currentToolCallId = (0,
|
|
1417
|
+
let currentMessageId = (0, import_shared7.randomId)();
|
|
1418
|
+
let currentToolCallId = (0, import_shared7.randomId)();
|
|
1417
1419
|
let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
|
|
1418
1420
|
for await (const chunk of await stream) {
|
|
1419
1421
|
if (chunk.type === "message_start") {
|
|
@@ -1470,7 +1472,7 @@ var AnthropicAdapter = class {
|
|
|
1470
1472
|
eventStream$.complete();
|
|
1471
1473
|
});
|
|
1472
1474
|
return {
|
|
1473
|
-
threadId: threadId || (0,
|
|
1475
|
+
threadId: threadId || (0, import_shared7.randomUUID)()
|
|
1474
1476
|
};
|
|
1475
1477
|
}
|
|
1476
1478
|
};
|
|
@@ -1510,7 +1512,7 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1510
1512
|
|
|
1511
1513
|
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1512
1514
|
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1513
|
-
var
|
|
1515
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1514
1516
|
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1515
1517
|
var ExperimentalOllamaAdapter = class {
|
|
1516
1518
|
model;
|
|
@@ -1529,7 +1531,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1529
1531
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1530
1532
|
const _stream = await ollama.stream(contents);
|
|
1531
1533
|
eventSource.stream(async (eventStream$) => {
|
|
1532
|
-
const currentMessageId = (0,
|
|
1534
|
+
const currentMessageId = (0, import_shared8.randomId)();
|
|
1533
1535
|
eventStream$.sendTextMessageStart({
|
|
1534
1536
|
messageId: currentMessageId
|
|
1535
1537
|
});
|
|
@@ -1545,18 +1547,18 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1545
1547
|
eventStream$.complete();
|
|
1546
1548
|
});
|
|
1547
1549
|
return {
|
|
1548
|
-
threadId: request.threadId || (0,
|
|
1550
|
+
threadId: request.threadId || (0, import_shared8.randomUUID)()
|
|
1549
1551
|
};
|
|
1550
1552
|
}
|
|
1551
1553
|
};
|
|
1552
1554
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1553
1555
|
|
|
1554
1556
|
// src/service-adapters/empty/empty-adapter.ts
|
|
1555
|
-
var
|
|
1557
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1556
1558
|
var EmptyAdapter = class {
|
|
1557
1559
|
async process(request) {
|
|
1558
1560
|
return {
|
|
1559
|
-
threadId: request.threadId || (0,
|
|
1561
|
+
threadId: request.threadId || (0, import_shared9.randomUUID)()
|
|
1560
1562
|
};
|
|
1561
1563
|
}
|
|
1562
1564
|
};
|
|
@@ -1564,11 +1566,11 @@ __name(EmptyAdapter, "EmptyAdapter");
|
|
|
1564
1566
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
1565
1567
|
|
|
1566
1568
|
// src/service-adapters/events.ts
|
|
1567
|
-
var
|
|
1569
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
1568
1570
|
var import_rxjs2 = require("rxjs");
|
|
1569
1571
|
|
|
1570
1572
|
// src/lib/telemetry-client.ts
|
|
1571
|
-
var
|
|
1573
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
1572
1574
|
|
|
1573
1575
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1574
1576
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1608,7 +1610,7 @@ var CustomEventNames;
|
|
|
1608
1610
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1609
1611
|
|
|
1610
1612
|
// src/agents/langgraph/event-source.ts
|
|
1611
|
-
var
|
|
1613
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1612
1614
|
var RemoteLangGraphEventSource = class {
|
|
1613
1615
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1614
1616
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1814,7 +1816,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1814
1816
|
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1815
1817
|
});
|
|
1816
1818
|
}
|
|
1817
|
-
const messageId = (0,
|
|
1819
|
+
const messageId = (0, import_shared10.randomId)();
|
|
1818
1820
|
events.push({
|
|
1819
1821
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1820
1822
|
messageId
|
|
@@ -1837,7 +1839,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1837
1839
|
// src/lib/runtime/remote-lg-action.ts
|
|
1838
1840
|
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1839
1841
|
var import_node_crypto = require("crypto");
|
|
1840
|
-
var
|
|
1842
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1841
1843
|
var import_partial_json = require("partial-json");
|
|
1842
1844
|
|
|
1843
1845
|
// src/graphql/types/enums.ts
|
|
@@ -2466,6 +2468,7 @@ CopilotKitLangGraphInterruptEvent = _ts_decorate5([
|
|
|
2466
2468
|
], CopilotKitLangGraphInterruptEvent);
|
|
2467
2469
|
|
|
2468
2470
|
// src/lib/runtime/remote-lg-action.ts
|
|
2471
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2469
2472
|
var activeInterruptEvent = false;
|
|
2470
2473
|
async function execute(args) {
|
|
2471
2474
|
return new ReadableStream({
|
|
@@ -2495,11 +2498,11 @@ async function streamEvents(controller, args) {
|
|
|
2495
2498
|
...propertyHeaders
|
|
2496
2499
|
}
|
|
2497
2500
|
});
|
|
2498
|
-
let threadId = argsInitialThreadId ?? (0,
|
|
2501
|
+
let threadId = argsInitialThreadId ?? (0, import_shared11.randomUUID)();
|
|
2499
2502
|
if (argsInitialThreadId && argsInitialThreadId.startsWith("ck-")) {
|
|
2500
2503
|
threadId = argsInitialThreadId.substring(3);
|
|
2501
2504
|
}
|
|
2502
|
-
if (!(0,
|
|
2505
|
+
if (!(0, import_shared11.isValidUUID)(threadId)) {
|
|
2503
2506
|
console.warn(`Cannot use the threadId ${threadId} with LangGraph Platform. Must be a valid UUID.`);
|
|
2504
2507
|
}
|
|
2505
2508
|
let wasInitiatedWithExistingThread = true;
|
|
@@ -2545,15 +2548,9 @@ async function streamEvents(controller, args) {
|
|
|
2545
2548
|
}
|
|
2546
2549
|
if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
|
|
2547
2550
|
let response = lgInterruptMetaEvent.response;
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
};
|
|
2552
|
-
} catch (e) {
|
|
2553
|
-
payload.command = {
|
|
2554
|
-
resume: response
|
|
2555
|
-
};
|
|
2556
|
-
}
|
|
2551
|
+
payload.command = {
|
|
2552
|
+
resume: (0, import_shared12.parseJson)(response, response)
|
|
2553
|
+
};
|
|
2557
2554
|
}
|
|
2558
2555
|
if (mode === "continue" && !activeInterruptEvent) {
|
|
2559
2556
|
await client.threads.updateState(threadId, {
|
|
@@ -2993,8 +2990,9 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
2993
2990
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2994
2991
|
|
|
2995
2992
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2996
|
-
var
|
|
2997
|
-
var
|
|
2993
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2994
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2995
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2998
2996
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2999
2997
|
const agents = endpoint.agents.map((agent) => ({
|
|
3000
2998
|
name: agent.name,
|
|
@@ -3017,8 +3015,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3017
3015
|
if (agentStates) {
|
|
3018
3016
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3019
3017
|
if (jsonState) {
|
|
3020
|
-
state =
|
|
3021
|
-
configurable =
|
|
3018
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3019
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3022
3020
|
}
|
|
3023
3021
|
}
|
|
3024
3022
|
try {
|
|
@@ -3041,7 +3039,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3041
3039
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
3042
3040
|
name: action.name,
|
|
3043
3041
|
description: action.description,
|
|
3044
|
-
parameters:
|
|
3042
|
+
parameters: (0, import_shared15.parseJson)(action.jsonSchema, "")
|
|
3045
3043
|
})),
|
|
3046
3044
|
metaEvents
|
|
3047
3045
|
});
|
|
@@ -3098,11 +3096,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3098
3096
|
body: await response.text()
|
|
3099
3097
|
}, "Failed to execute remote action");
|
|
3100
3098
|
if (response.status === 404) {
|
|
3101
|
-
throw new
|
|
3099
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3102
3100
|
url: fetchUrl
|
|
3103
3101
|
});
|
|
3104
3102
|
}
|
|
3105
|
-
throw new
|
|
3103
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3106
3104
|
status: response.status,
|
|
3107
3105
|
url: fetchUrl,
|
|
3108
3106
|
isRemoteEndpoint: true
|
|
@@ -3116,10 +3114,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3116
3114
|
}, "Executed remote action");
|
|
3117
3115
|
return result;
|
|
3118
3116
|
} catch (error) {
|
|
3119
|
-
if (error instanceof
|
|
3117
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3120
3118
|
throw error;
|
|
3121
3119
|
}
|
|
3122
|
-
throw new
|
|
3120
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3123
3121
|
error,
|
|
3124
3122
|
url: fetchUrl
|
|
3125
3123
|
});
|
|
@@ -3147,8 +3145,8 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3147
3145
|
if (agentStates) {
|
|
3148
3146
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3149
3147
|
if (jsonState) {
|
|
3150
|
-
state =
|
|
3151
|
-
configurable =
|
|
3148
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3149
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3152
3150
|
}
|
|
3153
3151
|
}
|
|
3154
3152
|
const fetchUrl = `${url}/agents/execute`;
|
|
@@ -3170,7 +3168,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3170
3168
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
3171
3169
|
name: action.name,
|
|
3172
3170
|
description: action.description,
|
|
3173
|
-
parameters:
|
|
3171
|
+
parameters: (0, import_shared15.parseJson)(action.jsonSchema, {})
|
|
3174
3172
|
})),
|
|
3175
3173
|
metaEvents
|
|
3176
3174
|
})
|
|
@@ -3182,11 +3180,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3182
3180
|
body: await response.text()
|
|
3183
3181
|
}, "Failed to execute remote agent");
|
|
3184
3182
|
if (response.status === 404) {
|
|
3185
|
-
throw new
|
|
3183
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3186
3184
|
url: fetchUrl
|
|
3187
3185
|
});
|
|
3188
3186
|
}
|
|
3189
|
-
throw new
|
|
3187
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3190
3188
|
status: response.status,
|
|
3191
3189
|
url: fetchUrl,
|
|
3192
3190
|
isRemoteEndpoint: true
|
|
@@ -3196,10 +3194,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3196
3194
|
streamResponse(response.body, eventSource.eventStream$);
|
|
3197
3195
|
return eventSource.processLangGraphEvents();
|
|
3198
3196
|
} catch (error) {
|
|
3199
|
-
if (error instanceof
|
|
3197
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3200
3198
|
throw error;
|
|
3201
3199
|
}
|
|
3202
|
-
throw new
|
|
3200
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3203
3201
|
error,
|
|
3204
3202
|
url: fetchUrl
|
|
3205
3203
|
});
|
|
@@ -3273,7 +3271,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
3273
3271
|
__name(createHeaders, "createHeaders");
|
|
3274
3272
|
|
|
3275
3273
|
// src/lib/runtime/remote-actions.ts
|
|
3276
|
-
var
|
|
3274
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
3277
3275
|
var EndpointType;
|
|
3278
3276
|
(function(EndpointType2) {
|
|
3279
3277
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -3307,7 +3305,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3307
3305
|
status: response.status,
|
|
3308
3306
|
body: await response.text()
|
|
3309
3307
|
}, "Failed to fetch actions from url");
|
|
3310
|
-
throw new
|
|
3308
|
+
throw new import_shared16.ResolvedCopilotKitError({
|
|
3311
3309
|
status: response.status,
|
|
3312
3310
|
url: fetchUrl,
|
|
3313
3311
|
isRemoteEndpoint: true
|
|
@@ -3319,10 +3317,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3319
3317
|
}, "Fetched actions from url");
|
|
3320
3318
|
return json;
|
|
3321
3319
|
} catch (error) {
|
|
3322
|
-
if (error instanceof
|
|
3320
|
+
if (error instanceof import_shared16.CopilotKitError) {
|
|
3323
3321
|
throw error;
|
|
3324
3322
|
}
|
|
3325
|
-
throw new
|
|
3323
|
+
throw new import_shared16.CopilotKitLowLevelError({
|
|
3326
3324
|
error,
|
|
3327
3325
|
url: fetchUrl
|
|
3328
3326
|
});
|
|
@@ -3385,7 +3383,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3385
3383
|
// src/lib/telemetry-client.ts
|
|
3386
3384
|
var import_node_crypto3 = require("crypto");
|
|
3387
3385
|
var packageJson = require_package();
|
|
3388
|
-
var telemetryClient = new
|
|
3386
|
+
var telemetryClient = new import_shared17.TelemetryClient({
|
|
3389
3387
|
packageName: packageJson.name,
|
|
3390
3388
|
packageVersion: packageJson.version
|
|
3391
3389
|
});
|
|
@@ -3702,10 +3700,10 @@ var RuntimeEventSource = class {
|
|
|
3702
3700
|
const errorMessage = `\u274C ${message}`;
|
|
3703
3701
|
if (!this.callback) {
|
|
3704
3702
|
this.stream(async (eventStream$) => {
|
|
3705
|
-
eventStream$.sendTextMessage((0,
|
|
3703
|
+
eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3706
3704
|
});
|
|
3707
3705
|
} else {
|
|
3708
|
-
this.eventStream$.sendTextMessage((0,
|
|
3706
|
+
this.eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3709
3707
|
}
|
|
3710
3708
|
}
|
|
3711
3709
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -3864,6 +3862,7 @@ __name(executeAction, "executeAction");
|
|
|
3864
3862
|
|
|
3865
3863
|
// src/service-adapters/conversion.ts
|
|
3866
3864
|
var import_class_transformer2 = require("class-transformer");
|
|
3865
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
3867
3866
|
function convertGqlInputToMessages(inputMessages) {
|
|
3868
3867
|
const messages = [];
|
|
3869
3868
|
for (const message of inputMessages) {
|
|
@@ -3880,7 +3879,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3880
3879
|
id: message.id,
|
|
3881
3880
|
createdAt: message.createdAt,
|
|
3882
3881
|
name: message.actionExecutionMessage.name,
|
|
3883
|
-
arguments:
|
|
3882
|
+
arguments: (0, import_shared19.parseJson)(message.actionExecutionMessage.arguments, {}),
|
|
3884
3883
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3885
3884
|
}));
|
|
3886
3885
|
} else if (message.resultMessage) {
|
|
@@ -3901,7 +3900,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3901
3900
|
runId: message.agentStateMessage.runId,
|
|
3902
3901
|
active: message.agentStateMessage.active,
|
|
3903
3902
|
role: message.agentStateMessage.role,
|
|
3904
|
-
state:
|
|
3903
|
+
state: (0, import_shared19.parseJson)(message.agentStateMessage.state, {}),
|
|
3905
3904
|
running: message.agentStateMessage.running
|
|
3906
3905
|
}));
|
|
3907
3906
|
}
|
|
@@ -3941,7 +3940,7 @@ var CopilotRuntime = class {
|
|
|
3941
3940
|
return await this.processAgentRequest(request);
|
|
3942
3941
|
}
|
|
3943
3942
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3944
|
-
throw new
|
|
3943
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
3945
3944
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3946
3945
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3947
3946
|
please use an LLM adapter instead.`
|
|
@@ -3953,7 +3952,7 @@ please use an LLM adapter instead.`
|
|
|
3953
3952
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3954
3953
|
name: action.name,
|
|
3955
3954
|
description: action.description,
|
|
3956
|
-
jsonSchema: JSON.stringify((0,
|
|
3955
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
3957
3956
|
}));
|
|
3958
3957
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3959
3958
|
...serverSideActionsInput,
|
|
@@ -4005,7 +4004,7 @@ please use an LLM adapter instead.`
|
|
|
4005
4004
|
extensions: result.extensions
|
|
4006
4005
|
};
|
|
4007
4006
|
} catch (error) {
|
|
4008
|
-
if (error instanceof
|
|
4007
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4009
4008
|
throw error;
|
|
4010
4009
|
}
|
|
4011
4010
|
console.error("Error getting response:", error);
|
|
@@ -4051,11 +4050,11 @@ please use an LLM adapter instead.`
|
|
|
4051
4050
|
});
|
|
4052
4051
|
if (!response.ok) {
|
|
4053
4052
|
if (response.status === 404) {
|
|
4054
|
-
throw new
|
|
4053
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4055
4054
|
url: fetchUrl
|
|
4056
4055
|
});
|
|
4057
4056
|
}
|
|
4058
|
-
throw new
|
|
4057
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4059
4058
|
status: response.status,
|
|
4060
4059
|
url: fetchUrl,
|
|
4061
4060
|
isRemoteEndpoint: true
|
|
@@ -4065,7 +4064,7 @@ please use an LLM adapter instead.`
|
|
|
4065
4064
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
4066
4065
|
name: agent.name,
|
|
4067
4066
|
description: agent.description ?? "" ?? "",
|
|
4068
|
-
id: (0,
|
|
4067
|
+
id: (0, import_shared20.randomId)(),
|
|
4069
4068
|
endpoint
|
|
4070
4069
|
}));
|
|
4071
4070
|
return [
|
|
@@ -4073,10 +4072,10 @@ please use an LLM adapter instead.`
|
|
|
4073
4072
|
...endpointAgents
|
|
4074
4073
|
];
|
|
4075
4074
|
} catch (error) {
|
|
4076
|
-
if (error instanceof
|
|
4075
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4077
4076
|
throw error;
|
|
4078
4077
|
}
|
|
4079
|
-
throw new
|
|
4078
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4080
4079
|
error,
|
|
4081
4080
|
url: fetchUrl
|
|
4082
4081
|
});
|
|
@@ -4138,11 +4137,11 @@ please use an LLM adapter instead.`
|
|
|
4138
4137
|
});
|
|
4139
4138
|
if (!response.ok) {
|
|
4140
4139
|
if (response.status === 404) {
|
|
4141
|
-
throw new
|
|
4140
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4142
4141
|
url: fetchUrl
|
|
4143
4142
|
});
|
|
4144
4143
|
}
|
|
4145
|
-
throw new
|
|
4144
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4146
4145
|
status: response.status,
|
|
4147
4146
|
url: fetchUrl,
|
|
4148
4147
|
isRemoteEndpoint: true
|
|
@@ -4155,10 +4154,10 @@ please use an LLM adapter instead.`
|
|
|
4155
4154
|
messages: JSON.stringify(data.messages)
|
|
4156
4155
|
};
|
|
4157
4156
|
} catch (error) {
|
|
4158
|
-
if (error instanceof
|
|
4157
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4159
4158
|
throw error;
|
|
4160
4159
|
}
|
|
4161
|
-
throw new
|
|
4160
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4162
4161
|
error,
|
|
4163
4162
|
url: fetchUrl
|
|
4164
4163
|
});
|
|
@@ -4176,7 +4175,7 @@ please use an LLM adapter instead.`
|
|
|
4176
4175
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4177
4176
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
4178
4177
|
if (!currentAgent) {
|
|
4179
|
-
throw new
|
|
4178
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4180
4179
|
agentName
|
|
4181
4180
|
});
|
|
4182
4181
|
}
|
|
@@ -4187,7 +4186,7 @@ please use an LLM adapter instead.`
|
|
|
4187
4186
|
)).map((action) => ({
|
|
4188
4187
|
name: action.name,
|
|
4189
4188
|
description: action.description,
|
|
4190
|
-
jsonSchema: JSON.stringify((0,
|
|
4189
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4191
4190
|
}));
|
|
4192
4191
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
4193
4192
|
...availableActionsForCurrentAgent,
|
|
@@ -5112,7 +5111,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
5112
5111
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
5113
5112
|
|
|
5114
5113
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
5115
|
-
var
|
|
5114
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
5116
5115
|
|
|
5117
5116
|
// src/graphql/types/agents-response.type.ts
|
|
5118
5117
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -5295,7 +5294,7 @@ var CopilotResolver = class {
|
|
|
5295
5294
|
rejectOutputMessagesPromise = reject;
|
|
5296
5295
|
});
|
|
5297
5296
|
logger2.debug("Processing");
|
|
5298
|
-
const { eventSource, threadId = (0,
|
|
5297
|
+
const { eventSource, threadId = (0, import_shared21.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5299
5298
|
serviceAdapter,
|
|
5300
5299
|
messages: data.messages,
|
|
5301
5300
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5428,7 +5427,7 @@ var CopilotResolver = class {
|
|
|
5428
5427
|
});
|
|
5429
5428
|
outputMessages = [
|
|
5430
5429
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5431
|
-
id: (0,
|
|
5430
|
+
id: (0, import_shared21.randomId)(),
|
|
5432
5431
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5433
5432
|
content: result.reason,
|
|
5434
5433
|
role: MessageRole.assistant
|
|
@@ -5606,7 +5605,7 @@ var CopilotResolver = class {
|
|
|
5606
5605
|
event
|
|
5607
5606
|
}, "Agent message event received");
|
|
5608
5607
|
pushMessage({
|
|
5609
|
-
id: (0,
|
|
5608
|
+
id: (0, import_shared21.randomId)(),
|
|
5610
5609
|
status: new SuccessMessageStatus(),
|
|
5611
5610
|
threadId: event.threadId,
|
|
5612
5611
|
agentName: event.agentName,
|
|
@@ -5619,7 +5618,7 @@ var CopilotResolver = class {
|
|
|
5619
5618
|
createdAt: /* @__PURE__ */ new Date()
|
|
5620
5619
|
});
|
|
5621
5620
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5622
|
-
id: (0,
|
|
5621
|
+
id: (0, import_shared21.randomId)(),
|
|
5623
5622
|
threadId: event.threadId,
|
|
5624
5623
|
agentName: event.agentName,
|
|
5625
5624
|
nodeName: event.nodeName,
|