mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 16:03:47 +00:00
fix(native-chat): preserve handoff launch authority
This commit is contained in:
@@ -75,9 +75,10 @@ import {
|
||||
import { ensureStructuredAgentSessionHost as installStructuredAgentSessionHost } from './structured-agent-session-runtime'
|
||||
import { getStructuredAgentSessionHost } from '../native-chat/agent-session-wire/structured-agent-session-registry'
|
||||
import type { AgentSessionAttachParams } from '../native-chat/agent-session-wire/structured-agent-session-attach'
|
||||
import type {
|
||||
StructuredAgentSessionHandoffTransport,
|
||||
StructuredTuiOwner
|
||||
import {
|
||||
StructuredTuiLaunchCleanupError,
|
||||
type StructuredAgentSessionHandoffTransport,
|
||||
type StructuredTuiOwner
|
||||
} from '../native-chat/agent-session-wire/structured-agent-session-handoff-types'
|
||||
import type { AgentSessionRecord } from '../../shared/agent-session-record'
|
||||
import {
|
||||
@@ -9121,7 +9122,7 @@ export class OrcaRuntimeService {
|
||||
private createStructuredAgentSessionHandoffTransport(): StructuredAgentSessionHandoffTransport {
|
||||
return {
|
||||
hostLabel: hostname(),
|
||||
launchTui: async ({ record, fence, spawnToken }) => {
|
||||
launchTui: async ({ record, fence, spawnToken, onSpawned }) => {
|
||||
const head = record.providerHandleChain.at(-1)
|
||||
if (head?.handle.provider !== 'codex') {
|
||||
throw new Error('agent_session_identity_required')
|
||||
@@ -9142,23 +9143,10 @@ export class OrcaRuntimeService {
|
||||
if (!terminal.processId || !terminal.paneKey || !terminal.tabId || !terminal.ptyId) {
|
||||
throw new Error('The resumed terminal did not publish a process identity.')
|
||||
}
|
||||
await this.waitForTerminal(terminal.handle, {
|
||||
condition: 'tui-idle',
|
||||
timeoutMs: 30_000
|
||||
})
|
||||
const proof = await this.waitForStructuredTuiProof({
|
||||
handle: terminal.handle,
|
||||
paneKey: terminal.paneKey,
|
||||
threadId: head.handle.threadId,
|
||||
spawnToken,
|
||||
codexHome: record.accountHome.path,
|
||||
sessionId: record.sessionId
|
||||
})
|
||||
const revealed = await this.focusTerminal(terminal.handle)
|
||||
return this.refreshStructuredTuiOwnerBinding({
|
||||
const spawnedOwner = this.refreshStructuredTuiOwnerBinding({
|
||||
terminal: {
|
||||
handle: terminal.handle,
|
||||
tabId: revealed.tabId,
|
||||
tabId: terminal.tabId,
|
||||
paneKey: terminal.paneKey,
|
||||
ptyId: terminal.ptyId
|
||||
},
|
||||
@@ -9173,15 +9161,43 @@ export class OrcaRuntimeService {
|
||||
resumed: true,
|
||||
fence,
|
||||
observedAt: Date.now()
|
||||
}),
|
||||
})
|
||||
})
|
||||
await onSpawned?.(spawnedOwner)
|
||||
await this.waitForTerminal(terminal.handle, {
|
||||
condition: 'tui-idle',
|
||||
timeoutMs: 30_000
|
||||
})
|
||||
const proof = await this.waitForStructuredTuiProof({
|
||||
handle: terminal.handle,
|
||||
paneKey: terminal.paneKey,
|
||||
threadId: head.handle.threadId,
|
||||
spawnToken,
|
||||
codexHome: record.accountHome.path,
|
||||
sessionId: record.sessionId
|
||||
})
|
||||
const revealed = await this.focusTerminal(terminal.handle)
|
||||
return this.refreshStructuredTuiOwnerBinding({
|
||||
...spawnedOwner,
|
||||
terminal: {
|
||||
handle: terminal.handle,
|
||||
tabId: revealed.tabId,
|
||||
paneKey: terminal.paneKey,
|
||||
ptyId: terminal.ptyId
|
||||
},
|
||||
process: spawnedOwner.process,
|
||||
...(proof.transcriptPath ? { transcriptPath: proof.transcriptPath } : {})
|
||||
})
|
||||
} catch (error) {
|
||||
await this.closeTerminal(terminal.handle)
|
||||
await this.waitForTerminal(terminal.handle, {
|
||||
condition: 'exit',
|
||||
timeoutMs: 15_000
|
||||
})
|
||||
try {
|
||||
await this.closeTerminal(terminal.handle)
|
||||
await this.waitForTerminal(terminal.handle, {
|
||||
condition: 'exit',
|
||||
timeoutMs: 15_000
|
||||
})
|
||||
} catch (cleanupError) {
|
||||
throw new StructuredTuiLaunchCleanupError(error, cleanupError)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user