fix: align desktop chat with BoosAPI client flow

This commit is contained in:
boos
2026-06-29 12:27:27 +08:00
parent 2a5eca83c8
commit bdfb9b8dc2
7 changed files with 302 additions and 56 deletions
+1 -1
View File
@@ -532,7 +532,7 @@ export default function AgentWorkbench() {
const abortRef = useRef<AbortController | null>(null);
const fileInputRef = useRef<HTMLInputElement | null>(null);
const jimengPollersRef = useRef<Record<string, ReturnType<typeof setTimeout>>>({});
const jimengPollersRef = useRef<Record<string, number>>({});
const scrollRef = useRef<HTMLDivElement | null>(null);
const currentCreationMode = useMemo(
() => CREATION_MODES.find((item) => item.value === creationMode) ?? CREATION_MODES[0],
+50
View File
@@ -340,6 +340,54 @@ function DownstreamKeyCopyIconButton({ fullKey }: { fullKey: string | undefined
);
}
function buildBoosApiDesktopImportUrl(fullKey: string): string {
const params = new URLSearchParams({
name: 'BoosAPI',
baseurl: window.location.origin,
apikey: fullKey,
type: 'openai',
});
return `boosapi://providers?${params.toString()}`;
}
function DownstreamKeyDesktopImportButton({ fullKey }: { fullKey: string | undefined }) {
const toast = useToast();
const disabled = !fullKey?.trim();
return (
<button
type="button"
className="btn btn-link"
title="导入到 BoosAPI Desktop"
aria-label="导入到 BoosAPI Desktop"
disabled={disabled}
style={{ padding: '2px 4px', fontSize: 12, opacity: disabled ? 0.45 : 1 }}
onClick={async (event) => {
event.stopPropagation();
const key = fullKey?.trim();
if (!key) {
toast.info('完整密钥暂不可用,请刷新页面后重试');
return;
}
const url = buildBoosApiDesktopImportUrl(key);
try {
window.location.href = url;
toast.success('已唤起 BoosAPI Desktop 导入配置');
} catch {
try {
await copyToClipboard(url);
toast.info('无法唤起 Desktop,已复制导入链接');
} catch {
toast.error('导入链接生成失败');
}
}
}}
>
导入 Desktop
</button>
);
}
function buildEditorForm(
item?: ManagedItem | DownstreamApiKeyItem | null,
routeOptions: RouteSelectorItem[] = [],
@@ -1223,6 +1271,7 @@ export default function DownstreamKeys() {
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
<span style={{ fontFamily: 'var(--font-mono)', fontSize: 12, color: 'var(--color-text-muted)' }}>{row.keyMasked}</span>
<DownstreamKeyCopyIconButton fullKey={row.key} />
<DownstreamKeyDesktopImportButton fullKey={row.key} />
</span>
)}
stacked
@@ -1292,6 +1341,7 @@ export default function DownstreamKeys() {
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', marginBottom: 4 }}>
<span style={{ fontFamily: 'var(--font-mono)', fontSize: 12, color: 'var(--color-text-muted)' }}>{row.keyMasked}</span>
<DownstreamKeyCopyIconButton fullKey={row.key} />
<DownstreamKeyDesktopImportButton fullKey={row.key} />
</div>
{row.description ? <div style={{ fontSize: 12, color: 'var(--color-text-secondary)', maxWidth: 320 }}>{row.description}</div> : null}
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 8 }}>