mirror of
https://github.com/iflytek/skillhub.git
synced 2026-12-03 00:47:22 +00:00
* feat(dsh): connect registry accounts and manage namespace skills and members Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): use the patched ZIP reader for skill packages Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): bind owned skill actions to the published version ID Signed-off-by: dongmucat <1127093059@qq.com> * fix(auth): handle context-prefixed registry requests consistently Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): address account isolation and upload review findings Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): recover changed upload targets and clear private detail caches Signed-off-by: dongmucat <1127093059@qq.com> * refactor(dsh): keep registry authentication inside the plugin Signed-off-by: dongmucat <1127093059@qq.com> * test(dsh): canonicalize temporary profile roots across platforms Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): clear expired accounts during detail reads Signed-off-by: dongmucat <1127093059@qq.com> * fix(auth): include DSH permissions in default personal tokens Signed-off-by: dongmucat <1127093059@qq.com> * fix(web): refresh token form analytics manifest Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): organize account dialogs and preserve modal focus Signed-off-by: dongmucat <1127093059@qq.com> * fix(ci): pin DSH browser checks to supported Ubuntu Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): unify workbench appearance and source navigation Signed-off-by: dongmucat <1127093059@qq.com> * test(dsh): wait for runtime readiness before availability install Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): align namespace pages with the account prototype Signed-off-by: dongmucat <1127093059@qq.com> * test(dsh): use monotonic clocks for fixture deadlines Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): expose namespace member management actions Add a direct member-management entry, explain disabled role and state restrictions, and preserve keyboard focus after membership changes. Exercise add, role change and removal through the real account components. Signed-off-by: dongmucat <1127093059@qq.com> * feat(dsh): support drag and drop skill uploads Use one validated file selection flow for dropping and browsing ZIPs. Show selected file details, protect in-flight uploads and confirmation revisions, and cover keyboard, busy and invalid-file behavior in Chromium. Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): right-align the catalog upload action Signed-off-by: dongmucat <1127093059@qq.com> * feat(dsh): persist Windows account credentials securely Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): remove saved accounts reliably on Windows Unicode paths Signed-off-by: dongmucat <1127093059@qq.com> * test(organizations): isolate committed portal fixtures Signed-off-by: dongmucat <1127093059@qq.com> * fix(auth): preserve token lifecycle state during usage updates Signed-off-by: dongmucat <1127093059@qq.com> * fix(skills): enforce caller-aware deletion across CLI endpoints Signed-off-by: dongmucat <1127093059@qq.com> * fix(dsh): submit account writes once and refresh registry views Signed-off-by: dongmucat <1127093059@qq.com> * chore(db): reserve unpublished token migration after upstream V128 Signed-off-by: dongmucat <1127093059@qq.com> --------- Signed-off-by: dongmucat <1127093059@qq.com>
129 lines
9.3 KiB
TypeScript
129 lines
9.3 KiB
TypeScript
import { useState, useSyncExternalStore } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { createPortal } from 'react-dom';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { AccountWorkspace, type AccountPageName } from '../../src/client/account-workspace.js';
|
|
import type { AccountRemote } from '../../src/client/account-common.js';
|
|
import { NativeControlStyles } from '../../src/client/native-control-styles.js';
|
|
import { AppearanceToggle } from '../../src/client/appearance-toggle.js';
|
|
import { ConfigPage } from '../../src/client/config-page.js';
|
|
import { Button } from '../../src/client/ui.js';
|
|
import type { ConfigForm, ConfigFormSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
import type { SkillHubConfig } from '../../src/host/types.js';
|
|
import type { AccountMember, MemberMutation, Visibility } from '../../src/host/account-types.js';
|
|
|
|
// Isolated UI fixture: no real service, credentials, or filesystem writes.
|
|
let identity: { handle: string; displayName: string } | null = null;
|
|
let uploadsEmpty = false;
|
|
let finishUpload: ((published: boolean) => void) | undefined;
|
|
let uploadedPatch = 0;
|
|
let publishedPatch = 0;
|
|
const writes = { upload: 0, add: 0, role: 0, remove: 0, delete: 0 };
|
|
function startWrite(action: keyof typeof writes) {
|
|
writes[action]++;
|
|
if (!navigator.onLine) throw new TypeError('Fixture Registry offline');
|
|
}
|
|
let pauseInspection = false;
|
|
let finishInspection: (() => void) | undefined;
|
|
Object.assign(globalThis, {
|
|
finishAccountUpload: (published = false) => finishUpload?.(published),
|
|
publishAccountVersion: () => { publishedPatch = uploadedPatch; },
|
|
accountWriteCounts: () => ({ ...writes }),
|
|
pauseNextAccountInspection: () => { pauseInspection = true; },
|
|
isAccountInspectionPaused: () => !!finishInspection,
|
|
finishAccountInspection: () => { const finish = finishInspection; finishInspection = undefined; finish?.(); },
|
|
});
|
|
const designMembers: AccountMember[] = [
|
|
{ userId: 'usr_11111111-2222-4333-8444-555555555555', displayName: '空间所有者', role: 'OWNER' },
|
|
{ userId: 'fixture-user', displayName: '演示用户', role: 'ADMIN' },
|
|
{ userId: 'usr_66666666-7777-4888-9999-aaaaaaaaaaaa', displayName: '团队成员', role: 'MEMBER' },
|
|
];
|
|
const spaces = [{ id: 1, slug: 'design', displayName: '设计团队', type: 'TEAM', status: 'ACTIVE', currentUserRole: 'ADMIN' },
|
|
...Array.from({ length: 11 }, (_, i) => ({ id: i + 2, slug: `team-${i + 2}`, displayName: `团队 ${i + 2}`, type: 'TEAM', status: 'ACTIVE', currentUserRole: 'MEMBER' })),
|
|
{ id: 13, slug: 'e2e-dsh-api-archived-fixture', displayName: 'DSH ownership retest · 示例归档空间', type: 'TEAM', status: 'ARCHIVED', currentUserRole: 'MEMBER' },
|
|
{ id: 14, slug: 'global', displayName: '全局空间', type: 'GLOBAL', status: 'ACTIVE', currentUserRole: 'MEMBER' },
|
|
{ id: 15, slug: 'frozen-team', displayName: '冻结团队', type: 'TEAM', status: 'FROZEN', currentUserRole: 'ADMIN' },
|
|
{ id: 16, slug: 'catalog', displayName: '目录空间', type: 'CATALOG', status: 'ACTIVE', currentUserRole: 'ADMIN' }];
|
|
const api = {
|
|
accountIdentity: () => identity,
|
|
connectAccount: async (_revision: string, token: string) => {
|
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
if (token !== 'fixture-token') throw new Error('Token 无效,请重新输入。');
|
|
identity = { handle: 'fixture-user', displayName: '演示用户' };
|
|
return identity;
|
|
},
|
|
disconnectAccount: () => { identity = null; return true; },
|
|
accountNamespaces: async () => { await new Promise(resolve => setTimeout(resolve, 200)); return spaces; },
|
|
accountOwned: (_revision: string, ns: string) => ns === 'global' || ns === 'design' && uploadsEmpty ? { items: [], total: 0 } : ({ items: [{ id: 1, slug: 'example', displayName: '示例技能', visibility: 'PRIVATE', status: 'ACTIVE' }], total: 1 }),
|
|
accountTeam: () => ({ items: [{ namespace: 'design', slug: 'example', version: `1.0.${publishedPatch}`, versionId: publishedPatch + 1 }], nextCursor: null }),
|
|
accountMembers: (_revision: string, ns: string) => ns === 'design' ? { items: [...designMembers], total: designMembers.length }
|
|
: { items: [{ userId: 'usr_11111111-2222-4333-8444-555555555555', displayName: '空间所有者', role: 'OWNER' }, { userId: 'fixture-user', displayName: '演示用户', role: ns === 'frozen-team' ? 'ADMIN' : 'MEMBER' }], total: 2 },
|
|
accountCandidates: () => [{ userId: 'candidate', displayName: '候选用户', email: 'candidate@example.test' }],
|
|
changeAccountMember: async (_revision: string, ns: string, command: MemberMutation) => {
|
|
startWrite(command.action);
|
|
if (ns !== 'design') throw new Error('Read-only fixture namespace');
|
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
if (command.action === 'add') designMembers.push({ userId: command.userId, displayName: '候选用户', role: command.role });
|
|
else {
|
|
const index = designMembers.findIndex(member => member.userId === command.userId);
|
|
if (index < 0 || designMembers[index]!.role === 'OWNER') throw new Error('Invalid fixture member');
|
|
if (command.action === 'remove') designMembers.splice(index, 1);
|
|
else designMembers[index] = { ...designMembers[index]!, role: command.role };
|
|
}
|
|
return true;
|
|
},
|
|
deleteAccountSkill: async () => {
|
|
startWrite('delete');
|
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
uploadsEmpty = true;
|
|
return true;
|
|
},
|
|
inspectUpload: async () => {
|
|
if (pauseInspection) { pauseInspection = false; await new Promise<void>(resolve => { finishInspection = resolve; }); }
|
|
return { slug: 'example', existing: null };
|
|
},
|
|
publishUpload: async (_revision: string, namespace: string, _archive: string, visibility: Visibility) => {
|
|
startWrite('upload');
|
|
const published = await new Promise<boolean>(resolve => { finishUpload = resolve; });
|
|
uploadedPatch++;
|
|
if (published) publishedPatch = uploadedPatch;
|
|
return { namespace, slug: 'example', version: `1.0.${uploadedPatch}`, visibility };
|
|
},
|
|
uploadStatus: () => ({ status: publishedPatch === uploadedPatch ? 'PUBLISHED' : 'UPLOADED' }),
|
|
};
|
|
const remote = Object.fromEntries(Object.entries(api).map(([name, fn]) => [name, async (...args: unknown[]) => {
|
|
try { return { ok: true, value: await Reflect.apply(fn, null, args) }; }
|
|
catch (error) {
|
|
if (error instanceof TypeError) return { ok: false, error: { code: 'skillhub/registry-error', details: { reason: 'NETWORK_ERROR' } } };
|
|
return { ok: false, error: { code: 'AUTH_REQUIRED', message: 'Token 无效,请重新输入。' } }; }
|
|
}])) as unknown as AccountRemote;
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
let snapshot: ConfigFormSnapshot<SkillHubConfig> = { status: 'ready', revision: 1, writable: true, base: {}, user: {},
|
|
value: { registryUrl: 'https://registry.example.test', savedRegistries: [{ name: '演示来源', url: 'https://registry.example.test' }, { name: '另一来源', url: 'https://other.example.test' }], detailTabs: { versions: 'auto', securityAudit: 'hide', reviews: 'auto' } } };
|
|
const listeners = new Set<() => void>();
|
|
const config: ConfigForm<SkillHubConfig> = {
|
|
getSnapshot: () => snapshot,
|
|
subscribe: listener => { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
mutate: async ops => {
|
|
const url = ops.find(op => op.op === 'set' && op.path[0] === 'registryUrl');
|
|
if (url?.op !== 'set' || typeof url.value !== 'string') return false;
|
|
if (snapshot.value?.registryUrl !== url.value) identity = null;
|
|
snapshot = { ...snapshot, revision: snapshot.revision! + 1, value: { ...snapshot.value!, registryUrl: url.value } };
|
|
listeners.forEach(listener => listener()); return true;
|
|
}, set: async () => false, unset: async () => false,
|
|
};
|
|
function Fixture() {
|
|
const [toolbar, setToolbar] = useState<HTMLDivElement | null>(null);
|
|
const [primary, setPrimary] = useState<HTMLDivElement | null>(null);
|
|
const [screen, navigate] = useState<AccountPageName>(null);
|
|
const [settings, showSettings] = useState(false);
|
|
const source = useSyncExternalStore(config.subscribe, config.getSnapshot);
|
|
if (settings) return <><Button onClick={() => showSettings(false)}>返回技能中心</Button><ConfigPage form={config} testConnection={async () => ({ ok: true, value: { reachable: true, mode: 'paged', elapsedMs: 1 } })} /></>;
|
|
return <section className="skillhub-controls astron-sh-catalog">
|
|
<NativeControlStyles /><header><AppearanceToggle /><div ref={setToolbar} /><div ref={setPrimary} /></header>
|
|
<AccountWorkspace key={source.revision} remote={remote} revision={`fixture-${source.revision}`} source={source.value!.registryUrl} toolbar={toolbar} primary={primary} screen={screen} navigate={navigate} settings={() => showSettings(true)} open={() => {}} />
|
|
{createPortal(<aside className="skillhub-controls astron-sh-management-notice" style={{ top: 'auto', bottom: 0, pointerEvents: 'none' }} aria-label="主题测试通知">界面测试通知</aside>, document.body)}
|
|
{createPortal(<aside aria-label="宿主会话" style={{ position: 'fixed', bottom: 0, left: 0, pointerEvents: 'none', background: 'light-dark(#fff,#101010)' }}><div className="skillhub-controls"><p>会话内搜索状态</p></div></aside>, document.body)}
|
|
</section>;
|
|
}
|
|
createRoot(document.getElementById('root')!).render(<QueryClientProvider client={client}><Fixture /></QueryClientProvider>);
|