@dudousxd/nestjs-agent-store-drizzle 0.14.0 → 0.16.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.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, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, 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 } from '@dudousxd/nestjs-agent-core';
3
+ import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, 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 } 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';
@@ -153,6 +153,25 @@ declare const agentThread: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
153
153
  }, {}, {
154
154
  length: number | undefined;
155
155
  }>;
156
+ model: drizzle_orm_sqlite_core.SQLiteColumn<{
157
+ name: "model";
158
+ tableName: "agent_thread";
159
+ dataType: "string";
160
+ columnType: "SQLiteText";
161
+ data: string;
162
+ driverParam: string;
163
+ notNull: false;
164
+ hasDefault: false;
165
+ isPrimaryKey: false;
166
+ isAutoincrement: false;
167
+ hasRuntimeDefault: false;
168
+ enumValues: [string, ...string[]];
169
+ baseColumn: never;
170
+ identity: undefined;
171
+ generated: undefined;
172
+ }, {}, {
173
+ length: number | undefined;
174
+ }>;
156
175
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
157
176
  name: "created_at";
158
177
  tableName: "agent_thread";
@@ -481,6 +500,25 @@ declare const agentMessage: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
481
500
  }, {}, {
482
501
  $type: AgentUiComponent[];
483
502
  }>;
503
+ feedback: drizzle_orm_sqlite_core.SQLiteColumn<{
504
+ name: "feedback";
505
+ tableName: "agent_message";
506
+ dataType: "json";
507
+ columnType: "SQLiteTextJson";
508
+ data: MessageFeedback;
509
+ driverParam: string;
510
+ notNull: false;
511
+ hasDefault: false;
512
+ isPrimaryKey: false;
513
+ isAutoincrement: false;
514
+ hasRuntimeDefault: false;
515
+ enumValues: undefined;
516
+ baseColumn: never;
517
+ identity: undefined;
518
+ generated: undefined;
519
+ }, {}, {
520
+ $type: MessageFeedback;
521
+ }>;
484
522
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
485
523
  name: "created_at";
486
524
  tableName: "agent_message";
@@ -2090,6 +2128,25 @@ declare const agentSchema: {
2090
2128
  }, {}, {
2091
2129
  length: number | undefined;
2092
2130
  }>;
2131
+ model: drizzle_orm_sqlite_core.SQLiteColumn<{
2132
+ name: "model";
2133
+ tableName: "agent_thread";
2134
+ dataType: "string";
2135
+ columnType: "SQLiteText";
2136
+ data: string;
2137
+ driverParam: string;
2138
+ notNull: false;
2139
+ hasDefault: false;
2140
+ isPrimaryKey: false;
2141
+ isAutoincrement: false;
2142
+ hasRuntimeDefault: false;
2143
+ enumValues: [string, ...string[]];
2144
+ baseColumn: never;
2145
+ identity: undefined;
2146
+ generated: undefined;
2147
+ }, {}, {
2148
+ length: number | undefined;
2149
+ }>;
2093
2150
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2094
2151
  name: "created_at";
2095
2152
  tableName: "agent_thread";
@@ -2413,6 +2470,25 @@ declare const agentSchema: {
2413
2470
  }, {}, {
2414
2471
  $type: AgentUiComponent[];
2415
2472
  }>;
2473
+ feedback: drizzle_orm_sqlite_core.SQLiteColumn<{
2474
+ name: "feedback";
2475
+ tableName: "agent_message";
2476
+ dataType: "json";
2477
+ columnType: "SQLiteTextJson";
2478
+ data: MessageFeedback;
2479
+ driverParam: string;
2480
+ notNull: false;
2481
+ hasDefault: false;
2482
+ isPrimaryKey: false;
2483
+ isAutoincrement: false;
2484
+ hasRuntimeDefault: false;
2485
+ enumValues: undefined;
2486
+ baseColumn: never;
2487
+ identity: undefined;
2488
+ generated: undefined;
2489
+ }, {}, {
2490
+ $type: MessageFeedback;
2491
+ }>;
2416
2492
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2417
2493
  name: "created_at";
2418
2494
  tableName: "agent_message";
@@ -3913,6 +3989,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3913
3989
  * agent answers the next turn, and {@link getThread} would materialize the whole transcript to
3914
3990
  * hand it over. `null` when the thread is unknown, soft-deleted, or has no default set.
