@copilotkit/runtime 1.6.0-next.1 → 1.6.0-next.10
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 +69 -0
- package/__snapshots__/schema/schema.graphql +1 -0
- package/dist/{chunk-CCQ73DAH.mjs → chunk-3ORZOFAL.mjs} +2 -2
- package/dist/{chunk-CHDIEE43.mjs → chunk-5NJDGEB3.mjs} +87 -44
- package/dist/chunk-5NJDGEB3.mjs.map +1 -0
- package/dist/{chunk-A25FIW7J.mjs → chunk-6XDMOAOM.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-FZJAYGIR.mjs} +45 -12
- package/dist/chunk-FZJAYGIR.mjs.map +1 -0
- package/dist/{chunk-C7GTLEVO.mjs → chunk-JUWN34MZ.mjs} +2 -2
- package/dist/{copilot-runtime-67033bfa.d.ts → copilot-runtime-15bfc4f4.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/{groq-adapter-9d15c927.d.ts → groq-adapter-fb9aa3ab.d.ts} +1 -1
- package/dist/{index-f6d1f30b.d.ts → index-5bec5424.d.ts} +2 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +199 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/{langserve-7cc5be48.d.ts → langserve-6f7af8d3.d.ts} +1 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +192 -116
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +5 -3
- 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 +3 -3
- package/dist/lib/integrations/nest/index.js +5 -3
- 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 +3 -3
- package/dist/lib/integrations/node-express/index.js +5 -3
- 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 +3 -3
- package/dist/lib/integrations/node-http/index.js +5 -3
- 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.d.ts +4 -4
- package/dist/service-adapters/index.js +70 -37
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +5 -4
- package/src/agents/langgraph/event-source.ts +21 -5
- package/src/graphql/types/enums.ts +1 -0
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +236 -0
- package/src/lib/runtime/copilot-runtime.ts +9 -3
- package/src/lib/runtime/remote-action-constructors.ts +9 -7
- package/src/lib/runtime/remote-lg-action.ts +35 -7
- package/src/service-adapters/conversion.ts +39 -46
- package/src/service-adapters/groq/groq-adapter.ts +6 -3
- package/src/service-adapters/openai/openai-adapter.ts +1 -1
- package/src/service-adapters/openai/openai-assistant-adapter.ts +1 -1
- package/src/service-adapters/openai/utils.ts +39 -13
- package/src/service-adapters/unify/unify-adapter.ts +1 -1
- package/tsconfig.json +3 -2
- package/dist/chunk-CHDIEE43.mjs.map +0 -1
- package/dist/chunk-OS5YD32G.mjs.map +0 -1
- /package/dist/{chunk-CCQ73DAH.mjs.map → chunk-3ORZOFAL.mjs.map} +0 -0
- /package/dist/{chunk-A25FIW7J.mjs.map → chunk-6XDMOAOM.mjs.map} +0 -0
- /package/dist/{chunk-C7GTLEVO.mjs.map → chunk-JUWN34MZ.mjs.map} +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var require_package = __commonJS({
|
|
|
44
44
|
publishConfig: {
|
|
45
45
|
access: "public"
|
|
46
46
|
},
|
|
47
|
-
version: "1.6.0-next.
|
|
47
|
+
version: "1.6.0-next.10",
|
|
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,13 +90,14 @@ 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",
|
|
96
97
|
"graphql-yoga": "^5.3.1",
|
|
97
98
|
"groq-sdk": "^0.5.0",
|
|
98
99
|
langchain: "^0.3.3",
|
|
99
|
-
openai: "^4.
|
|
100
|
+
openai: "^4.85.1",
|
|
100
101
|
"partial-json": "^0.1.7",
|
|
101
102
|
pino: "^9.2.0",
|
|
102
103
|
"pino-pretty": "^11.2.1",
|
|
@@ -149,7 +150,7 @@ __export(lib_exports, {
|
|
|
149
150
|
module.exports = __toCommonJS(lib_exports);
|
|
150
151
|
|
|
151
152
|
// src/lib/runtime/copilot-runtime.ts
|
|
152
|
-
var
|
|
153
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
153
154
|
|
|
154
155
|
// src/service-adapters/langchain/langserve.ts
|
|
155
156
|
var import_remote = require("langchain/runnables/remote");
|
|
@@ -233,6 +234,7 @@ __name(RemoteChain, "RemoteChain");
|
|
|
233
234
|
var import_openai = __toESM(require("openai"));
|
|
234
235
|
|
|
235
236
|
// src/service-adapters/openai/utils.ts
|
|
237
|
+
var import_shared = require("@copilotkit/shared");
|
|
236
238
|
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
237
239
|
maxTokens || (maxTokens = maxTokensForOpenAIModel(model));
|
|
238
240
|
const result = [];
|
|
@@ -242,7 +244,10 @@ function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
|
242
244
|
}
|
|
243
245
|
maxTokens -= toolsNumTokens;
|
|
244
246
|
for (const message of messages) {
|
|
245
|
-
if (
|
|
247
|
+
if ([
|
|
248
|
+
"system",
|
|
249
|
+
"developer"
|
|
250
|
+
].includes(message.role)) {
|
|
246
251
|
const numTokens = countMessageTokens(model, message);
|
|
247
252
|
maxTokens -= numTokens;
|
|
248
253
|
if (maxTokens < 0) {
|
|
@@ -255,7 +260,10 @@ function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
|
255
260
|
...messages
|
|
256
261
|
].reverse();
|
|
257
262
|
for (const message of reversedMessages) {
|
|
258
|
-
if (
|
|
263
|
+
if ([
|
|
264
|
+
"system",
|
|
265
|
+
"developer"
|
|
266
|
+
].includes(message.role)) {
|
|
259
267
|
result.unshift(message);
|
|
260
268
|
continue;
|
|
261
269
|
} else if (cutoff) {
|
|
@@ -278,9 +286,23 @@ function maxTokensForOpenAIModel(model) {
|
|
|
278
286
|
__name(maxTokensForOpenAIModel, "maxTokensForOpenAIModel");
|
|
279
287
|
var DEFAULT_MAX_TOKENS = 128e3;
|
|
280
288
|
var maxTokensByModel = {
|
|
289
|
+
// o1
|
|
290
|
+
o1: 2e5,
|
|
291
|
+
"o1-2024-12-17": 2e5,
|
|
292
|
+
"o1-mini": 128e3,
|
|
293
|
+
"o1-mini-2024-09-12": 128e3,
|
|
294
|
+
"o1-preview": 128e3,
|
|
295
|
+
"o1-preview-2024-09-12": 128e3,
|
|
296
|
+
// o3-mini
|
|
297
|
+
"o3-mini": 2e5,
|
|
298
|
+
"o3-mini-2025-01-31": 2e5,
|
|
281
299
|
// GPT-4
|
|
282
300
|
"gpt-4o": 128e3,
|
|
301
|
+
"chatgpt-4o-latest": 128e3,
|
|
302
|
+
"gpt-4o-2024-08-06": 128e3,
|
|
283
303
|
"gpt-4o-2024-05-13": 128e3,
|
|
304
|
+
"gpt-4o-mini": 128e3,
|
|
305
|
+
"gpt-4o-mini-2024-07-18": 128e3,
|
|
284
306
|
"gpt-4-turbo": 128e3,
|
|
285
307
|
"gpt-4-turbo-2024-04-09": 128e3,
|
|
286
308
|
"gpt-4-0125-preview": 128e3,
|
|
@@ -326,15 +348,22 @@ function convertActionInputToOpenAITool(action) {
|
|
|
326
348
|
function: {
|
|
327
349
|
name: action.name,
|
|
328
350
|
description: action.description,
|
|
329
|
-
parameters:
|
|
351
|
+
parameters: (0, import_shared.parseJson)(action.jsonSchema, {})
|
|
330
352
|
}
|
|
331
353
|
};
|
|
332
354
|
}
|
|
333
355
|
__name(convertActionInputToOpenAITool, "convertActionInputToOpenAITool");
|
|
334
|
-
function convertMessageToOpenAIMessage(message) {
|
|
356
|
+
function convertMessageToOpenAIMessage(message, options) {
|
|
357
|
+
const { keepSystemRole } = options || {
|
|
358
|
+
keepSystemRole: false
|
|
359
|
+
};
|
|
335
360
|
if (message.isTextMessage()) {
|
|
361
|
+
let role = message.role;
|
|
362
|
+
if (message.role === "system" && !keepSystemRole) {
|
|
363
|
+
role = "developer";
|
|
364
|
+
}
|
|
336
365
|
return {
|
|
337
|
-
role
|
|
366
|
+
role,
|
|
338
367
|
content: message.content
|
|
339
368
|
};
|
|
340
369
|
} else if (message.isActionExecutionMessage()) {
|
|
@@ -363,7 +392,10 @@ __name(convertMessageToOpenAIMessage, "convertMessageToOpenAIMessage");
|
|
|
363
392
|
function convertSystemMessageToAssistantAPI(message) {
|
|
364
393
|
return {
|
|
365
394
|
...message,
|
|
366
|
-
...
|
|
395
|
+
...[
|
|
396
|
+
"system",
|
|
397
|
+
"developer"
|
|
398
|
+
].includes(message.role) && {
|
|
367
399
|
role: "assistant",
|
|
368
400
|
content: "THE FOLLOWING MESSAGE IS A SYSTEM MESSAGE: " + message.content
|
|
369
401
|
}
|
|
@@ -372,7 +404,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
372
404
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
373
405
|
|
|
374
406
|
// src/service-adapters/openai/openai-adapter.ts
|
|
375
|
-
var
|
|
407
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
376
408
|
var DEFAULT_MODEL = "gpt-4o";
|
|
377
409
|
var OpenAIAdapter = class {
|
|
378
410
|
model = DEFAULT_MODEL;
|
|
@@ -391,8 +423,8 @@ var OpenAIAdapter = class {
|
|
|
391
423
|
async process(request) {
|
|
392
424
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
393
425
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
394
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
395
|
-
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
426
|
+
const threadId = threadIdFromRequest ?? (0, import_shared2.randomUUID)();
|
|
427
|
+
let openaiMessages = messages.map((m) => convertMessageToOpenAIMessage(m));
|
|
396
428
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
397
429
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
398
430
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
@@ -498,7 +530,7 @@ __name(OpenAIAdapter, "OpenAIAdapter");
|
|
|
498
530
|
// src/service-adapters/langchain/utils.ts
|
|
499
531
|
var import_messages = require("@langchain/core/messages");
|
|
500
532
|
var import_tools = require("@langchain/core/tools");
|
|
501
|
-
var
|
|
533
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
502
534
|
function convertMessageToLangChainMessage(message) {
|
|
503
535
|
if (message.isTextMessage()) {
|
|
504
536
|
if (message.role == "user") {
|
|
@@ -531,7 +563,7 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
531
563
|
return new import_tools.DynamicStructuredTool({
|
|
532
564
|
name: actionInput.name,
|
|
533
565
|
description: actionInput.description,
|
|
534
|
-
schema: (0,
|
|
566
|
+
schema: (0, import_shared3.convertJsonSchemaToZodSchema)(JSON.parse(actionInput.jsonSchema), true),
|
|
535
567
|
func: async () => {
|
|
536
568
|
return "";
|
|
537
569
|
}
|
|
@@ -564,7 +596,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
564
596
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
565
597
|
if (typeof result === "string") {
|
|
566
598
|
if (!actionExecution) {
|
|
567
|
-
eventStream$.sendTextMessage((0,
|
|
599
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result);
|
|
568
600
|
} else {
|
|
569
601
|
eventStream$.sendActionExecutionResult({
|
|
570
602
|
actionExecutionId: actionExecution.id,
|
|
@@ -575,11 +607,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
575
607
|
} else if (isAIMessage(result)) {
|
|
576
608
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
577
609
|
if (result.content) {
|
|
578
|
-
eventStream$.sendTextMessage((0,
|
|
610
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
579
611
|
}
|
|
580
612
|
for (const toolCall of result.tool_calls) {
|
|
581
613
|
eventStream$.sendActionExecution({
|
|
582
|
-
actionExecutionId: toolCall.id || (0,
|
|
614
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
583
615
|
actionName: toolCall.name,
|
|
584
616
|
args: JSON.stringify(toolCall.args)
|
|
585
617
|
});
|
|
@@ -587,12 +619,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
587
619
|
} else if (isBaseMessageChunk(result)) {
|
|
588
620
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
589
621
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
590
|
-
eventStream$.sendTextMessage((0,
|
|
622
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
591
623
|
}
|
|
592
624
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
593
625
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
594
626
|
eventStream$.sendActionExecution({
|
|
595
|
-
actionExecutionId: toolCall.id || (0,
|
|
627
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
596
628
|
actionName: toolCall.name,
|
|
597
629
|
args: JSON.stringify(toolCall.args)
|
|
598
630
|
});
|
|
@@ -666,7 +698,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
666
698
|
});
|
|
667
699
|
} else if (content) {
|
|
668
700
|
mode = "message";
|
|
669
|
-
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0,
|
|
701
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared3.randomId)();
|
|
670
702
|
eventStream$.sendTextMessageStart({
|
|
671
703
|
messageId: currentMessageId
|
|
672
704
|
});
|
|
@@ -723,7 +755,7 @@ function encodeResult(result) {
|
|
|
723
755
|
__name(encodeResult, "encodeResult");
|
|
724
756
|
|
|
725
757
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
726
|
-
var
|
|
758
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
727
759
|
var import_promises = require("@langchain/core/callbacks/promises");
|
|
728
760
|
var LangChainAdapter = class {
|
|
729
761
|
options;
|
|
@@ -736,7 +768,7 @@ var LangChainAdapter = class {
|
|
|
736
768
|
async process(request) {
|
|
737
769
|
try {
|
|
738
770
|
const { eventSource, model, actions, messages, runId, threadId: threadIdFromRequest } = request;
|
|
739
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
771
|
+
const threadId = threadIdFromRequest ?? (0, import_shared4.randomUUID)();
|
|
740
772
|
const result = await this.options.chainFn({
|
|
741
773
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
742
774
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -855,7 +887,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
855
887
|
];
|
|
856
888
|
const instructionsMessage = messages.shift();
|
|
857
889
|
const instructions = instructionsMessage.isTextMessage() ? instructionsMessage.content : "";
|
|
858
|
-
const userMessage = messages.map(convertMessageToOpenAIMessage).map(convertSystemMessageToAssistantAPI).at(-1);
|
|
890
|
+
const userMessage = messages.map((m) => convertMessageToOpenAIMessage(m)).map(convertSystemMessageToAssistantAPI).at(-1);
|
|
859
891
|
if (userMessage.role !== "user") {
|
|
860
892
|
throw new Error("No user message found");
|
|
861
893
|
}
|
|
@@ -980,7 +1012,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
|
|
|
980
1012
|
|
|
981
1013
|
// src/service-adapters/unify/unify-adapter.ts
|
|
982
1014
|
var import_openai3 = __toESM(require("openai"));
|
|
983
|
-
var
|
|
1015
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
984
1016
|
var UnifyAdapter = class {
|
|
985
1017
|
apiKey;
|
|
986
1018
|
model;
|
|
@@ -1001,7 +1033,7 @@ var UnifyAdapter = class {
|
|
|
1001
1033
|
baseURL: "https://api.unify.ai/v0/"
|
|
1002
1034
|
});
|
|
1003
1035
|
const forwardedParameters = request.forwardedParameters;
|
|
1004
|
-
const messages = request.messages.map(convertMessageToOpenAIMessage);
|
|
1036
|
+
const messages = request.messages.map((m) => convertMessageToOpenAIMessage(m));
|
|
1005
1037
|
const stream = await openai.chat.completions.create({
|
|
1006
1038
|
model: this.model,
|
|
1007
1039
|
messages,
|
|
@@ -1022,7 +1054,7 @@ var UnifyAdapter = class {
|
|
|
1022
1054
|
for await (const chunk of stream) {
|
|
1023
1055
|
if (this.start) {
|
|
1024
1056
|
model = chunk.model;
|
|
1025
|
-
currentMessageId = (0,
|
|
1057
|
+
currentMessageId = (0, import_shared5.randomId)();
|
|
1026
1058
|
eventStream$.sendTextMessageStart({
|
|
1027
1059
|
messageId: currentMessageId
|
|
1028
1060
|
});
|
|
@@ -1089,7 +1121,7 @@ var UnifyAdapter = class {
|
|
|
1089
1121
|
eventStream$.complete();
|
|
1090
1122
|
});
|
|
1091
1123
|
return {
|
|
1092
|
-
threadId: request.threadId || (0,
|
|
1124
|
+
threadId: request.threadId || (0, import_shared5.randomUUID)()
|
|
1093
1125
|
};
|
|
1094
1126
|
}
|
|
1095
1127
|
};
|
|
@@ -1097,8 +1129,8 @@ __name(UnifyAdapter, "UnifyAdapter");
|
|
|
1097
1129
|
|
|
1098
1130
|
// src/service-adapters/groq/groq-adapter.ts
|
|
1099
1131
|
var import_groq_sdk = require("groq-sdk");
|
|
1100
|
-
var
|
|
1101
|
-
var DEFAULT_MODEL2 = "
|
|
1132
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1133
|
+
var DEFAULT_MODEL2 = "llama-3.3-70b-versatile";
|
|
1102
1134
|
var GroqAdapter = class {
|
|
1103
1135
|
model = DEFAULT_MODEL2;
|
|
1104
1136
|
disableParallelToolCalls = false;
|
|
@@ -1116,7 +1148,9 @@ var GroqAdapter = class {
|
|
|
1116
1148
|
async process(request) {
|
|
1117
1149
|
const { threadId, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
1118
1150
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
1119
|
-
let openaiMessages = messages.map(convertMessageToOpenAIMessage
|
|
1151
|
+
let openaiMessages = messages.map((m) => convertMessageToOpenAIMessage(m, {
|
|
1152
|
+
keepSystemRole: true
|
|
1153
|
+
}));
|
|
1120
1154
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
1121
1155
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
1122
1156
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
@@ -1210,29 +1244,29 @@ var GroqAdapter = class {
|
|
|
1210
1244
|
eventStream$.complete();
|
|
1211
1245
|
});
|
|
1212
1246
|
return {
|
|
1213
|
-
threadId: request.threadId || (0,
|
|
1247
|
+
threadId: request.threadId || (0, import_shared6.randomUUID)()
|
|
1214
1248
|
};
|
|
1215
1249
|
}
|
|
1216
1250
|
};
|
|
1217
1251
|
__name(GroqAdapter, "GroqAdapter");
|
|
1218
1252
|
|
|
1219
1253
|
// src/service-adapters/empty/empty-adapter.ts
|
|
1220
|
-
var
|
|
1254
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1221
1255
|
var EmptyAdapter = class {
|
|
1222
1256
|
async process(request) {
|
|
1223
1257
|
return {
|
|
1224
|
-
threadId: request.threadId || (0,
|
|
1258
|
+
threadId: request.threadId || (0, import_shared7.randomUUID)()
|
|
1225
1259
|
};
|
|
1226
1260
|
}
|
|
1227
1261
|
};
|
|
1228
1262
|
__name(EmptyAdapter, "EmptyAdapter");
|
|
1229
1263
|
|
|
1230
1264
|
// src/service-adapters/events.ts
|
|
1231
|
-
var
|
|
1265
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
1232
1266
|
var import_rxjs2 = require("rxjs");
|
|
1233
1267
|
|
|
1234
1268
|
// src/lib/telemetry-client.ts
|
|
1235
|
-
var
|
|
1269
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
1236
1270
|
|
|
1237
1271
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1238
1272
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1272,7 +1306,7 @@ var CustomEventNames;
|
|
|
1272
1306
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1273
1307
|
|
|
1274
1308
|
// src/agents/langgraph/event-source.ts
|
|
1275
|
-
var
|
|
1309
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1276
1310
|
var RemoteLangGraphEventSource = class {
|
|
1277
1311
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1278
1312
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1323,10 +1357,16 @@ var RemoteLangGraphEventSource = class {
|
|
|
1323
1357
|
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1324
1358
|
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1325
1359
|
const responseMetadata = this.getResponseMetadata(event);
|
|
1360
|
+
const toolCallCheck = toolCallChunks && toolCallChunks.length > 0;
|
|
1361
|
+
let isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1326
1362
|
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1327
1363
|
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1328
|
-
|
|
1329
|
-
acc.
|
|
1364
|
+
let previousRoundHadToolCall = acc.isToolCall;
|
|
1365
|
+
acc.isToolCall = toolCallCheck;
|
|
1366
|
+
if (previousRoundHadToolCall && !toolCallCheck) {
|
|
1367
|
+
isToolCallEnd = true;
|
|
1368
|
+
}
|
|
1369
|
+
acc.isToolCallEnd = isToolCallEnd;
|
|
1330
1370
|
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1331
1371
|
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1332
1372
|
name: acc.lastToolCallName,
|
|
@@ -1346,7 +1386,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1346
1386
|
lastMessageId: null,
|
|
1347
1387
|
lastToolCallId: null,
|
|
1348
1388
|
lastToolCallName: null,
|
|
1349
|
-
currentContent: null
|
|
1389
|
+
currentContent: null,
|
|
1390
|
+
processedToolCallIds: /* @__PURE__ */ new Set()
|
|
1350
1391
|
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1351
1392
|
const events = [];
|
|
1352
1393
|
let shouldEmitMessages = true;
|
|
@@ -1374,13 +1415,13 @@ var RemoteLangGraphEventSource = class {
|
|
|
1374
1415
|
});
|
|
1375
1416
|
}
|
|
1376
1417
|
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1377
|
-
if (
|
|
1418
|
+
if (acc.isToolCallEnd && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName) && acc.lastToolCallId && !acc.processedToolCallIds.has(acc.lastToolCallId)) {
|
|
1419
|
+
acc.processedToolCallIds.add(acc.lastToolCallId);
|
|
1378
1420
|
events.push({
|
|
1379
1421
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1380
1422
|
actionExecutionId: acc.lastToolCallId
|
|
1381
1423
|
});
|
|
1382
|
-
}
|
|
1383
|
-
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1424
|
+
} else if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1384
1425
|
events.push({
|
|
1385
1426
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
1386
1427
|
messageId: acc.lastMessageId
|
|
@@ -1442,6 +1483,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1442
1483
|
parentMessageId: acc.lastMessageId
|
|
1443
1484
|
});
|
|
1444
1485
|
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1486
|
+
acc.processedToolCallIds.clear();
|
|
1445
1487
|
events.push({
|
|
1446
1488
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1447
1489
|
messageId: acc.lastMessageId
|
|
@@ -1478,7 +1520,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1478
1520
|
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1479
1521
|
});
|
|
1480
1522
|
}
|
|
1481
|
-
const messageId = (0,
|
|
1523
|
+
const messageId = (0, import_shared8.randomId)();
|
|
1482
1524
|
events.push({
|
|
1483
1525
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1484
1526
|
messageId
|
|
@@ -1501,7 +1543,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1501
1543
|
// src/lib/runtime/remote-lg-action.ts
|
|
1502
1544
|
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1503
1545
|
var import_node_crypto = require("crypto");
|
|
1504
|
-
var
|
|
1546
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1505
1547
|
var import_partial_json = require("partial-json");
|
|
1506
1548
|
|
|
1507
1549
|
// src/graphql/types/enums.ts
|
|
@@ -1512,6 +1554,7 @@ var MessageRole;
|
|
|
1512
1554
|
MessageRole2["assistant"] = "assistant";
|
|
1513
1555
|
MessageRole2["system"] = "system";
|
|
1514
1556
|
MessageRole2["tool"] = "tool";
|
|
1557
|
+
MessageRole2["developer"] = "developer";
|
|
1515
1558
|
})(MessageRole || (MessageRole = {}));
|
|
1516
1559
|
var CopilotRequestType;
|
|
1517
1560
|
(function(CopilotRequestType2) {
|
|
@@ -2130,6 +2173,7 @@ CopilotKitLangGraphInterruptEvent = _ts_decorate5([
|
|
|
2130
2173
|
], CopilotKitLangGraphInterruptEvent);
|
|
2131
2174
|
|
|
2132
2175
|
// src/lib/runtime/remote-lg-action.ts
|
|
2176
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
2133
2177
|
var activeInterruptEvent = false;
|
|
2134
2178
|
async function execute(args) {
|
|
2135
2179
|
return new ReadableStream({
|
|
@@ -2159,11 +2203,11 @@ async function streamEvents(controller, args) {
|
|
|
2159
2203
|
...propertyHeaders
|
|
2160
2204
|
}
|
|
2161
2205
|
});
|
|
2162
|
-
let threadId = argsInitialThreadId ?? (0,
|
|
2206
|
+
let threadId = argsInitialThreadId ?? (0, import_shared9.randomUUID)();
|
|
2163
2207
|
if (argsInitialThreadId && argsInitialThreadId.startsWith("ck-")) {
|
|
2164
2208
|
threadId = argsInitialThreadId.substring(3);
|
|
2165
2209
|
}
|
|
2166
|
-
if (!(0,
|
|
2210
|
+
if (!(0, import_shared9.isValidUUID)(threadId)) {
|
|
2167
2211
|
console.warn(`Cannot use the threadId ${threadId} with LangGraph Platform. Must be a valid UUID.`);
|
|
2168
2212
|
}
|
|
2169
2213
|
let wasInitiatedWithExistingThread = true;
|
|
@@ -2209,15 +2253,9 @@ async function streamEvents(controller, args) {
|
|
|
2209
2253
|
}
|
|
2210
2254
|
if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
|
|
2211
2255
|
let response = lgInterruptMetaEvent.response;
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
};
|
|
2216
|
-
} catch (e) {
|
|
2217
|
-
payload.command = {
|
|
2218
|
-
resume: response
|
|
2219
|
-
};
|
|
2220
|
-
}
|
|
2256
|
+
payload.command = {
|
|
2257
|
+
resume: (0, import_shared10.parseJson)(response, response)
|
|
2258
|
+
};
|
|
2221
2259
|
}
|
|
2222
2260
|
if (mode === "continue" && !activeInterruptEvent) {
|
|
2223
2261
|
await client.threads.updateState(threadId, {
|
|
@@ -2253,6 +2291,11 @@ async function streamEvents(controller, args) {
|
|
|
2253
2291
|
});
|
|
2254
2292
|
}
|
|
2255
2293
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
2294
|
+
const graphSchema = await client.assistants.getSchemas(assistantId);
|
|
2295
|
+
const schemaKeys = getSchemaKeys(graphSchema);
|
|
2296
|
+
if (payload.input && schemaKeys.input) {
|
|
2297
|
+
payload.input = Object.fromEntries(Object.entries(payload.input).filter(([key]) => schemaKeys.input.includes(key)));
|
|
2298
|
+
}
|
|
2256
2299
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
2257
2300
|
let prevNodeName = null;
|
|
2258
2301
|
let emitIntermediateStateUntilEnd = null;
|
|
@@ -2344,7 +2387,8 @@ async function streamEvents(controller, args) {
|
|
|
2344
2387
|
nodeName,
|
|
2345
2388
|
state: manuallyEmittedState,
|
|
2346
2389
|
running: true,
|
|
2347
|
-
active: true
|
|
2390
|
+
active: true,
|
|
2391
|
+
schemaKeys
|
|
2348
2392
|
}));
|
|
2349
2393
|
continue;
|
|
2350
2394
|
}
|
|
@@ -2376,7 +2420,8 @@ async function streamEvents(controller, args) {
|
|
|
2376
2420
|
nodeName,
|
|
2377
2421
|
state,
|
|
2378
2422
|
running: true,
|
|
2379
|
-
active: !exitingNode
|
|
2423
|
+
active: !exitingNode,
|
|
2424
|
+
schemaKeys
|
|
2380
2425
|
}));
|
|
2381
2426
|
}
|
|
2382
2427
|
emit(JSON.stringify(event) + "\n");
|
|
@@ -2394,7 +2439,8 @@ async function streamEvents(controller, args) {
|
|
|
2394
2439
|
state: state.values,
|
|
2395
2440
|
running: !shouldExit,
|
|
2396
2441
|
active: false,
|
|
2397
|
-
includeMessages: true
|
|
2442
|
+
includeMessages: true,
|
|
2443
|
+
schemaKeys
|
|
2398
2444
|
}));
|
|
2399
2445
|
return Promise.resolve();
|
|
2400
2446
|
} catch (e) {
|
|
@@ -2407,7 +2453,7 @@ async function streamEvents(controller, args) {
|
|
|
2407
2453
|
}
|
|
2408
2454
|
}
|
|
2409
2455
|
__name(streamEvents, "streamEvents");
|
|
2410
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
2456
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false, schemaKeys }) {
|
|
2411
2457
|
if (!includeMessages) {
|
|
2412
2458
|
state = Object.keys(state).reduce((acc, key) => {
|
|
2413
2459
|
if (key !== "messages") {
|
|
@@ -2421,6 +2467,9 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
2421
2467
|
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
2422
2468
|
};
|
|
2423
2469
|
}
|
|
2470
|
+
if (schemaKeys.output) {
|
|
2471
|
+
state = Object.fromEntries(Object.entries(state).filter(([key]) => schemaKeys.output.includes(key)));
|
|
2472
|
+
}
|
|
2424
2473
|
return JSON.stringify({
|
|
2425
2474
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
2426
2475
|
thread_id: threadId,
|
|
@@ -2655,10 +2704,30 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
2655
2704
|
return result;
|
|
2656
2705
|
}
|
|
2657
2706
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2707
|
+
function getSchemaKeys(graphSchema) {
|
|
2708
|
+
const CONSTANT_KEYS = [
|
|
2709
|
+
"messages",
|
|
2710
|
+
"copilotkit"
|
|
2711
|
+
];
|
|
2712
|
+
const inputSchema = Object.keys(graphSchema.input_schema.properties);
|
|
2713
|
+
const outputSchema = Object.keys(graphSchema.output_schema.properties);
|
|
2714
|
+
return {
|
|
2715
|
+
input: inputSchema && inputSchema.length ? [
|
|
2716
|
+
...inputSchema,
|
|
2717
|
+
...CONSTANT_KEYS
|
|
2718
|
+
] : null,
|
|
2719
|
+
output: outputSchema && outputSchema.length ? [
|
|
2720
|
+
...outputSchema,
|
|
2721
|
+
...CONSTANT_KEYS
|
|
2722
|
+
] : null
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
__name(getSchemaKeys, "getSchemaKeys");
|
|
2658
2726
|
|
|
2659
2727
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2660
|
-
var
|
|
2661
|
-
var
|
|
2728
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
2729
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2730
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2662
2731
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2663
2732
|
const agents = endpoint.agents.map((agent) => ({
|
|
2664
2733
|
name: agent.name,
|
|
@@ -2681,8 +2750,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2681
2750
|
if (agentStates) {
|
|
2682
2751
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
2683
2752
|
if (jsonState) {
|
|
2684
|
-
state =
|
|
2685
|
-
configurable =
|
|
2753
|
+
state = (0, import_shared13.parseJson)(jsonState.state, {});
|
|
2754
|
+
configurable = (0, import_shared13.parseJson)(jsonState.configurable, {});
|
|
2686
2755
|
}
|
|
2687
2756
|
}
|
|
2688
2757
|
try {
|
|
@@ -2702,7 +2771,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2702
2771
|
state,
|
|
2703
2772
|
configurable,
|
|
2704
2773
|
properties: graphqlContext.properties,
|
|
2705
|
-
actions:
|
|
2774
|
+
actions: (0, import_shared13.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
2706
2775
|
name: action.name,
|
|
2707
2776
|
description: action.description,
|
|
2708
2777
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -2762,11 +2831,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2762
2831
|
body: await response.text()
|
|
2763
2832
|
}, "Failed to execute remote action");
|
|
2764
2833
|
if (response.status === 404) {
|
|
2765
|
-
throw new
|
|
2834
|
+
throw new import_shared12.CopilotKitApiDiscoveryError({
|
|
2766
2835
|
url: fetchUrl
|
|
2767
2836
|
});
|
|
2768
2837
|
}
|
|
2769
|
-
throw new
|
|
2838
|
+
throw new import_shared12.ResolvedCopilotKitError({
|
|
2770
2839
|
status: response.status,
|
|
2771
2840
|
url: fetchUrl,
|
|
2772
2841
|
isRemoteEndpoint: true
|
|
@@ -2780,10 +2849,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2780
2849
|
}, "Executed remote action");
|
|
2781
2850
|
return result;
|
|
2782
2851
|
} catch (error) {
|
|
2783
|
-
if (error instanceof
|
|
2852
|
+
if (error instanceof import_shared11.CopilotKitError) {
|
|
2784
2853
|
throw error;
|
|
2785
2854
|
}
|
|
2786
|
-
throw new
|
|
2855
|
+
throw new import_shared11.CopilotKitLowLevelError({
|
|
2787
2856
|
error,
|
|
2788
2857
|
url: fetchUrl
|
|
2789
2858
|
});
|
|
@@ -2811,8 +2880,8 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2811
2880
|
if (agentStates) {
|
|
2812
2881
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
2813
2882
|
if (jsonState) {
|
|
2814
|
-
state =
|
|
2815
|
-
configurable =
|
|
2883
|
+
state = (0, import_shared13.parseJson)(jsonState.state, {});
|
|
2884
|
+
configurable = (0, import_shared13.parseJson)(jsonState.configurable, {});
|
|
2816
2885
|
}
|
|
2817
2886
|
}
|
|
2818
2887
|
const fetchUrl = `${url}/agents/execute`;
|
|
@@ -2831,7 +2900,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2831
2900
|
state,
|
|
2832
2901
|
configurable,
|
|
2833
2902
|
properties: graphqlContext.properties,
|
|
2834
|
-
actions:
|
|
2903
|
+
actions: (0, import_shared13.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
2835
2904
|
name: action.name,
|
|
2836
2905
|
description: action.description,
|
|
2837
2906
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -2846,11 +2915,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2846
2915
|
body: await response.text()
|
|
2847
2916
|
}, "Failed to execute remote agent");
|
|
2848
2917
|
if (response.status === 404) {
|
|
2849
|
-
throw new
|
|
2918
|
+
throw new import_shared12.CopilotKitApiDiscoveryError({
|
|
2850
2919
|
url: fetchUrl
|
|
2851
2920
|
});
|
|
2852
2921
|
}
|
|
2853
|
-
throw new
|
|
2922
|
+
throw new import_shared12.ResolvedCopilotKitError({
|
|
2854
2923
|
status: response.status,
|
|
2855
2924
|
url: fetchUrl,
|
|
2856
2925
|
isRemoteEndpoint: true
|
|
@@ -2860,10 +2929,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2860
2929
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2861
2930
|
return eventSource.processLangGraphEvents();
|
|
2862
2931
|
} catch (error) {
|
|
2863
|
-
if (error instanceof
|
|
2932
|
+
if (error instanceof import_shared11.CopilotKitError) {
|
|
2864
2933
|
throw error;
|
|
2865
2934
|
}
|
|
2866
|
-
throw new
|
|
2935
|
+
throw new import_shared11.CopilotKitLowLevelError({
|
|
2867
2936
|
error,
|
|
2868
2937
|
url: fetchUrl
|
|
2869
2938
|
});
|
|
@@ -2937,7 +3006,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
2937
3006
|
__name(createHeaders, "createHeaders");
|
|
2938
3007
|
|
|
2939
3008
|
// src/lib/runtime/remote-actions.ts
|
|
2940
|
-
var
|
|
3009
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2941
3010
|
var EndpointType;
|
|
2942
3011
|
(function(EndpointType2) {
|
|
2943
3012
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -2971,7 +3040,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2971
3040
|
status: response.status,
|
|
2972
3041
|
body: await response.text()
|
|
2973
3042
|
}, "Failed to fetch actions from url");
|
|
2974
|
-
throw new
|
|
3043
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
2975
3044
|
status: response.status,
|
|
2976
3045
|
url: fetchUrl,
|
|
2977
3046
|
isRemoteEndpoint: true
|
|
@@ -2983,10 +3052,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2983
3052
|
}, "Fetched actions from url");
|
|
2984
3053
|
return json;
|
|
2985
3054
|
} catch (error) {
|
|
2986
|
-
if (error instanceof
|
|
3055
|
+
if (error instanceof import_shared14.CopilotKitError) {
|
|
2987
3056
|
throw error;
|
|
2988
3057
|
}
|
|
2989
|
-
throw new
|
|
3058
|
+
throw new import_shared14.CopilotKitLowLevelError({
|
|
2990
3059
|
error,
|
|
2991
3060
|
url: fetchUrl
|
|
2992
3061
|
});
|
|
@@ -3049,7 +3118,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3049
3118
|
// src/lib/telemetry-client.ts
|
|
3050
3119
|
var import_node_crypto3 = require("crypto");
|
|
3051
3120
|
var packageJson = require_package();
|
|
3052
|
-
var telemetryClient = new
|
|
3121
|
+
var telemetryClient = new import_shared15.TelemetryClient({
|
|
3053
3122
|
packageName: packageJson.name,
|
|
3054
3123
|
packageVersion: packageJson.version
|
|
3055
3124
|
});
|
|
@@ -3366,10 +3435,10 @@ var RuntimeEventSource = class {
|
|
|
3366
3435
|
const errorMessage = `\u274C ${message}`;
|
|
3367
3436
|
if (!this.callback) {
|
|
3368
3437
|
this.stream(async (eventStream$) => {
|
|
3369
|
-
eventStream$.sendTextMessage((0,
|
|
3438
|
+
eventStream$.sendTextMessage((0, import_shared16.randomId)(), errorMessage);
|
|
3370
3439
|
});
|
|
3371
3440
|
} else {
|
|
3372
|
-
this.eventStream$.sendTextMessage((0,
|
|
3441
|
+
this.eventStream$.sendTextMessage((0, import_shared16.randomId)(), errorMessage);
|
|
3373
3442
|
}
|
|
3374
3443
|
}
|
|
3375
3444
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -3528,35 +3597,35 @@ __name(executeAction, "executeAction");
|
|
|
3528
3597
|
|
|
3529
3598
|
// src/service-adapters/conversion.ts
|
|
3530
3599
|
var import_class_transformer2 = require("class-transformer");
|
|
3600
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
3531
3601
|
function convertGqlInputToMessages(inputMessages) {
|
|
3532
|
-
const messages =
|
|
3533
|
-
for (const message of inputMessages) {
|
|
3602
|
+
const messages = (0, import_shared17.tryMap)(inputMessages, (message) => {
|
|
3534
3603
|
if (message.textMessage) {
|
|
3535
|
-
|
|
3604
|
+
return (0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
3536
3605
|
id: message.id,
|
|
3537
3606
|
createdAt: message.createdAt,
|
|
3538
3607
|
role: message.textMessage.role,
|
|
3539
3608
|
content: message.textMessage.content,
|
|
3540
3609
|
parentMessageId: message.textMessage.parentMessageId
|
|
3541
|
-
})
|
|
3610
|
+
});
|
|
3542
3611
|
} else if (message.actionExecutionMessage) {
|
|
3543
|
-
|
|
3612
|
+
return (0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
3544
3613
|
id: message.id,
|
|
3545
3614
|
createdAt: message.createdAt,
|
|
3546
3615
|
name: message.actionExecutionMessage.name,
|
|
3547
3616
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
3548
3617
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3549
|
-
})
|
|
3618
|
+
});
|
|
3550
3619
|
} else if (message.resultMessage) {
|
|
3551
|
-
|
|
3620
|
+
return (0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
3552
3621
|
id: message.id,
|
|
3553
3622
|
createdAt: message.createdAt,
|
|
3554
3623
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
3555
3624
|
actionName: message.resultMessage.actionName,
|
|
3556
3625
|
result: message.resultMessage.result
|
|
3557
|
-
})
|
|
3626
|
+
});
|
|
3558
3627
|
} else if (message.agentStateMessage) {
|
|
3559
|
-
|
|
3628
|
+
return (0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
3560
3629
|
id: message.id,
|
|
3561
3630
|
threadId: message.agentStateMessage.threadId,
|
|
3562
3631
|
createdAt: message.createdAt,
|
|
@@ -3567,10 +3636,12 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3567
3636
|
role: message.agentStateMessage.role,
|
|
3568
3637
|
state: JSON.parse(message.agentStateMessage.state),
|
|
3569
3638
|
running: message.agentStateMessage.running
|
|
3570
|
-
})
|
|
3639
|
+
});
|
|
3640
|
+
} else {
|
|
3641
|
+
return null;
|
|
3571
3642
|
}
|
|
3572
|
-
}
|
|
3573
|
-
return messages;
|
|
3643
|
+
});
|
|
3644
|
+
return messages.filter((m) => m);
|
|
3574
3645
|
}
|
|
3575
3646
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
3576
3647
|
|
|
@@ -3586,7 +3657,12 @@ var CopilotRuntime = class {
|
|
|
3586
3657
|
delegateAgentProcessingToServiceAdapter;
|
|
3587
3658
|
constructor(params) {
|
|
3588
3659
|
var _a, _b;
|
|
3589
|
-
|
|
3660
|
+
if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints)) {
|
|
3661
|
+
console.warn("Actions set in runtime instance will be ignored when remote endpoints are set");
|
|
3662
|
+
this.actions = [];
|
|
3663
|
+
} else {
|
|
3664
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
3665
|
+
}
|
|
3590
3666
|
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
3591
3667
|
const remoteChain = new RemoteChain(chain);
|
|
3592
3668
|
this.langserve.push(remoteChain.toAction());
|
|
@@ -3605,7 +3681,7 @@ var CopilotRuntime = class {
|
|
|
3605
3681
|
return await this.processAgentRequest(request);
|
|
3606
3682
|
}
|
|
3607
3683
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3608
|
-
throw new
|
|
3684
|
+
throw new import_shared18.CopilotKitMisuseError({
|
|
3609
3685
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3610
3686
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3611
3687
|
please use an LLM adapter instead.`
|
|
@@ -3617,7 +3693,7 @@ please use an LLM adapter instead.`
|
|
|
3617
3693
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3618
3694
|
name: action.name,
|
|
3619
3695
|
description: action.description,
|
|
3620
|
-
jsonSchema: JSON.stringify((0,
|
|
3696
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3621
3697
|
}));
|
|
3622
3698
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3623
3699
|
...serverSideActionsInput,
|
|
@@ -3669,7 +3745,7 @@ please use an LLM adapter instead.`
|
|
|
3669
3745
|
extensions: result.extensions
|
|
3670
3746
|
};
|
|
3671
3747
|
} catch (error) {
|
|
3672
|
-
if (error instanceof
|
|
3748
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3673
3749
|
throw error;
|
|
3674
3750
|
}
|
|
3675
3751
|
console.error("Error getting response:", error);
|
|
@@ -3715,11 +3791,11 @@ please use an LLM adapter instead.`
|
|
|
3715
3791
|
});
|
|
3716
3792
|
if (!response.ok) {
|
|
3717
3793
|
if (response.status === 404) {
|
|
3718
|
-
throw new
|
|
3794
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3719
3795
|
url: fetchUrl
|
|
3720
3796
|
});
|
|
3721
3797
|
}
|
|
3722
|
-
throw new
|
|
3798
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3723
3799
|
status: response.status,
|
|
3724
3800
|
url: fetchUrl,
|
|
3725
3801
|
isRemoteEndpoint: true
|
|
@@ -3729,7 +3805,7 @@ please use an LLM adapter instead.`
|
|
|
3729
3805
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
3730
3806
|
name: agent.name,
|
|
3731
3807
|
description: agent.description ?? "" ?? "",
|
|
3732
|
-
id: (0,
|
|
3808
|
+
id: (0, import_shared18.randomId)(),
|
|
3733
3809
|
endpoint
|
|
3734
3810
|
}));
|
|
3735
3811
|
return [
|
|
@@ -3737,10 +3813,10 @@ please use an LLM adapter instead.`
|
|
|
3737
3813
|
...endpointAgents
|
|
3738
3814
|
];
|
|
3739
3815
|
} catch (error) {
|
|
3740
|
-
if (error instanceof
|
|
3816
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3741
3817
|
throw error;
|
|
3742
3818
|
}
|
|
3743
|
-
throw new
|
|
3819
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3744
3820
|
error,
|
|
3745
3821
|
url: fetchUrl
|
|
3746
3822
|
});
|
|
@@ -3802,11 +3878,11 @@ please use an LLM adapter instead.`
|
|
|
3802
3878
|
});
|
|
3803
3879
|
if (!response.ok) {
|
|
3804
3880
|
if (response.status === 404) {
|
|
3805
|
-
throw new
|
|
3881
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3806
3882
|
url: fetchUrl
|
|
3807
3883
|
});
|
|
3808
3884
|
}
|
|
3809
|
-
throw new
|
|
3885
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3810
3886
|
status: response.status,
|
|
3811
3887
|
url: fetchUrl,
|
|
3812
3888
|
isRemoteEndpoint: true
|
|
@@ -3819,10 +3895,10 @@ please use an LLM adapter instead.`
|
|
|
3819
3895
|
messages: JSON.stringify(data.messages)
|
|
3820
3896
|
};
|
|
3821
3897
|
} catch (error) {
|
|
3822
|
-
if (error instanceof
|
|
3898
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3823
3899
|
throw error;
|
|
3824
3900
|
}
|
|
3825
|
-
throw new
|
|
3901
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3826
3902
|
error,
|
|
3827
3903
|
url: fetchUrl
|
|
3828
3904
|
});
|
|
@@ -3840,7 +3916,7 @@ please use an LLM adapter instead.`
|
|
|
3840
3916
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
3841
3917
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
3842
3918
|
if (!currentAgent) {
|
|
3843
|
-
throw new
|
|
3919
|
+
throw new import_shared18.CopilotKitAgentDiscoveryError({
|
|
3844
3920
|
agentName
|
|
3845
3921
|
});
|
|
3846
3922
|
}
|
|
@@ -3851,7 +3927,7 @@ please use an LLM adapter instead.`
|
|
|
3851
3927
|
)).map((action) => ({
|
|
3852
3928
|
name: action.name,
|
|
3853
3929
|
description: action.description,
|
|
3854
|
-
jsonSchema: JSON.stringify((0,
|
|
3930
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3855
3931
|
}));
|
|
3856
3932
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
3857
3933
|
...availableActionsForCurrentAgent,
|
|
@@ -3898,7 +3974,7 @@ please use an LLM adapter instead.`
|
|
|
3898
3974
|
threadId,
|
|
3899
3975
|
runId: void 0,
|
|
3900
3976
|
eventSource,
|
|
3901
|
-
serverSideActions
|
|
3977
|
+
serverSideActions,
|
|
3902
3978
|
actionInputsWithoutAgents: allAvailableActions
|
|
3903
3979
|
};
|
|
3904
3980
|
} catch (error) {
|
|
@@ -4776,7 +4852,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
4776
4852
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
4777
4853
|
|
|
4778
4854
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4779
|
-
var
|
|
4855
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
4780
4856
|
|
|
4781
4857
|
// src/graphql/types/agents-response.type.ts
|
|
4782
4858
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -4959,7 +5035,7 @@ var CopilotResolver = class {
|
|
|
4959
5035
|
rejectOutputMessagesPromise = reject;
|
|
4960
5036
|
});
|
|
4961
5037
|
logger2.debug("Processing");
|
|
4962
|
-
const { eventSource, threadId = (0,
|
|
5038
|
+
const { eventSource, threadId = (0, import_shared19.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
4963
5039
|
serviceAdapter,
|
|
4964
5040
|
messages: data.messages,
|
|
4965
5041
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5092,7 +5168,7 @@ var CopilotResolver = class {
|
|
|
5092
5168
|
});
|
|
5093
5169
|
outputMessages = [
|
|
5094
5170
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5095
|
-
id: (0,
|
|
5171
|
+
id: (0, import_shared19.randomId)(),
|
|
5096
5172
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5097
5173
|
content: result.reason,
|
|
5098
5174
|
role: MessageRole.assistant
|
|
@@ -5270,7 +5346,7 @@ var CopilotResolver = class {
|
|
|
5270
5346
|
event
|
|
5271
5347
|
}, "Agent message event received");
|
|
5272
5348
|
pushMessage({
|
|
5273
|
-
id: (0,
|
|
5349
|
+
id: (0, import_shared19.randomId)(),
|
|
5274
5350
|
status: new SuccessMessageStatus(),
|
|
5275
5351
|
threadId: event.threadId,
|
|
5276
5352
|
agentName: event.agentName,
|
|
@@ -5283,7 +5359,7 @@ var CopilotResolver = class {
|
|
|
5283
5359
|
createdAt: /* @__PURE__ */ new Date()
|
|
5284
5360
|
});
|
|
5285
5361
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5286
|
-
id: (0,
|
|
5362
|
+
id: (0, import_shared19.randomId)(),
|
|
5287
5363
|
threadId: event.threadId,
|
|
5288
5364
|
agentName: event.agentName,
|
|
5289
5365
|
nodeName: event.nodeName,
|