@opengeni/db 4.2.2 → 4.3.0-canary.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 (102) hide show
  1. package/dist/canonical-human-identities.js +3 -3
  2. package/dist/{chunk-6GAPAYZR.js → chunk-7JPLGBSA.js} +562 -86
  3. package/dist/chunk-7JPLGBSA.js.map +1 -0
  4. package/dist/{chunk-SNLIKELL.js → chunk-IHADTE7C.js} +2 -2
  5. package/dist/{chunk-7WX3R3YL.js → chunk-ILKJKDII.js} +7 -2
  6. package/dist/chunk-ILKJKDII.js.map +1 -0
  7. package/dist/{chunk-MGVOYVPS.js → chunk-NCSPNCQK.js} +3 -3
  8. package/dist/{chunk-B2KR3TEM.js → chunk-SGJDIF2D.js} +2 -2
  9. package/dist/{chunk-S4Y42VSX.js → chunk-Y5XFVJJM.js} +207 -3
  10. package/dist/chunk-Y5XFVJJM.js.map +1 -0
  11. package/dist/{chunk-FPTI4NP4.js → chunk-YGBOVXC7.js} +2 -2
  12. package/dist/{chunk-6Y7ZDVJ5.js → chunk-YGRT6VZO.js} +2 -2
  13. package/dist/{chunk-6IQ4X35Y.js → chunk-YVYBAWBU.js} +46 -1
  14. package/dist/chunk-YVYBAWBU.js.map +1 -0
  15. package/dist/connect-attempts.d.ts +60 -0
  16. package/dist/connection-setup-authority.d.ts +10 -0
  17. package/dist/connection-token-resolver.d.ts +11 -2
  18. package/dist/editable-artifact-durable-export.js +2 -2
  19. package/dist/editable-artifacts.js +3 -3
  20. package/dist/external-identities.d.ts +16 -0
  21. package/dist/external-identity-links.d.ts +74 -0
  22. package/dist/external-link-work.d.ts +51 -0
  23. package/dist/host-mcp-binding-match.d.ts +5 -0
  24. package/dist/host-mcp-bindings.d.ts +73 -0
  25. package/dist/host-mcp-task-authority.d.ts +47 -0
  26. package/dist/host-selection-identity.d.ts +6 -0
  27. package/dist/index.d.ts +51 -35
  28. package/dist/index.js +15171 -13775
  29. package/dist/index.js.map +1 -1
  30. package/dist/live-session-attempt.d.ts +275 -0
  31. package/dist/managed-auth-session-sets.js +3 -3
  32. package/dist/memory-domain.d.ts +3 -3
  33. package/dist/provision-roles.js +1 -1
  34. package/dist/retained-provider-commands.js +2 -2
  35. package/dist/runtime-posture.d.ts +6 -6
  36. package/dist/scheduled-task-revision-authority.d.ts +11 -0
  37. package/dist/schema.d.ts +1279 -9
  38. package/dist/schema.js +11 -1
  39. package/dist/session-background-commands.js +4 -4
  40. package/dist/session-command-output.js +4 -4
  41. package/dist/session-event-slices.js +2 -2
  42. package/dist/session-queue-commands.d.ts +7 -0
  43. package/dist/session-tenancy.d.ts +2 -0
  44. package/dist/session-tenancy.js +3 -3
  45. package/dist/video-generation.js +3 -3
  46. package/dist/workspace-authority.d.ts +4 -4
  47. package/dist/workspace-tool-defaults.js +4 -4
  48. package/drizzle/0437_organization_scoped_external_workspaces.sql +71 -0
  49. package/drizzle/0438_durable_connect_attempts.sql +95 -0
  50. package/drizzle/0439_external_identity_provisioning.sql +128 -0
  51. package/drizzle/0440_external_workspace_member_removal.sql +59 -0
  52. package/drizzle/0441_external_identity_membership_lifecycle.sql +163 -0
  53. package/drizzle/0442_external_owning_user_authority.sql +81 -0
  54. package/drizzle/0443_host_mcp_binding_registry.sql +93 -0
  55. package/drizzle/0444_host_mcp_delegations.sql +129 -0
  56. package/drizzle/0445_host_mcp_turn_authorities.sql +145 -0
  57. package/drizzle/0446_host_mcp_causal_continuation.sql +126 -0
  58. package/drizzle/0447_host_mcp_task_authorities.sql +264 -0
  59. package/drizzle/0448_host_mcp_child_authority.sql +115 -0
  60. package/drizzle/0449_external_identity_link_lifecycle.sql +107 -0
  61. package/drizzle/0450_external_identity_link_work.sql +179 -0
  62. package/drizzle/0451_external_link_preview_and_permission_ceiling.sql +82 -0
  63. package/drizzle/0452_external_link_scheduled_origin.sql +34 -0
  64. package/drizzle/0453_host_mcp_native_owner.sql +35 -0
  65. package/drizzle/0454_connect_origin_authority.sql +42 -0
  66. package/drizzle/0455_external_link_inventory_labels.sql +44 -0
  67. package/drizzle/0456_social_connection_versions.sql +14 -0
  68. package/drizzle/0457_canonical_session_scope_subject.sql +46 -0
  69. package/drizzle/0458_skill_review_wire_compatibility.sql +36 -0
  70. package/package.json +6 -6
  71. package/src/connect-attempts.ts +317 -0
  72. package/src/connection-authority.ts +9 -0
  73. package/src/connection-setup-authority.ts +35 -0
  74. package/src/connection-token-resolver.ts +177 -48
  75. package/src/external-identities.ts +70 -0
  76. package/src/external-identity-links.ts +364 -0
  77. package/src/external-link-work.ts +228 -0
  78. package/src/host-mcp-binding-match.ts +33 -0
  79. package/src/host-mcp-bindings.ts +741 -0
  80. package/src/host-mcp-task-authority.ts +383 -0
  81. package/src/host-selection-identity.ts +29 -0
  82. package/src/index.ts +398 -147
  83. package/src/live-session-attempt.ts +85 -0
  84. package/src/managed-human-provisioning.ts +6 -1
  85. package/src/memory-domain.ts +6 -11
  86. package/src/provision-roles.ts +3 -0
  87. package/src/runtime-posture.ts +47 -0
  88. package/src/scheduled-task-revision-authority.ts +30 -0
  89. package/src/schema.ts +228 -3
  90. package/src/session-control.ts +14 -0
  91. package/src/session-queue-commands.ts +11 -0
  92. package/src/session-tenancy.ts +7 -0
  93. package/src/workspace-authority.ts +5 -5
  94. package/dist/chunk-6GAPAYZR.js.map +0 -1
  95. package/dist/chunk-6IQ4X35Y.js.map +0 -1
  96. package/dist/chunk-7WX3R3YL.js.map +0 -1
  97. package/dist/chunk-S4Y42VSX.js.map +0 -1
  98. /package/dist/{chunk-SNLIKELL.js.map → chunk-IHADTE7C.js.map} +0 -0
  99. /package/dist/{chunk-MGVOYVPS.js.map → chunk-NCSPNCQK.js.map} +0 -0
  100. /package/dist/{chunk-B2KR3TEM.js.map → chunk-SGJDIF2D.js.map} +0 -0
  101. /package/dist/{chunk-FPTI4NP4.js.map → chunk-YGBOVXC7.js.map} +0 -0
  102. /package/dist/{chunk-6Y7ZDVJ5.js.map → chunk-YGRT6VZO.js.map} +0 -0
