@agimon-ai/doompi-core 0.0.1-alpha.127 → 0.0.1-alpha.128

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 (30) hide show
  1. package/dist/headlessServer.cjs +3 -3
  2. package/dist/headlessServer.mjs +3 -3
  3. package/dist/serverFacet.cjs +2 -0
  4. package/dist/serverFacet.d.mts +2 -1
  5. package/dist/serverFacet.mjs +2 -1
  6. package/dist/src/schemas/packageApi.cjs.map +1 -1
  7. package/dist/src/schemas/packageApi.d.mts +3 -0
  8. package/dist/src/schemas/packageApi.d.mts.map +1 -1
  9. package/dist/src/schemas/packageApi.mjs.map +1 -1
  10. package/dist/src/server/sessionMcpHandler.cjs +45 -19
  11. package/dist/src/server/sessionMcpHandler.cjs.map +1 -1
  12. package/dist/src/server/sessionMcpHandler.d.mts +1 -0
  13. package/dist/src/server/sessionMcpHandler.d.mts.map +1 -1
  14. package/dist/src/server/sessionMcpHandler.mjs +45 -19
  15. package/dist/src/server/sessionMcpHandler.mjs.map +1 -1
  16. package/dist/src/server/sessionMcpRoutes.cjs +21 -10
  17. package/dist/src/server/sessionMcpRoutes.cjs.map +1 -1
  18. package/dist/src/server/sessionMcpRoutes.mjs +21 -10
  19. package/dist/src/server/sessionMcpRoutes.mjs.map +1 -1
  20. package/dist/src/services/publicFileShares/index.cjs +5 -2
  21. package/dist/src/services/publicFileShares/index.cjs.map +1 -1
  22. package/dist/src/services/publicFileShares/index.mjs +5 -2
  23. package/dist/src/services/publicFileShares/index.mjs.map +1 -1
  24. package/dist/src/services/sessionAttachments/index.cjs +1 -1
  25. package/dist/src/services/sessionAttachments/index.d.mts +11 -0
  26. package/dist/src/services/sessionAttachments/index.d.mts.map +1 -0
  27. package/dist/src/services/sessionAttachments/index.mjs +1 -1
  28. package/dist/src/systems/main/adapters/headlessSessionHost.cjs +1 -1
  29. package/dist/src/systems/main/adapters/headlessSessionHost.mjs +1 -1
  30. package/package.json +1 -1
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
3
  require("./src/constants/contextApi.cjs");
4
- const require_harnessErrorMessage = require("./src/server/harnessErrorMessage.cjs");
4
+ const require_sessionFiles = require("./src/constants/sessionFiles.cjs");
5
5
  const require_contextDetailStore = require("./contextDetailStore.cjs");
6
+ const require_index = require("./src/services/sessionAttachments/index.cjs");
7
+ const require_harnessErrorMessage = require("./src/server/harnessErrorMessage.cjs");
6
8
  const require_serverTelemetry = require("./serverTelemetry.cjs");
7
9
  const require_packageApi = require("./src/schemas/packageApi.cjs");
8
- const require_sessionFiles = require("./src/constants/sessionFiles.cjs");
9
- const require_index = require("./src/services/sessionAttachments/index.cjs");
10
10
  const require_index$1 = require("./src/services/sessionMcpActivity/index.cjs");
11
11
  const require_index$2 = require("./src/services/sessionMcpConversations/index.cjs");
12
12
  const require_index$3 = require("./src/services/sessionMcpRegistrationStore/index.cjs");
@@ -1,10 +1,10 @@
1
1
  import "./src/constants/contextApi.mjs";
2
- import { harnessErrorMessage } from "./src/server/harnessErrorMessage.mjs";
2
+ import { SESSION_FILE_CONTENT_TYPES } from "./src/constants/sessionFiles.mjs";
3
3
  import { readContextDetail } from "./contextDetailStore.mjs";
4
+ import { writeSessionAttachment } from "./src/services/sessionAttachments/index.mjs";
5
+ import { harnessErrorMessage } from "./src/server/harnessErrorMessage.mjs";
4
6
  import { observe } from "./serverTelemetry.mjs";
5
7
  import { DOOM_API_CALLER_HEADERS, DOOM_API_CALLER_LOCALITY_HEADER, DOOM_API_CALLER_STEP_UP_HEADER, parseDoomSocketPath } from "./src/schemas/packageApi.mjs";
6
- import { SESSION_FILE_CONTENT_TYPES } from "./src/constants/sessionFiles.mjs";
7
- import { writeSessionAttachment } from "./src/services/sessionAttachments/index.mjs";
8
8
  import { createSessionMcpActivityStore } from "./src/services/sessionMcpActivity/index.mjs";
9
9
  import { createSessionMcpConversationStore } from "./src/services/sessionMcpConversations/index.mjs";
10
10
  import { createSessionMcpRegistrationStore } from "./src/services/sessionMcpRegistrationStore/index.mjs";
@@ -6,6 +6,7 @@ const require_serverFacetLoader = require("./src/server/serverFacetLoader.cjs");
6
6
  const require_pluginContributions = require("./src/schemas/pluginContributions.cjs");
7
7
  const require_serverPlugin = require("./src/extensions/serverPlugin.cjs");
8
8
  const require_index$1 = require("./src/services/packageResource/index.cjs");
9
+ const require_index$2 = require("./src/services/sessionAttachments/index.cjs");
9
10
  exports.DOOM_SERVER_BUNDLE_FILE = require_serverBundle.DOOM_SERVER_BUNDLE_FILE;
10
11
  exports.DOOM_SERVER_BUNDLE_VERSION = require_serverBundle.DOOM_SERVER_BUNDLE_VERSION;
11
12
  exports.DOOM_SERVER_FACET_EXPORT = require_serverFacet.DOOM_SERVER_FACET_EXPORT;
@@ -28,3 +29,4 @@ exports.readDoomServerHost = require_serverFacet.readDoomServerHost;
28
29
  exports.readPackageResource = require_index$1.readPackageResource;
29
30
  exports.requireDoomServerHost = require_serverFacet.requireDoomServerHost;
30
31
  exports.resolveServerBundleSource = require_serverFacetLoader.resolveServerBundleSource;
32
+ exports.writeSessionAttachment = require_index$2.writeSessionAttachment;
@@ -5,4 +5,5 @@ import { CreateDoomServerHostOptions, DoomServerHost, createDoomServerHost } fro
5
5
  import { InstallServerFacetsOptions, InstalledServerFacets, LoadServerBundleOptions, LoadedServerBundle, LoadedServerFacet, ServerBundleSource, installServerFacets, loadServerBundle, resolveServerBundleSource } from "./src/server/serverFacetLoader.mjs";
6
6
  import { defineServerPlugin } from "./src/extensions/serverPlugin.mjs";
7
7
  import { packageResourcePath, readPackageResource } from "./src/services/packageResource/index.mjs";
8
- export { type CreateDoomServerHostOptions, DOOM_SERVER_BUNDLE_FILE, DOOM_SERVER_BUNDLE_VERSION, DOOM_SERVER_FACET_EXPORT, DOOM_SERVER_FACET_MANIFEST_FIELD, DOOM_SERVER_HOST_SERVICE, type DeclaredServerFacet, type DoomPluginCommand, type DoomPluginTool, type DoomPluginToolExecution, type DoomPluginToolResult, type DoomServerBundle, type DoomServerBundleEntry, type DoomServerBundleOwner, type DoomServerFacet, DoomServerFacetManifestError, type DoomServerHost, type DoomServerHostService, type DoomServerMethod, type DoomServerPluginContext, type DoomServerPluginDefinition, type DoomServerPluginScope, type DoomServerRegistration, type DoomServerSessionPlugin, type InstallServerFacetsOptions, type InstalledServerFacets, type LoadServerBundleOptions, type LoadedServerBundle, type LoadedServerFacet, type ServerBundleSource, createDoomServerHost, declaredServerFacetsOf, defineCommand, defineServerMethod, defineServerPlugin, defineTool, installServerFacets, isDoomServerFacet, loadServerBundle, orderServerFacets, packageResourcePath, parseDoomServerBundle, readDoomServerHost, readPackageResource, requireDoomServerHost, resolveServerBundleSource };
8
+ import { writeSessionAttachment } from "./src/services/sessionAttachments/index.mjs";
9
+ export { type CreateDoomServerHostOptions, DOOM_SERVER_BUNDLE_FILE, DOOM_SERVER_BUNDLE_VERSION, DOOM_SERVER_FACET_EXPORT, DOOM_SERVER_FACET_MANIFEST_FIELD, DOOM_SERVER_HOST_SERVICE, type DeclaredServerFacet, type DoomPluginCommand, type DoomPluginTool, type DoomPluginToolExecution, type DoomPluginToolResult, type DoomServerBundle, type DoomServerBundleEntry, type DoomServerBundleOwner, type DoomServerFacet, DoomServerFacetManifestError, type DoomServerHost, type DoomServerHostService, type DoomServerMethod, type DoomServerPluginContext, type DoomServerPluginDefinition, type DoomServerPluginScope, type DoomServerRegistration, type DoomServerSessionPlugin, type InstallServerFacetsOptions, type InstalledServerFacets, type LoadServerBundleOptions, type LoadedServerBundle, type LoadedServerFacet, type ServerBundleSource, createDoomServerHost, declaredServerFacetsOf, defineCommand, defineServerMethod, defineServerPlugin, defineTool, installServerFacets, isDoomServerFacet, loadServerBundle, orderServerFacets, packageResourcePath, parseDoomServerBundle, readDoomServerHost, readPackageResource, requireDoomServerHost, resolveServerBundleSource, writeSessionAttachment };
@@ -5,4 +5,5 @@ import { installServerFacets, loadServerBundle, resolveServerBundleSource } from
5
5
  import { defineCommand, defineTool } from "./src/schemas/pluginContributions.mjs";
6
6
  import { defineServerPlugin } from "./src/extensions/serverPlugin.mjs";
7
7
  import { packageResourcePath, readPackageResource } from "./src/services/packageResource/index.mjs";
