@opengeni/core 0.28.1 → 1.0.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 (224) hide show
  1. package/README.md +1 -1
  2. package/dist/access/external-actor-authority.d.ts +47 -0
  3. package/dist/access/index.d.ts +182 -3
  4. package/dist/access/service-initiator.d.ts +3 -0
  5. package/dist/application/api-integration-servers.d.ts +20 -0
  6. package/dist/application/archived-session-imports.d.ts +6 -0
  7. package/dist/application/composer-submit.d.ts +24 -0
  8. package/dist/application/connect-authority.d.ts +13 -0
  9. package/dist/application/connect-operation.d.ts +31 -0
  10. package/dist/application/external-continuation.d.ts +15 -0
  11. package/dist/application/external-identity-lifecycle.d.ts +20 -0
  12. package/dist/application/external-link-work-admission.d.ts +12 -0
  13. package/dist/application/external-workspace-members.d.ts +34 -0
  14. package/dist/application/modal-native-worker-host-transport.d.ts +297 -0
  15. package/dist/application/new-session-drafts.d.ts +39 -2
  16. package/dist/application/sandbox-recovery.d.ts +58 -0
  17. package/dist/application/session-commands.d.ts +26 -13
  18. package/dist/application/session-mcp-credential-rotation.d.ts +29 -0
  19. package/dist/application/session-tenancy.d.ts +19 -0
  20. package/dist/application/user-resource-grants.d.ts +20 -0
  21. package/dist/billing/limits.d.ts +11 -0
  22. package/dist/canonical-human-identities.d.ts +7 -2
  23. package/dist/canonical-human-identities.js +17 -4
  24. package/dist/canonical-human-identities.js.map +1 -1
  25. package/dist/{chunk-6WKPWE5S.js → chunk-2MKMRGSY.js} +108 -24
  26. package/dist/chunk-2MKMRGSY.js.map +1 -0
  27. package/dist/{chunk-NYPMQ7NO.js → chunk-GVO3N37G.js} +205 -37
  28. package/dist/chunk-GVO3N37G.js.map +1 -0
  29. package/dist/{chunk-JJU6I5XD.js → chunk-LCQXNR62.js} +36 -10
  30. package/dist/chunk-LCQXNR62.js.map +1 -0
  31. package/dist/chunk-MM6N7CTO.js +387 -0
  32. package/dist/chunk-MM6N7CTO.js.map +1 -0
  33. package/dist/chunk-QO5GVFFO.js +235 -0
  34. package/dist/chunk-QO5GVFFO.js.map +1 -0
  35. package/dist/codex-model-availability.d.ts +14 -0
  36. package/dist/default-session-model.d.ts +139 -0
  37. package/dist/dependencies.d.ts +87 -4
  38. package/dist/developer-setup-credential-ceiling.d.ts +10 -0
  39. package/dist/domain/agent-config-resolution.d.ts +49 -0
  40. package/dist/domain/automations.d.ts +58 -0
  41. package/dist/domain/capabilities.d.ts +22 -4
  42. package/dist/domain/company-profile-agent-admin.d.ts +25 -0
  43. package/dist/domain/connection-account-selection-error.d.ts +8 -0
  44. package/dist/domain/connector-tool-permissions.d.ts +36 -0
  45. package/dist/domain/direct-model-provider.d.ts +3 -0
  46. package/dist/domain/editable-artifacts/agent-application.d.ts +10 -1
  47. package/dist/domain/editable-artifacts/durable-export.d.ts +22 -1
  48. package/dist/domain/editable-artifacts/ports.d.ts +10 -0
  49. package/dist/domain/editable-artifacts/service.d.ts +4 -3
  50. package/dist/domain/environments.d.ts +5 -9
  51. package/dist/domain/external-creation-attribution.d.ts +6 -0
  52. package/dist/domain/file-owner.d.ts +8 -0
  53. package/dist/domain/github-action-policies.d.ts +36 -0
  54. package/dist/domain/github-repository-bindings.d.ts +117 -0
  55. package/dist/domain/github-skill-source.d.ts +5 -0
  56. package/dist/domain/governed-learning-slack-publication.d.ts +45 -0
  57. package/dist/domain/insights-timing.d.ts +16 -0
  58. package/dist/domain/insights-usage.d.ts +27 -0
  59. package/dist/domain/insights.d.ts +28 -1
  60. package/dist/domain/knowledge-files.d.ts +20 -0
  61. package/dist/domain/knowledge-messages.d.ts +39 -0
  62. package/dist/domain/knowledge-messages.test.d.ts +1 -0
  63. package/dist/domain/knowledge-preparation.d.ts +10 -0
  64. package/dist/domain/knowledge-preparation.test.d.ts +1 -0
  65. package/dist/domain/knowledge-search.d.ts +15 -0
  66. package/dist/domain/knowledge-search.test.d.ts +1 -0
  67. package/dist/domain/knowledge.d.ts +9 -0
  68. package/dist/domain/mcp-account-bindings.d.ts +19 -0
  69. package/dist/domain/mcp-account-routes.d.ts +21 -0
  70. package/dist/domain/native-mcp-connection-admission.d.ts +3 -0
  71. package/dist/domain/organization-integration-catalog.d.ts +15 -0
  72. package/dist/domain/organization-membership-lifecycle.d.ts +1 -0
  73. package/dist/domain/personal-connection-delegations.d.ts +87 -4
  74. package/dist/domain/pr-review.d.ts +249 -0
  75. package/dist/domain/resources.d.ts +24 -3
  76. package/dist/domain/scheduled-task-access.d.ts +247 -0
  77. package/dist/domain/scheduled-tasks.d.ts +103 -6
  78. package/dist/domain/session-connection-accounts.d.ts +16 -0
  79. package/dist/domain/session-file-access.d.ts +4 -0
  80. package/dist/domain/session-native-connection-replacement.d.ts +14 -0
  81. package/dist/domain/session-start-timing.d.ts +7 -0
  82. package/dist/domain/session-tool-policy.d.ts +93 -4
  83. package/dist/domain/sessions.d.ts +275 -28
  84. package/dist/domain/skill-imports.d.ts +1 -0
  85. package/dist/domain/skill-search.d.ts +30 -0
  86. package/dist/domain/skills.d.ts +117 -0
  87. package/dist/domain/slack-bot.d.ts +46 -1
  88. package/dist/domain/workspace-members.d.ts +8 -1
  89. package/dist/editable-artifact-live/application.d.ts +12 -3
  90. package/dist/editable-artifact-live/ports.d.ts +0 -1
  91. package/dist/editable-artifact-live/server.d.ts +5 -2
  92. package/dist/editable-artifact-live/ticket.d.ts +2 -2
  93. package/dist/editable-artifact-live/types.d.ts +14 -2
  94. package/dist/editable-artifact-live.js +2 -2
  95. package/dist/editable-artifacts.js +10 -4
  96. package/dist/index.d.ts +49 -3
  97. package/dist/index.js +18812 -6833
  98. package/dist/index.js.map +1 -1
  99. package/dist/managed-auth-session-sets.d.ts +131 -0
  100. package/dist/managed-auth-session-sets.js +51 -0
  101. package/dist/managed-auth-session-sets.js.map +1 -0
  102. package/dist/managed-session.d.ts +98 -11
  103. package/dist/model-catalog.d.ts +117 -0
  104. package/dist/product-usage-metrics.d.ts +30 -0
  105. package/dist/rigs/index.d.ts +22 -5
  106. package/dist/rigs/provider-images.d.ts +1 -1
  107. package/dist/sandbox/fleet.d.ts +59 -10
  108. package/dist/sandbox/routing.d.ts +22 -2
  109. package/dist/sandbox/runtime-settings.d.ts +56 -0
  110. package/dist/session-authorization.d.ts +38 -1
  111. package/dist/site-session-origin.d.ts +9 -0
  112. package/dist/transcription.d.ts +12 -1
  113. package/dist/turn-surface.d.ts +18 -0
  114. package/dist/user-presence.d.ts +32 -0
  115. package/package.json +18 -11
  116. package/src/access/external-actor-authority.ts +94 -0
  117. package/src/access/index.ts +1386 -44
  118. package/src/access/service-initiator.ts +50 -0
  119. package/src/application/api-integration-servers.ts +215 -0
  120. package/src/application/archived-session-imports.ts +161 -0
  121. package/src/application/composer-submit.ts +77 -0
  122. package/src/application/connect-authority.ts +77 -0
  123. package/src/application/connect-operation.ts +80 -0
  124. package/src/application/external-continuation.ts +129 -0
  125. package/src/application/external-identity-lifecycle.ts +48 -0
  126. package/src/application/external-link-work-admission.ts +90 -0
  127. package/src/application/external-workspace-members.ts +232 -0
  128. package/src/application/modal-native-worker-host-transport.ts +263 -0
  129. package/src/application/new-session-drafts.ts +222 -29
  130. package/src/application/sandbox-recovery.ts +78 -0
  131. package/src/application/session-commands.ts +430 -73
  132. package/src/application/session-mcp-credential-rotation.ts +217 -0
  133. package/src/application/session-tenancy.ts +445 -0
  134. package/src/application/user-resource-grants.ts +154 -0
  135. package/src/billing/limits.ts +103 -24
  136. package/src/canonical-human-identities.ts +22 -3
  137. package/src/codex-model-availability.ts +136 -0
  138. package/src/default-session-model.ts +656 -0
  139. package/src/dependencies.ts +97 -5
  140. package/src/developer-setup-credential-ceiling.ts +60 -0
  141. package/src/domain/agent-config-resolution.ts +148 -0
  142. package/src/domain/automations.ts +270 -0
  143. package/src/domain/capabilities.ts +244 -151
  144. package/src/domain/company-profile-agent-admin.ts +56 -0
  145. package/src/domain/connection-account-selection-error.ts +19 -0
  146. package/src/domain/connector-tool-permissions.ts +371 -0
  147. package/src/domain/direct-model-provider.ts +62 -0
  148. package/src/domain/editable-artifacts/agent-application.ts +61 -15
  149. package/src/domain/editable-artifacts/durable-export.ts +100 -5
  150. package/src/domain/editable-artifacts/in-memory.ts +6 -0
  151. package/src/domain/editable-artifacts/ports.ts +11 -0
  152. package/src/domain/editable-artifacts/service.ts +32 -1
  153. package/src/domain/editable-artifacts/snapshot-compaction.ts +9 -5
  154. package/src/domain/editable-artifacts/snapshot-verifier-genesis.ts +10 -8
  155. package/src/domain/editable-artifacts/snapshot-verifier.ts +10 -3
  156. package/src/domain/environments.ts +25 -45
  157. package/src/domain/external-creation-attribution.ts +22 -0
  158. package/src/domain/file-owner.ts +67 -0
  159. package/src/domain/github-action-policies.ts +169 -0
  160. package/src/domain/github-repository-bindings.ts +295 -0
  161. package/src/domain/github-skill-source.ts +233 -0
  162. package/src/domain/governed-learning-slack-publication.ts +157 -0
  163. package/src/domain/insights-timing.ts +95 -0
  164. package/src/domain/insights-usage.ts +67 -0
  165. package/src/domain/insights.ts +270 -169
  166. package/src/domain/knowledge-files.ts +46 -0
  167. package/src/domain/knowledge-messages.test.ts +91 -0
  168. package/src/domain/knowledge-messages.ts +106 -0
  169. package/src/domain/knowledge-preparation.test.ts +276 -0
  170. package/src/domain/knowledge-preparation.ts +147 -0
  171. package/src/domain/knowledge-search.test.ts +561 -0
  172. package/src/domain/knowledge-search.ts +256 -0
  173. package/src/domain/knowledge.ts +133 -0
  174. package/src/domain/mcp-account-bindings.ts +171 -0
  175. package/src/domain/mcp-account-routes.ts +121 -0
  176. package/src/domain/native-mcp-connection-admission.ts +14 -0
  177. package/src/domain/organization-integration-catalog.ts +88 -0
  178. package/src/domain/organization-membership-lifecycle.ts +10 -0
  179. package/src/domain/personal-connection-delegations.ts +758 -115
  180. package/src/domain/pr-review.ts +687 -0
  181. package/src/domain/resources.ts +182 -25
  182. package/src/domain/scheduled-task-access.ts +1052 -0
  183. package/src/domain/scheduled-tasks.ts +1952 -215
  184. package/src/domain/session-connection-accounts.ts +67 -0
  185. package/src/domain/session-file-access.ts +47 -0
  186. package/src/domain/session-native-connection-replacement.ts +64 -0
  187. package/src/domain/session-start-timing.ts +55 -0
  188. package/src/domain/session-tool-policy.ts +443 -19
  189. package/src/domain/sessions.ts +3417 -619
  190. package/src/domain/skill-imports.ts +137 -17
  191. package/src/domain/skill-search.ts +221 -0
  192. package/src/domain/skills.ts +104 -0
  193. package/src/domain/slack-bot.ts +128 -3
  194. package/src/domain/workspace-members.ts +34 -2
  195. package/src/editable-artifact-live/application.ts +29 -4
  196. package/src/editable-artifact-live/ports.ts +0 -1
  197. package/src/editable-artifact-live/server.ts +167 -13
  198. package/src/editable-artifact-live/ticket.ts +87 -6
  199. package/src/editable-artifact-live/types.ts +16 -2
  200. package/src/editable-artifact-live/wire.ts +0 -10
  201. package/src/index.ts +69 -4
  202. package/src/managed-auth-session-sets.ts +371 -0
  203. package/src/managed-session.ts +520 -2
  204. package/src/model-catalog.ts +873 -0
  205. package/src/product-usage-metrics.ts +101 -0
  206. package/src/rigs/index.ts +179 -63
  207. package/src/rigs/provider-images.ts +2 -3
  208. package/src/sandbox/fleet.ts +471 -59
  209. package/src/sandbox/routing.ts +160 -33
  210. package/src/sandbox/runtime-settings.ts +281 -0
  211. package/src/session-authorization.ts +262 -78
  212. package/src/site-session-origin.ts +22 -0
  213. package/src/transcription.ts +13 -1
  214. package/src/turn-surface.ts +45 -0
  215. package/src/user-presence.ts +134 -0
  216. package/dist/chunk-6WKPWE5S.js.map +0 -1
  217. package/dist/chunk-IBOEYG6N.js +0 -34
  218. package/dist/chunk-IBOEYG6N.js.map +0 -1
  219. package/dist/chunk-JJU6I5XD.js.map +0 -1
  220. package/dist/chunk-NYPMQ7NO.js.map +0 -1
  221. package/dist/domain/durable-learning-slack-publication.d.ts +0 -72
  222. package/dist/domain/packs.d.ts +0 -55
  223. package/src/domain/durable-learning-slack-publication.ts +0 -202
  224. package/src/domain/packs.ts +0 -556
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  It owns code that is not intrinsically HTTP or Temporal process bootstrapping:
6
6
 