@@ -0,0 +1,60 @@
1
+ import { type ConnectAttempt as Attempt } from "@opengeni/contracts/connect";
2
+ import { ExternalActorContinuation } from "@opengeni/contracts/external-identities";
3
+ import { type Database } from "./database.js";
4
+ export type ConnectActorScope = {
5
+ accountId: string;
6
+ workspaceId: string;
7
+ subjectId: string;
8
+ };
9
+ /** Live admission under the attempt transaction. Implementations must acquire
10
+ * their key/membership/link fences in a consistent order and hold them through
11
+ * commit. No network I/O. The attempt argument is an isolated copy. */
12
+ export type ConnectOperationAuthorization = (tx: Database, attempt: Attempt, origin: ExternalActorContinuation | null) => Promise<void>;
13
+ export declare class ConnectAttemptConflictError extends Error {
14
+ readonly code = "CONNECT_ATTEMPT_CONFLICT";
15
+ constructor(message?: string);
16
+ }
17
+ export declare class ConnectAttemptNotFoundError extends Error {
18
+ readonly code = "CONNECT_ATTEMPT_NOT_FOUND";
19
+ constructor();
20
+ }
21
+ /** Caller must establish live workspace/actor authority before this storage
22
+ * seam. RLS scope is a consistency boundary, not proof of authentication. */
23
+ export declare function beginConnectAttempt(db: Database, scope: ConnectActorScope, input: {
24
+ idempotencyKey: string;
25
+ requestDigest: string;
26
+ returnUrl: string;
27
+ attempt: Attempt;
28
+ externalContinuation?: ExternalActorContinuation;
29
+ }): Promise<Attempt>;
30
+ export declare function getConnectAttempt(db: Database, scope: ConnectActorScope, id: string): Promise<{
31
+ attempt: Attempt;
32
+ returnUrl: string;
33
+ operationInFlight: boolean;
34
+ }>;
35
+ export declare function listPendingConnectAttempts(db: Database, scope: ConnectActorScope): Promise<Attempt[]>;
36
+ /** A claim is committed before remote effects. Never expire/reclaim it merely
37
+ * because the caller timed out: the provider may have accepted the operation. */
38
+ export declare function claimConnectOperation(db: Database, scope: ConnectActorScope, input: {
39
+ attemptId: string;
40
+ expectedRevision: number;
41
+ operationId: string;
42
+ inputDigest: string;
43
+ authorize?: ConnectOperationAuthorization;
44
+ }): Promise<{
45
+ status: "claimed";
46
+ attempt: Attempt;
47
+ } | {
48
+ status: "replayed";
49
+ attempt: Attempt;
50
+ }>;
51
+ /** Pass the same transaction to credential/installation persistence through
52
+ * commit so its receipt and the public setup result become visible atomically.
53
+ * Do not perform network effects inside commit. */
54
+ export declare function finishConnectOperation(db: Database, scope: ConnectActorScope, input: {
55
+ attemptId: string;
56
+ operationId: string;
57
+ inputDigest: string;
58
+ commit: (tx: Database, current: Attempt) => Promise<Attempt>;
59
+ authorize?: ConnectOperationAuthorization;
60
+ }): Promise<Attempt>;
@@ -0,0 +1,10 @@
1
+ import { Permission } from "@opengeni/contracts";
2
+ import { type Database } from "./database.js";
3
+ /** Callback authority for a server-signed API-key principal. No bearer is stored
4
+ * in OAuth state. Organization keys remain shared-workspace-only; workspace keys
5
+ * remain bound to their original workspace. Hold the row lock through commit. */
6
+ export declare function lockConnectionSetupKey(db: Database, input: {
7
+ accountId: string;
8
+ workspaceId: string;
9
+ subjectId: string;
10
+ }): Promise<Permission[] | null>;
@@ -1,5 +1,5 @@
1
1
  import { environmentsEncryptionKeyBytes, type McpServerConnectionRef, type Settings } from "@opengeni/config";