8
- export { DOOM_SERVER_BUNDLE_FILE, DOOM_SERVER_BUNDLE_VERSION, DOOM_SERVER_FACET_EXPORT, DOOM_SERVER_FACET_MANIFEST_FIELD, DOOM_SERVER_HOST_SERVICE, DoomServerFacetManifestError, createDoomServerHost, declaredServerFacetsOf, defineCommand, defineServerMethod, defineServerPlugin, defineTool, installServerFacets, isDoomServerFacet, loadServerBundle, orderServerFacets, packageResourcePath, parseDoomServerBundle, readDoomServerHost, readPackageResource, requireDoomServerHost, resolveServerBundleSource };
8
+ import { writeSessionAttachment } from "./src/services/sessionAttachments/index.mjs";
9
+ export { DOOM_SERVER_BUNDLE_FILE, DOOM_SERVER_BUNDLE_VERSION, DOOM_SERVER_FACET_EXPORT, DOOM_SERVER_FACET_MANIFEST_FIELD, DOOM_SERVER_HOST_SERVICE, DoomServerFacetManifestError, createDoomServerHost, declaredServerFacetsOf, defineCommand, defineServerMethod, defineServerPlugin, defineTool, installServerFacets, isDoomServerFacet, loadServerBundle, orderServerFacets, packageResourcePath, parseDoomServerBundle, readDoomServerHost, readPackageResource, requireDoomServerHost, resolveServerBundleSource, writeSessionAttachment };
@@ -1 +1 @@
1
- {"version":3,"file":"packageApi.cjs","names":[],"sources":["../../../src/schemas/packageApi.ts"],"sourcesContent":["/**\n * The HTTP surface a package offers its host.\n *\n * A server facet registers one with its host. The host mounts it under the API\n * route prefix, and the package writes routes relative to that mount.\n *\n * The handler is a plain fetch callback so no host and no package is committed\n * to one HTTP framework; a Hono app satisfies it through `app.fetch`.\n */\n\nimport type {\n DoomComputerUseSessionAccess,\n DoomDirectEventBus,\n DoomHubSessionService,\n DoomSessionCommunicationEndpoint,\n DoomSessionActivity,\n DoomSessionContext,\n} from './hubChannel';\nimport type { DoomMcpProjection } from './mcpProjection';\n/** The host-owned sync view a repository-scoped package API may inspect. */\nexport interface DoomRepositorySyncView {\n fresh: boolean;\n reasons: string[];\n mcpProjection?: DoomMcpProjection;\n}\n\n/** Where an API runs: inside one session's server, or in the machine-wide hub. */\nexport type DoomApiScope = 'global' | 'workspace' | 'session';\n\nexport const DOOM_API_SCOPES: readonly DoomApiScope[] = ['global', 'workspace', 'session'];\n\n/** Identity of an independently mounted plugin host. */\nexport type DoomApiMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; sessionId: string };\n\n/** Immutable browser contribution generation paired with a server mount. */\nexport interface DoomWebComposition {\n id: string;\n scope: DoomApiScope;\n revision: number;\n manifestUrl: string;\n rawAssetBaseUrl: string;\n verifiedAssetBaseUrl: string;\n entryPath: string;\n stylePaths: string[];\n channels: string[];\n}\n\n/** Canonical public prefix. Scope selection never falls through to a parent. */\nexport function doomApiMountPath(mount: DoomApiMount & { workspaceId?: string }): string {\n if (mount.scope === 'global') return '/api/plugins';\n if (mount.scope === 'workspace') return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/plugins`;\n if (!mount.workspaceId) throw new Error('A session API path requires its workspace identity.');\n return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/sessions/${encodeURIComponent(mount.sessionId)}/plugins`;\n}\n\n/** Scope addressed by a public WebSocket upgrade. */\nexport type DoomSocketMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; workspaceId: string; sessionId: string };\n\n/** Only canonical resource paths may select a protocol listener. */\nexport function parseDoomSocketPath(pathname: string): DoomSocketMount | undefined {\n if (pathname === '/api/ws') return { scope: 'global' };\n const match = /^\\/api\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?\\/ws$/u.exec(pathname);\n if (!match) return undefined;\n try {\n const workspaceId = decodeURIComponent(match[1]);\n return match[2] === undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'session', workspaceId, sessionId: decodeURIComponent(match[2]) };\n } catch {\n return undefined;\n }\n}\n\n/** The segment an API is mounted under, below this prefix. */\nexport const DOOM_API_ROUTE_PREFIX = '/api/plugins';\n/** Selects the hub API bundle that owns the named cockpit session. */\nexport const DOOM_HUB_API_SESSION_QUERY_PARAM = 'hubSession';\n\n/** Trusted caller headers written only by the cockpit-to-session proxy. */\nexport const DOOM_API_CALLER_LOCALITY_HEADER = 'x-doompi-api-caller-locality';\nexport const DOOM_API_CALLER_DEVICE_ID_HEADER = 'x-doompi-api-caller-device-id';\nexport const DOOM_API_CALLER_STEP_UP_HEADER = 'x-doompi-api-caller-step-up';\nexport const DOOM_API_CALLER_HEADERS = [\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_DEVICE_ID_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n] as const;\n\nexport type DoomApiCallerStepUp = 'not-required' | 'verified' | 'unavailable';\nexport type DoomApiCaller =\n | { locality: 'local'; stepUp: 'not-required' }\n | { locality: 'remote'; deviceId: string; stepUp: DoomApiCallerStepUp };\n\n/** Reads the proxy-authenticated caller identity, rejecting partial or contradictory stamps. */\nexport function doomApiCallerFrom(headers: Headers): DoomApiCaller | undefined {\n const locality = headers.get(DOOM_API_CALLER_LOCALITY_HEADER);\n const deviceId = headers.get(DOOM_API_CALLER_DEVICE_ID_HEADER);\n const stepUp = headers.get(DOOM_API_CALLER_STEP_UP_HEADER);\n if (locality === 'local') {\n return deviceId === null && stepUp === 'not-required' ? { locality, stepUp } : undefined;\n }\n if (\n locality === 'remote' &&\n deviceId !== null &&\n deviceId !== '' &&\n (stepUp === 'not-required' || stepUp === 'verified' || stepUp === 'unavailable')\n ) {\n return { locality, deviceId, stepUp };\n }\n return undefined;\n}\n/**\n * A browser-reachable OAuth redirect the host serves on its own listener.\n *\n * A package brokering third-party OAuth cannot use a loopback redirect when the\n * operator's browser is on another machine: `127.0.0.1` resolves to whichever\n * machine the browser runs on. The host owns a listener that is reachable from\n * wherever the cockpit is being used, so it lends that instead of the package\n * opening a port of its own.\n */\nexport interface DoomOAuthRedirect {\n /** Absolute URL to register as the redirect target, already origin-correct. */\n readonly redirectUri: string;\n /**\n * Accept redirects carrying this state. Must complete before the\n * authorization URL is surfaced, or the redirect races its own reservation.\n */\n reserve(state: string, timeoutMs?: number): Promise<void>;\n /** Resolves once the redirect carrying this state arrives. */\n wait(state: string, timeoutMs?: number): Promise<{ code: string; state: string }>;\n /** Drops a reservation whose flow ended without a redirect. */\n cancel(state: string): void;\n}\n\n/** An exact, host-owned receipt address. Provider IDs are not event cursor positions. */\nexport interface DoomRequestReceiptKey {\n namespace: string;\n activationId: string;\n requestId: string;\n}\n\nexport interface DoomRequestReceipt extends DoomRequestReceiptKey {\n fingerprint: string;\n destination: string;\n transactionId: string;\n outcome: 'reserved' | 'admitted' | 'rejected' | 'uncertain';\n}\n\nexport interface DoomRequestReceiptReservation extends DoomRequestReceiptKey {\n /** Lowercase SHA-256 of the authoritative request text, never the full transcript. */\n fingerprint: string;\n destination: string;\n transactionId: string;\n}\n\nexport type DoomRequestReceiptReserveResult =\n | { kind: 'reserved'; token: string }\n | { kind: 'existing'; receipt: DoomRequestReceipt }\n | { kind: 'conflict'; receipt: DoomRequestReceipt };\n\n/** A global-only receipt capability. A reservation is not an execution receipt. */\nexport interface DoomRequestReceipts {\n reserve(request: DoomRequestReceiptReservation): Promise<DoomRequestReceiptReserveResult>;\n lookup(key: DoomRequestReceiptKey): Promise<DoomRequestReceipt | undefined>;\n finish(\n request: DoomRequestReceiptKey & { token: string; outcome: 'admitted' | 'rejected' | 'uncertain' },\n ): Promise<DoomRequestReceipt>;\n}\n\n/** Permit returned for expensive local work. Calling it releases the slot. */\nexport interface DoomHostExecutionPermit {\n (): void;\n attachProcess?(pid: number): Promise<void>;\n}\n\n/** Host-wide admission for expensive local work. Release only after the owned process exits. */\nexport interface DoomHostExecutionBudget {\n acquire(signal?: AbortSignal): Promise<DoomHostExecutionPermit>;\n getSnapshot(): Readonly<{ running: number; queued: number; limit: number }>;\n}\n\n/** Synchronous host-owned exclusion across media APIs mounted at different scopes. */\nexport interface DoomHostMediaArbitration {\n register(busy: () => boolean): () => void;\n available(busy: () => boolean): boolean;\n}\n\n/** One host's paired agent registrations, shared across its global and session mounts. */\nexport interface DoomPeerAgentRegistry {\n register(sessionId: string, agent: { fetch(request: Request): Promise<Response> }, hubToken: string): () => void;\n get(sessionId: string): { fetch(request: Request): Promise<Response>; hubToken: string } | undefined;\n}\n\n/** Why shareFile rejects while the host has no public tunnel origin. */\nexport const DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE =\n 'Remote access is off, so DoomPi cannot share files with remote MCP servers. Turn it on and retry.';\n\n/**\n * A file published at a short-lived public tunnel URL: 10 minutes, 3 downloads, and gone\n * when the tunnel revision changes. Call revoke as soon as the consumer is done with it.\n */\nexport interface DoomSharedFile {\n /** Bearer link; never log or persist it. */\n url: string;\n fileName: string;\n mimeType: string;\n size: number;\n /** Idempotent. */\n revoke(): void;\n}\n\n/** What the host tells an API about itself when it starts. */\nexport interface DoomApiContext {\n scope: DoomApiScope;\n /** Stable, opaque workspace id, shared by every session and member checkout of the workspace. */\n workspaceId?: string;\n /**\n * The admitted workspace root for a workspace mount. For a session mount it is the checkout\n * the session runs in; read sessionContext for both roots. Absent from global mounts.\n */\n workspaceRoot?: string;\n /** The session's baseline context; present on session mounts whose host knows its workspace. */\n sessionContext?: DoomSessionContext;\n /** Explicit host home, never selected by a remote request. */\n homeDirectory?: string;\n /** The session this host serves; absent for a hub-scoped API. */\n sessionId?: string;\n /** The session's working directory; absent for a hub-scoped API. */\n cwd?: string;\n /** Session environment admitted by the server, never supplied by remote clients. */\n environment?: Readonly<Record<string, string | undefined>>;\n /** Shared only with child processes in this session, never with remote API clients. */\n internalToken?: string;\n /** Shared only with the cockpit hub for privileged cross-session coordination. */\n hubToken?: string;\n /**\n * Resolves a hub-issued opaque repository id to an admitted canonical root.\n * Hub APIs must never accept a browser-supplied filesystem path instead.\n */\n resolveRepository?(repositoryId: string): string | undefined;\n /** Reads the admitted repository's sync projection without exposing its state path. */\n readRepositorySync?(repositoryId: string): DoomRepositorySyncView | undefined;\n /** Admitted workspaces available to this mount. */\n repositories?(): readonly { id: string; name: string; path: string; active: boolean }[];\n /** Publish a successful config write to the owning mount's refresh lifecycle. */\n configurationChanged?(): void;\n /**\n * Borrows the hub's OAuth redirect surface. Undefined when the hub cannot\n * currently serve one, in which case the package keeps its own behaviour.\n */\n oauthRedirect?(): DoomOAuthRedirect | undefined;\n /** Canonical in-process lifecycle for sessions created by this host. */\n sessionService?: DoomHubSessionService;\n /** Host-bound, authenticated inter-session event endpoint for this session. */\n sessionCommunication?: DoomSessionCommunicationEndpoint;\n /** Same-process events shared by session APIs and hub channels. */\n directEvents?: DoomDirectEventBus;\n /**\n * Publishes this session's activity line to every page's rail; undefined clears it.\n * Session mounts only. The last publisher wins.\n */\n publishActivity?(activity: DoomSessionActivity | undefined): void;\n /** Trusted in-process dispatch to an explicitly selected mounted API. No browser authentication is performed here. */\n requestApi?(mount: DoomApiMount, basePath: string, request: Request): Promise<Response>;\n /** Present only on a session mounted by an authenticated Desktop host. */\n computerUse?: DoomComputerUseSessionAccess;\n /** Deliver a typed method to a channel on this exact hub mount, retaining the caller's connection identity. */\n receiveChannel?(sessionId: string, frameType: string, payload: unknown, connectionId: string): boolean;\n /** Host-owned replay evidence, supplied only on the global mount. Never exposed to browsers or agents. */\n requestReceipts?: DoomRequestReceipts;\n /** One host's exclusive media activity, shared across global and session scopes. */\n mediaArbitration?: DoomHostMediaArbitration;\n /** One host-wide heavy-job budget, not a separate budget for every session. */\n executionBudget?: DoomHostExecutionBudget;\n /** Paired agents belonging to this host only. */\n peerAgents?: DoomPeerAgentRegistry;\n /** Machine-owned Remote Control service, mounted only by the global core facet. */\n remoteControl?: { fetch(request: Request): Promise<Response> };\n /**\n * Publishes a file from this session's cwd or attachments at a short-lived tunnel URL.\n * Session mounts only; rejects with DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE while remote access is off.\n * The host asks no consent: the caller must obtain it before passing the URL on.\n */\n shareFile?(path: string, label: string): Promise<DoomSharedFile>;\n onNotice(message: string): void;\n}\n\n/**\n * One running surface. The host strips the mount prefix before calling, so\n * routes are declared relative ('/runners/:id/log') and a package never\n * repeats where it was mounted.\n */\nexport interface DoomApiHandler {\n fetch(request: Request): Response | Promise<Response>;\n close(): void;\n}\n\nexport interface DoomApi {\n /** Segment under /api/plugins/; globally unique across loaded packages. */\n basePath: string;\n start(context: DoomApiContext): DoomApiHandler;\n}\n"],"mappings":";AA6BA,MAAa,kBAA2C;CAAC;CAAU;CAAa;AAAS;;AAsBzF,SAAgB,iBAAiB,OAAwD;CACvF,IAAI,MAAM,UAAU,UAAU,OAAO;CACrC,IAAI,MAAM,UAAU,aAAa,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE;CACjG,IAAI,CAAC,MAAM,aAAa,MAAM,IAAI,MAAM,qDAAqD;CAC7F,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE,YAAY,mBAAmB,MAAM,SAAS,EAAE;AAClH;;AASA,SAAgB,oBAAoB,UAA+C;CACjF,IAAI,aAAa,WAAW,OAAO,EAAE,OAAO,SAAS;CACrD,MAAM,QAAQ,4DAA4D,KAAK,QAAQ;CACvF,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI;EACF,MAAM,cAAc,mBAAmB,MAAM,EAAE;EAC/C,OAAO,MAAM,OAAO,KAAA,IAChB;GAAE,OAAO;GAAa;EAAY,IAClC;GAAE,OAAO;GAAW;GAAa,WAAW,mBAAmB,MAAM,EAAE;EAAE;CAC/E,QAAQ;EACN;CACF;AACF;;AAGA,MAAa,wBAAwB;;AAErC,MAAa,mCAAmC;;AAGhD,MAAa,kCAAkC;AAC/C,MAAa,mCAAmC;AAChD,MAAa,iCAAiC;AAC9C,MAAa,0BAA0B;CACrC;CACA;CACA;AACF;;AAQA,SAAgB,kBAAkB,SAA6C;CAC7E,MAAM,WAAW,QAAQ,IAAI,+BAA+B;CAC5D,MAAM,WAAW,QAAQ,IAAI,gCAAgC;CAC7D,MAAM,SAAS,QAAQ,IAAI,8BAA8B;CACzD,IAAI,aAAa,SACf,OAAO,aAAa,QAAQ,WAAW,iBAAiB;EAAE;EAAU;CAAO,IAAI,KAAA;CAEjF,IACE,aAAa,YACb,aAAa,QACb,aAAa,OACZ,WAAW,kBAAkB,WAAW,cAAc,WAAW,gBAElE,OAAO;EAAE;EAAU;EAAU;CAAO;AAGxC;;AAoFA,MAAa,qCACX"}
1
+ {"version":3,"file":"packageApi.cjs","names":[],"sources":["../../../src/schemas/packageApi.ts"],"sourcesContent":["/**\n * The HTTP surface a package offers its host.\n *\n * A server facet registers one with its host. The host mounts it under the API\n * route prefix, and the package writes routes relative to that mount.\n *\n * The handler is a plain fetch callback so no host and no package is committed\n * to one HTTP framework; a Hono app satisfies it through `app.fetch`.\n */\n\nimport type {\n DoomComputerUseSessionAccess,\n DoomDirectEventBus,\n DoomHubSessionService,\n DoomSessionCommunicationEndpoint,\n DoomSessionActivity,\n DoomSessionContext,\n} from './hubChannel';\nimport type { DoomMcpProjection } from './mcpProjection';\n/** The host-owned sync view a repository-scoped package API may inspect. */\nexport interface DoomRepositorySyncView {\n fresh: boolean;\n reasons: string[];\n mcpProjection?: DoomMcpProjection;\n}\n\n/** Where an API runs: inside one session's server, or in the machine-wide hub. */\nexport type DoomApiScope = 'global' | 'workspace' | 'session';\n\nexport const DOOM_API_SCOPES: readonly DoomApiScope[] = ['global', 'workspace', 'session'];\n\n/** Identity of an independently mounted plugin host. */\nexport type DoomApiMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; sessionId: string };\n\n/** Immutable browser contribution generation paired with a server mount. */\nexport interface DoomWebComposition {\n id: string;\n scope: DoomApiScope;\n revision: number;\n manifestUrl: string;\n rawAssetBaseUrl: string;\n verifiedAssetBaseUrl: string;\n entryPath: string;\n stylePaths: string[];\n channels: string[];\n}\n\n/** Canonical public prefix. Scope selection never falls through to a parent. */\nexport function doomApiMountPath(mount: DoomApiMount & { workspaceId?: string }): string {\n if (mount.scope === 'global') return '/api/plugins';\n if (mount.scope === 'workspace') return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/plugins`;\n if (!mount.workspaceId) throw new Error('A session API path requires its workspace identity.');\n return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/sessions/${encodeURIComponent(mount.sessionId)}/plugins`;\n}\n\n/** Scope addressed by a public WebSocket upgrade. */\nexport type DoomSocketMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; workspaceId: string; sessionId: string };\n\n/** Only canonical resource paths may select a protocol listener. */\nexport function parseDoomSocketPath(pathname: string): DoomSocketMount | undefined {\n if (pathname === '/api/ws') return { scope: 'global' };\n const match = /^\\/api\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?\\/ws$/u.exec(pathname);\n if (!match) return undefined;\n try {\n const workspaceId = decodeURIComponent(match[1]);\n return match[2] === undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'session', workspaceId, sessionId: decodeURIComponent(match[2]) };\n } catch {\n return undefined;\n }\n}\n\n/** The segment an API is mounted under, below this prefix. */\nexport const DOOM_API_ROUTE_PREFIX = '/api/plugins';\n/** Selects the hub API bundle that owns the named cockpit session. */\nexport const DOOM_HUB_API_SESSION_QUERY_PARAM = 'hubSession';\n\n/** Trusted caller headers written only by the cockpit-to-session proxy. */\nexport const DOOM_API_CALLER_LOCALITY_HEADER = 'x-doompi-api-caller-locality';\nexport const DOOM_API_CALLER_DEVICE_ID_HEADER = 'x-doompi-api-caller-device-id';\nexport const DOOM_API_CALLER_STEP_UP_HEADER = 'x-doompi-api-caller-step-up';\nexport const DOOM_API_CALLER_HEADERS = [\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_DEVICE_ID_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n] as const;\n\nexport type DoomApiCallerStepUp = 'not-required' | 'verified' | 'unavailable';\nexport type DoomApiCaller =\n | { locality: 'local'; stepUp: 'not-required' }\n | { locality: 'remote'; deviceId: string; stepUp: DoomApiCallerStepUp };\n\n/** Reads the proxy-authenticated caller identity, rejecting partial or contradictory stamps. */\nexport function doomApiCallerFrom(headers: Headers): DoomApiCaller | undefined {\n const locality = headers.get(DOOM_API_CALLER_LOCALITY_HEADER);\n const deviceId = headers.get(DOOM_API_CALLER_DEVICE_ID_HEADER);\n const stepUp = headers.get(DOOM_API_CALLER_STEP_UP_HEADER);\n if (locality === 'local') {\n return deviceId === null && stepUp === 'not-required' ? { locality, stepUp } : undefined;\n }\n if (\n locality === 'remote' &&\n deviceId !== null &&\n deviceId !== '' &&\n (stepUp === 'not-required' || stepUp === 'verified' || stepUp === 'unavailable')\n ) {\n return { locality, deviceId, stepUp };\n }\n return undefined;\n}\n/**\n * A browser-reachable OAuth redirect the host serves on its own listener.\n *\n * A package brokering third-party OAuth cannot use a loopback redirect when the\n * operator's browser is on another machine: `127.0.0.1` resolves to whichever\n * machine the browser runs on. The host owns a listener that is reachable from\n * wherever the cockpit is being used, so it lends that instead of the package\n * opening a port of its own.\n */\nexport interface DoomOAuthRedirect {\n /** Absolute URL to register as the redirect target, already origin-correct. */\n readonly redirectUri: string;\n /**\n * Accept redirects carrying this state. Must complete before the\n * authorization URL is surfaced, or the redirect races its own reservation.\n */\n reserve(state: string, timeoutMs?: number): Promise<void>;\n /** Resolves once the redirect carrying this state arrives. */\n wait(state: string, timeoutMs?: number): Promise<{ code: string; state: string }>;\n /** Drops a reservation whose flow ended without a redirect. */\n cancel(state: string): void;\n}\n\n/** An exact, host-owned receipt address. Provider IDs are not event cursor positions. */\nexport interface DoomRequestReceiptKey {\n namespace: string;\n activationId: string;\n requestId: string;\n}\n\nexport interface DoomRequestReceipt extends DoomRequestReceiptKey {\n fingerprint: string;\n destination: string;\n transactionId: string;\n outcome: 'reserved' | 'admitted' | 'rejected' | 'uncertain';\n}\n\nexport interface DoomRequestReceiptReservation extends DoomRequestReceiptKey {\n /** Lowercase SHA-256 of the authoritative request text, never the full transcript. */\n fingerprint: string;\n destination: string;\n transactionId: string;\n}\n\nexport type DoomRequestReceiptReserveResult =\n | { kind: 'reserved'; token: string }\n | { kind: 'existing'; receipt: DoomRequestReceipt }\n | { kind: 'conflict'; receipt: DoomRequestReceipt };\n\n/** A global-only receipt capability. A reservation is not an execution receipt. */\nexport interface DoomRequestReceipts {\n reserve(request: DoomRequestReceiptReservation): Promise<DoomRequestReceiptReserveResult>;\n lookup(key: DoomRequestReceiptKey): Promise<DoomRequestReceipt | undefined>;\n finish(\n request: DoomRequestReceiptKey & { token: string; outcome: 'admitted' | 'rejected' | 'uncertain' },\n ): Promise<DoomRequestReceipt>;\n}\n\n/** Permit returned for expensive local work. Calling it releases the slot. */\nexport interface DoomHostExecutionPermit {\n (): void;\n attachProcess?(pid: number): Promise<void>;\n}\n\n/** Host-wide admission for expensive local work. Release only after the owned process exits. */\nexport interface DoomHostExecutionBudget {\n acquire(signal?: AbortSignal): Promise<DoomHostExecutionPermit>;\n getSnapshot(): Readonly<{ running: number; queued: number; limit: number }>;\n}\n\n/** Synchronous host-owned exclusion across media APIs mounted at different scopes. */\nexport interface DoomHostMediaArbitration {\n register(busy: () => boolean): () => void;\n available(busy: () => boolean): boolean;\n}\n\n/** One host's paired agent registrations, shared across its global and session mounts. */\nexport interface DoomPeerAgentRegistry {\n register(sessionId: string, agent: { fetch(request: Request): Promise<Response> }, hubToken: string): () => void;\n get(sessionId: string): { fetch(request: Request): Promise<Response>; hubToken: string } | undefined;\n}\n\n/** Why shareFile rejects while the host has no public tunnel origin. */\nexport const DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE =\n 'Remote access is off, so DoomPi cannot share files with remote MCP servers. Turn it on and retry.';\n\n/**\n * A file published at a short-lived public tunnel URL: 10 minutes, 3 downloads, and gone\n * when the tunnel revision changes. Call revoke as soon as the consumer is done with it.\n */\nexport interface DoomSharedFile {\n /** Bearer link; never log or persist it. */\n url: string;\n fileName: string;\n mimeType: string;\n size: number;\n /** Expiry as epoch milliseconds. */\n expiresAt: number;\n maxDownloads: number;\n /** Idempotent. */\n revoke(): void;\n}\n\n/** What the host tells an API about itself when it starts. */\nexport interface DoomApiContext {\n scope: DoomApiScope;\n /** Stable, opaque workspace id, shared by every session and member checkout of the workspace. */\n workspaceId?: string;\n /**\n * The admitted workspace root for a workspace mount. For a session mount it is the checkout\n * the session runs in; read sessionContext for both roots. Absent from global mounts.\n */\n workspaceRoot?: string;\n /** The session's baseline context; present on session mounts whose host knows its workspace. */\n sessionContext?: DoomSessionContext;\n /** Explicit host home, never selected by a remote request. */\n homeDirectory?: string;\n /** The session this host serves; absent for a hub-scoped API. */\n sessionId?: string;\n /** The session's working directory; absent for a hub-scoped API. */\n cwd?: string;\n /** Session environment admitted by the server, never supplied by remote clients. */\n environment?: Readonly<Record<string, string | undefined>>;\n /** Shared only with child processes in this session, never with remote API clients. */\n internalToken?: string;\n /** Shared only with the cockpit hub for privileged cross-session coordination. */\n hubToken?: string;\n /**\n * Resolves a hub-issued opaque repository id to an admitted canonical root.\n * Hub APIs must never accept a browser-supplied filesystem path instead.\n */\n resolveRepository?(repositoryId: string): string | undefined;\n /** Reads the admitted repository's sync projection without exposing its state path. */\n readRepositorySync?(repositoryId: string): DoomRepositorySyncView | undefined;\n /** Admitted workspaces available to this mount. */\n repositories?(): readonly { id: string; name: string; path: string; active: boolean }[];\n /** Publish a successful config write to the owning mount's refresh lifecycle. */\n configurationChanged?(): void;\n /**\n * Borrows the hub's OAuth redirect surface. Undefined when the hub cannot\n * currently serve one, in which case the package keeps its own behaviour.\n */\n oauthRedirect?(): DoomOAuthRedirect | undefined;\n /** Canonical in-process lifecycle for sessions created by this host. */\n sessionService?: DoomHubSessionService;\n /** Host-bound, authenticated inter-session event endpoint for this session. */\n sessionCommunication?: DoomSessionCommunicationEndpoint;\n /** Same-process events shared by session APIs and hub channels. */\n directEvents?: DoomDirectEventBus;\n /**\n * Publishes this session's activity line to every page's rail; undefined clears it.\n * Session mounts only. The last publisher wins.\n */\n publishActivity?(activity: DoomSessionActivity | undefined): void;\n /** Trusted in-process dispatch to an explicitly selected mounted API. No browser authentication is performed here. */\n requestApi?(mount: DoomApiMount, basePath: string, request: Request): Promise<Response>;\n /** Present only on a session mounted by an authenticated Desktop host. */\n computerUse?: DoomComputerUseSessionAccess;\n /** Deliver a typed method to a channel on this exact hub mount, retaining the caller's connection identity. */\n receiveChannel?(sessionId: string, frameType: string, payload: unknown, connectionId: string): boolean;\n /** Host-owned replay evidence, supplied only on the global mount. Never exposed to browsers or agents. */\n requestReceipts?: DoomRequestReceipts;\n /** One host's exclusive media activity, shared across global and session scopes. */\n mediaArbitration?: DoomHostMediaArbitration;\n /** One host-wide heavy-job budget, not a separate budget for every session. */\n executionBudget?: DoomHostExecutionBudget;\n /** Paired agents belonging to this host only. */\n peerAgents?: DoomPeerAgentRegistry;\n /** Machine-owned Remote Control service, mounted only by the global core facet. */\n remoteControl?: { fetch(request: Request): Promise<Response> };\n /**\n * Publishes a file from this session's cwd or attachments at a short-lived tunnel URL.\n * Session mounts only; rejects with DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE while remote access is off.\n * The host asks no consent: the caller must obtain it before passing the URL on.\n */\n shareFile?(path: string, label: string): Promise<DoomSharedFile>;\n onNotice(message: string): void;\n}\n\n/**\n * One running surface. The host strips the mount prefix before calling, so\n * routes are declared relative ('/runners/:id/log') and a package never\n * repeats where it was mounted.\n */\nexport interface DoomApiHandler {\n fetch(request: Request): Response | Promise<Response>;\n close(): void;\n}\n\nexport interface DoomApi {\n /** Segment under /api/plugins/; globally unique across loaded packages. */\n basePath: string;\n start(context: DoomApiContext): DoomApiHandler;\n}\n"],"mappings":";AA6BA,MAAa,kBAA2C;CAAC;CAAU;CAAa;AAAS;;AAsBzF,SAAgB,iBAAiB,OAAwD;CACvF,IAAI,MAAM,UAAU,UAAU,OAAO;CACrC,IAAI,MAAM,UAAU,aAAa,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE;CACjG,IAAI,CAAC,MAAM,aAAa,MAAM,IAAI,MAAM,qDAAqD;CAC7F,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE,YAAY,mBAAmB,MAAM,SAAS,EAAE;AAClH;;AASA,SAAgB,oBAAoB,UAA+C;CACjF,IAAI,aAAa,WAAW,OAAO,EAAE,OAAO,SAAS;CACrD,MAAM,QAAQ,4DAA4D,KAAK,QAAQ;CACvF,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI;EACF,MAAM,cAAc,mBAAmB,MAAM,EAAE;EAC/C,OAAO,MAAM,OAAO,KAAA,IAChB;GAAE,OAAO;GAAa;EAAY,IAClC;GAAE,OAAO;GAAW;GAAa,WAAW,mBAAmB,MAAM,EAAE;EAAE;CAC/E,QAAQ;EACN;CACF;AACF;;AAGA,MAAa,wBAAwB;;AAErC,MAAa,mCAAmC;;AAGhD,MAAa,kCAAkC;AAC/C,MAAa,mCAAmC;AAChD,MAAa,iCAAiC;AAC9C,MAAa,0BAA0B;CACrC;CACA;CACA;AACF;;AAQA,SAAgB,kBAAkB,SAA6C;CAC7E,MAAM,WAAW,QAAQ,IAAI,+BAA+B;CAC5D,MAAM,WAAW,QAAQ,IAAI,gCAAgC;CAC7D,MAAM,SAAS,QAAQ,IAAI,8BAA8B;CACzD,IAAI,aAAa,SACf,OAAO,aAAa,QAAQ,WAAW,iBAAiB;EAAE;EAAU;CAAO,IAAI,KAAA;CAEjF,IACE,aAAa,YACb,aAAa,QACb,aAAa,OACZ,WAAW,kBAAkB,WAAW,cAAc,WAAW,gBAElE,OAAO;EAAE;EAAU;EAAU;CAAO;AAGxC;;AAoFA,MAAa,qCACX"}
@@ -172,6 +172,9 @@ export interface DoomSharedFile {
172
172
  fileName: string;
173
173
  mimeType: string;
174
174
  size: number;
175
+ /** Expiry as epoch milliseconds. */
176
+ expiresAt: number;
177
+ maxDownloads: number;
175
178
  /** Idempotent. */
176
179
  revoke(): void;
177
180
  }
