feat(connector-account): add one Host registry and Plugins page surfaces for connector accounts
`@deepseek-ai/dsh-client-ui-connector-account` provides `ctx.connectorAccounts`, where CLI app plugins and MCP connectors register an account with its source, page operations, copy, and Host-side presentation, and the `connectorAccounts` Remote (`watch`, `start`, `cancel`). The browser half follows every account through one stream and renders each bundle's section, title tag, activation prompt, confirmation, and notice from the Host display; it opens authorization pages and reports notices only for the operations this browser started. `dsh-api-remotes` mounts the generated Remote, `dsh-web-app` loads the package, LiveShare classifies the three endpoints as owner-only, and the client test runtime answers `connectorAccounts/watch` with no accounts.
This commit is contained in:
1 parent
d51d623bfc
commit
a8f3badfee
63 files changed
+2913
-9
No files matched your search
+19
@@ -0,0 +1,19 @@
|
||||
# Bilingual-pair consistency record for 2026-11-06-connector-account-registry.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-11-06-connector-account-registry.md
|
||||
/agent-note-one-host-registry-and-one-browser-half-for-connector-accounts:
|
||||
en: 3950421fb526f6b7
|
||||
zh: 47c5f6cc4b735058
|
||||
/agent-note-one-host-registry-and-one-browser-half-for-connector-accounts/problem:
|
||||
en: 2a7b59cd509a0b9a
|
||||
zh: 38130ce17829342d
|
||||
/agent-note-one-host-registry-and-one-browser-half-for-connector-accounts/decision:
|
||||
en: d96b43106a1ba837
|
||||
zh: 97bc8f9436ec07d0
|
||||
/agent-note-one-host-registry-and-one-browser-half-for-connector-accounts/alternatives-considered:
|
||||
en: ee0aa3f9ea40ef15
|
||||
zh: fded69a6dcc8ca87
|
||||
/agent-note-one-host-registry-and-one-browser-half-for-connector-accounts/consequences:
|
||||
en: 5228f32becfbdec3
|
||||
zh: 013f1073e70d46f7
|
||||
@@ -0,0 +1,42 @@
|
||||
# Agent Note: One Host registry and one browser half for connector accounts
|
||||
|
||||
Status: implemented
|
||||
|
||||
English | [中文](2026-11-06-connector-account-registry.zh.md)
|
||||
|
||||
## Problem
|
||||
|
||||
Connector plugins show an account section on the Plugins page. CLI app plugins keep the account in their vendor CLI; MCP connectors keep an OAuth grant through the MCP manager. Both kinds need the same surfaces: a bundle's section, title tag, and activation prompt, a confirmation before an action that changes the account outside DSH, and a notice in the browser that started the operation. A client plugin cannot share runtime code with another feature plugin ([packages/client/AGENTS.md](../../../../packages/client/AGENTS.md) rule 3), so one browser half per connector kind duplicates the same code and lets the copies drift. When the browser decides an account's state or relays an identifier from one Remote to another, the Host can no longer run the flow without the browser.
|
||||
|
||||
## Decision
|
||||
|
||||
[`@deepseek-ai/dsh-client-ui-connector-account`](../../../../packages/client/ui-connector-account/README.md) provides one Host registry, `ctx.connectorAccounts`, one `connectorAccounts` Remote, and one browser half for every connector kind.
|
||||
|
||||
| Part | Contract |
|
||||
|---|---|
|
||||
| Registration | `register({ key, packageName?, source, operations, copy, present })` returns the disposer that withdraws the account |
|
||||
| Key | Unique among registered accounts and independent of the package, so an account that no bundle owns, such as a server configured in Settings, registers too |
|
||||
| Package | Decides which bundle page carries the section and tag; a package carries at most one account |
|
||||
| Source | The registrant's account: `snapshot`, `observe`, `refresh`, `start`, and `cancel` |
|
||||
| Display | `present(view)` on the Host gives the phase, status text, title tag, buttons and their commands, confirmations, failure, and the operation the activation prompt starts |
|
||||
| Remote | `watch`, plus `start(key, operation)` and `cancel(key, id)`, which route by key to the account's source |
|
||||
|
||||
The Host decides everything except opening the authorization page. The browser never learns how an account connects: it receives only the display, the operation in progress with its authorization page, and the latest result with its success text. The browser half keeps only what belongs to one browser: the operations it started, so their authorization pages open and their success is reported only there; the latest notice; and whether its stream is delivering. Buttons call `start` and `cancel` on the Remote themselves, and each surface keeps its own pending state.
|
||||
|
||||
The page registers one title tag entry and one notice entry. It also registers a section and an activation prompt for each account that names a package, because those two slots are keyed by package.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**Two registries behind one browser half.** Rejected: the browser would follow both Remotes and choose which one each button calls, which relays between Host services again, and the two Host registries would hold the same code.
|
||||
|
||||
**One browser half per connector kind.** Rejected: client plugins cannot import each other's values, so the shared surfaces would be written twice and diverge.
|
||||
|
||||
**Share the browser half through `PLATFORM_MODULES` or a browser-side service.** Rejected: the module table is reserved for shell-seeded and static infrastructure libraries, and a browser-side service would keep the registrations in the browser, which only repeat what the Host knows.
|
||||
|
||||
**Let the browser derive an account's phase and actions from the registrant's raw state.** Rejected: the rules for which actions apply would live where the Host cannot test or run them, and the browser would need the registrant's own Remote.
|
||||
|
||||
## Consequences
|
||||
|
||||
The registry and browser half exist once. A new connector kind writes a source and `present` on the Host and needs no browser code. The account rules live beside the services that own them, and the Host can run every operation without a browser.
|
||||
|
||||
Registrants map their account states onto five phases (checking, connecting, connected, disconnected, unavailable); a state outside them shows through its status text and detail. The Web and Desktop compositions load the registry whether or not a connector plugin is installed. An authorization page that opens after the start call answers can be blocked by the browser; the section's open button shows it again.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Agent Note:连接器账号使用一个 Host 注册表和一个浏览器一半
|
||||
|
||||
Status: implemented
|
||||
|
||||
[English](2026-11-06-connector-account-registry.md) | 中文
|
||||
|
||||
## 问题
|
||||
|
||||
连接器插件会在插件页显示账号区块。CLI 应用插件的账号保存在厂商 CLI 中;MCP 连接器通过 MCP 管理器保存 OAuth 授权。两类插件需要同样的界面:插件包的区块、标题旁标签和开启引导,在会改变 DSH 之外账号状态的操作前确认,以及只在发起操作的浏览器中显示的提示。客户端插件不能与其他功能插件共享运行时代码([packages/client/AGENTS.md](../../../../packages/client/AGENTS.md) 第 3 条),因此每类连接器各有一个浏览器一半,就会把同样的代码写两遍,副本还会逐渐不一致。如果由浏览器决定账号状态,或在两个 Remote 之间转发标识,Host 就无法在没有浏览器的情况下完成流程。
|
||||
|
||||
## 决定
|
||||
|
||||
[`@deepseek-ai/dsh-client-ui-connector-account`](../../../../packages/client/ui-connector-account/README.zh.md) 为所有连接器类型提供一个 Host 注册表 `ctx.connectorAccounts`、一个 `connectorAccounts` Remote 和一个浏览器一半。
|
||||
|
||||
| 部分 | 约定 |
|
||||
|---|---|
|
||||
| 注册 | `register({ key, packageName?, source, operations, copy, present })` 返回撤下账号的销毁函数 |
|
||||
| 键 | 在已注册账号中唯一,且与包无关,因此没有插件包承载的账号(如在 Settings 中配置的服务器)也能注册 |
|
||||
| 包 | 决定由哪个插件包页面承载区块和标签;一个包最多承载一个账号 |
|
||||
| 来源 | 注册方的账号:`snapshot`、`observe`、`refresh`、`start` 和 `cancel` |
|
||||
| 展示 | Host 上的 `present(view)` 给出阶段、状态文字、标题旁标签、按钮及其命令、确认、失败信息,以及开启引导启动的操作 |
|
||||
| Remote | `watch`,以及按键路由到账号来源的 `start(key, operation)` 和 `cancel(key, id)` |
|
||||
|
||||
除了打开授权页,其余都由 Host 决定。浏览器不知道账号如何连接:它只收到展示内容、进行中的操作及其授权页,以及带成功文本的最新结果。浏览器一半只保存属于本浏览器的东西:它发起的操作(授权页只在这里打开,成功只在这里报告)、最新提示,以及它的流是否在推送。按钮自己调用 Remote 的 `start` 和 `cancel`,每个界面自己保存未完成状态。
|
||||
|
||||
页面只注册一个标题旁标签条目和一个提示条目;对每个带包名的账号,再注册一个区块和一个开启引导,因为这两个插槽以包为键。
|
||||
|
||||
## 考虑过的替代方案
|
||||
|
||||
**一个浏览器一半背后有两个注册表。** 否决:浏览器要同时跟随两个 Remote,并为每个按钮选择调用哪一个,这又是在 Host 服务之间转发;两个 Host 注册表的代码也会相同。
|
||||
|
||||
**每类连接器各有一个浏览器一半。** 否决:客户端插件不能导入彼此的值,共用界面就要写两遍,并逐渐不一致。
|
||||
|
||||
**通过 `PLATFORM_MODULES` 或浏览器端服务共享浏览器一半。** 否决:模块表只留给由 shell 预置的基础设施和静态库;浏览器端服务会把注册留在浏览器中,而这些注册只是重复 Host 已知的信息。
|
||||
|
||||
**由浏览器根据注册方的原始状态推算账号阶段和操作。** 否决:哪些操作可用的规则会放在 Host 无法测试和执行的地方,浏览器还需要注册方自己的 Remote。
|
||||
|
||||
## 后果
|
||||
|
||||
注册表和浏览器一半只有一份。新的连接器类型只需在 Host 上编写来源和 `present`,不需要浏览器代码。账号规则与拥有它们的服务在一起,Host 不依赖浏览器就能执行每个操作。
|
||||
|
||||
注册方需要把账号状态映射到五个阶段(检查中、连接中、已连接、未连接、不可用);超出这些阶段的状态通过状态文字和说明表达。无论是否安装了连接器插件,Web 与桌面端组合都会加载注册表。启动调用返回后才打开的授权页可能被浏览器拦截;区块中的打开按钮可以再次打开它。
|
||||
@@ -6,5 +6,5 @@
|
||||
en: 41d772192075e133
|
||||
zh: 5ef3da69b4de1d8a
|
||||
/capability-seams-and-core-services:
|
||||
en: b76743a3ff14d2f4
|
||||
zh: 82431aa3ded14a89
|
||||
en: b3be76b595765ee3
|
||||
zh: 85de5f625a7a15a6
|
||||
@@ -28,6 +28,8 @@ flowchart LR
|
||||
pkg_plugin_manager["plugin-manager"]
|
||||
svc_pluginManager["ctx.pluginManager<br/>Current-profile plugin and bundle management"]
|
||||
pkg_ui_settings_plugin_inventory["ui-settings-plugin-inventory"]
|
||||
pkg_client_ui_connector_account["client-ui-connector-account"]
|
||||
svc_connectorAccounts["ctx.connectorAccounts<br/>Connector accounts on the Plugins page"]
|
||||
pkg_plugin_market["plugin-market"]
|
||||
svc_pluginMarket["ctx.pluginMarket<br/>Plugin market index reader"]
|
||||
pkg_client_ui_plugin_market["client-ui-plugin-market"]
|
||||
@@ -344,6 +346,7 @@ flowchart LR
|
||||
pkg_client_file_upload --> svc_fileUploads
|
||||
pkg_client_modules --> svc_clientModules
|
||||
pkg_client_product_analytics --> svc_productAnalytics
|
||||
pkg_client_ui_connector_account --> svc_connectorAccounts
|
||||
pkg_client_ui_plugin_manager --> svc_pluginRegistryProbe
|
||||
pkg_command_feedback --> svc_sessionFeedback
|
||||
pkg_commands --> svc_commands
|
||||
@@ -659,6 +662,7 @@ flowchart LR
|
||||
| `ctx.hmr` | `core` | [`hmr`](../packages/boot/hmr) | - | [`app-boot`](../packages/boot/app-boot) | - | Owns module and exact configuration watchers; application mutations share its queue and automatic reloads await the application file lock. |
|
||||
| `ctx.pluginRegistryProbe` | `core` | [`client-ui-plugin-manager`](../packages/client/ui-plugin-manager) | - | [`client-ui-plugin-manager`](../packages/client/ui-plugin-manager) | - | Races public registry responses on the Host; the Client owns the initial registry recommendation. |
|
||||
| `ctx.pluginManager` | `core` | [`plugin-manager`](../packages/boot/plugin-manager) | - | [`plugin-manager`](../packages/boot/plugin-manager), `ui-settings-plugin-inventory` | - | Shares profile package operations with the CLI and reports persisted and running state to Web and agent callers. |
|
||||
| `ctx.connectorAccounts` | `service` | [`client-ui-connector-account`](../packages/client/ui-connector-account) | - | - | - | Holds the accounts CLI app plugins and MCP connectors register and serves their Host-computed displays to the Plugins page through one Remote; authorization pages and notices stay in the browser that started the operation. |
|
||||
| `ctx.pluginMarket` | `core` | [`plugin-market`](../packages/boot/plugin-market) | - | [`client-ui-plugin-market`](../packages/client/ui-plugin-market), [`plugin-market`](../packages/boot/plugin-market) | - | Fetches and validates the index sources the user configures; installation goes through the plugin manager. |
|
||||
| `ctx.profileContext` | `core` | [`app-boot`](../packages/boot/app-boot) | - | [`plugin-manager`](../packages/boot/plugin-manager) | - | The dsh launcher supplies data-only profile locations and composition inputs; reload scheduling belongs to dsh-hmr. |
|
||||
| `ctx.connection` | `core` | [`client-connection`](../packages/client/connection) | - | [`api-gateway`](../packages/api/gateway), [`host-frontend-static`](../packages/host/frontend-static) | - | Owns browser authentication and shared HTTP request dispatch; API adapters register endpoints and streams. |
|
||||
|
||||
@@ -30,6 +30,8 @@ flowchart LR
|
||||
pkg_plugin_manager["plugin-manager"]
|
||||
svc_pluginManager["ctx.pluginManager<br/>Current-profile plugin and bundle management"]
|
||||
pkg_ui_settings_plugin_inventory["ui-settings-plugin-inventory"]
|
||||
pkg_client_ui_connector_account["client-ui-connector-account"]
|
||||
svc_connectorAccounts["ctx.connectorAccounts<br/>Connector accounts on the Plugins page"]
|
||||
pkg_plugin_market["plugin-market"]
|
||||
svc_pluginMarket["ctx.pluginMarket<br/>Plugin market index reader"]
|
||||
pkg_client_ui_plugin_market["client-ui-plugin-market"]
|
||||
@@ -346,6 +348,7 @@ flowchart LR
|
||||
pkg_client_file_upload --> svc_fileUploads
|
||||
pkg_client_modules --> svc_clientModules
|
||||
pkg_client_product_analytics --> svc_productAnalytics
|
||||
pkg_client_ui_connector_account --> svc_connectorAccounts
|
||||
pkg_client_ui_plugin_manager --> svc_pluginRegistryProbe
|
||||
pkg_command_feedback --> svc_sessionFeedback
|
||||
pkg_commands --> svc_commands
|
||||
@@ -661,6 +664,7 @@ flowchart LR
|
||||
| `ctx.hmr` | `core` | [`hmr`](../packages/boot/hmr) | - | [`app-boot`](../packages/boot/app-boot) | - | 负责模块和精确配置监听;应用修改共用其队列,自动重载等待应用文件锁。 |
|
||||
| `ctx.pluginRegistryProbe` | `core` | [`client-ui-plugin-manager`](../packages/client/ui-plugin-manager) | - | [`client-ui-plugin-manager`](../packages/client/ui-plugin-manager) | - | 在 Host 上并发比较公共安装源响应;初始安装源推荐由 Client 负责。 |
|
||||
| `ctx.pluginManager` | `core` | [`plugin-manager`](../packages/boot/plugin-manager) | - | [`plugin-manager`](../packages/boot/plugin-manager), `ui-settings-plugin-inventory` | - | 与 CLI 共享 profile 包操作,并向 Web 和 Agent 调用方分别报告持久状态与运行状态。 |
|
||||
| `ctx.connectorAccounts` | `service` | [`client-ui-connector-account`](../packages/client/ui-connector-account) | - | - | - | 保存 CLI 应用插件和 MCP 连接器注册的账号,并通过一个 Remote 把 Host 算好的展示内容提供给插件页;授权页和提示只出现在发起操作的浏览器中。 |
|
||||
| `ctx.pluginMarket` | `core` | [`plugin-market`](../packages/boot/plugin-market) | - | [`client-ui-plugin-market`](../packages/client/ui-plugin-market), [`plugin-market`](../packages/boot/plugin-market) | - | 获取并校验用户配置的索引源;安装通过插件管理器完成。 |
|
||||
| `ctx.profileContext` | `core` | [`app-boot`](../packages/boot/app-boot) | - | [`plugin-manager`](../packages/boot/plugin-manager) | - | dsh launcher 提供纯数据形式的 profile 位置与组合输入;重载调度由 dsh-hmr 负责。 |
|
||||
| `ctx.connection` | `core` | [`client-connection`](../packages/client/connection) | - | [`api-gateway`](../packages/api/gateway), [`host-frontend-static`](../packages/host/frontend-static) | - | 负责浏览器认证与共享 HTTP 请求分发;API 适配器注册端点和流。 |
|
||||
|
||||
@@ -5022,6 +5022,7 @@ These load from a `cordis.yml` entry with no `config:` block; they declare no co
|
||||
| `@deepseek-ai/dsh-client-ui-brand-official` | — | [`packages/client/ui-brand-official/src/index.ts`](../packages/client/ui-brand-official/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-chat` | — | [`packages/client/ui-chat/src/index.ts`](../packages/client/ui-chat/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-commands` | — | [`packages/client/ui-commands/src/index.ts`](../packages/client/ui-commands/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-connector-account` | — | [`packages/client/ui-connector-account/src/index.ts`](../packages/client/ui-connector-account/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-context-menu` | — | [`packages/client/ui-context-menu/src/index.ts`](../packages/client/ui-context-menu/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-conversation` | — | [`packages/client/ui-conversation/src/index.ts`](../packages/client/ui-conversation/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-cordis` | — | [`packages/extensions/ui-cordis/src/index.ts`](../packages/extensions/ui-cordis/src/index.ts) |
|
||||
|
||||
@@ -5024,6 +5024,7 @@ export interface Config {
|
||||
| `@deepseek-ai/dsh-client-ui-brand-official` | — | [`packages/client/ui-brand-official/src/index.ts`](../packages/client/ui-brand-official/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-chat` | — | [`packages/client/ui-chat/src/index.ts`](../packages/client/ui-chat/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-commands` | — | [`packages/client/ui-commands/src/index.ts`](../packages/client/ui-commands/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-connector-account` | — | [`packages/client/ui-connector-account/src/index.ts`](../packages/client/ui-connector-account/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-context-menu` | — | [`packages/client/ui-context-menu/src/index.ts`](../packages/client/ui-context-menu/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-conversation` | — | [`packages/client/ui-conversation/src/index.ts`](../packages/client/ui-conversation/src/index.ts) |
|
||||
| `@deepseek-ai/dsh-client-ui-cordis` | — | [`packages/extensions/ui-cordis/src/index.ts`](../packages/extensions/ui-cordis/src/index.ts) |
|
||||
|
||||
@@ -166,6 +166,7 @@ flowchart TD
|
||||
pkg_client_ui_brand_official["client-ui-brand-official"]
|
||||
pkg_client_ui_chat["client-ui-chat"]
|
||||
pkg_client_ui_commands["client-ui-commands"]
|
||||
pkg_client_ui_connector_account["client-ui-connector-account"]
|
||||
pkg_client_ui_context_menu["client-ui-context-menu"]
|
||||
pkg_client_ui_conversation["client-ui-conversation"]
|
||||
pkg_client_ui_deliverables["client-ui-deliverables"]
|
||||
@@ -1586,6 +1587,7 @@ flowchart TD
|
||||
| [`client-ui-brand-official`](../packages/client/ui-brand-official) | `client` | — |
|
||||
| [`client-ui-chat`](../packages/client/ui-chat) | `client` | — |
|
||||
| [`client-ui-commands`](../packages/client/ui-commands) | `client` | — |
|
||||
| [`client-ui-connector-account`](../packages/client/ui-connector-account) | `client` | — |
|
||||
| [`client-ui-context-menu`](../packages/client/ui-context-menu) | `client` | — |
|
||||
| [`client-ui-conversation`](../packages/client/ui-conversation) | `client` | — |
|
||||
| [`client-ui-deliverables`](../packages/client/ui-deliverables) | `client` | — |
|
||||
|
||||
@@ -168,6 +168,7 @@ flowchart TD
|
||||
pkg_client_ui_brand_official["client-ui-brand-official"]
|
||||
pkg_client_ui_chat["client-ui-chat"]
|
||||
pkg_client_ui_commands["client-ui-commands"]
|
||||
pkg_client_ui_connector_account["client-ui-connector-account"]
|
||||
pkg_client_ui_context_menu["client-ui-context-menu"]
|
||||
pkg_client_ui_conversation["client-ui-conversation"]
|
||||
pkg_client_ui_deliverables["client-ui-deliverables"]
|
||||
@@ -1588,6 +1589,7 @@ flowchart TD
|
||||
| [`client-ui-brand-official`](../packages/client/ui-brand-official) | `client` | — |
|
||||
| [`client-ui-chat`](../packages/client/ui-chat) | `client` | — |
|
||||
| [`client-ui-commands`](../packages/client/ui-commands) | `client` | — |
|
||||
| [`client-ui-connector-account`](../packages/client/ui-connector-account) | `client` | — |
|
||||
| [`client-ui-context-menu`](../packages/client/ui-context-menu) | `client` | — |
|
||||
| [`client-ui-conversation`](../packages/client/ui-conversation) | `client` | — |
|
||||
| [`client-ui-deliverables`](../packages/client/ui-deliverables) | `client` | — |
|
||||
|
||||
@@ -143,6 +143,50 @@ async edit( entry: Entry, change: (current: Record<string, unknown>, inherited:
|
||||
|
||||
Source: [`packages/boot/config-editor/src/index.ts`](../../packages/boot/config-editor/src/index.ts)
|
||||
|
||||
<a id="ctxconnectoraccounts--connectoraccounts"></a>
|
||||
|
||||
### `ctx.connectorAccounts` — `ConnectorAccounts`
|
||||
|
||||
Holds the registered accounts and serves them to the Plugins page.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Show one account on the Plugins page for as long as the returned disposer has not run.
|
||||
* @param registration - the account key, its bundle package, the account source, the page operations, and the
|
||||
* presentation.
|
||||
* @returns an idempotent disposer that withdraws the account.
|
||||
* @throws when another account already uses the key or the package.
|
||||
*/
|
||||
register<View extends AnyConnectorAccountView>(registration: ConnectorAccountRegistration<View>): () => void
|
||||
|
||||
/**
|
||||
* Follow every registered account; each new subscriber starts a check of each account that runs no operation.
|
||||
* @param signal - the Client's observation lifetime; disposal also ends the stream.
|
||||
* @returns the current accounts, then each changed set, coalescing changes that arrive before the next read.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *watch(signal: AbortSignal): AsyncIterable<ConnectorAccountsView>
|
||||
|
||||
/**
|
||||
* Start one of the operations the account registered as page actions.
|
||||
* @param key - the account key.
|
||||
* @param operation - the operation kind.
|
||||
* @returns the operation identity.
|
||||
* @throws for an unknown account or operation, or whatever the account's source refuses, such as a second operation.
|
||||
*/
|
||||
@Remote start(key: string, operation: string): ConnectorOperationId
|
||||
|
||||
/**
|
||||
* Cancel one operation while its phase is cancellable, and wait for it to settle.
|
||||
* @param key - the account key.
|
||||
* @param id - the operation to cancel; a finished one or a phase that is not cancellable is ignored.
|
||||
* @returns after the operation settles, or at once when nothing is cancelled.
|
||||
* @throws for an unknown account.
|
||||
*/
|
||||
@Remote cancel(key: string, id: ConnectorOperationId): Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-connector-account/src/index.ts`](../../packages/client/ui-connector-account/src/index.ts)
|
||||
|
||||
<a id="ctxheadlessstartup--headlessstartupvalues"></a>
|
||||
|
||||
### `ctx.headlessStartup` — `HeadlessStartupValues`
|
||||
|
||||
@@ -143,6 +143,50 @@ async edit( entry: Entry, change: (current: Record<string, unknown>, inherited:
|
||||
|
||||
Source: [`packages/boot/config-editor/src/index.ts`](../../packages/boot/config-editor/src/index.ts)
|
||||
|
||||
<a id="ctxconnectoraccounts--connectoraccounts"></a>
|
||||
|
||||
### `ctx.connectorAccounts` — `ConnectorAccounts`
|
||||
|
||||
Holds the registered accounts and serves them to the Plugins page.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Show one account on the Plugins page for as long as the returned disposer has not run.
|
||||
* @param registration - the account key, its bundle package, the account source, the page operations, and the
|
||||
* presentation.
|
||||
* @returns an idempotent disposer that withdraws the account.
|
||||
* @throws when another account already uses the key or the package.
|
||||
*/
|
||||
register<View extends AnyConnectorAccountView>(registration: ConnectorAccountRegistration<View>): () => void
|
||||
|
||||
/**
|
||||
* Follow every registered account; each new subscriber starts a check of each account that runs no operation.
|
||||
* @param signal - the Client's observation lifetime; disposal also ends the stream.
|
||||
* @returns the current accounts, then each changed set, coalescing changes that arrive before the next read.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *watch(signal: AbortSignal): AsyncIterable<ConnectorAccountsView>
|
||||
|
||||
/**
|
||||
* Start one of the operations the account registered as page actions.
|
||||
* @param key - the account key.
|
||||
* @param operation - the operation kind.
|
||||
* @returns the operation identity.
|
||||
* @throws for an unknown account or operation, or whatever the account's source refuses, such as a second operation.
|
||||
*/
|
||||
@Remote start(key: string, operation: string): ConnectorOperationId
|
||||
|
||||
/**
|
||||
* Cancel one operation while its phase is cancellable, and wait for it to settle.
|
||||
* @param key - the account key.
|
||||
* @param id - the operation to cancel; a finished one or a phase that is not cancellable is ignored.
|
||||
* @returns after the operation settles, or at once when nothing is cancelled.
|
||||
* @throws for an unknown account.
|
||||
*/
|
||||
@Remote cancel(key: string, id: ConnectorOperationId): Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-connector-account/src/index.ts`](../../packages/client/ui-connector-account/src/index.ts)
|
||||
|
||||
<a id="ctxheadlessstartup--headlessstartupvalues"></a>
|
||||
|
||||
### `ctx.headlessStartup` — `HeadlessStartupValues`
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: a7a78c6d1aeebeb3
|
||||
zh: 4bb69f32d8b05ba3
|
||||
/deepseek-ai-dsh-api-remotes/use-this-package:
|
||||
en: 5e5770cc1cbf49db
|
||||
zh: b9ee3c309d0cd93c
|
||||
en: d8622091b217f050
|
||||
zh: c36cb87f10e7802a
|
||||
/deepseek-ai-dsh-api-remotes/forwarded-host-events:
|
||||
en: 1dea001229f8c06a
|
||||
zh: 3acb1fa1c5d24f8c
|
||||
|
||||
@@ -29,7 +29,7 @@ Two-sided BFF for Host Remote capabilities selected by this application. The Hos
|
||||
|
||||
[`@deepseek-ai/dsh-api-session-controller`](../session-controller/README.md) owns Agent and Session identity policy, including the Typert lookup resolvers used by other namespaces. This package selects and mounts that generated Session contribution without a direct runtime dependency on `@deepseek-ai/dsh-session`; activation policy stays with Session Controller.
|
||||
|
||||
The Client assembly mounts Office conversion, Commands, Agent Teams, credentials, settings, Goal, Schedule, dynamic Cordis, file and Session references, read-only Host plugin inventory, plugin-installation registry response comparison, message feedback, permission presets, Session Controller, subagents, web provider list, and Workspace Controller contributions. The `permissionPresets` namespace returns the complete process-level catalog used by current-session controls. Cordis effect ownership withdraws every contribution when this assembly unloads, while `@deepseek-ai/dsh-api-gateway/client` owns descriptor validation, traced namespace Services, direct and scoped methods, invocation, streams, and cancellation. The Client entry consumes the shared `TypertClientRemote` interface through Cordis and does not import the concrete Gateway. It re-exports the Gateway Client face's declaration merges type-only, so a consumer reaching the forwarded-event vocabulary through this facade gains no runtime edge to the Gateway implementation.
|
||||
The Client assembly mounts Office conversion, Commands, Agent Teams, credentials, settings, Goal, Schedule, dynamic Cordis, file and Session references, read-only Host plugin inventory, plugin-installation registry response comparison, connector accounts, message feedback, permission presets, Session Controller, subagents, web provider list, and Workspace Controller contributions. The `permissionPresets` namespace returns the complete process-level catalog used by current-session controls. Cordis effect ownership withdraws every contribution when this assembly unloads, while `@deepseek-ai/dsh-api-gateway/client` owns descriptor validation, traced namespace Services, direct and scoped methods, invocation, streams, and cancellation. The Client entry consumes the shared `TypertClientRemote` interface through Cordis and does not import the concrete Gateway. It re-exports the Gateway Client face's declaration merges type-only, so a consumer reaching the forwarded-event vocabulary through this facade gains no runtime edge to the Gateway implementation.
|
||||
|
||||
This facade is also the front door for the wire type vocabulary a Client package names. It re-exports, type-only, the Remote failure vocabulary (`RemoteResult`, `RemoteFailure`, `RemoteErrorCode`, `RemoteErrorDetailsMap`), the Host facts (`RemoteHostFacts`), and each selected domain's client-safe payload types, so a Client feature package imports one specifier instead of reaching into `dsh-typert-protocol`, the Gateway, or an owner's Host entry. Two kinds of package deliberately skip this door: the API-layer packages this assembly itself selects — importing it back would close a dependency cycle — and their tests, which take the failure vocabulary from `dsh-typert-protocol` directly. A UI package's tests instead take the `RemoteError` constructor from [`dsh-client-test-runtime`](../../test-support/client-runtime/README.md).
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ kind: "package-reference"
|
||||
|
||||
[`@deepseek-ai/dsh-api-session-controller`](../session-controller/README.zh.md) 拥有 agent(智能体)与会话身份策略,包括供其他 namespace 使用的 Typert lookup 解析器。本包选择并挂载生成的会话 contribution,无需直接依赖 `@deepseek-ai/dsh-session` 的运行时;激活策略由会话控制器负责。
|
||||
|
||||
Client 组合挂载 Office 转换、Commands、Agent Teams、凭据、settings、Goal、Schedule、动态 Cordis、文件与会话引用、只读 Host 插件清单、插件安装源响应比较、消息反馈、权限预设、会话控制器、subagents、Web 提供方列表和 Workspace 控制器 contribution。`permissionPresets` namespace 返回 current-session 控件使用的完整进程级目录。该组合卸载时,Cordis effect 的所有权机制会撤回所有贡献;`@deepseek-ai/dsh-api-gateway/client` 负责描述符校验、可追踪的 namespace 服务、直接与作用域方法、调用、流与取消。Client 入口通过 Cordis 消费共享的 `TypertClientRemote` 接口,不导入具体 Gateway;它只以 type-only 形式重新导出 Gateway Client face 的声明合并,因此消费端经由本外观取到转发事件词汇时,运行时不会多出一条通往 Gateway 实现的边。
|
||||
Client 组合挂载 Office 转换、Commands、Agent Teams、凭据、settings、Goal、Schedule、动态 Cordis、文件与会话引用、只读 Host 插件清单、插件安装源响应比较、连接器账号、消息反馈、权限预设、会话控制器、subagents、Web 提供方列表和 Workspace 控制器 contribution。`permissionPresets` namespace 返回 current-session 控件使用的完整进程级目录。该组合卸载时,Cordis effect 的所有权机制会撤回所有贡献;`@deepseek-ai/dsh-api-gateway/client` 负责描述符校验、可追踪的 namespace 服务、直接与作用域方法、调用、流与取消。Client 入口通过 Cordis 消费共享的 `TypertClientRemote` 接口,不导入具体 Gateway;它只以 type-only 形式重新导出 Gateway Client face 的声明合并,因此消费端经由本外观取到转发事件词汇时,运行时不会多出一条通往 Gateway 实现的边。
|
||||
|
||||
本 facade 同时是 Client 包指称 wire 类型词汇的正门。它以 type-only 方式转出 Remote 失败词汇(`RemoteResult`、`RemoteFailure`、`RemoteErrorCode`、`RemoteErrorDetailsMap`)、Host 事实(`RemoteHostFacts`),以及各已选领域对 Client 安全的载荷类型,因此 Client 功能包只 import 一个 specifier,不必伸手进 `dsh-typert-protocol`、Gateway 或某个拥有方的 Host 入口。有两类包刻意不走这道门:本装配自己选中的 API 层包——反向 import 会形成依赖环——以及它们的测试,后者直接从 `dsh-typert-protocol` 取失败词汇。UI 包的测试则从 [`dsh-client-test-runtime`](../../test-support/client-runtime/README.zh.md) 取 `RemoteError` 构造器。
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
"@deepseek-ai/dsh-plugin-manager": "workspace:*",
|
||||
"@deepseek-ai/dsh-mcp-manager": "workspace:*",
|
||||
"@deepseek-ai/dsh-plugin-market": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-connector-account": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-plugin-manager": "workspace:*",
|
||||
"@deepseek-ai/dsh-office-kit": "workspace:*",
|
||||
"@deepseek-ai/dsh-deepseek-account": "workspace:*",
|
||||
|
||||
@@ -19,6 +19,7 @@ import pluginManagerRemote from '@deepseek-ai/dsh-plugin-manager/remote'
|
||||
import mcpManagerRemote from '@deepseek-ai/dsh-mcp-manager/remote'
|
||||
import toolResultsRemote from '@deepseek-ai/dsh-client-ui-trajectory/remote'
|
||||
import pluginRegistryProbeRemote from '@deepseek-ai/dsh-client-ui-plugin-manager/remote'
|
||||
import connectorAccountsRemote from '@deepseek-ai/dsh-client-ui-connector-account/remote'
|
||||
import pluginMarketRemote from '@deepseek-ai/dsh-plugin-market/remote'
|
||||
import pluginInventoryRemote from '@deepseek-ai/dsh-host-plugin-inventory/remote'
|
||||
import messageFeedbackRemote from '@deepseek-ai/dsh-message-feedback/remote'
|
||||
@@ -48,6 +49,7 @@ export type { McpManagedServerStatus, McpManagedServerView } from '@deepseek-ai/
|
||||
export type {} from '@deepseek-ai/dsh-plugin-manager/remote'
|
||||
export type {} from '@deepseek-ai/dsh-mcp-manager/remote'
|
||||
export type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/remote'
|
||||
export type {} from '@deepseek-ai/dsh-client-ui-connector-account/remote'
|
||||
export type {} from '@deepseek-ai/dsh-client-ui-trajectory/remote'
|
||||
export type {} from '@deepseek-ai/dsh-plugin-market/remote'
|
||||
export type {
|
||||
@@ -200,6 +202,7 @@ export async function apply(ctx: Context): Promise<() => Promise<void>> {
|
||||
productAnalyticsRemote, agentPresetsRemote, commandsRemote, agentTeamsRemote, settingsControllerRemote, accountRemote,
|
||||
goalsRemote, llmRemote, dynamicRemote, scheduleRemote,
|
||||
pluginInventoryRemote, pluginManagerRemote, mcpManagerRemote, pluginMarketRemote, pluginRegistryProbeRemote,
|
||||
connectorAccountsRemote,
|
||||
toolResultsRemote,
|
||||
messageFeedbackRemote, sessionFeedbackRemote,
|
||||
fileUploadsRemote, sessionReferencesRemote,
|
||||
|
||||
@@ -341,6 +341,11 @@
|
||||
- id: ui-plugin-manager
|
||||
name: '@deepseek-ai/dsh-client-ui-plugin-manager'
|
||||
|
||||
# Connector account sections on the Plugins page; CLI app plugins and MCP
|
||||
# connectors register their accounts with `ctx.connectorAccounts`.
|
||||
- id: ui-connector-account
|
||||
name: '@deepseek-ai/dsh-client-ui-connector-account'
|
||||
|
||||
# Read-only Plugin list tab in the Settings Plugins section; the built-in
|
||||
# bundles the sidebar page leaves out are inspected here.
|
||||
- id: ui-settings-plugin-inventory
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
"@deepseek-ai/dsh-client-ui-brand-official": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-chat": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-commands": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-connector-account": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-context-menu": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-conversation": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-cordis": "workspace:*",
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: 1eb35b015a6c423f
|
||||
zh: a8a3dceee2c9e943
|
||||
/client-web-gui-browser-half/packages:
|
||||
en: 2165938f26300774
|
||||
zh: 5f739534a8509545
|
||||
en: affd6d8506276e34
|
||||
zh: 92730ec91d83d609
|
||||
/client-web-gui-browser-half/related-documentation:
|
||||
en: d1d506e68fab7333
|
||||
zh: 1a90fe6f3f8f24a9
|
||||
|
||||
@@ -83,6 +83,7 @@ The kernel packages boot and serve the page; the UI feature packages present it.
|
||||
| [`ui-settings-subagent/`](ui-settings-subagent/README.md) | Provides the Subagent settings page on the Plugins page | — |
|
||||
| [`ui-settings-web-search/`](ui-settings-web-search/README.md) | Provides the web search and fetch settings page on the Plugins page | — |
|
||||
| [`ui-plugin-manager/`](ui-plugin-manager/README.md) | Contributes the sidebar Plugins panel: install, enable, disable, retry, and compose installed packages | — |
|
||||
| [`ui-connector-account/`](ui-connector-account/README.md) | Holds the accounts connector plugins register on the Host and shows each bundle's account section, tag, activation prompt, confirmations, and notices on the Plugins page | `ctx.connectorAccounts` |
|
||||
| [`ui-entry-customization/`](ui-entry-customization/README.md) | Adds region-local More menus that pin or unpin plugin launchers and start a plugin draft | — |
|
||||
| [`ui-plugin-market/`](ui-plugin-market/README.md) | Contributes the Discover tab to the Plugins page: browse market indexes and install their bundles | — |
|
||||
| [`ui-settings-plugin-inventory/`](ui-settings-plugin-inventory/README.md) | Contributes the read-only Host Loader inventory tab to Plugins settings | — |
|
||||
|
||||
@@ -83,6 +83,7 @@ kind: "package-group"
|
||||
| [`ui-settings-subagent/`](ui-settings-subagent/README.zh.md) | 在插件页提供子智能体设置页 | — |
|
||||
| [`ui-settings-web-search/`](ui-settings-web-search/README.zh.md) | 在插件页提供网页搜索与获取设置页 | — |
|
||||
| [`ui-plugin-manager/`](ui-plugin-manager/README.zh.md) | 贡献侧栏的“插件”面板:安装、启用、停用、重试与组合已安装的包 | — |
|
||||
| [`ui-connector-account/`](ui-connector-account/README.zh.md) | 保存连接器插件在 Host 上注册的账号,并在插件页显示每个插件包的账号区块、标签、开启引导、确认和提示 | `ctx.connectorAccounts` |
|
||||
| [`ui-entry-customization/`](ui-entry-customization/README.zh.md) | 添加分区域的“更多”菜单,固定或收起插件入口,并开始创建插件的草稿 | — |
|
||||
| [`ui-plugin-market/`](ui-plugin-market/README.zh.md) | 为“插件”页面贡献“发现”标签页:浏览市场索引并安装其中的组合包 | — |
|
||||
| [`ui-settings-plugin-inventory/`](ui-settings-plugin-inventory/README.zh.md) | 向「插件」设置贡献只读的 Host Loader 清单标签页 | — |
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/client/ui-connector-account/README.md
|
||||
/:
|
||||
en: f09638e4097c52fb
|
||||
zh: 2fb344b05a189ad0
|
||||
/deepseek-ai-dsh-client-ui-connector-account:
|
||||
en: bdb528546ec26353
|
||||
zh: 0dd55dbc0c8e837a
|
||||
/deepseek-ai-dsh-client-ui-connector-account/summary:
|
||||
en: b25fc16fb18a63c1
|
||||
zh: 4508e8a44745b08d
|
||||
/deepseek-ai-dsh-client-ui-connector-account/table-of-contents:
|
||||
en: d152484eb41ac6b4
|
||||
zh: 5b6bd00fce5371c3
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package:
|
||||
en: 9d8d49a0b1b3ce24
|
||||
zh: 8eba3710036afa00
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/register-an-account:
|
||||
en: e618281ea7721daf
|
||||
zh: a5d5f5e307ea3435
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/present-the-section:
|
||||
en: 73ca134d685b5872
|
||||
zh: 05b929fd28dc955e
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/following-operations:
|
||||
en: a9e64f316efcac3e
|
||||
zh: d059d31b65573bf5
|
||||
/deepseek-ai-dsh-client-ui-connector-account/use-this-package/shared-copy:
|
||||
en: f88db8d50a68a0ca
|
||||
zh: 6169fd1ffc9c79a0
|
||||
/deepseek-ai-dsh-client-ui-connector-account/understand-the-implementation:
|
||||
en: da424b56f995bef5
|
||||
zh: 298fc8e50149fea5
|
||||
/deepseek-ai-dsh-client-ui-connector-account/further-exploration:
|
||||
en: 029949903a73d283
|
||||
zh: 6f9a8c2f7620de69
|
||||
/deepseek-ai-dsh-client-ui-connector-account/model-experience:
|
||||
en: bdbc56a07884f8d6
|
||||
zh: 22ca2ee613472c0b
|
||||
/deepseek-ai-dsh-client-ui-connector-account/model-experience/kv-cache-effect:
|
||||
en: 4cd0965a7997970e
|
||||
zh: 690e5a9d945f7f6e
|
||||
/deepseek-ai-dsh-client-ui-connector-account/known-limitations-and-deferred-work:
|
||||
en: d2c5f54b80b86b15
|
||||
zh: 8b637f97ac1d0223
|
||||
/deepseek-ai-dsh-client-ui-connector-account/known-limitations-and-deferred-work/dev-note:
|
||||
en: 2ab3c4acae06850c
|
||||
zh: bd2093ba1fdd6860
|
||||
@@ -0,0 +1,138 @@
|
||||
---
|
||||
description: "Register a connector plugin's account on the Host with `ctx.connectorAccounts` and show its section, title tag, activation prompt, confirmations, and notices on the Plugins page through one `connectorAccounts` Remote, with the registrant's own text and the shared copy of this package."
|
||||
kind: "package-reference"
|
||||
---
|
||||
|
||||
# @deepseek-ai/dsh-client-ui-connector-account
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
## Summary
|
||||
|
||||
Connector plugins register their account on the Host with `ctx.connectorAccounts` to show it on the Plugins page: CLI app plugins register the account their vendor CLI keeps, and MCP connectors their OAuth server's account. The Host decides what the page shows and does: each registrant maps its account to a display, and the registry starts or cancels only the operations the account lists. The browser half renders each bundle's section, title tag, and activation prompt, and opens authorization pages and reports notices only in the browser that started the operation. The Web and Desktop compositions load both halves through [`dsh-web-app`](../../bundle/web-app/README.md).
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Use this package](#use-this-package)
|
||||
- [Understand the implementation](#understand-the-implementation)
|
||||
- [Further Exploration](#further-exploration)
|
||||
- [Model Experience](#model-experience)
|
||||
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
||||
- [Dev Note](#dev-note)
|
||||
|
||||
-----
|
||||
|
||||
<a id="use-this-package"></a>
|
||||
## Use this package
|
||||
|
||||
A registrant's Host row registers its account once; the registrant ships no browser code for the account.
|
||||
|
||||
### Register an account
|
||||
|
||||
The registrant's Host row registers its account source while the registry runs, so a composition without the registry, such as a headless profile, skips the registration:
|
||||
|
||||
```ts ignore-check
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-connector-account'
|
||||
|
||||
export function apply(ctx: Context): void {
|
||||
const account = new AcmeAccount(options)
|
||||
ctx.effect(() => () => account.dispose(), 'acme: account')
|
||||
ctx.inject(['connectorAccounts'], (scope) => {
|
||||
scope.effect(() => scope.connectorAccounts.register({
|
||||
key: '@acme/cli', packageName: '@acme/cli', source: account, copy,
|
||||
operations: [{ kind: 'check' }, { kind: 'connect', notice: { en: 'Acme connected', zh: 'Acme 已连接' } }],
|
||||
present: presentAccount,
|
||||
}), 'acme: Plugins page account')
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
- `key` identifies the account in the Remote; the page passes it back to start and cancel operations. A second registration with the same key throws.
|
||||
- `packageName` is the npm package whose bundle page carries the section and tag; a package carries at most one account. An account without one, such as a server configured in Settings, appears on no bundle page.
|
||||
- `source` is the account: its current view, change observation, a check, and starting and cancelling operations.
|
||||
- `operations` lists the kinds a page button may start, each with the optional text its success reports in the browser that started it; the registry rejects any other kind.
|
||||
- `copy` holds the section title, the hint under it, and the activation prompt's title, body, and Connect label.
|
||||
|
||||
The registrant imports the registry's types with `import type` from the package root or `./types`. The returned disposer withdraws the account from every page.
|
||||
|
||||
### Present the section
|
||||
|
||||
`present(view)` maps the account view to a `ConnectorAccountDisplay`: the phase, the status line, the optional title tag, buttons, the operation Connect starts in the activation prompt, detail, notes, and failure with its untranslated diagnostic items. The registry calls it for every stream on each change, so it only maps the view. Every string is `LocalizedText`, which each browser resolves in its active language. A button carries a command: `start` with one of the registered operation kinds, `cancel` for the operation in progress, which the source ignores in a phase that is not cancellable, or `open` to reopen its authorization page. A button with `confirm` asks first and runs only after the user accepts.
|
||||
|
||||
| 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 |
|
||||
| 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 dismisses itself once the phase settles elsewhere |
|
||||
| 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
|
||||
|
||||
Each browser opens one stream when the Web app loads, and the Host checks every account that runs no operation for each new stream; an account registered while a stream is open is checked at once. A browser follows the operation its latest start returned, from that answer until the stream delivers the operation's result. Each page the followed operation offers opens once in a new tab, over HTTPS or over HTTP on a loopback address; other browsers show the same section but open no page and report no notice. A second click before the first call answers starts nothing. A stream that fails for good shows the account service as not running with Retry, which reopens the stream once however often it is pressed. Unloading the browser half closes the stream; Host-owned operations keep running.
|
||||
|
||||
### Shared copy
|
||||
|
||||
The `connectorAccount` dictionary holds the copy every account shares: Close, Cancel, Retry, Later, the diagnostic label, the failure notice, and the not-running status, tag, and detail. Every other string comes from the registrant.
|
||||
|
||||
-----
|
||||
|
||||
<a id="understand-the-implementation"></a>
|
||||
## Understand the implementation
|
||||
|
||||
<details>
|
||||
<summary>Implementation internals — click to expand</summary>
|
||||
|
||||
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 or has stopped, 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.
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| [`src/index.ts`](src/index.ts) | The `ctx.connectorAccounts` registry and its Remote |
|
||||
| [`src/types.ts`](src/types.ts) | Registration, source, view, display, and entry types |
|
||||
| [`src/client/index.ts`](src/client/index.ts) | The browser entry: the dictionary and the slot registrations |
|
||||
| [`src/client/state.ts`](src/client/state.ts) | The stream store, the operations this browser started, and their pages and notices |
|
||||
| [`src/client/components.tsx`](src/client/components.tsx) | The surfaces, the slot entries, and the buttons' Remote calls |
|
||||
| [`src/client/locales.ts`](src/client/locales.ts) | The shared dictionary |
|
||||
| [`src/client/types.ts`](src/client/types.ts) | Browser state, notice, Remote, and face types |
|
||||
|
||||
</details>
|
||||
|
||||
-----
|
||||
|
||||
<a id="further-exploration"></a>
|
||||
## Further Exploration
|
||||
|
||||
- [Plugin manager page](../ui-plugin-manager/README.md) — the Plugins page and its bundle slots.
|
||||
- [Client package map](../README.md) — adjacent browser UI packages.
|
||||
|
||||
-----
|
||||
|
||||
<a id="model-experience"></a>
|
||||
## Model Experience
|
||||
|
||||
None, as the registry and its surfaces are Plugins page UI and add no model input. Each registrant documents the tools and skills its account enables.
|
||||
|
||||
#### KV Cache effect
|
||||
|
||||
None; registering or removing an account changes no model-visible text.
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
<a id="known-limitations-and-deferred-work"></a>
|
||||
|
||||
- The five display phases are fixed; a registrant maps any further account state onto one of them.
|
||||
- A registrant whose Host row fails to load shows no account section; the Plugins page still lists the bundle with its load failure.
|
||||
- Each browser that loads the Web app starts a check of every idle account.
|
||||
- The Web and Desktop compositions load the registry whether or not a connector plugin is installed.
|
||||
- An authorization page that opens after the call answers can be blocked by the browser; the section's open button shows it again.
|
||||
|
||||
<a id="dev-note"></a>
|
||||
### Dev Note
|
||||
|
||||
<details>
|
||||
<summary>Working context for maintainers — click to expand</summary>
|
||||
|
||||
Host specs drive the registry with fake account sources. Client specs drive `BrowserAccounts` with a fake Remote stream, render the surfaces with the Chinese dictionary and a fake Remote, and mount the browser half against a real slot registry and locale runtime.
|
||||
|
||||
</details>
|
||||
@@ -0,0 +1,138 @@
|
||||
---
|
||||
description: "通过 `ctx.connectorAccounts` 在 Host 上注册连接器插件的账号,并经由一个 `connectorAccounts` Remote 在插件页显示其区块、标题旁标签、开启引导、确认和提示,文案来自注册方自己的文本和本包的共用文案。"
|
||||
kind: "package-reference"
|
||||
---
|
||||
|
||||
# @deepseek-ai/dsh-client-ui-connector-account
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
## 概述
|
||||
|
||||
连接器插件在 Host 上通过 `ctx.connectorAccounts` 注册账号,在插件页显示账号:CLI 应用插件注册其厂商 CLI 保存的账号,MCP 连接器注册其 OAuth 服务器的账号。页面显示什么、能做什么由 Host 决定:每个注册方把自己的账号映射为展示内容,注册表只启动或取消该账号列出的操作。浏览器一半渲染每个插件包的区块、标题旁标签和开启引导,并且只在发起操作的浏览器中打开授权页、报告提示。Web 与桌面端组合通过 [`dsh-web-app`](../../bundle/web-app/README.zh.md) 加载这两半。
|
||||
|
||||
## 目录
|
||||
|
||||
- [使用此包](#use-this-package)
|
||||
- [理解实现](#understand-the-implementation)
|
||||
- [延伸阅读](#further-exploration)
|
||||
- [模型体验](#model-experience)
|
||||
- [已知限制与后续工作](#known-limitations-and-deferred-work)
|
||||
- [开发备注](#dev-note)
|
||||
|
||||
-----
|
||||
|
||||
<a id="use-this-package"></a>
|
||||
## 使用此包
|
||||
|
||||
注册方的 Host 行注册一次账号;注册方不为账号提供任何浏览器代码。
|
||||
|
||||
### 注册账号
|
||||
|
||||
注册方的 Host 行在注册表运行时注册其账号来源,因此没有注册表的组合(如 headless profile)会跳过注册:
|
||||
|
||||
```ts ignore-check
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-connector-account'
|
||||
|
||||
export function apply(ctx: Context): void {
|
||||
const account = new AcmeAccount(options)
|
||||
ctx.effect(() => () => account.dispose(), 'acme: account')
|
||||
ctx.inject(['connectorAccounts'], (scope) => {
|
||||
scope.effect(() => scope.connectorAccounts.register({
|
||||
key: '@acme/cli', packageName: '@acme/cli', source: account, copy,
|
||||
operations: [{ kind: 'check' }, { kind: 'connect', notice: { en: 'Acme connected', zh: 'Acme 已连接' } }],
|
||||
present: presentAccount,
|
||||
}), 'acme: Plugins page account')
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
- `key` 在 Remote 中标识该账号;页面启动和取消操作时把它传回。用同一个键再次注册会抛出异常。
|
||||
- `packageName` 是其插件包页面承载区块和标签的 npm 包;一个包最多承载一个账号。没有包名的账号(如在 Settings 中配置的服务器)不出现在任何插件包页面上。
|
||||
- `source` 是账号:其当前视图、变化观察、检查,以及启动和取消操作。
|
||||
- `operations` 列出页面按钮可以启动的操作类型,每项可带该操作成功时在发起它的浏览器中报告的文本;注册表拒绝其他类型。
|
||||
- `copy` 包含区块标题、区块下方的提示,以及开启引导的标题、正文和连接按钮文案。
|
||||
|
||||
注册方用 `import type` 从包根或 `./types` 导入注册表的类型。返回的销毁函数会把账号从所有页面撤下。
|
||||
|
||||
### 展示区块
|
||||
|
||||
`present(view)` 把账号视图映射为 `ConnectorAccountDisplay`:阶段、状态行、可选的标题旁标签、按钮、开启引导中“连接”启动的操作、说明、附加行,以及带不翻译诊断项的失败信息。注册表在每次变化时为每条流调用它,因此它只做视图映射。所有文案都是 `LocalizedText`,由各浏览器按当前语言解析。按钮携带一个命令:`start` 启动某个已注册的操作类型,`cancel` 取消进行中的操作(处于不可取消的阶段时来源会忽略),`open` 重新打开其授权页。带 `confirm` 的按钮会先询问,用户确认后才执行。
|
||||
|
||||
| 界面 | 行为 |
|
||||
|---|---|
|
||||
| 区块 | 标题、状态、按钮、说明、附加行、失败信息和提示。区块发起的调用未返回,或 Host 流中断时,按钮不可用。失败时先显示注册方的文案,再显示其诊断项 |
|
||||
| 标题旁标签 | 显示 display 的 `badge`,只出现在已启用插件包的页面或其某一行的页面上,且只在 display 带有标签时显示 |
|
||||
| 开启引导 | 插件包开启后,阶段为 `disconnected` 时打开;“连接”会打开插件包页面,并在 display 给出 `connect` 时启动该操作。阶段确定为其他值后自动关闭 |
|
||||
| 提示 | 本浏览器的最新结果,不受插件面板生命周期限制:操作成功的文本,或带警告图标的共用失败文案 |
|
||||
|
||||
### 跟随操作
|
||||
|
||||
每个浏览器在 Web 应用加载时打开一条流,Host 为每条新流检查每个没有在运行操作的账号;流打开期间注册的账号会立即检查。浏览器跟随其最近一次启动返回的操作,从返回时起,直到流推送该操作的结果。被跟随的操作提供的每个页面只在新标签页中打开一次,只打开 HTTPS 页面或回环地址上的 HTTP 页面;其他浏览器显示同样的区块,但不打开页面,也不报告提示。第一次调用返回前的第二次点击不会启动任何操作。流永久失败时,区块显示账号服务未运行,并提供“重试”;无论按多少次,都只重新打开流一次。卸载浏览器一半会关闭流;Host 持有的操作继续运行。
|
||||
|
||||
### 共用文案
|
||||
|
||||
`connectorAccount` 字典包含所有账号共用的文案:关闭、取消、重试、稍后、排障信息标签、失败提示,以及未运行时的状态、标签和说明。其余文案都来自注册方。
|
||||
|
||||
-----
|
||||
|
||||
<a id="understand-the-implementation"></a>
|
||||
## 理解实现
|
||||
|
||||
<details>
|
||||
<summary>实现细节——点击展开</summary>
|
||||
|
||||
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 撤下的账号会失去其插件包条目;卸载时撤下所有条目和流。
|
||||
|
||||
| 文件 | 职责 |
|
||||
|---|---|
|
||||
| [`src/index.ts`](src/index.ts) | `ctx.connectorAccounts` 注册表及其 Remote |
|
||||
| [`src/types.ts`](src/types.ts) | 注册、来源、视图、display 和条目类型 |
|
||||
| [`src/client/index.ts`](src/client/index.ts) | 浏览器入口:字典和插槽注册 |
|
||||
| [`src/client/state.ts`](src/client/state.ts) | 流的 store、本浏览器发起的操作,以及它们的页面和提示 |
|
||||
| [`src/client/components.tsx`](src/client/components.tsx) | 各界面、插槽条目,以及按钮的 Remote 调用 |
|
||||
| [`src/client/locales.ts`](src/client/locales.ts) | 共用字典 |
|
||||
| [`src/client/types.ts`](src/client/types.ts) | 浏览器状态、提示、Remote 和 face 类型 |
|
||||
|
||||
</details>
|
||||
|
||||
-----
|
||||
|
||||
<a id="further-exploration"></a>
|
||||
## 延伸阅读
|
||||
|
||||
- [插件管理页](../ui-plugin-manager/README.zh.md)——插件页及其插件包插槽。
|
||||
- [客户端包地图](../README.zh.md)——相邻的浏览器 UI 包。
|
||||
|
||||
-----
|
||||
|
||||
<a id="model-experience"></a>
|
||||
## 模型体验
|
||||
|
||||
无,注册表及其界面属于插件页 UI,不增加模型输入。各注册方自行说明其账号启用的工具和技能。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
无;注册或移除账号不改变任何模型可见文本。
|
||||
|
||||
## 已知限制与后续工作
|
||||
|
||||
<a id="known-limitations-and-deferred-work"></a>
|
||||
|
||||
- 五个显示阶段固定不变;注册方需把其他账号状态映射到其中之一。
|
||||
- Host 行加载失败的注册方不显示账号区块;插件页仍会列出该插件包及其加载失败。
|
||||
- 每个加载 Web 应用的浏览器都会触发一次对所有空闲账号的检查。
|
||||
- 无论是否安装了连接器插件,Web 与桌面端组合都会加载注册表。
|
||||
- 调用返回后才打开的授权页可能被浏览器拦截;区块中的打开按钮可以再次打开它。
|
||||
|
||||
<a id="dev-note"></a>
|
||||
### 开发备注
|
||||
|
||||
<details>
|
||||
<summary>维护者工作上下文——点击展开</summary>
|
||||
|
||||
Host 测试用假的账号来源驱动注册表。客户端测试用假的 Remote 流驱动 `BrowserAccounts`,用中文字典和假的 Remote 渲染各界面,并在真实的插槽注册表和 locale 运行时上挂载浏览器一半。
|
||||
|
||||
</details>
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Connector-Kontoverbindung",
|
||||
"description": "Kontobereich, Titel-Tag, Aktivierungshinweis und Benachrichtigungen auf der Seite „Plugins“ für Connector-Plugins."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Connector account connection",
|
||||
"description": "Account section, title tag, activation prompt, and notices on the Plugins page for connector plugins."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Conexión de cuenta de conectores",
|
||||
"description": "Sección de cuenta, etiqueta del título, aviso de activación y notificaciones en la página Complementos para los complementos de conectores."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Connexion de compte de connecteur",
|
||||
"description": "Section de compte, étiquette de titre, invite d’activation et notifications sur la page Plugins pour les plugins de connecteur."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "コネクターアカウント接続",
|
||||
"description": "コネクタープラグイン向けに、「プラグイン」ページでのアカウントセクション、タイトルタグ、有効化時の案内、通知を提供します。"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Conexão de conta de conector",
|
||||
"description": "Seção da conta, etiqueta do título, aviso de ativação e notificações na página Plug-ins para plugins de conector."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Подключение аккаунта коннектора",
|
||||
"description": "Раздел аккаунта, метка у заголовка, подсказка при включении и уведомления на странице «Плагины» для плагинов-коннекторов."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "连接器账号连接",
|
||||
"description": "在插件页为连接器插件提供账号区块、标题标签、开启引导与提示。"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-client-ui-connector-account",
|
||||
"description": "Connector account surfaces: the Host registry CLI app plugins and MCP connectors register their accounts with, and the Plugins page section, title tag, activation prompt, and notices it serves over one Remote",
|
||||
"version": "0.2.2-rc.1",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
||||
"directory": "packages/client/ui-connector-account"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./client": {
|
||||
"types": "./lib/types/client/index.d.ts",
|
||||
"default": "./lib/client.js"
|
||||
},
|
||||
"./types": {
|
||||
"types": "./lib/types/types.d.ts"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json",
|
||||
"./typert": {
|
||||
"types": "./lib/typert.host.d.ts",
|
||||
"default": "./lib/typert.host.js"
|
||||
},
|
||||
"./remote": {
|
||||
"types": "./lib/typert.remote-client.d.ts",
|
||||
"default": "./lib/typert.remote-client.js"
|
||||
},
|
||||
"./locale/*.json": "./locale/*.json"
|
||||
},
|
||||
"dsh": {
|
||||
"client": {
|
||||
"inject": [
|
||||
"@deepseek-ai/dsh-api-remotes",
|
||||
"@deepseek-ai/dsh-client-locale",
|
||||
"@deepseek-ai/dsh-client-ui-layout",
|
||||
"@deepseek-ai/dsh-client-ui-plugin-manager"
|
||||
],
|
||||
"platform": "web"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "tsdown",
|
||||
"watch": "tsdown --watch"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@deepseek-ai/dsh-typert-protocol": "workspace:*",
|
||||
"zod": "4.6.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-api-gateway": "workspace:*",
|
||||
"@deepseek-ai/dsh-api-remotes": "workspace:*",
|
||||
"@deepseek-ai/dsh-brand": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-locale": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-store": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-test-runtime": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-layout": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-plugin-manager": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-primitives": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-renderer": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-slots": "workspace:*",
|
||||
"@deepseek-ai/dsh-package-manifest": "workspace:*",
|
||||
"@deepseek-ai/dsh-util-values": "workspace:*",
|
||||
"@testing-library/react": "^16.3.3",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"files": [
|
||||
"locale/*.json",
|
||||
"lib/index.js",
|
||||
"lib/client.js",
|
||||
"lib/types/**/*.d.ts",
|
||||
"lib/types/**/*.d.ts.map",
|
||||
"lib/**/*.js.map",
|
||||
"lib/typert.host.js",
|
||||
"lib/typert.host.d.ts",
|
||||
"lib/typert.remote-client.js",
|
||||
"lib/typert.remote-client.d.ts",
|
||||
"lib/typert.remote-client.d.ts.map",
|
||||
"src"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0 0 4px;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.detail,
|
||||
.hint,
|
||||
.failure {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.detail {
|
||||
color: var(--dsw-alias-label-secondary);
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
}
|
||||
|
||||
.failure {
|
||||
color: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
/**
|
||||
* The account surfaces the Plugins page shows for registered connector accounts: a bundle's section, title tag, and
|
||||
* activation prompt, the confirmation a button asks for, and the notice, with the slot entries that read them.
|
||||
*/
|
||||
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 { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { assertNever } from '@deepseek-ai/dsh-util-values'
|
||||
import type {
|
||||
ConnectorAccountButton, ConnectorAccountCommand, ConnectorAccountEntry, ConnectorAccountFailure, ConnectorAccountPhase,
|
||||
} from '../types.ts'
|
||||
import css from './ConnectorAccount.module.css'
|
||||
import type { ConnectorAccountKey } from './locales.ts'
|
||||
import { openAuthorizationPage } from './state.ts'
|
||||
import type { ConnectorAccountFace, ConnectorAccountNotice, ConnectorAccountsState, ConnectorBundleAccountFace } from './types.ts'
|
||||
|
||||
type FaceProps = InjectFace<ConnectorAccountFace> & { t: Translate<ConnectorAccountKey> }
|
||||
type BundleFaceProps = InjectFace<ConnectorBundleAccountFace> & { t: Translate<ConnectorAccountKey> }
|
||||
type Resolve = (text: LocalizedText) => string
|
||||
/** The phase a surface shows: the Host's, or `stopped` once this browser's stream failed for good. */
|
||||
type ShownPhase = ConnectorAccountPhase | 'stopped'
|
||||
|
||||
const TONE: Record<ShownPhase, StateDotState> = {
|
||||
checking: 'ongoing', connecting: 'ongoing', connected: 'done', disconnected: 'idle', unavailable: 'warning', stopped: 'warning',
|
||||
}
|
||||
|
||||
const BADGE_TONE: Record<ShownPhase, TagTone> = {
|
||||
checking: 'outline', connecting: 'info', connected: 'success', disconnected: 'outline', unavailable: 'warning', stopped: 'warning',
|
||||
}
|
||||
|
||||
function shownPhase(entry: ConnectorAccountEntry, stopped: boolean): ShownPhase {
|
||||
return stopped ? 'stopped' : entry.display.phase
|
||||
}
|
||||
|
||||
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 section 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.
|
||||
*/
|
||||
function useAccountCommand(
|
||||
face: Pick<FaceProps, 'remote' | 'follow' | 'failed'>,
|
||||
): { readonly busy: boolean; readonly run: (entry: ConnectorAccountEntry, command: ConnectorAccountCommand) => void } {
|
||||
const [busy, setBusy] = useState(false)
|
||||
// A second click before the re-render still finds the first call pending.
|
||||
const pending = useRef(false)
|
||||
const call = (operation: () => Promise<void>): void => {
|
||||
if (pending.current) return
|
||||
pending.current = true
|
||||
setBusy(true)
|
||||
// The Host keeps the diagnostic; the page reports one retryable outcome.
|
||||
void operation().catch(() => { face.failed() }).finally(() => { pending.current = false; setBusy(false) })
|
||||
}
|
||||
const run = (entry: ConnectorAccountEntry, command: ConnectorAccountCommand): void => {
|
||||
const { key } = entry
|
||||
switch (command.kind) {
|
||||
case 'start':
|
||||
call(async () => { face.follow(key, await settle(face.remote.start(key, command.operation))) })
|
||||
return
|
||||
case 'cancel': {
|
||||
const operation = entry.operation
|
||||
if (operation !== undefined) call(async () => { await settle(face.remote.cancel(key, operation.id)) })
|
||||
return
|
||||
}
|
||||
case 'open':
|
||||
openAuthorizationPage(entry.operation?.authorizationUrl)
|
||||
return
|
||||
/* v8 ignore next -- closed command union */
|
||||
default: assertNever(command)
|
||||
}
|
||||
}
|
||||
return { busy, run }
|
||||
}
|
||||
|
||||
/** What the section shows about one account in this browser. */
|
||||
export interface ConnectorAccountSectionProps {
|
||||
readonly t: Translate<ConnectorAccountKey>
|
||||
readonly resolveText: Resolve
|
||||
readonly entry: ConnectorAccountEntry
|
||||
/** Whether the Host stream is delivering. */
|
||||
readonly linked: boolean
|
||||
/** Whether the Host stream failed for good. */
|
||||
readonly stopped: boolean
|
||||
/** Whether a call the section made has not answered. */
|
||||
readonly busy: boolean
|
||||
readonly onCommand: (command: ConnectorAccountCommand) => void
|
||||
readonly onRetry: () => void
|
||||
}
|
||||
|
||||
function describe(t: Translate<ConnectorAccountKey>, failure: ConnectorAccountFailure): string | undefined {
|
||||
const details = failure.details ?? []
|
||||
return details.length === 0 ? undefined : t('failure.details', { details: details.join(' · ') })
|
||||
}
|
||||
|
||||
/**
|
||||
* The account section on a bundle page.
|
||||
* @param props - the account, the stream state, the command and retry callbacks, and the translators.
|
||||
* @returns the title, status line, detail, rows, failure, hint, and the confirmation a button asked for.
|
||||
*/
|
||||
export function ConnectorAccountSection(props: ConnectorAccountSectionProps): ReactNode {
|
||||
const { t, resolveText, entry, linked, stopped, busy, onCommand, onRetry } = props
|
||||
const [confirming, setConfirming] = useState<ConnectorAccountButton>()
|
||||
const display = entry.display
|
||||
const phase = shownPhase(entry, stopped)
|
||||
// Reopening a stopped stream is the one action that does not need the Host stream.
|
||||
const disabled = busy || (!linked && !stopped)
|
||||
const button = (item: ConnectorAccountButton): ReactNode => {
|
||||
const label = resolveText(item.label)
|
||||
const onClick = item.confirm === undefined ? () => { onCommand(item.command) } : () => { setConfirming(item) }
|
||||
return <Button key={label} variant={item.variant ?? 'outline'} size="sm" disabled={disabled} onClick={onClick}>{label}</Button>
|
||||
}
|
||||
const failure = stopped ? undefined : display.failure
|
||||
const diagnostic = failure === undefined ? undefined : describe(t, failure)
|
||||
const confirm = confirming?.confirm
|
||||
return (
|
||||
<div className={css.section} data-connector-account={phase} data-connector-account-key={entry.key}>
|
||||
<h4 className={css.title}>{resolveText(entry.copy.title)}</h4>
|
||||
<div className={css.status}>
|
||||
<StateDot state={TONE[phase]} />
|
||||
<span className={css.label}>{stopped ? t('status.stopped') : resolveText(display.status)}</span>
|
||||
<div className={css.actions}>
|
||||
{stopped
|
||||
? <Button variant="outline" size="sm" onClick={onRetry}>{t('action.retry')}</Button>
|
||||
: display.buttons.map(button)}
|
||||
</div>
|
||||
</div>
|
||||
{stopped
|
||||
? <p className={css.detail}>{t('detail.stopped')}</p>
|
||||
: display.detail === undefined ? null : <p className={css.detail}>{resolveText(display.detail)}</p>}
|
||||
{stopped ? null : display.notes.map((note) => {
|
||||
const text = resolveText(note.text)
|
||||
return (
|
||||
<div key={text} className={css.status}>
|
||||
<span className={css.detail}>{text}</span>
|
||||
{note.button === undefined ? null : <div className={css.actions}>{button(note.button)}</div>}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{failure === undefined ? null : (
|
||||
<p className={css.failure} role="alert">{resolveText(failure.text)}{diagnostic === undefined ? null : <> {diagnostic}</>}</p>
|
||||
)}
|
||||
<p className={css.hint}>{resolveText(entry.copy.hint)}</p>
|
||||
{confirming === undefined || confirm === undefined ? null : (
|
||||
<ConnectorAccountConfirm t={t} title={resolveText(confirm.title)} body={resolveText(confirm.body)}
|
||||
label={resolveText(confirm.label)} onClose={() => { setConfirming(undefined) }}
|
||||
onConfirm={() => { onCommand(confirming.command) }} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The Plugins page detail the tag sits on: an item page, or a bundle or row page with its package. */
|
||||
export type ConnectorAccountBadgeSubject =
|
||||
| { readonly kind: 'item' }
|
||||
| { readonly kind: 'bundle' | 'row'; readonly pkg: { readonly name: string; readonly enabled: boolean } }
|
||||
|
||||
/** The tag's phase and text. */
|
||||
export interface ConnectorAccountBadgeProps {
|
||||
readonly phase: ShownPhase
|
||||
/** The tag's text; absent while nothing is settled. */
|
||||
readonly text: string | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* The account tag beside a bundle's title.
|
||||
* @param props - the account's phase and the tag's text.
|
||||
* @returns the tag, or null while nothing is settled.
|
||||
*/
|
||||
export function ConnectorAccountBadge({ phase, text }: ConnectorAccountBadgeProps): ReactNode {
|
||||
return text === undefined ? null : <Tag tone={BADGE_TONE[phase]}>{text}</Tag>
|
||||
}
|
||||
|
||||
/** The prompt's phase, text, and callbacks. */
|
||||
export interface ConnectorAccountActivationProps {
|
||||
readonly t: Translate<ConnectorAccountKey>
|
||||
readonly phase: ShownPhase
|
||||
readonly title: string
|
||||
readonly body: string
|
||||
/** The connect button's label. */
|
||||
readonly connect: string
|
||||
readonly onDismiss: () => void
|
||||
readonly onConnect: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Guidance after the user switches a bundle on while its account is not connected.
|
||||
* @param props - the phase, the registrant's text, the dismiss and connect callbacks, and the translator.
|
||||
* @returns a prompt shown while disconnected; it dismisses itself once the phase settles elsewhere.
|
||||
*/
|
||||
export function ConnectorAccountActivation(props: ConnectorAccountActivationProps): ReactNode {
|
||||
const { t, phase, title, body, connect, onDismiss, onConnect } = props
|
||||
const needed = phase === 'disconnected'
|
||||
useEffect(() => {
|
||||
if (phase !== 'checking' && !needed) onDismiss()
|
||||
}, [phase, needed, onDismiss])
|
||||
return (
|
||||
<Modal open={needed} title={title} closeLabel={t('close')} onClose={onDismiss}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={onDismiss}>{t('activation.later')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={onConnect}>{connect}</Button>
|
||||
</>}>
|
||||
<p>{body}</p>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
/** A confirmation's text and callbacks, with the translator for the shared buttons. */
|
||||
export interface ConnectorAccountConfirmProps {
|
||||
readonly t: Translate<ConnectorAccountKey>
|
||||
readonly title: string
|
||||
readonly body: string
|
||||
/** The confirm button's label. */
|
||||
readonly label: string
|
||||
readonly onClose: () => void
|
||||
readonly onConfirm: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm an action that changes the account outside DSH.
|
||||
* @param props - the question and the close and confirm callbacks.
|
||||
* @returns a dialog that closes before it confirms.
|
||||
*/
|
||||
export function ConnectorAccountConfirm({ t, title, body, label, onClose, onConfirm }: ConnectorAccountConfirmProps): ReactNode {
|
||||
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>
|
||||
</>}>
|
||||
<p>{body}</p>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
/** The latest notice and its dismissal, with both translators. */
|
||||
export interface ConnectorAccountToastProps {
|
||||
readonly t: Translate<ConnectorAccountKey>
|
||||
readonly resolveText: Resolve
|
||||
readonly notice: ConnectorAccountNotice | undefined
|
||||
readonly onDone: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Account outcomes reported outside the Plugins panel's lifetime.
|
||||
* @param props - the latest notice, its dismissal, and the translators.
|
||||
* @returns the toast for the notice, or null.
|
||||
*/
|
||||
export function ConnectorAccountToast({ t, resolveText, notice, onDone }: ConnectorAccountToastProps): ReactNode {
|
||||
if (notice === undefined) return null
|
||||
if (notice.kind === 'action-failed') {
|
||||
return <Toast key={notice.seq} text={t('notice.action-failed')} icon={<IconWarningOutlineRegular />} onDone={onDone} />
|
||||
}
|
||||
return <Toast key={notice.seq} text={resolveText(notice.text)} tone="success" onDone={onDone} />
|
||||
}
|
||||
|
||||
/**
|
||||
* The `plugins.bundle.config` entry of a bundle that owns an account.
|
||||
* @param props - the bundle's face and the translator.
|
||||
* @returns the section for the account, or null before the Host lists it.
|
||||
*/
|
||||
export function ConnectorAccountSectionEntry(props: BundleFaceProps): ReactNode {
|
||||
const { useConnectorAccounts, account, resolveText, retry, t } = props
|
||||
const entry = useConnectorAccounts(state => state.accounts.get(account))
|
||||
const linked = useConnectorAccounts(state => state.linked)
|
||||
const stopped = useConnectorAccounts(state => state.stopped)
|
||||
const { busy, run } = useAccountCommand(props)
|
||||
if (entry === undefined) return null
|
||||
return <ConnectorAccountSection t={t} resolveText={resolveText} entry={entry} linked={linked} stopped={stopped} busy={busy}
|
||||
onCommand={(command) => { run(entry, command) }} onRetry={retry} />
|
||||
}
|
||||
|
||||
function accountOf(state: ConnectorAccountsState, packageName: string): ConnectorAccountEntry | undefined {
|
||||
for (const entry of state.accounts.values()) if (entry.packageName === packageName) return entry
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* The `plugins.detail.badge` entry shared by every bundle that owns an account.
|
||||
* @param props - the open detail page's subject, the face, and the translator.
|
||||
* @returns the tag on the page of an enabled bundle that owns an account, or of one of its rows, or null.
|
||||
*/
|
||||
export function ConnectorAccountBadgeEntry(props: FaceProps & Pick<PropsRuntime<'plugins.detail.badge'>, 'subject'>): ReactNode {
|
||||
const { useConnectorAccounts, resolveText, subject, t } = props
|
||||
const page: ConnectorAccountBadgeSubject = subject
|
||||
const packageName = page.kind === 'item' || !page.pkg.enabled ? undefined : page.pkg.name
|
||||
const entry = useConnectorAccounts(state => packageName === undefined ? undefined : accountOf(state, packageName))
|
||||
const stopped = useConnectorAccounts(state => state.stopped)
|
||||
if (entry === undefined) return null
|
||||
const badge = entry.display.badge
|
||||
const text = stopped ? t('badge.stopped') : badge === undefined ? undefined : resolveText(badge)
|
||||
return <ConnectorAccountBadge phase={shownPhase(entry, stopped)} text={text} />
|
||||
}
|
||||
|
||||
/**
|
||||
* The `plugins.bundle.activation` entry of a bundle that owns an account; Connect opens the bundle page and starts the
|
||||
* display's `connect` command.
|
||||
* @param props - activation callbacks, the bundle's face, and the translator.
|
||||
* @returns the prompt for the account, or null before the Host lists it.
|
||||
*/
|
||||
export function ConnectorAccountActivationEntry(
|
||||
props: BundleFaceProps & Pick<PropsRuntime<'plugins.bundle.activation'>, 'onDismiss' | 'onOpenDetails'>,
|
||||
): ReactNode {
|
||||
const { useConnectorAccounts, account, resolveText, onDismiss, onOpenDetails, t } = props
|
||||
const entry = useConnectorAccounts(state => state.accounts.get(account))
|
||||
const stopped = useConnectorAccounts(state => state.stopped)
|
||||
const { run } = useAccountCommand(props)
|
||||
if (entry === undefined) return null
|
||||
const { activation } = entry.copy
|
||||
const { connect } = entry.display
|
||||
const onConnect = (): void => {
|
||||
onOpenDetails()
|
||||
if (connect !== undefined) run(entry, connect)
|
||||
}
|
||||
return (
|
||||
<ConnectorAccountActivation t={t} phase={shownPhase(entry, stopped)} title={resolveText(activation.title)}
|
||||
body={resolveText(activation.body)} connect={resolveText(activation.connect)} onDismiss={onDismiss} onConnect={onConnect} />
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The `shell.overlay` entry.
|
||||
* @param props - the face and the translator.
|
||||
* @returns the toast for the latest notice, or null.
|
||||
*/
|
||||
export function ConnectorAccountToastEntry({ useConnectorAccounts, resolveText, dismissNotice, t }: FaceProps): ReactNode {
|
||||
const notice = useConnectorAccounts(state => state.notice)
|
||||
return <ConnectorAccountToast t={t} resolveText={resolveText} notice={notice} onDone={dismissNotice} />
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Connector account surfaces, browser half: follows the accounts CLI app plugins and MCP connectors register on the Host,
|
||||
* and shows each bundle's section, title tag, and activation prompt on its Plugins page, with the notices of the
|
||||
* operations this browser started. The surfaces read the shared copy from this package's dictionary and each
|
||||
* registrant's text from the Host.
|
||||
*/
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
||||
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 {
|
||||
ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSectionEntry, ConnectorAccountToastEntry,
|
||||
} from './components.tsx'
|
||||
import { de, en, es, fr, ja, NS, pt, ru, zh } from './locales.ts'
|
||||
import { BrowserAccounts } from './state.ts'
|
||||
import type { ConnectorAccountFace } from './types.ts'
|
||||
|
||||
export type { ConnectorAccountKey } from './locales.ts'
|
||||
export type {
|
||||
ConnectorAccountFace, ConnectorAccountNotice, ConnectorAccountsState, ConnectorBundleAccountFace,
|
||||
} from './types.ts'
|
||||
|
||||
/** The `connectorAccounts` Remote that `dsh-api-remotes` mounts, and the services the slot registrations need. */
|
||||
export const inject = ['remote', 'remote.connectorAccounts', 'slots', 'locale']
|
||||
|
||||
function registerBundle(ctx: Context, face: ConnectorAccountFace, packageName: string, account: string): () => void {
|
||||
const bundle = { ...face, account }
|
||||
const dispose = ctx.effect(function* () {
|
||||
yield ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
||||
name: 'plugins.bundle.config', key: packageName, locale: NS, inject: () => bundle,
|
||||
}, ConnectorAccountSectionEntry))
|
||||
yield ctx.slots.inject('plugins.bundle.activation', () => ctx.slots.register({
|
||||
name: 'plugins.bundle.activation', key: packageName, locale: NS, inject: () => bundle,
|
||||
}, ConnectorAccountActivationEntry))
|
||||
}, `connector-account: ${packageName}`)
|
||||
return () => void dispose()
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the registered connector accounts for one plugin lifetime: one tag and one notice entry for the page, and a
|
||||
* section and activation prompt for each bundle that owns an account.
|
||||
* @param ctx - the browser plugin context.
|
||||
*/
|
||||
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)
|
||||
ctx.effect(() => async () => { await browser.dispose() }, 'connector-account: stream')
|
||||
const face: ConnectorAccountFace = {
|
||||
hooks: { connectorAccounts: browser.state },
|
||||
remote: ctx.remote.connectorAccounts,
|
||||
resolveText: text => ctx.locale.resolveText(text),
|
||||
follow: (key, id) => { browser.follow(key, id) },
|
||||
failed: () => { browser.failed() },
|
||||
retry: () => { browser.retry() },
|
||||
dismissNotice: () => { browser.dismissNotice() },
|
||||
}
|
||||
ctx.effect(function* () {
|
||||
yield ctx.slots.inject('plugins.detail.badge', () => ctx.slots.register({
|
||||
name: 'plugins.detail.badge', id: 'connector-account.badge', locale: NS, inject: () => face,
|
||||
}, ConnectorAccountBadgeEntry))
|
||||
yield ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
||||
name: 'shell.overlay', id: 'connector-account.notice', locale: NS, inject: () => face,
|
||||
}, ConnectorAccountToastEntry))
|
||||
}, 'connector-account: page surfaces')
|
||||
ctx.effect(() => {
|
||||
const shown = new Map<string, { readonly account: string; readonly withdraw: () => void }>()
|
||||
const sync = (): void => {
|
||||
const owned = new Map<string, string>()
|
||||
for (const entry of browser.state.getSnapshot().accounts.values()) {
|
||||
if (entry.packageName !== undefined) owned.set(entry.packageName, entry.key)
|
||||
}
|
||||
for (const [packageName, surfaces] of shown) {
|
||||
if (owned.get(packageName) === surfaces.account) continue
|
||||
surfaces.withdraw()
|
||||
shown.delete(packageName)
|
||||
}
|
||||
for (const [packageName, account] of owned) {
|
||||
if (!shown.has(packageName)) shown.set(packageName, { account, withdraw: registerBundle(ctx, face, packageName, account) })
|
||||
}
|
||||
}
|
||||
sync()
|
||||
const stop = browser.state.subscribe(sync)
|
||||
return () => {
|
||||
stop()
|
||||
for (const surfaces of shown.values()) surfaces.withdraw()
|
||||
}
|
||||
}, 'connector-account: bundle surfaces')
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/** Locale-owned copy the connector account surfaces share; each registrant's own text arrives from the Host. */
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-slots'
|
||||
|
||||
/** Dictionary namespace of the shared account copy. */
|
||||
export const NS = 'connectorAccount'
|
||||
|
||||
/** Chinese dictionary and key source. */
|
||||
export const zh = {
|
||||
close: '关闭',
|
||||
'action.cancel': '取消',
|
||||
'action.retry': '重试',
|
||||
'activation.later': '稍后',
|
||||
'failure.details': '排障信息:{details}',
|
||||
'notice.action-failed': '操作未完成,请重试',
|
||||
'badge.stopped': '未运行',
|
||||
'status.stopped': '账号服务未运行',
|
||||
'detail.stopped': '暂时无法读取账号状态,可以重试。',
|
||||
}
|
||||
|
||||
/** Every key the shared account surfaces translate. */
|
||||
export type ConnectorAccountKey = keyof typeof zh
|
||||
|
||||
/** English dictionary. */
|
||||
export const en: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Close',
|
||||
'action.cancel': 'Cancel',
|
||||
'action.retry': 'Retry',
|
||||
'activation.later': 'Later',
|
||||
'failure.details': 'Diagnostic: {details}',
|
||||
'notice.action-failed': 'The action did not finish. Try again.',
|
||||
'badge.stopped': 'Not running',
|
||||
'status.stopped': 'Account service not running',
|
||||
'detail.stopped': 'The account status cannot be read right now. Retry to reconnect.',
|
||||
}
|
||||
|
||||
/** Japanese dictionary. */
|
||||
export const ja: Record<ConnectorAccountKey, string> = {
|
||||
close: '閉じる',
|
||||
'action.cancel': 'キャンセル',
|
||||
'action.retry': '再試行',
|
||||
'activation.later': '後で',
|
||||
'failure.details': '診断情報:{details}',
|
||||
'notice.action-failed': '操作が完了しませんでした。もう一度お試しください。',
|
||||
'badge.stopped': '未稼働',
|
||||
'status.stopped': 'アカウントサービスが稼働していません',
|
||||
'detail.stopped': 'アカウントの状態を現在読み取れません。再試行して再接続してください。',
|
||||
}
|
||||
|
||||
/** Spanish dictionary. */
|
||||
export const es: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Cerrar',
|
||||
'action.cancel': 'Cancelar',
|
||||
'action.retry': 'Reintentar',
|
||||
'activation.later': 'Más tarde',
|
||||
'failure.details': 'Diagnóstico: {details}',
|
||||
'notice.action-failed': 'La acción no se completó. Inténtelo de nuevo.',
|
||||
'badge.stopped': 'No está en ejecución',
|
||||
'status.stopped': 'El servicio de cuentas no está en ejecución',
|
||||
'detail.stopped': 'No se puede leer el estado de la cuenta en este momento. Reintente para volver a conectar.',
|
||||
}
|
||||
|
||||
/** French dictionary. */
|
||||
export const fr: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Fermer',
|
||||
'action.cancel': 'Annuler',
|
||||
'action.retry': 'Réessayer',
|
||||
'activation.later': 'Plus tard',
|
||||
'failure.details': 'Diagnostic : {details}',
|
||||
'notice.action-failed': 'L’action n’a pas abouti. Réessayez.',
|
||||
'badge.stopped': 'Ne fonctionne pas',
|
||||
'status.stopped': 'Le service de comptes ne fonctionne pas',
|
||||
'detail.stopped': 'L’état du compte ne peut pas être lu pour le moment. Réessayez pour vous reconnecter.',
|
||||
}
|
||||
|
||||
/** German dictionary. */
|
||||
export const de: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Schließen',
|
||||
'action.cancel': 'Abbrechen',
|
||||
'action.retry': 'Erneut versuchen',
|
||||
'activation.later': 'Später',
|
||||
'failure.details': 'Diagnose: {details}',
|
||||
'notice.action-failed': 'Die Aktion wurde nicht abgeschlossen. Versuchen Sie es erneut.',
|
||||
'badge.stopped': 'Läuft nicht',
|
||||
'status.stopped': 'Kontodienst läuft nicht',
|
||||
'detail.stopped': 'Der Kontostatus kann gerade nicht gelesen werden. Versuchen Sie es erneut, um die Verbindung wiederherzustellen.',
|
||||
}
|
||||
|
||||
/** Russian dictionary. */
|
||||
export const ru: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Закрыть',
|
||||
'action.cancel': 'Отмена',
|
||||
'action.retry': 'Повторить',
|
||||
'activation.later': 'Позже',
|
||||
'failure.details': 'Диагностика: {details}',
|
||||
'notice.action-failed': 'Действие не завершено. Повторите попытку.',
|
||||
'badge.stopped': 'Не работает',
|
||||
'status.stopped': 'Служба аккаунтов не работает',
|
||||
'detail.stopped': 'Сейчас не удаётся прочитать состояние аккаунта. Повторите попытку, чтобы переподключиться.',
|
||||
}
|
||||
|
||||
/** Portuguese dictionary. */
|
||||
export const pt: Record<ConnectorAccountKey, string> = {
|
||||
close: 'Fechar',
|
||||
'action.cancel': 'Cancelar',
|
||||
'action.retry': 'Tentar novamente',
|
||||
'activation.later': 'Mais tarde',
|
||||
'failure.details': 'Diagnóstico: {details}',
|
||||
'notice.action-failed': 'A ação não foi concluída. Tente novamente.',
|
||||
'badge.stopped': 'Não está em execução',
|
||||
'status.stopped': 'O serviço de contas não está em execução',
|
||||
'detail.stopped': 'Não é possível ler o estado da conta agora. Tente novamente para reconectar.',
|
||||
}
|
||||
|
||||
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
||||
interface LocaleNamespaceMap {
|
||||
connectorAccount: ConnectorAccountKey
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* The page's one subscription to the registered accounts, and what only this browser knows about them: the operations
|
||||
* it started, whose authorization pages open here, and the notice to show.
|
||||
*/
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { RemoteStream } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
||||
import type { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
||||
import type { ConnectorAccountEntry, ConnectorAccountsView, ConnectorOperationId } from '../types.ts'
|
||||
import type { ConnectorAccountNotice, ConnectorAccountsRemote, ConnectorAccountsState } from './types.ts'
|
||||
|
||||
const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]'])
|
||||
|
||||
/**
|
||||
* Open an authorization page in a new tab when it is HTTPS, or HTTP on a loopback address such as a local
|
||||
* authorization server.
|
||||
* @param url - the page an operation waits on; other values open nothing.
|
||||
*/
|
||||
export function openAuthorizationPage(url: string | undefined): void {
|
||||
if (url === undefined || !URL.canParse(url)) return
|
||||
const parsed = new URL(url)
|
||||
if (parsed.protocol === 'https:' || (parsed.protocol === 'http:' && LOOPBACK_HOSTS.has(parsed.hostname))) {
|
||||
window.open(url, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
}
|
||||
|
||||
/** One Host subscription per browser, shared by every account surface on the page. */
|
||||
export class BrowserAccounts {
|
||||
/** The accounts, stream state, and notice every surface on the page reads. */
|
||||
readonly state: SnapshotStore<ConnectorAccountsState> = createSnapshotStore<ConnectorAccountsState>({
|
||||
accounts: new Map(), linked: true, stopped: false, notice: undefined,
|
||||
})
|
||||
|
||||
/**
|
||||
* The operation each account's latest start in this browser returned, with the pages already opened for it. It lasts
|
||||
* until the stream delivers its result or the account leaves.
|
||||
*/
|
||||
private readonly followed = new Map<string, { readonly id: ConnectorOperationId; readonly opened: Set<string> }>()
|
||||
private seq = 0
|
||||
private disposed = false
|
||||
private stream!: RemoteStream<ConnectorAccountsView>
|
||||
private observing!: Promise<void>
|
||||
|
||||
/**
|
||||
* @param ctx - the browser context carrying the Remote client.
|
||||
* @param remote - the `connectorAccounts` Remote.
|
||||
*/
|
||||
constructor(private readonly ctx: Context, private readonly remote: Pick<ConnectorAccountsRemote, 'watch'>) {
|
||||
this.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow an operation this browser started, replacing the account's previous one.
|
||||
* @param key - the account key.
|
||||
* @param id - the operation the Host started.
|
||||
*/
|
||||
follow(key: string, id: ConnectorOperationId): void {
|
||||
if (this.disposed) return
|
||||
this.followed.set(key, { id, opened: new Set() })
|
||||
// The stream may have delivered the operation before the start call answered.
|
||||
const entry = this.state.getSnapshot().accounts.get(key)
|
||||
if (entry !== undefined) this.track(entry)
|
||||
}
|
||||
|
||||
/** Report that a Remote call this browser made did not finish; the Host keeps the diagnostic. */
|
||||
failed(): void {
|
||||
this.notify({ kind: 'action-failed' })
|
||||
}
|
||||
|
||||
/** Clear the notice once it has been shown. */
|
||||
dismissNotice(): void {
|
||||
this.patch({ notice: undefined })
|
||||
}
|
||||
|
||||
/** Reopen the Host stream after it stopped; ignored while it runs, while a reopen is pending, or after disposal. */
|
||||
retry(): void {
|
||||
if (this.disposed || !this.state.getSnapshot().stopped) return
|
||||
// Clearing `stopped` before the reopen awaits claims it, so a second retry finds nothing to reopen.
|
||||
this.patch({ stopped: false })
|
||||
void this.reopen()
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop observing the Host; afterwards the page opens no page, reports nothing more, and a pending retry opens no stream.
|
||||
* Host-owned operations keep running.
|
||||
* @returns after the stream closes.
|
||||
*/
|
||||
async dispose(): Promise<void> {
|
||||
this.disposed = true
|
||||
await this.stream.dispose()
|
||||
await this.observing
|
||||
}
|
||||
|
||||
private subscribe(): void {
|
||||
this.stream = this.ctx.remote.$stream<ConnectorAccountsView>({
|
||||
name: 'Connector accounts', open: signal => this.remote.watch(signal),
|
||||
ended: () => new Error('Connector accounts stream ended'),
|
||||
carrierFailed: () => { this.patch({ linked: false }) },
|
||||
})
|
||||
this.observing = this.observe(this.stream)
|
||||
}
|
||||
|
||||
private async observe(stream: RemoteStream<ConnectorAccountsView>): Promise<void> {
|
||||
try {
|
||||
for await (const item of stream) {
|
||||
// An item the stream yielded just before disposal must not reach the disposed page.
|
||||
if (this.disposed) return
|
||||
this.show(item.value.accounts)
|
||||
item.accept()
|
||||
}
|
||||
} catch {
|
||||
// A terminal failure, such as a Host without the registry, ends the stream; a disposed page shows nothing.
|
||||
if (!this.disposed) this.patch({ linked: false, stopped: true })
|
||||
}
|
||||
}
|
||||
|
||||
private async reopen(): Promise<void> {
|
||||
await this.stream.dispose()
|
||||
await this.observing
|
||||
if (!this.disposed) this.subscribe()
|
||||
}
|
||||
|
||||
private show(entries: readonly ConnectorAccountEntry[]): void {
|
||||
const accounts = new Map(entries.map(entry => [entry.key, entry]))
|
||||
for (const key of [...this.followed.keys()]) if (!accounts.has(key)) this.followed.delete(key)
|
||||
this.patch({ accounts, linked: true, stopped: false })
|
||||
for (const entry of entries) this.track(entry)
|
||||
}
|
||||
|
||||
/** Open each new page of the account's followed operation once, and report its success once its result arrives. */
|
||||
private track(entry: ConnectorAccountEntry): void {
|
||||
const followed = this.followed.get(entry.key)
|
||||
if (followed === undefined) return
|
||||
const url = entry.operation?.id === followed.id ? entry.operation.authorizationUrl : undefined
|
||||
if (url !== undefined && !followed.opened.has(url)) {
|
||||
followed.opened.add(url)
|
||||
openAuthorizationPage(url)
|
||||
}
|
||||
const result = entry.result
|
||||
if (result?.id !== followed.id) return
|
||||
this.followed.delete(entry.key)
|
||||
if (result.notice !== undefined) this.notify({ kind: 'succeeded', text: result.notice })
|
||||
}
|
||||
|
||||
private notify(
|
||||
notice: { readonly kind: 'succeeded'; readonly text: LocalizedText } | { readonly kind: 'action-failed' },
|
||||
): void {
|
||||
if (this.disposed) return
|
||||
this.seq += 1
|
||||
const next: ConnectorAccountNotice = { ...notice, seq: this.seq }
|
||||
this.patch({ notice: next })
|
||||
}
|
||||
|
||||
private patch(change: Partial<ConnectorAccountsState>): void {
|
||||
this.state.set({ ...this.state.getSnapshot(), ...change })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/** Browser-side state and face of the accounts the Plugins page shows. */
|
||||
import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import type { ConnectorAccountEntry, ConnectorAccountsView, ConnectorOperationId } from '../types.ts'
|
||||
|
||||
/** A transient outcome the page reports outside its own lifetime; `seq` distinguishes repeats. */
|
||||
export type ConnectorAccountNotice =
|
||||
| { readonly seq: number; readonly kind: 'succeeded'; readonly text: LocalizedText }
|
||||
| { readonly seq: number; readonly kind: 'action-failed' }
|
||||
|
||||
/** What this browser shows: the Host's accounts, the stream state, and the latest notice. */
|
||||
export interface ConnectorAccountsState {
|
||||
/** Registered accounts by key, as the Host last published them. */
|
||||
readonly accounts: ReadonlyMap<string, ConnectorAccountEntry>
|
||||
/** Whether the Host stream is delivering. */
|
||||
readonly linked: boolean
|
||||
/** Whether the Host stream failed for good; `retry` reopens it. */
|
||||
readonly stopped: boolean
|
||||
readonly notice: ConnectorAccountNotice | undefined
|
||||
}
|
||||
|
||||
/** The `connectorAccounts` Remote methods the page uses. */
|
||||
export interface ConnectorAccountsRemote {
|
||||
watch(signal: AbortSignal): AsyncIterable<ConnectorAccountsView>
|
||||
start(key: string, operation: string): Promise<RemoteResult<ConnectorOperationId>>
|
||||
cancel(key: string, id: ConnectorOperationId): Promise<RemoteResult<void>>
|
||||
}
|
||||
|
||||
/** 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'>
|
||||
/** 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. */
|
||||
readonly follow: (key: string, id: ConnectorOperationId) => void
|
||||
/** Report that a Remote call this browser made did not finish. */
|
||||
readonly failed: () => void
|
||||
/** Reopen the Host stream after it stopped. */
|
||||
readonly retry: () => void
|
||||
readonly dismissNotice: () => void
|
||||
}
|
||||
|
||||
/** The face of a bundle's own surfaces, which show the bundle's account. */
|
||||
export interface ConnectorBundleAccountFace extends ConnectorAccountFace {
|
||||
/** The key of the account the bundle owns. */
|
||||
readonly account: string
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
declare module '*.module.css' {
|
||||
const classes: Record<string, string>
|
||||
export default classes
|
||||
}
|
||||
|
||||
declare module '*.css'
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Connector account surfaces, Host half. CLI app plugins and MCP connectors register their accounts with
|
||||
* `ctx.connectorAccounts`; the Plugins page follows every registered account through the `connectorAccounts` Remote and
|
||||
* starts or cancels operations through it, so the browser never learns how an account connects.
|
||||
* @module @deepseek-ai/dsh-client-ui-connector-account
|
||||
*/
|
||||
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import type {
|
||||
AnyConnectorAccountView, ConnectorAccountEntry, ConnectorAccountRegistration, ConnectorAccountsView, ConnectorOperationId,
|
||||
} from './types.ts'
|
||||
|
||||
export type * from './types.ts'
|
||||
|
||||
declare module '@deepseek-ai/cordis' {
|
||||
interface Context {
|
||||
/** Connector accounts on the Plugins page. */
|
||||
connectorAccounts: ConnectorAccounts
|
||||
}
|
||||
}
|
||||
|
||||
interface Registered {
|
||||
readonly packageName: string | undefined
|
||||
readonly entry: () => ConnectorAccountEntry
|
||||
readonly refresh: () => void
|
||||
readonly start: (operation: string) => ConnectorOperationId
|
||||
readonly cancel: (id: ConnectorOperationId) => Promise<void>
|
||||
}
|
||||
|
||||
function registeredOf<View extends AnyConnectorAccountView>(registration: ConnectorAccountRegistration<View>): Registered {
|
||||
const { key, packageName, source, operations, copy, present } = registration
|
||||
return {
|
||||
packageName,
|
||||
entry: () => {
|
||||
const view = source.snapshot()
|
||||
const { operation, result } = view
|
||||
const notice = result?.outcome === 'succeeded' ? operations.find(candidate => candidate.kind === result.kind)?.notice : undefined
|
||||
return {
|
||||
key, ...packageName === undefined ? {} : { packageName }, copy, display: present(view),
|
||||
...operation === undefined ? {} : {
|
||||
operation: {
|
||||
id: operation.id, ...operation.authorizationUrl === undefined ? {} : { authorizationUrl: operation.authorizationUrl },
|
||||
},
|
||||
},
|
||||
...result === undefined ? {} : { result: { id: result.id, ...notice === undefined ? {} : { notice } } },
|
||||
}
|
||||
},
|
||||
refresh: () => { source.refresh() },
|
||||
start: (operation) => {
|
||||
const kind = operations.find(candidate => candidate.kind === operation)?.kind
|
||||
if (kind === undefined) throw new Error(`connectorAccounts: ${key} has no page operation ${operation}`)
|
||||
return source.start(kind)
|
||||
},
|
||||
cancel: id => source.cancel(id),
|
||||
}
|
||||
}
|
||||
|
||||
/** Holds the registered accounts and serves them to the Plugins page. */
|
||||
export default class ConnectorAccounts extends TypertRemoteService {
|
||||
private readonly accounts = new Map<string, Registered>()
|
||||
private readonly listeners = new Set<() => void>()
|
||||
private readonly lifetime = new AbortController()
|
||||
private subscribers = 0
|
||||
|
||||
/** @param ctx - the Host context the registry serves the page from. */
|
||||
constructor(ctx: Context) {
|
||||
super(ctx, 'connectorAccounts')
|
||||
ctx.effect(() => () => { this.lifetime.abort(new Error('connectorAccounts: registry disposed')) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one account on the Plugins page for as long as the returned disposer has not run.
|
||||
* @param registration - the account key, its bundle package, the account source, the page operations, and the
|
||||
* presentation.
|
||||
* @returns an idempotent disposer that withdraws the account.
|
||||
* @throws when another account already uses the key or the package.
|
||||
*/
|
||||
register<View extends AnyConnectorAccountView>(registration: ConnectorAccountRegistration<View>): () => void {
|
||||
const { key, packageName } = registration
|
||||
if (this.accounts.has(key)) throw new Error(`connectorAccounts: ${key} is already registered`)
|
||||
if (packageName !== undefined && [...this.accounts.values()].some(account => account.packageName === packageName)) {
|
||||
throw new Error(`connectorAccounts: ${packageName} already has an account`)
|
||||
}
|
||||
this.accounts.set(key, registeredOf(registration))
|
||||
const stop = registration.source.observe(() => { this.changed() })
|
||||
// A page that already follows the accounts checks a newly registered one, as it checks each account it subscribes to.
|
||||
if (this.subscribers > 0) registration.source.refresh()
|
||||
this.changed()
|
||||
let active = true
|
||||
return () => {
|
||||
if (!active) return
|
||||
active = false
|
||||
stop()
|
||||
this.accounts.delete(key)
|
||||
this.changed()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow every registered account; each new subscriber starts a check of each account that runs no operation.
|
||||
* @param signal - the Client's observation lifetime; disposal also ends the stream.
|
||||
* @returns the current accounts, then each changed set, coalescing changes that arrive before the next read.
|
||||
*/
|
||||
@Remote({ mode: 'stream' })
|
||||
async *watch(signal: AbortSignal): AsyncIterable<ConnectorAccountsView> {
|
||||
const combined = AbortSignal.any([signal, this.lifetime.signal])
|
||||
let wake = Promise.withResolvers<void>()
|
||||
let changed = true
|
||||
const notify = (): void => { changed = true; wake.resolve() }
|
||||
this.listeners.add(notify)
|
||||
combined.addEventListener('abort', notify, { once: true })
|
||||
this.subscribers += 1
|
||||
try {
|
||||
for (const account of this.accounts.values()) account.refresh()
|
||||
for (;;) {
|
||||
if (!changed) await wake.promise
|
||||
if (combined.aborted) break
|
||||
wake = Promise.withResolvers<void>()
|
||||
changed = false
|
||||
yield { accounts: [...this.accounts.values()].map(account => account.entry()) }
|
||||
}
|
||||
} finally {
|
||||
this.subscribers -= 1
|
||||
this.listeners.delete(notify)
|
||||
combined.removeEventListener('abort', notify)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start one of the operations the account registered as page actions.
|
||||
* @param key - the account key.
|
||||
* @param operation - the operation kind.
|
||||
* @returns the operation identity.
|
||||
* @throws for an unknown account or operation, or whatever the account's source refuses, such as a second operation.
|
||||
*/
|
||||
@Remote
|
||||
start(key: string, operation: string): ConnectorOperationId {
|
||||
return this.account(key).start(operation)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel one operation while its phase is cancellable, and wait for it to settle.
|
||||
* @param key - the account key.
|
||||
* @param id - the operation to cancel; a finished one or a phase that is not cancellable is ignored.
|
||||
* @returns after the operation settles, or at once when nothing is cancelled.
|
||||
* @throws for an unknown account.
|
||||
*/
|
||||
@Remote
|
||||
cancel(key: string, id: ConnectorOperationId): Promise<void> {
|
||||
return this.account(key).cancel(id)
|
||||
}
|
||||
|
||||
private account(key: string): Registered {
|
||||
const account = this.accounts.get(key)
|
||||
if (account === undefined) throw new Error(`connectorAccounts: ${key} is not registered`)
|
||||
return account
|
||||
}
|
||||
|
||||
private changed(): void {
|
||||
for (const notify of this.listeners) notify()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Credential-free account views of connector plugins, and what the Plugins page receives about them. Each registrant
|
||||
* supplies its own account, operation, phase, and failure types and maps its views to the page's display, so CLI app
|
||||
* plugins and MCP connectors share one registry and one page.
|
||||
*/
|
||||
|
||||
import type { Branded } from '@deepseek-ai/dsh-brand'
|
||||
import type { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
||||
|
||||
/** Identifies one Host-owned account operation across the browsers that show the account. */
|
||||
export type ConnectorOperationId = Branded<'ConnectorOperationId'>
|
||||
|
||||
/** The account operation in progress; `Phase` names the registrant's own steps. */
|
||||
export interface ConnectorOperation<Kind extends string, Phase extends string> {
|
||||
readonly id: ConnectorOperationId
|
||||
readonly kind: Kind
|
||||
readonly phase: Phase
|
||||
/** Whether the source cancels the operation in its current phase. */
|
||||
readonly cancellable: boolean
|
||||
/** The page the user authorizes in, while the operation waits for one; only the browser that started it opens it. */
|
||||
readonly authorizationUrl?: string
|
||||
}
|
||||
|
||||
/** The most recent finished operation, kept until another one starts. */
|
||||
export interface ConnectorOperationResult<Kind extends string, Failure = unknown> {
|
||||
readonly id: ConnectorOperationId
|
||||
readonly kind: Kind
|
||||
readonly outcome: 'succeeded' | 'cancelled' | 'failed'
|
||||
/** The registrant's classified failure, for its own presentation; does not imply rollback or a safe retry. */
|
||||
readonly failure?: Failure
|
||||
}
|
||||
|
||||
/** The complete account view; observers reread it after each change. */
|
||||
export interface ConnectorAccountView<Account, Kind extends string, Phase extends string, Failure = unknown> {
|
||||
/** The account as the source last published it. */
|
||||
readonly account: Account
|
||||
readonly operation?: ConnectorOperation<Kind, Phase>
|
||||
readonly result?: ConnectorOperationResult<Kind, Failure>
|
||||
}
|
||||
|
||||
/** Any registrant's account view. */
|
||||
export type AnyConnectorAccountView = ConnectorAccountView<unknown, string, string>
|
||||
|
||||
/** The operation kinds a view reports. */
|
||||
export type ConnectorOperationKindOf<View extends AnyConnectorAccountView> = NonNullable<View['result']>['kind']
|
||||
|
||||
/** What the Plugins page shows about an account; each registrant maps its own account states onto these phases. */
|
||||
export type ConnectorAccountPhase = 'checking' | 'connecting' | 'connected' | 'disconnected' | 'unavailable'
|
||||
|
||||
/** What a section button does. */
|
||||
export type ConnectorAccountCommand =
|
||||
/** Start one of the operations the account registered as page actions. */
|
||||
| { readonly kind: 'start'; readonly operation: string }
|
||||
/** Cancel the operation in progress when it is cancellable. */
|
||||
| { readonly kind: 'cancel' }
|
||||
/** Open the current operation's authorization page again in this browser. */
|
||||
| { readonly kind: 'open' }
|
||||
|
||||
/** The question a button asks before it runs. */
|
||||
export interface ConnectorAccountConfirmation {
|
||||
readonly title: LocalizedText
|
||||
readonly body: LocalizedText
|
||||
/** The confirm button's label. */
|
||||
readonly label: LocalizedText
|
||||
}
|
||||
|
||||
/** One button in the section. */
|
||||
export interface ConnectorAccountButton {
|
||||
readonly label: LocalizedText
|
||||
readonly command: ConnectorAccountCommand
|
||||
/** Defaults to an outline button. */
|
||||
readonly variant?: 'primary' | 'ghost'
|
||||
/** Ask first, for an action that changes the account outside DSH, such as signing out. */
|
||||
readonly confirm?: ConnectorAccountConfirmation
|
||||
}
|
||||
|
||||
/** One extra row under the status line, such as the linked app, with an optional button. */
|
||||
export interface ConnectorAccountNote {
|
||||
readonly text: LocalizedText
|
||||
readonly button?: ConnectorAccountButton
|
||||
}
|
||||
|
||||
/** A failed operation as the section reports it. */
|
||||
export interface ConnectorAccountFailure {
|
||||
/** The registrant's recovery guidance. */
|
||||
readonly text: LocalizedText
|
||||
/** Untranslated diagnostic items shown after the guidance in order. */
|
||||
readonly details?: readonly string[]
|
||||
}
|
||||
|
||||
/** What the section shows for the current view; every text carries each shipped language. */
|
||||
export interface ConnectorAccountDisplay {
|
||||
readonly phase: ConnectorAccountPhase
|
||||
readonly status: LocalizedText
|
||||
/** The tag beside the bundle title; absent while nothing is settled. */
|
||||
readonly badge?: LocalizedText
|
||||
readonly buttons: readonly ConnectorAccountButton[]
|
||||
/** What Connect in the activation prompt starts after opening the bundle page; absent, Connect only opens the page. */
|
||||
readonly connect?: Extract<ConnectorAccountCommand, { readonly kind: 'start' }>
|
||||
readonly detail?: LocalizedText
|
||||
readonly notes: readonly ConnectorAccountNote[]
|
||||
readonly failure?: ConnectorAccountFailure
|
||||
}
|
||||
|
||||
/** The section's fixed text that names the service or uses its wording. */
|
||||
export interface ConnectorAccountCopy {
|
||||
readonly title: LocalizedText
|
||||
/** The line under the section, such as where the account is shared or authorized. */
|
||||
readonly hint: LocalizedText
|
||||
/** The prompt after the bundle is switched on while the account is disconnected. */
|
||||
readonly activation: { readonly title: LocalizedText; readonly body: LocalizedText; readonly connect: LocalizedText }
|
||||
}
|
||||
|
||||
/** One registered account as the Plugins page receives it. */
|
||||
export interface ConnectorAccountEntry {
|
||||
/** The registrant's stable account key, which the page passes back to start and cancel operations. */
|
||||
readonly key: string
|
||||
/** npm package whose bundle page carries the section and tag; absent for an account no bundle owns. */
|
||||
readonly packageName?: string
|
||||
readonly copy: ConnectorAccountCopy
|
||||
readonly display: ConnectorAccountDisplay
|
||||
/** The operation in progress, which a browser follows when it started it. */
|
||||
readonly operation?: { readonly id: ConnectorOperationId; readonly authorizationUrl?: string }
|
||||
/** The most recent finished operation, with the registrant's text when it succeeded. */
|
||||
readonly result?: { readonly id: ConnectorOperationId; readonly notice?: LocalizedText }
|
||||
}
|
||||
|
||||
/** Every registered account, as each change publishes it. */
|
||||
export interface ConnectorAccountsView {
|
||||
readonly accounts: readonly ConnectorAccountEntry[]
|
||||
}
|
||||
|
||||
/** The account a registration exposes to the page. */
|
||||
export interface ConnectorAccountSource<View extends AnyConnectorAccountView> {
|
||||
snapshot(): View
|
||||
/** @returns a disposer; the listener runs after each change without starting a check. */
|
||||
observe(listener: () => void): () => void
|
||||
/** Start a check unless an operation runs; a source whose view is always current does nothing. */
|
||||
refresh(): void
|
||||
/** @returns the started operation's identity. */
|
||||
start(kind: ConnectorOperationKindOf<View>): ConnectorOperationId
|
||||
/** @returns after the named operation settles, or at once when it is not cancellable. */
|
||||
cancel(id: ConnectorOperationId): Promise<void>
|
||||
}
|
||||
|
||||
/** One operation a page button may start, with the text its success reports in the browser that started it. */
|
||||
export interface ConnectorAccountOperation<Kind extends string> {
|
||||
readonly kind: Kind
|
||||
readonly notice?: LocalizedText
|
||||
}
|
||||
|
||||
/** One connector account, registered with the Host's `ctx.connectorAccounts`. */
|
||||
export interface ConnectorAccountRegistration<View extends AnyConnectorAccountView> {
|
||||
/** Stable key, unique among registered accounts, such as the bundle's package name. */
|
||||
readonly key: string
|
||||
/** npm package whose bundle page carries the section and tag; at most one account per package. */
|
||||
readonly packageName?: string
|
||||
readonly source: ConnectorAccountSource<View>
|
||||
/** The operations a page button may start; the registry rejects any other. */
|
||||
readonly operations: readonly ConnectorAccountOperation<ConnectorOperationKindOf<View>>[]
|
||||
readonly copy: ConnectorAccountCopy
|
||||
/** Map the current view to what the section shows; called on each change for each subscriber. */
|
||||
readonly present: (view: View) => ConnectorAccountDisplay
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* The browser plugin shows one tag and one notice entry for the page, and a section and activation prompt for each bundle
|
||||
* that owns an account, withdrawing them with the account or the plugin.
|
||||
*/
|
||||
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 { expect, it, onTestFinished, vi } from 'vitest'
|
||||
import {
|
||||
ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSectionEntry, ConnectorAccountToastEntry,
|
||||
} from '../src/client/components.tsx'
|
||||
import { NS } from '../src/client/locales.ts'
|
||||
import { apply, inject } from '../src/client/index.ts'
|
||||
import type { ConnectorAccountFace, ConnectorBundleAccountFace } from '../src/client/types.ts'
|
||||
import type { ConnectorAccountEntry, ConnectorAccountsView, ConnectorOperationId } from '../src/types.ts'
|
||||
|
||||
const FIXTURE = '@acme/fixture'
|
||||
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.hooks === 'object' && value.hooks !== null)
|
||||
}
|
||||
|
||||
/** Read the face a slot entry injects. */
|
||||
function faceOf(item: { readonly inject?: (() => Record<string, unknown>) | undefined }): ConnectorAccountFace {
|
||||
assert(item.inject !== undefined)
|
||||
const face = item.inject()
|
||||
isFace(face)
|
||||
return face
|
||||
}
|
||||
|
||||
function bundleFaceOf(item: { readonly inject?: (() => Record<string, unknown>) | undefined }): ConnectorBundleAccountFace {
|
||||
const face = faceOf(item)
|
||||
assert('account' in face && typeof face.account === 'string')
|
||||
return face as ConnectorBundleAccountFace
|
||||
}
|
||||
|
||||
function entry(key: string, packageName: string | null = key): ConnectorAccountEntry {
|
||||
return {
|
||||
key, ...packageName === null ? {} : { packageName },
|
||||
copy: { title: 'Fixture account', hint: 'Shared.', activation: { title: 'Connect', body: 'On.', connect: 'Connect' } },
|
||||
display: { phase: 'disconnected', status: 'Not connected', buttons: [], notes: [] },
|
||||
}
|
||||
}
|
||||
|
||||
async function bench() {
|
||||
const ctx = new Context()
|
||||
onTestFinished(async () => { await ctx.fiber.dispose() })
|
||||
const queue: ConnectorAccountsView[] = []
|
||||
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 }))
|
||||
class Remote extends Service {
|
||||
constructor() { super(ctx, 'remote') }
|
||||
$stream() {
|
||||
return {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
for (;;) {
|
||||
const next = queue.shift()
|
||||
if (next !== undefined) { yield { value: next, accept: () => { accepted++ } }; continue }
|
||||
if (closed) return
|
||||
await new Promise<void>((resolve) => { wake = resolve })
|
||||
}
|
||||
},
|
||||
dispose: closeStream,
|
||||
}
|
||||
}
|
||||
}
|
||||
new Remote()
|
||||
ctx.provide('remote.connectorAccounts', { watch: vi.fn(), start, cancel: vi.fn() })
|
||||
const locale = new LocaleRuntime(ctx)
|
||||
ctx.provide('locale', locale)
|
||||
await ctx.plugin(SlotRegistry)
|
||||
ctx.slots.register({ name: 'root', children: {
|
||||
'plugins.bundle.activation': { kind: 'keyed', scope: 'root' },
|
||||
'plugins.bundle.config': { kind: 'keyed', scope: 'root' },
|
||||
'plugins.detail.badge': { kind: 'list', scope: 'root' },
|
||||
'shell.overlay': { kind: 'list', scope: 'root' },
|
||||
} } as never, () => null)
|
||||
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,
|
||||
mount: () => ctx.plugin({ inject: [...inject], apply }),
|
||||
async publish(...entries: ConnectorAccountEntry[]) {
|
||||
const target = accepted + 1
|
||||
queue.push({ accounts: entries })
|
||||
wake?.()
|
||||
await vi.waitFor(() => { expect(accepted).toBe(target) })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
it('shows one tag and one notice entry for the page and each bundle\'s section and prompt under the shared dictionary', async () => {
|
||||
const b = await bench()
|
||||
await b.mount()
|
||||
expect(b.locale.bind(NS)('action.retry')).toBe('Retry')
|
||||
expect(b.ctx.slots.entries('plugins.detail.badge').map(item => [item.options.id, item.component])).toEqual([
|
||||
['connector-account.badge', ConnectorAccountBadgeEntry],
|
||||
])
|
||||
expect(b.ctx.slots.entries('shell.overlay').map(item => [item.options.id, item.component])).toEqual([
|
||||
['connector-account.notice', ConnectorAccountToastEntry],
|
||||
])
|
||||
expect(b.bundles('plugins.bundle.config')).toEqual([])
|
||||
|
||||
// An account no bundle owns gets no bundle surfaces.
|
||||
await b.publish(entry(FIXTURE), entry(OTHER), entry('mcp:custom', null))
|
||||
expect(b.bundles('plugins.bundle.config')).toEqual([[FIXTURE, FIXTURE], [OTHER, OTHER]])
|
||||
expect(b.bundles('plugins.bundle.activation')).toEqual([[FIXTURE, FIXTURE], [OTHER, OTHER]])
|
||||
const [section] = b.ctx.slots.entries('plugins.bundle.config')
|
||||
assert(section !== undefined)
|
||||
expect(section).toMatchObject({ locale: NS, component: ConnectorAccountSectionEntry })
|
||||
expect(b.ctx.slots.entries('plugins.bundle.activation')[0]).toMatchObject({ locale: NS, component: ConnectorAccountActivationEntry })
|
||||
const face = bundleFaceOf(section)
|
||||
const [badge] = b.ctx.slots.entries('plugins.detail.badge')
|
||||
assert(badge !== undefined)
|
||||
const [toast] = b.ctx.slots.entries('shell.overlay')
|
||||
assert(toast !== undefined)
|
||||
expect(faceOf(badge).hooks.connectorAccounts).toBe(face.hooks.connectorAccounts)
|
||||
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(b.start).toHaveBeenCalledWith(FIXTURE, 'connect')
|
||||
face.follow(FIXTURE, OP)
|
||||
face.failed()
|
||||
expect(face.hooks.connectorAccounts.getSnapshot().notice).toEqual({ seq: 1, kind: 'action-failed' })
|
||||
face.dismissNotice()
|
||||
face.retry()
|
||||
expect(face.hooks.connectorAccounts.getSnapshot().notice).toBeUndefined()
|
||||
|
||||
// A dropped account withdraws its bundle's surfaces, and a bundle whose account changed key shows the new one.
|
||||
await b.publish(entry(OTHER))
|
||||
expect(b.bundles('plugins.bundle.config')).toEqual([[OTHER, OTHER]])
|
||||
await b.publish(entry('mcp:other', OTHER))
|
||||
expect(b.bundles('plugins.bundle.config')).toEqual([[OTHER, 'mcp:other']])
|
||||
expect(b.bundles('plugins.bundle.activation')).toEqual([[OTHER, 'mcp:other']])
|
||||
})
|
||||
|
||||
it('withdraws every surface, the dictionaries, and the stream when the plugin unloads', async () => {
|
||||
const b = await bench()
|
||||
const fiber = b.mount()
|
||||
await fiber
|
||||
await b.publish(entry(FIXTURE), entry(OTHER))
|
||||
expect(b.bundles('plugins.bundle.config')).toHaveLength(2)
|
||||
await fiber.dispose()
|
||||
for (const slot of ['plugins.bundle.config', 'plugins.bundle.activation', 'plugins.detail.badge', 'shell.overlay'] as const) {
|
||||
expect(b.ctx.slots.entries(slot)).toEqual([])
|
||||
}
|
||||
expect(b.locale.bind(NS)('action.retry')).toBe('action.retry')
|
||||
expect(b.closeStream).toHaveBeenCalledOnce()
|
||||
})
|
||||
@@ -0,0 +1,264 @@
|
||||
// @vitest-environment jsdom
|
||||
/** The surfaces render each registrant's display from the Host with the shared copy, and buttons call the Remote directly. */
|
||||
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 {
|
||||
ConnectorAccountActivation, ConnectorAccountActivationEntry, ConnectorAccountBadgeEntry, ConnectorAccountSection,
|
||||
ConnectorAccountSectionEntry, ConnectorAccountToast, ConnectorAccountToastEntry,
|
||||
} from '../src/client/components.tsx'
|
||||
import { zh } from '../src/client/locales.ts'
|
||||
import type { ConnectorAccountsState } from '../src/client/types.ts'
|
||||
import type { ConnectorAccountDisplay, ConnectorAccountEntry, ConnectorOperationId } from '../src/types.ts'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
const KEY = '@acme/fixture'
|
||||
const OP = 'op-1' as ConnectorOperationId
|
||||
const t = makeTranslate(zh)
|
||||
const resolveText = (text: LocalizedText): string => typeof text === 'string' ? text : text.zh ?? text.en
|
||||
const button = (name: string) => screen.getByRole('button', { name })
|
||||
const disabled = (): boolean[] => screen.getAllByRole('button').map(element => (element as HTMLButtonElement).disabled)
|
||||
|
||||
const DISCONNECTED: ConnectorAccountDisplay = {
|
||||
phase: 'disconnected', status: { en: 'Not connected', zh: '未连接' }, badge: '未连接',
|
||||
buttons: [{ label: '连接演示', command: { kind: 'start', operation: 'connect' }, variant: 'primary' }], notes: [],
|
||||
}
|
||||
|
||||
function entry(display: ConnectorAccountDisplay = DISCONNECTED, extra: Partial<ConnectorAccountEntry> = {}): ConnectorAccountEntry {
|
||||
return {
|
||||
key: KEY, packageName: KEY, display,
|
||||
copy: { title: { en: 'Fixture account', zh: '演示账号' }, hint: '与终端共用。', activation: { title: '连接演示', body: '插件已开启。', connect: '连接演示' } },
|
||||
...extra,
|
||||
}
|
||||
}
|
||||
|
||||
function section(change: Partial<{ linked: boolean; stopped: boolean; busy: boolean }> = {}, display?: ConnectorAccountDisplay) {
|
||||
const onCommand = vi.fn()
|
||||
const onRetry = vi.fn()
|
||||
const view = render(
|
||||
<ConnectorAccountSection t={t} resolveText={resolveText} entry={entry(display)} linked={change.linked ?? true}
|
||||
stopped={change.stopped ?? false} busy={change.busy ?? false} onCommand={onCommand} onRetry={onRetry} />,
|
||||
)
|
||||
return { ...view, onCommand, onRetry }
|
||||
}
|
||||
|
||||
it('shows the registrant title, status, detail, notes, and hint, and runs each button as its command', () => {
|
||||
const display: ConnectorAccountDisplay = {
|
||||
...DISCONNECTED, detail: '先关联一个应用。',
|
||||
notes: [{ text: '应用:cli_a', button: { label: '更换', command: { kind: 'start', operation: 'link-app' }, variant: 'ghost' } }, { text: '普通说明' }],
|
||||
}
|
||||
const { container, onCommand } = section({}, display)
|
||||
expect(screen.getByText('演示账号')).toBeTruthy()
|
||||
expect(screen.getByText('未连接')).toBeTruthy()
|
||||
expect(screen.getByText('先关联一个应用。')).toBeTruthy()
|
||||
expect(screen.getByText('普通说明')).toBeTruthy()
|
||||
expect(screen.getByText('与终端共用。')).toBeTruthy()
|
||||
expect(container.querySelector('[data-connector-account="disconnected"][data-connector-account-key="@acme/fixture"]')).toBeTruthy()
|
||||
fireEvent.click(button('连接演示'))
|
||||
fireEvent.click(button('更换'))
|
||||
expect(onCommand.mock.calls).toEqual([[{ kind: 'start', operation: 'connect' }], [{ kind: 'start', operation: 'link-app' }]])
|
||||
})
|
||||
|
||||
it('disables the buttons while a call is pending or the Host stream is down', () => {
|
||||
const { rerender } = section({ busy: true })
|
||||
expect(disabled()).toEqual([true])
|
||||
rerender(
|
||||
<ConnectorAccountSection t={t} resolveText={resolveText} entry={entry()} linked={false} stopped={false} busy={false}
|
||||
onCommand={vi.fn()} onRetry={vi.fn()} />,
|
||||
)
|
||||
expect(disabled()).toEqual([true])
|
||||
})
|
||||
|
||||
it('asks before a button that changes the account outside DSH and runs it only after the user accepts', () => {
|
||||
const display: ConnectorAccountDisplay = {
|
||||
phase: 'connected', status: '已连接', notes: [],
|
||||
buttons: [{ label: '退出登录', command: { kind: 'start', operation: 'sign-out' }, confirm: { title: '退出演示?', body: '终端也会退出。', label: '确认退出' } }],
|
||||
}
|
||||
const { onCommand } = section({}, display)
|
||||
fireEvent.click(button('退出登录'))
|
||||
expect(screen.getByRole('dialog', { name: '退出演示?' })).toBeTruthy()
|
||||
expect(screen.getByText('终端也会退出。')).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.cancel']))
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
fireEvent.click(button('退出登录'))
|
||||
fireEvent.click(button('确认退出'))
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
expect(onCommand.mock.calls).toEqual([[{ kind: 'start', operation: 'sign-out' }]])
|
||||
})
|
||||
|
||||
it.each<[string, ConnectorAccountDisplay['failure'], string]>([
|
||||
['the guidance, then its diagnostic items', { text: '失败。', details: ['login', 'exit 3', 'internal'] }, '失败。 排障信息:login · exit 3 · internal'],
|
||||
['the guidance alone without diagnostic items', { text: '失败。' }, '失败。'],
|
||||
['the guidance alone for an empty diagnostic list', { text: '失败。', details: [] }, '失败。'],
|
||||
])('reports %s', (_name, failure, expected) => {
|
||||
section({}, { ...DISCONNECTED, ...failure === undefined ? {} : { failure } })
|
||||
expect(screen.getByRole('alert').textContent).toBe(expected)
|
||||
})
|
||||
|
||||
it('explains a stopped stream with the shared copy and reopens it even while offline', () => {
|
||||
const { container, onRetry } = section({ stopped: true, linked: false }, { ...DISCONNECTED, failure: { text: '失败。' }, notes: [{ text: '说明' }] })
|
||||
expect(screen.getByText(zh['status.stopped'])).toBeTruthy()
|
||||
expect(screen.getByText(zh['detail.stopped'])).toBeTruthy()
|
||||
expect(screen.queryByRole('alert')).toBeNull()
|
||||
expect(screen.queryByText('说明')).toBeNull()
|
||||
expect(container.querySelector('[data-connector-account="stopped"]')).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.retry']))
|
||||
expect(onRetry).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('prompts to connect only while disconnected and steps aside once the phase settles elsewhere', () => {
|
||||
const onDismiss = vi.fn()
|
||||
const onConnect = vi.fn()
|
||||
const prompt = (phase: 'checking' | 'disconnected' | 'connected') =>
|
||||
<ConnectorAccountActivation t={t} phase={phase} title="连接演示" body="插件已开启。" connect="立即连接" onDismiss={onDismiss} onConnect={onConnect} />
|
||||
const { rerender } = render(prompt('checking'))
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
expect(onDismiss).not.toHaveBeenCalled()
|
||||
rerender(prompt('disconnected'))
|
||||
expect(screen.getByRole('dialog', { name: '连接演示' })).toBeTruthy()
|
||||
expect(screen.getByText('插件已开启。')).toBeTruthy()
|
||||
fireEvent.click(button('立即连接'))
|
||||
expect(onConnect).toHaveBeenCalledOnce()
|
||||
fireEvent.click(button(zh['activation.later']))
|
||||
expect(onDismiss).toHaveBeenCalledOnce()
|
||||
rerender(prompt('connected'))
|
||||
expect(onDismiss).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('shows the latest notice with the registrant text or the shared failure copy', () => {
|
||||
const onDone = vi.fn()
|
||||
const toast = (notice: ConnectorAccountsState['notice']) =>
|
||||
<ConnectorAccountToast t={t} resolveText={resolveText} notice={notice} onDone={onDone} />
|
||||
const { rerender } = render(toast(undefined))
|
||||
expect(document.body.textContent).toBe('')
|
||||
rerender(toast({ seq: 1, kind: 'succeeded', text: { en: 'Connected', zh: '演示已连接' } }))
|
||||
expect(screen.getByText('演示已连接')).toBeTruthy()
|
||||
rerender(toast({ seq: 2, kind: 'action-failed' }))
|
||||
expect(screen.getByText(zh['notice.action-failed'])).toBeTruthy()
|
||||
})
|
||||
|
||||
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, stopped: false, 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)),
|
||||
},
|
||||
account: KEY, resolveText, follow: vi.fn(), failed: vi.fn(), retry: vi.fn(), dismissNotice: vi.fn(), t,
|
||||
}
|
||||
}
|
||||
|
||||
it('starts an operation through the Remote, follows it, and stays busy until the call answers', async () => {
|
||||
const props = face()
|
||||
const answer = Promise.withResolvers<RemoteResult<ConnectorOperationId>>()
|
||||
props.remote.start.mockReturnValueOnce(answer.promise)
|
||||
render(<ConnectorAccountSectionEntry {...props} />)
|
||||
fireEvent.click(button('连接演示'))
|
||||
expect(props.remote.start).toHaveBeenCalledWith(KEY, 'connect')
|
||||
expect(disabled()).toEqual([true])
|
||||
await act(async () => { answer.resolve(ok(OP)) })
|
||||
expect(props.follow).toHaveBeenCalledWith(KEY, OP)
|
||||
expect(disabled()).toEqual([false])
|
||||
expect(props.failed).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reports a start the Host refused or that never answered, without following it', async () => {
|
||||
const props = face()
|
||||
props.remote.start.mockResolvedValueOnce(refused()).mockRejectedValueOnce(new Error('carrier lost'))
|
||||
render(<ConnectorAccountSectionEntry {...props} />)
|
||||
await act(async () => { fireEvent.click(button('连接演示')) })
|
||||
await act(async () => { fireEvent.click(button('连接演示')) })
|
||||
expect(props.failed).toHaveBeenCalledTimes(2)
|
||||
expect(props.follow).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cancels the operation in progress and opens its authorization page again on request', async () => {
|
||||
const windowOpen = vi.spyOn(window, 'open').mockReturnValue(null)
|
||||
onTestFinished(() => { windowOpen.mockRestore() })
|
||||
const display: ConnectorAccountDisplay = {
|
||||
phase: 'connecting', status: '等待浏览器', notes: [],
|
||||
buttons: [{ label: '打开授权页', command: { kind: 'open' } }, { label: '取消', command: { kind: 'cancel' }, variant: 'ghost' }],
|
||||
}
|
||||
const props = face({}, [entry(display, { operation: { id: OP, authorizationUrl: 'https://example.com/a' } })])
|
||||
render(<ConnectorAccountSectionEntry {...props} />)
|
||||
fireEvent.click(button('打开授权页'))
|
||||
expect(windowOpen).toHaveBeenCalledWith('https://example.com/a', '_blank', 'noopener,noreferrer')
|
||||
await act(async () => { fireEvent.click(button('取消')) })
|
||||
expect(props.remote.cancel).toHaveBeenCalledWith(KEY, OP)
|
||||
// A cancel button with no operation in progress calls nothing.
|
||||
cleanup()
|
||||
const idle = face({}, [entry(display)])
|
||||
render(<ConnectorAccountSectionEntry {...idle} />)
|
||||
await act(async () => { fireEvent.click(button('取消')) })
|
||||
expect(idle.remote.cancel).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
const prompt = (props: ReturnType<typeof face>, onOpenDetails = vi.fn()) =>
|
||||
<ConnectorAccountActivationEntry {...props} onDismiss={vi.fn()} onOpenDetails={onOpenDetails} />
|
||||
|
||||
it('renders nothing for a bundle whose account the Host has not listed', () => {
|
||||
render(<ConnectorAccountSectionEntry {...face({}, [])} />)
|
||||
render(prompt(face({}, [])))
|
||||
expect(document.body.textContent).toBe('')
|
||||
})
|
||||
|
||||
it('tags only the enabled bundle that owns an account, with the Host text or the shared copy once the stream stopped', () => {
|
||||
const pkg = (name: string, enabled = true) => ({ name, installed: true, availability: 'profile', official: false, enabled, rows: [] } as const)
|
||||
const page = (name: string, enabled = true): PluginsSubject => ({ kind: 'bundle', pkg: pkg(name, enabled) })
|
||||
const row: PluginsSubject = { kind: 'row', pkg: pkg(KEY), row: { rowId: 'fixture', moduleName: '@acme/fixture-row', enabled: true } }
|
||||
const tag = (props: ReturnType<typeof face>, subject: PluginsSubject) => <ConnectorAccountBadgeEntry {...props} subject={subject} />
|
||||
const { rerender } = render(tag(face(), page(KEY)))
|
||||
expect(screen.getByText('未连接')).toBeTruthy()
|
||||
rerender(tag(face(), row))
|
||||
expect(screen.getByText('未连接')).toBeTruthy()
|
||||
rerender(tag(face({ stopped: true }), page(KEY)))
|
||||
expect(screen.getByText(zh['badge.stopped'])).toBeTruthy()
|
||||
for (const [props, subject] of [
|
||||
[face(), page(KEY, false)], [face(), page('@acme/other')], [face(), { kind: 'item', id: 'fixture-item' }],
|
||||
[face({}, [entry({ phase: 'checking', status: '检查中', buttons: [], notes: [] })]), page(KEY)],
|
||||
] as const) {
|
||||
rerender(tag(props, subject))
|
||||
expect(document.body.textContent).toBe('')
|
||||
}
|
||||
})
|
||||
|
||||
it('connects from the prompt through the operation the display names, or only opens the page', async () => {
|
||||
const onOpenDetails = vi.fn()
|
||||
const named = face({}, [entry({ ...DISCONNECTED, connect: { kind: 'start', operation: 'link-app' } })])
|
||||
const { rerender } = render(prompt(named, onOpenDetails))
|
||||
await act(async () => { fireEvent.click(button('连接演示')) })
|
||||
expect(onOpenDetails).toHaveBeenCalledOnce()
|
||||
expect(named.remote.start).toHaveBeenCalledWith(KEY, 'link-app')
|
||||
const bare = face()
|
||||
rerender(prompt(bare, onOpenDetails))
|
||||
fireEvent.click(button('连接演示'))
|
||||
expect(onOpenDetails).toHaveBeenCalledTimes(2)
|
||||
expect(bare.remote.start).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('starts once for a second click before the first call answers', async () => {
|
||||
const props = face({}, [entry({ ...DISCONNECTED, connect: { kind: 'start', operation: 'connect' } })])
|
||||
const answer = Promise.withResolvers<RemoteResult<ConnectorOperationId>>()
|
||||
props.remote.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()
|
||||
expect(props.follow).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('shows the account notice through the toast entry', () => {
|
||||
render(<ConnectorAccountToastEntry {...face({ notice: { seq: 1, kind: 'succeeded', text: '演示已连接' } })} />)
|
||||
expect(screen.getByText('演示已连接')).toBeTruthy()
|
||||
})
|
||||
@@ -0,0 +1,166 @@
|
||||
/** The registry serves every registered account to the Plugins page and routes page operations to the account that owns them. */
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import { expect, it, onTestFinished, vi } from 'vitest'
|
||||
import ConnectorAccounts from '../src/index.ts'
|
||||
import type {
|
||||
ConnectorAccountDisplay, ConnectorAccountRegistration, ConnectorAccountSource, ConnectorAccountsView, ConnectorAccountView,
|
||||
ConnectorOperationId,
|
||||
} from '../src/types.ts'
|
||||
|
||||
type View = ConnectorAccountView<{ readonly state: 'out' | 'in' }, 'check' | 'connect', 'authorizing'>
|
||||
|
||||
const OP = 'op-1' as ConnectorOperationId
|
||||
const COPY = {
|
||||
title: { en: 'Fixture account', zh: '演示账号' },
|
||||
hint: 'Shared with the terminal.',
|
||||
activation: { title: 'Connect Fixture', body: 'The plugin is on.', connect: 'Connect' },
|
||||
}
|
||||
|
||||
function source(initial: View = { account: { state: 'out' } }) {
|
||||
let view = initial
|
||||
const listeners = new Set<() => void>()
|
||||
const fake = {
|
||||
snapshot: () => view,
|
||||
observe: vi.fn((listener: () => void) => { listeners.add(listener); return () => { listeners.delete(listener) } }),
|
||||
refresh: vi.fn(),
|
||||
start: vi.fn((_kind: 'check' | 'connect') => OP),
|
||||
cancel: vi.fn(async (_id: ConnectorOperationId) => {}),
|
||||
} satisfies ConnectorAccountSource<View>
|
||||
return { fake, listeners, publish: (next: View) => { view = next; for (const listener of listeners) listener() } }
|
||||
}
|
||||
|
||||
function display(view: View): ConnectorAccountDisplay {
|
||||
return view.account.state === 'in'
|
||||
? { phase: 'connected', status: 'Connected', badge: 'Connected', buttons: [], notes: [] }
|
||||
: { phase: 'disconnected', status: 'Not connected', buttons: [{ label: 'Connect', command: { kind: 'start', operation: 'connect' }, variant: 'primary' }], notes: [] }
|
||||
}
|
||||
|
||||
/** A registration whose bundle package defaults to its key; `null` registers an account no bundle owns. */
|
||||
function registration(key: string, account = source(), packageName: string | null = key): ConnectorAccountRegistration<View> {
|
||||
return {
|
||||
key, ...packageName === null ? {} : { packageName }, source: account.fake, copy: COPY, present: display,
|
||||
operations: [{ kind: 'check' }, { kind: 'connect', notice: { en: 'Fixture connected', zh: '演示已连接' } }],
|
||||
}
|
||||
}
|
||||
|
||||
async function registry() {
|
||||
const ctx = new Context()
|
||||
onTestFinished(async () => { await ctx.fiber.dispose() })
|
||||
await ctx.plugin(ConnectorAccounts)
|
||||
return ctx
|
||||
}
|
||||
|
||||
/** Read the stream until a view satisfies the predicate. */
|
||||
async function until(
|
||||
stream: AsyncIterator<ConnectorAccountsView>, predicate: (view: ConnectorAccountsView) => boolean,
|
||||
): Promise<ConnectorAccountsView> {
|
||||
for (;;) {
|
||||
const next = await stream.next()
|
||||
if (next.done === true) throw new Error('stream ended')
|
||||
if (predicate(next.value)) return next.value
|
||||
}
|
||||
}
|
||||
|
||||
it('publishes each account with its key, package, copy, display, operation, and result, and checks it for each new subscriber', async () => {
|
||||
const ctx = await registry()
|
||||
const account = source()
|
||||
const withdraw = ctx.connectorAccounts.register(registration('@acme/fixture', account))
|
||||
expect(account.fake.refresh).not.toHaveBeenCalled()
|
||||
const controller = new AbortController()
|
||||
const stream = ctx.connectorAccounts.watch(controller.signal)[Symbol.asyncIterator]()
|
||||
const first = await until(stream, () => true)
|
||||
expect(account.fake.refresh).toHaveBeenCalledOnce()
|
||||
expect(first.accounts).toEqual([
|
||||
{ key: '@acme/fixture', packageName: '@acme/fixture', copy: COPY, display: display({ account: { state: 'out' } }) },
|
||||
])
|
||||
|
||||
account.publish({ account: { state: 'out' }, operation: { id: OP, kind: 'connect', phase: 'authorizing', cancellable: true, authorizationUrl: 'https://example.com/a' } })
|
||||
const waiting = await until(stream, view => view.accounts[0]?.operation !== undefined)
|
||||
expect(waiting.accounts[0]?.operation).toEqual({ id: OP, authorizationUrl: 'https://example.com/a' })
|
||||
|
||||
account.publish({ account: { state: 'out' }, operation: { id: OP, kind: 'connect', phase: 'authorizing', cancellable: false } })
|
||||
const checking = await until(stream, (view) => {
|
||||
const operation = view.accounts[0]?.operation
|
||||
return operation !== undefined && operation.authorizationUrl === undefined
|
||||
})
|
||||
expect(checking.accounts[0]?.operation).toEqual({ id: OP })
|
||||
|
||||
account.publish({ account: { state: 'in' }, result: { id: OP, kind: 'connect', outcome: 'succeeded' } })
|
||||
const connected = await until(stream, view => view.accounts[0]?.result !== undefined)
|
||||
expect(connected.accounts[0]).toMatchObject({
|
||||
display: { phase: 'connected' }, result: { id: OP, notice: { en: 'Fixture connected', zh: '演示已连接' } },
|
||||
})
|
||||
|
||||
// Only a success reports a notice, and only for an operation that registered one.
|
||||
account.publish({ account: { state: 'out' }, result: { id: OP, kind: 'connect', outcome: 'failed' } })
|
||||
expect((await until(stream, view => view.accounts[0]?.display.phase === 'disconnected')).accounts[0]?.result).toEqual({ id: OP })
|
||||
account.publish({ account: { state: 'in' }, result: { id: OP, kind: 'check', outcome: 'succeeded' } })
|
||||
expect((await until(stream, view => view.accounts[0]?.display.phase === 'connected')).accounts[0]?.result).toEqual({ id: OP })
|
||||
|
||||
withdraw()
|
||||
expect((await until(stream, view => view.accounts.length === 0)).accounts).toEqual([])
|
||||
withdraw()
|
||||
expect(account.listeners.size).toBe(0)
|
||||
controller.abort()
|
||||
expect((await stream.next()).done).toBe(true)
|
||||
})
|
||||
|
||||
it('publishes an account that no bundle owns without a package', async () => {
|
||||
const ctx = await registry()
|
||||
ctx.connectorAccounts.register(registration('mcp:custom', source(), null))
|
||||
const stream = ctx.connectorAccounts.watch(new AbortController().signal)[Symbol.asyncIterator]()
|
||||
const [entry] = (await until(stream, () => true)).accounts
|
||||
expect(entry).toEqual({ key: 'mcp:custom', copy: COPY, display: display({ account: { state: 'out' } }) })
|
||||
})
|
||||
|
||||
it('checks an account registered while the page follows, and none registered while nobody follows', async () => {
|
||||
const ctx = await registry()
|
||||
const idle = source()
|
||||
ctx.connectorAccounts.register(registration('@acme/idle', idle))
|
||||
const controller = new AbortController()
|
||||
const stream = ctx.connectorAccounts.watch(controller.signal)[Symbol.asyncIterator]()
|
||||
await until(stream, view => view.accounts.length === 1)
|
||||
const late = source()
|
||||
ctx.connectorAccounts.register(registration('@acme/late', late))
|
||||
expect(late.fake.refresh).toHaveBeenCalledOnce()
|
||||
expect((await until(stream, view => view.accounts.length === 2)).accounts.map(entry => entry.key)).toEqual(['@acme/idle', '@acme/late'])
|
||||
controller.abort()
|
||||
await stream.next()
|
||||
const after = source()
|
||||
ctx.connectorAccounts.register(registration('@acme/after', after))
|
||||
expect(after.fake.refresh).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('starts only the operations an account registered and cancels through its source', async () => {
|
||||
const ctx = await registry()
|
||||
const account = source()
|
||||
ctx.connectorAccounts.register(registration('@acme/fixture', account))
|
||||
expect(ctx.connectorAccounts.start('@acme/fixture', 'connect')).toBe(OP)
|
||||
expect(account.fake.start).toHaveBeenCalledWith('connect')
|
||||
expect(() => ctx.connectorAccounts.start('@acme/fixture', 'sign-out')).toThrow('@acme/fixture has no page operation sign-out')
|
||||
expect(() => ctx.connectorAccounts.start('@acme/other', 'connect')).toThrow('@acme/other is not registered')
|
||||
await ctx.connectorAccounts.cancel('@acme/fixture', OP)
|
||||
expect(account.fake.cancel).toHaveBeenCalledWith(OP)
|
||||
expect(() => ctx.connectorAccounts.cancel('@acme/other', OP)).toThrow('@acme/other is not registered')
|
||||
})
|
||||
|
||||
it('refuses a second account for a key or for a package', async () => {
|
||||
const ctx = await registry()
|
||||
ctx.connectorAccounts.register(registration('@acme/fixture'))
|
||||
expect(() => ctx.connectorAccounts.register(registration('@acme/fixture'))).toThrow('@acme/fixture is already registered')
|
||||
expect(() => ctx.connectorAccounts.register(registration('mcp:fixture', source(), '@acme/fixture')))
|
||||
.toThrow('@acme/fixture already has an account')
|
||||
expect(() => ctx.connectorAccounts.register(registration('mcp:custom', source(), null))).not.toThrow()
|
||||
})
|
||||
|
||||
it('ends every stream when the registry unloads', async () => {
|
||||
const ctx = new Context()
|
||||
const fiber = ctx.plugin(ConnectorAccounts)
|
||||
await fiber
|
||||
const stream = ctx.connectorAccounts.watch(new AbortController().signal)[Symbol.asyncIterator]()
|
||||
await until(stream, () => true)
|
||||
const pending = stream.next()
|
||||
await fiber.dispose()
|
||||
expect((await pending).done).toBe(true)
|
||||
await ctx.fiber.dispose()
|
||||
})
|
||||
@@ -0,0 +1,194 @@
|
||||
// @vitest-environment jsdom
|
||||
/** The browser follows every registered account through one Host stream and keeps only what this browser started. */
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import { RemoteStreamCarrierError, type RemoteStreamOptions } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import { expect, it, onTestFinished, vi } from 'vitest'
|
||||
import { BrowserAccounts, openAuthorizationPage } from '../src/client/state.ts'
|
||||
import type { ConnectorAccountEntry, ConnectorAccountsView, ConnectorOperationId } from '../src/types.ts'
|
||||
|
||||
const OP = 'op-1' as ConnectorOperationId
|
||||
const NEXT = 'op-2' as ConnectorOperationId
|
||||
const FIXTURE = '@acme/fixture'
|
||||
const OTHER = 'mcp:other'
|
||||
const COPY = { title: 'Fixture account', hint: 'Shared.', activation: { title: 'Connect', body: 'On.', connect: 'Connect' } }
|
||||
|
||||
function entry(key: string, extra: Partial<ConnectorAccountEntry> = {}): ConnectorAccountEntry {
|
||||
return { key, copy: COPY, display: { phase: 'disconnected', status: 'Not connected', buttons: [], notes: [] }, ...extra }
|
||||
}
|
||||
|
||||
const waiting = (url?: string, id = OP): Partial<ConnectorAccountEntry> =>
|
||||
({ operation: { id, ...url === undefined ? {} : { authorizationUrl: url } } })
|
||||
|
||||
function fixture() {
|
||||
const queue: ConnectorAccountsView[] = []
|
||||
let wake: (() => void) | undefined, closed = false, failure: Error | undefined, accepted = 0
|
||||
let options!: RemoteStreamOptions<ConnectorAccountsView>
|
||||
const open = () => ({
|
||||
async *[Symbol.asyncIterator]() {
|
||||
for (;;) {
|
||||
if (failure !== undefined) throw failure
|
||||
// A queued item still arrives after close, as an item the stream yielded just before disposal does.
|
||||
const next = queue.shift()
|
||||
if (next !== undefined) { yield { value: next, accept: () => { accepted++ } }; continue }
|
||||
if (closed) return
|
||||
await new Promise<void>((resolve) => { wake = resolve })
|
||||
}
|
||||
},
|
||||
dispose: vi.fn(async () => { closed = true; wake?.() }),
|
||||
})
|
||||
const streams: Array<ReturnType<typeof open>> = []
|
||||
const remote = { watch: vi.fn() }
|
||||
const ctx = new Context()
|
||||
ctx.provide('remote', {
|
||||
$stream: (value: typeof options) => {
|
||||
options = value
|
||||
closed = false
|
||||
failure = undefined
|
||||
streams.push(open())
|
||||
return streams.at(-1)
|
||||
},
|
||||
})
|
||||
const windowOpen = vi.spyOn(window, 'open').mockReturnValue(null)
|
||||
const browser = new BrowserAccounts(ctx, remote)
|
||||
onTestFinished(async () => { await browser.dispose(); windowOpen.mockRestore(); await ctx.fiber.dispose() })
|
||||
return {
|
||||
browser, remote, open: windowOpen, streams, options: () => options,
|
||||
state: () => browser.state.getSnapshot(),
|
||||
deliver(view: ConnectorAccountsView) { queue.push(view); wake?.() },
|
||||
async publish(...entries: ConnectorAccountEntry[]) {
|
||||
const target = accepted + 1
|
||||
this.deliver({ accounts: entries })
|
||||
await vi.waitFor(() => { expect(accepted).toBe(target) })
|
||||
},
|
||||
fail(error: Error) { failure = error; wake?.() },
|
||||
}
|
||||
}
|
||||
|
||||
// Every fixture step settles through microtasks, so one macrotask lets a pending reopen finish.
|
||||
const drain = () => new Promise<void>((resolve) => { setTimeout(resolve, 0) })
|
||||
|
||||
it('mirrors the Host accounts by key and reports carrier loss until the next item', async () => {
|
||||
const b = fixture()
|
||||
expect(b.state()).toEqual({ accounts: new Map(), linked: true, stopped: false, notice: undefined })
|
||||
const open = b.options().open(new AbortController().signal)
|
||||
expect(b.remote.watch).toHaveBeenCalledOnce()
|
||||
expect(open).toBe(b.remote.watch.mock.results[0]?.value)
|
||||
await b.publish(entry(FIXTURE), entry(OTHER))
|
||||
expect([...b.state().accounts.keys()]).toEqual([FIXTURE, OTHER])
|
||||
b.options().carrierFailed?.(new RemoteStreamCarrierError('offline'))
|
||||
expect(b.state().linked).toBe(false)
|
||||
await b.publish(entry(FIXTURE))
|
||||
expect(b.state()).toMatchObject({ linked: true, stopped: false })
|
||||
expect([...b.state().accounts.keys()]).toEqual([FIXTURE])
|
||||
expect(b.options().ended(true).message).toBe('Connector accounts stream ended')
|
||||
})
|
||||
|
||||
it('opens each new authorization page of an operation this browser started once, and no other account\'s', async () => {
|
||||
const b = fixture()
|
||||
b.browser.follow(FIXTURE, OP)
|
||||
await b.publish(entry(FIXTURE, waiting('https://example.com/a')), entry(OTHER, waiting('https://example.com/other')))
|
||||
expect(b.open.mock.calls).toEqual([['https://example.com/a', '_blank', 'noopener,noreferrer']])
|
||||
await b.publish(entry(FIXTURE, waiting('https://example.com/a')))
|
||||
await b.publish(entry(FIXTURE, waiting('http://127.0.0.1:8123/authorize')))
|
||||
// Another browser's operation on the same account opens nothing here.
|
||||
await b.publish(entry(FIXTURE, waiting('https://example.com/b', NEXT)))
|
||||
expect(b.open.mock.calls.map(([url]) => url)).toEqual(['https://example.com/a', 'http://127.0.0.1:8123/authorize'])
|
||||
})
|
||||
|
||||
it('opens the page at once when the stream delivered the operation before the start call answered', async () => {
|
||||
const b = fixture()
|
||||
await b.publish(entry(FIXTURE, waiting('https://example.com/a')))
|
||||
expect(b.open).not.toHaveBeenCalled()
|
||||
b.browser.follow(FIXTURE, OP)
|
||||
expect(b.open).toHaveBeenCalledWith('https://example.com/a', '_blank', 'noopener,noreferrer')
|
||||
})
|
||||
|
||||
it('reports the success of an operation this browser started once, and stops following it', async () => {
|
||||
const b = fixture()
|
||||
b.browser.follow(FIXTURE, OP)
|
||||
await b.publish(entry(FIXTURE, { result: { id: NEXT, notice: 'Other browser connected' } }))
|
||||
expect(b.state().notice).toBeUndefined()
|
||||
await b.publish(entry(FIXTURE, { result: { id: OP, notice: 'Fixture connected' } }))
|
||||
expect(b.state().notice).toEqual({ seq: 1, kind: 'succeeded', text: 'Fixture connected' })
|
||||
b.browser.dismissNotice()
|
||||
await b.publish(entry(FIXTURE, { result: { id: OP, notice: 'Fixture connected' } }))
|
||||
expect(b.state().notice).toBeUndefined()
|
||||
|
||||
// A result without the registrant's text, or a cancelled or failed one, reports nothing.
|
||||
b.browser.follow(FIXTURE, NEXT)
|
||||
await b.publish(entry(FIXTURE, { result: { id: NEXT } }))
|
||||
expect(b.state().notice).toBeUndefined()
|
||||
})
|
||||
|
||||
it('forgets the operation of an account the Host withdrew', async () => {
|
||||
const b = fixture()
|
||||
b.browser.follow(FIXTURE, OP)
|
||||
await b.publish(entry(OTHER))
|
||||
await b.publish(entry(FIXTURE, waiting('https://example.com/a')))
|
||||
expect(b.open).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reports a call that did not finish with a fresh notice each time', () => {
|
||||
const b = fixture()
|
||||
b.browser.failed()
|
||||
b.browser.failed()
|
||||
expect(b.state().notice).toEqual({ seq: 2, kind: 'action-failed' })
|
||||
})
|
||||
|
||||
it('stops after a terminal stream failure and reopens on retry', async () => {
|
||||
const b = fixture()
|
||||
await b.publish(entry(FIXTURE))
|
||||
b.browser.retry()
|
||||
expect(b.streams).toHaveLength(1)
|
||||
b.fail(new Error('Host without the registry'))
|
||||
await vi.waitFor(() => { expect(b.state().stopped).toBe(true) })
|
||||
expect(b.state().linked).toBe(false)
|
||||
b.browser.retry()
|
||||
b.browser.retry()
|
||||
await drain()
|
||||
expect(b.streams).toHaveLength(2)
|
||||
expect(b.streams[0]?.dispose).toHaveBeenCalledOnce()
|
||||
await b.publish(entry(FIXTURE))
|
||||
expect(b.state()).toMatchObject({ linked: true, stopped: false })
|
||||
})
|
||||
|
||||
it('opens nothing and reports nothing after disposal, and a retry pending at disposal opens no stream', async () => {
|
||||
const b = fixture()
|
||||
b.fail(new Error('Host without the registry'))
|
||||
await vi.waitFor(() => { expect(b.state().stopped).toBe(true) })
|
||||
b.browser.retry()
|
||||
await b.browser.dispose()
|
||||
await drain()
|
||||
expect(b.streams).toHaveLength(1)
|
||||
b.browser.follow(FIXTURE, OP)
|
||||
b.browser.failed()
|
||||
b.browser.retry()
|
||||
expect(b.state().notice).toBeUndefined()
|
||||
})
|
||||
|
||||
it('shows nothing for a stream that fails while the page disposes it', async () => {
|
||||
const b = fixture()
|
||||
const disposing = b.browser.dispose()
|
||||
b.fail(new Error('carrier lost'))
|
||||
await disposing
|
||||
expect(b.state()).toMatchObject({ linked: true, stopped: false })
|
||||
})
|
||||
|
||||
it('ignores an item the stream yielded just before disposal', async () => {
|
||||
const b = fixture()
|
||||
const disposing = b.browser.dispose()
|
||||
b.deliver({ accounts: [entry(FIXTURE)] })
|
||||
await disposing
|
||||
expect(b.state().accounts.size).toBe(0)
|
||||
})
|
||||
|
||||
it('opens only HTTPS pages and HTTP pages on loopback addresses', () => {
|
||||
const windowOpen = vi.spyOn(window, 'open').mockReturnValue(null)
|
||||
onTestFinished(() => { windowOpen.mockRestore() })
|
||||
for (const url of [undefined, 'not a url', 'http://example.com/a', 'javascript:alert(1)']) openAuthorizationPage(url)
|
||||
expect(windowOpen).not.toHaveBeenCalled()
|
||||
for (const url of ['https://example.com/a', 'http://localhost:1/a', 'http://[::1]:1/a', 'http://127.0.0.1:1/a']) openAuthorizationPage(url)
|
||||
expect(windowOpen.mock.calls.map(([url]) => url)).toEqual([
|
||||
'https://example.com/a', 'http://localhost:1/a', 'http://[::1]:1/a', 'http://127.0.0.1:1/a',
|
||||
])
|
||||
})
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.client.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types",
|
||||
"tsBuildInfoFile": "lib/tsconfig.client.tsbuildinfo"
|
||||
},
|
||||
"include": [
|
||||
"src/client",
|
||||
"src/css-modules.d.ts",
|
||||
"src/types.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../vendor/cordis"
|
||||
},
|
||||
{
|
||||
"path": "../../api/gateway/tsconfig.client.json"
|
||||
},
|
||||
{
|
||||
"path": "../../api/remotes/tsconfig.client.json"
|
||||
},
|
||||
{
|
||||
"path": "../store"
|
||||
},
|
||||
{
|
||||
"path": "../ui-layout"
|
||||
},
|
||||
{
|
||||
"path": "../ui-plugin-manager/tsconfig.client.json"
|
||||
},
|
||||
{
|
||||
"path": "../ui-primitives"
|
||||
},
|
||||
{
|
||||
"path": "../ui-renderer"
|
||||
},
|
||||
{
|
||||
"path": "../ui-slots"
|
||||
},
|
||||
{
|
||||
"path": "../../typert/protocol"
|
||||
},
|
||||
{
|
||||
"path": "../locale/tsconfig.client.json"
|
||||
},
|
||||
{
|
||||
"path": "../../util/brand"
|
||||
},
|
||||
{
|
||||
"path": "../../util/package-manifest"
|
||||
},
|
||||
{
|
||||
"path": "../../util/values"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types",
|
||||
"tsBuildInfoFile": "lib/tsconfig.host.tsbuildinfo"
|
||||
},
|
||||
"files": [
|
||||
"src/index.ts",
|
||||
"src/types.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../vendor/cordis"
|
||||
},
|
||||
{
|
||||
"path": "../../typert/protocol"
|
||||
},
|
||||
{
|
||||
"path": "../../util/brand"
|
||||
},
|
||||
{
|
||||
"path": "../../util/package-manifest"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.host.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.client.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { clientBundle } from '../tsdown.client.ts'
|
||||
|
||||
export default clientBundle(import.meta.dirname, ['lib/types/index.js'], { hostPhase: true })
|
||||
@@ -163,6 +163,9 @@ export const VIEWER_ENDPOINT_CLASSES = {
|
||||
'productAnalytics/report': 'owner-only', // owner product analytics
|
||||
'productAnalytics/watchPolicy': 'owner-only', // owner product analytics
|
||||
'pluginRegistryProbe/fastest': 'owner-only', // owner plugin registry probe
|
||||
'connectorAccounts/cancel': 'owner-only', // owner connector accounts on the Plugins page
|
||||
'connectorAccounts/start': 'owner-only', // owner connector accounts on the Plugins page
|
||||
'connectorAccounts/watch': 'owner-only', // owner connector accounts on the Plugins page
|
||||
'sessionReferenceResolver/candidates': 'owner-only', // owner composer reference resolution
|
||||
'officeKit/generation': 'owner-only', // owner document export
|
||||
'officeKit/render': 'owner-only', // owner document export
|
||||
|
||||
@@ -2831,6 +2831,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
slotInject: '',
|
||||
declaredBy: 'an entry in \'main\' (client-ui-plugin-manager), so it exists while that entry is mounted',
|
||||
occupants: [
|
||||
'client-ui-connector-account ConnectorAccountActivationEntry',
|
||||
'experimental-client-ui-voice-input VoiceSetupPrompt key \'@deepseek-ai/dsh-experimental-voice-input-bundle\'',
|
||||
'cua PermissionSetup key \'@deepseek-ai/dsh-cua-bundle\'',
|
||||
],
|
||||
@@ -2875,6 +2876,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
slotInject: '',
|
||||
declaredBy: 'an entry in \'main\' (client-ui-plugin-manager), so it exists while that entry is mounted',
|
||||
occupants: [
|
||||
'client-ui-connector-account ConnectorAccountSectionEntry',
|
||||
'experimental-client-ui-cot-translation TranslationSettings key \'@deepseek-ai/dsh-experimental-cot-translation-bundle\'',
|
||||
'experimental-client-ui-voice-input VoicePreparation key \'@deepseek-ai/dsh-experimental-voice-input-bundle\'',
|
||||
'cua PermissionPanel key \'@deepseek-ai/dsh-cua-bundle\'',
|
||||
@@ -2984,7 +2986,9 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
hookContext: '',
|
||||
slotInject: '',
|
||||
declaredBy: 'an entry in \'main\' (client-ui-plugin-manager), so it exists while that entry is mounted',
|
||||
occupants: [],
|
||||
occupants: [
|
||||
'client-ui-connector-account ConnectorAccountBadgeEntry id \'connector-account.badge\'',
|
||||
],
|
||||
replaceRisk: 'none',
|
||||
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'plugins.detail.badge\', () => ctx.slots.register(\n { name: \'plugins.detail.badge\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
|
||||
source: 'packages/client/ui-plugin-manager/src/client/slot-contract.ts:178',
|
||||
@@ -4052,6 +4056,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
occupants: [
|
||||
'client-ui-agent-team TeamDisableConfirmation id \'agent-team.disable\'',
|
||||
'client-ui-chat QuotaNoticeHost id \'chat.quota-notice\'',
|
||||
'client-ui-connector-account ConnectorAccountToastEntry id \'connector-account.notice\'',
|
||||
'client-ui-context-menu MenuOverlay id \'context-menu\'',
|
||||
'client-ui-file-drag FileDragFeedback id \'file-drag.feedback\'',
|
||||
'client-ui-open-in-app OpenInAppToast id \'open-in-app.toast\'',
|
||||
|
||||
@@ -812,6 +812,40 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'connectorAccounts',
|
||||
summary: 'Holds the registered accounts and serves them to the Plugins page.',
|
||||
description: 'Holds the registered accounts and serves them to the Plugins page.',
|
||||
methods: [
|
||||
{
|
||||
signature: 'register<View extends AnyConnectorAccountView>(registration: ConnectorAccountRegistration<View>): () => void',
|
||||
description: 'Show one account on the Plugins page for as long as the returned disposer has not run.',
|
||||
parameters: [{ name: 'registration', description: 'the account key, its bundle package, the account source, the page operations, and the presentation.' }],
|
||||
returns: 'an idempotent disposer that withdraws the account.',
|
||||
throws: ['when another account already uses the key or the package.'],
|
||||
},
|
||||
{
|
||||
signature: '@Remote({ mode: \'stream\' }) async *watch(signal: AbortSignal): AsyncIterable<ConnectorAccountsView>',
|
||||
description: 'Follow every registered account; each new subscriber starts a check of each account that runs no operation.',
|
||||
parameters: [{ name: 'signal', description: 'the Client\'s observation lifetime; disposal also ends the stream.' }],
|
||||
returns: 'the current accounts, then each changed set, coalescing changes that arrive before the next read.',
|
||||
},
|
||||
{
|
||||
signature: '@Remote start(key: string, operation: string): ConnectorOperationId',
|
||||
description: 'Start one of the operations the account registered as page actions.',
|
||||
parameters: [{ name: 'key', description: 'the account key.' }, { name: 'operation', description: 'the operation kind.' }],
|
||||
returns: 'the operation identity.',
|
||||
throws: ['for an unknown account or operation, or whatever the account\'s source refuses, such as a second operation.'],
|
||||
},
|
||||
{
|
||||
signature: '@Remote cancel(key: string, id: ConnectorOperationId): Promise<void>',
|
||||
description: 'Cancel one operation while its phase is cancellable, and wait for it to settle.',
|
||||
parameters: [{ name: 'key', description: 'the account key.' }, { name: 'id', description: 'the operation to cancel; a finished one or a phase that is not cancellable is ignored.' }],
|
||||
returns: 'after the operation settles, or at once when nothing is cancelled.',
|
||||
throws: ['for an unknown account.'],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'cotTranslation',
|
||||
summary: 'Optional reasoning translation delegates Session-bound storage to the translator.',
|
||||
@@ -5754,6 +5788,10 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
name: 'AnonymousTranslationSpec',
|
||||
declaration: 'export interface AnonymousTranslationSpec extends TranslationSpecFields {\n readonly provider: AnonymousTranslationProvider;\n}',
|
||||
},
|
||||
{
|
||||
name: 'AnyConnectorAccountView',
|
||||
declaration: 'export type AnyConnectorAccountView = ConnectorAccountView<unknown, string, string>;',
|
||||
},
|
||||
{
|
||||
name: 'AnyHook',
|
||||
declaration: 'export type AnyHook = ModHook<unknown, unknown>;',
|
||||
@@ -6178,6 +6216,78 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
name: 'ConnectionTrustRequest',
|
||||
declaration: 'export interface ConnectionTrustRequest {\n readonly headers: Headers | Readonly<Record<string, string | readonly string[] | undefined>>;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountButton',
|
||||
declaration: 'export interface ConnectorAccountButton {\n readonly label: LocalizedText;\n readonly command: ConnectorAccountCommand;\n readonly variant?: \'primary\' | \'ghost\';\n readonly confirm?: ConnectorAccountConfirmation;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountCommand',
|
||||
declaration: 'export type ConnectorAccountCommand = {\n readonly kind: \'start\';\n readonly operation: string;\n} | {\n readonly kind: \'cancel\';\n} | {\n readonly kind: \'open\';\n};',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountConfirmation',
|
||||
declaration: 'export interface ConnectorAccountConfirmation {\n readonly title: LocalizedText;\n readonly body: LocalizedText;\n readonly label: LocalizedText;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountCopy',
|
||||
declaration: 'export interface ConnectorAccountCopy {\n readonly title: LocalizedText;\n readonly hint: LocalizedText;\n readonly activation: {\n readonly title: LocalizedText;\n readonly body: LocalizedText;\n readonly connect: LocalizedText;\n };\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountDisplay',
|
||||
declaration: 'export interface ConnectorAccountDisplay {\n readonly phase: ConnectorAccountPhase;\n readonly status: LocalizedText;\n readonly badge?: LocalizedText;\n readonly buttons: readonly ConnectorAccountButton[];\n readonly connect?: Extract<ConnectorAccountCommand, {\n readonly kind: \'start\';\n }>;\n readonly detail?: LocalizedText;\n readonly notes: readonly ConnectorAccountNote[];\n readonly failure?: ConnectorAccountFailure;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountEntry',
|
||||
declaration: 'export interface ConnectorAccountEntry {\n readonly key: string;\n readonly packageName?: string;\n readonly copy: ConnectorAccountCopy;\n readonly display: ConnectorAccountDisplay;\n readonly operation?: {\n readonly id: ConnectorOperationId;\n readonly authorizationUrl?: string;\n };\n readonly result?: {\n readonly id: ConnectorOperationId;\n readonly notice?: LocalizedText;\n };\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountFailure',
|
||||
declaration: 'export interface ConnectorAccountFailure {\n readonly text: LocalizedText;\n readonly details?: readonly string[];\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountNote',
|
||||
declaration: 'export interface ConnectorAccountNote {\n readonly text: LocalizedText;\n readonly button?: ConnectorAccountButton;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountOperation',
|
||||
declaration: 'export interface ConnectorAccountOperation<Kind extends string> {\n readonly kind: Kind;\n readonly notice?: LocalizedText;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountPhase',
|
||||
declaration: 'export type ConnectorAccountPhase = \'checking\' | \'connecting\' | \'connected\' | \'disconnected\' | \'unavailable\';',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountRegistration',
|
||||
declaration: 'export interface ConnectorAccountRegistration<View extends AnyConnectorAccountView> {\n readonly key: string;\n readonly packageName?: string;\n readonly source: ConnectorAccountSource<View>;\n readonly operations: readonly ConnectorAccountOperation<ConnectorOperationKindOf<View>>[];\n readonly copy: ConnectorAccountCopy;\n readonly present: (view: View) => ConnectorAccountDisplay;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountSource',
|
||||
declaration: 'export interface ConnectorAccountSource<View extends AnyConnectorAccountView> {\n snapshot(): View;\n observe(listener: () => void): () => void;\n refresh(): void;\n start(kind: ConnectorOperationKindOf<View>): ConnectorOperationId;\n cancel(id: ConnectorOperationId): Promise<void>;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountsView',
|
||||
declaration: 'export interface ConnectorAccountsView {\n readonly accounts: readonly ConnectorAccountEntry[];\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorAccountView',
|
||||
declaration: 'export interface ConnectorAccountView<Account, Kind extends string, Phase extends string, Failure = unknown> {\n readonly account: Account;\n readonly operation?: ConnectorOperation<Kind, Phase>;\n readonly result?: ConnectorOperationResult<Kind, Failure>;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorOperation',
|
||||
declaration: 'export interface ConnectorOperation<Kind extends string, Phase extends string> {\n readonly id: ConnectorOperationId;\n readonly kind: Kind;\n readonly phase: Phase;\n readonly cancellable: boolean;\n readonly authorizationUrl?: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorOperationId',
|
||||
declaration: 'export type ConnectorOperationId = Branded<\'ConnectorOperationId\'>;',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorOperationKindOf',
|
||||
declaration: 'export type ConnectorOperationKindOf<View extends AnyConnectorAccountView> = NonNullable<View[\'result\']>[\'kind\'];',
|
||||
},
|
||||
{
|
||||
name: 'ConnectorOperationResult',
|
||||
declaration: 'export interface ConnectorOperationResult<Kind extends string, Failure = unknown> {\n readonly id: ConnectorOperationId;\n readonly kind: Kind;\n readonly outcome: \'succeeded\' | \'cancelled\' | \'failed\';\n readonly failure?: Failure;\n}',
|
||||
},
|
||||
{
|
||||
name: 'ContentBlockMap',
|
||||
declaration: 'export interface ContentBlockMap {\n \'text\': TextBlock;\n \'reasoning\': ReasoningBlock;\n \'image\': ImageBlock;\n \'file\': FileBlock;\n \'tool-call\': ToolCallBlock;\n \'tool-addition\': ToolAdditionBlock;\n \'tool-removal\': ToolRemovalBlock;\n}',
|
||||
|
||||
@@ -74,6 +74,7 @@ Every package below exports a Cordis plugin that a bundle patch can name in a Lo
|
||||
| `@deepseek-ai/dsh-client-ui-brand-official` | no | Official DeepSeek Harness brand artwork and click-triggered home background |
|
||||
| `@deepseek-ai/dsh-client-ui-chat` | no | Chat Conversation target, node definitions, renderers, and details surface |
|
||||
| `@deepseek-ai/dsh-client-ui-commands` | no | Client command surface: global directory cache, '/' source, three command UI kinds, popupSelect registry |
|
||||
| `@deepseek-ai/dsh-client-ui-connector-account` | no | Connector account surfaces: the Host registry CLI app plugins and MCP connectors register their accounts with, and the Plugins page section, title tag, activation prompt, and notices it serves over one Remote |
|
||||
| `@deepseek-ai/dsh-client-ui-context-menu` | no | Typed, plugin-extensible context menus with captured targets and shared Web presentation |
|
||||
| `@deepseek-ai/dsh-client-ui-conversation` | no | Target-neutral Conversation assembly, shell, composer, queue, and view navigation |
|
||||
| `@deepseek-ai/dsh-client-ui-deliverables` | no | Changed-files card with per-file comparison tabs, delivery cards, and clickable final-response file references for Web |
|
||||
|
||||
@@ -60,5 +60,7 @@ export const remoteDefaultResponses: RemoteTable = {
|
||||
'remoteAccess/follow': openStream([{ type: 'baseline', owner: true }]),
|
||||
// ui-sidebar-terminal header entry `agent-terminals`: the displayed Session's terminal roster, then open.
|
||||
'terminal/watch': openStream([[]]),
|
||||
// ui-connector-account `apply`: the registered connector accounts, none in a default composition, then open.
|
||||
'connectorAccounts/watch': openStream([{ accounts: [] }]),
|
||||
},
|
||||
}
|
||||
Generated
+67
@@ -1482,6 +1482,9 @@ importers:
|
||||
'@deepseek-ai/dsh-client-product-analytics':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/product-analytics
|
||||
'@deepseek-ai/dsh-client-ui-connector-account':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/ui-connector-account
|
||||
'@deepseek-ai/dsh-client-ui-plugin-manager':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/ui-plugin-manager
|
||||
@@ -2992,6 +2995,9 @@ importers:
|
||||
'@deepseek-ai/dsh-client-ui-commands':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/ui-commands
|
||||
'@deepseek-ai/dsh-client-ui-connector-account':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/ui-connector-account
|
||||
'@deepseek-ai/dsh-client-ui-context-menu':
|
||||
specifier: workspace:*
|
||||
version: link:../../client/ui-context-menu
|
||||
@@ -4184,6 +4190,67 @@ importers:
|
||||
specifier: ^18.2.0
|
||||
version: 18.3.1
|
||||
|
||||
packages/client/ui-connector-account:
|
||||
dependencies:
|
||||
'@deepseek-ai/dsh-typert-protocol':
|
||||
specifier: workspace:*
|
||||
version: link:../../typert/protocol
|
||||
zod:
|
||||
specifier: 4.6.6
|
||||
version: 4.6.6
|
||||
devDependencies:
|
||||
'@deepseek-ai/cordis':
|
||||
specifier: workspace:~
|
||||
version: link:../../../vendor/cordis
|
||||
'@deepseek-ai/dsh-api-gateway':
|
||||
specifier: workspace:*
|
||||
version: link:../../api/gateway
|
||||
'@deepseek-ai/dsh-api-remotes':
|
||||
specifier: workspace:*
|
||||
version: link:../../api/remotes
|
||||
'@deepseek-ai/dsh-brand':
|
||||
specifier: workspace:*
|
||||
version: link:../../util/brand
|
||||
'@deepseek-ai/dsh-client-locale':
|
||||
specifier: workspace:*
|
||||
version: link:../locale
|
||||
'@deepseek-ai/dsh-client-store':
|
||||
specifier: workspace:*
|
||||
version: link:../store
|
||||
'@deepseek-ai/dsh-client-test-runtime':
|
||||
specifier: workspace:*
|
||||
version: link:../../test-support/client-runtime
|
||||
'@deepseek-ai/dsh-client-ui-layout':
|
||||
specifier: workspace:*
|
||||
version: link:../ui-layout
|
||||
'@deepseek-ai/dsh-client-ui-plugin-manager':
|
||||
specifier: workspace:*
|
||||
version: link:../ui-plugin-manager
|
||||
'@deepseek-ai/dsh-client-ui-primitives':
|
||||
specifier: workspace:*
|
||||
version: link:../ui-primitives
|
||||
'@deepseek-ai/dsh-client-ui-renderer':
|
||||
specifier: workspace:*
|
||||
version: link:../ui-renderer
|
||||
'@deepseek-ai/dsh-client-ui-slots':
|
||||
specifier: workspace:*
|
||||
version: link:../ui-slots
|
||||
'@deepseek-ai/dsh-package-manifest':
|
||||
specifier: workspace:*
|
||||
version: link:../../util/package-manifest
|
||||
'@deepseek-ai/dsh-util-values':
|
||||
specifier: workspace:*
|
||||
version: link:../../util/values
|
||||
'@testing-library/react':
|
||||
specifier: ^16.3.3
|
||||
version: 16.3.3(@testing-library/[email protected])(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])
|
||||
react:
|
||||
specifier: ^18.2.0
|
||||
version: 18.3.1
|
||||
react-dom:
|
||||
specifier: ^18.2.0
|
||||
version: 18.3.1([email protected])
|
||||
|
||||
packages/client/ui-context-menu:
|
||||
devDependencies:
|
||||
'@deepseek-ai/cordis':
|
||||
|
||||
@@ -63,6 +63,7 @@ export const SERVICE_PAGE: Record<string, string> = {
|
||||
actionCards: 'boot.md',
|
||||
pluginRecommendations: 'boot.md',
|
||||
pluginMarket: 'boot.md',
|
||||
connectorAccounts: 'boot.md',
|
||||
pluginRegistryProbe: 'boot.md',
|
||||
configEditor: 'boot.md',
|
||||
profileContext: 'boot.md',
|
||||
@@ -1009,6 +1010,10 @@ export const FOUNDATION_TYPE_NAMES: ReadonlySet<string> = new Set([
|
||||
|
||||
/** Project types deliberately documented outside the subsystems catalog. */
|
||||
export const TYPE_LINK_EXEMPTIONS: Readonly<Record<string, string>> = {
|
||||
AnyConnectorAccountView: 'generic connector account view is owned by packages/client/ui-connector-account/README.md',
|
||||
ConnectorAccountRegistration: 'Plugins page account registration is owned by packages/client/ui-connector-account/README.md',
|
||||
ConnectorAccountsView: 'registered account stream item is owned by packages/client/ui-connector-account/README.md',
|
||||
ConnectorOperationId: 'account operation id is owned by packages/client/ui-connector-account/README.md',
|
||||
ActionCardDecision: 'packages/experimental/action-cards/README.md',
|
||||
ActionCardKind: 'packages/experimental/action-cards/README.md',
|
||||
ActionCardResult: 'packages/experimental/action-cards/README.md',
|
||||
|
||||
@@ -170,6 +170,13 @@ const SERVICE_ROLES: ServiceRole[] = [
|
||||
consumers: ['plugin-manager', 'ui-settings-plugin-inventory'],
|
||||
note: 'Shares profile package operations with the CLI and reports persisted and running state to Web and agent callers.',
|
||||
},
|
||||
{
|
||||
key: 'connectorAccounts',
|
||||
pkg: 'client-ui-connector-account',
|
||||
title: 'Connector accounts on the Plugins page',
|
||||
mode: 'service',
|
||||
note: 'Holds the accounts CLI app plugins and MCP connectors register and serves their Host-computed displays to the Plugins page through one Remote; authorization pages and notices stay in the browser that started the operation.',
|
||||
},
|
||||
{
|
||||
key: 'pluginMarket',
|
||||
pkg: 'plugin-market',
|
||||
|
||||
@@ -150,6 +150,7 @@ const SENTENCE_MODEL_EXPERIENCE: Readonly<Record<string, SentenceContract>> = {
|
||||
'packages/client/ui-brand-official': { kind: 'none', reason: 'Browser-side presentation occupants; registers nothing model-facing.' },
|
||||
'packages/client/ui-approval': { kind: 'none', reason: 'Browser-side approval presentation; registers nothing model-facing.' },
|
||||
'packages/client/ui-chat': { kind: 'none', reason: 'Browser-side Chat presentation; registers nothing model-facing.' },
|
||||
'packages/client/ui-connector-account': { kind: 'none', reason: 'Plugins page account surfaces over Host-registered accounts; each registrant documents the tools and skills its account enables.' },
|
||||
'packages/client/ui-message-feedback': { kind: 'none', reason: 'Browser-side controls over log-only message feedback; ratings and notes never enter model context or change model-input tokens.' },
|
||||
'packages/client/ui-tool': { kind: 'none', reason: 'Browser-side Tool presentation layer; renders logged calls without changing model context.' },
|
||||
'packages/client/ui-schedule': { kind: 'none', reason: 'Browser-side catalog, editing, and deletion of Host Schedule records; dsh-schedule owns storage and delivery, and dsh-tool-schedule contributes the model-facing tools in a preset that mounts it.' },
|
||||
|
||||
@@ -323,6 +323,8 @@
|
||||
"@deepseek-ai/dsh-client-ui-input-trigger": ["./packages/client/ui-input-trigger/src"],
|
||||
"@deepseek-ai/dsh-client-ui-reference": ["./packages/client/ui-reference/src"],
|
||||
"@deepseek-ai/dsh-client-ui-commands": ["./packages/client/ui-commands/src"],
|
||||
"@deepseek-ai/dsh-client-ui-connector-account": ["./packages/client/ui-connector-account/src"],
|
||||
"@deepseek-ai/dsh-client-ui-connector-account/types": ["./packages/client/ui-connector-account/src/types.ts"],
|
||||
"@deepseek-ai/dsh-client-ui-model-selection": ["./packages/client/ui-model-selection/src"],
|
||||
"@deepseek-ai/dsh-client-ui-goal": ["./packages/client/ui-goal/src"],
|
||||
"@deepseek-ai/dsh-client-ui-message-feedback": ["./packages/client/ui-message-feedback/src"],
|
||||
|
||||
@@ -142,6 +142,7 @@
|
||||
{ "path": "./packages/client/ui-directory-picker-native" },
|
||||
{ "path": "./packages/client/ui-goal" },
|
||||
{ "path": "./packages/client/ui-message-feedback" },
|
||||
{ "path": "./packages/client/ui-connector-account/tsconfig.client.json" },
|
||||
{ "path": "./packages/client/ui-model-selection" },
|
||||
{ "path": "./packages/client/ui-agent-preset" },
|
||||
{ "path": "./packages/client/ui-permission-presets" },
|
||||
|
||||
@@ -305,6 +305,7 @@
|
||||
{ "path": "./packages/client/ui-theme/tsconfig.host.json" },
|
||||
{ "path": "./packages/client/ui-chat/tsconfig.host.json" },
|
||||
{ "path": "./packages/client/ui-conversation/tsconfig.host.json" },
|
||||
{ "path": "./packages/client/ui-connector-account/tsconfig.host.json" },
|
||||
{ "path": "./packages/client/ui-settings/tsconfig.host.json" },
|
||||
{ "path": "./packages/client/ui-settings-general/tsconfig.host.json" },
|
||||
|
||||
|
||||
Reference in new issue
Block a user