@inkeep/agents-core 0.10.2 → 0.11.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.
@@ -24,29 +24,47 @@ var CredentialStoreType = {
24
24
  keychain: "keychain",
25
25
  nango: "nango"
26
26
  };
27
+ var tenantScoped = {
28
+ tenantId: sqliteCore.text("tenant_id").notNull(),
29
+ id: sqliteCore.text("id").notNull()
30
+ };
31
+ var projectScoped = {
32
+ ...tenantScoped,
33
+ projectId: sqliteCore.text("project_id").notNull()
34
+ };
35
+ var graphScoped = {
36
+ ...projectScoped,
37
+ graphId: sqliteCore.text("graph_id").notNull()
38
+ };
39
+ var agentScoped = {
40
+ ...graphScoped,
41
+ agentId: sqliteCore.text("agent_id").notNull()
42
+ };
43
+ var uiProperties = {
44
+ name: sqliteCore.text("name").notNull(),
45
+ description: sqliteCore.text("description").notNull()
46
+ };
47
+ var timestamps = {
48
+ createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
49
+ updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
50
+ };
27
51
  var projects = sqliteCore.sqliteTable(
28
52
  "projects",
29
53
  {
30
- tenantId: sqliteCore.text("tenant_id").notNull(),
31
- id: sqliteCore.text("id").notNull(),
32
- // This IS the project ID
33
- name: sqliteCore.text("name").notNull(),
34
- description: sqliteCore.text("description").notNull(),
54
+ ...tenantScoped,
55
+ ...uiProperties,
35
56
  // Project-level default model settings that can be inherited by graphs and agents
36
57
  models: sqliteCore.text("models", { mode: "json" }).$type(),
37
58
  // Project-level stopWhen configuration that can be inherited by graphs and agents
38
59
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
39
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
40
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
60
+ ...timestamps
41
61
  },
42
62
  (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.id] })]
43
63
  );
