mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* Keep inherited fork actions with the original chat * Keep fork boundary tests aligned with inherited actions * Keep inherited fork actions with their original chat * Keep fork refusal tests within their typecheck projects * Allow phone forks for supported agents beyond Claude and Codex * Gate inherited tip forks on host original-chat support * Require current host proof for inherited fork offers * Bind inherited fork actions to the current host runtime * Keep unsent browser forks definitive and offer accurate retry guidance * Offer copied tip forks only at the fork point and name their source * Offer forks on all completed copied replies * Explain which original response can be forked
66 lines
2.7 KiB
TypeScript
66 lines
2.7 KiB
TypeScript
import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'
|
|
import { useHostProtocolGates } from '../components/host-protocol-gates-context'
|
|
import type { TuiAgent } from '../../../src/shared/agent-launch/catalog/tui-agent'
|
|
import type { StructuredAgentSessionForkSource } from '../../../src/shared/agent-session/structured-agent-session-create'
|
|
import { MobileNativeChatForkedFromContext } from './mobile-native-chat-notice-context'
|
|
import { forkMobileStructuredChat } from './mobile-structured-chat-fork'
|
|
import {
|
|
MobileNativeChatForkContext,
|
|
useMobileNativeChatFork
|
|
} from './native-chat/use-mobile-native-chat-fork'
|
|
import { resolveMobileNativeChatSessionId } from './native-chat/mobile-native-chat-eligibility'
|
|
import type { MobileSessionController } from './use-mobile-session-controller'
|
|
|
|
/** The chat's "Fork from this response" and the chat a "Forked from" divider opens. */
|
|
export function MobileNativeChatForkProvider({
|
|
controller,
|
|
children
|
|
}: {
|
|
controller: MobileSessionController
|
|
children: React.ReactNode
|
|
}): React.JSX.Element {
|
|
const { client, nativeChatController: chat, openNativeSession, worktreeId } = controller
|
|
const { statusPending } = useHostProtocolGates()
|
|
// The controller is rebuilt each render; a fork reads its session state at the press.
|
|
const latestController = useRef(controller)
|
|
useLayoutEffect(() => {
|
|
latestController.current = controller
|
|
})
|
|
const createFork = useCallback(
|
|
(agent: TuiAgent, forkFrom: StructuredAgentSessionForkSource) =>
|
|
forkMobileStructuredChat(latestController.current, agent, forkFrom),
|
|
[]
|
|
)
|
|
const fork = useMobileNativeChatFork({
|
|
client,
|
|
hostCapabilities: controller.hostCapabilities,
|
|
hostStatusPending: statusPending || controller.connState !== 'connected',
|
|
agent: chat.nativeChatAgent,
|
|
sessionId: resolveMobileNativeChatSessionId(controller.activeSessionTab),
|
|
messages: chat.nativeChatSession.messages,
|
|
turnJournal: chat.nativeChatTurnJournal,
|
|
agentWorking: chat.nativeChatTurnActive,
|
|
sessionForkSupport: chat.nativeChatForkSupport,
|
|
createFork
|
|
})
|
|
// A fork and its source share a workspace and host.
|
|
const openSource = useMemo(
|
|
() =>
|
|
client
|
|
? (sourceSessionId: string) =>
|
|
void openNativeSession({
|
|
kind: 'history',
|
|
structuredSession: { sessionId: sourceSessionId, workspaceId: worktreeId }
|
|
})
|
|
: undefined,
|
|
[client, openNativeSession, worktreeId]
|
|
)
|
|
return (
|
|
<MobileNativeChatForkContext.Provider value={fork}>
|
|
<MobileNativeChatForkedFromContext.Provider value={openSource}>
|
|
{children}
|
|
</MobileNativeChatForkedFromContext.Provider>
|
|
</MobileNativeChatForkContext.Provider>
|
|
)
|
|
}
|