@agimon-ai/po-core 0.0.0-alpha.177 → 0.0.0-alpha.178

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.
@@ -119,10 +119,12 @@ function permitsDormant(mount, record) {
119
119
  if (record.workspaceId !== mount.workspaceId) return false;
120
120
  return mount.scope === "workspace" || mount.sessionId === record.sessionId;
121
121
  }
122
- /** What a Cloud chat connection may call on its session: the built-in prompt commands and the minimum reads. */
122
+ /**
123
+ * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.
124
+ * Reads such as stats and the command list are what a client asks for whenever it attaches.
125
+ */
123
126
  const CLOUD_CHAT_METHODS = /* @__PURE__ */ new Set([
124
- "readTranscriptPage",
125
- "getState",
127
+ ...require_piSessionRuntime.SESSION_READS,
126
128
  "prompt",
127
129
  "steer",
128
130
  "followUp",
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.cjs","names":["poScopeToWire","createThreadJournals","createProtocolServer","harnessErrorMessage","poForbidden","PoHubAccessContract","createLiveValue","PoHubContract","poRevisionsToWire","randomUUID","poPluginCallFromWire","poClientMetadataFrom","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 PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\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 /** 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 /** 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/** What a Cloud chat connection may call on its session: the built-in prompt commands and the minimum reads. */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n 'readTranscriptPage',\n 'getState',\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(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: 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(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.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\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 onPersonMessage: (text) => {\n if (permitted() && interactive()) hub.grantMentionedSessions?.(session.id, text);\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 authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\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":";;;;;;;;;;;;;;;;AAkCA,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,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,c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YAAAA,WAAAA,CAAW;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;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,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,OAAOO,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","PoHubAccessContract","createLiveValue","PoHubContract","poRevisionsToWire","randomUUID","poPluginCallFromWire","poClientMetadataFrom","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 PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\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 { 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 /** 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 /** 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(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: 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(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.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\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 onPersonMessage: (text) => {\n if (permitted() && interactive()) hub.grantMentionedSessions?.(session.id, text);\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 authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\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":";;;;;;;;;;;;;;;;AAkCA,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,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,yBAAyB,QAAQ,IAAI,IAAI;IACjF;IACA,WAAW,QAAQ;IACnB,aAAa,QAAQ;IACrB,KAAK,QAAQ;IACb,WAAW,QAAQ;GACrB;EACF;CACF,EACF,CAAC;CAED,IAAI;CACJ,OAAO;EACL,OAAO,MAAM,SAAS,CAAC,GAAG;GACxB,IAAI,YAAY,KAAA,GAAW;IACzB,KAAK,MAAM;IACX;GACF;GACA,MAAM,gBAAA,GAAeK,YAAAA,WAAAA,CAAW;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;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,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,OAAOO,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"}
@@ -27,7 +27,10 @@ export interface ConnectionAccess {
27
27
  */
28
28
  readonly cloudChat?: true;
29
29
  }
30
- /** What a Cloud chat connection may call on its session: the built-in prompt commands and the minimum reads. */
30
+ /**
31
+ * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.
32
+ * Reads such as stats and the command list are what a client asks for whenever it attaches.
33
+ */
31
34
  export declare const CLOUD_CHAT_METHODS: ReadonlySet<string>;
32
35
  export interface HeadlessProtocol {
33
36
  /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.d.mts","names":[],"sources":["../src/server/headlessProtocol.ts"],"mappings":";;;;;;;;;iBAoKiB;;WAEN,SAAS;WACT,OAAO;;EAEhB,iBAAiB;;EAEjB,kBAAkB;;EAElB;;EAEA;EACA;EACA,qBAAqB;;;;;WAKZ;;;qBAIE,oBAAoB;iBAiBhB;;EAEf,OAAO,MAAM,cAAc,SAAS,QAAQ;;EAE5C;EACA,SAAS;;;wBAIK,uBAAuB;EACrC,KAAK;EACL,YAAY;EACZ,YAAY;;EAEZ,iCAAiC;IAC/B"}
1
+ {"version":3,"file":"headlessProtocol.d.mts","names":[],"sources":["../src/server/headlessProtocol.ts"],"mappings":";;;;;;;;;iBAoKiB;;WAEN,SAAS;WACT,OAAO;;EAEhB,iBAAiB;;EAEjB,kBAAkB;;EAElB;;EAEA;EACA;EACA,qBAAqB;;;;;WAKZ;;;;;;qBAOE,oBAAoB;iBAgBhB;;EAEf,OAAO,MAAM,cAAc,SAAS,QAAQ;;EAE5C;EACA,SAAS;;;wBAIK,uBAAuB;EACrC,KAAK;EACL,YAAY;EACZ,YAAY;;EAEZ,iCAAiC;IAC/B"}
@@ -7,7 +7,7 @@ import { PoHubAccessContract, PoHubContract, PoHubRevisionsContract } from "./sr
7
7
  import { PoThreadContract } from "./src/schemas/protocolThreadContract.mjs";
8
8
  import { createProtocolServer } from "./src/services/chordAdapter/index.mjs";
9
9
  import "./sessionProtocol.mjs";
10
- import { serveAgentSessions } from "./src/pi/piSessionRuntime.mjs";
10
+ import { SESSION_READS, serveAgentSessions } from "./src/pi/piSessionRuntime.mjs";
11
11
  import "./pluginProtocol.mjs";
12
12
  import { reportingLargeFrames } from "./src/server/largeFrameLink.mjs";
13
13
  import { createThreadJournals } from "./src/server/threadJournals.mjs";
@@ -118,10 +118,12 @@ function permitsDormant(mount, record) {
118
118
  if (record.workspaceId !== mount.workspaceId) return false;
119
119
  return mount.scope === "workspace" || mount.sessionId === record.sessionId;
120
120
  }
121
- /** What a Cloud chat connection may call on its session: the built-in prompt commands and the minimum reads. */
121
+ /**
122
+ * What a Cloud chat connection may call on its session: every read a viewer may make, and the prompt commands.
123
+ * Reads such as stats and the command list are what a client asks for whenever it attaches.
124
+ */
122
125
  const CLOUD_CHAT_METHODS = /* @__PURE__ */ new Set([
123
- "readTranscriptPage",
124
- "getState",
126
+ ...SESSION_READS,
125
127
  "prompt",
126
128
  "steer",
127
129
  "followUp",
@@ -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 PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport type { PoClientMetadata } from '../schemas/clientMetadata';\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 /** 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 /** 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/** What a Cloud chat connection may call on its session: the built-in prompt commands and the minimum reads. */\nexport const CLOUD_CHAT_METHODS: ReadonlySet<string> = new Set([\n 'readTranscriptPage',\n 'getState',\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(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: 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(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.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\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 onPersonMessage: (text) => {\n if (permitted() && interactive()) hub.grantMentionedSessions?.(session.id, text);\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 authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\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":";;;;;;;;;;;;;;;AAkCA,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,QAAQ,wBAAwB,OAAO,CAAC,IAAI,EAAE,sBAAsB,QAAQ,qBAAqB;EACrG,GAAI,QAAQ,QAAQ,KAAA,IAAY,CAA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AAO;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 PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\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 { 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 /** 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 /** 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(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: 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(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.client === undefined ? {} : { client: connection.client }),\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n interactive,\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 onPersonMessage: (text) => {\n if (permitted() && interactive()) hub.grantMentionedSessions?.(session.id, text);\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 authorizeSession,\n authorizeInteract: access.authorizeInteract ?? (() => true),\n authorizeHost: access.authorizeHost ?? (() => true),\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":";;;;;;;;;;;;;;;AAkCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AA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ED,IAAI;CACJ,OAAO;EACL,OAAO,MAAM,SAAS,CAAC,GAAG;GACxB,IAAI,YAAY,KAAA,GAAW;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;IACA,mBAAmB,OAAO,4BAA4B;IACtD,eAAe,OAAO,wBAAwB;IAC9C,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"}
package/dist/native.d.mts CHANGED
@@ -5,7 +5,7 @@ import { isPoClientToken, poClientMetadataFrom } from "./src/services/clientMeta
5
5
  import { CalendarFederationOperation, DelegatedTokenClaims, FEDERATION_OPERATION_SCOPES, FederationCapabilities, FederationConsentCandidate, FederationConstraint, FederationContracts, FederationDeletionReceipt, FederationDeviceApproval, FederationEnvelope, FederationFencingToken, FederationFireOutcome, FederationFireReceipt, FederationFireRequest, FederationGrant, FederationHostRequest, FederationHostVisibility, FederationHubClaim, FederationHubEnrollment, FederationHubRemoval, FederationHubRemovalReceipt, FederationHubUnlinkReason, FederationLease, FederationOperation, FederationOperationScope, FederationPartialResult, FederationPrincipal, FederationProvider, FederationProviderConsent, FederationRecordReference, FederationRequest, FederationRoster, FederationRosterChange, FederationRosterHost, FederationVote, FederationWorkPaused, IdentityTokenClaims, PO_FEDERATION_CLIENT_SERVICE, PoFederationClient, READ_OPERATION_NAMES, federationEnrollmentGeneration, normalizeFederationOperations, splitConsentOperations } from "./src/schemas/federation.mjs";
6
6
  import { AUTH_BASE_PATH, AUTH_BOOTSTRAP_PATH, AUTH_PAIRING_PROOF_PATH, AuthBootstrap, AuthMethods, AuthPairingIdentity, AuthPairingRequest, AuthSession, AuthTeam, DeviceAdminApprovalRequest, DeviceApprovalChallenge, DeviceApprovalReject, DeviceApprovalRequest, DeviceApprovalStatus, DeviceApprovalSubmit, DeviceEnrollmentRequest, DeviceEnrollmentResponse, DeviceRecoveryCancelRequest, DeviceRecoveryPending, DeviceRecoveryRequest, DeviceRecoveryRotation, HubClaimRequest, IDENTITY_DEVICE_KEY_PATH, IdentityDeviceKeyRequest, IdentityDeviceKeyResponse, IdentityDeviceStatus, IdentityDeviceSummary, IdentityProof, IdentityProviders, identityProofFields } from "./src/schemas/identity.mjs";
7
7
  import { nonPortableConfigYaml } from "./src/services/portableConfig/index.mjs";
8
- import { WebTemplateRailActions, WebTemplateRailDirectoryListing, WebTemplateRailPendingSetup, WebTemplateRailSession, WebTemplateRailWorkspace } from "./src/web/types/template.mjs";
8
+ import { WebTemplateRailActions, WebTemplateRailDirectoryListing, WebTemplateRailPendingSetup, WebTemplateRailSession, WebTemplateRailWorkflow, WebTemplateRailWorkspace } from "./src/web/types/template.mjs";
9
9
  import { ActivityGroupContribution, DashboardTileData, DashboardTileSize, DialogPromptContribution, DialogPromptRenderProps, DockFaceContribution, HostStore, ModeContribution, OnboardingContext, OnboardingContribution, OnboardingProps, SelectionAxisContribution, SessionChannelContribution, SessionFrameSender, SessionRecords, SessionSetupActionContribution, SessionStore, SessionStoreChannel, SettingsPanelContribution, SettingsPanelProps, SettingsSectionContribution, SlotDeclaration, SlotFillContribution, TabContribution, TabHeader, ThemeContribution, ToolMessageRenderProps, ToolPromptRenderProps, ToolRendererContribution, ToolResultView, UserMessageActionContribution, UserMessageActionRunContext, WebPluginContributions, WebPluginDefinition, WebPluginRuntime, WebPluginSessionContext, WebPluginSessionOption, WebPluginSlotProps, WorkspaceRecords, WorkspaceStore } from "./src/web/types/webPlugin.mjs";
10
10
  import { NativeSessionView, NativeTemplateAsk, NativeTemplateComposerOptions, NativeTemplateContribution, NativeTemplateScreens, NativeTemplateSessionHeader, NativeTemplateSessionProps, NativeTemplateSessionsActions, NativeTemplateSessionsProps } from "./src/web/types/nativeTemplate.mjs";
11
11
  import { ActivityGroupFile, ChannelFile, DockFaceFile, FillFile, ModeFile, NativeTemplateFile, OnboardingFile, SelectionAxisFile, SettingsPanelFile, SettingsSectionFile, SlotFile, TabFile, ThemeFile, ToolRendererFile, UserMessageActionFile } from "./src/web/types/extensionFile.mjs";
@@ -27,4 +27,4 @@ import { bindNativeByteCodec, decodeBase64, encodeBase64 } from "./src/web/servi
27
27
  import { parseOnboarding } from "./src/web/schemas/onboarding.mjs";
28
28
  import { PluginCatalog, PluginTier, pluginCatalogLayerSchema, pluginCatalogSchema, pluginTierSchema, tierOf } from "./src/schemas/pluginCatalog.mjs";
29
29
  import { clientMetadata, updateClientDeviceName } from "@agimon-ai/po-web-security/browser";
30
- export { AUTH_BASE_PATH, AUTH_BOOTSTRAP_PATH, AUTH_PAIRING_PROOF_PATH, type ActivityGroupContribution, type ActivityGroupFile, type ApiCallInit, type ApiMethod, type ApiResult, type ApiRoutes, type ApiTransport, AuthBootstrap, AuthMethods, AuthPairingIdentity, AuthPairingRequest, AuthSession, AuthTeam, CalendarFederationOperation, type ChannelFile, DEFAULT_TEMPLATE_ID, type DashboardTileData, type DashboardTileSize, DelegatedTokenClaims, DeviceAdminApprovalRequest, DeviceApprovalChallenge, DeviceApprovalReject, DeviceApprovalRequest, DeviceApprovalStatus, DeviceApprovalSubmit, DeviceEnrollmentRequest, DeviceEnrollmentResponse, DeviceRecoveryCancelRequest, DeviceRecoveryPending, DeviceRecoveryRequest, DeviceRecoveryRotation, type DialogPromptContribution, type DialogPromptRenderProps, type DockFaceContribution, type DockFaceFile, FEDERATION_OPERATION_SCOPES, FederationCapabilities, FederationConsentCandidate, FederationConstraint, FederationContracts, FederationDeletionReceipt, FederationDeviceApproval, FederationEnvelope, FederationFencingToken, FederationFireOutcome, FederationFireReceipt, FederationFireRequest, FederationGrant, FederationHostRequest, FederationHostVisibility, FederationHubClaim, FederationHubEnrollment, FederationHubRemoval, FederationHubRemovalReceipt, FederationHubUnlinkReason, FederationLease, FederationOperation, FederationOperationScope, FederationPartialResult, FederationPrincipal, FederationProvider, FederationProviderConsent, FederationRecordReference, FederationRequest, FederationRoster, FederationRosterChange, FederationRosterHost, FederationVote, FederationWorkPaused, type FillFile, HOME_ENTITY_LIMIT, HOME_KINDS, HOME_PAGE_LIMIT, HOME_RECENT_KINDS, HOME_RECENT_LIMIT, HomeContribution, HomeCoverage, HomeEntity, HomeItem, HomeKind, HomeProjection, HomeRequest, HomeSnapshot, HomeSourceStatus, type HostStore, HubClaimRequest, IDENTITY_DEVICE_KEY_PATH, IdentityDeviceKeyRequest, IdentityDeviceKeyResponse, IdentityDeviceStatus, IdentityDeviceSummary, IdentityProof, IdentityProviders, IdentityTokenClaims, type ModeContribution, type ModeFile, NATIVE_HOST_MODULES, NATIVE_HOST_MODULE_IDS, NATIVE_UNISTYLES_COMPONENTS, NATIVE_UNISTYLES_COMPONENT_PREFIX, type NativeSessionView, type NativeTemplateAsk, type NativeTemplateComposerOptions, type NativeTemplateContribution, type NativeTemplateFile, type NativeTemplateScreens, type NativeTemplateSessionHeader, type NativeTemplateSessionProps, type NativeTemplateSessionsActions, type NativeTemplateSessionsProps, type OnboardingContext, type OnboardingContribution, type OnboardingFile, type OnboardingProps, PO_FEDERATION_CLIENT_SERVICE, type PluginCatalog, type PluginTier, type PoApprovalPrompt, type PoClientMetadata, PoFederationClient, READ_OPERATION_NAMES, type SelectionAxisContribution, type SelectionAxisFile, type SessionChannelContribution, type SessionFrameSender, type SessionRecords, type SessionSetupActionContribution, type SessionStore, type SessionStoreChannel, type SettingsPanelContribution, type SettingsPanelFile, type SettingsPanelProps, type SettingsSectionContribution, type SettingsSectionFile, type SlotDeclaration, type SlotFile, type SlotFillContribution, type TabContribution, type TabFile, type TabHeader, type ThemeContribution, type ThemeFile, type ToolMessageRenderProps, type ToolPromptRenderProps, type ToolRendererContribution, type ToolRendererFile, type ToolResultView, type UserMessageActionContribution, type UserMessageActionFile, type UserMessageActionRunContext, type WebPluginContributions, type WebPluginDefinition, type WebPluginRuntime, type WebPluginSessionContext, type WebPluginSessionOption, type WebPluginSlotProps, type WebTemplateRailActions, type WebTemplateRailDirectoryListing, type WebTemplateRailPendingSetup, type WebTemplateRailSession, type WebTemplateRailWorkspace, type WorkspaceRecords, type WorkspaceStore, apiResponse, applyPathParams, bindNativeByteCodec, clientMetadata, createApiClient, decodeBase64, defineActivityGroup, defineApiRoutes, defineChannelFile, defineDockFace, defineFileLinks, defineFill, defineHostProvider, defineHostStore, defineModeFile, defineWebPlugin as defineNativePlugin, defineNativeTemplate, defineOnboarding, defineSelectionAxis, defineSessionChannel, defineSessionStore, defineSettingsPanel, defineSettingsSection, defineSlot, defineSlotFile, defineTab, defineTheme, defineToolRenderer, defineUserMessageAction, defineWebLifecycle, defineWorkspaceStore, encodeBase64, federationEnrollmentGeneration, hostRevisionTopic, hubRevision, identityProofFields, isPoClientToken, nativeApiTransport, nonPortableConfigYaml, normalizeFederationOperations, parseHomeContribution, parseHomeEntity, parseHomeProjection, parseHomeSnapshot, parseNativeTemplate, parseOnboarding, parsePoApprovalPrompt, pluginCatalogLayerSchema, pluginCatalogSchema, pluginTierSchema, poClientMetadataFrom, railStepRows, sessionApiAddress, sessionApiPath, splitConsentOperations, subscribeHubRevision, tierOf, toolResultText, toolResultTextLines, updateClientDeviceName, workspaceRevisionTopic };
30
+ export { AUTH_BASE_PATH, AUTH_BOOTSTRAP_PATH, AUTH_PAIRING_PROOF_PATH, type ActivityGroupContribution, type ActivityGroupFile, type ApiCallInit, type ApiMethod, type ApiResult, type ApiRoutes, type ApiTransport, AuthBootstrap, AuthMethods, AuthPairingIdentity, AuthPairingRequest, AuthSession, AuthTeam, CalendarFederationOperation, type ChannelFile, DEFAULT_TEMPLATE_ID, type DashboardTileData, type DashboardTileSize, DelegatedTokenClaims, DeviceAdminApprovalRequest, DeviceApprovalChallenge, DeviceApprovalReject, DeviceApprovalRequest, DeviceApprovalStatus, DeviceApprovalSubmit, DeviceEnrollmentRequest, DeviceEnrollmentResponse, DeviceRecoveryCancelRequest, DeviceRecoveryPending, DeviceRecoveryRequest, DeviceRecoveryRotation, type DialogPromptContribution, type DialogPromptRenderProps, type DockFaceContribution, type DockFaceFile, FEDERATION_OPERATION_SCOPES, FederationCapabilities, FederationConsentCandidate, FederationConstraint, FederationContracts, FederationDeletionReceipt, FederationDeviceApproval, FederationEnvelope, FederationFencingToken, FederationFireOutcome, FederationFireReceipt, FederationFireRequest, FederationGrant, FederationHostRequest, FederationHostVisibility, FederationHubClaim, FederationHubEnrollment, FederationHubRemoval, FederationHubRemovalReceipt, FederationHubUnlinkReason, FederationLease, FederationOperation, FederationOperationScope, FederationPartialResult, FederationPrincipal, FederationProvider, FederationProviderConsent, FederationRecordReference, FederationRequest, FederationRoster, FederationRosterChange, FederationRosterHost, FederationVote, FederationWorkPaused, type FillFile, HOME_ENTITY_LIMIT, HOME_KINDS, HOME_PAGE_LIMIT, HOME_RECENT_KINDS, HOME_RECENT_LIMIT, HomeContribution, HomeCoverage, HomeEntity, HomeItem, HomeKind, HomeProjection, HomeRequest, HomeSnapshot, HomeSourceStatus, type HostStore, HubClaimRequest, IDENTITY_DEVICE_KEY_PATH, IdentityDeviceKeyRequest, IdentityDeviceKeyResponse, IdentityDeviceStatus, IdentityDeviceSummary, IdentityProof, IdentityProviders, IdentityTokenClaims, type ModeContribution, type ModeFile, NATIVE_HOST_MODULES, NATIVE_HOST_MODULE_IDS, NATIVE_UNISTYLES_COMPONENTS, NATIVE_UNISTYLES_COMPONENT_PREFIX, type NativeSessionView, type NativeTemplateAsk, type NativeTemplateComposerOptions, type NativeTemplateContribution, type NativeTemplateFile, type NativeTemplateScreens, type NativeTemplateSessionHeader, type NativeTemplateSessionProps, type NativeTemplateSessionsActions, type NativeTemplateSessionsProps, type OnboardingContext, type OnboardingContribution, type OnboardingFile, type OnboardingProps, PO_FEDERATION_CLIENT_SERVICE, type PluginCatalog, type PluginTier, type PoApprovalPrompt, type PoClientMetadata, PoFederationClient, READ_OPERATION_NAMES, type SelectionAxisContribution, type SelectionAxisFile, type SessionChannelContribution, type SessionFrameSender, type SessionRecords, type SessionSetupActionContribution, type SessionStore, type SessionStoreChannel, type SettingsPanelContribution, type SettingsPanelFile, type SettingsPanelProps, type SettingsSectionContribution, type SettingsSectionFile, type SlotDeclaration, type SlotFile, type SlotFillContribution, type TabContribution, type TabFile, type TabHeader, type ThemeContribution, type ThemeFile, type ToolMessageRenderProps, type ToolPromptRenderProps, type ToolRendererContribution, type ToolRendererFile, type ToolResultView, type UserMessageActionContribution, type UserMessageActionFile, type UserMessageActionRunContext, type WebPluginContributions, type WebPluginDefinition, type WebPluginRuntime, type WebPluginSessionContext, type WebPluginSessionOption, type WebPluginSlotProps, type WebTemplateRailActions, type WebTemplateRailDirectoryListing, type WebTemplateRailPendingSetup, type WebTemplateRailSession, type WebTemplateRailWorkflow, type WebTemplateRailWorkspace, type WorkspaceRecords, type WorkspaceStore, apiResponse, applyPathParams, bindNativeByteCodec, clientMetadata, createApiClient, decodeBase64, defineActivityGroup, defineApiRoutes, defineChannelFile, defineDockFace, defineFileLinks, defineFill, defineHostProvider, defineHostStore, defineModeFile, defineWebPlugin as defineNativePlugin, defineNativeTemplate, defineOnboarding, defineSelectionAxis, defineSessionChannel, defineSessionStore, defineSettingsPanel, defineSettingsSection, defineSlot, defineSlotFile, defineTab, defineTheme, defineToolRenderer, defineUserMessageAction, defineWebLifecycle, defineWorkspaceStore, encodeBase64, federationEnrollmentGeneration, hostRevisionTopic, hubRevision, identityProofFields, isPoClientToken, nativeApiTransport, nonPortableConfigYaml, normalizeFederationOperations, parseHomeContribution, parseHomeEntity, parseHomeProjection, parseHomeSnapshot, parseNativeTemplate, parseOnboarding, parsePoApprovalPrompt, pluginCatalogLayerSchema, pluginCatalogSchema, pluginTierSchema, poClientMetadataFrom, railStepRows, sessionApiAddress, sessionApiPath, splitConsentOperations, subscribeHubRevision, tierOf, toolResultText, toolResultTextLines, updateClientDeviceName, workspaceRevisionTopic };