@inkeep/agents-core 0.42.0 → 0.44.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 (125) hide show
  1. package/dist/auth/auth.d.ts +28 -26
  2. package/dist/auth/auth.js +21 -16
  3. package/dist/auth/authz/client.d.ts +8 -3
  4. package/dist/auth/authz/client.js +23 -17
  5. package/dist/auth/authz/config.d.ts +50 -29
  6. package/dist/auth/authz/config.js +42 -33
  7. package/dist/auth/authz/index.d.ts +3 -3
  8. package/dist/auth/authz/index.js +3 -3
  9. package/dist/auth/authz/permissions.d.ts +0 -4
  10. package/dist/auth/authz/permissions.js +9 -13
  11. package/dist/auth/authz/sync.d.ts +23 -2
  12. package/dist/auth/authz/sync.js +127 -53
  13. package/dist/auth/init.d.ts +1 -0
  14. package/dist/auth/init.js +115 -0
  15. package/dist/auth/permissions.d.ts +9 -9
  16. package/dist/client-exports.d.ts +3 -6
  17. package/dist/client-exports.js +4 -7
  18. package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
  19. package/dist/constants/execution-limits-shared/defaults.js +1 -1
  20. package/dist/constants/execution-limits-shared/index.d.ts +1 -1
  21. package/dist/constants/otel-attributes.d.ts +5 -0
  22. package/dist/constants/otel-attributes.js +8 -3
  23. package/dist/constants/signoz-queries.d.ts +1 -0
  24. package/dist/constants/signoz-queries.js +2 -1
  25. package/dist/context/TemplateEngine.d.ts +0 -6
  26. package/dist/context/TemplateEngine.js +4 -18
  27. package/dist/credential-stores/keychain-store.d.ts +20 -8
  28. package/dist/credential-stores/keychain-store.js +107 -43
  29. package/dist/data-access/index.d.ts +5 -4
  30. package/dist/data-access/index.js +5 -4
  31. package/dist/data-access/manage/agentFull.js +70 -25
  32. package/dist/data-access/manage/agents.d.ts +41 -41
  33. package/dist/data-access/manage/agents.js +29 -21
  34. package/dist/data-access/manage/artifactComponents.d.ts +12 -12
  35. package/dist/data-access/manage/artifactComponents.js +1 -1
  36. package/dist/data-access/manage/contextConfigs.d.ts +12 -12
  37. package/dist/data-access/manage/dataComponents.d.ts +6 -6
  38. package/dist/data-access/manage/dataComponents.js +1 -1
  39. package/dist/data-access/manage/functionTools.d.ts +44 -21
  40. package/dist/data-access/manage/functionTools.js +34 -22
  41. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
  42. package/dist/data-access/manage/subAgentRelations.d.ts +26 -26
  43. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
  44. package/dist/data-access/manage/subAgents.d.ts +15 -15
  45. package/dist/data-access/manage/tools.d.ts +39 -28
  46. package/dist/data-access/manage/tools.js +73 -31
  47. package/dist/data-access/manage/triggers.d.ts +27 -1
  48. package/dist/data-access/runtime/apiKeys.d.ts +20 -20
  49. package/dist/data-access/runtime/cascade-delete.d.ts +48 -1
  50. package/dist/data-access/runtime/cascade-delete.js +52 -2
  51. package/dist/data-access/runtime/conversations.d.ts +24 -24
  52. package/dist/data-access/runtime/github-work-app-installations.d.ts +261 -0
  53. package/dist/data-access/runtime/github-work-app-installations.js +457 -0
  54. package/dist/data-access/runtime/messages.d.ts +18 -18
  55. package/dist/data-access/runtime/organizations.d.ts +2 -2
  56. package/dist/data-access/runtime/organizations.js +4 -4
  57. package/dist/data-access/runtime/tasks.d.ts +6 -6
  58. package/dist/db/manage/manage-schema.d.ts +533 -402
  59. package/dist/db/manage/manage-schema.js +38 -27
  60. package/dist/db/runtime/runtime-schema.d.ts +1021 -177
  61. package/dist/db/runtime/runtime-schema.js +173 -5
  62. package/dist/db/utils.d.ts +6 -0
  63. package/dist/db/utils.js +42 -0
  64. package/dist/dolt/branch.js +1 -1
  65. package/dist/dolt/branches-api.js +1 -1
  66. package/dist/dolt/index.d.ts +2 -2
  67. package/dist/dolt/index.js +4 -4
  68. package/dist/dolt/migrate-all-branches.js +6 -1
  69. package/dist/dolt/migrate-dolt.js +4 -1
  70. package/dist/dolt/ref-helpers.js +1 -1
  71. package/dist/dolt/ref-middleware.js +1 -1
  72. package/dist/dolt/ref-scope.js +1 -1
  73. package/dist/dolt/schema-sync.d.ts +2 -1
  74. package/dist/dolt/schema-sync.js +10 -1
  75. package/dist/env.d.ts +6 -4
  76. package/dist/env.js +11 -10
  77. package/dist/index.d.ts +15 -16
  78. package/dist/index.js +23 -24
  79. package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
  80. package/dist/types/entities.d.ts +9 -2
  81. package/dist/types/index.d.ts +3 -3
  82. package/dist/types/utility.d.ts +17 -3
  83. package/dist/types/utility.js +2 -1
  84. package/dist/utils/JsonTransformer.d.ts +1 -3
  85. package/dist/utils/JsonTransformer.js +14 -23
  86. package/dist/utils/index.d.ts +3 -3
  87. package/dist/utils/index.js +3 -3
  88. package/dist/utils/jmespath-utils.d.ts +152 -0
  89. package/dist/utils/jmespath-utils.js +213 -0
  90. package/dist/utils/mcp-client.d.ts +1 -1
  91. package/dist/utils/mcp-client.js +1 -1
  92. package/dist/utils/signature-validation.d.ts +2 -0
  93. package/dist/utils/signature-validation.js +3 -0
  94. package/dist/utils/third-party-mcp-servers/composio-client.d.ts +13 -1
  95. package/dist/utils/third-party-mcp-servers/composio-client.js +24 -6
  96. package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
  97. package/dist/utils/third-party-mcp-servers/index.js +2 -2
  98. package/dist/utils/trigger-auth.d.ts +31 -8
  99. package/dist/utils/trigger-auth.js +121 -13
  100. package/dist/validation/agentFull.js +1 -1
  101. package/dist/validation/drizzle-schema-helpers.d.ts +4 -23
  102. package/dist/validation/drizzle-schema-helpers.js +3 -30
  103. package/dist/validation/index.d.ts +3 -5
  104. package/dist/validation/index.js +5 -7
  105. package/dist/validation/render-validation.js +19 -0
  106. package/dist/validation/schemas.d.ts +3675 -1665
  107. package/dist/validation/schemas.js +409 -94
  108. package/dist/validation/stream-event-schemas.d.ts +96 -1
  109. package/dist/validation/stream-event-schemas.js +67 -2
  110. package/drizzle/manage/0003_tiny_captain_universe.sql +8 -0
  111. package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
  112. package/drizzle/manage/0005_silent_shatterstar.sql +53 -0
  113. package/drizzle/manage/0006_fixed_umar.sql +1 -0
  114. package/drizzle/manage/meta/0003_snapshot.json +3134 -0
  115. package/drizzle/manage/meta/0004_snapshot.json +3141 -0
  116. package/drizzle/manage/meta/0005_snapshot.json +3141 -0
  117. package/drizzle/manage/meta/0006_snapshot.json +3148 -0
  118. package/drizzle/manage/meta/_journal.json +28 -0
  119. package/drizzle/runtime/0010_previous_black_knight.sql +84 -0
  120. package/drizzle/runtime/meta/0010_snapshot.json +3066 -0
  121. package/drizzle/runtime/meta/_journal.json +7 -0
  122. package/package.json +12 -5
  123. package/spicedb/schema.zed +114 -0
  124. package/dist/validation/id-validation.d.ts +0 -24
  125. package/dist/validation/id-validation.js +0 -52
