mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 18:47:40 +00:00
* fix(mobile): open Grok, OpenCode, OMP and Pi chats on the phone The phone advertised only the Claude chat lane, so the host retitled every other agent's chat tab 'Update to view' and the phone's resolver refused non-Claude/Codex chat tabs anyway. Mobile now reads any agent the host lists, passes the chat's real agent to its send and slash-command paths, advertises the registered-agents and Pi dialog capabilities, hides image attach for agents the host says take none (as desktop does), and draws Pi's input dialog as one line. * test(mobile): drive the agents read through the shared fake client * fix(mobile): read options reports with no model Grok, OpenCode and OMP can report no current model, and a chat at rest may have none saved. The host refuses those reports to clients that don't advertise agent-session.options.optional-model.v1, which left the phone's model picker on its seed list and dropped /clear and /compact. * fix(mobile): reserve the chat session for every launched agent The phone matches a launched chat tab only by its session id, which it minted only for Claude and Codex. A Grok, OpenCode, OMP or Pi chat started from + landed only once the host replied, and a lost reply read as "Couldn't confirm the agent started" even with the chat listed. Hosts accept an agent-named id for any agent and ignore it for a terminal launch. * fix(mobile): read the host's agents once per connection, retry after a failure Every session-screen mount asked agentSession.agents again, so the attach button popped in late for OpenCode and Pi, and a read that failed while connected was never retried. Share one read per client, drop it on disconnect, and forget a failed read so the next chat asks again. * test(mobile): pin the chat's own agent on the send path and attach gating The send-bridge test passed with the claude/codex narrowing reverted. Drive an OpenCode chat through the controller and the structured session's send, where /review is the agent's own command but Codex's host claims it, and check the overlay offers attach only when the agent takes images. * fix(mobile): offer a card's X only while a turn is running The X on a structured prompt card stops its turn. Pi opens dialogs outside a turn too, and tapping X there could only say "Stop not sent". Claude and Codex cards arrive inside a running turn, so they keep their X. * fix(runtime): let a phone read the host's registered agents The phone now asks agentSession.agents to decide whether a chat's agent takes images, but the mobile allowlist refused the method, so OpenCode and Pi never got an attach button. It returns only each agent's id and its fixed capability record. * fix(mobile): keep a host's refusal of the agents list for the connection Released hosts advertise registered agents but refuse agentSession.agents to phones (forbidden, not available to mobile clients). Treat that answer as no list until the next connection instead of re-asking on every chat; keep retrying transient failures. * fix(mobile): shrink the model pill before it pushes Send off the composer row On a narrow phone, attach + a long model label + mic left no room for Send (seen with Pi's resting label). The pill's slot is now the row's only shrinkable item, so its label truncates and the buttons keep their size. Rows that already fit look the same. * fix(mobile): keep /clear and /compact for a chat whose agent lists no models The phone dropped a structured chat's option controller when its picker had nothing to show, and the / menu reads the chat's conversation commands from that controller. OMP lists no models, so its menu lost /clear and /compact. Keep the controller for every structured chat; the picker still renders nothing without a model. * feat(runtime): say in a chat's options report whether it takes images The host's options read now carries acceptsImages for every session: the agent definition's imagePrompts, narrowed by a running ACP child to what its initialize advertised (the same rule its sends use). Absent means an older host. * refactor(mobile): read whether a chat takes images from its options report The phone no longer reads the host's agent list for the attach button. It takes acceptsImages from the agentSession.options read it already makes, keyed to the chat, and kept through a pick made during that read. Before the read answers, and from an older host, Claude and Codex keep attach and other agents don't, as before. Drops the agent-list hook with its cache and refusal latch, the host-support flag only it used, and agentSession.agents from the host's mobile allowlist. * refactor(native-chat): gate desktop chat images on the session's options report The composer's image gate takes the session's acceptsImages answer first, falling back to the host's agent list before the options read lands (a new chat's start) and for an older host that sends no answer. With the phone no longer using it, structuredAgentAcceptsImages moves back to the renderer, where it was. * test(native-chat): prove the session's image answer reaches the composer gate
201 lines
6.4 KiB
TypeScript
201 lines
6.4 KiB
TypeScript
import { createElement } from 'react'
|
|
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { MobileNativeChatQuestion } from './MobileNativeChatQuestion'
|
|
|
|
vi.mock('react-native', () => ({
|
|
Pressable: 'Pressable',
|
|
StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 },
|
|
Text: 'Text',
|
|
TextInput: 'TextInput',
|
|
View: 'View'
|
|
}))
|
|
|
|
vi.mock('lucide-react-native', () => ({
|
|
ArrowUp: 'ArrowUp',
|
|
Check: 'Check',
|
|
ChevronDown: 'ChevronDown',
|
|
ChevronUp: 'ChevronUp',
|
|
CircleHelp: 'CircleHelp',
|
|
X: 'X'
|
|
}))
|
|
|
|
describe('MobileNativeChatQuestion', () => {
|
|
let renderer: ReactTestRenderer | null = null
|
|
|
|
afterEach(() => {
|
|
act(() => renderer?.unmount())
|
|
renderer = null
|
|
})
|
|
|
|
it('submits the selected duplicate-label row by position', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick regions',
|
|
options: ['Region', 'Region'],
|
|
multiSelect: true,
|
|
allowOther: false,
|
|
optionTokens: ['first-token', 'second-token']
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'checkbox' })
|
|
await act(async () => choices[1]!.props.onPress())
|
|
const submit = renderer.root.findByProps({ accessibilityLabel: 'Submit selected options' })
|
|
await act(async () => submit.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('second-token')
|
|
})
|
|
|
|
it('submits a tokenless duplicate-label row by position', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick one',
|
|
options: ['Choice', 'Choice'],
|
|
multiSelect: false,
|
|
allowOther: false,
|
|
optionTokens: ['first-token', null]
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'button' })
|
|
await act(async () => choices[1]!.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('Choice')
|
|
})
|
|
|
|
it('submits structured multi-select choices together with other text', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick regions',
|
|
options: ['us-east', 'eu-west'],
|
|
multiSelect: true,
|
|
allowOther: true,
|
|
optionTokens: ['east-token', 'west-token'],
|
|
freeTextToken: 'other-token'
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const choices = renderer.root.findAllByProps({ accessibilityRole: 'checkbox' })
|
|
await act(async () => choices[0]!.props.onPress())
|
|
const input = renderer.root.findByType('TextInput')
|
|
await act(async () => input.props.onChangeText('ap-south'))
|
|
const submit = renderer.root.findByProps({ accessibilityLabel: 'Submit selected options' })
|
|
await act(async () => submit.props.onPress())
|
|
|
|
expect(onAnswer).toHaveBeenCalledWith('east-token, other-token:ap-south')
|
|
})
|
|
|
|
it('passes the rendered prompt identity to cancel', async () => {
|
|
const onCancel = vi.fn(async () => true)
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Pick one',
|
|
prompt: { itemId: 'question-1', expectedRevision: 7 },
|
|
options: ['Choice'],
|
|
multiSelect: false,
|
|
allowOther: false,
|
|
optionTokens: ['choice-token']
|
|
},
|
|
onAnswer: vi.fn(async () => true),
|
|
onCancel
|
|
})
|
|
)
|
|
})
|
|
const cancel = renderer.root.findByProps({ accessibilityLabel: 'Cancel' })
|
|
await act(async () => cancel.props.onPress())
|
|
expect(onCancel).toHaveBeenCalledWith({ itemId: 'question-1', expectedRevision: 7 })
|
|
})
|
|
|
|
it('prefills an editor and sends its whitespace unchanged', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
question: {
|
|
question: 'Edit the draft',
|
|
options: [],
|
|
multiSelect: false,
|
|
optionTokens: [],
|
|
freeTextToken: 'editor-token',
|
|
freeTextInput: {
|
|
allowEmpty: true,
|
|
multiline: true,
|
|
initialValue: ' draft\n',
|
|
placeholder: 'Write here'
|
|
}
|
|
},
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
|
|
const input = renderer.root.findByType('TextInput')
|
|
expect(input.props).toMatchObject({
|
|
value: ' draft\n',
|
|
placeholder: 'Write here',
|
|
multiline: true
|
|
})
|
|
await act(async () => input.props.onChangeText(' \n '))
|
|
const send = renderer.root.findByProps({ accessibilityLabel: 'Send reply' })
|
|
expect(send.props.disabled).toBe(false)
|
|
await act(async () => send.props.onPress())
|
|
expect(onAnswer).toHaveBeenCalledWith(`editor-token:${encodeURIComponent(' \n ')}`)
|
|
})
|
|
|
|
it('sends an empty allowed answer and still disables an empty legacy answer', async () => {
|
|
const onAnswer = vi.fn(async () => true)
|
|
const question = {
|
|
question: 'Input',
|
|
options: [],
|
|
multiSelect: false,
|
|
optionTokens: [],
|
|
freeTextToken: 'input-token'
|
|
}
|
|
await act(async () => {
|
|
renderer = create(
|
|
createElement(MobileNativeChatQuestion, {
|
|
// Pi's `input` dialog: a declared input that names no `multiline`.
|
|
question: { ...question, freeTextInput: { allowEmpty: true } },
|
|
onAnswer
|
|
})
|
|
)
|
|
})
|
|
const send = renderer.root.findByProps({ accessibilityLabel: 'Send reply' })
|
|
expect(renderer.root.findByType('TextInput').props.multiline).toBe(false)
|
|
expect(send.props.disabled).toBe(false)
|
|
await act(async () => send.props.onPress())
|
|
expect(onAnswer).toHaveBeenCalledWith('input-token:')
|
|
|
|
await act(async () =>
|
|
renderer.update(createElement(MobileNativeChatQuestion, { question, onAnswer }))
|
|
)
|
|
expect(renderer.root.findByProps({ accessibilityLabel: 'Send reply' }).props.disabled).toBe(
|
|
true
|
|
)
|
|
})
|
|
})
|