@dudousxd/nestjs-agent-store-drizzle 0.21.0 → 0.22.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 +114 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -2
- package/dist/index.d.ts +133 -2
- package/dist/index.js +99 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
2
2
|
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
3
|
-
import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, Actor, PageContext, QueuePause, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, ConfirmTokenStore, ConfirmTokenClaim } from '@dudousxd/nestjs-agent-core';
|
|
3
|
+
import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, Actor, PageContext, QueuePause, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, StreamFrameTable, StreamFrameRow, SqlTokenStreamSink, SqlTokenStreamSinkOptions, ConfirmTokenStore, ConfirmTokenClaim } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
export { ThreadTurnPage, ThreadTurnQuery } from '@dudousxd/nestjs-agent-core';
|
|
5
5
|
import { TablesRelationalConfig, SQL } from 'drizzle-orm';
|
|
6
6
|
import { OnModuleInit, OnModuleDestroy, Type, DynamicModule } from '@nestjs/common';
|
|
@@ -2347,6 +2347,109 @@ declare const agentConfirmToken: drizzle_orm_sqlite_core.SQLiteTableWithColumns<
|
|
|
2347
2347
|
};
|
|
2348
2348
|
dialect: "sqlite";
|
|
2349
2349
|
}>;
|
|
2350
|
+
/**
|
|
2351
|
+
* One row per frame of a run's live stream (`DrizzleTokenStreamSink`), numbered per run from 1 with
|
|
2352
|
+
* no gaps. `frame` is one NDJSON line; `null` marks the end, with `error` set when the run failed.
|
|
2353
|
+
* `created_at` (epoch-ms) is what the TTL counts from — a run's LAST row.
|
|
2354
|
+
*/
|
|
2355
|
+
declare const agentStreamFrame: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2356
|
+
name: "agent_stream_frame";
|
|
2357
|
+
schema: undefined;
|
|
2358
|
+
columns: {
|
|
2359
|
+
runId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2360
|
+
name: "run_id";
|
|
2361
|
+
tableName: "agent_stream_frame";
|
|
2362
|
+
dataType: "string";
|
|
2363
|
+
columnType: "SQLiteText";
|
|
2364
|
+
data: string;
|
|
2365
|
+
driverParam: string;
|
|
2366
|
+
notNull: true;
|
|
2367
|
+
hasDefault: false;
|
|
2368
|
+
isPrimaryKey: false;
|
|
2369
|
+
isAutoincrement: false;
|
|
2370
|
+
hasRuntimeDefault: false;
|
|
2371
|
+
enumValues: [string, ...string[]];
|
|
2372
|
+
baseColumn: never;
|
|
2373
|
+
identity: undefined;
|
|
2374
|
+
generated: undefined;
|
|
2375
|
+
}, {}, {
|
|
2376
|
+
length: number | undefined;
|
|
2377
|
+
}>;
|
|
2378
|
+
seq: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2379
|
+
name: "seq";
|
|
2380
|
+
tableName: "agent_stream_frame";
|
|
2381
|
+
dataType: "number";
|
|
2382
|
+
columnType: "SQLiteInteger";
|
|
2383
|
+
data: number;
|
|
2384
|
+
driverParam: number;
|
|
2385
|
+
notNull: true;
|
|
2386
|
+
hasDefault: false;
|
|
2387
|
+
isPrimaryKey: false;
|
|
2388
|
+
isAutoincrement: false;
|
|
2389
|
+
hasRuntimeDefault: false;
|
|
2390
|
+
enumValues: undefined;
|
|
2391
|
+
baseColumn: never;
|
|
2392
|
+
identity: undefined;
|
|
2393
|
+
generated: undefined;
|
|
2394
|
+
}, {}, {}>;
|
|
2395
|
+
frame: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2396
|
+
name: "frame";
|
|
2397
|
+
tableName: "agent_stream_frame";
|
|
2398
|
+
dataType: "string";
|
|
2399
|
+
columnType: "SQLiteText";
|
|
2400
|
+
data: string;
|
|
2401
|
+
driverParam: string;
|
|
2402
|
+
notNull: false;
|
|
2403
|
+
hasDefault: false;
|
|
2404
|
+
isPrimaryKey: false;
|
|
2405
|
+
isAutoincrement: false;
|
|
2406
|
+
hasRuntimeDefault: false;
|
|
2407
|
+
enumValues: [string, ...string[]];
|
|
2408
|
+
baseColumn: never;
|
|
2409
|
+
identity: undefined;
|
|
2410
|
+
generated: undefined;
|
|
2411
|
+
}, {}, {
|
|
2412
|
+
length: number | undefined;
|
|
2413
|
+
}>;
|
|
2414
|
+
error: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2415
|
+
name: "error";
|
|
2416
|
+
tableName: "agent_stream_frame";
|
|
2417
|
+
dataType: "string";
|
|
2418
|
+
columnType: "SQLiteText";
|
|
2419
|
+
data: string;
|
|
2420
|
+
driverParam: string;
|
|
2421
|
+
notNull: false;
|
|
2422
|
+
hasDefault: false;
|
|
2423
|
+
isPrimaryKey: false;
|
|
2424
|
+
isAutoincrement: false;
|
|
2425
|
+
hasRuntimeDefault: false;
|
|
2426
|
+
enumValues: [string, ...string[]];
|
|
2427
|
+
baseColumn: never;
|
|
2428
|
+
identity: undefined;
|
|
2429
|
+
generated: undefined;
|
|
2430
|
+
}, {}, {
|
|
2431
|
+
length: number | undefined;
|
|
2432
|
+
}>;
|
|
2433
|
+
createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2434
|
+
name: "created_at";
|
|
2435
|
+
tableName: "agent_stream_frame";
|
|
2436
|
+
dataType: "number";
|
|
2437
|
+
columnType: "SQLiteInteger";
|
|
2438
|
+
data: number;
|
|
2439
|
+
driverParam: number;
|
|
2440
|
+
notNull: true;
|
|
2441
|
+
hasDefault: false;
|
|
2442
|
+
isPrimaryKey: false;
|
|
2443
|
+
isAutoincrement: false;
|
|
2444
|
+
hasRuntimeDefault: false;
|
|
2445
|
+
enumValues: undefined;
|
|
2446
|
+
baseColumn: never;
|
|
2447
|
+
identity: undefined;
|
|
2448
|
+
generated: undefined;
|
|
2449
|
+
}, {}, {}>;
|
|
2450
|
+
};
|
|
2451
|
+
dialect: "sqlite";
|
|
2452
|
+
}>;
|
|
2350
2453
|
/** The tables this store owns, as one schema object, ready for `drizzle(client, { schema })`. */
|
|
2351
2454
|
declare const agentSchema: {
|
|
2352
2455
|
agentThread: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
@@ -4947,6 +5050,34 @@ declare class DrizzlePricingStore implements AgentPricingStore {
|
|
|
4947
5050
|
listCurrentPrices(): Promise<CurrentModelPrice[]>;
|
|
4948
5051
|
}
|
|
4949
5052
|
|
|
5053
|
+
/** {@link StreamFrameTable} over `agent_stream_frame`, through a Drizzle SQLite handle. */
|
|
5054
|
+
declare class DrizzleStreamFrameTable implements StreamFrameTable {
|
|
5055
|
+
private readonly db;
|
|
5056
|
+
constructor(db: AgentDrizzleDb);
|
|
5057
|
+
append(runId: string, row: {
|
|
5058
|
+
frame: string | null;
|
|
5059
|
+
error: string | null;
|
|
5060
|
+
createdAt: number;
|
|
5061
|
+
}): Promise<void>;
|
|
5062
|
+
read(runId: string, after: number, limit: number): Promise<StreamFrameRow[]>;
|
|
5063
|
+
has(runId: string): Promise<boolean>;
|
|
5064
|
+
remove(runIds: readonly string[]): Promise<void>;
|
|
5065
|
+
lapsedRuns(cutoff: number): Promise<string[]>;
|
|
5066
|
+
isUniqueViolation(error: unknown): boolean;
|
|
5067
|
+
}
|
|
5068
|
+
/**
|
|
5069
|
+
* A multi-replica `TokenStreamSink` over the app's Drizzle database — several replicas, no Redis.
|
|
5070
|
+
* Polled, with streamed text coalesced into one row per `flushMs`; see `SqlTokenStreamSink` for the
|
|
5071
|
+
* trade-offs. The `agent_stream_frame` table comes from `ensureAgentSchema` (or your migration).
|
|
5072
|
+
*
|
|
5073
|
+
* ```ts
|
|
5074
|
+
* AgentModule.forRoot({ model, sink: new DrizzleTokenStreamSink(db) });
|
|
5075
|
+
* ```
|
|
5076
|
+
*/
|
|
5077
|
+
declare class DrizzleTokenStreamSink extends SqlTokenStreamSink {
|
|
5078
|
+
constructor(db: AgentDrizzleDb, options?: SqlTokenStreamSinkOptions);
|
|
5079
|
+
}
|
|
5080
|
+
|
|
4950
5081
|
/**
|
|
4951
5082
|
* A production `ConfirmTokenStore` (`defineConfirmedTool`) over the `agent_confirm_token` table —
|
|
4952
5083
|
* what makes a confirmed write single use across replicas.
|
|
@@ -5195,4 +5326,4 @@ declare class DrizzleAgentStoreModule {
|
|
|
5195
5326
|
static forRoot(options: DrizzleAgentStoreModuleOptions): DynamicModule;
|
|
5196
5327
|
}
|
|
5197
5328
|
|
|
5198
|
-
export { type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentThreadRow, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentConfirmToken, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, ragIngestionLog };
|
|
5329
|
+
export { type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentThreadRow, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, DrizzleStreamFrameTable, DrizzleTokenStreamSink, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentConfirmToken, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentStreamFrame, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, ragIngestionLog };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
2
2
|
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
3
|
-
import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, Actor, PageContext, QueuePause, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, ConfirmTokenStore, ConfirmTokenClaim } from '@dudousxd/nestjs-agent-core';
|
|
3
|
+
import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, Actor, PageContext, QueuePause, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, StreamFrameTable, StreamFrameRow, SqlTokenStreamSink, SqlTokenStreamSinkOptions, ConfirmTokenStore, ConfirmTokenClaim } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
export { ThreadTurnPage, ThreadTurnQuery } from '@dudousxd/nestjs-agent-core';
|
|
5
5
|
import { TablesRelationalConfig, SQL } from 'drizzle-orm';
|
|
6
6
|
import { OnModuleInit, OnModuleDestroy, Type, DynamicModule } from '@nestjs/common';
|
|
@@ -2347,6 +2347,109 @@ declare const agentConfirmToken: drizzle_orm_sqlite_core.SQLiteTableWithColumns<
|
|
|
2347
2347
|
};
|
|
2348
2348
|
dialect: "sqlite";
|
|
2349
2349
|
}>;
|
|
2350
|
+
/**
|
|
2351
|
+
* One row per frame of a run's live stream (`DrizzleTokenStreamSink`), numbered per run from 1 with
|
|
2352
|
+
* no gaps. `frame` is one NDJSON line; `null` marks the end, with `error` set when the run failed.
|
|
2353
|
+
* `created_at` (epoch-ms) is what the TTL counts from — a run's LAST row.
|
|
2354
|
+
*/
|
|
2355
|
+
declare const agentStreamFrame: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
2356
|
+
name: "agent_stream_frame";
|
|
2357
|
+
schema: undefined;
|
|
2358
|
+
columns: {
|
|
2359
|
+
runId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2360
|
+
name: "run_id";
|
|
2361
|
+
tableName: "agent_stream_frame";
|
|
2362
|
+
dataType: "string";
|
|
2363
|
+
columnType: "SQLiteText";
|
|
2364
|
+
data: string;
|
|
2365
|
+
driverParam: string;
|
|
2366
|
+
notNull: true;
|
|
2367
|
+
hasDefault: false;
|
|
2368
|
+
isPrimaryKey: false;
|
|
2369
|
+
isAutoincrement: false;
|
|
2370
|
+
hasRuntimeDefault: false;
|
|
2371
|
+
enumValues: [string, ...string[]];
|
|
2372
|
+
baseColumn: never;
|
|
2373
|
+
identity: undefined;
|
|
2374
|
+
generated: undefined;
|
|
2375
|
+
}, {}, {
|
|
2376
|
+
length: number | undefined;
|
|
2377
|
+
}>;
|
|
2378
|
+
seq: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2379
|
+
name: "seq";
|
|
2380
|
+
tableName: "agent_stream_frame";
|
|
2381
|
+
dataType: "number";
|
|
2382
|
+
columnType: "SQLiteInteger";
|
|
2383
|
+
data: number;
|
|
2384
|
+
driverParam: number;
|
|
2385
|
+
notNull: true;
|
|
2386
|
+
hasDefault: false;
|
|
2387
|
+
isPrimaryKey: false;
|
|
2388
|
+
isAutoincrement: false;
|
|
2389
|
+
hasRuntimeDefault: false;
|
|
2390
|
+
enumValues: undefined;
|
|
2391
|
+
baseColumn: never;
|
|
2392
|
+
identity: undefined;
|
|
2393
|
+
generated: undefined;
|
|
2394
|
+
}, {}, {}>;
|
|
2395
|
+
frame: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2396
|
+
name: "frame";
|
|
2397
|
+
tableName: "agent_stream_frame";
|
|
2398
|
+
dataType: "string";
|
|
2399
|
+
columnType: "SQLiteText";
|
|
2400
|
+
data: string;
|
|
2401
|
+
driverParam: string;
|
|
2402
|
+
notNull: false;
|
|
2403
|
+
hasDefault: false;
|
|
2404
|
+
isPrimaryKey: false;
|
|
2405
|
+
isAutoincrement: false;
|
|
2406
|
+
hasRuntimeDefault: false;
|
|
2407
|
+
enumValues: [string, ...string[]];
|
|
2408
|
+
baseColumn: never;
|
|
2409
|
+
identity: undefined;
|
|
2410
|
+
generated: undefined;
|
|
2411
|
+
}, {}, {
|
|
2412
|
+
length: number | undefined;
|
|
2413
|
+
}>;
|
|
2414
|
+
error: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2415
|
+
name: "error";
|
|
2416
|
+
tableName: "agent_stream_frame";
|
|
2417
|
+
dataType: "string";
|
|
2418
|
+
columnType: "SQLiteText";
|
|
2419
|
+
data: string;
|
|
2420
|
+
driverParam: string;
|
|
2421
|
+
notNull: false;
|
|
2422
|
+
hasDefault: false;
|
|
2423
|
+
isPrimaryKey: false;
|
|
2424
|
+
isAutoincrement: false;
|
|
2425
|
+
hasRuntimeDefault: false;
|
|
2426
|
+
enumValues: [string, ...string[]];
|
|
2427
|
+
baseColumn: never;
|
|
2428
|
+
identity: undefined;
|
|
2429
|
+
generated: undefined;
|
|
2430
|
+
}, {}, {
|
|
2431
|
+
length: number | undefined;
|
|
2432
|
+
}>;
|
|
2433
|
+
createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
2434
|
+
name: "created_at";
|
|
2435
|
+
tableName: "agent_stream_frame";
|
|
2436
|
+
dataType: "number";
|
|
2437
|
+
columnType: "SQLiteInteger";
|
|
2438
|
+
data: number;
|
|
2439
|
+
driverParam: number;
|
|
2440
|
+
notNull: true;
|
|
2441
|
+
hasDefault: false;
|
|
2442
|
+
isPrimaryKey: false;
|
|
2443
|
+
isAutoincrement: false;
|
|
2444
|
+
hasRuntimeDefault: false;
|
|
2445
|
+
enumValues: undefined;
|
|
2446
|
+
baseColumn: never;
|
|
2447
|
+
identity: undefined;
|
|
2448
|
+
generated: undefined;
|
|
2449
|
+
}, {}, {}>;
|
|
2450
|
+
};
|
|
2451
|
+
dialect: "sqlite";
|
|
2452
|
+
}>;
|
|
2350
2453
|
/** The tables this store owns, as one schema object, ready for `drizzle(client, { schema })`. */
|
|
2351
2454
|
declare const agentSchema: {
|
|
2352
2455
|
agentThread: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
@@ -4947,6 +5050,34 @@ declare class DrizzlePricingStore implements AgentPricingStore {
|
|
|
4947
5050
|
listCurrentPrices(): Promise<CurrentModelPrice[]>;
|
|
4948
5051
|
}
|
|
4949
5052
|
|
|
5053
|
+
/** {@link StreamFrameTable} over `agent_stream_frame`, through a Drizzle SQLite handle. */
|
|
5054
|
+
declare class DrizzleStreamFrameTable implements StreamFrameTable {
|
|
5055
|
+
private readonly db;
|
|
5056
|
+
constructor(db: AgentDrizzleDb);
|
|
5057
|
+
append(runId: string, row: {
|
|
5058
|
+
frame: string | null;
|
|
5059
|
+
error: string | null;
|
|
5060
|
+
createdAt: number;
|
|
5061
|
+
}): Promise<void>;
|
|
5062
|
+
read(runId: string, after: number, limit: number): Promise<StreamFrameRow[]>;
|
|
5063
|
+
has(runId: string): Promise<boolean>;
|
|
5064
|
+
remove(runIds: readonly string[]): Promise<void>;
|
|
5065
|
+
lapsedRuns(cutoff: number): Promise<string[]>;
|
|
5066
|
+
isUniqueViolation(error: unknown): boolean;
|
|
5067
|
+
}
|
|
5068
|
+
/**
|
|
5069
|
+
* A multi-replica `TokenStreamSink` over the app's Drizzle database — several replicas, no Redis.
|
|
5070
|
+
* Polled, with streamed text coalesced into one row per `flushMs`; see `SqlTokenStreamSink` for the
|
|
5071
|
+
* trade-offs. The `agent_stream_frame` table comes from `ensureAgentSchema` (or your migration).
|
|
5072
|
+
*
|
|
5073
|
+
* ```ts
|
|
5074
|
+
* AgentModule.forRoot({ model, sink: new DrizzleTokenStreamSink(db) });
|
|
5075
|
+
* ```
|
|
5076
|
+
*/
|
|
5077
|
+
declare class DrizzleTokenStreamSink extends SqlTokenStreamSink {
|
|
5078
|
+
constructor(db: AgentDrizzleDb, options?: SqlTokenStreamSinkOptions);
|
|
5079
|
+
}
|
|
5080
|
+
|
|
4950
5081
|
/**
|
|
4951
5082
|
* A production `ConfirmTokenStore` (`defineConfirmedTool`) over the `agent_confirm_token` table —
|
|
4952
5083
|
* what makes a confirmed write single use across replicas.
|
|
@@ -5195,4 +5326,4 @@ declare class DrizzleAgentStoreModule {
|
|
|
5195
5326
|
static forRoot(options: DrizzleAgentStoreModuleOptions): DynamicModule;
|
|
5196
5327
|
}
|
|
5197
5328
|
|
|
5198
|
-
export { type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentThreadRow, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentConfirmToken, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, ragIngestionLog };
|
|
5329
|
+
export { type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentThreadRow, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, DrizzleStreamFrameTable, DrizzleTokenStreamSink, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentConfirmToken, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentStreamFrame, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, ragIngestionLog };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/schema.ts
|
|
5
|
-
import { index, integer, real, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
5
|
+
import { index, integer, primaryKey, real, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
6
6
|
var agentThread = sqliteTable("agent_thread", {
|
|
7
7
|
id: text("id").primaryKey(),
|
|
8
8
|
actorRef: text("actor_ref").notNull(),
|
|
@@ -275,6 +275,20 @@ var agentConfirmToken = sqliteTable("agent_confirm_token", {
|
|
|
275
275
|
}, (table) => [
|
|
276
276
|
index("agent_confirm_token_expires_idx").on(table.expiresAt)
|
|
277
277
|
]);
|
|
278
|
+
var agentStreamFrame = sqliteTable("agent_stream_frame", {
|
|
279
|
+
runId: text("run_id").notNull(),
|
|
280
|
+
seq: integer("seq").notNull(),
|
|
281
|
+
frame: text("frame"),
|
|
282
|
+
error: text("error"),
|
|
283
|
+
createdAt: integer("created_at").notNull()
|
|
284
|
+
}, (table) => [
|
|
285
|
+
primaryKey({
|
|
286
|
+
columns: [
|
|
287
|
+
table.runId,
|
|
288
|
+
table.seq
|
|
289
|
+
]
|
|
290
|
+
})
|
|
291
|
+
]);
|
|
278
292
|
var agentSchema = {
|
|
279
293
|
agentThread,
|
|
280
294
|
agentMessage,
|
|
@@ -441,6 +455,14 @@ var statements = [
|
|
|
441
455
|
)`,
|
|
442
456
|
`CREATE INDEX IF NOT EXISTS rag_ingestion_log_collection_idx
|
|
443
457
|
ON rag_ingestion_log (collection, updated_at)`,
|
|
458
|
+
`CREATE TABLE IF NOT EXISTS agent_stream_frame (
|
|
459
|
+
run_id TEXT NOT NULL,
|
|
460
|
+
seq INTEGER NOT NULL,
|
|
461
|
+
frame TEXT,
|
|
462
|
+
error TEXT,
|
|
463
|
+
created_at INTEGER NOT NULL,
|
|
464
|
+
PRIMARY KEY (run_id, seq)
|
|
465
|
+
)`,
|
|
444
466
|
`CREATE TABLE IF NOT EXISTS agent_confirm_token (
|
|
445
467
|
hash TEXT PRIMARY KEY NOT NULL,
|
|
446
468
|
actor_ref TEXT NOT NULL,
|
|
@@ -2150,8 +2172,71 @@ var DrizzlePricingStore = class {
|
|
|
2150
2172
|
}
|
|
2151
2173
|
};
|
|
2152
2174
|
|
|
2175
|
+
// src/drizzle-token-stream-sink.ts
|
|
2176
|
+
import { SqlTokenStreamSink } from "@dudousxd/nestjs-agent-core";
|
|
2177
|
+
import { and as and5, asc as asc3, eq as eq5, gt, inArray as inArray4, lt, max as max2, sql as sql4 } from "drizzle-orm";
|
|
2178
|
+
function isUniqueViolation(error) {
|
|
2179
|
+
for (let current = error; current !== null && typeof current === "object"; ) {
|
|
2180
|
+
const code = current.code;
|
|
2181
|
+
if (typeof code === "string" && code.startsWith("SQLITE_CONSTRAINT")) return true;
|
|
2182
|
+
current = current.cause;
|
|
2183
|
+
}
|
|
2184
|
+
return false;
|
|
2185
|
+
}
|
|
2186
|
+
__name(isUniqueViolation, "isUniqueViolation");
|
|
2187
|
+
var DrizzleStreamFrameTable = class {
|
|
2188
|
+
static {
|
|
2189
|
+
__name(this, "DrizzleStreamFrameTable");
|
|
2190
|
+
}
|
|
2191
|
+
db;
|
|
2192
|
+
constructor(db) {
|
|
2193
|
+
this.db = db;
|
|
2194
|
+
}
|
|
2195
|
+
async append(runId, row) {
|
|
2196
|
+
await this.db.run(sql4`INSERT INTO agent_stream_frame (run_id, seq, frame, error, created_at)
|
|
2197
|
+
SELECT ${runId}, COALESCE(MAX(seq), 0) + 1, ${row.frame}, ${row.error}, ${row.createdAt}
|
|
2198
|
+
FROM agent_stream_frame WHERE run_id = ${runId}`);
|
|
2199
|
+
}
|
|
2200
|
+
async read(runId, after, limit) {
|
|
2201
|
+
return this.db.select({
|
|
2202
|
+
seq: agentStreamFrame.seq,
|
|
2203
|
+
frame: agentStreamFrame.frame,
|
|
2204
|
+
error: agentStreamFrame.error
|
|
2205
|
+
}).from(agentStreamFrame).where(and5(eq5(agentStreamFrame.runId, runId), gt(agentStreamFrame.seq, after))).orderBy(asc3(agentStreamFrame.seq)).limit(limit);
|
|
2206
|
+
}
|
|
2207
|
+
async has(runId) {
|
|
2208
|
+
const rows = await this.db.select({
|
|
2209
|
+
seq: agentStreamFrame.seq
|
|
2210
|
+
}).from(agentStreamFrame).where(eq5(agentStreamFrame.runId, runId)).limit(1);
|
|
2211
|
+
return rows.length > 0;
|
|
2212
|
+
}
|
|
2213
|
+
async remove(runIds) {
|
|
2214
|
+
if (runIds.length === 0) return;
|
|
2215
|
+
await this.db.delete(agentStreamFrame).where(inArray4(agentStreamFrame.runId, [
|
|
2216
|
+
...runIds
|
|
2217
|
+
]));
|
|
2218
|
+
}
|
|
2219
|
+
async lapsedRuns(cutoff) {
|
|
2220
|
+
const rows = await this.db.select({
|
|
2221
|
+
runId: agentStreamFrame.runId
|
|
2222
|
+
}).from(agentStreamFrame).groupBy(agentStreamFrame.runId).having(lt(max2(agentStreamFrame.createdAt), cutoff));
|
|
2223
|
+
return rows.map((row) => row.runId);
|
|
2224
|
+
}
|
|
2225
|
+
isUniqueViolation(error) {
|
|
2226
|
+
return isUniqueViolation(error);
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2229
|
+
var DrizzleTokenStreamSink = class extends SqlTokenStreamSink {
|
|
2230
|
+
static {
|
|
2231
|
+
__name(this, "DrizzleTokenStreamSink");
|
|
2232
|
+
}
|
|
2233
|
+
constructor(db, options = {}) {
|
|
2234
|
+
super(new DrizzleStreamFrameTable(db), options);
|
|
2235
|
+
}
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2153
2238
|
// src/drizzle-confirm-token-store.ts
|
|
2154
|
-
import { eq as
|
|
2239
|
+
import { eq as eq6, lt as lt2 } from "drizzle-orm";
|
|
2155
2240
|
var DrizzleConfirmTokenStore = class {
|
|
2156
2241
|
static {
|
|
2157
2242
|
__name(this, "DrizzleConfirmTokenStore");
|
|
@@ -2173,10 +2258,10 @@ var DrizzleConfirmTokenStore = class {
|
|
|
2173
2258
|
return inserted.length === 1;
|
|
2174
2259
|
}
|
|
2175
2260
|
async release(hash) {
|
|
2176
|
-
await this.db.delete(agentConfirmToken).where(
|
|
2261
|
+
await this.db.delete(agentConfirmToken).where(eq6(agentConfirmToken.hash, hash));
|
|
2177
2262
|
}
|
|
2178
2263
|
async purgeExpired(now = Date.now()) {
|
|
2179
|
-
const purged = await this.db.delete(agentConfirmToken).where(
|
|
2264
|
+
const purged = await this.db.delete(agentConfirmToken).where(lt2(agentConfirmToken.expiresAt, now)).returning({
|
|
2180
2265
|
hash: agentConfirmToken.hash
|
|
2181
2266
|
});
|
|
2182
2267
|
return purged.length;
|
|
@@ -2186,7 +2271,7 @@ var DrizzleConfirmTokenStore = class {
|
|
|
2186
2271
|
// src/drizzle-rag-ingestion-log.ts
|
|
2187
2272
|
import { subscribe, unsubscribe } from "diagnostics_channel";
|
|
2188
2273
|
import { Injectable, Logger } from "@nestjs/common";
|
|
2189
|
-
import { and as
|
|
2274
|
+
import { and as and6, asc as asc4, count as count2, desc as desc3, eq as eq7, gt as gt2, lt as lt3, or as or2 } from "drizzle-orm";
|
|
2190
2275
|
function _ts_decorate(decorators, target, key, desc4) {
|
|
2191
2276
|
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
2192
2277
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -2235,7 +2320,7 @@ function num(value) {
|
|
|
2235
2320
|
__name(num, "num");
|
|
2236
2321
|
var RAG_INGESTION_LOG_PAGE_ORDER = [
|
|
2237
2322
|
desc3(ragIngestionLog.updatedAt),
|
|
2238
|
-
|
|
2323
|
+
asc4(ragIngestionLog.documentId)
|
|
2239
2324
|
];
|
|
2240
2325
|
var DEFAULT_PAGE_SIZE = 200;
|
|
2241
2326
|
var DEFAULT_BATCH_SIZE = 200;
|
|
@@ -2378,19 +2463,19 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2378
2463
|
}
|
|
2379
2464
|
/** The latest recorded outcome for one document, or null if it was never attempted. */
|
|
2380
2465
|
async get(documentId) {
|
|
2381
|
-
const [row] = await this.db.select().from(ragIngestionLog).where(
|
|
2466
|
+
const [row] = await this.db.select().from(ragIngestionLog).where(eq7(ragIngestionLog.documentId, documentId));
|
|
2382
2467
|
return row ?? null;
|
|
2383
2468
|
}
|
|
2384
2469
|
/** Forget one document's record. Returns whether a row was actually removed. */
|
|
2385
2470
|
async remove(documentId) {
|
|
2386
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2471
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq7(ragIngestionLog.documentId, documentId)).returning({
|
|
2387
2472
|
documentId: ragIngestionLog.documentId
|
|
2388
2473
|
});
|
|
2389
2474
|
return removed.length > 0;
|
|
2390
2475
|
}
|
|
2391
2476
|
/** Forget every record for a collection — for when the collection itself is deleted. */
|
|
2392
2477
|
async removeByCollection(collection) {
|
|
2393
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2478
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq7(ragIngestionLog.collection, collection)).returning({
|
|
2394
2479
|
documentId: ragIngestionLog.documentId
|
|
2395
2480
|
});
|
|
2396
2481
|
return removed.length;
|
|
@@ -2422,7 +2507,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2422
2507
|
}
|
|
2423
2508
|
}
|
|
2424
2509
|
where(query) {
|
|
2425
|
-
return
|
|
2510
|
+
return and6(query.collection !== void 0 ? eq7(ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? eq7(ragIngestionLog.status, query.status) : void 0);
|
|
2426
2511
|
}
|
|
2427
2512
|
/**
|
|
2428
2513
|
* The coordinates filter AND'd with "strictly after `cursor` in
|
|
@@ -2437,7 +2522,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2437
2522
|
if (cursor === void 0) {
|
|
2438
2523
|
return base;
|
|
2439
2524
|
}
|
|
2440
|
-
return
|
|
2525
|
+
return and6(base, or2(lt3(ragIngestionLog.updatedAt, cursor.updatedAt), and6(eq7(ragIngestionLog.updatedAt, cursor.updatedAt), gt2(ragIngestionLog.documentId, cursor.documentId))));
|
|
2441
2526
|
}
|
|
2442
2527
|
/**
|
|
2443
2528
|
* Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
|
|
@@ -2622,6 +2707,8 @@ export {
|
|
|
2622
2707
|
DrizzleMemoryProvider,
|
|
2623
2708
|
DrizzlePricingStore,
|
|
2624
2709
|
DrizzleRagIngestionLog,
|
|
2710
|
+
DrizzleStreamFrameTable,
|
|
2711
|
+
DrizzleTokenStreamSink,
|
|
2625
2712
|
RAG_INGESTION_LOG_PAGE_ORDER,
|
|
2626
2713
|
agentConfirmToken,
|
|
2627
2714
|
agentMemory,
|
|
@@ -2630,6 +2717,7 @@ export {
|
|
|
2630
2717
|
agentQueuedMessage,
|
|
2631
2718
|
agentRun,
|
|
2632
2719
|
agentSchema,
|
|
2720
|
+
agentStreamFrame,
|
|
2633
2721
|
agentThread,
|
|
2634
2722
|
agentTokenUsage,
|
|
2635
2723
|
agentToolCall,
|