7
7
  - access: `requireAccessContext`, `requireAccessGrant`, `requirePermission`
8
- - domain: session creation/follow-up, scheduled-task validation, environments, packs, capabilities, workspace members
8
+ - domain: session creation/follow-up, scheduled-task validation, environments, capabilities, workspace members
9
9
  - billing/admission: `checkLimit`, `requireLimit`, `recordWorkspaceUsage`
10
10
  - dependencies: `AppDependencies`, `ApiRouteDeps`, `SessionWorkflowClient`
11
11
 
@@ -0,0 +1,47 @@
1
+ import type { Permission } from "@opengeni/contracts";
2
+ export type ExternalAuthoritySnapshot = Readonly<{
3
+ accountId: string;
4
+ externalIdentityId: string;
5
+ identityStatus: "active" | "disabled" | "revoked";
6
+ identityRevision: number;
7
+ membershipStatus: "active" | "provisioning" | "suspended" | "revoked";
8
+ workspaceId: string;
9
+ permissions: readonly Permission[];
10
+ }>;
11
+ export type ExternalLinkAuthoritySnapshot = Readonly<{
12
+ id: string;
13
+ accountId: string;
14
+ externalIdentityId: string;
15
+ revision: number;
16
+ nativeSubjectId: string;
17
+ status: "pending" | "active" | "revoked" | "expired";
18
+ expiresAt: number | null;
19
+ permissions: readonly Permission[];
20
+ nativeAuthority: Readonly<{
21
+ subjectId: string;
22
+ accountId: string;
23
+ workspaceId: string;
24
+ active: boolean;
25
+ permissions: readonly Permission[];
26
+ }>;
27
+ }>;
28
+ /** Pure permission calculation over already authenticated, live snapshots.
29
+ * This does not authenticate assertions or establish provenance. Callers must
30
+ * read snapshots under their authorization fence, never from request JSON.
31
+ * Linked mode uses the native lane alone: external workspace permissions must
32
+ * not be unioned into that lane, nor must old external resources change owner.
33
+ */
34
+ export declare function externalActorPermissions(input: {
35
+ accountId: string;
36
+ workspaceId: string;
37
+ keyActive: boolean;
38
+ keyAccountId: string;
39
+ keyPermissions: readonly Permission[];
40
+ external: ExternalAuthoritySnapshot;
41
+ linked?: {
42
+ expectedId: string;
43
+ expectedRevision: number;
44
+ authority: ExternalLinkAuthoritySnapshot;
45
+ };
46
+ now: number;
47
+ }): Permission[];
@@ -1,23 +1,201 @@
1
1
  import { type Settings } from "@opengeni/config";