44
64
  var agentGraph = sqliteCore.sqliteTable(
45
65
  "agent_graph",
46
66
  {
47
- tenantId: sqliteCore.text("tenant_id").notNull(),
48
- projectId: sqliteCore.text("project_id").notNull(),
49
- id: sqliteCore.text("id").notNull(),
67
+ ...projectScoped,
50
68
  name: sqliteCore.text("name").notNull(),
51
69
  description: sqliteCore.text("description"),
52
70
  defaultAgentId: sqliteCore.text("default_agent_id"),
@@ -61,8 +79,7 @@ var agentGraph = sqliteCore.sqliteTable(
61
79
  graphPrompt: sqliteCore.text("graph_prompt"),
62
80
  // Graph-level stopWhen configuration that can be inherited by agents
63
81
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
64
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
65
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
82
+ ...timestamps
66
83
  },
67
84
  (table) => [
68
85
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -76,19 +93,14 @@ var agentGraph = sqliteCore.sqliteTable(
76
93
  var contextConfigs = sqliteCore.sqliteTable(
77
94
  "context_configs",
78
95
  {
79
- tenantId: sqliteCore.text("tenant_id").notNull(),
80
- projectId: sqliteCore.text("project_id").notNull(),
81
- // Add graph level scoping
82
- id: sqliteCore.text("id").notNull(),
83
- name: sqliteCore.text("name").notNull(),
84
- description: sqliteCore.text("description").notNull(),
96
+ ...projectScoped,
97
+ ...uiProperties,
85
98
  // Developer-defined Zod schema for validating incoming request context
86
99
  requestContextSchema: sqliteCore.blob("request_context_schema", { mode: "json" }).$type(),
87
100
  // Stores serialized Zod schema
88
101
  // Object mapping template keys to fetch definitions that use request context data
89
102
  contextVariables: sqliteCore.blob("context_variables", { mode: "json" }).$type(),
90
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
91
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
103
+ ...timestamps
92
104
  },
93
105
  (table) => [
94
106
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -102,9 +114,7 @@ var contextConfigs = sqliteCore.sqliteTable(
102
114
  var contextCache = sqliteCore.sqliteTable(
103
115
  "context_cache",
104
116
  {
105
- tenantId: sqliteCore.text("tenant_id").notNull(),
106
- projectId: sqliteCore.text("project_id").notNull(),
107
- id: sqliteCore.text("id").notNull(),
117
+ ...projectScoped,
108
118
  // Always scoped to conversation for complete data isolation
109
119
  conversationId: sqliteCore.text("conversation_id").notNull(),
110
120
  // Reference to the context config and specific fetch definition
@@ -121,8 +131,7 @@ var contextCache = sqliteCore.sqliteTable(
121
131
  fetchSource: sqliteCore.text("fetch_source"),
122
132
  // URL or source identifier
123
133
  fetchDurationMs: sqliteCore.integer("fetch_duration_ms"),
124
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
125
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
134
+ ...timestamps
126
135
  },
127
136
  (table) => [
128
137
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -141,12 +150,8 @@ var contextCache = sqliteCore.sqliteTable(
141
150
  var agents = sqliteCore.sqliteTable(
142
151
  "agents",
143
152
  {
144
- tenantId: sqliteCore.text("tenant_id").notNull(),
145
- projectId: sqliteCore.text("project_id").notNull(),
146
- graphId: sqliteCore.text("graph_id").notNull(),
147
- id: sqliteCore.text("id").notNull(),
148
- name: sqliteCore.text("name").notNull(),
149
- description: sqliteCore.text("description").notNull(),
153
+ ...graphScoped,
154
+ ...uiProperties,
150
155
  prompt: sqliteCore.text("prompt").notNull(),
151
156
  conversationHistoryConfig: sqliteCore.text("conversation_history_config", {
152
157
  mode: "json"
@@ -154,8 +159,7 @@ var agents = sqliteCore.sqliteTable(
154
159
  models: sqliteCore.text("models", { mode: "json" }).$type(),
155
160
  // Agent-level stopWhen configuration (inherited from project)
156
161
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
157
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
158
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
162
+ ...timestamps
159
163
  },
160
164
  (table) => [
161
165
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -169,10 +173,7 @@ var agents = sqliteCore.sqliteTable(
169
173
  var agentRelations = sqliteCore.sqliteTable(
170
174
  "agent_relations",
171
175
  {
172
- tenantId: sqliteCore.text("tenant_id").notNull(),
173
- projectId: sqliteCore.text("project_id").notNull(),
174
- graphId: sqliteCore.text("graph_id").notNull(),
175
- id: sqliteCore.text("id").notNull(),
176
+ ...graphScoped,
176
177
  sourceAgentId: sqliteCore.text("source_agent_id").notNull(),
177
178
  // For internal relationships
178
179
  targetAgentId: sqliteCore.text("target_agent_id"),
@@ -180,8 +181,7 @@ var agentRelations = sqliteCore.sqliteTable(
180
181
  externalAgentId: sqliteCore.text("external_agent_id"),
181
182
  relationType: sqliteCore.text("relation_type"),
182
183
  // 'transfer' | 'delegate'
183
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
184
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
184
+ ...timestamps
185
185
  },
186
186
  (table) => [
187
187
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -195,18 +195,13 @@ var agentRelations = sqliteCore.sqliteTable(
195
195
  var externalAgents = sqliteCore.sqliteTable(
196
196
  "external_agents",
197
197
  {
198
- tenantId: sqliteCore.text("tenant_id").notNull(),
199
- projectId: sqliteCore.text("project_id").notNull(),
200
- graphId: sqliteCore.text("graph_id").notNull(),
201
- id: sqliteCore.text("id").notNull(),
202
- name: sqliteCore.text("name").notNull(),
203
- description: sqliteCore.text("description").notNull(),
198
+ ...graphScoped,
199
+ ...uiProperties,
204
200
  baseUrl: sqliteCore.text("base_url").notNull(),
205
201
  // A2A endpoint URL
206
202
  credentialReferenceId: sqliteCore.text("credential_reference_id"),
207
203
  headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
208
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
209
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
204
+ ...timestamps
210
205
  },
211
206
  (table) => [
212
207
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -229,37 +224,30 @@ var externalAgents = sqliteCore.sqliteTable(
229
224
  var tasks = sqliteCore.sqliteTable(
230
225
  "tasks",
231
226
  {
232
- tenantId: sqliteCore.text("tenant_id").notNull(),
233
- projectId: sqliteCore.text("project_id").notNull(),
234
- id: sqliteCore.text("id").notNull(),
227
+ ...agentScoped,
235
228
  contextId: sqliteCore.text("context_id").notNull(),
236
229
  status: sqliteCore.text("status").notNull(),
237
230
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
238
- agentId: sqliteCore.text("agent_id").notNull(),
239
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
240
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
231
+ ...timestamps
241
232
  },
242
233
  (table) => [
243
234
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
244
235
  sqliteCore.foreignKey({
245
- columns: [table.tenantId, table.projectId],
246
- foreignColumns: [projects.tenantId, projects.id],
247
- name: "tasks_project_fk"
236
+ columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
237
+ foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
238
+ name: "tasks_agent_fk"
248
239
  }).onDelete("cascade")
249
240
  ]
250
241
  );
251
242
  var taskRelations = sqliteCore.sqliteTable(
252
243
  "task_relations",
253
244
  {
254
- tenantId: sqliteCore.text("tenant_id").notNull(),
255
- projectId: sqliteCore.text("project_id").notNull(),
256
- id: sqliteCore.text("id").notNull(),
245
+ ...projectScoped,
257
246
  parentTaskId: sqliteCore.text("parent_task_id").notNull(),
258
247
  childTaskId: sqliteCore.text("child_task_id").notNull(),
259
248
  relationType: sqliteCore.text("relation_type").default("parent_child"),
260
249
  // Could be extended for other relation types
261
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
262
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
250
+ ...timestamps
263
251
  },
264
252
  (table) => [
265
253
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -273,14 +261,10 @@ var taskRelations = sqliteCore.sqliteTable(
273
261
  var dataComponents = sqliteCore.sqliteTable(
274
262
  "data_components",
275
263
  {
276
- tenantId: sqliteCore.text("tenant_id").notNull(),
277
- projectId: sqliteCore.text("project_id").notNull(),
278
- id: sqliteCore.text("id").notNull(),
279
- name: sqliteCore.text("name").notNull(),
280
- description: sqliteCore.text("description").notNull(),
264
+ ...projectScoped,
265
+ ...uiProperties,
281
266
  props: sqliteCore.blob("props", { mode: "json" }).$type(),
282
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
283
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
267
+ ...timestamps
284
268
  },
285
269
  (table) => [
286
270
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -294,11 +278,7 @@ var dataComponents = sqliteCore.sqliteTable(
294
278
  var agentDataComponents = sqliteCore.sqliteTable(
295
279
  "agent_data_components",
296
280
  {
297
- tenantId: sqliteCore.text("tenant_id").notNull(),
298
- projectId: sqliteCore.text("project_id").notNull(),
299
- graphId: sqliteCore.text("graph_id").notNull(),
300
- agentId: sqliteCore.text("agent_id").notNull(),
301
- id: sqliteCore.text("id").notNull(),
281
+ ...agentScoped,
302
282
  dataComponentId: sqliteCore.text("data_component_id").notNull(),
303
283
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
304
284
  },
@@ -321,15 +301,11 @@ var agentDataComponents = sqliteCore.sqliteTable(
321
301
  var artifactComponents = sqliteCore.sqliteTable(
322
302
  "artifact_components",
323
303
  {
324
- tenantId: sqliteCore.text("tenant_id").notNull(),
325
- projectId: sqliteCore.text("project_id").notNull(),
326
- id: sqliteCore.text("id").notNull(),
327
- name: sqliteCore.text("name").notNull(),
328
- description: sqliteCore.text("description").notNull(),
304
+ ...projectScoped,
305
+ ...uiProperties,
329
306
  summaryProps: sqliteCore.blob("summary_props", { mode: "json" }).$type(),
330
307
  fullProps: sqliteCore.blob("full_props", { mode: "json" }).$type(),
331
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
332
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
308
+ ...timestamps
333
309
  },
334
310
  (table) => [
335
311
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -343,11 +319,7 @@ var artifactComponents = sqliteCore.sqliteTable(
343
319
  var agentArtifactComponents = sqliteCore.sqliteTable(
344
320
  "agent_artifact_components",
345
321
  {
346
- tenantId: sqliteCore.text("tenant_id").notNull(),
347
- projectId: sqliteCore.text("project_id").notNull(),
348
- graphId: sqliteCore.text("graph_id").notNull(),
349
- agentId: sqliteCore.text("agent_id").notNull(),
350
- id: sqliteCore.text("id").notNull(),
322
+ ...agentScoped,
351
323
  artifactComponentId: sqliteCore.text("artifact_component_id").notNull(),
352
324
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
353
325
  },
@@ -376,9 +348,7 @@ var agentArtifactComponents = sqliteCore.sqliteTable(
376
348
  var tools = sqliteCore.sqliteTable(
377
349
  "tools",
378
350
  {
379
- tenantId: sqliteCore.text("tenant_id").notNull(),
380
- projectId: sqliteCore.text("project_id").notNull(),
381
- id: sqliteCore.text("id").notNull(),
351
+ ...projectScoped,
382
352
  name: sqliteCore.text("name").notNull(),
383
353
  // Enhanced MCP configuration
384
354
  config: sqliteCore.blob("config", { mode: "json" }).$type().notNull(),
@@ -389,8 +359,7 @@ var tools = sqliteCore.sqliteTable(
389
359
  // Server capabilities and status
390
360
  capabilities: sqliteCore.blob("capabilities", { mode: "json" }).$type(),
391
361
  lastError: sqliteCore.text("last_error"),
392
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
393
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
362
+ ...timestamps
394
363
  },
395
364
  (table) => [
396
365
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -404,16 +373,11 @@ var tools = sqliteCore.sqliteTable(
404
373
  var agentToolRelations = sqliteCore.sqliteTable(
405
374
  "agent_tool_relations",
406
375
  {
407
- tenantId: sqliteCore.text("tenant_id").notNull(),
408
- projectId: sqliteCore.text("project_id").notNull(),
409
- graphId: sqliteCore.text("graph_id").notNull(),
410
- agentId: sqliteCore.text("agent_id").notNull(),
411
- id: sqliteCore.text("id").notNull(),
376
+ ...agentScoped,
412
377
  toolId: sqliteCore.text("tool_id").notNull(),
413
378
  selectedTools: sqliteCore.blob("selected_tools", { mode: "json" }).$type(),
414
379
  headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
415
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
416
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
380
+ ...timestamps
417
381
  },
418
382
  (table) => [
419
383
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -434,16 +398,13 @@ var agentToolRelations = sqliteCore.sqliteTable(
434
398
  var conversations = sqliteCore.sqliteTable(
435
399
  "conversations",
436
400
  {
437
- tenantId: sqliteCore.text("tenant_id").notNull(),
438
- projectId: sqliteCore.text("project_id").notNull(),
439
- id: sqliteCore.text("id").notNull(),
401
+ ...projectScoped,
440
402
  userId: sqliteCore.text("user_id"),
441
403
  activeAgentId: sqliteCore.text("active_agent_id").notNull(),
442
404
  title: sqliteCore.text("title"),
443
405
  lastContextResolution: sqliteCore.text("last_context_resolution"),
444
406
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
445
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
446
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
407
+ ...timestamps
447
408
  },
448
409
  (table) => [
449
410
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -457,9 +418,7 @@ var conversations = sqliteCore.sqliteTable(
457
418
  var messages = sqliteCore.sqliteTable(
458
419
  "messages",
459
420
  {
460
- tenantId: sqliteCore.text("tenant_id").notNull(),
461
- projectId: sqliteCore.text("project_id").notNull(),
462
- id: sqliteCore.text("id").notNull(),
421
+ ...projectScoped,
463
422
  conversationId: sqliteCore.text("conversation_id").notNull(),
464
423
  // Role mapping: user, agent, system (unified for both formats)
465
424
  role: sqliteCore.text("role").notNull(),
@@ -494,8 +453,7 @@ var messages = sqliteCore.sqliteTable(
494
453
  // A2A session identifier
495
454
  // Metadata for extensions
496
455
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
497
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
498
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
456
+ ...timestamps
499
457
  },
500
458
  (table) => [
501
459
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -509,10 +467,7 @@ var messages = sqliteCore.sqliteTable(
509
467
  var ledgerArtifacts = sqliteCore.sqliteTable(
510
468
  "ledger_artifacts",
511
469
  {
512
- // Primary identifier (maps to `artifactId`)
513
- tenantId: sqliteCore.text("tenant_id").notNull(),
514
- projectId: sqliteCore.text("project_id").notNull(),
515
- id: sqliteCore.text("id").notNull(),
470
+ ...projectScoped,
516
471
  // Links
517
472
  taskId: sqliteCore.text("task_id").notNull(),
518
473
  toolCallId: sqliteCore.text("tool_call_id"),
@@ -530,9 +485,7 @@ var ledgerArtifacts = sqliteCore.sqliteTable(
530
485
  visibility: sqliteCore.text("visibility").default("context"),
531
486
  allowedAgents: sqliteCore.blob("allowed_agents", { mode: "json" }).$type(),
532
487
  derivedFrom: sqliteCore.text("derived_from"),
533
- // Timestamps
534
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
535
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
488
+ ...timestamps
536
489
  },
537
490
  (table) => [
538
491
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id, table.taskId] }),
@@ -540,16 +493,21 @@ var ledgerArtifacts = sqliteCore.sqliteTable(
540
493
  columns: [table.tenantId, table.projectId],
541
494
  foreignColumns: [projects.tenantId, projects.id],
542
495
  name: "ledger_artifacts_project_fk"
543
- }).onDelete("cascade")
496
+ }).onDelete("cascade"),
497
+ sqliteCore.index("ledger_artifacts_task_id_idx").on(table.taskId),
498
+ sqliteCore.index("ledger_artifacts_tool_call_id_idx").on(table.toolCallId),
499
+ sqliteCore.index("ledger_artifacts_context_id_idx").on(table.contextId),
500
+ sqliteCore.unique("ledger_artifacts_task_context_name_unique").on(
501
+ table.taskId,
502
+ table.contextId,
503
+ table.name
504
+ )
544
505
  ]
545
506
  );
546
507
  var apiKeys = sqliteCore.sqliteTable(
547
508
  "api_keys",
548
509
  {
549
- id: sqliteCore.text("id").primaryKey(),
550
- tenantId: sqliteCore.text("tenant_id").notNull(),
551
- projectId: sqliteCore.text("project_id").notNull(),
552
- graphId: sqliteCore.text("graph_id").notNull(),
510
+ ...graphScoped,
553
511
  publicId: sqliteCore.text("public_id").notNull().unique(),
554
512
  // Public ID for O(1) lookup (e.g., "abc123def456")
555
513
  keyHash: sqliteCore.text("key_hash").notNull(),
@@ -559,8 +517,7 @@ var apiKeys = sqliteCore.sqliteTable(
559
517
  name: sqliteCore.text("name"),
560
518
  lastUsedAt: sqliteCore.text("last_used_at"),
561
519
  expiresAt: sqliteCore.text("expires_at"),
562
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
563
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
520
+ ...timestamps
564
521
  },
565
522
  (t) => [
566
523
  sqliteCore.foreignKey({
@@ -581,16 +538,13 @@ var apiKeys = sqliteCore.sqliteTable(
581
538
  var credentialReferences = sqliteCore.sqliteTable(
582
539
  "credential_references",
583
540
  {
584
- tenantId: sqliteCore.text("tenant_id").notNull(),
585
- projectId: sqliteCore.text("project_id").notNull(),
586
- id: sqliteCore.text("id").notNull(),
541
+ ...projectScoped,
587
542
  type: sqliteCore.text("type").notNull(),
588
543
  // Implementation type: 'keychain', 'nango', 'memory', etc.
589
544
  credentialStoreId: sqliteCore.text("credential_store_id").notNull(),
590
545
  // Maps to framework.getCredentialStore(id)
591
546
  retrievalParams: sqliteCore.blob("retrieval_params", { mode: "json" }).$type(),
592
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
593
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
547
+ ...timestamps
594
548
  },
595
549
  (t) => [
596
550
  sqliteCore.primaryKey({ columns: [t.tenantId, t.projectId, t.id] }),
@@ -601,18 +555,6 @@ var credentialReferences = sqliteCore.sqliteTable(
601
555
  }).onDelete("cascade")
602
556
  ]
603
557
  );
604
- sqliteCore.index("ledger_artifacts_task_id_idx").on(
605
- ledgerArtifacts.taskId
606
- );
607
- sqliteCore.index("ledger_artifacts_tool_call_id_idx").on(
608
- ledgerArtifacts.toolCallId
609
- );
610
- sqliteCore.index("ledger_artifacts_context_id_idx").on(
611
- ledgerArtifacts.contextId
612
- );
613
- sqliteCore.unique(
614
- "ledger_artifacts_task_context_name_unique"
615
- ).on(ledgerArtifacts.taskId, ledgerArtifacts.contextId, ledgerArtifacts.name);
616
558
  drizzleOrm.relations(tasks, ({ one, many }) => ({
617
559
  // A task belongs to one project
618
560
  project: one(projects, {
@@ -638,37 +580,24 @@ drizzleOrm.relations(tasks, ({ one, many }) => ({
638
580
  ledgerArtifacts: many(ledgerArtifacts)
639
581
  }));
640
582
  drizzleOrm.relations(projects, ({ many }) => ({
641
- // A project can have many agents
642
583
  agents: many(agents),
643
- // A project can have many agent graphs
644
584
  agentGraphs: many(agentGraph),
645
- // A project can have many tools
646
585
  tools: many(tools),
647
- // A project can have many context configs
648
586
  contextConfigs: many(contextConfigs),
649
- // A project can have many external agents
650
587
  externalAgents: many(externalAgents),
651
- // A project can have many conversations
652
588
  conversations: many(conversations),
653
- // A project can have many tasks
654
589
  tasks: many(tasks),
655
- // A project can have many data components
656
590
  dataComponents: many(dataComponents),
657
- // A project can have many artifact components
658
591
  artifactComponents: many(artifactComponents),
659
- // A project can have many ledger artifacts
660
592
  ledgerArtifacts: many(ledgerArtifacts),
661
- // A project can have many credential references
662
593
  credentialReferences: many(credentialReferences)
663
594
  }));
664
595
  drizzleOrm.relations(taskRelations, ({ one }) => ({
665
- // Each relation has one parent task
666
596
  parentTask: one(tasks, {
667
597
  fields: [taskRelations.parentTaskId],
668
598
  references: [tasks.id],
669
599
  relationName: "parentTask"
670
600
  }),
671
- // Each relation has one child task
672
601
  childTask: one(tasks, {
673
602
  fields: [taskRelations.childTaskId],
674
603
  references: [tasks.id],
@@ -676,107 +605,85 @@ drizzleOrm.relations(taskRelations, ({ one }) => ({
676
605
  })
677
606
  }));
678
607
  drizzleOrm.relations(contextConfigs, ({ many, one }) => ({
679
- // A context config belongs to one project
680
608
  project: one(projects, {
681
609
  fields: [contextConfigs.tenantId, contextConfigs.projectId],
682
610
  references: [projects.tenantId, projects.id]
683
611
  }),
684
- // A context config can be used by many agent graphs
685
612
  graphs: many(agentGraph),
686
- // A context config can have many cached entries
687
613
  cache: many(contextCache)
688
614
  }));
689
615
  drizzleOrm.relations(contextCache, ({ one }) => ({
690
- // Each cache entry belongs to one context config
691
616
  contextConfig: one(contextConfigs, {
692
617
  fields: [contextCache.contextConfigId],
693
618
  references: [contextConfigs.id]
694
619
  })
695
620
  }));
696
621
  drizzleOrm.relations(agents, ({ many, one }) => ({
697
- // A context config belongs to one project
698
622
  project: one(projects, {
699
623
  fields: [agents.tenantId, agents.projectId],
700
624
  references: [projects.tenantId, projects.id]
701
625
  }),
702
- // An agent can have many tasks
703
626
  tasks: many(tasks),
704
- // An agent can be the default agent for many graphs
705
627
  defaultForGraphs: many(agentGraph),
706
- // Agent relation tracking
707
628
  sourceRelations: many(agentRelations, {
708
629
  relationName: "sourceRelations"
709
630
  }),
710
631
  targetRelations: many(agentRelations, {
711
632
  relationName: "targetRelations"
712
633
  }),
713
- // Message tracking relations
714
634
  sentMessages: many(messages, {
715
635
  relationName: "sentMessages"
716
636
  }),
717
637
  receivedMessages: many(messages, {
718
638
  relationName: "receivedMessages"
719
639
  }),
720
- // Legacy message association (consider deprecating)
721
640
  associatedMessages: many(messages, {
722
641
  relationName: "associatedAgent"
723
642
  }),
724
643
  toolRelations: many(agentToolRelations),
725
- // Data component relations
726
644
  dataComponentRelations: many(agentDataComponents),
727
- // Artifact component relations
728
645
  artifactComponentRelations: many(agentArtifactComponents)
729
646
  }));
730
647
  drizzleOrm.relations(agentGraph, ({ one }) => ({
731
- // An agent graph belongs to one project
732
648
  project: one(projects, {
733
649
  fields: [agentGraph.tenantId, agentGraph.projectId],
734
650
  references: [projects.tenantId, projects.id]
735
651
  }),
736
- // An agent graph may have one default agent (optional)
737
652
  defaultAgent: one(agents, {
738
653
  fields: [agentGraph.defaultAgentId],
739
654
  references: [agents.id]
740
655
  }),
741
- // An agent graph can reference one context config
742
656
  contextConfig: one(contextConfigs, {
743
657
  fields: [agentGraph.contextConfigId],
744
658
  references: [contextConfigs.id]
745
659
  })
746
660
  }));
747
661
  drizzleOrm.relations(externalAgents, ({ one, many }) => ({
748
- // An external agent belongs to one project
749
662
  project: one(projects, {
750
663
  fields: [externalAgents.tenantId, externalAgents.projectId],
751
664
  references: [projects.tenantId, projects.id]
752
665
  }),
753
- // An external agent can be referenced by many agent relations
754
666
  agentRelations: many(agentRelations),
755
- // An external agent may have one credential reference
756
667
  credentialReference: one(credentialReferences, {
757
668
  fields: [externalAgents.credentialReferenceId],
758
669
  references: [credentialReferences.id]
759
670
  })
760
671
  }));
761
672
  drizzleOrm.relations(apiKeys, ({ one }) => ({
762
- // An API key belongs to one project
763
673
  project: one(projects, {
764
674
  fields: [apiKeys.tenantId, apiKeys.projectId],
765
675
  references: [projects.tenantId, projects.id]
766
676
  }),
767
- // An API key belongs to one tenant and graph
768
677
  graph: one(agentGraph, {
769
678
  fields: [apiKeys.graphId],
770
679
  references: [agentGraph.id]
771
680
  })
772
681
  }));
773
682
  drizzleOrm.relations(agentToolRelations, ({ one }) => ({
774
- // An agent-tool relation belongs to one agent
775
683
  agent: one(agents, {
776
684
  fields: [agentToolRelations.agentId],
777
685
  references: [agents.id]
778
686
  }),
779
- // An agent-tool relation belongs to one tool
780
687
  tool: one(tools, {
781
688
  fields: [agentToolRelations.toolId],
782
689
  references: [tools.id]
@@ -786,35 +693,28 @@ drizzleOrm.relations(credentialReferences, ({ many }) => ({
786
693
  tools: many(tools)
787
694
  }));
788
695
  drizzleOrm.relations(tools, ({ one, many }) => ({
789
- // A tool belongs to one project
790
696
  project: one(projects, {
791
697
  fields: [tools.tenantId, tools.projectId],
792
698
  references: [projects.tenantId, projects.id]
793
699
  }),
794
- // A tool can be used by many agents through agent-tool relations
795
700
  agentRelations: many(agentToolRelations),
796
- // A tool may have one credential reference
797
701
  credentialReference: one(credentialReferences, {
798
702
  fields: [tools.credentialReferenceId],
799
703
  references: [credentialReferences.id]
800
704
  })
801
705
  }));
802
706
  drizzleOrm.relations(conversations, ({ one, many }) => ({
803
- // A conversation belongs to one project
804
707
  project: one(projects, {
805
708
  fields: [conversations.tenantId, conversations.projectId],
806
709
  references: [projects.tenantId, projects.id]
807
710
  }),
808
- // A conversation has many messages
809
711
  messages: many(messages),
810
- // A conversation has one active agent
811
712
  activeAgent: one(agents, {
812
713
  fields: [conversations.activeAgentId],
813
714
  references: [agents.id]
814
715
  })
815
716
  }));
816
717
  drizzleOrm.relations(messages, ({ one, many }) => ({
817
- // A message belongs to one conversation
818
718
  conversation: one(conversations, {
819
719
  fields: [messages.conversationId],
820
720
  references: [conversations.id]
@@ -825,114 +725,94 @@ drizzleOrm.relations(messages, ({ one, many }) => ({
825
725
  references: [agents.id],
826
726
  relationName: "associatedAgent"
827
727
  }),
828
- // Sender tracking relations
829
728
  fromAgent: one(agents, {
830
729
  fields: [messages.fromAgentId],
831
730
  references: [agents.id],
832
731
  relationName: "sentMessages"
833
732
  }),
834
- // Recipient tracking relations
835
733
  toAgent: one(agents, {
836
734
  fields: [messages.toAgentId],
837
735
  references: [agents.id],
838
736
  relationName: "receivedMessages"
839
737
  }),
840
- // External agent sender tracking relations
841
738
  fromExternalAgent: one(externalAgents, {
842
739
  fields: [messages.fromExternalAgentId],
843
740
  references: [externalAgents.id],
844
741
  relationName: "receivedExternalMessages"
845
742
  }),
846
- // External agent recipient tracking relations
847
743
  toExternalAgent: one(externalAgents, {
848
744
  fields: [messages.toExternalAgentId],
849
745
  references: [externalAgents.id],
850
746
  relationName: "sentExternalMessages"
851
747
  }),
852
- // A message may be associated with a task
853
748
  task: one(tasks, {
854
749
  fields: [messages.taskId],
855
750
  references: [tasks.id]
856
751
  }),
857
- // A message may have a parent message (for threading)
858
752
  parentMessage: one(messages, {
859
753
  fields: [messages.parentMessageId],
860
754
  references: [messages.id],
861
755
  relationName: "parentChild"
862
756
  }),
863
- // A message may have child messages
864
757
  childMessages: many(messages, {
865
758
  relationName: "parentChild"
866
759
  })
867
760
  }));
868
761
  drizzleOrm.relations(artifactComponents, ({ many }) => ({
869
- // An artifact component can be associated with many agents
870
762
  agentRelations: many(agentArtifactComponents)
871
763
  }));
872
764
  drizzleOrm.relations(agentArtifactComponents, ({ one }) => ({
873
- // An agent-artifact component relation belongs to one agent
874
765
  agent: one(agents, {
875
766
  fields: [agentArtifactComponents.agentId],
876
767
  references: [agents.id]
877
768
  }),
878
- // An agent-artifact component relation belongs to one artifact component
879
769
  artifactComponent: one(artifactComponents, {
880
770
  fields: [agentArtifactComponents.artifactComponentId],
881
771
  references: [artifactComponents.id]
882
772
  })
883
773
  }));
884
774
  drizzleOrm.relations(dataComponents, ({ many, one }) => ({
885
- // A data component belongs to one project
886
775
  project: one(projects, {
887
776
  fields: [dataComponents.tenantId, dataComponents.projectId],
888
777
  references: [projects.tenantId, projects.id]
889
778
  }),
890
- // A data component can be associated with many agents
891
779
  agentRelations: many(agentDataComponents)
892
780
  }));
893
781
  drizzleOrm.relations(agentDataComponents, ({ one }) => ({
894
- // An agent-data component relation belongs to one agent
895
782
  agent: one(agents, {
896
783
  fields: [agentDataComponents.agentId],
897
784
  references: [agents.id]
898
785
  }),
899
- // An agent-data component relation belongs to one data component
900
786
  dataComponent: one(dataComponents, {
901
787
  fields: [agentDataComponents.dataComponentId],
902
788
  references: [dataComponents.id]
903
789
  })
904
790
  }));
905
791
  drizzleOrm.relations(ledgerArtifacts, ({ one }) => ({
906
- // A ledger artifact belongs to one project
907
792
  project: one(projects, {
908
793
  fields: [ledgerArtifacts.tenantId, ledgerArtifacts.projectId],
909
794
  references: [projects.tenantId, projects.id]
910
795
  }),
911
- // A ledger artifact may be associated with one task
912
796
  task: one(tasks, {
913
797
  fields: [ledgerArtifacts.taskId],
914
798
  references: [tasks.id]
915
799
  })
916
800
  }));
917
801
  drizzleOrm.relations(agentRelations, ({ one }) => ({
918
- // An agent relation belongs to one graph
919
802
  graph: one(agentGraph, {
920
803
  fields: [agentRelations.graphId],
921
804
  references: [agentGraph.id]
922
805
  }),
923
- // An agent relation has one source agent
924
806
  sourceAgent: one(agents, {
925
807
  fields: [agentRelations.sourceAgentId],
926
808
  references: [agents.id],
927
809
  relationName: "sourceRelations"
928
810
  }),
929
- // An agent relation may have one target agent (for internal relations)
930
811
  targetAgent: one(agents, {
931
812
  fields: [agentRelations.targetAgentId],
932
813
  references: [agents.id],
933
814
  relationName: "targetRelations"
934
815
  }),
935
- // An agent relation may have one external agent (for external relations)
936
816
  externalAgent: one(externalAgents, {
937
817
  fields: [agentRelations.externalAgentId],
938
818
  references: [externalAgents.id]