Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/app/src/features/workspace/entry-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ test("workspace preserves bot and message requests while routing native decision
}, { requestAnimationFrame: (run: () => void) => run(), setInterval: () => 1, clearInterval() {} })
const stack = { Screen: 'Screen', Protected: 'Protected' }
const layout = componentHarness('../../../../../apps/mobile/app/_layout.tsx', {
'expo-router': { Stack: stack, usePathname: () => '/' }, 'react-native-safe-area-context': { useSafeAreaInsets: () => ({ bottom: 0 }) }, 'expo-linking': { useLinkingURL: () => null }, '@/data/live': { LiveWorkspace: 'LiveWorkspace', useLive: () => shared, useWaiting: () => 0 },
'expo-router': { Stack: stack, useRouter: () => ({}), usePathname: () => '/' }, 'react-native-safe-area-context': { useSafeAreaInsets: () => ({ bottom: 0 }) }, 'expo-linking': { useLinkingURL: () => null }, '@/data/live': { LiveWorkspace: 'LiveWorkspace', useLive: () => shared, useWaiting: () => 0 },
'@/data/context': { useWorkspace: () => ({ session: { phase: 'ready' } }) }, '@vibeface/client/identity/context.tsx': { useDevice: () => device },
'uniwind': { useCSSVariable: () => ['white', 'black'] }, '@/lib/layout': { useWide: () => false }, 'react-native': { Platform: { OS: 'ios' }, View: 'View' },
})
Expand Down Expand Up @@ -1907,6 +1907,8 @@ function componentHarness(path: string, dependencies: Record<string, unknown>, g
focusEffects.set(index, { run, cleanup: focused ? run() ?? undefined : undefined })
})
}
const nativeRouterModule = dependencies['expo-router']
const nativeRouter = typeof nativeRouterModule === 'object' && nativeRouterModule !== null && 'router' in nativeRouterModule ? nativeRouterModule.router : {}
const require = (specifier: string): unknown => {
if (specifier === '@vibeface/client/workspace/model.ts') {
const override = dependencies[specifier]
Expand All @@ -1927,7 +1929,7 @@ function componentHarness(path: string, dependencies: Record<string, unknown>, g
if (specifier === '@/platform/files') return dependencies[specifier] ?? { privateFiles: { run: async (operation: (current: () => boolean) => Promise<unknown>) => operation(() => true), retain: (uri: string) => ({ uri }), release() {}, releasePicker() {} } }
if (specifier === '@/platform') return { mobilePlatform: { storage: platformStorage }, ...dependencies[specifier] as object }
if (specifier === '@tanstack/react-router') return { Link: 'Link', useNavigate: () => () => {}, useRouterState: ({ select }: { select: (state: unknown) => unknown }) => select({ location: { search: {} } }), ...dependencies[specifier] as object }
return specifier === 'react' ? react : specifier === 'react/jsx-runtime' ? { jsx, jsxs: jsx } : specifier === 'expo-router' ? { Link: 'Link', useFocusEffect, ...dependencies[specifier] as object } : dependencies[specifier] ?? ui
return specifier === 'react' ? react : specifier === 'react/jsx-runtime' ? { jsx, jsxs: jsx } : specifier === 'expo-router' ? { Link: 'Link', useFocusEffect, useRouter: () => nativeRouter, ...dependencies[specifier] as object } : dependencies[specifier] ?? ui
}
const filename = fileURLToPath(new URL(path, import.meta.url))
const source = readFileSync(filename, 'utf8') + (privateExport ? `\nexport { ${privateExport} }\n` : '')
Expand Down Expand Up @@ -3629,7 +3631,7 @@ test('native Stack focus restores non-chat views while the chat route owns its a
const views: string[] = []
const stack = { Screen: 'Screen', Protected: 'Protected' }
const app = componentHarness('../../../../../apps/mobile/app/_layout.tsx', {
'expo-router': { Stack: stack, usePathname: () => '/' }, 'react-native-safe-area-context': { useSafeAreaInsets: () => ({ bottom: 0 }) }, 'expo-linking': { useLinkingURL: () => null },
'expo-router': { Stack: stack, useRouter: () => ({}), usePathname: () => '/' }, 'react-native-safe-area-context': { useSafeAreaInsets: () => ({ bottom: 0 }) }, 'expo-linking': { useLinkingURL: () => null },
'@/data/live': { LiveWorkspace: 'LiveWorkspace', useLive: () => ({ setView: (view: string) => { views.push(view) } }), useWaiting: () => 0 },
'@/data/context': { useWorkspace: () => ({ session: { phase: 'ready' } }) }, '@vibeface/client/identity/context.tsx': { useDevice: () => ({}) },
'uniwind': { useCSSVariable: () => ['white', 'black'] }, '@/lib/layout': { useWide: () => false }, 'react-native': { Platform: { OS: 'ios' }, View: 'View' },
Expand Down Expand Up @@ -5191,7 +5193,7 @@ test('the native switch confirmation fixes the decoded entry and never erases fo
let url = link, erased = 0, canceled = 0
const kept: (string | null)[] = [], failures: unknown[] = []
const app = componentHarness('../../../../../apps/mobile/app/switch-network.tsx', {
'expo-router': { router: { back: () => { canceled++ } }, useLocalSearchParams: () => ({ link }) },
'expo-router': { router: { back() { throw new Error('module router is unbound') } }, useRouter: () => ({ back: () => { canceled++ } }), useLocalSearchParams: () => ({ link }) },
'expo-linking': { useLinkingURL: () => url },
'@vibeface/client/identity/context.tsx': { useDevice: () => ({ directory: { members: [] }, linkTarget: () => 'other' }) },
'@vibeface/client/identity/copy.ts': { soleManager: () => false, switchCopy: { title: '换到新的网络?', erase: () => '清除应用内数据', confirm: '换网络' } },
Expand Down
12 changes: 7 additions & 5 deletions apps/mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '@/platform/polyfills'
import '../global.css'

import { useLinkingURL } from 'expo-linking'
import { Link, Stack, router, usePathname } from 'expo-router'
import { Link, Stack, usePathname, useRouter } from 'expo-router'
import { ListChecks, MessageSquare, Settings, X } from 'lucide-react-native'
import * as SystemUI from 'expo-system-ui'
import { StatusBar } from 'expo-status-bar'
Expand Down Expand Up @@ -42,6 +42,7 @@ export default function RootLayout() {
}

function Screens() {
const router = useRouter()
const workspace = useWorkspace()
const shared = useLive()
const [background, foreground] = useCSSVariable(['--background', '--foreground']) as [string, string]
Expand All @@ -58,7 +59,7 @@ function Screens() {
if (device.linkTarget(link) === 'other') router.push({ pathname: '/switch-network', params: { link } })
// Reset to home alone: navigate would stack home on the focused join page, which the protected group cannot drop, and any screen left below keeps a back button.
else { if (router.canDismiss()) router.dismissAll(); router.replace('/') }
}, [url, ready])
}, [url, ready, router])
const wide = useWide()
const pathname = usePathname()
const insets = useSafeAreaInsets()
Expand Down Expand Up @@ -106,16 +107,16 @@ function Screens() {
<Stack.Screen name="new-channel" options={{ title: '新频道' }} />
<Stack.Screen name="channel/[channelId]" options={{ title: '频道' }} />
<Stack.Screen name="channel/[channelId]/settings" options={{ title: '频道设置' }} />
<Stack.Screen name="new-bot" options={{ title: '新 Bot', presentation: 'modal', headerLeft: Close }} />
<Stack.Screen name="new-bot" options={{ title: '新 Bot', presentation: 'modal', headerLeft: () => <Close /> }} />
{/* Opened from the new bot sheet it is a sheet too, with no back button of its own. */}
<Stack.Screen name="ai" options={({ route }) => ({ title: 'Bot 与任务', headerLeft: (route.params as { sheet?: string } | undefined)?.sheet ? Close : undefined })} />
<Stack.Screen name="ai" options={({ route }) => ({ title: 'Bot 与任务', headerLeft: (route.params as { sheet?: string } | undefined)?.sheet ? () => <Close /> : undefined })} />
<Stack.Screen name="settings" options={(props) => ({ title: '设置', ...root, ...viaTab(props) })} />
<Stack.Screen name="lab" options={{ title: '实验室' }} />
<Stack.Screen name="logs" options={{ title: '日志' }} />
<Stack.Screen name="external-chat" options={{ title: '外部聊天' }} />
<Stack.Screen name="transfers" options={{ title: '文件传输' }} />
<Stack.Screen name="device/[deviceId]" options={{ title: '' }} />
<Stack.Screen name="add-device" options={{ title: '添加设备', presentation: 'modal', headerLeft: Close }} />
<Stack.Screen name="add-device" options={{ title: '添加设备', presentation: 'modal', headerLeft: () => <Close /> }} />
<Stack.Screen name="recovery" options={{ title: '换恢复密码' }} />
<Stack.Screen name="switch-network" options={{ headerShown: false, presentation: 'formSheet', sheetAllowedDetents: 'fitToContents', sheetGrabberVisible: true }} />
</Stack.Protected>
Expand Down Expand Up @@ -146,5 +147,6 @@ function Screens() {

/** A sheet's own way out, beside the swipe down that not everyone knows. */
function Close() {
const router = useRouter()
return <Button variant="ghost" size="icon" className="rounded-full" accessibilityLabel="关闭" onPress={() => router.back()}><Icon as={X} className="size-5" /></Button>
}
3 changes: 2 additions & 1 deletion apps/mobile/app/add-device.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Clipboard from 'expo-clipboard'
import { openURL } from 'expo-linking'
import { router } from 'expo-router'
import { useRouter } from 'expo-router'
import { Check, CircleCheck, Clock, Copy, Download, Laptop, Link2, Plus, ScanEye, Share2, ShieldAlert, Smartphone, Sparkles, SquareTerminal } from 'lucide-react-native'
import { useEffect, useRef, useState } from 'react'
import { Pressable, ScrollView, Share, View } from 'react-native'
Expand All @@ -21,6 +21,7 @@ type Kind = (typeof kinds)[number]['value']

/** "添加设备": one single-use link the new device opens (a QR for phones, its own Vibeface page for computers), then both sides compare the safety code. */
export default function AddDevice() {
const router = useRouter()
const device = useDevice()
const { ready } = device
const { busy, error, run } = useRun()
Expand Down
10 changes: 6 additions & 4 deletions apps/mobile/app/b/[botId].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { historySections } from '@vibeface/client/workspace/model.ts'
import { HistoryControls } from '@/features/chat/history-controls'
import { Link, Stack, router, useFocusEffect, useLocalSearchParams } from 'expo-router'
import { Link, Stack, useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router'
import { useHeaderHeight } from 'expo-router/react-navigation'
import { ArrowDown, Bot, Crown, LoaderCircle, MessageSquareOff, Settings, Star } from 'lucide-react-native'
import { useCallback, useEffect, useRef, useState } from 'react'
Expand Down Expand Up @@ -92,6 +92,7 @@ function entries(chat: Conversation, extras: ReturnType<typeof useChatExtras>, b
}

export default function ChatScreen() {
const router = useRouter()
const { botId, routine } = useLocalSearchParams<{ botId: string; routine?: string }>()
const workspace = useWorkspace()
const device = useDevice()
Expand All @@ -105,7 +106,8 @@ export default function ChatScreen() {
// already ends where the bar's buttons begin.
const frame = useSafeAreaFrame().width
const wide = useWide()
const titleWidth = ios ? (wide ? frame - 320 : frame) - 120 : undefined
// Compact iPad windows also need leading room for the system window controls.
const titleWidth = Platform.OS === 'ios' ? (wide ? frame - 320 : frame) - (Platform.isPad && !wide ? 200 : 120) : undefined
const { theme } = useUniwind()
const chrome = useChatChrome()
const background = useCSSVariable('--background')
Expand Down Expand Up @@ -278,9 +280,9 @@ export default function ChatScreen() {
<Icon as={Star} className="size-3.5 fill-muted-foreground text-muted-foreground" /><Text className="text-meta text-muted-foreground">主 Bot</Text>
</View> : null}
</View>
{botCanSend(reach) ? <View pointerEvents="box-none" className="flex-row flex-wrap justify-center gap-2">
{botCanSend(reach) ? (!draft.text.trim() ? <View pointerEvents="box-none" className="flex-row flex-wrap justify-center gap-2">
{starters[bot.project ? 'project' : 'general'].map((example) => <Button key={example} variant="outline" className="rounded-full" style={{ borderColor: tint.edge }} onPress={() => setDraft({ text: example })}><Text className="text-muted-foreground">{example}</Text></Button>)}
</View> : starting ? <View role="status" className="flex-row items-center gap-1.5"><Icon as={LoaderCircle} className="text-muted-foreground" /><Text className="text-muted-foreground">Bot 正在启动</Text></View> : <>
</View> : null) : starting ? <View role="status" className="flex-row items-center gap-1.5"><Icon as={LoaderCircle} className="text-muted-foreground" /><Text className="text-muted-foreground">Bot 正在启动</Text></View> : <>
<View className="flex-row items-center gap-1.5"><Icon as={MessageSquareOff} className="text-muted-foreground" /><Text className="text-muted-foreground">Bot 还不能回复</Text></View>
{reach === 'offline' || canSetUp ? <Link href={setupHref} asChild>
<Button><Icon as={Bot} /><Text>{reach === 'offline' ? '查看设备' : '设置运行 Bot 的设备'}</Text></Button>
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/app/device/[deviceId].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, router, useLocalSearchParams } from 'expo-router'
import { Stack, useLocalSearchParams, useRouter } from 'expo-router'
import { ArrowRightLeft, Bot, Check, Crown, Laptop, MonitorSmartphone, Pencil, Sparkles, Trash2, X } from 'lucide-react-native'
import { useState } from 'react'
import { Alert, Pressable, ScrollView, View } from 'react-native'
Expand All @@ -20,6 +20,7 @@ import { useRun } from '@/lib/use-run'
const tag = 'flex-row items-center gap-1 rounded-md bg-muted px-1.5'

export default function DeviceDetail() {
const router = useRouter()
const { deviceId } = useLocalSearchParams<{ deviceId: string }>()
const device = useDevice()
const { members } = useWorkspace()
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, router, useLocalSearchParams } from 'expo-router'
import { Stack, useLocalSearchParams, useRouter } from 'expo-router'
import { useEffect } from 'react'
import { useHeaderHeight } from 'expo-router/react-navigation'
import { MessageSquare } from 'lucide-react-native'
Expand All @@ -12,6 +12,7 @@ import { useWide } from '@/lib/layout'

/** The phone's home; on a wide window the list lives in the sidebar and this pane only waits for a choice. */
export default function Home() {
const router = useRouter()
const wide = useWide()
const workspace = useWorkspace()
const { conversation, work, routine } = useLocalSearchParams<{ conversation?: string; work?: string; routine?: string }>()
Expand All @@ -20,7 +21,7 @@ export default function Home() {
if (!bot || !conversation) return
if (work) router.replace(`/b/${bot.bot_id}/work/${work}`)
else router.replace({ pathname: '/b/[botId]', params: { botId: bot.bot_id, ...(routine ? { routine } : {}) } })
}, [conversation, work, routine, bot?.bot_id])
}, [conversation, work, routine, bot?.bot_id, router])
const bar = useHeaderHeight()
const frame = useSafeAreaFrame()
const insets = useSafeAreaInsets()
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/app/switch-network.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router, useLocalSearchParams } from 'expo-router'
import { useLocalSearchParams, useRouter } from 'expo-router'
import { useLinkingURL } from 'expo-linking'
import { useState } from 'react'
import { ArrowRightLeft, Crown } from 'lucide-react-native'
Expand All @@ -20,6 +20,7 @@ const decode = (ticket: string) => mobilePlatform.secure.ticketDecode(ticket)

/** A join link from another network: the phone erases itself, and the join page that follows picks the same link up. */
export default function SwitchNetwork() {
const router = useRouter()
const device = useDevice()
const { busy, error, run } = useRun()
const { link } = useLocalSearchParams<{ link?: string }>()
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/components/kit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function Panel({ icon, title, children }: { icon: LucideIcon; title: stri
return <View className="gap-4">
<View className="flex-row items-center gap-2">
<Icon as={icon} className="text-muted-foreground" />
<Text role="heading" className="text-heading font-semibold">{title}</Text>
<Text role="heading" className="min-w-0 flex-1 text-heading font-semibold">{title}</Text>
</View>
{children}
</View>
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const buttonVariants = cva(
link: '',
},
size: {
default: cn('min-h-11 px-4 py-2', Platform.select({ web: 'has-[>svg]:px-3' })),
sm: cn('min-h-9 gap-1.5 px-3', Platform.select({ web: 'has-[>svg]:px-2.5' })),
default: cn('min-h-11 px-4 py-2', Platform.select({ ios: 'min-w-11', android: 'min-h-12 min-w-12', web: 'has-[>svg]:px-3' })),
sm: cn('min-h-9 gap-1.5 px-3', Platform.select({ ios: 'min-h-11 min-w-11', android: 'min-h-12 min-w-12', web: 'has-[>svg]:px-2.5' })),
// No sm: steps; on iPad widths they would override a caller's size.
icon: 'size-11',
icon: Platform.select({ android: 'size-12', default: 'size-11' }),
},
},
defaultVariants: {
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/data/live.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mobilePlatform } from '@/platform'
import { WorkspaceProvider } from './context'
import type { ChatMessage, Connection, Conversation, Member, Session, Workspace, WorkspaceActions } from './types'
import type { InputTarget } from '@vibeface/client/workspace/types.ts'
import { router } from 'expo-router'
import { useRouter } from 'expo-router'

const busyStates = ['pending_delivery', 'queued', 'steering', 'claimed', 'running', 'cancelling']
const streamingStates = [...busyStates, 'publishing']
Expand Down Expand Up @@ -86,6 +86,7 @@ function useConnection(): { session: Session; connection: Connection } {
}

function Device({ children }: { children: ReactNode }) {
const router = useRouter()
const device = useDevice()
const { ready } = device
if (!ready) return <Offline>{children}</Offline>
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/features/devices/scanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function Scanner({ title, onScanned, onCancel }: { title: string; onScann
if (!permission) return null
if (!permission.granted) return <Panel icon={Camera} title={title}>
<Text className="text-muted-foreground">需要相机权限才能扫码,也可以粘贴链接</Text>
<View className="flex-row gap-2">
<View className="flex-row flex-wrap gap-2">
<Button variant="ghost" onPress={onCancel}><Text>不扫了,粘贴链接</Text></Button>
<Button onPress={request}><Text>允许使用相机</Text></Button>
</View>
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/src/features/workspace/workspace.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { File } from 'expo-file-system'
import { Link, Stack, router, useFocusEffect } from 'expo-router'
import { Link, Stack, useFocusEffect, useRouter } from 'expo-router'
import { BrainCircuit, ChevronRight, CircleQuestionMark, ListChecks, MessagesSquare, Plus, Reply, Settings, X } from 'lucide-react-native'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Pressable, ScrollView, View } from 'react-native'
Expand Down Expand Up @@ -72,6 +72,7 @@ export function WorkspaceTasks({ botFilter = 'all', filter = 'all' }: { botFilte
}

export function CreateTaskScreen() {
const router = useRouter()
const shared = useLive()
const { busy, error, run } = useRun()
const [botId, setBotId] = useState(shared?.selectedBot?.bot_id ?? shared?.bots[0]?.bot_id ?? '')
Expand Down Expand Up @@ -108,6 +109,7 @@ export function ChannelsScreen() {
}

export function ChannelSettingsScreen({ channelId }: { channelId?: string }) {
const router = useRouter()
const shared = useLive()
const { ready } = useDevice()
const channel = shared?.workspaceState?.channels.find((item) => item.channel_id === channelId)
Expand Down Expand Up @@ -166,6 +168,7 @@ export function InputStatus({ pending }: { pending: PendingMessage }) {
}

export function ScopedWorkspaceScreen({ taskId, channelId }: { taskId?: string; channelId?: string }) {
const router = useRouter()
const shared = useLive()
const chrome = useChatChrome()
const { ready } = useDevice()
Expand Down
Loading
Loading