@inkeep/agents-manage-api 0.39.4 → 0.40.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 +119 -22
- 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 +55 -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 +204 -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,210 @@
|
|
|
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 { ErrorResponseSchema, PaginationQueryParamsSchema, SubAgentApiInsertSchema, SubAgentApiUpdateSchema, SubAgentIsDefaultError, SubAgentListResponse, SubAgentResponse, TenantProjectAgentIdParamsSchema, TenantProjectAgentParamsSchema, commonGetErrorResponses, createApiError, createSubAgent, deleteSubAgent, generateId, getSubAgentById, listSubAgentsPaginated, updateSubAgent } from "@inkeep/agents-core";
|
|
6
|
+
|
|
7
|
+
//#region src/routes/subAgents.ts
|
|
8
|
+
const app = new OpenAPIHono();
|
|
9
|
+
app.use("/", async (c, next) => {
|
|
10
|
+
if (c.req.method === "POST") return requirePermission({ sub_agent: ["create"] })(c, next);
|
|
11
|
+
return next();
|
|
12
|
+
});
|
|
13
|
+
app.use("/:id", async (c, next) => {
|
|
14
|
+
if (c.req.method === "PUT") return requirePermission({ sub_agent: ["update"] })(c, next);
|
|
15
|
+
if (c.req.method === "DELETE") return requirePermission({ sub_agent: ["delete"] })(c, next);
|
|
16
|
+
return next();
|
|
17
|
+
});
|
|
18
|
+
app.openapi(createRoute({
|
|
19
|
+
method: "get",
|
|
20
|
+
path: "/",
|
|
21
|
+
summary: "List SubAgents",
|
|
22
|
+
operationId: "list-subagents",
|
|
23
|
+
tags: ["SubAgent"],
|
|
24
|
+
request: {
|
|
25
|
+
params: TenantProjectAgentParamsSchema,
|
|
26
|
+
query: PaginationQueryParamsSchema
|
|
27
|
+
},
|
|
28
|
+
responses: {
|
|
29
|
+
200: {
|
|
30
|
+
description: "List of subAgents retrieved successfully",
|
|
31
|
+
content: { "application/json": { schema: SubAgentListResponse } }
|
|
32
|
+
},
|
|
33
|
+
...commonGetErrorResponses
|
|
34
|
+
},
|
|
35
|
+
...speakeasyOffsetLimitPagination
|
|
36
|
+
}), async (c) => {
|
|
37
|
+
const { tenantId, projectId, agentId } = 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 listSubAgentsPaginated(dbClient_default)({
|
|
41
|
+
scopes: {
|
|
42
|
+
tenantId,
|
|
43
|
+
projectId,
|
|
44
|
+
agentId
|
|
45
|
+
},
|
|
46
|
+
pagination: {
|
|
47
|
+
page,
|
|
48
|
+
limit
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const dataWithType = {
|
|
52
|
+
...result,
|
|
53
|
+
data: result.data.map((subAgent) => ({
|
|
54
|
+
...subAgent,
|
|
55
|
+
type: "internal"
|
|
56
|
+
}))
|
|
57
|
+
};
|
|
58
|
+
return c.json(dataWithType);
|
|
59
|
+
});
|
|
60
|
+
app.openapi(createRoute({
|
|
61
|
+
method: "get",
|
|
62
|
+
path: "/{id}",
|
|
63
|
+
summary: "Get SubAgent",
|
|
64
|
+
operationId: "get-subagent-by-id",
|
|
65
|
+
tags: ["SubAgent"],
|
|
66
|
+
request: { params: TenantProjectAgentIdParamsSchema },
|
|
67
|
+
responses: {
|
|
68
|
+
200: {
|
|
69
|
+
description: "SubAgent found",
|
|
70
|
+
content: { "application/json": { schema: SubAgentResponse } }
|
|
71
|
+
},
|
|
72
|
+
...commonGetErrorResponses
|
|
73
|
+
}
|
|
74
|
+
}), async (c) => {
|
|
75
|
+
const { tenantId, projectId, agentId, id } = c.req.valid("param");
|
|
76
|
+
const subAgent = await getSubAgentById(dbClient_default)({
|
|
77
|
+
scopes: {
|
|
78
|
+
tenantId,
|
|
79
|
+
projectId,
|
|
80
|
+
agentId
|
|
81
|
+
},
|
|
82
|
+
subAgentId: id
|
|
83
|
+
});
|
|
84
|
+
if (!subAgent) throw createApiError({
|
|
85
|
+
code: "not_found",
|
|
86
|
+
message: "SubAgent not found"
|
|
87
|
+
});
|
|
88
|
+
const subAgentWithType = {
|
|
89
|
+
...subAgent,
|
|
90
|
+
type: "internal"
|
|
91
|
+
};
|
|
92
|
+
return c.json({ data: subAgentWithType });
|
|
93
|
+
});
|
|
94
|
+
app.openapi(createRoute({
|
|
95
|
+
method: "post",
|
|
96
|
+
path: "/",
|
|
97
|
+
summary: "Create SubAgent",
|
|
98
|
+
operationId: "create-subagent",
|
|
99
|
+
tags: ["SubAgent"],
|
|
100
|
+
request: {
|
|
101
|
+
params: TenantProjectAgentParamsSchema,
|
|
102
|
+
body: { content: { "application/json": { schema: SubAgentApiInsertSchema } } }
|
|
103
|
+
},
|
|
104
|
+
responses: {
|
|
105
|
+
201: {
|
|
106
|
+
description: "SubAgent created successfully",
|
|
107
|
+
content: { "application/json": { schema: SubAgentResponse } }
|
|
108
|
+
},
|
|
109
|
+
...commonGetErrorResponses
|
|
110
|
+
}
|
|
111
|
+
}), async (c) => {
|
|
112
|
+
const { tenantId, projectId, agentId } = c.req.valid("param");
|
|
113
|
+
const body = c.req.valid("json");
|
|
114
|
+
const subAgentId = body.id ? String(body.id) : generateId();
|
|
115
|
+
const subAgentWithType = {
|
|
116
|
+
...await createSubAgent(dbClient_default)({
|
|
117
|
+
...body,
|
|
118
|
+
id: subAgentId,
|
|
119
|
+
tenantId,
|
|
120
|
+
projectId,
|
|
121
|
+
agentId
|
|
122
|
+
}),
|
|
123
|
+
type: "internal"
|
|
124
|
+
};
|
|
125
|
+
return c.json({ data: subAgentWithType }, 201);
|
|
126
|
+
});
|
|
127
|
+
app.openapi(createRoute({
|
|
128
|
+
method: "put",
|
|
129
|
+
path: "/{id}",
|
|
130
|
+
summary: "Update SubAgent",
|
|
131
|
+
operationId: "update-subagent",
|
|
132
|
+
tags: ["SubAgent"],
|
|
133
|
+
request: {
|
|
134
|
+
params: TenantProjectAgentIdParamsSchema,
|
|
135
|
+
body: { content: { "application/json": { schema: SubAgentApiUpdateSchema } } }
|
|
136
|
+
},
|
|
137
|
+
responses: {
|
|
138
|
+
200: {
|
|
139
|
+
description: "SubAgent updated successfully",
|
|
140
|
+
content: { "application/json": { schema: SubAgentResponse } }
|
|
141
|
+
},
|
|
142
|
+
...commonGetErrorResponses
|
|
143
|
+
}
|
|
144
|
+
}), async (c) => {
|
|
145
|
+
const { tenantId, projectId, agentId, id } = c.req.valid("param");
|
|
146
|
+
const body = c.req.valid("json");
|
|
147
|
+
const updatedSubAgent = await updateSubAgent(dbClient_default)({
|
|
148
|
+
scopes: {
|
|
149
|
+
tenantId,
|
|
150
|
+
projectId,
|
|
151
|
+
agentId
|
|
152
|
+
},
|
|
153
|
+
subAgentId: id,
|
|
154
|
+
data: body
|
|
155
|
+
});
|
|
156
|
+
if (!updatedSubAgent) throw createApiError({
|
|
157
|
+
code: "not_found",
|
|
158
|
+
message: "SubAgent not found"
|
|
159
|
+
});
|
|
160
|
+
const subAgentWithType = {
|
|
161
|
+
...updatedSubAgent,
|
|
162
|
+
type: "internal"
|
|
163
|
+
};
|
|
164
|
+
return c.json({ data: subAgentWithType });
|
|
165
|
+
});
|
|
166
|
+
app.openapi(createRoute({
|
|
167
|
+
method: "delete",
|
|
168
|
+
path: "/{id}",
|
|
169
|
+
summary: "Delete SubAgent",
|
|
170
|
+
operationId: "delete-subagent",
|
|
171
|
+
tags: ["SubAgent"],
|
|
172
|
+
request: { params: TenantProjectAgentIdParamsSchema },
|
|
173
|
+
responses: {
|
|
174
|
+
204: { description: "SubAgent deleted successfully" },
|
|
175
|
+
404: {
|
|
176
|
+
description: "SubAgent not found",
|
|
177
|
+
content: { "application/json": { schema: ErrorResponseSchema } }
|
|
178
|
+
},
|
|
179
|
+
409: {
|
|
180
|
+
description: "SubAgent is set as default and cannot be deleted",
|
|
181
|
+
content: { "application/json": { schema: ErrorResponseSchema } }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}), async (c) => {
|
|
185
|
+
const { tenantId, projectId, agentId, id } = c.req.valid("param");
|
|
186
|
+
try {
|
|
187
|
+
if (!await deleteSubAgent(dbClient_default)({
|
|
188
|
+
scopes: {
|
|
189
|
+
tenantId,
|
|
190
|
+
projectId,
|
|
191
|
+
agentId
|
|
192
|
+
},
|
|
193
|
+
subAgentId: id
|
|
194
|
+
})) throw createApiError({
|
|
195
|
+
code: "not_found",
|
|
196
|
+
message: "SubAgent not found"
|
|
197
|
+
});
|
|
198
|
+
return c.body(null, 204);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error instanceof SubAgentIsDefaultError) throw createApiError({
|
|
201
|
+
code: "conflict",
|
|
202
|
+
message: error.message
|
|
203
|
+
});
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
var subAgents_default = app;
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
export { subAgents_default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { CredentialStoreRegistry, ServerConfig } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/thirdPartyMCPServers.d.ts
|
|
5
|
+
type AppVariables = {
|
|
6
|
+
serverConfig: ServerConfig;
|
|
7
|
+
credentialStores: CredentialStoreRegistry;
|
|
8
|
+
userId?: string;
|
|
9
|
+
};
|
|
10
|
+
declare const app: OpenAPIHono<{
|
|
11
|
+
Variables: AppVariables;
|
|
12
|
+
}, {}, "/">;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { app as default };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
import { TenantProjectParamsSchema, ThirdPartyMCPServerResponse, commonGetErrorResponses, createApiError, fetchSingleComposioServer, getComposioOAuthRedirectUrl } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/thirdPartyMCPServers.ts
|
|
5
|
+
const app = new OpenAPIHono();
|
|
6
|
+
const ThirdPartyMCPServerBodySchema = z.object({
|
|
7
|
+
url: z.url().describe("The MCP server URL to fetch details for"),
|
|
8
|
+
credentialScope: z.enum(["project", "user"]).default("project").optional()
|
|
9
|
+
});
|
|
10
|
+
const GetOAuthRedirectBodySchema = z.object({
|
|
11
|
+
url: z.url().describe("The MCP server URL"),
|
|
12
|
+
credentialScope: z.enum(["project", "user"]).describe("The credential scope")
|
|
13
|
+
});
|
|
14
|
+
const OAuthRedirectResponse = z.object({ data: z.object({ redirectUrl: z.string().nullable() }) });
|
|
15
|
+
app.openapi(createRoute({
|
|
16
|
+
method: "post",
|
|
17
|
+
path: "/",
|
|
18
|
+
summary: "Get Third-Party MCP Server Details",
|
|
19
|
+
operationId: "get-third-party-mcp-server",
|
|
20
|
+
tags: ["Third-Party MCP Servers"],
|
|
21
|
+
description: "Fetch details for a specific third-party MCP server (e.g., Composio) including authentication status and connect URL",
|
|
22
|
+
request: {
|
|
23
|
+
params: TenantProjectParamsSchema,
|
|
24
|
+
body: { content: { "application/json": { schema: ThirdPartyMCPServerBodySchema } } }
|
|
25
|
+
},
|
|
26
|
+
responses: {
|
|
27
|
+
200: {
|
|
28
|
+
description: "Third-party MCP server details",
|
|
29
|
+
content: { "application/json": { schema: ThirdPartyMCPServerResponse } }
|
|
30
|
+
},
|
|
31
|
+
...commonGetErrorResponses
|
|
32
|
+
}
|
|
33
|
+
}), async (c) => {
|
|
34
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
35
|
+
const { url, credentialScope } = c.req.valid("json");
|
|
36
|
+
const userId = c.get("userId");
|
|
37
|
+
const server = await fetchSingleComposioServer(tenantId, projectId, url, credentialScope ?? "project", userId);
|
|
38
|
+
return c.json({ data: server });
|
|
39
|
+
});
|
|
40
|
+
app.openapi(createRoute({
|
|
41
|
+
method: "post",
|
|
42
|
+
path: "/oauth-redirect",
|
|
43
|
+
summary: "Get OAuth Redirect URL",
|
|
44
|
+
operationId: "get-oauth-redirect-url",
|
|
45
|
+
tags: ["Third-Party MCP Servers"],
|
|
46
|
+
description: "Get the OAuth redirect URL for a third-party MCP server. Call this after scope selection to get the correct URL for the selected scope.",
|
|
47
|
+
request: {
|
|
48
|
+
params: TenantProjectParamsSchema,
|
|
49
|
+
body: { content: { "application/json": { schema: GetOAuthRedirectBodySchema } } }
|
|
50
|
+
},
|
|
51
|
+
responses: {
|
|
52
|
+
200: {
|
|
53
|
+
description: "OAuth redirect URL",
|
|
54
|
+
content: { "application/json": { schema: OAuthRedirectResponse } }
|
|
55
|
+
},
|
|
56
|
+
...commonGetErrorResponses
|
|
57
|
+
}
|
|
58
|
+
}), async (c) => {
|
|
59
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
60
|
+
const { url, credentialScope } = c.req.valid("json");
|
|
61
|
+
const userId = c.get("userId");
|
|
62
|
+
if (credentialScope === "user" && !userId) throw createApiError({
|
|
63
|
+
code: "bad_request",
|
|
64
|
+
message: "User ID required for user-scoped credentials"
|
|
65
|
+
});
|
|
66
|
+
const redirectUrl = await getComposioOAuthRedirectUrl(tenantId, projectId, url, credentialScope, userId);
|
|
67
|
+
return c.json({ data: { redirectUrl } });
|
|
68
|
+
});
|
|
69
|
+
var thirdPartyMCPServers_default = app;
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { thirdPartyMCPServers_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AppVariablesWithServerConfig } from "../types/app.js";
|
|
2
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/tools.d.ts
|
|
5
|
+
declare const app: OpenAPIHono<{
|
|
6
|
+
Variables: AppVariablesWithServerConfig;
|
|
7
|
+
}, {}, "/">;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { app as default };
|
|
@@ -0,0 +1,256 @@
|
|
|
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 { speakeasyOffsetLimitPagination } from "./shared.js";
|
|
5
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
6
|
+
import { CredentialReferenceApiSelectSchema, CredentialReferenceResponse, McpToolListResponse, McpToolResponse, PaginationQueryParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiUpdateSchema, ToolStatusSchema, commonGetErrorResponses, createApiError, createTool, dbResultToMcpTool, deleteTool, generateId, getToolById, getUserScopedCredentialReference, listTools, updateTool } from "@inkeep/agents-core";
|
|
7
|
+
|
|
8
|
+
//#region src/routes/tools.ts
|
|
9
|
+
const logger = getLogger$1("tools");
|
|
10
|
+
const app = new OpenAPIHono();
|
|
11
|
+
app.use("/", async (c, next) => {
|
|
12
|
+
if (c.req.method === "POST") return requirePermission({ tool: ["create"] })(c, next);
|
|
13
|
+
return next();
|
|
14
|
+
});
|
|
15
|
+
app.use("/:id", async (c, next) => {
|
|
16
|
+
if (c.req.method === "PUT") return requirePermission({ tool: ["update"] })(c, next);
|
|
17
|
+
if (c.req.method === "DELETE") return requirePermission({ tool: ["delete"] })(c, next);
|
|
18
|
+
return next();
|
|
19
|
+
});
|
|
20
|
+
app.openapi(createRoute({
|
|
21
|
+
method: "get",
|
|
22
|
+
path: "/",
|
|
23
|
+
summary: "List Tools",
|
|
24
|
+
operationId: "list-tools",
|
|
25
|
+
tags: ["Tools"],
|
|
26
|
+
request: {
|
|
27
|
+
params: TenantProjectParamsSchema,
|
|
28
|
+
query: PaginationQueryParamsSchema.extend({ status: ToolStatusSchema.optional() })
|
|
29
|
+
},
|
|
30
|
+
responses: {
|
|
31
|
+
200: {
|
|
32
|
+
description: "List of tools retrieved successfully",
|
|
33
|
+
content: { "application/json": { schema: McpToolListResponse } }
|
|
34
|
+
},
|
|
35
|
+
...commonGetErrorResponses
|
|
36
|
+
},
|
|
37
|
+
...speakeasyOffsetLimitPagination
|
|
38
|
+
}), async (c) => {
|
|
39
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
40
|
+
const { page, limit, status } = c.req.valid("query");
|
|
41
|
+
let result;
|
|
42
|
+
const credentialStores = c.get("credentialStores");
|
|
43
|
+
const userId = c.get("userId");
|
|
44
|
+
if (status) {
|
|
45
|
+
const dbResult = await listTools(dbClient_default)({
|
|
46
|
+
scopes: {
|
|
47
|
+
tenantId,
|
|
48
|
+
projectId
|
|
49
|
+
},
|
|
50
|
+
pagination: {
|
|
51
|
+
page,
|
|
52
|
+
limit
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
result = {
|
|
56
|
+
data: (await Promise.all(dbResult.data.map(async (tool) => await dbResultToMcpTool(tool, dbClient_default, credentialStores, void 0, userId)))).filter((tool) => tool.status === status),
|
|
57
|
+
pagination: dbResult.pagination
|
|
58
|
+
};
|
|
59
|
+
} else {
|
|
60
|
+
const dbResult = await listTools(dbClient_default)({
|
|
61
|
+
scopes: {
|
|
62
|
+
tenantId,
|
|
63
|
+
projectId
|
|
64
|
+
},
|
|
65
|
+
pagination: {
|
|
66
|
+
page,
|
|
67
|
+
limit
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
result = {
|
|
71
|
+
data: await Promise.all(dbResult.data.map(async (tool) => await dbResultToMcpTool(tool, dbClient_default, credentialStores, void 0, userId))),
|
|
72
|
+
pagination: dbResult.pagination
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return c.json(result);
|
|
76
|
+
});
|
|
77
|
+
app.openapi(createRoute({
|
|
78
|
+
method: "get",
|
|
79
|
+
path: "/{id}",
|
|
80
|
+
summary: "Get Tool",
|
|
81
|
+
operationId: "get-tool",
|
|
82
|
+
tags: ["Tools"],
|
|
83
|
+
request: { params: TenantProjectIdParamsSchema },
|
|
84
|
+
responses: {
|
|
85
|
+
200: {
|
|
86
|
+
description: "Tool found",
|
|
87
|
+
content: { "application/json": { schema: McpToolResponse } }
|
|
88
|
+
},
|
|
89
|
+
...commonGetErrorResponses
|
|
90
|
+
}
|
|
91
|
+
}), async (c) => {
|
|
92
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
93
|
+
const tool = await getToolById(dbClient_default)({
|
|
94
|
+
scopes: {
|
|
95
|
+
tenantId,
|
|
96
|
+
projectId
|
|
97
|
+
},
|
|
98
|
+
toolId: id
|
|
99
|
+
});
|
|
100
|
+
if (!tool) throw createApiError({
|
|
101
|
+
code: "not_found",
|
|
102
|
+
message: "Tool not found"
|
|
103
|
+
});
|
|
104
|
+
const credentialStores = c.get("credentialStores");
|
|
105
|
+
const userId = c.get("userId");
|
|
106
|
+
return c.json({ data: await dbResultToMcpTool(tool, dbClient_default, credentialStores, void 0, userId) });
|
|
107
|
+
});
|
|
108
|
+
app.openapi(createRoute({
|
|
109
|
+
method: "post",
|
|
110
|
+
path: "/",
|
|
111
|
+
summary: "Create Tool",
|
|
112
|
+
operationId: "create-tool",
|
|
113
|
+
tags: ["Tools"],
|
|
114
|
+
request: {
|
|
115
|
+
params: TenantProjectParamsSchema,
|
|
116
|
+
body: { content: { "application/json": { schema: ToolApiInsertSchema } } }
|
|
117
|
+
},
|
|
118
|
+
responses: {
|
|
119
|
+
201: {
|
|
120
|
+
description: "Tool created successfully",
|
|
121
|
+
content: { "application/json": { schema: McpToolResponse } }
|
|
122
|
+
},
|
|
123
|
+
...commonGetErrorResponses
|
|
124
|
+
}
|
|
125
|
+
}), async (c) => {
|
|
126
|
+
const { tenantId, projectId } = c.req.valid("param");
|
|
127
|
+
const body = c.req.valid("json");
|
|
128
|
+
const credentialStores = c.get("credentialStores");
|
|
129
|
+
const userId = c.get("userId");
|
|
130
|
+
logger.info({ body }, "body");
|
|
131
|
+
const id = body.id || generateId();
|
|
132
|
+
const tool = await createTool(dbClient_default)({
|
|
133
|
+
tenantId,
|
|
134
|
+
projectId,
|
|
135
|
+
id,
|
|
136
|
+
name: body.name,
|
|
137
|
+
config: body.config,
|
|
138
|
+
credentialReferenceId: body.credentialReferenceId,
|
|
139
|
+
credentialScope: body.credentialScope,
|
|
140
|
+
imageUrl: body.imageUrl,
|
|
141
|
+
headers: body.headers
|
|
142
|
+
});
|
|
143
|
+
return c.json({ data: await dbResultToMcpTool(tool, dbClient_default, credentialStores, void 0, userId) }, 201);
|
|
144
|
+
});
|
|
145
|
+
app.openapi(createRoute({
|
|
146
|
+
method: "put",
|
|
147
|
+
path: "/{id}",
|
|
148
|
+
summary: "Update Tool",
|
|
149
|
+
operationId: "update-tool",
|
|
150
|
+
tags: ["Tools"],
|
|
151
|
+
request: {
|
|
152
|
+
params: TenantProjectIdParamsSchema,
|
|
153
|
+
body: { content: { "application/json": { schema: ToolApiUpdateSchema } } }
|
|
154
|
+
},
|
|
155
|
+
responses: {
|
|
156
|
+
200: {
|
|
157
|
+
description: "Tool updated successfully",
|
|
158
|
+
content: { "application/json": { schema: McpToolResponse } }
|
|
159
|
+
},
|
|
160
|
+
...commonGetErrorResponses
|
|
161
|
+
}
|
|
162
|
+
}), async (c) => {
|
|
163
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
164
|
+
const body = c.req.valid("json");
|
|
165
|
+
const credentialStores = c.get("credentialStores");
|
|
166
|
+
const userId = c.get("userId");
|
|
167
|
+
if (Object.keys(body).length === 0) throw createApiError({
|
|
168
|
+
code: "bad_request",
|
|
169
|
+
message: "No fields to update"
|
|
170
|
+
});
|
|
171
|
+
const updatedTool = await updateTool(dbClient_default)({
|
|
172
|
+
scopes: {
|
|
173
|
+
tenantId,
|
|
174
|
+
projectId
|
|
175
|
+
},
|
|
176
|
+
toolId: id,
|
|
177
|
+
data: {
|
|
178
|
+
name: body.name,
|
|
179
|
+
config: body.config,
|
|
180
|
+
credentialReferenceId: body.credentialReferenceId,
|
|
181
|
+
credentialScope: body.credentialScope,
|
|
182
|
+
imageUrl: body.imageUrl,
|
|
183
|
+
headers: body.headers
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
if (!updatedTool) throw createApiError({
|
|
187
|
+
code: "not_found",
|
|
188
|
+
message: "Tool not found"
|
|
189
|
+
});
|
|
190
|
+
return c.json({ data: await dbResultToMcpTool(updatedTool, dbClient_default, credentialStores, void 0, userId) });
|
|
191
|
+
});
|
|
192
|
+
app.openapi(createRoute({
|
|
193
|
+
method: "get",
|
|
194
|
+
path: "/{id}/user-credential",
|
|
195
|
+
summary: "Get User Credential for Tool",
|
|
196
|
+
operationId: "get-user-credential-for-tool",
|
|
197
|
+
tags: ["Tools"],
|
|
198
|
+
request: { params: TenantProjectIdParamsSchema },
|
|
199
|
+
responses: {
|
|
200
|
+
200: {
|
|
201
|
+
description: "User credential retrieved successfully",
|
|
202
|
+
content: { "application/json": { schema: CredentialReferenceResponse } }
|
|
203
|
+
},
|
|
204
|
+
...commonGetErrorResponses
|
|
205
|
+
}
|
|
206
|
+
}), async (c) => {
|
|
207
|
+
const { tenantId, projectId, id: toolId } = c.req.valid("param");
|
|
208
|
+
const userId = c.get("userId");
|
|
209
|
+
if (!userId) throw createApiError({
|
|
210
|
+
code: "unauthorized",
|
|
211
|
+
message: "User ID required for user-scoped credential lookup"
|
|
212
|
+
});
|
|
213
|
+
const credential = await getUserScopedCredentialReference(dbClient_default)({
|
|
214
|
+
scopes: {
|
|
215
|
+
tenantId,
|
|
216
|
+
projectId
|
|
217
|
+
},
|
|
218
|
+
toolId,
|
|
219
|
+
userId
|
|
220
|
+
});
|
|
221
|
+
if (!credential) throw createApiError({
|
|
222
|
+
code: "not_found",
|
|
223
|
+
message: "User credential not found for this tool"
|
|
224
|
+
});
|
|
225
|
+
const validatedCredential = CredentialReferenceApiSelectSchema.parse(credential);
|
|
226
|
+
return c.json({ data: validatedCredential });
|
|
227
|
+
});
|
|
228
|
+
app.openapi(createRoute({
|
|
229
|
+
method: "delete",
|
|
230
|
+
path: "/{id}",
|
|
231
|
+
summary: "Delete Tool",
|
|
232
|
+
operationId: "delete-tool",
|
|
233
|
+
tags: ["Tools"],
|
|
234
|
+
request: { params: TenantProjectIdParamsSchema },
|
|
235
|
+
responses: {
|
|
236
|
+
204: { description: "Tool deleted successfully" },
|
|
237
|
+
...commonGetErrorResponses
|
|
238
|
+
}
|
|
239
|
+
}), async (c) => {
|
|
240
|
+
const { tenantId, projectId, id } = c.req.valid("param");
|
|
241
|
+
if (!await deleteTool(dbClient_default)({
|
|
242
|
+
scopes: {
|
|
243
|
+
tenantId,
|
|
244
|
+
projectId
|
|
245
|
+
},
|
|
246
|
+
toolId: id
|
|
247
|
+
})) throw createApiError({
|
|
248
|
+
code: "not_found",
|
|
249
|
+
message: "Tool not found"
|
|
250
|
+
});
|
|
251
|
+
return c.body(null, 204);
|
|
252
|
+
});
|
|
253
|
+
var tools_default = app;
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
export { tools_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AppVariables } from "../create-app.js";
|
|
2
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
+
|
|
4
|
+
//#region src/routes/userOrganizations.d.ts
|
|
5
|
+
declare const userOrganizationsRoutes: OpenAPIHono<{
|
|
6
|
+
Variables: AppVariables;
|
|
7
|
+
}, {}, "/">;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { userOrganizationsRoutes as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import dbClient_default from "../data/db/dbClient.js";
|
|
2
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
3
|
+
import { addUserToOrganization, getUserOrganizations } from "@inkeep/agents-core";
|
|
4
|
+
import { AddUserToOrganizationRequestSchema, AddUserToOrganizationResponseSchema, UserOrganizationsResponseSchema } from "@inkeep/agents-core/auth/validation";
|
|
5
|
+
|
|
6
|
+
//#region src/routes/userOrganizations.ts
|
|
7
|
+
const userOrganizationsRoutes = new OpenAPIHono();
|
|
8
|
+
userOrganizationsRoutes.openapi(createRoute({
|
|
9
|
+
method: "get",
|
|
10
|
+
path: "/",
|
|
11
|
+
tags: ["user-organizations"],
|
|
12
|
+
summary: "List user organizations",
|
|
13
|
+
description: "Get all organizations associated with a user",
|
|
14
|
+
request: { params: z.object({ userId: z.string().describe("User ID") }) },
|
|
15
|
+
responses: { 200: {
|
|
16
|
+
description: "List of user organizations",
|
|
17
|
+
content: { "application/json": { schema: UserOrganizationsResponseSchema } }
|
|
18
|
+
} }
|
|
19
|
+
}), async (c) => {
|
|
20
|
+
const { userId } = c.req.valid("param");
|
|
21
|
+
const userOrganizations = (await getUserOrganizations(dbClient_default)(userId)).map((org) => ({
|
|
22
|
+
...org,
|
|
23
|
+
createdAt: org.createdAt.toISOString()
|
|
24
|
+
}));
|
|
25
|
+
return c.json(userOrganizations);
|
|
26
|
+
});
|
|
27
|
+
userOrganizationsRoutes.openapi(createRoute({
|
|
28
|
+
method: "post",
|
|
29
|
+
path: "/",
|
|
30
|
+
tags: ["user-organizations"],
|
|
31
|
+
summary: "Add user to organization",
|
|
32
|
+
description: "Associate a user with an organization",
|
|
33
|
+
request: {
|
|
34
|
+
params: z.object({ userId: z.string().describe("User ID") }),
|
|
35
|
+
body: { content: { "application/json": { schema: AddUserToOrganizationRequestSchema } } }
|
|
36
|
+
},
|
|
37
|
+
responses: { 201: {
|
|
38
|
+
description: "User added to organization",
|
|
39
|
+
content: { "application/json": { schema: AddUserToOrganizationResponseSchema } }
|
|
40
|
+
} }
|
|
41
|
+
}), async (c) => {
|
|
42
|
+
const { userId } = c.req.valid("param");
|
|
43
|
+
const { organizationId, role } = c.req.valid("json");
|
|
44
|
+
await addUserToOrganization(dbClient_default)({
|
|
45
|
+
userId,
|
|
46
|
+
organizationId,
|
|
47
|
+
role
|
|
48
|
+
});
|
|
49
|
+
return c.json({
|
|
50
|
+
organizationId,
|
|
51
|
+
role,
|
|
52
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
53
|
+
}, 201);
|
|
54
|
+
});
|
|
55
|
+
var userOrganizations_default = userOrganizationsRoutes;
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { userOrganizations_default as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SSOProviderConfig } from "@inkeep/agents-core/auth";
|
|
2
|
+
|
|
3
|
+
//#region src/sso-helpers.d.ts
|
|
4
|
+
interface OIDCProviderOptions {
|
|
5
|
+
providerId: string;
|
|
6
|
+
clientId: string;
|
|
7
|
+
clientSecret: string;
|
|
8
|
+
domain: string;
|
|
9
|
+
organizationId?: string;
|
|
10
|
+
scopes?: string[];
|
|
11
|
+
pkce?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare function createOIDCProvider(options: OIDCProviderOptions): Promise<SSOProviderConfig | null>;
|
|
14
|
+
declare function createAuth0Provider(options: {
|
|
15
|
+
domain: string;
|
|
16
|
+
clientId: string;
|
|
17
|
+
clientSecret: string;
|
|
18
|
+
}): Promise<SSOProviderConfig | null>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { OIDCProviderOptions, createAuth0Provider, createOIDCProvider };
|