@dudousxd/nestjs-agent-store-drizzle 0.20.1 → 0.21.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 +79 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +225 -3
- package/dist/index.d.ts +225 -3
- package/dist/index.js +75 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -23,11 +23,13 @@ var index_exports = {};
|
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
DrizzleAgentStore: () => DrizzleAgentStore,
|
|
25
25
|
DrizzleAgentStoreModule: () => DrizzleAgentStoreModule,
|
|
26
|
+
DrizzleConfirmTokenStore: () => DrizzleConfirmTokenStore,
|
|
26
27
|
DrizzleGovernanceQueries: () => DrizzleGovernanceQueries,
|
|
27
28
|
DrizzleMemoryProvider: () => DrizzleMemoryProvider,
|
|
28
29
|
DrizzlePricingStore: () => DrizzlePricingStore,
|
|
29
30
|
DrizzleRagIngestionLog: () => DrizzleRagIngestionLog,
|
|
30
31
|
RAG_INGESTION_LOG_PAGE_ORDER: () => RAG_INGESTION_LOG_PAGE_ORDER,
|
|
32
|
+
agentConfirmToken: () => agentConfirmToken,
|
|
31
33
|
agentMemory: () => agentMemory,
|
|
32
34
|
agentMessage: () => agentMessage,
|
|
33
35
|
agentModelPricing: () => agentModelPricing,
|
|
@@ -307,6 +309,15 @@ var ragIngestionLog = (0, import_sqlite_core.sqliteTable)("rag_ingestion_log", {
|
|
|
307
309
|
}, (table) => [
|
|
308
310
|
(0, import_sqlite_core.index)("rag_ingestion_log_collection_idx").on(table.collection, table.updatedAt)
|
|
309
311
|
]);
|
|
312
|
+
var agentConfirmToken = (0, import_sqlite_core.sqliteTable)("agent_confirm_token", {
|
|
313
|
+
hash: (0, import_sqlite_core.text)("hash").primaryKey(),
|
|
314
|
+
actorRef: (0, import_sqlite_core.text)("actor_ref").notNull(),
|
|
315
|
+
tool: (0, import_sqlite_core.text)("tool").notNull(),
|
|
316
|
+
expiresAt: (0, import_sqlite_core.integer)("expires_at").notNull(),
|
|
317
|
+
createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
|
|
318
|
+
}, (table) => [
|
|
319
|
+
(0, import_sqlite_core.index)("agent_confirm_token_expires_idx").on(table.expiresAt)
|
|
320
|
+
]);
|
|
310
321
|
var agentSchema = {
|
|
311
322
|
agentThread,
|
|
312
323
|
agentMessage,
|
|
@@ -316,7 +327,8 @@ var agentSchema = {
|
|
|
316
327
|
agentModelPricing,
|
|
317
328
|
agentRun,
|
|
318
329
|
agentMemory,
|
|
319
|
-
ragIngestionLog
|
|
330
|
+
ragIngestionLog,
|
|
331
|
+
agentConfirmToken
|
|
320
332
|
};
|
|
321
333
|
|
|
322
334
|
// src/ensure-schema.ts
|
|
@@ -471,7 +483,16 @@ var statements = [
|
|
|
471
483
|
updated_at INTEGER NOT NULL
|
|
472
484
|
)`,
|
|
473
485
|
`CREATE INDEX IF NOT EXISTS rag_ingestion_log_collection_idx
|
|
474
|
-
ON rag_ingestion_log (collection, updated_at)
|
|
486
|
+
ON rag_ingestion_log (collection, updated_at)`,
|
|
487
|
+
`CREATE TABLE IF NOT EXISTS agent_confirm_token (
|
|
488
|
+
hash TEXT PRIMARY KEY NOT NULL,
|
|
489
|
+
actor_ref TEXT NOT NULL,
|
|
490
|
+
tool TEXT NOT NULL,
|
|
491
|
+
expires_at INTEGER NOT NULL,
|
|
492
|
+
created_at INTEGER NOT NULL
|
|
493
|
+
)`,
|
|
494
|
+
`CREATE INDEX IF NOT EXISTS agent_confirm_token_expires_idx
|
|
495
|
+
ON agent_confirm_token (expires_at)`
|
|
475
496
|
];
|
|
476
497
|
var additiveColumns = [
|
|
477
498
|
{
|
|
@@ -2172,10 +2193,43 @@ var DrizzlePricingStore = class {
|
|
|
2172
2193
|
}
|
|
2173
2194
|
};
|
|
2174
2195
|
|
|
2196
|
+
// src/drizzle-confirm-token-store.ts
|
|
2197
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
2198
|
+
var DrizzleConfirmTokenStore = class {
|
|
2199
|
+
static {
|
|
2200
|
+
__name(this, "DrizzleConfirmTokenStore");
|
|
2201
|
+
}
|
|
2202
|
+
db;
|
|
2203
|
+
constructor(db) {
|
|
2204
|
+
this.db = db;
|
|
2205
|
+
}
|
|
2206
|
+
async claim(input) {
|
|
2207
|
+
const inserted = await this.db.insert(agentConfirmToken).values({
|
|
2208
|
+
hash: input.hash,
|
|
2209
|
+
actorRef: input.actorRef,
|
|
2210
|
+
tool: input.tool,
|
|
2211
|
+
expiresAt: input.expiresAt,
|
|
2212
|
+
createdAt: Date.now()
|
|
2213
|
+
}).onConflictDoNothing().returning({
|
|
2214
|
+
hash: agentConfirmToken.hash
|
|
2215
|
+
});
|
|
2216
|
+
return inserted.length === 1;
|
|
2217
|
+
}
|
|
2218
|
+
async release(hash) {
|
|
2219
|
+
await this.db.delete(agentConfirmToken).where((0, import_drizzle_orm6.eq)(agentConfirmToken.hash, hash));
|
|
2220
|
+
}
|
|
2221
|
+
async purgeExpired(now = Date.now()) {
|
|
2222
|
+
const purged = await this.db.delete(agentConfirmToken).where((0, import_drizzle_orm6.lt)(agentConfirmToken.expiresAt, now)).returning({
|
|
2223
|
+
hash: agentConfirmToken.hash
|
|
2224
|
+
});
|
|
2225
|
+
return purged.length;
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
|
|
2175
2229
|
// src/drizzle-rag-ingestion-log.ts
|
|
2176
2230
|
var import_node_diagnostics_channel = require("diagnostics_channel");
|
|
2177
2231
|
var import_common = require("@nestjs/common");
|
|
2178
|
-
var
|
|
2232
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
2179
2233
|
function _ts_decorate(decorators, target, key, desc4) {
|
|
2180
2234
|
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
2181
2235
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -2223,8 +2277,8 @@ function num(value) {
|
|
|
2223
2277
|
}
|
|
2224
2278
|
__name(num, "num");
|
|
2225
2279
|
var RAG_INGESTION_LOG_PAGE_ORDER = [
|
|
2226
|
-
(0,
|
|
2227
|
-
(0,
|
|
2280
|
+
(0, import_drizzle_orm7.desc)(ragIngestionLog.updatedAt),
|
|
2281
|
+
(0, import_drizzle_orm7.asc)(ragIngestionLog.documentId)
|
|
2228
2282
|
];
|
|
2229
2283
|
var DEFAULT_PAGE_SIZE = 200;
|
|
2230
2284
|
var DEFAULT_BATCH_SIZE = 200;
|
|
@@ -2288,7 +2342,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2288
2342
|
*/
|
|
2289
2343
|
async listPage(query = {}) {
|
|
2290
2344
|
const [totalRow] = await this.db.select({
|
|
2291
|
-
value: (0,
|
|
2345
|
+
value: (0, import_drizzle_orm7.count)()
|
|
2292
2346
|
}).from(ragIngestionLog).where(this.where(query));
|
|
2293
2347
|
return {
|
|
2294
2348
|
rows: await this.list(query),
|
|
@@ -2367,19 +2421,19 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2367
2421
|
}
|
|
2368
2422
|
/** The latest recorded outcome for one document, or null if it was never attempted. */
|
|
2369
2423
|
async get(documentId) {
|
|
2370
|
-
const [row] = await this.db.select().from(ragIngestionLog).where((0,
|
|
2424
|
+
const [row] = await this.db.select().from(ragIngestionLog).where((0, import_drizzle_orm7.eq)(ragIngestionLog.documentId, documentId));
|
|
2371
2425
|
return row ?? null;
|
|
2372
2426
|
}
|
|
2373
2427
|
/** Forget one document's record. Returns whether a row was actually removed. */
|
|
2374
2428
|
async remove(documentId) {
|
|
2375
|
-
const removed = await this.db.delete(ragIngestionLog).where((0,
|
|
2429
|
+
const removed = await this.db.delete(ragIngestionLog).where((0, import_drizzle_orm7.eq)(ragIngestionLog.documentId, documentId)).returning({
|
|
2376
2430
|
documentId: ragIngestionLog.documentId
|
|
2377
2431
|
});
|
|
2378
2432
|
return removed.length > 0;
|
|
2379
2433
|
}
|
|
2380
2434
|
/** Forget every record for a collection — for when the collection itself is deleted. */
|
|
2381
2435
|
async removeByCollection(collection) {
|
|
2382
|
-
const removed = await this.db.delete(ragIngestionLog).where((0,
|
|
2436
|
+
const removed = await this.db.delete(ragIngestionLog).where((0, import_drizzle_orm7.eq)(ragIngestionLog.collection, collection)).returning({
|
|
2383
2437
|
documentId: ragIngestionLog.documentId
|
|
2384
2438
|
});
|
|
2385
2439
|
return removed.length;
|
|
@@ -2411,7 +2465,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2411
2465
|
}
|
|
2412
2466
|
}
|
|
2413
2467
|
where(query) {
|
|
2414
|
-
return (0,
|
|
2468
|
+
return (0, import_drizzle_orm7.and)(query.collection !== void 0 ? (0, import_drizzle_orm7.eq)(ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? (0, import_drizzle_orm7.eq)(ragIngestionLog.status, query.status) : void 0);
|
|
2415
2469
|
}
|
|
2416
2470
|
/**
|
|
2417
2471
|
* The coordinates filter AND'd with "strictly after `cursor` in
|
|
@@ -2426,7 +2480,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2426
2480
|
if (cursor === void 0) {
|
|
2427
2481
|
return base;
|
|
2428
2482
|
}
|
|
2429
|
-
return (0,
|
|
2483
|
+
return (0, import_drizzle_orm7.and)(base, (0, import_drizzle_orm7.or)((0, import_drizzle_orm7.lt)(ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm7.gt)(ragIngestionLog.documentId, cursor.documentId))));
|
|
2430
2484
|
}
|
|
2431
2485
|
/**
|
|
2432
2486
|
* Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
|
|
@@ -2572,6 +2626,15 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
|
|
|
2572
2626
|
{
|
|
2573
2627
|
provide: import_nestjs_agent_core4.AGENT_GOVERNANCE_QUERIES,
|
|
2574
2628
|
useExisting: DrizzleGovernanceQueries
|
|
2629
|
+
},
|
|
2630
|
+
// What makes a `defineConfirmedTool` confirmation single use across replicas.
|
|
2631
|
+
{
|
|
2632
|
+
provide: DrizzleConfirmTokenStore,
|
|
2633
|
+
useFactory: /* @__PURE__ */ __name(() => new DrizzleConfirmTokenStore(options.db), "useFactory")
|
|
2634
|
+
},
|
|
2635
|
+
{
|
|
2636
|
+
provide: import_nestjs_agent_core4.AGENT_CONFIRM_TOKEN_STORE,
|
|
2637
|
+
useExisting: DrizzleConfirmTokenStore
|
|
2575
2638
|
}
|
|
2576
2639
|
],
|
|
2577
2640
|
exports: [
|
|
@@ -2584,7 +2647,9 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
|
|
|
2584
2647
|
DrizzleGovernanceQueries,
|
|
2585
2648
|
import_nestjs_agent_core4.AGENT_GOVERNANCE_QUERIES,
|
|
2586
2649
|
DrizzlePricingStore,
|
|
2587
|
-
import_nestjs_agent_core4.AGENT_PRICING_STORE
|
|
2650
|
+
import_nestjs_agent_core4.AGENT_PRICING_STORE,
|
|
2651
|
+
DrizzleConfirmTokenStore,
|
|
2652
|
+
import_nestjs_agent_core4.AGENT_CONFIRM_TOKEN_STORE
|
|
2588
2653
|
]
|
|
2589
2654
|
};
|
|
2590
2655
|
}
|
|
@@ -2596,11 +2661,13 @@ DrizzleAgentStoreModule = _ts_decorate2([
|
|
|
2596
2661
|
0 && (module.exports = {
|
|
2597
2662
|
DrizzleAgentStore,
|
|
2598
2663
|
DrizzleAgentStoreModule,
|
|
2664
|
+
DrizzleConfirmTokenStore,
|
|
2599
2665
|
DrizzleGovernanceQueries,
|
|
2600
2666
|
DrizzleMemoryProvider,
|
|
2601
2667
|
DrizzlePricingStore,
|
|
2602
2668
|
DrizzleRagIngestionLog,
|
|
2603
2669
|
RAG_INGESTION_LOG_PAGE_ORDER,
|
|
2670
|
+
agentConfirmToken,
|
|
2604
2671
|
agentMemory,
|
|
2605
2672
|
agentMessage,
|
|
2606
2673
|
agentModelPricing,
|