Files
orca/mobile/src/session/use-mobile-structured-transcript.ts
T
Kelvin Amoaba ce3fe75891 feat(mobile): set, pause, resume and clear a chat's goal from the phone (#38447)
* feat(mobile): set, pause, resume and clear a chat's goal from the phone

The phone sent /goal to the agent as plain text and showed no goal. It now
has desktop's goal mode (Goal chip, goal placeholder) and a goal strip on the
composer's top edge that expands to Pause/Resume and Clear goal.

The goal logic desktop and mobile share moves to src/shared: the goal report
(journal rows over the options answer), status labels, elapsed format, the
goal-mode pick rule and the goal row filter. agentSession.threadGoal joins the
phone allowlist behind agent-session.thread-goal.phone.v1, so older hosts keep
showing the goal without offering changes.

* fix(mobile): open each new goal's strip collapsed

* fix(mobile): keep goal sends' delivery choice and scope goal locks per chat

* fix(mobile): offer goal changes only when the paired desktop relays them

* test(mobile): pin which goal changes the phone offers per host

* refactor(mobile): reuse the queued box style and keep the goal strip stable per chunk

* fix(mobile): set phone goals through the composer's changeThreadGoal
2026-11-05 22:42:44 +00:00

47 lines
2.1 KiB
TypeScript

import { useMemo } from 'react'
import { agentSessionTranscriptRows } from '../../../src/shared/agent-session/agent-session-context-clear'
import type { StructuredAgentSessionState } from '../../../src/shared/agent-session/structured-agent-session-reducer'
import { projectStructuredAgentSessionMessages } from '../../../src/shared/agent-session/view/structured-agent-session-message-projection'
import { tuiAgentDisplayName } from '../../../src/shared/agent-launch/catalog/tui-agent-display-names'
import { withNativeChatCutTurnNotices } from '../../../src/shared/native-chat/transcript/native-chat-cut-turn-notice'
import { omitNativeChatThreadGoalRows } from '../../../src/shared/native-chat/transcript/native-chat-thread-goal-rows'
import { createStructuredQuestionProjection } from '../../../src/shared/structured-agent-question-projection'
import { projectStructuredAgentStartItem } from '../../../src/shared/structured-agent-start-projection'
const mobileStructuredTranscript = createStructuredQuestionProjection(
projectStructuredAgentStartItem
)
/** The chat's transcript rows, its messages with this phone's sends in flight, and the prompts they resolved. */
export function useMobileStructuredTranscript(
agent: string | null,
state: Pick<StructuredAgentSessionState, 'items' | 'submissions'>,
optimistic: Parameters<typeof projectStructuredAgentSessionMessages>[1]
) {
const transcriptItems = useMemo(
() =>
withNativeChatCutTurnNotices(agentSessionTranscriptRows(state.items), {
agentName: agent ? (tuiAgentDisplayName(agent) ?? agent) : undefined
}),
[agent, state.items]
)
const messages = useMemo(
() =>
// The goal strip on the composer shows goal state, as on desktop.
omitNativeChatThreadGoalRows(
projectStructuredAgentSessionMessages(
transcriptItems,
optimistic,
state.submissions,
mobileStructuredTranscript.messages
)
),
[transcriptItems, optimistic, state.submissions]
)
return {
transcriptItems,
messages,
receipts: mobileStructuredTranscript.transcript(transcriptItems).receipts
}
}