2
- import { type AccountGrant, type AccessContext, type AccessGrant, type Permission } from "@opengeni/contracts";
2
+ import { ExternalActorAttribution, type ExternalActorContinuation } from "@opengeni/contracts/external-identities";
3
+ import { type AccountGrant, type AccessContext, type AccessGrant, type OrganizationApiKeyAccess, OrganizationWorkspaceScope, Permission, type Workspace } from "@opengeni/contracts";
3
4
  import { type Database } from "@opengeni/db";
4
5
  import type { Context } from "hono";
6
+ import { z } from "zod";
5
7
  import type { ManagedAuth } from "../managed-auth-type.js";
8
+ import type { ManagedAuthSessionAdapter } from "../managed-auth-session-sets.js";
9
+ import type { UserPresenceRecorder } from "../user-presence.js";
10
+ /** Only canonical authentication can prove setup-key provenance. */
11
+ export declare function isDeveloperSetupApiKeyContext(context: AccessContext): boolean;
12
+ /** Provenance from canonical raw-key or verified restricted-token authentication. */
13
+ export declare function isDeveloperSetupAuthorization(authorization: AccessGrantAuthorization | undefined): boolean;
14
+ /** Exact grant objects resolved under authenticated setup-only provenance. */
15
+ export declare function isDeveloperSetupGrant(grant: AccessGrant): boolean;
16
+ /** Setup-derived credentials cannot carry literal organization or key authority. */
17
+ export declare function isDeveloperSetupDelegatedPermissionAllowed(permission: Permission): boolean;
18
+ /** Canonical authentication provenance, including the backing key of asUser. */
19
+ export declare function requireApiKeyManagementContext(context: AccessContext): void;
20
+ /** Membership is not an escape hatch for minting durable credentials. */
21
+ export declare function requireApiKeyDelegationContext(context: AccessContext, permissions: Permission[]): void;
22
+ /** Downstream legacy credentials cannot encode a partially selected admin. */
23
+ export declare function requireExplicitPermissionDelegation(grant: Pick<AccessGrant, "permissions" | "permissionMode">, requested: Permission[]): void;
24
+ export type DelegatedHumanAuthorization = Readonly<{
25
+ organizationId: string;
26
+ /** Exact native person subject, never an external identity or service. */
27
+ subjectId: string;
28
+ permissions: Permission[];
29
+ workspaceScope: OrganizationWorkspaceScope;
30
+ }>;
31
+ declare const delegatedHumanProfileSchema: z.ZodObject<{
32
+ id: z.ZodString;
33
+ name: z.ZodNullable<z.ZodString>;
34
+ email: z.ZodString;
35
+ emailVerified: z.ZodOptional<z.ZodBoolean>;
36
+ }, z.core.$strip>;
37
+ export type VerifiedDelegatedHumanContext = Readonly<{
38
+ /** Native identity projection only, never a browser/auth session. Absence of
39
+ * emailVerified means the native lookup did not prove email verification. */
40
+ user: Readonly<z.infer<typeof delegatedHumanProfileSchema>>;
41
+ subjectId: string;
42
+ authorization: DelegatedHumanAuthorization;
43
+ context: AccessContext;
44
+ }>;
45
+ /**
46
+ * TRUSTED OAUTH VERIFIED DISPATCH ONLY. Before each stamp the in-process caller
47
+ * must validate the live OAuth grant, revocation, exact native person subject,
48
+ * organization, permission ceilings and workspace scope. This API does not
49
+ * verify OAuth and must NEVER be called with headers, metadata, token claims,
50
+ * a previous request's proof, or other unverified caller input.
51
+ *
52
+ * Stamp the exact raw Request that the actions dispatcher will pass to routes,
53
+ * before any access resolution. Cloning/wrapping a Request does not copy proof.
54
+ * The resolver reloads the real native person's live access on this request
55
+ * (and on fresh reauthorization); no session or cached grant is fabricated or
56
+ * transplanted. This proof never becomes managed-cookie/person-present proof.
57
+ */
58
+ export declare function stampDelegatedHumanAuthorization(request: Request, input: DelegatedHumanAuthorization): void;
59
+ /** Immutable verified dispatch bounds for this exact raw Request, not a grant. */
60
+ export declare function verifiedDelegatedHumanAuthorizationForRequest(request: Request): DelegatedHumanAuthorization | null;
61
+ /**
62
+ * Resolve the exact verified OAuth-dispatch person and constrained live native
63
+ * access for this raw Request. Unstamped requests (even browser cookies) fail
64
+ * closed; callers must not fall back to a service or subject-shaped identity.
65
+ * Uses the same request-local native resolution as requireAccessContext.
66
+ *
67
+ * No session, session id or managed-cookie proof is created. emailVerified is
68
+ * forwarded only when the native profile lookup supplies it; missing is not
69
+ * verified and must never be filled from OAuth claims, headers or metadata.
70
+ */
71
+ export declare function requireVerifiedDelegatedHumanContext(c: Context, deps: AccessDeps): Promise<VerifiedDelegatedHumanContext>;
72
+ /** Exact resolved owning-person authorization; clones and service claims fail.
73
+ * Supplying the raw Request additionally binds proof to that exact dispatch,
74
+ * not another request with the same native person and authorization bounds. */
75
+ export declare function isVerifiedDelegatedHumanAuthorization(authorization: AccessGrantAuthorization, request?: Request): boolean;
76
+ /**
77
+ * Default permissions for a membership created on an external user's first
78
+ * request. Keep equal to `CONVERSATION_PERMISSIONS` in
79
+ * `packages/sdk/src/tenant-workspaces.ts`: conversation use only, no admin.
80
+ */
81
+ export declare const EXTERNAL_FIRST_USE_MEMBER_PERMISSIONS: readonly Permission[];
82
+ /** Creation audit only, never an authentication or delegation token. Metadata
83
+ * claiming to be external is insufficient; the exact resolver proof is needed. */
84
+ export declare function externalAttributionForAuthorization(authorization: AccessGrantAuthorization | undefined, grant: AccessGrant): ExternalActorAttribution | null;
85
+ export declare function externalActorContinuationForAuthorization(authorization: AccessGrantAuthorization): ExternalActorContinuation | null;
86
+ /** Dedicated owning-user proof. External/OAuth admission never sets the native
87
+ * cookie stamp. The resource/session layer still checks the exact owner. */
88
+ export declare function hasVerifiedOwningUserAuthorization(authorization: AccessGrantAuthorization): boolean;
89
+ /** Request-local organization service-key proof, not a principal-kind claim. */
90
+ export declare function isVerifiedOrganizationServiceAuthorization(authorization: AccessGrantAuthorization): boolean;
91
+ export type AccountScopedApiKeyWorkspaceAuthority = Readonly<{
92
+ accountId: string;
93
+ permissions: Permission[];
94
+ workspaceScope: OrganizationWorkspaceScope;
95
+ permissionMode: "legacy" | "explicit";
96
+ }>;
97
+ export declare function organizationWorkspaceInScope(scope: OrganizationWorkspaceScope, workspaceId: string): boolean;
98
+ /**
99
+ * Return account-scoped API-key workspace authority only for the exact
100
+ * AccessContext object stamped by successful API-key authentication. Subject
101
+ * shape alone is deliberately insufficient.
102
+ */
103
+ export declare function accountScopedApiKeyWorkspaceAuthority(context: AccessContext): AccountScopedApiKeyWorkspaceAuthority | null;
104
+ /** Classify stored scopes without changing the legacy full/read permission sets. */
105
+ export declare function organizationApiKeyAccess(permissions: Permission[]): OrganizationApiKeyAccess;
106
+ /**
107
+ * Opaque, request-local proof that the canonical access resolver authorized the
108
+ * exact account administrator named by the stamp. The random id is audit and
109
+ * replay provenance only; object identity is what prevents a caller from
110
+ * manufacturing this proof inside the API process.
111
+ */
112
+ export type AccountAdminAuthorizationStamp = Readonly<{
113
+ authorizationId: string;
114
+ accountId: string;
115
+ actorSubjectId: string;
116
+ permission: "account:admin";
117
+ }>;
6
118
  export type AccessDeps = {
7
119
  db: Database;
8
120
  settings: Settings;
9
121
  managedAuth?: ManagedAuth | null;
122
+ managedAuthSessionAdapter?: ManagedAuthSessionAdapter | null;
123
+ /** Analytics only: notes canonical managed-cookie activity, never authority. */
124
+ userPresence?: UserPresenceRecorder | null;
10
125
  };
