fix: pass chat_id to internal task calls for consistent function context (#20585)

Ensure chat_id is reliably passed to function pipelines/manifolds during internal task invocations (web search query generation, RAG query generation, image prompt generation).

This allows stateful functions to maintain per-chat state without fragmentation, as they will now receive a consistent chat_id for all chat-scoped invocations including internal tasks.

Backend changes:
- Pass chat_id in generate_queries call for web search
- Pass chat_id in generate_queries call for RAG/retrieval
- Pass chat_id in generate_image_prompt call

Frontend changes:
- Add optional chat_id parameter to generateQueries API function
- Add optional chat_id parameter to generateAutoCompletion API function

Fixes #20563
This commit is contained in:
Classic298
2026-02-12 15:36:42 -06:00
committed by GitHub
parent 0dcbd05e24
commit e8499ccdd1
2 changed files with 12 additions and 5 deletions
+3
View File
@@ -1255,6 +1255,7 @@ async def chat_web_search_handler(
"messages": messages, "messages": messages,
"prompt": user_message, "prompt": user_message,
"type": "web_search", "type": "web_search",
"chat_id": extra_params.get("__chat_id__"),
}, },
user, user,
) )
@@ -1585,6 +1586,7 @@ async def chat_image_generation_handler(
{ {
"model": form_data["model"], "model": form_data["model"],
"messages": form_data["messages"], "messages": form_data["messages"],
"chat_id": metadata.get("chat_id"),
}, },
user, user,
) )
@@ -1691,6 +1693,7 @@ async def chat_completion_files_handler(
"model": body["model"], "model": body["model"],
"messages": body["messages"], "messages": body["messages"],
"type": "retrieval", "type": "retrieval",
"chat_id": body.get("metadata", {}).get("chat_id"),
}, },
user, user,
) )
+9 -5
View File
@@ -864,7 +864,8 @@ export const generateQueries = async (
model: string, model: string,
messages: object[], messages: object[],
prompt: string, prompt: string,
type: string = 'web_search' type: string = 'web_search',
chat_id?: string
) => { ) => {
let error = null; let error = null;
@@ -879,7 +880,8 @@ export const generateQueries = async (
model: model, model: model,
messages: messages, messages: messages,
prompt: prompt, prompt: prompt,
type: type type: type,
...(chat_id && { chat_id: chat_id })
}) })
}) })
.then(async (res) => { .then(async (res) => {
@@ -933,7 +935,8 @@ export const generateAutoCompletion = async (
model: string, model: string,
prompt: string, prompt: string,
messages?: object[], messages?: object[],
type: string = 'search query' type: string = 'search query',
chat_id?: string
) => { ) => {
const controller = new AbortController(); const controller = new AbortController();
let error = null; let error = null;
@@ -951,7 +954,8 @@ export const generateAutoCompletion = async (
prompt: prompt, prompt: prompt,
...(messages && { messages: messages }), ...(messages && { messages: messages }),
type: type, type: type,
stream: false stream: false,
...(chat_id && { chat_id: chat_id })
}) })
}) })
.then(async (res) => { .then(async (res) => {
@@ -1675,7 +1679,7 @@ export interface ModelMeta {
profile_image_url?: string; profile_image_url?: string;
} }
export interface ModelParams {} export interface ModelParams { }
export type GlobalModelConfig = ModelConfig[]; export type GlobalModelConfig = ModelConfig[];