mirror of
https://github.com/stablyai/orca.git
synced 2026-10-02 00:02:05 +00:00
* feat(mobile): native-chat model/session-option picker + shared slash catalog (STA-3332) Piece A — shared slash catalog + send classification: - Mobile composer now serves getVerifiedNativeChatCommands from the shared catalog (agent-aware, with description rows) instead of a hardcoded provider-agnostic list that advertised commands Claude does not have. - classifyNativeChatSend moves to src/shared/native-chat-slash-commands.ts (renderer re-exports keep desktop import paths stable); mobile's send seam now gates optimistic echoes on it, so slash sends no longer create a 'Queued' bubble that no transcript echo can ever retire, and the ack-lost hold only arms for chat sends. Piece B — mobile model/session-option pickers: - New per-tab session-option tracking (state/commands/labels modules) ported from the desktop live flow, reading the shared agent-session-option catalog for Claude AND Codex. - Composer pill row (model + options) opening an inline choice card in the proven Ask-card pattern; applies use catalog modelApply semantics (/model <value> via the existing send path), Codex-style agent-picker entries dispatch the picker command and flip the tab to the terminal view. - Current model seeds from the hook-reported provider model when derivable; typed /model-style commands update tracked state (recordOutgoingCommand parity); dispatched values render as sent-not-confirmed. * fix(mobile): keep session option sends scoped * fix(mobile): synchronize native chat refs after commit * refactor: share native chat session option logic * fix(mobile): keep the live tab's session-option record from eviction `getScopedRecord` returned an existing record without re-inserting it, so the per-tab record map evicted by insertion order rather than recency. A long-lived active tab is the oldest key, so crossing the 32-scope cap silently dropped its tracked model and reset the pill to "Model". Desktop's scope cache does delete-then-set for exactly this reason. Also moves the shared session-option tests to src/shared so the root suite runs them (they only exercised src/shared logic the Electron renderer consumes, but sat under mobile/ where only mobile's vitest project sees them), and restores two "why" comments dropped while extracting the shared modules. * fix(mobile): stop a stale session-start report reverting a model pick Re-entering a chat tab re-delivers the same `agentStatus.model`, and the reported-model effect re-applied it unconditionally — so picking a model, moving to another tab, and coming back reverted the pill to the model the agent reported at session start, which cannot have observed the `/model` sent after it. The status stream reconnecting had the same effect. A report is now only treated as evidence when the matched catalog id CHANGES for that scope; a genuinely new report still supersedes a local pick. Mobile has no screen read to confirm a switch against, so the repeat is all we can key off. * fix(mobile): close four session-option picker defects found in review D1 — a picker apply could interleave with a composer send. The composer already blocks a text send while an apply is dispatching, but not the reverse: the host spaces a send's body and its Enter ~500ms apart, so an apply tapped inside that window was submitted as part of the user's prompt, and the pill then claimed a model change that never ran as a command. The pickers render inside the composer, so they now take its in-flight state directly — the same guard, mirrored. D2 — an option was filed under the wrong model. `setTrackedSessionOption` resolves the owning model when it commits, not when the command was built, and the report effect mutates the same record off-queue. A report landing mid-dispatch therefore recorded `/effort low` against the model it switched TO. Ports desktop's supersession guard, which skips the commit when the baseline moved. D3 — a command template's prefix also matches prose that starts with it, so "/model is a weird word" tracked that prose as the current model, rendered it as the pill label, and matched no catalog model, dropping every per-model option. Parsed values are now canonicalized against the catalog; a typed value containing whitespace is treated as a prompt rather than a command. Perf — `/` on a Codex tab returned all 45 commands into a non-virtualized ScrollView showing ~5, re-reconciled on every streaming tick above the transcript. Capped at 12. Also splits the row primitives out of MobileNativeChatSessionOptionPickers.tsx, which the D1 guard pushed to 402 effective lines against a 400 cap. * refactor: share the session-option display ordering CATEGORY_ORDER and the non-model sort were byte-identical in NativeChatSessionOptionPickers.tsx and mobile's labels module — pure logic with no i18n in it, so there was no reason for two copies that can drift. Both now call sortNativeChatSessionOptions from the shared snapshot module. * refactor(mobile): align model picker layout * style(mobile): round native chat composer * fix(mobile): inset rounded chat composer
207 lines
7.2 KiB
TypeScript
207 lines
7.2 KiB
TypeScript
import { useState } from 'react'
|
|
import { ActivityIndicator, Keyboard, Pressable, StyleSheet, Text, View } from 'react-native'
|
|
import { ChevronLeft, X } from 'lucide-react-native'
|
|
import { BottomDrawer } from '../components/BottomDrawer'
|
|
import { colors, radii, spacing, typography } from '../theme/mobile-theme'
|
|
import type {
|
|
SessionOptionDescriptor,
|
|
SessionOptionValue
|
|
} from '../../../src/shared/native-chat-session-options'
|
|
import {
|
|
mobileModelPillLabel,
|
|
mobileOptionsPillLabel,
|
|
mobileSessionOptionSummaryValue,
|
|
mobileSessionOptionDisabledReason
|
|
} from './mobile-native-chat-session-option-labels'
|
|
import {
|
|
DescriptorRows,
|
|
Pill,
|
|
SessionOptionCaption,
|
|
SessionOptionSummaryRow
|
|
} from './MobileNativeChatSessionOptionRows'
|
|
import { sortNativeChatSessionOptions } from '../../../src/shared/native-chat-session-option-snapshot'
|
|
import type { MobileNativeChatSessionOptionsController } from './use-mobile-native-chat-session-options'
|
|
|
|
export type MobileNativeChatSessionOptionPickersProps = {
|
|
controller: MobileNativeChatSessionOptionsController
|
|
/** Pickers lock while the agent works — a mid-turn `/model` interleaves with
|
|
* the agent's own output (desktop parity). */
|
|
isWorking: boolean
|
|
/** A composer send owns the TUI input line until it settles. The host spaces a
|
|
* send's body and its Enter ~500ms apart, so an apply dispatched inside that
|
|
* window would be submitted as part of the user's prompt. The composer blocks
|
|
* the reverse direction on `pendingId`; this is the same guard mirrored. */
|
|
sendInFlight?: boolean
|
|
}
|
|
|
|
/** Combined model/session-option trigger and its mobile bottom drawer. */
|
|
export function MobileNativeChatSessionOptionPickers({
|
|
controller,
|
|
isWorking,
|
|
sendInFlight = false
|
|
}: MobileNativeChatSessionOptionPickersProps): React.JSX.Element | null {
|
|
const [openDescriptorId, setOpenDescriptorId] = useState<string | null>(null)
|
|
const { snapshot, pendingId } = controller
|
|
const model = snapshot.find((descriptor) => descriptor.category === 'model')
|
|
const options = sortNativeChatSessionOptions(snapshot)
|
|
if (!model) {
|
|
return null
|
|
}
|
|
const disabled = isWorking || pendingId !== null || sendInFlight
|
|
const activeDescriptor = snapshot.find((descriptor) => descriptor.id === openDescriptorId)
|
|
const modelView = activeDescriptor?.id === model.id
|
|
const modelLabel = mobileModelPillLabel(model)
|
|
const optionsLabel = options.length > 0 ? mobileOptionsPillLabel(options) : null
|
|
const pillLabel = optionsLabel ? `${modelLabel} ${optionsLabel}` : modelLabel
|
|
const reason = mobileSessionOptionDisabledReason(activeDescriptor?.disabledReason)
|
|
|
|
const closePicker = (): void => setOpenDescriptorId(null)
|
|
const openPicker = (): void => {
|
|
Keyboard.dismiss()
|
|
setOpenDescriptorId(model.id)
|
|
}
|
|
|
|
const applyOption = (descriptor: SessionOptionDescriptor, value: SessionOptionValue): void => {
|
|
// Re-picking the tracked value is a no-op — never re-dispatch it.
|
|
if (
|
|
descriptor.valueSource !== 'unknown' &&
|
|
descriptor.kind.type === 'select' &&
|
|
descriptor.kind.currentValue === value
|
|
) {
|
|
closePicker()
|
|
return
|
|
}
|
|
void controller.setOption(descriptor.id, value).then((applied) => {
|
|
if (applied) {
|
|
closePicker()
|
|
}
|
|
})
|
|
}
|
|
const invokeAction = (descriptor: SessionOptionDescriptor): void => {
|
|
void controller.invokeAction(descriptor.id).then((invoked) => {
|
|
if (invoked) {
|
|
closePicker()
|
|
}
|
|
})
|
|
}
|
|
|
|
return (
|
|
<View>
|
|
<Pill
|
|
label={pillLabel}
|
|
accessibleName={`Model, ${pillLabel}`}
|
|
disabled={disabled}
|
|
onPress={openPicker}
|
|
/>
|
|
<BottomDrawer visible={activeDescriptor !== undefined} onClose={closePicker}>
|
|
{activeDescriptor ? (
|
|
<View style={styles.sheet}>
|
|
<View style={styles.sheetHeader}>
|
|
<Pressable
|
|
accessibilityLabel={modelView ? 'Close picker' : 'Back to models'}
|
|
accessibilityRole="button"
|
|
style={({ pressed }) => [styles.sheetNav, pressed && styles.pressed]}
|
|
onPress={modelView ? closePicker : () => setOpenDescriptorId(model.id)}
|
|
hitSlop={8}
|
|
>
|
|
{modelView ? (
|
|
<X size={18} color={colors.textSecondary} strokeWidth={2.2} />
|
|
) : (
|
|
<ChevronLeft size={18} color={colors.textSecondary} strokeWidth={2.2} />
|
|
)}
|
|
</Pressable>
|
|
<Text style={styles.sheetTitle}>
|
|
{modelView ? 'Select model' : `Select ${activeDescriptor.label.toLowerCase()}`}
|
|
</Text>
|
|
<View style={styles.sheetHeaderSide}>
|
|
{pendingId !== null ? (
|
|
<ActivityIndicator size="small" color={colors.textSecondary} />
|
|
) : null}
|
|
</View>
|
|
</View>
|
|
{activeDescriptor.valueSource === 'dispatched' ? (
|
|
<SessionOptionCaption>Sent to the agent — not confirmed</SessionOptionCaption>
|
|
) : null}
|
|
{reason ? <SessionOptionCaption>{reason}</SessionOptionCaption> : null}
|
|
<View style={styles.choiceGroup}>
|
|
<DescriptorRows
|
|
descriptor={activeDescriptor}
|
|
disabled={disabled}
|
|
grouped
|
|
onSetOption={(value) => applyOption(activeDescriptor, value)}
|
|
onInvokeAction={() => invokeAction(activeDescriptor)}
|
|
/>
|
|
</View>
|
|
{modelView && options.length > 0 ? (
|
|
<View style={styles.optionGroup}>
|
|
{options.map((descriptor, index) => (
|
|
<SessionOptionSummaryRow
|
|
key={descriptor.id}
|
|
label={descriptor.label}
|
|
value={mobileSessionOptionSummaryValue(descriptor)}
|
|
disabled={disabled}
|
|
divided={index < options.length - 1}
|
|
onPress={() => setOpenDescriptorId(descriptor.id)}
|
|
/>
|
|
))}
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
) : null}
|
|
</BottomDrawer>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
sheet: {
|
|
paddingBottom: spacing.xs
|
|
},
|
|
sheetHeader: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
paddingBottom: spacing.lg
|
|
},
|
|
sheetTitle: {
|
|
flex: 1,
|
|
color: colors.textPrimary,
|
|
fontSize: typography.titleSize,
|
|
fontWeight: '700',
|
|
textAlign: 'center'
|
|
},
|
|
sheetNav: {
|
|
width: 36,
|
|
height: 36,
|
|
borderRadius: 18,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
backgroundColor: colors.bgRaised,
|
|
borderWidth: StyleSheet.hairlineWidth,
|
|
borderColor: colors.borderSubtle
|
|
},
|
|
sheetHeaderSide: {
|
|
width: 36,
|
|
height: 36,
|
|
alignItems: 'center',
|
|
justifyContent: 'center'
|
|
},
|
|
choiceGroup: {
|
|
overflow: 'hidden',
|
|
borderRadius: radii.card,
|
|
borderWidth: StyleSheet.hairlineWidth,
|
|
borderColor: colors.borderSubtle,
|
|
backgroundColor: colors.bgRaised
|
|
},
|
|
optionGroup: {
|
|
overflow: 'hidden',
|
|
marginTop: spacing.md,
|
|
borderRadius: radii.card,
|
|
borderWidth: StyleSheet.hairlineWidth,
|
|
borderColor: colors.borderSubtle,
|
|
backgroundColor: colors.bgRaised
|
|
},
|
|
pressed: {
|
|
opacity: 0.7
|
|
}
|
|
})
|