DSH Plugin Data Flow: Host Supplies, Client Displays
DSH Plugin Data Flow: Host Manages Data, Client Only Renders
You asked me earlier: for DSH plugins to display data, does the data have to come from the Client? If not, where does it come from? Where does Host-side data come from? How do Host and Client actually communicate?
My answer at the time included some redundant information, such as using localStorage as an example, which conflated 'where data is stored after reaching the browser' with 'where data comes from.' This reorganized version keeps only the necessary facts and uses concrete plugins as examples. The core conclusion in one sentence: Data is managed by the Host. The Client does not 'find' data on its own; it makes a call to the Host, the Host returns results, and the Client handles rendering.
1. First, refute a common misconception
There is a claim: 'The Client can also hold data, such as localStorage, so the Client doesn't necessarily depend on the Host.' This claim is technically correct, but in the context of 'plugins displaying data,' it mixes two different questions. localStorage is where data lands after reaching the browser, not the source of the data. User information, credentials, file contents, external API returns—these things that need host capabilities to obtain, the Client can't touch from the start.
dsh-work-chat's architecture directly confirms this: the Host half is responsible for credentials, web-side interfaces, SSE streaming sends, and local persistence; the Client half only accesses the host via same-origin /workchat/* routes and does not directly go out to the network. The Client can't even reach external data; it can only ask the Host.
So a more accurate statement is: the Client can cache data the Host has given it, but it cannot replace the Host as the source of data.
2. Walk through the entire chain with a concrete example: user info from login to display
Suppose you have a login plugin that handles authentication and another display plugin that shows 'who is the current user' on the interface. How does this chain work?
Step 1: The login plugin's Host half gets credentials and verifies them.
The user submits username and password, and the Client sends the credentials to the login plugin's Host half. After the Host verifies them, it generates or reads user information. This information resides on the Host side—possibly in a local file, database, or in-memory session. dsh-model-usage's credential handling is a direct reference: credentials are only parsed and used on the Host, and the ZCode session uses a local encrypted credential file. The browser never sees what the key looks like.
Step 2: The display plugin's Host half gets the user info.
The Host halves of the login plugin and the display plugin run in the same Node runtime. DSH is built on the Cordis plugin system, and plugins collaborate through a service mechanism. The login plugin's Host half can register 'current user' as a service, and the display plugin's Host half gets it via ctx.get. There's no need for the Client side to 'find each other'; sharing happens inside the Host process.
Step 3: The display plugin's Host half sends the data down to its own Client half.
There are two mainstream ways here.
The first is Typert Remote. The Host half's class extends TypertRemoteService, and methods are marked with @Remote; the Client half calls via ctx.remote.<namespace>.<method>(). dsh-greeting is the official-style reference: send/list use strict mode, with bidirectional zod validation and full typing; contracts are generated by pnpm typert:gen. The data flow from Host to Client is type-safe.
The second is HTTP routing. The Host registers routes, and the Client sends requests to get data. dsh-provider-usage takes this path: the Client hits GET /stats every 60 seconds, and adapter code and keys live only in the host process; keys never enter the browser. dsh-model-usage likewise uses an authenticated /model-usage prefixed route.
Step 4: The Client half renders the interface.
The display plugin's Client half gets the user info (e.g., username, role, avatar URL) and draws it. It doesn't care whether the login plugin read the data from a file or queried a database; it only renders.
Throughout the chain, the Client never 'goes find data' on its own. It makes a call, and the Host returns the result.
3. Where does Host-side data come from?
There's no single rule. It depends on how the plugin's Host half is written. A few real plugins:
Pull from external APIs. dsh-provider-usage's adapter requests usage endpoints from various model providers (DeepSeek, Kimi, OpenRouter, etc.) on the Node side; keys stay in the host process, and HTML is sanitized before being sent down. dsh-model-usage likewise fetches data in parallel on the Host side, with TTL caching and single-flight control.
Read from a local credential service. dsh-doubao-work-connect's Host half registers a route that returns current login status and quota info, with statuses like signed-in, signed-out, cached; the Client gets it via GET /plugins/.../status. Credential reading and caching logic all live on the host side.
Execute host capabilities. dsh-greeting's exec method runs a command on the host via ctx.shell and returns structured results (exitCode, stdout, etc.); output goes only to the caller's UI, not to session logs. The Client can trigger it, but execution happens on the Host.
4. Communication methods are more than one, but there's a priority ordering
| Method | Use case | Example |
|---|---|---|
| Typert Remote | Structured data, type-safe cross-end calls | dsh-greeting's send/list |
| HTTP routes | Polling, status endpoints, file/HTML delivery | dsh-provider-usage's /stats |
| WebSocket | Real-time push, long connections | specific pairing or streaming scenarios |
Typert Remote is the official recommended strongly-typed RPC channel, but HTTP routes are also common in real plugins. Which one depends on the plugin design, not a hard rule. dsh-work-chat's Host half also uses SSE for streaming sends, showing that communication modalities can be combined as needed.
5. Summary
Back to your original questions:
- Where does data come from? The Host half decides. It can call APIs, read files, query databases, run commands, or get data from other plugins via Cordis services.
- How does the Client display? It makes a call to the Host, gets the result, and renders.
- How do Host and Client communicate? Typert Remote is the main channel, HTTP routes are a common alternative, and WebSocket is used in specific scenarios.
- What about localStorage? It's a cache landing spot after data arrives in the browser, not a source. You can drop it from this discussion.
If you're writing DSH plugins, one criterion is enough: does this task need credentials, file system, external network, or host process state? If yes, the data source is on the Host; the Client only says 'what I want' and 'draw it.'
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
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.