Repository navigation
feat(mobile): Model configuration and Task model list (#4860 S3c) #4970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,545
−75
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
89a2537
feat(mobile): Model configuration page with Default, Presets and Rout…
DoodleBears a173822
feat(mobile): Task model list in the preset editor and Bot model page…
DoodleBears 97957d6
fix(mobile): save an edited Task model note when leaving its page
DoodleBears 2a4fcfa
test(mobile): find the Model configuration row by its new label
DoodleBears e33e09d
fix(mobile): queue Task model note saves, keep the newest draft, and …
DoodleBears d5bab82
fix(mobile): keyboard-aware forms; queue notes against the last queue…
DoodleBears 79f77b9
fix(host-client): run model settings writes for one scope in order
DoodleBears 18e9cd7
fix(mobile): keep a failed Task model note draft and its error for th…
DoodleBears c8c5be8
fix(mobile): scope failed note drafts to the Host and clear them on a…
DoodleBears 96d715a
fix(mobile): keep Task model note commits in order across visits
DoodleBears e675f8c
fix(mobile): drop a failed note draft that a newer pending note super…
DoodleBears c331e80
fix(mobile): track note commits by id so only the latest commit owns …
DoodleBears aa34368
test(mobile): store the older failed note before checking that a newe…
DoodleBears 15e3edc
fix(mobile): a new note commit drops the older failed draft; reopenin…
DoodleBears 69f896c
fix(mobile): drop a failed note draft when the field returns to the s…
DoodleBears File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { SubChoiceRoute } from '../../../src/ui/chat/sub-choice-screen'; | ||
|
|
||
| export default function BotSubChoiceScreen() { | ||
| return <SubChoiceRoute kind="bot" />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ModelPresetNewScreen } from '../../src/ui/chat/model-preset-new-screen'; | ||
|
|
||
| export default function ModelPresetNewRoute() { | ||
| return <ModelPresetNewScreen />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { SubChoiceRoute } from '../../src/ui/chat/sub-choice-screen'; | ||
|
|
||
| export default function PresetSubChoiceScreen() { | ||
| return <SubChoiceRoute kind="preset" />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { ModelSettingsScreen } from '../../src/ui/chat/model-settings-route'; | ||
| import { ModelConfigurationScreen } from '../../src/ui/chat/model-configuration-screen'; | ||
|
|
||
| export default function GlobalModelsScreen() { | ||
| return <ModelSettingsScreen kind="global" />; | ||
| export default function ModelConfigurationRoute() { | ||
| return <ModelConfigurationScreen />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { useRouter } from 'expo-router'; | ||
| import { ScrollView, View } from 'react-native'; | ||
|
|
||
| import type { HostClient } from '@botharness/host-client/client'; | ||
| import { DEFAULT_MODEL_PRESET_ID } from '@botharness/host-client/model-plans'; | ||
| import type { ModelPreset } from '@botharness/host-client/bot-settings'; | ||
| import { useHostSession } from '../../host/host-session'; | ||
| import { space } from '../design/tokens'; | ||
| import { LoadingIndicator } from '../primitives/loading-indicator'; | ||
| import { SettingsGroupItem, SettingsHeading, SettingsRow } from '../primitives/settings-row'; | ||
| import { SheetPage } from '../primitives/sheet-page'; | ||
| import { useStrings } from '../strings'; | ||
| import { RouteIcon } from './model-route-label'; | ||
| import { presetDetail, presetFront } from './model-route-text'; | ||
| import { useModels } from './model-settings-screen'; | ||
| import { RoutingGroupLink, type RoutingGroupLinkItem } from './routing-group-links'; | ||
| import { SHEET_GROUP, SheetFailed, SheetLoading, SheetNote } from './sheet'; | ||
|
|
||
| export function ModelConfigurationScreen() { | ||
| const t = useStrings(); | ||
| const { client, saved } = useHostSession(); | ||
| if (client === undefined) return <SheetNote>{t.unreachable}</SheetNote>; | ||
| return <ModelConfigurationView key={saved?.hostId} client={client} />; | ||
| } | ||
|
|
||
| function ModelConfigurationView({ client }: { client: HostClient }) { | ||
| const t = useStrings(); | ||
| const router = useRouter(); | ||
| const models = useModels(client, { kind: 'global' }); | ||
| const value = models.value; | ||
| const page = (body: React.ReactNode) => <SheetPage title={t.modelConfig.title}>{body}</SheetPage>; | ||
| if (value === undefined) | ||
| return page( | ||
| models.error === undefined ? ( | ||
| <SheetLoading /> | ||
| ) : ( | ||
| <SheetFailed message={t.modelFailed} onRetry={models.refresh} /> | ||
| ), | ||
| ); | ||
| const pinned = value.presets.find((preset) => preset.id === DEFAULT_MODEL_PRESET_ID); | ||
| const others = value.presets.filter((preset) => preset.id !== DEFAULT_MODEL_PRESET_ID); | ||
| const openPreset = (preset: ModelPreset) => | ||
| router.push({ pathname: '/settings/model-preset', params: { id: preset.id } }); | ||
| const presetRow = (preset: ModelPreset, first: boolean, last: boolean) => ( | ||
| <SettingsGroupItem key={preset.id} first={first} last={last} on={SHEET_GROUP}> | ||
| <SettingsRow | ||
| on={SHEET_GROUP} | ||
| testID={`model-config-preset-${preset.id}`} | ||
| title={preset.name} | ||
| leading={<RouteIcon value={value} route={presetFront(value, preset)} />} | ||
| detail={presetDetail(value, preset)} | ||
| disclosure | ||
| control={{ kind: 'chevron' }} | ||
| onPress={() => openPreset(preset)} | ||
| /> | ||
| </SettingsGroupItem> | ||
| ); | ||
| const groupItems: RoutingGroupLinkItem[] = [ | ||
| ...(value.groups ?? []).map((group) => ({ kind: 'group' as const, group })), | ||
| { kind: 'add' }, | ||
| ]; | ||
| const heading = (text: string) => ( | ||
| <View style={{ paddingTop: space.x4, paddingBottom: space.x2 }}> | ||
| <SettingsHeading>{text}</SettingsHeading> | ||
| </View> | ||
| ); | ||
| return page( | ||
| <ScrollView style={{ flex: 1 }} contentContainerStyle={{ paddingVertical: space.x3 }}> | ||
| <SheetNote>{t.modelConfig.hint}</SheetNote> | ||
| {models.error === undefined ? null : <SheetNote>{models.error}</SheetNote>} | ||
| {models.busy ? <LoadingIndicator /> : null} | ||
| {pinned === undefined ? null : ( | ||
| <> | ||
| {heading(t.modelConfig.sectionDefault)} | ||
| {presetRow(pinned, true, true)} | ||
| </> | ||
| )} | ||
| {heading(t.modelConfig.sectionPresets)} | ||
| {others.map((preset, index) => presetRow(preset, index === 0, false))} | ||
| <SettingsGroupItem first={others.length === 0} last on={SHEET_GROUP}> | ||
| <SettingsRow | ||
| on={SHEET_GROUP} | ||
| testID="model-config-preset-new" | ||
| title={t.modelConfig.newPreset} | ||
| {...(others.length === 0 ? { detail: t.modelConfig.emptyPresets } : {})} | ||
| control={{ kind: 'add' }} | ||
| onPress={() => router.push('/settings/model-preset-new')} | ||
| /> | ||
| </SettingsGroupItem> | ||
| {groupItems.map((item, index) => ( | ||
| <RoutingGroupLink | ||
| key={item.kind === 'add' ? 'group-add' : `group:${item.group.id}`} | ||
| item={item} | ||
| first={index === 0} | ||
| models={value.models} | ||
| groups={value.groups ?? []} | ||
| /> | ||
| ))} | ||
| </ScrollView>, | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { useFocusEffect, useRouter } from 'expo-router'; | ||
| import { useCallback, useRef, useState } from 'react'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import { errorText } from '@botharness/host-client/bot-settings'; | ||
| import type { HostClient } from '@botharness/host-client/client'; | ||
| import { createModelPreset, DEFAULT_MODEL_PRESET_ID } from '@botharness/host-client/model-plans'; | ||
| import { presetSubFromLegacy, presetSubWithEngine } from '@botharness/host-protocol/preset-sub'; | ||
| import { useHostSession } from '../../host/host-session'; | ||
| import { space } from '../design/tokens'; | ||
| import { Button } from '../primitives/button'; | ||
| import { KeyboardFormScroll } from '../primitives/keyboard-form'; | ||
| import { SheetPage } from '../primitives/sheet-page'; | ||
| import { TextField } from '../primitives/text-field'; | ||
| import { useStrings } from '../strings'; | ||
| import { useModels } from './model-settings-screen'; | ||
| import { SheetFailed, SheetLoading, SheetNote } from './sheet'; | ||
|
|
||
| export function ModelPresetNewScreen() { | ||
| const t = useStrings(); | ||
| const { client, saved } = useHostSession(); | ||
| if (client === undefined) return <SheetNote>{t.unreachable}</SheetNote>; | ||
| return <ModelPresetNewView key={saved?.hostId} client={client} />; | ||
| } | ||
|
|
||
| function ModelPresetNewView({ client }: { client: HostClient }) { | ||
| const t = useStrings(); | ||
| const router = useRouter(); | ||
| const models = useModels(client, { kind: 'global' }); | ||
| const [name, setName] = useState(''); | ||
| const [busy, setBusy] = useState(false); | ||
| const [error, setError] = useState<string>(); | ||
| const focused = useRef(true); | ||
| useFocusEffect( | ||
| useCallback(() => { | ||
| focused.current = true; | ||
| return () => { | ||
| focused.current = false; | ||
| }; | ||
| }, []), | ||
| ); | ||
| const value = models.value; | ||
| const source = value?.presets.find((preset) => preset.id === DEFAULT_MODEL_PRESET_ID); | ||
| const create = () => { | ||
| if (source === undefined || busy || name.trim() === '') return; | ||
| setBusy(true); | ||
| setError(undefined); | ||
| createModelPreset(client, { | ||
| name: name.trim(), | ||
| ...(source.orchestratorGroupId === undefined | ||
| ? { orchestrator: source.orchestrator } | ||
| : { | ||
| orchestratorGroupId: source.orchestratorGroupId, | ||
| ...(source.orchestratorGroupEffort === undefined | ||
| ? {} | ||
| : { orchestratorGroupEffort: source.orchestratorGroupEffort }), | ||
| }), | ||
| ...(source.orchestratorEngine === undefined | ||
| ? {} | ||
| : { orchestratorEngine: source.orchestratorEngine }), | ||
| sub: source.sub ?? presetSubWithEngine(presetSubFromLegacy(source), source.assignmentEngine), | ||
| }).then( | ||
| (preset) => { | ||
| setBusy(false); | ||
| if (focused.current) | ||
| router.replace({ pathname: '/settings/model-preset', params: { id: preset.id } }); | ||
| }, | ||
| (cause: unknown) => { | ||
| setError(errorText(cause)); | ||
| setBusy(false); | ||
| }, | ||
| ); | ||
| }; | ||
| return ( | ||
| <SheetPage title={t.modelConfig.newPreset}> | ||
| {value === undefined ? ( | ||
| models.error === undefined ? ( | ||
| <SheetLoading /> | ||
| ) : ( | ||
| <SheetFailed message={t.modelFailed} onRetry={models.refresh} /> | ||
| ) | ||
| ) : ( | ||
| <KeyboardFormScroll | ||
| style={{ flex: 1 }} | ||
| contentContainerStyle={{ gap: space.x4, paddingVertical: space.x3 }} | ||
| > | ||
| <SheetNote>{t.modelConfig.newPresetHint}</SheetNote> | ||
| <View style={{ paddingHorizontal: space.x5, gap: space.x3 }}> | ||
| <TextField | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| testID="model-preset-new-name" | ||
| value={name} | ||
| onChangeText={setName} | ||
| autoFocus | ||
| accessibilityLabel={t.modelSettings.name} | ||
| placeholder={t.modelSettings.name} | ||
| onSubmitEditing={create} | ||
| /> | ||
| <Button | ||
| testID="model-preset-new-create" | ||
| label={t.modelConfig.create} | ||
| busy={busy} | ||
| disabled={name.trim() === '' || source === undefined} | ||
| onPress={create} | ||
| /> | ||
| </View> | ||
| {error === undefined ? null : <SheetNote>{error}</SheetNote>} | ||
| </KeyboardFormScroll> | ||
| )} | ||
| </SheetPage> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virtualize the preset and Routing Group lists.
When a Host has many presets or Routing Groups, both
.map()calls mount every row inside thisScrollView. Use aSectionListorFlatListfor the Default, Presets and Routing Groups sections.As per coding guidelines, “Long lists virtualize” and must not use “
ScrollViewover.map().”Source: Coding guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this one: the page has at most a few presets and Routing Groups (each is created by hand, and the Default preset is one row). It also matches the other short Settings lists, which render with plain rows. If presets ever grow past a screenful, the list can move to a SectionList then.