@inkeep/agents-manage-api 0.0.0-dev-20260118155108 → 0.0.0-dev-20260119163620

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 (42) hide show
  1. package/dist/data/db/dbClient.d.ts +2 -2
  2. package/dist/data/db/runDbClient.d.ts +2 -2
  3. package/dist/factory.d.ts +2 -2
  4. package/dist/index.d.ts +82 -22
  5. package/dist/middleware/auth.d.ts +2 -2
  6. package/dist/middleware/project-access.d.ts +31 -0
  7. package/dist/middleware/project-access.js +118 -0
  8. package/dist/routes/agent.js +4 -4
  9. package/dist/routes/agentFull.js +4 -4
  10. package/dist/routes/agentToolRelations.js +4 -4
  11. package/dist/routes/apiKeys.js +4 -4
  12. package/dist/routes/artifactComponents.js +4 -4
  13. package/dist/routes/contextConfigs.js +4 -4
  14. package/dist/routes/credentialStores.d.ts +2 -2
  15. package/dist/routes/credentialStores.js +5 -0
  16. package/dist/routes/credentials.js +4 -4
  17. package/dist/routes/dataComponents.js +4 -4
  18. package/dist/routes/evals/evaluationResults.d.ts +2 -2
  19. package/dist/routes/externalAgents.js +4 -4
  20. package/dist/routes/functionTools.js +4 -4
  21. package/dist/routes/functions.js +4 -4
  22. package/dist/routes/index.d.ts +2 -2
  23. package/dist/routes/index.js +6 -0
  24. package/dist/routes/mcp.d.ts +2 -2
  25. package/dist/routes/playgroundToken.js +18 -3
  26. package/dist/routes/projectFull.js +3 -2
  27. package/dist/routes/projectMembers.d.ts +9 -0
  28. package/dist/routes/projectMembers.js +201 -0
  29. package/dist/routes/projectPermissions.d.ts +9 -0
  30. package/dist/routes/projectPermissions.js +64 -0
  31. package/dist/routes/projects.js +38 -7
  32. package/dist/routes/signoz.d.ts +2 -2
  33. package/dist/routes/subAgentArtifactComponents.js +3 -3
  34. package/dist/routes/subAgentDataComponents.js +3 -3
  35. package/dist/routes/subAgentExternalAgentRelations.js +4 -4
  36. package/dist/routes/subAgentFunctionTools.js +3 -3
  37. package/dist/routes/subAgentRelations.js +4 -4
  38. package/dist/routes/subAgentTeamAgentRelations.js +4 -4
  39. package/dist/routes/subAgentToolRelations.js +4 -4
  40. package/dist/routes/subAgents.js +4 -4
  41. package/dist/routes/tools.js +4 -4
  42. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
- import * as _inkeep_agents_core0 from "@inkeep/agents-core";
1
+ import * as _inkeep_agents_core1 from "@inkeep/agents-core";
2
2
 
3
3
  //#region src/data/db/dbClient.d.ts
4
- declare const manageDbClient: _inkeep_agents_core0.AgentsManageDatabaseClient;
4
+ declare const manageDbClient: _inkeep_agents_core1.AgentsManageDatabaseClient;
5
5
  //#endregion
6
6
  export { manageDbClient as default };
@@ -1,6 +1,6 @@
1
- import * as _inkeep_agents_core1 from "@inkeep/agents-core";
1
+ import * as _inkeep_agents_core0 from "@inkeep/agents-core";
2
2
 
3
3
  //#region src/data/db/runDbClient.d.ts
4
- declare const runDbClient: _inkeep_agents_core1.AgentsRunDatabaseClient;
4
+ declare const runDbClient: _inkeep_agents_core0.AgentsRunDatabaseClient;
5
5
  //#endregion
6
6
  export { runDbClient as default };
package/dist/factory.d.ts CHANGED
@@ -1,7 +1,7 @@
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";
4
+ import * as hono2 from "hono";
5
5
  import { CredentialStore, ServerConfig } from "@inkeep/agents-core";
