'use client'; import { Checkbox } from '@/components/ui/checkbox'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import type { WorkbenchProDockProps, OutputFormat, Quality, SizePreset } from '@/components/workbench-pro-dock'; import { WorkbenchProRoutePanel } from '@/components/workbench-pro-route-panel'; import type { GptImageModel } from '@/lib/cost-utils'; import { useI18n } from '@/lib/i18n'; import { getImageOutputFormatLabel } from '@/lib/image-display-labels'; import type { ImageStreamMode } from '@/lib/image-upstream-strategy'; import { getPresetDimensions } from '@/lib/size-utils'; import { resolveStreamingBatchToggleState } from '@/lib/streaming-batch'; import type * as React from 'react'; type Translation = ReturnType['t']; type ProPanelProps = Omit; const modelOptions: GptImageModel[] = ['gpt-image-2', 'gpt-image-1.5', 'gpt-image-1', 'gpt-image-1-mini']; const outputFormatOptions: OutputFormat[] = ['png', 'jpeg', 'webp']; const qualityOptions: Quality[] = ['auto', 'low', 'medium', 'high']; const streamModeOptions: ImageStreamMode[] = ['auto', 'stream', 'non_stream']; function getQualityLabel(quality: Quality, t: Translation): string { if (quality === 'auto') return t('common.auto'); if (quality === 'low') return t('common.low'); if (quality === 'medium') return t('common.medium'); return t('common.high'); } function getStreamModeLabel(streamMode: ImageStreamMode, t: Translation): string { if (streamMode === 'stream') return t('streaming.modeStream'); if (streamMode === 'non_stream') return t('streaming.modeNonStream'); return t('streaming.modeAuto'); } function getStreamingStrategyLabel(strategy: ProPanelProps['streamingStrategy'], t: Translation): string { if (strategy === 'auto') return t('upstream.strategyAuto'); if (strategy === 'off') return t('upstream.strategyOff'); if (strategy === 'openai-sse') return t('upstream.strategyOpenAiSse'); if (strategy === 'newapi-keepalive-sse') return t('upstream.strategyKeepaliveSse'); if (strategy === 'responses-sse') return t('upstream.strategyResponsesSse'); if (strategy === 'force-sse') return t('upstream.strategyForceSse'); return t('upstream.serverDefault'); } function formatResolution(size: SizePreset, model: GptImageModel, t: Translation): string { const resolution = getPresetDimensions(size, model); if (resolution) return resolution; if (size === 'custom') return t('common.custom'); return '1024 px'; } function ReadonlyField({ label, children }: { label: string; children: React.ReactNode }) { return (

{label}

{children}
); } export function WorkbenchEasySummary({ model, streamMode, outputFormat, size, allowStreamingBatch, enableParallelBatch, parallelBatchTargetCount, streamingStrategy, defaultStreamingStrategy }: ProPanelProps) { const { t } = useI18n(); const resolution = formatResolution(size, model, t); const effectiveStreamingStrategy = streamingStrategy === 'server-default' ? defaultStreamingStrategy : streamingStrategy; const parallelBatchVisible = resolveStreamingBatchToggleState({ allowStreamingBatch, userEnabled: enableParallelBatch, targetCount: parallelBatchTargetCount, streamMode, streamingStrategy: effectiveStreamingStrategy }).checked; return (
{model} {parallelBatchVisible ? `${getStreamModeLabel(streamMode, t)} / ${t('streaming.parallelBatchEnabled')}` : getStreamModeLabel(streamMode, t)} {getImageOutputFormatLabel(outputFormat, t)} {resolution}
); } function OutputPanel({ outputFormat, onOutputFormatChange, quality, onQualityChange, disabled, resolution, t }: Pick & { resolution: string; t: Translation; }) { return (

{t('form.outputFormat')}

{t('form.quality')}

sRGB {resolution}
); } function ModelPanel({ model, onModelChange, disabled, resolution, t }: Pick & { resolution: string; t: Translation }) { return (

{t('form.model')}

{resolution}
); } function StreamPanel({ streamMode, onStreamModeChange, allowStreamingBatch, enableParallelBatch, onEnableParallelBatchChange, parallelBatchTargetCount, disabled, strategyLabel, streamingStrategy, defaultStreamingStrategy, t }: Pick< ProPanelProps, | 'streamMode' | 'onStreamModeChange' | 'allowStreamingBatch' | 'enableParallelBatch' | 'onEnableParallelBatchChange' | 'parallelBatchTargetCount' | 'disabled' | 'streamingStrategy' | 'defaultStreamingStrategy' > & { strategyLabel: string; t: Translation; }) { const effectiveStreamingStrategy = streamingStrategy === 'server-default' ? defaultStreamingStrategy : streamingStrategy; const streamingDisabledByStrategy = effectiveStreamingStrategy === 'off'; const parallelBatchToggle = resolveStreamingBatchToggleState({ allowStreamingBatch, userEnabled: enableParallelBatch, targetCount: parallelBatchTargetCount, streamMode, streamingStrategy: effectiveStreamingStrategy }); const canEnableParallelBatch = parallelBatchToggle.canEnable; const parallelBatchChecked = parallelBatchToggle.checked; const parallelBatchUnavailableKey = parallelBatchToggle.unavailableReasonKey; return (

{t('streaming.mode')}

{strategyLabel}

{canEnableParallelBatch ? t('streaming.parallelBatchDescription') : t(parallelBatchUnavailableKey)}

); } export function WorkbenchProPanel({ defaultTab, ...props }: ProPanelProps & { defaultTab: 'output' | 'model' | 'stream' | 'route' }) { const { t } = useI18n(); const resolution = formatResolution(props.size, props.model, t); const strategyLabel = getStreamingStrategyLabel(props.streamingStrategy, t); return ( {t('ux.output')} {t('ux.modelRoute')} {t('ux.streaming')} {t('ux.route')}
); }