@@ -179,11 +179,11 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
179
179
  useSecureCookies?: boolean | undefined;
180
180
  disableCSRFCheck?: boolean | undefined;
181
181
  disableOriginCheck?: boolean | undefined;
182
- crossSubDomainCookies: {
182
+ crossSubDomainCookies?: {
183
183
  enabled: boolean;
184
184
  additionalCookies?: string[];
185
185
  domain?: string;
186
- };
186
+ } | undefined;
187
187
  cookies?: {
188
188
  [key: string]: {
189
189
  name?: string;
@@ -852,27 +852,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
852
852
  ac: better_auth_plugins0.AccessControl;
853
853
  roles: {
854
854
  member: {
855
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
856
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
855
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
856
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
857
857
  connector: "OR" | "AND";
858
858
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
859
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
859
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
860
860
  };
861
861
  admin: {
862
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
863
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
862
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
863
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
864
864
  connector: "OR" | "AND";
865
865
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
866
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
866
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
867
867
  };
868
868
  owner: {
869
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
870
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
869
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
870
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
871
871
  connector: "OR" | "AND";
872
872
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
873
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
873
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
874
874
  };
875
875
  };
876
+ creatorRole: "admin";
876
877
  membershipLimit: number;
877
878
  invitationLimit: number;
878
879
  invitationExpiresIn: number;
@@ -897,13 +898,13 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
897
898
  user: better_auth0.User & Record<string, any>;
898
899
  organization: better_auth_plugins0.Organization & Record<string, any>;
899
900
  }) => Promise<void>;
