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

No files matched your search

+1
View File
@@ -63,6 +63,7 @@
"codemirror": "^6.0.2", "codemirror": "^6.0.2",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"dayjs": "^1.11.21", "dayjs": "^1.11.21",
"dnd-kit": "^0.0.2",
"docx": "^9.5.1", "docx": "^9.5.1",
"dotenv": "^17.2.3", "dotenv": "^17.2.3",
"embla-carousel-react": "^8.6.0", "embla-carousel-react": "^8.6.0",
+16 -10
View File
@@ -621,6 +621,11 @@ export function useThreadStream({
lockThreadRagMode(threadId); lockThreadRagMode(threadId);
} }
const mergedContext = {
...context,
...extraContext,
};
await thread.submit( await thread.submit(
{ {
messages: [ messages: [
@@ -650,21 +655,22 @@ export function useThreadStream({
recursion_limit: 1000, recursion_limit: 1000,
}, },
context: { context: {
...extraContext, ...mergedContext,
...context, thinking_enabled: mergedContext.mode !== "flash",
thinking_enabled: context.mode !== "flash", is_plan_mode:
is_plan_mode: context.mode === "pro" || context.mode === "ultra", mergedContext.mode === "pro" || mergedContext.mode === "ultra",
subagent_enabled: context.mode === "ultra", subagent_enabled: mergedContext.mode === "ultra",
reasoning_effort: reasoning_effort:
context.reasoning_effort ?? mergedContext.reasoning_effort ??
(context.mode === "ultra" (mergedContext.mode === "ultra"
? "high" ? "high"
: context.mode === "pro" : mergedContext.mode === "pro"
? "medium" ? "medium"
: context.mode === "thinking" : mergedContext.mode === "thinking"
? "low" ? "low"
: undefined), : undefined),
memory_injection_enabled: context.memory_injection_enabled ?? true, memory_injection_enabled:
mergedContext.memory_injection_enabled ?? true,
rag_mode_enabled: ragModeEnabled, rag_mode_enabled: ragModeEnabled,
thread_id: threadId, thread_id: threadId,
}, },
@@ -220,8 +220,10 @@ export default function IframeChatPage() {
prompt: data.payload?.prompt, prompt: data.payload?.prompt,
pageContext: data.payload?.pageContext, pageContext: data.payload?.pageContext,
screenshot: data.payload?.screenshot, screenshot: data.payload?.screenshot,
model: data.payload?.model,
requestId: data.requestId, requestId: data.requestId,
filesCount: files.length, filesCount: files.length,
iframeContext,
}); });
if (!submitText && files.length === 0) return; 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]?.filename, "shot.jpg");
assert.equal(result.files[0]?.mediaType, "image/jpeg"); 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[]; images?: BrainyScreenshotImage[];
}; };
type BrainyModelSelection = {
label?: string;
value?: string;
};
export type BrainyChatSubmitMessage = { export type BrainyChatSubmitMessage = {
source?: string; source?: string;
type?: string; type?: string;
@@ -29,6 +34,7 @@ export type BrainyChatSubmitMessage = {
prompt?: string; prompt?: string;
pageContext?: BrainyPageContext; pageContext?: BrainyPageContext;
screenshot?: BrainyScreenshot; screenshot?: BrainyScreenshot;
model?: BrainyModelSelection;
}; };
requestId?: string; requestId?: string;
}; };
@@ -261,13 +267,20 @@ export function parseBrainyChatSubmitMessage(
hasAttachedImage: files.length > 0, hasAttachedImage: files.length > 0,
}); });
const requestId = trimToUndefined(data.requestId); 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 { return {
submitText, submitText,
files, files,
...(requestId ...(Object.keys(iframeContext).length > 0 ? { iframeContext } : {}),
? { iframeContext: { brainy_request_id: requestId } }
: {}),
...(promptPrefix ? { additionalKwargs: { prompt_prefix: promptPrefix } } : {}), ...(promptPrefix ? { additionalKwargs: { prompt_prefix: promptPrefix } } : {}),
}; };
} }