@inkeep/agents-manage-api 0.1.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.
Files changed (110) hide show
  1. package/README.md +176 -0
  2. package/dist/ManagementServer.d.ts +28 -0
  3. package/dist/ManagementServer.d.ts.map +1 -0
  4. package/dist/ManagementServer.js +41 -0
  5. package/dist/__tests__/setup.d.ts +2 -0
  6. package/dist/__tests__/setup.d.ts.map +1 -0
  7. package/dist/__tests__/setup.js +26 -0
  8. package/dist/__tests__/utils/testProject.d.ts +18 -0
  9. package/dist/__tests__/utils/testProject.d.ts.map +1 -0
  10. package/dist/__tests__/utils/testProject.js +26 -0
  11. package/dist/__tests__/utils/testRequest.d.ts +2 -0
  12. package/dist/__tests__/utils/testRequest.d.ts.map +1 -0
  13. package/dist/__tests__/utils/testRequest.js +11 -0
  14. package/dist/__tests__/utils/testTenant.d.ts +64 -0
  15. package/dist/__tests__/utils/testTenant.d.ts.map +1 -0
  16. package/dist/__tests__/utils/testTenant.js +71 -0
  17. package/dist/app.d.ts +4 -0
  18. package/dist/app.d.ts.map +1 -0
  19. package/dist/app.js +140 -0
  20. package/dist/data/conversations.d.ts +59 -0
  21. package/dist/data/conversations.d.ts.map +1 -0
  22. package/dist/data/conversations.js +216 -0
  23. package/dist/data/db/clean.d.ts +6 -0
  24. package/dist/data/db/clean.d.ts.map +1 -0
  25. package/dist/data/db/clean.js +77 -0
  26. package/dist/data/db/dbClient.d.ts +3 -0
  27. package/dist/data/db/dbClient.d.ts.map +1 -0
  28. package/dist/data/db/dbClient.js +13 -0
  29. package/dist/data/graphFull.d.ts +11 -0
  30. package/dist/data/graphFull.d.ts.map +1 -0
  31. package/dist/data/graphFull.js +90 -0
  32. package/dist/data/graphFullClient.d.ts +22 -0
  33. package/dist/data/graphFullClient.d.ts.map +1 -0
  34. package/dist/data/graphFullClient.js +189 -0
  35. package/dist/data/tools.d.ts +81 -0
  36. package/dist/data/tools.d.ts.map +1 -0
  37. package/dist/data/tools.js +266 -0
  38. package/dist/env.d.ts +41 -0
  39. package/dist/env.d.ts.map +1 -0
  40. package/dist/env.js +59 -0
  41. package/dist/index.d.ts +4 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +42 -0
  44. package/dist/logger.d.ts +4 -0
  45. package/dist/logger.d.ts.map +1 -0
  46. package/dist/logger.js +32 -0
  47. package/dist/middleware/auth.d.ts +12 -0
  48. package/dist/middleware/auth.d.ts.map +1 -0
  49. package/dist/middleware/auth.js +36 -0
  50. package/dist/openapi.d.ts +2 -0
  51. package/dist/openapi.d.ts.map +1 -0
  52. package/dist/openapi.js +38 -0
  53. package/dist/routes/agentArtifactComponents.d.ts +4 -0
  54. package/dist/routes/agentArtifactComponents.d.ts.map +1 -0
  55. package/dist/routes/agentArtifactComponents.js +230 -0
  56. package/dist/routes/agentDataComponents.d.ts +4 -0
  57. package/dist/routes/agentDataComponents.d.ts.map +1 -0
  58. package/dist/routes/agentDataComponents.js +225 -0
  59. package/dist/routes/agentGraph.d.ts +4 -0
  60. package/dist/routes/agentGraph.d.ts.map +1 -0
  61. package/dist/routes/agentGraph.js +289 -0
  62. package/dist/routes/agentRelations.d.ts +4 -0
  63. package/dist/routes/agentRelations.d.ts.map +1 -0
  64. package/dist/routes/agentRelations.js +290 -0
  65. package/dist/routes/agentToolRelations.d.ts +4 -0
  66. package/dist/routes/agentToolRelations.d.ts.map +1 -0
  67. package/dist/routes/agentToolRelations.js +342 -0
  68. package/dist/routes/agents.d.ts +4 -0
  69. package/dist/routes/agents.d.ts.map +1 -0
  70. package/dist/routes/agents.js +213 -0
  71. package/dist/routes/apiKeys.d.ts +4 -0
  72. package/dist/routes/apiKeys.d.ts.map +1 -0
  73. package/dist/routes/apiKeys.js +236 -0
  74. package/dist/routes/artifactComponents.d.ts +4 -0
  75. package/dist/routes/artifactComponents.d.ts.map +1 -0
  76. package/dist/routes/artifactComponents.js +202 -0
  77. package/dist/routes/contextConfigs.d.ts +4 -0
  78. package/dist/routes/contextConfigs.d.ts.map +1 -0
  79. package/dist/routes/contextConfigs.js +181 -0
  80. package/dist/routes/credentials.d.ts +4 -0
  81. package/dist/routes/credentials.d.ts.map +1 -0
  82. package/dist/routes/credentials.js +219 -0
  83. package/dist/routes/dataComponents.d.ts +4 -0
  84. package/dist/routes/dataComponents.d.ts.map +1 -0
  85. package/dist/routes/dataComponents.js +188 -0
  86. package/dist/routes/externalAgents.d.ts +4 -0
  87. package/dist/routes/externalAgents.d.ts.map +1 -0
  88. package/dist/routes/externalAgents.js +216 -0
  89. package/dist/routes/graphFull.d.ts +4 -0
  90. package/dist/routes/graphFull.d.ts.map +1 -0
  91. package/dist/routes/graphFull.js +248 -0
  92. package/dist/routes/index.d.ts +4 -0
  93. package/dist/routes/index.d.ts.map +1 -0
  94. package/dist/routes/index.js +37 -0
  95. package/dist/routes/oauth.d.ts +14 -0
  96. package/dist/routes/oauth.d.ts.map +1 -0
  97. package/dist/routes/oauth.js +191 -0
  98. package/dist/routes/projects.d.ts +4 -0
  99. package/dist/routes/projects.d.ts.map +1 -0
  100. package/dist/routes/projects.js +221 -0
  101. package/dist/routes/tools.d.ts +4 -0
  102. package/dist/routes/tools.d.ts.map +1 -0
  103. package/dist/routes/tools.js +547 -0
  104. package/dist/utils/auth-detection.d.ts +22 -0
  105. package/dist/utils/auth-detection.d.ts.map +1 -0
  106. package/dist/utils/auth-detection.js +149 -0
  107. package/dist/utils/oauth-service.d.ts +88 -0
  108. package/dist/utils/oauth-service.d.ts.map +1 -0
  109. package/dist/utils/oauth-service.js +240 -0
  110. package/package.json +68 -0
