@inkeep/agents-manage-api 0.39.5 → 0.41.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.
- package/dist/create-app.d.ts +21 -0
- package/dist/create-app.js +144 -0
- package/dist/data/agentFull.d.ts +15 -0
- package/dist/data/agentFull.js +84 -0
- package/dist/data/conversations.d.ts +77 -0
- package/dist/data/conversations.js +152 -0
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +61 -0
- package/dist/env.js +55 -0
- package/dist/factory.d.ts +17 -2
- package/dist/factory.js +35 -2
- package/dist/index.d.ts +163 -57
- package/dist/index.js +8 -5
- package/dist/initialization.d.ts +6 -0
- package/dist/initialization.js +79 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +3 -0
- package/dist/middleware/auth.d.ts +24 -0
- package/dist/middleware/auth.js +64 -0
- package/dist/middleware/error-handler.d.ts +12 -0
- package/dist/middleware/error-handler.js +88 -0
- package/dist/middleware/require-permission.d.ts +19 -0
- package/dist/middleware/require-permission.js +80 -0
- package/dist/middleware/session-auth.d.ts +6 -0
- package/dist/middleware/session-auth.js +26 -0
- package/dist/middleware/tenant-access.d.ts +12 -0
- package/dist/middleware/tenant-access.js +54 -0
- package/dist/openapi.d.ts +7 -0
- package/dist/openapi.js +157 -0
- package/dist/routes/agent.d.ts +9 -0
- package/dist/routes/agent.js +244 -0
- package/dist/routes/agentFull.d.ts +9 -0
- package/dist/routes/agentFull.js +188 -0
- package/dist/routes/agentToolRelations.d.ts +9 -0
- package/dist/routes/agentToolRelations.js +284 -0
- package/dist/routes/apiKeys.d.ts +9 -0
- package/dist/routes/apiKeys.js +217 -0
- package/dist/routes/artifactComponents.d.ts +9 -0
- package/dist/routes/artifactComponents.js +206 -0
- package/dist/routes/cliAuth.d.ts +9 -0
- package/dist/routes/cliAuth.js +60 -0
- package/dist/routes/contextConfigs.d.ts +9 -0
- package/dist/routes/contextConfigs.js +175 -0
- package/dist/routes/conversations.d.ts +7 -0
- package/dist/routes/conversations.js +59 -0
- package/dist/routes/credentialStores.d.ts +9 -0
- package/dist/routes/credentialStores.js +81 -0
- package/dist/routes/credentials.d.ts +9 -0
- package/dist/routes/credentials.js +204 -0
- package/dist/routes/dataComponents.d.ts +9 -0
- package/dist/routes/dataComponents.js +188 -0
- package/dist/routes/externalAgents.d.ts +9 -0
- package/dist/routes/externalAgents.js +195 -0
- package/dist/routes/functionTools.d.ts +9 -0
- package/dist/routes/functionTools.js +252 -0
- package/dist/routes/functions.d.ts +9 -0
- package/dist/routes/functions.js +281 -0
- package/dist/routes/index.d.ts +7 -0
- package/dist/routes/index.js +54 -0
- package/dist/routes/invitations.d.ts +9 -0
- package/dist/routes/invitations.js +41 -0
- package/dist/routes/mcp.d.ts +7 -0
- package/dist/routes/mcp.js +45 -0
- package/dist/routes/mcpCatalog.d.ts +13 -0
- package/dist/routes/mcpCatalog.js +454 -0
- package/dist/routes/oauth.d.ts +10 -0
- package/dist/routes/oauth.js +314 -0
- package/dist/routes/playgroundToken.d.ts +9 -0
- package/dist/routes/playgroundToken.js +108 -0
- package/dist/routes/projectFull.d.ts +9 -0
- package/dist/routes/projectFull.js +193 -0
- package/dist/routes/projects.d.ts +9 -0
- package/dist/routes/projects.js +188 -0
- package/dist/routes/shared.d.ts +93 -0
- package/dist/routes/shared.js +44 -0
- package/dist/routes/signoz.d.ts +10 -0
- package/dist/routes/signoz.js +155 -0
- package/dist/routes/subAgentArtifactComponents.d.ts +9 -0
- package/dist/routes/subAgentArtifactComponents.js +198 -0
- package/dist/routes/subAgentDataComponents.d.ts +9 -0
- package/dist/routes/subAgentDataComponents.js +197 -0
- package/dist/routes/subAgentExternalAgentRelations.d.ts +9 -0
- package/dist/routes/subAgentExternalAgentRelations.js +213 -0
- package/dist/routes/subAgentRelations.d.ts +9 -0
- package/dist/routes/subAgentRelations.js +259 -0
- package/dist/routes/subAgentTeamAgentRelations.d.ts +9 -0
- package/dist/routes/subAgentTeamAgentRelations.js +213 -0
- package/dist/routes/subAgentToolRelations.d.ts +9 -0
- package/dist/routes/subAgentToolRelations.js +284 -0
- package/dist/routes/subAgents.d.ts +9 -0
- package/dist/routes/subAgents.js +210 -0
- package/dist/routes/thirdPartyMCPServers.d.ts +14 -0
- package/dist/routes/thirdPartyMCPServers.js +72 -0
- package/dist/routes/tools.d.ts +9 -0
- package/dist/routes/tools.js +256 -0
- package/dist/routes/userOrganizations.d.ts +9 -0
- package/dist/routes/userOrganizations.js +58 -0
- package/dist/sso-helpers.d.ts +20 -0
- package/dist/sso-helpers.js +51 -0
- package/dist/types/app.d.ts +47 -0
- package/dist/types/app.js +1 -0
- package/dist/utils/cors.d.ts +33 -0
- package/dist/utils/cors.js +98 -0
- package/dist/utils/oauth-service.d.ts +71 -0
- package/dist/utils/oauth-service.js +106 -0
- package/dist/utils/signoz-helpers.d.ts +9 -0
- package/dist/utils/signoz-helpers.js +33 -0
- package/dist/utils/temp-api-keys.d.ts +17 -0
- package/dist/utils/temp-api-keys.js +26 -0
- package/package.json +6 -13
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/factory2.d.ts +0 -41
- package/dist/factory2.d.ts.map +0 -1
- package/dist/factory2.js +0 -37085
- package/dist/factory2.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import dbClient_default from "../data/db/dbClient.js";
|
|
2
|
+
import { requirePermission } from "../middleware/require-permission.js";
|
|
3
|
+
import { speakeasyOffsetLimitPagination } from "./shared.js";
|
|
4
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
5
|
+
import { AgentApiInsertSchema, AgentApiUpdateSchema, AgentListResponse, AgentResponse, AgentWithinContextOfProjectResponse, ErrorResponseSchema, PaginationQueryParamsSchema, RelatedAgentInfoListResponse, TenantProjectAgentParamsSchema, TenantProjectAgentSubAgentParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createAgent, createApiError, deleteAgent, generateId, getAgentById, getAgentSubAgentInfos, getFullAgentDefinition, listAgentsPaginated, updateAgent } from "@inkeep/agents-core";
|
|
6
|
+
|
|
7
|
+
//#region src/routes/agent.ts
|
|
8
|
+
const app = new OpenAPIHono();
|
|
9
|
+
app.use("/", async (c, next) => {
|
|
10
|
+
if (c.req.method === "POST") return requirePermission({ agent: ["create"] })(c, next);
|
|
11
|
+
return next();
|
|
12
|
+
});
|
|
13
|
+
app.use("/:id", async (c, next) => {
|
|
14
|
+
if (c.req.method === "PUT") return requirePermission({ agent: ["update"] })(c, next);
|
|
15
|
+
if (c.req.method === "DELETE") return requirePermission({ agent: ["delete"] })(c, next);
|
|
16
|
+
return next();
|
|
17
|
+
});
|
|
18
|
+
app.openapi(createRoute({
|
|
19
|
+
method: "get",
|
|
20
|
+
path: "/",
|
|
21
|
+
summary: "List Agents",
|
|
22
|
+
operationId: "list-agents",
|
|
23
|
+
tags: ["Agents"],
|
|
24
|
+
request: {
|
|
25
|
+
params: TenantProjectParamsSchema,
|
|
26
|
+
query: PaginationQueryParamsSchema
|
|
27
|
+
},
|
|
28
|
+
responses: {
|
|
29
|
+
200: {
|
|
30
|
+
description: "List of agents retrieved successfully",
|
|
31
|
+
content: { "application/json": { schema: AgentListResponse } }
|
|
32
|
+
},
|
|
33
|
+
...commonGetErrorResponses
|
|
34
|
+
},
|
|
35
|
+
...speakeasyOffsetLimitPagination
|
|
36
|
+
}), async (c) => {
|
|
37
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
38
|
+
const page = Number(c.req.query("page")) || 1;
|
|
39
|
+
const limit = Math.min(Number(c.req.query("limit")) || 10, 100);
|
|
40
|
+
const result = await listAgentsPaginated(dbClient_default)({
|
|
41
|
+
scopes: {
|
|
42
|
+
tenantId,
|
|
43
|
+
projectId
|
|
44
|
+
},
|
|
45
|
+
pagination: {
|
|
46
|
+
page,
|
|
47
|
+
limit
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return c.json(result);
|
|
51
|
+
});
|
|
52
|
+
app.openapi(createRoute({
|
|
53
|
+
method: "get",
|
|
54
|
+
path: "/{id}",
|
|
55
|
+
summary: "Get Agent",
|
|
56
|
+
operationId: "get-agent",
|
|
57
|
+
tags: ["Agents"],
|
|
58
|
+
request: { params: TenantProjectIdParamsSchema },
|
|
59
|
+
responses: {
|
|
60
|
+
200: {
|
|
61
|
+
description: "Agent found",
|
|
62
|
+
content: { "application/json": { schema: AgentResponse } }
|
|
63
|
+
},
|
|
64
|
+
...commonGetErrorResponses
|
|
65
|
+
}
|
|
66
|
+
}), async (c) => {
|
|
67
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
68
|
+
const agent = await getAgentById(dbClient_default)({ scopes: {
|
|
69
|
+
tenantId,
|
|
70
|
+
projectId,
|
|
71
|
+
agentId: id
|
|
72
|
+
} });
|
|
73
|
+
if (!agent) throw createApiError({
|
|
74
|
+
code: "not_found",
|
|
75
|
+
message: "Agent not found"
|
|
76
|
+
});
|
|
77
|
+
return c.json({ data: agent });
|
|
78
|
+
});
|
|
79
|
+
app.openapi(createRoute({
|
|
80
|
+
method: "get",
|
|
81
|
+
path: "/{agentId}/sub-agents/{subAgentId}/related",
|
|
82
|
+
summary: "Get Related Agent Infos",
|
|
83
|
+
operationId: "get-related-agent-infos",
|
|
84
|
+
tags: ["Agent"],
|
|
85
|
+
request: { params: TenantProjectAgentSubAgentParamsSchema },
|
|
86
|
+
responses: {
|
|
87
|
+
200: {
|
|
88
|
+
description: "Related agent infos retrieved successfully",
|
|
89
|
+
content: { "application/json": { schema: RelatedAgentInfoListResponse } }
|
|
90
|
+
},
|
|
91
|
+
...commonGetErrorResponses
|
|
92
|
+
}
|
|
93
|
+
}), async (c) => {
|
|
94
|
+
const { tenantId, projectId, agentId, subAgentId } = c.req.valid("param");
|
|
95
|
+
const relatedAgents = await getAgentSubAgentInfos(dbClient_default)({
|
|
96
|
+
scopes: {
|
|
97
|
+
tenantId,
|
|
98
|
+
projectId
|
|
99
|
+
},
|
|
100
|
+
agentId,
|
|
101
|
+
subAgentId
|
|
102
|
+
});
|
|
103
|
+
return c.json({
|
|
104
|
+
data: relatedAgents,
|
|
105
|
+
pagination: {
|
|
106
|
+
page: 1,
|
|
107
|
+
limit: relatedAgents.length,
|
|
108
|
+
total: relatedAgents.length,
|
|
109
|
+
pages: 1
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
app.openapi(createRoute({
|
|
114
|
+
method: "get",
|
|
115
|
+
path: "/{agentId}/full",
|
|
116
|
+
summary: "Get Full Agent Definition",
|
|
117
|
+
operationId: "get-full-agent-definition",
|
|
118
|
+
tags: ["Agent"],
|
|
119
|
+
request: { params: TenantProjectAgentParamsSchema },
|
|
120
|
+
responses: {
|
|
121
|
+
200: {
|
|
122
|
+
description: "Full agent definition retrieved successfully",
|
|
123
|
+
content: { "application/json": { schema: AgentWithinContextOfProjectResponse } }
|
|
124
|
+
},
|
|
125
|
+
...commonGetErrorResponses
|
|
126
|
+
}
|
|
127
|
+
}), async (c) => {
|
|
128
|
+
const { tenantId, projectId, agentId } = c.req.valid("param");
|
|
129
|
+
const fullAgent = await getFullAgentDefinition(dbClient_default)({ scopes: {
|
|
130
|
+
tenantId,
|
|
131
|
+
projectId,
|
|
132
|
+
agentId
|
|
133
|
+
} });
|
|
134
|
+
if (!fullAgent) throw createApiError({
|
|
135
|
+
code: "not_found",
|
|
136
|
+
message: "Agent not found"
|
|
137
|
+
});
|
|
138
|
+
return c.json({ data: fullAgent });
|
|
139
|
+
});
|
|
140
|
+
app.openapi(createRoute({
|
|
141
|
+
method: "post",
|
|
142
|
+
path: "/",
|
|
143
|
+
summary: "Create Agent",
|
|
144
|
+
operationId: "create-agent",
|
|
145
|
+
tags: ["Agents"],
|
|
146
|
+
request: {
|
|
147
|
+
params: TenantProjectParamsSchema,
|
|
148
|
+
body: { content: { "application/json": { schema: AgentApiInsertSchema } } }
|
|
149
|
+
},
|
|
150
|
+
responses: {
|
|
151
|
+
201: {
|
|
152
|
+
description: "Agent created successfully",
|
|
153
|
+
content: { "application/json": { schema: AgentResponse } }
|
|
154
|
+
},
|
|
155
|
+
...commonGetErrorResponses
|
|
156
|
+
}
|
|
157
|
+
}), async (c) => {
|
|
158
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
159
|
+
const validatedBody = c.req.valid("json");
|
|
160
|
+
try {
|
|
161
|
+
const agent = await createAgent(dbClient_default)({
|
|
162
|
+
tenantId,
|
|
163
|
+
projectId,
|
|
164
|
+
id: validatedBody.id || generateId(),
|
|
165
|
+
name: validatedBody.name,
|
|
166
|
+
defaultSubAgentId: validatedBody.defaultSubAgentId,
|
|
167
|
+
contextConfigId: validatedBody.contextConfigId ?? void 0
|
|
168
|
+
});
|
|
169
|
+
return c.json({ data: agent }, 201);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error?.cause?.code === "23505") throw createApiError({
|
|
172
|
+
code: "conflict",
|
|
173
|
+
message: `An agent with ID '${validatedBody.id || "unknown"}' already exists`
|
|
174
|
+
});
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
app.openapi(createRoute({
|
|
179
|
+
method: "put",
|
|
180
|
+
path: "/{id}",
|
|
181
|
+
summary: "Update Agent",
|
|
182
|
+
operationId: "update-agent",
|
|
183
|
+
tags: ["Agents"],
|
|
184
|
+
request: {
|
|
185
|
+
params: TenantProjectIdParamsSchema,
|
|
186
|
+
body: { content: { "application/json": { schema: AgentApiUpdateSchema } } }
|
|
187
|
+
},
|
|
188
|
+
responses: {
|
|
189
|
+
200: {
|
|
190
|
+
description: "Agent updated successfully",
|
|
191
|
+
content: { "application/json": { schema: AgentResponse } }
|
|
192
|
+
},
|
|
193
|
+
...commonGetErrorResponses
|
|
194
|
+
}
|
|
195
|
+
}), async (c) => {
|
|
196
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
197
|
+
const validatedBody = c.req.valid("json");
|
|
198
|
+
const updatedAgent = await updateAgent(dbClient_default)({
|
|
199
|
+
scopes: {
|
|
200
|
+
tenantId,
|
|
201
|
+
projectId,
|
|
202
|
+
agentId: id
|
|
203
|
+
},
|
|
204
|
+
data: {
|
|
205
|
+
defaultSubAgentId: validatedBody.defaultSubAgentId,
|
|
206
|
+
contextConfigId: validatedBody.contextConfigId ?? void 0
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
if (!updatedAgent) throw createApiError({
|
|
210
|
+
code: "not_found",
|
|
211
|
+
message: "Agent not found"
|
|
212
|
+
});
|
|
213
|
+
return c.json({ data: updatedAgent });
|
|
214
|
+
});
|
|
215
|
+
app.openapi(createRoute({
|
|
216
|
+
method: "delete",
|
|
217
|
+
path: "/{id}",
|
|
218
|
+
summary: "Delete Agent",
|
|
219
|
+
operationId: "delete-agent",
|
|
220
|
+
tags: ["Agents"],
|
|
221
|
+
request: { params: TenantProjectIdParamsSchema },
|
|
222
|
+
responses: {
|
|
223
|
+
204: { description: "Agent deleted successfully" },
|
|
224
|
+
404: {
|
|
225
|
+
description: "Agent not found",
|
|
226
|
+
content: { "application/json": { schema: ErrorResponseSchema } }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}), async (c) => {
|
|
230
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
231
|
+
if (!await deleteAgent(dbClient_default)({ scopes: {
|
|
232
|
+
tenantId,
|
|
233
|
+
projectId,
|
|
234
|
+
agentId: id
|
|
235
|
+
} })) throw createApiError({
|
|
236
|
+
code: "not_found",
|
|
237
|
+
message: "Agent not found"
|
|
238
|
+
});
|
|
239
|
+
return c.body(null, 204);
|
|
240
|
+
});
|
|
241
|
+
var agent_default = app;
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { agent_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseAppVariables } from "../types/app.js";
|
|
2
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/agentFull.d.ts
|
|
5
|
+
declare const app: OpenAPIHono<{
|
|
6
|
+
Variables: BaseAppVariables;
|
|
7
|
+
}, {}, "/">;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { app as default };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
2
|
+
import dbClient_default from "../data/db/dbClient.js";
|
|
3
|
+
import { requirePermission } from "../middleware/require-permission.js";
|
|
4
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
5
|
+
import { AgentWithinContextOfProjectResponse, AgentWithinContextOfProjectSchema, ErrorResponseSchema, TenantProjectAgentParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError, createFullAgentServerSide, deleteFullAgent, getFullAgent, updateFullAgentServerSide } from "@inkeep/agents-core";
|
|
6
|
+
|
|
7
|
+
//#region src/routes/agentFull.ts
|
|
8
|
+
const logger = getLogger$1("agentFull");
|
|
9
|
+
const app = new OpenAPIHono();
|
|
10
|
+
app.use("/", async (c, next) => {
|
|
11
|
+
if (c.req.method === "POST") return requirePermission({ agent: ["create"] })(c, next);
|
|
12
|
+
return next();
|
|
13
|
+
});
|
|
14
|
+
app.use("/:agentId", async (c, next) => {
|
|
15
|
+
if (c.req.method === "PUT") return requirePermission({ agent: ["update"] })(c, next);
|
|
16
|
+
if (c.req.method === "DELETE") return requirePermission({ agent: ["delete"] })(c, next);
|
|
17
|
+
return next();
|
|
18
|
+
});
|
|
19
|
+
app.openapi(createRoute({
|
|
20
|
+
method: "post",
|
|
21
|
+
path: "/",
|
|
22
|
+
summary: "Create Full Agent",
|
|
23
|
+
operationId: "create-full-agent",
|
|
24
|
+
tags: ["Full Agent"],
|
|
25
|
+
description: "Create a complete agent with all agents, tools, and relationships from JSON definition",
|
|
26
|
+
request: {
|
|
27
|
+
params: TenantProjectParamsSchema,
|
|
28
|
+
body: { content: { "application/json": { schema: AgentWithinContextOfProjectSchema } } }
|
|
29
|
+
},
|
|
30
|
+
responses: {
|
|
31
|
+
201: {
|
|
32
|
+
description: "Full agent created successfully",
|
|
33
|
+
content: { "application/json": { schema: AgentWithinContextOfProjectResponse } }
|
|
34
|
+
},
|
|
35
|
+
409: {
|
|
36
|
+
description: "Agent already exists",
|
|
37
|
+
content: { "application/json": { schema: ErrorResponseSchema } }
|
|
38
|
+
},
|
|
39
|
+
...commonGetErrorResponses
|
|
40
|
+
}
|
|
41
|
+
}), async (c) => {
|
|
42
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
43
|
+
const agentData = c.req.valid("json");
|
|
44
|
+
const validatedAgentData = AgentWithinContextOfProjectSchema.parse(agentData);
|
|
45
|
+
const createdAgent = await createFullAgentServerSide(dbClient_default, logger)({
|
|
46
|
+
tenantId,
|
|
47
|
+
projectId
|
|
48
|
+
}, validatedAgentData);
|
|
49
|
+
return c.json({ data: createdAgent }, 201);
|
|
50
|
+
});
|
|
51
|
+
app.openapi(createRoute({
|
|
52
|
+
method: "get",
|
|
53
|
+
path: "/{agentId}",
|
|
54
|
+
summary: "Get Full Agent",
|
|
55
|
+
operationId: "get-full-agent",
|
|
56
|
+
tags: ["Full Agent"],
|
|
57
|
+
description: "Retrieve a complete agent definition with all agents, tools, and relationships",
|
|
58
|
+
request: { params: TenantProjectAgentParamsSchema },
|
|
59
|
+
responses: {
|
|
60
|
+
200: {
|
|
61
|
+
description: "Full agent found",
|
|
62
|
+
content: { "application/json": { schema: AgentWithinContextOfProjectResponse } }
|
|
63
|
+
},
|
|
64
|
+
...commonGetErrorResponses
|
|
65
|
+
}
|
|
66
|
+
}), async (c) => {
|
|
67
|
+
const { tenantId, projectId, agentId } = c.req.valid("param");
|
|
68
|
+
try {
|
|
69
|
+
const agent = await getFullAgent(dbClient_default, logger)({ scopes: {
|
|
70
|
+
tenantId,
|
|
71
|
+
projectId,
|
|
72
|
+
agentId
|
|
73
|
+
} });
|
|
74
|
+
if (!agent) throw createApiError({
|
|
75
|
+
code: "not_found",
|
|
76
|
+
message: "Agent not found"
|
|
77
|
+
});
|
|
78
|
+
return c.json({ data: agent });
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof Error && error.message.includes("not found")) throw createApiError({
|
|
81
|
+
code: "not_found",
|
|
82
|
+
message: "Agent not found"
|
|
83
|
+
});
|
|
84
|
+
throw createApiError({
|
|
85
|
+
code: "internal_server_error",
|
|
86
|
+
message: error instanceof Error ? error.message : "Failed to retrieve agent"
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
app.openapi(createRoute({
|
|
91
|
+
method: "put",
|
|
92
|
+
path: "/{agentId}",
|
|
93
|
+
summary: "Update Full Agent",
|
|
94
|
+
operationId: "update-full-agent",
|
|
95
|
+
tags: ["Full Agent"],
|
|
96
|
+
description: "Update or create a complete agent with all agents, tools, and relationships from JSON definition",
|
|
97
|
+
request: {
|
|
98
|
+
params: TenantProjectAgentParamsSchema,
|
|
99
|
+
body: { content: { "application/json": { schema: AgentWithinContextOfProjectSchema } } }
|
|
100
|
+
},
|
|
101
|
+
responses: {
|
|
102
|
+
200: {
|
|
103
|
+
description: "Full agent updated successfully",
|
|
104
|
+
content: { "application/json": { schema: AgentWithinContextOfProjectResponse } }
|
|
105
|
+
},
|
|
106
|
+
201: {
|
|
107
|
+
description: "Full agent created successfully",
|
|
108
|
+
content: { "application/json": { schema: AgentWithinContextOfProjectResponse } }
|
|
109
|
+
},
|
|
110
|
+
...commonGetErrorResponses
|
|
111
|
+
}
|
|
112
|
+
}), async (c) => {
|
|
113
|
+
const { tenantId, projectId, agentId } = c.req.valid("param");
|
|
114
|
+
const agentData = c.req.valid("json");
|
|
115
|
+
try {
|
|
116
|
+
logger.info({}, "test agent data");
|
|
117
|
+
const validatedAgentData = AgentWithinContextOfProjectSchema.parse(agentData);
|
|
118
|
+
if (agentId !== validatedAgentData.id) throw createApiError({
|
|
119
|
+
code: "bad_request",
|
|
120
|
+
message: `Agent ID mismatch: expected ${agentId}, got ${validatedAgentData.id}`
|
|
121
|
+
});
|
|
122
|
+
const isCreate = !await getFullAgent(dbClient_default, logger)({ scopes: {
|
|
123
|
+
tenantId,
|
|
124
|
+
projectId,
|
|
125
|
+
agentId
|
|
126
|
+
} });
|
|
127
|
+
const updatedAgent = isCreate ? await createFullAgentServerSide(dbClient_default, logger)({
|
|
128
|
+
tenantId,
|
|
129
|
+
projectId
|
|
130
|
+
}, validatedAgentData) : await updateFullAgentServerSide(dbClient_default, logger)({
|
|
131
|
+
tenantId,
|
|
132
|
+
projectId
|
|
133
|
+
}, validatedAgentData);
|
|
134
|
+
return c.json({ data: updatedAgent }, isCreate ? 201 : 200);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (error instanceof z.ZodError) throw createApiError({
|
|
137
|
+
code: "bad_request",
|
|
138
|
+
message: "Invalid agent definition"
|
|
139
|
+
});
|
|
140
|
+
if (error instanceof Error && error.message.includes("ID mismatch")) throw createApiError({
|
|
141
|
+
code: "bad_request",
|
|
142
|
+
message: error.message
|
|
143
|
+
});
|
|
144
|
+
throw createApiError({
|
|
145
|
+
code: "internal_server_error",
|
|
146
|
+
message: error instanceof Error ? error.message : "Failed to update agent"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
app.openapi(createRoute({
|
|
151
|
+
method: "delete",
|
|
152
|
+
path: "/{agentId}",
|
|
153
|
+
summary: "Delete Full Agent",
|
|
154
|
+
operationId: "delete-full-agent",
|
|
155
|
+
tags: ["Full Agent"],
|
|
156
|
+
description: "Delete a complete agent and cascade to all related entities (relationships, not other agents/tools)",
|
|
157
|
+
request: { params: TenantProjectAgentParamsSchema },
|
|
158
|
+
responses: {
|
|
159
|
+
204: { description: "Agent deleted successfully" },
|
|
160
|
+
...commonGetErrorResponses
|
|
161
|
+
}
|
|
162
|
+
}), async (c) => {
|
|
163
|
+
const { tenantId, projectId, agentId } = c.req.valid("param");
|
|
164
|
+
try {
|
|
165
|
+
if (!await deleteFullAgent(dbClient_default, logger)({ scopes: {
|
|
166
|
+
tenantId,
|
|
167
|
+
projectId,
|
|
168
|
+
agentId
|
|
169
|
+
} })) throw createApiError({
|
|
170
|
+
code: "not_found",
|
|
171
|
+
message: "Agent not found"
|
|
172
|
+
});
|
|
173
|
+
return c.body(null, 204);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error instanceof Error && error.message.includes("not found")) throw createApiError({
|
|
176
|
+
code: "not_found",
|
|
177
|
+
message: "Agent not found"
|
|
178
|
+
});
|
|
179
|
+
throw createApiError({
|
|
180
|
+
code: "internal_server_error",
|
|
181
|
+
message: error instanceof Error ? error.message : "Failed to delete agent"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
var agentFull_default = app;
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
export { agentFull_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseAppVariables } from "../types/app.js";
|
|
2
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/agentToolRelations.d.ts
|
|
5
|
+
declare const app: OpenAPIHono<{
|
|
6
|
+
Variables: BaseAppVariables;
|
|
7
|
+
}, {}, "/">;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { app as default };
|