@inkeep/agents-manage-api 0.0.0-dev-20260113172432 → 0.0.0-dev-20260115183047

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 (93) hide show
  1. package/README.md +2 -1
  2. package/dist/create-app.d.ts +6 -4
  3. package/dist/create-app.js +11 -3
  4. package/dist/data/db/dbClient.d.ts +3 -3
  5. package/dist/data/db/dbClient.js +3 -11
  6. package/dist/data/db/runDbClient.d.ts +6 -0
  7. package/dist/data/db/runDbClient.js +9 -0
  8. package/dist/env.d.ts +6 -2
  9. package/dist/env.js +3 -1
  10. package/dist/factory.d.ts +1 -1
  11. package/dist/factory.js +2 -2
  12. package/dist/index.d.ts +18 -18
  13. package/dist/index.js +3 -3
  14. package/dist/initialization.js +7 -7
  15. package/dist/middleware/auth.d.ts +5 -4
  16. package/dist/middleware/auth.js +19 -3
  17. package/dist/middleware/branch-scoped-db.d.ts +31 -0
  18. package/dist/middleware/branch-scoped-db.js +137 -0
  19. package/dist/middleware/ref.d.ts +11 -0
  20. package/dist/middleware/ref.js +170 -0
  21. package/dist/middleware/require-permission.d.ts +7 -12
  22. package/dist/middleware/session-auth.d.ts +2 -2
  23. package/dist/middleware/tenant-access.d.ts +2 -2
  24. package/dist/middleware/tenant-access.js +2 -2
  25. package/dist/routes/agent.js +28 -9
  26. package/dist/routes/agentFull.js +27 -8
  27. package/dist/routes/agentToolRelations.js +15 -10
  28. package/dist/routes/apiKeys.js +7 -6
  29. package/dist/routes/artifactComponents.js +10 -6
  30. package/dist/routes/branches.d.ts +9 -0
  31. package/dist/routes/branches.js +182 -0
  32. package/dist/routes/cliAuth.js +2 -2
  33. package/dist/routes/contextConfigs.js +21 -7
  34. package/dist/routes/conversations.d.ts +2 -2
  35. package/dist/routes/conversations.js +2 -2
  36. package/dist/routes/credentials.js +10 -7
  37. package/dist/routes/dataComponents.js +10 -6
  38. package/dist/routes/evals/datasetItems.d.ts +9 -0
  39. package/dist/routes/evals/datasetItems.js +310 -0
  40. package/dist/routes/evals/datasetRunConfigs.d.ts +9 -0
  41. package/dist/routes/evals/datasetRunConfigs.js +402 -0
  42. package/dist/routes/evals/datasetRuns.d.ts +9 -0
  43. package/dist/routes/evals/datasetRuns.js +256 -0
  44. package/dist/routes/evals/datasets.d.ts +9 -0
  45. package/dist/routes/evals/datasets.js +238 -0
  46. package/dist/routes/evals/evaluationJobConfigEvaluatorRelations.d.ts +9 -0
  47. package/dist/routes/evals/evaluationJobConfigEvaluatorRelations.js +146 -0
  48. package/dist/routes/evals/evaluationJobConfigs.d.ts +9 -0
  49. package/dist/routes/evals/evaluationJobConfigs.js +361 -0
  50. package/dist/routes/evals/evaluationResults.d.ts +7 -0
  51. package/dist/routes/evals/evaluationResults.js +192 -0
  52. package/dist/routes/evals/evaluationRunConfigs.d.ts +9 -0
  53. package/dist/routes/evals/evaluationRunConfigs.js +462 -0
  54. package/dist/routes/evals/evaluationSuiteConfigEvaluatorRelations.d.ts +9 -0
  55. package/dist/routes/evals/evaluationSuiteConfigEvaluatorRelations.js +146 -0
  56. package/dist/routes/evals/evaluationSuiteConfigs.d.ts +9 -0
  57. package/dist/routes/evals/evaluationSuiteConfigs.js +246 -0
  58. package/dist/routes/evals/evaluators.d.ts +9 -0
  59. package/dist/routes/evals/evaluators.js +281 -0
  60. package/dist/routes/evals/index.d.ts +9 -0
  61. package/dist/routes/evals/index.js +26 -0
  62. package/dist/routes/externalAgents.js +10 -6
  63. package/dist/routes/functionTools.js +10 -6
  64. package/dist/routes/functions.js +14 -10
  65. package/dist/routes/index.js +6 -0
  66. package/dist/routes/invitations.js +2 -2
  67. package/dist/routes/mcp.d.ts +2 -2
  68. package/dist/routes/oauth.js +9 -8
  69. package/dist/routes/playgroundToken.js +3 -3
  70. package/dist/routes/projectFull.js +130 -20
  71. package/dist/routes/projects.js +65 -11
  72. package/dist/routes/ref.d.ts +9 -0
  73. package/dist/routes/ref.js +33 -0
  74. package/dist/routes/signoz.d.ts +2 -2
  75. package/dist/routes/signoz.js +3 -3
  76. package/dist/routes/subAgentArtifactComponents.js +13 -9
  77. package/dist/routes/subAgentDataComponents.js +13 -9
  78. package/dist/routes/subAgentExternalAgentRelations.js +11 -7
  79. package/dist/routes/subAgentFunctionTools.d.ts +9 -0
  80. package/dist/routes/subAgentFunctionTools.js +205 -0
  81. package/dist/routes/subAgentRelations.js +14 -10
  82. package/dist/routes/subAgentTeamAgentRelations.js +11 -7
  83. package/dist/routes/subAgentToolRelations.js +15 -10
  84. package/dist/routes/subAgents.js +17 -7
  85. package/dist/routes/tools.js +18 -13
  86. package/dist/routes/userOrganizations.js +3 -3
  87. package/dist/types/app.d.ts +4 -1
  88. package/dist/utils/temp-api-keys.d.ts +2 -2
  89. package/dist/utils/workflow-api-helpers.d.ts +1 -0
  90. package/dist/utils/workflow-api-helpers.js +1 -0
  91. package/package.json +10 -6
  92. package/dist/data/conversations.d.ts +0 -77
  93. package/dist/data/conversations.js +0 -152
