@inkeep/agents-run-api 0.0.0-dev-20260114183157 → 0.0.0-dev-20260115183047

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.
Files changed (79) hide show
  1. package/README.md +2 -1
  2. package/dist/a2a/client.d.ts +3 -1
  3. package/dist/a2a/client.js +23 -9
  4. package/dist/a2a/handlers.js +11 -5
  5. package/dist/a2a/transfer.d.ts +6 -1
  6. package/dist/a2a/transfer.js +10 -6
  7. package/dist/agents/Agent.d.ts +8 -4
  8. package/dist/agents/Agent.js +216 -75
  9. package/dist/agents/ToolSessionManager.js +2 -2
  10. package/dist/agents/generateTaskHandler.d.ts +4 -9
  11. package/dist/agents/generateTaskHandler.js +107 -246
  12. package/dist/agents/relationTools.d.ts +19 -8
  13. package/dist/agents/relationTools.js +105 -14
  14. package/dist/agents/versions/v1/Phase1Config.js +13 -8
  15. package/dist/constants/execution-limits/index.js +1 -1
  16. package/dist/context/ContextFetcher.d.ts +68 -0
  17. package/dist/context/ContextFetcher.js +276 -0
  18. package/dist/context/ContextResolver.d.ts +56 -0
  19. package/dist/context/ContextResolver.js +273 -0
  20. package/dist/context/context.d.ts +19 -0
  21. package/dist/context/context.js +108 -0
  22. package/dist/context/contextCache.d.ts +56 -0
  23. package/dist/context/contextCache.js +175 -0
  24. package/dist/context/index.d.ts +6 -0
  25. package/dist/context/index.js +7 -0
  26. package/dist/context/validation.d.ts +39 -0
  27. package/dist/context/validation.js +255 -0
  28. package/dist/create-app.js +7 -2
  29. package/dist/data/agent.d.ts +2 -2
  30. package/dist/data/agent.js +17 -22
  31. package/dist/data/agents.d.ts +2 -2
  32. package/dist/data/agents.js +34 -42
  33. package/dist/data/conversations.d.ts +2 -1
  34. package/dist/data/conversations.js +7 -8
  35. package/dist/data/db/dbClient.d.ts +2 -2
  36. package/dist/data/db/dbClient.js +2 -10
  37. package/dist/env.d.ts +6 -2
  38. package/dist/env.js +3 -1
  39. package/dist/handlers/executionHandler.d.ts +3 -2
  40. package/dist/handlers/executionHandler.js +46 -22
  41. package/dist/middleware/api-key-auth.d.ts +4 -10
  42. package/dist/middleware/api-key-auth.js +164 -163
  43. package/dist/middleware/index.d.ts +3 -2
  44. package/dist/middleware/index.js +3 -2
  45. package/dist/middleware/projectConfig.d.ts +19 -0
  46. package/dist/middleware/projectConfig.js +80 -0
  47. package/dist/routes/agents.d.ts +2 -1
  48. package/dist/routes/agents.js +7 -13
  49. package/dist/routes/chat.d.ts +2 -1
  50. package/dist/routes/chat.js +29 -52
  51. package/dist/routes/chatDataStream.d.ts +2 -1
  52. package/dist/routes/chatDataStream.js +28 -30
  53. package/dist/routes/mcp.d.ts +2 -1
  54. package/dist/routes/mcp.js +25 -37
  55. package/dist/services/AgentSession.d.ts +5 -7
  56. package/dist/services/AgentSession.js +25 -34
  57. package/dist/services/ArtifactParser.d.ts +2 -2
  58. package/dist/services/ArtifactParser.js +2 -2
  59. package/dist/services/ArtifactService.d.ts +2 -3
  60. package/dist/services/ArtifactService.js +23 -20
  61. package/dist/services/BaseCompressor.js +2 -2
  62. package/dist/services/IncrementalStreamParser.d.ts +2 -2
  63. package/dist/services/IncrementalStreamParser.js +2 -2
  64. package/dist/services/ResponseFormatter.d.ts +2 -2
  65. package/dist/services/ResponseFormatter.js +2 -2
  66. package/dist/services/evaluationHttpClient.d.ts +21 -0
  67. package/dist/services/evaluationHttpClient.js +48 -0
  68. package/dist/services/evaluationRunConfigMatcher.d.ts +6 -0
  69. package/dist/services/evaluationRunConfigMatcher.js +7 -0
  70. package/dist/tools/NativeSandboxExecutor.js +1 -1
  71. package/dist/tools/distill-conversation-history-tool.js +2 -2
  72. package/dist/tools/distill-conversation-tool.js +2 -2
  73. package/dist/types/execution-context.d.ts +8 -14
  74. package/dist/types/execution-context.js +3 -2
  75. package/dist/utils/model-resolver.d.ts +2 -2
  76. package/dist/utils/model-resolver.js +3 -13
  77. package/dist/utils/project.d.ts +207 -0
  78. package/dist/utils/project.js +315 -0
  79. package/package.json +2 -2
