AI-native design editor. Open-source Figma alternative.
<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from '@open-pencil/vue/i18n'
import {
changePreviewSize,
compactAutomatically,
maxAgentSteps,
reasoningDisplay,
tokenUsageDisplay
} from '@/app/ai/chat/preferences'
import { AGENT_STEP_LIMIT_MIN, AGENT_STEP_LIMIT_MAX } from '@/app/ai/reply/schema'
import { resolveAgentStepLimit } from '@/app/ai/reply/step-limit'
import { openToolAccessSettings } from '@/app/automation/tool-access/settings/use'
import { DEFAULT_APP_PREFERENCES } from '@/app/settings/preferences/store'
import SettingsGroup from '@/components/settings/layout/SettingsGroup.vue'
import SettingsRow from '@/components/settings/layout/SettingsRow.vue'
import SettingsSection from '@/components/settings/layout/SettingsSection.vue'
import AppButton from '@/components/ui/button/AppButton.vue'
import PresetNumberField from '@/components/ui/input/PresetNumberField.vue'
import AppSelect from '@/components/ui/select/AppSelect.vue'
import AppSwitch from '@/components/ui/toggle/AppSwitch.vue'
const { ai, automation, settings } = useI18n()
const stepPresets = [25, 50, 100, 200]
const defaults = DEFAULT_APP_PREFERENCES.chat
const defaultSteps = resolveAgentStepLimit(defaults.maxAgentSteps)
const limitMessage = computed(() =>
ai.value.maxAgentStepsRange({ min: AGENT_STEP_LIMIT_MIN, max: AGENT_STEP_LIMIT_MAX })
)
const options = computed(() => [
{ value: 'collapsed' as const, label: ai.value.reasoningCollapsed },
{ value: 'while-thinking' as const, label: ai.value.reasoningWhileThinking },
{ value: 'expanded' as const, label: ai.value.reasoningExpanded }
])
const usageOptions = computed(() => [
{ value: 'hover' as const, label: ai.value.tokenUsageHover },
{ value: 'always' as const, label: ai.value.tokenUsageAlways },
{ value: 'hidden' as const, label: ai.value.tokenUsageHidden }
])
const previewOptions = computed(() => [
{ value: 'off' as const, label: ai.value.changePreviewOff },
{ value: 'small' as const, label: ai.value.changePreviewSmall },
{ value: 'medium' as const, label: ai.value.changePreviewMedium },
{ value: 'large' as const, label: ai.value.changePreviewLarge }
])
</script>
<template>
<SettingsSection>
<template #title>{{ ai.chatSettings }}</template>
<SettingsGroup>
<SettingsRow
:label="ai.reasoningDisplay"
:modified="reasoningDisplay !== defaults.reasoningDisplay"
class="max-sm:flex-col max-sm:items-stretch"
@reset="reasoningDisplay = defaults.reasoningDisplay"
>
<AppSelect
v-model="reasoningDisplay"
:label="ai.reasoningDisplay"
:options="options"
:ui="{ trigger: 'w-full sm:w-52' }"
/>
</SettingsRow>
<SettingsRow
:label="ai.changePreview"
:description="ai.changePreviewHint"
:modified="changePreviewSize !== defaults.changePreviewSize"
class="max-sm:flex-col max-sm:items-stretch"
@reset="changePreviewSize = defaults.changePreviewSize"
>
<AppSelect
v-model="changePreviewSize"
:label="ai.changePreview"
:options="previewOptions"
:ui="{ trigger: 'w-full sm:w-52' }"
/>
</SettingsRow>
<SettingsRow :label="ai.compactAutomatically" :description="ai.compactAutomaticallyHint">
<AppSwitch v-model="compactAutomatically" :label="ai.compactAutomatically" />
</SettingsRow>
<SettingsRow
:label="ai.tokenUsage"
:description="ai.tokenUsageHint"
class="max-sm:flex-col max-sm:items-stretch"
>
<AppSelect
v-model="tokenUsageDisplay"
:label="ai.tokenUsage"
:options="usageOptions"
:ui="{ trigger: 'w-full sm:w-52' }"
/>
</SettingsRow>
<SettingsRow
:label="ai.maxAgentSteps"
:description="ai.maxAgentStepsHint"
:modified="maxAgentSteps !== defaultSteps"
class="max-sm:flex-col max-sm:items-stretch"
@reset="maxAgentSteps = defaultSteps"
>
<PresetNumberField
v-model:number="maxAgentSteps"
:presets="stepPresets"
:min="AGENT_STEP_LIMIT_MIN"
:max="AGENT_STEP_LIMIT_MAX"
:label="ai.maxAgentSteps"
:custom-label="ai.maxAgentStepsCustom"
:range-message="limitMessage"
/>
</SettingsRow>
</SettingsGroup>
<SettingsGroup>
<SettingsRow :label="settings.toolAccess" :description="automation.aiToolAccessDescription">
<AppButton
size="xs"
variant="outline"
data-test-id="settings-ai-tool-access"
@click="openToolAccessSettings('ai')"
>{{ settings.edit }}</AppButton
>
</SettingsRow>
</SettingsGroup>
</SettingsSection>
</template>