900
- afterUpdateMemberRole: ({
901
+ beforeUpdateMemberRole: ({
901
902
  member,
902
903
  organization: org,
903
- previousRole
904
+ newRole
904
905
  }: {
905
906
  member: better_auth_plugins0.Member & Record<string, any>;
906
- previousRole: string;
907
+ newRole: string;
907
908
  user: better_auth0.User & Record<string, any>;
908
909
  organization: better_auth_plugins0.Organization & Record<string, any>;
909
910
  }) => Promise<void>;
@@ -1161,27 +1162,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
1161
1162
  ac: better_auth_plugins0.AccessControl;
1162
1163
  roles: {
1163
1164
  member: {
1164
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
1165
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
1165
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
1166
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
1166
1167
  connector: "OR" | "AND";
1167
1168
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1168
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
1169
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
1169
1170
  };
1170
1171
  admin: {
1171
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
1172
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
1172
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
1173
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
1173
1174
  connector: "OR" | "AND";
1174
1175
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1175
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
1176
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
1176
1177
  };
1177
1178
  owner: {
1178
- authorize<K_1 extends "organization" | "ac" | "member" | "project" | "team" | "invitation">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key] | {
1179
- actions: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>[key];
1179
+ authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
1180
+ actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
1180
1181
  connector: "OR" | "AND";
1181
1182
  } | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
1182
- statements: better_auth_plugins0.Subset<"organization" | "ac" | "member" | "project" | "team" | "invitation", better_auth_plugins0.Statements>;
1183
+ statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
1183
1184
  };
1184
1185
  };
1186
+ creatorRole: "admin";
1185
1187
  membershipLimit: number;
1186
1188
  invitationLimit: number;
1187
1189
  invitationExpiresIn: number;
@@ -1206,13 +1208,13 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
1206
1208
  user: better_auth0.User & Record<string, any>;
1207
1209
  organization: better_auth_plugins0.Organization & Record<string, any>;
1208
1210
  }) => Promise<void>;
