@dudousxd/nestjs-agent-store-drizzle 0.29.12 → 0.30.0
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/index.cjs +204 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4412 -2649
- package/dist/index.d.ts +4412 -2649
- package/dist/index.js +205 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
agentChannelState: () => agentChannelState,
|
|
38
38
|
agentConfirmToken: () => agentConfirmToken,
|
|
39
39
|
agentDialectOf: () => agentDialectOf,
|
|
40
|
+
agentGenuiCall: () => agentGenuiCall,
|
|
40
41
|
agentMemory: () => agentMemory,
|
|
41
42
|
agentMessage: () => agentMessage,
|
|
42
43
|
agentModelPricing: () => agentModelPricing,
|
|
@@ -247,6 +248,37 @@ var agentTokenUsage = (0, import_sqlite_core.sqliteTable)("agent_token_usage", {
|
|
|
247
248
|
}, (table) => [
|
|
248
249
|
(0, import_sqlite_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt)
|
|
249
250
|
]);
|
|
251
|
+
var agentGenuiCall = (0, import_sqlite_core.sqliteTable)("agent_genui_call", {
|
|
252
|
+
id: (0, import_sqlite_core.text)("id").primaryKey(),
|
|
253
|
+
runId: (0, import_sqlite_core.text)("run_id").notNull(),
|
|
254
|
+
threadId: (0, import_sqlite_core.text)("thread_id").notNull().references(() => agentThread.id, {
|
|
255
|
+
onDelete: "cascade"
|
|
256
|
+
}),
|
|
257
|
+
actorRef: (0, import_sqlite_core.text)("actor_ref").notNull(),
|
|
258
|
+
agentName: (0, import_sqlite_core.text)("agent_name"),
|
|
259
|
+
step: (0, import_sqlite_core.integer)("step").notNull(),
|
|
260
|
+
toolName: (0, import_sqlite_core.text)("tool_name").notNull(),
|
|
261
|
+
channel: (0, import_sqlite_core.text)("channel").notNull(),
|
|
262
|
+
mode: (0, import_sqlite_core.text)("mode").$type().notNull(),
|
|
263
|
+
modelId: (0, import_sqlite_core.text)("model_id").notNull(),
|
|
264
|
+
attempt: (0, import_sqlite_core.integer)("attempt").notNull(),
|
|
265
|
+
outcome: (0, import_sqlite_core.text)("outcome").$type().notNull(),
|
|
266
|
+
validity: (0, import_sqlite_core.text)("validity").$type().notNull(),
|
|
267
|
+
errorCategory: (0, import_sqlite_core.text)("error_category").$type(),
|
|
268
|
+
errorMessage: (0, import_sqlite_core.text)("error_message"),
|
|
269
|
+
inputTokens: (0, import_sqlite_core.integer)("input_tokens").notNull(),
|
|
270
|
+
outputTokens: (0, import_sqlite_core.integer)("output_tokens").notNull(),
|
|
271
|
+
costUsd: (0, import_sqlite_core.real)("cost_usd"),
|
|
272
|
+
costSource: (0, import_sqlite_core.text)("cost_source").$type(),
|
|
273
|
+
firstFrameMs: (0, import_sqlite_core.integer)("first_frame_ms"),
|
|
274
|
+
completeFrameMs: (0, import_sqlite_core.integer)("complete_frame_ms"),
|
|
275
|
+
payloadBytes: (0, import_sqlite_core.integer)("payload_bytes").notNull(),
|
|
276
|
+
payload: (0, import_sqlite_core.text)("payload"),
|
|
277
|
+
createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
|
|
278
|
+
}, (table) => [
|
|
279
|
+
(0, import_sqlite_core.index)("agent_genui_call_created_idx").on(table.createdAt),
|
|
280
|
+
(0, import_sqlite_core.index)("agent_genui_call_run_idx").on(table.runId)
|
|
281
|
+
]);
|
|
250
282
|
var agentModelPricing = (0, import_sqlite_core.sqliteTable)("agent_model_pricing", {
|
|
251
283
|
id: (0, import_sqlite_core.text)("id").primaryKey(),
|
|
252
284
|
modelId: (0, import_sqlite_core.text)("model_id").notNull(),
|
|
@@ -411,6 +443,7 @@ var agentSchema = {
|
|
|
411
443
|
agentQueuedMessage,
|
|
412
444
|
agentToolCall,
|
|
413
445
|
agentTokenUsage,
|
|
446
|
+
agentGenuiCall,
|
|
414
447
|
agentModelPricing,
|
|
415
448
|
agentRun,
|
|
416
449
|
agentMemory,
|
|
@@ -552,6 +585,45 @@ var agentTokenUsage2 = (0, import_mysql_core.mysqlTable)("agent_token_usage", {
|
|
|
552
585
|
}, (table) => [
|
|
553
586
|
(0, import_mysql_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt)
|
|
554
587
|
]);
|
|
588
|
+
var agentGenuiCall2 = (0, import_mysql_core.mysqlTable)("agent_genui_call", {
|
|
589
|
+
id: key("id").primaryKey(),
|
|
590
|
+
runId: key("run_id").notNull(),
|
|
591
|
+
threadId: key("thread_id").notNull().references(() => agentThread2.id, {
|
|
592
|
+
onDelete: "cascade"
|
|
593
|
+
}),
|
|
594
|
+
actorRef: key("actor_ref").notNull(),
|
|
595
|
+
agentName: key("agent_name"),
|
|
596
|
+
step: (0, import_mysql_core.int)("step").notNull(),
|
|
597
|
+
toolName: key("tool_name").notNull(),
|
|
598
|
+
channel: key("channel").notNull(),
|
|
599
|
+
mode: key("mode").$type().notNull(),
|
|
600
|
+
modelId: key("model_id").notNull(),
|
|
601
|
+
attempt: (0, import_mysql_core.int)("attempt").notNull(),
|
|
602
|
+
outcome: key("outcome").$type().notNull(),
|
|
603
|
+
validity: key("validity").$type().notNull(),
|
|
604
|
+
errorCategory: key("error_category").$type(),
|
|
605
|
+
errorMessage: (0, import_mysql_core.longtext)("error_message"),
|
|
606
|
+
inputTokens: (0, import_mysql_core.int)("input_tokens").notNull(),
|
|
607
|
+
outputTokens: (0, import_mysql_core.int)("output_tokens").notNull(),
|
|
608
|
+
costUsd: (0, import_mysql_core.double)("cost_usd"),
|
|
609
|
+
costSource: (0, import_mysql_core.varchar)("cost_source", {
|
|
610
|
+
length: 16
|
|
611
|
+
}).$type(),
|
|
612
|
+
firstFrameMs: (0, import_mysql_core.bigint)("first_frame_ms", {
|
|
613
|
+
mode: "number"
|
|
614
|
+
}),
|
|
615
|
+
completeFrameMs: (0, import_mysql_core.bigint)("complete_frame_ms", {
|
|
616
|
+
mode: "number"
|
|
617
|
+
}),
|
|
618
|
+
payloadBytes: (0, import_mysql_core.int)("payload_bytes").notNull(),
|
|
619
|
+
payload: (0, import_mysql_core.longtext)("payload"),
|
|
620
|
+
createdAt: (0, import_mysql_core.bigint)("created_at", {
|
|
621
|
+
mode: "number"
|
|
622
|
+
}).notNull()
|
|
623
|
+
}, (table) => [
|
|
624
|
+
(0, import_mysql_core.index)("agent_genui_call_created_idx").on(table.createdAt),
|
|
625
|
+
(0, import_mysql_core.index)("agent_genui_call_run_idx").on(table.runId)
|
|
626
|
+
]);
|
|
555
627
|
var agentModelPricing2 = (0, import_mysql_core.mysqlTable)("agent_model_pricing", {
|
|
556
628
|
id: key("id").primaryKey(),
|
|
557
629
|
modelId: key("model_id").notNull(),
|
|
@@ -707,6 +779,7 @@ var mysqlAgentSchema = {
|
|
|
707
779
|
agentQueuedMessage: agentQueuedMessage2,
|
|
708
780
|
agentToolCall: agentToolCall2,
|
|
709
781
|
agentTokenUsage: agentTokenUsage2,
|
|
782
|
+
agentGenuiCall: agentGenuiCall2,
|
|
710
783
|
agentModelPricing: agentModelPricing2,
|
|
711
784
|
agentRun: agentRun2,
|
|
712
785
|
agentMemory: agentMemory2,
|
|
@@ -835,6 +908,45 @@ var agentTokenUsage3 = (0, import_pg_core.pgTable)("agent_token_usage", {
|
|
|
835
908
|
}, (table) => [
|
|
836
909
|
(0, import_pg_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt)
|
|
837
910
|
]);
|
|
911
|
+
var agentGenuiCall3 = (0, import_pg_core.pgTable)("agent_genui_call", {
|
|
912
|
+
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
913
|
+
runId: (0, import_pg_core.text)("run_id").notNull(),
|
|
914
|
+
threadId: (0, import_pg_core.text)("thread_id").notNull().references(() => agentThread3.id, {
|
|
915
|
+
onDelete: "cascade"
|
|
916
|
+
}),
|
|
917
|
+
actorRef: (0, import_pg_core.text)("actor_ref").notNull(),
|
|
918
|
+
agentName: (0, import_pg_core.text)("agent_name"),
|
|
919
|
+
step: (0, import_pg_core.integer)("step").notNull(),
|
|
920
|
+
toolName: (0, import_pg_core.text)("tool_name").notNull(),
|
|
921
|
+
channel: (0, import_pg_core.text)("channel").notNull(),
|
|
922
|
+
mode: (0, import_pg_core.text)("mode").$type().notNull(),
|
|
923
|
+
modelId: (0, import_pg_core.text)("model_id").notNull(),
|
|
924
|
+
attempt: (0, import_pg_core.integer)("attempt").notNull(),
|
|
925
|
+
outcome: (0, import_pg_core.text)("outcome").$type().notNull(),
|
|
926
|
+
validity: (0, import_pg_core.text)("validity").$type().notNull(),
|
|
927
|
+
errorCategory: (0, import_pg_core.text)("error_category").$type(),
|
|
928
|
+
errorMessage: (0, import_pg_core.text)("error_message"),
|
|
929
|
+
inputTokens: (0, import_pg_core.integer)("input_tokens").notNull(),
|
|
930
|
+
outputTokens: (0, import_pg_core.integer)("output_tokens").notNull(),
|
|
931
|
+
costUsd: (0, import_pg_core.doublePrecision)("cost_usd"),
|
|
932
|
+
costSource: (0, import_pg_core.varchar)("cost_source", {
|
|
933
|
+
length: 16
|
|
934
|
+
}).$type(),
|
|
935
|
+
firstFrameMs: (0, import_pg_core.bigint)("first_frame_ms", {
|
|
936
|
+
mode: "number"
|
|
937
|
+
}),
|
|
938
|
+
completeFrameMs: (0, import_pg_core.bigint)("complete_frame_ms", {
|
|
939
|
+
mode: "number"
|
|
940
|
+
}),
|
|
941
|
+
payloadBytes: (0, import_pg_core.integer)("payload_bytes").notNull(),
|
|
942
|
+
payload: (0, import_pg_core.text)("payload"),
|
|
943
|
+
createdAt: (0, import_pg_core.bigint)("created_at", {
|
|
944
|
+
mode: "number"
|
|
945
|
+
}).notNull()
|
|
946
|
+
}, (table) => [
|
|
947
|
+
(0, import_pg_core.index)("agent_genui_call_created_idx").on(table.createdAt),
|
|
948
|
+
(0, import_pg_core.index)("agent_genui_call_run_idx").on(table.runId)
|
|
949
|
+
]);
|
|
838
950
|
var agentModelPricing3 = (0, import_pg_core.pgTable)("agent_model_pricing", {
|
|
839
951
|
id: (0, import_pg_core.text)("id").primaryKey(),
|
|
840
952
|
modelId: (0, import_pg_core.text)("model_id").notNull(),
|
|
@@ -988,6 +1100,7 @@ var pgAgentSchema = {
|
|
|
988
1100
|
agentQueuedMessage: agentQueuedMessage3,
|
|
989
1101
|
agentToolCall: agentToolCall3,
|
|
990
1102
|
agentTokenUsage: agentTokenUsage3,
|
|
1103
|
+
agentGenuiCall: agentGenuiCall3,
|
|
991
1104
|
agentModelPricing: agentModelPricing3,
|
|
992
1105
|
agentRun: agentRun3,
|
|
993
1106
|
agentMemory: agentMemory3,
|
|
@@ -2592,6 +2705,44 @@ var DrizzleAgentStore = class {
|
|
|
2592
2705
|
createdAt: /* @__PURE__ */ new Date()
|
|
2593
2706
|
});
|
|
2594
2707
|
}
|
|
2708
|
+
/**
|
|
2709
|
+
* Generative-UI telemetry: one `agent_genui_call` row per UI tool call, upserted by its tool call
|
|
2710
|
+
* id — a replayed record replaces the row (keeping the first `created_at`) rather than adding one.
|
|
2711
|
+
*/
|
|
2712
|
+
async recordGenuiCalls(rows) {
|
|
2713
|
+
const table = this.t.agentGenuiCall;
|
|
2714
|
+
for (const row of rows) {
|
|
2715
|
+
const columns = {
|
|
2716
|
+
runId: row.runId,
|
|
2717
|
+
threadId: row.threadId,
|
|
2718
|
+
actorRef: row.actorRef,
|
|
2719
|
+
agentName: row.agentName ?? null,
|
|
2720
|
+
step: row.step,
|
|
2721
|
+
toolName: row.toolName,
|
|
2722
|
+
channel: row.channel,
|
|
2723
|
+
mode: row.mode,
|
|
2724
|
+
modelId: row.modelId,
|
|
2725
|
+
attempt: row.attempt,
|
|
2726
|
+
outcome: row.outcome,
|
|
2727
|
+
validity: row.validity,
|
|
2728
|
+
errorCategory: row.errorCategory ?? null,
|
|
2729
|
+
errorMessage: row.errorMessage ?? null,
|
|
2730
|
+
inputTokens: row.inputTokens,
|
|
2731
|
+
outputTokens: row.outputTokens,
|
|
2732
|
+
costUsd: row.costUsd ?? null,
|
|
2733
|
+
costSource: row.costSource ?? null,
|
|
2734
|
+
firstFrameMs: row.firstFrameMs ?? null,
|
|
2735
|
+
completeFrameMs: row.completeFrameMs ?? null,
|
|
2736
|
+
payloadBytes: row.payloadBytes,
|
|
2737
|
+
payload: row.payload ?? null
|
|
2738
|
+
};
|
|
2739
|
+
await upsert(this.dialect, this.db.insert(table).values({
|
|
2740
|
+
id: row.toolCallId,
|
|
2741
|
+
...columns,
|
|
2742
|
+
createdAt: Date.now()
|
|
2743
|
+
}), table.id, columns);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2595
2746
|
async quotaToday(actorRef, day) {
|
|
2596
2747
|
return this.usageBetween(actorRef, day, day);
|
|
2597
2748
|
}
|
|
@@ -2764,6 +2915,51 @@ function emptyPage(query) {
|
|
|
2764
2915
|
};
|
|
2765
2916
|
}
|
|
2766
2917
|
__name(emptyPage, "emptyPage");
|
|
2918
|
+
function toGenuiCallRow(row) {
|
|
2919
|
+
return {
|
|
2920
|
+
toolCallId: row.id,
|
|
2921
|
+
runId: row.runId,
|
|
2922
|
+
threadId: row.threadId,
|
|
2923
|
+
actorRef: row.actorRef,
|
|
2924
|
+
...row.agentName !== null ? {
|
|
2925
|
+
agentName: row.agentName
|
|
2926
|
+
} : {},
|
|
2927
|
+
step: Number(row.step),
|
|
2928
|
+
toolName: row.toolName,
|
|
2929
|
+
channel: row.channel,
|
|
2930
|
+
mode: row.mode,
|
|
2931
|
+
modelId: row.modelId,
|
|
2932
|
+
attempt: Number(row.attempt),
|
|
2933
|
+
outcome: row.outcome,
|
|
2934
|
+
validity: row.validity,
|
|
2935
|
+
...row.errorCategory !== null ? {
|
|
2936
|
+
errorCategory: row.errorCategory
|
|
2937
|
+
} : {},
|
|
2938
|
+
...row.errorMessage !== null ? {
|
|
2939
|
+
errorMessage: row.errorMessage
|
|
2940
|
+
} : {},
|
|
2941
|
+
inputTokens: Number(row.inputTokens),
|
|
2942
|
+
outputTokens: Number(row.outputTokens),
|
|
2943
|
+
...row.costUsd !== null ? {
|
|
2944
|
+
costUsd: Number(row.costUsd)
|
|
2945
|
+
} : {},
|
|
2946
|
+
...row.costSource !== null ? {
|
|
2947
|
+
costSource: row.costSource
|
|
2948
|
+
} : {},
|
|
2949
|
+
...row.firstFrameMs !== null ? {
|
|
2950
|
+
firstFrameMs: Number(row.firstFrameMs)
|
|
2951
|
+
} : {},
|
|
2952
|
+
...row.completeFrameMs !== null ? {
|
|
2953
|
+
completeFrameMs: Number(row.completeFrameMs)
|
|
2954
|
+
} : {},
|
|
2955
|
+
payloadBytes: Number(row.payloadBytes),
|
|
2956
|
+
...row.payload !== null ? {
|
|
2957
|
+
payload: row.payload
|
|
2958
|
+
} : {},
|
|
2959
|
+
createdAt: new Date(Number(row.createdAt))
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
__name(toGenuiCallRow, "toGenuiCallRow");
|
|
2767
2963
|
function toRecentRunRow(run) {
|
|
2768
2964
|
return {
|
|
2769
2965
|
runId: run.id,
|
|
@@ -3349,6 +3545,13 @@ var DrizzleGovernanceQueries = class {
|
|
|
3349
3545
|
})
|
|
3350
3546
|
};
|
|
3351
3547
|
}
|
|
3548
|
+
/** Generative-UI stats over the `agent_genui_call` rows created in the (UTC, inclusive) day range. */
|
|
3549
|
+
async genuiStats(range) {
|
|
3550
|
+
const { start, end } = (0, import_nestjs_agent_core5.dayBoundsUtc)(range);
|
|
3551
|
+
const table = this.t.agentGenuiCall;
|
|
3552
|
+
const rows = await this.db.select().from(table).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.gte)(table.createdAt, start.getTime()), (0, import_drizzle_orm5.lte)(table.createdAt, end.getTime())));
|
|
3553
|
+
return (0, import_nestjs_agent_core5.summarizeGenuiCalls)(rows.map(toGenuiCallRow));
|
|
3554
|
+
}
|
|
3352
3555
|
/** Tool-call counts for a set of messages in ONE grouped query — the detail view's no-N+1 guarantee. */
|
|
3353
3556
|
async toolCallCountsByMessage(messageIds) {
|
|
3354
3557
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -4195,6 +4398,7 @@ DrizzleAgentStoreModule = _ts_decorate2([
|
|
|
4195
4398
|
agentChannelState,
|
|
4196
4399
|
agentConfirmToken,
|
|
4197
4400
|
agentDialectOf,
|
|
4401
|
+
agentGenuiCall,
|
|
4198
4402
|
agentMemory,
|
|
4199
4403
|
agentMessage,
|
|
4200
4404
|
agentModelPricing,
|