This commit is contained in:
fengxiangdebaozi committed 2026-06-04 11:09:29 +08:00
commit f87f6031de
5 files changed
+76 -33

No files matched your search

+1
View File
@@ -63,6 +63,7 @@
"codemirror": "^6.0.2",
"date-fns": "^4.1.0",
"dayjs": "^1.11.21",
"dnd-kit": "^0.0.2",
"docx": "^9.5.1",
"dotenv": "^17.2.3",
"embla-carousel-react": "^8.6.0",
+36 -30
View File
@@ -621,10 +621,15 @@ export function useThreadStream({
lockThreadRagMode(threadId);
}
await thread.submit(
{
messages: [
{
const mergedContext = {
...context,
...extraContext,
};
await thread.submit(
{
messages: [
{
type: "human",
content: [
{
@@ -642,32 +647,33 @@ export function useThreadStream({
},
],
},
{
threadId: threadId,
streamSubgraphs: true,
streamResumable: true,
config: {
recursion_limit: 1000,
},
context: {
...extraContext,
...context,
thinking_enabled: context.mode !== "flash",
is_plan_mode: context.mode === "pro" || context.mode === "ultra",
subagent_enabled: context.mode === "ultra",
reasoning_effort:
context.reasoning_effort ??
(context.mode === "ultra"
? "high"
: context.mode === "pro"
? "medium"
: context.mode === "thinking"
? "low"
: undefined),
memory_injection_enabled: context.memory_injection_enabled ?? true,
rag_mode_enabled: ragModeEnabled,
thread_id: threadId,
},
{
threadId: threadId,
streamSubgraphs: true,
streamResumable: true,
config: {
recursion_limit: 1000,
},
context: {
...mergedContext,
thinking_enabled: mergedContext.mode !== "flash",
is_plan_mode:
mergedContext.mode === "pro" || mergedContext.mode === "ultra",
subagent_enabled: mergedContext.mode === "ultra",
reasoning_effort:
mergedContext.reasoning_effort ??
(mergedContext.mode === "ultra"
? "high"
: mergedContext.mode === "pro"
? "medium"
: mergedContext.mode === "thinking"
? "low"
: undefined),
memory_injection_enabled:
mergedContext.memory_injection_enabled ?? true,
rag_mode_enabled: ragModeEnabled,
thread_id: threadId,
},
},
);
void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
@@ -220,8 +220,10 @@ export default function IframeChatPage() {
prompt: data.payload?.prompt,
pageContext: data.payload?.pageContext,
screenshot: data.payload?.screenshot,
model: data.payload?.model,
requestId: data.requestId,
filesCount: files.length,
iframeContext,
});
if (!submitText && files.length === 0) return;
@@ -79,3 +79,24 @@ test("keeps screenshot-only iframe submissions in the conversation flow", () =>
assert.equal(result.files[0]?.filename, "shot.jpg");
assert.equal(result.files[0]?.mediaType, "image/jpeg");
});
test("maps iframe model selection into stream context model_name", () => {
const result = parseBrainyChatSubmitMessage({
source: "brainy-extension",
type: "brainy:chat-submit",
requestId: "iframe-456",
payload: {
text: "帮我总结这个页面",
model: {
label: "Qwen3-32B: 效果与速度均衡(推荐)",
value: "OpenAI3",
},
},
});
assert.equal(result.submitText, "帮我总结这个页面");
assert.deepEqual(result.iframeContext, {
brainy_request_id: "iframe-456",
model_name: "OpenAI3",
});
});
+16 -3
View File
@@ -21,6 +21,11 @@ type BrainyScreenshot = {
images?: BrainyScreenshotImage[];
};
type BrainyModelSelection = {
label?: string;
value?: string;
};
export type BrainyChatSubmitMessage = {
source?: string;
type?: string;
@@ -29,6 +34,7 @@ export type BrainyChatSubmitMessage = {
prompt?: string;
pageContext?: BrainyPageContext;
screenshot?: BrainyScreenshot;
model?: BrainyModelSelection;
};
requestId?: string;
};
@@ -261,13 +267,20 @@ export function parseBrainyChatSubmitMessage(
hasAttachedImage: files.length > 0,
});
const requestId = trimToUndefined(data.requestId);
const modelName = trimToUndefined(data.payload?.model?.value);
const iframeContext: Record<string, unknown> = {};
if (requestId) {
iframeContext.brainy_request_id = requestId;
}
if (modelName) {
iframeContext.model_name = modelName;
}
return {
submitText,
files,
...(requestId
? { iframeContext: { brainy_request_id: requestId } }
: {}),
...(Object.keys(iframeContext).length > 0 ? { iframeContext } : {}),
...(promptPrefix ? { additionalKwargs: { prompt_prefix: promptPrefix } } : {}),
};
}