@@ -1 +1 @@
1
- {"version":3,"file":"packageApi.d.mts","names":[],"sources":["../../../src/schemas/packageApi.ts"],"mappings":";;;;iBAoBiB;EACf;EACA;EACA,gBAAgB;;;YAIN;qBAEC,0BAA0B;;YAG3B;EACN;;EACA;EAAoB;;EACpB;EAAkB;;;iBAGP;EACf;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;;;wBAIc,iBAAiB,OAAO;EAAiB;;;YAQ7C;EACN;;EACA;EAAoB;;EACpB;EAAkB;EAAqB;;;wBAG7B,oBAAoB,mBAAmB;;qBAe1C;;qBAEA;;qBAGA;qBACA;qBACA;qBACA;YAMD;YACA;EACN;EAAmB;;EACnB;EAAoB;EAAkB,QAAQ;;;wBAGpC,kBAAkB,SAAS,UAAU;;;;;;;;;;iBA0BpC;;WAEN;;;;;EAKT,QAAQ,eAAe,qBAAqB;;EAE5C,KAAK,eAAe,qBAAqB;IAAU;IAAc;;;EAEjE,OAAO;;;iBAIQ;EACf;EACA;EACA;;iBAGe,2BAA2B;EAC1C;EACA;EACA;EACA;;iBAGe,sCAAsC;;EAErD;EACA;EACA;;YAGU;EACN;EAAkB;;EAClB;EAAkB,SAAS;;EAC3B;EAAkB,SAAS;;;iBAGhB;EACf,QAAQ,SAAS,gCAAgC,QAAQ;EACzD,OAAO,KAAK,wBAAwB,QAAQ;EAC5C,OACE,SAAS;IAA0B;IAAe;MACjD,QAAQ;;;iBAII;;EAEf,eAAe,cAAc;;;iBAId;EACf,QAAQ,SAAS,cAAc,QAAQ;EACvC,eAAe;IAAW;IAAiB;IAAgB;;;;iBAI5C;EACf,SAAS;EACT,UAAU;;;iBAIK;EACf,SAAS,mBAAmB;IAAS,MAAM,SAAS,UAAU,QAAQ;KAAa;EACnF,IAAI;IAAsB,MAAM,SAAS,UAAU,QAAQ;IAAW;;;;qBAI3D;;;;;iBAOI;;EAEf;EACA;EACA;EACA;;EAEA;;;iBAIe;EACf,OAAO;;EAEP;;;;;EAKA;;EAEA,iBAAiB;;EAEjB;;EAEA;;EAEA;;EAEA,cAAc,SAAS;;EAEvB;;EAEA;;;;;EAKA,mBAAmB;;EAEnB,oBAAoB,uBAAuB;;EAE3C;IAA4B;IAAY;IAAc;IAAc;;;EAEpE;;;;;EAKA,kBAAkB;;EAElB,iBAAiB;;EAEjB,uBAAuB;;EAEvB,eAAe;;;;;EAKf,iBAAiB,UAAU;;EAE3B,YAAY,OAAO,cAAc,kBAAkB,SAAS,UAAU,QAAQ;;EAE9E,cAAc;;EAEd,gBAAgB,mBAAmB,mBAAmB,kBAAkB;;EAExE,kBAAkB;;EAElB,mBAAmB;;EAEnB,kBAAkB;;EAElB,aAAa;;EAEb;IAAkB,MAAM,SAAS,UAAU,QAAQ;;;;;;;EAMnD,WAAW,cAAc,gBAAgB,QAAQ;EACjD,SAAS;;;;;;;iBAQM;EACf,MAAM,SAAS,UAAU,WAAW,QAAQ;EAC5C;;iBAGe;;EAEf;EACA,MAAM,SAAS,iBAAiB"}
1
+ {"version":3,"file":"packageApi.d.mts","names":[],"sources":["../../../src/schemas/packageApi.ts"],"mappings":";;;;iBAoBiB;EACf;EACA;EACA,gBAAgB;;;YAIN;qBAEC,0BAA0B;;YAG3B;EACN;;EACA;EAAoB;;EACpB;EAAkB;;;iBAGP;EACf;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;;;wBAIc,iBAAiB,OAAO;EAAiB;;;YAQ7C;EACN;;EACA;EAAoB;;EACpB;EAAkB;EAAqB;;;wBAG7B,oBAAoB,mBAAmB;;qBAe1C;;qBAEA;;qBAGA;qBACA;qBACA;qBACA;YAMD;YACA;EACN;EAAmB;;EACnB;EAAoB;EAAkB,QAAQ;;;wBAGpC,kBAAkB,SAAS,UAAU;;;;;;;;;;iBA0BpC;;WAEN;;;;;EAKT,QAAQ,eAAe,qBAAqB;;EAE5C,KAAK,eAAe,qBAAqB;IAAU;IAAc;;;EAEjE,OAAO;;;iBAIQ;EACf;EACA;EACA;;iBAGe,2BAA2B;EAC1C;EACA;EACA;EACA;;iBAGe,sCAAsC;;EAErD;EACA;EACA;;YAGU;EACN;EAAkB;;EAClB;EAAkB,SAAS;;EAC3B;EAAkB,SAAS;;;iBAGhB;EACf,QAAQ,SAAS,gCAAgC,QAAQ;EACzD,OAAO,KAAK,wBAAwB,QAAQ;EAC5C,OACE,SAAS;IAA0B;IAAe;MACjD,QAAQ;;;iBAII;;EAEf,eAAe,cAAc;;;iBAId;EACf,QAAQ,SAAS,cAAc,QAAQ;EACvC,eAAe;IAAW;IAAiB;IAAgB;;;;iBAI5C;EACf,SAAS;EACT,UAAU;;;iBAIK;EACf,SAAS,mBAAmB;IAAS,MAAM,SAAS,UAAU,QAAQ;KAAa;EACnF,IAAI;IAAsB,MAAM,SAAS,UAAU,QAAQ;IAAW;;;;qBAI3D;;;;;iBAOI;;EAEf;EACA;EACA;EACA;;EAEA;EACA;;EAEA;;;iBAIe;EACf,OAAO;;EAEP;;;;;EAKA;;EAEA,iBAAiB;;EAEjB;;EAEA;;EAEA;;EAEA,cAAc,SAAS;;EAEvB;;EAEA;;;;;EAKA,mBAAmB;;EAEnB,oBAAoB,uBAAuB;;EAE3C;IAA4B;IAAY;IAAc;IAAc;;;EAEpE;;;;;EAKA,kBAAkB;;EAElB,iBAAiB;;EAEjB,uBAAuB;;EAEvB,eAAe;;;;;EAKf,iBAAiB,UAAU;;EAE3B,YAAY,OAAO,cAAc,kBAAkB,SAAS,UAAU,QAAQ;;EAE9E,cAAc;;EAEd,gBAAgB,mBAAmB,mBAAmB,kBAAkB;;EAExE,kBAAkB;;EAElB,mBAAmB;;EAEnB,kBAAkB;;EAElB,aAAa;;EAEb;IAAkB,MAAM,SAAS,UAAU,QAAQ;;;;;;;EAMnD,WAAW,cAAc,gBAAgB,QAAQ;EACjD,SAAS;;;;;;;iBAQM;EACf,MAAM,SAAS,UAAU,WAAW,QAAQ;EAC5C;;iBAGe;;EAEf;EACA,MAAM,SAAS,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"packageApi.mjs","names":[],"sources":["../../../src/schemas/packageApi.ts"],"sourcesContent":["/**\n * The HTTP surface a package offers its host.\n *\n * A server facet registers one with its host. The host mounts it under the API\n * route prefix, and the package writes routes relative to that mount.\n *\n * The handler is a plain fetch callback so no host and no package is committed\n * to one HTTP framework; a Hono app satisfies it through `app.fetch`.\n */\n\nimport type {\n DoomComputerUseSessionAccess,\n DoomDirectEventBus,\n DoomHubSessionService,\n DoomSessionCommunicationEndpoint,\n DoomSessionActivity,\n DoomSessionContext,\n} from './hubChannel';\nimport type { DoomMcpProjection } from './mcpProjection';\n/** The host-owned sync view a repository-scoped package API may inspect. */\nexport interface DoomRepositorySyncView {\n fresh: boolean;\n reasons: string[];\n mcpProjection?: DoomMcpProjection;\n}\n\n/** Where an API runs: inside one session's server, or in the machine-wide hub. */\nexport type DoomApiScope = 'global' | 'workspace' | 'session';\n\nexport const DOOM_API_SCOPES: readonly DoomApiScope[] = ['global', 'workspace', 'session'];\n\n/** Identity of an independently mounted plugin host. */\nexport type DoomApiMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; sessionId: string };\n\n/** Immutable browser contribution generation paired with a server mount. */\nexport interface DoomWebComposition {\n id: string;\n scope: DoomApiScope;\n revision: number;\n manifestUrl: string;\n rawAssetBaseUrl: string;\n verifiedAssetBaseUrl: string;\n entryPath: string;\n stylePaths: string[];\n channels: string[];\n}\n\n/** Canonical public prefix. Scope selection never falls through to a parent. */\nexport function doomApiMountPath(mount: DoomApiMount & { workspaceId?: string }): string {\n if (mount.scope === 'global') return '/api/plugins';\n if (mount.scope === 'workspace') return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/plugins`;\n if (!mount.workspaceId) throw new Error('A session API path requires its workspace identity.');\n return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/sessions/${encodeURIComponent(mount.sessionId)}/plugins`;\n}\n\n/** Scope addressed by a public WebSocket upgrade. */\nexport type DoomSocketMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; workspaceId: string; sessionId: string };\n\n/** Only canonical resource paths may select a protocol listener. */\nexport function parseDoomSocketPath(pathname: string): DoomSocketMount | undefined {\n if (pathname === '/api/ws') return { scope: 'global' };\n const match = /^\\/api\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?\\/ws$/u.exec(pathname);\n if (!match) return undefined;\n try {\n const workspaceId = decodeURIComponent(match[1]);\n return match[2] === undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'session', workspaceId, sessionId: decodeURIComponent(match[2]) };\n } catch {\n return undefined;\n }\n}\n\n/** The segment an API is mounted under, below this prefix. */\nexport const DOOM_API_ROUTE_PREFIX = '/api/plugins';\n/** Selects the hub API bundle that owns the named cockpit session. */\nexport const DOOM_HUB_API_SESSION_QUERY_PARAM = 'hubSession';\n\n/** Trusted caller headers written only by the cockpit-to-session proxy. */\nexport const DOOM_API_CALLER_LOCALITY_HEADER = 'x-doompi-api-caller-locality';\nexport const DOOM_API_CALLER_DEVICE_ID_HEADER = 'x-doompi-api-caller-device-id';\nexport const DOOM_API_CALLER_STEP_UP_HEADER = 'x-doompi-api-caller-step-up';\nexport const DOOM_API_CALLER_HEADERS = [\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_DEVICE_ID_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n] as const;\n\nexport type DoomApiCallerStepUp = 'not-required' | 'verified' | 'unavailable';\nexport type DoomApiCaller =\n | { locality: 'local'; stepUp: 'not-required' }\n | { locality: 'remote'; deviceId: string; stepUp: DoomApiCallerStepUp };\n\n/** Reads the proxy-authenticated caller identity, rejecting partial or contradictory stamps. */\nexport function doomApiCallerFrom(headers: Headers): DoomApiCaller | undefined {\n const locality = headers.get(DOOM_API_CALLER_LOCALITY_HEADER);\n const deviceId = headers.get(DOOM_API_CALLER_DEVICE_ID_HEADER);\n const stepUp = headers.get(DOOM_API_CALLER_STEP_UP_HEADER);\n if (locality === 'local') {\n return deviceId === null && stepUp === 'not-required' ? { locality, stepUp } : undefined;\n }\n if (\n locality === 'remote' &&\n deviceId !== null &&\n deviceId !== '' &&\n (stepUp === 'not-required' || stepUp === 'verified' || stepUp === 'unavailable')\n ) {\n return { locality, deviceId, stepUp };\n }\n return undefined;\n}\n/**\n * A browser-reachable OAuth redirect the host serves on its own listener.\n *\n * A package brokering third-party OAuth cannot use a loopback redirect when the\n * operator's browser is on another machine: `127.0.0.1` resolves to whichever\n * machine the browser runs on. The host owns a listener that is reachable from\n * wherever the cockpit is being used, so it lends that instead of the package\n * opening a port of its own.\n */\nexport interface DoomOAuthRedirect {\n /** Absolute URL to register as the redirect target, already origin-correct. */\n readonly redirectUri: string;\n /**\n * Accept redirects carrying this state. Must complete before the\n * authorization URL is surfaced, or the redirect races its own reservation.\n */\n reserve(state: string, timeoutMs?: number): Promise<void>;\n /** Resolves once the redirect carrying this state arrives. */\n wait(state: string, timeoutMs?: number): Promise<{ code: string; state: string }>;\n /** Drops a reservation whose flow ended without a redirect. */\n cancel(state: string): void;\n}\n\n/** An exact, host-owned receipt address. Provider IDs are not event cursor positions. */\nexport interface DoomRequestReceiptKey {\n namespace: string;\n activationId: string;\n requestId: string;\n}\n\nexport interface DoomRequestReceipt extends DoomRequestReceiptKey {\n fingerprint: string;\n destination: string;\n transactionId: string;\n outcome: 'reserved' | 'admitted' | 'rejected' | 'uncertain';\n}\n\nexport interface DoomRequestReceiptReservation extends DoomRequestReceiptKey {\n /** Lowercase SHA-256 of the authoritative request text, never the full transcript. */\n fingerprint: string;\n destination: string;\n transactionId: string;\n}\n\nexport type DoomRequestReceiptReserveResult =\n | { kind: 'reserved'; token: string }\n | { kind: 'existing'; receipt: DoomRequestReceipt }\n | { kind: 'conflict'; receipt: DoomRequestReceipt };\n\n/** A global-only receipt capability. A reservation is not an execution receipt. */\nexport interface DoomRequestReceipts {\n reserve(request: DoomRequestReceiptReservation): Promise<DoomRequestReceiptReserveResult>;\n lookup(key: DoomRequestReceiptKey): Promise<DoomRequestReceipt | undefined>;\n finish(\n request: DoomRequestReceiptKey & { token: string; outcome: 'admitted' | 'rejected' | 'uncertain' },\n ): Promise<DoomRequestReceipt>;\n}\n\n/** Permit returned for expensive local work. Calling it releases the slot. */\nexport interface DoomHostExecutionPermit {\n (): void;\n attachProcess?(pid: number): Promise<void>;\n}\n\n/** Host-wide admission for expensive local work. Release only after the owned process exits. */\nexport interface DoomHostExecutionBudget {\n acquire(signal?: AbortSignal): Promise<DoomHostExecutionPermit>;\n getSnapshot(): Readonly<{ running: number; queued: number; limit: number }>;\n}\n\n/** Synchronous host-owned exclusion across media APIs mounted at different scopes. */\nexport interface DoomHostMediaArbitration {\n register(busy: () => boolean): () => void;\n available(busy: () => boolean): boolean;\n}\n\n/** One host's paired agent registrations, shared across its global and session mounts. */\nexport interface DoomPeerAgentRegistry {\n register(sessionId: string, agent: { fetch(request: Request): Promise<Response> }, hubToken: string): () => void;\n get(sessionId: string): { fetch(request: Request): Promise<Response>; hubToken: string } | undefined;\n}\n\n/** Why shareFile rejects while the host has no public tunnel origin. */\nexport const DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE =\n 'Remote access is off, so DoomPi cannot share files with remote MCP servers. Turn it on and retry.';\n\n/**\n * A file published at a short-lived public tunnel URL: 10 minutes, 3 downloads, and gone\n * when the tunnel revision changes. Call revoke as soon as the consumer is done with it.\n */\nexport interface DoomSharedFile {\n /** Bearer link; never log or persist it. */\n url: string;\n fileName: string;\n mimeType: string;\n size: number;\n /** Idempotent. */\n revoke(): void;\n}\n\n/** What the host tells an API about itself when it starts. */\nexport interface DoomApiContext {\n scope: DoomApiScope;\n /** Stable, opaque workspace id, shared by every session and member checkout of the workspace. */\n workspaceId?: string;\n /**\n * The admitted workspace root for a workspace mount. For a session mount it is the checkout\n * the session runs in; read sessionContext for both roots. Absent from global mounts.\n */\n workspaceRoot?: string;\n /** The session's baseline context; present on session mounts whose host knows its workspace. */\n sessionContext?: DoomSessionContext;\n /** Explicit host home, never selected by a remote request. */\n homeDirectory?: string;\n /** The session this host serves; absent for a hub-scoped API. */\n sessionId?: string;\n /** The session's working directory; absent for a hub-scoped API. */\n cwd?: string;\n /** Session environment admitted by the server, never supplied by remote clients. */\n environment?: Readonly<Record<string, string | undefined>>;\n /** Shared only with child processes in this session, never with remote API clients. */\n internalToken?: string;\n /** Shared only with the cockpit hub for privileged cross-session coordination. */\n hubToken?: string;\n /**\n * Resolves a hub-issued opaque repository id to an admitted canonical root.\n * Hub APIs must never accept a browser-supplied filesystem path instead.\n */\n resolveRepository?(repositoryId: string): string | undefined;\n /** Reads the admitted repository's sync projection without exposing its state path. */\n readRepositorySync?(repositoryId: string): DoomRepositorySyncView | undefined;\n /** Admitted workspaces available to this mount. */\n repositories?(): readonly { id: string; name: string; path: string; active: boolean }[];\n /** Publish a successful config write to the owning mount's refresh lifecycle. */\n configurationChanged?(): void;\n /**\n * Borrows the hub's OAuth redirect surface. Undefined when the hub cannot\n * currently serve one, in which case the package keeps its own behaviour.\n */\n oauthRedirect?(): DoomOAuthRedirect | undefined;\n /** Canonical in-process lifecycle for sessions created by this host. */\n sessionService?: DoomHubSessionService;\n /** Host-bound, authenticated inter-session event endpoint for this session. */\n sessionCommunication?: DoomSessionCommunicationEndpoint;\n /** Same-process events shared by session APIs and hub channels. */\n directEvents?: DoomDirectEventBus;\n /**\n * Publishes this session's activity line to every page's rail; undefined clears it.\n * Session mounts only. The last publisher wins.\n */\n publishActivity?(activity: DoomSessionActivity | undefined): void;\n /** Trusted in-process dispatch to an explicitly selected mounted API. No browser authentication is performed here. */\n requestApi?(mount: DoomApiMount, basePath: string, request: Request): Promise<Response>;\n /** Present only on a session mounted by an authenticated Desktop host. */\n computerUse?: DoomComputerUseSessionAccess;\n /** Deliver a typed method to a channel on this exact hub mount, retaining the caller's connection identity. */\n receiveChannel?(sessionId: string, frameType: string, payload: unknown, connectionId: string): boolean;\n /** Host-owned replay evidence, supplied only on the global mount. Never exposed to browsers or agents. */\n requestReceipts?: DoomRequestReceipts;\n /** One host's exclusive media activity, shared across global and session scopes. */\n mediaArbitration?: DoomHostMediaArbitration;\n /** One host-wide heavy-job budget, not a separate budget for every session. */\n executionBudget?: DoomHostExecutionBudget;\n /** Paired agents belonging to this host only. */\n peerAgents?: DoomPeerAgentRegistry;\n /** Machine-owned Remote Control service, mounted only by the global core facet. */\n remoteControl?: { fetch(request: Request): Promise<Response> };\n /**\n * Publishes a file from this session's cwd or attachments at a short-lived tunnel URL.\n * Session mounts only; rejects with DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE while remote access is off.\n * The host asks no consent: the caller must obtain it before passing the URL on.\n */\n shareFile?(path: string, label: string): Promise<DoomSharedFile>;\n onNotice(message: string): void;\n}\n\n/**\n * One running surface. The host strips the mount prefix before calling, so\n * routes are declared relative ('/runners/:id/log') and a package never\n * repeats where it was mounted.\n */\nexport interface DoomApiHandler {\n fetch(request: Request): Response | Promise<Response>;\n close(): void;\n}\n\nexport interface DoomApi {\n /** Segment under /api/plugins/; globally unique across loaded packages. */\n basePath: string;\n start(context: DoomApiContext): DoomApiHandler;\n}\n"],"mappings":";AA6BA,MAAa,kBAA2C;CAAC;CAAU;CAAa;AAAS;;AAsBzF,SAAgB,iBAAiB,OAAwD;CACvF,IAAI,MAAM,UAAU,UAAU,OAAO;CACrC,IAAI,MAAM,UAAU,aAAa,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE;CACjG,IAAI,CAAC,MAAM,aAAa,MAAM,IAAI,MAAM,qDAAqD;CAC7F,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE,YAAY,mBAAmB,MAAM,SAAS,EAAE;AAClH;;AASA,SAAgB,oBAAoB,UAA+C;CACjF,IAAI,aAAa,WAAW,OAAO,EAAE,OAAO,SAAS;CACrD,MAAM,QAAQ,4DAA4D,KAAK,QAAQ;CACvF,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI;EACF,MAAM,cAAc,mBAAmB,MAAM,EAAE;EAC/C,OAAO,MAAM,OAAO,KAAA,IAChB;GAAE,OAAO;GAAa;EAAY,IAClC;GAAE,OAAO;GAAW;GAAa,WAAW,mBAAmB,MAAM,EAAE;EAAE;CAC/E,QAAQ;EACN;CACF;AACF;;AAGA,MAAa,wBAAwB;;AAErC,MAAa,mCAAmC;;AAGhD,MAAa,kCAAkC;AAC/C,MAAa,mCAAmC;AAChD,MAAa,iCAAiC;AAC9C,MAAa,0BAA0B;CACrC;CACA;CACA;AACF;;AAQA,SAAgB,kBAAkB,SAA6C;CAC7E,MAAM,WAAW,QAAQ,IAAI,+BAA+B;CAC5D,MAAM,WAAW,QAAQ,IAAI,gCAAgC;CAC7D,MAAM,SAAS,QAAQ,IAAI,8BAA8B;CACzD,IAAI,aAAa,SACf,OAAO,aAAa,QAAQ,WAAW,iBAAiB;EAAE;EAAU;CAAO,IAAI,KAAA;CAEjF,IACE,aAAa,YACb,aAAa,QACb,aAAa,OACZ,WAAW,kBAAkB,WAAW,cAAc,WAAW,gBAElE,OAAO;EAAE;EAAU;EAAU;CAAO;AAGxC;;AAoFA,MAAa,qCACX"}
1
+ {"version":3,"file":"packageApi.mjs","names":[],"sources":["../../../src/schemas/packageApi.ts"],"sourcesContent":["/**\n * The HTTP surface a package offers its host.\n *\n * A server facet registers one with its host. The host mounts it under the API\n * route prefix, and the package writes routes relative to that mount.\n *\n * The handler is a plain fetch callback so no host and no package is committed\n * to one HTTP framework; a Hono app satisfies it through `app.fetch`.\n */\n\nimport type {\n DoomComputerUseSessionAccess,\n DoomDirectEventBus,\n DoomHubSessionService,\n DoomSessionCommunicationEndpoint,\n DoomSessionActivity,\n DoomSessionContext,\n} from './hubChannel';\nimport type { DoomMcpProjection } from './mcpProjection';\n/** The host-owned sync view a repository-scoped package API may inspect. */\nexport interface DoomRepositorySyncView {\n fresh: boolean;\n reasons: string[];\n mcpProjection?: DoomMcpProjection;\n}\n\n/** Where an API runs: inside one session's server, or in the machine-wide hub. */\nexport type DoomApiScope = 'global' | 'workspace' | 'session';\n\nexport const DOOM_API_SCOPES: readonly DoomApiScope[] = ['global', 'workspace', 'session'];\n\n/** Identity of an independently mounted plugin host. */\nexport type DoomApiMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; sessionId: string };\n\n/** Immutable browser contribution generation paired with a server mount. */\nexport interface DoomWebComposition {\n id: string;\n scope: DoomApiScope;\n revision: number;\n manifestUrl: string;\n rawAssetBaseUrl: string;\n verifiedAssetBaseUrl: string;\n entryPath: string;\n stylePaths: string[];\n channels: string[];\n}\n\n/** Canonical public prefix. Scope selection never falls through to a parent. */\nexport function doomApiMountPath(mount: DoomApiMount & { workspaceId?: string }): string {\n if (mount.scope === 'global') return '/api/plugins';\n if (mount.scope === 'workspace') return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/plugins`;\n if (!mount.workspaceId) throw new Error('A session API path requires its workspace identity.');\n return `/api/workspaces/${encodeURIComponent(mount.workspaceId)}/sessions/${encodeURIComponent(mount.sessionId)}/plugins`;\n}\n\n/** Scope addressed by a public WebSocket upgrade. */\nexport type DoomSocketMount =\n | { scope: 'global' }\n | { scope: 'workspace'; workspaceId: string }\n | { scope: 'session'; workspaceId: string; sessionId: string };\n\n/** Only canonical resource paths may select a protocol listener. */\nexport function parseDoomSocketPath(pathname: string): DoomSocketMount | undefined {\n if (pathname === '/api/ws') return { scope: 'global' };\n const match = /^\\/api\\/workspaces\\/([^/]+)(?:\\/sessions\\/([^/]+))?\\/ws$/u.exec(pathname);\n if (!match) return undefined;\n try {\n const workspaceId = decodeURIComponent(match[1]);\n return match[2] === undefined\n ? { scope: 'workspace', workspaceId }\n : { scope: 'session', workspaceId, sessionId: decodeURIComponent(match[2]) };\n } catch {\n return undefined;\n }\n}\n\n/** The segment an API is mounted under, below this prefix. */\nexport const DOOM_API_ROUTE_PREFIX = '/api/plugins';\n/** Selects the hub API bundle that owns the named cockpit session. */\nexport const DOOM_HUB_API_SESSION_QUERY_PARAM = 'hubSession';\n\n/** Trusted caller headers written only by the cockpit-to-session proxy. */\nexport const DOOM_API_CALLER_LOCALITY_HEADER = 'x-doompi-api-caller-locality';\nexport const DOOM_API_CALLER_DEVICE_ID_HEADER = 'x-doompi-api-caller-device-id';\nexport const DOOM_API_CALLER_STEP_UP_HEADER = 'x-doompi-api-caller-step-up';\nexport const DOOM_API_CALLER_HEADERS = [\n DOOM_API_CALLER_LOCALITY_HEADER,\n DOOM_API_CALLER_DEVICE_ID_HEADER,\n DOOM_API_CALLER_STEP_UP_HEADER,\n] as const;\n\nexport type DoomApiCallerStepUp = 'not-required' | 'verified' | 'unavailable';\nexport type DoomApiCaller =\n | { locality: 'local'; stepUp: 'not-required' }\n | { locality: 'remote'; deviceId: string; stepUp: DoomApiCallerStepUp };\n\n/** Reads the proxy-authenticated caller identity, rejecting partial or contradictory stamps. */\nexport function doomApiCallerFrom(headers: Headers): DoomApiCaller | undefined {\n const locality = headers.get(DOOM_API_CALLER_LOCALITY_HEADER);\n const deviceId = headers.get(DOOM_API_CALLER_DEVICE_ID_HEADER);\n const stepUp = headers.get(DOOM_API_CALLER_STEP_UP_HEADER);\n if (locality === 'local') {\n return deviceId === null && stepUp === 'not-required' ? { locality, stepUp } : undefined;\n }\n if (\n locality === 'remote' &&\n deviceId !== null &&\n deviceId !== '' &&\n (stepUp === 'not-required' || stepUp === 'verified' || stepUp === 'unavailable')\n ) {\n return { locality, deviceId, stepUp };\n }\n return undefined;\n}\n/**\n * A browser-reachable OAuth redirect the host serves on its own listener.\n *\n * A package brokering third-party OAuth cannot use a loopback redirect when the\n * operator's browser is on another machine: `127.0.0.1` resolves to whichever\n * machine the browser runs on. The host owns a listener that is reachable from\n * wherever the cockpit is being used, so it lends that instead of the package\n * opening a port of its own.\n */\nexport interface DoomOAuthRedirect {\n /** Absolute URL to register as the redirect target, already origin-correct. */\n readonly redirectUri: string;\n /**\n * Accept redirects carrying this state. Must complete before the\n * authorization URL is surfaced, or the redirect races its own reservation.\n */\n reserve(state: string, timeoutMs?: number): Promise<void>;\n /** Resolves once the redirect carrying this state arrives. */\n wait(state: string, timeoutMs?: number): Promise<{ code: string; state: string }>;\n /** Drops a reservation whose flow ended without a redirect. */\n cancel(state: string): void;\n}\n\n/** An exact, host-owned receipt address. Provider IDs are not event cursor positions. */\nexport interface DoomRequestReceiptKey {\n namespace: string;\n activationId: string;\n requestId: string;\n}\n\nexport interface DoomRequestReceipt extends DoomRequestReceiptKey {\n fingerprint: string;\n destination: string;\n transactionId: string;\n outcome: 'reserved' | 'admitted' | 'rejected' | 'uncertain';\n}\n\nexport interface DoomRequestReceiptReservation extends DoomRequestReceiptKey {\n /** Lowercase SHA-256 of the authoritative request text, never the full transcript. */\n fingerprint: string;\n destination: string;\n transactionId: string;\n}\n\nexport type DoomRequestReceiptReserveResult =\n | { kind: 'reserved'; token: string }\n | { kind: 'existing'; receipt: DoomRequestReceipt }\n | { kind: 'conflict'; receipt: DoomRequestReceipt };\n\n/** A global-only receipt capability. A reservation is not an execution receipt. */\nexport interface DoomRequestReceipts {\n reserve(request: DoomRequestReceiptReservation): Promise<DoomRequestReceiptReserveResult>;\n lookup(key: DoomRequestReceiptKey): Promise<DoomRequestReceipt | undefined>;\n finish(\n request: DoomRequestReceiptKey & { token: string; outcome: 'admitted' | 'rejected' | 'uncertain' },\n ): Promise<DoomRequestReceipt>;\n}\n\n/** Permit returned for expensive local work. Calling it releases the slot. */\nexport interface DoomHostExecutionPermit {\n (): void;\n attachProcess?(pid: number): Promise<void>;\n}\n\n/** Host-wide admission for expensive local work. Release only after the owned process exits. */\nexport interface DoomHostExecutionBudget {\n acquire(signal?: AbortSignal): Promise<DoomHostExecutionPermit>;\n getSnapshot(): Readonly<{ running: number; queued: number; limit: number }>;\n}\n\n/** Synchronous host-owned exclusion across media APIs mounted at different scopes. */\nexport interface DoomHostMediaArbitration {\n register(busy: () => boolean): () => void;\n available(busy: () => boolean): boolean;\n}\n\n/** One host's paired agent registrations, shared across its global and session mounts. */\nexport interface DoomPeerAgentRegistry {\n register(sessionId: string, agent: { fetch(request: Request): Promise<Response> }, hubToken: string): () => void;\n get(sessionId: string): { fetch(request: Request): Promise<Response>; hubToken: string } | undefined;\n}\n\n/** Why shareFile rejects while the host has no public tunnel origin. */\nexport const DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE =\n 'Remote access is off, so DoomPi cannot share files with remote MCP servers. Turn it on and retry.';\n\n/**\n * A file published at a short-lived public tunnel URL: 10 minutes, 3 downloads, and gone\n * when the tunnel revision changes. Call revoke as soon as the consumer is done with it.\n */\nexport interface DoomSharedFile {\n /** Bearer link; never log or persist it. */\n url: string;\n fileName: string;\n mimeType: string;\n size: number;\n /** Expiry as epoch milliseconds. */\n expiresAt: number;\n maxDownloads: number;\n /** Idempotent. */\n revoke(): void;\n}\n\n/** What the host tells an API about itself when it starts. */\nexport interface DoomApiContext {\n scope: DoomApiScope;\n /** Stable, opaque workspace id, shared by every session and member checkout of the workspace. */\n workspaceId?: string;\n /**\n * The admitted workspace root for a workspace mount. For a session mount it is the checkout\n * the session runs in; read sessionContext for both roots. Absent from global mounts.\n */\n workspaceRoot?: string;\n /** The session's baseline context; present on session mounts whose host knows its workspace. */\n sessionContext?: DoomSessionContext;\n /** Explicit host home, never selected by a remote request. */\n homeDirectory?: string;\n /** The session this host serves; absent for a hub-scoped API. */\n sessionId?: string;\n /** The session's working directory; absent for a hub-scoped API. */\n cwd?: string;\n /** Session environment admitted by the server, never supplied by remote clients. */\n environment?: Readonly<Record<string, string | undefined>>;\n /** Shared only with child processes in this session, never with remote API clients. */\n internalToken?: string;\n /** Shared only with the cockpit hub for privileged cross-session coordination. */\n hubToken?: string;\n /**\n * Resolves a hub-issued opaque repository id to an admitted canonical root.\n * Hub APIs must never accept a browser-supplied filesystem path instead.\n */\n resolveRepository?(repositoryId: string): string | undefined;\n /** Reads the admitted repository's sync projection without exposing its state path. */\n readRepositorySync?(repositoryId: string): DoomRepositorySyncView | undefined;\n /** Admitted workspaces available to this mount. */\n repositories?(): readonly { id: string; name: string; path: string; active: boolean }[];\n /** Publish a successful config write to the owning mount's refresh lifecycle. */\n configurationChanged?(): void;\n /**\n * Borrows the hub's OAuth redirect surface. Undefined when the hub cannot\n * currently serve one, in which case the package keeps its own behaviour.\n */\n oauthRedirect?(): DoomOAuthRedirect | undefined;\n /** Canonical in-process lifecycle for sessions created by this host. */\n sessionService?: DoomHubSessionService;\n /** Host-bound, authenticated inter-session event endpoint for this session. */\n sessionCommunication?: DoomSessionCommunicationEndpoint;\n /** Same-process events shared by session APIs and hub channels. */\n directEvents?: DoomDirectEventBus;\n /**\n * Publishes this session's activity line to every page's rail; undefined clears it.\n * Session mounts only. The last publisher wins.\n */\n publishActivity?(activity: DoomSessionActivity | undefined): void;\n /** Trusted in-process dispatch to an explicitly selected mounted API. No browser authentication is performed here. */\n requestApi?(mount: DoomApiMount, basePath: string, request: Request): Promise<Response>;\n /** Present only on a session mounted by an authenticated Desktop host. */\n computerUse?: DoomComputerUseSessionAccess;\n /** Deliver a typed method to a channel on this exact hub mount, retaining the caller's connection identity. */\n receiveChannel?(sessionId: string, frameType: string, payload: unknown, connectionId: string): boolean;\n /** Host-owned replay evidence, supplied only on the global mount. Never exposed to browsers or agents. */\n requestReceipts?: DoomRequestReceipts;\n /** One host's exclusive media activity, shared across global and session scopes. */\n mediaArbitration?: DoomHostMediaArbitration;\n /** One host-wide heavy-job budget, not a separate budget for every session. */\n executionBudget?: DoomHostExecutionBudget;\n /** Paired agents belonging to this host only. */\n peerAgents?: DoomPeerAgentRegistry;\n /** Machine-owned Remote Control service, mounted only by the global core facet. */\n remoteControl?: { fetch(request: Request): Promise<Response> };\n /**\n * Publishes a file from this session's cwd or attachments at a short-lived tunnel URL.\n * Session mounts only; rejects with DOOM_SHARE_FILE_REMOTE_OFF_MESSAGE while remote access is off.\n * The host asks no consent: the caller must obtain it before passing the URL on.\n */\n shareFile?(path: string, label: string): Promise<DoomSharedFile>;\n onNotice(message: string): void;\n}\n\n/**\n * One running surface. The host strips the mount prefix before calling, so\n * routes are declared relative ('/runners/:id/log') and a package never\n * repeats where it was mounted.\n */\nexport interface DoomApiHandler {\n fetch(request: Request): Response | Promise<Response>;\n close(): void;\n}\n\nexport interface DoomApi {\n /** Segment under /api/plugins/; globally unique across loaded packages. */\n basePath: string;\n start(context: DoomApiContext): DoomApiHandler;\n}\n"],"mappings":";AA6BA,MAAa,kBAA2C;CAAC;CAAU;CAAa;AAAS;;AAsBzF,SAAgB,iBAAiB,OAAwD;CACvF,IAAI,MAAM,UAAU,UAAU,OAAO;CACrC,IAAI,MAAM,UAAU,aAAa,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE;CACjG,IAAI,CAAC,MAAM,aAAa,MAAM,IAAI,MAAM,qDAAqD;CAC7F,OAAO,mBAAmB,mBAAmB,MAAM,WAAW,EAAE,YAAY,mBAAmB,MAAM,SAAS,EAAE;AAClH;;AASA,SAAgB,oBAAoB,UAA+C;CACjF,IAAI,aAAa,WAAW,OAAO,EAAE,OAAO,SAAS;CACrD,MAAM,QAAQ,4DAA4D,KAAK,QAAQ;CACvF,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI;EACF,MAAM,cAAc,mBAAmB,MAAM,EAAE;EAC/C,OAAO,MAAM,OAAO,KAAA,IAChB;GAAE,OAAO;GAAa;EAAY,IAClC;GAAE,OAAO;GAAW;GAAa,WAAW,mBAAmB,MAAM,EAAE;EAAE;CAC/E,QAAQ;EACN;CACF;AACF;;AAGA,MAAa,wBAAwB;;AAErC,MAAa,mCAAmC;;AAGhD,MAAa,kCAAkC;AAC/C,MAAa,mCAAmC;AAChD,MAAa,iCAAiC;AAC9C,MAAa,0BAA0B;CACrC;CACA;CACA;AACF;;AAQA,SAAgB,kBAAkB,SAA6C;CAC7E,MAAM,WAAW,QAAQ,IAAI,+BAA+B;CAC5D,MAAM,WAAW,QAAQ,IAAI,gCAAgC;CAC7D,MAAM,SAAS,QAAQ,IAAI,8BAA8B;CACzD,IAAI,aAAa,SACf,OAAO,aAAa,QAAQ,WAAW,iBAAiB;EAAE;EAAU;CAAO,IAAI,KAAA;CAEjF,IACE,aAAa,YACb,aAAa,QACb,aAAa,OACZ,WAAW,kBAAkB,WAAW,cAAc,WAAW,gBAElE,OAAO;EAAE;EAAU;EAAU;CAAO;AAGxC;;AAoFA,MAAa,qCACX"}
@@ -52,6 +52,10 @@ const SESSION_MCP_EXTRA_TOOLS = [
52
52
  _meta: { ui: { visibility: ["model"] } }
53
53
  }
