@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.
Files changed (123) hide show
  1. package/dist/create-app.d.ts +21 -0
  2. package/dist/create-app.js +144 -0
  3. package/dist/data/agentFull.d.ts +15 -0
  4. package/dist/data/agentFull.js +84 -0
  5. package/dist/data/conversations.d.ts +77 -0
  6. package/dist/data/conversations.js +152 -0
  7. package/dist/data/db/dbClient.d.ts +6 -0
  8. package/dist/data/db/dbClient.js +17 -0
  9. package/dist/env.d.ts +61 -0
  10. package/dist/env.js +55 -0
  11. package/dist/factory.d.ts +17 -2
  12. package/dist/factory.js +35 -2
  13. package/dist/index.d.ts +119 -22
  14. package/dist/index.js +8 -5
  15. package/dist/initialization.d.ts +6 -0
  16. package/dist/initialization.js +79 -0
  17. package/dist/logger.d.ts +2 -0
  18. package/dist/logger.js +3 -0
  19. package/dist/middleware/auth.d.ts +24 -0
  20. package/dist/middleware/auth.js +55 -0
  21. package/dist/middleware/error-handler.d.ts +12 -0
  22. package/dist/middleware/error-handler.js +88 -0
  23. package/dist/middleware/require-permission.d.ts +19 -0
  24. package/dist/middleware/require-permission.js +80 -0
  25. package/dist/middleware/session-auth.d.ts +6 -0
  26. package/dist/middleware/session-auth.js +26 -0
  27. package/dist/middleware/tenant-access.d.ts +12 -0
  28. package/dist/middleware/tenant-access.js +54 -0
  29. package/dist/openapi.d.ts +7 -0
  30. package/dist/openapi.js +157 -0
  31. package/dist/routes/agent.d.ts +9 -0
  32. package/dist/routes/agent.js +244 -0
  33. package/dist/routes/agentFull.d.ts +9 -0
  34. package/dist/routes/agentFull.js +188 -0
  35. package/dist/routes/agentToolRelations.d.ts +9 -0
  36. package/dist/routes/agentToolRelations.js +284 -0
  37. package/dist/routes/apiKeys.d.ts +9 -0
  38. package/dist/routes/apiKeys.js +217 -0
  39. package/dist/routes/artifactComponents.d.ts +9 -0
  40. package/dist/routes/artifactComponents.js +204 -0
  41. package/dist/routes/cliAuth.d.ts +9 -0
  42. package/dist/routes/cliAuth.js +60 -0
  43. package/dist/routes/contextConfigs.d.ts +9 -0
  44. package/dist/routes/contextConfigs.js +175 -0
  45. package/dist/routes/conversations.d.ts +7 -0
  46. package/dist/routes/conversations.js +59 -0
  47. package/dist/routes/credentialStores.d.ts +9 -0
  48. package/dist/routes/credentialStores.js +81 -0
  49. package/dist/routes/credentials.d.ts +9 -0
  50. package/dist/routes/credentials.js +204 -0
  51. package/dist/routes/dataComponents.d.ts +9 -0
  52. package/dist/routes/dataComponents.js +188 -0
  53. package/dist/routes/externalAgents.d.ts +9 -0
  54. package/dist/routes/externalAgents.js +195 -0
  55. package/dist/routes/functionTools.d.ts +9 -0
  56. package/dist/routes/functionTools.js +252 -0
  57. package/dist/routes/functions.d.ts +9 -0
  58. package/dist/routes/functions.js +281 -0
  59. package/dist/routes/index.d.ts +7 -0
  60. package/dist/routes/index.js +54 -0
  61. package/dist/routes/invitations.d.ts +9 -0
  62. package/dist/routes/invitations.js +41 -0
  63. package/dist/routes/mcp.d.ts +7 -0
  64. package/dist/routes/mcp.js +45 -0
  65. package/dist/routes/mcpCatalog.d.ts +13 -0
  66. package/dist/routes/mcpCatalog.js +454 -0
  67. package/dist/routes/oauth.d.ts +10 -0
  68. package/dist/routes/oauth.js +314 -0
  69. package/dist/routes/playgroundToken.d.ts +9 -0
  70. package/dist/routes/playgroundToken.js +108 -0
  71. package/dist/routes/projectFull.d.ts +9 -0
  72. package/dist/routes/projectFull.js +193 -0
  73. package/dist/routes/projects.d.ts +9 -0
  74. package/dist/routes/projects.js +188 -0
  75. package/dist/routes/shared.d.ts +93 -0
  76. package/dist/routes/shared.js +44 -0
  77. package/dist/routes/signoz.d.ts +10 -0
  78. package/dist/routes/signoz.js +155 -0
  79. package/dist/routes/subAgentArtifactComponents.d.ts +9 -0
  80. package/dist/routes/subAgentArtifactComponents.js +198 -0
  81. package/dist/routes/subAgentDataComponents.d.ts +9 -0
  82. package/dist/routes/subAgentDataComponents.js +197 -0
  83. package/dist/routes/subAgentExternalAgentRelations.d.ts +9 -0
  84. package/dist/routes/subAgentExternalAgentRelations.js +213 -0
  85. package/dist/routes/subAgentRelations.d.ts +9 -0
  86. package/dist/routes/subAgentRelations.js +259 -0
  87. package/dist/routes/subAgentTeamAgentRelations.d.ts +9 -0
  88. package/dist/routes/subAgentTeamAgentRelations.js +213 -0
  89. package/dist/routes/subAgentToolRelations.d.ts +9 -0
  90. package/dist/routes/subAgentToolRelations.js +284 -0
  91. package/dist/routes/subAgents.d.ts +9 -0
  92. package/dist/routes/subAgents.js +210 -0
  93. package/dist/routes/thirdPartyMCPServers.d.ts +14 -0
  94. package/dist/routes/thirdPartyMCPServers.js +72 -0
  95. package/dist/routes/tools.d.ts +9 -0
  96. package/dist/routes/tools.js +256 -0
  97. package/dist/routes/userOrganizations.d.ts +9 -0
  98. package/dist/routes/userOrganizations.js +58 -0
  99. package/dist/sso-helpers.d.ts +20 -0
  100. package/dist/sso-helpers.js +51 -0
  101. package/dist/types/app.d.ts +47 -0
  102. package/dist/types/app.js +1 -0
  103. package/dist/utils/cors.d.ts +33 -0
  104. package/dist/utils/cors.js +98 -0
  105. package/dist/utils/oauth-service.d.ts +71 -0
  106. package/dist/utils/oauth-service.js +106 -0
  107. package/dist/utils/signoz-helpers.d.ts +9 -0
  108. package/dist/utils/signoz-helpers.js +33 -0
  109. package/dist/utils/temp-api-keys.d.ts +17 -0
  110. package/dist/utils/temp-api-keys.js +26 -0
  111. package/package.json +6 -13
  112. package/dist/chunk-VBDAOXYI.js +0 -832
  113. package/dist/chunk-VBDAOXYI.js.map +0 -1
  114. package/dist/factory2.d.ts +0 -41
  115. package/dist/factory2.d.ts.map +0 -1
  116. package/dist/factory2.js +0 -37085
  117. package/dist/factory2.js.map +0 -1
  118. package/dist/index.d.ts.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. package/dist/nodefs.js +0 -27
  121. package/dist/nodefs.js.map +0 -1
  122. package/dist/opfs-ahp.js +0 -368
  123. package/dist/opfs-ahp.js.map +0 -1