3915
3991
  */
3992
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
3993
+ modelForThread(threadId: string): Promise<string | null>;
3916
3994
  defaultAgentForThread(threadId: string): Promise<string | null>;
3917
3995
  /**
3918
3996
  * Persist the start of a run (turn). Replay-safe: called under a durable localStep.
@@ -3934,6 +4012,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3934
4012
  appendMessage(input: AppendMessageInput): Promise<StoredMessage>;
3935
4013
  setMessageToolResults(messageId: string, results: ToolResult[]): Promise<void>;
3936
4014
  setMessageUi(messageId: string, ui: AgentUiComponent[]): Promise<void>;
4015
+ threadOfMessage(messageId: string): Promise<string | null>;
4016
+ setMessageFeedback(messageId: string, feedback: MessageFeedback | null): Promise<void>;
3937
4017
  truncateFrom(threadId: string, messageId: string): Promise<void>;
3938
4018
  recordToolCall(input: RecordToolCallInput): Promise<void>;
3939
4019
  updateToolCall(input: UpdateToolCallInput): Promise<void>;
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, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, 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 } from '@dudousxd/nestjs-agent-core';
3
+ import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, 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 } 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';
@@ -153,6 +153,25 @@ declare const agentThread: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
153
153
  }, {}, {
154
154
  length: number | undefined;
155
155
  }>;
156
+ model: drizzle_orm_sqlite_core.SQLiteColumn<{
157
+ name: "model";
158
+ tableName: "agent_thread";
159
+ dataType: "string";
160
+ columnType: "SQLiteText";
161
+ data: string;
162
+ driverParam: string;
163
+ notNull: false;
164
+ hasDefault: false;
165
+ isPrimaryKey: false;
166
+ isAutoincrement: false;
167
+ hasRuntimeDefault: false;
168
+ enumValues: [string, ...string[]];
169
+ baseColumn: never;
170
+ identity: undefined;
171
+ generated: undefined;
172
+ }, {}, {
173
+ length: number | undefined;
174
+ }>;
156
175
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
157
176
  name: "created_at";
158
177
  tableName: "agent_thread";
@@ -481,6 +500,25 @@ declare const agentMessage: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
481
500
  }, {}, {
482
501
  $type: AgentUiComponent[];
483
502
  }>;
503
+ feedback: drizzle_orm_sqlite_core.SQLiteColumn<{
504
+ name: "feedback";
505
+ tableName: "agent_message";
506
+ dataType: "json";
507
+ columnType: "SQLiteTextJson";
508
+ data: MessageFeedback;
509
+ driverParam: string;
510
+ notNull: false;
511
+ hasDefault: false;
512
+ isPrimaryKey: false;
513
+ isAutoincrement: false;
514
+ hasRuntimeDefault: false;
515
+ enumValues: undefined;
516
+ baseColumn: never;
517
+ identity: undefined;
518
+ generated: undefined;
519
+ }, {}, {
520
+ $type: MessageFeedback;
521
+ }>;
484
522
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
485
523
  name: "created_at";
486
524
  tableName: "agent_message";
@@ -2090,6 +2128,25 @@ declare const agentSchema: {
2090
2128
  }, {}, {
2091
2129
  length: number | undefined;
2092
2130
  }>;
2131
+ model: drizzle_orm_sqlite_core.SQLiteColumn<{
2132
+ name: "model";
2133
+ tableName: "agent_thread";
2134
+ dataType: "string";
2135
+ columnType: "SQLiteText";
2136
+ data: string;
2137
+ driverParam: string;
2138
+ notNull: false;
2139
+ hasDefault: false;
2140
+ isPrimaryKey: false;
2141
+ isAutoincrement: false;
2142
+ hasRuntimeDefault: false;
2143
+ enumValues: [string, ...string[]];
2144
+ baseColumn: never;
2145
+ identity: undefined;
2146
+ generated: undefined;
2147
+ }, {}, {
2148
+ length: number | undefined;
2149
+ }>;
2093
2150
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2094
2151
  name: "created_at";
2095
2152
  tableName: "agent_thread";
@@ -2413,6 +2470,25 @@ declare const agentSchema: {
2413
2470
  }, {}, {
2414
2471
  $type: AgentUiComponent[];
2415
2472
  }>;
2473
+ feedback: drizzle_orm_sqlite_core.SQLiteColumn<{
2474
+ name: "feedback";
2475
+ tableName: "agent_message";
2476
+ dataType: "json";
2477
+ columnType: "SQLiteTextJson";
2478
+ data: MessageFeedback;
2479
+ driverParam: string;
2480
+ notNull: false;
2481
+ hasDefault: false;
2482
+ isPrimaryKey: false;
2483
+ isAutoincrement: false;
2484
+ hasRuntimeDefault: false;
2485
+ enumValues: undefined;
2486
+ baseColumn: never;
2487
+ identity: undefined;
2488
+ generated: undefined;
2489
+ }, {}, {
2490
+ $type: MessageFeedback;
2491
+ }>;
2416
2492
  createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2417
2493
  name: "created_at";
2418
2494
  tableName: "agent_message";
@@ -3913,6 +3989,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3913
3989
  * agent answers the next turn, and {@link getThread} would materialize the whole transcript to
3914
3990
  * hand it over. `null` when the thread is unknown, soft-deleted, or has no default set.
3915
3991
  */
