diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx index a4e7a44270..bf8181a7ee 100644 --- a/apps/mobile/app/_layout.tsx +++ b/apps/mobile/app/_layout.tsx @@ -92,7 +92,9 @@ function RootNavigator() { ['usage', t.usage], ['model-providers', t.modelProviders.title], ['model-provider-account', t.modelProviders.account], - ['models', t.modelSettings.title], + ['models', t.modelConfig.title], + ['model-preset-new', undefined], + ['model-sub-choice', undefined], ['model-picker', undefined], ['model-preset', undefined], ['routing-group', undefined], diff --git a/apps/mobile/app/bot/[slug]/_layout.tsx b/apps/mobile/app/bot/[slug]/_layout.tsx index 432aa8751a..02fde2f272 100644 --- a/apps/mobile/app/bot/[slug]/_layout.tsx +++ b/apps/mobile/app/bot/[slug]/_layout.tsx @@ -43,6 +43,7 @@ export default function BotProfileLayout() { + diff --git a/apps/mobile/app/bot/[slug]/model-sub-choice.tsx b/apps/mobile/app/bot/[slug]/model-sub-choice.tsx new file mode 100644 index 0000000000..2be38e3de5 --- /dev/null +++ b/apps/mobile/app/bot/[slug]/model-sub-choice.tsx @@ -0,0 +1,5 @@ +import { SubChoiceRoute } from '../../../src/ui/chat/sub-choice-screen'; + +export default function BotSubChoiceScreen() { + return ; +} diff --git a/apps/mobile/app/settings/model-preset-new.tsx b/apps/mobile/app/settings/model-preset-new.tsx new file mode 100644 index 0000000000..1932beed9c --- /dev/null +++ b/apps/mobile/app/settings/model-preset-new.tsx @@ -0,0 +1,5 @@ +import { ModelPresetNewScreen } from '../../src/ui/chat/model-preset-new-screen'; + +export default function ModelPresetNewRoute() { + return ; +} diff --git a/apps/mobile/app/settings/model-sub-choice.tsx b/apps/mobile/app/settings/model-sub-choice.tsx new file mode 100644 index 0000000000..16532d8971 --- /dev/null +++ b/apps/mobile/app/settings/model-sub-choice.tsx @@ -0,0 +1,5 @@ +import { SubChoiceRoute } from '../../src/ui/chat/sub-choice-screen'; + +export default function PresetSubChoiceScreen() { + return ; +} diff --git a/apps/mobile/app/settings/models.tsx b/apps/mobile/app/settings/models.tsx index 467a8ee0a1..5fb7be5094 100644 --- a/apps/mobile/app/settings/models.tsx +++ b/apps/mobile/app/settings/models.tsx @@ -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 ; +export default function ModelConfigurationRoute() { + return ; } diff --git a/apps/mobile/src/features/models/strings.ts b/apps/mobile/src/features/models/strings.ts index 1902225e13..65b06f92db 100644 --- a/apps/mobile/src/features/models/strings.ts +++ b/apps/mobile/src/features/models/strings.ts @@ -70,14 +70,26 @@ export const en = { signInFailed: 'Couldn’t start sign-in. Try again.', signInTimedOut: 'Sign-in didn’t finish on the computer. Try again.', }, + modelConfig: { + title: 'Model configuration', + section: 'Models', + rowHint: 'Default preset, presets and Routing Groups', + hint: 'New Bots and Bots without their own models use the Default preset.', + sectionDefault: 'Default', + sectionPresets: 'Presets', + newPreset: 'New preset', + emptyPresets: 'No other presets yet.', + newPresetHint: 'The new preset starts as a copy of the Default preset.', + create: 'Create preset', + }, modelSettings: { - title: 'Models and presets', + title: 'Model', global: 'Global default model', globalHint: 'Bots use this default unless set on their own. Applying a preset copies its models to that Bot.', - botHint: 'Orchestrator chats. Assignment models do delegated work. Only this Bot changes.', + botHint: 'The main model chats. Task models do delegated work. Only this Bot changes.', presetHint: 'Bots already using this preset keep their settings until you apply it again.', - orchestrator: 'Orchestrator model', + orchestrator: 'Main model', assignment: 'Assignment default model', allowed: 'Allowed Assignment models', allowedHint: @@ -88,8 +100,8 @@ export const en = { groupEffort: 'Set by each group member', groupEffortHint: 'Each model in this Routing Group runs with its own reasoning effort.', groupEffortShared: 'Members that support reasoning use this effort. Others run without one.', - inherit: 'Restore global default', - inherited: 'Following global default', + inherit: 'Use the Default preset', + inherited: 'Using the Default preset', search: 'Search models or providers', noResults: 'No matching models. Try another name or provider.', families: 'Model families', @@ -127,6 +139,23 @@ export const en = { saved: 'Preset saved', count: (count: number) => `${count} models`, }, + subChoices: { + title: 'Task models', + hint: 'The main model can pick any of these for a delegated task. Without a pick, it uses the default.', + followsMain: 'Same as main model', + followsMainHint: 'No task models yet, so delegated tasks use the main model.', + inherited: 'From the Default preset. Changing the list gives this Bot its own.', + add: 'Add a task model', + makeDefault: 'Make default', + remove: 'Remove from task models', + note: 'When should tasks use it? (optional)', + noteLabel: (name: string) => `Note for ${name}`, + effort: 'Reasoning effort', + stale: 'The group’s models no longer share the saved reasoning levels.', + clearEfforts: 'Clear effort limit', + full: 'The list already holds 20 models. Remove one to add another.', + search: 'Search models, Routing Groups or accounts', + }, routingGroup: { add: 'Add Routing Group', edit: 'Edit Routing Group', @@ -246,8 +275,20 @@ export const zh: typeof en = { signInFailed: '无法开始登录,再试一次。', signInTimedOut: '电脑上的登录没有完成,再试一次。', }, + modelConfig: { + title: '模型配置', + section: '模型', + rowHint: '默认预设、预设和路由组', + hint: '新建的 Bot 和没有单独设置模型的 Bot 使用默认预设。', + sectionDefault: '默认', + sectionPresets: '预设', + newPreset: '新建预设', + emptyPresets: '还没有其他预设。', + newPresetHint: '新预设会先复制默认预设的模型。', + create: '创建预设', + }, modelSettings: { - title: '模型与预设', + title: '模型', global: '全局默认模型', globalHint: 'Bot 未单独设置时使用这里的默认模型。应用预设会把它的模型复制给该 Bot。', botHint: '主模型负责对话,副模型执行委派任务。只影响此 Bot。', @@ -262,8 +303,8 @@ export const zh: typeof en = { groupEffort: '强度由路由组各成员决定', groupEffortHint: '路由组里的每个模型按各自的推理强度运行。', groupEffortShared: '支持推理的成员按这个强度运行,其余成员不带强度。', - inherit: '恢复全局默认', - inherited: '跟随全局默认', + inherit: '恢复为默认预设', + inherited: '使用默认预设', search: '搜索模型或服务商', noResults: '没有匹配的模型,更换名称或服务商。', families: '模型系列', @@ -298,6 +339,24 @@ export const zh: typeof en = { saved: '预设已保存', count: (count: number) => `${count} 个模型`, }, + subChoices: { + title: '副模型', + hint: '分派任务时,主模型可以从这些里挑选;没有指定时用标为「默认」的那个。', + followsMain: '跟随主模型', + followsMainHint: '还没有添加副模型,分派的任务也用主模型。', + inherited: '沿用默认预设。改动列表后,这个 Bot 会有自己的副模型。', + add: '添加副模型', + makeDefault: '设为默认', + remove: '从副模型中移除', + note: '什么时候用这个模型?(可选)', + noteLabel: (name: string) => `${name} 的使用说明`, + effort: '推理强度', + stale: '组内模型变了,原来的推理强度限制已不适用。', + clearEfforts: '清除强度限制', + full: '列表里已经有 20 个模型,先移除一个再添加。', + search: '搜索模型、路由组或账号', + }, + routingGroup: { add: '添加路由组', edit: '编辑路由组', diff --git a/apps/mobile/src/ui/chat/model-configuration-screen.tsx b/apps/mobile/src/ui/chat/model-configuration-screen.tsx new file mode 100644 index 0000000000..b89df6158e --- /dev/null +++ b/apps/mobile/src/ui/chat/model-configuration-screen.tsx @@ -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 {t.unreachable}; + return ; +} + +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) => {body}; + if (value === undefined) + return page( + models.error === undefined ? ( + + ) : ( + + ), + ); + 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) => ( + + } + detail={presetDetail(value, preset)} + disclosure + control={{ kind: 'chevron' }} + onPress={() => openPreset(preset)} + /> + + ); + const groupItems: RoutingGroupLinkItem[] = [ + ...(value.groups ?? []).map((group) => ({ kind: 'group' as const, group })), + { kind: 'add' }, + ]; + const heading = (text: string) => ( + + {text} + + ); + return page( + + {t.modelConfig.hint} + {models.error === undefined ? null : {models.error}} + {models.busy ? : 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))} + + router.push('/settings/model-preset-new')} + /> + + {groupItems.map((item, index) => ( + + ))} + , + ); +} diff --git a/apps/mobile/src/ui/chat/model-preset-new-screen.tsx b/apps/mobile/src/ui/chat/model-preset-new-screen.tsx new file mode 100644 index 0000000000..7fc6e74dae --- /dev/null +++ b/apps/mobile/src/ui/chat/model-preset-new-screen.tsx @@ -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 {t.unreachable}; + return ; +} + +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(); + 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 ( + + {value === undefined ? ( + models.error === undefined ? ( + + ) : ( + + ) + ) : ( + + {t.modelConfig.newPresetHint} + + +