@elizaos/plugin-sql 1.6.0-beta.1 → 1.6.1-alpha.1
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/dist/browser/index.browser.js +171 -1
- package/dist/browser/index.browser.js.map +3 -3
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.node.js +171 -1
- package/dist/node/index.node.js.map +3 -3
- package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1206,6 +1206,176 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
1206
1206
|
return logs;
|
|
1207
1207
|
});
|
|
1208
1208
|
}
|
|
1209
|
+
async getAgentRunSummaries(params = {}) {
|
|
1210
|
+
const limit = Math.min(Math.max(params.limit ?? 20, 1), 100);
|
|
1211
|
+
const fromDate = typeof params.from === "number" ? new Date(params.from) : undefined;
|
|
1212
|
+
const toDate = typeof params.to === "number" ? new Date(params.to) : undefined;
|
|
1213
|
+
return this.withDatabase(async () => {
|
|
1214
|
+
const runMap = new Map;
|
|
1215
|
+
const conditions = [
|
|
1216
|
+
eq(logTable.type, "run_event"),
|
|
1217
|
+
sql16`${logTable.body} ? 'runId'`,
|
|
1218
|
+
eq(roomTable.agentId, this.agentId)
|
|
1219
|
+
];
|
|
1220
|
+
if (params.roomId) {
|
|
1221
|
+
conditions.push(eq(logTable.roomId, params.roomId));
|
|
1222
|
+
}
|
|
1223
|
+
if (fromDate) {
|
|
1224
|
+
conditions.push(gte(logTable.createdAt, fromDate));
|
|
1225
|
+
}
|
|
1226
|
+
if (toDate) {
|
|
1227
|
+
conditions.push(lte(logTable.createdAt, toDate));
|
|
1228
|
+
}
|
|
1229
|
+
const whereClause = and(...conditions);
|
|
1230
|
+
const eventLimit = Math.max(limit * 20, 200);
|
|
1231
|
+
const runEventRows = await this.db.select({
|
|
1232
|
+
runId: sql16`(${logTable.body} ->> 'runId')`,
|
|
1233
|
+
status: sql16`(${logTable.body} ->> 'status')`,
|
|
1234
|
+
messageId: sql16`(${logTable.body} ->> 'messageId')`,
|
|
1235
|
+
rawBody: logTable.body,
|
|
1236
|
+
createdAt: logTable.createdAt,
|
|
1237
|
+
roomId: logTable.roomId,
|
|
1238
|
+
entityId: logTable.entityId
|
|
1239
|
+
}).from(logTable).innerJoin(roomTable, eq(roomTable.id, logTable.roomId)).where(whereClause).orderBy(desc(logTable.createdAt)).limit(eventLimit);
|
|
1240
|
+
for (const row of runEventRows) {
|
|
1241
|
+
const runId = row.runId;
|
|
1242
|
+
if (!runId)
|
|
1243
|
+
continue;
|
|
1244
|
+
const summary = runMap.get(runId) ?? {
|
|
1245
|
+
runId,
|
|
1246
|
+
status: "started",
|
|
1247
|
+
startedAt: null,
|
|
1248
|
+
endedAt: null,
|
|
1249
|
+
durationMs: null,
|
|
1250
|
+
messageId: undefined,
|
|
1251
|
+
roomId: undefined,
|
|
1252
|
+
entityId: undefined,
|
|
1253
|
+
metadata: {}
|
|
1254
|
+
};
|
|
1255
|
+
if (!summary.messageId && row.messageId) {
|
|
1256
|
+
summary.messageId = row.messageId;
|
|
1257
|
+
}
|
|
1258
|
+
if (!summary.roomId && row.roomId) {
|
|
1259
|
+
summary.roomId = row.roomId;
|
|
1260
|
+
}
|
|
1261
|
+
if (!summary.entityId && row.entityId) {
|
|
1262
|
+
summary.entityId = row.entityId;
|
|
1263
|
+
}
|
|
1264
|
+
const body = row.rawBody;
|
|
1265
|
+
if (body && typeof body === "object") {
|
|
1266
|
+
if (!summary.roomId && typeof body.roomId === "string") {
|
|
1267
|
+
summary.roomId = body.roomId;
|
|
1268
|
+
}
|
|
1269
|
+
if (!summary.entityId && typeof body.entityId === "string") {
|
|
1270
|
+
summary.entityId = body.entityId;
|
|
1271
|
+
}
|
|
1272
|
+
if (!summary.messageId && typeof body.messageId === "string") {
|
|
1273
|
+
summary.messageId = body.messageId;
|
|
1274
|
+
}
|
|
1275
|
+
if (!summary.metadata || Object.keys(summary.metadata).length === 0) {
|
|
1276
|
+
const metadata = body.metadata ?? undefined;
|
|
1277
|
+
summary.metadata = metadata ? { ...metadata } : {};
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const createdAt = row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt);
|
|
1281
|
+
const timestamp16 = createdAt.getTime();
|
|
1282
|
+
const eventStatus = row.status ?? body?.status;
|
|
1283
|
+
if (eventStatus === "started") {
|
|
1284
|
+
summary.startedAt = summary.startedAt === null ? timestamp16 : Math.min(summary.startedAt, timestamp16);
|
|
1285
|
+
} else if (eventStatus === "completed" || eventStatus === "timeout" || eventStatus === "error") {
|
|
1286
|
+
summary.status = eventStatus;
|
|
1287
|
+
summary.endedAt = timestamp16;
|
|
1288
|
+
if (summary.startedAt !== null) {
|
|
1289
|
+
summary.durationMs = Math.max(timestamp16 - summary.startedAt, 0);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
runMap.set(runId, summary);
|
|
1293
|
+
}
|
|
1294
|
+
let runs = Array.from(runMap.values());
|
|
1295
|
+
if (params.status && params.status !== "all") {
|
|
1296
|
+
runs = runs.filter((run) => run.status === params.status);
|
|
1297
|
+
}
|
|
1298
|
+
runs.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
|
|
1299
|
+
const total = runs.length;
|
|
1300
|
+
const limitedRuns = runs.slice(0, limit);
|
|
1301
|
+
const hasMore = total > limit;
|
|
1302
|
+
const runCounts = new Map;
|
|
1303
|
+
for (const run of limitedRuns) {
|
|
1304
|
+
runCounts.set(run.runId, { actions: 0, modelCalls: 0, errors: 0, evaluators: 0 });
|
|
1305
|
+
}
|
|
1306
|
+
const runIds = limitedRuns.map((run) => run.runId).filter(Boolean);
|
|
1307
|
+
if (runIds.length > 0) {
|
|
1308
|
+
const runIdArray = sql16`array[${sql16.join(runIds.map((id) => sql16`${id}`), sql16`, `)}]::text[]`;
|
|
1309
|
+
const actionSummary = await this.db.execute(sql16`
|
|
1310
|
+
SELECT
|
|
1311
|
+
body->>'runId' as "runId",
|
|
1312
|
+
COUNT(*)::int as "actions",
|
|
1313
|
+
SUM(CASE WHEN COALESCE(body->'result'->>'success', 'true') = 'false' THEN 1 ELSE 0 END)::int as "errors",
|
|
1314
|
+
SUM(COALESCE((body->>'promptCount')::int, 0))::int as "modelCalls"
|
|
1315
|
+
FROM ${logTable}
|
|
1316
|
+
WHERE type = 'action'
|
|
1317
|
+
AND body->>'runId' = ANY(${runIdArray})
|
|
1318
|
+
GROUP BY body->>'runId'
|
|
1319
|
+
`);
|
|
1320
|
+
const actionRows = actionSummary.rows ?? [];
|
|
1321
|
+
for (const row of actionRows) {
|
|
1322
|
+
const counts = runCounts.get(row.runId);
|
|
1323
|
+
if (!counts)
|
|
1324
|
+
continue;
|
|
1325
|
+
counts.actions += Number(row.actions ?? 0);
|
|
1326
|
+
counts.errors += Number(row.errors ?? 0);
|
|
1327
|
+
counts.modelCalls += Number(row.modelCalls ?? 0);
|
|
1328
|
+
}
|
|
1329
|
+
const evaluatorSummary = await this.db.execute(sql16`
|
|
1330
|
+
SELECT
|
|
1331
|
+
body->>'runId' as "runId",
|
|
1332
|
+
COUNT(*)::int as "evaluators"
|
|
1333
|
+
FROM ${logTable}
|
|
1334
|
+
WHERE type = 'evaluator'
|
|
1335
|
+
AND body->>'runId' = ANY(${runIdArray})
|
|
1336
|
+
GROUP BY body->>'runId'
|
|
1337
|
+
`);
|
|
1338
|
+
const evaluatorRows = evaluatorSummary.rows ?? [];
|
|
1339
|
+
for (const row of evaluatorRows) {
|
|
1340
|
+
const counts = runCounts.get(row.runId);
|
|
1341
|
+
if (!counts)
|
|
1342
|
+
continue;
|
|
1343
|
+
counts.evaluators += Number(row.evaluators ?? 0);
|
|
1344
|
+
}
|
|
1345
|
+
const genericSummary = await this.db.execute(sql16`
|
|
1346
|
+
SELECT
|
|
1347
|
+
body->>'runId' as "runId",
|
|
1348
|
+
COUNT(*) FILTER (WHERE type LIKE 'useModel:%')::int as "modelLogs",
|
|
1349
|
+
COUNT(*) FILTER (WHERE type = 'embedding_event' AND body->>'status' = 'failed')::int as "embeddingErrors"
|
|
1350
|
+
FROM ${logTable}
|
|
1351
|
+
WHERE (type LIKE 'useModel:%' OR type = 'embedding_event')
|
|
1352
|
+
AND body->>'runId' = ANY(${runIdArray})
|
|
1353
|
+
GROUP BY body->>'runId'
|
|
1354
|
+
`);
|
|
1355
|
+
const genericRows = genericSummary.rows ?? [];
|
|
1356
|
+
for (const row of genericRows) {
|
|
1357
|
+
const counts = runCounts.get(row.runId);
|
|
1358
|
+
if (!counts)
|
|
1359
|
+
continue;
|
|
1360
|
+
counts.modelCalls += Number(row.modelLogs ?? 0);
|
|
1361
|
+
counts.errors += Number(row.embeddingErrors ?? 0);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
for (const run of limitedRuns) {
|
|
1365
|
+
run.counts = runCounts.get(run.runId) ?? {
|
|
1366
|
+
actions: 0,
|
|
1367
|
+
modelCalls: 0,
|
|
1368
|
+
errors: 0,
|
|
1369
|
+
evaluators: 0
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
return {
|
|
1373
|
+
runs: limitedRuns,
|
|
1374
|
+
total,
|
|
1375
|
+
hasMore
|
|
1376
|
+
};
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1209
1379
|
async deleteLog(logId) {
|
|
1210
1380
|
return this.withDatabase(async () => {
|
|
1211
1381
|
await this.db.delete(logTable).where(eq(logTable.id, logId));
|
|
@@ -3250,5 +3420,5 @@ export {
|
|
|
3250
3420
|
DatabaseMigrationService
|
|
3251
3421
|
};
|
|
3252
3422
|
|
|
3253
|
-
//# debugId=
|
|
3423
|
+
//# debugId=009857297942F85964756E2164756E21
|
|
3254
3424
|
//# sourceMappingURL=index.browser.js.map
|