fix: a question the model asks in a side chat never shows (#33901)

When the model used Ask User in a saved side chat, the reply stopped to wait for the answer, but the side chat never showed the question, so the reply stayed unfinished for good. The side chat now shows the waiting question above its message box, as the main chat does, also for someone continuing a shared side chat, and answering or dismissing it lets the reply carry on. Until then the side chat takes no new message, so nothing is sent past an open question.

Fixes #33890
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-08 10:40:27 +09:00
1 parent 63d20d24ce
commit 5cbd9bc5cc
3 files changed
+91 -39

No files matched your search

+1 -35
View File
@@ -87,6 +87,7 @@
import {
applyResponseStreamEvent,
getOutputText,
getPendingAskUserFromMessage,
setOutputText
} from './Messages/structuredOutput';
@@ -622,41 +623,6 @@
}
};
const parseToolArguments = (args) => {
if (!args) {
return {};
}
let value = args;
while (typeof value === 'string') {
try {
value = JSON.parse(value);
} catch {
break;
}
}
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
};
const getPendingAskUserFromMessage = (message) => {
if (message?.role !== 'assistant' || !Array.isArray(message.output)) {
return null;
}
const call = message.output.find(
(item) =>
item?.type === 'function_call' &&
item?.name === 'ask_user' &&
item?.status === 'pending' &&
(item?.call_id || item?.id)
);
if (call) {
return { message, call, args: parseToolArguments(call.arguments) };
}
return null;
};
const findPendingAskUser = (chatHistory) => {
if (!chatHistory?.messages) {
return null;
@@ -22,9 +22,18 @@
import { getSkills } from '$lib/apis/skills';
import { generateOpenAIChatCompletion, getErrorMessage } from '$lib/apis/openai';
import { getTaskIdsByChatId, resumeTemporaryChat, stopTasksByChatId } from '$lib/apis';
import { createNewChat, getAllTags, getChatById, updateChatById } from '$lib/apis/chats';
import {
createNewChat,
getAllTags,
getChatById,
resolveChatMessageToolCall,
updateChatById
} from '$lib/apis/chats';
import { refreshChatList, refreshFolderChatLists } from '$lib/stores/chatList';
import { applyResponseStreamEvent } from '../Messages/structuredOutput';
import {
applyResponseStreamEvent,
getPendingAskUserFromMessage
} from '../Messages/structuredOutput';
import Messages from '../Messages.svelte';
import MessageInput from '../MessageInput.svelte';
import FilesOverlay from '../MessageInput/FilesOverlay.svelte';
@@ -162,6 +171,43 @@
onConfirm: (value: any) => resolveInteraction(interaction, value),
onCancel: () => resolveInteraction(interaction, { status: 'cancelled', answers: {} })
};
const resolvePendingAskUser = async (action: 'answer' | 'reject', answers?: unknown) => {
const { message, call } = pendingAskUser;
error = '';
try {
await resolveChatMessageToolCall(
localStorage.token,
id,
message.id,
call.call_id || call.id,
action,
{ answers }
);
// reconnect reads done to tell whether the resumed reply is still running
message.done = false;
} catch (err) {
error = getErrorMessage(err);
}
void reconnect();
};
$: pendingAskUser =
[...messages]
.reverse()
.filter((message) => (message.user_id ? message.user_id === $user?.id : !isShared))
.map(getPendingAskUserFromMessage)
.find(Boolean) ?? null;
$: savedAskUserPrompt = pendingAskUser
? {
show: true,
questions: Array.isArray(pendingAskUser.args?.questions)
? pendingAskUser.args.questions
: [],
allowOther: pendingAskUser.args?.allow_other !== false,
timeoutMs: null,
onConfirm: (value: any) => void resolvePendingAskUser('answer', value?.answers ?? {}),
onCancel: () => void resolvePendingAskUser('reject')
}
: null;
let system = [
systemPrompt,
'This is a separate side conversation. Earlier messages are reference context only. Answer the side question; do not continue the parent task.'
@@ -333,7 +379,7 @@
const send = async () => {
if (!canSend || disposed) return;
const question = draft.trim();
if ((!question && !files.length) || busy || sending || recovering) return;
if ((!question && !files.length) || busy || sending || recovering || pendingAskUser) return;
if (!atSelectedModel && selectedModels.length !== 1) {
error = $i18n.t('Select only one model');
return;
@@ -400,6 +446,7 @@
parentId: userMessage.id,
childrenIds: [] as string[],
role: 'assistant',
user_id: $user?.id,
content: '',
output: [],
done: false,
@@ -633,7 +680,7 @@
onToolApprovalModeChange={(mode: string) => {
params = { ...params, tool_approval_mode: mode };
}}
{askUser}
askUser={savedAskUserPrompt ?? askUser}
dropzoneId={`${inputId}-pane`}
{inputId}
{messagesContainerId}
@@ -780,3 +780,42 @@ export function setOutputText(output: OutputItem[], text: string): OutputItem[]
: item
);
}
function parseToolArguments(args: unknown): Record<string, unknown> {
if (!args) {
return {};
}
let value = args;
while (typeof value === 'string') {
try {
value = JSON.parse(value);
} catch {
break;
}
}
return typeof value === 'object' && value !== null && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
}
export function getPendingAskUserFromMessage<T extends { role?: string; output?: unknown }>(
message: T
) {
if (message?.role !== 'assistant' || !Array.isArray(message.output)) {
return null;
}
const call = message.output.find(
(item: OutputItem) =>
item?.type === 'function_call' &&
item?.name === 'ask_user' &&
item?.status === 'pending' &&
(item?.call_id || item?.id)
);
if (call) {
return { message, call, args: parseToolArguments(call.arguments) };
}
return null;
}