package/README.md CHANGED
@@ -41,7 +41,8 @@ pnpm db:migrate
41
41
  ```env
42
42
  ENVIRONMENT=development|production|test
43
43
  PORT=3002
44
- DATABASE_URL=pg_db_url
44
+ INKEEP_AGENTS_RUN_DATABASE_URL=pg_db_url
45
+ INKEEP_AGENTS_MANAGE_DATABASE_URL=dolt_db_url
45
46
  LOG_LEVEL=debug|info|warn|error
46
47
  ```
47
48
 
@@ -1,13 +1,13 @@
1
+ import * as _inkeep_agents_core0 from "@inkeep/agents-core";
2
+ import { CredentialStoreRegistry, ServerConfig } from "@inkeep/agents-core";
1
3
  import { Hono } from "hono";
2
- import { ServerConfig } from "@inkeep/agents-core";
3
4
  import { auth, createAuth } from "@inkeep/agents-core/auth";
4
5
  import * as hono_types0 from "hono/types";
5
- import { CredentialStoreRegistry as CredentialStoreRegistry$1 } from "@inkeep/agents-core/credential-stores";
6
6
 
7
7
  //#region src/create-app.d.ts
8
8
  type AppVariables = {
9
9
  serverConfig: ServerConfig;
10
- credentialStores: CredentialStoreRegistry$1;
10
+ credentialStores: CredentialStoreRegistry;
11
11
  auth: ReturnType<typeof createAuth> | null;
12
12
  user: typeof auth.$Infer.Session.user | null;
13
13
  session: typeof auth.$Infer.Session.session | null;
@@ -15,7 +15,9 @@ type AppVariables = {
15
15
  userEmail?: string;
16
16
  tenantId?: string;
17
17
  tenantRole?: string;
18
+ isInternalService?: boolean;
19
+ internalServicePayload?: _inkeep_agents_core0.InternalServiceTokenPayload;
18
20
  };
19
- declare function createManagementHono(serverConfig: ServerConfig, credentialStores: CredentialStoreRegistry$1, auth: ReturnType<typeof createAuth> | null): Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
21
+ declare function createManagementHono(serverConfig: ServerConfig, credentialStores: CredentialStoreRegistry, auth: ReturnType<typeof createAuth> | null): Hono<hono_types0.BlankEnv, hono_types0.BlankSchema, "/">;
20
22
  //#endregion
21
23
  export { AppVariables, createManagementHono };
@@ -1,11 +1,14 @@
1
1
  import { env } from "./env.js";
2
- import { getLogger } from "./logger.js";
2
+ import { getLogger as getLogger$1 } from "./logger.js";
3
3
  import { apiKeyAuth } from "./middleware/auth.js";
4
+ import { branchScopedDbMiddleware } from "./middleware/branch-scoped-db.js";
4
5
  import { errorHandler } from "./middleware/error-handler.js";
6
+ import { refMiddleware, writeProtectionMiddleware } from "./middleware/ref.js";
5
7
  import { sessionAuth } from "./middleware/session-auth.js";
6
8
  import { requireTenantAccess } from "./middleware/tenant-access.js";
7
9
  import { setupOpenAPIRoutes } from "./openapi.js";
8
10
  import cliAuth_default from "./routes/cliAuth.js";
11
+ import evals_default from "./routes/evals/index.js";
9
12
  import routes_default from "./routes/index.js";
10
13
  import invitations_default from "./routes/invitations.js";
11
14
  import mcp_default from "./routes/mcp.js";
@@ -16,13 +19,14 @@ import signoz_default from "./routes/signoz.js";
16
19
  import userOrganizations_default from "./routes/userOrganizations.js";
17
20
  import { authCorsConfig, defaultCorsConfig, isOriginAllowed, playgroundCorsConfig } from "./utils/cors.js";
18
21
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
22
+ import { handleApiError } from "@inkeep/agents-core";
19
23
  import { Hono } from "hono";
20
24
  import { cors } from "hono/cors";
21
25
  import { requestId } from "hono/request-id";
22
26
  import { pinoLogger } from "hono-pino";
23
27
 
24
28
  //#region src/create-app.ts
25
- const logger = getLogger("agents-manage-api");
29
+ const logger = getLogger$1("agents-manage-api");
26
30
  logger.info({ logger: logger.getTransports() }, "Logger initialized");
27
31
  const isTestEnvironment = () => process.env.ENVIRONMENT === "test";
28
32
  function createManagementHono(serverConfig, credentialStores, auth) {
@@ -35,7 +39,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
35
39
  return next();
36
40
  });
