@copilotkit/runtime 1.1.1-feat-runtime-remote-actions.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -3
- package/__snapshots__/schema/schema.graphql +0 -22
- package/dist/{chunk-4AJIFDOJ.mjs → chunk-6PAC74F2.mjs} +2 -2
- package/dist/{chunk-JMW74TAS.mjs → chunk-74B76SMO.mjs} +2 -2
- package/dist/{chunk-4MRXXS22.mjs → chunk-CUVWSISN.mjs} +3 -3
- package/dist/{chunk-KOC3ZRO4.mjs → chunk-GEIBJJQ4.mjs} +2 -12
- package/dist/chunk-GEIBJJQ4.mjs.map +1 -0
- package/dist/{chunk-MISUYYBG.mjs → chunk-MKV3LEJ6.mjs} +28 -356
- package/dist/chunk-MKV3LEJ6.mjs.map +1 -0
- package/dist/{chunk-CC3J37S6.mjs → chunk-NPCP4YZB.mjs} +2 -2
- package/dist/{chunk-CSIQEWDR.mjs → chunk-RDEOIOQR.mjs} +12 -101
- package/dist/chunk-RDEOIOQR.mjs.map +1 -0
- package/dist/{chunk-UTUNGR2L.mjs → chunk-URMISMK2.mjs} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +0 -11
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -3
- package/dist/{groq-adapter-35a54596.d.ts → groq-adapter-675b30c6.d.ts} +1 -1
- package/dist/{index-9cfb4d1f.d.ts → index-aa091e3c.d.ts} +1 -18
- package/dist/index.d.ts +8 -8
- package/dist/index.js +31 -451
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -8
- package/dist/{langserve-b97a6817.d.ts → langserve-a54438c6.d.ts} +2 -11
- package/dist/lib/index.d.ts +8 -8
- package/dist/lib/index.js +31 -451
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -8
- package/dist/lib/integrations/index.d.ts +7 -7
- package/dist/lib/integrations/index.js +14 -132
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +5 -5
- package/dist/lib/integrations/nest/index.js +14 -132
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +5 -5
- package/dist/lib/integrations/node-express/index.js +14 -132
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +5 -5
- package/dist/lib/integrations/node-http/index.js +14 -132
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/{pages-router-df63122a.d.ts → pages-router-df82c666.d.ts} +1 -1
- package/dist/service-adapters/index.d.ts +3 -3
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +3 -3
- package/dist/{copilot-runtime-40b55575.d.ts → shared-ec6c7db5.d.ts} +35 -47
- package/package.json +4 -4
- package/src/graphql/inputs/message.input.ts +0 -24
- package/src/graphql/resolvers/copilot.resolver.ts +7 -40
- package/src/graphql/types/converted/index.ts +0 -10
- package/src/graphql/types/copilot-response.type.ts +0 -23
- package/src/lib/{runtime/copilot-runtime.ts → copilot-runtime.ts} +14 -123
- package/src/lib/index.ts +1 -1
- package/src/lib/integrations/shared.ts +1 -1
- package/src/service-adapters/conversion.ts +0 -14
- package/src/service-adapters/events.ts +8 -49
- package/dist/chunk-CSIQEWDR.mjs.map +0 -1
- package/dist/chunk-KOC3ZRO4.mjs.map +0 -1
- package/dist/chunk-MISUYYBG.mjs.map +0 -1
- package/src/agents/langgraph/event-source.ts +0 -29
- package/src/agents/langgraph/events.ts +0 -295
- package/src/lib/runtime/remote-actions.ts +0 -271
- /package/dist/{chunk-4AJIFDOJ.mjs.map → chunk-6PAC74F2.mjs.map} +0 -0
- /package/dist/{chunk-JMW74TAS.mjs.map → chunk-74B76SMO.mjs.map} +0 -0
- /package/dist/{chunk-4MRXXS22.mjs.map → chunk-CUVWSISN.mjs.map} +0 -0
- /package/dist/{chunk-CC3J37S6.mjs.map → chunk-NPCP4YZB.mjs.map} +0 -0
- /package/dist/{chunk-UTUNGR2L.mjs.map → chunk-URMISMK2.mjs.map} +0 -0
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.1.
|
|
47
|
+
version: "1.1.2",
|
|
48
48
|
sideEffects: false,
|
|
49
49
|
main: "./dist/index.js",
|
|
50
50
|
module: "./dist/index.mjs",
|
|
@@ -138,8 +138,8 @@ __export(lib_exports, {
|
|
|
138
138
|
});
|
|
139
139
|
module.exports = __toCommonJS(lib_exports);
|
|
140
140
|
|
|
141
|
-
// src/lib/
|
|
142
|
-
var
|
|
141
|
+
// src/lib/copilot-runtime.ts
|
|
142
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
143
143
|
|
|
144
144
|
// src/service-adapters/openai/openai-adapter.ts
|
|
145
145
|
var import_openai = __toESM(require("openai"));
|
|
@@ -197,15 +197,6 @@ var ResultMessage = class extends BaseMessage {
|
|
|
197
197
|
result;
|
|
198
198
|
};
|
|
199
199
|
__name(ResultMessage, "ResultMessage");
|
|
200
|
-
var AgentMessage = class extends BaseMessage {
|
|
201
|
-
threadId;
|
|
202
|
-
agentName;
|
|
203
|
-
nodeName;
|
|
204
|
-
role;
|
|
205
|
-
state;
|
|
206
|
-
running;
|
|
207
|
-
};
|
|
208
|
-
__name(AgentMessage, "AgentMessage");
|
|
209
200
|
|
|
210
201
|
// src/service-adapters/openai/utils.ts
|
|
211
202
|
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
@@ -1258,216 +1249,6 @@ __name(GroqAdapter, "GroqAdapter");
|
|
|
1258
1249
|
|
|
1259
1250
|
// src/service-adapters/events.ts
|
|
1260
1251
|
var import_rxjs = require("rxjs");
|
|
1261
|
-
|
|
1262
|
-
// src/lib/telemetry-client.ts
|
|
1263
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1264
|
-
var packageJson = require_package();
|
|
1265
|
-
var telemetryClient = new import_shared7.TelemetryClient({
|
|
1266
|
-
packageName: packageJson.name,
|
|
1267
|
-
packageVersion: packageJson.version
|
|
1268
|
-
});
|
|
1269
|
-
var telemetry_client_default = telemetryClient;
|
|
1270
|
-
|
|
1271
|
-
// src/lib/runtime/remote-actions.ts
|
|
1272
|
-
function isAgentResult(obj, checkAgentMessageFlag = false) {
|
|
1273
|
-
if (checkAgentMessageFlag) {
|
|
1274
|
-
return typeof obj === "object" && obj !== null && "__agentMessage" in obj && obj.__agentMessage === true;
|
|
1275
|
-
} else {
|
|
1276
|
-
return typeof obj === "object" && obj !== null && "threadId" in obj && "state" in obj && "running" in obj && "name" in obj;
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
__name(isAgentResult, "isAgentResult");
|
|
1280
|
-
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
1281
|
-
const headers = {
|
|
1282
|
-
"Content-Type": "application/json"
|
|
1283
|
-
};
|
|
1284
|
-
if (onBeforeRequest) {
|
|
1285
|
-
const { headers: additionalHeaders } = onBeforeRequest({
|
|
1286
|
-
ctx: graphqlContext
|
|
1287
|
-
});
|
|
1288
|
-
if (additionalHeaders) {
|
|
1289
|
-
Object.assign(headers, additionalHeaders);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return headers;
|
|
1293
|
-
}
|
|
1294
|
-
__name(createHeaders, "createHeaders");
|
|
1295
|
-
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1296
|
-
logger2.debug({
|
|
1297
|
-
url
|
|
1298
|
-
}, "Fetching actions from url");
|
|
1299
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1300
|
-
const response = await fetch(`${url}/info`, {
|
|
1301
|
-
method: "POST",
|
|
1302
|
-
headers,
|
|
1303
|
-
body: JSON.stringify({
|
|
1304
|
-
properties: graphqlContext.properties
|
|
1305
|
-
})
|
|
1306
|
-
});
|
|
1307
|
-
if (!response.ok) {
|
|
1308
|
-
logger2.error({
|
|
1309
|
-
url,
|
|
1310
|
-
status: response.status,
|
|
1311
|
-
body: await response.text()
|
|
1312
|
-
}, "Failed to fetch actions from url");
|
|
1313
|
-
return [];
|
|
1314
|
-
}
|
|
1315
|
-
const json = await response.json();
|
|
1316
|
-
logger2.debug({
|
|
1317
|
-
json
|
|
1318
|
-
}, "Fetched actions from url");
|
|
1319
|
-
return json;
|
|
1320
|
-
}
|
|
1321
|
-
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
1322
|
-
function constructActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1323
|
-
return json["actions"].map((action) => ({
|
|
1324
|
-
name: action.name,
|
|
1325
|
-
description: action.description,
|
|
1326
|
-
parameters: action.parameters,
|
|
1327
|
-
handler: async (args) => {
|
|
1328
|
-
logger2.debug({
|
|
1329
|
-
actionName: action.name,
|
|
1330
|
-
args
|
|
1331
|
-
}, "Executing remote action");
|
|
1332
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1333
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1334
|
-
const response = await fetch(`${url}/actions/execute`, {
|
|
1335
|
-
method: "POST",
|
|
1336
|
-
headers,
|
|
1337
|
-
body: JSON.stringify({
|
|
1338
|
-
name: action.name,
|
|
1339
|
-
parameters: args,
|
|
1340
|
-
properties: graphqlContext.properties
|
|
1341
|
-
})
|
|
1342
|
-
});
|
|
1343
|
-
if (!response.ok) {
|
|
1344
|
-
logger2.error({
|
|
1345
|
-
url,
|
|
1346
|
-
status: response.status,
|
|
1347
|
-
body: await response.text()
|
|
1348
|
-
}, "Failed to execute remote action");
|
|
1349
|
-
return "Failed to execute remote action";
|
|
1350
|
-
}
|
|
1351
|
-
const requestResult = await response.json();
|
|
1352
|
-
if (isAgentResult(requestResult)) {
|
|
1353
|
-
logger2.debug({
|
|
1354
|
-
actionName: action.name,
|
|
1355
|
-
result: requestResult
|
|
1356
|
-
}, "Started agent session");
|
|
1357
|
-
return {
|
|
1358
|
-
...requestResult,
|
|
1359
|
-
__agentMessage: true
|
|
1360
|
-
};
|
|
1361
|
-
} else {
|
|
1362
|
-
const result = requestResult["result"];
|
|
1363
|
-
logger2.debug({
|
|
1364
|
-
actionName: action.name,
|
|
1365
|
-
result
|
|
1366
|
-
}, "Executed remote action");
|
|
1367
|
-
return result;
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}));
|
|
1371
|
-
}
|
|
1372
|
-
__name(constructActions, "constructActions");
|
|
1373
|
-
async function executeAgent({ agentName, nodeName, threadId, state, url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1374
|
-
logger2.debug({
|
|
1375
|
-
agentName,
|
|
1376
|
-
threadId,
|
|
1377
|
-
state
|
|
1378
|
-
}, "Executing remote action");
|
|
1379
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1380
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1381
|
-
const response = await fetch(`${url}/actions/execute`, {
|
|
1382
|
-
method: "POST",
|
|
1383
|
-
headers,
|
|
1384
|
-
body: JSON.stringify({
|
|
1385
|
-
threadId,
|
|
1386
|
-
state,
|
|
1387
|
-
name: agentName,
|
|
1388
|
-
nodeName
|
|
1389
|
-
})
|
|
1390
|
-
});
|
|
1391
|
-
if (!response.ok) {
|
|
1392
|
-
logger2.error({
|
|
1393
|
-
url,
|
|
1394
|
-
status: response.status,
|
|
1395
|
-
body: await response.text()
|
|
1396
|
-
}, "Failed to execute remote agent");
|
|
1397
|
-
throw new Error("Failed to execute remote agent");
|
|
1398
|
-
}
|
|
1399
|
-
const requestResult = await response.json();
|
|
1400
|
-
logger2.debug({
|
|
1401
|
-
agentName,
|
|
1402
|
-
threadId,
|
|
1403
|
-
state
|
|
1404
|
-
}, "Executed remote agent");
|
|
1405
|
-
return {
|
|
1406
|
-
...requestResult,
|
|
1407
|
-
__agentMessage: true
|
|
1408
|
-
};
|
|
1409
|
-
}
|
|
1410
|
-
__name(executeAgent, "executeAgent");
|
|
1411
|
-
async function setupRemoteActions({ remoteActionDefinitions, graphqlContext }) {
|
|
1412
|
-
const logger2 = graphqlContext.logger.child({
|
|
1413
|
-
component: "remote-actions.fetchRemoteActions"
|
|
1414
|
-
});
|
|
1415
|
-
logger2.debug({
|
|
1416
|
-
remoteActionDefinitions
|
|
1417
|
-
}, "Fetching remote actions");
|
|
1418
|
-
const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
|
|
1419
|
-
const result = await Promise.all(filtered.map(async (actionDefinition) => {
|
|
1420
|
-
const json = await fetchRemoteInfo({
|
|
1421
|
-
url: actionDefinition.url,
|
|
1422
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1423
|
-
graphqlContext,
|
|
1424
|
-
logger: logger2.child({
|
|
1425
|
-
component: "remote-actions.fetchActionsFromUrl",
|
|
1426
|
-
actionDefinition
|
|
1427
|
-
})
|
|
1428
|
-
});
|
|
1429
|
-
return constructActions({
|
|
1430
|
-
json,
|
|
1431
|
-
url: actionDefinition.url,
|
|
1432
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1433
|
-
graphqlContext,
|
|
1434
|
-
logger: logger2.child({
|
|
1435
|
-
component: "remote-actions.constructActions",
|
|
1436
|
-
actionDefinition
|
|
1437
|
-
})
|
|
1438
|
-
});
|
|
1439
|
-
}));
|
|
1440
|
-
return result.flat();
|
|
1441
|
-
}
|
|
1442
|
-
__name(setupRemoteActions, "setupRemoteActions");
|
|
1443
|
-
async function fetchRemoteActionLocations({ remoteActionDefinitions, graphqlContext }) {
|
|
1444
|
-
const logger2 = graphqlContext.logger.child({
|
|
1445
|
-
component: "remote-actions.fetchRemoteActionLocations"
|
|
1446
|
-
});
|
|
1447
|
-
logger2.debug({
|
|
1448
|
-
remoteActionDefinitions
|
|
1449
|
-
}, "Fetching remote action locations");
|
|
1450
|
-
const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
|
|
1451
|
-
const result = /* @__PURE__ */ new Map();
|
|
1452
|
-
await Promise.all(filtered.map(async (actionDefinition) => {
|
|
1453
|
-
const json = await fetchRemoteInfo({
|
|
1454
|
-
url: actionDefinition.url,
|
|
1455
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1456
|
-
graphqlContext,
|
|
1457
|
-
logger: logger2.child({
|
|
1458
|
-
component: "remote-actions.fetchActionsFromUrl",
|
|
1459
|
-
actionDefinition
|
|
1460
|
-
})
|
|
1461
|
-
});
|
|
1462
|
-
json["actions"].forEach((action) => {
|
|
1463
|
-
result.set(action.name, actionDefinition.url);
|
|
1464
|
-
});
|
|
1465
|
-
}));
|
|
1466
|
-
return result;
|
|
1467
|
-
}
|
|
1468
|
-
__name(fetchRemoteActionLocations, "fetchRemoteActionLocations");
|
|
1469
|
-
|
|
1470
|
-
// src/service-adapters/events.ts
|
|
1471
1252
|
var RuntimeEventTypes;
|
|
1472
1253
|
(function(RuntimeEventTypes2) {
|
|
1473
1254
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -1477,7 +1258,6 @@ var RuntimeEventTypes;
|
|
|
1477
1258
|
RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
|
|
1478
1259
|
RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
|
|
1479
1260
|
RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
|
|
1480
|
-
RuntimeEventTypes2["AgentMessage"] = "AgentMessage";
|
|
1481
1261
|
})(RuntimeEventTypes || (RuntimeEventTypes = {}));
|
|
1482
1262
|
var RuntimeEventSubject = class extends import_rxjs.ReplaySubject {
|
|
1483
1263
|
constructor() {
|
|
@@ -1536,16 +1316,6 @@ var RuntimeEventSubject = class extends import_rxjs.ReplaySubject {
|
|
|
1536
1316
|
result
|
|
1537
1317
|
});
|
|
1538
1318
|
}
|
|
1539
|
-
sendAgentMessage(threadId, agentName, nodeName, state, running) {
|
|
1540
|
-
this.next({
|
|
1541
|
-
type: "AgentMessage",
|
|
1542
|
-
threadId,
|
|
1543
|
-
agentName,
|
|
1544
|
-
nodeName,
|
|
1545
|
-
state,
|
|
1546
|
-
running
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
1319
|
};
|
|
1550
1320
|
__name(RuntimeEventSubject, "RuntimeEventSubject");
|
|
1551
1321
|
var RuntimeEventSource = class {
|
|
@@ -1593,7 +1363,6 @@ var RuntimeEventSource = class {
|
|
|
1593
1363
|
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1594
1364
|
console.error(error);
|
|
1595
1365
|
});
|
|
1596
|
-
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
1597
1366
|
return (0, import_rxjs.concat)((0, import_rxjs.of)(eventWithState.event), toolCallEventStream$);
|
|
1598
1367
|
} else {
|
|
1599
1368
|
return (0, import_rxjs.of)(eventWithState.event);
|
|
@@ -1616,19 +1385,14 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1616
1385
|
args = JSON.parse(actionArguments);
|
|
1617
1386
|
}
|
|
1618
1387
|
const result = await action.handler(args);
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
eventStream
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
name: action.name,
|
|
1628
|
-
id: actionExecutionId
|
|
1629
|
-
}
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1388
|
+
await streamLangChainResponse({
|
|
1389
|
+
result,
|
|
1390
|
+
eventStream$,
|
|
1391
|
+
actionExecution: {
|
|
1392
|
+
name: action.name,
|
|
1393
|
+
id: actionExecutionId
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1632
1396
|
}
|
|
1633
1397
|
__name(executeAction, "executeAction");
|
|
1634
1398
|
|
|
@@ -1660,27 +1424,15 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
1660
1424
|
actionName: message.resultMessage.actionName,
|
|
1661
1425
|
result: message.resultMessage.result
|
|
1662
1426
|
}));
|
|
1663
|
-
} else if (message.agentMessage) {
|
|
1664
|
-
messages.push((0, import_class_transformer.plainToInstance)(AgentMessage, {
|
|
1665
|
-
id: message.id,
|
|
1666
|
-
threadId: message.agentMessage.threadId,
|
|
1667
|
-
createdAt: message.createdAt,
|
|
1668
|
-
agentName: message.agentMessage.agentName,
|
|
1669
|
-
nodeName: message.agentMessage.nodeName,
|
|
1670
|
-
role: message.agentMessage.role,
|
|
1671
|
-
state: message.agentMessage.state,
|
|
1672
|
-
running: message.agentMessage.running
|
|
1673
|
-
}));
|
|
1674
1427
|
}
|
|
1675
1428
|
}
|
|
1676
1429
|
return messages;
|
|
1677
1430
|
}
|
|
1678
1431
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
1679
1432
|
|
|
1680
|
-
// src/lib/
|
|
1433
|
+
// src/lib/copilot-runtime.ts
|
|
1681
1434
|
var CopilotRuntime = class {
|
|
1682
1435
|
actions;
|
|
1683
|
-
remoteActionDefinitions;
|
|
1684
1436
|
langserve = [];
|
|
1685
1437
|
onBeforeRequest;
|
|
1686
1438
|
onAfterRequest;
|
|
@@ -1691,80 +1443,12 @@ var CopilotRuntime = class {
|
|
|
1691
1443
|
const remoteChain = new RemoteChain(chain);
|
|
1692
1444
|
this.langserve.push(remoteChain.toAction());
|
|
1693
1445
|
}
|
|
1694
|
-
this.remoteActionDefinitions = (params == null ? void 0 : params.remoteActions) || [];
|
|
1695
1446
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
1696
1447
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
1697
1448
|
}
|
|
1698
|
-
async processAgentRequest(request) {
|
|
1699
|
-
var _a;
|
|
1700
|
-
const { messages, outputMessagesPromise, graphqlContext } = request;
|
|
1701
|
-
const message = request.messages.slice(-1)[0].agentMessage;
|
|
1702
|
-
const agentName = message.agentName;
|
|
1703
|
-
const threadId = message.threadId;
|
|
1704
|
-
const state = JSON.parse(message.state);
|
|
1705
|
-
const nodeName = message.nodeName;
|
|
1706
|
-
const remoteActions = await fetchRemoteActionLocations({
|
|
1707
|
-
remoteActionDefinitions: this.remoteActionDefinitions,
|
|
1708
|
-
graphqlContext
|
|
1709
|
-
});
|
|
1710
|
-
const url = remoteActions.get(agentName);
|
|
1711
|
-
if (!url) {
|
|
1712
|
-
throw new Error(`Action location for agent name ${agentName} not found.`);
|
|
1713
|
-
}
|
|
1714
|
-
const inputMessages = convertGqlInputToMessages(messages);
|
|
1715
|
-
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
1716
|
-
threadId,
|
|
1717
|
-
runId: void 0,
|
|
1718
|
-
inputMessages,
|
|
1719
|
-
properties: graphqlContext.properties
|
|
1720
|
-
}));
|
|
1721
|
-
try {
|
|
1722
|
-
const eventSource = new RuntimeEventSource();
|
|
1723
|
-
const result = await executeAgent({
|
|
1724
|
-
agentName,
|
|
1725
|
-
nodeName,
|
|
1726
|
-
threadId,
|
|
1727
|
-
state,
|
|
1728
|
-
url,
|
|
1729
|
-
graphqlContext,
|
|
1730
|
-
logger: graphqlContext.logger
|
|
1731
|
-
});
|
|
1732
|
-
eventSource.stream(async (eventStream$) => {
|
|
1733
|
-
eventStream$.sendAgentMessage(result.threadId, agentName, result.nodeName, result.state, result.running);
|
|
1734
|
-
eventStream$.complete();
|
|
1735
|
-
});
|
|
1736
|
-
outputMessagesPromise.then((outputMessages) => {
|
|
1737
|
-
var _a2;
|
|
1738
|
-
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
1739
|
-
threadId: result.threadId,
|
|
1740
|
-
runId: void 0,
|
|
1741
|
-
inputMessages,
|
|
1742
|
-
outputMessages,
|
|
1743
|
-
properties: graphqlContext.properties
|
|
1744
|
-
});
|
|
1745
|
-
}).catch((_error) => {
|
|
1746
|
-
});
|
|
1747
|
-
return {
|
|
1748
|
-
threadId: result.threadId,
|
|
1749
|
-
runId: void 0,
|
|
1750
|
-
eventSource,
|
|
1751
|
-
actions: []
|
|
1752
|
-
};
|
|
1753
|
-
} catch (error) {
|
|
1754
|
-
console.error("Error getting response:", error);
|
|
1755
|
-
throw error;
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
1449
|
async process(request) {
|
|
1759
1450
|
var _a;
|
|
1760
|
-
|
|
1761
|
-
const [lastMessage] = request.messages.slice(-1);
|
|
1762
|
-
if (lastMessage.agentMessage) {
|
|
1763
|
-
return this.processAgentRequest(request);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters } = request;
|
|
1767
|
-
const messages = rawMessages.filter((message) => !message.agentMessage);
|
|
1451
|
+
const { serviceAdapter, messages, actions: clientSideActionsInput, threadId, runId, properties, outputMessagesPromise, forwardedParameters } = request;
|
|
1768
1452
|
const langserveFunctions = [];
|
|
1769
1453
|
for (const chainPromise of this.langserve) {
|
|
1770
1454
|
try {
|
|
@@ -1774,22 +1458,17 @@ var CopilotRuntime = class {
|
|
|
1774
1458
|
console.error("Error loading langserve chain:", error);
|
|
1775
1459
|
}
|
|
1776
1460
|
}
|
|
1777
|
-
const remoteActions = await setupRemoteActions({
|
|
1778
|
-
remoteActionDefinitions: this.remoteActionDefinitions,
|
|
1779
|
-
graphqlContext
|
|
1780
|
-
});
|
|
1781
1461
|
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
1782
|
-
properties
|
|
1462
|
+
properties
|
|
1783
1463
|
}) : this.actions;
|
|
1784
1464
|
const actions = [
|
|
1785
1465
|
...configuredActions,
|
|
1786
|
-
...langserveFunctions
|
|
1787
|
-
...remoteActions
|
|
1466
|
+
...langserveFunctions
|
|
1788
1467
|
];
|
|
1789
1468
|
const serverSideActionsInput = actions.map((action) => ({
|
|
1790
1469
|
name: action.name,
|
|
1791
1470
|
description: action.description,
|
|
1792
|
-
jsonSchema: JSON.stringify((0,
|
|
1471
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1793
1472
|
}));
|
|
1794
1473
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
1795
1474
|
...serverSideActionsInput,
|
|
@@ -1800,7 +1479,7 @@ var CopilotRuntime = class {
|
|
|
1800
1479
|
threadId,
|
|
1801
1480
|
runId,
|
|
1802
1481
|
inputMessages,
|
|
1803
|
-
properties
|
|
1482
|
+
properties
|
|
1804
1483
|
}));
|
|
1805
1484
|
try {
|
|
1806
1485
|
const eventSource = new RuntimeEventSource();
|
|
@@ -1819,7 +1498,7 @@ var CopilotRuntime = class {
|
|
|
1819
1498
|
runId: result.runId,
|
|
1820
1499
|
inputMessages,
|
|
1821
1500
|
outputMessages,
|
|
1822
|
-
properties
|
|
1501
|
+
properties
|
|
1823
1502
|
});
|
|
1824
1503
|
}).catch((_error) => {
|
|
1825
1504
|
});
|
|
@@ -1917,7 +1596,6 @@ var MessageInput = class extends BaseMessage {
|
|
|
1917
1596
|
textMessage;
|
|
1918
1597
|
actionExecutionMessage;
|
|
1919
1598
|
resultMessage;
|
|
1920
|
-
agentMessage;
|
|
1921
1599
|
};
|
|
1922
1600
|
__name(MessageInput, "MessageInput");
|
|
1923
1601
|
_ts_decorate2([
|
|
@@ -1938,12 +1616,6 @@ _ts_decorate2([
|
|
|
1938
1616
|
}),
|
|
1939
1617
|
_ts_metadata2("design:type", typeof ResultMessageInput === "undefined" ? Object : ResultMessageInput)
|
|
1940
1618
|
], MessageInput.prototype, "resultMessage", void 0);
|
|
1941
|
-
_ts_decorate2([
|
|
1942
|
-
(0, import_type_graphql3.Field)(() => AgentMessageInput, {
|
|
1943
|
-
nullable: true
|
|
1944
|
-
}),
|
|
1945
|
-
_ts_metadata2("design:type", typeof AgentMessageInput === "undefined" ? Object : AgentMessageInput)
|
|
1946
|
-
], MessageInput.prototype, "agentMessage", void 0);
|
|
1947
1619
|
MessageInput = _ts_decorate2([
|
|
1948
1620
|
(0, import_type_graphql3.InputType)()
|
|
1949
1621
|
], MessageInput);
|
|
@@ -2005,42 +1677,6 @@ _ts_decorate2([
|
|
|
2005
1677
|
ResultMessageInput = _ts_decorate2([
|
|
2006
1678
|
(0, import_type_graphql3.InputType)()
|
|
2007
1679
|
], ResultMessageInput);
|
|
2008
|
-
var AgentMessageInput = class {
|
|
2009
|
-
threadId;
|
|
2010
|
-
agentName;
|
|
2011
|
-
role;
|
|
2012
|
-
state;
|
|
2013
|
-
running;
|
|
2014
|
-
nodeName;
|
|
2015
|
-
};
|
|
2016
|
-
__name(AgentMessageInput, "AgentMessageInput");
|
|
2017
|
-
_ts_decorate2([
|
|
2018
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2019
|
-
_ts_metadata2("design:type", String)
|
|
2020
|
-
], AgentMessageInput.prototype, "threadId", void 0);
|
|
2021
|
-
_ts_decorate2([
|
|
2022
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2023
|
-
_ts_metadata2("design:type", String)
|
|
2024
|
-
], AgentMessageInput.prototype, "agentName", void 0);
|
|
2025
|
-
_ts_decorate2([
|
|
2026
|
-
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
2027
|
-
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
2028
|
-
], AgentMessageInput.prototype, "role", void 0);
|
|
2029
|
-
_ts_decorate2([
|
|
2030
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2031
|
-
_ts_metadata2("design:type", String)
|
|
2032
|
-
], AgentMessageInput.prototype, "state", void 0);
|
|
2033
|
-
_ts_decorate2([
|
|
2034
|
-
(0, import_type_graphql3.Field)(() => Boolean),
|
|
2035
|
-
_ts_metadata2("design:type", Boolean)
|
|
2036
|
-
], AgentMessageInput.prototype, "running", void 0);
|
|
2037
|
-
_ts_decorate2([
|
|
2038
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2039
|
-
_ts_metadata2("design:type", String)
|
|
2040
|
-
], AgentMessageInput.prototype, "nodeName", void 0);
|
|
2041
|
-
AgentMessageInput = _ts_decorate2([
|
|
2042
|
-
(0, import_type_graphql3.InputType)()
|
|
2043
|
-
], AgentMessageInput);
|
|
2044
1680
|
|
|
2045
1681
|
// src/graphql/inputs/frontend.input.ts
|
|
2046
1682
|
var import_type_graphql5 = require("type-graphql");
|
|
@@ -2584,8 +2220,6 @@ BaseMessageOutput = _ts_decorate11([
|
|
|
2584
2220
|
return ActionExecutionMessageOutput;
|
|
2585
2221
|
} else if (value.hasOwnProperty("result")) {
|
|
2586
2222
|
return ResultMessageOutput;
|
|
2587
|
-
} else if (value.hasOwnProperty("agentName")) {
|
|
2588
|
-
return AgentMessageOutput;
|
|
2589
2223
|
}
|
|
2590
2224
|
return void 0;
|
|
2591
2225
|
}
|
|
@@ -2659,44 +2293,6 @@ ResultMessageOutput = _ts_decorate11([
|
|
|
2659
2293
|
implements: BaseMessageOutput
|
|
2660
2294
|
})
|
|
2661
2295
|
], ResultMessageOutput);
|
|
2662
|
-
var AgentMessageOutput = class {
|
|
2663
|
-
threadId;
|
|
2664
|
-
agentName;
|
|
2665
|
-
nodeName;
|
|
2666
|
-
role;
|
|
2667
|
-
state;
|
|
2668
|
-
running;
|
|
2669
|
-
};
|
|
2670
|
-
__name(AgentMessageOutput, "AgentMessageOutput");
|
|
2671
|
-
_ts_decorate11([
|
|
2672
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2673
|
-
_ts_metadata11("design:type", String)
|
|
2674
|
-
], AgentMessageOutput.prototype, "threadId", void 0);
|
|
2675
|
-
_ts_decorate11([
|
|
2676
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2677
|
-
_ts_metadata11("design:type", String)
|
|
2678
|
-
], AgentMessageOutput.prototype, "agentName", void 0);
|
|
2679
|
-
_ts_decorate11([
|
|
2680
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2681
|
-
_ts_metadata11("design:type", String)
|
|
2682
|
-
], AgentMessageOutput.prototype, "nodeName", void 0);
|
|
2683
|
-
_ts_decorate11([
|
|
2684
|
-
(0, import_type_graphql12.Field)(() => MessageRole),
|
|
2685
|
-
_ts_metadata11("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
2686
|
-
], AgentMessageOutput.prototype, "role", void 0);
|
|
2687
|
-
_ts_decorate11([
|
|
2688
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2689
|
-
_ts_metadata11("design:type", String)
|
|
2690
|
-
], AgentMessageOutput.prototype, "state", void 0);
|
|
2691
|
-
_ts_decorate11([
|
|
2692
|
-
(0, import_type_graphql12.Field)(() => Boolean),
|
|
2693
|
-
_ts_metadata11("design:type", Boolean)
|
|
2694
|
-
], AgentMessageOutput.prototype, "running", void 0);
|
|
2695
|
-
AgentMessageOutput = _ts_decorate11([
|
|
2696
|
-
(0, import_type_graphql12.ObjectType)({
|
|
2697
|
-
implements: BaseMessageOutput
|
|
2698
|
-
})
|
|
2699
|
-
], AgentMessageOutput);
|
|
2700
2296
|
var CopilotResponse = class {
|
|
2701
2297
|
threadId;
|
|
2702
2298
|
status;
|
|
@@ -2767,6 +2363,15 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
2767
2363
|
};
|
|
2768
2364
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
2769
2365
|
|
|
2366
|
+
// src/lib/telemetry-client.ts
|
|
2367
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
2368
|
+
var packageJson = require_package();
|
|
2369
|
+
var telemetryClient = new import_shared8.TelemetryClient({
|
|
2370
|
+
packageName: packageJson.name,
|
|
2371
|
+
packageVersion: packageJson.version
|
|
2372
|
+
});
|
|
2373
|
+
var telemetry_client_default = telemetryClient;
|
|
2374
|
+
|
|
2770
2375
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2771
2376
|
var import_shared9 = require("@copilotkit/shared");
|
|
2772
2377
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
@@ -2793,6 +2398,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
2793
2398
|
__name(_ts_param, "_ts_param");
|
|
2794
2399
|
var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
|
|
2795
2400
|
var _a;
|
|
2401
|
+
console.log("invokeGuardrails.baseUrl", baseUrl);
|
|
2796
2402
|
if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
|
|
2797
2403
|
const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
|
|
2798
2404
|
role: m.textMessage.role,
|
|
@@ -2838,6 +2444,8 @@ var CopilotResolver = class {
|
|
|
2838
2444
|
logger2.debug({
|
|
2839
2445
|
data
|
|
2840
2446
|
}, "Generating Copilot response");
|
|
2447
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2448
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
2841
2449
|
if (properties) {
|
|
2842
2450
|
logger2.debug("Properties provided, merging with context properties");
|
|
2843
2451
|
ctx.properties = {
|
|
@@ -2845,8 +2453,6 @@ var CopilotResolver = class {
|
|
|
2845
2453
|
...properties
|
|
2846
2454
|
};
|
|
2847
2455
|
}
|
|
2848
|
-
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2849
|
-
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
2850
2456
|
let copilotCloudPublicApiKey = null;
|
|
2851
2457
|
let copilotCloudBaseUrl;
|
|
2852
2458
|
if (data.cloud) {
|
|
@@ -2892,8 +2498,8 @@ var CopilotResolver = class {
|
|
|
2892
2498
|
threadId: data.threadId,
|
|
2893
2499
|
runId: data.runId,
|
|
2894
2500
|
publicApiKey: void 0,
|
|
2501
|
+
properties: ctx.properties || {},
|
|
2895
2502
|
outputMessagesPromise,
|
|
2896
|
-
graphqlContext: ctx,
|
|
2897
2503
|
forwardedParameters: data.forwardedParameters
|
|
2898
2504
|
});
|
|
2899
2505
|
logger2.debug("Event source created, creating response");
|
|
@@ -3101,32 +2707,6 @@ var CopilotResolver = class {
|
|
|
3101
2707
|
result: event.result
|
|
3102
2708
|
}));
|
|
3103
2709
|
break;
|
|
3104
|
-
case RuntimeEventTypes.AgentMessage:
|
|
3105
|
-
logger2.debug({
|
|
3106
|
-
event
|
|
3107
|
-
}, "Agent message event received");
|
|
3108
|
-
pushMessage({
|
|
3109
|
-
id: (0, import_shared9.randomId)(),
|
|
3110
|
-
status: new SuccessMessageStatus(),
|
|
3111
|
-
threadId: event.threadId,
|
|
3112
|
-
agentName: event.agentName,
|
|
3113
|
-
nodeName: event.nodeName,
|
|
3114
|
-
state: JSON.stringify(event.state),
|
|
3115
|
-
running: event.running,
|
|
3116
|
-
role: MessageRole.assistant,
|
|
3117
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
3118
|
-
});
|
|
3119
|
-
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentMessage, {
|
|
3120
|
-
id: (0, import_shared9.randomId)(),
|
|
3121
|
-
threadId: event.threadId,
|
|
3122
|
-
agentName: event.agentName,
|
|
3123
|
-
nodeName: event.nodeName,
|
|
3124
|
-
state: JSON.stringify(event.state),
|
|
3125
|
-
running: event.running,
|
|
3126
|
-
role: MessageRole.assistant,
|
|
3127
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
3128
|
-
}));
|
|
3129
|
-
break;
|
|
3130
2710
|
}
|
|
3131
2711
|
},
|
|
3132
2712
|
error: (err) => {
|