跪拜 Guibai
← All articles
Frontend

DSH Plugin Data Flow: Host Supplies, Client Displays

By 再吃一根胡萝卜 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Keeping all credential and network access on the Host side means the browser never sees keys, and plugins share data through a single host channel instead of each client reaching out independently. That makes security review and debugging straightforward: the Host is the only trust boundary.

Summary

DSH plugin architecture puts a clean separation between data and display. The Host process handles credentials, file access, external network calls, and persistence; the Client is a thin view that only requests specific data and paints it. LocalStorage, often cited as a counterexample, is just a cache for data that already arrived in the browser, not a source. Anything that requires host capabilities—user info, API keys, file contents—cannot be obtained by the Client directly.

The article traces a login-to-display flow: the login plugin's Host verifies credentials and stores user info; the display plugin's Host retrieves it via Cordis services using `ctx.get`; then it pushes to its own Client either through Typert Remote (type-safe RPC with zod validation and generated contracts) or HTTP routes (like `dsh-provider-usage` polling `GET /stats` every 60 seconds). The Client never looks for data; it asks and renders.

Host-side data sources vary: adapters pull usage from external APIs (DeepSeek, Kimi, OpenRouter) with keys kept in the Node process, or read local credential services, or execute shell commands via `ctx.shell` and return structured output. Communication options include Typert Remote as the official strong-typed channel, HTTP for polling and status endpoints, and WebSocket for streaming; `dsh-work-chat` even layers SSE on top. The rule: if a task needs credentials, file system, external network, or host state, the data source belongs to the Host.

Takeaways
— In DSH, the Host is the sole source of data; the Client only makes calls and renders.
— localStorage is a cache after data arrives in the browser, not a source; it cannot substitute for Host-managed data.
— A login plugin's Host verifies credentials and stores user info; a display plugin's Host retrieves it via Cordis services (ctx.get) and passes it to its own Client.
— Typert Remote provides type-safe cross-end calls with zod validation and generated contracts (dsh-greeting).
— HTTP routes like GET /stats are common for polling and status endpoints, with keys kept only in the Host process.
— Host data can come from external API adapters, local credential services, or executing shell commands via ctx.shell.
— Communication options include Typert Remote, HTTP, WebSocket, and SSE; they can be combined per plugin needs.
— The decision rule: any data requiring credentials, file system, external network, or host state must come from the Host.
Conclusions

The distinction between where data is stored (browser cache) and where it originates is a common source of confusion in plugin systems; the article's explicit separation clarifies the trust model.

Cordis's service mechanism lets Host-side plugins share data without any Client involvement, so cross-plugin communication stays inside one process and avoids network overhead.

The preference for Typert Remote over HTTP for typed data shows type safety across the boundary is valued, yet HTTP remains for polling and status, indicating a pragmatic mix rather than a single mandate.

Concepts & terms
Typert Remote
A type-safe RPC mechanism in DSH: Host methods annotated with `@Remote` are callable from the Client via `ctx.remote.<namespace>.<method>()`, with zod validation and generated contracts via `pnpm typert:gen`.
Cordis
The plugin container/framework DSH is built on; plugins run in a shared Node process and can provide/consume services via `ctx` (e.g., `ctx.get`) for cross-plugin communication.
Host side / Client side
Host side is the Node.js process holding credentials, filesystem access, and network; Client side is the browser UI that renders data and makes calls back to Host via same-origin routes or RPC.
From the discussion
Featured comments
组合搭配函数

I really approve of this division. The Client should just focus on rendering. I once took over code that used localStorage as a data source and went wild with it; state was all over the place, and trying to change it was a nightmare.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