Skip to content

Commit f84913f

Browse files
committed
Add user token to OpenAI API requests
1 parent 0eb8216 commit f84913f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib/server/textGeneration/mcp/runMcpFlow.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export async function* runMcpFlow({
248248
route: resolvedRoute,
249249
candidateModelId,
250250
toolCount: oaTools.length,
251+
hasUserToken: Boolean((locals as any)?.token),
251252
},
252253
"[mcp] starting completion with tools"
253254
);
@@ -402,6 +403,7 @@ export async function* runMcpFlow({
402403
headers: {
403404
"ChatUI-Conversation-ID": conv._id.toString(),
404405
"X-use-cache": "false",
406+
...(locals?.token ? { Authorization: `Bearer ${locals.token}` } : {}),
405407
},
406408
}
407409
);
@@ -523,7 +525,14 @@ export async function* runMcpFlow({
523525
console.debug({ loop }, "[mcp] missing tool_call id in stream; retrying non-stream to recover ids");
524526
const nonStream = await openai.chat.completions.create(
525527
{ ...completionBase, messages: messagesOpenAI, stream: false },
526-
{ signal: abortSignal }
528+
{
529+
signal: abortSignal,
530+
headers: {
531+
"ChatUI-Conversation-ID": conv._id.toString(),
532+
"X-use-cache": "false",
533+
...(locals?.token ? { Authorization: `Bearer ${locals.token}` } : {}),
534+
},
535+
}
527536
);
528537
const tc = nonStream.choices?.[0]?.message?.tool_calls ?? [];
529538
calls = tc.map((t) => ({

0 commit comments

Comments
 (0)