@inkeep/agents-core 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -169,7 +169,7 @@ var projects = sqliteCore.sqliteTable(
169
169
  // This IS the project ID
170
170
  name: sqliteCore.text("name").notNull(),
171
171
  description: sqliteCore.text("description").notNull(),
172
- // Project-level default model settingsuration that can be inherited by graphs and agents
172
+ // Project-level default model settings that can be inherited by graphs and agents
173
173
  models: sqliteCore.text("models", { mode: "json" }).$type(),
174
174
  // Project-level stopWhen configuration that can be inherited by graphs and agents
175
175
  stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
@@ -194,7 +194,14 @@ var contextConfigs = sqliteCore.sqliteTable(
194
194
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
195
195
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
196
196
  },
197
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
197
+ (table) => [
198
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
199
+ sqliteCore.foreignKey({
200
+ columns: [table.tenantId, table.projectId],
201
+ foreignColumns: [projects.tenantId, projects.id],
202
+ name: "context_configs_project_fk"
203
+ }).onDelete("cascade")
204
+ ]
198
205
  );
199
206
  var contextCache = sqliteCore.sqliteTable(
200
207
  "context_cache",
@@ -223,6 +230,11 @@ var contextCache = sqliteCore.sqliteTable(
223
230
  },
224
231
  (table) => [
225
232
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
233
+ sqliteCore.foreignKey({
234
+ columns: [table.tenantId, table.projectId],
235
+ foreignColumns: [projects.tenantId, projects.id],
236
+ name: "context_cache_project_fk"
237
+ }).onDelete("cascade"),
226
238
  sqliteCore.index("context_cache_lookup_idx").on(
227
239
  table.conversationId,
228
240
  table.contextConfigId,
@@ -254,7 +266,7 @@ var agents = sqliteCore.sqliteTable(
254
266
  columns: [table.tenantId, table.projectId],
255
267
  foreignColumns: [projects.tenantId, projects.id],
256
268
  name: "agents_project_fk"
257
- })
269
+ }).onDelete("cascade")
258
270
  ]
259
271
  );
260
272
  var agentRelations = sqliteCore.sqliteTable(
@@ -280,7 +292,7 @@ var agentRelations = sqliteCore.sqliteTable(
280
292
  columns: [table.tenantId, table.projectId],
281
293
  foreignColumns: [projects.tenantId, projects.id],
282
294
  name: "agent_relations_project_fk"
283
- })
295
+ }).onDelete("cascade")
284
296
  ]
285
297
  );
286
298
  var externalAgents = sqliteCore.sqliteTable(
@@ -300,6 +312,11 @@ var externalAgents = sqliteCore.sqliteTable(
300
312
  },
301
313
  (table) => [
302
314
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
315
+ sqliteCore.foreignKey({
316
+ columns: [table.tenantId, table.projectId],
317
+ foreignColumns: [projects.tenantId, projects.id],
318
+ name: "external_agents_project_fk"
319
+ }).onDelete("cascade"),
303
320
  sqliteCore.foreignKey({
304
321
  columns: [table.tenantId, table.projectId, table.credentialReferenceId],
305
322
  foreignColumns: [
@@ -339,7 +356,7 @@ var agentGraph = sqliteCore.sqliteTable(
339
356
  columns: [table.tenantId, table.projectId],
340
357
  foreignColumns: [projects.tenantId, projects.id],
341
358
  name: "agent_graph_project_fk"
342
- })
359
+ }).onDelete("cascade")
343
360
  ]
344
361
  );
345
362
  var tasks = sqliteCore.sqliteTable(
@@ -355,7 +372,14 @@ var tasks = sqliteCore.sqliteTable(
355
372
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
356
373
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
357
374
  },
358
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
375
+ (table) => [
376
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
377
+ sqliteCore.foreignKey({
378
+ columns: [table.tenantId, table.projectId],
379
+ foreignColumns: [projects.tenantId, projects.id],
380
+ name: "tasks_project_fk"
381
+ }).onDelete("cascade")
382
+ ]
359
383
  );
360
384
  var taskRelations = sqliteCore.sqliteTable(
361
385
  "task_relations",
@@ -370,7 +394,14 @@ var taskRelations = sqliteCore.sqliteTable(
370
394
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
371
395
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
372
396
  },
373
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
397
+ (table) => [
398
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
399
+ sqliteCore.foreignKey({
400
+ columns: [table.tenantId, table.projectId],
401
+ foreignColumns: [projects.tenantId, projects.id],
402
+ name: "task_relations_project_fk"
403
+ }).onDelete("cascade")
404
+ ]
374
405
  );
