Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(web-app): side padding for chat/cowork and open Cowork model settings as a sheet

James Dame77a18f7a216
diff --git a/web-app/src/containers/CoworkEmptyState.tsx b/web-app/src/containers/CoworkEmptyState.tsx
index 17e92645e..a350bd1d4 100644
--- a/web-app/src/containers/CoworkEmptyState.tsx
+++ b/web-app/src/containers/CoworkEmptyState.tsx
@@ -30,13 +30,12 @@ export function CoworkEmptyState({ folder, onPick }: Props) {
const scope = name ? 'folder' : 'sandbox'
return (
- // No horizontal padding here: the column must match the composer's
- // (mx-auto w-4/5) exactly so the invitation shares its left edge instead of
- // a coincidentally-close one. The px-2 below mirrors the input's own text
- // inset, and the examples pull back by the same amount so their labels line
- // up under the heading while the hover target keeps its breathing room.
+ // The column matches the composer's (mx-auto, same width fractions and
+ // px-6 gutter) so the invitation shares its left edge. The examples pull
+ // back by -mx-2 so their labels line up under the heading while the hover
+ // target keeps its breathing room.
<div className="absolute inset-0 flex flex-col justify-end pb-3">
- <div className="mx-auto w-full px-2 md:w-4/5 xl:w-4/6">
+ <div className="mx-auto w-full px-6 md:w-4/5 xl:w-4/6">
<div className="animate-in fade-in-0 duration-500 motion-reduce:animate-none">
<Handshake size={20} className="text-primary" aria-hidden />
<h1 className="mt-3 font-studio text-2xl font-medium tracking-tight">
diff --git a/web-app/src/containers/CoworkModelChip.tsx b/web-app/src/containers/CoworkModelChip.tsx
index ea26b32f0..5dfa3734c 100644
--- a/web-app/src/containers/CoworkModelChip.tsx
+++ b/web-app/src/containers/CoworkModelChip.tsx
@@ -10,7 +10,7 @@ import { useTranslation } from '@/i18n/react-i18next-compat'
import { coworkModelContext, formatContextSize } from '@/lib/coworkModelControls'
/**
- * Opens the model rail, and only when there is something to configure -- a
+ * Opens the model settings sheet, and only when there is something to configure -- a
* local llamacpp/mlx model with settings. Remote providers have no local knobs,
* so the chip stays hidden there like the diff/tasks chips do when empty.
*/
@@ -36,7 +36,7 @@ export function CoworkModelChip({
<Button
variant="ghost"
size="xs"
- aria-pressed={open}
+ aria-haspopup="dialog"
aria-label={t('common:modelPanel.a11y')}
onClick={onToggle}
className={cn(
diff --git a/web-app/src/containers/CoworkModelPanel.tsx b/web-app/src/containers/CoworkModelPanel.tsx
deleted file mode 100644
index 671f694fe..000000000
--- a/web-app/src/containers/CoworkModelPanel.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-import { CoworkSidePanel } from '@/containers/CoworkSidePanel'
-import { ModelSettingFields } from '@/containers/ModelSetting'
-import ProvidersAvatar from '@/containers/ProvidersAvatar'
-import { coworkModelContext, formatContextSize } from '@/lib/coworkModelControls'
-import { getModelDisplayName } from '@/lib/utils'
-import { useTranslation } from '@/i18n/react-i18next-compat'
-
-/**
- * Model settings docked as a Cowork rail, so the llamacpp/mlx knobs sit beside
- * the transcript like the diff/files/todo panels instead of the header Sheet.
- * The form body itself is shared with ModelSetting (ModelSettingFields).
- */
-export function CoworkModelPanel({
- model,
- provider,
- onClose,
-}: {
- model: Model
- provider: ProviderObject
- onClose: () => void
-}): React.ReactElement {
- const { t } = useTranslation()
- const context = coworkModelContext(provider, model.id)
-
- return (
- <CoworkSidePanel
- title={getModelDisplayName(model)}
- leading={
- <div className="shrink-0">
- <ProvidersAvatar provider={provider} />
- </div>
- }
- summary={
- context ? (
- <span
- className="shrink-0 font-mono text-xs tabular-nums text-main-view-fg/60"
- title={t('common:modelPanel.contextTooltip', {
- value: context.value.toLocaleString(),
- max: context.max.toLocaleString(),
- })}
- >
- {formatContextSize(context.value)}
- </span>
- ) : null
- }
- onClose={onClose}
- >
- <div className="flex h-full flex-col">
- <ModelSettingFields model={model} provider={provider} />
- </div>
- </CoworkSidePanel>
- )
-}
diff --git a/web-app/src/containers/ModelSetting.tsx b/web-app/src/containers/ModelSetting.tsx
index ee5e93711..d975e7a87 100644
--- a/web-app/src/containers/ModelSetting.tsx
+++ b/web-app/src/containers/ModelSetting.tsx
@@ -30,7 +30,7 @@ type ModelSettingProps = {
/**
* Shared model-settings form + persistence, driven by both the header Sheet
- * (ModelSetting) and the Cowork right rail (CoworkModelPanel). Keeping the
+ * (ModelSetting) and the Cowork sheet (ModelSettingSheet). Keeping the
* handlers here avoids two copies of the debounced yaml-write / router-restart
* logic diverging.
*/
@@ -261,7 +261,7 @@ function useModelSettingControls(model: Model, provider: ProviderObject) {
}
}
-/** The settings body, shared by the header Sheet and the Cowork rail. */
+/** The settings body, shared by the header Sheet and the Cowork sheet. */
export function ModelSettingFields({ model, provider }: ModelSettingProps) {
const { t } = useTranslation()
const {
@@ -381,8 +381,43 @@ export function ModelSettingFields({ model, provider }: ModelSettingProps) {
)
}
-export function ModelSetting({ model, provider }: ModelSettingProps) {
+function ModelSettingSheetBody({ model, provider }: ModelSettingProps) {
const { t } = useTranslation()
+ return (
+ <SheetContent>
+ <SheetHeader>
+ <SheetTitle>
+ {t('common:modelSettings.title', {
+ modelId: getModelDisplayName(model),
+ })}
+ </SheetTitle>
+ <SheetDescription className="text-xs leading-normal">
+ {t('common:modelSettings.description')}
+ </SheetDescription>
+ </SheetHeader>
+ <ModelSettingFields model={model} provider={provider} />
+ </SheetContent>
+ )
+}
+
+/** Controlled variant without a trigger (Cowork opens it from a chip). */
+export function ModelSettingSheet({
+ model,
+ provider,
+ open,
+ onOpenChange,
+}: ModelSettingProps & {
+ open: boolean
+ onOpenChange: (open: boolean) => void
+}) {
+ return (
+ <Sheet open={open} onOpenChange={onOpenChange}>
+ <ModelSettingSheetBody model={model} provider={provider} />
+ </Sheet>
+ )
+}
+
+export function ModelSetting({ model, provider }: ModelSettingProps) {
return (
<Sheet>
<SheetTrigger asChild>
@@ -390,19 +425,7 @@ export function ModelSetting({ model, provider }: ModelSettingProps) {
<IconSettings size={18} className="text-muted-foreground" />
</Button>
</SheetTrigger>
- <SheetContent>
- <SheetHeader>
- <SheetTitle>
- {t('common:modelSettings.title', {
- modelId: getModelDisplayName(model),
- })}
- </SheetTitle>
- <SheetDescription className="text-xs leading-normal">
- {t('common:modelSettings.description')}
- </SheetDescription>
- </SheetHeader>
- <ModelSettingFields model={model} provider={provider} />
- </SheetContent>
+ <ModelSettingSheetBody model={model} provider={provider} />
</Sheet>
)
}
diff --git a/web-app/src/containers/__tests__/ModelSettingSheet.test.tsx b/web-app/src/containers/__tests__/ModelSettingSheet.test.tsx
new file mode 100644
index 000000000..208548158
--- /dev/null
+++ b/web-app/src/containers/__tests__/ModelSettingSheet.test.tsx
@@ -0,0 +1,31 @@
+import { describe, it, expect, vi } from 'vitest'
+import { render, screen, fireEvent } from '@testing-library/react'
+import '@testing-library/jest-dom'
+
+vi.mock('@/i18n/react-i18next-compat', () => ({
+ useTranslation: () => ({ t: (k: string) => k }),
+}))
+
+import { ModelSettingSheet } from '../ModelSetting'
+
+const model = { id: 'm1', name: 'M1' } as unknown as Model
+const provider = { provider: 'remote', models: [model], settings: [] } as unknown as ProviderObject
+
+describe('ModelSettingSheet', () => {
+ it('renders nothing while closed', () => {
+ render(
+ <ModelSettingSheet model={model} provider={provider} open={false} onOpenChange={vi.fn()} />
+ )
+ expect(screen.queryByText('common:modelSettings.description')).toBeNull()
+ })
+
+ it('shows the title and description when open and reports close', () => {
+ const onOpenChange = vi.fn()
+ render(
+ <ModelSettingSheet model={model} provider={provider} open onOpenChange={onOpenChange} />
+ )
+ expect(screen.getByText('common:modelSettings.description')).toBeInTheDocument()
+ fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' })
+ expect(onOpenChange).toHaveBeenCalledWith(false)
+ })
+})
diff --git a/web-app/src/hooks/__tests__/useTokensCount.test.ts b/web-app/src/hooks/__tests__/useTokensCount.test.ts
index 78f715f8b..7b280d60d 100644
--- a/web-app/src/hooks/__tests__/useTokensCount.test.ts
+++ b/web-app/src/hooks/__tests__/useTokensCount.test.ts
@@ -232,7 +232,7 @@ describe('useTokensCount', () => {
expect(result.current.tokenCount).toBe(4242)
})
- // "Increase context" (Cowork's recovery chip, the model rail's settings
+ // "Increase context" (Cowork's recovery chip, the model settings sheet's
// form) writes the new size and reloads the router with it. The meter
// divides by the launched window, so it has to refetch or it keeps
// reporting the previous one for the rest of the session.
diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.json
index 79addddc3..7dc977930 100644
--- a/web-app/src/locales/en/common.json
+++ b/web-app/src/locales/en/common.json
@@ -164,8 +164,7 @@
},
"modelPanel": {
"title": "Model settings",
- "a11y": "Open model settings",
- "contextTooltip": "Context window: {{value}} of {{max}} tokens"
+ "a11y": "Open model settings"
},
"coworkSlash": {
"skillUnavailable": "Skill '{{name}}' is not available",
diff --git a/web-app/src/routes/__tests__/coworkSkills.test.tsx b/web-app/src/routes/__tests__/coworkSkills.test.tsx
index 5724fba4d..effcf2d6c 100644
--- a/web-app/src/routes/__tests__/coworkSkills.test.tsx
+++ b/web-app/src/routes/__tests__/coworkSkills.test.tsx
@@ -212,8 +212,9 @@ vi.mock('@/containers/CoworkFilesPanel', () => ({
vi.mock('@/containers/CoworkTodoChip', () => ({ CoworkTodoChip: () => null }))
vi.mock('@/containers/CoworkTasksChip', () => ({ CoworkTasksChip: () => null }))
vi.mock('@/containers/CoworkModelChip', () => ({ CoworkModelChip: () => null }))
-vi.mock('@/containers/CoworkModelPanel', () => ({
- CoworkModelPanel: () => null,
+vi.mock('@/containers/ModelSetting', () => ({
+ ModelSetting: () => null,
+ ModelSettingSheet: () => null,
}))
vi.mock('@/containers/CoworkSandboxChip', () => ({
CoworkSandboxChip: () => null,
diff --git a/web-app/src/routes/cowork.tsx b/web-app/src/routes/cowork.tsx
index 119874de8..ecf2ab6ad 100644
--- a/web-app/src/routes/cowork.tsx
+++ b/web-app/src/routes/cowork.tsx
@@ -82,7 +82,7 @@ import { CoworkFilesPanel } from '@/containers/CoworkFilesPanel'
import { CoworkTodoChip } from '@/containers/CoworkTodoChip'
import { CoworkTasksChip } from '@/containers/CoworkTasksChip'
import { CoworkModelChip } from '@/containers/CoworkModelChip'
-import { CoworkModelPanel } from '@/containers/CoworkModelPanel'
+import { ModelSettingSheet } from '@/containers/ModelSetting'
import { collectCodeFileDiffs } from '@/lib/coworkDiffs'
import { CoworkSandboxChip } from '@/containers/CoworkSandboxChip'
import { CoworkBudgetNotice } from '@/containers/CoworkBudgetNotice'
@@ -230,7 +230,7 @@ function CoworkPage() {
const overflowModel = coworkLocalModel(overflowProvider, selectedModel?.id)
const overflowContext = coworkModelContext(overflowProvider, selectedModel?.id)
// The selected provider's own model entry (with settings) drives the model
- // rail; undefined for remote/inactive providers, which hides its chip.
+ // settings sheet; undefined for remote/inactive providers, which hides its chip.
const modelProvider = providers.find(
(provider) => provider.provider === selectedProvider
)
@@ -1472,6 +1472,9 @@ function CoworkPage() {
// they were opened from.
useEffect(() => setRail(null), [session?.id])
+ // The model sheet floats over the page; only docked rails narrow the column.
+ const dockedRail = rail !== null && rail.kind !== 'model'
+
return (
<div
data-testid="cowork-surface"
@@ -1506,12 +1509,12 @@ function CoworkPage() {
reads as tucked behind it. */}
<ConversationContent
className={cn(
- 'mx-auto w-full pb-4',
+ 'mx-auto w-full px-6 pb-4',
// The centering fractions assume the transcript owns the
// width; with a side panel open the column is already
// narrow, so keeping them crushes the message and composer
// into an unreadable sliver.
- !rail && 'md:w-4/5 xl:w-4/6'
+ !dockedRail && 'md:w-4/5 xl:w-4/6'
)}
>
{uiMessages.map((message, i) => (
@@ -1635,7 +1638,7 @@ function CoworkPage() {
</div>
<div className="py-4 shrink-0">
- <div className={cn('mx-auto w-full', !rail && 'md:w-4/5 xl:w-4/6')}>
+ <div className={cn('mx-auto w-full px-6', !dockedRail && 'md:w-4/5 xl:w-4/6')}>
{/* The card rises in when a question arrives and folds away once
answered, so the chat box glides instead of jumping. A card
already pending when the view mounts just appears. */}
@@ -1824,11 +1827,16 @@ function CoworkPage() {
onClose={() => setRail(null)}
/>
)}
- {rail?.kind === 'model' && localModel && modelProvider && (
- <CoworkModelPanel
+ {/* Always mounted so Radix can play the close animation; the sheet
+ overlays the page, so it is not a docked rail. */}
+ {localModel && modelProvider && (
+ <ModelSettingSheet
model={localModel}
provider={modelProvider}
- onClose={() => setRail(null)}
+ open={rail?.kind === 'model'}
+ onOpenChange={(open) =>
+ setRail((r) => (!open && r?.kind === 'model' ? null : r))
+ }
/>
)}
</div>
diff --git a/web-app/src/routes/index.tsx b/web-app/src/routes/index.tsx
index 4a6b5509c..438f58adc 100644
--- a/web-app/src/routes/index.tsx
+++ b/web-app/src/routes/index.tsx
@@ -66,7 +66,7 @@ function Index() {
>
<div
className={cn(
- 'mx-auto w-full md:w-4/5 xl:w-4/6 -mt-20',
+ 'mx-auto w-full px-6 md:w-4/5 xl:w-4/6 -mt-20',
)}
>
<div className={cn('text-center mb-4')}>
diff --git a/web-app/src/routes/threads/$threadId.tsx b/web-app/src/routes/threads/$threadId.tsx
index 5f9f06078..a6cbf45b1 100644
--- a/web-app/src/routes/threads/$threadId.tsx
+++ b/web-app/src/routes/threads/$threadId.tsx
@@ -2305,7 +2305,7 @@ function ThreadDetail() {
>
<Conversation className="absolute inset-0 text-start">
<ConversationContent
- className={cn('mx-auto w-full md:w-4/5 xl:w-4/6')}
+ className={cn('mx-auto w-full px-6 md:w-4/5 xl:w-4/6')}
>
{chatMessages.map((message, index) => {
const isLastMessage = index === chatMessages.length - 1
@@ -2455,7 +2455,7 @@ function ThreadDetail() {
</div>
{/* Chat Input - Fixed at bottom */}
- <div className="py-4 mx-auto w-full md:w-4/5 xl:w-4/6">
+ <div className="py-4 px-6 mx-auto w-full md:w-4/5 xl:w-4/6">
<ChatInput
model={threadModel}
onSubmit={handleSubmit}