1209
- afterUpdateMemberRole: ({
1211
+ beforeUpdateMemberRole: ({
1210
1212
  member,
1211
1213
  organization: org,
1212
- previousRole
1214
+ newRole
1213
1215
  }: {
1214
1216
  member: better_auth_plugins0.Member & Record<string, any>;
1215
- previousRole: string;
1217
+ newRole: string;
1216
1218
  user: better_auth0.User & Record<string, any>;
1217
1219
  organization: better_auth_plugins0.Organization & Record<string, any>;
1218
1220
  }) => Promise<void>;
package/dist/auth/auth.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { member, ssoProvider } from "./auth-schema.js";
2
+ import { OrgRoles } from "./authz/config.js";
2
3
  import { env } from "../env.js";
3
4
  import { generateId } from "../utils/conversations.js";
4
5
  import "../utils/index.js";
@@ -22,7 +23,7 @@ async function getInitialOrganization(dbClient, userId) {
22
23
  /**
23
24
  * Extracts the root domain from a URL for cross-subdomain cookie sharing.
24
25
  * For example:
25
- * - https://manage-api.pilot.inkeep.com -> .pilot.inkeep.com
26
+ * - https://api.pilot.inkeep.com -> .pilot.inkeep.com
26
27
  * - https://pilot.inkeep.com -> .pilot.inkeep.com
27
28
  * - http://localhost:3002 -> undefined (no domain for localhost)
28
29
  *
@@ -105,10 +106,10 @@ function createAuth(config) {
105
106
  }
106
107
  },
107
108
  advanced: {
108
- crossSubDomainCookies: {
109
+ ...cookieDomain && { crossSubDomainCookies: {
109
110
  enabled: true,
110
- ...cookieDomain && { domain: cookieDomain }
111
- },
111
+ domain: cookieDomain
112
+ } },
112
113
  defaultCookieAttributes: {
113
114
  sameSite: "none",
114
115
  secure: true,
@@ -137,6 +138,7 @@ function createAuth(config) {
137
138
  admin: adminRole,
138
139
  owner: ownerRole
139
140
  },
141
+ creatorRole: OrgRoles.ADMIN,
140
142
  membershipLimit: 300,
141
143
  invitationLimit: 300,
142
144
  invitationExpiresIn: 10080 * 60,
@@ -163,20 +165,23 @@ function createAuth(config) {
163
165
  console.error("❌ SpiceDB sync failed for new member:", error);
164
166
  }
165
167
  },
166
- afterUpdateMemberRole: async ({ member: member$1, organization: org, previousRole }) => {
167
- try {
168
- const { changeOrgRole } = await import("./authz/sync.js");
169
- const oldRole = previousRole;
170
- const newRole = member$1.role;
171
- await changeOrgRole({
168
+ beforeUpdateMemberRole: async ({ member: member$1, organization: org, newRole }) => {
169
+ const { changeOrgRole, revokeAllProjectMemberships } = await import("./authz/sync.js");
170
+ const oldRole = member$1.role;
171
+ const targetRole = newRole;
172
+ await changeOrgRole({
173
+ tenantId: org.id,
174
+ userId: member$1.userId,
175
+ oldRole,
176
+ newRole: targetRole
177
+ });
178
+ console.log(`🔐 SpiceDB: Updated member ${member$1.userId} role from ${oldRole} to ${targetRole} in org ${org.name}`);
179
+ if (oldRole === OrgRoles.MEMBER && (targetRole === OrgRoles.ADMIN || targetRole === OrgRoles.OWNER)) {
180
+ await revokeAllProjectMemberships({
172
181
  tenantId: org.id,
173
- userId: member$1.userId,
174
- oldRole,
175
- newRole
182
+ userId: member$1.userId
176
183
  });
177
- console.log(`🔐 SpiceDB: Updated member ${member$1.userId} role from ${oldRole} to ${newRole} in org ${org.name}`);
178
- } catch (error) {
179
- console.error("❌ SpiceDB sync failed for role update:", error);
184
+ console.log(`🔐 SpiceDB: Revoked all project memberships for ${member$1.userId} (promoted to ${targetRole})`);
180
185
  }
181
186
  },
182
187
  afterRemoveMember: async ({ member: member$1, organization: org }) => {
@@ -12,9 +12,10 @@ declare function getSpiceClient(): ZedClientInterface;
12
12
  * Reset the client (useful for testing)
13
13
  */
14
14
  declare function resetSpiceClient(): void;
15
+ declare const RelationshipOperation: typeof v1.RelationshipUpdate_Operation;
16
+ declare const Permissionship: typeof v1.CheckPermissionResponse_Permissionship;
15
17
  /**
16
18
  * Check if a subject has a permission on a resource.
17
- * Note: Caller must verify isAuthzEnabled(tenantId) before calling.
18
19
  */
19
20
  declare function checkPermission(params: {
20
21
  resourceType: string;
@@ -67,15 +68,19 @@ declare function deleteRelationship(params: {
67
68
  }): Promise<void>;
68
69
  /**
69
70
  * Read relationships for a resource to list subjects with access.
71
+ * Optionally filter by subject type and ID.
70
72
  */
71
73
  declare function readRelationships(params: {
72
74
  resourceType: string;
73
- resourceId: string;
75
+ resourceId?: string;
74
76
  relation?: string;
77
+ subjectType?: string;
78
+ subjectId?: string;
75
79
  }): Promise<Array<{
80
+ resourceId: string;
76
81
  subjectType: string;
77
82
  subjectId: string;
78
83
  relation: string;
79
84
  }>>;
80
85
  //#endregion
81
- export { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
86
+ export { Permissionship, RelationshipOperation, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
@@ -7,6 +7,7 @@ import { v1 } from "@authzed/authzed-node";
7
7
  *
8
8
  * Provides a singleton SpiceDB client and helper functions for common operations.
9
9
  */
10
+ const { RelationshipUpdate_Operation, CheckPermissionResponse_Permissionship } = v1;
10
11
  let client = null;
11
12
  /**
12
13
  * Get the SpiceDB client singleton.
@@ -25,11 +26,10 @@ function getSpiceClient() {
25
26
  function resetSpiceClient() {
26
27
  client = null;
27
28
  }
28
- const PERMISSIONSHIP_HAS_PERMISSION = 2;
29
- const RELATIONSHIP_OPERATION_CREATE = 1;
29
+ const RelationshipOperation = RelationshipUpdate_Operation;
30
+ const Permissionship = CheckPermissionResponse_Permissionship;
30
31
  /**
31
32
  * Check if a subject has a permission on a resource.
32
- * Note: Caller must verify isAuthzEnabled(tenantId) before calling.
33
33
  */
34
34
  async function checkPermission(params) {
35
35
  return (await getSpiceClient().promises.checkPermission({
@@ -46,12 +46,12 @@ async function checkPermission(params) {
46
46
  optionalRelation: ""
47
47
  },
48
48
  consistency: { requirement: {
49
- oneofKind: "minimizeLatency",
50
- minimizeLatency: true
49
+ oneofKind: "fullyConsistent",
50
+ fullyConsistent: true
51
51
  } },
52
52
  context: void 0,
53
53
  withTracing: false
54
- })).permissionship === PERMISSIONSHIP_HAS_PERMISSION;
54
+ })).permissionship === CheckPermissionResponse_Permissionship.HAS_PERMISSION;
55
55
  }
56
56
  /**
57
57
  * Check multiple permissions on a resource in a single request.
@@ -75,15 +75,15 @@ async function checkBulkPermissions(params) {
75
75
  const response = await spice.promises.checkBulkPermissions(v1.CheckBulkPermissionsRequest.create({
76
76
  items,
77
77
  consistency: { requirement: {
78
- oneofKind: "minimizeLatency",
79
- minimizeLatency: true
78
+ oneofKind: "fullyConsistent",
79
+ fullyConsistent: true
80
80
  } }
81
81
  }));
82
82
  const result = {};
83
83
  for (let i = 0; i < params.permissions.length; i++) {
84
84
  const permission = params.permissions[i];
85
85
  const pair = response.pairs[i];
86
- if (pair.response.oneofKind === "item") result[permission] = pair.response.item.permissionship === PERMISSIONSHIP_HAS_PERMISSION;
86
+ if (pair.response.oneofKind === "item") result[permission] = pair.response.item.permissionship === CheckPermissionResponse_Permissionship.HAS_PERMISSION;
87
87
  else result[permission] = false;
88
88
  }
89
89
  return result;
@@ -103,8 +103,8 @@ async function lookupResources(params) {
103
103
  optionalRelation: ""
104
104
  },
105
105
  consistency: { requirement: {
106
- oneofKind: "minimizeLatency",
107
- minimizeLatency: true
106
+ oneofKind: "fullyConsistent",
107
+ fullyConsistent: true
108
108
  } },
109
109
  context: void 0,
110
110
  optionalLimit: 0,
@@ -117,7 +117,7 @@ async function lookupResources(params) {
117
117
  async function writeRelationship(params) {
118
118
  await getSpiceClient().promises.writeRelationships({
119
119
  updates: [{
120
- operation: RELATIONSHIP_OPERATION_CREATE,
120
+ operation: RelationshipUpdate_Operation.TOUCH,
121
121
  relationship: {
122
122
  resource: {
123
123
  objectType: params.resourceType,
@@ -162,23 +162,29 @@ async function deleteRelationship(params) {
162
162
  }
163
163
  /**
164
164
  * Read relationships for a resource to list subjects with access.
165
+ * Optionally filter by subject type and ID.
165
166
  */
166
167
  async function readRelationships(params) {
167
168
  return (await getSpiceClient().promises.readRelationships({
168
169
  relationshipFilter: {
169
170
  resourceType: params.resourceType,
170
- optionalResourceId: params.resourceId,
171
+ optionalResourceId: params.resourceId || "",
171
172
  optionalResourceIdPrefix: "",
172
173
  optionalRelation: params.relation || "",
173
- optionalSubjectFilter: void 0
174
+ optionalSubjectFilter: params.subjectType || params.subjectId ? {
175
+ subjectType: params.subjectType || "",
176
+ optionalSubjectId: params.subjectId || "",
177
+ optionalRelation: void 0
178
+ } : void 0
174
179
  },
175
180
  consistency: { requirement: {
176
- oneofKind: "minimizeLatency",
177
- minimizeLatency: true
181
+ oneofKind: "fullyConsistent",
182
+ fullyConsistent: true
178
183
  } },
179
184
  optionalLimit: 0,
180
185
  optionalCursor: void 0
181
186
  })).map((item) => ({
187
+ resourceId: item.relationship?.resource?.objectId || "",
182
188
  subjectType: item.relationship?.subject?.object?.objectType || "",
183
189
  subjectId: item.relationship?.subject?.object?.objectId || "",
184
190
  relation: item.relationship?.relation || ""
@@ -186,4 +192,4 @@ async function readRelationships(params) {
186
192
  }
187
193
 
188
194
  //#endregion
189
- export { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
195
+ export { Permissionship, RelationshipOperation, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
@@ -1,23 +1,7 @@
1
1
  //#region src/auth/authz/config.d.ts
2
- /**
3
- * SpiceDB Authorization Configuration
4
- *
5
- * Feature flag and configuration for the SpiceDB authorization system.
6
- */
7
- /**
8
- * Check if authorization is enabled.
9
- *
10
- * When called without tenantId:
11
- * - Returns true if ENABLE_AUTHZ=true
12
- *
13
- * When called with tenantId:
14
- * - If ENABLE_AUTHZ=false → returns false
15
- * - If ENABLE_AUTHZ=true and TENANT_ID is not set → returns true (all tenants)
16
- * - If ENABLE_AUTHZ=true and TENANT_ID is set → returns true only if tenantId matches
17
- */
18
- declare function isAuthzEnabled(tenantId: string): boolean;
19
2
  /**
20
3
  * Get SpiceDB connection configuration from environment variables.
4
+ * TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
21
5
  */
22
6
  declare function getSpiceDbConfig(): {
23
7
  endpoint: string;
@@ -48,29 +32,66 @@ declare const SpiceDbRelations: {
48
32
  readonly PROJECT_VIEWER: "project_viewer";
49
33
  };
50
34
  /**
51
- * SpiceDB permissions used in the schema
35
+ * SpiceDB permissions for organization resources.
52
36
  *
53
- * Permissions are named as verbs (actions) per SpiceDB best practices.
37
+ * From schema.zed definition organization:
38
+ * - view: owner + admin + member
39
+ * - manage: owner + admin (includes managing org settings and all projects)
54
40
  */
41
+ declare const SpiceDbOrgPermissions: {
42
+ readonly VIEW: "view";
43
+ readonly MANAGE: "manage";
44
+ };
45
+ type SpiceDbOrgPermission = (typeof SpiceDbOrgPermissions)[keyof typeof SpiceDbOrgPermissions];
55
46
  /**
56
- * SpiceDB permissions used in permission checks.
47
+ * SpiceDB permissions for project resources.
57
48
  *
58
- * Note: Organization-level permissions (manage) are handled via
59
- * orgRole bypass in permission functions, not direct SpiceDB checks.
49
+ * From schema.zed definition project:
50
+ * - view: read-only access to project and its resources
51
+ * - use: invoke agents, create API keys, view traces
52
+ * - edit: modify configurations, manage members
60
53
  */
61
- declare const SpiceDbPermissions: {
54
+ declare const SpiceDbProjectPermissions: {
62
55
  readonly VIEW: "view";
63
56
  readonly USE: "use";
64
57
  readonly EDIT: "edit";
65
- readonly DELETE: "delete";
66
58
  };
67
- type OrgRole = 'owner' | 'admin' | 'member';
59
+ type SpiceDbProjectPermission = (typeof SpiceDbProjectPermissions)[keyof typeof SpiceDbProjectPermissions];
60
+ /**
61
+ * Permission levels for project access checks.
62
+ */
63
+ type ProjectPermissionLevel = SpiceDbProjectPermission;
68
64
  /**
69
- * Project roles hierarchy:
70
- * - project_admin: Full access (view + use + edit + manage members + delete)
65
+ * Organization roles from SpiceDB schema.
66
+ */
67
+ declare const OrgRoles: {
68
+ readonly OWNER: "owner";
69
+ readonly ADMIN: "admin";
70
+ readonly MEMBER: "member";
71
+ };
72
+ type OrgRole = (typeof OrgRoles)[keyof typeof OrgRoles];
73
+ /**
74
+ * Project roles from SpiceDB schema.
75
+ *
76
+ * Hierarchy:
77
+ * - project_admin: Full access (view + use + edit + manage members)
71
78
  * - project_member: Operator access (view + use: invoke agents, create API keys)
72
79
  * - project_viewer: Read-only access (view only)
73
80
  */
74
- type ProjectRole = 'project_admin' | 'project_member' | 'project_viewer';
81
+ declare const ProjectRoles: {
82
+ readonly ADMIN: "project_admin";
83
+ readonly MEMBER: "project_member";
84
+ readonly VIEWER: "project_viewer";
85
+ };
86
+ type ProjectRole = (typeof ProjectRoles)[keyof typeof ProjectRoles];
87
+ /**
88
+ * Project permission capabilities.
89
+ * Maps to the SpiceDB permission checks (view, use, edit).
90
+ */
91
+ interface ProjectPermissions {
92
+ canView: boolean;
93
+ canUse: boolean;
94
+ canEdit: boolean;
95
+ }
75
96
  //#endregion
76
- export { OrgRole, ProjectRole, SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled };
97
+ export { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig };
@@ -1,34 +1,15 @@
1
1
  //#region src/auth/authz/config.ts
2
2
  /**
3
- * SpiceDB Authorization Configuration
4
- *
5
- * Feature flag and configuration for the SpiceDB authorization system.
6
- */
7
- /**
8
- * Check if authorization is enabled.
9
- *
10
- * When called without tenantId:
11
- * - Returns true if ENABLE_AUTHZ=true
12
- *
13
- * When called with tenantId:
14
- * - If ENABLE_AUTHZ=false → returns false
15
- * - If ENABLE_AUTHZ=true and TENANT_ID is not set → returns true (all tenants)
16
- * - If ENABLE_AUTHZ=true and TENANT_ID is set → returns true only if tenantId matches
17
- */
18
- function isAuthzEnabled(tenantId) {
19
- if (process.env.ENABLE_AUTHZ !== "true") return false;
20
- const configuredTenantId = process.env.TENANT_ID?.trim();
21
- if (!configuredTenantId) return true;
22
- return tenantId === configuredTenantId;
23
- }
24
- /**
25
3
  * Get SpiceDB connection configuration from environment variables.
4
+ * TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
26
5
  */
27
6
  function getSpiceDbConfig() {
7
+ const endpoint = process.env.SPICEDB_ENDPOINT || "localhost:50051";
8
+ const isLocalhost = endpoint.startsWith("localhost") || endpoint.startsWith("127.0.0.1");
28
9
  return {
29
- endpoint: process.env.SPICEDB_ENDPOINT || "localhost:50051",
10
+ endpoint,
30
11
  token: process.env.SPICEDB_PRESHARED_KEY || "",
31
- tlsEnabled: process.env.SPICEDB_TLS_ENABLED === "true"
12
+ tlsEnabled: !isLocalhost
32
13
  };
33
14
  }
34
15
  /**
@@ -55,22 +36,50 @@ const SpiceDbRelations = {
55
36
  PROJECT_VIEWER: "project_viewer"
56
37
  };
57
38
  /**
58
- * SpiceDB permissions used in the schema
39
+ * SpiceDB permissions for organization resources.
59
40
  *
60
- * Permissions are named as verbs (actions) per SpiceDB best practices.
41
+ * From schema.zed definition organization:
42
+ * - view: owner + admin + member
43
+ * - manage: owner + admin (includes managing org settings and all projects)
61
44
  */
45
+ const SpiceDbOrgPermissions = {
46
+ VIEW: "view",
47
+ MANAGE: "manage"
48
+ };
62
49
  /**
63
- * SpiceDB permissions used in permission checks.
50
+ * SpiceDB permissions for project resources.
64
51
  *
65
- * Note: Organization-level permissions (manage) are handled via
66
- * orgRole bypass in permission functions, not direct SpiceDB checks.
52
+ * From schema.zed definition project:
53
+ * - view: read-only access to project and its resources
54
+ * - use: invoke agents, create API keys, view traces
55
+ * - edit: modify configurations, manage members
67
56
  */
68
- const SpiceDbPermissions = {
57
+ const SpiceDbProjectPermissions = {
69
58
  VIEW: "view",
70
59
  USE: "use",
71
- EDIT: "edit",
72
- DELETE: "delete"
60
+ EDIT: "edit"
61
+ };
62
+ /**
63
+ * Organization roles from SpiceDB schema.
64
+ */
65
+ const OrgRoles = {
66
+ OWNER: "owner",
67
+ ADMIN: "admin",
68
+ MEMBER: "member"
69
+ };
70
+ /**
71
+ * Project roles from SpiceDB schema.
72
+ *
73
+ * Hierarchy:
74
+ * - project_admin: Full access (view + use + edit + manage members)
75
+ * - project_member: Operator access (view + use: invoke agents, create API keys)
76
+ * - project_viewer: Read-only access (view only)
77
+ */
78
+ const ProjectRoles = {
79
+ ADMIN: "project_admin",
80
+ MEMBER: "project_member",
81
+ VIEWER: "project_viewer"
73
82
  };
74
83
 
75
84
  //#endregion
76
- export { SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled };
85
+ export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig };
@@ -1,5 +1,5 @@
1
1
  import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
2
- import { OrgRole, ProjectRole, SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled } from "./config.js";
2
+ import { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig } from "./config.js";
3
3
  import { canEditProject, canUseProject, canViewProject, listAccessibleProjectIds } from "./permissions.js";
4
- import { changeProjectRole, grantProjectAccess, listProjectMembers, removeProjectFromSpiceDb, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
5
- export { type OrgRole, type ProjectRole, SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, isAuthzEnabled, listAccessibleProjectIds, listProjectMembers, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
4
+ import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
5
+ export { type OrgRole, OrgRoles, type ProjectPermissionLevel, type ProjectPermissions, type ProjectRole, ProjectRoles, type SpiceDbOrgPermission, SpiceDbOrgPermissions, type SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
@@ -1,6 +1,6 @@
1
- import { SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled } from "./config.js";
1
+ import { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig } from "./config.js";
2
2
  import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
3
3
  import { canEditProject, canUseProject, canViewProject, listAccessibleProjectIds } from "./permissions.js";
4
- import { changeProjectRole, grantProjectAccess, listProjectMembers, removeProjectFromSpiceDb, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
4
+ import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
5
5
 
6
- export { SpiceDbPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, isAuthzEnabled, listAccessibleProjectIds, listProjectMembers, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
6
+ export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
@@ -10,7 +10,6 @@ import { OrgRole } from "./config.js";
10
10
  * - Otherwise: checks SpiceDB
11
11
  */
12
12
  declare function canViewProject(params: {
13
- tenantId: string;
14
13
  userId: string;
15
14
  projectId: string;
16
15
  orgRole: OrgRole;
@@ -23,7 +22,6 @@ declare function canViewProject(params: {
23
22
  * - Otherwise: checks SpiceDB for use permission
24
23
  */
25
24
  declare function canUseProject(params: {
26
- tenantId: string;
27
25
  userId: string;
28
26
  projectId: string;
29
27
  orgRole: OrgRole;
@@ -36,7 +34,6 @@ declare function canUseProject(params: {
36
34
  * - Otherwise: checks SpiceDB for edit permission
37
35
  */
38
36
  declare function canEditProject(params: {
39
- tenantId: string;
40
37
  userId: string;
41
38
  projectId: string;
42
39
  orgRole: OrgRole;
@@ -49,7 +46,6 @@ declare function canEditProject(params: {
49
46
  * - Otherwise: uses SpiceDB LookupResources
50
47
  */
51
48
  declare function listAccessibleProjectIds(params: {
52
- tenantId: string;
53
49
  userId: string;
54
50
  orgRole: OrgRole;
55
51
  }): Promise<string[] | 'all'>;