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