375
406
  var dataComponents = sqliteCore.sqliteTable(
376
407
  "data_components",
@@ -384,7 +415,14 @@ var dataComponents = sqliteCore.sqliteTable(
384
415
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
385
416
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
386
417
  },
387
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
418
+ (table) => [
419
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
420
+ sqliteCore.foreignKey({
421
+ columns: [table.tenantId, table.projectId],
422
+ foreignColumns: [projects.tenantId, projects.id],
423
+ name: "data_components_project_fk"
424
+ }).onDelete("cascade")
425
+ ]
388
426
  );
389
427
  var agentDataComponents = sqliteCore.sqliteTable(
390
428
  "agent_data_components",
@@ -398,6 +436,12 @@ var agentDataComponents = sqliteCore.sqliteTable(
398
436
  },
399
437
  (table) => [
400
438
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
439
+ // Foreign key constraint to projects table
440
+ sqliteCore.foreignKey({
441
+ columns: [table.tenantId, table.projectId],
442
+ foreignColumns: [projects.tenantId, projects.id],
443
+ name: "agent_data_components_project_fk"
444
+ }).onDelete("cascade"),
401
445
  // Foreign key constraint to agents table
402
446
  sqliteCore.foreignKey({
403
447
  columns: [table.tenantId, table.projectId, table.agentId],
@@ -425,7 +469,14 @@ var artifactComponents = sqliteCore.sqliteTable(
425
469
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
426
470
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
427
471
  },
428
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
472
+ (table) => [
473
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
474
+ sqliteCore.foreignKey({
475
+ columns: [table.tenantId, table.projectId],
476
+ foreignColumns: [projects.tenantId, projects.id],
477
+ name: "artifact_components_project_fk"
478
+ }).onDelete("cascade")
479
+ ]
429
480
  );
430
481
  var agentArtifactComponents = sqliteCore.sqliteTable(
431
482
  "agent_artifact_components",
@@ -439,6 +490,12 @@ var agentArtifactComponents = sqliteCore.sqliteTable(
439
490
  },
440
491
  (table) => [
441
492
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
493
+ // Foreign key constraint to projects table
494
+ sqliteCore.foreignKey({
495
+ columns: [table.tenantId, table.projectId],
496
+ foreignColumns: [projects.tenantId, projects.id],
497
+ name: "agent_artifact_components_project_fk"
498
+ }).onDelete("cascade"),
442
499
  // Foreign key constraint to agents table
443
500
  sqliteCore.foreignKey({
444
501
  columns: [table.tenantId, table.projectId, table.agentId],
@@ -482,7 +539,14 @@ var tools = sqliteCore.sqliteTable(
482
539
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
483
540
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
484
541
  },
485
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
542
+ (table) => [
543
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
544
+ sqliteCore.foreignKey({
545
+ columns: [table.tenantId, table.projectId],
546
+ foreignColumns: [projects.tenantId, projects.id],
547
+ name: "tools_project_fk"
548
+ }).onDelete("cascade")
549
+ ]
486
550
  );
487
551
  var agentToolRelations = sqliteCore.sqliteTable(
488
552
  "agent_tool_relations",
@@ -498,6 +562,12 @@ var agentToolRelations = sqliteCore.sqliteTable(
498
562
  },
499
563
  (table) => [
500
564
  sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
565
+ // Foreign key constraint to projects table
566
+ sqliteCore.foreignKey({
567
+ columns: [table.tenantId, table.projectId],
568
+ foreignColumns: [projects.tenantId, projects.id],
569
+ name: "agent_tool_relations_project_fk"
570
+ }).onDelete("cascade"),
501
571
  // Foreign key constraint to agents table
502
572
  sqliteCore.foreignKey({
503
573
  columns: [table.tenantId, table.projectId, table.agentId],
@@ -526,7 +596,14 @@ var conversations = sqliteCore.sqliteTable(
526
596
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
527
597
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
528
598
  },
529
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
599
+ (table) => [
600
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
601
+ sqliteCore.foreignKey({
602
+ columns: [table.tenantId, table.projectId],
603
+ foreignColumns: [projects.tenantId, projects.id],
604
+ name: "conversations_project_fk"
605
+ }).onDelete("cascade")
606
+ ]
530
607
  );
531
608
  var messages = sqliteCore.sqliteTable(
532
609
  "messages",
@@ -571,7 +648,14 @@ var messages = sqliteCore.sqliteTable(
571
648
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
572
649
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
573
650
  },
574
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
651
+ (table) => [
652
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
653
+ sqliteCore.foreignKey({
654
+ columns: [table.tenantId, table.projectId],
655
+ foreignColumns: [projects.tenantId, projects.id],
656
+ name: "messages_project_fk"
657
+ }).onDelete("cascade")
658
+ ]
575
659
  );
576
660
  var ledgerArtifacts = sqliteCore.sqliteTable(
577
661
  "ledger_artifacts",
@@ -599,7 +683,14 @@ var ledgerArtifacts = sqliteCore.sqliteTable(
599
683
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
600
684
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
601
685
  },
602
- (table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]
686
+ (table) => [
687
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
688
+ sqliteCore.foreignKey({
689
+ columns: [table.tenantId, table.projectId],
690
+ foreignColumns: [projects.tenantId, projects.id],
691
+ name: "ledger_artifacts_project_fk"
692
+ }).onDelete("cascade")
693
+ ]
603
694
  );
604
695
  var apiKeys = sqliteCore.sqliteTable(
605
696
  "api_keys",
@@ -620,6 +711,11 @@ var apiKeys = sqliteCore.sqliteTable(
620
711
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
621
712
  },
622
713
  (t) => [
714
+ sqliteCore.foreignKey({
715
+ columns: [t.tenantId, t.projectId],
716
+ foreignColumns: [projects.tenantId, projects.id],
717
+ name: "api_keys_project_fk"
718
+ }).onDelete("cascade"),
623
719
  sqliteCore.foreignKey({
624
720
  columns: [t.tenantId, t.projectId, t.graphId],
625
721
  foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
@@ -644,7 +740,14 @@ var credentialReferences = sqliteCore.sqliteTable(
644
740
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
645
741
  updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
646
742
  },
647
- (t) => [sqliteCore.primaryKey({ columns: [t.tenantId, t.projectId, t.id] })]
743
+ (t) => [
744
+ sqliteCore.primaryKey({ columns: [t.tenantId, t.projectId, t.id] }),
745
+ sqliteCore.foreignKey({
746
+ columns: [t.tenantId, t.projectId],
747
+ foreignColumns: [projects.tenantId, projects.id],
748
+ name: "credential_references_project_fk"
749
+ }).onDelete("cascade")
750
+ ]
648
751
  );
649
752
  var ledgerArtifactsTaskIdIdx = sqliteCore.index("ledger_artifacts_task_id_idx").on(
650
753
  ledgerArtifacts.taskId
@@ -958,6 +1061,12 @@ var CredentialStoreType = {
958
1061
  };
959
1062
 
960
1063
  // src/validation/schemas.ts
1064
+ var StopWhenSchema = zodOpenapi.z.object({
1065
+ transferCountIs: zodOpenapi.z.number().min(1).max(100).optional(),
1066
+ stepCountIs: zodOpenapi.z.number().min(1).max(1e3).optional()
1067
+ });
1068
+ var GraphStopWhenSchema = StopWhenSchema.pick({ transferCountIs: true });
1069
+ var AgentStopWhenSchema = StopWhenSchema.pick({ stepCountIs: true });
961
1070
  var MIN_ID_LENGTH = 1;
962
1071
  var MAX_ID_LENGTH = 255;
963
1072
  var URL_SAFE_ID_PATTERN = /^[a-zA-Z0-9\-_.]+$/;
@@ -1401,16 +1510,20 @@ var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
1401
1510
  });
1402
1511
  var FullGraphDefinitionSchema = AgentGraphApiInsertSchema.extend({
1403
1512
  agents: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.union([FullGraphAgentInsertSchema, ExternalAgentApiInsertSchema])),
1404
- tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema),
1513
+ tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema).optional(),
1405
1514
  credentialReferences: zodOpenapi.z.array(CredentialReferenceApiInsertSchema).optional(),
1406
1515
  dataComponents: zodOpenapi.z.record(zodOpenapi.z.string(), DataComponentApiInsertSchema).optional(),
1407
1516
  artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
1408
1517
  contextConfig: zodOpenapi.z.optional(ContextConfigApiInsertSchema),
1409
1518
  statusUpdates: zodOpenapi.z.optional(StatusUpdateSchema),
1410
1519
  models: ModelSchema.optional(),
1411
- stopWhen: zodOpenapi.z.object({
1412
- transferCountIs: zodOpenapi.z.number().min(1).max(100).optional()
1413
- }).optional(),
1520
+ stopWhen: GraphStopWhenSchema.optional(),
1521
+ graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
1522
+ });
1523
+ var GraphWithinContextOfProjectSchema = AgentGraphApiInsertSchema.extend({
1524
+ agents: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.union([FullGraphAgentInsertSchema, ExternalAgentApiInsertSchema])),
1525
+ models: ModelSchema.optional(),
1526
+ stopWhen: GraphStopWhenSchema.optional(),
1414
1527
  graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
1415
1528
  });
1416
1529
  var PaginationSchema = zodOpenapi.z.object({
@@ -1440,7 +1553,8 @@ var RemovedResponseSchema = zodOpenapi.z.object({
1440
1553
  });
1441
1554
  var ProjectSelectSchema = drizzleZod.createSelectSchema(projects);
1442
1555
  var ProjectInsertSchema = drizzleZod.createInsertSchema(projects).extend({
1443
- models: ProjectModelSchema.optional()
1556
+ models: ProjectModelSchema.optional(),
1557
+ stopWhen: StopWhenSchema.optional()
1444
1558
  }).omit({
1445
1559
  createdAt: true,
1446
1560
  updatedAt: true
@@ -1449,6 +1563,17 @@ var ProjectUpdateSchema = ProjectInsertSchema.partial();
1449
1563
  var ProjectApiSelectSchema = ProjectSelectSchema.omit({ tenantId: true });
1450
1564
  var ProjectApiInsertSchema = ProjectInsertSchema.omit({ tenantId: true });
1451
1565
  var ProjectApiUpdateSchema = ProjectUpdateSchema.omit({ tenantId: true });
1566
+ var FullProjectDefinitionSchema = ProjectApiInsertSchema.extend({
1567
+ graphs: zodOpenapi.z.record(zodOpenapi.z.string(), GraphWithinContextOfProjectSchema),
1568
+ tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema),
1569
+ dataComponents: zodOpenapi.z.record(zodOpenapi.z.string(), DataComponentApiInsertSchema).optional(),
1570
+ artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
1571
+ contextConfig: zodOpenapi.z.record(zodOpenapi.z.string(), ContextConfigApiInsertSchema).optional(),
1572
+ statusUpdates: zodOpenapi.z.optional(StatusUpdateSchema),
1573
+ credentialReferences: zodOpenapi.z.array(CredentialReferenceApiInsertSchema).optional(),
1574
+ createdAt: zodOpenapi.z.string().optional(),
1575
+ updatedAt: zodOpenapi.z.string().optional()
1576
+ });
1452
1577
  var HeadersScopeSchema = zodOpenapi.z.object({
1453
1578
  "x-inkeep-tenant-id": zodOpenapi.z.string().optional().openapi({
1454
1579
  description: "Tenant identifier",
@@ -4754,7 +4879,7 @@ function validateAndTypeGraphData(data) {
4754
4879
  }
4755
4880
  function validateToolReferences(graphData) {
4756
4881
  const errors = [];
4757
- const availableToolIds = new Set(Object.keys(graphData.tools));
4882
+ const availableToolIds = new Set(Object.keys(graphData.tools || {}));
4758
4883
  for (const [agentId, agentData] of Object.entries(graphData.agents)) {
4759
4884
  if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
4760
4885
  for (const toolId of agentData.tools) {
@@ -5173,7 +5298,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5173
5298
  "All credential references created/updated successfully"
5174
5299
  );
5175
5300
  }
5176
- const toolPromises = Object.entries(typed.tools).map(async ([toolId, toolData]) => {
5301
+ const toolPromises = Object.entries(typed.tools || {}).map(async ([toolId, toolData]) => {
5177
5302
  try {
5178
5303
  logger11.info({ toolId }, "Processing tool");
5179
5304
  await upsertTool(db)({
@@ -5191,7 +5316,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5191
5316
  });
5192
5317
  await Promise.all(toolPromises);
5193
5318
  logger11.info(
5194
- { toolCount: Object.keys(typed.tools).length },
5319
+ { toolCount: Object.keys(typed.tools || {}).length },
5195
5320
  "All tools created/updated successfully"
5196
5321
  );
5197
5322
  let contextConfigId;
@@ -5550,7 +5675,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5550
5675
  tenantId,
5551
5676
  graphId: typedGraphDefinition.id,
5552
5677
  agentCount: Object.keys(typedGraphDefinition.agents).length,
5553
- toolCount: Object.keys(typedGraphDefinition.tools).length
5678
+ toolCount: Object.keys(typedGraphDefinition.tools || {}).length
5554
5679
  },
5555
5680
  "Updating full graph in database"
5556
5681
  );
@@ -5606,7 +5731,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5606
5731
  "All credential references created/updated successfully"
5607
5732
  );
5608
5733
  }
5609
- const toolPromises = Object.entries(typedGraphDefinition.tools).map(
5734
+ const toolPromises = Object.entries(typedGraphDefinition.tools || {}).map(
5610
5735
  async ([toolId, toolData]) => {
5611
5736
  try {
5612
5737
  logger11.info({ toolId }, "Processing tool");
@@ -5626,7 +5751,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5626
5751
  );
5627
5752
  await Promise.all(toolPromises);
5628
5753
  logger11.info(
5629
- { toolCount: Object.keys(typedGraphDefinition.tools).length },
5754
+ { toolCount: Object.keys(typedGraphDefinition.tools || {}).length },
5630
5755
  "All tools created/updated successfully"
5631
5756
  );
5632
5757
  let contextConfigId;
@@ -6456,10 +6581,6 @@ var deleteProject = (db) => async (params) => {
6456
6581
  if (!projectExistsInTableResult) {
6457
6582
  return false;
6458
6583
  }
6459
- const hasResources = await projectExists(db)(params.scopes);
6460
- if (hasResources) {
6461
- throw new Error("Cannot delete project with existing resources");
6462
- }
6463
6584
  await db.delete(projects).where(
6464
6585
  drizzleOrm.and(drizzleOrm.eq(projects.tenantId, params.scopes.tenantId), drizzleOrm.eq(projects.id, params.scopes.projectId))
6465
6586
  );
@@ -6516,6 +6637,353 @@ async function cascadeStopWhenUpdates(db, scopes, oldStopWhen, newStopWhen) {
6516
6637
  }
6517
6638
  }
6518
6639
  }
6640
+
6641
+ // src/data-access/projectFull.ts
6642
+ var defaultLogger2 = getLogger("projectFull");
6643
+ function validateAndTypeProjectData(projectData) {
6644
+ return projectData;
6645
+ }
6646
+ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scopes, projectData) => {
6647
+ const { tenantId } = scopes;
6648
+ const typed = validateAndTypeProjectData(projectData);
6649
+ logger11.info(
6650
+ {
6651
+ tenantId,
6652
+ projectId: typed.id,
6653
+ graphCount: Object.keys(typed.graphs || {}).length
6654
+ },
6655
+ "Creating full project in database"
6656
+ );
6657
+ try {
6658
+ const projectPayload = {
6659
+ id: typed.id,
6660
+ name: typed.name,
6661
+ description: typed.description || "",
6662
+ models: typed.models,
6663
+ stopWhen: typed.stopWhen,
6664
+ tenantId,
6665
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
6666
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
6667
+ };
6668
+ logger11.info({ projectId: typed.id }, "Creating project metadata");
6669
+ await createProject(db)(projectPayload);
6670
+ logger11.info({ projectId: typed.id }, "Project metadata created successfully");
6671
+ if (typed.graphs && Object.keys(typed.graphs).length > 0) {
6672
+ logger11.info(
6673
+ {
6674
+ projectId: typed.id,
6675
+ graphCount: Object.keys(typed.graphs).length
6676
+ },
6677
+ "Creating project graphs"
6678
+ );
6679
+ const graphPromises = Object.entries(typed.graphs).map(async ([graphId, graphData]) => {
6680
+ try {
6681
+ logger11.info({ projectId: typed.id, graphId }, "Creating graph in project");
6682
+ const graphDataWithUndefined = {
6683
+ ...graphData,
6684
+ statusUpdates: graphData.statusUpdates === null ? void 0 : graphData.statusUpdates
6685
+ };
6686
+ await createFullGraphServerSide(db, logger11)(
6687
+ { tenantId, projectId: typed.id },
6688
+ graphDataWithUndefined
6689
+ );
6690
+ logger11.info({ projectId: typed.id, graphId }, "Graph created successfully in project");
6691
+ } catch (error) {
6692
+ logger11.error(
6693
+ { projectId: typed.id, graphId, error },
6694
+ "Failed to create graph in project"
6695
+ );
6696
+ throw error;
6697
+ }
6698
+ });
6699
+ await Promise.all(graphPromises);
6700
+ logger11.info(
6701
+ {
6702
+ projectId: typed.id,
6703
+ graphCount: Object.keys(typed.graphs).length
6704
+ },
6705
+ "All project graphs created successfully"
6706
+ );
6707
+ }
6708
+ logger11.info({ projectId: typed.id }, "Full project created successfully");
6709
+ return await getFullProject(
6710
+ db,
6711
+ logger11
6712
+ )({
6713
+ scopes: { tenantId, projectId: typed.id },
6714
+ projectId: typed.id
6715
+ });
6716
+ } catch (error) {
6717
+ logger11.error(
6718
+ {
6719
+ tenantId,
6720
+ projectId: typed.id,
6721
+ error
6722
+ },
6723
+ "Failed to create full project"
6724
+ );
6725
+ throw error;
6726
+ }
6727
+ };
6728
+ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scopes, projectData) => {
6729
+ const { tenantId } = scopes;
6730
+ const typed = validateAndTypeProjectData(projectData);
6731
+ if (!typed.id) {
6732
+ throw new Error("Project ID is required");
6733
+ }
6734
+ logger11.info(
6735
+ {
6736
+ tenantId,
6737
+ projectId: typed.id,
6738
+ graphCount: Object.keys(typed.graphs || {}).length
6739
+ },
6740
+ "Updating full project in database"
6741
+ );
6742
+ try {
6743
+ const existingProject = await getProject(db)({
6744
+ scopes: { tenantId, projectId: typed.id }
6745
+ });
6746
+ if (!existingProject) {
6747
+ logger11.info({ projectId: typed.id }, "Project not found, creating new project");
6748
+ return await createFullProjectServerSide(db, logger11)(
6749
+ { tenantId, projectId: typed.id },
6750
+ projectData
6751
+ );
6752
+ }
6753
+ const projectUpdatePayload = {
6754
+ name: typed.name,
6755
+ description: typed.description || "",
6756
+ models: typed.models,
6757
+ stopWhen: typed.stopWhen
6758
+ };
6759
+ logger11.info({ projectId: typed.id }, "Updating project metadata");
6760
+ await updateProject(db)({
6761
+ scopes: { tenantId, projectId: typed.id },
6762
+ data: projectUpdatePayload
6763
+ });
6764
+ logger11.info({ projectId: typed.id }, "Project metadata updated successfully");
6765
+ if (typed.graphs && Object.keys(typed.graphs).length > 0) {
6766
+ logger11.info(
6767
+ {
6768
+ projectId: typed.id,
6769
+ graphCount: Object.keys(typed.graphs).length
6770
+ },
6771
+ "Updating project graphs"
6772
+ );
6773
+ const graphPromises = Object.entries(typed.graphs).map(async ([graphId, graphData]) => {
6774
+ try {
6775
+ logger11.info({ projectId: typed.id, graphId }, "Updating graph in project");
6776
+ const graphDataWithUndefined = {
6777
+ ...graphData,
6778
+ statusUpdates: graphData.statusUpdates === null ? void 0 : graphData.statusUpdates
6779
+ };
6780
+ await updateFullGraphServerSide(db, logger11)(
6781
+ { tenantId, projectId: typed.id },
6782
+ graphDataWithUndefined
6783
+ );
6784
+ logger11.info({ projectId: typed.id, graphId }, "Graph updated successfully in project");
6785
+ } catch (error) {
6786
+ logger11.error(
6787
+ { projectId: typed.id, graphId, error },
6788
+ "Failed to update graph in project"
6789
+ );
6790
+ throw error;
6791
+ }
6792
+ });
6793
+ await Promise.all(graphPromises);
6794
+ logger11.info(
6795
+ {
6796
+ projectId: typed.id,
6797
+ graphCount: Object.keys(typed.graphs).length
6798
+ },
6799
+ "All project graphs updated successfully"
6800
+ );
6801
+ }
6802
+ logger11.info({ projectId: typed.id }, "Full project updated successfully");
6803
+ return await getFullProject(
6804
+ db,
6805
+ logger11
6806
+ )({
6807
+ scopes: { tenantId, projectId: typed.id },
6808
+ projectId: typed.id
6809
+ });
6810
+ } catch (error) {
6811
+ logger11.error(
6812
+ {
6813
+ tenantId,
6814
+ projectId: typed.id,
6815
+ error
6816
+ },
6817
+ "Failed to update full project"
6818
+ );
6819
+ throw error;
6820
+ }
6821
+ };
6822
+ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
6823
+ const { scopes, projectId } = params;
6824
+ const { tenantId } = scopes;
6825
+ logger11.info({ tenantId, projectId }, "Retrieving full project definition");
6826
+ try {
6827
+ const project = await getProject(db)({
6828
+ scopes: { tenantId, projectId }
6829
+ });
6830
+ if (!project) {
6831
+ logger11.info({ tenantId, projectId }, "Project not found");
6832
+ return null;
6833
+ }
6834
+ logger11.info({ tenantId, projectId }, "Project metadata retrieved");
6835
+ const graphList = await listAgentGraphs(db)({
6836
+ scopes: { tenantId, projectId }
6837
+ });
6838
+ logger11.info(
6839
+ {
6840
+ tenantId,
6841
+ projectId,
6842
+ graphCount: graphList.length
6843
+ },
6844
+ "Found graphs for project"
6845
+ );
6846
+ const graphs = {};
6847
+ if (graphList.length > 0) {
6848
+ const graphPromises = graphList.map(async (graph) => {
6849
+ try {
6850
+ logger11.info(
6851
+ { tenantId, projectId, graphId: graph.id },
6852
+ "Retrieving full graph definition"
6853
+ );
6854
+ const fullGraph = await getFullGraph(db)({
6855
+ scopes: { tenantId, projectId },
6856
+ graphId: graph.id
6857
+ });
6858
+ if (fullGraph) {
6859
+ graphs[graph.id] = fullGraph;
6860
+ logger11.info(
6861
+ { tenantId, projectId, graphId: graph.id },
6862
+ "Full graph definition retrieved"
6863
+ );
6864
+ } else {
6865
+ logger11.warn({ tenantId, projectId, graphId: graph.id }, "Graph definition not found");
6866
+ }
6867
+ } catch (error) {
6868
+ logger11.error(
6869
+ { tenantId, projectId, graphId: graph.id, error },
6870
+ "Failed to retrieve full graph definition"
6871
+ );
6872
+ }
6873
+ });
6874
+ await Promise.all(graphPromises);
6875
+ }
6876
+ const fullProjectDefinition = {
6877
+ id: project.id,
6878
+ name: project.name,
6879
+ description: project.description,
6880
+ models: project.models || void 0,
6881
+ stopWhen: project.stopWhen || void 0,
6882
+ graphs,
6883
+ tools: {},
6884
+ // TODO: Implement proper tools retrieval
6885
+ createdAt: project.createdAt,
6886
+ updatedAt: project.updatedAt
6887
+ };
6888
+ logger11.info(
6889
+ {
6890
+ tenantId,
6891
+ projectId,
6892
+ graphCount: Object.keys(fullProjectDefinition.graphs).length
6893
+ },
6894
+ "Full project definition retrieved"
6895
+ );
6896
+ return fullProjectDefinition;
6897
+ } catch (error) {
6898
+ logger11.error(
6899
+ {
6900
+ tenantId,
6901
+ projectId,
6902
+ error
6903
+ },
6904
+ "Failed to retrieve full project"
6905
+ );
6906
+ throw error;
6907
+ }
6908
+ };
6909
+ var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
6910
+ const { scopes, projectId } = params;
6911
+ const { tenantId } = scopes;
6912
+ logger11.info({ tenantId, projectId }, "Deleting full project and related entities");
6913
+ try {
6914
+ const project = await getFullProject(
6915
+ db,
6916
+ logger11
6917
+ )({
6918
+ scopes: { tenantId, projectId },
6919
+ projectId
6920
+ });
6921
+ if (!project) {
6922
+ logger11.info({ tenantId, projectId }, "Project not found for deletion");
6923
+ return false;
6924
+ }
6925
+ if (project.graphs && Object.keys(project.graphs).length > 0) {
6926
+ logger11.info(
6927
+ {
6928
+ tenantId,
6929
+ projectId,
6930
+ graphCount: Object.keys(project.graphs).length
6931
+ },
6932
+ "Deleting project graphs"
6933
+ );
6934
+ const graphPromises = Object.keys(project.graphs).map(async (graphId) => {
6935
+ try {
6936
+ logger11.info({ tenantId, projectId, graphId }, "Deleting graph from project");
6937
+ await deleteFullGraph(
6938
+ db,
6939
+ logger11
6940
+ )({
6941
+ scopes: { tenantId, projectId },
6942
+ graphId
6943
+ });
6944
+ logger11.info(
6945
+ { tenantId, projectId, graphId },
6946
+ "Graph deleted successfully from project"
6947
+ );
6948
+ } catch (error) {
6949
+ logger11.error(
6950
+ { tenantId, projectId, graphId, error },
6951
+ "Failed to delete graph from project"
6952
+ );
6953
+ throw error;
6954
+ }
6955
+ });
6956
+ await Promise.all(graphPromises);
6957
+ logger11.info(
6958
+ {
6959
+ tenantId,
6960
+ projectId,
6961
+ graphCount: Object.keys(project.graphs).length
6962
+ },
6963
+ "All project graphs deleted successfully"
6964
+ );
6965
+ }
6966
+ const deleted = await deleteProject(db)({
6967
+ scopes: { tenantId, projectId }
6968
+ });
6969
+ if (!deleted) {
6970
+ logger11.warn({ tenantId, projectId }, "Project deletion returned false");
6971
+ return false;
6972
+ }
6973
+ logger11.info({ tenantId, projectId }, "Full project deleted successfully");
6974
+ return true;
6975
+ } catch (error) {
6976
+ logger11.error(
6977
+ {
6978
+ tenantId,
6979
+ projectId,
6980
+ error
6981
+ },
6982
+ "Failed to delete full project"
6983
+ );
6984
+ throw error;
6985
+ }
6986
+ };
6519
6987
  var createTask = (db) => async (params) => {
6520
6988
  const now = (/* @__PURE__ */ new Date()).toISOString();
6521
6989
  const [created] = await db.insert(tasks).values({
@@ -6877,6 +7345,8 @@ function getTitleFromCode(code) {
6877
7345
  return "Forbidden";
6878
7346
  case "not_found":
6879
7347
  return "Not Found";
7348
+ case "conflict":
7349
+ return "Conflict";
6880
7350
  case "unprocessable_entity":
6881
7351
  return "Unprocessable Entity";
6882
7352
  case "internal_server_error":
@@ -7191,12 +7661,8 @@ function getTracer(serviceName, serviceVersion) {
7191
7661
  }
7192
7662
  }
7193
7663
 
7194
- // package.json
7195
- var package_default = {
7196
- version: "0.1.6"};
7197
-
7198
7664
  // src/utils/tracer.ts
7199
- var tracer = getTracer("agents-core", package_default.version);
7665
+ var tracer = getTracer("agents-core");
7200
7666
  var logger5 = getLogger("context-cache");
7201
7667
  var ContextCache = class {
7202
7668
  constructor(tenantId, projectId, dbClient) {
@@ -9208,6 +9674,7 @@ exports.AgentRelationQuerySchema = AgentRelationQuerySchema;
9208
9674
  exports.AgentRelationSelectSchema = AgentRelationSelectSchema;
9209
9675
  exports.AgentRelationUpdateSchema = AgentRelationUpdateSchema;
9210
9676
  exports.AgentSelectSchema = AgentSelectSchema;
9677
+ exports.AgentStopWhenSchema = AgentStopWhenSchema;
9211
9678
  exports.AgentToolRelationApiInsertSchema = AgentToolRelationApiInsertSchema;
9212
9679
  exports.AgentToolRelationApiSelectSchema = AgentToolRelationApiSelectSchema;
9213
9680
  exports.AgentToolRelationApiUpdateSchema = AgentToolRelationApiUpdateSchema;
@@ -9284,6 +9751,9 @@ exports.FetchConfigSchema = FetchConfigSchema;
9284
9751
  exports.FetchDefinitionSchema = FetchDefinitionSchema;
9285
9752
  exports.FullGraphAgentInsertSchema = FullGraphAgentInsertSchema;
9286
9753
  exports.FullGraphDefinitionSchema = FullGraphDefinitionSchema;
9754
+ exports.FullProjectDefinitionSchema = FullProjectDefinitionSchema;
9755
+ exports.GraphStopWhenSchema = GraphStopWhenSchema;
9756
+ exports.GraphWithinContextOfProjectSchema = GraphWithinContextOfProjectSchema;
9287
9757
  exports.HTTP_REQUEST_PARTS = HTTP_REQUEST_PARTS;
9288
9758
  exports.HeadersScopeSchema = HeadersScopeSchema;
9289
9759
  exports.IdParamsSchema = IdParamsSchema;
@@ -9328,6 +9798,7 @@ exports.RemovedResponseSchema = RemovedResponseSchema;
9328
9798
  exports.SingleResponseSchema = SingleResponseSchema;
9329
9799
  exports.StatusComponentSchema = StatusComponentSchema;
9330
9800
  exports.StatusUpdateSchema = StatusUpdateSchema;
9801
+ exports.StopWhenSchema = StopWhenSchema;
9331
9802
  exports.TOOL_STATUS_VALUES = TOOL_STATUS_VALUES;
9332
9803
  exports.TaskApiInsertSchema = TaskApiInsertSchema;
9333
9804
  exports.TaskApiSelectSchema = TaskApiSelectSchema;
@@ -9418,6 +9889,7 @@ exports.createExecutionContext = createExecutionContext;
9418
9889
  exports.createExternalAgent = createExternalAgent;
9419
9890
  exports.createExternalAgentRelation = createExternalAgentRelation;
9420
9891
  exports.createFullGraphServerSide = createFullGraphServerSide;
9892
+ exports.createFullProjectServerSide = createFullProjectServerSide;
9421
9893
  exports.createInMemoryDatabaseClient = createInMemoryDatabaseClient;
9422
9894
  exports.createKeyChainStore = createKeyChainStore;
9423
9895
  exports.createMessage = createMessage;
@@ -9447,6 +9919,7 @@ exports.deleteCredentialReference = deleteCredentialReference;
9447
9919
  exports.deleteDataComponent = deleteDataComponent;
9448
9920
  exports.deleteExternalAgent = deleteExternalAgent;
9449
9921
  exports.deleteFullGraph = deleteFullGraph;
9922
+ exports.deleteFullProject = deleteFullProject;
9450
9923
  exports.deleteLedgerArtifactsByContext = deleteLedgerArtifactsByContext;
9451
9924
  exports.deleteLedgerArtifactsByTask = deleteLedgerArtifactsByTask;
9452
9925
  exports.deleteMessage = deleteMessage;
@@ -9509,6 +9982,7 @@ exports.getExternalAgentByUrl = getExternalAgentByUrl;
9509
9982
  exports.getExternalAgentRelations = getExternalAgentRelations;
9510
9983
  exports.getFullGraph = getFullGraph;
9511
9984
  exports.getFullGraphDefinition = getFullGraphDefinition;
9985
+ exports.getFullProject = getFullProject;
9512
9986
  exports.getGraphAgentInfos = getGraphAgentInfos;
9513
9987
  exports.getHealthyToolsForAgent = getHealthyToolsForAgent;
9514
9988
  exports.getLedgerArtifacts = getLedgerArtifacts;
@@ -9612,6 +10086,7 @@ exports.updateCredentialReference = updateCredentialReference;
9612
10086
  exports.updateDataComponent = updateDataComponent;
9613
10087
  exports.updateExternalAgent = updateExternalAgent;
9614
10088
  exports.updateFullGraphServerSide = updateFullGraphServerSide;
10089
+ exports.updateFullProjectServerSide = updateFullProjectServerSide;
9615
10090
  exports.updateMessage = updateMessage;
9616
10091
  exports.updateProject = updateProject;
9617
10092
  exports.updateTask = updateTask;