@inkeep/agents-manage-api 0.0.0-dev-20250910232631

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