@opengeni/core 0.28.1 → 1.0.2-canary.37191796234001

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 (222) 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 +176 -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 +32 -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/native-mcp-connection-admission.d.ts +3 -0
  70. package/dist/domain/organization-integration-catalog.d.ts +15 -0
  71. package/dist/domain/organization-membership-lifecycle.d.ts +1 -0
  72. package/dist/domain/personal-connection-delegations.d.ts +85 -4
  73. package/dist/domain/pr-review.d.ts +249 -0
  74. package/dist/domain/resources.d.ts +24 -3
  75. package/dist/domain/scheduled-task-access.d.ts +247 -0
  76. package/dist/domain/scheduled-tasks.d.ts +103 -6
  77. package/dist/domain/session-connection-accounts.d.ts +16 -0
  78. package/dist/domain/session-file-access.d.ts +4 -0
  79. package/dist/domain/session-native-connection-replacement.d.ts +14 -0
  80. package/dist/domain/session-start-timing.d.ts +7 -0
  81. package/dist/domain/session-tool-policy.d.ts +93 -4
  82. package/dist/domain/sessions.d.ts +275 -28
  83. package/dist/domain/skill-imports.d.ts +1 -0
  84. package/dist/domain/skill-search.d.ts +30 -0
  85. package/dist/domain/skills.d.ts +117 -0
  86. package/dist/domain/slack-bot.d.ts +46 -1
  87. package/dist/domain/workspace-members.d.ts +8 -1
  88. package/dist/editable-artifact-live/application.d.ts +12 -3
  89. package/dist/editable-artifact-live/ports.d.ts +0 -1
  90. package/dist/editable-artifact-live/server.d.ts +5 -2
  91. package/dist/editable-artifact-live/ticket.d.ts +2 -2
  92. package/dist/editable-artifact-live/types.d.ts +14 -2
  93. package/dist/editable-artifact-live.js +2 -2
  94. package/dist/editable-artifacts.js +10 -4
  95. package/dist/index.d.ts +48 -3
  96. package/dist/index.js +18665 -6827
  97. package/dist/index.js.map +1 -1
  98. package/dist/managed-auth-session-sets.d.ts +131 -0
  99. package/dist/managed-auth-session-sets.js +51 -0
  100. package/dist/managed-auth-session-sets.js.map +1 -0
  101. package/dist/managed-session.d.ts +98 -11
  102. package/dist/model-catalog.d.ts +117 -0
  103. package/dist/product-usage-metrics.d.ts +30 -0
  104. package/dist/rigs/index.d.ts +22 -5
  105. package/dist/rigs/provider-images.d.ts +1 -1
  106. package/dist/sandbox/fleet.d.ts +59 -10
  107. package/dist/sandbox/routing.d.ts +22 -2
  108. package/dist/sandbox/runtime-settings.d.ts +56 -0
  109. package/dist/session-authorization.d.ts +38 -1
  110. package/dist/site-session-origin.d.ts +9 -0
  111. package/dist/transcription.d.ts +12 -1
  112. package/dist/turn-surface.d.ts +18 -0
  113. package/dist/user-presence.d.ts +32 -0
  114. package/package.json +18 -11
  115. package/src/access/external-actor-authority.ts +94 -0
  116. package/src/access/index.ts +1274 -44
  117. package/src/access/service-initiator.ts +50 -0
  118. package/src/application/api-integration-servers.ts +215 -0
  119. package/src/application/archived-session-imports.ts +161 -0
  120. package/src/application/composer-submit.ts +77 -0
  121. package/src/application/connect-authority.ts +77 -0
  122. package/src/application/connect-operation.ts +80 -0
  123. package/src/application/external-continuation.ts +129 -0
  124. package/src/application/external-identity-lifecycle.ts +48 -0
  125. package/src/application/external-link-work-admission.ts +90 -0
  126. package/src/application/external-workspace-members.ts +230 -0
  127. package/src/application/modal-native-worker-host-transport.ts +263 -0
  128. package/src/application/new-session-drafts.ts +222 -29
  129. package/src/application/sandbox-recovery.ts +78 -0
  130. package/src/application/session-commands.ts +430 -73
  131. package/src/application/session-mcp-credential-rotation.ts +217 -0
  132. package/src/application/session-tenancy.ts +445 -0
  133. package/src/application/user-resource-grants.ts +154 -0
  134. package/src/billing/limits.ts +102 -23
  135. package/src/canonical-human-identities.ts +22 -3
  136. package/src/codex-model-availability.ts +136 -0
  137. package/src/default-session-model.ts +656 -0
  138. package/src/dependencies.ts +97 -5
  139. package/src/developer-setup-credential-ceiling.ts +60 -0
  140. package/src/domain/agent-config-resolution.ts +148 -0
  141. package/src/domain/automations.ts +270 -0
  142. package/src/domain/capabilities.ts +237 -144
  143. package/src/domain/company-profile-agent-admin.ts +56 -0
  144. package/src/domain/connection-account-selection-error.ts +19 -0
  145. package/src/domain/connector-tool-permissions.ts +371 -0
  146. package/src/domain/direct-model-provider.ts +62 -0
  147. package/src/domain/editable-artifacts/agent-application.ts +61 -15
  148. package/src/domain/editable-artifacts/durable-export.ts +100 -5
  149. package/src/domain/editable-artifacts/in-memory.ts +6 -0
  150. package/src/domain/editable-artifacts/ports.ts +11 -0
  151. package/src/domain/editable-artifacts/service.ts +32 -1
  152. package/src/domain/editable-artifacts/snapshot-compaction.ts +9 -5
  153. package/src/domain/editable-artifacts/snapshot-verifier-genesis.ts +10 -8
  154. package/src/domain/editable-artifacts/snapshot-verifier.ts +10 -3
  155. package/src/domain/environments.ts +25 -45
  156. package/src/domain/external-creation-attribution.ts +22 -0
  157. package/src/domain/file-owner.ts +67 -0
  158. package/src/domain/github-action-policies.ts +169 -0
  159. package/src/domain/github-repository-bindings.ts +295 -0
  160. package/src/domain/github-skill-source.ts +233 -0
  161. package/src/domain/governed-learning-slack-publication.ts +157 -0
  162. package/src/domain/insights-timing.ts +95 -0
  163. package/src/domain/insights-usage.ts +67 -0
  164. package/src/domain/insights.ts +270 -169
  165. package/src/domain/knowledge-files.ts +46 -0
  166. package/src/domain/knowledge-messages.test.ts +91 -0
  167. package/src/domain/knowledge-messages.ts +106 -0
  168. package/src/domain/knowledge-preparation.test.ts +276 -0
  169. package/src/domain/knowledge-preparation.ts +147 -0
  170. package/src/domain/knowledge-search.test.ts +561 -0
  171. package/src/domain/knowledge-search.ts +256 -0
  172. package/src/domain/knowledge.ts +133 -0
  173. package/src/domain/mcp-account-bindings.ts +180 -0
  174. package/src/domain/native-mcp-connection-admission.ts +14 -0
  175. package/src/domain/organization-integration-catalog.ts +88 -0
  176. package/src/domain/organization-membership-lifecycle.ts +10 -0
  177. package/src/domain/personal-connection-delegations.ts +756 -115
  178. package/src/domain/pr-review.ts +687 -0
  179. package/src/domain/resources.ts +182 -25
  180. package/src/domain/scheduled-task-access.ts +1052 -0
  181. package/src/domain/scheduled-tasks.ts +1951 -214
  182. package/src/domain/session-connection-accounts.ts +67 -0
  183. package/src/domain/session-file-access.ts +47 -0
  184. package/src/domain/session-native-connection-replacement.ts +64 -0
  185. package/src/domain/session-start-timing.ts +55 -0
  186. package/src/domain/session-tool-policy.ts +443 -19
  187. package/src/domain/sessions.ts +3416 -618
  188. package/src/domain/skill-imports.ts +137 -17
  189. package/src/domain/skill-search.ts +221 -0
  190. package/src/domain/skills.ts +104 -0
  191. package/src/domain/slack-bot.ts +126 -1
  192. package/src/domain/workspace-members.ts +34 -2
  193. package/src/editable-artifact-live/application.ts +29 -4
  194. package/src/editable-artifact-live/ports.ts +0 -1
  195. package/src/editable-artifact-live/server.ts +167 -13
  196. package/src/editable-artifact-live/ticket.ts +87 -6
  197. package/src/editable-artifact-live/types.ts +16 -2
  198. package/src/editable-artifact-live/wire.ts +0 -10
  199. package/src/index.ts +68 -4
  200. package/src/managed-auth-session-sets.ts +371 -0
  201. package/src/managed-session.ts +520 -2
  202. package/src/model-catalog.ts +873 -0
  203. package/src/product-usage-metrics.ts +101 -0
  204. package/src/rigs/index.ts +179 -63
  205. package/src/rigs/provider-images.ts +2 -3
  206. package/src/sandbox/fleet.ts +471 -59
  207. package/src/sandbox/routing.ts +160 -33
  208. package/src/sandbox/runtime-settings.ts +281 -0
  209. package/src/session-authorization.ts +262 -78
  210. package/src/site-session-origin.ts +22 -0
  211. package/src/transcription.ts +13 -1
  212. package/src/turn-surface.ts +45 -0
  213. package/src/user-presence.ts +134 -0
  214. package/dist/chunk-6WKPWE5S.js.map +0 -1
  215. package/dist/chunk-IBOEYG6N.js +0 -34
  216. package/dist/chunk-IBOEYG6N.js.map +0 -1
  217. package/dist/chunk-JJU6I5XD.js.map +0 -1
  218. package/dist/chunk-NYPMQ7NO.js.map +0 -1
  219. package/dist/domain/durable-learning-slack-publication.d.ts +0 -72
  220. package/dist/domain/packs.d.ts +0 -55
  221. package/src/domain/durable-learning-slack-publication.ts +0 -202
  222. 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,195 @@
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
+ /** Creation audit only, never an authentication or delegation token. Metadata
77
+ * claiming to be external is insufficient; the exact resolver proof is needed. */
78
+ export declare function externalAttributionForAuthorization(authorization: AccessGrantAuthorization | undefined, grant: AccessGrant): ExternalActorAttribution | null;
79
+ export declare function externalActorContinuationForAuthorization(authorization: AccessGrantAuthorization): ExternalActorContinuation | null;
80
+ /** Dedicated owning-user proof. External/OAuth admission never sets the native
81
+ * cookie stamp. The resource/session layer still checks the exact owner. */
82
+ export declare function hasVerifiedOwningUserAuthorization(authorization: AccessGrantAuthorization): boolean;
83
+ /** Request-local organization service-key proof, not a principal-kind claim. */
84
+ export declare function isVerifiedOrganizationServiceAuthorization(authorization: AccessGrantAuthorization): boolean;
85
+ export type AccountScopedApiKeyWorkspaceAuthority = Readonly<{
86
+ accountId: string;
87
+ permissions: Permission[];
88
+ workspaceScope: OrganizationWorkspaceScope;
89
+ permissionMode: "legacy" | "explicit";
90
+ }>;
91
+ export declare function organizationWorkspaceInScope(scope: OrganizationWorkspaceScope, workspaceId: string): boolean;
92
+ /**
93
+ * Return account-scoped API-key workspace authority only for the exact
94
+ * AccessContext object stamped by successful API-key authentication. Subject
95
+ * shape alone is deliberately insufficient.
96
+ */
97
+ export declare function accountScopedApiKeyWorkspaceAuthority(context: AccessContext): AccountScopedApiKeyWorkspaceAuthority | null;
98
+ /** Classify stored scopes without changing the legacy full/read permission sets. */
99
+ export declare function organizationApiKeyAccess(permissions: Permission[]): OrganizationApiKeyAccess;
100
+ /**
101
+ * Opaque, request-local proof that the canonical access resolver authorized the
102
+ * exact account administrator named by the stamp. The random id is audit and
103
+ * replay provenance only; object identity is what prevents a caller from
104
+ * manufacturing this proof inside the API process.
105
+ */
106
+ export type AccountAdminAuthorizationStamp = Readonly<{
107
+ authorizationId: string;
108
+ accountId: string;
109
+ actorSubjectId: string;
110
+ permission: "account:admin";
111
+ }>;
6
112
  export type AccessDeps = {
7
113
  db: Database;
8
114
  settings: Settings;
9
115
  managedAuth?: ManagedAuth | null;
116
+ managedAuthSessionAdapter?: ManagedAuthSessionAdapter | null;
117
+ /** Analytics only: notes canonical managed-cookie activity, never authority. */
118
+ userPresence?: UserPresenceRecorder | null;
10
119
  };