6
6
  import { SSOProviderConfig, UserAuthConfig } from "@inkeep/agents-core/auth";
7
7
  import * as hono_types1 from "hono/types";
@@ -12,6 +12,6 @@ declare function createManagementApp(config?: {
12
12
  credentialStores?: CredentialStore[];
13
13
  auth?: UserAuthConfig;
14
14
  skipInitialization?: boolean;
15
- }): hono0.Hono<hono_types1.BlankEnv, hono_types1.BlankSchema, "/">;
15
+ }): hono2.Hono<hono_types1.BlankEnv, hono_types1.BlankSchema, "/">;
16
16
  //#endregion
17
17
  export { type SSOProviderConfig, type UserAuthConfig, createAuth0Provider, createManagementApp, createManagementHono, createOIDCProvider, initializeDefaultUser };
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" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
788
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
789
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", 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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
792
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
793
793
  };
794
794
  admin: {
795
- authorize<K_1 extends "function" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
795
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
796
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", 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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
799
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
800
800
  };
801
801
  owner: {
802
- authorize<K_1 extends "function" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
802
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
803
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", 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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
806
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
807
807
  };
808
808
  };
809
809
  membershipLimit: number;
@@ -819,6 +819,36 @@ declare const auth: better_auth0.Auth<{
819
819
  user: better_auth0.User;
820
820
  };
821
821
  }): Promise<void>;
822
+ organizationHooks: {
823
+ afterAcceptInvitation: ({
824
+ member,
825
+ user,
826
+ organization: org
827
+ }: {
828
+ invitation: better_auth_plugins0.Invitation & Record<string, any>;
829
+ member: better_auth_plugins0.Member & Record<string, any>;
830
+ user: better_auth0.User & Record<string, any>;
831
+ organization: better_auth_plugins0.Organization & Record<string, any>;
832
+ }) => Promise<void>;
833
+ afterUpdateMemberRole: ({
834
+ member,
835
+ organization: org,
836
+ previousRole
837
+ }: {
838
+ member: better_auth_plugins0.Member & Record<string, any>;
839
+ previousRole: string;
840
+ user: better_auth0.User & Record<string, any>;
841
+ organization: better_auth_plugins0.Organization & Record<string, any>;
842
+ }) => Promise<void>;
843
+ afterRemoveMember: ({
844
+ member,
845
+ organization: org
846
+ }: {
847
+ member: better_auth_plugins0.Member & Record<string, any>;
848
+ user: better_auth0.User & Record<string, any>;
849
+ organization: better_auth_plugins0.Organization & Record<string, any>;
850
+ }) => Promise<void>;
851
+ };
822
852
  }>;
