@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,64 @@
|
|
|
1
|
+
import { env } from "../env.js";
|
|
2
|
+
import dbClient_default from "../data/db/dbClient.js";
|
|
3
|
+
import { getLogger, validateAndGetApiKey } from "@inkeep/agents-core";
|
|
4
|
+
import { createMiddleware } from "hono/factory";
|
|
5
|
+
import { HTTPException } from "hono/http-exception";
|
|
6
|
+
|
|
7
|
+
//#region src/middleware/auth.ts
|
|
8
|
+
const logger = getLogger("env-key-auth");
|
|
9
|
+
/**
|
|
10
|
+
* Middleware to authenticate API requests using Bearer token authentication
|
|
11
|
+
* Authentication priority:
|
|
12
|
+
* 1. Bypass secret (INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET)
|
|
13
|
+
* 2. Better-auth session token (from device authorization flow)
|
|
14
|
+
* 3. Database API key
|
|
15
|
+
*/
|
|
16
|
+
const apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
17
|
+
const authHeader = c.req.header("Authorization");
|
|
18
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) throw new HTTPException(401, { message: "Missing or invalid authorization header. Expected: Bearer <api_key>" });
|
|
19
|
+
const token = authHeader.substring(7);
|
|
20
|
+
if (env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET && token === env.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET) {
|
|
21
|
+
logger.info({}, "Bypass secret authenticated successfully");
|
|
22
|
+
c.set("userId", "system");
|
|
23
|
+
c.set("userEmail", "system@internal");
|
|
24
|
+
await next();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const auth = c.get("auth");
|
|
28
|
+
if (auth) try {
|
|
29
|
+
const headers = new Headers();
|
|
30
|
+
headers.set("Authorization", authHeader);
|
|
31
|
+
const forwardedCookie = c.req.header("x-forwarded-cookie");
|
|
32
|
+
const cookie = c.req.header("cookie");
|
|
33
|
+
if (forwardedCookie) {
|
|
34
|
+
headers.set("cookie", forwardedCookie);
|
|
35
|
+
logger.debug({ source: "x-forwarded-cookie" }, "Using x-forwarded-cookie for session validation");
|
|
36
|
+
} else if (cookie) {
|
|
37
|
+
headers.set("cookie", cookie);
|
|
38
|
+
logger.debug({ source: "cookie" }, "Using cookie for session validation");
|
|
39
|
+
}
|
|
40
|
+
const session = await auth.api.getSession({ headers });
|
|
41
|
+
if (session?.user) {
|
|
42
|
+
logger.info({ userId: session.user.id }, "Better-auth session authenticated successfully");
|
|
43
|
+
c.set("userId", session.user.id);
|
|
44
|
+
c.set("userEmail", session.user.email);
|
|
45
|
+
await next();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.debug({ error }, "Better-auth session validation failed, trying API key");
|
|
50
|
+
}
|
|
51
|
+
const validatedKey = await validateAndGetApiKey(token, dbClient_default);
|
|
52
|
+
if (validatedKey) {
|
|
53
|
+
logger.info({ keyId: validatedKey.id }, "API key authenticated successfully");
|
|
54
|
+
c.set("userId", `apikey:${validatedKey.id}`);
|
|
55
|
+
c.set("userEmail", `apikey-${validatedKey.id}@internal`);
|
|
56
|
+
c.set("tenantId", validatedKey.tenantId);
|
|
57
|
+
await next();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
throw new HTTPException(401, { message: "Invalid Token" });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { apiKeyAuth };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context } from "hono";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/error-handler.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global error handler for the Hono application
|
|
7
|
+
* Handles Zod validation errors, HTTP exceptions, and unexpected errors
|
|
8
|
+
* Returns RFC 7807 Problem Details format
|
|
9
|
+
*/
|
|
10
|
+
declare function errorHandler(err: Error, c: Context): Promise<Response>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { errorHandler };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getLogger as getLogger$1 } from "../logger.js";
|
|
2
|
+
import { handleApiError } from "@inkeep/agents-core";
|
|
3
|
+
import { HTTPException } from "hono/http-exception";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/error-handler.ts
|
|
6
|
+
const logger = getLogger$1("error-handler");
|
|
7
|
+
/**
|
|
8
|
+
* Extract Zod validation issues from an error object
|
|
9
|
+
*/
|
|
10
|
+
function extractZodIssues(err) {
|
|
11
|
+
if (err && typeof err === "object") {
|
|
12
|
+
if ("cause" in err && err.cause && typeof err.cause === "object" && "issues" in err.cause) {
|
|
13
|
+
const issues = err.cause.issues;
|
|
14
|
+
if (Array.isArray(issues)) return issues;
|
|
15
|
+
}
|
|
16
|
+
if ("issues" in err && Array.isArray(err.issues)) return err.issues;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Format Zod validation errors into RFC 7807 problem detail format
|
|
21
|
+
*/
|
|
22
|
+
function formatZodValidationError(c, zodIssues) {
|
|
23
|
+
c.status(400);
|
|
24
|
+
c.header("Content-Type", "application/problem+json");
|
|
25
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
26
|
+
return c.json({
|
|
27
|
+
type: "https://docs.inkeep.com/agents-api/errors#bad_request",
|
|
28
|
+
title: "Validation Failed",
|
|
29
|
+
status: 400,
|
|
30
|
+
detail: "Request validation failed",
|
|
31
|
+
errors: zodIssues.map((issue) => ({
|
|
32
|
+
detail: issue.message,
|
|
33
|
+
pointer: issue.path ? `/${issue.path.join("/")}` : void 0,
|
|
34
|
+
name: issue.path ? issue.path.join(".") : void 0,
|
|
35
|
+
reason: issue.message
|
|
36
|
+
}))
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Log server errors with appropriate context
|
|
41
|
+
*/
|
|
42
|
+
function logServerError(err, path, requestId, status, isExpectedError) {
|
|
43
|
+
if (!isExpectedError) {
|
|
44
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
45
|
+
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
46
|
+
logger.error({
|
|
47
|
+
error: err,
|
|
48
|
+
message: errorMessage,
|
|
49
|
+
stack: errorStack,
|
|
50
|
+
path,
|
|
51
|
+
requestId
|
|
52
|
+
}, "Unexpected server error occurred");
|
|
53
|
+
} else logger.error({
|
|
54
|
+
error: err,
|
|
55
|
+
path,
|
|
56
|
+
requestId,
|
|
57
|
+
status
|
|
58
|
+
}, "Server error occurred");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Global error handler for the Hono application
|
|
62
|
+
* Handles Zod validation errors, HTTP exceptions, and unexpected errors
|
|
63
|
+
* Returns RFC 7807 Problem Details format
|
|
64
|
+
*/
|
|
65
|
+
async function errorHandler(err, c) {
|
|
66
|
+
const isExpectedError = err instanceof HTTPException;
|
|
67
|
+
const status = isExpectedError ? err.status : 500;
|
|
68
|
+
const requestId = c.get("requestId") || "unknown";
|
|
69
|
+
const zodIssues = extractZodIssues(err);
|
|
70
|
+
if (status === 400 && zodIssues) return formatZodValidationError(c, zodIssues);
|
|
71
|
+
if (status >= 500) logServerError(err, c.req.path, requestId, status, isExpectedError);
|
|
72
|
+
const errorResponse = await handleApiError(err, requestId);
|
|
73
|
+
c.status(errorResponse.status);
|
|
74
|
+
const responseBody = {
|
|
75
|
+
...errorResponse.code && { code: errorResponse.code },
|
|
76
|
+
title: errorResponse.title,
|
|
77
|
+
status: errorResponse.status,
|
|
78
|
+
detail: errorResponse.detail,
|
|
79
|
+
...errorResponse.instance && { instance: errorResponse.instance },
|
|
80
|
+
...errorResponse.error && { error: errorResponse.error }
|
|
81
|
+
};
|
|
82
|
+
c.header("Content-Type", "application/problem+json");
|
|
83
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
84
|
+
return c.body(JSON.stringify(responseBody));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { errorHandler };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as hono1 from "hono";
|
|
2
|
+
import { createAuth } from "@inkeep/agents-core/auth";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/require-permission.d.ts
|
|
5
|
+
type Permission = {
|
|
6
|
+
[resource: string]: string | string[];
|
|
7
|
+
};
|
|
8
|
+
type MinimalAuthVariables = {
|
|
9
|
+
Variables: {
|
|
10
|
+
auth: ReturnType<typeof createAuth> | null;
|
|
11
|
+
userId: string;
|
|
12
|
+
userEmail: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
tenantRole: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare const requirePermission: <Env$1 extends MinimalAuthVariables = MinimalAuthVariables>(permissions: Permission) => hono1.MiddlewareHandler<Env$1, string, {}, Response>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { requirePermission };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { env } from "../env.js";
|
|
2
|
+
import { createApiError } from "@inkeep/agents-core";
|
|
3
|
+
import { createMiddleware } from "hono/factory";
|
|
4
|
+
import { HTTPException } from "hono/http-exception";
|
|
5
|
+
|
|
6
|
+
//#region src/middleware/require-permission.ts
|
|
7
|
+
function formatPermissionsForDisplay(permissions) {
|
|
8
|
+
const formatted = [];
|
|
9
|
+
for (const [resource, actions] of Object.entries(permissions)) {
|
|
10
|
+
const actionList = Array.isArray(actions) ? actions : [actions];
|
|
11
|
+
for (const action of actionList) formatted.push(`${resource}:${action}`);
|
|
12
|
+
}
|
|
13
|
+
return formatted;
|
|
14
|
+
}
|
|
15
|
+
const requirePermission = (permissions) => createMiddleware(async (c, next) => {
|
|
16
|
+
const isTestEnvironment = process.env.ENVIRONMENT === "test";
|
|
17
|
+
const auth = c.get("auth");
|
|
18
|
+
if (env.DISABLE_AUTH || isTestEnvironment || !auth) {
|
|
19
|
+
await next();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const userId = c.get("userId");
|
|
23
|
+
const tenantId = c.get("tenantId");
|
|
24
|
+
const tenantRole = c.get("tenantRole");
|
|
25
|
+
const requiredPermissions = formatPermissionsForDisplay(permissions);
|
|
26
|
+
if (userId === "system" || userId?.startsWith("apikey:")) {
|
|
27
|
+
await next();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!userId || !tenantId) throw createApiError({
|
|
31
|
+
code: "unauthorized",
|
|
32
|
+
message: "User or organization context not found. Ensure you are authenticated and belong to an organization.",
|
|
33
|
+
instance: c.req.path,
|
|
34
|
+
extensions: {
|
|
35
|
+
requiredPermissions,
|
|
36
|
+
context: {
|
|
37
|
+
hasUserId: !!userId,
|
|
38
|
+
hasTenantId: !!tenantId
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
const result = await auth.api.hasPermission({
|
|
44
|
+
body: {
|
|
45
|
+
permissions,
|
|
46
|
+
organizationId: tenantId
|
|
47
|
+
},
|
|
48
|
+
headers: c.req.raw.headers
|
|
49
|
+
});
|
|
50
|
+
if (!result || !result.success) throw createApiError({
|
|
51
|
+
code: "forbidden",
|
|
52
|
+
message: `Permission denied. Required: ${requiredPermissions.join(", ")}`,
|
|
53
|
+
instance: c.req.path,
|
|
54
|
+
extensions: {
|
|
55
|
+
requiredPermissions,
|
|
56
|
+
context: {
|
|
57
|
+
userId,
|
|
58
|
+
organizationId: tenantId,
|
|
59
|
+
currentRole: tenantRole || "unknown"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
await next();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof HTTPException) throw error;
|
|
66
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
67
|
+
throw createApiError({
|
|
68
|
+
code: "internal_server_error",
|
|
69
|
+
message: "Failed to verify permissions",
|
|
70
|
+
instance: c.req.path,
|
|
71
|
+
extensions: {
|
|
72
|
+
requiredPermissions,
|
|
73
|
+
internalError: errorMessage
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { requirePermission };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createApiError } from "@inkeep/agents-core";
|
|
2
|
+
import { createMiddleware } from "hono/factory";
|
|
3
|
+
import { HTTPException } from "hono/http-exception";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/session-auth.ts
|
|
6
|
+
const sessionAuth = () => createMiddleware(async (c, next) => {
|
|
7
|
+
try {
|
|
8
|
+
const user = c.get("user");
|
|
9
|
+
if (!user) throw createApiError({
|
|
10
|
+
code: "unauthorized",
|
|
11
|
+
message: "Please log in to access this resource"
|
|
12
|
+
});
|
|
13
|
+
c.set("userId", user.id);
|
|
14
|
+
c.set("userEmail", user.email);
|
|
15
|
+
await next();
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof HTTPException) throw error;
|
|
18
|
+
throw createApiError({
|
|
19
|
+
code: "unauthorized",
|
|
20
|
+
message: "Authentication failed"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { sessionAuth };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as hono4 from "hono";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/tenant-access.d.ts
|
|
4
|
+
declare const requireTenantAccess: () => hono4.MiddlewareHandler<{
|
|
5
|
+
Variables: {
|
|
6
|
+
userId: string;
|
|
7
|
+
tenantId: string;
|
|
8
|
+
tenantRole: string;
|
|
9
|
+
};
|
|
10
|
+
}, string, {}, Response>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { requireTenantAccess };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import dbClient_default from "../data/db/dbClient.js";
|
|
2
|
+
import { createApiError, getUserOrganizations } from "@inkeep/agents-core";
|
|
3
|
+
import { createMiddleware } from "hono/factory";
|
|
4
|
+
import { HTTPException } from "hono/http-exception";
|
|
5
|
+
|
|
6
|
+
//#region src/middleware/tenant-access.ts
|
|
7
|
+
const requireTenantAccess = () => createMiddleware(async (c, next) => {
|
|
8
|
+
const userId = c.get("userId");
|
|
9
|
+
const tenantId = c.req.param("tenantId");
|
|
10
|
+
if (!userId) throw createApiError({
|
|
11
|
+
code: "unauthorized",
|
|
12
|
+
message: "User ID not found"
|
|
13
|
+
});
|
|
14
|
+
if (!tenantId) throw createApiError({
|
|
15
|
+
code: "bad_request",
|
|
16
|
+
message: "Organization ID is required"
|
|
17
|
+
});
|
|
18
|
+
if (userId === "system") {
|
|
19
|
+
c.set("tenantId", tenantId);
|
|
20
|
+
c.set("tenantRole", "owner");
|
|
21
|
+
await next();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (userId.startsWith("apikey:")) {
|
|
25
|
+
const apiKeyTenantId = c.get("tenantId");
|
|
26
|
+
if (apiKeyTenantId && apiKeyTenantId !== tenantId) throw createApiError({
|
|
27
|
+
code: "forbidden",
|
|
28
|
+
message: "API key does not have access to this organization"
|
|
29
|
+
});
|
|
30
|
+
c.set("tenantId", tenantId);
|
|
31
|
+
c.set("tenantRole", "owner");
|
|
32
|
+
await next();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const organizationAccess = (await getUserOrganizations(dbClient_default)(userId)).find((org) => org.organizationId === tenantId);
|
|
37
|
+
if (!organizationAccess) throw createApiError({
|
|
38
|
+
code: "forbidden",
|
|
39
|
+
message: "Access denied to this organization"
|
|
40
|
+
});
|
|
41
|
+
c.set("tenantId", tenantId);
|
|
42
|
+
c.set("tenantRole", organizationAccess.role);
|
|
43
|
+
await next();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error instanceof HTTPException) throw error;
|
|
46
|
+
throw createApiError({
|
|
47
|
+
code: "internal_server_error",
|
|
48
|
+
message: "Failed to verify organization access"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { requireTenantAccess };
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import { swaggerUI } from "@hono/swagger-ui";
|
|
3
|
+
|
|
4
|
+
//#region src/openapi.ts
|
|
5
|
+
function setupOpenAPIRoutes(app) {
|
|
6
|
+
app.get("/openapi.json", (c) => {
|
|
7
|
+
try {
|
|
8
|
+
const serverUrl = process.env.VERCEL_ENV === "production" && process.env.VERCEL_PROJECT_PRODUCTION_URL ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` : process.env.VERCEL_ENV === "preview" && process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : env.INKEEP_AGENTS_MANAGE_API_URL;
|
|
9
|
+
const document = app.getOpenAPIDocument({
|
|
10
|
+
openapi: "3.0.0",
|
|
11
|
+
info: {
|
|
12
|
+
title: "Inkeep Agents Manage API",
|
|
13
|
+
version: "1.0.0",
|
|
14
|
+
description: "REST API for the management of the Inkeep Agent Framework."
|
|
15
|
+
},
|
|
16
|
+
servers: [{
|
|
17
|
+
url: serverUrl,
|
|
18
|
+
description: "API Server"
|
|
19
|
+
}],
|
|
20
|
+
tags: [
|
|
21
|
+
{
|
|
22
|
+
name: "Agent",
|
|
23
|
+
description: "Operations for managing individual agents"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "Agent Artifact Component Relations",
|
|
27
|
+
description: "Operations for managing agent artifact component relationships"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "Agent Data Component Relations",
|
|
31
|
+
description: "Operations for managing agent data component relationships"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "Agents",
|
|
35
|
+
description: "Operations for managing agents"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "API Keys",
|
|
39
|
+
description: "Operations for managing API keys"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "Artifact Component",
|
|
43
|
+
description: "Operations for managing artifact components"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "Context Config",
|
|
47
|
+
description: "Operations for managing context configurations"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "Credential",
|
|
51
|
+
description: "Operations for managing credentials"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "Credential Store",
|
|
55
|
+
description: "Operations for managing credential stores"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "Data Component",
|
|
59
|
+
description: "Operations for managing data components"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "External Agents",
|
|
63
|
+
description: "Operations for managing external agents"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "Full Agent",
|
|
67
|
+
description: "Operations for managing complete agent definitions"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "Full Project",
|
|
71
|
+
description: "Operations for managing complete project definitions"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "Function Tools",
|
|
75
|
+
description: "Operations for managing function tools"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "Functions",
|
|
79
|
+
description: "Operations for managing functions"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "OAuth",
|
|
83
|
+
description: "OAuth authentication endpoints for MCP tools"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "Projects",
|
|
87
|
+
description: "Operations for managing projects"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "Sub Agent External Agent Relations",
|
|
91
|
+
description: "Operations for managing sub agent external agent relationships"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "Sub Agent Relations",
|
|
95
|
+
description: "Operations for managing sub agent relationships"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "Sub Agent Team Agent Relations",
|
|
99
|
+
description: "Operations for managing sub agent team agent relationships"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "SubAgent",
|
|
103
|
+
description: "Operations for managing sub agents"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "SubAgent Tool Relations",
|
|
107
|
+
description: "Operations for managing sub agent tool relationships"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "Tools",
|
|
111
|
+
description: "Operations for managing MCP tools"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
document.components = {
|
|
116
|
+
...document.components,
|
|
117
|
+
securitySchemes: {
|
|
118
|
+
...document.components?.securitySchemes || {},
|
|
119
|
+
cookieAuth: {
|
|
120
|
+
type: "apiKey",
|
|
121
|
+
in: "cookie",
|
|
122
|
+
name: "better-auth.session_token",
|
|
123
|
+
description: "Session-based authentication using HTTP-only cookies. Cookies are automatically sent by browsers. For server-side requests, include cookies with names starting with \"better-auth.\" in the Cookie header."
|
|
124
|
+
},
|
|
125
|
+
bearerAuth: {
|
|
126
|
+
type: "http",
|
|
127
|
+
scheme: "bearer",
|
|
128
|
+
bearerFormat: "Token",
|
|
129
|
+
description: "Bearer token authentication. Use this for API clients and service-to-service communication. Set the Authorization header to \"Bearer <token>\"."
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
document.security = [{
|
|
134
|
+
cookieAuth: [],
|
|
135
|
+
bearerAuth: []
|
|
136
|
+
}];
|
|
137
|
+
return c.json(document);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("OpenAPI document generation failed:", error);
|
|
140
|
+
const errorDetails = error instanceof Error ? {
|
|
141
|
+
message: error.message,
|
|
142
|
+
stack: error.stack
|
|
143
|
+
} : JSON.stringify(error, null, 2);
|
|
144
|
+
return c.json({
|
|
145
|
+
error: "Failed to generate OpenAPI document",
|
|
146
|
+
details: errorDetails
|
|
147
|
+
}, 500);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
app.get("/docs", swaggerUI({
|
|
151
|
+
url: "/openapi.json",
|
|
152
|
+
title: "Inkeep Agents Manage API Documentation"
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
export { setupOpenAPIRoutes };
|