120
+ /** null means this is not an authenticated external lane; [] means that lane
121
+ * has no readable inventory. Callers must not fall back from [] to service or
122
+ * bare-subject discovery. */
123
+ export declare function listExternalActorWorkspaces(context: AccessContext, deps: AccessDeps): Promise<Workspace[] | null>;
11
124
  export declare function requireAccessContext(c: Context, deps: AccessDeps): Promise<AccessContext>;
12
125
  export declare function requireAccessGrant(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrant>;
126
+ /**
127
+ * Re-resolve the authenticated principal and its current grants without using
128
+ * the request-local access cache. Long-lived responses use this to ensure a
129
+ * membership suspension or revocation takes effect while the connection is
130
+ * still open.
131
+ */
132
+ export declare function requireFreshAccessGrant(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrant>;
13
133
  export type AccessGrantAuthorization = {
14
134
  grant: AccessGrant;
15
135
  accountGrant: AccountGrant | null;
16
136
  authenticatedSubjectId: string;
17
137
  contextIntegrity: boolean;
138
+ /**
139
+ * Did this request authenticate as the canonical managed-cookie (Better Auth)
140
+ * session that OWNS this grant's subject? Cookie/person-present ceremonies
141
+ * retain this strict gate; owning-user boundaries use
142
+ * `hasVerifiedOwningUserAuthorization` instead.
143
+ * False for every bearer, API-key, delegated, service, local, and configured
144
+ * principal, and for any future path that does not verify a cookie.
145
+ */
146
+ canonicalManagedHumanSession: boolean;
147
+ /** Exact in-process single-user local bootstrap, never a delegated bearer. */
148
+ canonicalLocalHumanSession: boolean;
18
149
  };
19
150
  export declare function accessGrantAuthorizationFromContext(context: AccessContext, grant: AccessGrant): AccessGrantAuthorization;
151
+ /**
152
+ * Mint the capability passed to an account-admin database lifecycle.
153
+ *
154
+ * This deliberately accepts every canonical access mode (managed,
155
+ * local/configured, and signed delegation). Organization-membership rows are
156
+ * one possible source of account authority, not the definition of it. A plain
157
+ * object with matching fields is rejected because only values returned by the
158
+ * access resolver are present in `resolvedAccessGrantAuthorizations`.
159
+ */
160
+ export declare function requireAccountAdminAuthorizationStamp(authorization: AccessGrantAuthorization): AccountAdminAuthorizationStamp;
161
+ /**
162
+ * Verify that an access authorization was minted by the canonical request
163
+ * resolver for this exact subject and workspace.
164
+ *
165
+ * This is the protocol-neutral boundary for request-local services that need
166
+ * the authenticated grant rather than a caller-supplied grant-shaped object.
167
+ * Object identity is intentional: matching fields alone are not proof that the
168
+ * request authenticated the named subject.
169
+ */
170
+ export declare function requireResolvedAccessGrantAuthorization(authorization: AccessGrantAuthorization, workspaceId: string): AccessGrant;
171
+ /**
172
+ * Resolve the exact built-in single-user local administrator for an account.
173
+ *
174
+ * This is intentionally narrower than checking `context.mode === "local"` or
175
+ * the `dev` subject name. Only the in-process local bootstrap branch can place
176
+ * the resolved context in `canonicalLocalHumanContexts`, so delegated bearer
177
+ * tokens and caller-constructed contexts cannot borrow this authority.
178
+ */
179
+ export declare function requireCanonicalLocalAccountAdministrator(c: Context, deps: AccessDeps, accountId: string): Promise<{
180
+ subjectId: string;
181
+ authorization: AccessGrantAuthorization;
182
+ }>;
20
183
  export declare function requireAccessGrantAuthorization(c: Context, deps: AccessDeps, workspaceId: string, permission?: Permission): Promise<AccessGrantAuthorization>;
184
+ /**
185
+ * Settings administration is narrower than workspace administration. The
186
+ * verified owning user may configure their Personal workspace, but
187
+ * never acquires the admin wildcard (and its membership/delegation powers).
188
+ * Delegated owners also need workspace:admin in their verified dispatch/key
189
+ * ceiling: a read-only delegation cannot turn ownership into a settings write.
190
+ * Only use this boundary for workspace configuration, not access management.
191
+ */
192
+ export declare function requireWorkspaceSettingsGrant(c: Context, deps: AccessDeps, workspaceId: string): Promise<AccessGrant>;
21
193
  export declare function requirePermission(grant: AccessGrant, permission: Permission): void;
22
194
  /**
23
195
  * Require a permission to be present literally on the grant. This deliberately
@@ -26,5 +198,6 @@ export declare function requirePermission(grant: AccessGrant, permission: Permis
26
198
  * acquire implicitly.
27
199
  */
28
200
  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;
201
+ export declare function hasLiteralPermission(permissions: readonly Permission[], permission: Permission): boolean;
202
+ export declare function hasPermission(permissions: readonly Permission[], permission: Permission, permissionMode?: AccessGrant["permissionMode"]): boolean;
203
+ 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,32 @@
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 reads never call this operation.
5
+ * Existing memberships are not overwritten, including reduced permissions. */
6
+ export declare function addExternalWorkspaceMemberForRequest(c: Context, deps: AccessDeps, workspaceId: string, input: unknown): Promise<ExternalIdentity>;
7
+ export declare function lookupExternalIdentityForRequest(c: Context, deps: AccessDeps, organizationId: string, input: unknown): Promise<{
8
+ found: false;
9
+ } | {
10
+ found: true;
11
+ subjectId: string;
12
+ organizationMembershipId: string;
13
+ identityStatus: "active" | "disabled" | "revoked";
14
+ identityAuthorizationRevision: number;
15
+ membershipStatus: "active" | "provisioning" | "revoked" | "suspended";
16
+ membershipAuthorizationRevision: number;
17
+ }>;
18
+ export declare function cancelExternalWorkspaceMemberGrantForRequest(c: Context, deps: AccessDeps, organizationId: string, workspaceId: string, membershipId: string, input: unknown): Promise<{
19
+ removed: boolean;
20
+ replay: boolean;
21
+ fencedGrantOperationId: string;
22
+ }>;
23
+ /** Keyed permission change for an existing external member. Widening only
24
+ * rewrites the set; narrowing also advances the member's authorization
25
+ * revision so live authority re-checks. Never cancels or tears down work. */
26
+ export declare function updateExternalWorkspaceMemberForRequest(c: Context, deps: AccessDeps, organizationId: string, workspaceId: string, membershipId: string, input: unknown): Promise<{
27
+ subjectId: string;
28
+ organizationMembershipId: string;
29
+ 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")[];
30
+ narrowed: boolean;
31
+ replay: boolean;
32
+ }>;