@dudousxd/nestjs-agent-store-drizzle 0.20.2 → 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.js
CHANGED
|
@@ -266,6 +266,15 @@ var ragIngestionLog = sqliteTable("rag_ingestion_log", {
|
|
|
266
266
|
}, (table) => [
|
|
267
267
|
index("rag_ingestion_log_collection_idx").on(table.collection, table.updatedAt)
|
|
268
268
|
]);
|
|
269
|
+
var agentConfirmToken = sqliteTable("agent_confirm_token", {
|
|
270
|
+
hash: text("hash").primaryKey(),
|
|
271
|
+
actorRef: text("actor_ref").notNull(),
|
|
272
|
+
tool: text("tool").notNull(),
|
|
273
|
+
expiresAt: integer("expires_at").notNull(),
|
|
274
|
+
createdAt: integer("created_at").notNull()
|
|
275
|
+
}, (table) => [
|
|
276
|
+
index("agent_confirm_token_expires_idx").on(table.expiresAt)
|
|
277
|
+
]);
|
|
269
278
|
var agentSchema = {
|
|
270
279
|
agentThread,
|
|
271
280
|
agentMessage,
|
|
@@ -275,7 +284,8 @@ var agentSchema = {
|
|
|
275
284
|
agentModelPricing,
|
|
276
285
|
agentRun,
|
|
277
286
|
agentMemory,
|
|
278
|
-
ragIngestionLog
|
|
287
|
+
ragIngestionLog,
|
|
288
|
+
agentConfirmToken
|
|
279
289
|
};
|
|
280
290
|
|
|
281
291
|
// src/ensure-schema.ts
|
|
@@ -430,7 +440,16 @@ var statements = [
|
|
|
430
440
|
updated_at INTEGER NOT NULL
|
|
431
441
|
)`,
|
|
432
442
|
`CREATE INDEX IF NOT EXISTS rag_ingestion_log_collection_idx
|
|
433
|
-
ON rag_ingestion_log (collection, updated_at)
|
|
443
|
+
ON rag_ingestion_log (collection, updated_at)`,
|
|
444
|
+
`CREATE TABLE IF NOT EXISTS agent_confirm_token (
|
|
445
|
+
hash TEXT PRIMARY KEY NOT NULL,
|
|
446
|
+
actor_ref TEXT NOT NULL,
|
|
447
|
+
tool TEXT NOT NULL,
|
|
448
|
+
expires_at INTEGER NOT NULL,
|
|
449
|
+
created_at INTEGER NOT NULL
|
|
450
|
+
)`,
|
|
451
|
+
`CREATE INDEX IF NOT EXISTS agent_confirm_token_expires_idx
|
|
452
|
+
ON agent_confirm_token (expires_at)`
|
|
434
453
|
];
|
|
435
454
|
var additiveColumns = [
|
|
436
455
|
{
|
|
@@ -2131,10 +2150,43 @@ var DrizzlePricingStore = class {
|
|
|
2131
2150
|
}
|
|
2132
2151
|
};
|
|
2133
2152
|
|
|
2153
|
+
// src/drizzle-confirm-token-store.ts
|
|
2154
|
+
import { eq as eq5, lt } from "drizzle-orm";
|
|
2155
|
+
var DrizzleConfirmTokenStore = class {
|
|
2156
|
+
static {
|
|
2157
|
+
__name(this, "DrizzleConfirmTokenStore");
|
|
2158
|
+
}
|
|
2159
|
+
db;
|
|
2160
|
+
constructor(db) {
|
|
2161
|
+
this.db = db;
|
|
2162
|
+
}
|
|
2163
|
+
async claim(input) {
|
|
2164
|
+
const inserted = await this.db.insert(agentConfirmToken).values({
|
|
2165
|
+
hash: input.hash,
|
|
2166
|
+
actorRef: input.actorRef,
|
|
2167
|
+
tool: input.tool,
|
|
2168
|
+
expiresAt: input.expiresAt,
|
|
2169
|
+
createdAt: Date.now()
|
|
2170
|
+
}).onConflictDoNothing().returning({
|
|
2171
|
+
hash: agentConfirmToken.hash
|
|
2172
|
+
});
|
|
2173
|
+
return inserted.length === 1;
|
|
2174
|
+
}
|
|
2175
|
+
async release(hash) {
|
|
2176
|
+
await this.db.delete(agentConfirmToken).where(eq5(agentConfirmToken.hash, hash));
|
|
2177
|
+
}
|
|
2178
|
+
async purgeExpired(now = Date.now()) {
|
|
2179
|
+
const purged = await this.db.delete(agentConfirmToken).where(lt(agentConfirmToken.expiresAt, now)).returning({
|
|
2180
|
+
hash: agentConfirmToken.hash
|
|
2181
|
+
});
|
|
2182
|
+
return purged.length;
|
|
2183
|
+
}
|
|
2184
|
+
};
|
|
2185
|
+
|
|
2134
2186
|
// src/drizzle-rag-ingestion-log.ts
|
|
2135
2187
|
import { subscribe, unsubscribe } from "diagnostics_channel";
|
|
2136
2188
|
import { Injectable, Logger } from "@nestjs/common";
|
|
2137
|
-
import { and as and5, asc as asc3, count as count2, desc as desc3, eq as
|
|
2189
|
+
import { and as and5, asc as asc3, count as count2, desc as desc3, eq as eq6, gt, lt as lt2, or as or2 } from "drizzle-orm";
|
|
2138
2190
|
function _ts_decorate(decorators, target, key, desc4) {
|
|
2139
2191
|
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
2140
2192
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -2326,19 +2378,19 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2326
2378
|
}
|
|
2327
2379
|
/** The latest recorded outcome for one document, or null if it was never attempted. */
|
|
2328
2380
|
async get(documentId) {
|
|
2329
|
-
const [row] = await this.db.select().from(ragIngestionLog).where(
|
|
2381
|
+
const [row] = await this.db.select().from(ragIngestionLog).where(eq6(ragIngestionLog.documentId, documentId));
|
|
2330
2382
|
return row ?? null;
|
|
2331
2383
|
}
|
|
2332
2384
|
/** Forget one document's record. Returns whether a row was actually removed. */
|
|
2333
2385
|
async remove(documentId) {
|
|
2334
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2386
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq6(ragIngestionLog.documentId, documentId)).returning({
|
|
2335
2387
|
documentId: ragIngestionLog.documentId
|
|
2336
2388
|
});
|
|
2337
2389
|
return removed.length > 0;
|
|
2338
2390
|
}
|
|
2339
2391
|
/** Forget every record for a collection — for when the collection itself is deleted. */
|
|
2340
2392
|
async removeByCollection(collection) {
|
|
2341
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2393
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq6(ragIngestionLog.collection, collection)).returning({
|
|
2342
2394
|
documentId: ragIngestionLog.documentId
|
|
2343
2395
|
});
|
|
2344
2396
|
return removed.length;
|
|
@@ -2370,7 +2422,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2370
2422
|
}
|
|
2371
2423
|
}
|
|
2372
2424
|
where(query) {
|
|
2373
|
-
return and5(query.collection !== void 0 ?
|
|
2425
|
+
return and5(query.collection !== void 0 ? eq6(ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? eq6(ragIngestionLog.status, query.status) : void 0);
|
|
2374
2426
|
}
|
|
2375
2427
|
/**
|
|
2376
2428
|
* The coordinates filter AND'd with "strictly after `cursor` in
|
|
@@ -2385,7 +2437,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2385
2437
|
if (cursor === void 0) {
|
|
2386
2438
|
return base;
|
|
2387
2439
|
}
|
|
2388
|
-
return and5(base, or2(
|
|
2440
|
+
return and5(base, or2(lt2(ragIngestionLog.updatedAt, cursor.updatedAt), and5(eq6(ragIngestionLog.updatedAt, cursor.updatedAt), gt(ragIngestionLog.documentId, cursor.documentId))));
|
|
2389
2441
|
}
|
|
2390
2442
|
/**
|
|
2391
2443
|
* Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
|
|
@@ -2461,7 +2513,7 @@ DrizzleRagIngestionLog = _ts_decorate([
|
|
|
2461
2513
|
], DrizzleRagIngestionLog);
|
|
2462
2514
|
|
|
2463
2515
|
// src/drizzle-agent-store.module.ts
|
|
2464
|
-
import { AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, AGENT_STORE } from "@dudousxd/nestjs-agent-core";
|
|
2516
|
+
import { AGENT_CONFIRM_TOKEN_STORE, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, AGENT_STORE } from "@dudousxd/nestjs-agent-core";
|
|
2465
2517
|
import { Module } from "@nestjs/common";
|
|
2466
2518
|
function _ts_decorate2(decorators, target, key, desc4) {
|
|
2467
2519
|
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
@@ -2531,6 +2583,15 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
|
|
|
2531
2583
|
{
|
|
2532
2584
|
provide: AGENT_GOVERNANCE_QUERIES,
|
|
2533
2585
|
useExisting: DrizzleGovernanceQueries
|
|
2586
|
+
},
|
|
2587
|
+
// What makes a `defineConfirmedTool` confirmation single use across replicas.
|
|
2588
|
+
{
|
|
2589
|
+
provide: DrizzleConfirmTokenStore,
|
|
2590
|
+
useFactory: /* @__PURE__ */ __name(() => new DrizzleConfirmTokenStore(options.db), "useFactory")
|
|
2591
|
+
},
|
|
2592
|
+
{
|
|
2593
|
+
provide: AGENT_CONFIRM_TOKEN_STORE,
|
|
2594
|
+
useExisting: DrizzleConfirmTokenStore
|
|
2534
2595
|
}
|
|
2535
2596
|
],
|
|
2536
2597
|
exports: [
|
|
@@ -2543,7 +2604,9 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
|
|
|
2543
2604
|
DrizzleGovernanceQueries,
|
|
2544
2605
|
AGENT_GOVERNANCE_QUERIES,
|
|
2545
2606
|
DrizzlePricingStore,
|
|
2546
|
-
AGENT_PRICING_STORE
|
|
2607
|
+
AGENT_PRICING_STORE,
|
|
2608
|
+
DrizzleConfirmTokenStore,
|
|
2609
|
+
AGENT_CONFIRM_TOKEN_STORE
|
|
2547
2610
|
]
|
|
2548
2611
|
};
|
|
2549
2612
|
}
|
|
@@ -2554,11 +2617,13 @@ DrizzleAgentStoreModule = _ts_decorate2([
|
|
|
2554
2617
|
export {
|
|
2555
2618
|
DrizzleAgentStore,
|
|
2556
2619
|
DrizzleAgentStoreModule,
|
|
2620
|
+
DrizzleConfirmTokenStore,
|
|
2557
2621
|
DrizzleGovernanceQueries,
|
|
2558
2622
|
DrizzleMemoryProvider,
|
|
2559
2623
|
DrizzlePricingStore,
|
|
2560
2624
|
DrizzleRagIngestionLog,
|
|
2561
2625
|
RAG_INGESTION_LOG_PAGE_ORDER,
|
|
2626
|
+
agentConfirmToken,
|
|
2562
2627
|
agentMemory,
|
|
2563
2628
|
agentMessage,
|
|
2564
2629
|
agentModelPricing,
|