@copilotkit/runtime 1.6.0-next.1 → 1.6.0-next.11
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 +75 -0
- package/__snapshots__/schema/schema.graphql +1 -0
- package/dist/{chunk-CCQ73DAH.mjs → chunk-6L2NPMPT.mjs} +2 -2
- package/dist/{chunk-CHDIEE43.mjs → chunk-DVFBTXBT.mjs} +87 -44
- package/dist/chunk-DVFBTXBT.mjs.map +1 -0
- package/dist/{chunk-OS5YD32G.mjs → chunk-FZJAYGIR.mjs} +45 -12
- package/dist/chunk-FZJAYGIR.mjs.map +1 -0
- package/dist/{chunk-C7GTLEVO.mjs → chunk-LGQL6LK4.mjs} +2 -2
- package/dist/{chunk-A25FIW7J.mjs → chunk-O3Q4BRZA.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-6L2NPMPT.mjs.map} +0 -0
- /package/dist/{chunk-C7GTLEVO.mjs.map → chunk-LGQL6LK4.mjs.map} +0 -0
- /package/dist/{chunk-A25FIW7J.mjs.map → chunk-O3Q4BRZA.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.11",
|
|
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",
|
|
@@ -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 = [];
|
|
@@ -251,7 +253,10 @@ function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
|
251
253
|
}
|
|
252
254
|
maxTokens -= toolsNumTokens;
|
|
253
255
|
for (const message of messages) {
|
|
254
|
-
if (
|
|
256
|
+
if ([
|
|
257
|
+
"system",
|
|
258
|
+
"developer"
|
|
259
|
+
].includes(message.role)) {
|
|
255
260
|
const numTokens = countMessageTokens(model, message);
|
|
256
261
|
maxTokens -= numTokens;
|
|
257
262
|
if (maxTokens < 0) {
|
|
@@ -264,7 +269,10 @@ function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
|
264
269
|
...messages
|
|
265
270
|
].reverse();
|
|
266
271
|
for (const message of reversedMessages) {
|
|
267
|
-
if (
|
|
272
|
+
if ([
|
|
273
|
+
"system",
|
|
274
|
+
"developer"
|
|
275
|
+
].includes(message.role)) {
|
|
268
276
|
result.unshift(message);
|
|
269
277
|
continue;
|
|
270
278
|
} else if (cutoff) {
|
|
@@ -287,9 +295,23 @@ function maxTokensForOpenAIModel(model) {
|
|
|
287
295
|
__name(maxTokensForOpenAIModel, "maxTokensForOpenAIModel");
|
|
288
296
|
var DEFAULT_MAX_TOKENS = 128e3;
|
|
289
297
|
var maxTokensByModel = {
|
|
298
|
+
// o1
|
|
299
|
+
o1: 2e5,
|
|
300
|
+
"o1-2024-12-17": 2e5,
|
|
301
|
+
"o1-mini": 128e3,
|
|
302
|
+
"o1-mini-2024-09-12": 128e3,
|
|
303
|
+
"o1-preview": 128e3,
|
|
304
|
+
"o1-preview-2024-09-12": 128e3,
|
|
305
|
+
// o3-mini
|
|
306
|
+
"o3-mini": 2e5,
|
|
307
|
+
"o3-mini-2025-01-31": 2e5,
|
|
290
308
|
// GPT-4
|
|
291
309
|
"gpt-4o": 128e3,
|
|
310
|
+
"chatgpt-4o-latest": 128e3,
|
|
311
|
+
"gpt-4o-2024-08-06": 128e3,
|
|
292
312
|
"gpt-4o-2024-05-13": 128e3,
|
|
313
|
+
"gpt-4o-mini": 128e3,
|
|
314
|
+
"gpt-4o-mini-2024-07-18": 128e3,
|
|
293
315
|
"gpt-4-turbo": 128e3,
|
|
294
316
|
"gpt-4-turbo-2024-04-09": 128e3,
|
|
295
317
|
"gpt-4-0125-preview": 128e3,
|
|
@@ -335,15 +357,22 @@ function convertActionInputToOpenAITool(action) {
|
|
|
335
357
|
function: {
|
|
336
358
|
name: action.name,
|
|
337
359
|
description: action.description,
|
|
338
|
-
parameters:
|
|
360
|
+
parameters: (0, import_shared.parseJson)(action.jsonSchema, {})
|
|
339
361
|
}
|
|
340
362
|
};
|
|
341
363
|
}
|
|
342
364
|
__name(convertActionInputToOpenAITool, "convertActionInputToOpenAITool");
|
|
343
|
-
function convertMessageToOpenAIMessage(message) {
|
|
365
|
+
function convertMessageToOpenAIMessage(message, options) {
|
|
366
|
+
const { keepSystemRole } = options || {
|
|
367
|
+
keepSystemRole: false
|
|
368
|
+
};
|
|
344
369
|
if (message.isTextMessage()) {
|
|
370
|
+
let role = message.role;
|
|
371
|
+
if (message.role === "system" && !keepSystemRole) {
|
|
372
|
+
role = "developer";
|
|
373
|
+
}
|
|
345
374
|
return {
|
|
346
|
-
role
|
|
375
|
+
role,
|
|
347
376
|
content: message.content
|
|
348
377
|
};
|
|
349
378
|
} else if (message.isActionExecutionMessage()) {
|
|
@@ -372,7 +401,10 @@ __name(convertMessageToOpenAIMessage, "convertMessageToOpenAIMessage");
|
|
|
372
401
|
function convertSystemMessageToAssistantAPI(message) {
|
|
373
402
|
return {
|
|
374
403
|
...message,
|
|
375
|
-
...
|
|
404
|
+
...[
|
|
405
|
+
"system",
|
|
406
|
+
"developer"
|
|
407
|
+
].includes(message.role) && {
|
|
376
408
|
role: "assistant",
|
|
377
409
|
content: "THE FOLLOWING MESSAGE IS A SYSTEM MESSAGE: " + message.content
|
|
378
410
|
}
|
|
@@ -381,7 +413,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
381
413
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
382
414
|
|
|
383
415
|
// src/service-adapters/openai/openai-adapter.ts
|
|
384
|
-
var
|
|
416
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
385
417
|
var DEFAULT_MODEL = "gpt-4o";
|
|
386
418
|
var OpenAIAdapter = class {
|
|
387
419
|
model = DEFAULT_MODEL;
|
|
@@ -400,8 +432,8 @@ var OpenAIAdapter = class {
|
|
|
400
432
|
async process(request) {
|
|
401
433
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
402
434
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
403
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
404
|
-
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
435
|
+
const threadId = threadIdFromRequest ?? (0, import_shared2.randomUUID)();
|
|
436
|
+
let openaiMessages = messages.map((m) => convertMessageToOpenAIMessage(m));
|
|
405
437
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
406
438
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
407
439
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
@@ -507,7 +539,7 @@ __name(OpenAIAdapter, "OpenAIAdapter");
|
|
|
507
539
|
// src/service-adapters/langchain/utils.ts
|
|
508
540
|
var import_messages = require("@langchain/core/messages");
|
|
509
541
|
var import_tools = require("@langchain/core/tools");
|
|
510
|
-
var
|
|
542
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
511
543
|
function convertMessageToLangChainMessage(message) {
|
|
512
544
|
if (message.isTextMessage()) {
|
|
513
545
|
if (message.role == "user") {
|
|
@@ -540,7 +572,7 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
540
572
|
return new import_tools.DynamicStructuredTool({
|
|
541
573
|
name: actionInput.name,
|
|
542
574
|
description: actionInput.description,
|
|
543
|
-
schema: (0,
|
|
575
|
+
schema: (0, import_shared3.convertJsonSchemaToZodSchema)(JSON.parse(actionInput.jsonSchema), true),
|
|
544
576
|
func: async () => {
|
|
545
577
|
return "";
|
|
546
578
|
}
|
|
@@ -573,7 +605,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
573
605
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
574
606
|
if (typeof result === "string") {
|
|
575
607
|
if (!actionExecution) {
|
|
576
|
-
eventStream$.sendTextMessage((0,
|
|
608
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result);
|
|
577
609
|
} else {
|
|
578
610
|
eventStream$.sendActionExecutionResult({
|
|
579
611
|
actionExecutionId: actionExecution.id,
|
|
@@ -584,11 +616,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
584
616
|
} else if (isAIMessage(result)) {
|
|
585
617
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
586
618
|
if (result.content) {
|
|
587
|
-
eventStream$.sendTextMessage((0,
|
|
619
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
588
620
|
}
|
|
589
621
|
for (const toolCall of result.tool_calls) {
|
|
590
622
|
eventStream$.sendActionExecution({
|
|
591
|
-
actionExecutionId: toolCall.id || (0,
|
|
623
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
592
624
|
actionName: toolCall.name,
|
|
593
625
|
args: JSON.stringify(toolCall.args)
|
|
594
626
|
});
|
|
@@ -596,12 +628,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
596
628
|
} else if (isBaseMessageChunk(result)) {
|
|
597
629
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
598
630
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
599
|
-
eventStream$.sendTextMessage((0,
|
|
631
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
600
632
|
}
|
|
601
633
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
602
634
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
603
635
|
eventStream$.sendActionExecution({
|
|
604
|
-
actionExecutionId: toolCall.id || (0,
|
|
636
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
605
637
|
actionName: toolCall.name,
|
|
606
638
|
args: JSON.stringify(toolCall.args)
|
|
607
639
|
});
|
|
@@ -675,7 +707,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
675
707
|
});
|
|
676
708
|
} else if (content) {
|
|
677
709
|
mode = "message";
|
|
678
|
-
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0,
|
|
710
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared3.randomId)();
|
|
679
711
|
eventStream$.sendTextMessageStart({
|
|
680
712
|
messageId: currentMessageId
|
|
681
713
|
});
|
|
@@ -732,7 +764,7 @@ function encodeResult(result) {
|
|
|
732
764
|
__name(encodeResult, "encodeResult");
|
|
733
765
|
|
|
734
766
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
735
|
-
var
|
|
767
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
736
768
|
var import_promises = require("@langchain/core/callbacks/promises");
|
|
737
769
|
var LangChainAdapter = class {
|
|
738
770
|
options;
|
|
@@ -745,7 +777,7 @@ var LangChainAdapter = class {
|
|
|
745
777
|
async process(request) {
|
|
746
778
|
try {
|
|
747
779
|
const { eventSource, model, actions, messages, runId, threadId: threadIdFromRequest } = request;
|
|
748
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
780
|
+
const threadId = threadIdFromRequest ?? (0, import_shared4.randomUUID)();
|
|
749
781
|
const result = await this.options.chainFn({
|
|
750
782
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
751
783
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -864,7 +896,7 @@ var OpenAIAssistantAdapter = class {
|
|
|
864
896
|
];
|
|
865
897
|
const instructionsMessage = messages.shift();
|
|
866
898
|
const instructions = instructionsMessage.isTextMessage() ? instructionsMessage.content : "";
|
|
867
|
-
const userMessage = messages.map(convertMessageToOpenAIMessage).map(convertSystemMessageToAssistantAPI).at(-1);
|
|
899
|
+
const userMessage = messages.map((m) => convertMessageToOpenAIMessage(m)).map(convertSystemMessageToAssistantAPI).at(-1);
|
|
868
900
|
if (userMessage.role !== "user") {
|
|
869
901
|
throw new Error("No user message found");
|
|
870
902
|
}
|
|
@@ -989,7 +1021,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
|
|
|
989
1021
|
|
|
990
1022
|
// src/service-adapters/unify/unify-adapter.ts
|
|
991
1023
|
var import_openai3 = __toESM(require("openai"));
|
|
992
|
-
var
|
|
1024
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
993
1025
|
var UnifyAdapter = class {
|
|
994
1026
|
apiKey;
|
|
995
1027
|
model;
|
|
@@ -1010,7 +1042,7 @@ var UnifyAdapter = class {
|
|
|
1010
1042
|
baseURL: "https://api.unify.ai/v0/"
|
|
1011
1043
|
});
|
|
1012
1044
|
const forwardedParameters = request.forwardedParameters;
|
|
1013
|
-
const messages = request.messages.map(convertMessageToOpenAIMessage);
|
|
1045
|
+
const messages = request.messages.map((m) => convertMessageToOpenAIMessage(m));
|
|
1014
1046
|
const stream = await openai.chat.completions.create({
|
|
1015
1047
|
model: this.model,
|
|
1016
1048
|
messages,
|
|
@@ -1031,7 +1063,7 @@ var UnifyAdapter = class {
|
|
|
1031
1063
|
for await (const chunk of stream) {
|
|
1032
1064
|
if (this.start) {
|
|
1033
1065
|
model = chunk.model;
|
|
1034
|
-
currentMessageId = (0,
|
|
1066
|
+
currentMessageId = (0, import_shared5.randomId)();
|
|
1035
1067
|
eventStream$.sendTextMessageStart({
|
|
1036
1068
|
messageId: currentMessageId
|
|
1037
1069
|
});
|
|
@@ -1098,7 +1130,7 @@ var UnifyAdapter = class {
|
|
|
1098
1130
|
eventStream$.complete();
|
|
1099
1131
|
});
|
|
1100
1132
|
return {
|
|
1101
|
-
threadId: request.threadId || (0,
|
|
1133
|
+
threadId: request.threadId || (0, import_shared5.randomUUID)()
|
|
1102
1134
|
};
|
|
1103
1135
|
}
|
|
1104
1136
|
};
|
|
@@ -1106,8 +1138,8 @@ __name(UnifyAdapter, "UnifyAdapter");
|
|
|
1106
1138
|
|
|
1107
1139
|
// src/service-adapters/groq/groq-adapter.ts
|
|
1108
1140
|
var import_groq_sdk = require("groq-sdk");
|
|
1109
|
-
var
|
|
1110
|
-
var DEFAULT_MODEL2 = "
|
|
1141
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1142
|
+
var DEFAULT_MODEL2 = "llama-3.3-70b-versatile";
|
|
1111
1143
|
var GroqAdapter = class {
|
|
1112
1144
|
model = DEFAULT_MODEL2;
|
|
1113
1145
|
disableParallelToolCalls = false;
|
|
@@ -1125,7 +1157,9 @@ var GroqAdapter = class {
|
|
|
1125
1157
|
async process(request) {
|
|
1126
1158
|
const { threadId, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
1127
1159
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
1128
|
-
let openaiMessages = messages.map(convertMessageToOpenAIMessage
|
|
1160
|
+
let openaiMessages = messages.map((m) => convertMessageToOpenAIMessage(m, {
|
|
1161
|
+
keepSystemRole: true
|
|
1162
|
+
}));
|
|
1129
1163
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
1130
1164
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
1131
1165
|
if ((forwardedParameters == null ? void 0 : forwardedParameters.toolChoice) === "function") {
|
|
@@ -1219,7 +1253,7 @@ var GroqAdapter = class {
|
|
|
1219
1253
|
eventStream$.complete();
|
|
1220
1254
|
});
|
|
1221
1255
|
return {
|
|
1222
|
-
threadId: request.threadId || (0,
|
|
1256
|
+
threadId: request.threadId || (0, import_shared6.randomUUID)()
|
|
1223
1257
|
};
|
|
1224
1258
|
}
|
|
1225
1259
|
};
|
|
@@ -1361,7 +1395,7 @@ function groupAnthropicMessagesByRole(messageParams) {
|
|
|
1361
1395
|
__name(groupAnthropicMessagesByRole, "groupAnthropicMessagesByRole");
|
|
1362
1396
|
|
|
1363
1397
|
// src/service-adapters/anthropic/anthropic-adapter.ts
|
|
1364
|
-
var
|
|
1398
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1365
1399
|
var DEFAULT_MODEL3 = "claude-3-sonnet-20240229";
|
|
1366
1400
|
var AnthropicAdapter = class {
|
|
1367
1401
|
model = DEFAULT_MODEL3;
|
|
@@ -1412,8 +1446,8 @@ var AnthropicAdapter = class {
|
|
|
1412
1446
|
eventSource.stream(async (eventStream$) => {
|
|
1413
1447
|
let mode = null;
|
|
1414
1448
|
let didOutputText = false;
|
|
1415
|
-
let currentMessageId = (0,
|
|
1416
|
-
let currentToolCallId = (0,
|
|
1449
|
+
let currentMessageId = (0, import_shared7.randomId)();
|
|
1450
|
+
let currentToolCallId = (0, import_shared7.randomId)();
|
|
1417
1451
|
let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
|
|
1418
1452
|
for await (const chunk of await stream) {
|
|
1419
1453
|
if (chunk.type === "message_start") {
|
|
@@ -1470,7 +1504,7 @@ var AnthropicAdapter = class {
|
|
|
1470
1504
|
eventStream$.complete();
|
|
1471
1505
|
});
|
|
1472
1506
|
return {
|
|
1473
|
-
threadId: threadId || (0,
|
|
1507
|
+
threadId: threadId || (0, import_shared7.randomUUID)()
|
|
1474
1508
|
};
|
|
1475
1509
|
}
|
|
1476
1510
|
};
|
|
@@ -1510,7 +1544,7 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1510
1544
|
|
|
1511
1545
|
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1512
1546
|
var import_ollama = require("@langchain/community/llms/ollama");
|
|
1513
|
-
var
|
|
1547
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1514
1548
|
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1515
1549
|
var ExperimentalOllamaAdapter = class {
|
|
1516
1550
|
model;
|
|
@@ -1529,7 +1563,7 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1529
1563
|
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1530
1564
|
const _stream = await ollama.stream(contents);
|
|
1531
1565
|
eventSource.stream(async (eventStream$) => {
|
|
1532
|
-
const currentMessageId = (0,
|
|
1566
|
+
const currentMessageId = (0, import_shared8.randomId)();
|
|
1533
1567
|
eventStream$.sendTextMessageStart({
|
|
1534
1568
|
messageId: currentMessageId
|
|
1535
1569
|
});
|
|
@@ -1545,18 +1579,18 @@ var ExperimentalOllamaAdapter = class {
|
|
|
1545
1579
|
eventStream$.complete();
|
|
1546
1580
|
});
|
|
1547
1581
|
return {
|
|
1548
|
-
threadId: request.threadId || (0,
|
|
1582
|
+
threadId: request.threadId || (0, import_shared8.randomUUID)()
|
|
1549
1583
|
};
|
|
1550
1584
|
}
|
|
1551
1585
|
};
|
|
1552
1586
|
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1553
1587
|
|
|
1554
1588
|
// src/service-adapters/empty/empty-adapter.ts
|
|
1555
|
-
var
|
|
1589
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1556
1590
|
var EmptyAdapter = class {
|
|
1557
1591
|
async process(request) {
|
|
1558
1592
|
return {
|
|
1559
|
-
threadId: request.threadId || (0,
|
|
1593
|
+
threadId: request.threadId || (0, import_shared9.randomUUID)()
|
|
1560
1594
|
};
|
|
1561
1595
|
}
|
|
1562
1596
|
};
|
|
@@ -1564,11 +1598,11 @@ __name(EmptyAdapter, "EmptyAdapter");
|
|
|
1564
1598
|
var ExperimentalEmptyAdapter = EmptyAdapter;
|
|
1565
1599
|
|
|
1566
1600
|
// src/service-adapters/events.ts
|
|
1567
|
-
var
|
|
1601
|
+
var import_shared18 = require("@copilotkit/shared");
|
|
1568
1602
|
var import_rxjs2 = require("rxjs");
|
|
1569
1603
|
|
|
1570
1604
|
// src/lib/telemetry-client.ts
|
|
1571
|
-
var
|
|
1605
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
1572
1606
|
|
|
1573
1607
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1574
1608
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1608,7 +1642,7 @@ var CustomEventNames;
|
|
|
1608
1642
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1609
1643
|
|
|
1610
1644
|
// src/agents/langgraph/event-source.ts
|
|
1611
|
-
var
|
|
1645
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1612
1646
|
var RemoteLangGraphEventSource = class {
|
|
1613
1647
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1614
1648
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1659,10 +1693,16 @@ var RemoteLangGraphEventSource = class {
|
|
|
1659
1693
|
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1660
1694
|
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1661
1695
|
const responseMetadata = this.getResponseMetadata(event);
|
|
1696
|
+
const toolCallCheck = toolCallChunks && toolCallChunks.length > 0;
|
|
1697
|
+
let isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1662
1698
|
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1663
1699
|
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1664
|
-
|
|
1665
|
-
acc.
|
|
1700
|
+
let previousRoundHadToolCall = acc.isToolCall;
|
|
1701
|
+
acc.isToolCall = toolCallCheck;
|
|
1702
|
+
if (previousRoundHadToolCall && !toolCallCheck) {
|
|
1703
|
+
isToolCallEnd = true;
|
|
1704
|
+
}
|
|
1705
|
+
acc.isToolCallEnd = isToolCallEnd;
|
|
1666
1706
|
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1667
1707
|
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1668
1708
|
name: acc.lastToolCallName,
|
|
@@ -1682,7 +1722,8 @@ var RemoteLangGraphEventSource = class {
|
|
|
1682
1722
|
lastMessageId: null,
|
|
1683
1723
|
lastToolCallId: null,
|
|
1684
1724
|
lastToolCallName: null,
|
|
1685
|
-
currentContent: null
|
|
1725
|
+
currentContent: null,
|
|
1726
|
+
processedToolCallIds: /* @__PURE__ */ new Set()
|
|
1686
1727
|
}), (0, import_rxjs.mergeMap)((acc) => {
|
|
1687
1728
|
const events = [];
|
|
1688
1729
|
let shouldEmitMessages = true;
|
|
@@ -1710,13 +1751,13 @@ var RemoteLangGraphEventSource = class {
|
|
|
1710
1751
|
});
|
|
1711
1752
|
}
|
|
1712
1753
|
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1713
|
-
if (
|
|
1754
|
+
if (acc.isToolCallEnd && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName) && acc.lastToolCallId && !acc.processedToolCallIds.has(acc.lastToolCallId)) {
|
|
1755
|
+
acc.processedToolCallIds.add(acc.lastToolCallId);
|
|
1714
1756
|
events.push({
|
|
1715
1757
|
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1716
1758
|
actionExecutionId: acc.lastToolCallId
|
|
1717
1759
|
});
|
|
1718
|
-
}
|
|
1719
|
-
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1760
|
+
} else if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1720
1761
|
events.push({
|
|
1721
1762
|
type: RuntimeEventTypes.TextMessageEnd,
|
|
1722
1763
|
messageId: acc.lastMessageId
|
|
@@ -1778,6 +1819,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1778
1819
|
parentMessageId: acc.lastMessageId
|
|
1779
1820
|
});
|
|
1780
1821
|
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1822
|
+
acc.processedToolCallIds.clear();
|
|
1781
1823
|
events.push({
|
|
1782
1824
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1783
1825
|
messageId: acc.lastMessageId
|
|
@@ -1814,7 +1856,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1814
1856
|
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1815
1857
|
});
|
|
1816
1858
|
}
|
|
1817
|
-
const messageId = (0,
|
|
1859
|
+
const messageId = (0, import_shared10.randomId)();
|
|
1818
1860
|
events.push({
|
|
1819
1861
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1820
1862
|
messageId
|
|
@@ -1837,7 +1879,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1837
1879
|
// src/lib/runtime/remote-lg-action.ts
|
|
1838
1880
|
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1839
1881
|
var import_node_crypto = require("crypto");
|
|
1840
|
-
var
|
|
1882
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1841
1883
|
var import_partial_json = require("partial-json");
|
|
1842
1884
|
|
|
1843
1885
|
// src/graphql/types/enums.ts
|
|
@@ -1848,6 +1890,7 @@ var MessageRole;
|
|
|
1848
1890
|
MessageRole2["assistant"] = "assistant";
|
|
1849
1891
|
MessageRole2["system"] = "system";
|
|
1850
1892
|
MessageRole2["tool"] = "tool";
|
|
1893
|
+
MessageRole2["developer"] = "developer";
|
|
1851
1894
|
})(MessageRole || (MessageRole = {}));
|
|
1852
1895
|
var CopilotRequestType;
|
|
1853
1896
|
(function(CopilotRequestType2) {
|
|
@@ -2466,6 +2509,7 @@ CopilotKitLangGraphInterruptEvent = _ts_decorate5([
|
|
|
2466
2509
|
], CopilotKitLangGraphInterruptEvent);
|
|
2467
2510
|
|
|
2468
2511
|
// src/lib/runtime/remote-lg-action.ts
|
|
2512
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2469
2513
|
var activeInterruptEvent = false;
|
|
2470
2514
|
async function execute(args) {
|
|
2471
2515
|
return new ReadableStream({
|
|
@@ -2495,11 +2539,11 @@ async function streamEvents(controller, args) {
|
|
|
2495
2539
|
...propertyHeaders
|
|
2496
2540
|
}
|
|
2497
2541
|
});
|
|
2498
|
-
let threadId = argsInitialThreadId ?? (0,
|
|
2542
|
+
let threadId = argsInitialThreadId ?? (0, import_shared11.randomUUID)();
|
|
2499
2543
|
if (argsInitialThreadId && argsInitialThreadId.startsWith("ck-")) {
|
|
2500
2544
|
threadId = argsInitialThreadId.substring(3);
|
|
2501
2545
|
}
|
|
2502
|
-
if (!(0,
|
|
2546
|
+
if (!(0, import_shared11.isValidUUID)(threadId)) {
|
|
2503
2547
|
console.warn(`Cannot use the threadId ${threadId} with LangGraph Platform. Must be a valid UUID.`);
|
|
2504
2548
|
}
|
|
2505
2549
|
let wasInitiatedWithExistingThread = true;
|
|
@@ -2545,15 +2589,9 @@ async function streamEvents(controller, args) {
|
|
|
2545
2589
|
}
|
|
2546
2590
|
if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
|
|
2547
2591
|
let response = lgInterruptMetaEvent.response;
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
};
|
|
2552
|
-
} catch (e) {
|
|
2553
|
-
payload.command = {
|
|
2554
|
-
resume: response
|
|
2555
|
-
};
|
|
2556
|
-
}
|
|
2592
|
+
payload.command = {
|
|
2593
|
+
resume: (0, import_shared12.parseJson)(response, response)
|
|
2594
|
+
};
|
|
2557
2595
|
}
|
|
2558
2596
|
if (mode === "continue" && !activeInterruptEvent) {
|
|
2559
2597
|
await client.threads.updateState(threadId, {
|
|
@@ -2589,6 +2627,11 @@ async function streamEvents(controller, args) {
|
|
|
2589
2627
|
});
|
|
2590
2628
|
}
|
|
2591
2629
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
2630
|
+
const graphSchema = await client.assistants.getSchemas(assistantId);
|
|
2631
|
+
const schemaKeys = getSchemaKeys(graphSchema);
|
|
2632
|
+
if (payload.input && schemaKeys.input) {
|
|
2633
|
+
payload.input = Object.fromEntries(Object.entries(payload.input).filter(([key]) => schemaKeys.input.includes(key)));
|
|
2634
|
+
}
|
|
2592
2635
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
2593
2636
|
let prevNodeName = null;
|
|
2594
2637
|
let emitIntermediateStateUntilEnd = null;
|
|
@@ -2680,7 +2723,8 @@ async function streamEvents(controller, args) {
|
|
|
2680
2723
|
nodeName,
|
|
2681
2724
|
state: manuallyEmittedState,
|
|
2682
2725
|
running: true,
|
|
2683
|
-
active: true
|
|
2726
|
+
active: true,
|
|
2727
|
+
schemaKeys
|
|
2684
2728
|
}));
|
|
2685
2729
|
continue;
|
|
2686
2730
|
}
|
|
@@ -2712,7 +2756,8 @@ async function streamEvents(controller, args) {
|
|
|
2712
2756
|
nodeName,
|
|
2713
2757
|
state,
|
|
2714
2758
|
running: true,
|
|
2715
|
-
active: !exitingNode
|
|
2759
|
+
active: !exitingNode,
|
|
2760
|
+
schemaKeys
|
|
2716
2761
|
}));
|
|
2717
2762
|
}
|
|
2718
2763
|
emit(JSON.stringify(event) + "\n");
|
|
@@ -2730,7 +2775,8 @@ async function streamEvents(controller, args) {
|
|
|
2730
2775
|
state: state.values,
|
|
2731
2776
|
running: !shouldExit,
|
|
2732
2777
|
active: false,
|
|
2733
|
-
includeMessages: true
|
|
2778
|
+
includeMessages: true,
|
|
2779
|
+
schemaKeys
|
|
2734
2780
|
}));
|
|
2735
2781
|
return Promise.resolve();
|
|
2736
2782
|
} catch (e) {
|
|
@@ -2743,7 +2789,7 @@ async function streamEvents(controller, args) {
|
|
|
2743
2789
|
}
|
|
2744
2790
|
}
|
|
2745
2791
|
__name(streamEvents, "streamEvents");
|
|
2746
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
2792
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false, schemaKeys }) {
|
|
2747
2793
|
if (!includeMessages) {
|
|
2748
2794
|
state = Object.keys(state).reduce((acc, key) => {
|
|
2749
2795
|
if (key !== "messages") {
|
|
@@ -2757,6 +2803,9 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
2757
2803
|
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
2758
2804
|
};
|
|
2759
2805
|
}
|
|
2806
|
+
if (schemaKeys.output) {
|
|
2807
|
+
state = Object.fromEntries(Object.entries(state).filter(([key]) => schemaKeys.output.includes(key)));
|
|
2808
|
+
}
|
|
2760
2809
|
return JSON.stringify({
|
|
2761
2810
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
2762
2811
|
thread_id: threadId,
|
|
@@ -2991,10 +3040,30 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
2991
3040
|
return result;
|
|
2992
3041
|
}
|
|
2993
3042
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
3043
|
+
function getSchemaKeys(graphSchema) {
|
|
3044
|
+
const CONSTANT_KEYS = [
|
|
3045
|
+
"messages",
|
|
3046
|
+
"copilotkit"
|
|
3047
|
+
];
|
|
3048
|
+
const inputSchema = Object.keys(graphSchema.input_schema.properties);
|
|
3049
|
+
const outputSchema = Object.keys(graphSchema.output_schema.properties);
|
|
3050
|
+
return {
|
|
3051
|
+
input: inputSchema && inputSchema.length ? [
|
|
3052
|
+
...inputSchema,
|
|
3053
|
+
...CONSTANT_KEYS
|
|
3054
|
+
] : null,
|
|
3055
|
+
output: outputSchema && outputSchema.length ? [
|
|
3056
|
+
...outputSchema,
|
|
3057
|
+
...CONSTANT_KEYS
|
|
3058
|
+
] : null
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3061
|
+
__name(getSchemaKeys, "getSchemaKeys");
|
|
2994
3062
|
|
|
2995
3063
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2996
|
-
var
|
|
2997
|
-
var
|
|
3064
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
3065
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
3066
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2998
3067
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2999
3068
|
const agents = endpoint.agents.map((agent) => ({
|
|
3000
3069
|
name: agent.name,
|
|
@@ -3017,8 +3086,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3017
3086
|
if (agentStates) {
|
|
3018
3087
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3019
3088
|
if (jsonState) {
|
|
3020
|
-
state =
|
|
3021
|
-
configurable =
|
|
3089
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3090
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3022
3091
|
}
|
|
3023
3092
|
}
|
|
3024
3093
|
try {
|
|
@@ -3038,7 +3107,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
3038
3107
|
state,
|
|
3039
3108
|
configurable,
|
|
3040
3109
|
properties: graphqlContext.properties,
|
|
3041
|
-
actions:
|
|
3110
|
+
actions: (0, import_shared15.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
3042
3111
|
name: action.name,
|
|
3043
3112
|
description: action.description,
|
|
3044
3113
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -3098,11 +3167,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3098
3167
|
body: await response.text()
|
|
3099
3168
|
}, "Failed to execute remote action");
|
|
3100
3169
|
if (response.status === 404) {
|
|
3101
|
-
throw new
|
|
3170
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3102
3171
|
url: fetchUrl
|
|
3103
3172
|
});
|
|
3104
3173
|
}
|
|
3105
|
-
throw new
|
|
3174
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3106
3175
|
status: response.status,
|
|
3107
3176
|
url: fetchUrl,
|
|
3108
3177
|
isRemoteEndpoint: true
|
|
@@ -3116,10 +3185,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3116
3185
|
}, "Executed remote action");
|
|
3117
3186
|
return result;
|
|
3118
3187
|
} catch (error) {
|
|
3119
|
-
if (error instanceof
|
|
3188
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3120
3189
|
throw error;
|
|
3121
3190
|
}
|
|
3122
|
-
throw new
|
|
3191
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3123
3192
|
error,
|
|
3124
3193
|
url: fetchUrl
|
|
3125
3194
|
});
|
|
@@ -3147,8 +3216,8 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3147
3216
|
if (agentStates) {
|
|
3148
3217
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
3149
3218
|
if (jsonState) {
|
|
3150
|
-
state =
|
|
3151
|
-
configurable =
|
|
3219
|
+
state = (0, import_shared15.parseJson)(jsonState.state, {});
|
|
3220
|
+
configurable = (0, import_shared15.parseJson)(jsonState.configurable, {});
|
|
3152
3221
|
}
|
|
3153
3222
|
}
|
|
3154
3223
|
const fetchUrl = `${url}/agents/execute`;
|
|
@@ -3167,7 +3236,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3167
3236
|
state,
|
|
3168
3237
|
configurable,
|
|
3169
3238
|
properties: graphqlContext.properties,
|
|
3170
|
-
actions:
|
|
3239
|
+
actions: (0, import_shared15.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
3171
3240
|
name: action.name,
|
|
3172
3241
|
description: action.description,
|
|
3173
3242
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -3182,11 +3251,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3182
3251
|
body: await response.text()
|
|
3183
3252
|
}, "Failed to execute remote agent");
|
|
3184
3253
|
if (response.status === 404) {
|
|
3185
|
-
throw new
|
|
3254
|
+
throw new import_shared14.CopilotKitApiDiscoveryError({
|
|
3186
3255
|
url: fetchUrl
|
|
3187
3256
|
});
|
|
3188
3257
|
}
|
|
3189
|
-
throw new
|
|
3258
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
3190
3259
|
status: response.status,
|
|
3191
3260
|
url: fetchUrl,
|
|
3192
3261
|
isRemoteEndpoint: true
|
|
@@ -3196,10 +3265,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
3196
3265
|
streamResponse(response.body, eventSource.eventStream$);
|
|
3197
3266
|
return eventSource.processLangGraphEvents();
|
|
3198
3267
|
} catch (error) {
|
|
3199
|
-
if (error instanceof
|
|
3268
|
+
if (error instanceof import_shared13.CopilotKitError) {
|
|
3200
3269
|
throw error;
|
|
3201
3270
|
}
|
|
3202
|
-
throw new
|
|
3271
|
+
throw new import_shared13.CopilotKitLowLevelError({
|
|
3203
3272
|
error,
|
|
3204
3273
|
url: fetchUrl
|
|
3205
3274
|
});
|
|
@@ -3273,7 +3342,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
3273
3342
|
__name(createHeaders, "createHeaders");
|
|
3274
3343
|
|
|
3275
3344
|
// src/lib/runtime/remote-actions.ts
|
|
3276
|
-
var
|
|
3345
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
3277
3346
|
var EndpointType;
|
|
3278
3347
|
(function(EndpointType2) {
|
|
3279
3348
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -3307,7 +3376,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3307
3376
|
status: response.status,
|
|
3308
3377
|
body: await response.text()
|
|
3309
3378
|
}, "Failed to fetch actions from url");
|
|
3310
|
-
throw new
|
|
3379
|
+
throw new import_shared16.ResolvedCopilotKitError({
|
|
3311
3380
|
status: response.status,
|
|
3312
3381
|
url: fetchUrl,
|
|
3313
3382
|
isRemoteEndpoint: true
|
|
@@ -3319,10 +3388,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
3319
3388
|
}, "Fetched actions from url");
|
|
3320
3389
|
return json;
|
|
3321
3390
|
} catch (error) {
|
|
3322
|
-
if (error instanceof
|
|
3391
|
+
if (error instanceof import_shared16.CopilotKitError) {
|
|
3323
3392
|
throw error;
|
|
3324
3393
|
}
|
|
3325
|
-
throw new
|
|
3394
|
+
throw new import_shared16.CopilotKitLowLevelError({
|
|
3326
3395
|
error,
|
|
3327
3396
|
url: fetchUrl
|
|
3328
3397
|
});
|
|
@@ -3385,7 +3454,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3385
3454
|
// src/lib/telemetry-client.ts
|
|
3386
3455
|
var import_node_crypto3 = require("crypto");
|
|
3387
3456
|
var packageJson = require_package();
|
|
3388
|
-
var telemetryClient = new
|
|
3457
|
+
var telemetryClient = new import_shared17.TelemetryClient({
|
|
3389
3458
|
packageName: packageJson.name,
|
|
3390
3459
|
packageVersion: packageJson.version
|
|
3391
3460
|
});
|
|
@@ -3702,10 +3771,10 @@ var RuntimeEventSource = class {
|
|
|
3702
3771
|
const errorMessage = `\u274C ${message}`;
|
|
3703
3772
|
if (!this.callback) {
|
|
3704
3773
|
this.stream(async (eventStream$) => {
|
|
3705
|
-
eventStream$.sendTextMessage((0,
|
|
3774
|
+
eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3706
3775
|
});
|
|
3707
3776
|
} else {
|
|
3708
|
-
this.eventStream$.sendTextMessage((0,
|
|
3777
|
+
this.eventStream$.sendTextMessage((0, import_shared18.randomId)(), errorMessage);
|
|
3709
3778
|
}
|
|
3710
3779
|
}
|
|
3711
3780
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -3864,35 +3933,35 @@ __name(executeAction, "executeAction");
|
|
|
3864
3933
|
|
|
3865
3934
|
// src/service-adapters/conversion.ts
|
|
3866
3935
|
var import_class_transformer2 = require("class-transformer");
|
|
3936
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
3867
3937
|
function convertGqlInputToMessages(inputMessages) {
|
|
3868
|
-
const messages =
|
|
3869
|
-
for (const message of inputMessages) {
|
|
3938
|
+
const messages = (0, import_shared19.tryMap)(inputMessages, (message) => {
|
|
3870
3939
|
if (message.textMessage) {
|
|
3871
|
-
|
|
3940
|
+
return (0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
3872
3941
|
id: message.id,
|
|
3873
3942
|
createdAt: message.createdAt,
|
|
3874
3943
|
role: message.textMessage.role,
|
|
3875
3944
|
content: message.textMessage.content,
|
|
3876
3945
|
parentMessageId: message.textMessage.parentMessageId
|
|
3877
|
-
})
|
|
3946
|
+
});
|
|
3878
3947
|
} else if (message.actionExecutionMessage) {
|
|
3879
|
-
|
|
3948
|
+
return (0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
3880
3949
|
id: message.id,
|
|
3881
3950
|
createdAt: message.createdAt,
|
|
3882
3951
|
name: message.actionExecutionMessage.name,
|
|
3883
3952
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
3884
3953
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3885
|
-
})
|
|
3954
|
+
});
|
|
3886
3955
|
} else if (message.resultMessage) {
|
|
3887
|
-
|
|
3956
|
+
return (0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
3888
3957
|
id: message.id,
|
|
3889
3958
|
createdAt: message.createdAt,
|
|
3890
3959
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
3891
3960
|
actionName: message.resultMessage.actionName,
|
|
3892
3961
|
result: message.resultMessage.result
|
|
3893
|
-
})
|
|
3962
|
+
});
|
|
3894
3963
|
} else if (message.agentStateMessage) {
|
|
3895
|
-
|
|
3964
|
+
return (0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
3896
3965
|
id: message.id,
|
|
3897
3966
|
threadId: message.agentStateMessage.threadId,
|
|
3898
3967
|
createdAt: message.createdAt,
|
|
@@ -3903,10 +3972,12 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3903
3972
|
role: message.agentStateMessage.role,
|
|
3904
3973
|
state: JSON.parse(message.agentStateMessage.state),
|
|
3905
3974
|
running: message.agentStateMessage.running
|
|
3906
|
-
})
|
|
3975
|
+
});
|
|
3976
|
+
} else {
|
|
3977
|
+
return null;
|
|
3907
3978
|
}
|
|
3908
|
-
}
|
|
3909
|
-
return messages;
|
|
3979
|
+
});
|
|
3980
|
+
return messages.filter((m) => m);
|
|
3910
3981
|
}
|
|
3911
3982
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
3912
3983
|
|
|
@@ -3922,7 +3993,12 @@ var CopilotRuntime = class {
|
|
|
3922
3993
|
delegateAgentProcessingToServiceAdapter;
|
|
3923
3994
|
constructor(params) {
|
|
3924
3995
|
var _a, _b;
|
|
3925
|
-
|
|
3996
|
+
if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints)) {
|
|
3997
|
+
console.warn("Actions set in runtime instance will be ignored when remote endpoints are set");
|
|
3998
|
+
this.actions = [];
|
|
3999
|
+
} else {
|
|
4000
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
4001
|
+
}
|
|
3926
4002
|
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
3927
4003
|
const remoteChain = new RemoteChain(chain);
|
|
3928
4004
|
this.langserve.push(remoteChain.toAction());
|
|
@@ -3941,7 +4017,7 @@ var CopilotRuntime = class {
|
|
|
3941
4017
|
return await this.processAgentRequest(request);
|
|
3942
4018
|
}
|
|
3943
4019
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3944
|
-
throw new
|
|
4020
|
+
throw new import_shared20.CopilotKitMisuseError({
|
|
3945
4021
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3946
4022
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3947
4023
|
please use an LLM adapter instead.`
|
|
@@ -3953,7 +4029,7 @@ please use an LLM adapter instead.`
|
|
|
3953
4029
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3954
4030
|
name: action.name,
|
|
3955
4031
|
description: action.description,
|
|
3956
|
-
jsonSchema: JSON.stringify((0,
|
|
4032
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
3957
4033
|
}));
|
|
3958
4034
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3959
4035
|
...serverSideActionsInput,
|
|
@@ -4005,7 +4081,7 @@ please use an LLM adapter instead.`
|
|
|
4005
4081
|
extensions: result.extensions
|
|
4006
4082
|
};
|
|
4007
4083
|
} catch (error) {
|
|
4008
|
-
if (error instanceof
|
|
4084
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4009
4085
|
throw error;
|
|
4010
4086
|
}
|
|
4011
4087
|
console.error("Error getting response:", error);
|
|
@@ -4051,11 +4127,11 @@ please use an LLM adapter instead.`
|
|
|
4051
4127
|
});
|
|
4052
4128
|
if (!response.ok) {
|
|
4053
4129
|
if (response.status === 404) {
|
|
4054
|
-
throw new
|
|
4130
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4055
4131
|
url: fetchUrl
|
|
4056
4132
|
});
|
|
4057
4133
|
}
|
|
4058
|
-
throw new
|
|
4134
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4059
4135
|
status: response.status,
|
|
4060
4136
|
url: fetchUrl,
|
|
4061
4137
|
isRemoteEndpoint: true
|
|
@@ -4065,7 +4141,7 @@ please use an LLM adapter instead.`
|
|
|
4065
4141
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
4066
4142
|
name: agent.name,
|
|
4067
4143
|
description: agent.description ?? "" ?? "",
|
|
4068
|
-
id: (0,
|
|
4144
|
+
id: (0, import_shared20.randomId)(),
|
|
4069
4145
|
endpoint
|
|
4070
4146
|
}));
|
|
4071
4147
|
return [
|
|
@@ -4073,10 +4149,10 @@ please use an LLM adapter instead.`
|
|
|
4073
4149
|
...endpointAgents
|
|
4074
4150
|
];
|
|
4075
4151
|
} catch (error) {
|
|
4076
|
-
if (error instanceof
|
|
4152
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4077
4153
|
throw error;
|
|
4078
4154
|
}
|
|
4079
|
-
throw new
|
|
4155
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4080
4156
|
error,
|
|
4081
4157
|
url: fetchUrl
|
|
4082
4158
|
});
|
|
@@ -4138,11 +4214,11 @@ please use an LLM adapter instead.`
|
|
|
4138
4214
|
});
|
|
4139
4215
|
if (!response.ok) {
|
|
4140
4216
|
if (response.status === 404) {
|
|
4141
|
-
throw new
|
|
4217
|
+
throw new import_shared20.CopilotKitApiDiscoveryError({
|
|
4142
4218
|
url: fetchUrl
|
|
4143
4219
|
});
|
|
4144
4220
|
}
|
|
4145
|
-
throw new
|
|
4221
|
+
throw new import_shared20.ResolvedCopilotKitError({
|
|
4146
4222
|
status: response.status,
|
|
4147
4223
|
url: fetchUrl,
|
|
4148
4224
|
isRemoteEndpoint: true
|
|
@@ -4155,10 +4231,10 @@ please use an LLM adapter instead.`
|
|
|
4155
4231
|
messages: JSON.stringify(data.messages)
|
|
4156
4232
|
};
|
|
4157
4233
|
} catch (error) {
|
|
4158
|
-
if (error instanceof
|
|
4234
|
+
if (error instanceof import_shared20.CopilotKitError) {
|
|
4159
4235
|
throw error;
|
|
4160
4236
|
}
|
|
4161
|
-
throw new
|
|
4237
|
+
throw new import_shared20.CopilotKitLowLevelError({
|
|
4162
4238
|
error,
|
|
4163
4239
|
url: fetchUrl
|
|
4164
4240
|
});
|
|
@@ -4176,7 +4252,7 @@ please use an LLM adapter instead.`
|
|
|
4176
4252
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
4177
4253
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
4178
4254
|
if (!currentAgent) {
|
|
4179
|
-
throw new
|
|
4255
|
+
throw new import_shared20.CopilotKitAgentDiscoveryError({
|
|
4180
4256
|
agentName
|
|
4181
4257
|
});
|
|
4182
4258
|
}
|
|
@@ -4187,7 +4263,7 @@ please use an LLM adapter instead.`
|
|
|
4187
4263
|
)).map((action) => ({
|
|
4188
4264
|
name: action.name,
|
|
4189
4265
|
description: action.description,
|
|
4190
|
-
jsonSchema: JSON.stringify((0,
|
|
4266
|
+
jsonSchema: JSON.stringify((0, import_shared20.actionParametersToJsonSchema)(action.parameters))
|
|
4191
4267
|
}));
|
|
4192
4268
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
4193
4269
|
...availableActionsForCurrentAgent,
|
|
@@ -4234,7 +4310,7 @@ please use an LLM adapter instead.`
|
|
|
4234
4310
|
threadId,
|
|
4235
4311
|
runId: void 0,
|
|
4236
4312
|
eventSource,
|
|
4237
|
-
serverSideActions
|
|
4313
|
+
serverSideActions,
|
|
4238
4314
|
actionInputsWithoutAgents: allAvailableActions
|
|
4239
4315
|
};
|
|
4240
4316
|
} catch (error) {
|
|
@@ -5112,7 +5188,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
5112
5188
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
5113
5189
|
|
|
5114
5190
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
5115
|
-
var
|
|
5191
|
+
var import_shared21 = require("@copilotkit/shared");
|
|
5116
5192
|
|
|
5117
5193
|
// src/graphql/types/agents-response.type.ts
|
|
5118
5194
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -5295,7 +5371,7 @@ var CopilotResolver = class {
|
|
|
5295
5371
|
rejectOutputMessagesPromise = reject;
|
|
5296
5372
|
});
|
|
5297
5373
|
logger2.debug("Processing");
|
|
5298
|
-
const { eventSource, threadId = (0,
|
|
5374
|
+
const { eventSource, threadId = (0, import_shared21.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
5299
5375
|
serviceAdapter,
|
|
5300
5376
|
messages: data.messages,
|
|
5301
5377
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5428,7 +5504,7 @@ var CopilotResolver = class {
|
|
|
5428
5504
|
});
|
|
5429
5505
|
outputMessages = [
|
|
5430
5506
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5431
|
-
id: (0,
|
|
5507
|
+
id: (0, import_shared21.randomId)(),
|
|
5432
5508
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5433
5509
|
content: result.reason,
|
|
5434
5510
|
role: MessageRole.assistant
|
|
@@ -5606,7 +5682,7 @@ var CopilotResolver = class {
|
|
|
5606
5682
|
event
|
|
5607
5683
|
}, "Agent message event received");
|
|
5608
5684
|
pushMessage({
|
|
5609
|
-
id: (0,
|
|
5685
|
+
id: (0, import_shared21.randomId)(),
|
|
5610
5686
|
status: new SuccessMessageStatus(),
|
|
5611
5687
|
threadId: event.threadId,
|
|
5612
5688
|
agentName: event.agentName,
|
|
@@ -5619,7 +5695,7 @@ var CopilotResolver = class {
|
|
|
5619
5695
|
createdAt: /* @__PURE__ */ new Date()
|
|
5620
5696
|
});
|
|
5621
5697
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5622
|
-
id: (0,
|
|
5698
|
+
id: (0, import_shared21.randomId)(),
|
|
5623
5699
|
threadId: event.threadId,
|
|
5624
5700
|
agentName: event.agentName,
|
|
5625
5701
|
nodeName: event.nodeName,
|