@agimon-ai/po-core 0.0.0-alpha.196 → 0.0.0-alpha.198

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 (89) hide show
  1. package/dist/headlessProtocol.cjs +1 -0
  2. package/dist/headlessProtocol.cjs.map +1 -1
  3. package/dist/headlessProtocol.mjs +1 -0
  4. package/dist/headlessProtocol.mjs.map +1 -1
  5. package/dist/headlessServer.cjs +1 -1
  6. package/dist/headlessServer.mjs +1 -1
  7. package/dist/headlessSessionHost.d.mts +2 -0
  8. package/dist/headlessSessionHost.d.mts.map +1 -1
  9. package/dist/locale.cjs +1 -0
  10. package/dist/locale.d.mts +2 -2
  11. package/dist/locale.mjs +2 -2
  12. package/dist/native.cjs +1 -1
  13. package/dist/native.mjs +1 -1
  14. package/dist/piSettings.cjs +1 -0
  15. package/dist/piSettings.d.mts +2 -2
  16. package/dist/piSettings.mjs +2 -2
  17. package/dist/po-runtime-identity.json +1 -1
  18. package/dist/runtimePackages.cjs +1 -1
  19. package/dist/runtimePackages.mjs +1 -1
  20. package/dist/runtimePiSettings.cjs +1 -0
  21. package/dist/runtimePiSettings.d.mts +2 -2
  22. package/dist/runtimePiSettings.mjs +2 -2
  23. package/dist/src/pi/piSessionRuntime.cjs +34 -14
  24. package/dist/src/pi/piSessionRuntime.cjs.map +1 -1
  25. package/dist/src/pi/piSessionRuntime.d.mts +2 -0
  26. package/dist/src/pi/piSessionRuntime.d.mts.map +1 -1
  27. package/dist/src/pi/piSessionRuntime.mjs +34 -14
  28. package/dist/src/pi/piSessionRuntime.mjs.map +1 -1
  29. package/dist/src/schemas/locale.cjs +21 -0
  30. package/dist/src/schemas/locale.cjs.map +1 -1
  31. package/dist/src/schemas/locale.d.mts +5 -0
  32. package/dist/src/schemas/locale.d.mts.map +1 -1
  33. package/dist/src/schemas/locale.mjs +21 -1
  34. package/dist/src/schemas/locale.mjs.map +1 -1
  35. package/dist/src/services/bundlePublication/index.cjs +1 -1
  36. package/dist/src/services/chordAdapter/index.cjs +8 -3
  37. package/dist/src/services/chordAdapter/index.cjs.map +1 -1
  38. package/dist/src/services/chordAdapter/index.d.mts.map +1 -1
  39. package/dist/src/services/chordAdapter/index.mjs +8 -3
  40. package/dist/src/services/chordAdapter/index.mjs.map +1 -1
  41. package/dist/src/services/nativeChildTools/index.cjs +1 -1
  42. package/dist/src/services/nativeChildTools/index.mjs +1 -1
  43. package/dist/src/services/piExtensionHost/index.cjs +1 -1
  44. package/dist/src/services/piExtensionHost/index.mjs +1 -1
  45. package/dist/src/services/piSettings/sync.cjs +24 -0
  46. package/dist/src/services/piSettings/sync.cjs.map +1 -1
  47. package/dist/src/services/piSettings/sync.d.mts +2 -0
  48. package/dist/src/services/piSettings/sync.d.mts.map +1 -1
  49. package/dist/src/services/piSettings/sync.mjs +25 -2
  50. package/dist/src/services/piSettings/sync.mjs.map +1 -1
  51. package/dist/src/services/toolContinuation/index.cjs +1 -1
  52. package/dist/src/services/toolContinuation/index.cjs.map +1 -1
  53. package/dist/src/services/toolContinuation/index.mjs +1 -1
  54. package/dist/src/services/toolContinuation/index.mjs.map +1 -1
  55. package/dist/src/systems/main/adapters/headlessHost.cjs +41 -9
  56. package/dist/src/systems/main/adapters/headlessHost.cjs.map +1 -1
  57. package/dist/src/systems/main/adapters/headlessHost.d.mts +2 -0
  58. package/dist/src/systems/main/adapters/headlessHost.d.mts.map +1 -1
  59. package/dist/src/systems/main/adapters/headlessHost.mjs +41 -9
  60. package/dist/src/systems/main/adapters/headlessHost.mjs.map +1 -1
  61. package/dist/src/systems/main/adapters/headlessSessionHost.cjs +12 -3
  62. package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
  63. package/dist/src/systems/main/adapters/headlessSessionHost.mjs +14 -5
  64. package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
  65. package/dist/src/systems/main/types/headlessHost.d.mts +2 -0
  66. package/dist/src/systems/main/types/headlessHost.d.mts.map +1 -1
  67. package/dist/src/web/schemas/template.cjs +8 -3
  68. package/dist/src/web/schemas/template.cjs.map +1 -1
  69. package/dist/src/web/schemas/template.d.mts.map +1 -1
  70. package/dist/src/web/schemas/template.mjs +8 -3
  71. package/dist/src/web/schemas/template.mjs.map +1 -1
  72. package/dist/src/web/services/testing/settingsDirectory.cjs +164 -0
  73. package/dist/src/web/services/testing/settingsDirectory.cjs.map +1 -0
  74. package/dist/src/web/services/testing/settingsDirectory.d.mts +18 -0
  75. package/dist/src/web/services/testing/settingsDirectory.d.mts.map +1 -0
  76. package/dist/src/web/services/testing/settingsDirectory.mjs +164 -0
  77. package/dist/src/web/services/testing/settingsDirectory.mjs.map +1 -0
  78. package/dist/src/web/types/nativeTemplate.d.mts +4 -0
  79. package/dist/src/web/types/nativeTemplate.d.mts.map +1 -1
  80. package/dist/src/web/types/template.d.mts +5 -0
  81. package/dist/src/web/types/template.d.mts.map +1 -1
  82. package/dist/src/web/types/webPlugin.d.mts +14 -0
  83. package/dist/src/web/types/webPlugin.d.mts.map +1 -1
  84. package/dist/web.cjs +1 -1
  85. package/dist/web.mjs +1 -1
  86. package/dist/webTesting.cjs +2 -0
  87. package/dist/webTesting.d.mts +2 -1
  88. package/dist/webTesting.mjs +2 -1
  89. package/package.json +5 -5
