@inkeep/agents-core 0.24.2 → 0.26.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.
@@ -38,6 +38,8 @@ __export(schema_exports, {
38
38
  subAgentArtifactComponentsRelations: () => subAgentArtifactComponentsRelations,
39
39
  subAgentDataComponents: () => subAgentDataComponents,
40
40
  subAgentDataComponentsRelations: () => subAgentDataComponentsRelations,
41
+ subAgentExternalAgentRelations: () => subAgentExternalAgentRelations,
42
+ subAgentExternalAgentRelationsRelations: () => subAgentExternalAgentRelationsRelations,
41
43
  subAgentFunctionToolRelations: () => subAgentFunctionToolRelations,
42
44
  subAgentFunctionToolRelationsRelations: () => subAgentFunctionToolRelationsRelations,
43
45
  subAgentRelations: () => subAgentRelations,
@@ -183,7 +185,6 @@ var subAgentRelations = sqliteTable(
183
185
  ...agentScoped,
184
186
  sourceSubAgentId: text("source_sub_agent_id").notNull(),
185
187
  targetSubAgentId: text("target_sub_agent_id"),
186
- externalSubAgentId: text("external_sub_agent_id"),
187
188
  relationType: text("relation_type"),
188
189
  ...timestamps
189
190
  },
@@ -199,19 +200,18 @@ var subAgentRelations = sqliteTable(
199
200
  var externalAgents = sqliteTable(
200
201
  "external_agents",
201
202
  {
202
- ...agentScoped,
203
+ ...projectScoped,
203
204
  ...uiProperties,
204
205
  baseUrl: text("base_url").notNull(),
205
206
  credentialReferenceId: text("credential_reference_id"),
206
- headers: blob("headers", { mode: "json" }).$type(),
207
207
  ...timestamps
208
208
  },
209
209
  (table) => [
210
- primaryKey({ columns: [table.tenantId, table.projectId, table.agentId, table.id] }),
210
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
211
211
  foreignKey({
212
- columns: [table.tenantId, table.projectId, table.agentId],
213
- foreignColumns: [agents.tenantId, agents.projectId, agents.id],
214
- name: "external_agents_agent_fk"
212
+ columns: [table.tenantId, table.projectId],
213
+ foreignColumns: [projects.tenantId, projects.id],
214
+ name: "external_agents_project_fk"
215
215
  }).onDelete("cascade"),
216
216
  foreignKey({
217
217
  columns: [table.tenantId, table.projectId, table.credentialReferenceId],
@@ -430,6 +430,28 @@ var subAgentToolRelations = sqliteTable(
430
430
  }).onDelete("cascade")
431
431
  ]
432
432
  );
433
+ var subAgentExternalAgentRelations = sqliteTable(
434
+ "sub_agent_external_agent_relations",
435
+ {
436
+ ...subAgentScoped,
437
+ externalAgentId: text("external_agent_id").notNull(),
438
+ headers: blob("headers", { mode: "json" }).$type(),
439
+ ...timestamps
440
+ },
441
+ (table) => [
442
+ primaryKey({ columns: [table.tenantId, table.projectId, table.agentId, table.id] }),
443
+ foreignKey({
444
+ columns: [table.tenantId, table.projectId, table.agentId, table.subAgentId],
445
+ foreignColumns: [subAgents.tenantId, subAgents.projectId, subAgents.agentId, subAgents.id],
446
+ name: "sub_agent_external_agent_relations_sub_agent_fk"
447
+ }).onDelete("cascade"),
448
+ foreignKey({
449
+ columns: [table.tenantId, table.projectId, table.externalAgentId],
450
+ foreignColumns: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
451
+ name: "sub_agent_external_agent_relations_external_agent_fk"
452
+ }).onDelete("cascade")
453
+ ]
454
+ );
433
455
  var subAgentFunctionToolRelations = sqliteTable(
434
456
  "sub_agent_function_tool_relations",
435
457
  {
@@ -691,7 +713,7 @@ var externalAgentsRelations = relations(externalAgents, ({ one, many }) => ({
691
713
  fields: [externalAgents.tenantId, externalAgents.projectId],
692
714
  references: [projects.tenantId, projects.id]
693
715
  }),
694
- subAgentRelations: many(subAgentRelations),
716
+ subAgentExternalAgentRelations: many(subAgentExternalAgentRelations),
695
717
  credentialReference: one(credentialReferences, {
696
718
  fields: [externalAgents.credentialReferenceId],
697
719
  references: [credentialReferences.id]
@@ -763,13 +785,13 @@ var messagesRelations = relations(messages, ({ one, many }) => ({
763
785
  relationName: "receivedMessages"
764
786
  }),
765
787
  fromExternalAgent: one(externalAgents, {
766
- fields: [messages.fromExternalAgentId],
767
- references: [externalAgents.id],
788
+ fields: [messages.tenantId, messages.projectId, messages.fromExternalAgentId],
789
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
768
790
  relationName: "receivedExternalMessages"
769
791
  }),
770
792
  toExternalAgent: one(externalAgents, {
771
- fields: [messages.toExternalAgentId],
772
- references: [externalAgents.id],
793
+ fields: [messages.tenantId, messages.projectId, messages.toExternalAgentId],
794
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
773
795
  relationName: "sentExternalMessages"
774
796
  }),
775
797
  task: one(tasks, {
@@ -853,10 +875,6 @@ var subAgentRelationsRelations = relations(subAgentRelations, ({ one }) => ({
853
875
  fields: [subAgentRelations.targetSubAgentId],
854
876
  references: [subAgents.id],
855
877
  relationName: "targetRelations"
856
- }),
857
- externalAgent: one(externalAgents, {
858
- fields: [subAgentRelations.externalSubAgentId],
859
- references: [externalAgents.id]
860
878
  })
861
879
  }));
862
880
  var functionToolsRelations = relations(functionTools, ({ one, many }) => ({
@@ -887,5 +905,27 @@ var subAgentFunctionToolRelationsRelations = relations(
887
905
  })
888
906
  })
889
907
  );
908
+ var subAgentExternalAgentRelationsRelations = relations(
909
+ subAgentExternalAgentRelations,
910
+ ({ one }) => ({
911
+ subAgent: one(subAgents, {
912
+ fields: [
913
+ subAgentExternalAgentRelations.tenantId,
914
+ subAgentExternalAgentRelations.projectId,
915
+ subAgentExternalAgentRelations.agentId,
916
+ subAgentExternalAgentRelations.subAgentId
917
+ ],
918
+ references: [subAgents.tenantId, subAgents.projectId, subAgents.agentId, subAgents.id]
919
+ }),
920
+ externalAgent: one(externalAgents, {
921
+ fields: [
922
+ subAgentExternalAgentRelations.tenantId,
923
+ subAgentExternalAgentRelations.projectId,
924
+ subAgentExternalAgentRelations.externalAgentId
925
+ ],
926
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id]
927
+ })
928
+ })
929
+ );
890
930
 
891
- export { agentRelations, agentToolRelationsRelations, agents, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, functionTools, functionToolsRelations, functions, functionsRelations, ledgerArtifacts, ledgerArtifactsRelations, messages, messagesRelations, projects, projectsRelations, schema_exports, subAgentArtifactComponents, subAgentArtifactComponentsRelations, subAgentDataComponents, subAgentDataComponentsRelations, subAgentFunctionToolRelations, subAgentFunctionToolRelationsRelations, subAgentRelations, subAgentRelationsRelations, subAgentToolRelations, subAgents, subAgentsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations };
931
+ export { agentRelations, agentToolRelationsRelations, agents, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, functionTools, functionToolsRelations, functions, functionsRelations, ledgerArtifacts, ledgerArtifactsRelations, messages, messagesRelations, projects, projectsRelations, schema_exports, subAgentArtifactComponents, subAgentArtifactComponentsRelations, subAgentDataComponents, subAgentDataComponentsRelations, subAgentExternalAgentRelations, subAgentExternalAgentRelationsRelations, subAgentFunctionToolRelations, subAgentFunctionToolRelationsRelations, subAgentRelations, subAgentRelationsRelations, subAgentToolRelations, subAgents, subAgentsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations };
@@ -1,13 +1,7 @@
1
- import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-HN77JIDP.js';
1
+ import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-NXC2HZQL.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  // src/validation/agentFull.ts
5
- function isInternalAgent(agent) {
6
- return "prompt" in agent;
7
- }
8
- function isExternalAgent(agent) {
9
- return "baseUrl" in agent;
10
- }
11
5
  function validateAndTypeAgentData(data) {
12
6
  return AgentWithinContextOfProjectSchema.parse(data);
13
7
  }
@@ -17,7 +11,7 @@ function validateToolReferences(agentData, availableToolIds) {
17
11
  }
18
12
  const errors = [];
19
13
  for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
20
- if (isInternalAgent(subAgent) && subAgent.canUse && Array.isArray(subAgent.canUse)) {
14
+ if (subAgent.canUse && Array.isArray(subAgent.canUse)) {
21
15
  for (const canUseItem of subAgent.canUse) {
22
16
  if (!availableToolIds.has(canUseItem.toolId)) {
23
17
  errors.push(`Agent '${subAgentId}' references non-existent tool '${canUseItem.toolId}'`);
@@ -36,7 +30,7 @@ function validateDataComponentReferences(agentData, availableDataComponentIds) {
36
30
  }
37
31
  const errors = [];
38
32
  for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
39
- if (isInternalAgent(subAgent) && subAgent.dataComponents) {
33
+ if (subAgent.dataComponents) {
40
34
  for (const dataComponentId of subAgent.dataComponents) {
41
35
  if (!availableDataComponentIds.has(dataComponentId)) {
42
36
  errors.push(
@@ -57,7 +51,7 @@ function validateArtifactComponentReferences(agentData, availableArtifactCompone
57
51
  }
58
52
  const errors = [];
59
53
  for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
60
- if (isInternalAgent(subAgent) && subAgent.artifactComponents) {
54
+ if (subAgent.artifactComponents) {
61
55
  for (const artifactComponentId of subAgent.artifactComponents) {
62
56
  if (!availableArtifactComponentIds.has(artifactComponentId)) {
63
57
  errors.push(
@@ -75,32 +69,56 @@ ${errors.join("\n")}`);
75
69
  function validateAgentRelationships(agentData) {
76
70
  const errors = [];
77
71
  const availableAgentIds = new Set(Object.keys(agentData.subAgents));
72
+ const availableExternalAgentIds = new Set(Object.keys(agentData.externalAgents ?? {}));
78
73
  for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
79
- if (isInternalAgent(subAgent)) {
80
- if (subAgent.canTransferTo && Array.isArray(subAgent.canTransferTo)) {
81
- for (const targetId of subAgent.canTransferTo) {
82
- if (!availableAgentIds.has(targetId)) {
74
+ if (subAgent.canTransferTo && Array.isArray(subAgent.canTransferTo)) {
75
+ for (const targetId of subAgent.canTransferTo) {
76
+ if (!availableAgentIds.has(targetId)) {
77
+ errors.push(
78
+ `Agent '${subAgentId}' has transfer target '${targetId}' that doesn't exist in agent`
79
+ );
80
+ }
81
+ }
82
+ }
83
+ if (subAgent.canDelegateTo && Array.isArray(subAgent.canDelegateTo)) {
84
+ for (const targetItem of subAgent.canDelegateTo) {
85
+ console.log("targetItem", targetItem);
86
+ if (typeof targetItem === "string") {
87
+ console.log("targetItem is string", targetItem);
88
+ if (!availableAgentIds.has(targetItem) && !availableExternalAgentIds.has(targetItem)) {
83
89
  errors.push(
84
- `Agent '${subAgentId}' has transfer target '${targetId}' that doesn't exist in agent`
90
+ `Agent '${subAgentId}' has delegation target '${targetItem}' that doesn't exist in agent`
85
91
  );
86
92
  }
87
93
  }
88
94
  }
89
- if (subAgent.canDelegateTo && Array.isArray(subAgent.canDelegateTo)) {
90
- for (const targetId of subAgent.canDelegateTo) {
91
- if (!availableAgentIds.has(targetId)) {
95
+ }
96
+ }
97
+ if (errors.length > 0)
98
+ throw new Error(`Agent relationship validation failed:
99
+ ${errors.join("\n")}`);
100
+ }
101
+ function validateSubAgentExternalAgentRelations(agentData, availableExternalAgentIds) {
102
+ if (!availableExternalAgentIds) {
103
+ return;
104
+ }
105
+ const errors = [];
106
+ for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
107
+ if (subAgent.canDelegateTo && Array.isArray(subAgent.canDelegateTo)) {
108
+ for (const targetItem of subAgent.canDelegateTo) {
109
+ if (typeof targetItem === "object" && "externalAgentId" in targetItem) {
110
+ if (!availableExternalAgentIds.has(targetItem.externalAgentId)) {
92
111
  errors.push(
93
- `Agent '${subAgentId}' has delegation target '${targetId}' that doesn't exist in agent`
112
+ `Agent '${subAgentId}' has delegation target '${targetItem.externalAgentId}' that doesn't exist in agent`
94
113
  );
95
114
  }
96
115
  }
97
116
  }
98
117
  }
99
118
  }
100
- if (errors.length > 0) {
101
- throw new Error(`Agent relationship validation failed:
119
+ if (errors.length > 0)
120
+ throw new Error(`Sub agent external agent relation validation failed:
102
121
  ${errors.join("\n")}`);
103
- }
104
122
  }
105
123
  function validateAgentStructure(agentData, projectResources) {
106
124
  if (agentData.defaultSubAgentId && !agentData.subAgents[agentData.defaultSubAgentId]) {
@@ -110,6 +128,7 @@ function validateAgentStructure(agentData, projectResources) {
110
128
  validateToolReferences(agentData, projectResources.toolIds);
111
129
  validateDataComponentReferences(agentData, projectResources.dataComponentIds);
112
130
  validateArtifactComponentReferences(agentData, projectResources.artifactComponentIds);
131
+ validateSubAgentExternalAgentRelations(agentData, projectResources.externalAgentIds);
113
132
  }
114
133
  validateAgentRelationships(agentData);
115
134
  }
@@ -278,4 +297,4 @@ function validatePreview(preview) {
278
297
  };
279
298
  }
280
299
 
281
- export { A2AMessageMetadataSchema, DataOperationDetailsSchema, DataOperationEventSchema, DelegationReturnedDataSchema, DelegationSentDataSchema, TransferDataSchema, generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAgentStructure, validateAndTypeAgentData, validateArtifactComponentReferences, validateDataComponentReferences, validatePreview, validateToolReferences };
300
+ export { A2AMessageMetadataSchema, DataOperationDetailsSchema, DataOperationEventSchema, DelegationReturnedDataSchema, DelegationSentDataSchema, TransferDataSchema, generateIdFromName, isValidResourceId, validateAgentRelationships, validateAgentStructure, validateAndTypeAgentData, validateArtifactComponentReferences, validateDataComponentReferences, validatePreview, validateSubAgentExternalAgentRelations, validateToolReferences };
@@ -1,4 +1,4 @@
1
- import { subAgents, subAgentRelations, agents, tasks, taskRelations, tools, conversations, messages, contextCache, dataComponents, subAgentDataComponents, artifactComponents, subAgentArtifactComponents, externalAgents, apiKeys, credentialReferences, functionTools, functions, contextConfigs, subAgentToolRelations, ledgerArtifacts, projects } from './chunk-5B6IOJZY.js';
1
+ import { subAgents, subAgentRelations, agents, tasks, taskRelations, tools, conversations, messages, contextCache, dataComponents, subAgentDataComponents, artifactComponents, subAgentArtifactComponents, externalAgents, apiKeys, credentialReferences, functionTools, functions, contextConfigs, subAgentToolRelations, subAgentExternalAgentRelations, ledgerArtifacts, projects } from './chunk-ALZI4IXB.js';
2
2
  import { VALID_RELATION_TYPES, MCPTransportType, TOOL_STATUS_VALUES, CredentialStoreType, MCPServerType } from './chunk-YFHT5M2R.js';
3
3
  import { z } from '@hono/zod-openapi';
4
4
  import { createSelectSchema, createInsertSchema } from 'drizzle-zod';
@@ -297,16 +297,15 @@ var SubAgentArtifactComponentApiUpdateSchema = createAgentScopedApiUpdateSchema(
297
297
  SubAgentArtifactComponentUpdateSchema
298
298
  );
299
299
  var ExternalAgentSelectSchema = createSelectSchema(externalAgents).extend({
300
- credentialReferenceId: z.string().nullable().optional(),
301
- headers: z.record(z.string(), z.string()).nullable().optional()
300
+ credentialReferenceId: z.string().nullable().optional()
302
301
  });
303
302
  var ExternalAgentInsertSchema = createInsertSchema(externalAgents).extend({
304
303
  id: resourceIdSchema
305
304
  });
306
305
  var ExternalAgentUpdateSchema = ExternalAgentInsertSchema.partial();
307
- var ExternalAgentApiSelectSchema = createAgentScopedApiSchema(ExternalAgentSelectSchema).openapi("ExternalAgent");
308
- var ExternalAgentApiInsertSchema = createAgentScopedApiInsertSchema(ExternalAgentInsertSchema).openapi("ExternalAgentCreate");
309
- var ExternalAgentApiUpdateSchema = createAgentScopedApiUpdateSchema(ExternalAgentUpdateSchema).openapi("ExternalAgentUpdate");
306
+ var ExternalAgentApiSelectSchema = createApiSchema(ExternalAgentSelectSchema).openapi("ExternalAgent");
307
+ var ExternalAgentApiInsertSchema = createApiInsertSchema(ExternalAgentInsertSchema).openapi("ExternalAgentCreate");
308
+ var ExternalAgentApiUpdateSchema = createApiUpdateSchema(ExternalAgentUpdateSchema).openapi("ExternalAgentUpdate");
310
309
  var AllAgentSchema = z.discriminatedUnion("type", [
311
310
  SubAgentApiSelectSchema.extend({ type: z.literal("internal") }),
312
311
  ExternalAgentApiSelectSchema.extend({ type: z.literal("external") })
@@ -371,7 +370,8 @@ var CredentialReferenceInsertSchema = createInsertSchema(credentialReferences).e
371
370
  var CredentialReferenceUpdateSchema = CredentialReferenceInsertSchema.partial();
372
371
  var CredentialReferenceApiSelectSchema = createApiSchema(CredentialReferenceSelectSchema).extend({
373
372
  type: z.enum(CredentialStoreType),
374
- tools: z.array(ToolSelectSchema).optional()
373
+ tools: z.array(ToolSelectSchema).optional(),
374
+ externalAgents: z.array(ExternalAgentSelectSchema).optional()
375
375
  }).openapi("CredentialReference");
376
376
  var CredentialReferenceApiInsertSchema = createApiInsertSchema(
377
377
  CredentialReferenceInsertSchema
@@ -500,6 +500,27 @@ var SubAgentToolRelationApiInsertSchema = createAgentScopedApiInsertSchema(
500
500
  var SubAgentToolRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(
501
501
  SubAgentToolRelationUpdateSchema
502
502
  ).openapi("SubAgentToolRelationUpdate");
503
+ var SubAgentExternalAgentRelationSelectSchema = createSelectSchema(
504
+ subAgentExternalAgentRelations
505
+ );
506
+ var SubAgentExternalAgentRelationInsertSchema = createInsertSchema(
507
+ subAgentExternalAgentRelations
508
+ ).extend({
509
+ id: resourceIdSchema,
510
+ subAgentId: resourceIdSchema,
511
+ externalAgentId: resourceIdSchema,
512
+ headers: z.record(z.string(), z.string()).nullish()
513
+ });
514
+ var SubAgentExternalAgentRelationUpdateSchema = SubAgentExternalAgentRelationInsertSchema.partial();
515
+ var SubAgentExternalAgentRelationApiSelectSchema = createAgentScopedApiSchema(
516
+ SubAgentExternalAgentRelationSelectSchema
517
+ ).openapi("SubAgentExternalAgentRelation");
518
+ var SubAgentExternalAgentRelationApiInsertSchema = createAgentScopedApiInsertSchema(
519
+ SubAgentExternalAgentRelationInsertSchema
520
+ ).omit({ id: true, subAgentId: true }).openapi("SubAgentExternalAgentRelationCreate");
521
+ var SubAgentExternalAgentRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(
522
+ SubAgentExternalAgentRelationUpdateSchema
523
+ ).openapi("SubAgentExternalAgentRelationUpdate");
503
524
  var LedgerArtifactSelectSchema = createSelectSchema(ledgerArtifacts);
504
525
  var LedgerArtifactInsertSchema = createInsertSchema(ledgerArtifacts);
505
526
  var LedgerArtifactUpdateSchema = LedgerArtifactInsertSchema.partial();
@@ -528,6 +549,11 @@ var CanUseItemSchema = z.object({
528
549
  toolSelection: z.array(z.string()).nullish(),
529
550
  headers: z.record(z.string(), z.string()).nullish()
530
551
  }).openapi("CanUseItem");
552
+ var canDelegateToExternalAgentSchema = z.object({
553
+ externalAgentId: z.string(),
554
+ subAgentExternalAgentRelationId: z.string().optional(),
555
+ headers: z.record(z.string(), z.string()).nullish()
556
+ });
531
557
  var FullAgentAgentInsertSchema = SubAgentApiInsertSchema.extend({
532
558
  type: z.literal("internal"),
533
559
  canUse: z.array(CanUseItemSchema),
@@ -535,16 +561,22 @@ var FullAgentAgentInsertSchema = SubAgentApiInsertSchema.extend({
535
561
  dataComponents: z.array(z.string()).optional(),
536
562
  artifactComponents: z.array(z.string()).optional(),
537
563
  canTransferTo: z.array(z.string()).optional(),
538
- canDelegateTo: z.array(z.string()).optional()
564
+ canDelegateTo: z.array(
565
+ z.union([
566
+ z.string(),
567
+ // Internal subAgent ID
568
+ canDelegateToExternalAgentSchema
569
+ // External agent with headers
570
+ ])
571
+ ).optional()
539
572
  });
540
573
  var AgentWithinContextOfProjectSchema = AgentApiInsertSchema.extend({
541
- subAgents: z.record(
542
- z.string(),
543
- z.union([FullAgentAgentInsertSchema, ExternalAgentApiInsertSchema])
544
- ),
574
+ subAgents: z.record(z.string(), FullAgentAgentInsertSchema),
545
575
  // Lookup maps for UI to resolve canUse items
546
576
  tools: z.record(z.string(), ToolApiInsertSchema).optional(),
547
577
  // MCP tools (project-scoped)
578
+ externalAgents: z.record(z.string(), ExternalAgentApiInsertSchema).optional(),
579
+ // External agents (project-scoped)
548
580
  functionTools: z.record(z.string(), FunctionToolApiInsertSchema).optional(),
549
581
  // Function tools (agent-scoped)
550
582
  functions: z.record(z.string(), FunctionApiInsertSchema).optional(),
@@ -606,6 +638,7 @@ var FullProjectDefinitionSchema = ProjectApiInsertSchema.extend({
606
638
  functions: z.record(z.string(), FunctionApiInsertSchema).optional(),
607
639
  dataComponents: z.record(z.string(), DataComponentApiInsertSchema).optional(),
608
640
  artifactComponents: z.record(z.string(), ArtifactComponentApiInsertSchema).optional(),
641
+ externalAgents: z.record(z.string(), ExternalAgentApiInsertSchema).optional(),
609
642
  statusUpdates: z.optional(StatusUpdateSchema),
610
643
  credentialReferences: z.record(z.string(), CredentialReferenceApiInsertSchema).optional(),
611
644
  createdAt: z.string().optional(),
@@ -862,4 +895,4 @@ function validatePropsAsJsonSchema(props) {
862
895
  }
863
896
  }
864
897
 
865
- export { AgentApiInsertSchema, AgentApiSelectSchema, AgentApiUpdateSchema, AgentInsertSchema, AgentListResponse, AgentResponse, AgentSelectSchema, AgentStopWhenSchema, AgentUpdateSchema, AgentWithinContextOfProjectSchema, AllAgentSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiSelectSchema, ApiKeyApiUpdateSchema, ApiKeyInsertSchema, ApiKeyListResponse, ApiKeyResponse, ApiKeySelectSchema, ApiKeyUpdateSchema, ArtifactComponentApiInsertSchema, ArtifactComponentApiSelectSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentInsertSchema, ArtifactComponentListResponse, ArtifactComponentResponse, ArtifactComponentSelectSchema, ArtifactComponentUpdateSchema, CanUseItemSchema, ContextCacheApiInsertSchema, ContextCacheApiSelectSchema, ContextCacheApiUpdateSchema, ContextCacheInsertSchema, ContextCacheSelectSchema, ContextCacheUpdateSchema, ContextConfigApiInsertSchema, ContextConfigApiSelectSchema, ContextConfigApiUpdateSchema, ContextConfigInsertSchema, ContextConfigListResponse, ContextConfigResponse, ContextConfigSelectSchema, ContextConfigUpdateSchema, ConversationApiInsertSchema, ConversationApiSelectSchema, ConversationApiUpdateSchema, ConversationInsertSchema, ConversationListResponse, ConversationResponse, ConversationSelectSchema, ConversationUpdateSchema, CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema, CredentialReferenceApiUpdateSchema, CredentialReferenceInsertSchema, CredentialReferenceListResponse, CredentialReferenceResponse, CredentialReferenceSelectSchema, CredentialReferenceUpdateSchema, DataComponentApiInsertSchema, DataComponentApiSelectSchema, DataComponentApiUpdateSchema, DataComponentBaseSchema, DataComponentInsertSchema, DataComponentListResponse, DataComponentResponse, DataComponentSelectSchema, DataComponentUpdateSchema, ErrorResponseSchema, ExistsResponseSchema, ExternalAgentApiInsertSchema, ExternalAgentApiSelectSchema, ExternalAgentApiUpdateSchema, ExternalAgentInsertSchema, ExternalAgentListResponse, ExternalAgentResponse, ExternalAgentSelectSchema, ExternalAgentUpdateSchema, ExternalSubAgentRelationApiInsertSchema, ExternalSubAgentRelationInsertSchema, FetchConfigSchema, FetchDefinitionSchema, FullAgentAgentInsertSchema, FullProjectDefinitionSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, FunctionInsertSchema, FunctionListResponse, FunctionResponse, FunctionSelectSchema, FunctionToolApiInsertSchema, FunctionToolApiSelectSchema, FunctionToolApiUpdateSchema, FunctionToolConfigSchema, FunctionToolInsertSchema, FunctionToolListResponse, FunctionToolResponse, FunctionToolSelectSchema, FunctionToolUpdateSchema, FunctionUpdateSchema, HeadersScopeSchema, LedgerArtifactApiInsertSchema, LedgerArtifactApiSelectSchema, LedgerArtifactApiUpdateSchema, LedgerArtifactInsertSchema, LedgerArtifactSelectSchema, LedgerArtifactUpdateSchema, ListResponseSchema, MAX_ID_LENGTH, MCPToolConfigSchema, MIN_ID_LENGTH, McpToolDefinitionSchema, McpToolSchema, McpTransportConfigSchema, MessageApiInsertSchema, MessageApiSelectSchema, MessageApiUpdateSchema, MessageInsertSchema, MessageListResponse, MessageResponse, MessageSelectSchema, MessageUpdateSchema, ModelSchema, ModelSettingsSchema, PaginationQueryParamsSchema, PaginationSchema, ProjectApiInsertSchema, ProjectApiSelectSchema, ProjectApiUpdateSchema, ProjectInsertSchema, ProjectListResponse, ProjectModelSchema, ProjectResponse, ProjectSelectSchema, ProjectUpdateSchema, RemovedResponseSchema, SingleResponseSchema, StatusComponentSchema, StatusUpdateSchema, StopWhenSchema, SubAgentApiInsertSchema, SubAgentApiSelectSchema, SubAgentApiUpdateSchema, SubAgentArtifactComponentApiInsertSchema, SubAgentArtifactComponentApiSelectSchema, SubAgentArtifactComponentApiUpdateSchema, SubAgentArtifactComponentInsertSchema, SubAgentArtifactComponentListResponse, SubAgentArtifactComponentResponse, SubAgentArtifactComponentSelectSchema, SubAgentArtifactComponentUpdateSchema, SubAgentDataComponentApiInsertSchema, SubAgentDataComponentApiSelectSchema, SubAgentDataComponentApiUpdateSchema, SubAgentDataComponentInsertSchema, SubAgentDataComponentListResponse, SubAgentDataComponentResponse, SubAgentDataComponentSelectSchema, SubAgentDataComponentUpdateSchema, SubAgentInsertSchema, SubAgentListResponse, SubAgentRelationApiInsertSchema, SubAgentRelationApiSelectSchema, SubAgentRelationApiUpdateSchema, SubAgentRelationInsertSchema, SubAgentRelationListResponse, SubAgentRelationQuerySchema, SubAgentRelationResponse, SubAgentRelationSelectSchema, SubAgentRelationUpdateSchema, SubAgentResponse, SubAgentSelectSchema, SubAgentStopWhenSchema, SubAgentToolRelationApiInsertSchema, SubAgentToolRelationApiSelectSchema, SubAgentToolRelationApiUpdateSchema, SubAgentToolRelationInsertSchema, SubAgentToolRelationListResponse, SubAgentToolRelationResponse, SubAgentToolRelationSelectSchema, SubAgentToolRelationUpdateSchema, SubAgentUpdateSchema, TaskApiInsertSchema, TaskApiSelectSchema, TaskApiUpdateSchema, TaskInsertSchema, TaskRelationApiInsertSchema, TaskRelationApiSelectSchema, TaskRelationApiUpdateSchema, TaskRelationInsertSchema, TaskRelationSelectSchema, TaskRelationUpdateSchema, TaskSelectSchema, TaskUpdateSchema, TenantIdParamsSchema, TenantParamsSchema, TenantProjectAgentIdParamsSchema, TenantProjectAgentParamsSchema, TenantProjectAgentSubAgentIdParamsSchema, TenantProjectAgentSubAgentParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolListResponse, ToolResponse, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, resourceIdSchema, validatePropsAsJsonSchema };
898
+ export { AgentApiInsertSchema, AgentApiSelectSchema, AgentApiUpdateSchema, AgentInsertSchema, AgentListResponse, AgentResponse, AgentSelectSchema, AgentStopWhenSchema, AgentUpdateSchema, AgentWithinContextOfProjectSchema, AllAgentSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiSelectSchema, ApiKeyApiUpdateSchema, ApiKeyInsertSchema, ApiKeyListResponse, ApiKeyResponse, ApiKeySelectSchema, ApiKeyUpdateSchema, ArtifactComponentApiInsertSchema, ArtifactComponentApiSelectSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentInsertSchema, ArtifactComponentListResponse, ArtifactComponentResponse, ArtifactComponentSelectSchema, ArtifactComponentUpdateSchema, CanUseItemSchema, ContextCacheApiInsertSchema, ContextCacheApiSelectSchema, ContextCacheApiUpdateSchema, ContextCacheInsertSchema, ContextCacheSelectSchema, ContextCacheUpdateSchema, ContextConfigApiInsertSchema, ContextConfigApiSelectSchema, ContextConfigApiUpdateSchema, ContextConfigInsertSchema, ContextConfigListResponse, ContextConfigResponse, ContextConfigSelectSchema, ContextConfigUpdateSchema, ConversationApiInsertSchema, ConversationApiSelectSchema, ConversationApiUpdateSchema, ConversationInsertSchema, ConversationListResponse, ConversationResponse, ConversationSelectSchema, ConversationUpdateSchema, CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema, CredentialReferenceApiUpdateSchema, CredentialReferenceInsertSchema, CredentialReferenceListResponse, CredentialReferenceResponse, CredentialReferenceSelectSchema, CredentialReferenceUpdateSchema, DataComponentApiInsertSchema, DataComponentApiSelectSchema, DataComponentApiUpdateSchema, DataComponentBaseSchema, DataComponentInsertSchema, DataComponentListResponse, DataComponentResponse, DataComponentSelectSchema, DataComponentUpdateSchema, ErrorResponseSchema, ExistsResponseSchema, ExternalAgentApiInsertSchema, ExternalAgentApiSelectSchema, ExternalAgentApiUpdateSchema, ExternalAgentInsertSchema, ExternalAgentListResponse, ExternalAgentResponse, ExternalAgentSelectSchema, ExternalAgentUpdateSchema, ExternalSubAgentRelationApiInsertSchema, ExternalSubAgentRelationInsertSchema, FetchConfigSchema, FetchDefinitionSchema, FullAgentAgentInsertSchema, FullProjectDefinitionSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, FunctionInsertSchema, FunctionListResponse, FunctionResponse, FunctionSelectSchema, FunctionToolApiInsertSchema, FunctionToolApiSelectSchema, FunctionToolApiUpdateSchema, FunctionToolConfigSchema, FunctionToolInsertSchema, FunctionToolListResponse, FunctionToolResponse, FunctionToolSelectSchema, FunctionToolUpdateSchema, FunctionUpdateSchema, HeadersScopeSchema, LedgerArtifactApiInsertSchema, LedgerArtifactApiSelectSchema, LedgerArtifactApiUpdateSchema, LedgerArtifactInsertSchema, LedgerArtifactSelectSchema, LedgerArtifactUpdateSchema, ListResponseSchema, MAX_ID_LENGTH, MCPToolConfigSchema, MIN_ID_LENGTH, McpToolDefinitionSchema, McpToolSchema, McpTransportConfigSchema, MessageApiInsertSchema, MessageApiSelectSchema, MessageApiUpdateSchema, MessageInsertSchema, MessageListResponse, MessageResponse, MessageSelectSchema, MessageUpdateSchema, ModelSchema, ModelSettingsSchema, PaginationQueryParamsSchema, PaginationSchema, ProjectApiInsertSchema, ProjectApiSelectSchema, ProjectApiUpdateSchema, ProjectInsertSchema, ProjectListResponse, ProjectModelSchema, ProjectResponse, ProjectSelectSchema, ProjectUpdateSchema, RemovedResponseSchema, SingleResponseSchema, StatusComponentSchema, StatusUpdateSchema, StopWhenSchema, SubAgentApiInsertSchema, SubAgentApiSelectSchema, SubAgentApiUpdateSchema, SubAgentArtifactComponentApiInsertSchema, SubAgentArtifactComponentApiSelectSchema, SubAgentArtifactComponentApiUpdateSchema, SubAgentArtifactComponentInsertSchema, SubAgentArtifactComponentListResponse, SubAgentArtifactComponentResponse, SubAgentArtifactComponentSelectSchema, SubAgentArtifactComponentUpdateSchema, SubAgentDataComponentApiInsertSchema, SubAgentDataComponentApiSelectSchema, SubAgentDataComponentApiUpdateSchema, SubAgentDataComponentInsertSchema, SubAgentDataComponentListResponse, SubAgentDataComponentResponse, SubAgentDataComponentSelectSchema, SubAgentDataComponentUpdateSchema, SubAgentExternalAgentRelationApiInsertSchema, SubAgentExternalAgentRelationApiSelectSchema, SubAgentExternalAgentRelationApiUpdateSchema, SubAgentExternalAgentRelationInsertSchema, SubAgentExternalAgentRelationSelectSchema, SubAgentExternalAgentRelationUpdateSchema, SubAgentInsertSchema, SubAgentListResponse, SubAgentRelationApiInsertSchema, SubAgentRelationApiSelectSchema, SubAgentRelationApiUpdateSchema, SubAgentRelationInsertSchema, SubAgentRelationListResponse, SubAgentRelationQuerySchema, SubAgentRelationResponse, SubAgentRelationSelectSchema, SubAgentRelationUpdateSchema, SubAgentResponse, SubAgentSelectSchema, SubAgentStopWhenSchema, SubAgentToolRelationApiInsertSchema, SubAgentToolRelationApiSelectSchema, SubAgentToolRelationApiUpdateSchema, SubAgentToolRelationInsertSchema, SubAgentToolRelationListResponse, SubAgentToolRelationResponse, SubAgentToolRelationSelectSchema, SubAgentToolRelationUpdateSchema, SubAgentUpdateSchema, TaskApiInsertSchema, TaskApiSelectSchema, TaskApiUpdateSchema, TaskInsertSchema, TaskRelationApiInsertSchema, TaskRelationApiSelectSchema, TaskRelationApiUpdateSchema, TaskRelationInsertSchema, TaskRelationSelectSchema, TaskRelationUpdateSchema, TaskSelectSchema, TaskUpdateSchema, TenantIdParamsSchema, TenantParamsSchema, TenantProjectAgentIdParamsSchema, TenantProjectAgentParamsSchema, TenantProjectAgentSubAgentIdParamsSchema, TenantProjectAgentSubAgentParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolListResponse, ToolResponse, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, canDelegateToExternalAgentSchema, resourceIdSchema, validatePropsAsJsonSchema };
@@ -161,7 +161,6 @@ var subAgentRelations = sqliteCore.sqliteTable(
161
161
  ...agentScoped,
162
162
  sourceSubAgentId: sqliteCore.text("source_sub_agent_id").notNull(),
163
163
  targetSubAgentId: sqliteCore.text("target_sub_agent_id"),
164
- externalSubAgentId: sqliteCore.text("external_sub_agent_id"),
165
164
  relationType: sqliteCore.text("relation_type"),
166
165
  ...timestamps
167
166
  },
@@ -177,19 +176,18 @@ var subAgentRelations = sqliteCore.sqliteTable(
177
176
  var externalAgents = sqliteCore.sqliteTable(
178
177
  "external_agents",
179
178
  {
180
- ...agentScoped,
179
+ ...projectScoped,
181
180
  ...uiProperties,
182
181
  baseUrl: sqliteCore.text("base_url").notNull(),
183
182
  credentialReferenceId: sqliteCore.text("credential_reference_id"),
184
- headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
185
183
  ...timestamps
186
184
  },
187
185
  (table) => [
188
- sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.agentId, table.id] }),
186
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
189
187
  sqliteCore.foreignKey({
190
- columns: [table.tenantId, table.projectId, table.agentId],
191
- foreignColumns: [agents.tenantId, agents.projectId, agents.id],
192
- name: "external_agents_agent_fk"
188
+ columns: [table.tenantId, table.projectId],
189
+ foreignColumns: [projects.tenantId, projects.id],
190
+ name: "external_agents_project_fk"
193
191
  }).onDelete("cascade"),
194
192
  sqliteCore.foreignKey({
195
193
  columns: [table.tenantId, table.projectId, table.credentialReferenceId],
@@ -408,6 +406,28 @@ var subAgentToolRelations = sqliteCore.sqliteTable(
408
406
  }).onDelete("cascade")
409
407
  ]
410
408
  );
409
+ var subAgentExternalAgentRelations = sqliteCore.sqliteTable(
410
+ "sub_agent_external_agent_relations",
411
+ {
412
+ ...subAgentScoped,
413
+ externalAgentId: sqliteCore.text("external_agent_id").notNull(),
414
+ headers: sqliteCore.blob("headers", { mode: "json" }).$type(),
415
+ ...timestamps
416
+ },
417
+ (table) => [
418
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.agentId, table.id] }),
419
+ sqliteCore.foreignKey({
420
+ columns: [table.tenantId, table.projectId, table.agentId, table.subAgentId],
421
+ foreignColumns: [subAgents.tenantId, subAgents.projectId, subAgents.agentId, subAgents.id],
422
+ name: "sub_agent_external_agent_relations_sub_agent_fk"
423
+ }).onDelete("cascade"),
424
+ sqliteCore.foreignKey({
425
+ columns: [table.tenantId, table.projectId, table.externalAgentId],
426
+ foreignColumns: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
427
+ name: "sub_agent_external_agent_relations_external_agent_fk"
428
+ }).onDelete("cascade")
429
+ ]
430
+ );
411
431
  var subAgentFunctionToolRelations = sqliteCore.sqliteTable(
412
432
  "sub_agent_function_tool_relations",
413
433
  {
@@ -669,7 +689,7 @@ drizzleOrm.relations(externalAgents, ({ one, many }) => ({
669
689
  fields: [externalAgents.tenantId, externalAgents.projectId],
670
690
  references: [projects.tenantId, projects.id]
671
691
  }),
672
- subAgentRelations: many(subAgentRelations),
692
+ subAgentExternalAgentRelations: many(subAgentExternalAgentRelations),
673
693
  credentialReference: one(credentialReferences, {
674
694
  fields: [externalAgents.credentialReferenceId],
675
695
  references: [credentialReferences.id]
@@ -741,13 +761,13 @@ drizzleOrm.relations(messages, ({ one, many }) => ({
741
761
  relationName: "receivedMessages"
742
762
  }),
743
763
  fromExternalAgent: one(externalAgents, {
744
- fields: [messages.fromExternalAgentId],
745
- references: [externalAgents.id],
764
+ fields: [messages.tenantId, messages.projectId, messages.fromExternalAgentId],
765
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
746
766
  relationName: "receivedExternalMessages"
747
767
  }),
748
768
  toExternalAgent: one(externalAgents, {
749
- fields: [messages.toExternalAgentId],
750
- references: [externalAgents.id],
769
+ fields: [messages.tenantId, messages.projectId, messages.toExternalAgentId],
770
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id],
751
771
  relationName: "sentExternalMessages"
752
772
  }),
753
773
  task: one(tasks, {
@@ -831,10 +851,6 @@ drizzleOrm.relations(subAgentRelations, ({ one }) => ({
831
851
  fields: [subAgentRelations.targetSubAgentId],
832
852
  references: [subAgents.id],
833
853
  relationName: "targetRelations"
834
- }),
835
- externalAgent: one(externalAgents, {
836
- fields: [subAgentRelations.externalSubAgentId],
837
- references: [externalAgents.id]
838
854
  })
839
855
  }));
840
856
  drizzleOrm.relations(functionTools, ({ one, many }) => ({
@@ -865,6 +881,28 @@ drizzleOrm.relations(
865
881
  })
866
882
  })
867
883
  );
884
+ drizzleOrm.relations(
885
+ subAgentExternalAgentRelations,
886
+ ({ one }) => ({
887
+ subAgent: one(subAgents, {
888
+ fields: [
889
+ subAgentExternalAgentRelations.tenantId,
890
+ subAgentExternalAgentRelations.projectId,
891
+ subAgentExternalAgentRelations.agentId,
892
+ subAgentExternalAgentRelations.subAgentId
893
+ ],
894
+ references: [subAgents.tenantId, subAgents.projectId, subAgents.agentId, subAgents.id]
895
+ }),
896
+ externalAgent: one(externalAgents, {
897
+ fields: [
898
+ subAgentExternalAgentRelations.tenantId,
899
+ subAgentExternalAgentRelations.projectId,
900
+ subAgentExternalAgentRelations.externalAgentId
901
+ ],
902
+ references: [externalAgents.tenantId, externalAgents.projectId, externalAgents.id]
903
+ })
904
+ })
905
+ );
868
906
 
869
907
  // src/validation/schemas.ts
870
908
  var StopWhenSchema = zodOpenapi.z.object({
@@ -1160,16 +1198,15 @@ createAgentScopedApiUpdateSchema(
1160
1198
  SubAgentArtifactComponentUpdateSchema
1161
1199
  );
1162
1200
  var ExternalAgentSelectSchema = drizzleZod.createSelectSchema(externalAgents).extend({
1163
- credentialReferenceId: zodOpenapi.z.string().nullable().optional(),
1164
- headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.string()).nullable().optional()
1201
+ credentialReferenceId: zodOpenapi.z.string().nullable().optional()
1165
1202
  });
1166
1203
  var ExternalAgentInsertSchema = drizzleZod.createInsertSchema(externalAgents).extend({
1167
1204
  id: resourceIdSchema
1168
1205
  });
1169
1206
  var ExternalAgentUpdateSchema = ExternalAgentInsertSchema.partial();
1170
- var ExternalAgentApiSelectSchema = createAgentScopedApiSchema(ExternalAgentSelectSchema).openapi("ExternalAgent");
1171
- var ExternalAgentApiInsertSchema = createAgentScopedApiInsertSchema(ExternalAgentInsertSchema).openapi("ExternalAgentCreate");
1172
- createAgentScopedApiUpdateSchema(ExternalAgentUpdateSchema).openapi("ExternalAgentUpdate");
1207
+ var ExternalAgentApiSelectSchema = createApiSchema(ExternalAgentSelectSchema).openapi("ExternalAgent");
1208
+ var ExternalAgentApiInsertSchema = createApiInsertSchema(ExternalAgentInsertSchema).openapi("ExternalAgentCreate");
1209
+ createApiUpdateSchema(ExternalAgentUpdateSchema).openapi("ExternalAgentUpdate");
1173
1210
  zodOpenapi.z.discriminatedUnion("type", [
1174
1211
  SubAgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("internal") }),
1175
1212
  ExternalAgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("external") })
@@ -1234,7 +1271,8 @@ var CredentialReferenceInsertSchema = drizzleZod.createInsertSchema(credentialRe
1234
1271
  var CredentialReferenceUpdateSchema = CredentialReferenceInsertSchema.partial();
1235
1272
  var CredentialReferenceApiSelectSchema = createApiSchema(CredentialReferenceSelectSchema).extend({
1236
1273
  type: zodOpenapi.z.enum(CredentialStoreType),
1237
- tools: zodOpenapi.z.array(ToolSelectSchema).optional()
1274
+ tools: zodOpenapi.z.array(ToolSelectSchema).optional(),
1275
+ externalAgents: zodOpenapi.z.array(ExternalAgentSelectSchema).optional()
1238
1276
  }).openapi("CredentialReference");
1239
1277
  var CredentialReferenceApiInsertSchema = createApiInsertSchema(
1240
1278
  CredentialReferenceInsertSchema
@@ -1363,6 +1401,27 @@ createAgentScopedApiInsertSchema(
1363
1401
  createAgentScopedApiUpdateSchema(
1364
1402
  SubAgentToolRelationUpdateSchema
1365
1403
  ).openapi("SubAgentToolRelationUpdate");
1404
+ var SubAgentExternalAgentRelationSelectSchema = drizzleZod.createSelectSchema(
1405
+ subAgentExternalAgentRelations
1406
+ );
1407
+ var SubAgentExternalAgentRelationInsertSchema = drizzleZod.createInsertSchema(
1408
+ subAgentExternalAgentRelations
1409
+ ).extend({
1410
+ id: resourceIdSchema,
1411
+ subAgentId: resourceIdSchema,
1412
+ externalAgentId: resourceIdSchema,
1413
+ headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.string()).nullish()
1414
+ });
1415
+ var SubAgentExternalAgentRelationUpdateSchema = SubAgentExternalAgentRelationInsertSchema.partial();
1416
+ createAgentScopedApiSchema(
1417
+ SubAgentExternalAgentRelationSelectSchema
1418
+ ).openapi("SubAgentExternalAgentRelation");
1419
+ createAgentScopedApiInsertSchema(
1420
+ SubAgentExternalAgentRelationInsertSchema
1421
+ ).omit({ id: true, subAgentId: true }).openapi("SubAgentExternalAgentRelationCreate");
1422
+ createAgentScopedApiUpdateSchema(
1423
+ SubAgentExternalAgentRelationUpdateSchema
1424
+ ).openapi("SubAgentExternalAgentRelationUpdate");
1366
1425
  var LedgerArtifactSelectSchema = drizzleZod.createSelectSchema(ledgerArtifacts);
1367
1426
  var LedgerArtifactInsertSchema = drizzleZod.createInsertSchema(ledgerArtifacts);
1368
1427
  var LedgerArtifactUpdateSchema = LedgerArtifactInsertSchema.partial();
@@ -1391,6 +1450,11 @@ var CanUseItemSchema = zodOpenapi.z.object({
1391
1450
  toolSelection: zodOpenapi.z.array(zodOpenapi.z.string()).nullish(),
1392
1451
  headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.string()).nullish()
1393
1452
  }).openapi("CanUseItem");
1453
+ var canDelegateToExternalAgentSchema = zodOpenapi.z.object({
1454
+ externalAgentId: zodOpenapi.z.string(),
1455
+ subAgentExternalAgentRelationId: zodOpenapi.z.string().optional(),
1456
+ headers: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.string()).nullish()
1457
+ });
1394
1458
  var FullAgentAgentInsertSchema = SubAgentApiInsertSchema.extend({
1395
1459
  type: zodOpenapi.z.literal("internal"),
1396
1460
  canUse: zodOpenapi.z.array(CanUseItemSchema),
@@ -1398,16 +1462,22 @@ var FullAgentAgentInsertSchema = SubAgentApiInsertSchema.extend({
1398
1462
  dataComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
1399
1463
  artifactComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
1400
1464
  canTransferTo: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
1401
- canDelegateTo: zodOpenapi.z.array(zodOpenapi.z.string()).optional()
1465
+ canDelegateTo: zodOpenapi.z.array(
1466
+ zodOpenapi.z.union([
1467
+ zodOpenapi.z.string(),
1468
+ // Internal subAgent ID
1469
+ canDelegateToExternalAgentSchema
1470
+ // External agent with headers
1471
+ ])
1472
+ ).optional()
1402
1473
  });
1403
1474
  var AgentWithinContextOfProjectSchema = AgentApiInsertSchema.extend({
1404
- subAgents: zodOpenapi.z.record(
1405
- zodOpenapi.z.string(),
1406
- zodOpenapi.z.union([FullAgentAgentInsertSchema, ExternalAgentApiInsertSchema])
1407
- ),
1475
+ subAgents: zodOpenapi.z.record(zodOpenapi.z.string(), FullAgentAgentInsertSchema),
1408
1476
  // Lookup maps for UI to resolve canUse items
1409
1477
  tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema).optional(),
1410
1478
  // MCP tools (project-scoped)
1479
+ externalAgents: zodOpenapi.z.record(zodOpenapi.z.string(), ExternalAgentApiInsertSchema).optional(),
1480
+ // External agents (project-scoped)
1411
1481
  functionTools: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionToolApiInsertSchema).optional(),
1412
1482
  // Function tools (agent-scoped)
1413
1483
  functions: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionApiInsertSchema).optional(),
@@ -1462,6 +1532,7 @@ ProjectApiInsertSchema.extend({
1462
1532
  functions: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionApiInsertSchema).optional(),
1463
1533
  dataComponents: zodOpenapi.z.record(zodOpenapi.z.string(), DataComponentApiInsertSchema).optional(),
1464
1534
  artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
1535
+ externalAgents: zodOpenapi.z.record(zodOpenapi.z.string(), ExternalAgentApiInsertSchema).optional(),
1465
1536
  statusUpdates: zodOpenapi.z.optional(StatusUpdateSchema),
1466
1537
  credentialReferences: zodOpenapi.z.record(zodOpenapi.z.string(), CredentialReferenceApiInsertSchema).optional(),
1467
1538
  createdAt: zodOpenapi.z.string().optional(),
@@ -2172,15 +2243,7 @@ var AgentAgentApiInsertSchema = zod.z.object({
2172
2243
  defaultSubAgentId: zod.z.string().optional()
2173
2244
  });
2174
2245
  var FullAgentDefinitionSchema = AgentAgentApiInsertSchema.extend({
2175
- subAgents: zod.z.record(
2176
- zod.z.string(),
2177
- zod.z.union([
2178
- FullAgentAgentInsertSchema,
2179
- ExternalAgentApiInsertSchema2.extend({
2180
- id: zod.z.string()
2181
- })
2182
- ])
2183
- ),
2246
+ subAgents: zod.z.record(zod.z.string(), zod.z.union([FullAgentAgentInsertSchema])),
2184
2247
  contextConfig: zod.z.optional(ContextConfigApiInsertSchema2),
2185
2248
  models: zod.z.object({
2186
2249
  base: zod.z.object({