Merge branch 'feat/mcp-tool-loading' into feat/notion-plugin
This commit is contained in:
commit
37a0630893
9 files changed
+111
-69
No files matched your search
@@ -21,8 +21,8 @@
|
||||
en: e618281ea7721daf
|
||||
zh: a5d5f5e307ea3435
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/present-the-section:
|
||||
en: f2bb2f05e2e122a4
|
||||
zh: f3dc9945b3f30736
|
||||
en: fcbc46fc932ed5c8
|
||||
zh: 2f1cce21453bced6
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/following-operations:
|
||||
en: 0f6140d7ed6427b9
|
||||
zh: feadef500ee4fd98
|
||||
@@ -30,8 +30,8 @@
|
||||
en: 353a48db7e7dd0f7
|
||||
zh: 653f3d983d3fd572
|
||||
/deepseek-ai-dsh-client-ui-connector-account/understand-the-implementation:
|
||||
en: 890bd2109a5b5c4f
|
||||
zh: f4373b71cb4f2018
|
||||
en: 8c16bb36ce00d4cc
|
||||
zh: d52d2a6f2beacf21
|
||||
/deepseek-ai-dsh-client-ui-connector-account/further-exploration:
|
||||
en: 029949903a73d283
|
||||
zh: 6f9a8c2f7620de69
|
||||
|
||||
@@ -61,9 +61,9 @@ The registrant imports the registry's types with `import type` from the package
|
||||
|
||||
| Surface | Behavior |
|
||||
|---|---|
|
||||
| Section | Title, status, buttons, detail, notes, failure, and hint. Buttons are disabled while a call the section made is pending or the Host stream is down. A failure shows the registrant's text, then its diagnostic items |
|
||||
| Section | Title, status, buttons, detail, notes, failure, and hint. Buttons, including a confirmation's, are disabled while a call the section made is pending or the Host stream is down. A failure shows the registrant's text, then its diagnostic items |
|
||||
| Title tag | The display's `badge`, shown only on the enabled bundle's page or one of its row pages, and only while the display has one |
|
||||
| Activation prompt | Open while the phase is `disconnected` after the bundle is switched on; Connect opens the bundle page and starts the display's `connect` operation, if it names one. It waits while the account is checking or connecting and dismisses itself once the account is connected or unavailable |
|
||||
| Activation prompt | Open while the phase is `disconnected` after the bundle is switched on; Connect opens the bundle page and starts the display's `connect` operation, if it names one, and is disabled while the Host stream is down. It waits while the account is checking or connecting and dismisses itself once the account is connected or unavailable |
|
||||
| Notice | The latest outcome in this browser, outside the Plugins panel's lifetime: the operation's success text, or the shared failure copy with a warning icon |
|
||||
|
||||
### Following operations
|
||||
@@ -84,7 +84,7 @@ The `connectorAccount` dictionary holds the copy every account shares: Close, Ca
|
||||
|
||||
The Host half, `ConnectorAccounts`, is a Remote service. `register()` observes the account's source, and each `watch` stream reads every account's entry after each change, coalescing changes that arrive before the next read: the key and package, the copy, `present(view)`, the operation in progress, and the latest result with its success text. `start` and `cancel` route by key to the account's source.
|
||||
|
||||
[`dsh-api-remotes`](../../api/remotes/README.md) mounts the generated `connectorAccounts` Remote. The browser half opens one `watch` stream through `BrowserAccounts`, whose one store holds the Host's accounts by key, whether the stream is delivering, and the latest notice; it also remembers the operations this browser started. It registers one `plugins.detail.badge` entry and one `shell.overlay` notice for the page, and for each account with a package, `plugins.bundle.config` and `plugins.bundle.activation` keyed by the package name, all under the `connectorAccount` namespace. The buttons call `start` and `cancel` on the Remote themselves and report the started operation to `BrowserAccounts`. An account the Host drops loses its bundle entries, and unloading withdraws every entry and the stream.
|
||||
[`dsh-api-remotes`](../../api/remotes/README.md) mounts the generated `connectorAccounts` Remote. The browser half opens one `watch` stream through `BrowserAccounts`, whose one store holds the Host's accounts by key, whether the stream is delivering, and the latest notice; it also remembers the operations this browser started. It registers one `plugins.detail.badge` entry and one `shell.overlay` notice for the page, and for each account with a package, `plugins.bundle.config` and `plugins.bundle.activation` keyed by the package name, all under the `connectorAccount` namespace. The surfaces receive `start` and `cancel` callbacks that call the Remote and reject when the Host refuses or the call does not answer; the buttons await them and report the started operation to `BrowserAccounts`. An account the Host drops loses its bundle entries, and unloading withdraws every entry and the stream.
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
|
||||
@@ -61,9 +61,9 @@ export function apply(ctx: Context): void {
|
||||
|
||||
| 界面 | 行为 |
|
||||
|---|---|
|
||||
| 区块 | 标题、状态、按钮、说明、附加行、失败信息和提示。区块发起的调用未返回,或 Host 流中断时,按钮不可用。失败时先显示注册方的文案,再显示其诊断项 |
|
||||
| 区块 | 标题、状态、按钮、说明、附加行、失败信息和提示。区块发起的调用未返回,或 Host 流中断时,按钮(包括确认框的按钮)不可用。失败时先显示注册方的文案,再显示其诊断项 |
|
||||
| 标题旁标签 | 显示 display 的 `badge`,只出现在已启用插件包的页面或其某一行的页面上,且只在 display 带有标签时显示 |
|
||||
| 开启引导 | 插件包开启后,阶段为 `disconnected` 时打开;“连接”会打开插件包页面,并在 display 给出 `connect` 时启动该操作。账号检查中或连接中时继续等待,已连接或不可用时自动关闭 |
|
||||
| 开启引导 | 插件包开启后,阶段为 `disconnected` 时打开;“连接”会打开插件包页面,并在 display 给出 `connect` 时启动该操作;Host 流中断时它不可用。账号检查中或连接中时继续等待,已连接或不可用时自动关闭 |
|
||||
| 提示 | 本浏览器的最新结果,不受插件面板生命周期限制:操作成功的文本,或带警告图标的共用失败文案 |
|
||||
|
||||
### 跟随操作
|
||||
@@ -84,7 +84,7 @@ export function apply(ctx: Context): void {
|
||||
|
||||
Host 一半 `ConnectorAccounts` 是一个 Remote 服务。`register()` 观察账号来源,每条 `watch` 流在每次变化后读取每个账号的条目,并合并在下一次读取前到达的变化:键和包、文案、`present(view)`、进行中的操作,以及带成功文本的最新结果。`start` 和 `cancel` 按键路由到该账号的来源。
|
||||
|
||||
[`dsh-api-remotes`](../../api/remotes/README.zh.md) 挂载生成的 `connectorAccounts` Remote。浏览器一半通过 `BrowserAccounts` 打开一条 `watch` 流;它的一个 store 保存按键索引的 Host 账号、流是否在推送,以及最新提示,同时记住本浏览器发起的操作。它为页面注册一个 `plugins.detail.badge` 条目和一个 `shell.overlay` 提示,并为每个带包名的账号注册以包名为键的 `plugins.bundle.config` 和 `plugins.bundle.activation`,全部使用 `connectorAccount` 命名空间。按钮自己调用 Remote 的 `start` 和 `cancel`,并把启动的操作报告给 `BrowserAccounts`。Host 撤下的账号会失去其插件包条目;卸载时撤下所有条目和流。
|
||||
[`dsh-api-remotes`](../../api/remotes/README.zh.md) 挂载生成的 `connectorAccounts` Remote。浏览器一半通过 `BrowserAccounts` 打开一条 `watch` 流;它的一个 store 保存按键索引的 Host 账号、流是否在推送,以及最新提示,同时记住本浏览器发起的操作。它为页面注册一个 `plugins.detail.badge` 条目和一个 `shell.overlay` 提示,并为每个带包名的账号注册以包名为键的 `plugins.bundle.config` 和 `plugins.bundle.activation`,全部使用 `connectorAccount` 命名空间。各界面收到 `start` 和 `cancel` 两个回调:它们调用 Remote,在 Host 拒绝或调用没有回应时 reject;按钮等待回调结果,并把启动的操作报告给 `BrowserAccounts`。Host 撤下的账号会失去其插件包条目;卸载时撤下所有条目和流。
|
||||
|
||||
| 文件 | 职责 |
|
||||
|---|---|
|
||||
|
||||
@@ -13,12 +13,16 @@
|
||||
|
||||
.status {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.label {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
@@ -26,6 +30,7 @@
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* The account surfaces the Plugins page shows for registered connector accounts: a bundle's section with the
|
||||
* confirmation a button asks for, the title tag, the activation prompt, and the notice. Each is the slot entry that reads
|
||||
* this browser's state and calls the Remote.
|
||||
* this browser's state and calls the Host through the injected callbacks.
|
||||
*/
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import { Button, IconWarningOutlineRegular, Modal, StateDot, Tag, Toast, type StateDotState, type TagTone } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { InjectFace, PropsRuntime, Translate } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { assertNever } from '@deepseek-ai/dsh-util-values'
|
||||
import type { ConnectorAccountButton, ConnectorAccountCommand, ConnectorAccountEntry, ConnectorAccountPhase } from '../types.ts'
|
||||
import css from './ConnectorAccount.module.css'
|
||||
@@ -26,21 +25,21 @@ const BADGE_TONE: Record<ConnectorAccountPhase, TagTone> = {
|
||||
checking: 'outline', connecting: 'info', connected: 'success', disconnected: 'outline', unavailable: 'warning',
|
||||
}
|
||||
|
||||
async function settle<T>(call: Promise<RemoteResult<T>>): Promise<T> {
|
||||
const result = await call
|
||||
if (!result.ok) throw new Error(result.error.message)
|
||||
return result.value
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a button's command against the Host: start and cancel call the Remote directly, and open shows the operation's
|
||||
* authorization page again in this browser.
|
||||
* @param face - the Remote and the browser state the commands report to.
|
||||
* @returns whether a call this surface made has not answered, and the runner of one account's command.
|
||||
* Run a button's command against the Host: start and cancel call the face's callbacks, and open shows the
|
||||
* operation's authorization page again in this browser.
|
||||
* @param face - the Host callbacks and the browser state the commands read and report to.
|
||||
* @returns whether a call this surface made has not answered, whether the Host stream is delivering, and the runner of
|
||||
* one account's command.
|
||||
*/
|
||||
function useAccountCommand(
|
||||
face: Pick<FaceProps, 'remote' | 'follow' | 'failed'>,
|
||||
): { readonly busy: boolean; readonly run: (entry: ConnectorAccountEntry, command: ConnectorAccountCommand) => void } {
|
||||
face: Pick<FaceProps, 'useConnectorAccounts' | 'start' | 'cancel' | 'follow' | 'failed'>,
|
||||
): {
|
||||
readonly busy: boolean
|
||||
readonly linked: boolean
|
||||
readonly run: (entry: ConnectorAccountEntry, command: ConnectorAccountCommand) => void
|
||||
} {
|
||||
const linked = face.useConnectorAccounts(state => state.linked)
|
||||
const [busy, setBusy] = useState(false)
|
||||
// A second click before the re-render still finds the first call pending.
|
||||
const pending = useRef(false)
|
||||
@@ -55,11 +54,11 @@ function useAccountCommand(
|
||||
const { key } = entry
|
||||
switch (command.kind) {
|
||||
case 'start':
|
||||
call(async () => { face.follow(key, await settle(face.remote.start(key, command.operation))) })
|
||||
call(async () => { face.follow(key, await face.start(key, command.operation)) })
|
||||
return
|
||||
case 'cancel': {
|
||||
const operation = entry.operation
|
||||
if (operation !== undefined) call(async () => { await settle(face.remote.cancel(key, operation.id)) })
|
||||
if (operation !== undefined) call(async () => { await face.cancel(key, operation.id) })
|
||||
return
|
||||
}
|
||||
case 'open':
|
||||
@@ -69,7 +68,7 @@ function useAccountCommand(
|
||||
default: assertNever(command)
|
||||
}
|
||||
}
|
||||
return { busy, run }
|
||||
return { busy, linked, run }
|
||||
}
|
||||
|
||||
/** Ask before an action that changes the account outside DSH; the dialog closes before it confirms. */
|
||||
@@ -78,15 +77,16 @@ function Confirm(props: {
|
||||
readonly title: string
|
||||
readonly body: string
|
||||
readonly label: string
|
||||
readonly disabled: boolean
|
||||
readonly onClose: () => void
|
||||
readonly onConfirm: () => void
|
||||
}): ReactNode {
|
||||
const { t, title, body, label, onClose, onConfirm } = props
|
||||
const { t, title, body, label, disabled, onClose, onConfirm } = props
|
||||
return (
|
||||
<Modal open title={title} closeLabel={t('close')} onClose={onClose}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={onClose}>{t('action.cancel')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={() => { onClose(); onConfirm() }}>{label}</Button>
|
||||
<Button variant="primary" data-modal-autofocus disabled={disabled} onClick={() => { onClose(); onConfirm() }}>{label}</Button>
|
||||
</>}>
|
||||
<p>{body}</p>
|
||||
</Modal>
|
||||
@@ -102,15 +102,15 @@ function Confirm(props: {
|
||||
export function ConnectorAccountSectionEntry(props: BundleFaceProps): ReactNode {
|
||||
const { useConnectorAccounts, account, resolveText, t } = props
|
||||
const entry = useConnectorAccounts(state => state.accounts.get(account))
|
||||
const linked = useConnectorAccounts(state => state.linked)
|
||||
const { busy, run } = useAccountCommand(props)
|
||||
const { busy, linked, run } = useAccountCommand(props)
|
||||
const disabled = busy || !linked
|
||||
const [confirming, setConfirming] = useState<ConnectorAccountButton>()
|
||||
if (entry === undefined) return null
|
||||
const { display } = entry
|
||||
const button = (item: ConnectorAccountButton): ReactNode => {
|
||||
const label = resolveText(item.label)
|
||||
const onClick = item.confirm === undefined ? () => { run(entry, item.command) } : () => { setConfirming(item) }
|
||||
return <Button key={label} variant={item.variant ?? 'outline'} size="sm" disabled={busy || !linked} onClick={onClick}>{label}</Button>
|
||||
return <Button key={label} variant={item.variant ?? 'outline'} size="sm" disabled={disabled} onClick={onClick}>{label}</Button>
|
||||
}
|
||||
const details = display.failure?.details ?? []
|
||||
const confirm = confirming?.confirm
|
||||
@@ -141,7 +141,7 @@ export function ConnectorAccountSectionEntry(props: BundleFaceProps): ReactNode
|
||||
<p className={css.hint}>{resolveText(entry.copy.hint)}</p>
|
||||
{confirming === undefined || confirm === undefined ? null : (
|
||||
<Confirm t={t} title={resolveText(confirm.title)} body={resolveText(confirm.body)} label={resolveText(confirm.label)}
|
||||
onClose={() => { setConfirming(undefined) }} onConfirm={() => { run(entry, confirming.command) }} />
|
||||
disabled={disabled} onClose={() => { setConfirming(undefined) }} onConfirm={() => { run(entry, confirming.command) }} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
@@ -178,7 +178,7 @@ export function ConnectorAccountActivationEntry(
|
||||
): ReactNode {
|
||||
const { useConnectorAccounts, account, resolveText, onDismiss, onOpenDetails, t } = props
|
||||
const entry = useConnectorAccounts(state => state.accounts.get(account))
|
||||
const { run } = useAccountCommand(props)
|
||||
const { linked, run } = useAccountCommand(props)
|
||||
const phase = entry?.display.phase
|
||||
useEffect(() => {
|
||||
if (phase === 'connected' || phase === 'unavailable') onDismiss()
|
||||
@@ -194,7 +194,7 @@ export function ConnectorAccountActivationEntry(
|
||||
<Modal open={phase === 'disconnected'} title={resolveText(activation.title)} closeLabel={t('close')} onClose={onDismiss}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={onDismiss}>{t('activation.later')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={onConnect}>{resolveText(activation.connect)}</Button>
|
||||
<Button variant="primary" data-modal-autofocus disabled={!linked} onClick={onConnect}>{resolveText(activation.connect)}</Button>
|
||||
</>}>
|
||||
<p>{resolveText(activation.body)}</p>
|
||||
</Modal>
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {} from '@deepseek-ai/dsh-client-locale/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-layout/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import {
|
||||
ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSectionEntry, ConnectorAccountToastEntry,
|
||||
} from './components.tsx'
|
||||
@@ -25,6 +26,13 @@ export type {
|
||||
/** The `connectorAccounts` Remote that `dsh-api-remotes` mounts, and the services the slot registrations need. */
|
||||
export const inject = ['remote', 'remote.connectorAccounts', 'slots', 'locale']
|
||||
|
||||
/** The value of a Remote call, or a rejection with the Host's message when the Host refused it. */
|
||||
async function settle<T>(call: Promise<RemoteResult<T>>): Promise<T> {
|
||||
const result = await call
|
||||
if (!result.ok) throw new Error(result.error.message)
|
||||
return result.value
|
||||
}
|
||||
|
||||
function registerBundle(ctx: Context, face: ConnectorAccountFace, packageName: string, account: string): () => void {
|
||||
const bundle = { ...face, account }
|
||||
const dispose = ctx.effect(function* () {
|
||||
@@ -45,11 +53,13 @@ function registerBundle(ctx: Context, face: ConnectorAccountFace, packageName: s
|
||||
*/
|
||||
export function apply(ctx: Context): void {
|
||||
ctx.effect(() => ctx.locale.register(NS, { zh, en, ja, es, fr, de, ru, pt }), 'connector-account: dictionaries')
|
||||
const browser = new BrowserAccounts(ctx, ctx.remote.connectorAccounts)
|
||||
const remote = ctx.remote.connectorAccounts
|
||||
const browser = new BrowserAccounts(ctx, remote)
|
||||
ctx.effect(() => async () => { await browser.dispose() }, 'connector-account: stream')
|
||||
const face: ConnectorAccountFace = {
|
||||
hooks: { connectorAccounts: browser.state },
|
||||
remote: ctx.remote.connectorAccounts,
|
||||
start: (key, operation) => settle(remote.start(key, operation)),
|
||||
cancel: (key, id) => settle(remote.cancel(key, id)),
|
||||
resolveText: text => ctx.locale.resolveText(text),
|
||||
follow: (key, id) => { browser.follow(key, id) },
|
||||
failed: () => { browser.failed() },
|
||||
|
||||
@@ -28,8 +28,13 @@ export interface ConnectorAccountsRemote {
|
||||
/** The face every surface entry injects. */
|
||||
export interface ConnectorAccountFace {
|
||||
hooks: { connectorAccounts: HostObservable<ConnectorAccountsState> }
|
||||
/** The Remote the buttons call directly. */
|
||||
readonly remote: Pick<ConnectorAccountsRemote, 'start' | 'cancel'>
|
||||
/**
|
||||
* Start an operation of an account on the Host. Resolves to the operation the Host started, and rejects when the Host
|
||||
* refuses or the call does not answer.
|
||||
*/
|
||||
readonly start: (key: string, operation: string) => Promise<ConnectorOperationId>
|
||||
/** Cancel an account's operation on the Host; rejects like `start`. */
|
||||
readonly cancel: (key: string, id: ConnectorOperationId) => Promise<void>
|
||||
/** Pick the active language's entry of a registrant's text. */
|
||||
readonly resolveText: (text: LocalizedText) => string
|
||||
/** Remember an operation this browser started: its authorization page opens here, and its success is reported here. */
|
||||
|
||||
@@ -6,7 +6,7 @@ import assert from 'node:assert/strict'
|
||||
import { Context, Service } from '@deepseek-ai/cordis'
|
||||
import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client'
|
||||
import { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { RemoteError, type RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { expect, it, onTestFinished, vi } from 'vitest'
|
||||
import {
|
||||
ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSectionEntry, ConnectorAccountToastEntry,
|
||||
@@ -21,7 +21,8 @@ const OTHER = '@acme/other'
|
||||
const OP = 'op-1' as ConnectorOperationId
|
||||
|
||||
function isFace(value: Record<string, unknown>): asserts value is Record<string, unknown> & ConnectorAccountFace {
|
||||
assert(typeof value.resolveText === 'function' && typeof value.follow === 'function' && typeof value.remote === 'object')
|
||||
assert(typeof value.resolveText === 'function' && typeof value.follow === 'function')
|
||||
assert(typeof value.start === 'function' && typeof value.cancel === 'function')
|
||||
assert(typeof value.hooks === 'object' && value.hooks !== null)
|
||||
}
|
||||
|
||||
@@ -54,6 +55,7 @@ async function bench() {
|
||||
let wake: (() => void) | undefined, closed = false, accepted = 0
|
||||
const closeStream = vi.fn(async () => { closed = true; wake?.() })
|
||||
const start = vi.fn(async (_key: string, _operation: string): Promise<RemoteResult<ConnectorOperationId>> => ({ ok: true, value: OP }))
|
||||
const cancel = vi.fn(async (_key: string, _id: ConnectorOperationId): Promise<RemoteResult<void>> => ({ ok: true, value: undefined }))
|
||||
class Remote extends Service {
|
||||
constructor() { super(ctx, 'remote') }
|
||||
$stream() {
|
||||
@@ -71,7 +73,7 @@ async function bench() {
|
||||
}
|
||||
}
|
||||
new Remote()
|
||||
ctx.provide('remote.connectorAccounts', { watch: vi.fn(), start, cancel: vi.fn() })
|
||||
ctx.provide('remote.connectorAccounts', { watch: vi.fn(), start, cancel })
|
||||
const locale = new LocaleRuntime(ctx)
|
||||
ctx.provide('locale', locale)
|
||||
await ctx.plugin(SlotRegistry)
|
||||
@@ -84,7 +86,7 @@ async function bench() {
|
||||
const bundles = (slot: 'plugins.bundle.config' | 'plugins.bundle.activation') =>
|
||||
ctx.slots.entries(slot).map(item => [item.options.key, bundleFaceOf(item).account])
|
||||
return {
|
||||
ctx, locale, start, closeStream, bundles,
|
||||
ctx, locale, start, cancel, closeStream, bundles,
|
||||
mount: () => ctx.plugin({ inject: [...inject], apply }),
|
||||
async publish(...entries: ConnectorAccountEntry[]) {
|
||||
const target = accepted + 1
|
||||
@@ -124,8 +126,13 @@ it('shows one tag and one notice entry for the page and each bundle\'s section a
|
||||
expect(faceOf(toast).hooks.connectorAccounts).toBe(face.hooks.connectorAccounts)
|
||||
expect([...face.hooks.connectorAccounts.getSnapshot().accounts.keys()]).toEqual([FIXTURE, OTHER, 'mcp:custom'])
|
||||
expect(face.resolveText({ en: 'Connected', zh: '已连接' })).toBe('Connected')
|
||||
await face.remote.start(FIXTURE, 'connect')
|
||||
expect(await face.start(FIXTURE, 'connect')).toBe(OP)
|
||||
expect(b.start).toHaveBeenCalledWith(FIXTURE, 'connect')
|
||||
await face.cancel(FIXTURE, OP)
|
||||
expect(b.cancel).toHaveBeenCalledWith(FIXTURE, OP)
|
||||
// A refusal reaches the buttons as a rejection with the Host's message.
|
||||
b.start.mockResolvedValueOnce({ ok: false, error: new RemoteError('gateway/internal', 'offline', {}) } as never)
|
||||
await expect(face.start(FIXTURE, 'connect')).rejects.toThrow('offline')
|
||||
face.follow(FIXTURE, OP)
|
||||
face.failed()
|
||||
expect(face.hooks.connectorAccounts.getSnapshot().notice).toEqual({ seq: 1, kind: 'action-failed' })
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// @vitest-environment jsdom
|
||||
/** The slot entries render each registrant's display from the Host with the shared copy, and buttons call the Remote directly. */
|
||||
/** The slot entries render each registrant's display from the Host with the shared copy, and buttons call the Host callbacks. */
|
||||
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import type { PluginsSubject } from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
|
||||
import type { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
||||
import { RemoteError, type RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { afterEach, expect, it, onTestFinished, vi } from 'vitest'
|
||||
import {
|
||||
ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSectionEntry, ConnectorAccountToastEntry,
|
||||
@@ -36,19 +35,14 @@ function entry(display: ConnectorAccountDisplay = DISCONNECTED, extra: Partial<C
|
||||
}
|
||||
}
|
||||
|
||||
const ok = <T,>(value: T): RemoteResult<T> => ({ ok: true, value })
|
||||
const refused = (): RemoteResult<never> => ({ ok: false, error: new RemoteError('gateway/internal', 'offline', {}) }) as never
|
||||
|
||||
function face(change: Partial<ConnectorAccountsState> = {}, accounts: readonly ConnectorAccountEntry[] = [entry()]) {
|
||||
const current: ConnectorAccountsState = {
|
||||
accounts: new Map(accounts.map(item => [item.key, item])), linked: true, notice: undefined, ...change,
|
||||
}
|
||||
return {
|
||||
useConnectorAccounts: <R,>(selector: (value: ConnectorAccountsState) => R): R => selector(current),
|
||||
remote: {
|
||||
start: vi.fn(async (_key: string, _operation: string) => ok(OP)),
|
||||
cancel: vi.fn(async (_key: string, _id: ConnectorOperationId): Promise<RemoteResult<void>> => ok(undefined)),
|
||||
},
|
||||
start: vi.fn(async (_key: string, _operation: string) => OP),
|
||||
cancel: vi.fn(async (_key: string, _id: ConnectorOperationId) => {}),
|
||||
account: KEY, resolveText, follow: vi.fn(), failed: vi.fn(), dismissNotice: vi.fn(), t,
|
||||
}
|
||||
}
|
||||
@@ -57,7 +51,7 @@ const sectionOf = (display: ConnectorAccountDisplay, change: Partial<ConnectorAc
|
||||
const prompt = (props: ReturnType<typeof face>, onDismiss = vi.fn(), onOpenDetails = vi.fn()) =>
|
||||
<ConnectorAccountActivationEntry {...props} onDismiss={onDismiss} onOpenDetails={onOpenDetails} />
|
||||
|
||||
it('shows the registrant title, status, detail, notes, and hint, and starts each button\'s operation through the Remote', async () => {
|
||||
it('shows the registrant title, status, detail, notes, and hint, and starts each button\'s operation on the Host', async () => {
|
||||
const props = sectionOf({
|
||||
...DISCONNECTED, detail: '先关联一个应用。',
|
||||
notes: [{ text: '应用:cli_a', button: { label: '更换', command: { kind: 'start', operation: 'link-app' }, variant: 'ghost' } }, { text: '普通说明' }],
|
||||
@@ -67,18 +61,18 @@ it('shows the registrant title, status, detail, notes, and hint, and starts each
|
||||
expect(container.querySelector('[data-connector-account="disconnected"][data-connector-account-key="@acme/fixture"]')).toBeTruthy()
|
||||
await click('连接演示')
|
||||
await click('更换')
|
||||
expect(props.remote.start.mock.calls).toEqual([[KEY, 'connect'], [KEY, 'link-app']])
|
||||
expect(props.start.mock.calls).toEqual([[KEY, 'connect'], [KEY, 'link-app']])
|
||||
expect(props.follow.mock.calls).toEqual([[KEY, OP], [KEY, OP]])
|
||||
})
|
||||
|
||||
it('disables the buttons while a call is pending or the Host stream is down', async () => {
|
||||
const props = face()
|
||||
const answer = Promise.withResolvers<RemoteResult<ConnectorOperationId>>()
|
||||
props.remote.start.mockReturnValueOnce(answer.promise)
|
||||
const answer = Promise.withResolvers<ConnectorOperationId>()
|
||||
props.start.mockReturnValueOnce(answer.promise)
|
||||
render(<ConnectorAccountSectionEntry {...props} />)
|
||||
fireEvent.click(button('连接演示'))
|
||||
expect(disabled()).toEqual([true])
|
||||
await act(async () => { answer.resolve(ok(OP)) })
|
||||
await act(async () => { answer.resolve(OP) })
|
||||
expect(disabled()).toEqual([false])
|
||||
expect(props.failed).not.toHaveBeenCalled()
|
||||
cleanup()
|
||||
@@ -100,7 +94,28 @@ it('asks before a button that changes the account outside DSH and starts it only
|
||||
fireEvent.click(button('退出登录'))
|
||||
await click('确认退出')
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
expect(props.remote.start.mock.calls).toEqual([[KEY, 'sign-out']])
|
||||
expect(props.start.mock.calls).toEqual([[KEY, 'sign-out']])
|
||||
})
|
||||
|
||||
it('disables an open confirmation and the activation prompt\'s Connect while the Host stream is down', () => {
|
||||
const display: ConnectorAccountDisplay = {
|
||||
phase: 'connected', status: '已连接', notes: [],
|
||||
buttons: [{ label: '退出登录', command: { kind: 'start', operation: 'sign-out' }, confirm: { title: '退出演示?', body: '终端也会退出。', label: '确认退出' } }],
|
||||
}
|
||||
const { rerender } = render(<ConnectorAccountSectionEntry {...sectionOf(display)} />)
|
||||
fireEvent.click(button('退出登录'))
|
||||
// The stream drops while the confirmation is open.
|
||||
const down = sectionOf(display, { linked: false })
|
||||
rerender(<ConnectorAccountSectionEntry {...down} />)
|
||||
fireEvent.click(button('确认退出'))
|
||||
expect((button('确认退出') as HTMLButtonElement).disabled).toBe(true)
|
||||
expect(down.start).not.toHaveBeenCalled()
|
||||
cleanup()
|
||||
const offline = sectionOf({ ...DISCONNECTED, connect: { kind: 'start', operation: 'connect' } }, { linked: false })
|
||||
render(prompt(offline))
|
||||
fireEvent.click(button('连接演示'))
|
||||
expect((button('连接演示') as HTMLButtonElement).disabled).toBe(true)
|
||||
expect(offline.start).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each<[string, ConnectorAccountDisplay['failure'], string]>([
|
||||
@@ -112,9 +127,9 @@ it.each<[string, ConnectorAccountDisplay['failure'], string]>([
|
||||
expect(screen.getByRole('alert').textContent).toBe(expected)
|
||||
})
|
||||
|
||||
it('reports a start the Host refused or that never answered, without following it', async () => {
|
||||
it('reports a start that the Host refused or that never answered, without following it', async () => {
|
||||
const props = face()
|
||||
props.remote.start.mockResolvedValueOnce(refused()).mockRejectedValueOnce(new Error('carrier lost'))
|
||||
props.start.mockRejectedValueOnce(new Error('offline')).mockRejectedValueOnce(new Error('carrier lost'))
|
||||
render(<ConnectorAccountSectionEntry {...props} />)
|
||||
await click('连接演示')
|
||||
await click('连接演示')
|
||||
@@ -134,13 +149,13 @@ it('cancels the operation in progress and opens its authorization page again on
|
||||
fireEvent.click(button('打开授权页'))
|
||||
expect(windowOpen).toHaveBeenCalledWith('https://example.com/a', '_blank', 'noopener,noreferrer')
|
||||
await click('取消')
|
||||
expect(props.remote.cancel).toHaveBeenCalledWith(KEY, OP)
|
||||
expect(props.cancel).toHaveBeenCalledWith(KEY, OP)
|
||||
// A cancel button with no operation in progress calls nothing.
|
||||
cleanup()
|
||||
const idle = sectionOf(display)
|
||||
render(<ConnectorAccountSectionEntry {...idle} />)
|
||||
await click('取消')
|
||||
expect(idle.remote.cancel).not.toHaveBeenCalled()
|
||||
expect(idle.cancel).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders nothing for a bundle whose account the Host has not listed', () => {
|
||||
@@ -191,23 +206,23 @@ it('connects from the prompt through the operation the display names, or only op
|
||||
const { rerender } = render(prompt(named, vi.fn(), onOpenDetails))
|
||||
await click('连接演示')
|
||||
expect(onOpenDetails).toHaveBeenCalledOnce()
|
||||
expect(named.remote.start).toHaveBeenCalledWith(KEY, 'link-app')
|
||||
expect(named.start).toHaveBeenCalledWith(KEY, 'link-app')
|
||||
const bare = face()
|
||||
rerender(prompt(bare, vi.fn(), onOpenDetails))
|
||||
fireEvent.click(button('连接演示'))
|
||||
expect(onOpenDetails).toHaveBeenCalledTimes(2)
|
||||
expect(bare.remote.start).not.toHaveBeenCalled()
|
||||
expect(bare.start).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('starts once for a second click before the first call answers', async () => {
|
||||
const props = sectionOf({ ...DISCONNECTED, connect: { kind: 'start', operation: 'connect' } })
|
||||
const answer = Promise.withResolvers<RemoteResult<ConnectorOperationId>>()
|
||||
props.remote.start.mockReturnValueOnce(answer.promise)
|
||||
const answer = Promise.withResolvers<ConnectorOperationId>()
|
||||
props.start.mockReturnValueOnce(answer.promise)
|
||||
render(prompt(props))
|
||||
fireEvent.click(button('连接演示'))
|
||||
fireEvent.click(button('连接演示'))
|
||||
await act(async () => { answer.resolve(ok(OP)) })
|
||||
expect(props.remote.start).toHaveBeenCalledOnce()
|
||||
await act(async () => { answer.resolve(OP) })
|
||||
expect(props.start).toHaveBeenCalledOnce()
|
||||
expect(props.follow).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user