@copilotkit/runtime 1.6.0-next.2 → 1.6.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/{chunk-CNE5TM3A.mjs → chunk-4FCUC27H.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-7EXH7PVD.mjs} +3 -2
- package/dist/chunk-7EXH7PVD.mjs.map +1 -0
- package/dist/{chunk-O7ERQQ2G.mjs → chunk-ROFUPT7E.mjs} +2 -2
- package/dist/{chunk-6BXTXLGY.mjs → chunk-YUCVJM6E.mjs} +23 -25
- package/dist/chunk-YUCVJM6E.mjs.map +1 -0
- package/dist/{chunk-DDOT5G7D.mjs → chunk-Z5VUD7NL.mjs} +2 -2
- package/dist/index.js +89 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/lib/index.js +82 -83
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.js +3 -2
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.js +3 -2
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.js +3 -2
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.js +3 -2
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.js +28 -27
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +4 -3
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +236 -0
- package/src/lib/runtime/remote-action-constructors.ts +7 -6
- package/src/lib/runtime/remote-lg-action.ts +2 -6
- package/src/service-adapters/conversion.ts +3 -2
- package/src/service-adapters/openai/utils.ts +2 -1
- package/tsconfig.json +3 -2
- package/dist/chunk-6BXTXLGY.mjs.map +0 -1
- package/dist/chunk-OS5YD32G.mjs.map +0 -1
- /package/dist/{chunk-CNE5TM3A.mjs.map → chunk-4FCUC27H.mjs.map} +0 -0
- /package/dist/{chunk-O7ERQQ2G.mjs.map → chunk-ROFUPT7E.mjs.map} +0 -0
- /package/dist/{chunk-DDOT5G7D.mjs.map → chunk-Z5VUD7NL.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
config,
|
|
4
4
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
5
5
|
copilotRuntimeNextJSPagesRouterEndpoint
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ROFUPT7E.mjs";
|
|
7
7
|
import {
|
|
8
8
|
copilotRuntimeNestEndpoint
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4FCUC27H.mjs";
|
|
10
10
|
import {
|
|
11
11
|
copilotRuntimeNodeExpressEndpoint
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-Z5VUD7NL.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CopilotRuntime,
|
|
15
15
|
addCustomHeaderPlugin,
|
|
@@ -21,7 +21,12 @@ import {
|
|
|
21
21
|
getCommonConfig,
|
|
22
22
|
langGraphPlatformEndpoint,
|
|
23
23
|
resolveEndpointType
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-YUCVJM6E.mjs";
|
|
25
|
+
import {
|
|
26
|
+
GuardrailsValidationFailureResponse,
|
|
27
|
+
MessageStreamInterruptedResponse,
|
|
28
|
+
UnknownErrorResponse
|
|
29
|
+
} from "./chunk-5BIEM2UU.mjs";
|
|
25
30
|
import {
|
|
26
31
|
AnthropicAdapter,
|
|
27
32
|
EmptyAdapter,
|
|
@@ -34,12 +39,7 @@ import {
|
|
|
34
39
|
OpenAIAssistantAdapter,
|
|
35
40
|
RemoteChain,
|
|
36
41
|
UnifyAdapter
|
|
37
|
-
} from "./chunk-
|
|
38
|
-
import {
|
|
39
|
-
GuardrailsValidationFailureResponse,
|
|
40
|
-
MessageStreamInterruptedResponse,
|
|
41
|
-
UnknownErrorResponse
|
|
42
|
-
} from "./chunk-5BIEM2UU.mjs";
|
|
42
|
+
} from "./chunk-7EXH7PVD.mjs";
|
|
43
43
|
import "./chunk-RTFJTJMA.mjs";
|
|
44
44
|
import "./chunk-2OZAGFV3.mjs";
|
|
45
45
|
import "./chunk-FHD4JECV.mjs";
|
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.4",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -66,7 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
devDependencies: {
|
|
67
67
|
"@swc/core": "1.5.28",
|
|
68
68
|
"@types/express": "^4.17.21",
|
|
69
|
-
"@types/jest": "^29.5.
|
|
69
|
+
"@types/jest": "^29.5.12",
|
|
70
70
|
"@types/node": "^18.11.17",
|
|
71
71
|
"@whatwg-node/server": "^0.9.34",
|
|
72
72
|
eslint: "^8.56.0",
|
|
@@ -90,6 +90,7 @@ var require_package = __commonJS({
|
|
|
90
90
|
"@langchain/langgraph-sdk": "^0.0.36",
|
|
91
91
|
"@langchain/openai": "^0.4.2",
|
|
92
92
|
"class-transformer": "^0.5.1",
|
|
93
|
+
"class-validator": "^0.14.1",
|
|
93
94
|
express: "^4.19.2",
|
|
94
95
|
graphql: "^16.8.1",
|
|
95
96
|
"graphql-scalars": "^1.23.0",
|
|
@@ -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 = [];
|
|
@@ -326,7 +328,7 @@ function convertActionInputToOpenAITool(action) {
|
|
|
326
328
|
function: {
|
|
327
329
|
name: action.name,
|
|
328
330
|
description: action.description,
|
|
329
|
-
parameters:
|
|
331
|
+
parameters: (0, import_shared.parseJson)(action.jsonSchema, {})
|
|
330
332
|
}
|
|
331
333
|
};
|
|
332
334
|
}
|
|
@@ -372,7 +374,7 @@ function convertSystemMessageToAssistantAPI(message) {
|
|
|
372
374
|
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
373
375
|
|
|
374
376
|
// src/service-adapters/openai/openai-adapter.ts
|
|
375
|
-
var
|
|
377
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
376
378
|
var DEFAULT_MODEL = "gpt-4o";
|
|
377
379
|
var OpenAIAdapter = class {
|
|
378
380
|
model = DEFAULT_MODEL;
|
|
@@ -391,7 +393,7 @@ var OpenAIAdapter = class {
|
|
|
391
393
|
async process(request) {
|
|
392
394
|
const { threadId: threadIdFromRequest, model = this.model, messages, actions, eventSource, forwardedParameters } = request;
|
|
393
395
|
const tools = actions.map(convertActionInputToOpenAITool);
|
|
394
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
396
|
+
const threadId = threadIdFromRequest ?? (0, import_shared2.randomUUID)();
|
|
395
397
|
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
396
398
|
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
397
399
|
let toolChoice = forwardedParameters == null ? void 0 : forwardedParameters.toolChoice;
|
|
@@ -498,7 +500,7 @@ __name(OpenAIAdapter, "OpenAIAdapter");
|
|
|
498
500
|
// src/service-adapters/langchain/utils.ts
|
|
499
501
|
var import_messages = require("@langchain/core/messages");
|
|
500
502
|
var import_tools = require("@langchain/core/tools");
|
|
501
|
-
var
|
|
503
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
502
504
|
function convertMessageToLangChainMessage(message) {
|
|
503
505
|
if (message.isTextMessage()) {
|
|
504
506
|
if (message.role == "user") {
|
|
@@ -531,7 +533,7 @@ function convertActionInputToLangChainTool(actionInput) {
|
|
|
531
533
|
return new import_tools.DynamicStructuredTool({
|
|
532
534
|
name: actionInput.name,
|
|
533
535
|
description: actionInput.description,
|
|
534
|
-
schema: (0,
|
|
536
|
+
schema: (0, import_shared3.convertJsonSchemaToZodSchema)(JSON.parse(actionInput.jsonSchema), true),
|
|
535
537
|
func: async () => {
|
|
536
538
|
return "";
|
|
537
539
|
}
|
|
@@ -564,7 +566,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
564
566
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
565
567
|
if (typeof result === "string") {
|
|
566
568
|
if (!actionExecution) {
|
|
567
|
-
eventStream$.sendTextMessage((0,
|
|
569
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result);
|
|
568
570
|
} else {
|
|
569
571
|
eventStream$.sendActionExecutionResult({
|
|
570
572
|
actionExecutionId: actionExecution.id,
|
|
@@ -575,11 +577,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
575
577
|
} else if (isAIMessage(result)) {
|
|
576
578
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
577
579
|
if (result.content) {
|
|
578
|
-
eventStream$.sendTextMessage((0,
|
|
580
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
579
581
|
}
|
|
580
582
|
for (const toolCall of result.tool_calls) {
|
|
581
583
|
eventStream$.sendActionExecution({
|
|
582
|
-
actionExecutionId: toolCall.id || (0,
|
|
584
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
583
585
|
actionName: toolCall.name,
|
|
584
586
|
args: JSON.stringify(toolCall.args)
|
|
585
587
|
});
|
|
@@ -587,12 +589,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
587
589
|
} else if (isBaseMessageChunk(result)) {
|
|
588
590
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
589
591
|
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
590
|
-
eventStream$.sendTextMessage((0,
|
|
592
|
+
eventStream$.sendTextMessage((0, import_shared3.randomId)(), result.content);
|
|
591
593
|
}
|
|
592
594
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
593
595
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
594
596
|
eventStream$.sendActionExecution({
|
|
595
|
-
actionExecutionId: toolCall.id || (0,
|
|
597
|
+
actionExecutionId: toolCall.id || (0, import_shared3.randomId)(),
|
|
596
598
|
actionName: toolCall.name,
|
|
597
599
|
args: JSON.stringify(toolCall.args)
|
|
598
600
|
});
|
|
@@ -666,7 +668,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
666
668
|
});
|
|
667
669
|
} else if (content) {
|
|
668
670
|
mode = "message";
|
|
669
|
-
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0,
|
|
671
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared3.randomId)();
|
|
670
672
|
eventStream$.sendTextMessageStart({
|
|
671
673
|
messageId: currentMessageId
|
|
672
674
|
});
|
|
@@ -723,7 +725,7 @@ function encodeResult(result) {
|
|
|
723
725
|
__name(encodeResult, "encodeResult");
|
|
724
726
|
|
|
725
727
|
// src/service-adapters/langchain/langchain-adapter.ts
|
|
726
|
-
var
|
|
728
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
727
729
|
var import_promises = require("@langchain/core/callbacks/promises");
|
|
728
730
|
var LangChainAdapter = class {
|
|
729
731
|
options;
|
|
@@ -736,7 +738,7 @@ var LangChainAdapter = class {
|
|
|
736
738
|
async process(request) {
|
|
737
739
|
try {
|
|
738
740
|
const { eventSource, model, actions, messages, runId, threadId: threadIdFromRequest } = request;
|
|
739
|
-
const threadId = threadIdFromRequest ?? (0,
|
|
741
|
+
const threadId = threadIdFromRequest ?? (0, import_shared4.randomUUID)();
|
|
740
742
|
const result = await this.options.chainFn({
|
|
741
743
|
messages: messages.map(convertMessageToLangChainMessage),
|
|
742
744
|
tools: actions.map(convertActionInputToLangChainTool),
|
|
@@ -980,7 +982,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
|
|
|
980
982
|
|
|
981
983
|
// src/service-adapters/unify/unify-adapter.ts
|
|
982
984
|
var import_openai3 = __toESM(require("openai"));
|
|
983
|
-
var
|
|
985
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
984
986
|
var UnifyAdapter = class {
|
|
985
987
|
apiKey;
|
|
986
988
|
model;
|
|
@@ -1022,7 +1024,7 @@ var UnifyAdapter = class {
|
|
|
1022
1024
|
for await (const chunk of stream) {
|
|
1023
1025
|
if (this.start) {
|
|
1024
1026
|
model = chunk.model;
|
|
1025
|
-
currentMessageId = (0,
|
|
1027
|
+
currentMessageId = (0, import_shared5.randomId)();
|
|
1026
1028
|
eventStream$.sendTextMessageStart({
|
|
1027
1029
|
messageId: currentMessageId
|
|
1028
1030
|
});
|
|
@@ -1089,7 +1091,7 @@ var UnifyAdapter = class {
|
|
|
1089
1091
|
eventStream$.complete();
|
|
1090
1092
|
});
|
|
1091
1093
|
return {
|
|
1092
|
-
threadId: request.threadId || (0,
|
|
1094
|
+
threadId: request.threadId || (0, import_shared5.randomUUID)()
|
|
1093
1095
|
};
|
|
1094
1096
|
}
|
|
1095
1097
|
};
|
|
@@ -1097,7 +1099,7 @@ __name(UnifyAdapter, "UnifyAdapter");
|
|
|
1097
1099
|
|
|
1098
1100
|
// src/service-adapters/groq/groq-adapter.ts
|
|
1099
1101
|
var import_groq_sdk = require("groq-sdk");
|
|
1100
|
-
var
|
|
1102
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1101
1103
|
var DEFAULT_MODEL2 = "llama3-groq-70b-8192-tool-use-preview";
|
|
1102
1104
|
var GroqAdapter = class {
|
|
1103
1105
|
model = DEFAULT_MODEL2;
|
|
@@ -1210,29 +1212,29 @@ var GroqAdapter = class {
|
|
|
1210
1212
|
eventStream$.complete();
|
|
1211
1213
|
});
|
|
1212
1214
|
return {
|
|
1213
|
-
threadId: request.threadId || (0,
|
|
1215
|
+
threadId: request.threadId || (0, import_shared6.randomUUID)()
|
|
1214
1216
|
};
|
|
1215
1217
|
}
|
|
1216
1218
|
};
|
|
1217
1219
|
__name(GroqAdapter, "GroqAdapter");
|
|
1218
1220
|
|
|
1219
1221
|
// src/service-adapters/empty/empty-adapter.ts
|
|
1220
|
-
var
|
|
1222
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1221
1223
|
var EmptyAdapter = class {
|
|
1222
1224
|
async process(request) {
|
|
1223
1225
|
return {
|
|
1224
|
-
threadId: request.threadId || (0,
|
|
1226
|
+
threadId: request.threadId || (0, import_shared7.randomUUID)()
|
|
1225
1227
|
};
|
|
1226
1228
|
}
|
|
1227
1229
|
};
|
|
1228
1230
|
__name(EmptyAdapter, "EmptyAdapter");
|
|
1229
1231
|
|
|
1230
1232
|
// src/service-adapters/events.ts
|
|
1231
|
-
var
|
|
1233
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
1232
1234
|
var import_rxjs2 = require("rxjs");
|
|
1233
1235
|
|
|
1234
1236
|
// src/lib/telemetry-client.ts
|
|
1235
|
-
var
|
|
1237
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
1236
1238
|
|
|
1237
1239
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1238
1240
|
var import_node_crypto2 = require("crypto");
|
|
@@ -1272,7 +1274,7 @@ var CustomEventNames;
|
|
|
1272
1274
|
})(CustomEventNames || (CustomEventNames = {}));
|
|
1273
1275
|
|
|
1274
1276
|
// src/agents/langgraph/event-source.ts
|
|
1275
|
-
var
|
|
1277
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1276
1278
|
var RemoteLangGraphEventSource = class {
|
|
1277
1279
|
eventStream$ = new import_rxjs.ReplaySubject();
|
|
1278
1280
|
shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
|
|
@@ -1478,7 +1480,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1478
1480
|
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1479
1481
|
});
|
|
1480
1482
|
}
|
|
1481
|
-
const messageId = (0,
|
|
1483
|
+
const messageId = (0, import_shared8.randomId)();
|
|
1482
1484
|
events.push({
|
|
1483
1485
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1484
1486
|
messageId
|
|
@@ -1501,7 +1503,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1501
1503
|
// src/lib/runtime/remote-lg-action.ts
|
|
1502
1504
|
var import_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
1503
1505
|
var import_node_crypto = require("crypto");
|
|
1504
|
-
var
|
|
1506
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1505
1507
|
var import_partial_json = require("partial-json");
|
|
1506
1508
|
|
|
1507
1509
|
// src/graphql/types/enums.ts
|
|
@@ -2130,6 +2132,7 @@ CopilotKitLangGraphInterruptEvent = _ts_decorate5([
|
|
|
2130
2132
|
], CopilotKitLangGraphInterruptEvent);
|
|
2131
2133
|
|
|
2132
2134
|
// src/lib/runtime/remote-lg-action.ts
|
|
2135
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
2133
2136
|
var activeInterruptEvent = false;
|
|
2134
2137
|
async function execute(args) {
|
|
2135
2138
|
return new ReadableStream({
|
|
@@ -2159,11 +2162,11 @@ async function streamEvents(controller, args) {
|
|
|
2159
2162
|
...propertyHeaders
|
|
2160
2163
|
}
|
|
2161
2164
|
});
|
|
2162
|
-
let threadId = argsInitialThreadId ?? (0,
|
|
2165
|
+
let threadId = argsInitialThreadId ?? (0, import_shared9.randomUUID)();
|
|
2163
2166
|
if (argsInitialThreadId && argsInitialThreadId.startsWith("ck-")) {
|
|
2164
2167
|
threadId = argsInitialThreadId.substring(3);
|
|
2165
2168
|
}
|
|
2166
|
-
if (!(0,
|
|
2169
|
+
if (!(0, import_shared9.isValidUUID)(threadId)) {
|
|
2167
2170
|
console.warn(`Cannot use the threadId ${threadId} with LangGraph Platform. Must be a valid UUID.`);
|
|
2168
2171
|
}
|
|
2169
2172
|
let wasInitiatedWithExistingThread = true;
|
|
@@ -2209,15 +2212,9 @@ async function streamEvents(controller, args) {
|
|
|
2209
2212
|
}
|
|
2210
2213
|
if (lgInterruptMetaEvent == null ? void 0 : lgInterruptMetaEvent.response) {
|
|
2211
2214
|
let response = lgInterruptMetaEvent.response;
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
};
|
|
2216
|
-
} catch (e) {
|
|
2217
|
-
payload.command = {
|
|
2218
|
-
resume: response
|
|
2219
|
-
};
|
|
2220
|
-
}
|
|
2215
|
+
payload.command = {
|
|
2216
|
+
resume: (0, import_shared10.parseJson)(response, response)
|
|
2217
|
+
};
|
|
2221
2218
|
}
|
|
2222
2219
|
if (mode === "continue" && !activeInterruptEvent) {
|
|
2223
2220
|
await client.threads.updateState(threadId, {
|
|
@@ -2657,8 +2654,9 @@ function copilotkitMessagesToLangChain(messages) {
|
|
|
2657
2654
|
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
2658
2655
|
|
|
2659
2656
|
// src/lib/runtime/remote-action-constructors.ts
|
|
2660
|
-
var
|
|
2661
|
-
var
|
|
2657
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
2658
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2659
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2662
2660
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
2663
2661
|
const agents = endpoint.agents.map((agent) => ({
|
|
2664
2662
|
name: agent.name,
|
|
@@ -2681,8 +2679,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2681
2679
|
if (agentStates) {
|
|
2682
2680
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
2683
2681
|
if (jsonState) {
|
|
2684
|
-
state =
|
|
2685
|
-
configurable =
|
|
2682
|
+
state = (0, import_shared13.parseJson)(jsonState.state, {});
|
|
2683
|
+
configurable = (0, import_shared13.parseJson)(jsonState.configurable, {});
|
|
2686
2684
|
}
|
|
2687
2685
|
}
|
|
2688
2686
|
try {
|
|
@@ -2705,7 +2703,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2705
2703
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
2706
2704
|
name: action.name,
|
|
2707
2705
|
description: action.description,
|
|
2708
|
-
parameters:
|
|
2706
|
+
parameters: (0, import_shared13.parseJson)(action.jsonSchema, "")
|
|
2709
2707
|
})),
|
|
2710
2708
|
metaEvents
|
|
2711
2709
|
});
|
|
@@ -2762,11 +2760,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2762
2760
|
body: await response.text()
|
|
2763
2761
|
}, "Failed to execute remote action");
|
|
2764
2762
|
if (response.status === 404) {
|
|
2765
|
-
throw new
|
|
2763
|
+
throw new import_shared12.CopilotKitApiDiscoveryError({
|
|
2766
2764
|
url: fetchUrl
|
|
2767
2765
|
});
|
|
2768
2766
|
}
|
|
2769
|
-
throw new
|
|
2767
|
+
throw new import_shared12.ResolvedCopilotKitError({
|
|
2770
2768
|
status: response.status,
|
|
2771
2769
|
url: fetchUrl,
|
|
2772
2770
|
isRemoteEndpoint: true
|
|
@@ -2780,10 +2778,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2780
2778
|
}, "Executed remote action");
|
|
2781
2779
|
return result;
|
|
2782
2780
|
} catch (error) {
|
|
2783
|
-
if (error instanceof
|
|
2781
|
+
if (error instanceof import_shared11.CopilotKitError) {
|
|
2784
2782
|
throw error;
|
|
2785
2783
|
}
|
|
2786
|
-
throw new
|
|
2784
|
+
throw new import_shared11.CopilotKitLowLevelError({
|
|
2787
2785
|
error,
|
|
2788
2786
|
url: fetchUrl
|
|
2789
2787
|
});
|
|
@@ -2811,8 +2809,8 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2811
2809
|
if (agentStates) {
|
|
2812
2810
|
const jsonState = agentStates.find((state2) => state2.agentName === name);
|
|
2813
2811
|
if (jsonState) {
|
|
2814
|
-
state =
|
|
2815
|
-
configurable =
|
|
2812
|
+
state = (0, import_shared13.parseJson)(jsonState.state, {});
|
|
2813
|
+
configurable = (0, import_shared13.parseJson)(jsonState.configurable, {});
|
|
2816
2814
|
}
|
|
2817
2815
|
}
|
|
2818
2816
|
const fetchUrl = `${url}/agents/execute`;
|
|
@@ -2834,7 +2832,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2834
2832
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
2835
2833
|
name: action.name,
|
|
2836
2834
|
description: action.description,
|
|
2837
|
-
parameters:
|
|
2835
|
+
parameters: (0, import_shared13.parseJson)(action.jsonSchema, {})
|
|
2838
2836
|
})),
|
|
2839
2837
|
metaEvents
|
|
2840
2838
|
})
|
|
@@ -2846,11 +2844,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2846
2844
|
body: await response.text()
|
|
2847
2845
|
}, "Failed to execute remote agent");
|
|
2848
2846
|
if (response.status === 404) {
|
|
2849
|
-
throw new
|
|
2847
|
+
throw new import_shared12.CopilotKitApiDiscoveryError({
|
|
2850
2848
|
url: fetchUrl
|
|
2851
2849
|
});
|
|
2852
2850
|
}
|
|
2853
|
-
throw new
|
|
2851
|
+
throw new import_shared12.ResolvedCopilotKitError({
|
|
2854
2852
|
status: response.status,
|
|
2855
2853
|
url: fetchUrl,
|
|
2856
2854
|
isRemoteEndpoint: true
|
|
@@ -2860,10 +2858,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2860
2858
|
streamResponse(response.body, eventSource.eventStream$);
|
|
2861
2859
|
return eventSource.processLangGraphEvents();
|
|
2862
2860
|
} catch (error) {
|
|
2863
|
-
if (error instanceof
|
|
2861
|
+
if (error instanceof import_shared11.CopilotKitError) {
|
|
2864
2862
|
throw error;
|
|
2865
2863
|
}
|
|
2866
|
-
throw new
|
|
2864
|
+
throw new import_shared11.CopilotKitLowLevelError({
|
|
2867
2865
|
error,
|
|
2868
2866
|
url: fetchUrl
|
|
2869
2867
|
});
|
|
@@ -2937,7 +2935,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
|
|
|
2937
2935
|
__name(createHeaders, "createHeaders");
|
|
2938
2936
|
|
|
2939
2937
|
// src/lib/runtime/remote-actions.ts
|
|
2940
|
-
var
|
|
2938
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2941
2939
|
var EndpointType;
|
|
2942
2940
|
(function(EndpointType2) {
|
|
2943
2941
|
EndpointType2["CopilotKit"] = "copilotKit";
|
|
@@ -2971,7 +2969,7 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2971
2969
|
status: response.status,
|
|
2972
2970
|
body: await response.text()
|
|
2973
2971
|
}, "Failed to fetch actions from url");
|
|
2974
|
-
throw new
|
|
2972
|
+
throw new import_shared14.ResolvedCopilotKitError({
|
|
2975
2973
|
status: response.status,
|
|
2976
2974
|
url: fetchUrl,
|
|
2977
2975
|
isRemoteEndpoint: true
|
|
@@ -2983,10 +2981,10 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
|
|
|
2983
2981
|
}, "Fetched actions from url");
|
|
2984
2982
|
return json;
|
|
2985
2983
|
} catch (error) {
|
|
2986
|
-
if (error instanceof
|
|
2984
|
+
if (error instanceof import_shared14.CopilotKitError) {
|
|
2987
2985
|
throw error;
|
|
2988
2986
|
}
|
|
2989
|
-
throw new
|
|
2987
|
+
throw new import_shared14.CopilotKitLowLevelError({
|
|
2990
2988
|
error,
|
|
2991
2989
|
url: fetchUrl
|
|
2992
2990
|
});
|
|
@@ -3049,7 +3047,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
3049
3047
|
// src/lib/telemetry-client.ts
|
|
3050
3048
|
var import_node_crypto3 = require("crypto");
|
|
3051
3049
|
var packageJson = require_package();
|
|
3052
|
-
var telemetryClient = new
|
|
3050
|
+
var telemetryClient = new import_shared15.TelemetryClient({
|
|
3053
3051
|
packageName: packageJson.name,
|
|
3054
3052
|
packageVersion: packageJson.version
|
|
3055
3053
|
});
|
|
@@ -3366,10 +3364,10 @@ var RuntimeEventSource = class {
|
|
|
3366
3364
|
const errorMessage = `\u274C ${message}`;
|
|
3367
3365
|
if (!this.callback) {
|
|
3368
3366
|
this.stream(async (eventStream$) => {
|
|
3369
|
-
eventStream$.sendTextMessage((0,
|
|
3367
|
+
eventStream$.sendTextMessage((0, import_shared16.randomId)(), errorMessage);
|
|
3370
3368
|
});
|
|
3371
3369
|
} else {
|
|
3372
|
-
this.eventStream$.sendTextMessage((0,
|
|
3370
|
+
this.eventStream$.sendTextMessage((0, import_shared16.randomId)(), errorMessage);
|
|
3373
3371
|
}
|
|
3374
3372
|
}
|
|
3375
3373
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents, threadId }) {
|
|
@@ -3528,6 +3526,7 @@ __name(executeAction, "executeAction");
|
|
|
3528
3526
|
|
|
3529
3527
|
// src/service-adapters/conversion.ts
|
|
3530
3528
|
var import_class_transformer2 = require("class-transformer");
|
|
3529
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
3531
3530
|
function convertGqlInputToMessages(inputMessages) {
|
|
3532
3531
|
const messages = [];
|
|
3533
3532
|
for (const message of inputMessages) {
|
|
@@ -3544,7 +3543,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3544
3543
|
id: message.id,
|
|
3545
3544
|
createdAt: message.createdAt,
|
|
3546
3545
|
name: message.actionExecutionMessage.name,
|
|
3547
|
-
arguments:
|
|
3546
|
+
arguments: (0, import_shared17.parseJson)(message.actionExecutionMessage.arguments, {}),
|
|
3548
3547
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3549
3548
|
}));
|
|
3550
3549
|
} else if (message.resultMessage) {
|
|
@@ -3565,7 +3564,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3565
3564
|
runId: message.agentStateMessage.runId,
|
|
3566
3565
|
active: message.agentStateMessage.active,
|
|
3567
3566
|
role: message.agentStateMessage.role,
|
|
3568
|
-
state:
|
|
3567
|
+
state: (0, import_shared17.parseJson)(message.agentStateMessage.state, {}),
|
|
3569
3568
|
running: message.agentStateMessage.running
|
|
3570
3569
|
}));
|
|
3571
3570
|
}
|
|
@@ -3605,7 +3604,7 @@ var CopilotRuntime = class {
|
|
|
3605
3604
|
return await this.processAgentRequest(request);
|
|
3606
3605
|
}
|
|
3607
3606
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3608
|
-
throw new
|
|
3607
|
+
throw new import_shared18.CopilotKitMisuseError({
|
|
3609
3608
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3610
3609
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3611
3610
|
please use an LLM adapter instead.`
|
|
@@ -3617,7 +3616,7 @@ please use an LLM adapter instead.`
|
|
|
3617
3616
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3618
3617
|
name: action.name,
|
|
3619
3618
|
description: action.description,
|
|
3620
|
-
jsonSchema: JSON.stringify((0,
|
|
3619
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3621
3620
|
}));
|
|
3622
3621
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3623
3622
|
...serverSideActionsInput,
|
|
@@ -3669,7 +3668,7 @@ please use an LLM adapter instead.`
|
|
|
3669
3668
|
extensions: result.extensions
|
|
3670
3669
|
};
|
|
3671
3670
|
} catch (error) {
|
|
3672
|
-
if (error instanceof
|
|
3671
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3673
3672
|
throw error;
|
|
3674
3673
|
}
|
|
3675
3674
|
console.error("Error getting response:", error);
|
|
@@ -3715,11 +3714,11 @@ please use an LLM adapter instead.`
|
|
|
3715
3714
|
});
|
|
3716
3715
|
if (!response.ok) {
|
|
3717
3716
|
if (response.status === 404) {
|
|
3718
|
-
throw new
|
|
3717
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3719
3718
|
url: fetchUrl
|
|
3720
3719
|
});
|
|
3721
3720
|
}
|
|
3722
|
-
throw new
|
|
3721
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3723
3722
|
status: response.status,
|
|
3724
3723
|
url: fetchUrl,
|
|
3725
3724
|
isRemoteEndpoint: true
|
|
@@ -3729,7 +3728,7 @@ please use an LLM adapter instead.`
|
|
|
3729
3728
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
3730
3729
|
name: agent.name,
|
|
3731
3730
|
description: agent.description ?? "" ?? "",
|
|
3732
|
-
id: (0,
|
|
3731
|
+
id: (0, import_shared18.randomId)(),
|
|
3733
3732
|
endpoint
|
|
3734
3733
|
}));
|
|
3735
3734
|
return [
|
|
@@ -3737,10 +3736,10 @@ please use an LLM adapter instead.`
|
|
|
3737
3736
|
...endpointAgents
|
|
3738
3737
|
];
|
|
3739
3738
|
} catch (error) {
|
|
3740
|
-
if (error instanceof
|
|
3739
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3741
3740
|
throw error;
|
|
3742
3741
|
}
|
|
3743
|
-
throw new
|
|
3742
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3744
3743
|
error,
|
|
3745
3744
|
url: fetchUrl
|
|
3746
3745
|
});
|
|
@@ -3802,11 +3801,11 @@ please use an LLM adapter instead.`
|
|
|
3802
3801
|
});
|
|
3803
3802
|
if (!response.ok) {
|
|
3804
3803
|
if (response.status === 404) {
|
|
3805
|
-
throw new
|
|
3804
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3806
3805
|
url: fetchUrl
|
|
3807
3806
|
});
|
|
3808
3807
|
}
|
|
3809
|
-
throw new
|
|
3808
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3810
3809
|
status: response.status,
|
|
3811
3810
|
url: fetchUrl,
|
|
3812
3811
|
isRemoteEndpoint: true
|
|
@@ -3819,10 +3818,10 @@ please use an LLM adapter instead.`
|
|
|
3819
3818
|
messages: JSON.stringify(data.messages)
|
|
3820
3819
|
};
|
|
3821
3820
|
} catch (error) {
|
|
3822
|
-
if (error instanceof
|
|
3821
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3823
3822
|
throw error;
|
|
3824
3823
|
}
|
|
3825
|
-
throw new
|
|
3824
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3826
3825
|
error,
|
|
3827
3826
|
url: fetchUrl
|
|
3828
3827
|
});
|
|
@@ -3840,7 +3839,7 @@ please use an LLM adapter instead.`
|
|
|
3840
3839
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
3841
3840
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
3842
3841
|
if (!currentAgent) {
|
|
3843
|
-
throw new
|
|
3842
|
+
throw new import_shared18.CopilotKitAgentDiscoveryError({
|
|
3844
3843
|
agentName
|
|
3845
3844
|
});
|
|
3846
3845
|
}
|
|
@@ -3851,7 +3850,7 @@ please use an LLM adapter instead.`
|
|
|
3851
3850
|
)).map((action) => ({
|
|
3852
3851
|
name: action.name,
|
|
3853
3852
|
description: action.description,
|
|
3854
|
-
jsonSchema: JSON.stringify((0,
|
|
3853
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3855
3854
|
}));
|
|
3856
3855
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
3857
3856
|
...availableActionsForCurrentAgent,
|
|
@@ -4776,7 +4775,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
4776
4775
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
4777
4776
|
|
|
4778
4777
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4779
|
-
var
|
|
4778
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
4780
4779
|
|
|
4781
4780
|
// src/graphql/types/agents-response.type.ts
|
|
4782
4781
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -4959,7 +4958,7 @@ var CopilotResolver = class {
|
|
|
4959
4958
|
rejectOutputMessagesPromise = reject;
|
|
4960
4959
|
});
|
|
4961
4960
|
logger2.debug("Processing");
|
|
4962
|
-
const { eventSource, threadId = (0,
|
|
4961
|
+
const { eventSource, threadId = (0, import_shared19.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
4963
4962
|
serviceAdapter,
|
|
4964
4963
|
messages: data.messages,
|
|
4965
4964
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5092,7 +5091,7 @@ var CopilotResolver = class {
|
|
|
5092
5091
|
});
|
|
5093
5092
|
outputMessages = [
|
|
5094
5093
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5095
|
-
id: (0,
|
|
5094
|
+
id: (0, import_shared19.randomId)(),
|
|
5096
5095
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5097
5096
|
content: result.reason,
|
|
5098
5097
|
role: MessageRole.assistant
|
|
@@ -5270,7 +5269,7 @@ var CopilotResolver = class {
|
|
|
5270
5269
|
event
|
|
5271
5270
|
}, "Agent message event received");
|
|
5272
5271
|
pushMessage({
|
|
5273
|
-
id: (0,
|
|
5272
|
+
id: (0, import_shared19.randomId)(),
|
|
5274
5273
|
status: new SuccessMessageStatus(),
|
|
5275
5274
|
threadId: event.threadId,
|
|
5276
5275
|
agentName: event.agentName,
|
|
@@ -5283,7 +5282,7 @@ var CopilotResolver = class {
|
|
|
5283
5282
|
createdAt: /* @__PURE__ */ new Date()
|
|
5284
5283
|
});
|
|
5285
5284
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5286
|
-
id: (0,
|
|
5285
|
+
id: (0, import_shared19.randomId)(),
|
|
5287
5286
|
threadId: event.threadId,
|
|
5288
5287
|
agentName: event.agentName,
|
|
5289
5288
|
nodeName: event.nodeName,
|