@dudousxd/nestjs-agent-store-drizzle 0.21.0 → 0.22.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/README.md +1 -1
- package/dist/index.cjs +123 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -3
- package/dist/index.d.ts +135 -3
- package/dist/index.js +108 -13
- 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<{
|
|
@@ -4742,7 +4845,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader, ChatQue
|
|
|
4742
4845
|
toolCallOutcomes(toolCallIds: readonly string[]): Promise<ToolCallOutcome[]>;
|
|
4743
4846
|
failUnsettledToolCalls(runId: string, error: string): Promise<number>;
|
|
4744
4847
|
/**
|
|
4745
|
-
* Of `mediaIds`, the ones a surviving message in
|
|
4848
|
+
* Of `mediaIds`, the ones a surviving message — or a message waiting in the queue — in one of
|
|
4849
|
+
* this actor's threads still carries.
|
|
4746
4850
|
*
|
|
4747
4851
|
* Reads the `attachments` JSON back out and matches in memory rather than pushing the match into
|
|
4748
4852
|
* SQL: the column holds an array of objects, and every dialect this adapter's sibling targets
|
|
@@ -4947,6 +5051,34 @@ declare class DrizzlePricingStore implements AgentPricingStore {
|
|
|
4947
5051
|
listCurrentPrices(): Promise<CurrentModelPrice[]>;
|
|
4948
5052
|
}
|
|
4949
5053
|
|
|
5054
|
+
/** {@link StreamFrameTable} over `agent_stream_frame`, through a Drizzle SQLite handle. */
|
|
5055
|
+
declare class DrizzleStreamFrameTable implements StreamFrameTable {
|
|
5056
|
+
private readonly db;
|
|
5057
|
+
constructor(db: AgentDrizzleDb);
|
|
5058
|
+
append(runId: string, row: {
|
|
5059
|
+
frame: string | null;
|
|
5060
|
+
error: string | null;
|
|
5061
|
+
createdAt: number;
|
|
5062
|
+
}): Promise<void>;
|
|
5063
|
+
read(runId: string, after: number, limit: number): Promise<StreamFrameRow[]>;
|
|
5064
|
+
has(runId: string): Promise<boolean>;
|
|
5065
|
+
remove(runIds: readonly string[]): Promise<void>;
|
|
5066
|
+
lapsedRuns(cutoff: number): Promise<string[]>;
|
|
5067
|
+
isUniqueViolation(error: unknown): boolean;
|
|
5068
|
+
}
|
|
5069
|
+
/**
|
|
5070
|
+
* A multi-replica `TokenStreamSink` over the app's Drizzle database — several replicas, no Redis.
|
|
5071
|
+
* Polled, with streamed text coalesced into one row per `flushMs`; see `SqlTokenStreamSink` for the
|
|
5072
|
+
* trade-offs. The `agent_stream_frame` table comes from `ensureAgentSchema` (or your migration).
|
|
5073
|
+
*
|
|
5074
|
+
* ```ts
|
|
5075
|
+
* AgentModule.forRoot({ model, sink: new DrizzleTokenStreamSink(db) });
|
|
5076
|
+
* ```
|
|
5077
|
+
*/
|
|
5078
|
+
declare class DrizzleTokenStreamSink extends SqlTokenStreamSink {
|
|
5079
|
+
constructor(db: AgentDrizzleDb, options?: SqlTokenStreamSinkOptions);
|
|
5080
|
+
}
|
|
5081
|
+
|
|
4950
5082
|
/**
|
|
4951
5083
|
* A production `ConfirmTokenStore` (`defineConfirmedTool`) over the `agent_confirm_token` table —
|
|
4952
5084
|
* what makes a confirmed write single use across replicas.
|
|
@@ -5195,4 +5327,4 @@ declare class DrizzleAgentStoreModule {
|
|
|
5195
5327
|
static forRoot(options: DrizzleAgentStoreModuleOptions): DynamicModule;
|
|
5196
5328
|
}
|
|
5197
5329
|
|
|
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 };
|
|
5330
|
+
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<{
|
|
@@ -4742,7 +4845,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader, ChatQue
|
|
|
4742
4845
|
toolCallOutcomes(toolCallIds: readonly string[]): Promise<ToolCallOutcome[]>;
|
|
4743
4846
|
failUnsettledToolCalls(runId: string, error: string): Promise<number>;
|
|
4744
4847
|
/**
|
|
4745
|
-
* Of `mediaIds`, the ones a surviving message in
|
|
4848
|
+
* Of `mediaIds`, the ones a surviving message — or a message waiting in the queue — in one of
|
|
4849
|
+
* this actor's threads still carries.
|
|
4746
4850
|
*
|
|
4747
4851
|
* Reads the `attachments` JSON back out and matches in memory rather than pushing the match into
|
|
4748
4852
|
* SQL: the column holds an array of objects, and every dialect this adapter's sibling targets
|
|
@@ -4947,6 +5051,34 @@ declare class DrizzlePricingStore implements AgentPricingStore {
|
|
|
4947
5051
|
listCurrentPrices(): Promise<CurrentModelPrice[]>;
|
|
4948
5052
|
}
|
|
4949
5053
|
|
|
5054
|
+
/** {@link StreamFrameTable} over `agent_stream_frame`, through a Drizzle SQLite handle. */
|
|
5055
|
+
declare class DrizzleStreamFrameTable implements StreamFrameTable {
|
|
5056
|
+
private readonly db;
|
|
5057
|
+
constructor(db: AgentDrizzleDb);
|
|
5058
|
+
append(runId: string, row: {
|
|
5059
|
+
frame: string | null;
|
|
5060
|
+
error: string | null;
|
|
5061
|
+
createdAt: number;
|
|
5062
|
+
}): Promise<void>;
|
|
5063
|
+
read(runId: string, after: number, limit: number): Promise<StreamFrameRow[]>;
|
|
5064
|
+
has(runId: string): Promise<boolean>;
|
|
5065
|
+
remove(runIds: readonly string[]): Promise<void>;
|
|
5066
|
+
lapsedRuns(cutoff: number): Promise<string[]>;
|
|
5067
|
+
isUniqueViolation(error: unknown): boolean;
|
|
5068
|
+
}
|
|
5069
|
+
/**
|
|
5070
|
+
* A multi-replica `TokenStreamSink` over the app's Drizzle database — several replicas, no Redis.
|
|
5071
|
+
* Polled, with streamed text coalesced into one row per `flushMs`; see `SqlTokenStreamSink` for the
|
|
5072
|
+
* trade-offs. The `agent_stream_frame` table comes from `ensureAgentSchema` (or your migration).
|
|
5073
|
+
*
|
|
5074
|
+
* ```ts
|
|
5075
|
+
* AgentModule.forRoot({ model, sink: new DrizzleTokenStreamSink(db) });
|
|
5076
|
+
* ```
|
|
5077
|
+
*/
|
|
5078
|
+
declare class DrizzleTokenStreamSink extends SqlTokenStreamSink {
|
|
5079
|
+
constructor(db: AgentDrizzleDb, options?: SqlTokenStreamSinkOptions);
|
|
5080
|
+
}
|
|
5081
|
+
|
|
4950
5082
|
/**
|
|
4951
5083
|
* A production `ConfirmTokenStore` (`defineConfirmedTool`) over the `agent_confirm_token` table —
|
|
4952
5084
|
* what makes a confirmed write single use across replicas.
|
|
@@ -5195,4 +5327,4 @@ declare class DrizzleAgentStoreModule {
|
|
|
5195
5327
|
static forRoot(options: DrizzleAgentStoreModuleOptions): DynamicModule;
|
|
5196
5328
|
}
|
|
5197
5329
|
|
|
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 };
|
|
5330
|
+
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,
|
|
@@ -1167,7 +1189,8 @@ var DrizzleAgentStore = class {
|
|
|
1167
1189
|
return rows.length;
|
|
1168
1190
|
}
|
|
1169
1191
|
/**
|
|
1170
|
-
* Of `mediaIds`, the ones a surviving message in
|
|
1192
|
+
* Of `mediaIds`, the ones a surviving message — or a message waiting in the queue — in one of
|
|
1193
|
+
* this actor's threads still carries.
|
|
1171
1194
|
*
|
|
1172
1195
|
* Reads the `attachments` JSON back out and matches in memory rather than pushing the match into
|
|
1173
1196
|
* SQL: the column holds an array of objects, and every dialect this adapter's sibling targets
|
|
@@ -1186,9 +1209,15 @@ var DrizzleAgentStore = class {
|
|
|
1186
1209
|
const rows = await this.db.select({
|
|
1187
1210
|
attachments: agentMessage.attachments
|
|
1188
1211
|
}).from(agentMessage).innerJoin(agentThread, eq(agentMessage.threadId, agentThread.id)).where(and(eq(agentThread.actorRef, actorRef), isNotNull(agentMessage.attachments)));
|
|
1212
|
+
const queued = await this.db.select({
|
|
1213
|
+
attachments: agentQueuedMessage.attachments
|
|
1214
|
+
}).from(agentQueuedMessage).innerJoin(agentThread, eq(agentQueuedMessage.threadId, agentThread.id)).where(and(eq(agentThread.actorRef, actorRef), isNotNull(agentQueuedMessage.attachments)));
|
|
1189
1215
|
const wanted = new Set(mediaIds);
|
|
1190
1216
|
const found = /* @__PURE__ */ new Set();
|
|
1191
|
-
for (const row of
|
|
1217
|
+
for (const row of [
|
|
1218
|
+
...rows,
|
|
1219
|
+
...queued
|
|
1220
|
+
]) {
|
|
1192
1221
|
for (const attachment of row.attachments ?? []) {
|
|
1193
1222
|
if (wanted.has(attachment.mediaId)) {
|
|
1194
1223
|
found.add(attachment.mediaId);
|
|
@@ -2150,8 +2179,71 @@ var DrizzlePricingStore = class {
|
|
|
2150
2179
|
}
|
|
2151
2180
|
};
|
|
2152
2181
|
|
|
2182
|
+
// src/drizzle-token-stream-sink.ts
|
|
2183
|
+
import { SqlTokenStreamSink } from "@dudousxd/nestjs-agent-core";
|
|
2184
|
+
import { and as and5, asc as asc3, eq as eq5, gt, inArray as inArray4, lt, max as max2, sql as sql4 } from "drizzle-orm";
|
|
2185
|
+
function isUniqueViolation(error) {
|
|
2186
|
+
for (let current = error; current !== null && typeof current === "object"; ) {
|
|
2187
|
+
const code = current.code;
|
|
2188
|
+
if (typeof code === "string" && code.startsWith("SQLITE_CONSTRAINT")) return true;
|
|
2189
|
+
current = current.cause;
|
|
2190
|
+
}
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
__name(isUniqueViolation, "isUniqueViolation");
|
|
2194
|
+
var DrizzleStreamFrameTable = class {
|
|
2195
|
+
static {
|
|
2196
|
+
__name(this, "DrizzleStreamFrameTable");
|
|
2197
|
+
}
|
|
2198
|
+
db;
|
|
2199
|
+
constructor(db) {
|
|
2200
|
+
this.db = db;
|
|
2201
|
+
}
|
|
2202
|
+
async append(runId, row) {
|
|
2203
|
+
await this.db.run(sql4`INSERT INTO agent_stream_frame (run_id, seq, frame, error, created_at)
|
|
2204
|
+
SELECT ${runId}, COALESCE(MAX(seq), 0) + 1, ${row.frame}, ${row.error}, ${row.createdAt}
|
|
2205
|
+
FROM agent_stream_frame WHERE run_id = ${runId}`);
|
|
2206
|
+
}
|
|
2207
|
+
async read(runId, after, limit) {
|
|
2208
|
+
return this.db.select({
|
|
2209
|
+
seq: agentStreamFrame.seq,
|
|
2210
|
+
frame: agentStreamFrame.frame,
|
|
2211
|
+
error: agentStreamFrame.error
|
|
2212
|
+
}).from(agentStreamFrame).where(and5(eq5(agentStreamFrame.runId, runId), gt(agentStreamFrame.seq, after))).orderBy(asc3(agentStreamFrame.seq)).limit(limit);
|
|
2213
|
+
}
|
|
2214
|
+
async has(runId) {
|
|
2215
|
+
const rows = await this.db.select({
|
|
2216
|
+
seq: agentStreamFrame.seq
|
|
2217
|
+
}).from(agentStreamFrame).where(eq5(agentStreamFrame.runId, runId)).limit(1);
|
|
2218
|
+
return rows.length > 0;
|
|
2219
|
+
}
|
|
2220
|
+
async remove(runIds) {
|
|
2221
|
+
if (runIds.length === 0) return;
|
|
2222
|
+
await this.db.delete(agentStreamFrame).where(inArray4(agentStreamFrame.runId, [
|
|
2223
|
+
...runIds
|
|
2224
|
+
]));
|
|
2225
|
+
}
|
|
2226
|
+
async lapsedRuns(cutoff) {
|
|
2227
|
+
const rows = await this.db.select({
|
|
2228
|
+
runId: agentStreamFrame.runId
|
|
2229
|
+
}).from(agentStreamFrame).groupBy(agentStreamFrame.runId).having(lt(max2(agentStreamFrame.createdAt), cutoff));
|
|
2230
|
+
return rows.map((row) => row.runId);
|
|
2231
|
+
}
|
|
2232
|
+
isUniqueViolation(error) {
|
|
2233
|
+
return isUniqueViolation(error);
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
var DrizzleTokenStreamSink = class extends SqlTokenStreamSink {
|
|
2237
|
+
static {
|
|
2238
|
+
__name(this, "DrizzleTokenStreamSink");
|
|
2239
|
+
}
|
|
2240
|
+
constructor(db, options = {}) {
|
|
2241
|
+
super(new DrizzleStreamFrameTable(db), options);
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2153
2245
|
// src/drizzle-confirm-token-store.ts
|
|
2154
|
-
import { eq as
|
|
2246
|
+
import { eq as eq6, lt as lt2 } from "drizzle-orm";
|
|
2155
2247
|
var DrizzleConfirmTokenStore = class {
|
|
2156
2248
|
static {
|
|
2157
2249
|
__name(this, "DrizzleConfirmTokenStore");
|
|
@@ -2173,10 +2265,10 @@ var DrizzleConfirmTokenStore = class {
|
|
|
2173
2265
|
return inserted.length === 1;
|
|
2174
2266
|
}
|
|
2175
2267
|
async release(hash) {
|
|
2176
|
-
await this.db.delete(agentConfirmToken).where(
|
|
2268
|
+
await this.db.delete(agentConfirmToken).where(eq6(agentConfirmToken.hash, hash));
|
|
2177
2269
|
}
|
|
2178
2270
|
async purgeExpired(now = Date.now()) {
|
|
2179
|
-
const purged = await this.db.delete(agentConfirmToken).where(
|
|
2271
|
+
const purged = await this.db.delete(agentConfirmToken).where(lt2(agentConfirmToken.expiresAt, now)).returning({
|
|
2180
2272
|
hash: agentConfirmToken.hash
|
|
2181
2273
|
});
|
|
2182
2274
|
return purged.length;
|
|
@@ -2186,7 +2278,7 @@ var DrizzleConfirmTokenStore = class {
|
|
|
2186
2278
|
// src/drizzle-rag-ingestion-log.ts
|
|
2187
2279
|
import { subscribe, unsubscribe } from "diagnostics_channel";
|
|
2188
2280
|
import { Injectable, Logger } from "@nestjs/common";
|
|
2189
|
-
import { and as
|
|
2281
|
+
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
2282
|
function _ts_decorate(decorators, target, key, desc4) {
|
|
2191
2283
|
var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key) : desc4, d;
|
|
2192
2284
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -2235,7 +2327,7 @@ function num(value) {
|
|
|
2235
2327
|
__name(num, "num");
|
|
2236
2328
|
var RAG_INGESTION_LOG_PAGE_ORDER = [
|
|
2237
2329
|
desc3(ragIngestionLog.updatedAt),
|
|
2238
|
-
|
|
2330
|
+
asc4(ragIngestionLog.documentId)
|
|
2239
2331
|
];
|
|
2240
2332
|
var DEFAULT_PAGE_SIZE = 200;
|
|
2241
2333
|
var DEFAULT_BATCH_SIZE = 200;
|
|
@@ -2378,19 +2470,19 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2378
2470
|
}
|
|
2379
2471
|
/** The latest recorded outcome for one document, or null if it was never attempted. */
|
|
2380
2472
|
async get(documentId) {
|
|
2381
|
-
const [row] = await this.db.select().from(ragIngestionLog).where(
|
|
2473
|
+
const [row] = await this.db.select().from(ragIngestionLog).where(eq7(ragIngestionLog.documentId, documentId));
|
|
2382
2474
|
return row ?? null;
|
|
2383
2475
|
}
|
|
2384
2476
|
/** Forget one document's record. Returns whether a row was actually removed. */
|
|
2385
2477
|
async remove(documentId) {
|
|
2386
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2478
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq7(ragIngestionLog.documentId, documentId)).returning({
|
|
2387
2479
|
documentId: ragIngestionLog.documentId
|
|
2388
2480
|
});
|
|
2389
2481
|
return removed.length > 0;
|
|
2390
2482
|
}
|
|
2391
2483
|
/** Forget every record for a collection — for when the collection itself is deleted. */
|
|
2392
2484
|
async removeByCollection(collection) {
|
|
2393
|
-
const removed = await this.db.delete(ragIngestionLog).where(
|
|
2485
|
+
const removed = await this.db.delete(ragIngestionLog).where(eq7(ragIngestionLog.collection, collection)).returning({
|
|
2394
2486
|
documentId: ragIngestionLog.documentId
|
|
2395
2487
|
});
|
|
2396
2488
|
return removed.length;
|
|
@@ -2422,7 +2514,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2422
2514
|
}
|
|
2423
2515
|
}
|
|
2424
2516
|
where(query) {
|
|
2425
|
-
return
|
|
2517
|
+
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
2518
|
}
|
|
2427
2519
|
/**
|
|
2428
2520
|
* The coordinates filter AND'd with "strictly after `cursor` in
|
|
@@ -2437,7 +2529,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
|
|
|
2437
2529
|
if (cursor === void 0) {
|
|
2438
2530
|
return base;
|
|
2439
2531
|
}
|
|
2440
|
-
return
|
|
2532
|
+
return and6(base, or2(lt3(ragIngestionLog.updatedAt, cursor.updatedAt), and6(eq7(ragIngestionLog.updatedAt, cursor.updatedAt), gt2(ragIngestionLog.documentId, cursor.documentId))));
|
|
2441
2533
|
}
|
|
2442
2534
|
/**
|
|
2443
2535
|
* Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
|
|
@@ -2622,6 +2714,8 @@ export {
|
|
|
2622
2714
|
DrizzleMemoryProvider,
|
|
2623
2715
|
DrizzlePricingStore,
|
|
2624
2716
|
DrizzleRagIngestionLog,
|
|
2717
|
+
DrizzleStreamFrameTable,
|
|
2718
|
+
DrizzleTokenStreamSink,
|
|
2625
2719
|
RAG_INGESTION_LOG_PAGE_ORDER,
|
|
2626
2720
|
agentConfirmToken,
|
|
2627
2721
|
agentMemory,
|
|
@@ -2630,6 +2724,7 @@ export {
|
|
|
2630
2724
|
agentQueuedMessage,
|
|
2631
2725
|
agentRun,
|
|
2632
2726
|
agentSchema,
|
|
2727
|
+
agentStreamFrame,
|
|
2633
2728
|
agentThread,
|
|
2634
2729
|
agentTokenUsage,
|
|
2635
2730
|
agentToolCall,
|