@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/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",
|
|
@@ -142,8 +142,8 @@ __export(src_exports, {
|
|
|
142
142
|
module.exports = __toCommonJS(src_exports);
|
|
143
143
|
var import_reflect_metadata = require("reflect-metadata");
|
|
144
144
|
|
|
145
|
-
// src/lib/
|
|
146
|
-
var
|
|
145
|
+
// src/lib/copilot-runtime.ts
|
|
146
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
147
147
|
|
|
148
148
|
// src/service-adapters/openai/openai-adapter.ts
|
|
149
149
|
var import_openai = __toESM(require("openai"));
|
|
@@ -201,15 +201,6 @@ var ResultMessage = class extends BaseMessage {
|
|
|
201
201
|
result;
|
|
202
202
|
};
|
|
203
203
|
__name(ResultMessage, "ResultMessage");
|
|
204
|
-
var AgentMessage = class extends BaseMessage {
|
|
205
|
-
threadId;
|
|
206
|
-
agentName;
|
|
207
|
-
nodeName;
|
|
208
|
-
role;
|
|
209
|
-
state;
|
|
210
|
-
running;
|
|
211
|
-
};
|
|
212
|
-
__name(AgentMessage, "AgentMessage");
|
|
213
204
|
|
|
214
205
|
// src/service-adapters/openai/utils.ts
|
|
215
206
|
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
@@ -1262,216 +1253,6 @@ __name(GroqAdapter, "GroqAdapter");
|
|
|
1262
1253
|
|
|
1263
1254
|
// src/service-adapters/events.ts
|
|
1264
1255
|
var import_rxjs = require("rxjs");
|
|
1265
|
-
|
|
1266
|
-
// src/lib/telemetry-client.ts
|
|
1267
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1268
|
-
var packageJson = require_package();
|
|
1269
|
-
var telemetryClient = new import_shared7.TelemetryClient({
|
|
1270
|
-
packageName: packageJson.name,
|
|
1271
|
-
packageVersion: packageJson.version
|
|
1272
|
-
});
|
|
1273
|
-
var telemetry_client_default = telemetryClient;
|
|
1274
|
-
|
|
1275
|
-
// src/lib/runtime/remote-actions.ts
|
|
1276
|
-
function isAgentResult(obj, checkAgentMessageFlag = false) {
|
|
1277
|
-
if (checkAgentMessageFlag) {
|
|
1278
|
-
return typeof obj === "object" && obj !== null && "__agentMessage" in obj && obj.__agentMessage === true;
|
|
1279
|
-
} else {
|
|
1280
|
-
return typeof obj === "object" && obj !== null && "threadId" in obj && "state" in obj && "running" in obj && "name" in obj;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
__name(isAgentResult, "isAgentResult");
|
|
1284
|
-
function createHeaders(onBeforeRequest, graphqlContext) {
|
|
1285
|
-
const headers = {
|
|
1286
|
-
"Content-Type": "application/json"
|
|
1287
|
-
};
|
|
1288
|
-
if (onBeforeRequest) {
|
|
1289
|
-
const { headers: additionalHeaders } = onBeforeRequest({
|
|
1290
|
-
ctx: graphqlContext
|
|
1291
|
-
});
|
|
1292
|
-
if (additionalHeaders) {
|
|
1293
|
-
Object.assign(headers, additionalHeaders);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
return headers;
|
|
1297
|
-
}
|
|
1298
|
-
__name(createHeaders, "createHeaders");
|
|
1299
|
-
async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1300
|
-
logger2.debug({
|
|
1301
|
-
url
|
|
1302
|
-
}, "Fetching actions from url");
|
|
1303
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1304
|
-
const response = await fetch(`${url}/info`, {
|
|
1305
|
-
method: "POST",
|
|
1306
|
-
headers,
|
|
1307
|
-
body: JSON.stringify({
|
|
1308
|
-
properties: graphqlContext.properties
|
|
1309
|
-
})
|
|
1310
|
-
});
|
|
1311
|
-
if (!response.ok) {
|
|
1312
|
-
logger2.error({
|
|
1313
|
-
url,
|
|
1314
|
-
status: response.status,
|
|
1315
|
-
body: await response.text()
|
|
1316
|
-
}, "Failed to fetch actions from url");
|
|
1317
|
-
return [];
|
|
1318
|
-
}
|
|
1319
|
-
const json = await response.json();
|
|
1320
|
-
logger2.debug({
|
|
1321
|
-
json
|
|
1322
|
-
}, "Fetched actions from url");
|
|
1323
|
-
return json;
|
|
1324
|
-
}
|
|
1325
|
-
__name(fetchRemoteInfo, "fetchRemoteInfo");
|
|
1326
|
-
function constructActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1327
|
-
return json["actions"].map((action) => ({
|
|
1328
|
-
name: action.name,
|
|
1329
|
-
description: action.description,
|
|
1330
|
-
parameters: action.parameters,
|
|
1331
|
-
handler: async (args) => {
|
|
1332
|
-
logger2.debug({
|
|
1333
|
-
actionName: action.name,
|
|
1334
|
-
args
|
|
1335
|
-
}, "Executing remote action");
|
|
1336
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1337
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1338
|
-
const response = await fetch(`${url}/actions/execute`, {
|
|
1339
|
-
method: "POST",
|
|
1340
|
-
headers,
|
|
1341
|
-
body: JSON.stringify({
|
|
1342
|
-
name: action.name,
|
|
1343
|
-
parameters: args,
|
|
1344
|
-
properties: graphqlContext.properties
|
|
1345
|
-
})
|
|
1346
|
-
});
|
|
1347
|
-
if (!response.ok) {
|
|
1348
|
-
logger2.error({
|
|
1349
|
-
url,
|
|
1350
|
-
status: response.status,
|
|
1351
|
-
body: await response.text()
|
|
1352
|
-
}, "Failed to execute remote action");
|
|
1353
|
-
return "Failed to execute remote action";
|
|
1354
|
-
}
|
|
1355
|
-
const requestResult = await response.json();
|
|
1356
|
-
if (isAgentResult(requestResult)) {
|
|
1357
|
-
logger2.debug({
|
|
1358
|
-
actionName: action.name,
|
|
1359
|
-
result: requestResult
|
|
1360
|
-
}, "Started agent session");
|
|
1361
|
-
return {
|
|
1362
|
-
...requestResult,
|
|
1363
|
-
__agentMessage: true
|
|
1364
|
-
};
|
|
1365
|
-
} else {
|
|
1366
|
-
const result = requestResult["result"];
|
|
1367
|
-
logger2.debug({
|
|
1368
|
-
actionName: action.name,
|
|
1369
|
-
result
|
|
1370
|
-
}, "Executed remote action");
|
|
1371
|
-
return result;
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
}));
|
|
1375
|
-
}
|
|
1376
|
-
__name(constructActions, "constructActions");
|
|
1377
|
-
async function executeAgent({ agentName, nodeName, threadId, state, url, onBeforeRequest, graphqlContext, logger: logger2 }) {
|
|
1378
|
-
logger2.debug({
|
|
1379
|
-
agentName,
|
|
1380
|
-
threadId,
|
|
1381
|
-
state
|
|
1382
|
-
}, "Executing remote action");
|
|
1383
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
1384
|
-
telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
|
|
1385
|
-
const response = await fetch(`${url}/actions/execute`, {
|
|
1386
|
-
method: "POST",
|
|
1387
|
-
headers,
|
|
1388
|
-
body: JSON.stringify({
|
|
1389
|
-
threadId,
|
|
1390
|
-
state,
|
|
1391
|
-
name: agentName,
|
|
1392
|
-
nodeName
|
|
1393
|
-
})
|
|
1394
|
-
});
|
|
1395
|
-
if (!response.ok) {
|
|
1396
|
-
logger2.error({
|
|
1397
|
-
url,
|
|
1398
|
-
status: response.status,
|
|
1399
|
-
body: await response.text()
|
|
1400
|
-
}, "Failed to execute remote agent");
|
|
1401
|
-
throw new Error("Failed to execute remote agent");
|
|
1402
|
-
}
|
|
1403
|
-
const requestResult = await response.json();
|
|
1404
|
-
logger2.debug({
|
|
1405
|
-
agentName,
|
|
1406
|
-
threadId,
|
|
1407
|
-
state
|
|
1408
|
-
}, "Executed remote agent");
|
|
1409
|
-
return {
|
|
1410
|
-
...requestResult,
|
|
1411
|
-
__agentMessage: true
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
__name(executeAgent, "executeAgent");
|
|
1415
|
-
async function setupRemoteActions({ remoteActionDefinitions, graphqlContext }) {
|
|
1416
|
-
const logger2 = graphqlContext.logger.child({
|
|
1417
|
-
component: "remote-actions.fetchRemoteActions"
|
|
1418
|
-
});
|
|
1419
|
-
logger2.debug({
|
|
1420
|
-
remoteActionDefinitions
|
|
1421
|
-
}, "Fetching remote actions");
|
|
1422
|
-
const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
|
|
1423
|
-
const result = await Promise.all(filtered.map(async (actionDefinition) => {
|
|
1424
|
-
const json = await fetchRemoteInfo({
|
|
1425
|
-
url: actionDefinition.url,
|
|
1426
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1427
|
-
graphqlContext,
|
|
1428
|
-
logger: logger2.child({
|
|
1429
|
-
component: "remote-actions.fetchActionsFromUrl",
|
|
1430
|
-
actionDefinition
|
|
1431
|
-
})
|
|
1432
|
-
});
|
|
1433
|
-
return constructActions({
|
|
1434
|
-
json,
|
|
1435
|
-
url: actionDefinition.url,
|
|
1436
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1437
|
-
graphqlContext,
|
|
1438
|
-
logger: logger2.child({
|
|
1439
|
-
component: "remote-actions.constructActions",
|
|
1440
|
-
actionDefinition
|
|
1441
|
-
})
|
|
1442
|
-
});
|
|
1443
|
-
}));
|
|
1444
|
-
return result.flat();
|
|
1445
|
-
}
|
|
1446
|
-
__name(setupRemoteActions, "setupRemoteActions");
|
|
1447
|
-
async function fetchRemoteActionLocations({ remoteActionDefinitions, graphqlContext }) {
|
|
1448
|
-
const logger2 = graphqlContext.logger.child({
|
|
1449
|
-
component: "remote-actions.fetchRemoteActionLocations"
|
|
1450
|
-
});
|
|
1451
|
-
logger2.debug({
|
|
1452
|
-
remoteActionDefinitions
|
|
1453
|
-
}, "Fetching remote action locations");
|
|
1454
|
-
const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
|
|
1455
|
-
const result = /* @__PURE__ */ new Map();
|
|
1456
|
-
await Promise.all(filtered.map(async (actionDefinition) => {
|
|
1457
|
-
const json = await fetchRemoteInfo({
|
|
1458
|
-
url: actionDefinition.url,
|
|
1459
|
-
onBeforeRequest: actionDefinition.onBeforeRequest,
|
|
1460
|
-
graphqlContext,
|
|
1461
|
-
logger: logger2.child({
|
|
1462
|
-
component: "remote-actions.fetchActionsFromUrl",
|
|
1463
|
-
actionDefinition
|
|
1464
|
-
})
|
|
1465
|
-
});
|
|
1466
|
-
json["actions"].forEach((action) => {
|
|
1467
|
-
result.set(action.name, actionDefinition.url);
|
|
1468
|
-
});
|
|
1469
|
-
}));
|
|
1470
|
-
return result;
|
|
1471
|
-
}
|
|
1472
|
-
__name(fetchRemoteActionLocations, "fetchRemoteActionLocations");
|
|
1473
|
-
|
|
1474
|
-
// src/service-adapters/events.ts
|
|
1475
1256
|
var RuntimeEventTypes;
|
|
1476
1257
|
(function(RuntimeEventTypes2) {
|
|
1477
1258
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -1481,7 +1262,6 @@ var RuntimeEventTypes;
|
|
|
1481
1262
|
RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
|
|
1482
1263
|
RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
|
|
1483
1264
|
RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
|
|
1484
|
-
RuntimeEventTypes2["AgentMessage"] = "AgentMessage";
|
|
1485
1265
|
})(RuntimeEventTypes || (RuntimeEventTypes = {}));
|
|
1486
1266
|
var RuntimeEventSubject = class extends import_rxjs.ReplaySubject {
|
|
1487
1267
|
constructor() {
|
|
@@ -1540,16 +1320,6 @@ var RuntimeEventSubject = class extends import_rxjs.ReplaySubject {
|
|
|
1540
1320
|
result
|
|
1541
1321
|
});
|
|
1542
1322
|
}
|
|
1543
|
-
sendAgentMessage(threadId, agentName, nodeName, state, running) {
|
|
1544
|
-
this.next({
|
|
1545
|
-
type: "AgentMessage",
|
|
1546
|
-
threadId,
|
|
1547
|
-
agentName,
|
|
1548
|
-
nodeName,
|
|
1549
|
-
state,
|
|
1550
|
-
running
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
1323
|
};
|
|
1554
1324
|
__name(RuntimeEventSubject, "RuntimeEventSubject");
|
|
1555
1325
|
var RuntimeEventSource = class {
|
|
@@ -1597,7 +1367,6 @@ var RuntimeEventSource = class {
|
|
|
1597
1367
|
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1598
1368
|
console.error(error);
|
|
1599
1369
|
});
|
|
1600
|
-
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
1601
1370
|
return (0, import_rxjs.concat)((0, import_rxjs.of)(eventWithState.event), toolCallEventStream$);
|
|
1602
1371
|
} else {
|
|
1603
1372
|
return (0, import_rxjs.of)(eventWithState.event);
|
|
@@ -1620,19 +1389,14 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
1620
1389
|
args = JSON.parse(actionArguments);
|
|
1621
1390
|
}
|
|
1622
1391
|
const result = await action.handler(args);
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
eventStream
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
name: action.name,
|
|
1632
|
-
id: actionExecutionId
|
|
1633
|
-
}
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1392
|
+
await streamLangChainResponse({
|
|
1393
|
+
result,
|
|
1394
|
+
eventStream$,
|
|
1395
|
+
actionExecution: {
|
|
1396
|
+
name: action.name,
|
|
1397
|
+
id: actionExecutionId
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1636
1400
|
}
|
|
1637
1401
|
__name(executeAction, "executeAction");
|
|
1638
1402
|
|
|
@@ -1664,27 +1428,15 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
1664
1428
|
actionName: message.resultMessage.actionName,
|
|
1665
1429
|
result: message.resultMessage.result
|
|
1666
1430
|
}));
|
|
1667
|
-
} else if (message.agentMessage) {
|
|
1668
|
-
messages.push((0, import_class_transformer.plainToInstance)(AgentMessage, {
|
|
1669
|
-
id: message.id,
|
|
1670
|
-
threadId: message.agentMessage.threadId,
|
|
1671
|
-
createdAt: message.createdAt,
|
|
1672
|
-
agentName: message.agentMessage.agentName,
|
|
1673
|
-
nodeName: message.agentMessage.nodeName,
|
|
1674
|
-
role: message.agentMessage.role,
|
|
1675
|
-
state: message.agentMessage.state,
|
|
1676
|
-
running: message.agentMessage.running
|
|
1677
|
-
}));
|
|
1678
1431
|
}
|
|
1679
1432
|
}
|
|
1680
1433
|
return messages;
|
|
1681
1434
|
}
|
|
1682
1435
|
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
1683
1436
|
|
|
1684
|
-
// src/lib/
|
|
1437
|
+
// src/lib/copilot-runtime.ts
|
|
1685
1438
|
var CopilotRuntime = class {
|
|
1686
1439
|
actions;
|
|
1687
|
-
remoteActionDefinitions;
|
|
1688
1440
|
langserve = [];
|
|
1689
1441
|
onBeforeRequest;
|
|
1690
1442
|
onAfterRequest;
|
|
@@ -1695,80 +1447,12 @@ var CopilotRuntime = class {
|
|
|
1695
1447
|
const remoteChain = new RemoteChain(chain);
|
|
1696
1448
|
this.langserve.push(remoteChain.toAction());
|
|
1697
1449
|
}
|
|
1698
|
-
this.remoteActionDefinitions = (params == null ? void 0 : params.remoteActions) || [];
|
|
1699
1450
|
this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
|
|
1700
1451
|
this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
|
|
1701
1452
|
}
|
|
1702
|
-
async processAgentRequest(request) {
|
|
1703
|
-
var _a;
|
|
1704
|
-
const { messages, outputMessagesPromise, graphqlContext } = request;
|
|
1705
|
-
const message = request.messages.slice(-1)[0].agentMessage;
|
|
1706
|
-
const agentName = message.agentName;
|
|
1707
|
-
const threadId = message.threadId;
|
|
1708
|
-
const state = JSON.parse(message.state);
|
|
1709
|
-
const nodeName = message.nodeName;
|
|
1710
|
-
const remoteActions = await fetchRemoteActionLocations({
|
|
1711
|
-
remoteActionDefinitions: this.remoteActionDefinitions,
|
|
1712
|
-
graphqlContext
|
|
1713
|
-
});
|
|
1714
|
-
const url = remoteActions.get(agentName);
|
|
1715
|
-
if (!url) {
|
|
1716
|
-
throw new Error(`Action location for agent name ${agentName} not found.`);
|
|
1717
|
-
}
|
|
1718
|
-
const inputMessages = convertGqlInputToMessages(messages);
|
|
1719
|
-
await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
|
|
1720
|
-
threadId,
|
|
1721
|
-
runId: void 0,
|
|
1722
|
-
inputMessages,
|
|
1723
|
-
properties: graphqlContext.properties
|
|
1724
|
-
}));
|
|
1725
|
-
try {
|
|
1726
|
-
const eventSource = new RuntimeEventSource();
|
|
1727
|
-
const result = await executeAgent({
|
|
1728
|
-
agentName,
|
|
1729
|
-
nodeName,
|
|
1730
|
-
threadId,
|
|
1731
|
-
state,
|
|
1732
|
-
url,
|
|
1733
|
-
graphqlContext,
|
|
1734
|
-
logger: graphqlContext.logger
|
|
1735
|
-
});
|
|
1736
|
-
eventSource.stream(async (eventStream$) => {
|
|
1737
|
-
eventStream$.sendAgentMessage(result.threadId, agentName, result.nodeName, result.state, result.running);
|
|
1738
|
-
eventStream$.complete();
|
|
1739
|
-
});
|
|
1740
|
-
outputMessagesPromise.then((outputMessages) => {
|
|
1741
|
-
var _a2;
|
|
1742
|
-
(_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
|
|
1743
|
-
threadId: result.threadId,
|
|
1744
|
-
runId: void 0,
|
|
1745
|
-
inputMessages,
|
|
1746
|
-
outputMessages,
|
|
1747
|
-
properties: graphqlContext.properties
|
|
1748
|
-
});
|
|
1749
|
-
}).catch((_error) => {
|
|
1750
|
-
});
|
|
1751
|
-
return {
|
|
1752
|
-
threadId: result.threadId,
|
|
1753
|
-
runId: void 0,
|
|
1754
|
-
eventSource,
|
|
1755
|
-
actions: []
|
|
1756
|
-
};
|
|
1757
|
-
} catch (error) {
|
|
1758
|
-
console.error("Error getting response:", error);
|
|
1759
|
-
throw error;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
1453
|
async process(request) {
|
|
1763
1454
|
var _a;
|
|
1764
|
-
|
|
1765
|
-
const [lastMessage] = request.messages.slice(-1);
|
|
1766
|
-
if (lastMessage.agentMessage) {
|
|
1767
|
-
return this.processAgentRequest(request);
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters } = request;
|
|
1771
|
-
const messages = rawMessages.filter((message) => !message.agentMessage);
|
|
1455
|
+
const { serviceAdapter, messages, actions: clientSideActionsInput, threadId, runId, properties, outputMessagesPromise, forwardedParameters } = request;
|
|
1772
1456
|
const langserveFunctions = [];
|
|
1773
1457
|
for (const chainPromise of this.langserve) {
|
|
1774
1458
|
try {
|
|
@@ -1778,22 +1462,17 @@ var CopilotRuntime = class {
|
|
|
1778
1462
|
console.error("Error loading langserve chain:", error);
|
|
1779
1463
|
}
|
|
1780
1464
|
}
|
|
1781
|
-
const remoteActions = await setupRemoteActions({
|
|
1782
|
-
remoteActionDefinitions: this.remoteActionDefinitions,
|
|
1783
|
-
graphqlContext
|
|
1784
|
-
});
|
|
1785
1465
|
const configuredActions = typeof this.actions === "function" ? this.actions({
|
|
1786
|
-
properties
|
|
1466
|
+
properties
|
|
1787
1467
|
}) : this.actions;
|
|
1788
1468
|
const actions = [
|
|
1789
1469
|
...configuredActions,
|
|
1790
|
-
...langserveFunctions
|
|
1791
|
-
...remoteActions
|
|
1470
|
+
...langserveFunctions
|
|
1792
1471
|
];
|
|
1793
1472
|
const serverSideActionsInput = actions.map((action) => ({
|
|
1794
1473
|
name: action.name,
|
|
1795
1474
|
description: action.description,
|
|
1796
|
-
jsonSchema: JSON.stringify((0,
|
|
1475
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1797
1476
|
}));
|
|
1798
1477
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
1799
1478
|
...serverSideActionsInput,
|
|
@@ -1804,7 +1483,7 @@ var CopilotRuntime = class {
|
|
|
1804
1483
|
threadId,
|
|
1805
1484
|
runId,
|
|
1806
1485
|
inputMessages,
|
|
1807
|
-
properties
|
|
1486
|
+
properties
|
|
1808
1487
|
}));
|
|
1809
1488
|
try {
|
|
1810
1489
|
const eventSource = new RuntimeEventSource();
|
|
@@ -1823,7 +1502,7 @@ var CopilotRuntime = class {
|
|
|
1823
1502
|
runId: result.runId,
|
|
1824
1503
|
inputMessages,
|
|
1825
1504
|
outputMessages,
|
|
1826
|
-
properties
|
|
1505
|
+
properties
|
|
1827
1506
|
});
|
|
1828
1507
|
}).catch((_error) => {
|
|
1829
1508
|
});
|
|
@@ -1921,7 +1600,6 @@ var MessageInput = class extends BaseMessage {
|
|
|
1921
1600
|
textMessage;
|
|
1922
1601
|
actionExecutionMessage;
|
|
1923
1602
|
resultMessage;
|
|
1924
|
-
agentMessage;
|
|
1925
1603
|
};
|
|
1926
1604
|
__name(MessageInput, "MessageInput");
|
|
1927
1605
|
_ts_decorate2([
|
|
@@ -1942,12 +1620,6 @@ _ts_decorate2([
|
|
|
1942
1620
|
}),
|
|
1943
1621
|
_ts_metadata2("design:type", typeof ResultMessageInput === "undefined" ? Object : ResultMessageInput)
|
|
1944
1622
|
], MessageInput.prototype, "resultMessage", void 0);
|
|
1945
|
-
_ts_decorate2([
|
|
1946
|
-
(0, import_type_graphql3.Field)(() => AgentMessageInput, {
|
|
1947
|
-
nullable: true
|
|
1948
|
-
}),
|
|
1949
|
-
_ts_metadata2("design:type", typeof AgentMessageInput === "undefined" ? Object : AgentMessageInput)
|
|
1950
|
-
], MessageInput.prototype, "agentMessage", void 0);
|
|
1951
1623
|
MessageInput = _ts_decorate2([
|
|
1952
1624
|
(0, import_type_graphql3.InputType)()
|
|
1953
1625
|
], MessageInput);
|
|
@@ -2009,42 +1681,6 @@ _ts_decorate2([
|
|
|
2009
1681
|
ResultMessageInput = _ts_decorate2([
|
|
2010
1682
|
(0, import_type_graphql3.InputType)()
|
|
2011
1683
|
], ResultMessageInput);
|
|
2012
|
-
var AgentMessageInput = class {
|
|
2013
|
-
threadId;
|
|
2014
|
-
agentName;
|
|
2015
|
-
role;
|
|
2016
|
-
state;
|
|
2017
|
-
running;
|
|
2018
|
-
nodeName;
|
|
2019
|
-
};
|
|
2020
|
-
__name(AgentMessageInput, "AgentMessageInput");
|
|
2021
|
-
_ts_decorate2([
|
|
2022
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2023
|
-
_ts_metadata2("design:type", String)
|
|
2024
|
-
], AgentMessageInput.prototype, "threadId", void 0);
|
|
2025
|
-
_ts_decorate2([
|
|
2026
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2027
|
-
_ts_metadata2("design:type", String)
|
|
2028
|
-
], AgentMessageInput.prototype, "agentName", void 0);
|
|
2029
|
-
_ts_decorate2([
|
|
2030
|
-
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
2031
|
-
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
2032
|
-
], AgentMessageInput.prototype, "role", void 0);
|
|
2033
|
-
_ts_decorate2([
|
|
2034
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2035
|
-
_ts_metadata2("design:type", String)
|
|
2036
|
-
], AgentMessageInput.prototype, "state", void 0);
|
|
2037
|
-
_ts_decorate2([
|
|
2038
|
-
(0, import_type_graphql3.Field)(() => Boolean),
|
|
2039
|
-
_ts_metadata2("design:type", Boolean)
|
|
2040
|
-
], AgentMessageInput.prototype, "running", void 0);
|
|
2041
|
-
_ts_decorate2([
|
|
2042
|
-
(0, import_type_graphql3.Field)(() => String),
|
|
2043
|
-
_ts_metadata2("design:type", String)
|
|
2044
|
-
], AgentMessageInput.prototype, "nodeName", void 0);
|
|
2045
|
-
AgentMessageInput = _ts_decorate2([
|
|
2046
|
-
(0, import_type_graphql3.InputType)()
|
|
2047
|
-
], AgentMessageInput);
|
|
2048
1684
|
|
|
2049
1685
|
// src/graphql/inputs/frontend.input.ts
|
|
2050
1686
|
var import_type_graphql5 = require("type-graphql");
|
|
@@ -2588,8 +2224,6 @@ BaseMessageOutput = _ts_decorate11([
|
|
|
2588
2224
|
return ActionExecutionMessageOutput;
|
|
2589
2225
|
} else if (value.hasOwnProperty("result")) {
|
|
2590
2226
|
return ResultMessageOutput;
|
|
2591
|
-
} else if (value.hasOwnProperty("agentName")) {
|
|
2592
|
-
return AgentMessageOutput;
|
|
2593
2227
|
}
|
|
2594
2228
|
return void 0;
|
|
2595
2229
|
}
|
|
@@ -2663,44 +2297,6 @@ ResultMessageOutput = _ts_decorate11([
|
|
|
2663
2297
|
implements: BaseMessageOutput
|
|
2664
2298
|
})
|
|
2665
2299
|
], ResultMessageOutput);
|
|
2666
|
-
var AgentMessageOutput = class {
|
|
2667
|
-
threadId;
|
|
2668
|
-
agentName;
|
|
2669
|
-
nodeName;
|
|
2670
|
-
role;
|
|
2671
|
-
state;
|
|
2672
|
-
running;
|
|
2673
|
-
};
|
|
2674
|
-
__name(AgentMessageOutput, "AgentMessageOutput");
|
|
2675
|
-
_ts_decorate11([
|
|
2676
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2677
|
-
_ts_metadata11("design:type", String)
|
|
2678
|
-
], AgentMessageOutput.prototype, "threadId", void 0);
|
|
2679
|
-
_ts_decorate11([
|
|
2680
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2681
|
-
_ts_metadata11("design:type", String)
|
|
2682
|
-
], AgentMessageOutput.prototype, "agentName", void 0);
|
|
2683
|
-
_ts_decorate11([
|
|
2684
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2685
|
-
_ts_metadata11("design:type", String)
|
|
2686
|
-
], AgentMessageOutput.prototype, "nodeName", void 0);
|
|
2687
|
-
_ts_decorate11([
|
|
2688
|
-
(0, import_type_graphql12.Field)(() => MessageRole),
|
|
2689
|
-
_ts_metadata11("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
2690
|
-
], AgentMessageOutput.prototype, "role", void 0);
|
|
2691
|
-
_ts_decorate11([
|
|
2692
|
-
(0, import_type_graphql12.Field)(() => String),
|
|
2693
|
-
_ts_metadata11("design:type", String)
|
|
2694
|
-
], AgentMessageOutput.prototype, "state", void 0);
|
|
2695
|
-
_ts_decorate11([
|
|
2696
|
-
(0, import_type_graphql12.Field)(() => Boolean),
|
|
2697
|
-
_ts_metadata11("design:type", Boolean)
|
|
2698
|
-
], AgentMessageOutput.prototype, "running", void 0);
|
|
2699
|
-
AgentMessageOutput = _ts_decorate11([
|
|
2700
|
-
(0, import_type_graphql12.ObjectType)({
|
|
2701
|
-
implements: BaseMessageOutput
|
|
2702
|
-
})
|
|
2703
|
-
], AgentMessageOutput);
|
|
2704
2300
|
var CopilotResponse = class {
|
|
2705
2301
|
threadId;
|
|
2706
2302
|
status;
|
|
@@ -2771,6 +2367,15 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
|
|
|
2771
2367
|
};
|
|
2772
2368
|
__name(UnknownErrorResponse, "UnknownErrorResponse");
|
|
2773
2369
|
|
|
2370
|
+
// src/lib/telemetry-client.ts
|
|
2371
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
2372
|
+
var packageJson = require_package();
|
|
2373
|
+
var telemetryClient = new import_shared8.TelemetryClient({
|
|
2374
|
+
packageName: packageJson.name,
|
|
2375
|
+
packageVersion: packageJson.version
|
|
2376
|
+
});
|
|
2377
|
+
var telemetry_client_default = telemetryClient;
|
|
2378
|
+
|
|
2774
2379
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2775
2380
|
var import_shared9 = require("@copilotkit/shared");
|
|
2776
2381
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
@@ -2797,6 +2402,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
2797
2402
|
__name(_ts_param, "_ts_param");
|
|
2798
2403
|
var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
|
|
2799
2404
|
var _a;
|
|
2405
|
+
console.log("invokeGuardrails.baseUrl", baseUrl);
|
|
2800
2406
|
if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
|
|
2801
2407
|
const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
|
|
2802
2408
|
role: m.textMessage.role,
|
|
@@ -2842,6 +2448,8 @@ var CopilotResolver = class {
|
|
|
2842
2448
|
logger2.debug({
|
|
2843
2449
|
data
|
|
2844
2450
|
}, "Generating Copilot response");
|
|
2451
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2452
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
2845
2453
|
if (properties) {
|
|
2846
2454
|
logger2.debug("Properties provided, merging with context properties");
|
|
2847
2455
|
ctx.properties = {
|
|
@@ -2849,8 +2457,6 @@ var CopilotResolver = class {
|
|
|
2849
2457
|
...properties
|
|
2850
2458
|
};
|
|
2851
2459
|
}
|
|
2852
|
-
const copilotRuntime = ctx._copilotkit.runtime;
|
|
2853
|
-
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
2854
2460
|
let copilotCloudPublicApiKey = null;
|
|
2855
2461
|
let copilotCloudBaseUrl;
|
|
2856
2462
|
if (data.cloud) {
|
|
@@ -2896,8 +2502,8 @@ var CopilotResolver = class {
|
|
|
2896
2502
|
threadId: data.threadId,
|
|
2897
2503
|
runId: data.runId,
|
|
2898
2504
|
publicApiKey: void 0,
|
|
2505
|
+
properties: ctx.properties || {},
|
|
2899
2506
|
outputMessagesPromise,
|
|
2900
|
-
graphqlContext: ctx,
|
|
2901
2507
|
forwardedParameters: data.forwardedParameters
|
|
2902
2508
|
});
|
|
2903
2509
|
logger2.debug("Event source created, creating response");
|
|
@@ -3105,32 +2711,6 @@ var CopilotResolver = class {
|
|
|
3105
2711
|
result: event.result
|
|
3106
2712
|
}));
|
|
3107
2713
|
break;
|
|
3108
|
-
case RuntimeEventTypes.AgentMessage:
|
|
3109
|
-
logger2.debug({
|
|
3110
|
-
event
|
|
3111
|
-
}, "Agent message event received");
|
|
3112
|
-
pushMessage({
|
|
3113
|
-
id: (0, import_shared9.randomId)(),
|
|
3114
|
-
status: new SuccessMessageStatus(),
|
|
3115
|
-
threadId: event.threadId,
|
|
3116
|
-
agentName: event.agentName,
|
|
3117
|
-
nodeName: event.nodeName,
|
|
3118
|
-
state: JSON.stringify(event.state),
|
|
3119
|
-
running: event.running,
|
|
3120
|
-
role: MessageRole.assistant,
|
|
3121
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
3122
|
-
});
|
|
3123
|
-
outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentMessage, {
|
|
3124
|
-
id: (0, import_shared9.randomId)(),
|
|
3125
|
-
threadId: event.threadId,
|
|
3126
|
-
agentName: event.agentName,
|
|
3127
|
-
nodeName: event.nodeName,
|
|
3128
|
-
state: JSON.stringify(event.state),
|
|
3129
|
-
running: event.running,
|
|
3130
|
-
role: MessageRole.assistant,
|
|
3131
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
3132
|
-
}));
|
|
3133
|
-
break;
|
|
3134
2714
|
}
|
|
3135
2715
|
},
|
|
3136
2716
|
error: (err) => {
|