@copilotkit/runtime 1.4.0-pre-1-4-0.11 → 1.4.0-pre-1-4-0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -100
- package/dist/{chunk-BNQDVBQH.mjs → chunk-56IQ6PGC.mjs} +449 -75
- package/dist/chunk-56IQ6PGC.mjs.map +1 -0
- package/dist/chunk-DFOKBSIS.mjs +1 -0
- package/dist/chunk-DFOKBSIS.mjs.map +1 -0
- package/dist/{chunk-VBGS6IWV.mjs → chunk-RDHJQVWH.mjs} +483 -71
- package/dist/chunk-RDHJQVWH.mjs.map +1 -0
- package/dist/{chunk-V2YEM4Z5.mjs → chunk-SBWLAAB3.mjs} +4 -3
- package/dist/chunk-SBWLAAB3.mjs.map +1 -0
- package/dist/{chunk-677K33J7.mjs → chunk-SVL5LEKB.mjs} +4 -3
- package/dist/chunk-SVL5LEKB.mjs.map +1 -0
- package/dist/{chunk-3DNY5YTL.mjs → chunk-YUJSVJWS.mjs} +5 -4
- package/dist/chunk-YUJSVJWS.mjs.map +1 -0
- package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-dbe5fa02.d.ts} +4 -4
- package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-192d2413.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +486 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -22
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f00629d2.d.ts → langserve-878c62b9.d.ts} +46 -9
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +465 -163
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +21 -21
- package/dist/lib/integrations/index.d.ts +3 -3
- package/dist/lib/integrations/index.js +161 -85
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +2 -2
- package/dist/lib/integrations/nest/index.js +158 -82
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +2 -2
- package/dist/lib/integrations/node-express/index.js +158 -82
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +2 -2
- package/dist/lib/integrations/node-http/index.js +157 -81
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +3 -3
- package/dist/service-adapters/index.js +243 -73
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -2
- package/package.json +4 -4
- package/src/agents/langgraph/event-source.ts +12 -0
- package/src/agents/langgraph/events.ts +2 -0
- package/src/graphql/resolvers/copilot.resolver.ts +28 -2
- package/src/lib/integrations/nest/index.ts +5 -2
- package/src/lib/integrations/nextjs/app-router.ts +5 -2
- package/src/lib/integrations/nextjs/pages-router.ts +5 -2
- package/src/lib/integrations/node-express/index.ts +5 -2
- package/src/lib/integrations/node-http/index.ts +5 -2
- package/src/lib/runtime/copilot-runtime.ts +48 -42
- package/src/lib/runtime/remote-action-constructors.ts +17 -3
- package/src/lib/runtime/remote-lg-cloud-action.ts +41 -15
- package/src/lib/telemetry-client.ts +43 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +15 -6
- package/src/service-adapters/events.ts +86 -36
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/google/google-genai-adapter.ts +2 -2
- package/src/service-adapters/groq/groq-adapter.ts +22 -8
- package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
- package/src/service-adapters/langchain/utils.ts +47 -31
- package/src/service-adapters/openai/openai-adapter.ts +25 -8
- package/src/service-adapters/openai/openai-assistant-adapter.ts +21 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-3DNY5YTL.mjs.map +0 -1
- package/dist/chunk-677K33J7.mjs.map +0 -1
- package/dist/chunk-BNQDVBQH.mjs.map +0 -1
- package/dist/chunk-FL67XJAX.mjs +0 -288
- package/dist/chunk-FL67XJAX.mjs.map +0 -1
- package/dist/chunk-MXXPWWBF.mjs +0 -218
- package/dist/chunk-MXXPWWBF.mjs.map +0 -1
- package/dist/chunk-V2YEM4Z5.mjs.map +0 -1
- package/dist/chunk-VBGS6IWV.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
RemoteChain,
|
|
2
3
|
streamLangChainResponse
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-56IQ6PGC.mjs";
|
|
4
5
|
import {
|
|
5
6
|
GuardrailsValidationFailureResponse,
|
|
6
7
|
MessageStreamInterruptedResponse,
|
|
@@ -36,7 +37,7 @@ var require_package = __commonJS({
|
|
|
36
37
|
publishConfig: {
|
|
37
38
|
access: "public"
|
|
38
39
|
},
|
|
39
|
-
version: "1.4.0-pre-1-4-0.
|
|
40
|
+
version: "1.4.0-pre-1-4-0-alpha.10",
|
|
40
41
|
sideEffects: false,
|
|
41
42
|
main: "./dist/index.js",
|
|
42
43
|
module: "./dist/index.mjs",
|
|
@@ -121,7 +122,7 @@ import { buildSchemaSync } from "type-graphql";
|
|
|
121
122
|
|
|
122
123
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
123
124
|
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
|
|
124
|
-
import { ReplaySubject as ReplaySubject3, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
125
|
+
import { ReplaySubject as ReplaySubject3, Subject, filter, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
125
126
|
|
|
126
127
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
127
128
|
import { Field as Field9, InputType as InputType9 } from "type-graphql";
|
|
@@ -1023,16 +1024,14 @@ CopilotResponse = _ts_decorate11([
|
|
|
1023
1024
|
import { Repeater } from "graphql-yoga";
|
|
1024
1025
|
|
|
1025
1026
|
// src/service-adapters/events.ts
|
|
1026
|
-
import {
|
|
1027
|
+
import { randomId as randomId3 } from "@copilotkit/shared";
|
|
1028
|
+
import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1027
1029
|
|
|
1028
1030
|
// src/lib/telemetry-client.ts
|
|
1029
1031
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
packageVersion: packageJson.version
|
|
1034
|
-
});
|
|
1035
|
-
var telemetry_client_default = telemetryClient;
|
|
1032
|
+
|
|
1033
|
+
// src/lib/runtime/remote-action-constructors.ts
|
|
1034
|
+
import { createHash as createHash2 } from "crypto";
|
|
1036
1035
|
|
|
1037
1036
|
// src/agents/langgraph/event-source.ts
|
|
1038
1037
|
import { ReplaySubject, scan, mergeMap, catchError } from "rxjs";
|
|
@@ -1049,6 +1048,8 @@ var LangGraphEventTypes;
|
|
|
1049
1048
|
LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
|
|
1050
1049
|
LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
|
|
1051
1050
|
LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
|
|
1051
|
+
LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
|
|
1052
|
+
LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
|
|
1052
1053
|
LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
|
|
1053
1054
|
})(LangGraphEventTypes || (LangGraphEventTypes = {}));
|
|
1054
1055
|
var CustomEventNames;
|
|
@@ -1142,12 +1143,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1142
1143
|
}
|
|
1143
1144
|
if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1144
1145
|
events.push({
|
|
1145
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1146
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1147
|
+
actionExecutionId: eventWithState.prevToolCallMessageId
|
|
1146
1148
|
});
|
|
1147
1149
|
}
|
|
1148
1150
|
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1149
1151
|
events.push({
|
|
1150
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1152
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1153
|
+
messageId: eventWithState.prevMessageId
|
|
1151
1154
|
});
|
|
1152
1155
|
}
|
|
1153
1156
|
switch (eventWithState.event.event) {
|
|
@@ -1159,10 +1162,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1159
1162
|
});
|
|
1160
1163
|
events.push({
|
|
1161
1164
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1165
|
+
messageId: eventWithState.event.data.message_id,
|
|
1162
1166
|
content: eventWithState.event.data.message
|
|
1163
1167
|
});
|
|
1164
1168
|
events.push({
|
|
1165
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1169
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1170
|
+
messageId: eventWithState.event.data.message_id
|
|
1166
1171
|
});
|
|
1167
1172
|
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1168
1173
|
events.push({
|
|
@@ -1172,10 +1177,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1172
1177
|
});
|
|
1173
1178
|
events.push({
|
|
1174
1179
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1180
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1175
1181
|
args: JSON.stringify(eventWithState.event.data.args)
|
|
1176
1182
|
});
|
|
1177
1183
|
events.push({
|
|
1178
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1184
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1185
|
+
actionExecutionId: eventWithState.event.data.id
|
|
1179
1186
|
});
|
|
1180
1187
|
}
|
|
1181
1188
|
break;
|
|
@@ -1219,6 +1226,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1219
1226
|
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1220
1227
|
events.push({
|
|
1221
1228
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1229
|
+
actionExecutionId: eventWithState.toolCallMessageId,
|
|
1222
1230
|
args
|
|
1223
1231
|
});
|
|
1224
1232
|
}
|
|
@@ -1226,6 +1234,7 @@ var RemoteLangGraphEventSource = class {
|
|
|
1226
1234
|
if (shouldEmitMessages) {
|
|
1227
1235
|
events.push({
|
|
1228
1236
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1237
|
+
messageId: eventWithState.messageId,
|
|
1229
1238
|
content
|
|
1230
1239
|
});
|
|
1231
1240
|
}
|
|
@@ -1238,12 +1247,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1238
1247
|
const events = [];
|
|
1239
1248
|
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1240
1249
|
events.push({
|
|
1241
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1250
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1251
|
+
messageId: lastEventWithState.messageId
|
|
1242
1252
|
});
|
|
1243
1253
|
}
|
|
1244
1254
|
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1245
1255
|
events.push({
|
|
1246
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1256
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1257
|
+
actionExecutionId: lastEventWithState.toolCallMessageId
|
|
1247
1258
|
});
|
|
1248
1259
|
}
|
|
1249
1260
|
const messageId = randomId();
|
|
@@ -1253,10 +1264,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1253
1264
|
});
|
|
1254
1265
|
events.push({
|
|
1255
1266
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1267
|
+
messageId,
|
|
1256
1268
|
content: "\u274C An error occurred. Please try again."
|
|
1257
1269
|
});
|
|
1258
1270
|
events.push({
|
|
1259
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1271
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1272
|
+
messageId
|
|
1260
1273
|
});
|
|
1261
1274
|
return events;
|
|
1262
1275
|
}));
|
|
@@ -1266,7 +1279,7 @@ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
|
|
|
1266
1279
|
|
|
1267
1280
|
// src/lib/runtime/remote-lg-cloud-action.ts
|
|
1268
1281
|
import { Client } from "@langchain/langgraph-sdk";
|
|
1269
|
-
import { randomUUID } from "crypto";
|
|
1282
|
+
import { createHash, randomUUID } from "crypto";
|
|
1270
1283
|
import { parse as parsePartialJson } from "partial-json";
|
|
1271
1284
|
async function execute(args) {
|
|
1272
1285
|
return new ReadableStream({
|
|
@@ -1281,6 +1294,7 @@ async function execute(args) {
|
|
|
1281
1294
|
}
|
|
1282
1295
|
__name(execute, "execute");
|
|
1283
1296
|
async function streamEvents(controller, args) {
|
|
1297
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1284
1298
|
const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions, logger: logger2 } = args;
|
|
1285
1299
|
let nodeName = initialNodeName;
|
|
1286
1300
|
let state = initialState;
|
|
@@ -1354,7 +1368,14 @@ async function streamEvents(controller, args) {
|
|
|
1354
1368
|
const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
|
|
1355
1369
|
let latestStateValues = {};
|
|
1356
1370
|
let updatedState = state;
|
|
1371
|
+
let manuallyEmittedState = null;
|
|
1372
|
+
let streamInfo = {
|
|
1373
|
+
hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
|
|
1374
|
+
};
|
|
1357
1375
|
try {
|
|
1376
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1377
|
+
hashedLgcKey: streamInfo.hashedLgcKey
|
|
1378
|
+
});
|
|
1358
1379
|
for await (const chunk of streamResponse2) {
|
|
1359
1380
|
if (![
|
|
1360
1381
|
"events",
|
|
@@ -1376,26 +1397,37 @@ async function streamEvents(controller, args) {
|
|
|
1376
1397
|
const runId = event.metadata.run_id;
|
|
1377
1398
|
externalRunId = runId;
|
|
1378
1399
|
const metadata = event.metadata;
|
|
1400
|
+
if (((_b = (_a = event.data) == null ? void 0 : _a.output) == null ? void 0 : _b.model) != null && ((_d = (_c = event.data) == null ? void 0 : _c.output) == null ? void 0 : _d.model) != "") {
|
|
1401
|
+
streamInfo.provider = (_f = (_e = event.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
|
|
1402
|
+
}
|
|
1403
|
+
if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
|
|
1404
|
+
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
1405
|
+
}
|
|
1406
|
+
if (metadata.langgraph_version != null && metadata.langgraph_version != "") {
|
|
1407
|
+
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
1408
|
+
}
|
|
1379
1409
|
shouldExit = shouldExit || eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitExit;
|
|
1380
1410
|
const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
|
|
1381
1411
|
const manuallyEmitIntermediateState = eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
|
|
1412
|
+
const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
|
|
1413
|
+
if (exitingNode) {
|
|
1414
|
+
manuallyEmittedState = null;
|
|
1415
|
+
}
|
|
1382
1416
|
if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
|
|
1383
1417
|
nodeName = currentNodeName;
|
|
1384
|
-
if (eventType === LangGraphEventTypes.OnChainStart || eventType === LangGraphEventTypes.OnChainEnd) {
|
|
1385
|
-
updatedState = latestStateValues;
|
|
1386
|
-
}
|
|
1387
1418
|
}
|
|
1419
|
+
updatedState = manuallyEmittedState ?? latestStateValues;
|
|
1388
1420
|
if (!nodeName) {
|
|
1389
1421
|
continue;
|
|
1390
1422
|
}
|
|
1391
1423
|
if (manuallyEmitIntermediateState) {
|
|
1392
|
-
|
|
1424
|
+
manuallyEmittedState = event.data;
|
|
1393
1425
|
emit(getStateSyncEvent({
|
|
1394
1426
|
threadId,
|
|
1395
1427
|
runId,
|
|
1396
1428
|
agentName: agent.name,
|
|
1397
1429
|
nodeName,
|
|
1398
|
-
state:
|
|
1430
|
+
state: manuallyEmittedState,
|
|
1399
1431
|
running: true,
|
|
1400
1432
|
active: true
|
|
1401
1433
|
}));
|
|
@@ -1419,7 +1451,6 @@ async function streamEvents(controller, args) {
|
|
|
1419
1451
|
if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === LangGraphEventTypes.OnChainEnd) {
|
|
1420
1452
|
emitIntermediateStateUntilEnd = null;
|
|
1421
1453
|
}
|
|
1422
|
-
const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
|
|
1423
1454
|
if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
|
|
1424
1455
|
state = updatedState;
|
|
1425
1456
|
prevNodeName = nodeName;
|
|
@@ -1438,6 +1469,7 @@ async function streamEvents(controller, args) {
|
|
|
1438
1469
|
state = await client.threads.getState(threadId);
|
|
1439
1470
|
const isEndNode = state.next.length === 0;
|
|
1440
1471
|
nodeName = Object.keys(state.metadata.writes)[0];
|
|
1472
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
|
|
1441
1473
|
emit(getStateSyncEvent({
|
|
1442
1474
|
threadId,
|
|
1443
1475
|
runId: externalRunId,
|
|
@@ -1685,7 +1717,12 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1685
1717
|
logger2.debug({
|
|
1686
1718
|
actionName: agent.name
|
|
1687
1719
|
}, "Executing LangGraph Cloud agent");
|
|
1688
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1720
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1721
|
+
agentExecution: true,
|
|
1722
|
+
type: "langgraph-cloud",
|
|
1723
|
+
agentsAmount: endpoint.agents.length,
|
|
1724
|
+
hashedLgcKey: createHash2("sha256").update(endpoint.langsmithApiKey).digest("hex")
|
|
1725
|
+
});
|
|
1689
1726
|
let state = {};
|
|
1690
1727
|
if (agentStates) {
|
|
1691
1728
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -1739,7 +1776,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1739
1776
|
args
|
|
1740
1777
|
}, "Executing remote action");
|
|
1741
1778
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1742
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1779
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1780
|
+
agentExecution: false,
|
|
1781
|
+
type: "self-hosted",
|
|
1782
|
+
agentsAmount: json["agents"].length
|
|
1783
|
+
});
|
|
1743
1784
|
try {
|
|
1744
1785
|
const response = await fetch(`${url}/actions/execute`, {
|
|
1745
1786
|
method: "POST",
|
|
@@ -1785,7 +1826,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1785
1826
|
actionName: agent.name
|
|
1786
1827
|
}, "Executing remote agent");
|
|
1787
1828
|
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1788
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1829
|
+
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1830
|
+
agentExecution: true,
|
|
1831
|
+
type: "self-hosted",
|
|
1832
|
+
agentsAmount: json["agents"].length
|
|
1833
|
+
});
|
|
1789
1834
|
let state = {};
|
|
1790
1835
|
if (agentStates) {
|
|
1791
1836
|
const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
|
|
@@ -1996,6 +2041,329 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
|
|
|
1996
2041
|
}
|
|
1997
2042
|
__name(setupRemoteActions, "setupRemoteActions");
|
|
1998
2043
|
|
|
2044
|
+
// src/lib/telemetry-client.ts
|
|
2045
|
+
import { createHash as createHash3 } from "crypto";
|
|
2046
|
+
|
|
2047
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2048
|
+
import { actionParametersToJsonSchema, randomId as randomId2 } from "@copilotkit/shared";
|
|
2049
|
+
|
|
2050
|
+
// src/service-adapters/conversion.ts
|
|
2051
|
+
import { plainToInstance } from "class-transformer";
|
|
2052
|
+
function convertGqlInputToMessages(inputMessages) {
|
|
2053
|
+
const messages = [];
|
|
2054
|
+
for (const message of inputMessages) {
|
|
2055
|
+
if (message.textMessage) {
|
|
2056
|
+
messages.push(plainToInstance(TextMessage, {
|
|
2057
|
+
id: message.id,
|
|
2058
|
+
createdAt: message.createdAt,
|
|
2059
|
+
role: message.textMessage.role,
|
|
2060
|
+
content: message.textMessage.content
|
|
2061
|
+
}));
|
|
2062
|
+
} else if (message.actionExecutionMessage) {
|
|
2063
|
+
messages.push(plainToInstance(ActionExecutionMessage, {
|
|
2064
|
+
id: message.id,
|
|
2065
|
+
createdAt: message.createdAt,
|
|
2066
|
+
name: message.actionExecutionMessage.name,
|
|
2067
|
+
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2068
|
+
scope: message.actionExecutionMessage.scope
|
|
2069
|
+
}));
|
|
2070
|
+
} else if (message.resultMessage) {
|
|
2071
|
+
messages.push(plainToInstance(ResultMessage, {
|
|
2072
|
+
id: message.id,
|
|
2073
|
+
createdAt: message.createdAt,
|
|
2074
|
+
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
2075
|
+
actionName: message.resultMessage.actionName,
|
|
2076
|
+
result: message.resultMessage.result
|
|
2077
|
+
}));
|
|
2078
|
+
} else if (message.agentStateMessage) {
|
|
2079
|
+
messages.push(plainToInstance(AgentStateMessage, {
|
|
2080
|
+
id: message.id,
|
|
2081
|
+
threadId: message.agentStateMessage.threadId,
|
|
2082
|
+
createdAt: message.createdAt,
|
|
2083
|
+
agentName: message.agentStateMessage.agentName,
|
|
2084
|
+
nodeName: message.agentStateMessage.nodeName,
|
|
2085
|
+
runId: message.agentStateMessage.runId,
|
|
2086
|
+
active: message.agentStateMessage.active,
|
|
2087
|
+
role: message.agentStateMessage.role,
|
|
2088
|
+
state: JSON.parse(message.agentStateMessage.state),
|
|
2089
|
+
running: message.agentStateMessage.running
|
|
2090
|
+
}));
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return messages;
|
|
2094
|
+
}
|
|
2095
|
+
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
2096
|
+
|
|
2097
|
+
// src/lib/runtime/copilot-runtime.ts
|
|
2098
|
+
import { from } from "rxjs";
|
|
2099
|
+
var CopilotRuntime = class {
|
|
2100
|
+
actions;
|
|
2101
|
+
remoteEndpointDefinitions;
|
|
2102
|
+
langserve = [];
|
|
2103
|
+
onBeforeRequest;
|
|
2104
|
+
onAfterRequest;
|
|
2105
|
+
constructor(params) {
|
|
2106
|
+
var _a, _b;
|
|
2107
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
2108
|
+
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
2109
|
+
const remoteChain = new RemoteChain(chain);
|
|
2110
|
+
this.langserve.push(remoteChain.toAction());
|
|
2111
|
+
}
|
|
2112
|
+
this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) ?? (params == null ? void 0 : params.remoteActions) ?? [];
|
|
2113
|
+
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
2114
|
+
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
2115
|
+
}
|
|
2116
|
+
async processRuntimeRequest(request) {
|
|
2117
|
+
var _a;
|
|
2118
|
+
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, agentSession, url } = request;
|
|
2119
|
+
const eventSource = new RuntimeEventSource();
|
|
2120
|
+
try {
|
|
2121
|
+
if (agentSession) {
|
|
2122
|
+
return await this.processAgentRequest(request);
|
|
2123
|
+
}
|
|
2124
|
+
const messages = rawMessages.filter((message) => !message.agentStateMessage);
|
|
2125
|
+
const inputMessages = convertGqlInputToMessages(messages);
|
|
2126
|
+
const serverSideActions = await this.getServerSideActions(request);
|
|
2127
|
+
const serverSideActionsInput = serverSideActions.map((action) => ({
|
|
2128
|
+
name: action.name,
|
|
2129
|
+
description: action.description,
|
|
2130
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters))
|
|
2131
|
+
}));
|
|
2132
|
+
const actionInputs = flattenToolCallsNoDuplicates([
|
|
2133
|
+
...serverSideActionsInput,
|
|
2134
|
+
...clientSideActionsInput
|
|
2135
|
+
]);
|
|
2136
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2137
|
+
threadId,
|
|
2138
|
+
runId,
|
|
2139
|
+
inputMessages,
|
|
2140
|
+
properties: graphqlContext.properties,
|
|
2141
|
+
url
|
|
2142
|
+
}));
|
|
2143
|
+
const result = await serviceAdapter.process({
|
|
2144
|
+
messages: inputMessages,
|
|
2145
|
+
actions: actionInputs,
|
|
2146
|
+
threadId,
|
|
2147
|
+
runId,
|
|
2148
|
+
eventSource,
|
|
2149
|
+
forwardedParameters
|
|
2150
|
+
});
|
|
2151
|
+
outputMessagesPromise.then((outputMessages) => {
|
|
2152
|
+
var _a2;
|
|
2153
|
+
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
2154
|
+
threadId: result.threadId,
|
|
2155
|
+
runId: result.runId,
|
|
2156
|
+
inputMessages,
|
|
2157
|
+
outputMessages,
|
|
2158
|
+
properties: graphqlContext.properties,
|
|
2159
|
+
url
|
|
2160
|
+
});
|
|
2161
|
+
}).catch((_error) => {
|
|
2162
|
+
});
|
|
2163
|
+
return {
|
|
2164
|
+
threadId: result.threadId,
|
|
2165
|
+
runId: result.runId,
|
|
2166
|
+
eventSource,
|
|
2167
|
+
serverSideActions,
|
|
2168
|
+
actionInputsWithoutAgents: actionInputs.filter((action) => (
|
|
2169
|
+
// TODO-AGENTS: do not exclude ALL server side actions
|
|
2170
|
+
!serverSideActions.find((serverSideAction) => serverSideAction.name == action.name)
|
|
2171
|
+
))
|
|
2172
|
+
};
|
|
2173
|
+
} catch (error) {
|
|
2174
|
+
console.error("Error getting response:", error);
|
|
2175
|
+
eventSource.sendErrorMessageToChat();
|
|
2176
|
+
return {
|
|
2177
|
+
threadId: threadId || randomId2(),
|
|
2178
|
+
runId: runId || randomId2(),
|
|
2179
|
+
eventSource,
|
|
2180
|
+
serverSideActions: [],
|
|
2181
|
+
actionInputsWithoutAgents: []
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
async processAgentRequest(request) {
|
|
2186
|
+
var _a;
|
|
2187
|
+
const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
|
|
2188
|
+
const { threadId, agentName, nodeName } = agentSession;
|
|
2189
|
+
const serverSideActions = await this.getServerSideActions(request);
|
|
2190
|
+
const messages = convertGqlInputToMessages(rawMessages);
|
|
2191
|
+
const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
|
|
2192
|
+
if (!agent) {
|
|
2193
|
+
throw new Error(`Agent ${agentName} not found`);
|
|
2194
|
+
}
|
|
2195
|
+
const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
|
|
2196
|
+
name: action.name,
|
|
2197
|
+
description: action.description,
|
|
2198
|
+
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters))
|
|
2199
|
+
}));
|
|
2200
|
+
const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
|
|
2201
|
+
...serverSideActionsInput,
|
|
2202
|
+
...request.actions
|
|
2203
|
+
]);
|
|
2204
|
+
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
2205
|
+
threadId,
|
|
2206
|
+
runId: void 0,
|
|
2207
|
+
inputMessages: messages,
|
|
2208
|
+
properties: graphqlContext.properties
|
|
2209
|
+
}));
|
|
2210
|
+
try {
|
|
2211
|
+
const eventSource = new RuntimeEventSource();
|
|
2212
|
+
const stream = await agent.langGraphAgentHandler({
|
|
2213
|
+
name: agentName,
|
|
2214
|
+
threadId,
|
|
2215
|
+
nodeName,
|
|
2216
|
+
actionInputsWithoutAgents
|
|
2217
|
+
});
|
|
2218
|
+
eventSource.stream(async (eventStream$) => {
|
|
2219
|
+
from(stream).subscribe({
|
|
2220
|
+
next: (event) => eventStream$.next(event),
|
|
2221
|
+
error: (err) => console.error("Error in stream", err),
|
|
2222
|
+
complete: () => eventStream$.complete()
|
|
2223
|
+
});
|
|
2224
|
+
});
|
|
2225
|
+
outputMessagesPromise.then((outputMessages) => {
|
|
2226
|
+
var _a2;
|
|
2227
|
+
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
2228
|
+
threadId,
|
|
2229
|
+
runId: void 0,
|
|
2230
|
+
inputMessages: messages,
|
|
2231
|
+
outputMessages,
|
|
2232
|
+
properties: graphqlContext.properties
|
|
2233
|
+
});
|
|
2234
|
+
}).catch((_error) => {
|
|
2235
|
+
});
|
|
2236
|
+
return {
|
|
2237
|
+
threadId,
|
|
2238
|
+
runId: void 0,
|
|
2239
|
+
eventSource,
|
|
2240
|
+
serverSideActions: [],
|
|
2241
|
+
actionInputsWithoutAgents
|
|
2242
|
+
};
|
|
2243
|
+
} catch (error) {
|
|
2244
|
+
console.error("Error getting response:", error);
|
|
2245
|
+
throw error;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
async getServerSideActions(request) {
|
|
2249
|
+
const { messages: rawMessages, graphqlContext, agentStates, url } = request;
|
|
2250
|
+
const inputMessages = convertGqlInputToMessages(rawMessages);
|
|
2251
|
+
const langserveFunctions = [];
|
|
2252
|
+
for (const chainPromise of this.langserve) {
|
|
2253
|
+
try {
|
|
2254
|
+
const chain = await chainPromise;
|
|
2255
|
+
langserveFunctions.push(chain);
|
|
2256
|
+
} catch (error) {
|
|
2257
|
+
console.error("Error loading langserve chain:", error);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
|
|
2261
|
+
...endpoint,
|
|
2262
|
+
type: resolveEndpointType(endpoint)
|
|
2263
|
+
}));
|
|
2264
|
+
const remoteActions = await setupRemoteActions({
|
|
2265
|
+
remoteEndpointDefinitions,
|
|
2266
|
+
graphqlContext,
|
|
2267
|
+
messages: inputMessages,
|
|
2268
|
+
agentStates,
|
|
2269
|
+
frontendUrl: url
|
|
2270
|
+
});
|
|
2271
|
+
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
2272
|
+
properties: graphqlContext.properties,
|
|
2273
|
+
url
|
|
2274
|
+
}) : this.actions;
|
|
2275
|
+
return [
|
|
2276
|
+
...configuredActions,
|
|
2277
|
+
...langserveFunctions,
|
|
2278
|
+
...remoteActions
|
|
2279
|
+
];
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
__name(CopilotRuntime, "CopilotRuntime");
|
|
2283
|
+
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
2284
|
+
let allTools = [];
|
|
2285
|
+
const allToolNames = [];
|
|
2286
|
+
for (const tool of toolsByPriority) {
|
|
2287
|
+
if (!allToolNames.includes(tool.name)) {
|
|
2288
|
+
allTools.push(tool);
|
|
2289
|
+
allToolNames.push(tool.name);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
return allTools;
|
|
2293
|
+
}
|
|
2294
|
+
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
2295
|
+
function copilotKitEndpoint(config) {
|
|
2296
|
+
return {
|
|
2297
|
+
...config,
|
|
2298
|
+
type: EndpointType.CopilotKit
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
__name(copilotKitEndpoint, "copilotKitEndpoint");
|
|
2302
|
+
function langGraphCloudEndpoint(config) {
|
|
2303
|
+
return {
|
|
2304
|
+
...config,
|
|
2305
|
+
type: EndpointType.LangGraphCloud
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
__name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
|
|
2309
|
+
function resolveEndpointType(endpoint) {
|
|
2310
|
+
if (!endpoint.type) {
|
|
2311
|
+
if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
|
|
2312
|
+
return EndpointType.LangGraphCloud;
|
|
2313
|
+
} else {
|
|
2314
|
+
return EndpointType.CopilotKit;
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
return endpoint.type;
|
|
2318
|
+
}
|
|
2319
|
+
__name(resolveEndpointType, "resolveEndpointType");
|
|
2320
|
+
|
|
2321
|
+
// src/lib/telemetry-client.ts
|
|
2322
|
+
var packageJson = require_package();
|
|
2323
|
+
var telemetryClient = new TelemetryClient({
|
|
2324
|
+
packageName: packageJson.name,
|
|
2325
|
+
packageVersion: packageJson.version
|
|
2326
|
+
});
|
|
2327
|
+
function getRuntimeInstanceTelemetryInfo(runtime) {
|
|
2328
|
+
const endpointsInfo = runtime.remoteEndpointDefinitions.reduce((acc, endpoint) => {
|
|
2329
|
+
let info = {
|
|
2330
|
+
...acc
|
|
2331
|
+
};
|
|
2332
|
+
const endpointType = resolveEndpointType(endpoint);
|
|
2333
|
+
if (!info.endpointTypes.includes(endpointType)) {
|
|
2334
|
+
info = {
|
|
2335
|
+
...info,
|
|
2336
|
+
endpointTypes: [
|
|
2337
|
+
...info.endpointTypes,
|
|
2338
|
+
endpointType
|
|
2339
|
+
]
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
if (endpointType === EndpointType.LangGraphCloud) {
|
|
2343
|
+
const ep = endpoint;
|
|
2344
|
+
info = {
|
|
2345
|
+
...info,
|
|
2346
|
+
agentsAmount: ep.agents.length,
|
|
2347
|
+
hashedKey: createHash3("sha256").update(ep.langsmithApiKey).digest("hex")
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2350
|
+
return info;
|
|
2351
|
+
}, {
|
|
2352
|
+
endpointTypes: [],
|
|
2353
|
+
agentsAmount: null,
|
|
2354
|
+
hashedKey: null
|
|
2355
|
+
});
|
|
2356
|
+
return {
|
|
2357
|
+
actionsAmount: runtime.actions.length,
|
|
2358
|
+
endpointsAmount: runtime.remoteEndpointDefinitions.length,
|
|
2359
|
+
endpointTypes: endpointsInfo.endpointTypes,
|
|
2360
|
+
agentsAmount: endpointsInfo.agentsAmount,
|
|
2361
|
+
hashedLgcKey: endpointsInfo.hashedKey
|
|
2362
|
+
};
|
|
2363
|
+
}
|
|
2364
|
+
__name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
2365
|
+
var telemetry_client_default = telemetryClient;
|
|
2366
|
+
|
|
1999
2367
|
// src/service-adapters/events.ts
|
|
2000
2368
|
var RuntimeEventTypes;
|
|
2001
2369
|
(function(RuntimeEventTypes2) {
|
|
@@ -2012,52 +2380,71 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2012
2380
|
constructor() {
|
|
2013
2381
|
super();
|
|
2014
2382
|
}
|
|
2015
|
-
sendTextMessageStart(messageId) {
|
|
2383
|
+
sendTextMessageStart({ messageId }) {
|
|
2016
2384
|
this.next({
|
|
2017
2385
|
type: "TextMessageStart",
|
|
2018
2386
|
messageId
|
|
2019
2387
|
});
|
|
2020
2388
|
}
|
|
2021
|
-
sendTextMessageContent(content) {
|
|
2389
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2022
2390
|
this.next({
|
|
2023
2391
|
type: "TextMessageContent",
|
|
2024
|
-
content
|
|
2392
|
+
content,
|
|
2393
|
+
messageId
|
|
2025
2394
|
});
|
|
2026
2395
|
}
|
|
2027
|
-
sendTextMessageEnd() {
|
|
2396
|
+
sendTextMessageEnd({ messageId }) {
|
|
2028
2397
|
this.next({
|
|
2029
|
-
type: "TextMessageEnd"
|
|
2398
|
+
type: "TextMessageEnd",
|
|
2399
|
+
messageId
|
|
2030
2400
|
});
|
|
2031
2401
|
}
|
|
2032
2402
|
sendTextMessage(messageId, content) {
|
|
2033
|
-
this.sendTextMessageStart(
|
|
2034
|
-
|
|
2035
|
-
|
|
2403
|
+
this.sendTextMessageStart({
|
|
2404
|
+
messageId
|
|
2405
|
+
});
|
|
2406
|
+
this.sendTextMessageContent({
|
|
2407
|
+
messageId,
|
|
2408
|
+
content
|
|
2409
|
+
});
|
|
2410
|
+
this.sendTextMessageEnd({
|
|
2411
|
+
messageId
|
|
2412
|
+
});
|
|
2036
2413
|
}
|
|
2037
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2414
|
+
sendActionExecutionStart({ actionExecutionId, actionName }) {
|
|
2038
2415
|
this.next({
|
|
2039
2416
|
type: "ActionExecutionStart",
|
|
2040
2417
|
actionExecutionId,
|
|
2041
2418
|
actionName
|
|
2042
2419
|
});
|
|
2043
2420
|
}
|
|
2044
|
-
sendActionExecutionArgs(args) {
|
|
2421
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2045
2422
|
this.next({
|
|
2046
2423
|
type: "ActionExecutionArgs",
|
|
2047
|
-
args
|
|
2424
|
+
args,
|
|
2425
|
+
actionExecutionId
|
|
2048
2426
|
});
|
|
2049
2427
|
}
|
|
2050
|
-
sendActionExecutionEnd() {
|
|
2428
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2051
2429
|
this.next({
|
|
2052
|
-
type: "ActionExecutionEnd"
|
|
2430
|
+
type: "ActionExecutionEnd",
|
|
2431
|
+
actionExecutionId
|
|
2053
2432
|
});
|
|
2054
2433
|
}
|
|
2055
|
-
sendActionExecution(actionExecutionId,
|
|
2056
|
-
this.sendActionExecutionStart(
|
|
2057
|
-
|
|
2058
|
-
|
|
2434
|
+
sendActionExecution({ actionExecutionId, actionName, args }) {
|
|
2435
|
+
this.sendActionExecutionStart({
|
|
2436
|
+
actionExecutionId,
|
|
2437
|
+
actionName
|
|
2438
|
+
});
|
|
2439
|
+
this.sendActionExecutionArgs({
|
|
2440
|
+
actionExecutionId,
|
|
2441
|
+
args
|
|
2442
|
+
});
|
|
2443
|
+
this.sendActionExecutionEnd({
|
|
2444
|
+
actionExecutionId
|
|
2445
|
+
});
|
|
2059
2446
|
}
|
|
2060
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2447
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2061
2448
|
this.next({
|
|
2062
2449
|
type: "ActionExecutionResult",
|
|
2063
2450
|
actionName,
|
|
@@ -2065,7 +2452,7 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2065
2452
|
result
|
|
2066
2453
|
});
|
|
2067
2454
|
}
|
|
2068
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2455
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2069
2456
|
this.next({
|
|
2070
2457
|
type: "AgentStateMessage",
|
|
2071
2458
|
threadId,
|
|
@@ -2086,9 +2473,20 @@ var RuntimeEventSource = class {
|
|
|
2086
2473
|
async stream(callback) {
|
|
2087
2474
|
this.callback = callback;
|
|
2088
2475
|
}
|
|
2476
|
+
sendErrorMessageToChat() {
|
|
2477
|
+
const errorMessage = "\u274C An error occurred. Please try again.";
|
|
2478
|
+
if (!this.callback) {
|
|
2479
|
+
this.stream(async (eventStream$) => {
|
|
2480
|
+
eventStream$.sendTextMessage(randomId3(), errorMessage);
|
|
2481
|
+
});
|
|
2482
|
+
} else {
|
|
2483
|
+
this.eventStream$.sendTextMessage(randomId3(), errorMessage);
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2089
2486
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
2090
2487
|
this.callback(this.eventStream$).catch((error) => {
|
|
2091
2488
|
console.error("Error in event source callback", error);
|
|
2489
|
+
this.sendErrorMessageToChat();
|
|
2092
2490
|
});
|
|
2093
2491
|
return this.eventStream$.pipe(
|
|
2094
2492
|
// mark tools for server side execution
|
|
@@ -2160,12 +2558,16 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2160
2558
|
}
|
|
2161
2559
|
}
|
|
2162
2560
|
if (isLangGraphAgentAction(action)) {
|
|
2163
|
-
eventStream$.sendActionExecutionResult(
|
|
2561
|
+
eventStream$.sendActionExecutionResult({
|
|
2562
|
+
actionExecutionId,
|
|
2563
|
+
actionName: action.name,
|
|
2564
|
+
result: `${action.name} agent started`
|
|
2565
|
+
});
|
|
2164
2566
|
const stream = await action.langGraphAgentHandler({
|
|
2165
2567
|
name: action.name,
|
|
2166
2568
|
actionInputsWithoutAgents
|
|
2167
2569
|
});
|
|
2168
|
-
|
|
2570
|
+
from2(stream).subscribe({
|
|
2169
2571
|
next: (event) => eventStream$.next(event),
|
|
2170
2572
|
error: (err) => console.error("Error in stream", err),
|
|
2171
2573
|
complete: () => eventStream$.complete()
|
|
@@ -2186,9 +2588,9 @@ __name(executeAction, "executeAction");
|
|
|
2186
2588
|
|
|
2187
2589
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2188
2590
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
2189
|
-
import { plainToInstance } from "class-transformer";
|
|
2591
|
+
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2190
2592
|
import { GraphQLError } from "graphql";
|
|
2191
|
-
import { randomId as
|
|
2593
|
+
import { randomId as randomId4 } from "@copilotkit/shared";
|
|
2192
2594
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
2193
2595
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2194
2596
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2305,7 +2707,7 @@ var CopilotResolver = class {
|
|
|
2305
2707
|
rejectOutputMessagesPromise = reject;
|
|
2306
2708
|
});
|
|
2307
2709
|
logger2.debug("Processing");
|
|
2308
|
-
const { eventSource, threadId =
|
|
2710
|
+
const { eventSource, threadId = randomId4(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
2309
2711
|
serviceAdapter,
|
|
2310
2712
|
messages: data.messages,
|
|
2311
2713
|
actions: data.frontend.actions,
|
|
@@ -2349,8 +2751,8 @@ var CopilotResolver = class {
|
|
|
2349
2751
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2350
2752
|
});
|
|
2351
2753
|
outputMessages = [
|
|
2352
|
-
|
|
2353
|
-
id:
|
|
2754
|
+
plainToInstance2(TextMessage, {
|
|
2755
|
+
id: randomId4(),
|
|
2354
2756
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2355
2757
|
content: result.reason,
|
|
2356
2758
|
role: MessageRole.assistant
|
|
@@ -2398,7 +2800,9 @@ var CopilotResolver = class {
|
|
|
2398
2800
|
// skip until this message start event
|
|
2399
2801
|
skipWhile((e) => e !== event),
|
|
2400
2802
|
// take until the message end event
|
|
2401
|
-
takeWhile((e) => e.type
|
|
2803
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
2804
|
+
// filter out any other message events or message ids
|
|
2805
|
+
filter((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
2402
2806
|
);
|
|
2403
2807
|
const streamingTextStatus = new Subject();
|
|
2404
2808
|
const messageId = event.messageId;
|
|
@@ -2416,7 +2820,7 @@ var CopilotResolver = class {
|
|
|
2416
2820
|
reason,
|
|
2417
2821
|
messageId: messageId2
|
|
2418
2822
|
}, "Text streaming interrupted");
|
|
2419
|
-
streamingTextStatus.next(
|
|
2823
|
+
streamingTextStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
2420
2824
|
reason
|
|
2421
2825
|
}));
|
|
2422
2826
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -2449,7 +2853,7 @@ var CopilotResolver = class {
|
|
|
2449
2853
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2450
2854
|
stopStreamingText();
|
|
2451
2855
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2452
|
-
outputMessages.push(
|
|
2856
|
+
outputMessages.push(plainToInstance2(TextMessage, {
|
|
2453
2857
|
id: messageId,
|
|
2454
2858
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2455
2859
|
content: textChunks.join(""),
|
|
@@ -2462,7 +2866,13 @@ var CopilotResolver = class {
|
|
|
2462
2866
|
break;
|
|
2463
2867
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2464
2868
|
logger2.debug("Action execution start event received");
|
|
2465
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2869
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2870
|
+
skipWhile((e) => e !== event),
|
|
2871
|
+
// take until the action execution end event
|
|
2872
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
2873
|
+
// filter out any other action execution events or action execution ids
|
|
2874
|
+
filter((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
2875
|
+
);
|
|
2466
2876
|
const streamingArgumentsStatus = new Subject();
|
|
2467
2877
|
pushMessage({
|
|
2468
2878
|
id: event.actionExecutionId,
|
|
@@ -2485,7 +2895,7 @@ var CopilotResolver = class {
|
|
|
2485
2895
|
logger2.error({
|
|
2486
2896
|
err
|
|
2487
2897
|
}, "Error in action execution argument stream");
|
|
2488
|
-
streamingArgumentsStatus.next(
|
|
2898
|
+
streamingArgumentsStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
2489
2899
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2490
2900
|
}));
|
|
2491
2901
|
stopStreamingArguments();
|
|
@@ -2496,7 +2906,7 @@ var CopilotResolver = class {
|
|
|
2496
2906
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2497
2907
|
stopStreamingArguments();
|
|
2498
2908
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2499
|
-
outputMessages.push(
|
|
2909
|
+
outputMessages.push(plainToInstance2(ActionExecutionMessage, {
|
|
2500
2910
|
id: event.actionExecutionId,
|
|
2501
2911
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2502
2912
|
name: event.actionName,
|
|
@@ -2513,15 +2923,15 @@ var CopilotResolver = class {
|
|
|
2513
2923
|
result: event.result
|
|
2514
2924
|
}, "Action execution result event received");
|
|
2515
2925
|
pushMessage({
|
|
2516
|
-
id:
|
|
2926
|
+
id: randomId4(),
|
|
2517
2927
|
status: new SuccessMessageStatus(),
|
|
2518
2928
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2519
2929
|
actionExecutionId: event.actionExecutionId,
|
|
2520
2930
|
actionName: event.actionName,
|
|
2521
2931
|
result: event.result
|
|
2522
2932
|
});
|
|
2523
|
-
outputMessages.push(
|
|
2524
|
-
id:
|
|
2933
|
+
outputMessages.push(plainToInstance2(ResultMessage, {
|
|
2934
|
+
id: randomId4(),
|
|
2525
2935
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2526
2936
|
actionExecutionId: event.actionExecutionId,
|
|
2527
2937
|
actionName: event.actionName,
|
|
@@ -2533,7 +2943,7 @@ var CopilotResolver = class {
|
|
|
2533
2943
|
event
|
|
2534
2944
|
}, "Agent message event received");
|
|
2535
2945
|
pushMessage({
|
|
2536
|
-
id:
|
|
2946
|
+
id: randomId4(),
|
|
2537
2947
|
status: new SuccessMessageStatus(),
|
|
2538
2948
|
threadId: event.threadId,
|
|
2539
2949
|
agentName: event.agentName,
|
|
@@ -2545,8 +2955,8 @@ var CopilotResolver = class {
|
|
|
2545
2955
|
role: MessageRole.assistant,
|
|
2546
2956
|
createdAt: /* @__PURE__ */ new Date()
|
|
2547
2957
|
});
|
|
2548
|
-
outputMessages.push(
|
|
2549
|
-
id:
|
|
2958
|
+
outputMessages.push(plainToInstance2(AgentStateMessage, {
|
|
2959
|
+
id: randomId4(),
|
|
2550
2960
|
threadId: event.threadId,
|
|
2551
2961
|
agentName: event.agentName,
|
|
2552
2962
|
nodeName: event.nodeName,
|
|
@@ -2733,7 +3143,7 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
2733
3143
|
_copilotkit: options.properties._copilotkit
|
|
2734
3144
|
});
|
|
2735
3145
|
}
|
|
2736
|
-
telemetry_client_default.capture("oss.runtime.instance_created",
|
|
3146
|
+
telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
|
|
2737
3147
|
const logger2 = commonConfig.logging;
|
|
2738
3148
|
logger2.debug("Creating Node HTTP endpoint");
|
|
2739
3149
|
const yoga = createYoga({
|
|
@@ -2745,14 +3155,16 @@ function copilotRuntimeNodeHttpEndpoint(options) {
|
|
|
2745
3155
|
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
2746
3156
|
|
|
2747
3157
|
export {
|
|
3158
|
+
getRuntimeInstanceTelemetryInfo,
|
|
2748
3159
|
telemetry_client_default,
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
3160
|
+
CopilotRuntime,
|
|
3161
|
+
flattenToolCallsNoDuplicates,
|
|
3162
|
+
copilotKitEndpoint,
|
|
3163
|
+
langGraphCloudEndpoint,
|
|
3164
|
+
resolveEndpointType,
|
|
2753
3165
|
createContext,
|
|
2754
3166
|
buildSchema,
|
|
2755
3167
|
getCommonConfig,
|
|
2756
3168
|
copilotRuntimeNodeHttpEndpoint
|
|
2757
3169
|
};
|
|
2758
|
-
//# sourceMappingURL=chunk-
|
|
3170
|
+
//# sourceMappingURL=chunk-RDHJQVWH.mjs.map
|