@@ -509,6 +509,7 @@ function createHeadlessProtocol(options) {
509
509
  ...methods === void 0 ? {} : { methods },
510
510
  options: {
511
511
  runtime: session.host.runtime,
512
+ translate: session.host.translate,
512
513
  onPresentationFrame: (listen) => session.host.onPresentationFrame((frame) => {
513
514
  if (permitted()) listen(frame);
514
515
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.cjs","names":["poScopeToWire","SESSION_READS","createThreadJournals","createProtocolServer","harnessErrorMessage","poForbidden","PoHubLifecycleContract","createLiveValue","PoHubAccessContract","PoHubContract","poRevisionsToWire","randomUUID","poPluginCallFromWire","poClientMetadataFrom","PoHubBotSettingsContract","PoHubRevisionsContract","PoThreadContract","PoChannelsContract","serveAgentSessions","reportingLargeFrames"],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n poPluginCallFromWire,\n poRevisionsToWire,\n poScopeToWire,\n type PoPluginCall,\n type PoPluginWireCall,\n} from '../exports/pluginProtocol';\nimport {\n PoChannelsContract,\n PoHubAccessContract,\n PoHubBotSettingsContract,\n PoHubContract,\n PoHubLifecycleContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubBotSettingsRef,\n type HubNotice,\n type HubLifecycleSnapshot,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { SESSION_READS, serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\nimport type { HumanActor } from '../schemas/humanIdentity';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { createLiveValue, poForbidden, type ProtocolLink } from '../schemas/protocolContracts';\nimport { createProtocolServer } from '../services/chordAdapter';\nimport { poClientMetadataFrom } from '../services/clientMetadata/_lib/codec';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined\n ? {}\n : { webComposition: { ...session.webComposition, scope: poScopeToWire(session.webComposition.scope) } }),\n ...(session.nativeComposition === undefined\n ? {}\n : { nativeComposition: { ...session.nativeComposition, scope: poScopeToWire(session.nativeComposition.scope) } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'host' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'host') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n /** Verified request actor, never client metadata. Absent on internal and mirrored links. */\n readonly humanActor?: HumanActor;\n /** Self-reported display metadata, never an authorization principal. */\n readonly client?: PoClientMetadata;\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n /** Whether this connection may act in the session, not only watch it. Evaluated for every call. */\n authorizeInteract(sessionId: string): boolean;\n /** Whether this connection may call host and workspace packages. False for a teammate on a team host. */\n authorizeHost(): boolean;\n /** Hosting wrappers can verify current owner-only authority independently of general package access. */\n authorizeHostOwner?(): boolean | Promise<boolean>;\n /** False once the caller lost its place on this host, such as a teammate removed from the team. */\n current(): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n /**\n * Set only out of band by the host for a Cloud chat stream. It limits the connection to one session's chat:\n * no generic package call, channel, thread, revision or home read, and only the methods in `CLOUD_CHAT_METHODS`.\n */\n readonly cloudChat?: true;\n}\n\n/**\n * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.\n * Reads such as stats and the command list are what a client asks for whenever it attaches.\n */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n ...SESSION_READS,\n 'prompt',\n 'steer',\n 'followUp',\n 'abort',\n 'abortOperation',\n]);\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ntype Principal = { connectionId: string };\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: ProtocolLink, access?: Partial<ConnectionAccess>): void;\n /** Rechecks every connection after access changed: one holding a session it may no longer reach is dropped. */\n reauthorize(): void;\n close(): Promise<void>;\n}\n\n/** One protocol server for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const server = createProtocolServer<Principal>({\n name: 'headless',\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw poForbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim, or a share taken back, makes every reference the connection holds to that session gone at once.\n const reauthorize = (): void => {\n for (const [connectionId, connection] of connections) {\n let revoked = !connection.current();\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n server.revoke({ connectionId });\n }\n // Lists are recomputed for everyone still connected, so a session newly shared or hidden shows at once.\n for (const refresh of sessionLists) refresh();\n };\n /** Live projections recomputed after caller authority changes. */\n const sessionLists = new Set<() => void>();\n const stopClaims = hub.computerUse?.subscribe?.(reauthorize);\n\n server.serve(PoHubLifecycleContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n const sessions = createLiveValue<Record<string, HubLifecycleSnapshot>>({});\n const refresh = (): void => {\n const rows: Record<string, HubLifecycleSnapshot> = Object.create(null);\n if (connection.current()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n const dormant = new Map(dormantSessions().map((record) => [record.sessionId, record]));\n for (const snapshot of hub.lifecycle.list()) {\n const record = dormant.get(snapshot.sessionId);\n if (\n !reachable(connection, snapshot.sessionId) &&\n !(\n record !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n )\n continue;\n // Only public host-defined codes cross this boundary, never arbitrary transition reasons.\n const reasons: readonly NonNullable<HubLifecycleSnapshot['reason']>[] = [\n 'profile_timeout',\n 'profile_source_failed',\n 'profile_changed',\n 'provider_not_ready',\n 'plugin_not_ready',\n 'profile_missing',\n 'profile_not_applied',\n 'open_failed',\n 'stop_failed',\n ];\n const reason = reasons.find((code) => code === snapshot.reason);\n rows[snapshot.sessionId] = {\n sessionId: snapshot.sessionId,\n state: snapshot.state,\n since: snapshot.since,\n attemptId: snapshot.attemptId,\n ...(snapshot.trigger === undefined ? {} : { trigger: snapshot.trigger }),\n ...(reason === undefined ? {} : { reason }),\n };\n }\n }\n sessions.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stopLifecycle = hub.lifecycle.subscribe(refresh);\n const stopHub = hub.onEvent(refresh);\n return () => {\n sessionLists.delete(refresh);\n stopLifecycle();\n stopHub();\n };\n });\n return { sessions };\n });\n\n server.serve(PoHubAccessContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const interact = createLiveValue<Record<string, boolean>>({});\n const refresh = (): void => {\n const rights: Record<string, boolean> = {};\n if (connection.current()) {\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) rights[session.id] = connection.authorizeInteract(session.id);\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n rights[record.sessionId] = connection.authorizeInteract(record.sessionId);\n }\n interact.replace(rights);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { interact };\n });\n\n server.serve(PoHubContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'host' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n // Filled when the object activates, so a hold never computes its views twice.\n const sessions = createLiveValue<Record<string, HubSessionView>>({});\n const workspaces = createLiveValue<Record<string, HubWorkspaceView>>({});\n const pending = createLiveValue<HubNotice[]>([]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'host' || key === own));\n };\n const compositions = createLiveValue<Record<string, number>>({});\n const onHub = (event: HeadlessHubEvent): void => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(visibleSessions());\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(visibleWorkspaces());\n return;\n case 'compositions':\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change((draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n };\n const refreshSessions = (): void => sessions.replace(visibleSessions());\n self.subscribe(() => {\n refreshSessions();\n workspaces.replace(visibleWorkspaces());\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n sessionLists.add(refreshSessions);\n const stop = hub.onEvent(onHub);\n return () => {\n sessionLists.delete(refreshSessions);\n stop();\n };\n });\n return {\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (received: PoPluginWireCall, { signal }) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n let call: PoPluginCall = poPluginCallFromWire(received);\n let client = connection.client;\n // The host-to-container hop keeps origin hints inside the existing JSON input,\n // without changing po.hub@1 or copying any authenticated caller capability.\n if (call.service === 'po.protocol-forward' && call.method === 'invoke') {\n const envelope = call.input;\n if (\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['service', 'method', 'input', 'client'].includes(key)) ||\n !('service' in envelope) ||\n typeof envelope.service !== 'string' ||\n envelope.service.length > 128 ||\n !('method' in envelope) ||\n typeof envelope.method !== 'string' ||\n envelope.method.length > 128 ||\n !('input' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded plugin call.');\n const parsed = poClientMetadataFrom({\n preface: { poClient: 'client' in envelope ? envelope.client : undefined },\n });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n call = { mount: call.mount, service: envelope.service, method: envelope.method, input: envelope.input };\n if (call.service === 'po.protocol-forward') throw new Error('Nested forwarding is not supported.');\n }\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw poForbidden('This session belongs to its Desktop instance.');\n // A package call may change anything, so watching a session is not enough to make one.\n if (call.mount.scope === 'session' && !connection.authorizeInteract(call.mount.sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n if (call.mount.scope !== 'session' && !connection.authorizeHost())\n throw poForbidden('Only the owner of this computer can do that.');\n if (mount.scope !== 'host') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw poForbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n client,\n signal,\n hostOwner: await (connection.authorizeHostOwner?.() ?? connection.authorizeHost()),\n })) as JsonValue;\n },\n ackNotice: async ({ id }) => {\n pending.change((draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n server.serve(PoHubBotSettingsContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const allowed = () =>\n !connection.cloudChat && connection.mount.scope === 'host' && connection.current() && connection.authorizeHost();\n if (!allowed()) throw poForbidden('Only the host may read the bot settings feed.');\n const settings = createLiveValue<HubBotSettingsRef['settings']['value']>({});\n const refresh = (): void => {\n const rows: HubBotSettingsRef['settings']['value'] = Object.create(null);\n if (allowed()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions()) {\n if (\n record.bot !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId)\n )\n rows[record.sessionId] = { bot: record.bot, botRevision: record.botRevision ?? 0 };\n }\n for (const session of hub.snapshot()) {\n delete rows[session.id];\n if (session.bot !== undefined && reachable(connection, session.id))\n rows[session.id] = { bot: session.bot, botRevision: session.botRevision ?? 0 };\n }\n }\n settings.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { settings };\n });\n\n server.serve(PoHubRevisionsContract, (_params, principal, self) => {\n const { mount, cloudChat } = connectionOf(principal);\n if (cloudChat) throw poForbidden('This connection may not make that call.');\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('host:') || topic.startsWith(own)),\n );\n };\n const revisions = createLiveValue<Record<string, number>>({});\n self.subscribe(() => {\n revisions.replace(poRevisionsToWire(visibleRevisions()));\n return hub.onEvent((event) => {\n if (event.kind === 'revisions') revisions.replace(poRevisionsToWire(visibleRevisions()));\n });\n });\n return { revisions };\n });\n\n server.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const frame = createLiveValue<Record<string, JsonValue> | null>(null);\n self.subscribe(() => {\n const tail = threads.subscribe(sessionId, threadId);\n frame.replace((tail.at(-1) ?? null) as Record<string, JsonValue> | null);\n const stop = threads.onFrame((event) => {\n // Each frame is a fresh wrapper around the child's state; the adapter sends only what changed.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(event.frame as Record<string, JsonValue>);\n });\n return () => {\n stop();\n threads.unsubscribe(sessionId, threadId);\n };\n });\n return { frame } as never;\n },\n { linger: THREAD_LINGER_MS },\n );\n\n server.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const visiblePayloads = (): Record<string, JsonValue> => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId, connection))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n };\n const latest = createLiveValue<Record<string, JsonValue>>({});\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.subscribe(() => {\n latest.replace(visiblePayloads());\n return hub.onEvent((event) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n if (event.deviceId !== undefined && event.deviceId !== connection.client?.deviceId) return;\n latest.change((draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n });\n return {\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw poForbidden('This session belongs to Desktop.');\n if (!connection.authorizeInteract(sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n let client = connection.client;\n if (\n payload !== null &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n 'poProtocolForward' in payload\n ) {\n const envelope = payload.poProtocolForward;\n if (\n Object.keys(payload).length !== 1 ||\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['payload', 'client'].includes(key)) ||\n !('payload' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded channel frame.');\n const parsed = poClientMetadataFrom({ preface: { poClient: envelope.client } });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n payload = envelope.payload;\n }\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n client,\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(server, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n const interactive = () => connection.authorizeInteract(session.id);\n const methods = connection.cloudChat ? CLOUD_CHAT_METHODS : undefined;\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n ...(methods === undefined ? {} : { methods }),\n forward,\n };\n return {\n ...(connection.humanActor === undefined ? {} : { humanActor: connection.humanActor }),\n ...(connection.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n // Bound to this connection: a mention grants only sessions this person may reach and act in.\n onPersonMessage: (text) => {\n if (!permitted() || !interactive()) return;\n hub.grantMentionedSessions?.(session.id, text, (target) => {\n const stopped = dormantSessions().find((record) => record.sessionId === target);\n const placed =\n hub.session(target) !== undefined\n ? reachable(connection, target)\n : stopped !== undefined && permitsDormant(connection.mount, stopped);\n return placed && connection.authorizeSession(target) && connection.authorizeInteract(target);\n });\n },\n ...(methods === undefined ? {} : { methods }),\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n if (!interactive()) throw poForbidden('You can view this session, but not act in it.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n onDeviceTimeZone: (timeZone) => {\n if (permitted()) session.host.setDeviceTimeZone?.(timeZone);\n },\n onDeviceLocale: (locale) => {\n if (permitted()) session.host.setDeviceLocale?.(locale);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'host' },\n client: access.client,\n humanActor: access.humanActor,\n authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\n authorizeHostOwner: access.authorizeHostOwner,\n current: access.current ?? (() => true),\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n ...(access.cloudChat === true ? { cloudChat: true as const } : {}),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n server.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), { connectionId });\n },\n reauthorize,\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await server.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;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O,SAAS,EAAE,OAAO,OAAO;IACvC,QAAQ,OAAO;IACf,YAAY,OAAO;IACnB;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,oBAAoB,OAAO;IAC3B,SAAS,OAAO,kBAAkB;IAClC;IACA,sBAAsB,OAAO,+BAA+B,iBAAiB;IAC7E,GAAI,OAAO,cAAc,OAAO,EAAE,WAAW,KAAc,IAAI,CAAC;IAChE,0BAAU,IAAI,IAAI;GACpB,CAAC;GACD,KAAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,OAAO,OAAOQ,uBAAAA,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG,EAAE,aAAa,CAAC;EACjG;EACA;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,qBAAqB;IACrB,MAAM,OAAO,MAAM;GACrB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
1
+ {"version":3,"file":"headlessProtocol.cjs","names":["poScopeToWire","SESSION_READS","createThreadJournals","createProtocolServer","harnessErrorMessage","poForbidden","PoHubLifecycleContract","createLiveValue","PoHubAccessContract","PoHubContract","poRevisionsToWire","randomUUID","poPluginCallFromWire","poClientMetadataFrom","PoHubBotSettingsContract","PoHubRevisionsContract","PoThreadContract","PoChannelsContract","serveAgentSessions","reportingLargeFrames"],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n poPluginCallFromWire,\n poRevisionsToWire,\n poScopeToWire,\n type PoPluginCall,\n type PoPluginWireCall,\n} from '../exports/pluginProtocol';\nimport {\n PoChannelsContract,\n PoHubAccessContract,\n PoHubBotSettingsContract,\n PoHubContract,\n PoHubLifecycleContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubBotSettingsRef,\n type HubNotice,\n type HubLifecycleSnapshot,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { SESSION_READS, serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\nimport type { HumanActor } from '../schemas/humanIdentity';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { createLiveValue, poForbidden, type ProtocolLink } from '../schemas/protocolContracts';\nimport { createProtocolServer } from '../services/chordAdapter';\nimport { poClientMetadataFrom } from '../services/clientMetadata/_lib/codec';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined\n ? {}\n : { webComposition: { ...session.webComposition, scope: poScopeToWire(session.webComposition.scope) } }),\n ...(session.nativeComposition === undefined\n ? {}\n : { nativeComposition: { ...session.nativeComposition, scope: poScopeToWire(session.nativeComposition.scope) } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'host' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'host') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n /** Verified request actor, never client metadata. Absent on internal and mirrored links. */\n readonly humanActor?: HumanActor;\n /** Self-reported display metadata, never an authorization principal. */\n readonly client?: PoClientMetadata;\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n /** Whether this connection may act in the session, not only watch it. Evaluated for every call. */\n authorizeInteract(sessionId: string): boolean;\n /** Whether this connection may call host and workspace packages. False for a teammate on a team host. */\n authorizeHost(): boolean;\n /** Hosting wrappers can verify current owner-only authority independently of general package access. */\n authorizeHostOwner?(): boolean | Promise<boolean>;\n /** False once the caller lost its place on this host, such as a teammate removed from the team. */\n current(): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n /**\n * Set only out of band by the host for a Cloud chat stream. It limits the connection to one session's chat:\n * no generic package call, channel, thread, revision or home read, and only the methods in `CLOUD_CHAT_METHODS`.\n */\n readonly cloudChat?: true;\n}\n\n/**\n * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.\n * Reads such as stats and the command list are what a client asks for whenever it attaches.\n */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n ...SESSION_READS,\n 'prompt',\n 'steer',\n 'followUp',\n 'abort',\n 'abortOperation',\n]);\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ntype Principal = { connectionId: string };\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: ProtocolLink, access?: Partial<ConnectionAccess>): void;\n /** Rechecks every connection after access changed: one holding a session it may no longer reach is dropped. */\n reauthorize(): void;\n close(): Promise<void>;\n}\n\n/** One protocol server for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const server = createProtocolServer<Principal>({\n name: 'headless',\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw poForbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim, or a share taken back, makes every reference the connection holds to that session gone at once.\n const reauthorize = (): void => {\n for (const [connectionId, connection] of connections) {\n let revoked = !connection.current();\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n server.revoke({ connectionId });\n }\n // Lists are recomputed for everyone still connected, so a session newly shared or hidden shows at once.\n for (const refresh of sessionLists) refresh();\n };\n /** Live projections recomputed after caller authority changes. */\n const sessionLists = new Set<() => void>();\n const stopClaims = hub.computerUse?.subscribe?.(reauthorize);\n\n server.serve(PoHubLifecycleContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n const sessions = createLiveValue<Record<string, HubLifecycleSnapshot>>({});\n const refresh = (): void => {\n const rows: Record<string, HubLifecycleSnapshot> = Object.create(null);\n if (connection.current()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n const dormant = new Map(dormantSessions().map((record) => [record.sessionId, record]));\n for (const snapshot of hub.lifecycle.list()) {\n const record = dormant.get(snapshot.sessionId);\n if (\n !reachable(connection, snapshot.sessionId) &&\n !(\n record !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n )\n continue;\n // Only public host-defined codes cross this boundary, never arbitrary transition reasons.\n const reasons: readonly NonNullable<HubLifecycleSnapshot['reason']>[] = [\n 'profile_timeout',\n 'profile_source_failed',\n 'profile_changed',\n 'provider_not_ready',\n 'plugin_not_ready',\n 'profile_missing',\n 'profile_not_applied',\n 'open_failed',\n 'stop_failed',\n ];\n const reason = reasons.find((code) => code === snapshot.reason);\n rows[snapshot.sessionId] = {\n sessionId: snapshot.sessionId,\n state: snapshot.state,\n since: snapshot.since,\n attemptId: snapshot.attemptId,\n ...(snapshot.trigger === undefined ? {} : { trigger: snapshot.trigger }),\n ...(reason === undefined ? {} : { reason }),\n };\n }\n }\n sessions.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stopLifecycle = hub.lifecycle.subscribe(refresh);\n const stopHub = hub.onEvent(refresh);\n return () => {\n sessionLists.delete(refresh);\n stopLifecycle();\n stopHub();\n };\n });\n return { sessions };\n });\n\n server.serve(PoHubAccessContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const interact = createLiveValue<Record<string, boolean>>({});\n const refresh = (): void => {\n const rights: Record<string, boolean> = {};\n if (connection.current()) {\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) rights[session.id] = connection.authorizeInteract(session.id);\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n rights[record.sessionId] = connection.authorizeInteract(record.sessionId);\n }\n interact.replace(rights);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { interact };\n });\n\n server.serve(PoHubContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'host' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n // Filled when the object activates, so a hold never computes its views twice.\n const sessions = createLiveValue<Record<string, HubSessionView>>({});\n const workspaces = createLiveValue<Record<string, HubWorkspaceView>>({});\n const pending = createLiveValue<HubNotice[]>([]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'host' || key === own));\n };\n const compositions = createLiveValue<Record<string, number>>({});\n const onHub = (event: HeadlessHubEvent): void => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(visibleSessions());\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(visibleWorkspaces());\n return;\n case 'compositions':\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change((draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n };\n const refreshSessions = (): void => sessions.replace(visibleSessions());\n self.subscribe(() => {\n refreshSessions();\n workspaces.replace(visibleWorkspaces());\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n sessionLists.add(refreshSessions);\n const stop = hub.onEvent(onHub);\n return () => {\n sessionLists.delete(refreshSessions);\n stop();\n };\n });\n return {\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (received: PoPluginWireCall, { signal }) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n let call: PoPluginCall = poPluginCallFromWire(received);\n let client = connection.client;\n // The host-to-container hop keeps origin hints inside the existing JSON input,\n // without changing po.hub@1 or copying any authenticated caller capability.\n if (call.service === 'po.protocol-forward' && call.method === 'invoke') {\n const envelope = call.input;\n if (\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['service', 'method', 'input', 'client'].includes(key)) ||\n !('service' in envelope) ||\n typeof envelope.service !== 'string' ||\n envelope.service.length > 128 ||\n !('method' in envelope) ||\n typeof envelope.method !== 'string' ||\n envelope.method.length > 128 ||\n !('input' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded plugin call.');\n const parsed = poClientMetadataFrom({\n preface: { poClient: 'client' in envelope ? envelope.client : undefined },\n });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n call = { mount: call.mount, service: envelope.service, method: envelope.method, input: envelope.input };\n if (call.service === 'po.protocol-forward') throw new Error('Nested forwarding is not supported.');\n }\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw poForbidden('This session belongs to its Desktop instance.');\n // A package call may change anything, so watching a session is not enough to make one.\n if (call.mount.scope === 'session' && !connection.authorizeInteract(call.mount.sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n if (call.mount.scope !== 'session' && !connection.authorizeHost())\n throw poForbidden('Only the owner of this computer can do that.');\n if (mount.scope !== 'host') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw poForbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n client,\n signal,\n hostOwner: await (connection.authorizeHostOwner?.() ?? connection.authorizeHost()),\n })) as JsonValue;\n },\n ackNotice: async ({ id }) => {\n pending.change((draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n server.serve(PoHubBotSettingsContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const allowed = () =>\n !connection.cloudChat && connection.mount.scope === 'host' && connection.current() && connection.authorizeHost();\n if (!allowed()) throw poForbidden('Only the host may read the bot settings feed.');\n const settings = createLiveValue<HubBotSettingsRef['settings']['value']>({});\n const refresh = (): void => {\n const rows: HubBotSettingsRef['settings']['value'] = Object.create(null);\n if (allowed()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions()) {\n if (\n record.bot !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId)\n )\n rows[record.sessionId] = { bot: record.bot, botRevision: record.botRevision ?? 0 };\n }\n for (const session of hub.snapshot()) {\n delete rows[session.id];\n if (session.bot !== undefined && reachable(connection, session.id))\n rows[session.id] = { bot: session.bot, botRevision: session.botRevision ?? 0 };\n }\n }\n settings.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { settings };\n });\n\n server.serve(PoHubRevisionsContract, (_params, principal, self) => {\n const { mount, cloudChat } = connectionOf(principal);\n if (cloudChat) throw poForbidden('This connection may not make that call.');\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('host:') || topic.startsWith(own)),\n );\n };\n const revisions = createLiveValue<Record<string, number>>({});\n self.subscribe(() => {\n revisions.replace(poRevisionsToWire(visibleRevisions()));\n return hub.onEvent((event) => {\n if (event.kind === 'revisions') revisions.replace(poRevisionsToWire(visibleRevisions()));\n });\n });\n return { revisions };\n });\n\n server.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const frame = createLiveValue<Record<string, JsonValue> | null>(null);\n self.subscribe(() => {\n const tail = threads.subscribe(sessionId, threadId);\n frame.replace((tail.at(-1) ?? null) as Record<string, JsonValue> | null);\n const stop = threads.onFrame((event) => {\n // Each frame is a fresh wrapper around the child's state; the adapter sends only what changed.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(event.frame as Record<string, JsonValue>);\n });\n return () => {\n stop();\n threads.unsubscribe(sessionId, threadId);\n };\n });\n return { frame } as never;\n },\n { linger: THREAD_LINGER_MS },\n );\n\n server.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const visiblePayloads = (): Record<string, JsonValue> => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId, connection))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n };\n const latest = createLiveValue<Record<string, JsonValue>>({});\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.subscribe(() => {\n latest.replace(visiblePayloads());\n return hub.onEvent((event) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n if (event.deviceId !== undefined && event.deviceId !== connection.client?.deviceId) return;\n latest.change((draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n });\n return {\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw poForbidden('This session belongs to Desktop.');\n if (!connection.authorizeInteract(sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n let client = connection.client;\n if (\n payload !== null &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n 'poProtocolForward' in payload\n ) {\n const envelope = payload.poProtocolForward;\n if (\n Object.keys(payload).length !== 1 ||\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['payload', 'client'].includes(key)) ||\n !('payload' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded channel frame.');\n const parsed = poClientMetadataFrom({ preface: { poClient: envelope.client } });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n payload = envelope.payload;\n }\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n client,\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(server, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n const interactive = () => connection.authorizeInteract(session.id);\n const methods = connection.cloudChat ? CLOUD_CHAT_METHODS : undefined;\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n ...(methods === undefined ? {} : { methods }),\n forward,\n };\n return {\n ...(connection.humanActor === undefined ? {} : { humanActor: connection.humanActor }),\n ...(connection.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n // Bound to this connection: a mention grants only sessions this person may reach and act in.\n onPersonMessage: (text) => {\n if (!permitted() || !interactive()) return;\n hub.grantMentionedSessions?.(session.id, text, (target) => {\n const stopped = dormantSessions().find((record) => record.sessionId === target);\n const placed =\n hub.session(target) !== undefined\n ? reachable(connection, target)\n : stopped !== undefined && permitsDormant(connection.mount, stopped);\n return placed && connection.authorizeSession(target) && connection.authorizeInteract(target);\n });\n },\n ...(methods === undefined ? {} : { methods }),\n options: {\n runtime: session.host.runtime,\n translate: session.host.translate,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n if (!interactive()) throw poForbidden('You can view this session, but not act in it.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n onDeviceTimeZone: (timeZone) => {\n if (permitted()) session.host.setDeviceTimeZone?.(timeZone);\n },\n onDeviceLocale: (locale) => {\n if (permitted()) session.host.setDeviceLocale?.(locale);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'host' },\n client: access.client,\n humanActor: access.humanActor,\n authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\n authorizeHostOwner: access.authorizeHostOwner,\n current: access.current ?? (() => true),\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n ...(access.cloudChat === true ? { cloudChat: true as const } : {}),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n server.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), { connectionId });\n },\n reauthorize,\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await server.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAC3B,CAAC,IACD,EAAE,gBAAgB;GAAE,GAAG,QAAQ;GAAgB,OAAOA,uBAAAA,cAAc,QAAQ,eAAe,KAAK;EAAE,EAAE;EACxG,GAAI,QAAQ,sBAAsB,KAAA,IAC9B,CAAC,IACD,EAAE,mBAAmB;GAAE,GAAG,QAAQ;GAAmB,OAAOA,uBAAAA,cAAc,QAAQ,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AAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,OAAO,OAAOQ,uBAAAA,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG,EAAE,aAAa,CAAC;EACjG;EACA;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,qBAAqB;IACrB,MAAM,OAAO,MAAM;GACrB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
@@ -508,6 +508,7 @@ function createHeadlessProtocol(options) {
508
508
  ...methods === void 0 ? {} : { methods },
509
509
  options: {
510
510
  runtime: session.host.runtime,
511
+ translate: session.host.translate,
511
512
  onPresentationFrame: (listen) => session.host.onPresentationFrame((frame) => {
512
513
  if (permitted()) listen(frame);
513
514
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.mjs","names":[],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n poPluginCallFromWire,\n poRevisionsToWire,\n poScopeToWire,\n type PoPluginCall,\n type PoPluginWireCall,\n} from '../exports/pluginProtocol';\nimport {\n PoChannelsContract,\n PoHubAccessContract,\n PoHubBotSettingsContract,\n PoHubContract,\n PoHubLifecycleContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubBotSettingsRef,\n type HubNotice,\n type HubLifecycleSnapshot,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { SESSION_READS, serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\nimport type { HumanActor } from '../schemas/humanIdentity';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { createLiveValue, poForbidden, type ProtocolLink } from '../schemas/protocolContracts';\nimport { createProtocolServer } from '../services/chordAdapter';\nimport { poClientMetadataFrom } from '../services/clientMetadata/_lib/codec';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined\n ? {}\n : { webComposition: { ...session.webComposition, scope: poScopeToWire(session.webComposition.scope) } }),\n ...(session.nativeComposition === undefined\n ? {}\n : { nativeComposition: { ...session.nativeComposition, scope: poScopeToWire(session.nativeComposition.scope) } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'host' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'host') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n /** Verified request actor, never client metadata. Absent on internal and mirrored links. */\n readonly humanActor?: HumanActor;\n /** Self-reported display metadata, never an authorization principal. */\n readonly client?: PoClientMetadata;\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n /** Whether this connection may act in the session, not only watch it. Evaluated for every call. */\n authorizeInteract(sessionId: string): boolean;\n /** Whether this connection may call host and workspace packages. False for a teammate on a team host. */\n authorizeHost(): boolean;\n /** Hosting wrappers can verify current owner-only authority independently of general package access. */\n authorizeHostOwner?(): boolean | Promise<boolean>;\n /** False once the caller lost its place on this host, such as a teammate removed from the team. */\n current(): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n /**\n * Set only out of band by the host for a Cloud chat stream. It limits the connection to one session's chat:\n * no generic package call, channel, thread, revision or home read, and only the methods in `CLOUD_CHAT_METHODS`.\n */\n readonly cloudChat?: true;\n}\n\n/**\n * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.\n * Reads such as stats and the command list are what a client asks for whenever it attaches.\n */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n ...SESSION_READS,\n 'prompt',\n 'steer',\n 'followUp',\n 'abort',\n 'abortOperation',\n]);\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ntype Principal = { connectionId: string };\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: ProtocolLink, access?: Partial<ConnectionAccess>): void;\n /** Rechecks every connection after access changed: one holding a session it may no longer reach is dropped. */\n reauthorize(): void;\n close(): Promise<void>;\n}\n\n/** One protocol server for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const server = createProtocolServer<Principal>({\n name: 'headless',\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw poForbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim, or a share taken back, makes every reference the connection holds to that session gone at once.\n const reauthorize = (): void => {\n for (const [connectionId, connection] of connections) {\n let revoked = !connection.current();\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n server.revoke({ connectionId });\n }\n // Lists are recomputed for everyone still connected, so a session newly shared or hidden shows at once.\n for (const refresh of sessionLists) refresh();\n };\n /** Live projections recomputed after caller authority changes. */\n const sessionLists = new Set<() => void>();\n const stopClaims = hub.computerUse?.subscribe?.(reauthorize);\n\n server.serve(PoHubLifecycleContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n const sessions = createLiveValue<Record<string, HubLifecycleSnapshot>>({});\n const refresh = (): void => {\n const rows: Record<string, HubLifecycleSnapshot> = Object.create(null);\n if (connection.current()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n const dormant = new Map(dormantSessions().map((record) => [record.sessionId, record]));\n for (const snapshot of hub.lifecycle.list()) {\n const record = dormant.get(snapshot.sessionId);\n if (\n !reachable(connection, snapshot.sessionId) &&\n !(\n record !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n )\n continue;\n // Only public host-defined codes cross this boundary, never arbitrary transition reasons.\n const reasons: readonly NonNullable<HubLifecycleSnapshot['reason']>[] = [\n 'profile_timeout',\n 'profile_source_failed',\n 'profile_changed',\n 'provider_not_ready',\n 'plugin_not_ready',\n 'profile_missing',\n 'profile_not_applied',\n 'open_failed',\n 'stop_failed',\n ];\n const reason = reasons.find((code) => code === snapshot.reason);\n rows[snapshot.sessionId] = {\n sessionId: snapshot.sessionId,\n state: snapshot.state,\n since: snapshot.since,\n attemptId: snapshot.attemptId,\n ...(snapshot.trigger === undefined ? {} : { trigger: snapshot.trigger }),\n ...(reason === undefined ? {} : { reason }),\n };\n }\n }\n sessions.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stopLifecycle = hub.lifecycle.subscribe(refresh);\n const stopHub = hub.onEvent(refresh);\n return () => {\n sessionLists.delete(refresh);\n stopLifecycle();\n stopHub();\n };\n });\n return { sessions };\n });\n\n server.serve(PoHubAccessContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const interact = createLiveValue<Record<string, boolean>>({});\n const refresh = (): void => {\n const rights: Record<string, boolean> = {};\n if (connection.current()) {\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) rights[session.id] = connection.authorizeInteract(session.id);\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n rights[record.sessionId] = connection.authorizeInteract(record.sessionId);\n }\n interact.replace(rights);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { interact };\n });\n\n server.serve(PoHubContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'host' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n // Filled when the object activates, so a hold never computes its views twice.\n const sessions = createLiveValue<Record<string, HubSessionView>>({});\n const workspaces = createLiveValue<Record<string, HubWorkspaceView>>({});\n const pending = createLiveValue<HubNotice[]>([]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'host' || key === own));\n };\n const compositions = createLiveValue<Record<string, number>>({});\n const onHub = (event: HeadlessHubEvent): void => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(visibleSessions());\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(visibleWorkspaces());\n return;\n case 'compositions':\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change((draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n };\n const refreshSessions = (): void => sessions.replace(visibleSessions());\n self.subscribe(() => {\n refreshSessions();\n workspaces.replace(visibleWorkspaces());\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n sessionLists.add(refreshSessions);\n const stop = hub.onEvent(onHub);\n return () => {\n sessionLists.delete(refreshSessions);\n stop();\n };\n });\n return {\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (received: PoPluginWireCall, { signal }) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n let call: PoPluginCall = poPluginCallFromWire(received);\n let client = connection.client;\n // The host-to-container hop keeps origin hints inside the existing JSON input,\n // without changing po.hub@1 or copying any authenticated caller capability.\n if (call.service === 'po.protocol-forward' && call.method === 'invoke') {\n const envelope = call.input;\n if (\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['service', 'method', 'input', 'client'].includes(key)) ||\n !('service' in envelope) ||\n typeof envelope.service !== 'string' ||\n envelope.service.length > 128 ||\n !('method' in envelope) ||\n typeof envelope.method !== 'string' ||\n envelope.method.length > 128 ||\n !('input' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded plugin call.');\n const parsed = poClientMetadataFrom({\n preface: { poClient: 'client' in envelope ? envelope.client : undefined },\n });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n call = { mount: call.mount, service: envelope.service, method: envelope.method, input: envelope.input };\n if (call.service === 'po.protocol-forward') throw new Error('Nested forwarding is not supported.');\n }\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw poForbidden('This session belongs to its Desktop instance.');\n // A package call may change anything, so watching a session is not enough to make one.\n if (call.mount.scope === 'session' && !connection.authorizeInteract(call.mount.sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n if (call.mount.scope !== 'session' && !connection.authorizeHost())\n throw poForbidden('Only the owner of this computer can do that.');\n if (mount.scope !== 'host') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw poForbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n client,\n signal,\n hostOwner: await (connection.authorizeHostOwner?.() ?? connection.authorizeHost()),\n })) as JsonValue;\n },\n ackNotice: async ({ id }) => {\n pending.change((draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n server.serve(PoHubBotSettingsContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const allowed = () =>\n !connection.cloudChat && connection.mount.scope === 'host' && connection.current() && connection.authorizeHost();\n if (!allowed()) throw poForbidden('Only the host may read the bot settings feed.');\n const settings = createLiveValue<HubBotSettingsRef['settings']['value']>({});\n const refresh = (): void => {\n const rows: HubBotSettingsRef['settings']['value'] = Object.create(null);\n if (allowed()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions()) {\n if (\n record.bot !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId)\n )\n rows[record.sessionId] = { bot: record.bot, botRevision: record.botRevision ?? 0 };\n }\n for (const session of hub.snapshot()) {\n delete rows[session.id];\n if (session.bot !== undefined && reachable(connection, session.id))\n rows[session.id] = { bot: session.bot, botRevision: session.botRevision ?? 0 };\n }\n }\n settings.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { settings };\n });\n\n server.serve(PoHubRevisionsContract, (_params, principal, self) => {\n const { mount, cloudChat } = connectionOf(principal);\n if (cloudChat) throw poForbidden('This connection may not make that call.');\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('host:') || topic.startsWith(own)),\n );\n };\n const revisions = createLiveValue<Record<string, number>>({});\n self.subscribe(() => {\n revisions.replace(poRevisionsToWire(visibleRevisions()));\n return hub.onEvent((event) => {\n if (event.kind === 'revisions') revisions.replace(poRevisionsToWire(visibleRevisions()));\n });\n });\n return { revisions };\n });\n\n server.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const frame = createLiveValue<Record<string, JsonValue> | null>(null);\n self.subscribe(() => {\n const tail = threads.subscribe(sessionId, threadId);\n frame.replace((tail.at(-1) ?? null) as Record<string, JsonValue> | null);\n const stop = threads.onFrame((event) => {\n // Each frame is a fresh wrapper around the child's state; the adapter sends only what changed.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(event.frame as Record<string, JsonValue>);\n });\n return () => {\n stop();\n threads.unsubscribe(sessionId, threadId);\n };\n });\n return { frame } as never;\n },\n { linger: THREAD_LINGER_MS },\n );\n\n server.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const visiblePayloads = (): Record<string, JsonValue> => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId, connection))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n };\n const latest = createLiveValue<Record<string, JsonValue>>({});\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.subscribe(() => {\n latest.replace(visiblePayloads());\n return hub.onEvent((event) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n if (event.deviceId !== undefined && event.deviceId !== connection.client?.deviceId) return;\n latest.change((draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n });\n return {\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw poForbidden('This session belongs to Desktop.');\n if (!connection.authorizeInteract(sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n let client = connection.client;\n if (\n payload !== null &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n 'poProtocolForward' in payload\n ) {\n const envelope = payload.poProtocolForward;\n if (\n Object.keys(payload).length !== 1 ||\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['payload', 'client'].includes(key)) ||\n !('payload' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded channel frame.');\n const parsed = poClientMetadataFrom({ preface: { poClient: envelope.client } });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n payload = envelope.payload;\n }\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n client,\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(server, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n const interactive = () => connection.authorizeInteract(session.id);\n const methods = connection.cloudChat ? CLOUD_CHAT_METHODS : undefined;\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n ...(methods === undefined ? {} : { methods }),\n forward,\n };\n return {\n ...(connection.humanActor === undefined ? {} : { humanActor: connection.humanActor }),\n ...(connection.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n // Bound to this connection: a mention grants only sessions this person may reach and act in.\n onPersonMessage: (text) => {\n if (!permitted() || !interactive()) return;\n hub.grantMentionedSessions?.(session.id, text, (target) => {\n const stopped = dormantSessions().find((record) => record.sessionId === target);\n const placed =\n hub.session(target) !== undefined\n ? reachable(connection, target)\n : stopped !== undefined && permitsDormant(connection.mount, stopped);\n return placed && connection.authorizeSession(target) && connection.authorizeInteract(target);\n });\n },\n ...(methods === undefined ? {} : { methods }),\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n if (!interactive()) throw poForbidden('You can view this session, but not act in it.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n onDeviceTimeZone: (timeZone) => {\n if (permitted()) session.host.setDeviceTimeZone?.(timeZone);\n },\n onDeviceLocale: (locale) => {\n if (permitted()) session.host.setDeviceLocale?.(locale);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'host' },\n client: access.client,\n humanActor: access.humanActor,\n authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\n authorizeHostOwner: access.authorizeHostOwner,\n current: access.current ?? (() => true),\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n ...(access.cloudChat === true ? { cloudChat: true as const } : {}),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n server.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), { connectionId });\n },\n reauthorize,\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await server.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAC3B,CAAC,IACD,EAAE,gBAAgB;GAAE,GAAG,QAAQ;GAAgB,OAAO,cAAc,QAAQ,eAAe,KAAK;EAAE,EAAE;EACxG,GAAI,QAAQ,sBAAsB,KAAA,IAC9B,CAAC,IACD,EAAE,mBAAmB;GAAE,GAAG,QAAQ;GAAmB,OAAO,cAAc,QAAQ,kBAAkB,KAAK;EAAE,EAAE;EACjH,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,WAAW,QAAQ;EACnB,WAAW,QAAQ,aAAa,QAAQ;EACxC,OAAO,QAAQ,SAAS;EACxB,YAAY,QAAQ,cAAc,QAAQ;EAC1C,QAAQ;EACR,qBAAqB,QAAQ,uBAAuB;EACpD,cAAc,QAAQ,gBAAgB;EACtC,eAAe,QAAQ,iBAAiB;EACxC,GAAI,QAAQ,kBAAkB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe,QAAQ,cAAc;EAEtF,GAAI,QAA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,IAAI,cAAc;IAC5B,OAAO,OAAO,SAAS,EAAE,OAAO,OAAO;IACvC,QAAQ,OAAO;IACf,YAAY,OAAO;IACnB;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,oBAAoB,OAAO;IAC3B,SAAS,OAAO,kBAAkB;IAClC;IACA,sBAAsB,OAAO,+BAA+B,iBAAiB;IAC7E,GAAI,OAAO,cAAc,OAAO,EAAE,WAAW,KAAc,IAAI,CAAC;IAChE,0BAAU,IAAI,IAAI;GACpB,CAAC;GACD,KAAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,OAAO,OAAO,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG,EAAE,aAAa,CAAC;EACjG;EACA;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,qBAAqB;IACrB,MAAM,OAAO,MAAM;GACrB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
1
+ {"version":3,"file":"headlessProtocol.mjs","names":[],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport {\n poPluginCallFromWire,\n poRevisionsToWire,\n poScopeToWire,\n type PoPluginCall,\n type PoPluginWireCall,\n} from '../exports/pluginProtocol';\nimport {\n PoChannelsContract,\n PoHubAccessContract,\n PoHubBotSettingsContract,\n PoHubContract,\n PoHubLifecycleContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubBotSettingsRef,\n type HubNotice,\n type HubLifecycleSnapshot,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { SESSION_READS, serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\nimport type { HumanActor } from '../schemas/humanIdentity';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { createLiveValue, poForbidden, type ProtocolLink } from '../schemas/protocolContracts';\nimport { createProtocolServer } from '../services/chordAdapter';\nimport { poClientMetadataFrom } from '../services/clientMetadata/_lib/codec';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined\n ? {}\n : { webComposition: { ...session.webComposition, scope: poScopeToWire(session.webComposition.scope) } }),\n ...(session.nativeComposition === undefined\n ? {}\n : { nativeComposition: { ...session.nativeComposition, scope: poScopeToWire(session.nativeComposition.scope) } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'host' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'host') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n /** Verified request actor, never client metadata. Absent on internal and mirrored links. */\n readonly humanActor?: HumanActor;\n /** Self-reported display metadata, never an authorization principal. */\n readonly client?: PoClientMetadata;\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n /** Whether this connection may act in the session, not only watch it. Evaluated for every call. */\n authorizeInteract(sessionId: string): boolean;\n /** Whether this connection may call host and workspace packages. False for a teammate on a team host. */\n authorizeHost(): boolean;\n /** Hosting wrappers can verify current owner-only authority independently of general package access. */\n authorizeHostOwner?(): boolean | Promise<boolean>;\n /** False once the caller lost its place on this host, such as a teammate removed from the team. */\n current(): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n /**\n * Set only out of band by the host for a Cloud chat stream. It limits the connection to one session's chat:\n * no generic package call, channel, thread, revision or home read, and only the methods in `CLOUD_CHAT_METHODS`.\n */\n readonly cloudChat?: true;\n}\n\n/**\n * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.\n * Reads such as stats and the command list are what a client asks for whenever it attaches.\n */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n ...SESSION_READS,\n 'prompt',\n 'steer',\n 'followUp',\n 'abort',\n 'abortOperation',\n]);\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ntype Principal = { connectionId: string };\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: ProtocolLink, access?: Partial<ConnectionAccess>): void;\n /** Rechecks every connection after access changed: one holding a session it may no longer reach is dropped. */\n reauthorize(): void;\n close(): Promise<void>;\n}\n\n/** One protocol server for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const server = createProtocolServer<Principal>({\n name: 'headless',\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw poForbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim, or a share taken back, makes every reference the connection holds to that session gone at once.\n const reauthorize = (): void => {\n for (const [connectionId, connection] of connections) {\n let revoked = !connection.current();\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n server.revoke({ connectionId });\n }\n // Lists are recomputed for everyone still connected, so a session newly shared or hidden shows at once.\n for (const refresh of sessionLists) refresh();\n };\n /** Live projections recomputed after caller authority changes. */\n const sessionLists = new Set<() => void>();\n const stopClaims = hub.computerUse?.subscribe?.(reauthorize);\n\n server.serve(PoHubLifecycleContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n const sessions = createLiveValue<Record<string, HubLifecycleSnapshot>>({});\n const refresh = (): void => {\n const rows: Record<string, HubLifecycleSnapshot> = Object.create(null);\n if (connection.current()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n const dormant = new Map(dormantSessions().map((record) => [record.sessionId, record]));\n for (const snapshot of hub.lifecycle.list()) {\n const record = dormant.get(snapshot.sessionId);\n if (\n !reachable(connection, snapshot.sessionId) &&\n !(\n record !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n )\n continue;\n // Only public host-defined codes cross this boundary, never arbitrary transition reasons.\n const reasons: readonly NonNullable<HubLifecycleSnapshot['reason']>[] = [\n 'profile_timeout',\n 'profile_source_failed',\n 'profile_changed',\n 'provider_not_ready',\n 'plugin_not_ready',\n 'profile_missing',\n 'profile_not_applied',\n 'open_failed',\n 'stop_failed',\n ];\n const reason = reasons.find((code) => code === snapshot.reason);\n rows[snapshot.sessionId] = {\n sessionId: snapshot.sessionId,\n state: snapshot.state,\n since: snapshot.since,\n attemptId: snapshot.attemptId,\n ...(snapshot.trigger === undefined ? {} : { trigger: snapshot.trigger }),\n ...(reason === undefined ? {} : { reason }),\n };\n }\n }\n sessions.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stopLifecycle = hub.lifecycle.subscribe(refresh);\n const stopHub = hub.onEvent(refresh);\n return () => {\n sessionLists.delete(refresh);\n stopLifecycle();\n stopHub();\n };\n });\n return { sessions };\n });\n\n server.serve(PoHubAccessContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const interact = createLiveValue<Record<string, boolean>>({});\n const refresh = (): void => {\n const rights: Record<string, boolean> = {};\n if (connection.current()) {\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) rights[session.id] = connection.authorizeInteract(session.id);\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(connection.mount, record)\n )\n rights[record.sessionId] = connection.authorizeInteract(record.sessionId);\n }\n interact.replace(rights);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { interact };\n });\n\n server.serve(PoHubContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'host' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n // Filled when the object activates, so a hold never computes its views twice.\n const sessions = createLiveValue<Record<string, HubSessionView>>({});\n const workspaces = createLiveValue<Record<string, HubWorkspaceView>>({});\n const pending = createLiveValue<HubNotice[]>([]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'host' || key === own));\n };\n const compositions = createLiveValue<Record<string, number>>({});\n const onHub = (event: HeadlessHubEvent): void => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(visibleSessions());\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(visibleWorkspaces());\n return;\n case 'compositions':\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change((draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n };\n const refreshSessions = (): void => sessions.replace(visibleSessions());\n self.subscribe(() => {\n refreshSessions();\n workspaces.replace(visibleWorkspaces());\n compositions.replace(poRevisionsToWire(visibleCompositions()));\n sessionLists.add(refreshSessions);\n const stop = hub.onEvent(onHub);\n return () => {\n sessionLists.delete(refreshSessions);\n stop();\n };\n });\n return {\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (received: PoPluginWireCall, { signal }) => {\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n let call: PoPluginCall = poPluginCallFromWire(received);\n let client = connection.client;\n // The host-to-container hop keeps origin hints inside the existing JSON input,\n // without changing po.hub@1 or copying any authenticated caller capability.\n if (call.service === 'po.protocol-forward' && call.method === 'invoke') {\n const envelope = call.input;\n if (\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['service', 'method', 'input', 'client'].includes(key)) ||\n !('service' in envelope) ||\n typeof envelope.service !== 'string' ||\n envelope.service.length > 128 ||\n !('method' in envelope) ||\n typeof envelope.method !== 'string' ||\n envelope.method.length > 128 ||\n !('input' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded plugin call.');\n const parsed = poClientMetadataFrom({\n preface: { poClient: 'client' in envelope ? envelope.client : undefined },\n });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n call = { mount: call.mount, service: envelope.service, method: envelope.method, input: envelope.input };\n if (call.service === 'po.protocol-forward') throw new Error('Nested forwarding is not supported.');\n }\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw poForbidden('This session belongs to its Desktop instance.');\n // A package call may change anything, so watching a session is not enough to make one.\n if (call.mount.scope === 'session' && !connection.authorizeInteract(call.mount.sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n if (call.mount.scope !== 'session' && !connection.authorizeHost())\n throw poForbidden('Only the owner of this computer can do that.');\n if (mount.scope !== 'host') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw poForbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n client,\n signal,\n hostOwner: await (connection.authorizeHostOwner?.() ?? connection.authorizeHost()),\n })) as JsonValue;\n },\n ackNotice: async ({ id }) => {\n pending.change((draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n server.serve(PoHubBotSettingsContract, (_params, principal, self) => {\n const connection = connectionOf(principal);\n const allowed = () =>\n !connection.cloudChat && connection.mount.scope === 'host' && connection.current() && connection.authorizeHost();\n if (!allowed()) throw poForbidden('Only the host may read the bot settings feed.');\n const settings = createLiveValue<HubBotSettingsRef['settings']['value']>({});\n const refresh = (): void => {\n const rows: HubBotSettingsRef['settings']['value'] = Object.create(null);\n if (allowed()) {\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions()) {\n if (\n record.bot !== undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId)\n )\n rows[record.sessionId] = { bot: record.bot, botRevision: record.botRevision ?? 0 };\n }\n for (const session of hub.snapshot()) {\n delete rows[session.id];\n if (session.bot !== undefined && reachable(connection, session.id))\n rows[session.id] = { bot: session.bot, botRevision: session.botRevision ?? 0 };\n }\n }\n settings.replace(rows);\n };\n self.subscribe(() => {\n refresh();\n sessionLists.add(refresh);\n const stop = hub.onEvent((event) => {\n if (\n event.kind === 'upsert' ||\n event.kind === 'removed' ||\n event.kind === 'dormant_changed' ||\n event.kind === 'workspace_upsert' ||\n event.kind === 'workspace_removed'\n )\n refresh();\n });\n return () => {\n sessionLists.delete(refresh);\n stop();\n };\n });\n return { settings };\n });\n\n server.serve(PoHubRevisionsContract, (_params, principal, self) => {\n const { mount, cloudChat } = connectionOf(principal);\n if (cloudChat) throw poForbidden('This connection may not make that call.');\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'host') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('host:') || topic.startsWith(own)),\n );\n };\n const revisions = createLiveValue<Record<string, number>>({});\n self.subscribe(() => {\n revisions.replace(poRevisionsToWire(visibleRevisions()));\n return hub.onEvent((event) => {\n if (event.kind === 'revisions') revisions.replace(poRevisionsToWire(visibleRevisions()));\n });\n });\n return { revisions };\n });\n\n server.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const frame = createLiveValue<Record<string, JsonValue> | null>(null);\n self.subscribe(() => {\n const tail = threads.subscribe(sessionId, threadId);\n frame.replace((tail.at(-1) ?? null) as Record<string, JsonValue> | null);\n const stop = threads.onFrame((event) => {\n // Each frame is a fresh wrapper around the child's state; the adapter sends only what changed.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(event.frame as Record<string, JsonValue>);\n });\n return () => {\n stop();\n threads.unsubscribe(sessionId, threadId);\n };\n });\n return { frame } as never;\n },\n { linger: THREAD_LINGER_MS },\n );\n\n server.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (connection.cloudChat) throw poForbidden('This connection may not make that call.');\n if (!reachable(connection, sessionId)) throw poForbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const visiblePayloads = (): Record<string, JsonValue> => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId, connection))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n };\n const latest = createLiveValue<Record<string, JsonValue>>({});\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.subscribe(() => {\n latest.replace(visiblePayloads());\n return hub.onEvent((event) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n if (event.deviceId !== undefined && event.deviceId !== connection.client?.deviceId) return;\n latest.change((draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n });\n return {\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw poForbidden('This session belongs to Desktop.');\n if (!connection.authorizeInteract(sessionId))\n throw poForbidden('You can view this session, but not act in it.');\n let client = connection.client;\n if (\n payload !== null &&\n typeof payload === 'object' &&\n !Array.isArray(payload) &&\n 'poProtocolForward' in payload\n ) {\n const envelope = payload.poProtocolForward;\n if (\n Object.keys(payload).length !== 1 ||\n typeof envelope !== 'object' ||\n envelope === null ||\n Array.isArray(envelope) ||\n Object.keys(envelope).some((key) => !['payload', 'client'].includes(key)) ||\n !('payload' in envelope) ||\n JSON.stringify(envelope).length > 8 * 1024 * 1024\n )\n throw new Error('Invalid forwarded channel frame.');\n const parsed = poClientMetadataFrom({ preface: { poClient: envelope.client } });\n if ('client' in envelope && parsed.status !== 'ok') throw new Error('Invalid forwarded client metadata.');\n client = parsed.status === 'ok' ? parsed.metadata : undefined;\n payload = envelope.payload;\n }\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n client,\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(server, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n const interactive = () => connection.authorizeInteract(session.id);\n const methods = connection.cloudChat ? CLOUD_CHAT_METHODS : undefined;\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n ...(methods === undefined ? {} : { methods }),\n forward,\n };\n return {\n ...(connection.humanActor === undefined ? {} : { humanActor: connection.humanActor }),\n ...(connection.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\n // Bound to this connection: a mention grants only sessions this person may reach and act in.\n onPersonMessage: (text) => {\n if (!permitted() || !interactive()) return;\n hub.grantMentionedSessions?.(session.id, text, (target) => {\n const stopped = dormantSessions().find((record) => record.sessionId === target);\n const placed =\n hub.session(target) !== undefined\n ? reachable(connection, target)\n : stopped !== undefined && permitsDormant(connection.mount, stopped);\n return placed && connection.authorizeSession(target) && connection.authorizeInteract(target);\n });\n },\n ...(methods === undefined ? {} : { methods }),\n options: {\n runtime: session.host.runtime,\n translate: session.host.translate,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n if (!interactive()) throw poForbidden('You can view this session, but not act in it.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw poForbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n onDeviceTimeZone: (timeZone) => {\n if (permitted()) session.host.setDeviceTimeZone?.(timeZone);\n },\n onDeviceLocale: (locale) => {\n if (permitted()) session.host.setDeviceLocale?.(locale);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'host' },\n client: access.client,\n humanActor: access.humanActor,\n authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\n authorizeHostOwner: access.authorizeHostOwner,\n current: access.current ?? (() => true),\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n ...(access.cloudChat === true ? { cloudChat: true as const } : {}),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n server.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), { connectionId });\n },\n reauthorize,\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await server.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAC3B,CAAC,IACD,EAAE,gBAAgB;GAAE,GAAG,QAAQ;GAAgB,OAAO,cAAc,QAAQ,eAAe,KAAK;EAAE,EAAE;EACxG,GAAI,QAAQ,sBAAsB,KAAA,IAC9B,CAAC,IACD,EAAE,mBAAmB;GAAE,GAAG,QAAQ;GAAmB,OAAO,cAAc,QAAQ,kBAAkB,KAAK;EAAE,EAAE;EACjH,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,WAAW,QAAQ;EACnB,WAAW,QAAQ,aAAa,QAAQ;EACxC,OAAO,QAAQ,SAAS;EACxB,YAAY,QAAQ,cAAc,QAAQ;EAC1C,QAAQ;EACR,qBAAqB,QAAQ,uBAAuB;EACpD,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IACzB,KAAK,MAAM;IACX;GACF;GACA,MAAM,eAAe,WAAW;GAChC,MAAM,mBAAmB,OAAO,sBAAsB,OAAe,CAAC,IAAI,aAAa,cAAc,EAAE;GACvG,MAAM,mBAAmB,OAAO,2BAA2B;GAC3D,YAAY,IAAI,cAAc;IAC5B,OAAO,OAAO,SAAS,EAAE,OAAO,OAAO;IACvC,QAAQ,OAAO;IACf,YAAY,OAAO;IACnB;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,oBAAoB,OAAO;IAC3B,SAAS,OAAO,kBAAkB;IAClC;IACA,sBAAsB,OAAO,+BAA+B,iBAAiB;IAC7E,GAAI,OAAO,cAAc,OAAO,EAAE,WAAW,KAAc,IAAI,CAAC;IAChE,0BAAU,IAAI,IAAI;GACpB,CAAC;GACD,KAAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,OAAO,OAAO,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG,EAAE,aAAa,CAAC;EACjG;EACA;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,qBAAqB;IACrB,MAAM,OAAO,MAAM;GACrB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
@@ -7,9 +7,9 @@ const require_hubChannel = require("./src/schemas/hubChannel.cjs");
7
7
  const require_packageApi = require("./src/schemas/packageApi.cjs");
8
8
  const require_index = require("./src/services/sessionAccess/index.cjs");
9
9
  const require_sessionProtocol = require("./src/schemas/sessionProtocol.cjs");
10
+ const require_serverTelemetry = require("./serverTelemetry.cjs");
10
11
  const require_harnessErrorMessage = require("./src/server/harnessErrorMessage.cjs");
11
12
  const require_contextDetailStore = require("./contextDetailStore.cjs");
12
- const require_serverTelemetry = require("./serverTelemetry.cjs");
13
13
  const require_protocolContracts = require("./src/schemas/protocolContracts.cjs");
14
14
  require("./packageApi.cjs");
15
15
  const require_sessionFiles = require("./src/constants/sessionFiles.cjs");
@@ -5,9 +5,9 @@ import { isBotWakePeriodMs, parseLaunchSelection } from "./src/schemas/hubChanne
5
5
  import { PO_API_CALLER_DEVICE_ID_HEADER, PO_API_CALLER_HEADERS, PO_API_CALLER_LOCALITY_HEADER, PO_API_CALLER_STEP_UP_HEADER, PO_API_PEER_ADDRESS_HEADER, parsePoSocketPath, poApiCallerFrom, poSessionStarterFrom } from "./src/schemas/packageApi.mjs";
6
6
  import { createSessionAccess, memberRouteNeed, parseSessionShare, sessionOfRoute } from "./src/services/sessionAccess/index.mjs";
7
7
  import { normalizeSessionGroups } from "./src/schemas/sessionProtocol.mjs";
8
+ import { observe } from "./serverTelemetry.mjs";
8
9
  import { harnessErrorMessage } from "./src/server/harnessErrorMessage.mjs";
9
10
  import { readContextDetail } from "./contextDetailStore.mjs";
10
- import { observe } from "./serverTelemetry.mjs";
11
11
  import { webSocketLink } from "./src/schemas/protocolContracts.mjs";
12
12
  import "./packageApi.mjs";
13
13
  import { SESSION_FILES_API } from "./src/constants/sessionFiles.mjs";
@@ -155,6 +155,8 @@ export interface HeadlessSessionHost {
155
155
  setDeviceTimeZone?(timeZone: string): void;
156
156
  /** Records the language the person reads Po in on the device they last wrote from. Optional like the zone. */
157
157
  setDeviceLocale?(locale: string): void;
158
+ /** Human notices use this session's admitted language. This callback is never sent over the wire. */
159
+ translate?: (key: string, fallback: string) => string;
158
160
  dispose(options?: HeadlessSessionCloseOptions): Promise<void>;
159
161
  }
160
162
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"headlessSessionHost.d.mts","names":[],"sources":["../src/systems/main/types/headlessSessionHost.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BY,iBAAiB,SAC3B,KACE;;YAYQ,4BAA4B,KACtC;;iBAKe;;WAEN;WACA,cAAc;;WAEd;aAAyC;aAAuB;;;EAEzE,aAAa,QAAQ,OAAO;IAAU,OAAO,MAAM;IAAM,gBAAg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AAgC;EAC/E,oBAAoB,WAAW,OAAO;;EAEtC,aAAa,WAAW,WAAW;;EAEnC,kBAAkB,WAAW;EAC7B,qBAAqB,OAAO;;EAE5B,mBAAmB;;EAEnB,iBAAiB;;EAEjB,aAAa,aAAa;EAC1B,QAAQ,UAAU,8BAA8B"}
package/dist/locale.cjs CHANGED
@@ -12,4 +12,5 @@ exports.isLocaleTag = require_locale.isLocaleTag;
12
12
  exports.matchLocale = require_locale.matchLocale;
13
13
  exports.readPoLang = require_lang.readPoLang;
14
14
  exports.readPoPersonLocale = require_lang.readPoPersonLocale;
15
+ exports.resolveEnvLocale = require_locale.resolveEnvLocale;
15
16
  exports.translateMessage = require_locale.translateMessage;
package/dist/locale.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { DEFAULT_LOCALE, LocaleCatalog, LocaleContribution, LocaleTag, canonicalLocale, formatMessage, isLocaleTag, matchLocale, translateMessage } from "./src/schemas/locale.mjs";
1
+ import { DEFAULT_LOCALE, LocaleCatalog, LocaleContribution, LocaleTag, canonicalLocale, formatMessage, isLocaleTag, matchLocale, resolveEnvLocale, translateMessage } from "./src/schemas/locale.mjs";
2
2
  import { PO_LANG_CONTRACT, PO_LANG_SERVICE, PO_PERSON_LOCALE_CONTRACT, PO_PERSON_LOCALE_SERVICE, PoLangService, PoPersonLocale, readPoLang, readPoPersonLocale } from "./src/schemas/lang.mjs";
3
- export { DEFAULT_LOCALE, type LocaleCatalog, type LocaleContribution, type LocaleTag, PO_LANG_CONTRACT, PO_LANG_SERVICE, PO_PERSON_LOCALE_CONTRACT, PO_PERSON_LOCALE_SERVICE, type PoLangService, type PoPersonLocale, canonicalLocale, formatMessage, isLocaleTag, matchLocale, readPoLang, readPoPersonLocale, translateMessage };
3
+ export { DEFAULT_LOCALE, type LocaleCatalog, type LocaleContribution, type LocaleTag, PO_LANG_CONTRACT, PO_LANG_SERVICE, PO_PERSON_LOCALE_CONTRACT, PO_PERSON_LOCALE_SERVICE, type PoLangService, type PoPersonLocale, canonicalLocale, formatMessage, isLocaleTag, matchLocale, readPoLang, readPoPersonLocale, resolveEnvLocale, translateMessage };