Revert "Merge branch 'gzy' into 'master'"

This reverts merge request !157
This commit is contained in:
g zy committed 2026-06-29 08:43:19 +00:00
1 parent d8af6c8f48
commit 75e8a90ac7
3 files changed
+18 -69

No files matched your search

@@ -20,7 +20,6 @@ import {
} from "@/components/ui/dialog";
import { PromptInputButton } from "@/components/ai-elements/prompt-input";
import { AgentManageDialog } from "@/components/workspace/agents/agent-manage-dialog";
import { Tooltip } from "@/components/workspace/tooltip";
import { useAgentSelector, useAgentsPaginated } from "@/core/agents";
import type { Agent } from "@/core/agents";
import { getStoredAuth } from "@/core/auth";
@@ -87,7 +86,6 @@ export function AgentSelector({
};
const triggerLabel = selectedAgent ? desensitize(selectedAgent.name) : "选择 Agent";
const iconTooltipLabel = selectedAgent ? triggerLabel : "未选择";
const iconMode = triggerVariant === "icon";
return (
@@ -95,7 +93,6 @@ export function AgentSelector({
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
{iconMode ? (
<Tooltip content={iconTooltipLabel}>
<Button
type="button"
variant="ghost"
@@ -128,7 +125,6 @@ export function AgentSelector({
</span>
)}
</Button>
</Tooltip>
) : (
<PromptInputButton
type="button"
@@ -166,25 +166,3 @@ test("mapped domain overrides the user's manual selection for that incoming mess
},
);
});
test("unmapped incoming url resets auto-selected agent back to default when there is no manual selection", () => {
assert.deepEqual(
resolveIncomingIframeSelection({
pageUrl: "https://another-unknown.example.com/article",
mappings: [
{
id: "m1",
domain: "foo.example.com",
agentId: "agent-1",
enabled: true,
},
],
availableAgentIds: ["agent-1", "agent-2"],
manualSelectedAgentId: null,
}),
{
selectedAgentId: null,
forceDefaultAssistant: true,
},
);
});
+18 -43
View File
@@ -83,13 +83,6 @@ type BrainyChatInterruptMessage = {
};
requestId?: string;
};
type BrainyUrlContextMessage = {
source?: string;
type?: string;
payload?: {
url?: string;
};
};
type PendingIframeSubmit = {
message: PromptInputMessage;
externalContext?: Record<string, unknown>;
@@ -436,33 +429,9 @@ export default function IframeChatPage() {
[thread],
);
const applyIncomingUrlSelection = useCallback(
(pageUrl: string | null | undefined) => {
const nextSelection = resolveIncomingIframeSelection({
pageUrl,
mappings: pluginManagementSettings?.domainAgentMappings ?? [],
availableAgentIds: selectorLoading
? undefined
: selectorAgents.map((agent) => agent.id),
manualSelectedAgentId,
});
setSelectedAgentId(nextSelection.selectedAgentId);
setForceDefaultAssistant(nextSelection.forceDefaultAssistant);
return nextSelection;
},
[
manualSelectedAgentId,
pluginManagementSettings?.domainAgentMappings,
selectorAgents,
selectorLoading,
],
);
useEffect(() => {
const handleMessage = (
event: MessageEvent<
BrainyChatSubmitMessage | BrainyChatInterruptMessage | BrainyUrlContextMessage
>,
event: MessageEvent<BrainyChatSubmitMessage | BrainyChatInterruptMessage>,
) => {
const data = event.data;
if (data?.source !== "brainy-extension") return;
@@ -470,12 +439,6 @@ export default function IframeChatPage() {
void handleInterrupt(data as BrainyChatInterruptMessage);
return;
}
if (data?.type === "brainy:context-url") {
applyIncomingUrlSelection(
(data as BrainyUrlContextMessage).payload?.url ?? null,
);
return;
}
if (data?.type !== "brainy:chat-submit") return;
const submitMessage = data as BrainyChatSubmitMessage;
const { submitText, files, iframeContext, additionalKwargs } =
@@ -483,6 +446,17 @@ export default function IframeChatPage() {
if (!submitText && files.length === 0) return;
const nextSelection = resolveIncomingIframeSelection({
pageUrl: submitMessage.payload?.pageContext?.url,
mappings: pluginManagementSettings?.domainAgentMappings ?? [],
availableAgentIds: selectorLoading
? undefined
: selectorAgents.map((agent) => agent.id),
manualSelectedAgentId,
});
setSelectedAgentId(nextSelection.selectedAgentId);
setForceDefaultAssistant(nextSelection.forceDefaultAssistant);
console.log("收到插件消息", {
text: submitMessage.payload?.text,
prompt: submitMessage.payload?.prompt,
@@ -499,8 +473,8 @@ export default function IframeChatPage() {
message: { text: submitText, files },
externalContext: iframeContext,
options: additionalKwargs ? { additionalKwargs } : undefined,
targetSelectedAgentId: selectedAgentId,
targetForceDefaultAssistant: forceDefaultAssistant,
targetSelectedAgentId: nextSelection.selectedAgentId,
targetForceDefaultAssistant: nextSelection.forceDefaultAssistant,
});
};
@@ -509,10 +483,11 @@ export default function IframeChatPage() {
window.removeEventListener("message", handleMessage);
};
}, [
applyIncomingUrlSelection,
forceDefaultAssistant,
handleInterrupt,
selectedAgentId,
manualSelectedAgentId,
pluginManagementSettings?.domainAgentMappings,
selectorAgents,
selectorLoading,
]);
const isLandingState = isNewThread && !hasStartedConversation;