@inkeep/agents-core 0.10.1 → 0.11.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.
@@ -4,29 +4,47 @@ var drizzleOrm = require('drizzle-orm');
4
4
  var sqliteCore = require('drizzle-orm/sqlite-core');
5
5
 
6
6
  // src/db/schema.ts
7
+ var tenantScoped = {
8
+ tenantId: sqliteCore.text("tenant_id").notNull(),
9
+ id: sqliteCore.text("id").notNull()
10
+ };
11
+ var projectScoped = {
12
+ ...tenantScoped,
13
+ projectId: sqliteCore.text("project_id").notNull()
14
+ };
15
+ var graphScoped = {
16
+ ...projectScoped,
17
+ graphId: sqliteCore.text("graph_id").notNull()
18
+ };
19
+ var agentScoped = {
20
+ ...graphScoped,
21
+ agentId: sqliteCore.text("agent_id").notNull()
22
+ };
23
+ var uiProperties = {
24
+ name: sqliteCore.text("name").notNull(),
25
+ description: sqliteCore.text("description").notNull()
26
+ };
27
+ var timestamps = {
28
+ createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
29
+ updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
30
+ };
7
31
  var projects = sqliteCore.sqliteTable(
8
32
  "projects",
9
33
  {
10
- tenantId: sqliteCore.text("tenant_id").notNull(),
11
- id: sqliteCore.text("id").notNull(),
12
- // This IS the project ID
13
- name: sqliteCore.text("name").notNull(),
14
- description: sqliteCore.text("description").notNull(),
34
+ ...tenantScoped,
35
+ ...uiProperties,
15
36
  // Project-level default model settings that can be inherited by graphs and agents
16
37
  models: sqliteCore.text("models", { mode: "json" }).$type(),
17
38
  // Project-level stopWhen configuration that can be inherited by graphs and agents
18
39
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
19
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
20
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
40
+ ...timestamps
21
41
  },
22
42
  (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.id] })]
23
43
  );