823
853
  schema: {
824
854
  organization: {
@@ -947,7 +977,7 @@ declare const auth: better_auth0.Auth<{
947
977
  id: string;
948
978
  organizationId: string;
949
979
  email: string;
950
- role: "member" | "admin" | "owner";
980
+ role: "member" | "owner" | "admin";
951
981
  status: better_auth_plugins0.InvitationStatus;
952
982
  inviterId: string;
953
983
  expiresAt: Date;
@@ -956,7 +986,7 @@ declare const auth: better_auth0.Auth<{
956
986
  Member: {
957
987
  id: string;
958
988
  organizationId: string;
959
- role: "member" | "admin" | "owner";
989
+ role: "member" | "owner" | "admin";
960
990
  createdAt: Date;
961
991
  userId: string;
962
992
  user: {
@@ -972,7 +1002,7 @@ declare const auth: better_auth0.Auth<{
972
1002
  members: {
973
1003
  id: string;
974
1004
  organizationId: string;
975
- role: "member" | "admin" | "owner";
1005
+ role: "member" | "owner" | "admin";
976
1006
  createdAt: Date;
977
1007
  userId: string;
978
1008
  user: {
@@ -986,7 +1016,7 @@ declare const auth: better_auth0.Auth<{
986
1016
  id: string;
987
1017
  organizationId: string;
988
1018
  email: string;
989
- role: "member" | "admin" | "owner";
1019
+ role: "member" | "owner" | "admin";
990
1020
  status: better_auth_plugins0.InvitationStatus;
991
1021
  inviterId: string;
992
1022
  expiresAt: Date;
@@ -1064,25 +1094,25 @@ declare const auth: better_auth0.Auth<{
1064
1094
  ac: better_auth_plugins0.AccessControl;
1065
1095
  roles: {
1066
1096
  member: {
1067
- authorize<K_1 extends "function" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1097
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
1098
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key];
1069
1099
  connector: "OR" | "AND";
1070
1100
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1071
- statements: better_auth_plugins0.Subset<"function" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1101
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
1072
1102
  };
1073
1103
  admin: {
1074
- authorize<K_1 extends "function" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1104
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
1105
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key];
1076
1106
  connector: "OR" | "AND";
1077
1107
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1078
- statements: better_auth_plugins0.Subset<"function" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1108
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
1079
1109
  };
1080
1110
  owner: {
1081
- authorize<K_1 extends "function" | "agent" | "organization" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "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" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
1111
+ authorize<K_1 extends "project" | "organization" | "team" | "member" | "ac" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key] | {
1112
+ actions: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>[key];
1083
1113
  connector: "OR" | "AND";
1084
1114
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1085
- statements: better_auth_plugins0.Subset<"function" | "agent" | "organization" | "member" | "invitation" | "ac" | "project" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
1115
+ statements: better_auth_plugins0.Subset<"project" | "organization" | "team" | "member" | "ac" | "invitation", better_auth_plugins0.Statements>;
1086
1116
  };
1087
1117
  };
1088
1118
  membershipLimit: number;
@@ -1098,6 +1128,36 @@ declare const auth: better_auth0.Auth<{
1098
1128
  user: better_auth0.User;
1099
1129
  };
1100
1130
  }): Promise<void>;
1131
+ organizationHooks: {
1132
+ afterAcceptInvitation: ({
1133
+ member,
1134
+ user,
1135
+ organization: org
1136
+ }: {
1137
+ invitation: better_auth_plugins0.Invitation & Record<string, any>;
1138
+ member: better_auth_plugins0.Member & Record<string, any>;
1139
+ user: better_auth0.User & Record<string, any>;
1140
+ organization: better_auth_plugins0.Organization & Record<string, any>;
1141
+ }) => Promise<void>;
1142
+ afterUpdateMemberRole: ({
1143
+ member,
1144
+ organization: org,
1145
+ previousRole
1146
+ }: {
1147
+ member: better_auth_plugins0.Member & Record<string, any>;
1148
+ previousRole: string;
1149
+ user: better_auth0.User & Record<string, any>;
1150
+ organization: better_auth_plugins0.Organization & Record<string, any>;
1151
+ }) => Promise<void>;
1152
+ afterRemoveMember: ({
1153
+ member,
1154
+ organization: org
1155
+ }: {
1156
+ member: better_auth_plugins0.Member & Record<string, any>;
1157
+ user: better_auth0.User & Record<string, any>;
1158
+ organization: better_auth_plugins0.Organization & Record<string, any>;
1159
+ }) => Promise<void>;
1160
+ };
1101
1161
  }>;
1102
1162
  }, {
1103
1163
  id: "device-authorization";
@@ -1,4 +1,4 @@
1
- import * as hono2 from "hono";
1
+ import * as hono1 from "hono";
2
2
  import { BaseExecutionContext } from "@inkeep/agents-core";
3
3
  import { createAuth } from "@inkeep/agents-core/auth";
4
4
 
@@ -12,7 +12,7 @@ import { createAuth } from "@inkeep/agents-core/auth";
12
12
  * 3. Database API key
13
13
  * 4. Internal service token
14
14
  */
15
- declare const apiKeyAuth: () => hono2.MiddlewareHandler<{
15
+ declare const apiKeyAuth: () => hono1.MiddlewareHandler<{
16
16
  Variables: {
17
17
  executionContext: BaseExecutionContext;
18
18
  userId?: string;
@@ -0,0 +1,31 @@
1
+ import { BaseAppVariables } from "../types/app.js";
2
+ import * as hono0 from "hono";
3
+
4
+ //#region src/middleware/project-access.d.ts
5
+
6
+ /**
7
+ * Permission levels for project access
8
+ *
9
+ * - view: Can see project and resources (read-only)
10
+ * - use: Can invoke agents, create API keys, view traces
11
+ * - edit: Can modify configurations and manage members
12
+ */
13
+ type ProjectPermission = 'view' | 'use' | 'edit';
14
+ /**
15
+ * Middleware to check project-level access.
16
+ *
17
+ * When ENABLE_AUTHZ is false:
18
+ * - 'view' permission: all org members can view
19
+ * - 'edit': only org owner/admin
20
+ *
21
+ * When ENABLE_AUTHZ is true:
22
+ * - Uses SpiceDB to check permissions
23
+ * - Org owner/admin bypass (handled in canViewProject etc.)
24
+ */
25
+ declare const requireProjectPermission: <Env$1 extends {
26
+ Variables: BaseAppVariables;
27
+ } = {
28
+ Variables: BaseAppVariables;
29
+ }>(permission?: ProjectPermission) => hono0.MiddlewareHandler<Env$1, string, {}, Response>;
30
+ //#endregion
31
+ export { ProjectPermission, requireProjectPermission };
@@ -0,0 +1,118 @@
1
+ import { env } from "../env.js";
2
+ import { canEditProject, canUseProject, canViewProject, createApiError, isAuthzEnabled } from "@inkeep/agents-core";
3
+ import { createMiddleware } from "hono/factory";
4
+ import { HTTPException } from "hono/http-exception";
5
+
6
+ //#region src/middleware/project-access.ts
7
+ /**
8
+ * Middleware to check project-level access.
9
+ *
10
+ * When ENABLE_AUTHZ is false:
11
+ * - 'view' permission: all org members can view
12
+ * - 'edit': only org owner/admin
13
+ *
14
+ * When ENABLE_AUTHZ is true:
15
+ * - Uses SpiceDB to check permissions
16
+ * - Org owner/admin bypass (handled in canViewProject etc.)
17
+ */
18
+ const requireProjectPermission = (permission = "view") => createMiddleware(async (c, next) => {
19
+ const isTestEnvironment = process.env.ENVIRONMENT === "test";
20
+ if (env.DISABLE_AUTH || isTestEnvironment) {
21
+ await next();
22
+ return;
23
+ }
24
+ const userId = c.get("userId");
25
+ const tenantId = c.get("tenantId");
26
+ const tenantRole = c.get("tenantRole");
27
+ const projectId = c.req.param("projectId") || c.req.param("id");
28
+ if (!userId || !tenantId) throw createApiError({
29
+ code: "unauthorized",
30
+ message: "User or organization context not found",
31
+ instance: c.req.path
32
+ });
33
+ if (!projectId) throw createApiError({
34
+ code: "bad_request",
35
+ message: "Project ID is required",
36
+ instance: c.req.path
37
+ });
38
+ if (userId === "system" || userId.startsWith("apikey:")) {
39
+ await next();
40
+ return;
41
+ }
42
+ try {
43
+ let hasAccess = false;
44
+ switch (permission) {
45
+ case "view":
46
+ hasAccess = await canViewProject({
47
+ tenantId,
48
+ userId,
49
+ projectId,
50
+ orgRole: tenantRole
51
+ });
52
+ break;
53
+ case "use":
54
+ hasAccess = await canUseProject({
55
+ tenantId,
56
+ userId,
57
+ projectId,
58
+ orgRole: tenantRole
59
+ });
60
+ break;
61
+ case "edit":
62
+ hasAccess = await canEditProject({
63
+ tenantId,
64
+ userId,
65
+ projectId,
66
+ orgRole: tenantRole
67
+ });
68
+ break;
69
+ }
70
+ if (!hasAccess) {
71
+ if (isAuthzEnabled(tenantId) && permission !== "view") {
72
+ if (await canViewProject({
73
+ tenantId,
74
+ userId,
75
+ projectId,
76
+ orgRole: tenantRole
77
+ })) throw createApiError({
78
+ code: "forbidden",
79
+ message: `Permission denied. Required: project:${permission}`,
80
+ instance: c.req.path,
81
+ extensions: { requiredPermissions: [`project:${permission}`] }
82
+ });
83
+ }
84
+ if (isAuthzEnabled(tenantId)) throw createApiError({
85
+ code: "not_found",
86
+ message: "Project not found",
87
+ instance: c.req.path
88
+ });
89
+ throw createApiError({
90
+ code: "forbidden",
91
+ message: `Permission denied. Required: project:${permission}`,
92
+ instance: c.req.path,
93
+ extensions: {
94
+ requiredPermissions: [`project:${permission}`],
95
+ context: {
96
+ userId,
97
+ organizationId: tenantId,
98
+ projectId,
99
+ currentRole: tenantRole
100
+ }
101
+ }
102
+ });
103
+ }
104
+ await next();
105
+ } catch (error) {
106
+ if (error instanceof HTTPException) throw error;
107
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
108
+ throw createApiError({
109
+ code: "internal_server_error",
110
+ message: "Failed to verify project access",
111
+ instance: c.req.path,
112
+ extensions: { internalError: errorMessage }
113
+ });
114
+ }
115
+ });
116
+
117
+ //#endregion
118
+ export { requireProjectPermission };
@@ -1,5 +1,5 @@
1
1
  import runDbClient_default from "../data/db/runDbClient.js";
2
- import { requirePermission } from "../middleware/require-permission.js";
2
+ import { requireProjectPermission } from "../middleware/project-access.js";
3
3
  import { speakeasyOffsetLimitPagination } from "./shared.js";
4
4
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
5
5
  import { AgentApiInsertSchema, AgentApiUpdateSchema, AgentListResponse, AgentResponse, AgentWithinContextOfProjectResponse, ErrorResponseSchema, PaginationQueryParamsSchema, RelatedAgentInfoListResponse, TenantProjectAgentParamsSchema, TenantProjectAgentSubAgentParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, cascadeDeleteByAgent, commonGetErrorResponses, createAgent, createApiError, deleteAgent, generateId, getAgentById, getAgentSubAgentInfos, getFullAgentDefinition, listAgentsPaginated, listSubAgents, updateAgent } from "@inkeep/agents-core";
@@ -7,12 +7,12 @@ import { AgentApiInsertSchema, AgentApiUpdateSchema, AgentListResponse, AgentRes
7
7
  //#region src/routes/agent.ts
8
8
  const app = new OpenAPIHono();
9
9
  app.use("/", async (c, next) => {
10
- if (c.req.method === "POST") return requirePermission({ agent: ["create"] })(c, next);
10
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
11
11
  return next();
12
12
  });
13
13
  app.use("/:id", async (c, next) => {
14
- if (c.req.method === "PUT") return requirePermission({ agent: ["update"] })(c, next);
15
- if (c.req.method === "DELETE") return requirePermission({ agent: ["delete"] })(c, next);
14
+ if (c.req.method === "PUT") return requireProjectPermission("edit")(c, next);
15
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
16
16
  return next();
17
17
  });
18
18
  app.openapi(createRoute({
@@ -1,6 +1,6 @@
1
1
  import { getLogger as getLogger$1 } from "../logger.js";
2
2
  import runDbClient_default from "../data/db/runDbClient.js";
3
- import { requirePermission } from "../middleware/require-permission.js";
3
+ import { requireProjectPermission } from "../middleware/project-access.js";
4
4
  import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
5
5
  import { AgentWithinContextOfProjectResponse, AgentWithinContextOfProjectSchema, ErrorResponseSchema, TenantProjectAgentParamsSchema, TenantProjectParamsSchema, cascadeDeleteByAgent, commonGetErrorResponses, createApiError, createFullAgentServerSide, deleteFullAgent, getFullAgent, listSubAgents, updateFullAgentServerSide } from "@inkeep/agents-core";
6
6
 
@@ -8,12 +8,12 @@ import { AgentWithinContextOfProjectResponse, AgentWithinContextOfProjectSchema,
8
8
  const logger = getLogger$1("agentFull");
9
9
  const app = new OpenAPIHono();
10
10
  app.use("/", async (c, next) => {
11
- if (c.req.method === "POST") return requirePermission({ agent: ["create"] })(c, next);
11
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
12
12
  return next();
13
13
  });
14
14
  app.use("/:agentId", async (c, next) => {
15
- if (c.req.method === "PUT") return requirePermission({ agent: ["update"] })(c, next);
16
- if (c.req.method === "DELETE") return requirePermission({ agent: ["delete"] })(c, next);
15
+ if (c.req.method === "PUT") return requireProjectPermission("edit")(c, next);
16
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
17
17
  return next();
18
18
  });
19
19
  app.openapi(createRoute({
@@ -1,4 +1,4 @@
1
- import { requirePermission } from "../middleware/require-permission.js";
1
+ import { requireProjectPermission } from "../middleware/project-access.js";
2
2
  import { speakeasyOffsetLimitPagination } from "./shared.js";
3
3
  import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
4
4
  import { ErrorResponseSchema, PaginationQueryParamsSchema, SubAgentToolRelationApiInsertSchema, SubAgentToolRelationApiUpdateSchema, SubAgentToolRelationListResponse, SubAgentToolRelationResponse, TenantProjectAgentIdParamsSchema, TenantProjectAgentParamsSchema, commonGetErrorResponses, createAgentToolRelation, createApiError, deleteAgentToolRelation, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsForTool, listAgentToolRelations, updateAgentToolRelation } from "@inkeep/agents-core";
@@ -6,12 +6,12 @@ import { ErrorResponseSchema, PaginationQueryParamsSchema, SubAgentToolRelationA
6
6
  //#region src/routes/agentToolRelations.ts
7
7
  const app = new OpenAPIHono();
8
8
  app.use("/", async (c, next) => {
9
- if (c.req.method === "POST") return requirePermission({ agent: ["create"] })(c, next);
9
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
10
10
  return next();
11
11
  });
12
12
  app.use("/:id", async (c, next) => {
13
- if (c.req.method === "PUT") return requirePermission({ agent: ["update"] })(c, next);
14
- if (c.req.method === "DELETE") return requirePermission({ agent: ["delete"] })(c, next);
13
+ if (c.req.method === "PUT") return requireProjectPermission("edit")(c, next);
14
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
15
15
  return next();
16
16
  });
17
17
  app.openapi(createRoute({
@@ -1,5 +1,5 @@
1
1
  import runDbClient_default from "../data/db/runDbClient.js";
2
- import { requirePermission } from "../middleware/require-permission.js";
2
+ import { requireProjectPermission } from "../middleware/project-access.js";
3
3
  import { speakeasyOffsetLimitPagination } from "./shared.js";
4
4
  import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
5
5
  import { ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiUpdateSchema, ApiKeyListResponse, ApiKeyResponse, ErrorResponseSchema, PaginationQueryParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError, createApiKey, deleteApiKey, generateApiKey, getApiKeyById, listApiKeysPaginated, updateApiKey } from "@inkeep/agents-core";
@@ -7,12 +7,12 @@ import { ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiUpdate
7
7
  //#region src/routes/apiKeys.ts
8
8
  const app = new OpenAPIHono();
9
9
  app.use("/", async (c, next) => {
10
- if (c.req.method === "POST") return requirePermission({ api_key: ["create"] })(c, next);
10
+ if (c.req.method === "POST") return requireProjectPermission("use")(c, next);
11
11
  return next();
12
12
  });
13
13
  app.use("/:id", async (c, next) => {
14
- if (c.req.method === "PATCH") return requirePermission({ api_key: ["update"] })(c, next);
15
- if (c.req.method === "DELETE") return requirePermission({ api_key: ["delete"] })(c, next);
14
+ if (c.req.method === "PATCH") return requireProjectPermission("edit")(c, next);
15
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
16
16
  return next();
17
17
  });
18
18
  app.openapi(createRoute({
@@ -1,4 +1,4 @@
1
- import { requirePermission } from "../middleware/require-permission.js";
1
+ import { requireProjectPermission } from "../middleware/project-access.js";
2
2
  import { speakeasyOffsetLimitPagination } from "./shared.js";
3
3
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
4
4
  import { ArtifactComponentApiInsertSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentListResponse, ArtifactComponentResponse, ErrorResponseSchema, PaginationQueryParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError, createArtifactComponent, deleteArtifactComponent, generateId, getArtifactComponentById, listArtifactComponentsPaginated, updateArtifactComponent, validatePropsAsJsonSchema } from "@inkeep/agents-core";
@@ -6,12 +6,12 @@ import { ArtifactComponentApiInsertSchema, ArtifactComponentApiUpdateSchema, Art
6
6
  //#region src/routes/artifactComponents.ts
7
7
  const app = new OpenAPIHono();
8
8
  app.use("/", async (c, next) => {
9
- if (c.req.method === "POST") return requirePermission({ artifact_component: ["create"] })(c, next);
9
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
10
10
  return next();
11
11
  });
12
12
  app.use("/:id", async (c, next) => {
13
- if (c.req.method === "PATCH") return requirePermission({ artifact_component: ["update"] })(c, next);
14
- if (c.req.method === "DELETE") return requirePermission({ artifact_component: ["delete"] })(c, next);
13
+ if (c.req.method === "PATCH" || c.req.method === "PUT") return requireProjectPermission("edit")(c, next);
14
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
15
15
  return next();
16
16
  });
17
17
  app.openapi(createRoute({
@@ -1,5 +1,5 @@
1
1
  import runDbClient_default from "../data/db/runDbClient.js";
2
- import { requirePermission } from "../middleware/require-permission.js";
2
+ import { requireProjectPermission } from "../middleware/project-access.js";
3
3
  import { speakeasyOffsetLimitPagination } from "./shared.js";
4
4
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
5
5
  import { ContextConfigApiInsertSchema, ContextConfigApiUpdateSchema, ContextConfigListResponse, ContextConfigResponse, PaginationQueryParamsSchema, TenantProjectAgentIdParamsSchema, TenantProjectAgentParamsSchema, cascadeDeleteByContextConfig, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, createApiError, createContextConfig, deleteContextConfig, getContextConfigById, listContextConfigsPaginated, updateContextConfig } from "@inkeep/agents-core";
@@ -7,12 +7,12 @@ import { ContextConfigApiInsertSchema, ContextConfigApiUpdateSchema, ContextConf
7
7
  //#region src/routes/contextConfigs.ts
8
8
  const app = new OpenAPIHono();
9
9
  app.use("/", async (c, next) => {
10
- if (c.req.method === "POST") return requirePermission({ context_config: ["create"] })(c, next);
10
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
11
11
  return next();
12
12
  });
13
13
  app.use("/:id", async (c, next) => {
14
- if (c.req.method === "PUT") return requirePermission({ context_config: ["update"] })(c, next);
15
- if (c.req.method === "DELETE") return requirePermission({ context_config: ["delete"] })(c, next);
14
+ if (c.req.method === "PUT") return requireProjectPermission("edit")(c, next);
15
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
16
16
  return next();
17
17
  });
18
18
  app.openapi(createRoute({
@@ -1,9 +1,9 @@
1
- import { PublicAppVariables } from "../types/app.js";
1
+ import { AppVariablesWithCredentials } from "../types/app.js";
2
2
  import { OpenAPIHono } from "@hono/zod-openapi";
3
3
 
4
4
  //#region src/routes/credentialStores.d.ts
5
5
  declare const app: OpenAPIHono<{
6
- Variables: PublicAppVariables;
6
+ Variables: AppVariablesWithCredentials;
7
7
  }, {}, "/">;
8
8
  //#endregion
9
9
  export { app as default };
@@ -1,8 +1,13 @@
1
+ import { requireProjectPermission } from "../middleware/project-access.js";
1
2
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
2
3
  import { CreateCredentialInStoreRequestSchema, CreateCredentialInStoreResponseSchema, CredentialStoreListResponseSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError } from "@inkeep/agents-core";
3
4
 
4
5
  //#region src/routes/credentialStores.ts
5
6
  const app = new OpenAPIHono();
7
+ app.use("/:id/credentials", async (c, next) => {
8
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
9
+ return next();
10
+ });
6
11
  app.openapi(createRoute({
7
12
  method: "get",
8
13
  path: "/",
@@ -1,4 +1,4 @@
1
- import { requirePermission } from "../middleware/require-permission.js";
1
+ import { requireProjectPermission } from "../middleware/project-access.js";
2
2
  import { speakeasyOffsetLimitPagination } from "./shared.js";
3
3
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
4
4
  import { CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema, CredentialReferenceApiUpdateSchema, CredentialReferenceListResponse, CredentialReferenceResponse, ErrorResponseSchema, ListResponseSchema, PaginationQueryParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError, createCredentialReference, deleteCredentialReference, getCredentialReferenceById, getCredentialReferenceWithResources, getCredentialStoreLookupKeyFromRetrievalParams, listCredentialReferencesPaginated, updateCredentialReference } from "@inkeep/agents-core";
@@ -6,12 +6,12 @@ import { CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema,
6
6
  //#region src/routes/credentials.ts
7
7
  const app = new OpenAPIHono();
8
8
  app.use("/", async (c, next) => {
9
- if (c.req.method === "POST") return requirePermission({ credential: ["create"] })(c, next);
9
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
10
10
  return next();
11
11
  });
12
12
  app.use("/:id", async (c, next) => {
13
- if (c.req.method === "PATCH") return requirePermission({ credential: ["update"] })(c, next);
14
- if (c.req.method === "DELETE") return requirePermission({ credential: ["delete"] })(c, next);
13
+ if (c.req.method === "PATCH") return requireProjectPermission("edit")(c, next);
14
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
15
15
  return next();
16
16
  });
17
17
  app.openapi(createRoute({
@@ -1,4 +1,4 @@
1
- import { requirePermission } from "../middleware/require-permission.js";
1
+ import { requireProjectPermission } from "../middleware/project-access.js";
2
2
  import { speakeasyOffsetLimitPagination } from "./shared.js";
3
3
  import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
4
4
  import { DataComponentApiInsertSchema, DataComponentApiUpdateSchema, DataComponentListResponse, DataComponentResponse, ErrorResponseSchema, PaginationQueryParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, commonGetErrorResponses, createApiError, createDataComponent, deleteDataComponent, getDataComponent, listDataComponentsPaginated, updateDataComponent, validatePropsAsJsonSchema } from "@inkeep/agents-core";
@@ -6,12 +6,12 @@ import { DataComponentApiInsertSchema, DataComponentApiUpdateSchema, DataCompone
6
6
  //#region src/routes/dataComponents.ts
7
7
  const app = new OpenAPIHono();
8
8
  app.use("/", async (c, next) => {
9
- if (c.req.method === "POST") return requirePermission({ data_component: ["create"] })(c, next);
9
+ if (c.req.method === "POST") return requireProjectPermission("edit")(c, next);
10
10
  return next();
11
11
  });
12
12
  app.use("/:id", async (c, next) => {
13
- if (c.req.method === "PATCH") return requirePermission({ data_component: ["update"] })(c, next);
14
- if (c.req.method === "DELETE") return requirePermission({ data_component: ["delete"] })(c, next);
13
+ if (c.req.method === "PATCH") return requireProjectPermission("edit")(c, next);
14
+ if (c.req.method === "DELETE") return requireProjectPermission("edit")(c, next);
15
15
  return next();
16
16
  });
17
17
  app.openapi(createRoute({