Revert "Merge branch 'gzy' into 'master'"
This reverts merge request !157
This commit is contained in:
1 parent
d8af6c8f48
commit
75e8a90ac7
3 files changed
+50
-101
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,40 +93,38 @@ export function AgentSelector({
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
{iconMode ? (
|
||||
<Tooltip content={iconTooltipLabel}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
aria-label={selectedAgent ? `已选择智能体:${triggerLabel}` : "选择智能体"}
|
||||
className={cn(
|
||||
"relative size-9 rounded-full text-muted-foreground shadow-none hover:bg-muted/60 hover:text-foreground",
|
||||
selectedAgent && "text-amber-600 hover:text-amber-700",
|
||||
selectedAgent && iconActiveClassName,
|
||||
iconButtonClassName,
|
||||
)}
|
||||
>
|
||||
<BotIcon className="size-4" />
|
||||
{selectedAgent && (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label="清除已选 agent"
|
||||
className="absolute -right-1 -top-1 inline-flex size-4 items-center justify-center rounded-full border bg-background text-foreground shadow-sm hover:bg-muted"
|
||||
onClick={handleClear}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onAgentChange(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<XIcon className="size-2.5" />
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={disabled}
|
||||
aria-label={selectedAgent ? `已选择智能体:${triggerLabel}` : "选择智能体"}
|
||||
className={cn(
|
||||
"relative size-9 rounded-full text-muted-foreground shadow-none hover:bg-muted/60 hover:text-foreground",
|
||||
selectedAgent && "text-amber-600 hover:text-amber-700",
|
||||
selectedAgent && iconActiveClassName,
|
||||
iconButtonClassName,
|
||||
)}
|
||||
>
|
||||
<BotIcon className="size-4" />
|
||||
{selectedAgent && (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label="清除已选 agent"
|
||||
className="absolute -right-1 -top-1 inline-flex size-4 items-center justify-center rounded-full border bg-background text-foreground shadow-sm hover:bg-muted"
|
||||
onClick={handleClear}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onAgentChange(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<XIcon className="size-2.5" />
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
<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,
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user