3992
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
3993
+ modelForThread(threadId: string): Promise<string | null>;
3916
3994
  defaultAgentForThread(threadId: string): Promise<string | null>;
3917
3995
  /**
3918
3996
  * Persist the start of a run (turn). Replay-safe: called under a durable localStep.
@@ -3934,6 +4012,8 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3934
4012
  appendMessage(input: AppendMessageInput): Promise<StoredMessage>;
3935
4013
  setMessageToolResults(messageId: string, results: ToolResult[]): Promise<void>;
3936
4014
  setMessageUi(messageId: string, ui: AgentUiComponent[]): Promise<void>;
4015
+ threadOfMessage(messageId: string): Promise<string | null>;
4016
+ setMessageFeedback(messageId: string, feedback: MessageFeedback | null): Promise<void>;
3937
4017
  truncateFrom(threadId: string, messageId: string): Promise<void>;
3938
4018
  recordToolCall(input: RecordToolCallInput): Promise<void>;
3939
4019
  updateToolCall(input: UpdateToolCallInput): Promise<void>;
package/dist/index.js CHANGED
@@ -14,6 +14,8 @@ var agentThread = sqliteTable("agent_thread", {
14
14
  activeStreamId: text("active_stream_id"),
15
15
  /** The agent a new turn on this thread defaults to when the caller names none. */
16
16
  defaultAgent: text("default_agent"),
17
+ /** The model every turn on this thread runs on unless the send names one; `null` → default. */
18
+ model: text("model"),
17
19
  createdAt: integer("created_at", {
18
20
  mode: "timestamp_ms"
19
21
  }).notNull(),
