@opengeni/core 1.2.1-canary.37222177070001 → 1.3.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.
@@ -3,7 +3,7 @@ import {
3
3
  getManagedAuthRequestActorLeaseStamp,
4
4
  getManagedSession,
5
5
  markManagedAuthRequestActorTransitionApplied
6
- } from "./chunk-MM6N7CTO.js";
6
+ } from "./chunk-672TAJCH.js";
7
7
  import "./chunk-QO5GVFFO.js";
8
8
 
9
9
  // src/canonical-human-identities.ts
@@ -7,7 +7,13 @@ import {
7
7
  } from "./chunk-QO5GVFFO.js";
8
8
 
9
9
  // src/managed-session.ts
10
+ import { AsyncLocalStorage } from "async_hooks";
10
11
  import { managedUserEmailAllowed } from "@opengeni/config";
12
+ import {
13
+ DatabaseUnavailableError,
14
+ isDatabaseConnectionLoss,
15
+ isRetryableDatabaseTransportFailure
16
+ } from "@opengeni/db";
11
17
  import {
12
18
  acquireManagedAuthActorMutationLease,
13
19
  getManagedAuthAdoptedSessionSnapshot,
@@ -19,6 +25,36 @@ import {
19
25
  } from "@opengeni/db/managed-auth-session-sets";
20
26
  import { validateCanonicalHumanSession } from "@opengeni/db/canonical-human-identities";
21
27
  import { HTTPException } from "hono/http-exception";
28
+ var managedAuthLookupFailures = new AsyncLocalStorage();
29
+ var MANAGED_AUTH_LOOKUP_FAILURE_LIMIT = 8;
30
+ function recordManagedAuthLoggedFailure(args) {
31
+ const store = managedAuthLookupFailures.getStore();
32
+ if (!store) return;
33
+ for (const value of args) {
34
+ if (store.errors.length >= MANAGED_AUTH_LOOKUP_FAILURE_LIMIT) return;
35
+ if (value && typeof value === "object") store.errors.push(value);
36
+ }
37
+ }
38
+ function isBetterAuthInternalServerError(error) {
39
+ if (!error || typeof error !== "object") return false;
40
+ const candidate = error;
41
+ return candidate.status === "INTERNAL_SERVER_ERROR" || candidate.statusCode === 500;
42
+ }
43
+ async function withManagedAuthSessionLookup(lookup) {
44
+ const store = { errors: [] };
45
+ try {
46
+ return await managedAuthLookupFailures.run(store, lookup);
47
+ } catch (error) {
48
+ if (isBetterAuthInternalServerError(error) && store.errors.some(
49
+ (logged) => isDatabaseConnectionLoss(logged) || isRetryableDatabaseTransportFailure(logged)
50
+ )) {
51
+ throw new DatabaseUnavailableError("managed auth session store unavailable", {
52
+ cause: error
53
+ });
54
+ }
55
+ throw error;
56
+ }
57
+ }
22
58
  var ACTOR_MUTATION_LEASE_SECONDS = 15 * 60;
23
59
  var ACTOR_MUTATION_LEASE_REFRESH_MS = 5 * 60 * 1e3;
24
60
  var ACTOR_MUTATION_HANDLER_DEADLINE_MS = 10 * 60 * 1e3;
@@ -165,10 +201,12 @@ async function resolveManagedSession(c, auth, options) {
165
201
  throw error;
166
202
  }
167
203
  }
168
- const result = await auth.api.getSession({
169
- headers: c.req.raw.headers,
170
- returnHeaders: true
171
- });
204
+ const result = await withManagedAuthSessionLookup(
205
+ () => auth.api.getSession({
206
+ headers: c.req.raw.headers,
207
+ returnHeaders: true
208
+ })
209
+ );
172
210
  for (const cookie of setCookieHeaders(result.headers)) {
173
211
  c.header("set-cookie", cookie, { append: true });
174
212
  }
@@ -372,6 +410,8 @@ function setCookieHeaders(headers) {
372
410
  }
373
411
 
