diff --git a/src/servers/api/pi/rest.ts b/src/servers/api/pi/rest.ts index 403b27f3..36da2a16 100644 --- a/src/servers/api/pi/rest.ts +++ b/src/servers/api/pi/rest.ts @@ -29,7 +29,7 @@ piRestRouter.get('/pi/models', async (ctx: Context) => { providerNames[`officer-local-${lp.id}`] = lp.name; } - return ctx.json({ models, providerNames }); + return ctx.json({ models, providerNames, hostHome: process.env.HOME ?? '' }); } catch (err) { logger.error('Failed to list models', { error: String(err) }); return ctx.json({ models: [], providerNames: {} }); diff --git a/src/workspaces/officerdev/src/apps/ChatHistory/ChatDetailPanel.tsx b/src/workspaces/officerdev/src/apps/ChatHistory/ChatDetailPanel.tsx index 534928e0..bca4f25e 100644 --- a/src/workspaces/officerdev/src/apps/ChatHistory/ChatDetailPanel.tsx +++ b/src/workspaces/officerdev/src/apps/ChatHistory/ChatDetailPanel.tsx @@ -1,7 +1,9 @@ +import { useState } from 'react'; import { useLocation } from 'react-router'; -import { Trash2 } from 'lucide-react'; +import { Trash2, Home, Monitor } from 'lucide-react'; import { usePanelChannel } from 'hooks/usePanelChannel'; import { useChatSessions } from 'state/useChatSessions'; +import { getHostHome } from 'state/useModels'; import { usePiChat, EmbeddableChat } from '../Chat'; export type SelectedSession = { @@ -91,12 +93,48 @@ function SessionChat({ sessionId, model }: SessionChatProps) { ); } +function CwdToggle({ cwdMode, onChange }: { cwdMode: 'user' | 'host'; onChange: (mode: 'user' | 'host') => void }) { + const hostHome = getHostHome(); + if (!hostHome) return null; + + return ( +
+ cwd + + +
+ ); +} + function NewChat() { const location = useLocation(); const locationState = location.state as ChatLocationState; + const [cwdMode, setCwdMode] = useState<'user' | 'host'>('user'); const chat = usePiChat(undefined, locationState?.model); + const cwd = cwdMode === 'host' ? { path: getHostHome() } : locationState?.cwd; + const initialMessage = locationState?.initialMessage ? { text: locationState.initialMessage, @@ -114,13 +152,14 @@ function NewChat() { isGenerating={chat.isGenerating} onDelete={undefined} /> + {!chat.hasStarted && } diff --git a/src/workspaces/state/src/useModels.ts b/src/workspaces/state/src/useModels.ts index ceb92301..0ad15760 100644 --- a/src/workspaces/state/src/useModels.ts +++ b/src/workspaces/state/src/useModels.ts @@ -12,11 +12,16 @@ export function modelKey(m: ModelOption): string { // Store provider names globally for display let globalProviderNames: Record = {}; +let globalHostHome = ''; export function getProviderDisplayName(providerId: string): string { return globalProviderNames[providerId] || providerId; } +export function getHostHome(): string { + return globalHostHome; +} + export function usePiModels() { const client = useClient(); const { isAuthenticated } = useAuth(); @@ -25,7 +30,7 @@ export function usePiModels() { queryKey: ['PI_MODELS'], enabled: isAuthenticated, queryFn: async () => { - const data = await client.get<{ models: ModelOption[]; providerNames?: Record }>('/pi/models'); + const data = await client.get<{ models: ModelOption[]; providerNames?: Record; hostHome?: string }>('/pi/models'); console.log('[usePiModels] Fetched models:', { modelCount: data.models.length, @@ -38,6 +43,10 @@ export function usePiModels() { globalProviderNames = data.providerNames; console.log('[usePiModels] Stored provider names:', globalProviderNames); } + + if (data.hostHome) { + globalHostHome = data.hostHome; + } return data.models; },