mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
a25957c88c
commit
f46467d359
14 files changed
+329
-200
No files matched your search
@@ -59,8 +59,10 @@ export interface SendMessageResult {
|
||||
assistant_message?: ChatMessageRow;
|
||||
}
|
||||
|
||||
export type ToolApprovalMode = 'ask' | 'auto' | 'full';
|
||||
|
||||
export interface ChatSendParams {
|
||||
tool_approval_mode?: string;
|
||||
tool_approval_mode?: ToolApprovalMode;
|
||||
plan_mode?: boolean;
|
||||
request_params?: Record<string, unknown>;
|
||||
voice_mode?: boolean;
|
||||
@@ -104,6 +106,12 @@ export const updateChatTitle = (chatId: string, title: string) =>
|
||||
body: JSON.stringify({ title })
|
||||
});
|
||||
|
||||
export const updateChatSettings = (chatId: string, modelId: string, params: ChatSendParams) =>
|
||||
fetchJSON<{ ok: boolean }>(
|
||||
`/api/chats/${chatId}/settings`,
|
||||
jsonBody({ model_id: modelId, params })
|
||||
);
|
||||
|
||||
export const forkChat = (chatId: string, messageId?: string | null) =>
|
||||
fetchJSON<{ ok: boolean; chat_id: string }>(
|
||||
`/api/chats/${chatId}/fork`,
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
import Icon from '../Icon.svelte';
|
||||
import DropdownMenu from '../DropdownMenu.svelte';
|
||||
import ModelSelector from '../common/ModelSelector.svelte';
|
||||
import { selectedModelId, workspaceList } from '$lib/stores';
|
||||
import { workspaceList } from '$lib/stores';
|
||||
import { defaultModel } from '$lib/stores/chat';
|
||||
import { getPathDisplayName } from '$lib/utils/paths';
|
||||
import { createBot, updateBot, verifyBotToken, type BotData, type BotForm } from '$lib/apis/bots';
|
||||
import { toast } from 'svelte-sonner';
|
||||
@@ -25,7 +26,7 @@
|
||||
let platform = $state(bot?.platform || 'telegram');
|
||||
let name = $state(bot?.name || '');
|
||||
let token = $state('');
|
||||
let modelId = $state(bot?.model_id || $selectedModelId || '');
|
||||
let modelId = $state(bot?.model_id || $defaultModel || '');
|
||||
let workspace = $state(bot?.workspace || '');
|
||||
let allowedSenders = $state(bot?.allowed_senders?.join(', ') || '');
|
||||
let saving = $state(false);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { activeWorkspace, addWorkspace, openFileTab, selectedModelId } from '$lib/stores';
|
||||
import { activeWorkspace, addWorkspace, openFileTab } from '$lib/stores';
|
||||
import { defaultModel } from '$lib/stores/chat';
|
||||
import {
|
||||
getGitLog,
|
||||
getGitDiff,
|
||||
@@ -382,7 +383,7 @@
|
||||
if (!stagedFiles.length || generatingCommitMessage) return;
|
||||
generatingCommitMessage = true;
|
||||
try {
|
||||
const message = await generateGitCommitMessage(workspacePath, $selectedModelId || undefined);
|
||||
const message = await generateGitCommitMessage(workspacePath, $defaultModel || undefined);
|
||||
commitSummary = message.summary;
|
||||
commitDescription = message.description;
|
||||
} catch (e) {
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
import DropdownMenu from '../DropdownMenu.svelte';
|
||||
import ModelSelector from '../common/ModelSelector.svelte';
|
||||
import ScheduleDropdown from './ScheduleDropdown.svelte';
|
||||
import { selectedModelId, workspaceList } from '$lib/stores';
|
||||
import { workspaceList } from '$lib/stores';
|
||||
import { defaultModel } from '$lib/stores/chat';
|
||||
import { getPathDisplayName } from '$lib/utils/paths';
|
||||
import type { AutomationData, AutomationForm } from '$lib/apis/automations';
|
||||
import { createAutomation, updateAutomation } from '$lib/apis/automations';
|
||||
@@ -25,7 +26,7 @@
|
||||
|
||||
let name = $state(automation?.name || '');
|
||||
let prompt = $state(automation?.prompt || '');
|
||||
let modelId = $state(automation?.model_id || $selectedModelId || '');
|
||||
let modelId = $state(automation?.model_id || $defaultModel || '');
|
||||
let workspace = $state(automation?.workspace || '');
|
||||
let rrule = $state(automation?.rrule || 'RRULE:FREQ=DAILY;BYHOUR=9;BYMINUTE=0');
|
||||
let saving = $state(false);
|
||||
|
||||
@@ -201,6 +201,10 @@
|
||||
return _t('chat.tool.killTask', { id: args.task_id || '?' });
|
||||
case 'image_generate':
|
||||
return args.image || args.images?.length ? 'Edit image' : 'Generate image';
|
||||
case 'ask_user': {
|
||||
const count = Array.isArray(args.questions) ? args.questions.length : 0;
|
||||
return `Asked ${count} question${count === 1 ? '' : 's'}`;
|
||||
}
|
||||
case 'web_search':
|
||||
return _t('chat.tool.webSearch', { query: args.query || '?' });
|
||||
case 'read_url': {
|
||||
@@ -343,7 +347,7 @@
|
||||
|
||||
for (const [index, item] of output.entries()) {
|
||||
if (item.type === 'function_call') {
|
||||
if (item.name !== 'ask_user') {
|
||||
if (item.name !== 'ask_user' || item.status !== 'pending') {
|
||||
ensureGroup();
|
||||
currentGroup!.entries.push(item);
|
||||
currentGroup!.calls.push(item);
|
||||
|
||||
@@ -29,13 +29,12 @@
|
||||
import Tasks from './Tasks.svelte';
|
||||
import AskUserCard from './AskUserCard.svelte';
|
||||
import Icon from '../Icon.svelte';
|
||||
import { planMode } from '$lib/stores';
|
||||
import type { ToolApprovalMode } from '$lib/apis/chat';
|
||||
import {
|
||||
sttConfigured,
|
||||
ttsConfigured,
|
||||
ttsEnabled,
|
||||
unlockTtsAudioPlayback,
|
||||
voiceModeEnabled,
|
||||
voiceModeSttMode
|
||||
} from '$lib/stores/audio';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
@@ -66,6 +65,10 @@
|
||||
interface Props {
|
||||
inputText: string;
|
||||
selectedModel: string;
|
||||
toolApprovalMode?: ToolApprovalMode;
|
||||
planMode?: boolean;
|
||||
requestParams?: Record<string, unknown>;
|
||||
voiceModeEnabled?: boolean;
|
||||
sending: boolean;
|
||||
streaming?: boolean;
|
||||
workspace?: string;
|
||||
@@ -91,10 +94,15 @@
|
||||
onqueuesendnow?: (id: string) => void;
|
||||
onqueueedit?: (id: string) => void;
|
||||
onqueuedelete?: (id: string) => void;
|
||||
onsettingschange?: () => void;
|
||||
}
|
||||
let {
|
||||
inputText = $bindable(),
|
||||
selectedModel = $bindable(),
|
||||
toolApprovalMode = $bindable('auto'),
|
||||
planMode = $bindable(false),
|
||||
requestParams = $bindable({}),
|
||||
voiceModeEnabled = $bindable(false),
|
||||
sending,
|
||||
streaming = false,
|
||||
workspace = '',
|
||||
@@ -114,7 +122,8 @@
|
||||
onaskuseranswer,
|
||||
onqueuesendnow,
|
||||
onqueueedit,
|
||||
onqueuedelete
|
||||
onqueuedelete,
|
||||
onsettingschange
|
||||
}: Props = $props();
|
||||
|
||||
let editorEl: HTMLDivElement | undefined = $state();
|
||||
@@ -137,7 +146,7 @@
|
||||
const voiceStatusLabel = $derived(
|
||||
voiceWaitingForResponse || streaming || sending
|
||||
? $t('chat.voiceWaiting')
|
||||
: voiceListening || voiceRearming || $voiceModeEnabled
|
||||
: voiceListening || voiceRearming || voiceModeEnabled
|
||||
? $t('chat.voiceListening')
|
||||
: $t('chat.voiceModeOn')
|
||||
);
|
||||
@@ -678,7 +687,7 @@
|
||||
clearVoiceRestartTimer();
|
||||
if (
|
||||
!voiceModeAvailable ||
|
||||
!$voiceModeEnabled ||
|
||||
!voiceModeEnabled ||
|
||||
voiceWaitingForResponse ||
|
||||
voiceListening ||
|
||||
voiceRecognition ||
|
||||
@@ -822,7 +831,7 @@
|
||||
clearVoiceRestartTimer(false);
|
||||
if (
|
||||
!voiceModeAvailable ||
|
||||
!$voiceModeEnabled ||
|
||||
!voiceModeEnabled ||
|
||||
voiceWaitingForResponse ||
|
||||
voiceListening ||
|
||||
voiceRecognition ||
|
||||
@@ -838,7 +847,7 @@
|
||||
(window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
|
||||
if (!SpeechRecognition) {
|
||||
alert($t('chat.dictate.unsupported'));
|
||||
voiceModeEnabled.set(false);
|
||||
voiceModeEnabled = false;
|
||||
voiceRearming = false;
|
||||
return;
|
||||
}
|
||||
@@ -890,7 +899,7 @@
|
||||
recognition.onerror = (event: any) => {
|
||||
voiceListening = false;
|
||||
if (event?.error === 'not-allowed' || event?.error === 'service-not-allowed') {
|
||||
voiceModeEnabled.set(false);
|
||||
voiceModeEnabled = false;
|
||||
stopVoiceRecognition();
|
||||
}
|
||||
};
|
||||
@@ -922,8 +931,9 @@
|
||||
alert($t('chat.ttsNotConfigured'));
|
||||
return;
|
||||
}
|
||||
const next = !$voiceModeEnabled;
|
||||
voiceModeEnabled.set(next);
|
||||
const next = !voiceModeEnabled;
|
||||
voiceModeEnabled = next;
|
||||
onsettingschange?.();
|
||||
if (next) {
|
||||
void unlockTtsAudioPlayback();
|
||||
void acquireVoiceWakeLock();
|
||||
@@ -939,11 +949,11 @@
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!voiceModeAvailable && $voiceModeEnabled) {
|
||||
voiceModeEnabled.set(false);
|
||||
if (!voiceModeAvailable && voiceModeEnabled) {
|
||||
voiceModeEnabled = false;
|
||||
stopVoiceRecognition();
|
||||
}
|
||||
if (!$voiceModeEnabled) return;
|
||||
if (!voiceModeEnabled) return;
|
||||
if (streaming) voiceSawStreaming = true;
|
||||
if (voiceSawStreaming && !streaming && !sending) {
|
||||
voiceWaitingForResponse = false;
|
||||
@@ -953,7 +963,7 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if ($voiceModeEnabled && inputText.trim()) {
|
||||
if (voiceModeEnabled && inputText.trim()) {
|
||||
stopVoiceRecognition();
|
||||
}
|
||||
});
|
||||
@@ -1247,7 +1257,7 @@
|
||||
<span class="flex-1 min-w-0 flex items-baseline gap-1.5 overflow-hidden">
|
||||
<span class="truncate">{$t('chat.commandPlan')}</span>
|
||||
<span class="app-muted text-[0.625rem] truncate shrink-0">
|
||||
{$planMode ? $t('chat.commandPlanOn') : $t('chat.commandPlanOff')}
|
||||
{planMode ? $t('chat.commandPlanOn') : $t('chat.commandPlanOff')}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
@@ -1464,7 +1474,7 @@
|
||||
{/if}
|
||||
<!-- Editor area -->
|
||||
<div class="px-2.5">
|
||||
{#if $voiceModeEnabled}
|
||||
{#if voiceModeEnabled}
|
||||
<div class="app-muted pt-2 flex items-center gap-2 text-[0.6875rem] font-medium">
|
||||
<span class="relative flex size-2">
|
||||
<span
|
||||
@@ -1493,6 +1503,10 @@
|
||||
>
|
||||
<div class="ml-0.5 self-end flex items-center gap-1">
|
||||
<PlusMenu
|
||||
bind:toolApprovalMode
|
||||
bind:planMode
|
||||
bind:requestParams
|
||||
onchange={onsettingschange}
|
||||
onfiles={(files) => {
|
||||
if (files) processFiles(Array.from(files));
|
||||
}}
|
||||
@@ -1500,13 +1514,13 @@
|
||||
processFiles([file]);
|
||||
}}
|
||||
/>
|
||||
{#if $planMode}
|
||||
{#if planMode}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$t('chat.commandPlanOff')}
|
||||
title={$t('chat.commandPlanOff')}
|
||||
class="app-surface app-interactive group p-[0.3125rem] flex gap-1 items-center text-xs rounded-full transition-colors duration-150 border"
|
||||
onclick={() => planMode.set(false)}
|
||||
onclick={() => onplan?.()}
|
||||
>
|
||||
<svg
|
||||
class="size-3 shrink-0 group-hover:hidden"
|
||||
@@ -1538,7 +1552,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="self-end mr-1 flex items-center gap-2">
|
||||
<ModelSelector bind:selectedModel />
|
||||
<ModelSelector bind:selectedModel onchange={onsettingschange} />
|
||||
<DictateButton
|
||||
ontext={(text) => {
|
||||
inputText += text;
|
||||
@@ -1550,7 +1564,7 @@
|
||||
onsend={handleSubmit}
|
||||
{oncancel}
|
||||
onvoice={voiceModeAvailable ? toggleVoiceMode : undefined}
|
||||
voiceActive={$voiceModeEnabled || voiceListening}
|
||||
voiceActive={voiceModeEnabled || voiceListening}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
createMessage,
|
||||
queueSendNow as apiQueueSendNow,
|
||||
queueDelete as apiQueueDelete,
|
||||
updateChatSettings,
|
||||
type ChatMessageRow,
|
||||
type ChatSendParams,
|
||||
type ChatInfo,
|
||||
type ToolApprovalMode,
|
||||
type ContextUsage,
|
||||
type ChatTask
|
||||
} from '$lib/apis/chat';
|
||||
@@ -31,16 +33,7 @@
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import {
|
||||
currentWorkspace,
|
||||
openChatTab,
|
||||
toolApprovalMode,
|
||||
planMode,
|
||||
streamingBehavior,
|
||||
selectedModelId,
|
||||
requestParams,
|
||||
widescreenMode
|
||||
} from '$lib/stores';
|
||||
import { currentWorkspace, openChatTab, streamingBehavior, widescreenMode } from '$lib/stores';
|
||||
import { getPathDisplayName } from '$lib/utils/paths';
|
||||
import {
|
||||
ttsEnabled,
|
||||
@@ -50,8 +43,7 @@
|
||||
ttsAutoStreamEnabled,
|
||||
ttsPlaybackEnabled,
|
||||
ttsVoice,
|
||||
unlockTtsAudioPlayback,
|
||||
voiceModeEnabled
|
||||
unlockTtsAudioPlayback
|
||||
} from '$lib/stores/audio';
|
||||
|
||||
import ChatInput from './ChatInput.svelte';
|
||||
@@ -93,6 +85,10 @@
|
||||
let inputText = $state('');
|
||||
let chatId = $state<string | null>(initialChatId ?? null);
|
||||
let selectedModel = $state('');
|
||||
let toolApprovalMode = $state<ToolApprovalMode>('auto');
|
||||
let planMode = $state(false);
|
||||
let requestParams = $state<Record<string, unknown>>({});
|
||||
let voiceModeEnabled = $state(false);
|
||||
let allMessages = $state<ChatMessageRow[]>([]);
|
||||
const pendingAskUser = $derived.by(() => {
|
||||
for (const message of [...allMessages].reverse()) {
|
||||
@@ -401,10 +397,11 @@
|
||||
const savedScroll = !isInitialLoad && messagesEl ? messagesEl.scrollTop : -1;
|
||||
|
||||
try {
|
||||
const data = await getChat(id, selectedModel || undefined);
|
||||
const data = await getChat(id);
|
||||
// Discard stale response if a newer loadChat was called while we waited
|
||||
if (gen !== loadGeneration) return;
|
||||
allMessages = data.messages;
|
||||
loadChatSettings(data.chat.meta);
|
||||
currentMessageId = data.chat.current_message_id;
|
||||
contextUsage = data.context_usage ?? null;
|
||||
setChatTasks(
|
||||
@@ -650,13 +647,49 @@
|
||||
if (chatId) loadChat(chatId);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
function resetChatSettings() {
|
||||
const models = get(chatModels);
|
||||
const saved = get(selectedModelId);
|
||||
const dm = get(defaultModel);
|
||||
if (saved && models.some((m) => m.id === saved)) selectedModel = saved;
|
||||
else if (dm) selectedModel = dm;
|
||||
if (dm) selectedModel = dm;
|
||||
else if (models.length) selectedModel = models[0].id;
|
||||
toolApprovalMode = 'auto';
|
||||
planMode = false;
|
||||
requestParams = {};
|
||||
voiceModeEnabled = false;
|
||||
}
|
||||
|
||||
function loadChatSettings(meta: Record<string, any> | null) {
|
||||
resetChatSettings();
|
||||
const params = meta?.params;
|
||||
if (!params || typeof params !== 'object') return;
|
||||
if (
|
||||
params.tool_approval_mode === 'ask' ||
|
||||
params.tool_approval_mode === 'auto' ||
|
||||
params.tool_approval_mode === 'full'
|
||||
) {
|
||||
toolApprovalMode = params.tool_approval_mode;
|
||||
}
|
||||
planMode = params.plan_mode === true;
|
||||
if (params.request_params && typeof params.request_params === 'object') {
|
||||
requestParams = params.request_params;
|
||||
}
|
||||
voiceModeEnabled = params.voice_mode === true;
|
||||
const models = get(chatModels);
|
||||
if (
|
||||
typeof meta?.last_model === 'string' &&
|
||||
models.some((model) => model.id === meta.last_model)
|
||||
) {
|
||||
selectedModel = meta.last_model;
|
||||
}
|
||||
}
|
||||
|
||||
async function persistChatSettings() {
|
||||
if (!chatId || !selectedModel) return;
|
||||
await updateChatSettings(chatId, selectedModel, getChatSendParams()).catch(() => {});
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
resetChatSettings();
|
||||
|
||||
if (chatId) {
|
||||
loadChat(chatId);
|
||||
@@ -691,23 +724,17 @@
|
||||
|
||||
$effect(() => {
|
||||
if (!$ttsEnabled || !$ttsConfigured) {
|
||||
voiceModeEnabled.set(false);
|
||||
voiceModeEnabled = false;
|
||||
ttsPlaybackEnabled.set(false);
|
||||
stopTtsPlayback();
|
||||
} else if (
|
||||
(!$ttsPlaybackEnabled && !$voiceModeEnabled && !$ttsAutoStreamEnabled) ||
|
||||
(!$ttsPlaybackEnabled && !voiceModeEnabled && !$ttsAutoStreamEnabled) ||
|
||||
!$ttsConfigured
|
||||
) {
|
||||
stopTtsPlayback();
|
||||
}
|
||||
});
|
||||
|
||||
// ── Persist model selection ─────────────────────────────────
|
||||
|
||||
$effect(() => {
|
||||
if (selectedModel) selectedModelId.set(selectedModel);
|
||||
});
|
||||
|
||||
// ── Sync streaming state to shared store for tab icon ────
|
||||
|
||||
$effect(() => {
|
||||
@@ -787,11 +814,11 @@
|
||||
|
||||
function getChatSendParams(): ChatSendParams {
|
||||
const params: ChatSendParams = {
|
||||
tool_approval_mode: get(toolApprovalMode),
|
||||
plan_mode: get(planMode),
|
||||
request_params: get(requestParams)
|
||||
tool_approval_mode: toolApprovalMode,
|
||||
plan_mode: planMode,
|
||||
request_params: requestParams
|
||||
};
|
||||
if (get(voiceModeEnabled)) params.voice_mode = true;
|
||||
if (voiceModeEnabled) params.voice_mode = true;
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -1004,7 +1031,8 @@
|
||||
}
|
||||
|
||||
function handlePlanCommand() {
|
||||
planMode.set(!get(planMode));
|
||||
planMode = !planMode;
|
||||
persistChatSettings();
|
||||
}
|
||||
|
||||
function firstUserMessageTitle(): string {
|
||||
@@ -1288,12 +1316,12 @@
|
||||
return (
|
||||
$ttsEnabled &&
|
||||
$ttsConfigured &&
|
||||
($ttsPlaybackEnabled || $voiceModeEnabled || $ttsAutoStreamEnabled)
|
||||
($ttsPlaybackEnabled || voiceModeEnabled || $ttsAutoStreamEnabled)
|
||||
);
|
||||
}
|
||||
|
||||
function shouldStreamTts() {
|
||||
return $ttsEnabled && $ttsConfigured && ($voiceModeEnabled || $ttsAutoStreamEnabled);
|
||||
return $ttsEnabled && $ttsConfigured && (voiceModeEnabled || $ttsAutoStreamEnabled);
|
||||
}
|
||||
|
||||
function resetTtsBuffer() {
|
||||
@@ -1483,7 +1511,7 @@
|
||||
toast.error($t('admin.audio.tts') + ': ' + detail);
|
||||
}
|
||||
ttsPlaybackEnabled.set(false);
|
||||
voiceModeEnabled.set(false);
|
||||
voiceModeEnabled = false;
|
||||
}
|
||||
|
||||
function scheduleTtsPrepare(generation: number) {
|
||||
@@ -1586,7 +1614,7 @@
|
||||
if (generation === ttsGeneration) ttsPlaying = false;
|
||||
if (generation === ttsGeneration) speakingMessageId = null;
|
||||
if (generation === ttsGeneration) ttsStopRequested = false;
|
||||
if (generation === ttsGeneration && !$voiceModeEnabled) ttsPlaybackEnabled.set(false);
|
||||
if (generation === ttsGeneration && !voiceModeEnabled) ttsPlaybackEnabled.set(false);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1637,6 +1665,10 @@
|
||||
bind:this={chatInputEl}
|
||||
bind:inputText
|
||||
bind:selectedModel
|
||||
bind:toolApprovalMode
|
||||
bind:planMode
|
||||
bind:requestParams
|
||||
bind:voiceModeEnabled
|
||||
{sending}
|
||||
{workspace}
|
||||
placeholder={$t('chat.placeholder', { name: workspaceDisplayName })}
|
||||
@@ -1645,6 +1677,7 @@
|
||||
onaskuseranswer={handleAskUserAnswer}
|
||||
onsend={send}
|
||||
onplan={handlePlanCommand}
|
||||
onsettingschange={persistChatSettings}
|
||||
{queuedMessages}
|
||||
onqueuesendnow={handleQueueSendNow}
|
||||
onqueueedit={handleQueueEdit}
|
||||
@@ -1757,6 +1790,10 @@
|
||||
bind:this={chatInputEl}
|
||||
bind:inputText
|
||||
bind:selectedModel
|
||||
bind:toolApprovalMode
|
||||
bind:planMode
|
||||
bind:requestParams
|
||||
bind:voiceModeEnabled
|
||||
{sending}
|
||||
{streaming}
|
||||
{workspace}
|
||||
@@ -1769,6 +1806,7 @@
|
||||
oncompact={handleManualCompact}
|
||||
onfork={handleForkChat}
|
||||
onplan={handlePlanCommand}
|
||||
onsettingschange={persistChatSettings}
|
||||
onstatus={handleStatusCommand}
|
||||
onskillslist={handleSkillsListCommand}
|
||||
oncancel={handleCancel}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { toolApprovalMode, planMode, requestParams, type ToolApprovalMode } from '$lib/stores';
|
||||
import type { ToolApprovalMode } from '$lib/apis/chat';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { t } from '$lib/i18n';
|
||||
import Icon from '../Icon.svelte';
|
||||
@@ -9,8 +9,19 @@
|
||||
interface Props {
|
||||
onfiles: (files: FileList) => void;
|
||||
oncapture?: (file: File) => void;
|
||||
toolApprovalMode?: ToolApprovalMode;
|
||||
planMode?: boolean;
|
||||
requestParams?: Record<string, unknown>;
|
||||
onchange?: () => void;
|
||||
}
|
||||
let { onfiles, oncapture }: Props = $props();
|
||||
let {
|
||||
onfiles,
|
||||
oncapture,
|
||||
toolApprovalMode = $bindable('auto'),
|
||||
planMode = $bindable(false),
|
||||
requestParams = $bindable({}),
|
||||
onchange
|
||||
}: Props = $props();
|
||||
|
||||
let open = $state(false);
|
||||
let tab = $state<'' | 'tools' | 'request_params'>('');
|
||||
@@ -28,12 +39,12 @@
|
||||
]);
|
||||
|
||||
const currentModeLabel = $derived(
|
||||
modes.find((m) => m.value === $toolApprovalMode)?.label ?? $t('plusMenu.toolPermissions')
|
||||
modes.find((m) => m.value === toolApprovalMode)?.label ?? $t('plusMenu.toolPermissions')
|
||||
);
|
||||
|
||||
// ── Request params state ────────────────────────
|
||||
let paramRows = $state<Array<{ key: string; value: string }>>(
|
||||
Object.entries($requestParams).map(([key, value]) => ({
|
||||
Object.entries(requestParams).map(([key, value]) => ({
|
||||
key,
|
||||
value: typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value)
|
||||
}))
|
||||
@@ -64,9 +75,17 @@
|
||||
result[key.trim()] = value;
|
||||
}
|
||||
}
|
||||
requestParams.set(result);
|
||||
requestParams = result;
|
||||
onchange?.();
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
paramRows = Object.entries(requestParams).map(([key, value]) => ({
|
||||
key,
|
||||
value: typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value)
|
||||
}));
|
||||
});
|
||||
|
||||
function toggle() {
|
||||
open = !open;
|
||||
if (open) {
|
||||
@@ -88,7 +107,8 @@
|
||||
}
|
||||
|
||||
function selectMode(mode: ToolApprovalMode) {
|
||||
toolApprovalMode.set(mode);
|
||||
toolApprovalMode = mode;
|
||||
onchange?.();
|
||||
}
|
||||
|
||||
function triggerUpload() {
|
||||
@@ -282,7 +302,10 @@
|
||||
<!-- Plan mode toggle -->
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white transition-colors duration-75"
|
||||
onclick={() => planMode.update((v) => !v)}
|
||||
onclick={() => {
|
||||
planMode = !planMode;
|
||||
onchange?.();
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
class="size-3.5 shrink-0"
|
||||
@@ -299,7 +322,13 @@
|
||||
<line x1="9" y1="17" x2="15" y2="17" />
|
||||
</svg>
|
||||
<span class="flex-1 text-left truncate">{$t('plusMenu.planMode')}</span>
|
||||
<ToggleSwitch value={$planMode} onchange={(v) => planMode.set(v)} />
|
||||
<ToggleSwitch
|
||||
value={planMode}
|
||||
onchange={(v) => {
|
||||
planMode = v;
|
||||
onchange?.();
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div class="app-divider h-px mx-1 my-0.5"></div>
|
||||
@@ -359,14 +388,14 @@
|
||||
{#each modes as mode}
|
||||
<button
|
||||
class="flex items-center gap-2 w-full h-7 px-2 rounded-xl text-xs transition-colors duration-75
|
||||
{$toolApprovalMode === mode.value
|
||||
{toolApprovalMode === mode.value
|
||||
? 'text-gray-900 dark:text-white bg-gray-50 dark:bg-white/5'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5 hover:text-gray-900 dark:hover:text-white'}"
|
||||
onclick={() => selectMode(mode.value)}
|
||||
use:tooltip={{ content: mode.desc, placement: 'right' }}
|
||||
>
|
||||
<span class="flex-1 text-left truncate">{mode.label}</span>
|
||||
{#if $toolApprovalMode === mode.value}
|
||||
{#if toolApprovalMode === mode.value}
|
||||
<svg
|
||||
class="w-3 h-3 shrink-0 text-gray-400 dark:text-gray-500"
|
||||
viewBox="0 0 24 24"
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
let { item, pairedOutput, done, chatId, messageId, toolLabel, onapprove }: Props = $props();
|
||||
|
||||
let expanded = $state($expandToolDetails);
|
||||
let expanded = $state($expandToolDetails || item.name === 'ask_user');
|
||||
$effect(() => {
|
||||
expanded = $expandToolDetails;
|
||||
expanded = $expandToolDetails || item.name === 'ask_user';
|
||||
});
|
||||
|
||||
const args = $derived(item.arguments || {});
|
||||
@@ -30,6 +30,15 @@
|
||||
const isDone = $derived(item.status === 'completed');
|
||||
const isRejected = $derived(item.status === 'rejected');
|
||||
const isPending = $derived(item.status === 'pending');
|
||||
const isAskUser = $derived(toolName === 'ask_user');
|
||||
const askUserQuestions = $derived(Array.isArray(args.questions) ? args.questions : []);
|
||||
const askUserAnswers = $derived.by(() => {
|
||||
try {
|
||||
return JSON.parse(pairedOutput?.output || '{}').answers || {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
const imageToolOutput = $derived.by(() => {
|
||||
if (toolName !== 'image_generate' || !pairedOutput?.output) {
|
||||
return null;
|
||||
@@ -103,6 +112,20 @@
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
{:else if isAskUser}
|
||||
<div class="text-gray-400 dark:text-gray-500">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="size-3.5"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.75"
|
||||
>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m5 12 3 3 5-7" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M13 7h6M13 12h6M13 17h6" />
|
||||
</svg>
|
||||
</div>
|
||||
{:else if isDone}
|
||||
<div class="text-emerald-500 dark:text-emerald-400">
|
||||
<svg
|
||||
@@ -202,97 +225,115 @@
|
||||
{#if expanded}
|
||||
<div id={callId} transition:slide={{ duration: 300, easing: quintOut, axis: 'y' }}>
|
||||
<div
|
||||
class="border border-gray-50 dark:border-gray-850/30 rounded-2xl my-1.5 p-3 space-y-3 overflow-hidden"
|
||||
class={isAskUser
|
||||
? 'ml-5 mt-1.5 space-y-1.5 text-xs leading-relaxed'
|
||||
: 'border border-gray-50 dark:border-gray-850/30 rounded-2xl my-1.5 p-3 space-y-3 overflow-hidden'}
|
||||
>
|
||||
{#if Object.keys(args).length > 0}
|
||||
<div>
|
||||
<div
|
||||
class="text-[0.625rem] uppercase tracking-wider text-gray-400 dark:text-gray-500 mb-1.5 px-1"
|
||||
>
|
||||
{$t('chat.toolInput')}
|
||||
{#if isAskUser}
|
||||
{#each askUserQuestions as question}
|
||||
{@const answer = askUserAnswers[question.id]?.answers?.join(', ')}
|
||||
<div>
|
||||
<div class="text-gray-600 dark:text-gray-300">{question.question}</div>
|
||||
<div class="text-gray-400 dark:text-gray-500">
|
||||
{answer || 'No answer recorded'}{answer === question.options?.[0]?.label
|
||||
? ' (Recommended)'
|
||||
: ''}
|
||||
</div>
|
||||
</div>
|
||||
{#if toolName === 'edit_file' && args.target}
|
||||
{/each}
|
||||
{:else}
|
||||
{#if Object.keys(args).length > 0}
|
||||
<div>
|
||||
<div
|
||||
class="text-[0.6875rem] font-mono rounded-lg overflow-hidden border border-gray-200/60 dark:border-white/6"
|
||||
class="text-[0.625rem] uppercase tracking-wider text-gray-400 dark:text-gray-500 mb-1.5 px-1"
|
||||
>
|
||||
<div
|
||||
class="bg-red-50/80 dark:bg-red-950/20 text-red-700 dark:text-red-400 px-2.5 py-1 whitespace-pre-wrap break-all leading-relaxed"
|
||||
>
|
||||
<span class="select-none text-red-400 dark:text-red-600 mr-1">-</span>{args.target
|
||||
.length > 500
|
||||
? args.target.slice(0, 500) + '...'
|
||||
: args.target}
|
||||
</div>
|
||||
<div
|
||||
class="bg-green-50/80 dark:bg-green-950/20 text-green-700 dark:text-green-400 px-2.5 py-1 whitespace-pre-wrap break-all leading-relaxed"
|
||||
>
|
||||
<span class="select-none text-green-400 dark:text-green-600 mr-1">+</span>{(
|
||||
args.replacement || ''
|
||||
).length > 500
|
||||
? args.replacement.slice(0, 500) + '...'
|
||||
: args.replacement || ''}
|
||||
</div>
|
||||
{$t('chat.toolInput')}
|
||||
</div>
|
||||
{#if args.start_line}
|
||||
<div class="text-[0.625rem] text-gray-400 dark:text-gray-600 mt-1 px-1">
|
||||
{$t('chat.toolLines', {
|
||||
start: args.start_line,
|
||||
end: args.end_line || 'end'
|
||||
})}
|
||||
</div>
|
||||
{/if}
|
||||
{:else if toolName === 'run_command'}
|
||||
<code
|
||||
class="block text-xs font-mono text-gray-600 dark:text-gray-300 bg-gray-50 dark:bg-gray-900 rounded-lg px-2.5 py-1.5 overflow-x-auto break-all whitespace-pre-wrap"
|
||||
>{args.command}</code
|
||||
>
|
||||
{:else}
|
||||
<div class="px-1 space-y-0.5">
|
||||
{#each Object.entries(args) as [key, value]}
|
||||
<div class="flex gap-2 text-xs py-0.5">
|
||||
<span class="text-gray-600 dark:text-gray-400 shrink-0">{key}</span>
|
||||
<span class="text-gray-800 dark:text-gray-200 break-all whitespace-pre-wrap">
|
||||
{typeof value === 'object' ? JSON.stringify(value, null, 2) : value}
|
||||
</span>
|
||||
{#if toolName === 'edit_file' && args.target}
|
||||
<div
|
||||
class="text-[0.6875rem] font-mono rounded-lg overflow-hidden border border-gray-200/60 dark:border-white/6"
|
||||
>
|
||||
<div
|
||||
class="bg-red-50/80 dark:bg-red-950/20 text-red-700 dark:text-red-400 px-2.5 py-1 whitespace-pre-wrap break-all leading-relaxed"
|
||||
>
|
||||
<span class="select-none text-red-400 dark:text-red-600 mr-1">-</span>{args
|
||||
.target.length > 500
|
||||
? args.target.slice(0, 500) + '...'
|
||||
: args.target}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if pairedOutput?.output}
|
||||
<div>
|
||||
<div
|
||||
class="text-[0.625rem] uppercase tracking-wider text-gray-400 dark:text-gray-500 mb-1.5 px-1"
|
||||
>
|
||||
{$t('chat.toolOutput')}
|
||||
</div>
|
||||
<div class="w-full min-w-0 overflow-hidden">
|
||||
{#if imageToolOutput?.length}
|
||||
<div class="px-1 space-y-1">
|
||||
{#each imageToolOutput as image}
|
||||
<div class="text-xs text-gray-600 dark:text-gray-300 break-all leading-relaxed">
|
||||
{image.path || image.url || image.id}
|
||||
<div
|
||||
class="bg-green-50/80 dark:bg-green-950/20 text-green-700 dark:text-green-400 px-2.5 py-1 whitespace-pre-wrap break-all leading-relaxed"
|
||||
>
|
||||
<span class="select-none text-green-400 dark:text-green-600 mr-1">+</span>{(
|
||||
args.replacement || ''
|
||||
).length > 500
|
||||
? args.replacement.slice(0, 500) + '...'
|
||||
: args.replacement || ''}
|
||||
</div>
|
||||
</div>
|
||||
{#if args.start_line}
|
||||
<div class="text-[0.625rem] text-gray-400 dark:text-gray-600 mt-1 px-1">
|
||||
{$t('chat.toolLines', {
|
||||
start: args.start_line,
|
||||
end: args.end_line || 'end'
|
||||
})}
|
||||
</div>
|
||||
{/if}
|
||||
{:else if toolName === 'run_command'}
|
||||
<code
|
||||
class="block text-xs font-mono text-gray-600 dark:text-gray-300 bg-gray-50 dark:bg-gray-900 rounded-lg px-2.5 py-1.5 overflow-x-auto break-all whitespace-pre-wrap"
|
||||
>{args.command}</code
|
||||
>
|
||||
{:else}
|
||||
<div class="px-1 space-y-0.5">
|
||||
{#each Object.entries(args) as [key, value]}
|
||||
<div class="flex gap-2 text-xs py-0.5">
|
||||
<span class="text-gray-600 dark:text-gray-400 shrink-0">{key}</span>
|
||||
<span class="text-gray-800 dark:text-gray-200 break-all whitespace-pre-wrap">
|
||||
{typeof value === 'object' ? JSON.stringify(value, null, 2) : value}
|
||||
</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<pre
|
||||
class="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono max-h-64 overflow-auto leading-relaxed">{formattedOutput.length >
|
||||
10000
|
||||
? formattedOutput.slice(0, 10000)
|
||||
: formattedOutput}</pre>
|
||||
{/if}
|
||||
{#if !imageToolOutput?.length && formattedOutput.length > 10000}
|
||||
<div class="text-[0.625rem] text-gray-400 dark:text-gray-600 mt-1 px-1">
|
||||
{$t('chat.totalChars', {
|
||||
count: formattedOutput.length.toLocaleString()
|
||||
})}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if pairedOutput?.output}
|
||||
<div>
|
||||
<div
|
||||
class="text-[0.625rem] uppercase tracking-wider text-gray-400 dark:text-gray-500 mb-1.5 px-1"
|
||||
>
|
||||
{$t('chat.toolOutput')}
|
||||
</div>
|
||||
<div class="w-full min-w-0 overflow-hidden">
|
||||
{#if imageToolOutput?.length}
|
||||
<div class="px-1 space-y-1">
|
||||
{#each imageToolOutput as image}
|
||||
<div
|
||||
class="text-xs text-gray-600 dark:text-gray-300 break-all leading-relaxed"
|
||||
>
|
||||
{image.path || image.url || image.id}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<pre
|
||||
class="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono max-h-64 overflow-auto leading-relaxed">{formattedOutput.length >
|
||||
10000
|
||||
? formattedOutput.slice(0, 10000)
|
||||
: formattedOutput}</pre>
|
||||
{/if}
|
||||
{#if !imageToolOutput?.length && formattedOutput.length > 10000}
|
||||
<div class="text-[0.625rem] text-gray-400 dark:text-gray-600 mt-1 px-1">
|
||||
{$t('chat.totalChars', {
|
||||
count: formattedOutput.length.toLocaleString()
|
||||
})}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,8 +8,14 @@
|
||||
selectedModel: string;
|
||||
preferAbove?: boolean;
|
||||
align?: 'start' | 'end';
|
||||
onchange?: (model: string) => void;
|
||||
}
|
||||
let { selectedModel = $bindable(), preferAbove = true, align = 'end' }: Props = $props();
|
||||
let {
|
||||
selectedModel = $bindable(),
|
||||
preferAbove = true,
|
||||
align = 'end',
|
||||
onchange
|
||||
}: Props = $props();
|
||||
|
||||
let btnEl: HTMLButtonElement | undefined = $state();
|
||||
let searchInputEl: HTMLInputElement | undefined = $state();
|
||||
@@ -33,6 +39,7 @@
|
||||
check: true,
|
||||
onclick: () => {
|
||||
selectedModel = m.id;
|
||||
onchange?.(m.id);
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -110,21 +110,15 @@ export interface HomeState {
|
||||
splitDirection: SplitDirection;
|
||||
}
|
||||
|
||||
export type ToolApprovalMode = 'ask' | 'auto' | 'full';
|
||||
|
||||
export interface UserPreferences {
|
||||
theme?: Theme;
|
||||
appearance?: AppearancePreferences;
|
||||
sidebarOpen: boolean;
|
||||
sidebarWidth: number;
|
||||
toolApprovalMode: ToolApprovalMode;
|
||||
planMode: boolean;
|
||||
locale: string;
|
||||
workspaceOrder?: string[]; // ordered paths for sidebar drag-reorder
|
||||
keybindings?: Record<string, string>; // user-customised keyboard shortcuts
|
||||
version?: string; // last seen app version for changelog
|
||||
selectedModelId?: string; // last selected chat model, synced across browsers
|
||||
requestParams?: Record<string, unknown>; // arbitrary params merged into API request body
|
||||
showUpdateToast?: boolean; // show version update notifications (default true)
|
||||
pwa?: PwaPreferences;
|
||||
textScale?: number | null;
|
||||
@@ -304,9 +298,6 @@ if (typeof window !== 'undefined') {
|
||||
}
|
||||
export const sidebarWidth = writable(220);
|
||||
export const theme = writable<Theme>('dark');
|
||||
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
|
||||
export const planMode = writable(false);
|
||||
export const requestParams = writable<Record<string, unknown>>({});
|
||||
export const appVersion = writable('');
|
||||
export const lastSeenVersion = writable('');
|
||||
export const latestVersion = writable('');
|
||||
@@ -323,19 +314,11 @@ export const updateAvailable = derived([appVersion, latestVersion], ([$app, $lat
|
||||
export const showChangelog = writable(false);
|
||||
export const showUpdateToastPref = writable(true);
|
||||
export const showSearch = writable(false);
|
||||
/** @deprecated Use toolApprovalMode */
|
||||
export const autoApproveTools = {
|
||||
subscribe: toolApprovalMode.subscribe,
|
||||
set: (v: boolean) => toolApprovalMode.set(v ? 'full' : 'ask'),
|
||||
update: (fn: (v: boolean) => boolean) =>
|
||||
toolApprovalMode.update((m) => (fn(m === 'full') ? 'full' : 'ask'))
|
||||
};
|
||||
export const stateLoaded = writable(false);
|
||||
export const gitReviewOpen = writable(false);
|
||||
export const isGitRepo = writable(false);
|
||||
export type StreamingBehavior = 'queue' | 'interrupt';
|
||||
export const streamingBehavior = writable<StreamingBehavior>('queue');
|
||||
export const selectedModelId = writable<string>('');
|
||||
export const pwaPreferences = writable<PwaPreferences>(defaultPwaPreferences);
|
||||
export const themeConfig = writable<ThemeConfig | null>(null);
|
||||
export const textScale = writable<number | null>(null);
|
||||
@@ -439,14 +422,10 @@ function persistPreferences(): void {
|
||||
},
|
||||
sidebarOpen: get(sidebarOpen),
|
||||
sidebarWidth: get(sidebarWidth),
|
||||
toolApprovalMode: get(toolApprovalMode),
|
||||
planMode: get(planMode),
|
||||
locale: i18next.language,
|
||||
workspaceOrder: get(workspaceOrder),
|
||||
keybindings: get(keybindings),
|
||||
version: get(lastSeenVersion),
|
||||
selectedModelId: get(selectedModelId) || undefined,
|
||||
requestParams: Object.keys(get(requestParams)).length ? get(requestParams) : undefined,
|
||||
showUpdateToast: get(showUpdateToastPref),
|
||||
pwa: get(pwaPreferences),
|
||||
textScale: get(textScale),
|
||||
@@ -480,15 +459,6 @@ function subscribeForPersistence() {
|
||||
sidebarWidth.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
toolApprovalMode.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
planMode.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
requestParams.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
workspaceOrder.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
@@ -498,9 +468,6 @@ function subscribeForPersistence() {
|
||||
lastSeenVersion.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
selectedModelId.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
showUpdateToastPref.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
@@ -533,20 +500,10 @@ export async function loadPreferences(): Promise<void> {
|
||||
themeConfig.set(sanitizeThemeConfig(appearance.themeConfig));
|
||||
if (prefs.sidebarOpen !== undefined) sidebarOpen.set(prefs.sidebarOpen as boolean);
|
||||
if (prefs.sidebarWidth !== undefined) sidebarWidth.set(prefs.sidebarWidth as number);
|
||||
// Support new toolApprovalMode and legacy boolean autoApproveTools
|
||||
if (prefs.toolApprovalMode) {
|
||||
toolApprovalMode.set(prefs.toolApprovalMode as ToolApprovalMode);
|
||||
} else if (prefs.autoApproveTools !== undefined) {
|
||||
// Legacy boolean migration
|
||||
toolApprovalMode.set((prefs.autoApproveTools as unknown as boolean) ? 'full' : 'ask');
|
||||
}
|
||||
if (prefs.planMode !== undefined) planMode.set(prefs.planMode as boolean);
|
||||
if (prefs.locale) changeLocale(prefs.locale as string);
|
||||
if (Array.isArray(prefs.workspaceOrder)) workspaceOrder.set(prefs.workspaceOrder as string[]);
|
||||
if (prefs.keybindings) loadKeybindings(prefs.keybindings as Record<string, string>);
|
||||
if (prefs.version) lastSeenVersion.set(prefs.version as string);
|
||||
if (prefs.selectedModelId) selectedModelId.set(prefs.selectedModelId as string);
|
||||
if (prefs.requestParams) requestParams.set(prefs.requestParams as Record<string, unknown>);
|
||||
if (prefs.showUpdateToast !== undefined)
|
||||
showUpdateToastPref.set(prefs.showUpdateToast as boolean);
|
||||
textScale.set(
|
||||
|
||||
@@ -23,7 +23,6 @@ export const ttsVoice = writable<string>('alloy');
|
||||
export const ttsFormat = writable<string>('mp3');
|
||||
export const ttsPlaybackSpeed = writable<number>(1);
|
||||
export const ttsAutoStreamEnabled = writable<boolean>(false);
|
||||
export const voiceModeEnabled = writable<boolean>(false);
|
||||
export const voiceModeSttMode = writable<'browser' | 'provider'>('browser');
|
||||
export const ttsPlaybackEnabled = writable<boolean>(
|
||||
typeof localStorage !== 'undefined'
|
||||
|
||||
@@ -502,6 +502,11 @@ class UpdateChatRequest(BaseModel):
|
||||
title: str
|
||||
|
||||
|
||||
class UpdateChatSettingsRequest(BaseModel):
|
||||
model_id: str
|
||||
params: dict = {}
|
||||
|
||||
|
||||
@router.patch("/{chat_id}")
|
||||
async def update_chat(chat_id: str, body: UpdateChatRequest, request: Request):
|
||||
"""Rename a chat."""
|
||||
@@ -521,6 +526,21 @@ async def update_chat(chat_id: str, body: UpdateChatRequest, request: Request):
|
||||
return {"ok": True, "title": title}
|
||||
|
||||
|
||||
@router.patch("/{chat_id}/settings")
|
||||
async def update_chat_settings(chat_id: str, body: UpdateChatSettingsRequest, request: Request):
|
||||
"""Save composer settings for one chat."""
|
||||
user_id = _get_user(request)
|
||||
chat = await Chat.get_by_id(chat_id)
|
||||
if not chat or chat.user_id != user_id:
|
||||
raise HTTPException(404, "chat not found")
|
||||
|
||||
meta = dict(chat.meta or {})
|
||||
meta["last_model"] = body.model_id
|
||||
meta["params"] = body.params
|
||||
await Chat.update_meta(chat_id, meta, now_ms())
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.delete("/{chat_id}")
|
||||
async def delete_chat(chat_id: str, request: Request):
|
||||
"""Delete a chat and all its messages."""
|
||||
|
||||
+10
-1
@@ -69,6 +69,8 @@ ASK_USER_SCHEMA = {
|
||||
"properties": {
|
||||
"questions": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"maxItems": 3,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -77,6 +79,8 @@ ASK_USER_SCHEMA = {
|
||||
"question": {"type": "string"},
|
||||
"options": {
|
||||
"type": "array",
|
||||
"minItems": 2,
|
||||
"maxItems": 3,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -90,7 +94,12 @@ ASK_USER_SCHEMA = {
|
||||
"required": ["id", "header", "question", "options"],
|
||||
},
|
||||
},
|
||||
"autoResolutionMs": {"type": "integer"},
|
||||
"autoResolutionMs": {
|
||||
"type": "integer",
|
||||
"minimum": 60_000,
|
||||
"maximum": 240_000,
|
||||
"default": DEFAULT_AUTO_RESOLUTION_MS,
|
||||
},
|
||||
},
|
||||
"required": ["questions"],
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user