@copilotkit/runtime 1.6.0-next.3 → 1.6.0-next.5
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 +15 -0
- package/dist/{chunk-25Z2ZUVM.mjs → chunk-3C73PW47.mjs} +2 -2
- package/dist/{chunk-OS5YD32G.mjs → chunk-7EXH7PVD.mjs} +3 -2
- package/dist/chunk-7EXH7PVD.mjs.map +1 -0
- package/dist/{chunk-J6E3ZTJ3.mjs → chunk-F6WKKTYT.mjs} +29 -31
- package/dist/chunk-F6WKKTYT.mjs.map +1 -0
- package/dist/{chunk-7HPGWUP7.mjs → chunk-I6W6FUR5.mjs} +2 -2
- package/dist/{chunk-ZM4JOETB.mjs → chunk-RG3UJM7Q.mjs} +2 -2
- package/dist/index.js +99 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/lib/index.js +92 -93
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- 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 +9 -7
- package/src/lib/runtime/remote-lg-action.ts +2 -6
- package/src/service-adapters/conversion.ts +39 -46
- 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-25Z2ZUVM.mjs.map → chunk-3C73PW47.mjs.map} +0 -0
- /package/dist/{chunk-7HPGWUP7.mjs.map → chunk-I6W6FUR5.mjs.map} +0 -0
- /package/dist/{chunk-ZM4JOETB.mjs.map → chunk-RG3UJM7Q.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-3C73PW47.mjs";
|
|
7
7
|
import {
|
|
8
8
|
copilotRuntimeNestEndpoint
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RG3UJM7Q.mjs";
|
|
10
10
|
import {
|
|
11
11
|
copilotRuntimeNodeExpressEndpoint
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-I6W6FUR5.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CopilotRuntime,
|
|
15
15
|
addCustomHeaderPlugin,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
getCommonConfig,
|
|
22
22
|
langGraphPlatformEndpoint,
|
|
23
23
|
resolveEndpointType
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-F6WKKTYT.mjs";
|
|
25
25
|
import {
|
|
26
26
|
AnthropicAdapter,
|
|
27
27
|
EmptyAdapter,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
OpenAIAssistantAdapter,
|
|
35
35
|
RemoteChain,
|
|
36
36
|
UnifyAdapter
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-7EXH7PVD.mjs";
|
|
38
38
|
import {
|
|
39
39
|
GuardrailsValidationFailureResponse,
|
|
40
40
|
MessageStreamInterruptedResponse,
|
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.5",
|
|
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 {
|
|
@@ -2703,7 +2700,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
2703
2700
|
state,
|
|
2704
2701
|
configurable,
|
|
2705
2702
|
properties: graphqlContext.properties,
|
|
2706
|
-
actions:
|
|
2703
|
+
actions: (0, import_shared13.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
2707
2704
|
name: action.name,
|
|
2708
2705
|
description: action.description,
|
|
2709
2706
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -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`;
|
|
@@ -2832,7 +2829,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
2832
2829
|
state,
|
|
2833
2830
|
configurable,
|
|
2834
2831
|
properties: graphqlContext.properties,
|
|
2835
|
-
actions:
|
|
2832
|
+
actions: (0, import_shared13.tryMap)(actionInputsWithoutAgents, (action) => ({
|
|
2836
2833
|
name: action.name,
|
|
2837
2834
|
description: action.description,
|
|
2838
2835
|
parameters: JSON.parse(action.jsonSchema)
|
|
@@ -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,35 +3526,35 @@ __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
|
-
const messages =
|
|
3534
|
-
for (const message of inputMessages) {
|
|
3531
|
+
const messages = (0, import_shared17.tryMap)(inputMessages, (message) => {
|
|
3535
3532
|
if (message.textMessage) {
|
|
3536
|
-
|
|
3533
|
+
return (0, import_class_transformer2.plainToInstance)(TextMessage, {
|
|
3537
3534
|
id: message.id,
|
|
3538
3535
|
createdAt: message.createdAt,
|
|
3539
3536
|
role: message.textMessage.role,
|
|
3540
3537
|
content: message.textMessage.content,
|
|
3541
3538
|
parentMessageId: message.textMessage.parentMessageId
|
|
3542
|
-
})
|
|
3539
|
+
});
|
|
3543
3540
|
} else if (message.actionExecutionMessage) {
|
|
3544
|
-
|
|
3541
|
+
return (0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
|
|
3545
3542
|
id: message.id,
|
|
3546
3543
|
createdAt: message.createdAt,
|
|
3547
3544
|
name: message.actionExecutionMessage.name,
|
|
3548
3545
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
3549
3546
|
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
3550
|
-
})
|
|
3547
|
+
});
|
|
3551
3548
|
} else if (message.resultMessage) {
|
|
3552
|
-
|
|
3549
|
+
return (0, import_class_transformer2.plainToInstance)(ResultMessage, {
|
|
3553
3550
|
id: message.id,
|
|
3554
3551
|
createdAt: message.createdAt,
|
|
3555
3552
|
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
3556
3553
|
actionName: message.resultMessage.actionName,
|
|
3557
3554
|
result: message.resultMessage.result
|
|
3558
|
-
})
|
|
3555
|
+
});
|
|
3559
3556
|
} else if (message.agentStateMessage) {
|
|
3560
|
-
|
|
3557
|
+
return (0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
|
|
3561
3558
|
id: message.id,
|
|
3562
3559
|
threadId: message.agentStateMessage.threadId,
|
|
3563
3560
|
createdAt: message.createdAt,
|
|
@@ -3568,10 +3565,12 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
3568
3565
|
role: message.agentStateMessage.role,
|
|
3569
3566
|
state: JSON.parse(message.agentStateMessage.state),
|
|
3570
3567
|
running: message.agentStateMessage.running
|
|
3571
|
-
})
|
|
3568
|
+
});
|
|
3569
|
+
} else {
|
|
3570
|
+
return null;
|
|
3572
3571
|
}
|
|
3573
|
-
}
|
|
3574
|
-
return messages;
|
|
3572
|
+
});
|
|
3573
|
+
return messages.filter((m) => m);
|
|
3575
3574
|
}
|
|
3576
3575
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
3577
3576
|
|
|
@@ -3606,7 +3605,7 @@ var CopilotRuntime = class {
|
|
|
3606
3605
|
return await this.processAgentRequest(request);
|
|
3607
3606
|
}
|
|
3608
3607
|
if (serviceAdapter instanceof EmptyAdapter) {
|
|
3609
|
-
throw new
|
|
3608
|
+
throw new import_shared18.CopilotKitMisuseError({
|
|
3610
3609
|
message: `Invalid adapter configuration: EmptyAdapter is only meant to be used with agent lock mode.
|
|
3611
3610
|
For non-agent components like useCopilotChatSuggestions, CopilotTextarea, or CopilotTask,
|
|
3612
3611
|
please use an LLM adapter instead.`
|
|
@@ -3618,7 +3617,7 @@ please use an LLM adapter instead.`
|
|
|
3618
3617
|
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
3619
3618
|
name: action.name,
|
|
3620
3619
|
description: action.description,
|
|
3621
|
-
jsonSchema: JSON.stringify((0,
|
|
3620
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3622
3621
|
}));
|
|
3623
3622
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
3624
3623
|
...serverSideActionsInput,
|
|
@@ -3670,7 +3669,7 @@ please use an LLM adapter instead.`
|
|
|
3670
3669
|
extensions: result.extensions
|
|
3671
3670
|
};
|
|
3672
3671
|
} catch (error) {
|
|
3673
|
-
if (error instanceof
|
|
3672
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3674
3673
|
throw error;
|
|
3675
3674
|
}
|
|
3676
3675
|
console.error("Error getting response:", error);
|
|
@@ -3716,11 +3715,11 @@ please use an LLM adapter instead.`
|
|
|
3716
3715
|
});
|
|
3717
3716
|
if (!response.ok) {
|
|
3718
3717
|
if (response.status === 404) {
|
|
3719
|
-
throw new
|
|
3718
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3720
3719
|
url: fetchUrl
|
|
3721
3720
|
});
|
|
3722
3721
|
}
|
|
3723
|
-
throw new
|
|
3722
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3724
3723
|
status: response.status,
|
|
3725
3724
|
url: fetchUrl,
|
|
3726
3725
|
isRemoteEndpoint: true
|
|
@@ -3730,7 +3729,7 @@ please use an LLM adapter instead.`
|
|
|
3730
3729
|
const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
|
|
3731
3730
|
name: agent.name,
|
|
3732
3731
|
description: agent.description ?? "" ?? "",
|
|
3733
|
-
id: (0,
|
|
3732
|
+
id: (0, import_shared18.randomId)(),
|
|
3734
3733
|
endpoint
|
|
3735
3734
|
}));
|
|
3736
3735
|
return [
|
|
@@ -3738,10 +3737,10 @@ please use an LLM adapter instead.`
|
|
|
3738
3737
|
...endpointAgents
|
|
3739
3738
|
];
|
|
3740
3739
|
} catch (error) {
|
|
3741
|
-
if (error instanceof
|
|
3740
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3742
3741
|
throw error;
|
|
3743
3742
|
}
|
|
3744
|
-
throw new
|
|
3743
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3745
3744
|
error,
|
|
3746
3745
|
url: fetchUrl
|
|
3747
3746
|
});
|
|
@@ -3803,11 +3802,11 @@ please use an LLM adapter instead.`
|
|
|
3803
3802
|
});
|
|
3804
3803
|
if (!response.ok) {
|
|
3805
3804
|
if (response.status === 404) {
|
|
3806
|
-
throw new
|
|
3805
|
+
throw new import_shared18.CopilotKitApiDiscoveryError({
|
|
3807
3806
|
url: fetchUrl
|
|
3808
3807
|
});
|
|
3809
3808
|
}
|
|
3810
|
-
throw new
|
|
3809
|
+
throw new import_shared18.ResolvedCopilotKitError({
|
|
3811
3810
|
status: response.status,
|
|
3812
3811
|
url: fetchUrl,
|
|
3813
3812
|
isRemoteEndpoint: true
|
|
@@ -3820,10 +3819,10 @@ please use an LLM adapter instead.`
|
|
|
3820
3819
|
messages: JSON.stringify(data.messages)
|
|
3821
3820
|
};
|
|
3822
3821
|
} catch (error) {
|
|
3823
|
-
if (error instanceof
|
|
3822
|
+
if (error instanceof import_shared18.CopilotKitError) {
|
|
3824
3823
|
throw error;
|
|
3825
3824
|
}
|
|
3826
|
-
throw new
|
|
3825
|
+
throw new import_shared18.CopilotKitLowLevelError({
|
|
3827
3826
|
error,
|
|
3828
3827
|
url: fetchUrl
|
|
3829
3828
|
});
|
|
@@ -3841,7 +3840,7 @@ please use an LLM adapter instead.`
|
|
|
3841
3840
|
const messages = convertGqlInputToMessages(rawMessages);
|
|
3842
3841
|
const currentAgent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
3843
3842
|
if (!currentAgent) {
|
|
3844
|
-
throw new
|
|
3843
|
+
throw new import_shared18.CopilotKitAgentDiscoveryError({
|
|
3845
3844
|
agentName
|
|
3846
3845
|
});
|
|
3847
3846
|
}
|
|
@@ -3852,7 +3851,7 @@ please use an LLM adapter instead.`
|
|
|
3852
3851
|
)).map((action) => ({
|
|
3853
3852
|
name: action.name,
|
|
3854
3853
|
description: action.description,
|
|
3855
|
-
jsonSchema: JSON.stringify((0,
|
|
3854
|
+
jsonSchema: JSON.stringify((0, import_shared18.actionParametersToJsonSchema)(action.parameters))
|
|
3856
3855
|
}));
|
|
3857
3856
|
const allAvailableActions = flattenToolCallsNoDuplicates([
|
|
3858
3857
|
...availableActionsForCurrentAgent,
|
|
@@ -4777,7 +4776,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
4777
4776
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
4778
4777
|
|
|
4779
4778
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
4780
|
-
var
|
|
4779
|
+
var import_shared19 = require("@copilotkit/shared");
|
|
4781
4780
|
|
|
4782
4781
|
// src/graphql/types/agents-response.type.ts
|
|
4783
4782
|
var import_type_graphql19 = require("type-graphql");
|
|
@@ -4960,7 +4959,7 @@ var CopilotResolver = class {
|
|
|
4960
4959
|
rejectOutputMessagesPromise = reject;
|
|
4961
4960
|
});
|
|
4962
4961
|
logger2.debug("Processing");
|
|
4963
|
-
const { eventSource, threadId = (0,
|
|
4962
|
+
const { eventSource, threadId = (0, import_shared19.randomId)(), runId, serverSideActions, actionInputsWithoutAgents, extensions } = await copilotRuntime.processRuntimeRequest({
|
|
4964
4963
|
serviceAdapter,
|
|
4965
4964
|
messages: data.messages,
|
|
4966
4965
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -5093,7 +5092,7 @@ var CopilotResolver = class {
|
|
|
5093
5092
|
});
|
|
5094
5093
|
outputMessages = [
|
|
5095
5094
|
(0, import_class_transformer3.plainToInstance)(TextMessage, {
|
|
5096
|
-
id: (0,
|
|
5095
|
+
id: (0, import_shared19.randomId)(),
|
|
5097
5096
|
createdAt: /* @__PURE__ */ new Date(),
|
|
5098
5097
|
content: result.reason,
|
|
5099
5098
|
role: MessageRole.assistant
|
|
@@ -5271,7 +5270,7 @@ var CopilotResolver = class {
|
|
|
5271
5270
|
event
|
|
5272
5271
|
}, "Agent message event received");
|
|
5273
5272
|
pushMessage({
|
|
5274
|
-
id: (0,
|
|
5273
|
+
id: (0, import_shared19.randomId)(),
|
|
5275
5274
|
status: new SuccessMessageStatus(),
|
|
5276
5275
|
threadId: event.threadId,
|
|
5277
5276
|
agentName: event.agentName,
|
|
@@ -5284,7 +5283,7 @@ var CopilotResolver = class {
|
|
|
5284
5283
|
createdAt: /* @__PURE__ */ new Date()
|
|
5285
5284
|
});
|
|
5286
5285
|
outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
|
|
5287
|
-
id: (0,
|
|
5286
|
+
id: (0, import_shared19.randomId)(),
|
|
5288
5287
|
threadId: event.threadId,
|
|
5289
5288
|
agentName: event.agentName,
|
|
5290
5289
|
nodeName: event.nodeName,
|