MCPcopy
hub / github.com/ChatGPTNextWeb/NextChat / onUserInput

Function onUserInput

app/store/chat.ts:407–528  ·  view source on GitHub ↗
(
        content: string,
        attachImages?: string[],
        isMcpResponse?: boolean,
      )

Source from the content-addressed store, hash-verified

405 },
406
407 async onUserInput(
408 content: string,
409 attachImages?: string[],
410 isMcpResponse?: boolean,
411 ) {
412 const session = get().currentSession();
413 const modelConfig = session.mask.modelConfig;
414
415 // MCP Response no need to fill template
416 let mContent: string | MultimodalContent[] = isMcpResponse
417 ? content
418 : fillTemplateWith(content, modelConfig);
419
420 if (!isMcpResponse && attachImages && attachImages.length > 0) {
421 mContent = [
422 ...(content ? [{ type: "text" as const, text: content }] : []),
423 ...attachImages.map((url) => ({
424 type: "image_url" as const,
425 image_url: { url },
426 })),
427 ];
428 }
429
430 let userMessage: ChatMessage = createMessage({
431 role: "user",
432 content: mContent,
433 isMcpResponse,
434 });
435
436 const botMessage: ChatMessage = createMessage({
437 role: "assistant",
438 streaming: true,
439 model: modelConfig.model,
440 });
441
442 // get recent messages
443 const recentMessages = await get().getMessagesWithMemory();
444 const sendMessages = recentMessages.concat(userMessage);
445 const messageIndex = session.messages.length + 1;
446
447 // save user's and bot's message
448 get().updateTargetSession(session, (session) => {
449 const savedUserMessage = {
450 ...userMessage,
451 content: mContent,
452 };
453 session.messages = session.messages.concat([
454 savedUserMessage,
455 botMessage,
456 ]);
457 });
458
459 const api: ClientApi = getClientApi(modelConfig.providerName);
460 // make request
461 api.llm.chat({
462 messages: sendMessages,
463 config: { ...modelConfig, stream: true },
464 onUpdate(message) {

Callers

nothing calls this directly

Calls 5

getClientApiFunction · 0.90
fillTemplateWithFunction · 0.85
createMessageFunction · 0.85
getFunction · 0.70
chatMethod · 0.45

Tested by

no test coverage detected