2
- import type { ConnectionCredentialPlacement, ConnectionKind, ConnectionCredentialsPort, ConnectionStatus, McpConnectionResourceScope, McpCredentialAuthNeededReason, McpCredentialsRequest, TurnInitiator, TurnInitiatorContext } from "@opengeni/contracts";
2
+ import type { ConnectionCredentialPlacement, ConnectionKind, ConnectionCredentialsPort, ConnectionStatus, McpConnectionResourceScope, McpCredentialAuthNeededReason, McpCredentialsRequest, McpGatewayCredentialsRequest, TurnInitiator, TurnInitiatorContext } from "@opengeni/contracts";
3
3
  import { type ConnectionUseAttribution, type ConnectionUseAuthorizationResult } from "@opengeni/contracts/connection-authority";
4
4
  import { type DnsLookup, type FetchLike } from "@opengeni/network";
5
5
  export { isPrivateAddress } from "@opengeni/network";
@@ -113,6 +113,11 @@ export type HostMcpCredentialResolverContext = {
113
113
  initiator: TurnInitiator;
114
114
  initiatorContext: TurnInitiatorContext;
115
115
  surface: McpCredentialsRequest["surface"];
116
+ /** Backend-owned attempt liveness, independent of binding delegation. */
117
+ authorizeExecution?: (request: McpCredentialsRequest) => Promise<boolean>;
118
+ /** Backend-owned live validator. Never populate from caller JSON or a host
119
+ * credential response. Omission denies every explicit durable reference. */
120
+ authorizeDurableBinding?: (request: McpCredentialsRequest) => Promise<boolean>;
116
121
  };
