import type { BrowserFileRuntime } from "../../src/adapters/browser-files/index.ts"; import type { ProductScopeParticipant } from "../../src/bootstrap/product-composition-contract.ts"; /** What features receive: this session's runtime, asked for per operation. */ export type SessionBrowserFiles = Readonly<{ /** * The current session's runtime, built on first use. Ask again for each * operation; one kept past a sign-out answers `UNAVAILABLE`. */ current(): BrowserFileRuntime; }>; /** * 2026-11-03 02-01. How a product gives features a browser file runtime that * lives for one session. The runtime does not know the session, and * `composeProduct` runs once at boot, so the capability is a getter and the * runtime behind it is disposed by a scope participant on every sign-out and * account switch: the previous user's selected files, preview object URLs and * running downloads end there. The next call to `current()` builds a fresh one. * * file-transfer is an opt-in recipe (`productionComposition: false`), so the * template does not build this. A product that installs a feature using it * types the capability in `src/features/product-capabilities.ts`, as * `docs/manual/03-outside-feature-folder.md` says: * * export interface ProductFeaturePlatformCapabilities { * readonly files: SessionBrowserFiles; * } * * not with a `declare module` augmentation of `FeaturePlatformCapabilities`, * whose key `check:types:node` does not see (1105/02-03). The feature lists * `files` in `needs`, and the product returns both halves from * `src/bootstrap/product-composition.ts`: * * const browserFiles = createSessionBrowserFileCapability(() => * createBrowserFileRuntime({ input, policies, limits, download }), * ); * return { * capabilities: { files: browserFiles.files }, * credentialProviders: {}, * scopeParticipants: [browserFiles.scopeParticipant], * }; * * The runtime options are the product's decisions (policies, limits, the * download capability resolver); none is chosen here. */ export function createSessionBrowserFileCapability( create: () => BrowserFileRuntime, ): Readonly<{ files: SessionBrowserFiles; scopeParticipant: ProductScopeParticipant; }> { let runtime: BrowserFileRuntime | null = null; return Object.freeze({ files: Object.freeze({ current: () => (runtime ??= create()), }), scopeParticipant: Object.freeze({ label: "browser-files", close() { const ending = runtime; runtime = null; ending?.dispose(); }, }), }); }