374
412
  export {
413
+ recordManagedAuthLoggedFailure,
414
+ withManagedAuthSessionLookup,
375
415
  configureManagedUserAdmission,
376
416
  getManagedSession,
377
417
  assertManagedUserAdmission,
@@ -384,4 +424,4 @@ export {
384
424
  getManagedAuthRequestActorAdmissionStamp,
385
425
  getManagedAuthRequestActorLeaseStamp
386
426
  };
387
- //# sourceMappingURL=chunk-MM6N7CTO.js.map
427
+ //# sourceMappingURL=chunk-672TAJCH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/managed-session.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { managedUserEmailAllowed } from \"@opengeni/config\";\nimport type { Context } from \"hono\";\nimport type { ManagedAuth } from \"./managed-auth-type\";\nimport {\n DatabaseUnavailableError,\n isDatabaseConnectionLoss,\n isRetryableDatabaseTransportFailure,\n type Database,\n} from \"@opengeni/db\";\nimport {\n acquireManagedAuthActorMutationLease,\n getManagedAuthAdoptedSessionSnapshot,\n getManagedAuthSessionSetSnapshot,\n ManagedAuthSessionSetAuthorityError,\n ManagedAuthSessionSetGenerationConflictError,\n releaseManagedAuthActorMutationLease,\n validateManagedAuthActorMutationLease,\n} from \"@opengeni/db/managed-auth-session-sets\";\nimport { validateCanonicalHumanSession } from \"@opengeni/db/canonical-human-identities\";\nimport type { ManagedAuthSessionSetMode } from \"@opengeni/contracts/managed-auth-session-sets\";\nimport { HTTPException } from \"hono/http-exception\";\nimport {\n MANAGED_AUTH_ACTOR_EPOCH_HEADER,\n MANAGED_AUTH_SESSION_SET_COOKIE,\n ManagedAuthActorChangeError,\n managedAuthSha256,\n resolveManagedAuthSelectedSession,\n type ManagedAuthSessionAdapter,\n} from \"./managed-auth-session-sets\";\n\n/**\n * Better Auth's session endpoint replaces every non-API failure with a generic\n * INTERNAL_SERVER_ERROR and passes the original only to its logger. A lookup run\n * through `withManagedAuthSessionLookup` collects what the logger saw, so a lost\n * database connection is reported as a retryable outage instead of an opaque 500.\n */\nconst managedAuthLookupFailures = new AsyncLocalStorage<{ errors: unknown[] }>();\nconst MANAGED_AUTH_LOOKUP_FAILURE_LIMIT = 8;\n\n/** Better Auth `logger.log` sink; a no-op outside a managed-auth session lookup. */\nexport function recordManagedAuthLoggedFailure(args: readonly unknown[]): void {\n const store = managedAuthLookupFailures.getStore();\n if (!store) return;\n for (const value of args) {\n if (store.errors.length >= MANAGED_AUTH_LOOKUP_FAILURE_LIMIT) return;\n if (value && typeof value === \"object\") store.errors.push(value);\n }\n}\n\nfunction isBetterAuthInternalServerError(error: unknown): boolean {\n if (!error || typeof error !== \"object\") return false;\n const candidate = error as { status?: unknown; statusCode?: unknown };\n return candidate.status === \"INTERNAL_SERVER_ERROR\" || candidate.statusCode === 500;\n}\n\nexport async function withManagedAuthSessionLookup<T>(lookup: () => Promise<T>): Promise<T> {\n const store = { errors: [] as unknown[] };\n try {\n return await managedAuthLookupFailures.run(store, lookup);\n } catch (error) {\n // Better Auth's session endpoint only reads its database adapter, so a\n // socket failure it logged is that adapter's connection, not another service.\n if (\n isBetterAuthInternalServerError(error) &&\n store.errors.some(\n (logged) => isDatabaseConnectionLoss(logged) || isRetryableDatabaseTransportFailure(logged),\n )\n ) {\n throw new DatabaseUnavailableError(\"managed auth session store unavailable\", {\n cause: error,\n });\n }\n throw error;\n }\n}\n\nconst ACTOR_MUTATION_LEASE_SECONDS = 15 * 60;\nconst ACTOR_MUTATION_LEASE_REFRESH_MS = 5 * 60 * 1_000;\nconst ACTOR_MUTATION_HANDLER_DEADLINE_MS = 10 * 60 * 1_000;\nconst ACTOR_MUTATION_FATAL_SAFETY_MS = 5_000;\ntype ActorMutationLeaseRuntime = {\n monotonicNow: () => number;\n schedule: (callback: () => void, delayMs: number) => ReturnType<typeof setTimeout>;\n cancel: (timer: ReturnType<typeof setTimeout>) => void;\n terminate: () => void;\n};\nconst productionActorMutationLeaseRuntime: ActorMutationLeaseRuntime = {\n monotonicNow: () => performance.now(),\n schedule: (callback, delayMs) => unrefTimer(setTimeout(callback, delayMs)),\n cancel: (timer) => clearTimeout(timer),\n terminate: () => {\n process.stderr.write(\"fatal: managed actor mutation outlived its durable lease\\n\");\n process.exit(1);\n },\n};\nlet actorMutationLeaseRuntime = productionActorMutationLeaseRuntime;\ntype ActorMutationLease = {\n db: Database;\n authorityHash: string;\n actorEpoch: string;\n requestId: string;\n refreshTimer: ReturnType<typeof setTimeout> | null;\n deadlineTimer: ReturnType<typeof setTimeout> | null;\n fatalTimer: ReturnType<typeof setTimeout> | null;\n expiresAt: Date;\n localFatalDeadlineMonotonicMs: number;\n runtime: ActorMutationLeaseRuntime;\n abortController: AbortController;\n poisoned: unknown | null;\n actorTransitionApplied: boolean;\n};\nconst actorMutationLeaseByRequest = new WeakMap<Request, ActorMutationLease>();\nconst managedActorEpochByRequest = new WeakMap<Request, string>();\nconst managedActorAdmissionByRequest = new WeakMap<Request, ManagedAuthActorAdmissionStamp>();\n\n/**\n * Read a Better Auth session without bypassing its sliding-cookie renewal.\n *\n * Better Auth can refresh the durable session while resolving `getSession`.\n * Programmatic callers must explicitly request and forward the returned cookie\n * headers; the HTTP handler does this automatically, but direct API calls do not.\n */\nconst managedUserAllowlists = new WeakMap<ManagedAuth, readonly string[]>();\n\n/** Bind admission to this auth instance, including all session-set modes. */\nexport function configureManagedUserAdmission(\n auth: ManagedAuth,\n emails: readonly string[] | undefined,\n): void {\n if (emails === undefined) managedUserAllowlists.delete(auth);\n else managedUserAllowlists.set(auth, [...emails]);\n}\n\nexport async function getManagedSession(...args: Parameters<typeof resolveManagedSession>) {\n const session = await resolveManagedSession(...args);\n assertManagedUserAdmission(args[1], session?.user);\n return session;\n}\n\nexport function assertManagedUserAdmission(\n auth: ManagedAuth,\n user: { email: string; emailVerified: boolean } | null | undefined,\n): void {\n const emails = managedUserAllowlists.get(auth);\n if (\n user &&\n emails !== undefined &&\n (!user.emailVerified || !managedUserEmailAllowed(emails, user.email))\n )\n throw new HTTPException(403, { message: \"Account is not permitted on this deployment\" });\n}\n\nasync function resolveManagedSession(\n c: Context,\n auth: ManagedAuth,\n options?: {\n db?: Database | undefined;\n allowIdentityRecovery?: boolean | undefined;\n sessionSetMode?: ManagedAuthSessionSetMode | undefined;\n sessionAdapter?: ManagedAuthSessionAdapter | null | undefined;\n },\n) {\n const sessionSetMode = options?.sessionSetMode ?? \"legacy\";\n if (sessionSetMode !== \"legacy\" && options?.db && options.sessionAdapter) {\n const authority = requestCookie(c.req.raw, MANAGED_AUTH_SESSION_SET_COOKIE);\n if (authority) {\n try {\n // A long-lived response reuses this exact Request for periodic\n // authorization. Once admitted, the server-owned stamp is the actor\n // fence: a client may omit the header on its initial GET, but a later\n // reauthorization must not follow a newly selected actor.\n const admittedActorEpoch = managedActorEpochByRequest.get(c.req.raw) ?? null;\n const expectedActorEpoch =\n admittedActorEpoch ?? c.req.header(MANAGED_AUTH_ACTOR_EPOCH_HEADER) ?? null;\n const legacyAmbient =\n sessionSetMode === \"dual\" && expectedActorEpoch === null\n ? await options.sessionAdapter.resolveAmbientSession(c.req.raw.headers)\n : null;\n const selected = await resolveManagedAuthSelectedSession({\n db: options.db,\n adapter: options.sessionAdapter,\n authority,\n mode: sessionSetMode,\n expectedActorEpoch,\n legacyAmbientSessionId:\n typeof legacyAmbient?.session?.id === \"string\" ? legacyAmbient.session.id : null,\n allowRecovery: options.allowIdentityRecovery ?? false,\n });\n if (selected) {\n // The actor epoch is both an admission fence and response provenance.\n // A browser must ignore a late finite response after another tab has\n // advanced selection, even when the request itself was read-only.\n if (admittedActorEpoch === null) {\n c.header(MANAGED_AUTH_ACTOR_EPOCH_HEADER, selected.projection.actorEpoch);\n managedActorEpochByRequest.set(c.req.raw, selected.projection.actorEpoch);\n }\n managedActorAdmissionByRequest.set(c.req.raw, {\n authorityHash: managedAuthSha256(authority),\n actorEpoch: selected.projection.actorEpoch,\n });\n }\n if (selected && !selected.session) return null;\n if (selected?.session) {\n let resolvedSession = selected.session;\n if (requestNeedsActorMutationLease(c.req.method)) {\n await ensureActorMutationLease(\n c.req.raw,\n options.db,\n authority,\n selected.projection.actorEpoch,\n );\n const selectedSlot = await selectedSlotForAuthority(\n options.db,\n authority,\n sessionSetMode,\n options.allowIdentityRecovery ?? false,\n );\n if (!selectedSlot) throw new ManagedAuthActorChangeError();\n const refreshed = await options.sessionAdapter.refreshSelectedSession(selectedSlot);\n if (\n !refreshed ||\n refreshed.session.id !== selectedSlot.authSessionId ||\n refreshed.user.id !== selectedSlot.authUserId\n ) {\n throw new ManagedAuthActorChangeError();\n }\n resolvedSession = refreshed;\n }\n return resolvedSession;\n }\n // Once a browser presents a session-set authority it is authoritative.\n // An absent/expired/rekeyed authority must never fall through to an\n // ambient Better Auth cookie in dual mode: that would bypass the actor\n // epoch and mutation-lease fences after another tab transitions.\n return null;\n } catch (error) {\n if (error instanceof ManagedAuthActorChangeError) {\n // Response headers are immutable after an SSE body starts. The\n // original response already carries its actor epoch; reauthorization\n // closes that stream through the thrown conflict instead.\n if (!managedActorEpochByRequest.has(c.req.raw)) {\n c.header(\"x-opengeni-actor-state\", \"changed\");\n }\n throw new HTTPException(409, { message: error.code, cause: error });\n }\n throw error;\n }\n }\n if (sessionSetMode === \"broker\") return null;\n const ambient = await options.sessionAdapter.resolveAmbientSession(c.req.raw.headers);\n if (ambient?.session?.id)\n try {\n const adopted = await getManagedAuthAdoptedSessionSnapshot(options.db, ambient.session.id);\n if (adopted) {\n const admittedActorEpoch = managedActorEpochByRequest.get(c.req.raw) ?? null;\n if (\n adopted.actorEpoch !== \"1\" ||\n (admittedActorEpoch !== null && adopted.actorEpoch !== admittedActorEpoch) ||\n !adopted.selected ||\n adopted.selected.authSessionId !== ambient.session.id ||\n adopted.selected.authUserId !== ambient.user.id\n ) {\n throw new ManagedAuthActorChangeError();\n }\n if (admittedActorEpoch === null) {\n c.header(MANAGED_AUTH_ACTOR_EPOCH_HEADER, adopted.actorEpoch);\n managedActorEpochByRequest.set(c.req.raw, adopted.actorEpoch);\n }\n managedActorAdmissionByRequest.set(c.req.raw, {\n authorityHash: adopted.authorityHash,\n actorEpoch: adopted.actorEpoch,\n });\n if (requestNeedsActorMutationLease(c.req.method)) {\n await ensureActorMutationLeaseForHash(\n c.req.raw,\n options.db,\n adopted.authorityHash,\n adopted.actorEpoch,\n );\n const current = await getManagedAuthAdoptedSessionSnapshot(\n options.db,\n ambient.session.id,\n );\n if (\n current?.authorityHash !== adopted.authorityHash ||\n current.actorEpoch !== adopted.actorEpoch ||\n !current.selected ||\n current.selected.authSessionId !== ambient.session.id\n ) {\n throw new ManagedAuthActorChangeError();\n }\n const refreshed = await options.sessionAdapter.refreshSelectedSession(current.selected);\n if (\n !refreshed ||\n refreshed.session.id !== ambient.session.id ||\n refreshed.user.id !== ambient.user.id\n ) {\n throw new ManagedAuthActorChangeError();\n }\n return refreshed;\n }\n return ambient;\n }\n } catch (error) {\n if (error instanceof ManagedAuthActorChangeError) {\n if (!managedActorEpochByRequest.has(c.req.raw)) {\n c.header(\"x-opengeni-actor-state\", \"changed\");\n }\n throw new HTTPException(409, { message: error.code, cause: error });\n }\n throw error;\n }\n }\n const result = await withManagedAuthSessionLookup(() =>\n auth.api.getSession({\n headers: c.req.raw.headers,\n returnHeaders: true,\n }),\n );\n\n for (const cookie of setCookieHeaders(result.headers)) {\n c.header(\"set-cookie\", cookie, { append: true });\n }\n\n const session = result.response;\n if (!session?.user || !options?.db) return session;\n const authSessionId = session.session?.id;\n if (typeof authSessionId !== \"string\") return null;\n const valid = await validateCanonicalHumanSession(options.db, {\n authSessionId,\n authUserId: session.user.id,\n ...(options.allowIdentityRecovery === undefined\n ? {}\n : { allowRecovery: options.allowIdentityRecovery }),\n });\n return valid ? session : null;\n}\n\n/** Safe response provenance for a request authenticated through session-set authority. */\nexport function getManagedAuthRequestActorEpoch(request: Request): string | null {\n return managedActorEpochByRequest.get(request) ?? null;\n}\n\nfunction selectedSlotForAuthority(\n db: Database,\n authority: string,\n mode: ManagedAuthSessionSetMode,\n allowRecovery: boolean,\n) {\n return getManagedAuthSessionSetSnapshot(db, {\n authorityHash: managedAuthSha256(authority),\n mode,\n includeInternal: true,\n allowRecovery,\n readOnly: true,\n }).then((snapshot) => snapshot?.selected ?? null);\n}\n\n/** Release the multi-replica actor fence after the outer HTTP handler settles. */\nexport async function releaseManagedAuthRequestActorLease(request: Request): Promise<void> {\n const lease = actorMutationLeaseByRequest.get(request);\n if (!lease) return;\n actorMutationLeaseByRequest.delete(request);\n if (lease.refreshTimer) lease.runtime.cancel(lease.refreshTimer);\n if (lease.deadlineTimer) lease.runtime.cancel(lease.deadlineTimer);\n if (lease.fatalTimer) lease.runtime.cancel(lease.fatalTimer);\n await releaseManagedAuthActorMutationLease(lease.db, {\n authorityHash: lease.authorityHash,\n requestId: lease.requestId,\n });\n}\n\n/** Cooperative cancellation signal for actor-scoped provider/external I/O. */\nexport function getManagedAuthRequestActorAbortSignal(request: Request): AbortSignal | null {\n return actorMutationLeaseByRequest.get(request)?.abortController.signal ?? null;\n}\n\n/** @internal Deterministic lease-clock seam used only by direct lifecycle tests. */\nexport function installManagedAuthActorLeaseRuntimeForTest(\n overrides: Partial<ActorMutationLeaseRuntime>,\n): () => void {\n const previous = actorMutationLeaseRuntime;\n actorMutationLeaseRuntime = {\n ...productionActorMutationLeaseRuntime,\n ...overrides,\n };\n return () => {\n actorMutationLeaseRuntime = previous;\n };\n}\n\n/**\n * Exact post-handler fence. A finite unsafe response is not released unless\n * its request-owned lease is still live at the same actor epoch.\n */\nexport async function validateManagedAuthRequestActorLease(request: Request): Promise<void> {\n const lease = actorMutationLeaseByRequest.get(request);\n if (!lease) return;\n if (lease.actorTransitionApplied) return;\n if (lease.poisoned !== null) {\n throw new ManagedAuthActorLeaseOutcomeUnknownError({\n cause: lease.poisoned,\n });\n }\n const valid = await validateManagedAuthActorMutationLease(lease.db, {\n authorityHash: lease.authorityHash,\n actorEpoch: lease.actorEpoch,\n requestId: lease.requestId,\n });\n if (!valid) throw new ManagedAuthActorChangeError();\n}\n\nexport class ManagedAuthActorLeaseOutcomeUnknownError extends Error {\n readonly name = \"ManagedAuthActorLeaseOutcomeUnknownError\";\n readonly code = \"operation_outcome_unknown\";\n constructor(options?: ErrorOptions) {\n super(\"The actor-scoped request outcome is unknown after its durable lease was lost\", options);\n }\n}\n\n/** A known-applied same-request canonical transition intentionally consumes its lease. */\nexport function markManagedAuthRequestActorTransitionApplied(request: Request): void {\n const lease = actorMutationLeaseByRequest.get(request);\n if (lease) lease.actorTransitionApplied = true;\n}\n\nexport type ManagedAuthActorMutationLeaseStamp = {\n authorityHash: string;\n actorEpoch: string;\n requestId: string;\n};\n\nexport type ManagedAuthActorAdmissionStamp = {\n authorityHash: string;\n actorEpoch: string;\n};\n\n/** Verified server-owned actor evidence available to both reads and mutations. */\nexport function getManagedAuthRequestActorAdmissionStamp(\n request: Request,\n): ManagedAuthActorAdmissionStamp | null {\n return managedActorAdmissionByRequest.get(request) ?? null;\n}\n\n/** Exact request-owned fence passed into a same-transaction actor transition. */\nexport function getManagedAuthRequestActorLeaseStamp(\n request: Request,\n): ManagedAuthActorMutationLeaseStamp | null {\n const lease = actorMutationLeaseByRequest.get(request);\n return lease\n ? {\n authorityHash: lease.authorityHash,\n actorEpoch: lease.actorEpoch,\n requestId: lease.requestId,\n }\n : null;\n}\n\nfunction requestNeedsActorMutationLease(method: string): boolean {\n return method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\";\n}\n\nasync function ensureActorMutationLease(\n request: Request,\n db: Database,\n authority: string,\n actorEpoch: string,\n): Promise<void> {\n const authorityHash = managedAuthSha256(authority);\n await ensureActorMutationLeaseForHash(request, db, authorityHash, actorEpoch);\n}\n\nasync function ensureActorMutationLeaseForHash(\n request: Request,\n db: Database,\n authorityHash: string,\n actorEpoch: string,\n): Promise<void> {\n const existing = actorMutationLeaseByRequest.get(request);\n if (existing) {\n if (existing.authorityHash !== authorityHash || existing.actorEpoch !== actorEpoch) {\n throw new ManagedAuthActorChangeError();\n }\n return;\n }\n const lease: ActorMutationLease = {\n db,\n authorityHash,\n actorEpoch,\n requestId: crypto.randomUUID(),\n refreshTimer: null,\n deadlineTimer: null,\n fatalTimer: null,\n expiresAt: new Date(0),\n localFatalDeadlineMonotonicMs: 0,\n runtime: actorMutationLeaseRuntime,\n abortController: new AbortController(),\n poisoned: null,\n actorTransitionApplied: false,\n };\n const acquireStartedAtMonotonicMs = lease.runtime.monotonicNow();\n try {\n lease.expiresAt = await acquireManagedAuthActorMutationLease(db, {\n authorityHash,\n actorEpoch,\n requestId: lease.requestId,\n leaseSeconds: ACTOR_MUTATION_LEASE_SECONDS,\n });\n } catch (error) {\n if (\n error instanceof ManagedAuthSessionSetGenerationConflictError ||\n error instanceof ManagedAuthSessionSetAuthorityError\n ) {\n throw new ManagedAuthActorChangeError();\n }\n throw error;\n }\n lease.localFatalDeadlineMonotonicMs =\n acquireStartedAtMonotonicMs +\n ACTOR_MUTATION_LEASE_SECONDS * 1_000 -\n ACTOR_MUTATION_FATAL_SAFETY_MS;\n actorMutationLeaseByRequest.set(request, lease);\n scheduleActorMutationLeaseRefresh(request, lease);\n lease.deadlineTimer = lease.runtime.schedule(() => {\n poisonActorMutationLease(\n request,\n lease,\n new Error(\"managed actor mutation handler exceeded its bounded lifetime\"),\n );\n }, ACTOR_MUTATION_HANDLER_DEADLINE_MS);\n}\n\nfunction scheduleActorMutationLeaseRefresh(request: Request, lease: ActorMutationLease): void {\n const timer = lease.runtime.schedule(() => {\n if (actorMutationLeaseByRequest.get(request) !== lease) return;\n const refreshStartedAtMonotonicMs = lease.runtime.monotonicNow();\n void acquireManagedAuthActorMutationLease(lease.db, {\n authorityHash: lease.authorityHash,\n actorEpoch: lease.actorEpoch,\n requestId: lease.requestId,\n leaseSeconds: ACTOR_MUTATION_LEASE_SECONDS,\n })\n .then(async (expiresAt) => {\n if (actorMutationLeaseByRequest.get(request) !== lease) {\n // Release may have won while this pooled acquire statement was in\n // flight. Converge the just-renewed row immediately; never resurrect\n // a request-owned fence after the outer handler has settled.\n await releaseManagedAuthActorMutationLease(lease.db, {\n authorityHash: lease.authorityHash,\n requestId: lease.requestId,\n });\n return;\n }\n lease.expiresAt = expiresAt;\n lease.localFatalDeadlineMonotonicMs =\n refreshStartedAtMonotonicMs +\n ACTOR_MUTATION_LEASE_SECONDS * 1_000 -\n ACTOR_MUTATION_FATAL_SAFETY_MS;\n scheduleActorMutationLeaseRefresh(request, lease);\n })\n .catch((error) => poisonActorMutationLease(request, lease, error));\n }, ACTOR_MUTATION_LEASE_REFRESH_MS);\n lease.refreshTimer = timer;\n}\n\nfunction poisonActorMutationLease(\n request: Request,\n lease: ActorMutationLease,\n error: unknown,\n): void {\n if (actorMutationLeaseByRequest.get(request) !== lease || lease.poisoned !== null) return;\n lease.poisoned = error;\n if (lease.refreshTimer) lease.runtime.cancel(lease.refreshTimer);\n lease.refreshTimer = null;\n lease.abortController.abort(error);\n const fatalAfterMs = Math.max(\n 0,\n lease.localFatalDeadlineMonotonicMs - lease.runtime.monotonicNow(),\n );\n lease.fatalTimer = lease.runtime.schedule(() => {\n if (actorMutationLeaseByRequest.get(request) !== lease) return;\n // A handler that ignored cooperative cancellation must not outlive the\n // durable fence and resume under a later actor. Terminate this API\n // instance before PostgreSQL can expire the lease; process death is the\n // final multi-replica-safe cancellation boundary.\n lease.runtime.terminate();\n }, fatalAfterMs);\n}\n\nfunction unrefTimer<T extends ReturnType<typeof setTimeout>>(timer: T): T {\n (timer as T & { unref?: () => void }).unref?.();\n return timer;\n}\n\nfunction requestCookie(request: Request, name: string): string | null {\n const header = request.headers.get(\"cookie\");\n if (!header) return null;\n for (const part of header.split(\";\")) {\n const separator = part.indexOf(\"=\");\n if (separator < 0 || part.slice(0, separator).trim() !== name) continue;\n const value = part.slice(separator + 1).trim();\n if (!value || value.length > 512) return null;\n try {\n return decodeURIComponent(value);\n } catch {\n return null;\n }\n }\n return null;\n}\n\nfunction setCookieHeaders(headers: Headers): string[] {\n const getSetCookie = (\n headers as Headers & {\n getSetCookie?: () => string[];\n }\n ).getSetCookie;\n if (getSetCookie) {\n return getSetCookie.call(headers);\n }\n\n const cookie = headers.get(\"set-cookie\");\n return cookie ? [cookie] : [];\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AAGxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qCAAqC;AAE9C,SAAS,qBAAqB;AAgB9B,IAAM,4BAA4B,IAAI,kBAAyC;AAC/E,IAAM,oCAAoC;AAGnC,SAAS,+BAA+B,MAAgC;AAC7E,QAAM,QAAQ,0BAA0B,SAAS;AACjD,MAAI,CAAC,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A,EAC1B,GAAG,YAAY;AACjB;AAEA,SAAS,WAAoD,OAAa;AACxE,EAAC,MAAqC,QAAQ;AAC9C,SAAO;AACT;AAEA,SAAS,cAAc,SAAkB,MAA6B;AACpE,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,OAAQ,QAAO;AACpB,aAAW,QAAQ,OAAO,MAAM,GAAG,GAAG;AACpC,UAAM,YAAY,KAAK,QAAQ,GAAG;AAClC,QAAI,YAAY,KAAK,KAAK,MAAM,GAAG,SAAS,EAAE,KAAK,MAAM,KAAM;AAC/D,UAAM,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,KAAK;AAC7C,QAAI,CAAC,SAAS,MAAM,SAAS,IAAK,QAAO;AACzC,QAAI;AACF,aAAO,mBAAmB,KAAK;AAAA,IACjC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,iBAAiB,SAA4B;AACpD,QAAM,eACJ,QAGA;AACF,MAAI,cAAc;AAChB,WAAO,aAAa,KAAK,OAAO;AAAA,EAClC;AAEA,QAAM,SAAS,QAAQ,IAAI,YAAY;AACvC,SAAO,SAAS,CAAC,MAAM,IAAI,CAAC;AAC9B;","names":[]}
@@ -9,6 +9,8 @@ type Input = {
9
9
  grant: AccessGrant;
10
10
  capabilityId: string;
11
11
  personalOwnerVerified: boolean;
12
+ connectionId?: string;
13
+ instanceKey?: string;
12
14
  };
13
15
  type ListedTool = {
14
16
  name: string;
@@ -1,18 +1,18 @@
1
1
  import { type Database, type KnowledgeContext } from "@opengeni/db";
2
2
  /** Retain actual message bytes, never a model-authored reconstruction of a confirmation. */
3
3
  export declare function retainKnowledgeMessage(db: Database, context: KnowledgeContext, messageId?: string): Promise<{
4
- revisionId?: never;
5
4
  retained: boolean;
6
5
  reason: string;
7
6
  entryId?: never;
7
+ revisionId?: never;
8
8
  outcome?: never;
9
9
  messageId?: never;
10
10
  reused?: never;
11
11
  } | {
12
- revisionId?: never;
13
12
  retained: boolean;
14
13
  reason: string;
15
14
  entryId: string;
15
+ revisionId?: never;
16
16
  outcome?: never;
17
17
  messageId?: never;
18
18
  reused?: never;
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export * from "./user-presence.js";
13
13
  export * from "./product-usage-metrics.js";
14
14
  export * from "./sandbox-types.js";
15
15
  export * from "./managed-auth-type.js";
16
- export { getManagedAuthRequestActorAbortSignal, getManagedAuthRequestActorAdmissionStamp, getManagedAuthRequestActorEpoch, getManagedAuthRequestActorLeaseStamp, getManagedSession, configureManagedUserAdmission, assertManagedUserAdmission, ManagedAuthActorLeaseOutcomeUnknownError, markManagedAuthRequestActorTransitionApplied, releaseManagedAuthRequestActorLease, validateManagedAuthRequestActorLease, type ManagedAuthActorAdmissionStamp, type ManagedAuthActorMutationLeaseStamp, } from "./managed-session.js";
16
+ export { getManagedAuthRequestActorAbortSignal, getManagedAuthRequestActorAdmissionStamp, getManagedAuthRequestActorEpoch, getManagedAuthRequestActorLeaseStamp, getManagedSession, recordManagedAuthLoggedFailure, withManagedAuthSessionLookup, configureManagedUserAdmission, assertManagedUserAdmission, ManagedAuthActorLeaseOutcomeUnknownError, markManagedAuthRequestActorTransitionApplied, releaseManagedAuthRequestActorLease, validateManagedAuthRequestActorLease, type ManagedAuthActorAdmissionStamp, type ManagedAuthActorMutationLeaseStamp, } from "./managed-session.js";
17
17
  export * from "./transcription.js";
18
18
  export * from "./model-catalog.js";
19
19
  export * from "./goal-admission.js";