37
41
  app.use(pinoLogger({
38
- pino: getLogger("agents-manage-api").getPinoInstance(),
42
+ pino: getLogger$1("agents-manage-api").getPinoInstance(),
39
43
  http: { onResLevel(c) {
40
44
  if (c.res.status >= 500) return "error";
41
45
  return "info";
@@ -125,6 +129,9 @@ function createManagementHono(serverConfig, credentialStores, auth) {
125
129
  await next();
126
130
  });
127
131
  else app.use("/tenants/:tenantId/*", requireTenantAccess());
132
+ app.use("/tenants/*", async (c, next) => refMiddleware(c, next));
133
+ app.use("/tenants/*", (c, next) => writeProtectionMiddleware(c, next));
134
+ app.use("/tenants/*", async (c, next) => branchScopedDbMiddleware(c, next));
128
135
  app.route("/api/users/:userId/organizations", userOrganizations_default);
129
136
  app.route("/api/cli", cliAuth_default);
130
137
  app.route("/api/invitations", invitations_default);
@@ -132,6 +139,7 @@ function createManagementHono(serverConfig, credentialStores, auth) {
132
139
  app.route("/tenants/:tenantId/playground/token", playgroundToken_default);
133
140
  app.route("/tenants/:tenantId/signoz", signoz_default);
134
141
  app.route("/tenants/:tenantId", projectFull_default);
142
+ app.route("/tenants/:tenantId/projects/:projectId/evals", evals_default);
135
143
  app.route("/oauth", oauth_default);
136
144
  app.route("/mcp", mcp_default);
137
145
  setupOpenAPIRoutes(app);
@@ -1,6 +1,6 @@
1
- import { DatabaseClient } from "@inkeep/agents-core";
1
+ import * as _inkeep_agents_core0 from "@inkeep/agents-core";
2
2
 
3
3
  //#region src/data/db/dbClient.d.ts
4
- declare let dbClient: DatabaseClient;
4
+ declare const manageDbClient: _inkeep_agents_core0.AgentsManageDatabaseClient;
5
5
  //#endregion
6
- export { dbClient as default };
6
+ export { manageDbClient as default };
@@ -1,17 +1,9 @@
1
1
  import { env } from "../../env.js";
2
- import { createDatabaseClient } from "@inkeep/agents-core";
3
- import { PGlite } from "@electric-sql/pglite";
4
- import * as schema from "@inkeep/agents-core/db/schema";
5
- import { drizzle } from "drizzle-orm/pglite";
2
+ import { createAgentsManageDatabaseClient } from "@inkeep/agents-core";
6
3
 
7
4
  //#region src/data/db/dbClient.ts
8
- let dbClient;
9
- if (env.ENVIRONMENT === "test") dbClient = drizzle({
10
- client: new PGlite(),
11
- schema
12
- });
13
- else dbClient = createDatabaseClient({ connectionString: env.DATABASE_URL });
14
- var dbClient_default = dbClient;
5
+ const manageDbClient = createAgentsManageDatabaseClient({ connectionString: env.INKEEP_AGENTS_MANAGE_DATABASE_URL });
6
+ var dbClient_default = manageDbClient;
15
7
 
16
8
  //#endregion
17
9
  export { dbClient_default as default };
@@ -0,0 +1,6 @@
1
+ import * as _inkeep_agents_core1 from "@inkeep/agents-core";
2
+
3
+ //#region src/data/db/runDbClient.d.ts
4
+ declare const runDbClient: _inkeep_agents_core1.AgentsRunDatabaseClient;
5
+ //#endregion
6
+ export { runDbClient as default };
@@ -0,0 +1,9 @@
1
+ import { env } from "../../env.js";
2
+ import { createAgentsRunDatabaseClient } from "@inkeep/agents-core";
3
+
4
+ //#region src/data/db/runDbClient.ts
5
+ const runDbClient = createAgentsRunDatabaseClient({ connectionString: env.INKEEP_AGENTS_RUN_DATABASE_URL });
6
+ var runDbClient_default = runDbClient;
7
+
8
+ //#endregion
9
+ export { runDbClient_default as default };
package/dist/env.d.ts CHANGED
@@ -15,7 +15,9 @@ declare const envSchema: z.ZodObject<{
15
15
  }>>;
16
16
  INKEEP_AGENTS_MANAGE_API_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
17
17
  INKEEP_AGENTS_MANAGE_UI_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
18
- DATABASE_URL: z.ZodOptional<z.ZodString>;
18
+ INKEEP_AGENTS_EVAL_API_URL: z.ZodDefault<z.ZodOptional<z.ZodString>>;
19
+ INKEEP_AGENTS_MANAGE_DATABASE_URL: z.ZodOptional<z.ZodString>;
20
+ INKEEP_AGENTS_RUN_DATABASE_URL: z.ZodOptional<z.ZodString>;
19
21
  LOG_LEVEL: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
20
22
  trace: "trace";
21
23
  debug: "debug";
@@ -39,13 +41,15 @@ declare const envSchema: z.ZodObject<{
39
41
  declare const env: {
40
42
  INKEEP_AGENTS_MANAGE_API_URL: string;
41
43
  INKEEP_AGENTS_MANAGE_UI_URL: string;
44
+ INKEEP_AGENTS_EVAL_API_URL: string;
42
45
  LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error";
43
46
  NANGO_SERVER_URL: string;
44
47
  TENANT_ID: string;
45
48
  DISABLE_AUTH: boolean;
46
49
  NODE_ENV?: "development" | "production" | "test" | undefined;
47
50
  ENVIRONMENT?: "development" | "production" | "test" | "pentest" | undefined;
48
- DATABASE_URL?: string | undefined;
51
+ INKEEP_AGENTS_MANAGE_DATABASE_URL?: string | undefined;
52
+ INKEEP_AGENTS_RUN_DATABASE_URL?: string | undefined;
49
53
  NANGO_SECRET_KEY?: string | undefined;
50
54
  INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET?: string | undefined;
51
55
  BETTER_AUTH_SECRET?: string | undefined;
package/dist/env.js CHANGED
@@ -17,7 +17,9 @@ const envSchema = z.object({
17
17
  ]).optional(),
18
18
  INKEEP_AGENTS_MANAGE_API_URL: z.string().optional().default("http://localhost:3002"),
19
19
  INKEEP_AGENTS_MANAGE_UI_URL: z.string().optional().default("http://localhost:3000"),
20
- DATABASE_URL: z.string().optional(),
20
+ INKEEP_AGENTS_EVAL_API_URL: z.string().optional().default("http://localhost:3005"),
21
+ INKEEP_AGENTS_MANAGE_DATABASE_URL: z.string().optional(),
22
+ INKEEP_AGENTS_RUN_DATABASE_URL: z.string().optional(),
21
23
  LOG_LEVEL: z.enum([
22
24
  "trace",
23
25
  "debug",
package/dist/factory.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createManagementHono } from "./create-app.js";
2
2
  import { initializeDefaultUser } from "./initialization.js";
3
3
  import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
4
- import * as hono0 from "hono";
5
4
  import { CredentialStore, ServerConfig } from "@inkeep/agents-core";
5
+ import * as hono0 from "hono";
6
6
  import { SSOProviderConfig, UserAuthConfig } from "@inkeep/agents-core/auth";
7
7
  import * as hono_types1 from "hono/types";
8
8
 
package/dist/factory.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { env } from "./env.js";
2
- import dbClient_default from "./data/db/dbClient.js";
2
+ import runDbClient_default from "./data/db/runDbClient.js";
3
3
  import { createManagementHono } from "./create-app.js";
4
4
  import { initializeDefaultUser } from "./initialization.js";
5
5
  import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
@@ -20,7 +20,7 @@ function createManagementAuth(userAuthConfig) {
20
20
  return createAuth({
21
21
  baseURL: env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002",
22
22
  secret: env.BETTER_AUTH_SECRET || "development-secret-change-in-production",
23
- dbClient: dbClient_default,
23
+ dbClient: runDbClient_default,
24
24
  ...userAuthConfig?.ssoProviders && { ssoProviders: userAuthConfig.ssoProviders },
25
25
  ...userAuthConfig?.socialProviders && { socialProviders: userAuthConfig.socialProviders }
26
26
  });
package/dist/index.d.ts CHANGED
@@ -785,25 +785,25 @@ declare const auth: better_auth0.Auth<{
785
785
  ac: better_auth_plugins0.AccessControl;
786
786
  roles: {
787
787
  member: {
788
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
789
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
788
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
789
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
790
790
  connector: "OR" | "AND";
791
791
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
792
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
792
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
793
793
  };
794
794
  admin: {
795
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
796
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
795
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
796
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
797
797
  connector: "OR" | "AND";
798
798
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
799
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
799
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
800
800
  };
801
801
  owner: {
802
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
803
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
802
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
803
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
804
804
  connector: "OR" | "AND";
805
805
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
806
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
806
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
807
807
  };
808
808
  };
809
809
  membershipLimit: number;
@@ -1064,25 +1064,25 @@ declare const auth: better_auth0.Auth<{
1064
1064
  ac: better_auth_plugins0.AccessControl;
1065
1065
  roles: {
1066
1066
  member: {
1067
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
1068
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
1067
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
1068
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1069
1069
  connector: "OR" | "AND";
1070
1070
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1071
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
1071
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1072
1072
  };
1073
1073
  admin: {
1074
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
1075
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
1074
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
1075
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1076
1076
  connector: "OR" | "AND";
1077
1077
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1078
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
1078
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1079
1079
  };
1080
1080
  owner: {
1081
- authorize<K_1 extends "function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key] | {
1082
- actions: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>[key];
1081
+ authorize<K_1 extends "function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "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" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
1082
+ actions: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1083
1083
  connector: "OR" | "AND";
1084
1084
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1085
- statements: better_auth_plugins0.Subset<"function" | "organization" | "agent" | "invitation" | "member" | "project" | "tool" | "sub_agent" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team" | "ac", better_auth_plugins0.Statements>;
1085
+ statements: better_auth_plugins0.Subset<"function" | "invitation" | "member" | "organization" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1086
1086
  };
1087
1087
  };
1088
1088
  membershipLimit: number;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { env } from "./env.js";
2
- import dbClient_default from "./data/db/dbClient.js";
2
+ import runDbClient_default from "./data/db/runDbClient.js";
3
3
  import { createManagementHono } from "./create-app.js";
4
4
  import { initializeDefaultUser } from "./initialization.js";
5
5
  import { createAuth0Provider, createOIDCProvider } from "./sso-helpers.js";
6
6
  import { createManagementApp } from "./factory.js";
7
- import { Hono } from "hono";
8
7
  import { CredentialStoreRegistry, createDefaultCredentialStores } from "@inkeep/agents-core";
8
+ import { Hono } from "hono";
9
9
  import { createAuth } from "@inkeep/agents-core/auth";
10
10
 
11
11
  //#region src/index.ts
@@ -23,7 +23,7 @@ function createManagementAuth(userAuthConfig) {
23
23
  return createAuth({
24
24
  baseURL: env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002",
25
25
  secret: env.BETTER_AUTH_SECRET || "development-secret-change-in-production",
26
- dbClient: dbClient_default,
26
+ dbClient: runDbClient_default,
27
27
  ...userAuthConfig?.ssoProviders && { ssoProviders: userAuthConfig.ssoProviders },
28
28
  ...userAuthConfig?.socialProviders && { socialProviders: userAuthConfig.socialProviders }
29
29
  });
@@ -1,6 +1,6 @@
1
1
  import { env } from "./env.js";
2
2
  import { getLogger as getLogger$1 } from "./logger.js";
3
- import dbClient_default from "./data/db/dbClient.js";
3
+ import runDbClient_default from "./data/db/runDbClient.js";
4
4
  import { generateId, getUserByEmail, member, organization } from "@inkeep/agents-core";
5
5
  import { and, eq } from "drizzle-orm";
6
6
 
@@ -10,8 +10,8 @@ async function initializeDefaultUser(authInstance) {
10
10
  const { INKEEP_AGENTS_MANAGE_UI_USERNAME, INKEEP_AGENTS_MANAGE_UI_PASSWORD, DISABLE_AUTH } = env;
11
11
  const hasCredentials = INKEEP_AGENTS_MANAGE_UI_USERNAME && INKEEP_AGENTS_MANAGE_UI_PASSWORD;
12
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({
13
+ if ((await runDbClient_default.select().from(organization).where(eq(organization.id, orgId)).limit(1)).length === 0) {
14
+ await runDbClient_default.insert(organization).values({
15
15
  id: orgId,
16
16
  name: env.TENANT_ID,
17
17
  slug: env.TENANT_ID,
@@ -26,7 +26,7 @@ async function initializeDefaultUser(authInstance) {
26
26
  return;
27
27
  }
28
28
  try {
29
- let user = await getUserByEmail(dbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
29
+ let user = await getUserByEmail(runDbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
30
30
  if (user) logger.info({
31
31
  email: INKEEP_AGENTS_MANAGE_UI_USERNAME,
32
32
  userId: user.id
@@ -38,15 +38,15 @@ async function initializeDefaultUser(authInstance) {
38
38
  password: INKEEP_AGENTS_MANAGE_UI_PASSWORD,
39
39
  name: INKEEP_AGENTS_MANAGE_UI_USERNAME.split("@")[0]
40
40
  } })).user) throw new Error("signUpEmail returned no user");
41
- user = await getUserByEmail(dbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
41
+ user = await getUserByEmail(runDbClient_default)(INKEEP_AGENTS_MANAGE_UI_USERNAME);
42
42
  if (!user) throw new Error("User was created but could not be retrieved from database");
43
43
  logger.info({
44
44
  email: user.email,
45
45
  id: user.id
46
46
  }, "Default user created from INKEEP_AGENTS_MANAGE_UI_USERNAME/INKEEP_AGENTS_MANAGE_UI_PASSWORD");
47
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({
48
+ if ((await runDbClient_default.select().from(member).where(and(eq(member.userId, user.id), eq(member.organizationId, orgId))).limit(1)).length === 0) {
49
+ await runDbClient_default.insert(member).values({
50
50
  id: generateId(),
51
51
  userId: user.id,
52
52
  organizationId: orgId,
@@ -1,5 +1,5 @@
1
- import * as hono0 from "hono";
2
- import { ExecutionContext } from "@inkeep/agents-core";
1
+ import { BaseExecutionContext } from "@inkeep/agents-core";
2
+ import * as hono6 from "hono";
3
3
  import { createAuth } from "@inkeep/agents-core/auth";
4
4
 
5
5
  //#region src/middleware/auth.d.ts
@@ -10,10 +10,11 @@ import { createAuth } from "@inkeep/agents-core/auth";
10
10
  * 1. Bypass secret (INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET)
11
11
  * 2. Better-auth session token (from device authorization flow)
12
12
  * 3. Database API key
13
+ * 4. Internal service token
13
14
  */
14
- declare const apiKeyAuth: () => hono0.MiddlewareHandler<{
15
+ declare const apiKeyAuth: () => hono6.MiddlewareHandler<{
15
16
  Variables: {
16
- executionContext: ExecutionContext;
17
+ executionContext: BaseExecutionContext;
17
18
  userId?: string;
18
19
  userEmail?: string;
19
20
  tenantId?: string;
@@ -1,6 +1,6 @@
1
1
  import { env } from "../env.js";
2
- import dbClient_default from "../data/db/dbClient.js";
3
- import { getLogger, validateAndGetApiKey } from "@inkeep/agents-core";
2
+ import runDbClient_default from "../data/db/runDbClient.js";
3
+ import { getLogger, isInternalServiceToken, validateAndGetApiKey, verifyInternalServiceAuthHeader } from "@inkeep/agents-core";
4
4
  import { createMiddleware } from "hono/factory";
5
5
  import { HTTPException } from "hono/http-exception";
6
6
 
@@ -12,6 +12,7 @@ const logger = getLogger("env-key-auth");
12
12
  * 1. Bypass secret (INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET)
13
13
  * 2. Better-auth session token (from device authorization flow)
14
14
  * 3. Database API key
15
+ * 4. Internal service token
15
16
  */
16
17
  const apiKeyAuth = () => createMiddleware(async (c, next) => {
17
18
  const authHeader = c.req.header("Authorization");
@@ -48,7 +49,7 @@ const apiKeyAuth = () => createMiddleware(async (c, next) => {
48
49
  } catch (error) {
49
50
  logger.debug({ error }, "Better-auth session validation failed, trying API key");
50
51
  }
51
- const validatedKey = await validateAndGetApiKey(token, dbClient_default);
52
+ const validatedKey = await validateAndGetApiKey(token, runDbClient_default);
52
53
  if (validatedKey) {
53
54
  logger.info({ keyId: validatedKey.id }, "API key authenticated successfully");
54
55
  c.set("userId", `apikey:${validatedKey.id}`);
@@ -57,6 +58,21 @@ const apiKeyAuth = () => createMiddleware(async (c, next) => {
57
58
  await next();
58
59
  return;
59
60
  }
61
+ if (isInternalServiceToken(token)) {
62
+ const result = await verifyInternalServiceAuthHeader(authHeader);
63
+ if (!result.valid || !result.payload) throw new HTTPException(401, { message: result.error || "Invalid internal service token" });
64
+ logger.info({
65
+ serviceId: result.payload.sub,
66
+ tenantId: result.payload.tenantId,
67
+ projectId: result.payload.projectId,
68
+ userId: result.payload.userId
69
+ }, "Internal service authenticated");
70
+ c.set("userId", result.payload.userId || `system`);
71
+ c.set("userEmail", `${result.payload.sub}@internal.inkeep`);
72
+ if (result.payload.tenantId) c.set("tenantId", result.payload.tenantId);
73
+ await next();
74
+ return;
75
+ }
60
76
  throw new HTTPException(401, { message: "Invalid Token" });
61
77
  });
62
78
 
@@ -0,0 +1,31 @@
1
+ import { AgentsManageDatabaseClient } from "@inkeep/agents-core";
2
+ import { Context, Next } from "hono";
3
+ import { Pool } from "pg";
4
+
5
+ //#region src/middleware/branch-scoped-db.d.ts
6
+ declare function isProjectDeleteOperation(path: string, method: string): boolean;
7
+ /**
8
+ * Get the underlying connection pool from a Drizzle database client
9
+ */
10
+ declare function getPoolFromClient(client: AgentsManageDatabaseClient): Pool | null;
11
+ /**
12
+ * Middleware that provides branch-scoped database connections
13
+ *
14
+ * Flow:
15
+ * 1. Get a dedicated connection from the pool
16
+ * 2. If ref is specified, checkout that branch/tag/commit on this connection
17
+ * 3. Create a Drizzle client wrapping this specific connection
18
+ * 4. Inject into context as 'db' (request-scoped database client)
19
+ * 5. Execute the route handler
20
+ * 6. For write operations on branches: auto-commit changes
21
+ * 7. Always cleanup: checkout main and release connection
22
+ *
23
+ * This ensures:
24
+ * - All operations in a request use the same connection (correct)
25
+ * - Only one checkout per request (performant)
26
+ * - Automatic commits for successful writes on branches
27
+ * - Proper connection cleanup
28
+ */
29
+ declare const branchScopedDbMiddleware: (c: Context, next: Next) => Promise<void>;
30
+ //#endregion
31
+ export { branchScopedDbMiddleware, getPoolFromClient, isProjectDeleteOperation };