@@ -1,27 +1,17 @@
1
- import dbClient_default from "../data/db/dbClient.js";
2
- import { getAgentById, getProject } from "@inkeep/agents-core";
3
-
4
1
  //#region src/utils/model-resolver.ts
5
- async function resolveModelConfig(agentId, subAgent) {
2
+ async function resolveModelConfig(executionContext, subAgent) {
3
+ const { agentId, project } = executionContext;
6
4
  if (subAgent.models?.base?.model) return {
7
5
  base: subAgent.models.base,
8
6
  structuredOutput: subAgent.models.structuredOutput || subAgent.models.base,
9
7
  summarizer: subAgent.models.summarizer || subAgent.models.base
10
8
  };
11
- const agent = await getAgentById(dbClient_default)({ scopes: {
12
- tenantId: subAgent.tenantId,
13
- projectId: subAgent.projectId,
14
- agentId
15
- } });
9
+ const agent = project.agents[agentId];
16
10
  if (agent?.models?.base?.model) return {
17
11
  base: agent.models.base,
18
12
  structuredOutput: subAgent.models?.structuredOutput || agent.models.structuredOutput || agent.models.base,
19
13
  summarizer: subAgent.models?.summarizer || agent.models.summarizer || agent.models.base
20
14
  };
21
- const project = await getProject(dbClient_default)({ scopes: {
22
- tenantId: subAgent.tenantId,
23
- projectId: subAgent.projectId
24
- } });
25
15
  if (project?.models?.base?.model) return {
26
16
  base: project.models.base,
27
17
  structuredOutput: subAgent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
@@ -0,0 +1,207 @@
1
+ import { AgentWithinContextOfProjectSelectWithRelationIds, ArtifactComponentApiSelect, CanDelegateToItem, CanRelateToInternalSubAgent, DataComponentApiSelect, ExternalAgentApiSelect, FullAgentSubAgentSelectWithRelationIds, FullProjectSelectWithRelationIds, ToolApiSelect } from "@inkeep/agents-core";
2
+
3
+ //#region src/utils/project.d.ts
4
+
5
+ /**
6
+ * Get an agent from the project definition
7
+ * Replaces direct database calls with lookup from pre-fetched project data
8
+ */
9
+ declare function getAgentFromProject(params: {
10
+ project: FullProjectSelectWithRelationIds;
11
+ agentId: string;
12
+ }): AgentWithinContextOfProjectSelectWithRelationIds | null;
13
+ /**
14
+ * Get a sub-agent from the project definition
15
+ * Replaces direct database calls with lookup from pre-fetched project data
16
+ */
17
+ declare function getSubAgentFromProject(params: {
18
+ project: FullProjectSelectWithRelationIds;
19
+ agentId: string;
20
+ subAgentId?: string;
21
+ }): FullAgentSubAgentSelectWithRelationIds | null;
22
+ type InternalRelation = {
23
+ id: string;
24
+ name: string;
25
+ description: string | null;
26
+ relationType: 'transfer' | 'delegate';
27
+ relationId: string;
28
+ };
29
+ type ExternalRelation = {
30
+ externalAgent: {
31
+ id: string;
32
+ name: string;
33
+ description: string | null;
34
+ baseUrl: string;
35
+ credentialReferenceId?: string | null;
36
+ };
37
+ headers?: Record<string, string> | null;
38
+ relationId: string;
39
+ };
40
+ type TeamRelation = {
41
+ targetAgent: {
42
+ id: string;
43
+ name: string;
44
+ description: string | null;
45
+ };
46
+ targetAgentId: string;
47
+ headers?: Record<string, string> | null;
48
+ relationId: string;
49
+ };
50
+ type ParsedDelegateRelations = {
51
+ internalDelegateRelations: InternalRelation[];
52
+ externalRelations: ExternalRelation[];
53
+ teamRelations: TeamRelation[];
54
+ };
55
+ /**
56
+ * Extract transfer relations from a sub-agent's canTransferTo array
57
+ * Returns sub-agents that can be transferred to with their details
58
+ */
59
+ declare function extractTransferRelations(params: {
60
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
61
+ canTransferTo: CanRelateToInternalSubAgent[];
62
+ }): InternalRelation[];
63
+ /**
64
+ * Parse canDelegateTo array to separate internal, external, and team relations
65
+ * Handles the union type of string | CanDelegateToExternalAgent | CanDelegateToTeamAgent
66
+ */
67
+ declare function parseDelegateRelations(params: {
68
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
69
+ project: FullProjectSelectWithRelationIds;
70
+ canDelegateTo: CanDelegateToItem[];
71
+ }): ParsedDelegateRelations;
72
+ /**
73
+ * Get all relations for a sub-agent (transfers + delegates combined)
74
+ * Convenience function that combines extractTransferRelations and parseDelegateRelations
75
+ */
76
+ declare function getSubAgentRelations(params: {
77
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
78
+ project: FullProjectSelectWithRelationIds;
79
+ subAgent: FullAgentSubAgentSelectWithRelationIds;
80
+ }): {
81
+ transferRelations: InternalRelation[];
82
+ internalDelegateRelations: InternalRelation[];
83
+ externalRelations: ExternalRelation[];
84
+ teamRelations: TeamRelation[];
85
+ };
86
+ type ToolForAgent = {
87
+ toolId: string;
88
+ tool: ToolApiSelect;
89
+ selectedTools: string[] | null | undefined;
90
+ headers: Record<string, string> | null | undefined;
91
+ toolPolicies: Record<string, {
92
+ needsApproval?: boolean;
93
+ }> | null | undefined;
94
+ relationshipId: string | undefined;
95
+ };
96
+ /**
97
+ * Get tools for a sub-agent from their canUse array
98
+ * Resolves tool references from both agent-level and project-level tools
99
+ */
100
+ declare function getToolsForSubAgent(params: {
101
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
102
+ project: FullProjectSelectWithRelationIds;
103
+ subAgent: FullAgentSubAgentSelectWithRelationIds;
104
+ }): ToolForAgent[];
105
+ type DataComponentForAgent = DataComponentApiSelect;
106
+ type ArtifactComponentForAgent = ArtifactComponentApiSelect;
107
+ /**
108
+ * Get data components for a sub-agent
109
+ * Resolves data component references from project-level dataComponents
110
+ */
111
+ declare function getDataComponentsForSubAgent(params: {
112
+ project: FullProjectSelectWithRelationIds;
113
+ subAgent: FullAgentSubAgentSelectWithRelationIds;
114
+ }): DataComponentForAgent[];
115
+ /**
116
+ * Get artifact components for a sub-agent
117
+ * Resolves artifact component references from project-level artifactComponents
118
+ */
119
+ declare function getArtifactComponentsForSubAgent(params: {
120
+ project: FullProjectSelectWithRelationIds;
121
+ subAgent: FullAgentSubAgentSelectWithRelationIds;
122
+ }): ArtifactComponentForAgent[];
123
+ type TargetTransferRelation = {
124
+ id: string;
125
+ name: string;
126
+ description: string | null;
127
+ relationId: string;
128
+ };
129
+ type TargetExternalAgentRelation = {
130
+ externalAgent: ExternalAgentApiSelect;
131
+ headers?: Record<string, string> | null;
132
+ relationId: string;
133
+ };
134
+ /**
135
+ * Get transfer relations for a target sub-agent
136
+ * Used when building agent configurations that need to know what the target can transfer to
137
+ */
138
+ declare function getTransferRelationsForTargetSubAgent(params: {
139
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
140
+ subAgentId: string;
141
+ }): TargetTransferRelation[];
142
+ /**
143
+ * Get delegate relations (external agents) for a target sub-agent
144
+ * Used when building agent configurations that need to know what external agents the target can delegate to
145
+ */
146
+ declare function getExternalAgentRelationsForTargetSubAgent(params: {
147
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
148
+ project: FullProjectSelectWithRelationIds;
149
+ subAgentId: string;
150
+ }): TargetExternalAgentRelation[];
151
+ type RelationForDescription = {
152
+ id: string;
153
+ name: string;
154
+ description: string | null;
155
+ relationType?: 'transfer' | 'delegate';
156
+ relationId: string;
157
+ };
158
+ type ExternalRelationForDescription = {
159
+ externalAgent: {
160
+ id: string;
161
+ name: string;
162
+ description: string | null;
163
+ };
164
+ relationId: string;
165
+ };
166
+ type TeamRelationForDescription = {
167
+ targetAgent: {
168
+ id: string;
169
+ name: string;
170
+ description: string | null;
171
+ };
172
+ targetAgentId: string;
173
+ relationId: string;
174
+ };
175
+ type RelationsForDescriptionGeneration = {
176
+ internalRelations: RelationForDescription[];
177
+ externalRelations: ExternalRelationForDescription[];
178
+ teamRelations: TeamRelationForDescription[];
179
+ };
180
+ /**
181
+ * Build relation arrays from a sub-agent's canTransferTo and canDelegateTo
182
+ * Used for generating enhanced descriptions
183
+ */
184
+ declare function buildRelationsForDescription(params: {
185
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
186
+ project: FullProjectSelectWithRelationIds;
187
+ subAgent: FullAgentSubAgentSelectWithRelationIds;
188
+ }): RelationsForDescriptionGeneration;
189
+ /**
190
+ * Enhance an internal relation with a generated description
191
+ * Looks up the related sub-agent and builds relation data for description generation
192
+ */
193
+ declare function enhanceInternalRelation(params: {
194
+ relation: InternalRelation;
195
+ agent: AgentWithinContextOfProjectSelectWithRelationIds;
196
+ project: FullProjectSelectWithRelationIds;
197
+ }): InternalRelation;
198
+ /**
199
+ * Enhance a team relation with a generated description
200
+ * Looks up the team agent's default sub-agent and builds relation data for description generation
201
+ */
202
+ declare function enhanceTeamRelation(params: {
203
+ relation: TeamRelation;
204
+ project: FullProjectSelectWithRelationIds;
205
+ }): TeamRelation;
206
+ //#endregion
207
+ export { ArtifactComponentForAgent, DataComponentForAgent, ExternalRelation, ExternalRelationForDescription, InternalRelation, ParsedDelegateRelations, RelationForDescription, RelationsForDescriptionGeneration, TargetExternalAgentRelation, TargetTransferRelation, TeamRelation, TeamRelationForDescription, ToolForAgent, buildRelationsForDescription, enhanceInternalRelation, enhanceTeamRelation, extractTransferRelations, getAgentFromProject, getArtifactComponentsForSubAgent, getDataComponentsForSubAgent, getExternalAgentRelationsForTargetSubAgent, getSubAgentFromProject, getSubAgentRelations, getToolsForSubAgent, getTransferRelationsForTargetSubAgent, parseDelegateRelations };
@@ -0,0 +1,315 @@
1
+ import { getLogger } from "../logger.js";
2
+ import { generateDescriptionWithRelationData } from "../data/agents.js";
3
+
4
+ //#region src/utils/project.ts
5
+ const logger = getLogger("project-helper");
6
+ /**
7
+ * Get an agent from the project definition
8
+ * Replaces direct database calls with lookup from pre-fetched project data
9
+ */
10
+ function getAgentFromProject(params) {
11
+ const { project, agentId } = params;
12
+ const agent = project.agents[agentId];
13
+ if (!agent) {
14
+ logger.warn({ agentId }, "Agent not found in project");
15
+ return null;
16
+ }
17
+ return agent;
18
+ }
19
+ /**
20
+ * Get a sub-agent from the project definition
21
+ * Replaces direct database calls with lookup from pre-fetched project data
22
+ */
23
+ function getSubAgentFromProject(params) {
24
+ const { project, agentId, subAgentId } = params;
25
+ const agent = project.agents[agentId];
26
+ if (!agent) {
27
+ logger.warn({ agentId }, "Agent not found in project");
28
+ return null;
29
+ }
30
+ const targetSubAgentId = subAgentId || agent.defaultSubAgentId;
31
+ if (!targetSubAgentId) {
32
+ logger.warn({ agentId }, "No default sub-agent ID configured for agent");
33
+ return null;
34
+ }
35
+ const subAgent = agent.subAgents?.[targetSubAgentId];
36
+ if (!subAgent) {
37
+ logger.warn({
38
+ agentId,
39
+ subAgentId: targetSubAgentId
40
+ }, "Sub-agent not found in project");
41
+ return null;
42
+ }
43
+ return subAgent;
44
+ }
45
+ /**
46
+ * Extract transfer relations from a sub-agent's canTransferTo array
47
+ * Returns sub-agents that can be transferred to with their details
48
+ */
49
+ function extractTransferRelations(params) {
50
+ const { agent, canTransferTo } = params;
51
+ return canTransferTo.map((relation) => {
52
+ const targetSubAgent = agent.subAgents?.[relation.subAgentId];
53
+ if (targetSubAgent) return {
54
+ id: relation.subAgentId,
55
+ name: targetSubAgent.name,
56
+ description: targetSubAgent.description,
57
+ relationType: "transfer",
58
+ relationId: relation.subAgentSubAgentRelationId
59
+ };
60
+ return null;
61
+ }).filter((r) => r !== null);
62
+ }
63
+ /**
64
+ * Parse canDelegateTo array to separate internal, external, and team relations
65
+ * Handles the union type of string | CanDelegateToExternalAgent | CanDelegateToTeamAgent
66
+ */
67
+ function parseDelegateRelations(params) {
68
+ const { agent, project, canDelegateTo } = params;
69
+ const internalDelegateRelations = [];
70
+ const externalRelations = [];
71
+ const teamRelations = [];
72
+ for (const item of canDelegateTo) if ("subAgentId" in item) {
73
+ const targetSubAgent = agent.subAgents?.[item.subAgentId];
74
+ if (targetSubAgent) internalDelegateRelations.push({
75
+ id: item.subAgentId,
76
+ name: targetSubAgent.name,
77
+ description: targetSubAgent.description,
78
+ relationType: "delegate",
79
+ relationId: item.subAgentSubAgentRelationId
80
+ });
81
+ } else if ("externalAgentId" in item) {
82
+ const extAgentId = item.externalAgentId;
83
+ const extHeaders = item.headers;
84
+ const extRelationId = item.subAgentExternalAgentRelationId;
85
+ const externalAgent = agent.externalAgents?.[extAgentId] || project.externalAgents?.[extAgentId];
86
+ if (externalAgent) externalRelations.push({
87
+ externalAgent: {
88
+ id: extAgentId,
89
+ name: externalAgent.name,
90
+ description: externalAgent.description,
91
+ baseUrl: externalAgent.baseUrl,
92
+ credentialReferenceId: externalAgent.credentialReferenceId
93
+ },
94
+ headers: extHeaders,
95
+ relationId: extRelationId
96
+ });
97
+ } else if ("agentId" in item) {
98
+ const teamAgentId = item.agentId;
99
+ const teamHeaders = item.headers;
100
+ const teamRelationId = item.subAgentTeamAgentRelationId;
101
+ const teamAgent = agent.teamAgents?.[teamAgentId];
102
+ if (teamAgent) teamRelations.push({
103
+ targetAgent: {
104
+ id: teamAgentId,
105
+ name: teamAgent.name,
106
+ description: teamAgent.description
107
+ },
108
+ targetAgentId: teamAgentId,
109
+ headers: teamHeaders,
110
+ relationId: teamRelationId
111
+ });
112
+ }
113
+ return {
114
+ internalDelegateRelations,
115
+ externalRelations,
116
+ teamRelations
117
+ };
118
+ }
119
+ /**
120
+ * Get all relations for a sub-agent (transfers + delegates combined)
121
+ * Convenience function that combines extractTransferRelations and parseDelegateRelations
122
+ */
123
+ function getSubAgentRelations(params) {
124
+ const { agent, project, subAgent } = params;
125
+ const canTransferTo = subAgent.canTransferTo || [];
126
+ const canDelegateTo = subAgent.canDelegateTo || [];
127
+ const transferRelations = extractTransferRelations({
128
+ agent,
129
+ canTransferTo
130
+ });
131
+ const { internalDelegateRelations, externalRelations, teamRelations } = parseDelegateRelations({
132
+ agent,
133
+ project,
134
+ canDelegateTo
135
+ });
136
+ return {
137
+ transferRelations,
138
+ internalDelegateRelations,
139
+ externalRelations,
140
+ teamRelations
141
+ };
142
+ }
143
+ /**
144
+ * Get tools for a sub-agent from their canUse array
145
+ * Resolves tool references from both agent-level and project-level tools
146
+ */
147
+ function getToolsForSubAgent(params) {
148
+ const { agent, project, subAgent } = params;
149
+ return (subAgent.canUse || []).map((canUseItem) => {
150
+ const tool = agent.tools?.[canUseItem.toolId] || project.tools?.[canUseItem.toolId];
151
+ if (!tool) return null;
152
+ return {
153
+ toolId: canUseItem.toolId,
154
+ tool,
155
+ selectedTools: canUseItem.toolSelection,
156
+ headers: canUseItem.headers,
157
+ toolPolicies: canUseItem.toolPolicies,
158
+ relationshipId: canUseItem.agentToolRelationId
159
+ };
160
+ }).filter((item) => item !== null);
161
+ }
162
+ /**
163
+ * Get data components for a sub-agent
164
+ * Resolves data component references from project-level dataComponents
165
+ */
166
+ function getDataComponentsForSubAgent(params) {
167
+ const { project, subAgent } = params;
168
+ const dataComponentIds = subAgent.dataComponents || [];
169
+ const dataComponentsMap = project.dataComponents || {};
170
+ return dataComponentIds.map((id) => dataComponentsMap[id]).filter((c) => c !== null && c !== void 0);
171
+ }
172
+ /**
173
+ * Get artifact components for a sub-agent
174
+ * Resolves artifact component references from project-level artifactComponents
175
+ */
176
+ function getArtifactComponentsForSubAgent(params) {
177
+ const { project, subAgent } = params;
178
+ const artifactComponentIds = subAgent.artifactComponents || [];
179
+ const artifactComponentsMap = project.artifactComponents || {};
180
+ return artifactComponentIds.map((id) => artifactComponentsMap[id]).filter((c) => c !== null && c !== void 0);
181
+ }
182
+ /**
183
+ * Get transfer relations for a target sub-agent
184
+ * Used when building agent configurations that need to know what the target can transfer to
185
+ */
186
+ function getTransferRelationsForTargetSubAgent(params) {
187
+ const { agent, subAgentId } = params;
188
+ const targetSubAgent = agent.subAgents?.[subAgentId];
189
+ if (!targetSubAgent) return [];
190
+ return (targetSubAgent.canTransferTo || []).map((relation) => {
191
+ const target = agent.subAgents?.[relation.subAgentId];
192
+ return target ? {
193
+ id: relation.subAgentId,
194
+ name: target.name,
195
+ description: target.description,
196
+ relationId: relation.subAgentSubAgentRelationId
197
+ } : null;
198
+ }).filter((r) => r !== null);
199
+ }
200
+ /**
201
+ * Get delegate relations (external agents) for a target sub-agent
202
+ * Used when building agent configurations that need to know what external agents the target can delegate to
203
+ */
204
+ function getExternalAgentRelationsForTargetSubAgent(params) {
205
+ const { agent, project, subAgentId } = params;
206
+ const targetSubAgent = agent.subAgents?.[subAgentId];
207
+ if (!targetSubAgent) return [];
208
+ return (targetSubAgent.canDelegateTo || []).filter((item) => typeof item === "object" && item !== null && "externalAgentId" in item).map((item) => {
209
+ const extAgent = agent.externalAgents?.[item.externalAgentId] || project.externalAgents?.[item.externalAgentId];
210
+ return extAgent ? {
211
+ externalAgent: {
212
+ ...extAgent,
213
+ id: item.externalAgentId
214
+ },
215
+ headers: item.headers,
216
+ relationId: item.subAgentExternalAgentRelationId
217
+ } : null;
218
+ }).filter((r) => r !== null);
219
+ }
220
+ /**
221
+ * Build relation arrays from a sub-agent's canTransferTo and canDelegateTo
222
+ * Used for generating enhanced descriptions
223
+ */
224
+ function buildRelationsForDescription(params) {
225
+ const { agent, project, subAgent } = params;
226
+ const canTransferTo = subAgent.canTransferTo || [];
227
+ const canDelegateTo = subAgent.canDelegateTo || [];
228
+ const internalRelations = canTransferTo.map((relation) => {
229
+ const target = agent.subAgents?.[relation.subAgentId];
230
+ return target ? {
231
+ id: relation.subAgentId,
232
+ name: target.name,
233
+ description: target.description,
234
+ relationType: "transfer",
235
+ relationId: relation.subAgentSubAgentRelationId
236
+ } : null;
237
+ }).filter((r) => r !== null);
238
+ const externalRelations = [];
239
+ const teamRelations = [];
240
+ for (const item of canDelegateTo) if ("externalAgentId" in item) {
241
+ const extId = item.externalAgentId;
242
+ const extAgent = agent.externalAgents?.[extId] || project.externalAgents?.[extId];
243
+ if (extAgent) externalRelations.push({
244
+ externalAgent: {
245
+ id: extId,
246
+ name: extAgent.name,
247
+ description: extAgent.description
248
+ },
249
+ relationId: item.subAgentExternalAgentRelationId
250
+ });
251
+ } else if ("agentId" in item) {
252
+ const tId = item.agentId;
253
+ const tAgent = agent.teamAgents?.[tId];
254
+ if (tAgent) teamRelations.push({
255
+ targetAgent: {
256
+ id: tId,
257
+ name: tAgent.name,
258
+ description: tAgent.description
259
+ },
260
+ targetAgentId: tId,
261
+ relationId: item.subAgentTeamAgentRelationId
262
+ });
263
+ }
264
+ return {
265
+ internalRelations,
266
+ externalRelations,
267
+ teamRelations
268
+ };
269
+ }
270
+ /**
271
+ * Enhance an internal relation with a generated description
272
+ * Looks up the related sub-agent and builds relation data for description generation
273
+ */
274
+ function enhanceInternalRelation(params) {
275
+ const { relation, agent, project } = params;
276
+ const relatedSubAgent = agent.subAgents?.[relation.id];
277
+ if (!relatedSubAgent) return relation;
278
+ const { internalRelations, externalRelations, teamRelations } = buildRelationsForDescription({
279
+ agent,
280
+ project,
281
+ subAgent: relatedSubAgent
282
+ });
283
+ const enhancedDescription = generateDescriptionWithRelationData(relation.description || "", internalRelations, externalRelations, teamRelations);
284
+ return {
285
+ ...relation,
286
+ description: enhancedDescription
287
+ };
288
+ }
289
+ /**
290
+ * Enhance a team relation with a generated description
291
+ * Looks up the team agent's default sub-agent and builds relation data for description generation
292
+ */
293
+ function enhanceTeamRelation(params) {
294
+ const { relation, project } = params;
295
+ const teamAgent = project.agents[relation.targetAgentId];
296
+ if (!teamAgent?.defaultSubAgentId) return relation;
297
+ const defaultSubAgent = teamAgent.subAgents?.[teamAgent.defaultSubAgentId];
298
+ if (!defaultSubAgent) return relation;
299
+ const { internalRelations, externalRelations, teamRelations } = buildRelationsForDescription({
300
+ agent: teamAgent,
301
+ project,
302
+ subAgent: defaultSubAgent
303
+ });
304
+ const enhancedDescription = generateDescriptionWithRelationData(teamAgent.description || "", internalRelations, externalRelations, teamRelations);
305
+ return {
306
+ ...relation,
307
+ targetAgent: {
308
+ ...relation.targetAgent,
309
+ description: enhancedDescription
310
+ }
311
+ };
312
+ }
313
+
314
+ //#endregion
315
+ export { buildRelationsForDescription, enhanceInternalRelation, enhanceTeamRelation, extractTransferRelations, getAgentFromProject, getArtifactComponentsForSubAgent, getDataComponentsForSubAgent, getExternalAgentRelationsForTargetSubAgent, getSubAgentFromProject, getSubAgentRelations, getToolsForSubAgent, getTransferRelationsForTargetSubAgent, parseDelegateRelations };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20260114183157",
3
+ "version": "0.0.0-dev-20260115183047",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -41,7 +41,7 @@
41
41
  "hono": "^4.10.4",
42
42
  "jmespath": "^0.16.0",
43
43
  "llm-info": "^1.0.69",
44
- "@inkeep/agents-core": "^0.0.0-dev-20260114183157"
44
+ "@inkeep/agents-core": "^0.0.0-dev-20260115183047"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@hono/zod-openapi": "^1.1.5",