增加模型选择功能,支持不同 Agent 模型
Build Push and Deploy / docker-image (push) Successful in 1m3s
Build Push and Deploy / deploy-fallback-log (push) Has been skipped

This commit is contained in:
2026-05-13 18:12:22 +08:00
parent a4486e3d89
commit 8058b7b859
5 changed files with 192 additions and 42 deletions
@@ -3,7 +3,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { abortAgentChat, forkAgentChat, streamAgentChat } from "@/lib/chatStream";
import type { StreamEvent } from "@/lib/chatStream";
import type { AgentModel, StreamEvent } from "@/lib/chatStream";
import type {
AgentArtifact,
BranchGroup,
@@ -37,6 +37,7 @@ type UseAgentChatSessionOptions = {
},
) => void;
onBeforeSend?: () => void;
getModel?: () => AgentModel;
};
type PromptRunOptions = {
@@ -137,6 +138,7 @@ const messagesEqual = (left: Message[], right: Message[]) =>
export const useAgentChatSession = ({
onToolCall,
onBeforeSend,
getModel,
}: UseAgentChatSessionOptions) => {
const storageSessionIdRef = useRef<string | undefined>(undefined);
const hydrationCompletedRef = useRef(false);
@@ -317,6 +319,7 @@ export const useAgentChatSession = ({
await streamAgentChat({
message: prompt,
sessionId: sessionIdOverride ?? sessionIdRef.current,
model: getModel?.(),
signal: controller.signal,
onEvent: (event) => {
if ("sessionId" in event && event.sessionId && event.sessionId !== sessionIdRef.current) {
@@ -448,7 +451,7 @@ export const useAgentChatSession = ({
setIsStreaming(false);
}
},
[appendArtifact, isHydrating, isStreaming, messages, onBeforeSend, onToolCall],
[appendArtifact, getModel, isHydrating, isStreaming, messages, onBeforeSend, onToolCall],
);
const abort = useCallback(() => {