@@ -0,0 +1,289 @@
1
+ // @ts-nocheck
2
+ import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
3
+ import { nanoid } from 'nanoid';
4
+ import { z } from 'zod';
5
+ import { listAgentGraphs } from '@inkeep/agents-core';
6
+ import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
7
+ import { createAgentGraph, deleteAgentGraph, getAgentGraph, getFullGraphDefinition, getGraphAgentInfos, updateAgentGraph, AgentGraphApiInsertSchema, AgentGraphApiSelectSchema, AgentGraphApiUpdateSchema, ErrorResponseSchema, FullGraphDefinitionSchema, IdParamsSchema, ListResponseSchema, PaginationQueryParamsSchema, SingleResponseSchema, TenantProjectParamsSchema, } from '@inkeep/agents-core';
8
+ import dbClient from '../data/db/dbClient.js';
9
+ const app = new OpenAPIHono();
10
+ // List agent graphs
11
+ app.openapi(createRoute({
12
+ method: 'get',
13
+ path: '/',
14
+ summary: 'List Agent Graphs',
15
+ operationId: 'list-agent-graphs',
16
+ tags: ['CRUD Agent Graph'],
17
+ request: {
18
+ params: TenantProjectParamsSchema,
19
+ query: PaginationQueryParamsSchema,
20
+ },
21
+ responses: {
22
+ 200: {
23
+ description: 'List of agent graphs retrieved successfully',
24
+ content: {
25
+ 'application/json': {
26
+ schema: ListResponseSchema(AgentGraphApiSelectSchema),
27
+ },
28
+ },
29
+ },
30
+ ...commonGetErrorResponses,
31
+ },
32
+ }), async (c) => {
33
+ const { tenantId, projectId } = c.req.valid('param');
34
+ const page = Number(c.req.query('page')) || 1;
35
+ const limit = Math.min(Number(c.req.query('limit')) || 10, 100);
36
+ const graphs = await listAgentGraphs(dbClient)({ scopes: { tenantId, projectId } });
37
+ return c.json({
38
+ data: graphs,
39
+ pagination: {
40
+ page,
41
+ limit,
42
+ total: graphs.length,
43
+ pages: Math.ceil(graphs.length / limit),
44
+ },
45
+ });
46
+ });
47
+ // Get agent graph by ID
48
+ app.openapi(createRoute({
49
+ method: 'get',
50
+ path: '/{id}',
51
+ summary: 'Get Agent Graph',
52
+ operationId: 'get-agent-graph',
53
+ tags: ['CRUD Agent Graph'],
54
+ request: {
55
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
56
+ },
57
+ responses: {
58
+ 200: {
59
+ description: 'Agent graph found',
60
+ content: {
61
+ 'application/json': {
62
+ schema: SingleResponseSchema(AgentGraphApiSelectSchema),
63
+ },
64
+ },
65
+ },
66
+ ...commonGetErrorResponses,
67
+ },
68
+ }), async (c) => {
69
+ const { tenantId, projectId, id } = c.req.valid('param');
70
+ const graph = await getAgentGraph(dbClient)({
71
+ scopes: { tenantId, projectId },
72
+ graphId: id,
73
+ });
74
+ if (!graph) {
75
+ throw createApiError({
76
+ code: 'not_found',
77
+ message: 'Agent graph not found',
78
+ });
79
+ }
80
+ return c.json({ data: graph });
81
+ });
82
+ // Get related agent infos for a specific agent within a graph
83
+ app.openapi(createRoute({
84
+ method: 'get',
85
+ path: '/{graphId}/agents/{agentId}/related',
86
+ summary: 'Get Related Agent Infos',
87
+ operationId: 'get-related-agent-infos',
88
+ tags: ['CRUD Agent Graph'],
89
+ request: {
90
+ params: TenantProjectParamsSchema.extend({
91
+ graphId: z.string(),
92
+ agentId: z.string(),
93
+ }),
94
+ },
95
+ responses: {
96
+ 200: {
97
+ description: 'Related agent infos retrieved successfully',
98
+ content: {
99
+ 'application/json': {
100
+ schema: ListResponseSchema(z.object({
101
+ id: z.string(),
102
+ name: z.string(),
103
+ description: z.string(),
104
+ })),
105
+ },
106
+ },
107
+ },
108
+ ...commonGetErrorResponses,
109
+ },
110
+ }), async (c) => {
111
+ const { tenantId, projectId, graphId, agentId } = c.req.valid('param');
112
+ const relatedAgents = await getGraphAgentInfos(dbClient)({
113
+ scopes: { tenantId, projectId },
114
+ graphId,
115
+ agentId,
116
+ });
117
+ return c.json({
118
+ data: relatedAgents,
119
+ pagination: {
120
+ page: 1,
121
+ limit: relatedAgents.length,
122
+ total: relatedAgents.length,
123
+ pages: 1,
124
+ },
125
+ });
126
+ });
127
+ // Get full graph definition
128
+ app.openapi(createRoute({
129
+ method: 'get',
130
+ path: '/{graphId}/full',
131
+ summary: 'Get Full Graph Definition',
132
+ operationId: 'get-full-graph-definition',
133
+ tags: ['CRUD Agent Graph'],
134
+ request: {
135
+ params: TenantProjectParamsSchema.extend({
136
+ graphId: z.string(),
137
+ }),
138
+ },
139
+ responses: {
140
+ 200: {
141
+ description: 'Full graph definition retrieved successfully',
142
+ content: {
143
+ 'application/json': {
144
+ schema: SingleResponseSchema(FullGraphDefinitionSchema),
145
+ },
146
+ },
147
+ },
148
+ ...commonGetErrorResponses,
149
+ },
150
+ }), async (c) => {
151
+ const { tenantId, projectId, graphId } = c.req.valid('param');
152
+ const fullGraph = await getFullGraphDefinition(dbClient)({
153
+ scopes: { tenantId, projectId },
154
+ graphId,
155
+ });
156
+ if (!fullGraph) {
157
+ throw createApiError({
158
+ code: 'not_found',
159
+ message: 'Agent graph not found',
160
+ });
161
+ }
162
+ return c.json({ data: fullGraph });
163
+ });
164
+ // Create agent graph
165
+ app.openapi(createRoute({
166
+ method: 'post',
167
+ path: '/',
168
+ summary: 'Create Agent Graph',
169
+ operationId: 'create-agent-graph',
170
+ tags: ['CRUD Agent Graph'],
171
+ request: {
172
+ params: TenantProjectParamsSchema,
173
+ body: {
174
+ content: {
175
+ 'application/json': {
176
+ schema: AgentGraphApiInsertSchema,
177
+ },
178
+ },
179
+ },
180
+ },
181
+ responses: {
182
+ 201: {
183
+ description: 'Agent graph created successfully',
184
+ content: {
185
+ 'application/json': {
186
+ schema: SingleResponseSchema(AgentGraphApiSelectSchema),
187
+ },
188
+ },
189
+ },
190
+ ...commonGetErrorResponses,
191
+ },
192
+ }), async (c) => {
193
+ const { tenantId, projectId } = c.req.valid('param');
194
+ const validatedBody = c.req.valid('json');
195
+ const graph = await createAgentGraph(dbClient)({
196
+ tenantId,
197
+ projectId,
198
+ id: validatedBody.id || nanoid(),
199
+ name: validatedBody.name,
200
+ defaultAgentId: validatedBody.defaultAgentId,
201
+ contextConfigId: validatedBody.contextConfigId ?? undefined,
202
+ });
203
+ return c.json({ data: graph }, 201);
204
+ });
205
+ // Update agent graph
206
+ app.openapi(createRoute({
207
+ method: 'put',
208
+ path: '/{id}',
209
+ summary: 'Update Agent Graph',
210
+ operationId: 'update-agent-graph',
211
+ tags: ['CRUD Agent Graph'],
212
+ request: {
213
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
214
+ body: {
215
+ content: {
216
+ 'application/json': {
217
+ schema: AgentGraphApiUpdateSchema,
218
+ },
219
+ },
220
+ },
221
+ },
222
+ responses: {
223
+ 200: {
224
+ description: 'Agent graph updated successfully',
225
+ content: {
226
+ 'application/json': {
227
+ schema: SingleResponseSchema(AgentGraphApiSelectSchema),
228
+ },
229
+ },
230
+ },
231
+ ...commonGetErrorResponses,
232
+ },
233
+ }), async (c) => {
234
+ const { tenantId, projectId, id } = c.req.valid('param');
235
+ const validatedBody = c.req.valid('json');
236
+ const updatedGraph = await updateAgentGraph(dbClient)({
237
+ scopes: { tenantId, projectId },
238
+ graphId: id,
239
+ data: {
240
+ defaultAgentId: validatedBody.defaultAgentId,
241
+ contextConfigId: validatedBody.contextConfigId ?? undefined,
242
+ },
243
+ });
244
+ if (!updatedGraph) {
245
+ throw createApiError({
246
+ code: 'not_found',
247
+ message: 'Agent graph not found',
248
+ });
249
+ }
250
+ return c.json({ data: updatedGraph });
251
+ });
252
+ // Delete agent graph
253
+ app.openapi(createRoute({
254
+ method: 'delete',
255
+ path: '/{id}',
256
+ summary: 'Delete Agent Graph',
257
+ operationId: 'delete-agent-graph',
258
+ tags: ['CRUD Agent Graph'],
259
+ request: {
260
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
261
+ },
262
+ responses: {
263
+ 204: {
264
+ description: 'Agent graph deleted successfully',
265
+ },
266
+ 404: {
267
+ description: 'Agent graph not found',
268
+ content: {
269
+ 'application/json': {
270
+ schema: ErrorResponseSchema,
271
+ },
272
+ },
273
+ },
274
+ },
275
+ }), async (c) => {
276
+ const { tenantId, projectId, id } = c.req.valid('param');
277
+ const deleted = await deleteAgentGraph(dbClient)({
278
+ scopes: { tenantId, projectId },
279
+ graphId: id,
280
+ });
281
+ if (!deleted) {
282
+ throw createApiError({
283
+ code: 'not_found',
284
+ message: 'Agent graph not found',
285
+ });
286
+ }
287
+ return c.body(null, 204);
288
+ });
289
+ export default app;
@@ -0,0 +1,4 @@
1
+ import { OpenAPIHono } from '@hono/zod-openapi';
2
+ declare const app: OpenAPIHono<import("hono").Env, {}, "/">;
3
+ export default app;
4
+ //# sourceMappingURL=agentRelations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentRelations.d.ts","sourceRoot":"","sources":["../../src/routes/agentRelations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA6B7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAwU9B,eAAe,GAAG,CAAC"}
@@ -0,0 +1,290 @@
1
+ import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
2
+ import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
3
+ import { ErrorResponseSchema, IdParamsSchema, ListResponseSchema, PaginationQueryParamsSchema, SingleResponseSchema, TenantProjectParamsSchema, AgentRelationQuerySchema, AgentRelationApiInsertSchema, AgentRelationApiUpdateSchema, AgentRelationApiSelectSchema, getAgentRelationsBySource, getAgentRelationsByTarget, getExternalAgentRelations, listAgentRelations, getAgentRelationById, validateExternalAgent, validateInternalAgent, createAgentRelation, updateAgentRelation, deleteAgentRelation, } from '@inkeep/agents-core';
4
+ import dbClient from '../data/db/dbClient.js';
5
+ import { nanoid } from 'nanoid';
6
+ const app = new OpenAPIHono();
7
+ // List agent relations
8
+ app.openapi(createRoute({
9
+ method: 'get',
10
+ path: '/',
11
+ summary: 'List Agent Relations',
12
+ operationId: 'list-agent-relations',
13
+ tags: ['CRUD Agent Relations'],
14
+ request: {
15
+ params: TenantProjectParamsSchema,
16
+ query: PaginationQueryParamsSchema.merge(AgentRelationQuerySchema),
17
+ },
18
+ responses: {
19
+ 200: {
20
+ description: 'List of agent relations retrieved successfully',
21
+ content: {
22
+ 'application/json': {
23
+ schema: ListResponseSchema(AgentRelationApiSelectSchema),
24
+ },
25
+ },
26
+ },
27
+ ...commonGetErrorResponses,
28
+ },
29
+ }), async (c) => {
30
+ const { tenantId, projectId } = c.req.valid('param');
31
+ const { page = 1, limit = 10, sourceAgentId, targetAgentId, externalAgentId, } = c.req.valid('query');
32
+ const pageNum = Number(page);
33
+ const limitNum = Math.min(Number(limit), 100);
34
+ try {
35
+ let result;
36
+ if (sourceAgentId) {
37
+ const rawResult = await getAgentRelationsBySource(dbClient)({
38
+ scopes: { tenantId, projectId },
39
+ sourceAgentId,
40
+ pagination: { page: pageNum, limit: limitNum },
41
+ });
42
+ result = { ...rawResult, data: rawResult.data };
43
+ }
44
+ else if (targetAgentId) {
45
+ const rawResult = await getAgentRelationsByTarget(dbClient)({
46
+ scopes: { tenantId, projectId },
47
+ targetAgentId,
48
+ pagination: { page: pageNum, limit: limitNum },
49
+ });
50
+ result = { ...rawResult, data: rawResult.data };
51
+ }
52
+ else if (externalAgentId) {
53
+ const rawResult = await getExternalAgentRelations(dbClient)({
54
+ scopes: { tenantId, projectId },
55
+ externalAgentId,
56
+ pagination: { page: pageNum, limit: limitNum },
57
+ });
58
+ result = { ...rawResult, data: rawResult.data };
59
+ }
60
+ else {
61
+ const rawResult = await listAgentRelations(dbClient)({
62
+ scopes: { tenantId, projectId },
63
+ pagination: { page: pageNum, limit: limitNum },
64
+ });
65
+ result = { ...rawResult, data: rawResult.data };
66
+ }
67
+ return c.json(result);
68
+ }
69
+ catch (error) {
70
+ throw createApiError({
71
+ code: 'internal_server_error',
72
+ message: 'Failed to retrieve agent relations',
73
+ });
74
+ }
75
+ });
76
+ // Get agent relation by ID
77
+ app.openapi(createRoute({
78
+ method: 'get',
79
+ path: '/{id}',
80
+ summary: 'Get Agent Relation',
81
+ operationId: 'get-agent-relation-by-id',
82
+ tags: ['CRUD Agent Relations'],
83
+ request: {
84
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
85
+ },
86
+ responses: {
87
+ 200: {
88
+ description: 'Agent relation found',
89
+ content: {
90
+ 'application/json': {
91
+ schema: SingleResponseSchema(AgentRelationApiSelectSchema),
92
+ },
93
+ },
94
+ },
95
+ ...commonGetErrorResponses,
96
+ },
97
+ }), async (c) => {
98
+ const { tenantId, projectId, id } = c.req.valid('param');
99
+ const agentRelation = (await getAgentRelationById(dbClient)({
100
+ scopes: { tenantId, projectId },
101
+ relationId: id,
102
+ }));
103
+ if (!agentRelation) {
104
+ throw createApiError({
105
+ code: 'not_found',
106
+ message: 'Agent relation not found',
107
+ });
108
+ }
109
+ return c.json({ data: agentRelation });
110
+ });
111
+ // Create agent relation
112
+ app.openapi(createRoute({
113
+ method: 'post',
114
+ path: '/',
115
+ summary: 'Create Agent Relation',
116
+ operationId: 'create-agent-relation',
117
+ tags: ['CRUD Agent Relations'],
118
+ request: {
119
+ params: TenantProjectParamsSchema,
120
+ body: {
121
+ content: {
122
+ 'application/json': {
123
+ schema: AgentRelationApiInsertSchema,
124
+ },
125
+ },
126
+ },
127
+ },
128
+ responses: {
129
+ 201: {
130
+ description: 'Agent relation created successfully',
131
+ content: {
132
+ 'application/json': {
133
+ schema: SingleResponseSchema(AgentRelationApiSelectSchema),
134
+ },
135
+ },
136
+ },
137
+ ...commonGetErrorResponses,
138
+ },
139
+ }), async (c) => {
140
+ const { tenantId, projectId } = c.req.valid('param');
141
+ const body = await c.req.valid('json');
142
+ // Determine if this is an external agent relationship
143
+ const isExternalAgent = body.externalAgentId != null;
144
+ // Validate that the target agent exists in the appropriate table
145
+ if (isExternalAgent && body.externalAgentId) {
146
+ // Check if external agent exists
147
+ const externalAgentExists = await validateExternalAgent(dbClient)({
148
+ scopes: { tenantId, projectId },
149
+ agentId: body.externalAgentId,
150
+ });
151
+ if (!externalAgentExists) {
152
+ throw createApiError({
153
+ code: 'bad_request',
154
+ message: `External agent with ID ${body.externalAgentId} not found`,
155
+ });
156
+ }
157
+ }
158
+ if (!isExternalAgent && body.targetAgentId) {
159
+ // Check if internal agent exists
160
+ const internalAgentExists = await validateInternalAgent(dbClient)({
161
+ scopes: { tenantId, projectId },
162
+ agentId: body.targetAgentId,
163
+ });
164
+ if (!internalAgentExists) {
165
+ throw createApiError({
166
+ code: 'bad_request',
167
+ message: `Internal agent with ID ${body.targetAgentId} not found`,
168
+ });
169
+ }
170
+ }
171
+ // Check if relation already exists (prevent duplicates)
172
+ const existingRelations = await listAgentRelations(dbClient)({
173
+ scopes: { tenantId, projectId },
174
+ pagination: { page: 1, limit: 1000 },
175
+ });
176
+ const isDuplicate = existingRelations.data.some((relation) => {
177
+ if (relation.graphId !== body.graphId || relation.sourceAgentId !== body.sourceAgentId) {
178
+ return false;
179
+ }
180
+ // Check for duplicate based on relationship type
181
+ if (isExternalAgent) {
182
+ return relation.externalAgentId === body.externalAgentId;
183
+ }
184
+ return relation.targetAgentId === body.targetAgentId;
185
+ });
186
+ if (isDuplicate) {
187
+ const agentType = isExternalAgent ? 'external' : 'internal';
188
+ throw createApiError({
189
+ code: 'unprocessable_entity',
190
+ message: `A relation between these agents (${agentType}) in this graph already exists`,
191
+ });
192
+ }
193
+ // Create the relation with the correct data structure
194
+ const relationData = {
195
+ graphId: body.graphId,
196
+ tenantId,
197
+ id: nanoid(),
198
+ projectId,
199
+ sourceAgentId: body.sourceAgentId,
200
+ targetAgentId: isExternalAgent ? undefined : body.targetAgentId,
201
+ externalAgentId: isExternalAgent ? body.externalAgentId : undefined,
202
+ relationType: body.relationType,
203
+ };
204
+ const agentRelation = await createAgentRelation(dbClient)({
205
+ ...relationData,
206
+ });
207
+ return c.json({ data: agentRelation }, 201);
208
+ });
209
+ // Update agent relation
210
+ app.openapi(createRoute({
211
+ method: 'put',
212
+ path: '/{id}',
213
+ summary: 'Update Agent Relation',
214
+ operationId: 'update-agent-relation',
215
+ tags: ['CRUD Agent Relations'],
216
+ request: {
217
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
218
+ body: {
219
+ content: {
220
+ 'application/json': {
221
+ schema: AgentRelationApiUpdateSchema,
222
+ },
223
+ },
224
+ },
225
+ },
226
+ responses: {
227
+ 200: {
228
+ description: 'Agent relation updated successfully',
229
+ content: {
230
+ 'application/json': {
231
+ schema: SingleResponseSchema(AgentRelationApiSelectSchema),
232
+ },
233
+ },
234
+ },
235
+ ...commonGetErrorResponses,
236
+ },
237
+ }), async (c) => {
238
+ const { tenantId, projectId, id } = c.req.valid('param');
239
+ const body = await c.req.valid('json');
240
+ const updatedAgentRelation = await updateAgentRelation(dbClient)({
241
+ scopes: { tenantId, projectId },
242
+ relationId: id,
243
+ data: body,
244
+ });
245
+ if (!updatedAgentRelation) {
246
+ throw createApiError({
247
+ code: 'not_found',
248
+ message: 'Agent relation not found',
249
+ });
250
+ }
251
+ return c.json({ data: updatedAgentRelation });
252
+ });
253
+ // Delete agent relation
254
+ app.openapi(createRoute({
255
+ method: 'delete',
256
+ path: '/{id}',
257
+ summary: 'Delete Agent Relation',
258
+ operationId: 'delete-agent-relation',
259
+ tags: ['CRUD Agent Relations'],
260
+ request: {
261
+ params: TenantProjectParamsSchema.merge(IdParamsSchema),
262
+ },
263
+ responses: {
264
+ 204: {
265
+ description: 'Agent relation deleted successfully',
266
+ },
267
+ 404: {
268
+ description: 'Agent relation not found',
269
+ content: {
270
+ 'application/json': {
271
+ schema: ErrorResponseSchema,
272
+ },
273
+ },
274
+ },
275
+ },
276
+ }), async (c) => {
277
+ const { tenantId, projectId, id } = c.req.valid('param');
278
+ const deleted = await deleteAgentRelation(dbClient)({
279
+ scopes: { tenantId, projectId },
280
+ relationId: id,
281
+ });
282
+ if (!deleted) {
283
+ throw createApiError({
284
+ code: 'not_found',
285
+ message: 'Agent relation not found',
286
+ });
287
+ }
288
+ return c.body(null, 204);
289
+ });
290
+ export default app;
@@ -0,0 +1,4 @@
1
+ import { OpenAPIHono } from '@hono/zod-openapi';
2
+ declare const app: OpenAPIHono<import("hono").Env, {}, "/">;
3
+ export default app;
4
+ //# sourceMappingURL=agentToolRelations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentToolRelations.d.ts","sourceRoot":"","sources":["../../src/routes/agentToolRelations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA0B7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AA0Y9B,eAAe,GAAG,CAAC"}