feat: 从iframe对接模型配置

This commit is contained in:
ZyGuo committed 2026-06-04 11:03:50 +08:00
1 parent c05513ae1e
commit f496546cc0
5 files changed
+76 -33

No files matched your 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 } } : {}),
};
}