@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
package/dist/factory.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import dbClient_default from "./data/db/dbClient.js";
|
|
3
|
+
import { createManagementHono } from "./create-app.js";
|
|
4
|
+
import { initializeDefaultUser } from "./initialization.js";
|
|
5
|
+
import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
|
|
6
|
+
import { CredentialStoreRegistry, createDefaultCredentialStores } from "@inkeep/agents-core";
|
|
7
|
+
import { createAuth } from "@inkeep/agents-core/auth";
|
|
3
8
|
|
|
9
|
+
//#region src/factory.ts
|
|
10
|
+
const defaultConfig = {
|
|
11
|
+
port: 3002,
|
|
12
|
+
serverOptions: {
|
|
13
|
+
requestTimeout: 6e4,
|
|
14
|
+
keepAliveTimeout: 6e4,
|
|
15
|
+
keepAlive: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function createManagementAuth(userAuthConfig) {
|
|
19
|
+
if (env.DISABLE_AUTH) return null;
|
|
20
|
+
return createAuth({
|
|
21
|
+
baseURL: env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002",
|
|
22
|
+
secret: env.BETTER_AUTH_SECRET || "development-secret-change-in-production",
|
|
23
|
+
dbClient: dbClient_default,
|
|
24
|
+
...userAuthConfig?.ssoProviders && { ssoProviders: userAuthConfig.ssoProviders },
|
|
25
|
+
...userAuthConfig?.socialProviders && { socialProviders: userAuthConfig.socialProviders }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function createManagementApp(config) {
|
|
29
|
+
const serverConfig = config?.serverConfig ?? defaultConfig;
|
|
30
|
+
const registry = new CredentialStoreRegistry(config?.credentialStores ?? createDefaultCredentialStores());
|
|
31
|
+
const auth$1 = createManagementAuth(config?.auth);
|
|
32
|
+
if (!config?.skipInitialization && env.ENVIRONMENT !== "test") initializeDefaultUser(auth$1);
|
|
33
|
+
return createManagementHono(serverConfig, registry, auth$1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
4
37
|
export { createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, initializeDefaultUser };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createManagementHono } from "./create-app.js";
|
|
2
|
+
import { initializeDefaultUser } from "./initialization.js";
|
|
3
|
+
import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
|
|
4
|
+
import { SSOProviderConfig, UserAuthConfig, createManagementApp } from "./factory.js";
|
|
2
5
|
import { Hono } from "hono";
|
|
3
6
|
import * as better_auth0 from "better-auth";
|
|
4
7
|
import * as better_auth_social_providers0 from "better-auth/social-providers";
|
|
@@ -19,7 +22,51 @@ declare const auth: better_auth0.Auth<{
|
|
|
19
22
|
autoSignIn: true;
|
|
20
23
|
};
|
|
21
24
|
socialProviders: {
|
|
22
|
-
google:
|
|
25
|
+
google: {
|
|
26
|
+
redirectURI?: string | undefined;
|
|
27
|
+
clientId: string;
|
|
28
|
+
accessType?: ("offline" | "online") | undefined;
|
|
29
|
+
display?: ("page" | "popup" | "touch" | "wap") | undefined;
|
|
30
|
+
hd?: string | undefined;
|
|
31
|
+
clientSecret?: string | undefined;
|
|
32
|
+
scope?: string[] | undefined;
|
|
33
|
+
disableDefaultScope?: boolean | undefined;
|
|
34
|
+
clientKey?: string | undefined;
|
|
35
|
+
disableIdTokenSignIn?: boolean | undefined;
|
|
36
|
+
verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
|
|
37
|
+
getUserInfo?: ((token: better_auth0.OAuth2Tokens) => Promise<{
|
|
38
|
+
user: {
|
|
39
|
+
id: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
email?: string | null;
|
|
42
|
+
image?: string;
|
|
43
|
+
emailVerified: boolean;
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
};
|
|
46
|
+
data: any;
|
|
47
|
+
}>) | undefined;
|
|
48
|
+
refreshAccessToken?: ((refreshToken: string) => Promise<better_auth0.OAuth2Tokens>) | undefined;
|
|
49
|
+
mapProfileToUser?: ((profile: better_auth_social_providers0.GoogleProfile) => {
|
|
50
|
+
id?: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
email?: string | null;
|
|
53
|
+
image?: string;
|
|
54
|
+
emailVerified?: boolean;
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
} | Promise<{
|
|
57
|
+
id?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
email?: string | null;
|
|
60
|
+
image?: string;
|
|
61
|
+
emailVerified?: boolean;
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}>) | undefined;
|
|
64
|
+
disableImplicitSignUp?: boolean | undefined;
|
|
65
|
+
disableSignUp?: boolean | undefined;
|
|
66
|
+
prompt?: ("select_account" | "consent" | "login" | "none" | "select_account consent") | undefined;
|
|
67
|
+
responseMode?: ("query" | "form_post") | undefined;
|
|
68
|
+
overrideUserInfoOnSignIn?: boolean | undefined;
|
|
69
|
+
};
|
|
23
70
|
} | undefined;
|
|
24
71
|
session: {
|
|
25
72
|
expiresIn: number;
|
|
@@ -660,6 +707,57 @@ declare const auth: better_auth0.Auth<{
|
|
|
660
707
|
enabled: true;
|
|
661
708
|
};
|
|
662
709
|
};
|
|
710
|
+
}, {
|
|
711
|
+
id: "oauth-proxy";
|
|
712
|
+
options: better_auth_plugins0.OAuthProxyOptions | undefined;
|
|
713
|
+
endpoints: {
|
|
714
|
+
oAuthProxy: better_auth0.StrictEndpoint<"/oauth-proxy-callback", {
|
|
715
|
+
method: "GET";
|
|
716
|
+
operationId: string;
|
|
717
|
+
query: zod0.ZodObject<{
|
|
718
|
+
callbackURL: zod0.ZodString;
|
|
719
|
+
cookies: zod0.ZodString;
|
|
720
|
+
}, better_auth0.$strip>;
|
|
721
|
+
use: ((inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>)[];
|
|
722
|
+
metadata: {
|
|
723
|
+
openapi: {
|
|
724
|
+
operationId: string;
|
|
725
|
+
description: string;
|
|
726
|
+
parameters: {
|
|
727
|
+
in: "query";
|
|
728
|
+
name: string;
|
|
729
|
+
required: true;
|
|
730
|
+
description: string;
|
|
731
|
+
}[];
|
|
732
|
+
responses: {
|
|
733
|
+
302: {
|
|
734
|
+
description: string;
|
|
735
|
+
headers: {
|
|
736
|
+
Location: {
|
|
737
|
+
description: string;
|
|
738
|
+
schema: {
|
|
739
|
+
type: string;
|
|
740
|
+
};
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
} & {
|
|
748
|
+
use: any[];
|
|
749
|
+
}, never>;
|
|
750
|
+
};
|
|
751
|
+
hooks: {
|
|
752
|
+
before: {
|
|
753
|
+
matcher(context: better_auth0.HookEndpointContext): boolean;
|
|
754
|
+
handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>;
|
|
755
|
+
}[];
|
|
756
|
+
after: {
|
|
757
|
+
matcher(context: better_auth0.HookEndpointContext): boolean;
|
|
758
|
+
handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>;
|
|
759
|
+
}[];
|
|
760
|
+
};
|
|
663
761
|
}, {
|
|
664
762
|
id: "organization";
|
|
665
763
|
endpoints: better_auth_plugins0.OrganizationEndpoints<{
|
|
@@ -667,25 +765,25 @@ declare const auth: better_auth0.Auth<{
|
|
|
667
765
|
ac: better_auth_plugins0.AccessControl;
|
|
668
766
|
roles: {
|
|
669
767
|
member: {
|
|
670
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
671
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
768
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
769
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
672
770
|
connector: "OR" | "AND";
|
|
673
771
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
674
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
772
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
675
773
|
};
|
|
676
774
|
admin: {
|
|
677
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
678
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
775
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
776
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
679
777
|
connector: "OR" | "AND";
|
|
680
778
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
681
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
779
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
682
780
|
};
|
|
683
781
|
owner: {
|
|
684
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
685
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
782
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
783
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
686
784
|
connector: "OR" | "AND";
|
|
687
785
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
688
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
786
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
689
787
|
};
|
|
690
788
|
};
|
|
691
789
|
membershipLimit: number;
|
|
@@ -946,25 +1044,25 @@ declare const auth: better_auth0.Auth<{
|
|
|
946
1044
|
ac: better_auth_plugins0.AccessControl;
|
|
947
1045
|
roles: {
|
|
948
1046
|
member: {
|
|
949
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
950
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1047
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1048
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
951
1049
|
connector: "OR" | "AND";
|
|
952
1050
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
953
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1051
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
954
1052
|
};
|
|
955
1053
|
admin: {
|
|
956
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
957
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1054
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1055
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
958
1056
|
connector: "OR" | "AND";
|
|
959
1057
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
960
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1058
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
961
1059
|
};
|
|
962
1060
|
owner: {
|
|
963
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
964
|
-
actions: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1061
|
+
authorize<K_1 extends "function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1062
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
965
1063
|
connector: "OR" | "AND";
|
|
966
1064
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
967
|
-
statements: better_auth_plugins0.Subset<"function" | "organization" | "
|
|
1065
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
968
1066
|
};
|
|
969
1067
|
};
|
|
970
1068
|
membershipLimit: number;
|
|
@@ -1327,5 +1425,4 @@ declare const auth: better_auth0.Auth<{
|
|
|
1327
1425
|
}> | null;
|
|
1328
1426
|
declare const app: Hono;
|
|
1329
1427
|
//#endregion
|
|
1330
|
-
export { Hono, type SSOProviderConfig, type UserAuthConfig, auth, createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, app as default, initializeDefaultUser };
|
|
1331
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1428
|
+
export { Hono, type SSOProviderConfig, type UserAuthConfig, auth, createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, app as default, initializeDefaultUser };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import dbClient_default from "./data/db/dbClient.js";
|
|
3
|
+
import { createManagementHono } from "./create-app.js";
|
|
4
|
+
import { initializeDefaultUser } from "./initialization.js";
|
|
5
|
+
import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
|
|
6
|
+
import { createManagementApp } from "./factory.js";
|
|
7
|
+
import { Hono } from "hono";
|
|
3
8
|
import { CredentialStoreRegistry, createDefaultCredentialStores } from "@inkeep/agents-core";
|
|
4
9
|
import { createAuth } from "@inkeep/agents-core/auth";
|
|
5
|
-
import { Hono } from "hono";
|
|
6
10
|
|
|
7
11
|
//#region src/index.ts
|
|
8
12
|
const defaultConfig = {
|
|
@@ -44,5 +48,4 @@ if (env.ENVIRONMENT === "development") initializeDefaultUser(auth);
|
|
|
44
48
|
var src_default = app;
|
|
45
49
|
|
|
46
50
|
//#endregion
|
|
47
|
-
export { Hono, auth, createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, src_default as default, initializeDefaultUser };
|
|
48
|
-
//# sourceMappingURL=index.js.map
|
|
51
|
+
export { Hono, auth, createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, src_default as default, initializeDefaultUser };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import { getLogger as getLogger$1 } from "./logger.js";
|
|
3
|
+
import dbClient_default from "./data/db/dbClient.js";
|
|
4
|
+
import { generateId, getUserByEmail, member, organization } from "@inkeep/agents-core";
|
|
5
|
+
import { and, eq } from "drizzle-orm";
|
|
6
|
+
|
|
7
|
+
//#region src/initialization.ts
|
|
8
|
+
const logger = getLogger$1("initialization");
|
|
9
|
+
async function initializeDefaultUser(authInstance) {
|
|
10
|
+
const { INKEEP_AGENTS_MANAGE_UI_USERNAME, INKEEP_AGENTS_MANAGE_UI_PASSWORD, DISABLE_AUTH } = env;
|
|
11
|
+
const hasCredentials = INKEEP_AGENTS_MANAGE_UI_USERNAME && INKEEP_AGENTS_MANAGE_UI_PASSWORD;
|
|
12
|
+
const orgId = env.TENANT_ID;
|
|
13
|
+
if ((await dbClient_default.select().from(organization).where(eq(organization.id, orgId)).limit(1)).length === 0) {
|
|
14
|
+
await dbClient_default.insert(organization).values({
|
|
15
|
+
id: orgId,
|
|
16
|
+
name: env.TENANT_ID,
|
|
17
|
+
slug: env.TENANT_ID,
|
|
18
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
19
|
+
logo: null,
|
|
20
|
+
metadata: null
|
|
21
|
+
});
|
|
22
|
+
logger.info({ organizationId: orgId }, "Created default organization");
|
|
23
|
+
} else logger.info({ organizationId: orgId }, "Organization already exists");
|
|
24
|
+
if (!hasCredentials || DISABLE_AUTH || !authInstance) {
|
|
25
|
+
logger.info({ hasCredentials: false }, "Skipping default user creation");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
let user = await getUserByEmail(dbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
|
|
30
|
+
if (user) logger.info({
|
|
31
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME,
|
|
32
|
+
userId: user.id
|
|
33
|
+
}, "Default user already exists");
|
|
34
|
+
else {
|
|
35
|
+
logger.info({ email: INKEEP_AGENTS_MANAGE_UI_USERNAME }, "Creating default user with Better Auth...");
|
|
36
|
+
if (!(await authInstance.api.signUpEmail({ body: {
|
|
37
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME,
|
|
38
|
+
password: INKEEP_AGENTS_MANAGE_UI_PASSWORD,
|
|
39
|
+
name: INKEEP_AGENTS_MANAGE_UI_USERNAME.split("@")[0]
|
|
40
|
+
} })).user) throw new Error("signUpEmail returned no user");
|
|
41
|
+
user = await getUserByEmail(dbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
|
|
42
|
+
if (!user) throw new Error("User was created but could not be retrieved from database");
|
|
43
|
+
logger.info({
|
|
44
|
+
email: user.email,
|
|
45
|
+
id: user.id
|
|
46
|
+
}, "Default user created from INKEEP_AGENTS_MANAGE_UI_USERNAME/INKEEP_AGENTS_MANAGE_UI_PASSWORD");
|
|
47
|
+
}
|
|
48
|
+
if ((await dbClient_default.select().from(member).where(and(eq(member.userId, user.id), eq(member.organizationId, orgId))).limit(1)).length === 0) {
|
|
49
|
+
await dbClient_default.insert(member).values({
|
|
50
|
+
id: generateId(),
|
|
51
|
+
userId: user.id,
|
|
52
|
+
organizationId: orgId,
|
|
53
|
+
role: "owner",
|
|
54
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
55
|
+
});
|
|
56
|
+
logger.info({
|
|
57
|
+
userId: user.id,
|
|
58
|
+
organizationId: orgId
|
|
59
|
+
}, "Added user as organization owner");
|
|
60
|
+
} else logger.info({
|
|
61
|
+
userId: user.id,
|
|
62
|
+
organizationId: orgId
|
|
63
|
+
}, "User already a member of organization");
|
|
64
|
+
logger.info({
|
|
65
|
+
organizationId: orgId,
|
|
66
|
+
organizationSlug: env.TENANT_ID,
|
|
67
|
+
userId: user.id,
|
|
68
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME
|
|
69
|
+
}, "✅ Initialization complete - login with these credentials");
|
|
70
|
+
} catch (error) {
|
|
71
|
+
logger.error({
|
|
72
|
+
error,
|
|
73
|
+
email: INKEEP_AGENTS_MANAGE_UI_USERNAME
|
|
74
|
+
}, "❌ Failed to create default user");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { initializeDefaultUser };
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as hono2 from "hono";
|
|
2
|
+
import { ExecutionContext } from "@inkeep/agents-core";
|
|
3
|
+
import { createAuth } from "@inkeep/agents-core/auth";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/auth.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Middleware to authenticate API requests using Bearer token authentication
|
|
9
|
+
* Authentication priority:
|
|
10
|
+
* 1. Bypass secret (INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET)
|
|
11
|
+
* 2. Better-auth session token (from device authorization flow)
|
|
12
|
+
* 3. Database API key
|
|
13
|
+
*/
|
|
14
|
+
declare const apiKeyAuth: () => hono2.MiddlewareHandler<{
|
|
15
|
+
Variables: {
|
|
16
|
+
executionContext: ExecutionContext;
|
|
17
|
+
userId?: string;
|
|
18
|
+
userEmail?: string;
|
|
19
|
+
tenantId?: string;
|
|
20
|
+
auth: ReturnType<typeof createAuth> | null;
|
|
21
|
+
};
|
|
22
|
+
}, string, {}, Response>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { apiKeyAuth };
|
|
@@ -0,0 +1,55 @@
|
|
|
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 session = await auth.api.getSession({ headers });
|
|
32
|
+
if (session?.user) {
|
|
33
|
+
logger.info({ userId: session.user.id }, "Better-auth session authenticated successfully");
|
|
34
|
+
c.set("userId", session.user.id);
|
|
35
|
+
c.set("userEmail", session.user.email);
|
|
36
|
+
await next();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger.debug({ error }, "Better-auth session validation failed, trying API key");
|
|
41
|
+
}
|
|
42
|
+
const validatedKey = await validateAndGetApiKey(token, dbClient_default);
|
|
43
|
+
if (validatedKey) {
|
|
44
|
+
logger.info({ keyId: validatedKey.id }, "API key authenticated successfully");
|
|
45
|
+
c.set("userId", `apikey:${validatedKey.id}`);
|
|
46
|
+
c.set("userEmail", `apikey-${validatedKey.id}@internal`);
|
|
47
|
+
c.set("tenantId", validatedKey.tenantId);
|
|
48
|
+
await next();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
throw new HTTPException(401, { message: "Invalid Token" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
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 hono4 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) => hono4.MiddlewareHandler<Env$1, string, {}, Response>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { requirePermission };
|