54
54
  ];
55
+ function presentationMeta(meta, presentation) {
56
+ if (presentation === "app" || meta === void 0) return meta;
57
+ return Object.fromEntries(Object.entries(meta).filter(([key]) => key !== "ui" && !key.startsWith("openai/") || key === "openai/fileParams").filter(([key]) => key !== "doompi/widget" && key !== "doompi/toolName"));
58
+ }
55
59
  function publicTool(tool) {
56
60
  return {
57
61
  name: tool.name,
@@ -72,8 +76,8 @@ function publicTool(tool) {
72
76
  function grantedExtraTools(grant) {
73
77
  return grant.scope === "session" ? SESSION_MCP_EXTRA_TOOLS : SESSION_MCP_EXTRA_TOOLS.filter((tool) => grant.tools.includes(tool.name));
74
78
  }
75
- function extraTools(baseline, tools) {
76
- return tools.map(publicTool).filter((tool) => !SESSION_MCP_EXTRA_TOOLS.some((wrapper) => wrapper.name === tool.name) && !(0, node_util.isDeepStrictEqual)(baseline.tools.find((original) => original.name === tool.name), tool));
79
+ function extraTools(baseline, tools, presentTool) {
80
+ return tools.map(publicTool).map(presentTool).filter((tool) => !SESSION_MCP_EXTRA_TOOLS.some((wrapper) => wrapper.name === tool.name) && !(0, node_util.isDeepStrictEqual)(baseline.tools.find((original) => original.name === tool.name), tool));
77
81
  }
78
82
  /** Remote agents see `${prefix}_${name}`; grants, baselines, and history keep internal names. */
79
83
  function sessionMcpWireName(prefix, name) {
@@ -171,7 +175,14 @@ function createSessionMcpHttpHandler(options) {
171
175
  if (audience.protocol !== "https:" || audience.username !== "" || audience.password !== "" || audience.search !== "" || audience.hash !== "") throw new Error("Session MCP audience must be an absolute HTTPS URL without credentials, a query, or a fragment.");
172
176
  const exactAudience = audience.href;
173
177
  if (options.pathToken !== void 0 && !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/u.test(options.pathToken)) throw new Error("Session MCP path token must be a compact JWT.");
174
- const exactResource = options.pathToken === void 0 ? exactAudience : `${exactAudience}/${options.pathToken}`;
178
+ const presentation = options.presentation ?? "pure";
179
+ const resourceAudience = presentation === "app" ? exactAudience.replace(/\/mcp$/u, "/mcp-app") : exactAudience;
180
+ const presentTool = (tool) => ({
181
+ ...tool,
182
+ _meta: presentationMeta(tool._meta, presentation)
183
+ });
184
+ const baselineKey = (clientId) => JSON.stringify([presentation, clientId]);
185
+ const exactResource = options.pathToken === void 0 ? resourceAudience : `${resourceAudience}/${options.pathToken}`;
175
186
  const authenticate = options.pathToken === void 0 ? options.authorization.authenticateAccessToken : options.authorization.authenticateUrlToken;
176
187
  const operations = options.operations ?? /* @__PURE__ */ new Map();
177
188
  const baselines = options.baselines ?? /* @__PURE__ */ new Map();
@@ -232,7 +243,7 @@ function createSessionMcpHttpHandler(options) {
232
243
  const active = await authorizeOperation();
233
244
  await options.onVerified?.(active.grant);
234
245
  const { tools, skills } = grantedSurface(active.grant, active.target.toolSurface);
235
- const parentTools = tools.map(publicTool);
246
+ const parentTools = tools.map(publicTool).map(presentTool);
236
247
  const wrappers = grantedExtraTools(active.grant);
237
248
  const baseline = structuredClone({
238
249
  tools: parentTools,
@@ -242,8 +253,8 @@ function createSessionMcpHttpHandler(options) {
242
253
  }))
243
254
  });
244
255
  await authorizeOperation();
245
- baselines.set(active.grant.clientId, baseline);
246
- return { tools: [...parentTools, ...wrappers].map((tool) => wireTool(prefix, tool)) };
256
+ baselines.set(baselineKey(active.grant.clientId), baseline);
257
+ return { tools: [...parentTools, ...wrappers].map((tool) => wireTool(prefix, presentTool(tool))) };
247
258
  });
248
259
  server.setRequestHandler("tools/call", async (message, ctx) => {
249
260
  const conversation = require_index.sessionMcpConversationDigest(ctx.mcpReq._meta ?? message.params._meta);
@@ -266,10 +277,15 @@ function createSessionMcpHttpHandler(options) {
266
277
  let skillAccessOpen = true;
267
278
  let widgetTool;
268
279
  let invocation;
280
+ let fileTransfer = false;
269
281
  const publishInvocation = () => {
270
282
  if (invocation?.sessionId === void 0) return;
271
283
  try {
272
- options.onInvocation?.({ ...invocation });
284
+ options.onInvocation?.(fileTransfer ? {
285
+ ...invocation,
286
+ input: { redacted: "file transfer" },
287
+ ...invocation.output === void 0 ? {} : { output: { redacted: "file transfer" } }
288
+ } : { ...invocation });
273
289
  } catch {
274
290
  options.onNotice?.("session MCP call history could not be saved");
275
291
  }
@@ -284,7 +300,10 @@ function createSessionMcpHttpHandler(options) {
284
300
  };
285
301
  publishInvocation();
286
302
  }
287
- return result;
303
+ return {
304
+ ...result,
305
+ _meta: presentationMeta(result._meta, presentation)
306
+ };
288
307
  };
289
308
  try {
290
309
  const parent = await authorizeOperation();
@@ -297,12 +316,14 @@ function createSessionMcpHttpHandler(options) {
297
316
  toolName: requested ?? message.params.name,
298
317
  startedAt: Date.now(),
299
318
  status: "running",
300
- input: message.params.arguments ?? {}
319
+ input: { redacted: "pending tool authorization" }
301
320
  };
302
- publishInvocation();
303
321
  const wrapper = grantedExtraTools(parent.grant).some((tool) => tool.name === requested);
304
322
  const advertised = wrapper ? void 0 : grantedSurface(parent.grant, parent.target.toolSurface).tools.find((tool) => tool.name === requested);
305
323
  if (!wrapper && !advertised) throw new require_index.SessionMcpConversationError("TOOL_NOT_AVAILABLE", `Tool '${message.params.name}' is not available on this connection.` + (prefix === void 0 ? "" : ` Tool names here start with '${prefix}_'.`) + nextCall("session_capabilities", " for the current list."));
324
+ const transferName = requested === "use_extra_tools" && typeof message.params.arguments?.name === "string" ? sessionMcpInternalName(prefix, message.params.arguments.name) : requested;
325
+ fileTransfer = grantedSurface(parent.grant, parent.target.toolSurface).tools.some((tool) => tool.name === transferName && tool._meta?.["doompi/fileTransfer"] === true);
326
+ publishInvocation();
306
327
  widgetTool = advertised;
307
328
  const wrapperArgs = wrapper ? toolArguments(requested, message.params.arguments ?? {}, wire) : void 0;
308
329
  await options.onVerified?.(parent.grant);
@@ -321,7 +342,7 @@ function createSessionMcpHttpHandler(options) {
321
342
  };
322
343
  };
323
344
  if (wrapper && !conversation) throw new require_index.SessionMcpConversationError("CONVERSATION_ID_REQUIRED", "This connection requires conversation metadata. Use a compatible ChatGPT conversation and retry.");
324
- if ((requested === "load_extra_tools" || requested === "use_extra_tools") && !baselines.has(parent.grant.clientId)) throw new require_index.SessionMcpConversationError("SESSION_MCP_BASELINE_REQUIRED", "Refresh this MCP connection tool catalog before loading or using extra tools.");
345
+ if ((requested === "load_extra_tools" || requested === "use_extra_tools") && !baselines.has(baselineKey(parent.grant.clientId))) throw new require_index.SessionMcpConversationError("SESSION_MCP_BASELINE_REQUIRED", "Refresh this MCP connection tool catalog before loading or using extra tools.");
325
346
  const active = await resolveTarget(true);
326
347
  invocation = {
327
348
  ...invocation,
@@ -329,8 +350,8 @@ function createSessionMcpHttpHandler(options) {
329
350
  };
330
351
  publishInvocation();
331
352
  const { snapshot, tools, skills } = grantedSurface(active.grant, active.target.toolSurface);
332
- const baseline = baselines.get(parent.grant.clientId);
333
- const extras = wrapper && baseline ? extraTools(baseline, tools) : [];
353
+ const baseline = baselines.get(baselineKey(parent.grant.clientId));
354
+ const extras = wrapper && baseline ? extraTools(baseline, tools, presentTool) : [];
334
355
  if (requested === "session_capabilities" && wrapper) {
335
356
  const capabilities = {
336
357
  sessionId: active.target.sessionId ?? parent.grant.sessionId,
@@ -339,7 +360,7 @@ function createSessionMcpHttpHandler(options) {
339
360
  baseline: baseline === void 0 ? "missing" : "available",
340
361
  inventory: "active_surface",
341
362
  discovery: "unknown",
342
- tools: [...tools.map(publicTool), ...grantedExtraTools(active.grant)].map((tool) => wireTool(prefix, tool)),
363
+ tools: [...tools.map(publicTool).map(presentTool), ...grantedExtraTools(active.grant)].map((tool) => wireTool(prefix, presentTool(tool))),
343
364
  skills: skills.map(({ name, description }) => ({
344
365
  name,
345
366
  description
@@ -360,7 +381,7 @@ function createSessionMcpHttpHandler(options) {
360
381
  }
361
382
  if (requested === "load_extra_tools" && wrapper) {
362
383
  const discovery = {
363
- tools: extras.map((tool) => wireTool(prefix, tool)),
384
+ tools: extras.map((tool) => wireTool(prefix, presentTool(tool))),
364
385
  skills: (tools.some((tool) => tool.name === "load_skill") ? skills : []).map(({ name, description }) => ({
365
386
  name,
366
387
  description
@@ -382,6 +403,7 @@ function createSessionMcpHttpHandler(options) {
382
403
  const selected = tools.find((tool) => tool.name === name);
383
404
  if (name === void 0 || wrapper && (!extras.some((tool) => tool.name === name) || !selected)) throw new require_index.SessionMcpConversationError("TOOL_NOT_AVAILABLE", `Extra tool '${wrapperArgs?.name ?? message.params.name}' is not available.` + nextCall("load_extra_tools", " and pass a name it returns."));
384
405
  if (!wrapper && (!selected || !(0, node_util.isDeepStrictEqual)(selected.parameters, advertised.parameters) || !(0, node_util.isDeepStrictEqual)(selected.outputSchema, advertised.outputSchema) || !(0, node_util.isDeepStrictEqual)(selected.annotations, advertised.annotations) || !(0, node_util.isDeepStrictEqual)(selected._meta, advertised._meta))) throw new require_index.SessionMcpConversationError("SESSION_TOOL_SURFACE_CHANGED", `This tool changed or was removed after your tool list loaded.${nextCall("load_extra_tools", grantedExtraTools(grant).some((tool) => tool.name === "use_extra_tools") ? ", and if it lists the tool, run it with " + wire("use_extra_tools") + "." : ", then refresh the connection to call a returned tool.")}`);
406
+ fileTransfer ||= selected?._meta?.["doompi/fileTransfer"] === true;
385
407
  widgetTool = wrapper ? void 0 : selected;
386
408
  const recheck = async () => {
387
409
  const current = await resolveTarget(false);
@@ -476,13 +498,13 @@ function createSessionMcpHttpHandler(options) {
476
498
  finishedAt: Date.now(),
477
499
  output: {
478
500
  cause,
479
- message: error instanceof Error ? error.message : "Tool call failed."
501
+ message: fileTransfer ? "File transfer failed." : error instanceof Error ? error.message : "Tool call failed."
480
502
  }
481
503
  };
482
504
  publishInvocation();
483
505
  }
484
506
  if (!(error instanceof require_index.SessionMcpConversationError)) throw error;
485
- return widgetResult(widgetTool, {
507
+ const failure = widgetResult(widgetTool, {
486
508
  content: [{
487
509
  type: "text",
488
510
  text: error.message
@@ -494,6 +516,10 @@ function createSessionMcpHttpHandler(options) {
494
516
  ...error.bindingId === void 0 ? {} : { bindingId: error.bindingId }
495
517
  }
496
518
  }, prefix);
519
+ return {
520
+ ...failure,
521
+ _meta: presentationMeta(failure._meta, presentation)
522
+ };
497
523
  } finally {
498
524
  skillAccessOpen = false;
499
525
  operations.delete(key);
@@ -502,7 +528,7 @@ function createSessionMcpHttpHandler(options) {
502
528
  server.setRequestHandler("resources/list", async () => {
503
529
  const active = await authorizeOperation();
504
530
  const { uiResources } = grantedSurface(active.grant, active.target.toolSurface);
505
- return { resources: [...uiResources] };
531
+ return { resources: presentation === "app" ? [...uiResources] : [] };
506
532
  });
507
533
  server.setRequestHandler("resources/read", async (message, ctx) => {
508
534
  const conversation = require_index.sessionMcpConversationDigest(ctx.mcpReq._meta ?? message.params._meta);
@@ -521,7 +547,7 @@ function createSessionMcpHttpHandler(options) {
521
547
  }] };
522
548
  }
523
549
  const resource = uiResources.find((candidate) => candidate.uri === message.params.uri);
524
- if (resource !== void 0 && active.target.toolSurface.readUiResource !== void 0) {
550
+ if (presentation === "app" && resource !== void 0 && active.target.toolSurface.readUiResource !== void 0) {
525
551
  request.signal.throwIfAborted();
526
552
  const text = await active.target.toolSurface.readUiResource(snapshot.revision, resource.uri);
527
553
  request.signal.throwIfAborted();