Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat: 支持可编辑的用户上下文选择

whq6e790bf76471
diff --git a/jiuwenswarm/channels/web/frontend/package.json b/jiuwenswarm/channels/web/frontend/package.json
index c22e5ffcad..f171b6dafa 100644
--- a/jiuwenswarm/channels/web/frontend/package.json
+++ b/jiuwenswarm/channels/web/frontend/package.json
@@ -24,6 +24,7 @@
"test:web-http-client": "tsc src/services/webHttpClient.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/web-http-client --skipLibCheck --noEmitOnError && node --test tests/webHttpClient.test.mjs",
"test:runtime-scope": "tsc src/services/runtimeScope.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/runtime-scope --skipLibCheck --noEmitOnError && node --test tests/runtimeScope.test.mjs",
"test:user-web-entry": "esbuild src/EnterpriseEntry.tsx --bundle --packages=external --platform=node --format=esm --outfile=node_modules/.cache/user-web-entry/EnterpriseEntry.mjs --alias:virtual:login-auth-simulate-provider=./src/auth/simulate/available.ts --define:import.meta.env.VITE_USER_WEB_MODE='\"personal\"' --define:import.meta.env.VITE_ENABLE_USER_WEB_EMBEDDING='\"false\"' --define:import.meta.env.VITE_LOGIN_AUTH_SIMULATE='\"false\"' && esbuild src/auth/config.ts src/auth/simulate/SimulatedAuthProvider.ts --bundle --packages=external --platform=node --format=esm --outdir=node_modules/.cache/user-web-entry/auth && node --test tests/userWebEntry.test.mjs",
+ "test:editable-combobox": "tsc src/components/SessionSidebar/editableComboboxModel.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/editable-combobox --skipLibCheck --noEmitOnError && node --test tests/editableCombobox.test.mjs",
"test:a2a-ingress-panel": "tsc src/components/A2AIngressPanel/a2aIngressPanelState.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/a2a-ingress-panel-state --skipLibCheck --noEmitOnError && node --test tests/a2aIngressPanelState.test.mjs",
"test:chat-store-streaming": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/chatStoreStreaming.test.mjs",
"test:settle-historical-tool-executions": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/settleHistoricalToolExecutions.test.mjs",
diff --git a/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx b/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx
index a80f8e7244..cb08a1db76 100644
--- a/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/EnterpriseEntry.tsx
@@ -79,28 +79,69 @@ function entryPath(): string {
return window.location.pathname.startsWith('/chat') ? '/chat/' : '/';
}
-function contextUrl(userId: string, resolved: ResolvedContext): string {
+function contextUrl(userId: string, resolved: ResolvedContext, debugContext = false): string {
const query = new URLSearchParams({
user_id: userId,
group_id: resolved.org.group_id,
bot_id: resolved.selectedBot,
gateway_id: resolved.gateway.jiuwenclaw_id,
});
+ if (debugContext) query.set('debug_context', '1');
return `${entryPath()}?${query.toString()}`;
}
-function activateContext(userId: string, resolved: ResolvedContext, navigate: boolean): void {
+function activateContext(userId: string, resolved: ResolvedContext, navigate: boolean, debugContext = false): void {
setRuntimeScope({
userId,
groupId: resolved.org.group_id,
botId: resolved.selectedBot,
gatewayId: resolved.gateway.jiuwenclaw_id,
});
- const nextUrl = contextUrl(userId, resolved);
+ const nextUrl = contextUrl(userId, resolved, debugContext);
if (navigate) window.location.replace(nextUrl);
else window.history.replaceState({}, '', nextUrl);
}
+export function isDebugContext(search: string): boolean {
+ return new URLSearchParams(search).get('debug_context') === '1';
+}
+
+export function buildRequestedDebugContext(
+ orgs: EnterpriseOrg[],
+ gateways: EnterpriseGateway[],
+ agents: EnterpriseAgent[],
+ preferred: ReturnType<typeof parseRuntimeScope>,
+): ResolvedContext | null {
+ if (!preferred.groupId || !preferred.gatewayId || !preferred.botId) return null;
+ const org = orgs.find(item => item.group_id === preferred.groupId) ?? {
+ group_id: preferred.groupId,
+ name: preferred.groupId,
+ };
+ const gateway = gateways.find(item => item.jiuwenclaw_id === preferred.gatewayId) ?? {
+ jiuwenclaw_id: preferred.gatewayId,
+ jiuwenclaw_name: preferred.gatewayId,
+ gateway_endpoint: null,
+ };
+ return { org, gateway, agents, selectedBot: preferred.botId };
+}
+
+async function resolveRequestedDebugContext(
+ provider: EnterpriseAuthProvider,
+ orgs: EnterpriseOrg[],
+ gateways: EnterpriseGateway[],
+ preferred: ReturnType<typeof parseRuntimeScope>,
+): Promise<ResolvedContext | null> {
+ if (!preferred.groupId || !preferred.gatewayId || !preferred.botId) return null;
+ let agents: EnterpriseAgent[] = [];
+ try {
+ agents = await provider.listAgents(preferred.groupId, preferred.gatewayId);
+ } catch (error) {
+ if (error instanceof EnterpriseAuthError && error.status === 401) throw error;
+ // 自定义 ID 用于联调错误路由;列表查询失败不能覆盖手工输入的上下文。
+ }
+ return buildRequestedDebugContext(orgs, gateways, agents, preferred);
+}
+
function errorText(error: unknown): string {
return error instanceof Error && error.message ? error.message : '加载企业用户上下文失败';
}
@@ -162,11 +203,13 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {
provider.listOrganizations(),
provider.listGateways(),
]);
- const resolved = await resolveFirstContext(
- provider,
- orderedContextCandidates(gateways, orgs, preferred.gatewayId, preferred.groupId),
- preferred.botId,
- );
+ const resolved = isDebugContext(window.location.search)
+ ? await resolveRequestedDebugContext(provider, orgs, gateways, preferred)
+ : await resolveFirstContext(
+ provider,
+ orderedContextCandidates(gateways, orgs, preferred.gatewayId, preferred.groupId),
+ preferred.botId,
+ );
if (cancelled) return;
if (!resolved) {
setPhase('empty');
@@ -232,7 +275,17 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {
contextSwitching,
onOrgChange: orgId => {
const org = context.orgs.find(item => item.group_id === orgId);
- if (!org) return;
+ if (!org) {
+ const normalized = orgId.trim();
+ if (!normalized) return;
+ activateContext(
+ context.user.user_id,
+ { ...context, org: { group_id: normalized, name: normalized } },
+ true,
+ true,
+ );
+ return;
+ }
const gateways = movePreferredFirst([...context.gateways], item => item.jiuwenclaw_id === context.gateway.jiuwenclaw_id);
void switchContext(
gateways.map(gateway => ({ gateway, org })),
@@ -242,7 +295,24 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {
},
onGatewayChange: gatewayId => {
const gateway = context.gateways.find(item => item.jiuwenclaw_id === gatewayId);
- if (!gateway) return;
+ if (!gateway) {
+ const normalized = gatewayId.trim();
+ if (!normalized) return;
+ activateContext(
+ context.user.user_id,
+ {
+ ...context,
+ gateway: {
+ jiuwenclaw_id: normalized,
+ jiuwenclaw_name: normalized,
+ gateway_endpoint: null,
+ },
+ },
+ true,
+ true,
+ );
+ return;
+ }
const orgs = movePreferredFirst([...context.orgs], item => item.group_id === context.org.group_id);
void switchContext(
orgs.map(org => ({ gateway, org })),
@@ -252,7 +322,23 @@ export function EnterpriseEntry({ children }: { children: ReactNode }) {
},
onBotChange: botId => {
const selected = context.agents.find(agent => agentRuntimeId(agent) === botId);
- if (!selected || botId === context.selectedBot) return;
+ if (botId === context.selectedBot) return;
+ if (!selected) {
+ const normalized = botId.trim();
+ if (!normalized) return;
+ activateContext(
+ context.user.user_id,
+ {
+ gateway: context.gateway,
+ org: context.org,
+ agents: context.agents,
+ selectedBot: normalized,
+ },
+ true,
+ true,
+ );
+ return;
+ }
activateContext(
context.user.user_id,
{
diff --git a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/EditableCombobox.tsx b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/EditableCombobox.tsx
new file mode 100644
index 0000000000..30a811da35
--- /dev/null
+++ b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/EditableCombobox.tsx
@@ -0,0 +1,155 @@
+import { useEffect, useId, useMemo, useState, type FocusEvent, type KeyboardEvent } from 'react';
+import {
+ filterEditableComboboxOptions,
+ resolveEditableComboboxCommit,
+ type EditableComboboxOption,
+} from './editableComboboxModel';
+
+interface EditableComboboxProps {
+ ariaLabel: string;
+ disabled?: boolean;
+ emptyText?: string;
+ onChange: (value: string) => void;
+ options: EditableComboboxOption[];
+ value: string;
+}
+
+export function EditableCombobox({ ariaLabel, disabled = false, emptyText = '没有匹配项', onChange, options, value }: EditableComboboxProps) {
+ const listboxId = useId();
+ const selectedOption = options.find(option => option.value === value);
+ const selectedLabel = selectedOption?.label ?? value;
+ const [inputValue, setInputValue] = useState(selectedLabel);
+ const [open, setOpen] = useState(false);
+ const [activeIndex, setActiveIndex] = useState(0);
+ const filteredOptions = useMemo(() => filterEditableComboboxOptions(options, inputValue, selectedLabel), [inputValue, options, selectedLabel]);
+
+ useEffect(() => {
+ if (!open) setInputValue(selectedLabel);
+ }, [open, selectedLabel]);
+
+ useEffect(() => {
+ setActiveIndex(index => Math.min(index, Math.max(filteredOptions.length - 1, 0)));
+ }, [filteredOptions.length]);
+
+ const reset = () => {
+ setOpen(false);
+ setInputValue(selectedLabel);
+ setActiveIndex(0);
+ };
+
+ const commitInput = () => {
+ const committedValue = resolveEditableComboboxCommit(options, inputValue);
+ setOpen(false);
+ setActiveIndex(0);
+ if (!committedValue || committedValue === value) {
+ setInputValue(selectedLabel);
+ return;
+ }
+ const committedOption = options.find(option => option.value === committedValue);
+ setInputValue(committedOption?.label ?? committedValue);
+ onChange(committedValue);
+ };
+
+ const selectOption = (option: EditableComboboxOption) => {
+ setOpen(false);
+ setInputValue(option.label);
+ setActiveIndex(0);
+ if (option.value !== value) onChange(option.value);
+ };
+
+ const handleBlur = (event: FocusEvent<HTMLDivElement>) => {
+ if (!event.currentTarget.contains(event.relatedTarget as Node | null)) commitInput();
+ };
+
+ const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.key === 'ArrowDown') {
+ event.preventDefault();
+ setOpen(true);
+ setActiveIndex(index => Math.min(index + 1, Math.max(filteredOptions.length - 1, 0)));
+ return;
+ }
+ if (event.key === 'ArrowUp') {
+ event.preventDefault();
+ setOpen(true);
+ setActiveIndex(index => Math.max(index - 1, 0));
+ return;
+ }
+ if (event.key === 'Enter' && open) {
+ event.preventDefault();
+ if (filteredOptions.length > 0) selectOption(filteredOptions[activeIndex] ?? filteredOptions[0]);
+ else commitInput();
+ return;
+ }
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ reset();
+ }
+ };
+
+ return (
+ <div className={`editable-combobox${open ? ' editable-combobox--open' : ''}`} onBlur={handleBlur}>
+ <input
+ type="text"
+ role="combobox"
+ aria-label={ariaLabel}
+ aria-autocomplete="list"
+ aria-controls={listboxId}
+ aria-expanded={open}
+ aria-activedescendant={open && filteredOptions.length > 0 ? `${listboxId}-option-${activeIndex}` : undefined}
+ autoComplete="off"
+ disabled={disabled}
+ value={inputValue}
+ onChange={event => {
+ setInputValue(event.target.value);
+ setOpen(true);
+ setActiveIndex(0);
+ }}
+ onFocus={event => {
+ event.currentTarget.select();
+ setOpen(true);
+ setActiveIndex(0);
+ }}
+ onKeyDown={handleKeyDown}
+ />
+ <button
+ type="button"
+ className="editable-combobox__toggle"
+ aria-label={`${ariaLabel}选项`}
+ aria-expanded={open}
+ disabled={disabled}
+ onClick={() => {
+ setInputValue(selectedLabel);
+ setOpen(current => !current);
+ setActiveIndex(0);
+ }}
+ >
+ <svg viewBox="0 0 16 16" aria-hidden>
+ <path d="m4 6 4 4 4-4" />
+ </svg>
+ </button>
+ {open && !disabled && (
+ <div id={listboxId} className="editable-combobox__list" role="listbox">
+ {filteredOptions.length > 0 ? (
+ filteredOptions.map((option, index) => (
+ <button
+ id={`${listboxId}-option-${index}`}
+ key={option.value}
+ type="button"
+ role="option"
+ aria-selected={option.value === value}
+ className={`editable-combobox__option${index === activeIndex ? ' editable-combobox__option--active' : ''}`}
+ onMouseDown={event => event.preventDefault()}
+ onMouseEnter={() => setActiveIndex(index)}
+ onClick={() => selectOption(option)}
+ >
+ {option.label}
+ </button>
+ ))
+ ) : (
+ <div className="editable-combobox__empty">{emptyText}</div>
+ )}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/SessionSidebar.css b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/SessionSidebar.css
index 5fe674a5e4..8e50360d6e 100644
--- a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/SessionSidebar.css
+++ b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/SessionSidebar.css
@@ -340,14 +340,112 @@
.enterprise-context-popover__user { padding-bottom: 12px; margin-bottom: 10px; border-bottom: 1px solid var(--color-border-default); color: var(--color-text-primary); font-size: 13px; font-weight: 600; }
.enterprise-context-popover__user small { display: block; margin-top: 4px; color: var(--color-text-secondary); font-size: 11px; font-weight: 400; }
.enterprise-context-popover label { display: block; margin-top: 10px; color: var(--color-text-secondary); font-size: 11px; }
-.enterprise-context-popover select { display: block; box-sizing: border-box; width: 100%; margin-top: 5px; padding: 7px; border: 1px solid var(--color-border-default); border-radius: 6px; background: var(--color-surface-card); color: var(--color-text-primary); font-size: 12px; }
+.editable-combobox {
+ position: relative;
+ margin-top: 5px;
+}
+.editable-combobox input {
+ display: block;
+ box-sizing: border-box;
+ width: 100%;
+ height: 32px;
+ padding: 0 30px 0 9px;
+ border: 1px solid var(--color-border-default);
+ border-radius: 7px;
+ outline: none;
+ background: var(--color-surface-card);
+ color: var(--color-text-primary);
+ font-size: 12px;
+}
+.editable-combobox input:focus {
+ border-color: var(--color-action-primary);
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-action-primary) 16%, transparent);
+}
+.editable-combobox input:disabled {
+ cursor: wait;
+ opacity: 0.65;
+}
+.editable-combobox__toggle {
+ position: absolute;
+ top: 0;
+ right: 0;
+ display: grid;
+ width: 30px;
+ height: 32px;
+ padding: 0;
+ place-items: center;
+ border: 0;
+ background: transparent;
+ color: var(--color-text-secondary);
+ cursor: pointer;
+}
+.editable-combobox__toggle:disabled {
+ cursor: wait;
+ opacity: 0.65;
+}
+.editable-combobox__toggle svg {
+ width: 14px;
+ height: 14px;
+ fill: none;
+ stroke: currentColor;
+ stroke-linecap: round;
+ stroke-linejoin: round;
+ stroke-width: 1.5;
+ transition: transform 0.15s ease;
+}
+.editable-combobox--open .editable-combobox__toggle svg {
+ transform: rotate(180deg);
+}
+.editable-combobox__list {
+ position: absolute;
+ z-index: 1;
+ top: calc(100% + 4px);
+ right: 0;
+ left: 0;
+ max-height: 168px;
+ overflow-y: auto;
+ padding: 4px;
+ border: 1px solid var(--color-border-default);
+ border-radius: 7px;
+ background: var(--color-surface-popover);
+ box-shadow: var(--effect-shadow-lg);
+}
+.editable-combobox__option {
+ display: block;
+ width: 100%;
+ padding: 7px 8px;
+ overflow: hidden;
+ border: 0;
+ border-radius: 5px;
+ background: transparent;
+ color: var(--color-text-primary);
+ cursor: pointer;
+ font-size: 12px;
+ line-height: 1.35;
+ text-align: left;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.editable-combobox__option--active,
+.editable-combobox__option:hover {
+ background: var(--color-surface-hover);
+}
+.editable-combobox__option[aria-selected='true'] {
+ color: var(--color-action-primary);
+ font-weight: 600;
+}
+.editable-combobox__empty {
+ padding: 8px;
+ color: var(--color-text-secondary);
+ font-size: 11px;
+ text-align: center;
+}
/* 企业版用户面:与主侧栏统一的克制弹层样式。 */
.enterprise-context-popover { padding: 12px; border-radius: 12px; background: var(--color-surface-popover); box-shadow: var(--effect-shadow-lg); }
.enterprise-context-popover__user { margin: 0 2px 8px; padding: 4px 4px 10px; font-size: 13px; }
.enterprise-context-popover label { margin-top: 8px; font-size: 11px; }
-.enterprise-context-popover select { height: 32px; margin-top: 4px; padding: 0 28px 0 9px; appearance: auto; border-radius: 7px; background: var(--color-surface-card); font-size: 12px; }
-.enterprise-context-popover select:disabled { cursor: wait; opacity: .65; }
+.enterprise-context-popover .editable-combobox { margin-top: 4px; }
.enterprise-context-popover__status { margin-top: 10px; color: var(--color-text-secondary); font-size: 11px; }
.enterprise-context-popover__error { margin-top: 10px; color: var(--color-feedback-danger); font-size: 11px; line-height: 1.45; }
.enterprise-context-popover__logout { width: 100%; margin-top: 12px; padding: 8px 10px; border: 1px solid var(--color-border-default); border-radius: 7px; background: transparent; color: var(--color-feedback-danger); cursor: pointer; font-size: 12px; text-align: center; }
diff --git a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/editableComboboxModel.ts b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/editableComboboxModel.ts
new file mode 100644
index 0000000000..c6b1623148
--- /dev/null
+++ b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/editableComboboxModel.ts
@@ -0,0 +1,30 @@
+export interface EditableComboboxOption {
+ value: string;
+ label: string;
+}
+
+export function filterEditableComboboxOptions(options: EditableComboboxOption[], query: string, selectedLabel: string): EditableComboboxOption[] {
+ const normalizedQuery = query.trim().toLocaleLowerCase();
+ if (!normalizedQuery || normalizedQuery === selectedLabel.trim().toLocaleLowerCase()) {
+ return options;
+ }
+ return options.filter(option => {
+ const value = option.value.toLocaleLowerCase();
+ const label = option.label.toLocaleLowerCase();
+ return value.includes(normalizedQuery) || label.includes(normalizedQuery);
+ });
+}
+
+export function resolveEditableComboboxCommit(
+ options: EditableComboboxOption[],
+ input: string,
+): string | null {
+ const normalizedInput = input.trim();
+ if (!normalizedInput) return null;
+ const normalizedLookup = normalizedInput.toLocaleLowerCase();
+ const exactOption = options.find(option =>
+ option.value.trim().toLocaleLowerCase() === normalizedLookup
+ || option.label.trim().toLocaleLowerCase() === normalizedLookup
+ );
+ return exactOption?.value ?? normalizedInput;
+}
diff --git a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/index.tsx
index 8fa381c889..27886c591d 100644
--- a/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/index.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/components/SessionSidebar/index.tsx
@@ -22,6 +22,7 @@ import AgentDesignIcon from '../../assets/智能体.svg?react';
import MoreDesignIcon from '../../assets/更多.svg?react';
import { webRequest } from '../../services/webClient';
import { useEnterpriseContext } from '../../services/enterpriseContext';
+import { EditableCombobox } from './EditableCombobox';
type MainNavKey =
'chat' | 'skills' | 'agents' | 'teams' | 'sessions' | 'cron' | 'channels' | 'extensions' | 'configpanel' | 'browserpanel' | 'updatepanel' | 'a2aingress';
@@ -279,37 +280,36 @@ export function SessionSidebar({
</div>
<label>
组织(group_id)
- <select value={enterprise.org.group_id} disabled={enterprise.contextSwitching} onChange={event => enterprise.onOrgChange(event.target.value)}>
- {enterprise.orgs.map(item => (
- <option key={item.group_id} value={item.group_id}>
- {item.name} · {item.group_id}
- </option>
- ))}
- </select>
+ <EditableCombobox
+ ariaLabel="组织(group_id)"
+ value={enterprise.org.group_id}
+ disabled={enterprise.contextSwitching}
+ options={enterprise.orgs.map(item => ({ value: item.group_id, label: `${item.name} · ${item.group_id}` }))}
+ onChange={enterprise.onOrgChange}
+ />
</label>
<label>
组网(gateway_id)
- <select
+ <EditableCombobox
+ ariaLabel="组网(gateway_id)"
value={enterprise.gateway.jiuwenclaw_id}
disabled={enterprise.contextSwitching}
- onChange={event => enterprise.onGatewayChange(event.target.value)}
- >
- {enterprise.gateways.map(item => (
- <option key={item.jiuwenclaw_id} value={item.jiuwenclaw_id}>
- {item.jiuwenclaw_name} · {item.jiuwenclaw_id}
- </option>
- ))}
- </select>
+ options={enterprise.gateways.map(item => ({ value: item.jiuwenclaw_id, label: `${item.jiuwenclaw_name} · ${item.jiuwenclaw_id}` }))}
+ onChange={enterprise.onGatewayChange}
+ />
</label>
<label>
Agent(bot_id)
- <select value={enterprise.selectedBot} disabled={enterprise.contextSwitching} onChange={event => enterprise.onBotChange(event.target.value)}>
- {enterprise.agents.map(item => (
- <option key={item.resource_id || item.template_id} value={item.resource_id || item.template_id}>
- {item.template_name} · {item.resource_id || item.template_id}
- </option>
- ))}
- </select>
+ <EditableCombobox
+ ariaLabel="Agent(bot_id)"
+ value={enterprise.selectedBot}
+ disabled={enterprise.contextSwitching}
+ options={enterprise.agents.map(item => ({
+ value: item.resource_id || item.template_id,
+ label: `${item.template_name} · ${item.resource_id || item.template_id}`,
+ }))}
+ onChange={enterprise.onBotChange}
+ />
</label>
{enterprise.contextSwitching && <div className="enterprise-context-popover__status">正在切换...</div>}
{enterprise.contextError && <div className="enterprise-context-popover__error">{enterprise.contextError}</div>}
diff --git a/jiuwenswarm/channels/web/frontend/tests/editableCombobox.test.mjs b/jiuwenswarm/channels/web/frontend/tests/editableCombobox.test.mjs
new file mode 100644
index 0000000000..cbb9a3a999
--- /dev/null
+++ b/jiuwenswarm/channels/web/frontend/tests/editableCombobox.test.mjs
@@ -0,0 +1,30 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+
+const { filterEditableComboboxOptions, resolveEditableComboboxCommit } = await import(
+ '../node_modules/.cache/editable-combobox/components/SessionSidebar/editableComboboxModel.js'
+);
+
+const options = [
+ { value: 'group-alpha', label: '研发组织 · group-alpha' },
+ { value: 'group-beta', label: '测试组织 · group-beta' },
+];
+
+test('empty query and selected label both expose the complete authorized list', () => {
+ assert.deepEqual(filterEditableComboboxOptions(options, '', options[0].label), options);
+ assert.deepEqual(filterEditableComboboxOptions(options, options[0].label, options[0].label), options);
+});
+
+test('editable query filters by display name or identifier without changing the source list', () => {
+ assert.deepEqual(filterEditableComboboxOptions(options, '测试', options[0].label), [options[1]]);
+ assert.deepEqual(filterEditableComboboxOptions(options, 'ALPHA', options[0].label), [options[0]]);
+ assert.deepEqual(filterEditableComboboxOptions(options, 'missing', options[0].label), []);
+ assert.equal(options.length, 2);
+});
+
+test('commit resolves an exact option but preserves an unknown debug value', () => {
+ assert.equal(resolveEditableComboboxCommit(options, '测试组织 · group-beta'), 'group-beta');
+ assert.equal(resolveEditableComboboxCommit(options, 'GROUP-ALPHA'), 'group-alpha');
+ assert.equal(resolveEditableComboboxCommit(options, ' debug-group '), 'debug-group');
+ assert.equal(resolveEditableComboboxCommit(options, ' '), null);
+});
diff --git a/jiuwenswarm/channels/web/frontend/tests/userWebEntry.test.mjs b/jiuwenswarm/channels/web/frontend/tests/userWebEntry.test.mjs
index 1600ec3662..0509304cf8 100644
--- a/jiuwenswarm/channels/web/frontend/tests/userWebEntry.test.mjs
+++ b/jiuwenswarm/channels/web/frontend/tests/userWebEntry.test.mjs
@@ -21,7 +21,13 @@ globalThis.window = {
location: { pathname: '/', search: '', replace() {} },
};
-const { EnterpriseEntry, chooseAgent, orderedContextCandidates } = await import('../node_modules/.cache/user-web-entry/EnterpriseEntry.mjs');
+const {
+ EnterpriseEntry,
+ buildRequestedDebugContext,
+ chooseAgent,
+ isDebugContext,
+ orderedContextCandidates,
+} = await import('../node_modules/.cache/user-web-entry/EnterpriseEntry.mjs');
const { parseLoginAuthSimulate } = await import('../node_modules/.cache/user-web-entry/auth/config.js');
const { buildSimulatedEnterpriseContext } = await import('../node_modules/.cache/user-web-entry/auth/simulate/SimulatedAuthProvider.js');
@@ -124,3 +130,18 @@ test('agent selection accepts a still-authorized URL agent and otherwise falls b
assert.equal(chooseAgent(agents, 'removed-agent')?.resource_id, 'agent-1');
assert.equal(chooseAgent([], 'agent-2'), null);
});
+
+test('debug context preserves explicitly entered routing identifiers', () => {
+ const debugContext = buildRequestedDebugContext(
+ [{ group_id: 'group-1', name: 'Group 1' }],
+ [{ jiuwenclaw_id: 'gateway-1', jiuwenclaw_name: 'Gateway 1', gateway_endpoint: null }],
+ [],
+ { groupId: 'debug-group', gatewayId: 'debug-gateway', botId: 'debug-bot' },
+ );
+
+ assert.equal(isDebugContext('?debug_context=1'), true);
+ assert.equal(isDebugContext('?debug_context=0'), false);
+ assert.equal(debugContext?.org.group_id, 'debug-group');
+ assert.equal(debugContext?.gateway.jiuwenclaw_id, 'debug-gateway');
+ assert.equal(debugContext?.selectedBot, 'debug-bot');
+});