126
+ /** null means this is not an authenticated external lane; [] means that lane
127
+ * has no readable inventory. Callers must not fall back from [] to service or
128
+ * bare-subject discovery. */
129
+ export declare function listExternalActorWorkspaces(context: AccessContext, deps: AccessDeps): Promise<Workspace[] | null>;
11
130
  export declare function requireAccessContext(c: Context, deps: AccessDeps): Promise<AccessContext>;
12
131
  export declare function requireAccessGrant(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrant>;
132
+ /**
133
+ * Re-resolve the authenticated principal and its current grants without using
134
+ * the request-local access cache. Long-lived responses use this to ensure a
135
+ * membership suspension or revocation takes effect while the connection is
136
+ * still open.
137
+ */
138
+ export declare function requireFreshAccessGrant(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrant>;
13
139
  export type AccessGrantAuthorization = {
14
140
  grant: AccessGrant;
15
141
  accountGrant: AccountGrant | null;
16
142
  authenticatedSubjectId: string;
17
143
  contextIntegrity: boolean;
144
+ /**
145
+ * Did this request authenticate as the canonical managed-cookie (Better Auth)
146
+ * session that OWNS this grant's subject? Cookie/person-present ceremonies
147
+ * retain this strict gate; owning-user boundaries use
148
+ * `hasVerifiedOwningUserAuthorization` instead.
149
+ * False for every bearer, API-key, delegated, service, local, and configured
150
+ * principal, and for any future path that does not verify a cookie.
151
+ */
152
+ canonicalManagedHumanSession: boolean;
153
+ /** Exact in-process single-user local bootstrap, never a delegated bearer. */
154
+ canonicalLocalHumanSession: boolean;
18
155
  };
19
156
  export declare function accessGrantAuthorizationFromContext(context: AccessContext, grant: AccessGrant): AccessGrantAuthorization;
157
+ /**
158
+ * Mint the capability passed to an account-admin database lifecycle.
159
+ *
160
+ * This deliberately accepts every canonical access mode (managed,
161
+ * local/configured, and signed delegation). Organization-membership rows are
162
+ * one possible source of account authority, not the definition of it. A plain
163
+ * object with matching fields is rejected because only values returned by the
164
+ * access resolver are present in `resolvedAccessGrantAuthorizations`.
165
+ */
166
+ export declare function requireAccountAdminAuthorizationStamp(authorization: AccessGrantAuthorization): AccountAdminAuthorizationStamp;
167
+ /**
168
+ * Verify that an access authorization was minted by the canonical request
169
+ * resolver for this exact subject and workspace.
170
+ *
171
+ * This is the protocol-neutral boundary for request-local services that need
172
+ * the authenticated grant rather than a caller-supplied grant-shaped object.
173
+ * Object identity is intentional: matching fields alone are not proof that the
174
+ * request authenticated the named subject.
175
+ */
176
+ export declare function requireResolvedAccessGrantAuthorization(authorization: AccessGrantAuthorization, workspaceId: string): AccessGrant;
177
+ /**
178
+ * Resolve the exact built-in single-user local administrator for an account.
179
+ *
180
+ * This is intentionally narrower than checking `context.mode === "local"` or
181
+ * the `dev` subject name. Only the in-process local bootstrap branch can place
182
+ * the resolved context in `canonicalLocalHumanContexts`, so delegated bearer
183
+ * tokens and caller-constructed contexts cannot borrow this authority.
184
+ */
185
+ export declare function requireCanonicalLocalAccountAdministrator(c: Context, deps: AccessDeps, accountId: string): Promise<{
186
+ subjectId: string;
187
+ authorization: AccessGrantAuthorization;
188
+ }>;
20
189
  export declare function requireAccessGrantAuthorization(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrantAuthorization>;
190
+ /**
191
+ * Settings administration is narrower than workspace administration. The
192
+ * verified owning user may configure their Personal workspace, but
193
+ * never acquires the admin wildcard (and its membership/delegation powers).
194
+ * Delegated owners also need workspace:admin in their verified dispatch/key
195
+ * ceiling: a read-only delegation cannot turn ownership into a settings write.
196
+ * Only use this boundary for workspace configuration, not access management.
197
+ */
198
+ export declare function requireWorkspaceSettingsGrant(c: Context, deps: AccessDeps, workspaceId: string): Promise<AccessGrant>;
21
199
  export declare function requirePermission(grant: AccessGrant, permission: Permission): void;
22
200
  /**
23
201
  * Require a permission to be present literally on the grant. This deliberately
@@ -26,5 +204,6 @@ export declare function requirePermission(grant: AccessGrant, permission: Permis
26
204
  * acquire implicitly.
27
205
  */
28
206
  export declare function requireLiteralPermission(grant: AccessGrant, permission: Permission): void;
29
- export declare function hasLiteralPermission(permissions: Permission[], permission: Permission): boolean;
30
- export declare function hasPermission(permissions: Permission[], permission: Permission): boolean;
207
+ export declare function hasLiteralPermission(permissions: readonly Permission[], permission: Permission): boolean;
208
+ export declare function hasPermission(permissions: readonly Permission[], permission: Permission, permissionMode?: AccessGrant["permissionMode"]): boolean;
209
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type AccessGrant } from "@opengeni/contracts";
2
+ /** Validated provenance only. The API key remains the authenticated principal. */
3
+ export declare function serviceInitiatorFromHeaders(headers: Headers): Pick<AccessGrant, "serviceInitiator" | "serviceInitiatorContext"> | null;
@@ -0,0 +1,20 @@
1
+ import { type IntegrationInvocationAuthority } from "@opengeni/capabilities";
2
+ import type { Settings } from "@opengeni/config";
3
+ import type { ToolAuthNeededPayload } from "@opengeni/contracts";
4
+ import type { ApiIntegrationRuntime, ResolveConnectionCredentialInput, ResolveConnectionCredentialResult } from "@opengeni/db";
5
+ import type { FetchLike } from "@opengeni/network";
6
+ import type { LocalMcpServerRegistration } from "@opengeni/runtime";
7
+ export type BuildApiIntegrationServersInput = {
8
+ settings: Settings;
9
+ integrations: readonly ApiIntegrationRuntime[];
10
+ authority: Omit<IntegrationInvocationAuthority, "connectionRef">;
11
+ resolveCredential: (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
12
+ onAuthNeeded?: (payload: ToolAuthNeededPayload) => Promise<void> | void;
13
+ fetchImpl?: FetchLike;
14
+ };
15
+ /**
16
+ * Compile active persisted API facets into ordinary in-process MCP providers.
17
+ * The caller supplies its authority resolver, so agent attempts and current
18
+ * humans use the same provider assembly without sharing credentials or policy.
19
+ */
20
+ export declare function buildApiIntegrationMcpServers(input: BuildApiIntegrationServersInput): LocalMcpServerRegistration[];
@@ -0,0 +1,6 @@
1
+ import { AppendArchivedSessionEventsResponse, ImportArchivedSessionResponse } from "@opengeni/contracts";
2
+ import { type AccessGrantAuthorization } from "../access/index.js";
3
+ import type { ApiRouteDeps } from "../dependencies.js";
4
+ export { ArchivedSessionImportError } from "@opengeni/db";
5
+ export declare function importArchivedSessionForRequest(deps: ApiRouteDeps, authorization: AccessGrantAuthorization, workspaceId: string, rawPayload: unknown): Promise<ImportArchivedSessionResponse>;
6
+ export declare function appendArchivedSessionEventsForRequest(deps: ApiRouteDeps, authorization: AccessGrantAuthorization, workspaceId: string, importId: string, rawPayload: unknown): Promise<AppendArchivedSessionEventsResponse>;
@@ -0,0 +1,24 @@
1
+ import type { AccessGrant, ResourceRef, SubmitComposerDraftRequest, SubmitComposerDraftResponse } from "@opengeni/contracts";
2
+ import type { AccessGrantAuthorization } from "../access/index.js";
3
+ import type { AcceptSessionUserMessageDependencies } from "../dependencies.js";
4
+ export type SubmitComposerDraftForRequestOptions = {
5
+ authorization?: AccessGrantAuthorization | undefined;
6
+ /**
7
+ * Trusted host-owned resources admitted with this command without writing
8
+ * them into the actor's browser-visible draft first. The saved draft remains
9
+ * the exact content fence for actor-owned text, annotations, resources, and
10
+ * execution policy; these resources participate in the accepted command's
11
+ * idempotency hash, validation, turn, and durable session resource set.
12
+ */
13
+ additionalResources?: ResourceRef[] | undefined;
14
+ };
15
+ /**
16
+ * Atomically accept one established-session composer draft.
17
+ *
18
+ * This is the application boundary shared by the stock HTTP adapter and an
19
+ * in-process embedding host. A host may prepare its own durable business state
20
+ * before calling this function and project the returned receipt afterward, but
21
+ * OpenGeni remains the sole authority for draft validation/rotation, event
22
+ * append, turn creation, routing, and idempotent replay.
23
+ */
24
+ export declare function submitComposerDraftForRequest(deps: AcceptSessionUserMessageDependencies, grant: AccessGrant, workspaceId: string, sessionId: string, input: SubmitComposerDraftRequest, options?: SubmitComposerDraftForRequestOptions): Promise<SubmitComposerDraftResponse>;
@@ -0,0 +1,13 @@
1
+ import type { Permission } from "@opengeni/contracts";
2
+ import type { ExternalActorContinuation } from "@opengeni/contracts/external-identities";
3
+ import { type Database } from "@opengeni/db";
4
+ /** Accept only a verified request owner or authenticated server-minted OAuth
5
+ * state. The callback does not need a browser cookie: it rechecks the stored
6
+ * principal against current authority before claiming and committing effects. */
7
+ export declare function requireConnectOwnerAuthority(db: Database, state: {
8
+ accountId: string;
9
+ workspaceId: string;
10
+ subjectId: string;
11
+ personalOwnerVerified?: boolean;
12
+ externalContinuation?: ExternalActorContinuation;
13
+ }, permission?: Permission, origin?: ExternalActorContinuation | null): Promise<void>;
@@ -0,0 +1,31 @@
1
+ import type { ConnectAttempt } from "@opengeni/contracts/connect";
2
+ import { type ConnectActorScope, type ConnectOperationAuthorization, type Database } from "@opengeni/db";
3
+ /** Provider result is deliberately not serializable: secrets can remain in its
4
+ * closure until encrypted credential persistence. Do not retain/log this value. */
5
+ export type PreparedConnectOperation = {
6
+ commit: (tx: Database, current: ConnectAttempt) => Promise<ConnectAttempt>;
7
+ };
8
+ /** Internal provider-adapter boundary, not an HTTP authentication adapter.
9
+ *
10
+ * authorize is mandatory, including for a receipt replay. It must validate the
11
+ * exact saved key/actor/link authority and current permission under database
12
+ * locks. execute owns provider-specific proof, destination and cancellation.
13
+ * No remote effects may occur inside authorize or commit.
14
+ *
15
+ * A failed execute/authorization/commit keeps the durable claim occupied. It
16
+ * does not release or retry work whose provider outcome may be unknown.
17
+ */
18
+ export declare function executeConnectOperation(input: {
19
+ db: Database;
20
+ scope: ConnectActorScope;
21
+ attemptId: string;
22
+ expectedRevision: number;
23
+ operationId: string;
24
+ /** Caller computes a stable keyed digest if input contains low-entropy secrets. */
25
+ inputDigest: string;
26
+ /** Trusted server adapter classification, never derived from request data.
27
+ * Cancellation releases pending setup; it acquires no integration authority. */
28
+ purpose?: "acquisition" | "cancellation";
29
+ authorize: ConnectOperationAuthorization;
30
+ execute: (attempt: ConnectAttempt) => Promise<PreparedConnectOperation>;
31
+ }): Promise<ConnectAttempt>;
@@ -0,0 +1,15 @@
1
+ import type { Permission } from "@opengeni/contracts";
2
+ import { type Database } from "@opengeni/db";
3
+ import { type AccessGrantAuthorization } from "../access/index.js";
4
+ /** Capture verified request authority before asynchronous preflight. Invoke
5
+ * inside the canonical mutation transaction after its lifecycle locks, so a
6
+ * revoked key/generation rolls the write back without changing lock order. */
7
+ export declare function externalContinuationCommitAuthorizer(authorization: AccessGrantAuthorization | undefined): ((tx: Database) => Promise<void>) | undefined;
8
+ /** Caller verifies/decrypts its server-minted continuation before invoking.
9
+ * An open transaction retains lifecycle/key/identity locks through persistence.
10
+ * Historical creator audit alone must never enter this path as a credential. */
11
+ export declare function requireExternalContinuationAuthority(tx: Database, raw: unknown, scope: {
12
+ accountId: string;
13
+ workspaceId: string;
14
+ subjectId: string;
15
+ }, permission: Permission | readonly Permission[]): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import type { Context } from "hono";
2
+ import { type AccessDeps } from "../access/index.js";
3
+ /** Host service administration is separate from asUser and native-cookie
4
+ * administration. The database rechecks the live key and exact external target
5
+ * under the canonical organization lifecycle fences, including receipt replay. */
6
+ export declare function updateExternalIdentityMembershipForRequest(context: Context, deps: AccessDeps, organizationId: string, membershipId: string, input: unknown): Promise<{
7
+ id: string;
8
+ organizationId: string;
9
+ subjectId: string;
10
+ name: string | null;
11
+ email: string | null;
12
+ role: "admin" | "member" | "owner";
13
+ status: "active" | "provisioning" | "revoked" | "suspended";
14
+ authorizationRevision: number;
15
+ personalWorkspaceId: string | null;
16
+ revokedAt: string | null;
17
+ personalRetentionUntil: string | null;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ }>;
@@ -0,0 +1,12 @@
1
+ import type { ScheduledTask } from "@opengeni/contracts";
2
+ import { type Database } from "@opengeni/db";
3
+ import { type AccessGrantAuthorization } from "../access/index.js";
4
+ /** Closure is created only from the access resolver's object-identity proof.
5
+ * JSON metadata and an ordinary named native subject can never enter it. */
6
+ export declare function prepareExternalLinkTurnAdmission(authorization: AccessGrantAuthorization | undefined): ((tx: Database, sessionId: string, turnId: string) => Promise<void>) | undefined;
7
+ export declare function prepareExternalLinkTaskAdmission(authorization: AccessGrantAuthorization | undefined, actor?: {
8
+ sessionId: string;
9
+ turnId: string;
10
+ attemptId: string;
11
+ executionGeneration: number;
12
+ } | null): ((tx: Database, task: ScheduledTask) => Promise<void>) | undefined;
@@ -0,0 +1,34 @@
1
+ import type { Context } from "hono";
2
+ import { type ExternalIdentity } from "@opengeni/contracts/external-identities";
3
+ import { type AccessDeps } from "../access/index.js";
4
+ /** Explicit host onboarding. Ordinary asUser requests never call this
5
+ * operation; their first-use membership is `provisionExternalMemberOnFirstUse`
6
+ * in `../access`, under the same key authority and lifecycle fence.
7
+ * Existing memberships are not overwritten, including reduced permissions. */
8
+ export declare function addExternalWorkspaceMemberForRequest(c: Context, deps: AccessDeps, workspaceId: string, input: unknown): Promise<ExternalIdentity>;
9
+ export declare function lookupExternalIdentityForRequest(c: Context, deps: AccessDeps, organizationId: string, input: unknown): Promise<{
10
+ found: false;
11
+ } | {
12
+ found: true;
13
+ subjectId: string;
14
+ organizationMembershipId: string;
15
+ identityStatus: "active" | "disabled" | "revoked";
16
+ identityAuthorizationRevision: number;
17
+ membershipStatus: "active" | "provisioning" | "revoked" | "suspended";
18
+ membershipAuthorizationRevision: number;
19
+ }>;
20
+ export declare function cancelExternalWorkspaceMemberGrantForRequest(c: Context, deps: AccessDeps, organizationId: string, workspaceId: string, membershipId: string, input: unknown): Promise<{
21
+ removed: boolean;
22
+ replay: boolean;
23
+ fencedGrantOperationId: string;
24
+ }>;
25
+ /** Keyed permission change for an existing external member. Widening only
26
+ * rewrites the set; narrowing also advances the member's authorization
27
+ * revision so live authority re-checks. Never cancels or tears down work. */
28
+ export declare function updateExternalWorkspaceMemberForRequest(c: Context, deps: AccessDeps, organizationId: string, workspaceId: string, membershipId: string, input: unknown): Promise<{
29
+ subjectId: string;
30
+ organizationMembershipId: string;
31
+ permissions: ("account:admin" | "account:read" | "api_keys:manage" | "artifacts:publish" | "artifacts:read" | "billing:manage" | "billing:read" | "capabilities:manage" | "codemode:call" | "connections:read" | "connections:write" | "documents:manage" | "documents:search" | "enrollments:manage" | "enrollments:read" | "environments:manage" | "environments:use" | "files:read" | "files:upload" | "files:write" | "github:manage" | "github:use" | "goals:manage" | "mcp_servers:attach" | "members:manage" | "rigs:manage" | "rigs:use" | "scheduled_tasks:manage" | "scheduled_tasks:run" | "secrets:list" | "secrets:read" | "secrets:write" | "sessions:control" | "sessions:create" | "sessions:read" | "stream:acknowledge" | "stream:control" | "stream:view" | "terminal:attach" | "usage_allowances:manage" | "variable-sets:attach" | "variable-sets:list" | "variable-sets:manage" | "variable-sets:read" | "variable-sets:use" | "variable-sets:write" | "workspace:admin" | "workspace:create" | "workspace:read")[];
32
+ narrowed: boolean;
33
+ replay: boolean;
34
+ }>;