117
122
  export declare class HostMcpCredentialScopeError extends Error {
118
123
  constructor(field: "accountId" | "workspaceId" | "sessionId");
@@ -126,7 +131,11 @@ export declare class HostMcpCredentialBindingError extends Error {
126
131
  * reach a request; the returned object is a fresh copy so a host cannot mutate
127
132
  * headers after resolution.
128
133
  */
129
- export declare function buildHostConnectionTokenResolver(resolve: NonNullable<ConnectionCredentialsPort["mcpCredentials"]>, context: HostMcpCredentialResolverContext): (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
134
+ export declare function buildHostConnectionTokenResolver(resolve: NonNullable<ConnectionCredentialsPort["mcpCredentials"]>, suppliedContext: HostMcpCredentialResolverContext): (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
135
+ /** Authenticated request-time adapter. No synthetic session/turn authority and
136
+ * no durable binding admission; every physical use must retain live API proof. */
137
+ export declare function buildHostGatewayConnectionTokenResolver(resolve: NonNullable<ConnectionCredentialsPort["mcpGatewayCredentials"]>, suppliedContext: Pick<McpGatewayCredentialsRequest, "accountId" | "workspaceId" | "authority">, reauthorize: () => Promise<void>): (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
138
+ export declare function normalizedHostCredentialHeaders(headers: Record<string, string>, allowEmpty?: boolean): Record<string, string>;
130
139
  export type ConnectionBrokerDeps = {
131
140
  loadCredential: (db: Database, settings: Settings, input: ConnectionCredentialLookupInput) => Promise<ConnectionCredentialForBroker | null>;
132
141
  recordRefresh: (db: Database, input: ConnectionTokenRefreshInput) => Promise<boolean>;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-B2KR3TEM.js";
5
- import "./chunk-S4Y42VSX.js";
4
+ } from "./chunk-SGJDIF2D.js";
5
+ import "./chunk-Y5XFVJJM.js";
6
6
  import "./chunk-PZ5AY32C.js";
7
7
 
8
8
  // src/editable-artifact-durable-export.ts
@@ -8,9 +8,9 @@ import {
8
8
  PostgresEditableArtifactStore,
9
9
  listEditableArtifactIdsForSession,
10
10
  touchEditableArtifactSessionLink
11
- } from "./chunk-FPTI4NP4.js";
12
- import "./chunk-B2KR3TEM.js";
13
- import "./chunk-S4Y42VSX.js";
11
+ } from "./chunk-YGBOVXC7.js";
12
+ import "./chunk-SGJDIF2D.js";
13
+ import "./chunk-Y5XFVJJM.js";
14
14
  import "./chunk-PZ5AY32C.js";
15
15
  export {
16
16
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
@@ -0,0 +1,16 @@
1
+ import { Permission } from "@opengeni/contracts";
2
+ import { ExternalIdentity } from "@opengeni/contracts/external-identities";
3
+ import { type Database } from "./database.js";
4
+ /** Pass an open transaction to retain the key lock through the protected write. */
5
+ export declare function lockActiveExternalOrganizationKey(tx: Database, accountId: string, keyId: string): Promise<Permission[] | null>;
6
+ /** Transaction-local fence shared with organization member lifecycle writers.
7
+ * Caller must pass an open transaction, not a pool-level database handle. */
8
+ export declare function lockExternalWorkspaceMembershipLifecycle(tx: Database, accountId: string): Promise<void>;
9
+ /** Internal lifecycle seam. Caller must authenticate an organization key and
10
+ * establish its exact account before invoking; this does not admit HTTP users.
11
+ * It never creates shared-workspace membership or reactivates removed users. */
12
+ export declare function ensureExternalIdentity(db: Database, input: {
13
+ accountId: string;
14
+ externalId: string;
15
+ source?: string;
16
+ }): Promise<ExternalIdentity>;
@@ -0,0 +1,74 @@
1
+ import { ConfirmExternalIdentityLinkRequest, ExternalIdentityLink, ExternalIdentityLinkPage, ExternalIdentityReference, type ExternalIdentity } from "@opengeni/contracts/external-identities";
2
+ import { type Database } from "./database.js";
3
+ export declare class ExternalIdentityLinkConflictError extends Error {
4
+ readonly name = "ExternalIdentityLinkConflictError";
5
+ constructor();
6
+ }
7
+ /** Internal persistence seam. The API must prove a host external actor and
8
+ * freeze its key permission ceiling before calling. No login is provisioned. */
9
+ export declare function beginExternalIdentityLink(db: Database, identity: ExternalIdentity, raw: unknown): Promise<{
10
+ link: {
11
+ id: string;
12
+ accountId: string;
13
+ externalIdentityId: string;
14
+ externalIdentity?: {
15
+ externalId: string;
16
+ source: string;
17
+ } | undefined;
18
+ nativeSubjectId: string | null;
19
+ status: "active" | "expired" | "pending" | "revoked";
20
+ revision: number;
21
+ 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" | "variable-sets:attach" | "variable-sets:list" | "variable-sets:manage" | "variable-sets:read" | "variable-sets:use" | "variable-sets:write" | "workspace:admin" | "workspace:create" | "workspace:read")[];
22
+ expiresAt: string | null;
23
+ };
24
+ challenge: string;
25
+ confirmBefore: string;
26
+ }>;
27
+ /** Caller proves either exact host identity or native login, never a caller's
28
+ * claimed subject. The challenge is intentionally absent from every read. */
29
+ export declare function getExternalIdentityLink(db: Database, input: {
30
+ accountId: string;
31
+ linkId: string;
32
+ subjectId: string;
33
+ }): Promise<ExternalIdentityLink | null>;
34
+ /** Bounded inventory of the verified participant's links. Neither account-wide
35
+ * access nor a supplied cursor reveals another participant's pending requests. */
36
+ export declare function listExternalIdentityLinks(db: Database, input: {
37
+ accountId: string;
38
+ subjectId: string;
39
+ cursor?: string;
40
+ }): Promise<ExternalIdentityLinkPage>;
41
+ /** Consent-screen projection, only after canonical native login admission.
42
+ * The short-lived challenge proves which host request the human is approving. */
43
+ export declare function previewExternalIdentityLink(db: Database, input: {
44
+ accountId: string;
45
+ linkId: string;
46
+ challenge: string;
47
+ }): Promise<{
48
+ link: ExternalIdentityLink;
49
+ externalIdentity: ExternalIdentityReference;
50
+ } | null>;
51
+ /** Must only receive the canonical native-session subject after explicit UI
52
+ * consent. Possession of the challenge alone is not native authentication. */
53
+ export declare function confirmExternalIdentityLink(db: Database, input: {
54
+ accountId: string;
55
+ linkId: string;
56
+ nativeSubjectId: string;
57
+ request: ConfirmExternalIdentityLinkRequest;
58
+ }): Promise<ExternalIdentityLink>;
59
+ export declare function revokeExternalIdentityLink(db: Database, input: {
60
+ accountId: string;
61
+ linkId: string;
62
+ subjectId: string;
63
+ expectedRevision: number;
64
+ }): Promise<ExternalIdentityLink>;
65
+ /** Live linked admission primitive. It retains membership/link locks when
66
+ * called in an open transaction. Never uses old creator audit as authority. */
67
+ export declare function resolveExternalIdentityLink(db: Database, input: {
68
+ identity: ExternalIdentity;
69
+ linkId: string;
70
+ expectedRevision: number;
71
+ }): Promise<{
72
+ link: ExternalIdentityLink;
73
+ personalWorkspaceId: string;
74
+ } | null>;
@@ -0,0 +1,51 @@
1
+ import { type ScheduledTask } from "@opengeni/contracts";
2
+ import { ExternalLinkWorkSnapshot } from "@opengeni/contracts/external-identities";
3
+ import { type Database } from "./database.js";
4
+ type Scope = {
5
+ accountId: string;
6
+ workspaceId: string;
7
+ };
8
+ type Source = {
9
+ kind: "direct";
10
+ } | {
11
+ kind: "causal" | "child";
12
+ turnId: string;
13
+ } | {
14
+ kind: "scheduled";
15
+ taskId: string;
16
+ taskRevision: number;
17
+ };
18
+ /** Does not consult or resurrect the key used at creation. Its immutable
19
+ * permission ceiling is already captured; membership/link revocation is live. */
20
+ export declare function externalLinkWorkSnapshotIsLive(db: Database, raw: unknown): Promise<boolean>;
21
+ export declare function getExternalLinkTurnSnapshot(db: Database, scope: Scope, turnId: string): Promise<ExternalLinkWorkSnapshot | null>;
22
+ /** null is an ordinary native/external turn; a revoked linked turn is false,
23
+ * never null. Callers must not fall back to unlinked authority after denial. */
24
+ export declare function getExternalLinkTurnAuthorization(db: Database, scope: Scope, turnId: string): Promise<{
25
+ authorized: boolean;
26
+ 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" | "variable-sets:attach" | "variable-sets:list" | "variable-sets:manage" | "variable-sets:read" | "variable-sets:use" | "variable-sets:write" | "workspace:admin" | "workspace:create" | "workspace:read")[];
27
+ } | null>;
28
+ export declare function captureExternalLinkTurnAuthority(db: Database, input: Scope & {
29
+ sessionId: string;
30
+ turnId: string;
31
+ snapshot: ExternalLinkWorkSnapshot;
32
+ source?: Source;
33
+ }): Promise<void>;
34
+ export declare function inheritExternalLinkTurnAuthority(db: Database, input: Scope & {
35
+ sessionId: string;
36
+ turnId: string;
37
+ sourceTurnId: string;
38
+ kind: "causal" | "child";
39
+ }): Promise<void>;
40
+ export declare function getExternalLinkTaskSnapshot(db: Database, input: Scope & {
41
+ taskId: string;
42
+ taskRevision: number;
43
+ }): Promise<ExternalLinkWorkSnapshot | null>;
44
+ export declare function captureExternalLinkTaskAuthority(db: Database, task: ScheduledTask, raw: ExternalLinkWorkSnapshot): Promise<void>;
45
+ export declare function cloneExternalLinkTaskAuthority(db: Database, task: ScheduledTask, sourceRevision: number): Promise<void>;
46
+ export declare function captureScheduledExternalLinkTurnAuthority(db: Database, input: Scope & {
47
+ sessionId: string;
48
+ turnId: string;
49
+ runId: string;
50
+ }): Promise<void>;
51
+ export {};
@@ -0,0 +1,5 @@
1
+ import { type McpCredentialsRequest } from "@opengeni/contracts";
2
+ /** Metadata comparison only. A caller must independently establish accepted
3
+ * execution delegation and live owner/workspace authority. A matching registry
4
+ * row never authorizes a turn, a scheduler, or a nested session by itself. */
5
+ export declare function hostMcpBindingMatchesRequest(rawBinding: unknown, request: McpCredentialsRequest): boolean;
@@ -0,0 +1,73 @@
1
+ import { type McpCredentialsRequest } from "@opengeni/contracts";
2
+ import { HostMcpBinding, HostMcpDelegation, HostMcpAcceptedAuthority } from "@opengeni/contracts/host-mcp-bindings";
3
+ import { type Database } from "./database.js";
4
+ export type HostMcpBindingOwner = {
5
+ accountId: string;
6
+ workspaceId: string;
7
+ subjectId: string;
8
+ authorizationRevision: number;
9
+ };
10
+ /** Resolve the effective member's revision, not the authenticating external
11
+ * identity revision. Caller must separately prove its authority to act as them. */
12
+ export declare function resolveHostMcpBindingOwner(db: Database, input: Omit<HostMcpBindingOwner, "authorizationRevision">): Promise<HostMcpBindingOwner>;
13
+ export declare class HostMcpBindingConflictError extends Error {
14
+ constructor();
15
+ }
16
+ export declare class HostMcpDelegationAuthorityError extends Error {
17
+ }
18
+ /** Low-level persistence, not HTTP authentication. Callers must establish the
19
+ * exact external owner and workspace grant before entering this scoped seam. */
20
+ export declare function createHostMcpBinding(db: Database, owner: HostMcpBindingOwner, raw: unknown): Promise<HostMcpBinding>;
21
+ export declare function getHostMcpBinding(db: Database, owner: HostMcpBindingOwner, id: string): Promise<HostMcpBinding | null>;
22
+ export declare function revokeHostMcpBinding(db: Database, owner: HostMcpBindingOwner, id: string, expectedGeneration: number): Promise<HostMcpBinding>;
23
+ /** Internal persistence only. Caller must first verify owner identity and grant
24
+ * issuance permission. No worker consumes these rows without accepted-work capture. */
25
+ export declare function issueHostMcpDelegation(db: Database, owner: HostMcpBindingOwner, raw: unknown): Promise<HostMcpDelegation>;
26
+ export declare function getHostMcpDelegation(db: Database, owner: HostMcpBindingOwner, id: string): Promise<HostMcpDelegation | null>;
27
+ export declare function revokeHostMcpDelegation(db: Database, owner: HostMcpBindingOwner, id: string, expectedGeneration: number): Promise<HostMcpDelegation>;
28
+ /** Internal direct-admission boundary, NOT authentication and NOT persistence.
29
+ * The caller must establish a verified external owner and explicit selection,
30
+ * and capture the returned authority with accepted work INSIDE `capture`.
31
+ * Locks remain held through that callback. Historical initiator metadata only
32
+ * narrows the verified caller's selection; it never establishes who called.
33
+ * Schedules, continuations and inherited turns need their own frozen causal
34
+ * authority path and deliberately cannot use this direct-only boundary.
35
+ */
36
+ export declare function withDirectHostMcpAdmission<T>(db: Database, owner: HostMcpBindingOwner, input: {
37
+ sessionId: string;
38
+ turnId: string;
39
+ delegationId: string;
40
+ expectedDelegationGeneration: number;
41
+ }, capture: (tx: Database, authority: HostMcpAcceptedAuthority) => Promise<T>): Promise<T>;
42
+ /** Internal direct-turn persistence. The authenticated acceptance transaction
43
+ * must call this before claim; this does not authenticate the supplied owner.
44
+ * Exact replay is allowed, but a turn/server selection cannot be replaced. */
45
+ export declare function captureDirectHostMcpAuthority(db: Database, owner: HostMcpBindingOwner, input: Parameters<typeof withDirectHostMcpAdmission>[2]): Promise<HostMcpAcceptedAuthority>;
46
+ /** Copy only the authority of an exact causal turn after its canonical machine
47
+ * update has been delivered. The insert trigger independently proves delivery,
48
+ * live generations and byte-equivalent authority; no creator fallback exists.
49
+ * Revoked selections are omitted, allowing a continuation to explain loss of
50
+ * access without making its whole session permanently unclaimable. */
51
+ export declare function inheritCausalHostMcpTurnAuthorities(db: Database, input: {
52
+ accountId: string;
53
+ workspaceId: string;
54
+ sessionId: string;
55
+ subjectId: string;
56
+ sourceTurnId: string;
57
+ targetTurnId: string;
58
+ }): Promise<void>;
59
+ /** Initial child turn only. The stored parent-turn pointer was admitted by the
60
+ * native signed-attempt creation boundary; caller metadata never chooses it. */
61
+ export declare function inheritChildHostMcpTurnAuthorities(db: Database, input: {
62
+ accountId: string;
63
+ workspaceId: string;
64
+ sessionId: string;
65
+ turnId: string;
66
+ subjectId: string;
67
+ }): Promise<void>;
68
+ /** Live consumption of captured direct or same-session causal turn authority.
69
+ * Request context must come from the accepted attempt, never caller JSON.
70
+ * Missing/revoked authority denies; infrastructure failures propagate so the
71
+ * broker reports refresh_failed rather than misclassifying an outage.
72
+ * The historical function name is retained for existing internal consumers. */
73
+ export declare function authorizeDirectHostMcpUse(db: Database, request: McpCredentialsRequest): Promise<boolean>;
@@ -0,0 +1,47 @@
1
+ import { type ScheduledTask } from "@opengeni/contracts";
2
+ import { HostMcpTaskAuthority, HostMcpBindingDefinition } from "@opengeni/contracts/host-mcp-bindings";
3
+ import { type Database } from "./database.js";
4
+ import { type HostMcpBindingOwner } from "./host-mcp-bindings.js";
5
+ export type SelectedHostMcpTaskGrant = {
6
+ delegationId: string;
7
+ generation: number;
8
+ bindingId: string;
9
+ bindingGeneration: number;
10
+ definition: HostMcpBindingDefinition;
11
+ };
12
+ /** Internal capture only. The API/core authenticates the external owner and
13
+ * rechecks that proof in this same task-write transaction before calling. */
14
+ export declare function captureHostMcpTaskAuthorities(db: Database, owner: HostMcpBindingOwner, task: ScheduledTask, selections: SelectedHostMcpTaskGrant[]): Promise<void>;
15
+ /** Backend-only read; native immutable task-revision proof chooses the owner.
16
+ * No caller-supplied subject and no ambient workspace account enumeration. */
17
+ export declare function getHostMcpTaskAuthorities(db: Database, input: {
18
+ accountId: string;
19
+ workspaceId: string;
20
+ taskId: string;
21
+ taskAuthorityRevision: number;
22
+ }): Promise<HostMcpTaskAuthority[]>;
23
+ /** Native task revisions are the authority/version boundary, including ordinary
24
+ * lifecycle edits. Never silently drop or reassign retained host selections. */
25
+ export declare function cloneHostMcpTaskAuthorities(db: Database, task: ScheduledTask, sourceRevision: number): Promise<void>;
26
+ /** Claim-time attachment to the exact accepted run. No host callback or key is
27
+ * used here; credentials are requested only when the accepted attempt uses MCP. */
28
+ export declare function captureScheduledHostMcpTurnAuthorities(db: Database, input: {
29
+ accountId: string;
30
+ workspaceId: string;
31
+ sessionId: string;
32
+ turnId: string;
33
+ runId: string;
34
+ }): Promise<void>;
35
+ /** Agent-created task: derive selections exclusively from its live accepted
36
+ * attempt, then re-admit only native successor-eligible grants. No user lookup
37
+ * or connection inventory is a fallback for a turn with no captured authority. */
38
+ export declare function inheritHostMcpTaskAuthoritiesFromAttempt(db: Database, task: ScheduledTask, source: {
39
+ sessionId: string;
40
+ turnId: string;
41
+ attemptId: string;
42
+ executionGeneration: number;
43
+ }, configured: Array<{
44
+ bindingId: string;
45
+ bindingGeneration: number;
46
+ definition: HostMcpBindingDefinition;
47
+ }>): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { type HostMcpCreateSelection } from "@opengeni/contracts/host-mcp-bindings";
2
+ export type { HostMcpCreateSelection } from "@opengeni/contracts/host-mcp-bindings";
3
+ /** Replay identity only: neither grant admission nor credential authority. */
4
+ export declare function normalizeHostCreateSelection(value: unknown): HostMcpCreateSelection[];
5
+ export declare function metadataWithHostCreateSelection(metadata: Record<string, unknown>, value: unknown): Record<string, unknown>;
6
+ export declare function hostCreateSelectionFromMetadata(metadata: Record<string, unknown>): HostMcpCreateSelection[];