package/dist/factory.js CHANGED
@@ -1,4 +1,37 @@
1
- import { a as createManagementHono, i as initializeDefaultUser, n as createAuth0Provider, r as createOIDCProvider, t as createManagementApp } from "./factory2.js";
2
- import "./chunk-VBDAOXYI.js";
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 { a as createOIDCProvider, i as createAuth0Provider, n as UserAuthConfig, o as initializeDefaultUser, r as createManagementApp, s as createManagementHono, t as SSOProviderConfig } from "./factory2.js";
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: better_auth_social_providers0.GoogleOptions;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
671
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
678
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
685
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
950
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
957
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key] | {
964
- actions: better_auth_plugins0.Subset<"function" | "organization" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>[key];
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" | "ac" | "member" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "invitation" | "team", better_auth_plugins0.Statements>;
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 { a as createManagementHono, i as initializeDefaultUser, n as createAuth0Provider, o as dbClient_default, r as createOIDCProvider, s as env, t as createManagementApp } from "./factory2.js";
2
- import "./chunk-VBDAOXYI.js";
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,6 @@
1
+ import { createAuth } from "@inkeep/agents-core/auth";
2
+
3
+ //#region src/initialization.d.ts
4
+ declare function initializeDefaultUser(authInstance?: ReturnType<typeof createAuth> | null): Promise<void>;
5
+ //#endregion
6
+ export { 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 };
@@ -0,0 +1,2 @@
1
+ import { getLogger } from "@inkeep/agents-core";
2
+ export { getLogger };
package/dist/logger.js ADDED
@@ -0,0 +1,3 @@
1
+ import { getLogger } from "@inkeep/agents-core";
2
+
3
+ export { getLogger };
@@ -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 };