Skip to content
Open
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
25 changes: 16 additions & 9 deletions src/components/prose/GenerationThoughts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEffect, useState } from 'react'
import {
ChainOfThought,
ChainOfThoughtContent,
ChainOfThoughtHeader,
ChainOfThoughtStep,
} from '@/components/ui/chain-of-thought'
import { Loader2, Brain, Wrench, CheckCircle2, PenLine, FileText } from 'lucide-react'
Expand Down Expand Up @@ -31,33 +33,38 @@ export function GenerationThoughts({
steps,
streaming,
hasText,
defaultExpanded = true,
}: {
steps: ThoughtStep[]
streaming: boolean
hasText: boolean
defaultExpanded?: boolean
}) {
// Determine if reasoning is still actively streaming (no text yet, last step is reasoning)
const lastStep = steps[steps.length - 1]
const isThinking = streaming && !hasText && lastStep?.type === 'reasoning'

// Open per the story setting while generating, then collapse once it completes
const [open, setOpen] = useState(defaultExpanded)
useEffect(() => {
setOpen(streaming ? defaultExpanded : false)
}, [streaming, defaultExpanded])

return (
<div className="mb-4" data-component-id="generation-thoughts-root">
<ChainOfThought defaultOpen={true}>
<ChainOfThought open={open} onOpenChange={setOpen}>
<ChainOfThoughtHeader>{isThinking ? 'Thinking' : 'Thoughts'}</ChainOfThoughtHeader>
<ChainOfThoughtContent>
{steps.map((step, i) => {
if (step.type === 'reasoning') {
// Reasoning text sits directly under the header — the header is its label
return (
<ChainOfThoughtStep
<div
key={`reasoning-${i}`}
icon={Brain}
label="Thinking"
status={isThinking && i === steps.length - 1 ? 'active' : 'complete'}
className="text-[0.625rem] text-muted-foreground italic font-mono whitespace-pre-wrap leading-relaxed max-h-[200px] overflow-y-auto"
>
<div className="text-[0.625rem] text-muted-foreground italic font-mono whitespace-pre-wrap leading-relaxed max-h-[200px] overflow-y-auto">
{step.text}
</div>
</ChainOfThoughtStep>
{step.text}
</div>
)
}
if (step.type === 'prewriter-text') {
Expand Down
5 changes: 5 additions & 0 deletions src/components/prose/ProseBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export const ProseBlock = memo(function ProseBlock({
void isFirst
void isLast
const queryClient = useQueryClient()
const { data: story } = useQuery({
queryKey: ['story', storyId],
queryFn: () => api.stories.get(storyId),
})
const [actionMode, setActionMode] = useState<'regenerate' | null>(null)
const [showUndo, setShowUndo] = useState(false)
const [isStreamingAction, setIsStreamingAction] = useState(false)
Expand Down Expand Up @@ -567,6 +571,7 @@ export const ProseBlock = memo(function ProseBlock({
steps={actionThoughtSteps}
streaming={isStreamingAction}
hasText={!!streamedActionText}
defaultExpanded={story?.settings.expandThoughtsByDefault ?? true}
/>
)}
<StreamMarkdown
Expand Down
5 changes: 5 additions & 0 deletions src/components/prose/ProseChainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ function StreamingSection({
const [fragmentCountBeforeGeneration, setFragmentCountBeforeGeneration] = useState<number | null>(null)
const isNearBottomRef = useRef(true)
const queryClient = useQueryClient()
const { data: story } = useQuery({
queryKey: ['story', storyId],
queryFn: () => api.stories.get(storyId),
})

// Track whether user is near the bottom of the scroll area
useEffect(() => {
Expand Down Expand Up @@ -148,6 +152,7 @@ function StreamingSection({
steps={thoughtSteps}
streaming={isGenerating}
hasText={!!streamedText}
defaultExpanded={story?.settings.expandThoughtsByDefault ?? true}
/>
)}
<StreamMarkdown content={streamedText} streaming={isGenerating} variant="prose" />
Expand Down
8 changes: 8 additions & 0 deletions src/components/sidebar/SettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ export function SettingsPanel({
label="Toggle disable thinking"
/>
</SettingRow>
<SettingRow label="Expand thinking by default" description="Show the model's thinking expanded while it generates, instead of collapsed">
<Toggle
checked={story.settings.expandThoughtsByDefault ?? true}
onChange={(next) => updateMutation.mutate({ expandThoughtsByDefault: next })}
disabled={updateMutation.isPending}
label="Toggle expand thinking by default"
/>
</SettingRow>
</SettingsGroup>

<SettingsGroup title="Context" description="How the prompt is assembled before generation starts.">
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const settings = {
guidedSceneSettingPrompt?: string
guidedSuggestPrompt?: string
disableThinking?: boolean
expandThoughtsByDefault?: boolean
}) =>
apiFetch<StoryMeta>(`/stories/${storyId}/settings`, {
method: 'PATCH',
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface StoryMeta {
guidedSceneSettingPrompt?: string
guidedSuggestPrompt?: string
disableThinking?: boolean
expandThoughtsByDefault?: boolean
/** erratanet provenance: installed-from pack and/or where this story is published. */
erratanet?: {
pack?: string
Expand Down
3 changes: 2 additions & 1 deletion src/server/fragments/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const StoryMetaSchema = z.object({
guidedSceneSettingPrompt: z.string().optional(),
guidedSuggestPrompt: z.string().optional(),
disableThinking: z.boolean().default(false),
expandThoughtsByDefault: z.boolean().default(true),
// erratanet provenance. Absent for purely local stories.
erratanet: z
.object({
Expand All @@ -175,7 +176,7 @@ export const StoryMetaSchema = z.object({
})
.optional(),
})
.default({ outputFormat: 'markdown', enabledPlugins: [], summarizationThreshold: 4, maxSteps: 10, modelOverrides: {}, generationMode: 'standard', clarifyBeforeGenerate: false, prewriterReasoning: 'normal', disableLibrarianAutoAnalysis: false, autoApplyLibrarianSuggestions: false, disableLibrarianDirections: false, disableLibrarianSuggestions: false, contextOrderMode: 'simple', fragmentOrder: [], customFragmentTypes: [], enabledBuiltinTools: [], contextCompact: { type: 'proseLimit', value: 10 }, summaryCompact: { maxCharacters: 12000, targetCharacters: 9000 }, enableHierarchicalSummary: false, disableThinking: false }),
.default({ outputFormat: 'markdown', enabledPlugins: [], summarizationThreshold: 4, maxSteps: 10, modelOverrides: {}, generationMode: 'standard', clarifyBeforeGenerate: false, prewriterReasoning: 'normal', disableLibrarianAutoAnalysis: false, autoApplyLibrarianSuggestions: false, disableLibrarianDirections: false, disableLibrarianSuggestions: false, contextOrderMode: 'simple', fragmentOrder: [], customFragmentTypes: [], enabledBuiltinTools: [], contextCompact: { type: 'proseLimit', value: 10 }, summaryCompact: { maxCharacters: 12000, targetCharacters: 9000 }, enableHierarchicalSummary: false, disableThinking: false, expandThoughtsByDefault: true }),
})

export type StoryMeta = z.infer<typeof StoryMetaSchema>
Expand Down
3 changes: 3 additions & 0 deletions src/server/routes/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function storyRoutes(dataDir: string) {
disableLibrarianDirections: false,
disableLibrarianSuggestions: false,
disableThinking: false,
expandThoughtsByDefault: true,
contextOrderMode: 'simple' as const,
fragmentOrder: [],
customFragmentTypes: [],
Expand Down Expand Up @@ -170,6 +171,7 @@ export function storyRoutes(dataDir: string) {
...(body.summaryCompact !== undefined ? { summaryCompact: body.summaryCompact } : {}),
...(body.enableHierarchicalSummary !== undefined ? { enableHierarchicalSummary: body.enableHierarchicalSummary } : {}),
...(body.disableThinking !== undefined ? { disableThinking: body.disableThinking } : {}),
...(body.expandThoughtsByDefault !== undefined ? { expandThoughtsByDefault: body.expandThoughtsByDefault } : {}),
}

const applyGuidedPrompt = (
Expand Down Expand Up @@ -238,6 +240,7 @@ export function storyRoutes(dataDir: string) {
guidedSceneSettingPrompt: t.Optional(t.String()),
guidedSuggestPrompt: t.Optional(t.String()),
disableThinking: t.Optional(t.Boolean()),
expandThoughtsByDefault: t.Optional(t.Boolean()),
}),
detail: { summary: 'Update story settings' },
})
Expand Down
1 change: 1 addition & 0 deletions tests/fragments/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('StoryMetaSchema', () => {
expect(result.settings.outputFormat).toBe('markdown')
expect(result.settings.enabledPlugins).toEqual([])
expect(result.settings.customFragmentTypes).toEqual([])
expect(result.settings.expandThoughtsByDefault).toBe(true)
})

it('accepts full story metadata', () => {
Expand Down