@inkeep/agents-manage-api 0.1.1 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +29 -17
- package/README.md +1 -1
- package/SUPPLEMENTAL_TERMS.md +40 -0
- package/dist/index.cjs +5083 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.js +5046 -35
- package/package.json +15 -13
- package/dist/ManagementServer.d.ts +0 -28
- package/dist/ManagementServer.d.ts.map +0 -1
- package/dist/ManagementServer.js +0 -41
- package/dist/__tests__/setup.d.ts +0 -2
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/setup.js +0 -26
- package/dist/__tests__/utils/testProject.d.ts +0 -18
- package/dist/__tests__/utils/testProject.d.ts.map +0 -1
- package/dist/__tests__/utils/testProject.js +0 -26
- package/dist/__tests__/utils/testRequest.d.ts +0 -2
- package/dist/__tests__/utils/testRequest.d.ts.map +0 -1
- package/dist/__tests__/utils/testRequest.js +0 -11
- package/dist/__tests__/utils/testTenant.d.ts +0 -64
- package/dist/__tests__/utils/testTenant.d.ts.map +0 -1
- package/dist/__tests__/utils/testTenant.js +0 -71
- package/dist/app.d.ts +0 -4
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -140
- package/dist/data/conversations.d.ts +0 -59
- package/dist/data/conversations.d.ts.map +0 -1
- package/dist/data/conversations.js +0 -216
- package/dist/data/db/clean.d.ts +0 -6
- package/dist/data/db/clean.d.ts.map +0 -1
- package/dist/data/db/clean.js +0 -77
- package/dist/data/db/dbClient.d.ts +0 -3
- package/dist/data/db/dbClient.d.ts.map +0 -1
- package/dist/data/db/dbClient.js +0 -13
- package/dist/data/graphFull.d.ts +0 -11
- package/dist/data/graphFull.d.ts.map +0 -1
- package/dist/data/graphFull.js +0 -90
- package/dist/data/graphFullClient.d.ts +0 -22
- package/dist/data/graphFullClient.d.ts.map +0 -1
- package/dist/data/graphFullClient.js +0 -189
- package/dist/data/tools.d.ts +0 -81
- package/dist/data/tools.d.ts.map +0 -1
- package/dist/data/tools.js +0 -266
- package/dist/env.d.ts +0 -41
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -32
- package/dist/middleware/auth.d.ts +0 -12
- package/dist/middleware/auth.d.ts.map +0 -1
- package/dist/middleware/auth.js +0 -36
- package/dist/openapi.d.ts +0 -2
- package/dist/openapi.d.ts.map +0 -1
- package/dist/openapi.js +0 -38
- package/dist/routes/agentArtifactComponents.d.ts +0 -4
- package/dist/routes/agentArtifactComponents.d.ts.map +0 -1
- package/dist/routes/agentArtifactComponents.js +0 -230
- package/dist/routes/agentDataComponents.d.ts +0 -4
- package/dist/routes/agentDataComponents.d.ts.map +0 -1
- package/dist/routes/agentDataComponents.js +0 -225
- package/dist/routes/agentGraph.d.ts +0 -4
- package/dist/routes/agentGraph.d.ts.map +0 -1
- package/dist/routes/agentGraph.js +0 -289
- package/dist/routes/agentRelations.d.ts +0 -4
- package/dist/routes/agentRelations.d.ts.map +0 -1
- package/dist/routes/agentRelations.js +0 -290
- package/dist/routes/agentToolRelations.d.ts +0 -4
- package/dist/routes/agentToolRelations.d.ts.map +0 -1
- package/dist/routes/agentToolRelations.js +0 -342
- package/dist/routes/agents.d.ts +0 -4
- package/dist/routes/agents.d.ts.map +0 -1
- package/dist/routes/agents.js +0 -213
- package/dist/routes/apiKeys.d.ts +0 -4
- package/dist/routes/apiKeys.d.ts.map +0 -1
- package/dist/routes/apiKeys.js +0 -236
- package/dist/routes/artifactComponents.d.ts +0 -4
- package/dist/routes/artifactComponents.d.ts.map +0 -1
- package/dist/routes/artifactComponents.js +0 -202
- package/dist/routes/contextConfigs.d.ts +0 -4
- package/dist/routes/contextConfigs.d.ts.map +0 -1
- package/dist/routes/contextConfigs.js +0 -181
- package/dist/routes/credentials.d.ts +0 -4
- package/dist/routes/credentials.d.ts.map +0 -1
- package/dist/routes/credentials.js +0 -219
- package/dist/routes/dataComponents.d.ts +0 -4
- package/dist/routes/dataComponents.d.ts.map +0 -1
- package/dist/routes/dataComponents.js +0 -188
- package/dist/routes/externalAgents.d.ts +0 -4
- package/dist/routes/externalAgents.d.ts.map +0 -1
- package/dist/routes/externalAgents.js +0 -216
- package/dist/routes/graphFull.d.ts +0 -4
- package/dist/routes/graphFull.d.ts.map +0 -1
- package/dist/routes/graphFull.js +0 -248
- package/dist/routes/index.d.ts +0 -4
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/index.js +0 -37
- package/dist/routes/oauth.d.ts +0 -14
- package/dist/routes/oauth.d.ts.map +0 -1
- package/dist/routes/oauth.js +0 -191
- package/dist/routes/projects.d.ts +0 -4
- package/dist/routes/projects.d.ts.map +0 -1
- package/dist/routes/projects.js +0 -221
- package/dist/routes/tools.d.ts +0 -4
- package/dist/routes/tools.d.ts.map +0 -1
- package/dist/routes/tools.js +0 -547
- package/dist/utils/auth-detection.d.ts +0 -22
- package/dist/utils/auth-detection.d.ts.map +0 -1
- package/dist/utils/auth-detection.js +0 -149
- package/dist/utils/oauth-service.d.ts +0 -88
- package/dist/utils/oauth-service.d.ts.map +0 -1
- package/dist/utils/oauth-service.js +0 -240
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
|
|
4
|
-
import { AgentToolRelationApiInsertSchema, AgentToolRelationApiSelectSchema, AgentToolRelationApiUpdateSchema, ErrorResponseSchema, IdParamsSchema, ListResponseSchema, PaginationQueryParamsSchema, SingleResponseSchema, TenantProjectParamsSchema, getAgentToolRelationById, getAgentToolRelationByAgent, getAgentToolRelationByTool, listAgentToolRelations, getToolsForAgent, getAgentsForTool, createAgentToolRelation, updateAgentToolRelation, deleteAgentToolRelation, } from '@inkeep/agents-core';
|
|
5
|
-
import dbClient from '../data/db/dbClient.js';
|
|
6
|
-
const app = new OpenAPIHono();
|
|
7
|
-
// List agent tool relations
|
|
8
|
-
app.openapi(createRoute({
|
|
9
|
-
method: 'get',
|
|
10
|
-
path: '/',
|
|
11
|
-
summary: 'List Agent Tool Relations',
|
|
12
|
-
operationId: 'list-agent-tool-relations',
|
|
13
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
14
|
-
request: {
|
|
15
|
-
params: TenantProjectParamsSchema,
|
|
16
|
-
query: PaginationQueryParamsSchema.extend({
|
|
17
|
-
agentId: z.string().optional(),
|
|
18
|
-
toolId: z.string().optional(),
|
|
19
|
-
}),
|
|
20
|
-
},
|
|
21
|
-
responses: {
|
|
22
|
-
200: {
|
|
23
|
-
description: 'List of agent tool relations retrieved successfully',
|
|
24
|
-
content: {
|
|
25
|
-
'application/json': {
|
|
26
|
-
schema: ListResponseSchema(AgentToolRelationApiSelectSchema),
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
...commonGetErrorResponses,
|
|
31
|
-
},
|
|
32
|
-
}), async (c) => {
|
|
33
|
-
const { tenantId, projectId } = c.req.valid('param');
|
|
34
|
-
const { page, limit, agentId, toolId } = c.req.valid('query');
|
|
35
|
-
let result;
|
|
36
|
-
// Filter by agent if provided
|
|
37
|
-
if (agentId) {
|
|
38
|
-
const dbResult = await getAgentToolRelationByAgent(dbClient)({
|
|
39
|
-
scopes: { tenantId, projectId },
|
|
40
|
-
agentId,
|
|
41
|
-
pagination: { page, limit },
|
|
42
|
-
});
|
|
43
|
-
result = {
|
|
44
|
-
data: dbResult.data,
|
|
45
|
-
pagination: dbResult.pagination,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
// Filter by tool if provided
|
|
49
|
-
else if (toolId) {
|
|
50
|
-
const dbResult = await getAgentToolRelationByTool(dbClient)({
|
|
51
|
-
scopes: { tenantId, projectId },
|
|
52
|
-
toolId,
|
|
53
|
-
pagination: { page, limit },
|
|
54
|
-
});
|
|
55
|
-
result = {
|
|
56
|
-
data: dbResult.data,
|
|
57
|
-
pagination: dbResult.pagination,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
// Default: get all agent tool relations
|
|
61
|
-
else {
|
|
62
|
-
const dbResult = await listAgentToolRelations(dbClient)({
|
|
63
|
-
scopes: { tenantId, projectId },
|
|
64
|
-
pagination: { page, limit },
|
|
65
|
-
});
|
|
66
|
-
result = {
|
|
67
|
-
data: dbResult.data,
|
|
68
|
-
pagination: dbResult.pagination,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return c.json(result);
|
|
72
|
-
});
|
|
73
|
-
// Get agent tool relation by ID
|
|
74
|
-
app.openapi(createRoute({
|
|
75
|
-
method: 'get',
|
|
76
|
-
path: '/{id}',
|
|
77
|
-
summary: 'Get Agent Tool Relation',
|
|
78
|
-
operationId: 'get-agent-tool-relation',
|
|
79
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
80
|
-
request: {
|
|
81
|
-
params: TenantProjectParamsSchema.merge(IdParamsSchema),
|
|
82
|
-
},
|
|
83
|
-
responses: {
|
|
84
|
-
200: {
|
|
85
|
-
description: 'Agent tool relation found',
|
|
86
|
-
content: {
|
|
87
|
-
'application/json': {
|
|
88
|
-
schema: SingleResponseSchema(AgentToolRelationApiSelectSchema),
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
...commonGetErrorResponses,
|
|
93
|
-
},
|
|
94
|
-
}), async (c) => {
|
|
95
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
96
|
-
const agentToolRelation = await getAgentToolRelationById(dbClient)({
|
|
97
|
-
scopes: { tenantId, projectId },
|
|
98
|
-
relationId: id,
|
|
99
|
-
});
|
|
100
|
-
if (!agentToolRelation) {
|
|
101
|
-
throw createApiError({
|
|
102
|
-
code: 'not_found',
|
|
103
|
-
message: 'Agent tool relation not found',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return c.json({ data: agentToolRelation });
|
|
107
|
-
});
|
|
108
|
-
// Get tools for a specific agent (with tool details)
|
|
109
|
-
app.openapi(createRoute({
|
|
110
|
-
method: 'get',
|
|
111
|
-
path: '/agent/{agentId}/tools',
|
|
112
|
-
summary: 'Get Tools for Agent',
|
|
113
|
-
operationId: 'get-tools-for-agent',
|
|
114
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
115
|
-
request: {
|
|
116
|
-
params: TenantProjectParamsSchema.extend({
|
|
117
|
-
agentId: z.string(),
|
|
118
|
-
}),
|
|
119
|
-
query: PaginationQueryParamsSchema,
|
|
120
|
-
},
|
|
121
|
-
responses: {
|
|
122
|
-
200: {
|
|
123
|
-
description: 'Tools for agent retrieved successfully',
|
|
124
|
-
content: {
|
|
125
|
-
'application/json': {
|
|
126
|
-
schema: ListResponseSchema(AgentToolRelationApiSelectSchema),
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
...commonGetErrorResponses,
|
|
131
|
-
},
|
|
132
|
-
}), async (c) => {
|
|
133
|
-
const { tenantId, projectId, agentId } = c.req.valid('param');
|
|
134
|
-
const { page, limit } = c.req.valid('query');
|
|
135
|
-
const dbResult = await getToolsForAgent(dbClient)({
|
|
136
|
-
scopes: { tenantId, projectId },
|
|
137
|
-
agentId,
|
|
138
|
-
pagination: { page, limit },
|
|
139
|
-
});
|
|
140
|
-
const result = {
|
|
141
|
-
data: dbResult.data,
|
|
142
|
-
pagination: dbResult.pagination,
|
|
143
|
-
};
|
|
144
|
-
return c.json(result);
|
|
145
|
-
});
|
|
146
|
-
// Get agents for a specific tool (with agent details)
|
|
147
|
-
app.openapi(createRoute({
|
|
148
|
-
method: 'get',
|
|
149
|
-
path: '/tool/{toolId}/agents',
|
|
150
|
-
summary: 'Get Agents for Tool',
|
|
151
|
-
operationId: 'get-agents-for-tool',
|
|
152
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
153
|
-
request: {
|
|
154
|
-
params: TenantProjectParamsSchema.extend({
|
|
155
|
-
toolId: z.string(),
|
|
156
|
-
}),
|
|
157
|
-
query: PaginationQueryParamsSchema,
|
|
158
|
-
},
|
|
159
|
-
responses: {
|
|
160
|
-
200: {
|
|
161
|
-
description: 'Agents for tool retrieved successfully',
|
|
162
|
-
content: {
|
|
163
|
-
'application/json': {
|
|
164
|
-
schema: ListResponseSchema(AgentToolRelationApiSelectSchema),
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
...commonGetErrorResponses,
|
|
169
|
-
},
|
|
170
|
-
}), async (c) => {
|
|
171
|
-
const { tenantId, projectId, toolId } = c.req.valid('param');
|
|
172
|
-
const { page, limit } = c.req.valid('query');
|
|
173
|
-
const dbResult = await getAgentsForTool(dbClient)({
|
|
174
|
-
scopes: { tenantId, projectId },
|
|
175
|
-
toolId,
|
|
176
|
-
pagination: { page, limit },
|
|
177
|
-
});
|
|
178
|
-
const result = {
|
|
179
|
-
data: dbResult.data,
|
|
180
|
-
pagination: dbResult.pagination,
|
|
181
|
-
};
|
|
182
|
-
return c.json(result);
|
|
183
|
-
});
|
|
184
|
-
// Create agent tool relation
|
|
185
|
-
app.openapi(createRoute({
|
|
186
|
-
method: 'post',
|
|
187
|
-
path: '/',
|
|
188
|
-
summary: 'Create Agent Tool Relation',
|
|
189
|
-
operationId: 'create-agent-tool-relation',
|
|
190
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
191
|
-
request: {
|
|
192
|
-
params: TenantProjectParamsSchema,
|
|
193
|
-
body: {
|
|
194
|
-
content: {
|
|
195
|
-
'application/json': {
|
|
196
|
-
schema: AgentToolRelationApiInsertSchema,
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
responses: {
|
|
202
|
-
201: {
|
|
203
|
-
description: 'Agent tool relation created successfully',
|
|
204
|
-
content: {
|
|
205
|
-
'application/json': {
|
|
206
|
-
schema: SingleResponseSchema(AgentToolRelationApiSelectSchema),
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
...commonGetErrorResponses,
|
|
211
|
-
},
|
|
212
|
-
}), async (c) => {
|
|
213
|
-
const { tenantId, projectId } = c.req.valid('param');
|
|
214
|
-
const body = c.req.valid('json');
|
|
215
|
-
// Check if relation already exists (prevent duplicates)
|
|
216
|
-
const existingRelations = await listAgentToolRelations(dbClient)({
|
|
217
|
-
scopes: { tenantId, projectId },
|
|
218
|
-
pagination: { limit: 1000 },
|
|
219
|
-
});
|
|
220
|
-
const isDuplicate = existingRelations.data.some((relation) => {
|
|
221
|
-
const typedRelation = relation;
|
|
222
|
-
return typedRelation.agentId === body.agentId && typedRelation.toolId === body.toolId;
|
|
223
|
-
});
|
|
224
|
-
if (isDuplicate) {
|
|
225
|
-
throw createApiError({
|
|
226
|
-
code: 'unprocessable_entity',
|
|
227
|
-
message: 'Agent tool relation already exists',
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
const agentToolRelation = await createAgentToolRelation(dbClient)({
|
|
232
|
-
scopes: { tenantId, projectId },
|
|
233
|
-
data: body,
|
|
234
|
-
});
|
|
235
|
-
return c.json({ data: agentToolRelation }, 201);
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
// Handle foreign key constraint violations
|
|
239
|
-
if (error instanceof Error && (error.message.includes('FOREIGN KEY constraint failed') ||
|
|
240
|
-
error.message.includes('foreign key constraint') ||
|
|
241
|
-
error.message.includes('SQLITE_CONSTRAINT_FOREIGNKEY') ||
|
|
242
|
-
error.code === 'SQLITE_CONSTRAINT_FOREIGNKEY' ||
|
|
243
|
-
error?.cause?.code === 'SQLITE_CONSTRAINT_FOREIGNKEY')) {
|
|
244
|
-
throw createApiError({
|
|
245
|
-
code: 'bad_request',
|
|
246
|
-
message: 'Invalid agent ID or tool ID - referenced entity does not exist',
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
throw error;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
// Update agent tool relation
|
|
253
|
-
app.openapi(createRoute({
|
|
254
|
-
method: 'put',
|
|
255
|
-
path: '/{id}',
|
|
256
|
-
summary: 'Update Agent Tool Relation',
|
|
257
|
-
operationId: 'update-agent-tool-relation',
|
|
258
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
259
|
-
request: {
|
|
260
|
-
params: TenantProjectParamsSchema.merge(IdParamsSchema),
|
|
261
|
-
body: {
|
|
262
|
-
content: {
|
|
263
|
-
'application/json': {
|
|
264
|
-
schema: AgentToolRelationApiUpdateSchema,
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
responses: {
|
|
270
|
-
200: {
|
|
271
|
-
description: 'Agent tool relation updated successfully',
|
|
272
|
-
content: {
|
|
273
|
-
'application/json': {
|
|
274
|
-
schema: SingleResponseSchema(AgentToolRelationApiSelectSchema),
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
...commonGetErrorResponses,
|
|
279
|
-
},
|
|
280
|
-
}), async (c) => {
|
|
281
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
282
|
-
console.log('id', id);
|
|
283
|
-
const body = await c.req.valid('json');
|
|
284
|
-
// Check if there are any fields to update
|
|
285
|
-
if (Object.keys(body).length === 0) {
|
|
286
|
-
throw createApiError({
|
|
287
|
-
code: 'bad_request',
|
|
288
|
-
message: 'No fields to update',
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
console.log('body', body);
|
|
292
|
-
const updatedAgentToolRelation = await updateAgentToolRelation(dbClient)({
|
|
293
|
-
scopes: { tenantId, projectId },
|
|
294
|
-
relationId: id,
|
|
295
|
-
data: body,
|
|
296
|
-
});
|
|
297
|
-
if (!updatedAgentToolRelation) {
|
|
298
|
-
throw createApiError({
|
|
299
|
-
code: 'not_found',
|
|
300
|
-
message: 'Agent tool relation not found',
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
return c.json({ data: updatedAgentToolRelation });
|
|
304
|
-
});
|
|
305
|
-
// Delete agent tool relation
|
|
306
|
-
app.openapi(createRoute({
|
|
307
|
-
method: 'delete',
|
|
308
|
-
path: '/{id}',
|
|
309
|
-
summary: 'Delete Agent Tool Relation',
|
|
310
|
-
operationId: 'delete-agent-tool-relation',
|
|
311
|
-
tags: ['CRUD Agent Tool Relations'],
|
|
312
|
-
request: {
|
|
313
|
-
params: TenantProjectParamsSchema.merge(IdParamsSchema),
|
|
314
|
-
},
|
|
315
|
-
responses: {
|
|
316
|
-
204: {
|
|
317
|
-
description: 'Agent tool relation deleted successfully',
|
|
318
|
-
},
|
|
319
|
-
404: {
|
|
320
|
-
description: 'Agent tool relation not found',
|
|
321
|
-
content: {
|
|
322
|
-
'application/json': {
|
|
323
|
-
schema: ErrorResponseSchema,
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
}), async (c) => {
|
|
329
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
330
|
-
const deleted = await deleteAgentToolRelation(dbClient)({
|
|
331
|
-
scopes: { tenantId, projectId },
|
|
332
|
-
relationId: id,
|
|
333
|
-
});
|
|
334
|
-
if (!deleted) {
|
|
335
|
-
throw createApiError({
|
|
336
|
-
code: 'not_found',
|
|
337
|
-
message: 'Agent tool relation not found',
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
return c.body(null, 204);
|
|
341
|
-
});
|
|
342
|
-
export default app;
|
package/dist/routes/agents.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAqB7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AAkP9B,eAAe,GAAG,CAAC"}
|
package/dist/routes/agents.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
|
-
import { commonGetErrorResponses, createApiError } from '@inkeep/agents-core';
|
|
4
|
-
import { listAgentsPaginated, getAgentById, createAgent, updateAgent, deleteAgent, AgentApiInsertSchema, AgentApiSelectSchema, AgentApiUpdateSchema, ErrorResponseSchema, ListResponseSchema, PaginationQueryParamsSchema, SingleResponseSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, } from '@inkeep/agents-core';
|
|
5
|
-
import dbClient from '../data/db/dbClient.js';
|
|
6
|
-
const app = new OpenAPIHono();
|
|
7
|
-
app.openapi(createRoute({
|
|
8
|
-
method: 'get',
|
|
9
|
-
path: '/',
|
|
10
|
-
summary: 'List Agents',
|
|
11
|
-
operationId: 'list-agents',
|
|
12
|
-
tags: ['CRUD Agent'],
|
|
13
|
-
request: {
|
|
14
|
-
params: TenantProjectParamsSchema,
|
|
15
|
-
query: PaginationQueryParamsSchema,
|
|
16
|
-
},
|
|
17
|
-
responses: {
|
|
18
|
-
200: {
|
|
19
|
-
description: 'List of agents retrieved successfully',
|
|
20
|
-
content: {
|
|
21
|
-
'application/json': {
|
|
22
|
-
schema: ListResponseSchema(AgentApiSelectSchema),
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
...commonGetErrorResponses,
|
|
27
|
-
},
|
|
28
|
-
}), async (c) => {
|
|
29
|
-
const { tenantId, projectId } = c.req.valid('param');
|
|
30
|
-
const page = Number(c.req.query('page')) || 1;
|
|
31
|
-
const limit = Math.min(Number(c.req.query('limit')) || 10, 100);
|
|
32
|
-
const result = await listAgentsPaginated(dbClient)({
|
|
33
|
-
scopes: { tenantId, projectId },
|
|
34
|
-
pagination: { page, limit },
|
|
35
|
-
});
|
|
36
|
-
// Add type field to all agents in the response
|
|
37
|
-
const dataWithType = {
|
|
38
|
-
...result,
|
|
39
|
-
data: result.data.map((agent) => ({
|
|
40
|
-
...agent,
|
|
41
|
-
type: 'internal',
|
|
42
|
-
})),
|
|
43
|
-
};
|
|
44
|
-
return c.json(dataWithType);
|
|
45
|
-
});
|
|
46
|
-
app.openapi(createRoute({
|
|
47
|
-
method: 'get',
|
|
48
|
-
path: '/{id}',
|
|
49
|
-
summary: 'Get Agent',
|
|
50
|
-
operationId: 'get-agent-by-id',
|
|
51
|
-
tags: ['CRUD Agent'],
|
|
52
|
-
request: {
|
|
53
|
-
params: TenantProjectIdParamsSchema,
|
|
54
|
-
},
|
|
55
|
-
responses: {
|
|
56
|
-
200: {
|
|
57
|
-
description: 'Agent found',
|
|
58
|
-
content: {
|
|
59
|
-
'application/json': {
|
|
60
|
-
schema: SingleResponseSchema(AgentApiSelectSchema),
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
...commonGetErrorResponses,
|
|
65
|
-
},
|
|
66
|
-
}), async (c) => {
|
|
67
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
68
|
-
const agent = await getAgentById(dbClient)({
|
|
69
|
-
scopes: { tenantId, projectId },
|
|
70
|
-
agentId: id,
|
|
71
|
-
});
|
|
72
|
-
if (!agent) {
|
|
73
|
-
throw createApiError({
|
|
74
|
-
code: 'not_found',
|
|
75
|
-
message: 'Agent not found',
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
// Add type field to the agent response
|
|
79
|
-
const agentWithType = {
|
|
80
|
-
...agent,
|
|
81
|
-
type: 'internal',
|
|
82
|
-
};
|
|
83
|
-
return c.json({ data: agentWithType });
|
|
84
|
-
});
|
|
85
|
-
app.openapi(createRoute({
|
|
86
|
-
method: 'post',
|
|
87
|
-
path: '/',
|
|
88
|
-
summary: 'Create Agent',
|
|
89
|
-
operationId: 'create-agent',
|
|
90
|
-
tags: ['CRUD Agent'],
|
|
91
|
-
request: {
|
|
92
|
-
params: TenantProjectParamsSchema,
|
|
93
|
-
body: {
|
|
94
|
-
content: {
|
|
95
|
-
'application/json': {
|
|
96
|
-
schema: AgentApiInsertSchema,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
responses: {
|
|
102
|
-
201: {
|
|
103
|
-
description: 'Agent created successfully',
|
|
104
|
-
content: {
|
|
105
|
-
'application/json': {
|
|
106
|
-
schema: SingleResponseSchema(AgentApiSelectSchema),
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
...commonGetErrorResponses,
|
|
111
|
-
},
|
|
112
|
-
}), async (c) => {
|
|
113
|
-
const { tenantId, projectId } = c.req.valid('param');
|
|
114
|
-
const body = c.req.valid('json');
|
|
115
|
-
const agentId = body.id ? String(body.id) : nanoid();
|
|
116
|
-
const agent = await createAgent(dbClient)({
|
|
117
|
-
...body,
|
|
118
|
-
id: agentId,
|
|
119
|
-
tenantId,
|
|
120
|
-
projectId,
|
|
121
|
-
});
|
|
122
|
-
// Add type field to the agent response
|
|
123
|
-
const agentWithType = {
|
|
124
|
-
...agent,
|
|
125
|
-
type: 'internal',
|
|
126
|
-
};
|
|
127
|
-
return c.json({ data: agentWithType }, 201);
|
|
128
|
-
});
|
|
129
|
-
app.openapi(createRoute({
|
|
130
|
-
method: 'put',
|
|
131
|
-
path: '/{id}',
|
|
132
|
-
summary: 'Update Agent',
|
|
133
|
-
operationId: 'update-agent',
|
|
134
|
-
tags: ['CRUD Agent'],
|
|
135
|
-
request: {
|
|
136
|
-
params: TenantProjectIdParamsSchema,
|
|
137
|
-
body: {
|
|
138
|
-
content: {
|
|
139
|
-
'application/json': {
|
|
140
|
-
schema: AgentApiUpdateSchema,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
responses: {
|
|
146
|
-
200: {
|
|
147
|
-
description: 'Agent updated successfully',
|
|
148
|
-
content: {
|
|
149
|
-
'application/json': {
|
|
150
|
-
schema: SingleResponseSchema(AgentApiSelectSchema),
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
...commonGetErrorResponses,
|
|
155
|
-
},
|
|
156
|
-
}), async (c) => {
|
|
157
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
158
|
-
const body = c.req.valid('json');
|
|
159
|
-
const updatedAgent = await updateAgent(dbClient)({
|
|
160
|
-
scopes: { tenantId, projectId },
|
|
161
|
-
agentId: id,
|
|
162
|
-
data: body,
|
|
163
|
-
});
|
|
164
|
-
if (!updatedAgent) {
|
|
165
|
-
throw createApiError({
|
|
166
|
-
code: 'not_found',
|
|
167
|
-
message: 'Agent not found',
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
// Add type field to the agent response
|
|
171
|
-
const agentWithType = {
|
|
172
|
-
...updatedAgent,
|
|
173
|
-
type: 'internal',
|
|
174
|
-
};
|
|
175
|
-
return c.json({ data: agentWithType });
|
|
176
|
-
});
|
|
177
|
-
app.openapi(createRoute({
|
|
178
|
-
method: 'delete',
|
|
179
|
-
path: '/{id}',
|
|
180
|
-
summary: 'Delete Agent',
|
|
181
|
-
operationId: 'delete-agent',
|
|
182
|
-
tags: ['CRUD Agent'],
|
|
183
|
-
request: {
|
|
184
|
-
params: TenantProjectIdParamsSchema,
|
|
185
|
-
},
|
|
186
|
-
responses: {
|
|
187
|
-
204: {
|
|
188
|
-
description: 'Agent deleted successfully',
|
|
189
|
-
},
|
|
190
|
-
404: {
|
|
191
|
-
description: 'Agent not found',
|
|
192
|
-
content: {
|
|
193
|
-
'application/json': {
|
|
194
|
-
schema: ErrorResponseSchema,
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
}), async (c) => {
|
|
200
|
-
const { tenantId, projectId, id } = c.req.valid('param');
|
|
201
|
-
const deleted = await deleteAgent(dbClient)({
|
|
202
|
-
scopes: { tenantId, projectId },
|
|
203
|
-
agentId: id,
|
|
204
|
-
});
|
|
205
|
-
if (!deleted) {
|
|
206
|
-
throw createApiError({
|
|
207
|
-
code: 'not_found',
|
|
208
|
-
message: 'Agent not found',
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return c.body(null, 204);
|
|
212
|
-
});
|
|
213
|
-
export default app;
|
package/dist/routes/apiKeys.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiKeys.d.ts","sourceRoot":"","sources":["../../src/routes/apiKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuB7D,QAAA,MAAM,GAAG,0CAAoB,CAAC;AA4Q9B,eAAe,GAAG,CAAC"}
|