@@ -57,6 +59,10 @@ var agentMessage = sqliteTable("agent_message", {
57
59
  ui: text("ui", {
58
60
  mode: "json"
59
61
  }).$type(),
62
+ /** The thread owner's thumbs-up/down (+ comment); `null` when unrated. Not copied on fork. */
63
+ feedback: text("feedback", {
64
+ mode: "json"
65
+ }).$type(),
60
66
  createdAt: integer("created_at", {
61
67
  mode: "timestamp_ms"
62
68
  }).notNull()
@@ -247,6 +253,7 @@ var statements = [
247
253
  transient INTEGER NOT NULL DEFAULT 0,
248
254
  active_stream_id TEXT,
249
255
  default_agent TEXT,
256
+ model TEXT,
250
257
  created_at INTEGER NOT NULL,
251
258
  updated_at INTEGER NOT NULL,
252
259
  deleted_at INTEGER
@@ -268,6 +275,7 @@ var statements = [
268
275
  reasoning TEXT,
269
276
  reasoning_ms INTEGER,
270
277
  ui TEXT,
278
+ feedback TEXT,
271
279
  created_at INTEGER NOT NULL
272
280
  )`,
273
281
  `CREATE INDEX IF NOT EXISTS agent_message_thread_created_idx
@@ -407,6 +415,16 @@ var additiveColumns = [
407
415
  column: "ui",
408
416
  ddl: "ALTER TABLE agent_message ADD COLUMN ui TEXT"
409
417
  },
418
+ {
419
+ table: "agent_message",
420
+ column: "feedback",
421
+ ddl: "ALTER TABLE agent_message ADD COLUMN feedback TEXT"
422
+ },
423
+ {
424
+ table: "agent_thread",
425
+ column: "model",
426
+ ddl: "ALTER TABLE agent_thread ADD COLUMN model TEXT"
427
+ },
410
428
  {
411
429
  table: "agent_tool_call",
412
430
  column: "approver",
@@ -472,6 +490,7 @@ var DrizzleAgentStore = class {
472
490
  transient: input.transient ?? false,
473
491
  activeStreamId: null,
474
492
  defaultAgent: null,
493
+ model: null,
475
494
  createdAt: now,
476
495
  updatedAt: now,
477
496
  deletedAt: null
@@ -577,6 +596,7 @@ var DrizzleAgentStore = class {
577
596
  transient: false,
578
597
  activeStreamId: null,
579
598
  defaultAgent: source.defaultAgent,
599
+ model: source.model,
580
600
  createdAt: now,
581
601
  updatedAt: now,
582
602
  deletedAt: null
@@ -725,6 +745,9 @@ var DrizzleAgentStore = class {
725
745
  if (patch.defaultAgent !== void 0) {
726
746
  updates.defaultAgent = patch.defaultAgent;
727
747
  }
748
+ if (patch.model !== void 0) {
749
+ updates.model = patch.model;
750
+ }
728
751
  if (Object.keys(updates).length === 0) {
729
752
  return;
730
753
  }
@@ -736,6 +759,13 @@ var DrizzleAgentStore = class {
736
759
  * agent answers the next turn, and {@link getThread} would materialize the whole transcript to
737
760
  * hand it over. `null` when the thread is unknown, soft-deleted, or has no default set.
738
761
  */
762
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
763
+ async modelForThread(threadId) {
764
+ const [thread] = await this.db.select({
765
+ model: agentThread.model
766
+ }).from(agentThread).where(and(eq(agentThread.id, threadId), isNull(agentThread.deletedAt)));
767
+ return thread?.model ?? null;
768
+ }
739
769
  async defaultAgentForThread(threadId) {
740
770
  const [thread] = await this.db.select({
741
771
  defaultAgent: agentThread.defaultAgent
@@ -810,6 +840,7 @@ var DrizzleAgentStore = class {
810
840
  reasoning: input.reasoning ?? null,
811
841
  reasoningMs: input.reasoningMs ?? null,
812
842
  ui: input.ui ?? null,
843
+ feedback: null,
813
844
  createdAt: now
814
845
  };
815
846
  await this.db.insert(agentMessage).values(message);
@@ -828,6 +859,17 @@ var DrizzleAgentStore = class {
828
859
  ui: ui.length > 0 ? ui : null
829
860
  }).where(eq(agentMessage.id, messageId));
830
861
  }
862
+ async threadOfMessage(messageId) {
863
+ const [row] = await this.db.select({
864
+ threadId: agentMessage.threadId
865
+ }).from(agentMessage).where(eq(agentMessage.id, messageId)).limit(1);
866
+ return row?.threadId ?? null;
867
+ }
868
+ async setMessageFeedback(messageId, feedback) {
869
+ await this.db.update(agentMessage).set({
870
+ feedback
871
+ }).where(eq(agentMessage.id, messageId));
872
+ }
831
873
  async truncateFrom(threadId, messageId) {
832
874
  const messages = await this.db.select().from(agentMessage).where(eq(agentMessage.threadId, threadId)).orderBy(asc(agentMessage.createdAt), asc(agentMessage.id));
833
875
  const cutoff = messages.findIndex((message) => message.id === messageId);
@@ -954,6 +996,9 @@ var DrizzleAgentStore = class {
954
996
  createdAt: thread.createdAt.toISOString(),
955
997
  updatedAt: thread.updatedAt.toISOString(),
956
998
  defaultAgent: thread.defaultAgent,
999
+ ...thread.model != null ? {
1000
+ model: thread.model
1001
+ } : {},
957
1002
  ...lastContent !== void 0 ? {
958
1003
  lastMessagePreview: lastContent.slice(0, 120)
959
1004
  } : {}
@@ -994,6 +1039,9 @@ var DrizzleAgentStore = class {
994
1039
  } : {},
995
1040
  ...message.ui != null ? {
996
1041
  ui: message.ui
1042
+ } : {},
1043
+ ...message.feedback != null ? {
1044
+ feedback: message.feedback
997
1045
  } : {}
998
1046
  };
999
1047
  }