24
44
  var agentGraph = sqliteCore.sqliteTable(
25
45
  "agent_graph",
26
46
  {
27
- tenantId: sqliteCore.text("tenant_id").notNull(),
28
- projectId: sqliteCore.text("project_id").notNull(),
29
- id: sqliteCore.text("id").notNull(),
47
+ ...projectScoped,
30
48
  name: sqliteCore.text("name").notNull(),
31
49
  description: sqliteCore.text("description"),
32
50
  defaultAgentId: sqliteCore.text("default_agent_id"),
@@ -41,8 +59,7 @@ var agentGraph = sqliteCore.sqliteTable(
41
59
  graphPrompt: sqliteCore.text("graph_prompt"),
42
60
  // Graph-level stopWhen configuration that can be inherited by agents
43
61
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
44
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
45
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
62
+ ...timestamps
46
63
  },
47
64
  (table) => [
48
65
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -56,19 +73,14 @@ var agentGraph = sqliteCore.sqliteTable(
56
73
  var contextConfigs = sqliteCore.sqliteTable(
57
74
  "context_configs",
58
75
  {
59
- tenantId: sqliteCore.text("tenant_id").notNull(),
60
- projectId: sqliteCore.text("project_id").notNull(),
61
- // Add graph level scoping
62
- id: sqliteCore.text("id").notNull(),
63
- name: sqliteCore.text("name").notNull(),
64
- description: sqliteCore.text("description").notNull(),
76
+ ...projectScoped,
77
+ ...uiProperties,
65
78
  // Developer-defined Zod schema for validating incoming request context
66
79
  requestContextSchema: sqliteCore.blob("request_context_schema", { mode: "json" }).$type(),
67
80
  // Stores serialized Zod schema
68
81
  // Object mapping template keys to fetch definitions that use request context data
69
82
  contextVariables: sqliteCore.blob("context_variables", { mode: "json" }).$type(),
70
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
71
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
83
+ ...timestamps
72
84
  },
73
85
  (table) => [
74
86
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -82,9 +94,7 @@ var contextConfigs = sqliteCore.sqliteTable(
82
94
  var contextCache = sqliteCore.sqliteTable(
83
95
  "context_cache",
84
96
  {
85
- tenantId: sqliteCore.text("tenant_id").notNull(),
86
- projectId: sqliteCore.text("project_id").notNull(),
87
- id: sqliteCore.text("id").notNull(),
97
+ ...projectScoped,
88
98
  // Always scoped to conversation for complete data isolation
89
99
  conversationId: sqliteCore.text("conversation_id").notNull(),
90
100
  // Reference to the context config and specific fetch definition
@@ -101,8 +111,7 @@ var contextCache = sqliteCore.sqliteTable(
101
111
  fetchSource: sqliteCore.text("fetch_source"),
102
112
  // URL or source identifier
103
113
  fetchDurationMs: sqliteCore.integer("fetch_duration_ms"),
104
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
105
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
114
+ ...timestamps
106
115
  },
107
116
  (table) => [
108
117
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -121,12 +130,8 @@ var contextCache = sqliteCore.sqliteTable(
121
130
  var agents = sqliteCore.sqliteTable(
122
131
  "agents",
123
132
  {
124
- tenantId: sqliteCore.text("tenant_id").notNull(),
125
- projectId: sqliteCore.text("project_id").notNull(),
126
- graphId: sqliteCore.text("graph_id").notNull(),
127
- id: sqliteCore.text("id").notNull(),
128
- name: sqliteCore.text("name").notNull(),
129
- description: sqliteCore.text("description").notNull(),
133
+ ...graphScoped,
134
+ ...uiProperties,
130
135
  prompt: sqliteCore.text("prompt").notNull(),
131
136
  conversationHistoryConfig: sqliteCore.text("conversation_history_config", {
132
137
  mode: "json"
@@ -134,8 +139,7 @@ var agents = sqliteCore.sqliteTable(
134
139
  models: sqliteCore.text("models", { mode: "json" }).$type(),
135
140
  // Agent-level stopWhen configuration (inherited from project)
136
141
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
137
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
138
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
142
+ ...timestamps
139
143
  },
140
144
  (table) => [
141
145
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -149,10 +153,7 @@ var agents = sqliteCore.sqliteTable(
149
153
  var agentRelations = sqliteCore.sqliteTable(
150
154
  "agent_relations",
151
155
  {
152
- tenantId: sqliteCore.text("tenant_id").notNull(),
153
- projectId: sqliteCore.text("project_id").notNull(),
154
- graphId: sqliteCore.text("graph_id").notNull(),
155
- id: sqliteCore.text("id").notNull(),
156
+ ...graphScoped,
156
157
  sourceAgentId: sqliteCore.text("source_agent_id").notNull(),
157
158
  // For internal relationships
158
159
  targetAgentId: sqliteCore.text("target_agent_id"),
@@ -160,8 +161,7 @@ var agentRelations = sqliteCore.sqliteTable(
160
161
  externalAgentId: sqliteCore.text("external_agent_id"),
161
162
  relationType: sqliteCore.text("relation_type"),
162
163
  // 'transfer' | 'delegate'
163
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
164
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
164
+ ...timestamps
165
165
  },
166
166
  (table) => [
167
167
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -175,18 +175,13 @@ var agentRelations = sqliteCore.sqliteTable(
175
175
  var externalAgents = sqliteCore.sqliteTable(
176
176
  "external_agents",
177
177
  {
178
- tenantId: sqliteCore.text("tenant_id").notNull(),
179
- projectId: sqliteCore.text("project_id").notNull(),
180
- graphId: sqliteCore.text("graph_id").notNull(),
181
- id: sqliteCore.text("id").notNull(),
182
- name: sqliteCore.text("name").notNull(),
183
- description: sqliteCore.text("description").notNull(),
178
+ ...graphScoped,
179
+ ...uiProperties,
184
180
  baseUrl: sqliteCore.text("base_url").notNull(),
185
181
  // A2A endpoint URL
186
182
  credentialReferenceId: sqliteCore.text("credential_reference_id"),
187
183
  headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
188
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
189
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
184
+ ...timestamps
190
185
  },
191
186
  (table) => [
192
187
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -209,37 +204,30 @@ var externalAgents = sqliteCore.sqliteTable(
209
204
  var tasks = sqliteCore.sqliteTable(
210
205
  "tasks",
211
206
  {
212
- tenantId: sqliteCore.text("tenant_id").notNull(),
213
- projectId: sqliteCore.text("project_id").notNull(),
214
- id: sqliteCore.text("id").notNull(),
207
+ ...agentScoped,
215
208
  contextId: sqliteCore.text("context_id").notNull(),
216
209
  status: sqliteCore.text("status").notNull(),
217
210
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
218
- agentId: sqliteCore.text("agent_id").notNull(),
219
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
220
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
211
+ ...timestamps
221
212
  },
222
213
  (table) => [
223
214
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
224
215
  sqliteCore.foreignKey({
225
- columns: [table.tenantId, table.projectId],
226
- foreignColumns: [projects.tenantId, projects.id],
227
- name: "tasks_project_fk"
216
+ columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
217
+ foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
218
+ name: "tasks_agent_fk"
228
219
  }).onDelete("cascade")
229
220
  ]
230
221
  );
231
222
  var taskRelations = sqliteCore.sqliteTable(
232
223
  "task_relations",
233
224
  {
234
- tenantId: sqliteCore.text("tenant_id").notNull(),
235
- projectId: sqliteCore.text("project_id").notNull(),
236
- id: sqliteCore.text("id").notNull(),
225
+ ...projectScoped,
237
226
  parentTaskId: sqliteCore.text("parent_task_id").notNull(),
238
227
  childTaskId: sqliteCore.text("child_task_id").notNull(),
239
228
  relationType: sqliteCore.text("relation_type").default("parent_child"),
240
229
  // Could be extended for other relation types
241
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
242
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
230
+ ...timestamps
243
231
  },
244
232
  (table) => [
245
233
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -253,14 +241,10 @@ var taskRelations = sqliteCore.sqliteTable(
253
241
  var dataComponents = sqliteCore.sqliteTable(
254
242
  "data_components",
255
243
  {
256
- tenantId: sqliteCore.text("tenant_id").notNull(),
257
- projectId: sqliteCore.text("project_id").notNull(),
258
- id: sqliteCore.text("id").notNull(),
259
- name: sqliteCore.text("name").notNull(),
260
- description: sqliteCore.text("description").notNull(),
244
+ ...projectScoped,
245
+ ...uiProperties,
261
246
  props: sqliteCore.blob("props", { mode: "json" }).$type(),
262
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
263
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
247
+ ...timestamps
264
248
  },
265
249
  (table) => [
266
250
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -274,11 +258,7 @@ var dataComponents = sqliteCore.sqliteTable(
274
258
  var agentDataComponents = sqliteCore.sqliteTable(
275
259
  "agent_data_components",
276
260
  {
277
- tenantId: sqliteCore.text("tenant_id").notNull(),
278
- projectId: sqliteCore.text("project_id").notNull(),
279
- graphId: sqliteCore.text("graph_id").notNull(),
280
- agentId: sqliteCore.text("agent_id").notNull(),
281
- id: sqliteCore.text("id").notNull(),
261
+ ...agentScoped,
282
262
  dataComponentId: sqliteCore.text("data_component_id").notNull(),
283
263
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
284
264
  },
@@ -301,15 +281,11 @@ var agentDataComponents = sqliteCore.sqliteTable(
301
281
  var artifactComponents = sqliteCore.sqliteTable(
302
282
  "artifact_components",
303
283
  {
304
- tenantId: sqliteCore.text("tenant_id").notNull(),
305
- projectId: sqliteCore.text("project_id").notNull(),
306
- id: sqliteCore.text("id").notNull(),
307
- name: sqliteCore.text("name").notNull(),
308
- description: sqliteCore.text("description").notNull(),
284
+ ...projectScoped,
285
+ ...uiProperties,
309
286
  summaryProps: sqliteCore.blob("summary_props", { mode: "json" }).$type(),
310
287
  fullProps: sqliteCore.blob("full_props", { mode: "json" }).$type(),
311
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
312
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
288
+ ...timestamps
313
289
  },
314
290
  (table) => [
315
291
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -323,11 +299,7 @@ var artifactComponents = sqliteCore.sqliteTable(
323
299
  var agentArtifactComponents = sqliteCore.sqliteTable(
324
300
  "agent_artifact_components",
325
301
  {
326
- tenantId: sqliteCore.text("tenant_id").notNull(),
327
- projectId: sqliteCore.text("project_id").notNull(),
328
- graphId: sqliteCore.text("graph_id").notNull(),
329
- agentId: sqliteCore.text("agent_id").notNull(),
330
- id: sqliteCore.text("id").notNull(),
302
+ ...agentScoped,
331
303
  artifactComponentId: sqliteCore.text("artifact_component_id").notNull(),
332
304
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
333
305
  },
@@ -356,9 +328,7 @@ var agentArtifactComponents = sqliteCore.sqliteTable(
356
328
  var tools = sqliteCore.sqliteTable(
357
329
  "tools",
358
330
  {
359
- tenantId: sqliteCore.text("tenant_id").notNull(),
360
- projectId: sqliteCore.text("project_id").notNull(),
361
- id: sqliteCore.text("id").notNull(),
331
+ ...projectScoped,
362
332
  name: sqliteCore.text("name").notNull(),
363
333
  // Enhanced MCP configuration
364
334
  config: sqliteCore.blob("config", { mode: "json" }).$type().notNull(),
@@ -369,8 +339,7 @@ var tools = sqliteCore.sqliteTable(
369
339
  // Server capabilities and status
370
340
  capabilities: sqliteCore.blob("capabilities", { mode: "json" }).$type(),
371
341
  lastError: sqliteCore.text("last_error"),
372
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
373
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
342
+ ...timestamps
374
343
  },
375
344
  (table) => [
376
345
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -384,16 +353,11 @@ var tools = sqliteCore.sqliteTable(
384
353
  var agentToolRelations = sqliteCore.sqliteTable(
385
354
  "agent_tool_relations",
386
355
  {
387
- tenantId: sqliteCore.text("tenant_id").notNull(),
388
- projectId: sqliteCore.text("project_id").notNull(),
389
- graphId: sqliteCore.text("graph_id").notNull(),
390
- agentId: sqliteCore.text("agent_id").notNull(),
391
- id: sqliteCore.text("id").notNull(),
356
+ ...agentScoped,
392
357
  toolId: sqliteCore.text("tool_id").notNull(),
393
358
  selectedTools: sqliteCore.blob("selected_tools", { mode: "json" }).$type(),
394
359
  headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
395
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
396
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
360
+ ...timestamps
397
361
  },
398
362
  (table) => [
399
363
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
@@ -414,16 +378,13 @@ var agentToolRelations = sqliteCore.sqliteTable(
414
378
  var conversations = sqliteCore.sqliteTable(
415
379
  "conversations",
416
380
  {
417
- tenantId: sqliteCore.text("tenant_id").notNull(),
418
- projectId: sqliteCore.text("project_id").notNull(),
419
- id: sqliteCore.text("id").notNull(),
381
+ ...projectScoped,
420
382
  userId: sqliteCore.text("user_id"),
421
383
  activeAgentId: sqliteCore.text("active_agent_id").notNull(),
422
384
  title: sqliteCore.text("title"),
423
385
  lastContextResolution: sqliteCore.text("last_context_resolution"),
424
386
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
425
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
426
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
387
+ ...timestamps
427
388
  },
428
389
  (table) => [
429
390
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -437,9 +398,7 @@ var conversations = sqliteCore.sqliteTable(
437
398
  var messages = sqliteCore.sqliteTable(
438
399
  "messages",
439
400
  {
440
- tenantId: sqliteCore.text("tenant_id").notNull(),
441
- projectId: sqliteCore.text("project_id").notNull(),
442
- id: sqliteCore.text("id").notNull(),
401
+ ...projectScoped,
443
402
  conversationId: sqliteCore.text("conversation_id").notNull(),
444
403
  // Role mapping: user, agent, system (unified for both formats)
445
404
  role: sqliteCore.text("role").notNull(),
@@ -474,8 +433,7 @@ var messages = sqliteCore.sqliteTable(
474
433
  // A2A session identifier
475
434
  // Metadata for extensions
476
435
  metadata: sqliteCore.blob("metadata", { mode: "json" }).$type(),
477
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
478
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
436
+ ...timestamps
479
437
  },
480
438
  (table) => [
481
439
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
@@ -489,10 +447,7 @@ var messages = sqliteCore.sqliteTable(
489
447
  var ledgerArtifacts = sqliteCore.sqliteTable(
490
448
  "ledger_artifacts",
491
449
  {
492
- // Primary identifier (maps to `artifactId`)
493
- tenantId: sqliteCore.text("tenant_id").notNull(),
494
- projectId: sqliteCore.text("project_id").notNull(),
495
- id: sqliteCore.text("id").notNull(),
450
+ ...projectScoped,
496
451
  // Links
497
452
  taskId: sqliteCore.text("task_id").notNull(),
498
453
  toolCallId: sqliteCore.text("tool_call_id"),
@@ -510,9 +465,7 @@ var ledgerArtifacts = sqliteCore.sqliteTable(
510
465
  visibility: sqliteCore.text("visibility").default("context"),
511
466
  allowedAgents: sqliteCore.blob("allowed_agents", { mode: "json" }).$type(),
512
467
  derivedFrom: sqliteCore.text("derived_from"),
513
- // Timestamps
514
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
515
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
468
+ ...timestamps
516
469
  },
517
470
  (table) => [
518
471
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id, table.taskId] }),
@@ -520,16 +473,21 @@ var ledgerArtifacts = sqliteCore.sqliteTable(
520
473
  columns: [table.tenantId, table.projectId],
521
474
  foreignColumns: [projects.tenantId, projects.id],
522
475
  name: "ledger_artifacts_project_fk"
523
- }).onDelete("cascade")
476
+ }).onDelete("cascade"),
477
+ sqliteCore.index("ledger_artifacts_task_id_idx").on(table.taskId),
478
+ sqliteCore.index("ledger_artifacts_tool_call_id_idx").on(table.toolCallId),
479
+ sqliteCore.index("ledger_artifacts_context_id_idx").on(table.contextId),
480
+ sqliteCore.unique("ledger_artifacts_task_context_name_unique").on(
481
+ table.taskId,
482
+ table.contextId,
483
+ table.name
484
+ )
524
485
  ]
525
486
  );
526
487
  var apiKeys = sqliteCore.sqliteTable(
527
488
  "api_keys",
528
489
  {
529
- id: sqliteCore.text("id").primaryKey(),
530
- tenantId: sqliteCore.text("tenant_id").notNull(),
531
- projectId: sqliteCore.text("project_id").notNull(),
532
- graphId: sqliteCore.text("graph_id").notNull(),
490
+ ...graphScoped,
533
491
  publicId: sqliteCore.text("public_id").notNull().unique(),
534
492
  // Public ID for O(1) lookup (e.g., "abc123def456")
535
493
  keyHash: sqliteCore.text("key_hash").notNull(),
@@ -539,8 +497,7 @@ var apiKeys = sqliteCore.sqliteTable(
539
497
  name: sqliteCore.text("name"),
540
498
  lastUsedAt: sqliteCore.text("last_used_at"),
541
499
  expiresAt: sqliteCore.text("expires_at"),
542
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
543
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
500
+ ...timestamps
544
501
  },
545
502
  (t) => [
546
503
  sqliteCore.foreignKey({
@@ -561,16 +518,13 @@ var apiKeys = sqliteCore.sqliteTable(
561
518
  var credentialReferences = sqliteCore.sqliteTable(
562
519
  "credential_references",
563
520
  {
564
- tenantId: sqliteCore.text("tenant_id").notNull(),
565
- projectId: sqliteCore.text("project_id").notNull(),
566
- id: sqliteCore.text("id").notNull(),
521
+ ...projectScoped,
567
522
  type: sqliteCore.text("type").notNull(),
568
523
  // Implementation type: 'keychain', 'nango', 'memory', etc.
569
524
  credentialStoreId: sqliteCore.text("credential_store_id").notNull(),
570
525
  // Maps to framework.getCredentialStore(id)
571
526
  retrievalParams: sqliteCore.blob("retrieval_params", { mode: "json" }).$type(),
572
- createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
573
- updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
527
+ ...timestamps
574
528
  },
575
529
  (t) => [
576
530
  sqliteCore.primaryKey({ columns: [t.tenantId, t.projectId, t.id] }),
@@ -581,18 +535,6 @@ var credentialReferences = sqliteCore.sqliteTable(
581
535
  }).onDelete("cascade")
582
536
  ]
583
537
  );
584
- var ledgerArtifactsTaskIdIdx = sqliteCore.index("ledger_artifacts_task_id_idx").on(
585
- ledgerArtifacts.taskId
586
- );
587
- var ledgerArtifactsToolCallIdIdx = sqliteCore.index("ledger_artifacts_tool_call_id_idx").on(
588
- ledgerArtifacts.toolCallId
589
- );
590
- var ledgerArtifactsContextIdIdx = sqliteCore.index("ledger_artifacts_context_id_idx").on(
591
- ledgerArtifacts.contextId
592
- );
593
- var ledgerArtifactsTaskContextNameUnique = sqliteCore.unique(
594
- "ledger_artifacts_task_context_name_unique"
595
- ).on(ledgerArtifacts.taskId, ledgerArtifacts.contextId, ledgerArtifacts.name);
596
538
  var tasksRelations = drizzleOrm.relations(tasks, ({ one, many }) => ({
597
539
  // A task belongs to one project
598
540
  project: one(projects, {
@@ -618,37 +560,24 @@ var tasksRelations = drizzleOrm.relations(tasks, ({ one, many }) => ({
618
560
  ledgerArtifacts: many(ledgerArtifacts)
619
561
  }));
620
562
  var projectsRelations = drizzleOrm.relations(projects, ({ many }) => ({
621
- // A project can have many agents
622
563
  agents: many(agents),
623
- // A project can have many agent graphs
624
564
  agentGraphs: many(agentGraph),
625
- // A project can have many tools
626
565
  tools: many(tools),
627
- // A project can have many context configs
628
566
  contextConfigs: many(contextConfigs),
629
- // A project can have many external agents
630
567
  externalAgents: many(externalAgents),
631
- // A project can have many conversations
632
568
  conversations: many(conversations),
633
- // A project can have many tasks
634
569
  tasks: many(tasks),
635
- // A project can have many data components
636
570
  dataComponents: many(dataComponents),
637
- // A project can have many artifact components
638
571
  artifactComponents: many(artifactComponents),
639
- // A project can have many ledger artifacts
640
572
  ledgerArtifacts: many(ledgerArtifacts),
641
- // A project can have many credential references
642
573
  credentialReferences: many(credentialReferences)
643
574
  }));
644
575
  var taskRelationsRelations = drizzleOrm.relations(taskRelations, ({ one }) => ({
645
- // Each relation has one parent task
646
576
  parentTask: one(tasks, {
647
577
  fields: [taskRelations.parentTaskId],
648
578
  references: [tasks.id],
649
579
  relationName: "parentTask"
650
580
  }),
651
- // Each relation has one child task
652
581
  childTask: one(tasks, {
653
582
  fields: [taskRelations.childTaskId],
654
583
  references: [tasks.id],
@@ -656,107 +585,85 @@ var taskRelationsRelations = drizzleOrm.relations(taskRelations, ({ one }) => ({
656
585
  })
657
586
  }));
658
587
  var contextConfigsRelations = drizzleOrm.relations(contextConfigs, ({ many, one }) => ({
659
- // A context config belongs to one project
660
588
  project: one(projects, {
661
589
  fields: [contextConfigs.tenantId, contextConfigs.projectId],
662
590
  references: [projects.tenantId, projects.id]
663
591
  }),
664
- // A context config can be used by many agent graphs
665
592
  graphs: many(agentGraph),
666
- // A context config can have many cached entries
667
593
  cache: many(contextCache)
668
594
  }));
669
595
  var contextCacheRelations = drizzleOrm.relations(contextCache, ({ one }) => ({
670
- // Each cache entry belongs to one context config
671
596
  contextConfig: one(contextConfigs, {
672
597
  fields: [contextCache.contextConfigId],
673
598
  references: [contextConfigs.id]
674
599
  })
675
600
  }));
676
601
  var agentsRelations = drizzleOrm.relations(agents, ({ many, one }) => ({
677
- // A context config belongs to one project
678
602
  project: one(projects, {
679
603
  fields: [agents.tenantId, agents.projectId],
680
604
  references: [projects.tenantId, projects.id]
681
605
  }),
682
- // An agent can have many tasks
683
606
  tasks: many(tasks),
684
- // An agent can be the default agent for many graphs
685
607
  defaultForGraphs: many(agentGraph),
686
- // Agent relation tracking
687
608
  sourceRelations: many(agentRelations, {
688
609
  relationName: "sourceRelations"
689
610
  }),
690
611
  targetRelations: many(agentRelations, {
691
612
  relationName: "targetRelations"
692
613
  }),
693
- // Message tracking relations
694
614
  sentMessages: many(messages, {
695
615
  relationName: "sentMessages"
696
616
  }),
697
617
  receivedMessages: many(messages, {
698
618
  relationName: "receivedMessages"
699
619
  }),
700
- // Legacy message association (consider deprecating)
701
620
  associatedMessages: many(messages, {
702
621
  relationName: "associatedAgent"
703
622
  }),
704
623
  toolRelations: many(agentToolRelations),
705
- // Data component relations
706
624
  dataComponentRelations: many(agentDataComponents),
707
- // Artifact component relations
708
625
  artifactComponentRelations: many(agentArtifactComponents)
709
626
  }));
710
627
  var agentGraphRelations = drizzleOrm.relations(agentGraph, ({ one }) => ({
711
- // An agent graph belongs to one project
712
628
  project: one(projects, {
713
629
  fields: [agentGraph.tenantId, agentGraph.projectId],
714
630
  references: [projects.tenantId, projects.id]
715
631
  }),
716
- // An agent graph may have one default agent (optional)
717
632
  defaultAgent: one(agents, {
718
633
  fields: [agentGraph.defaultAgentId],
719
634
  references: [agents.id]
720
635
  }),
721
- // An agent graph can reference one context config
722
636
  contextConfig: one(contextConfigs, {
723
637
  fields: [agentGraph.contextConfigId],
724
638
  references: [contextConfigs.id]
725
639
  })
726
640
  }));
727
641
  var externalAgentsRelations = drizzleOrm.relations(externalAgents, ({ one, many }) => ({
728
- // An external agent belongs to one project
729
642
  project: one(projects, {
730
643
  fields: [externalAgents.tenantId, externalAgents.projectId],
731
644
  references: [projects.tenantId, projects.id]
732
645
  }),
733
- // An external agent can be referenced by many agent relations
734
646
  agentRelations: many(agentRelations),
735
- // An external agent may have one credential reference
736
647
  credentialReference: one(credentialReferences, {
737
648
  fields: [externalAgents.credentialReferenceId],
738
649
  references: [credentialReferences.id]
739
650
  })
740
651
  }));
741
652
  var apiKeysRelations = drizzleOrm.relations(apiKeys, ({ one }) => ({
742
- // An API key belongs to one project
743
653
  project: one(projects, {
744
654
  fields: [apiKeys.tenantId, apiKeys.projectId],
745
655
  references: [projects.tenantId, projects.id]
746
656
  }),
747
- // An API key belongs to one tenant and graph
748
657
  graph: one(agentGraph, {
749
658
  fields: [apiKeys.graphId],
750
659
  references: [agentGraph.id]
751
660
  })
752
661
  }));
753
662
  var agentToolRelationsRelations = drizzleOrm.relations(agentToolRelations, ({ one }) => ({
754
- // An agent-tool relation belongs to one agent
755
663
  agent: one(agents, {
756
664
  fields: [agentToolRelations.agentId],
757
665
  references: [agents.id]
758
666
  }),
759
- // An agent-tool relation belongs to one tool
760
667
  tool: one(tools, {
761
668
  fields: [agentToolRelations.toolId],
762
669
  references: [tools.id]
@@ -766,35 +673,28 @@ var credentialReferencesRelations = drizzleOrm.relations(credentialReferences, (
766
673
  tools: many(tools)
767
674
  }));
768
675
  var toolsRelations = drizzleOrm.relations(tools, ({ one, many }) => ({
769
- // A tool belongs to one project
770
676
  project: one(projects, {
771
677
  fields: [tools.tenantId, tools.projectId],
772
678
  references: [projects.tenantId, projects.id]
773
679
  }),
774
- // A tool can be used by many agents through agent-tool relations
775
680
  agentRelations: many(agentToolRelations),
776
- // A tool may have one credential reference
777
681
  credentialReference: one(credentialReferences, {
778
682
  fields: [tools.credentialReferenceId],
779
683
  references: [credentialReferences.id]
780
684
  })
781
685
  }));
782
686
  var conversationsRelations = drizzleOrm.relations(conversations, ({ one, many }) => ({
783
- // A conversation belongs to one project
784
687
  project: one(projects, {
785
688
  fields: [conversations.tenantId, conversations.projectId],
786
689
  references: [projects.tenantId, projects.id]
787
690
  }),
788
- // A conversation has many messages
789
691
  messages: many(messages),
790
- // A conversation has one active agent
791
692
  activeAgent: one(agents, {
792
693
  fields: [conversations.activeAgentId],
793
694
  references: [agents.id]
794
695
  })
795
696
  }));
796
697
  var messagesRelations = drizzleOrm.relations(messages, ({ one, many }) => ({
797
- // A message belongs to one conversation
798
698
  conversation: one(conversations, {
799
699
  fields: [messages.conversationId],
800
700
  references: [conversations.id]
@@ -805,114 +705,94 @@ var messagesRelations = drizzleOrm.relations(messages, ({ one, many }) => ({
805
705
  references: [agents.id],
806
706
  relationName: "associatedAgent"
807
707
  }),
808
- // Sender tracking relations
809
708
  fromAgent: one(agents, {
810
709
  fields: [messages.fromAgentId],
811
710
  references: [agents.id],
812
711
  relationName: "sentMessages"
813
712
  }),
814
- // Recipient tracking relations
815
713
  toAgent: one(agents, {
816
714
  fields: [messages.toAgentId],
817
715
  references: [agents.id],
818
716
  relationName: "receivedMessages"
819
717
  }),
820
- // External agent sender tracking relations
821
718
  fromExternalAgent: one(externalAgents, {
822
719
  fields: [messages.fromExternalAgentId],
823
720
  references: [externalAgents.id],
824
721
  relationName: "receivedExternalMessages"
825
722
  }),
826
- // External agent recipient tracking relations
827
723
  toExternalAgent: one(externalAgents, {
828
724
  fields: [messages.toExternalAgentId],
829
725
  references: [externalAgents.id],
830
726
  relationName: "sentExternalMessages"
831
727
  }),
832
- // A message may be associated with a task
833
728
  task: one(tasks, {
834
729
  fields: [messages.taskId],
835
730
  references: [tasks.id]
836
731
  }),
837
- // A message may have a parent message (for threading)
838
732
  parentMessage: one(messages, {
839
733
  fields: [messages.parentMessageId],
840
734
  references: [messages.id],
841
735
  relationName: "parentChild"
842
736
  }),
843
- // A message may have child messages
844
737
  childMessages: many(messages, {
845
738
  relationName: "parentChild"
846
739
  })
847
740
  }));
848
741
  var artifactComponentsRelations = drizzleOrm.relations(artifactComponents, ({ many }) => ({
849
- // An artifact component can be associated with many agents
850
742
  agentRelations: many(agentArtifactComponents)
851
743
  }));
852
744
  var agentArtifactComponentsRelations = drizzleOrm.relations(agentArtifactComponents, ({ one }) => ({
853
- // An agent-artifact component relation belongs to one agent
854
745
  agent: one(agents, {
855
746
  fields: [agentArtifactComponents.agentId],
856
747
  references: [agents.id]
857
748
  }),
858
- // An agent-artifact component relation belongs to one artifact component
859
749
  artifactComponent: one(artifactComponents, {
860
750
  fields: [agentArtifactComponents.artifactComponentId],
861
751
  references: [artifactComponents.id]
862
752
  })
863
753
  }));
864
754
  var dataComponentsRelations = drizzleOrm.relations(dataComponents, ({ many, one }) => ({
865
- // A data component belongs to one project
866
755
  project: one(projects, {
867
756
  fields: [dataComponents.tenantId, dataComponents.projectId],
868
757
  references: [projects.tenantId, projects.id]
869
758
  }),
870
- // A data component can be associated with many agents
871
759
  agentRelations: many(agentDataComponents)
872
760
  }));
873
761
  var agentDataComponentsRelations = drizzleOrm.relations(agentDataComponents, ({ one }) => ({
874
- // An agent-data component relation belongs to one agent
875
762
  agent: one(agents, {
876
763
  fields: [agentDataComponents.agentId],
877
764
  references: [agents.id]
878
765
  }),
879
- // An agent-data component relation belongs to one data component
880
766
  dataComponent: one(dataComponents, {
881
767
  fields: [agentDataComponents.dataComponentId],
882
768
  references: [dataComponents.id]
883
769
  })
884
770
  }));
885
771
  var ledgerArtifactsRelations = drizzleOrm.relations(ledgerArtifacts, ({ one }) => ({
886
- // A ledger artifact belongs to one project
887
772
  project: one(projects, {
888
773
  fields: [ledgerArtifacts.tenantId, ledgerArtifacts.projectId],
889
774
  references: [projects.tenantId, projects.id]
890
775
  }),
891
- // A ledger artifact may be associated with one task
892
776
  task: one(tasks, {
893
777
  fields: [ledgerArtifacts.taskId],
894
778
  references: [tasks.id]
895
779
  })
896
780
  }));
897
781
  var agentRelationsRelations = drizzleOrm.relations(agentRelations, ({ one }) => ({
898
- // An agent relation belongs to one graph
899
782
  graph: one(agentGraph, {
900
783
  fields: [agentRelations.graphId],
901
784
  references: [agentGraph.id]
902
785
  }),
903
- // An agent relation has one source agent
904
786
  sourceAgent: one(agents, {
905
787
  fields: [agentRelations.sourceAgentId],
906
788
  references: [agents.id],
907
789
  relationName: "sourceRelations"
908
790
  }),
909
- // An agent relation may have one target agent (for internal relations)
910
791
  targetAgent: one(agents, {
911
792
  fields: [agentRelations.targetAgentId],
912
793
  references: [agents.id],
913
794
  relationName: "targetRelations"
914
795
  }),
915
- // An agent relation may have one external agent (for external relations)
916
796
  externalAgent: one(externalAgents, {
917
797
  fields: [agentRelations.externalAgentId],
918
798
  references: [externalAgents.id]
@@ -948,11 +828,7 @@ exports.dataComponentsRelations = dataComponentsRelations;
948
828
  exports.externalAgents = externalAgents;
949
829
  exports.externalAgentsRelations = externalAgentsRelations;
950
830
  exports.ledgerArtifacts = ledgerArtifacts;
951
- exports.ledgerArtifactsContextIdIdx = ledgerArtifactsContextIdIdx;
952
831
  exports.ledgerArtifactsRelations = ledgerArtifactsRelations;
953
- exports.ledgerArtifactsTaskContextNameUnique = ledgerArtifactsTaskContextNameUnique;
954
- exports.ledgerArtifactsTaskIdIdx = ledgerArtifactsTaskIdIdx;
955
- exports.ledgerArtifactsToolCallIdIdx = ledgerArtifactsToolCallIdIdx;
956
832
  exports.messages = messages;
957
833
  exports.messagesRelations = messagesRelations;
958
834
  exports.projects = projects;