@morlay/dsh-command 0.0.0-stage → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -2
  3. package/dist/command-endpoint-D8Ze5gCZ.d.mts +72 -0
  4. package/dist/command-registry.service-CFFfpdoB.mjs +13 -0
  5. package/dist/command-registry.service-CVViz-lS.d.mts +18 -0
  6. package/dist/contract.d.mts +73 -0
  7. package/dist/contract.mjs +55 -0
  8. package/dist/decorate-g56z_1VW.mjs +8 -0
  9. package/dist/endpoint.d.mts +18 -0
  10. package/dist/endpoint.mjs +77 -0
  11. package/dist/index.d.mts +3 -0
  12. package/dist/index.mjs +3 -0
  13. package/dist/server.d.mts +30 -0
  14. package/dist/server.mjs +99 -0
  15. package/dist/ui.d.mts +105 -0
  16. package/dist/ui.mjs +196 -0
  17. package/package.json +54 -3
  18. package/src/command-registry.service.ts +21 -0
  19. package/src/contract/command-catalog.contract.ts +13 -0
  20. package/src/contract/command-contribution.ts +17 -0
  21. package/src/contract/command-entry.ts +5 -0
  22. package/src/contract/command-registry.contract.ts +22 -0
  23. package/src/contract/command-runner.contract.ts +15 -0
  24. package/src/contract/command-ui.contract.ts +36 -0
  25. package/src/contract/command.decorator.ts +78 -0
  26. package/src/contract/index.ts +12 -0
  27. package/src/endpoint/command-endpoint.ts +113 -0
  28. package/src/endpoint/command-line.ts +32 -0
  29. package/src/endpoint/index.ts +11 -0
  30. package/src/index.ts +5 -0
  31. package/src/server/command-endpoint.service.ts +64 -0
  32. package/src/server/command-entry-of.ts +13 -0
  33. package/src/server/command-execution.ts +45 -0
  34. package/src/server/command.provide.ts +10 -0
  35. package/src/server/index.ts +16 -0
  36. package/src/server/registry-catalog.ts +30 -0
  37. package/src/server/registry-runner.ts +31 -0
  38. package/src/ui/command-endpoint.client.ts +84 -0
  39. package/src/ui/command-palette.store.ts +92 -0
  40. package/src/ui/command-palette.view.tsx +41 -0
  41. package/src/ui/command-ui.service.ts +13 -0
  42. package/src/ui/command.provide.ts +19 -0
  43. package/src/ui/conversation-input-overlay.slot.ts +8 -0
  44. package/src/ui/index.ts +11 -0
  45. package/src/ui/remote-command-catalog.ts +17 -0
  46. package/src/ui/remote-command-runner.ts +18 -0
@@ -0,0 +1,64 @@
1
+ // `commands` 组的**宿主侧实现**:把注册表接到契约定义的方法上,并注册到 wire。
2
+ //
3
+ // 组名与方法名都来自契约(`@RemoteGroup` / `@RemoteMethod`),这里只写业务转发。
4
+ import { SessionId } from "@morlay/dsh-session/endpoint";
5
+ import { AgentDirectory } from "@morlay/dsh-agent";
6
+ import type { CommandSubmitAttachment } from "@deepseek-ai/dsh-commands/types";
7
+ import {
8
+ CommandEndpoint,
9
+ CommandId,
10
+ type CommandExecuteValue,
11
+ type CommandListValue,
12
+ splitCommandLine,
13
+ } from "@morlay/dsh-command/endpoint";
14
+ import { inject, type OnInit } from "@morlay/zephyr";
15
+ import { RemoteHandlers } from "@morlay/zephyr-app";
16
+ import { RemoteGroup, registerRemoteGroup } from "@morlay/zephyr-app/remote";
17
+ // 相对引用:契约面只放 `register`,按 agent 读/执行在实现面上(本包内部)。
18
+ import { CommandRegistryDefault } from "../command-registry.service.ts";
19
+ import { commandEntryOf } from "./command-entry-of.ts";
20
+ import { runCommand } from "./command-execution.ts";
21
+
22
+ /** `commands` 组的宿主实现。 */
23
+ @RemoteGroup()
24
+ export class CommandEndpointDefault extends CommandEndpoint implements OnInit {
25
+ private readonly handlers = inject(RemoteHandlers);
26
+
27
+ private readonly registry = inject(CommandRegistryDefault);
28
+
29
+ private readonly agents = inject(AgentDirectory);
30
+
31
+ onInit(): void {
32
+ registerRemoteGroup(this.handlers, this);
33
+ }
34
+
35
+ override async list(sessionId: SessionId): Promise<CommandListValue> {
36
+ const agent = this.agents.get(sessionId);
37
+ if (agent === undefined) return [];
38
+ return this.registry.list(agent).map(commandEntryOf);
39
+ }
40
+
41
+ override async execute(
42
+ sessionId: SessionId,
43
+ line: string,
44
+ // 附件按协议收下但本装配不消费(见债:命令附件未接线);类型与契约一致,不宽化。
45
+ _submittedAttachments: readonly CommandSubmitAttachment[],
46
+ ): Promise<CommandExecuteValue> {
47
+ const agent = this.agents.get(sessionId);
48
+ if (agent === undefined) throw new Error(`commands/execute: 会话 "${sessionId}" 没有 agent`);
49
+ // wire 上是整行(上游协议):拆名在宿主侧做,规则只有 `splitCommandLine` 一份。
50
+ const { name } = splitCommandLine(line);
51
+ const execution = await runCommand({
52
+ registry: this.registry,
53
+ agent,
54
+ line,
55
+ where: "commands/execute",
56
+ });
57
+ // `runCommand` 的 `undefined` 是「注册表里没这条命令」——按 wire 契约回一个结构化失败,
58
+ // 而不是让调用方收到 `undefined` 再去猜。
59
+ if (execution === undefined) {
60
+ return { commandId: CommandId(""), result: { kind: "error", text: `没有命令 "${name}"` } };
61
+ }
62
+ return execution;
63
+ }
64
+ }
@@ -0,0 +1,13 @@
1
+ // 上游 descriptor → 我们对外暴露的 `CommandEntry`:**两者现在是同一个类型**(`CommandEntry` 是
2
+ // `CommandDescriptor` 的别名),所以这里只留一层直通——调用点在,将来要投影字段时改这一处。
3
+ import type { CommandDescriptor } from "@morlay/dsh-command/server";
4
+ import type { CommandEntry } from "@morlay/dsh-command/contract";
5
+
6
+ /**
7
+ * 一条命令的对外形状。
8
+ * @param descriptor - 上游 `CommandRuntime.list(agent)` 的返回项。
9
+ * @returns 同一份(类型是别名,不再手抄字段)。
10
+ */
11
+ export function commandEntryOf(descriptor: CommandDescriptor): CommandEntry {
12
+ return descriptor;
13
+ }
@@ -0,0 +1,45 @@
1
+ // 按名字执行一条命令:`/name input` 的拼装、上游执行入口、以及「命令不存在」的判空,都只在这里写。
2
+ //
3
+ // 两个调用点(`command-endpoint.service.ts` 的 wire 方法、`registry-runner.ts` 的同进程端口)用同一份,
4
+ // 差别只有报错前缀(`where`)。
5
+ import type CommandRuntime from "@deepseek-ai/dsh-commands";
6
+ import { type CommandExecuteValue, splitCommandLine } from "@morlay/dsh-command/endpoint";
7
+
8
+ /** 一次命令执行要的东西。 */
9
+ export interface CommandRun {
10
+ /** 命令注册表的执行面(上游 `CommandRuntime["execute"]`)。 */
11
+ readonly registry: Pick<CommandRuntime, "execute">;
12
+
13
+ /** 目标 agent(会话已在调用方解析过)。 */
14
+ readonly agent: Parameters<CommandRuntime["execute"]>[0];
15
+
16
+ /** 整行(`/plan off`):wire 与注册表的执行入口都是这个形状,拆名只在报错时用。 */
17
+ readonly line: string;
18
+
19
+ /** 报错前缀:wire 侧 `commands/execute`、同进程侧 `commands`。 */
20
+ readonly where: string;
21
+ }
22
+
23
+ /**
24
+ * 执行一条命令。
25
+ * @param options - 注册表、agent、名字与输入、报错前缀。
26
+ * @returns 注册表的结算值(`commandId` + `result`);处理器自己结算的失败在 `result.kind` 上。
27
+ * @throws 名字解析不到时抛错(上游对语法错或未知名字返回 `undefined`)。
28
+ */
29
+ export async function runCommand(options: CommandRun): Promise<CommandExecuteValue> {
30
+ const line = options.line;
31
+ // 上游 `execute` 要一个 signal(它的 typert 客户端可以按调用传),但我们的入口链上**没有取消源**:
32
+ // `CommandRunner.run` 不带 signal,wire 上一元的 `@RemoteMethod` 走 `RemoteHandlers.invoke(args)`,
33
+ // 也只有 stream 那一路才拿得到 signal。这里给一个不会 abort 的 controller——要真能取消,
34
+ // 得先让入口(契约 + wire 请求)把 signal 带进来。
35
+ const execution = await options.registry.execute(
36
+ options.agent,
37
+ line,
38
+ [],
39
+ new AbortController().signal,
40
+ );
41
+ if (execution === undefined) {
42
+ throw new Error(`${options.where}: 没有命令 "${splitCommandLine(line).name}"`);
43
+ }
44
+ return execution;
45
+ }
@@ -0,0 +1,10 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { remoteDescriptor } from "@morlay/zephyr-app";
3
+ import { CommandEndpointDefault } from "./command-endpoint.service.ts";
4
+ import { CommandRegistryDefault } from "../command-registry.service.ts";
5
+
6
+ export const provideCommand = provide([
7
+ CommandRegistryDefault,
8
+ CommandEndpointDefault,
9
+ remoteDescriptor(() => import("@deepseek-ai/dsh-commands/remote")),
10
+ ]);
@@ -0,0 +1,16 @@
1
+ // command 的**宿主半**(`@morlay/dsh-command/server`):
2
+ // `CommandEndpointDefault` 实现 `endpoint/` 的组契约并注册到 wire;
3
+ // `RegistryCatalog` / `RegistryRunner` 是同进程直连注册表的端口实现(单机模式、集成测试)。
4
+ export { CommandEndpointDefault } from "./command-endpoint.service.ts";
5
+ export { RegistryCatalog } from "./registry-catalog.ts";
6
+ export { RegistryRunner } from "./registry-runner.ts";
7
+ export { provideCommand } from "./command.provide.ts";
8
+
9
+ // 上游门面:**只出被消费的**三个类型(`command-entry-of.ts`、`contract/command-contribution.ts` 与它们的
10
+ // spec 从这里取类型)。上游其余符号(`CommandId` / `CommandDefinitionId` / `parseCommand` / `name` …)
11
+ // 没有消费方,不再整包透传——要用的人直接引 `@deepseek-ai/dsh-commands`。
12
+ export type {
13
+ CommandDescriptor,
14
+ CommandInvocation,
15
+ CommandResult,
16
+ } from "@deepseek-ai/dsh-commands";
@@ -0,0 +1,30 @@
1
+ // 端口的**同进程实现**:直接接命令注册表的实现类(上游 `CommandRuntime` 的适配实例),中间不经过 wire。
2
+ //
3
+ // 这是包 API 的一部分(不是测试辅助):单机模式与集成测试都用它——两端在同一个进程里时,
4
+ // `CommandCatalog` 就是注册表的一层薄封装,没有理由再绕一次 wire。
5
+ // 生产里浏览器那一侧用 `RemoteCommandCatalog` / `RemoteCommandRunner`(走 `remote.commands.*`),
6
+ // 契约与形状完全一致,换的只是「怎么到达注册表」。
7
+ //
8
+ // 注入的是**实现类**而不是契约:契约面只放 `register`(写),按 agent 取目录是宿主内部的事。
9
+ import { inject, Injectable } from "@morlay/zephyr";
10
+ import type { SessionId } from "@morlay/dsh-session/endpoint";
11
+ import { AgentDirectory } from "@morlay/dsh-agent";
12
+ import { CommandCatalog } from "@morlay/dsh-command/contract";
13
+ import type { CommandEntry } from "@morlay/dsh-command/contract";
14
+ // 相对引用:本包根出口会带进 `./server` 的装配模块,走包名会把依赖绕成环。
15
+ import { CommandRegistryDefault } from "../command-registry.service.ts";
16
+ import { commandEntryOf } from "./command-entry-of.ts";
17
+
18
+ /** 直连注册表的目录实现:按会话解析 agent 后取它的命令。 */
19
+ @Injectable()
20
+ export class RegistryCatalog extends CommandCatalog {
21
+ private readonly registry = inject(CommandRegistryDefault);
22
+
23
+ private readonly agents = inject(AgentDirectory);
24
+
25
+ async list(sessionId: SessionId): Promise<readonly CommandEntry[]> {
26
+ const agent = this.agents.get(sessionId);
27
+ if (agent === undefined) return [];
28
+ return this.registry.list(agent).map(commandEntryOf);
29
+ }
30
+ }
@@ -0,0 +1,31 @@
1
+ // 端口的**同进程实现**(执行器):直接接命令注册表的实现类,中间不经过 wire。
2
+ //
3
+ // 单机模式与集成测试用;生产浏览器那一侧用 `RemoteCommandRunner`(走 `remote.commands.execute`)。
4
+ // 注入实现类而不是契约:执行入口(含 `command/run` 生命周期事件)在注册表的实现面,不在写契约上。
5
+ import { inject, Injectable } from "@morlay/zephyr";
6
+ import type { SessionId } from "@morlay/dsh-session/endpoint";
7
+ import { AgentDirectory } from "@morlay/dsh-agent";
8
+ import { commandLineOf, type CommandExecuteValue } from "@morlay/dsh-command/endpoint";
9
+ import { CommandRunner } from "@morlay/dsh-command/contract";
10
+ // 相对引用:本包根出口会带进 `./server` 的装配模块,走包名会把依赖绕成环。
11
+ import { CommandRegistryDefault } from "../command-registry.service.ts";
12
+ import { runCommand } from "./command-execution.ts";
13
+
14
+ /** 直连注册表的执行器实现:交给注册表自己的执行入口(它负责解析与生命周期事件)。 */
15
+ @Injectable()
16
+ export class RegistryRunner extends CommandRunner {
17
+ private readonly registry = inject(CommandRegistryDefault);
18
+
19
+ private readonly agents = inject(AgentDirectory);
20
+
21
+ async run(sessionId: SessionId, name: string, input?: string): Promise<CommandExecuteValue> {
22
+ const agent = this.agents.get(sessionId);
23
+ if (agent === undefined) throw new Error(`commands: 会话 "${sessionId}" 没有 agent`);
24
+ return runCommand({
25
+ registry: this.registry,
26
+ agent,
27
+ line: commandLineOf(name, input),
28
+ where: "commands",
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,84 @@
1
+ // `CommandEndpoint` 的**客户端形态**:只消费、不实现。
2
+ //
3
+ // 两个方法都**显式转发**(不用 `@RemoteClient()` 的生成转发):`execute` 的 wire 是三个位置参数
4
+ // (会话 / 整行 / 附件),而生成转发的 unary 兜底是 `invoke('<组>/<方法>', { request: 实参[0] })`——
5
+ // 只包第一个实参,后两段会丢。真机的 `commands/execute: 缺少会话或命令名` 就是这么来的。
6
+ //
7
+ // 显式转发同时保住「装配期就能用」:它不依赖 `$mount` 已完成(`CommandRunner` 在 `$mount` 之前就可能被调)。
8
+ //
9
+ // 挂载仍归它自己:上游消费方(`ui-commands` / `ui-plan` / 会话面)读的是 `ctx.remote.commands`——那是
10
+ // **按 namespace 的**面,只有 `$mount` 过 descriptor 才有;我们的组不在上游 `TYPERT_REMOTE` 里,所以这份
11
+ // descriptor 由契约自己编译(`remoteDescriptorsOf`,与宿主侧 `registerRemoteGroup` 成对)。
12
+ //
13
+ // `remote` 字段在这里显式声明:契约类**不**继承 `RemoteClientBase`(那个基类带 `inject(Remote)`,
14
+ // 而契约被宿主侧共用,宿主没有 `Remote` 这个服务)。
15
+ import type { CommandSubmitAttachment } from "@deepseek-ai/dsh-commands/types";
16
+ import type { SessionId } from "@morlay/dsh-session/endpoint";
17
+ import {
18
+ CommandEndpoint,
19
+ type CommandExecuteValue,
20
+ type CommandListValue,
21
+ } from "@morlay/dsh-command/endpoint";
22
+ import { RemoteClient, groupNameOf, remoteDescriptorsOf } from "@morlay/zephyr-app/remote";
23
+ import { inject, type Context, type OnInit } from "@morlay/zephyr";
24
+ import { Remote, RemoteTransport } from "@morlay/zephyr-app/client";
25
+
26
+ /** `commands` 组的客户端契约实例。 */
27
+ @RemoteClient()
28
+ export class CommandEndpointClient extends CommandEndpoint implements OnInit {
29
+ /** 转发目标:`remote.invoke`(wire 的命名参数由契约的 `parameters` 声明决定)。 */
30
+ protected readonly remote = inject(Remote);
31
+
32
+ /** 传输:转发走它(我们的组不注册进上游 `remote`)。 */
33
+ protected readonly transport = inject(RemoteTransport);
34
+
35
+ /**
36
+ * 挂上这一组的 descriptor:客户端形态**自己挂自己那一组**,不另开 binding 行。
37
+ *
38
+ * 面本身是给**上游消费方**用的(`ctx.remote.commands.execute(sessionId, line, attachments)`);
39
+ * 本仓自己的调用走下面的显式转发。
40
+ * @param ctx - 本行 ctx:disposer 挂在它上面,卸载随行 fiber。
41
+ */
42
+ async onInit(ctx: Context): Promise<void> {
43
+ const dispose = await this.remote.$mount(remoteDescriptorsOf(CommandEndpoint));
44
+ ctx.effect(() => dispose);
45
+ }
46
+
47
+ /**
48
+ * 列目录:wire 是 `{ sessionId }`(一个位置参数)。
49
+ * @param sessionId - 目标会话。
50
+ * @returns 目录(未知会话给空数组)。
51
+ */
52
+ override async list(sessionId: SessionId): Promise<CommandListValue> {
53
+ return (await this.invoke("list", { sessionId })) as CommandListValue;
54
+ }
55
+
56
+ /**
57
+ * 执行一条命令:wire 是 `{ sessionId, line, submittedAttachments }`(三个扁平字段)。
58
+ * @param sessionId - 目标会话。
59
+ * @param line - 整行(`/plan off`)。
60
+ * @param submittedAttachments - 随命令提交的附件(本装配不消费,仍按协议传)。
61
+ * @returns 注册表给出的执行结果。
62
+ */
63
+ override async execute(
64
+ sessionId: SessionId,
65
+ line: string,
66
+ submittedAttachments: readonly CommandSubmitAttachment[],
67
+ ): Promise<CommandExecuteValue> {
68
+ return (await this.invoke("execute", {
69
+ sessionId,
70
+ line,
71
+ submittedAttachments,
72
+ })) as CommandExecuteValue;
73
+ }
74
+
75
+ /**
76
+ * 一次 unary 调用:端点名由组名(契约上的 `@RemoteGroup`)与方法名拼出,不另写字符串表。
77
+ * @param method - 方法名。
78
+ * @param args - wire 的命名参数。
79
+ * @returns 宿主给的原样值。
80
+ */
81
+ private async invoke(method: string, args: Readonly<Record<string, unknown>>): Promise<unknown> {
82
+ return await this.transport.invoke(`${groupNameOf(this.constructor)}/${method}`, { args });
83
+ }
84
+ }
@@ -0,0 +1,92 @@
1
+ // 命令弹层的**状态 store**(浏览器半):每会话的 open / query / selected / entries,外加动作。
2
+ //
3
+ // 它只依赖 `endpoint/commands.ts` 里的两个端口(`CommandCatalog` / `CommandRunner`)——实现由组合层
4
+ // 绑定(可能是走 remote 的实现,也可能是测试里的假实现),所以这个模块能单独跑起来。
5
+ import { inject, Injectable } from "@morlay/zephyr";
6
+ import { SessionId } from "@morlay/dsh-session/endpoint";
7
+ import { CommandCatalog, CommandRunner } from "@morlay/dsh-command/contract";
8
+ import type { CommandEntry } from "@morlay/dsh-command/contract";
9
+
10
+ /** 一个会话的命令弹层状态。 */
11
+ export interface CommandPaletteState {
12
+ readonly open: boolean;
13
+ readonly query: string;
14
+ readonly selected: number;
15
+ readonly entries: readonly CommandEntry[];
16
+ }
17
+
18
+ const CLOSED: CommandPaletteState = { open: false, query: "", selected: 0, entries: [] };
19
+
20
+ /** 命令弹层的状态机(视图通过 `useSyncExternalStore` 订阅)。 */
21
+ @Injectable()
22
+ export class CommandPaletteStore {
23
+ private readonly catalog = inject(CommandCatalog);
24
+
25
+ private readonly runner = inject(CommandRunner);
26
+
27
+ private readonly listeners = new Set<() => void>();
28
+
29
+ private readonly states = new Map<string, CommandPaletteState>();
30
+
31
+ /** 一个会话的当前状态(没打开过就是关闭态)。 */
32
+ stateOf(sessionId: string): CommandPaletteState {
33
+ return this.states.get(sessionId) ?? CLOSED;
34
+ }
35
+
36
+ /** 订阅状态变化。 */
37
+ subscribe(listener: () => void): () => void {
38
+ this.listeners.add(listener);
39
+ return () => {
40
+ this.listeners.delete(listener);
41
+ };
42
+ }
43
+
44
+ /** 打开弹层(拉一次目录)。 */
45
+ async open(sessionId: string): Promise<void> {
46
+ const entries = await this.catalog.list(SessionId(sessionId));
47
+ this.patch(sessionId, { open: true, query: "", selected: 0, entries });
48
+ }
49
+
50
+ /** 关闭弹层。 */
51
+ close(sessionId: string): void {
52
+ this.patch(sessionId, CLOSED);
53
+ }
54
+
55
+ /** 改过滤词(选中项回到第一个)。 */
56
+ setQuery(sessionId: string, query: string): void {
57
+ this.patch(sessionId, { query, selected: 0 });
58
+ }
59
+
60
+ /** 在过滤后的列表里移动选中项(循环)。 */
61
+ move(sessionId: string, delta: number): void {
62
+ const state = this.stateOf(sessionId);
63
+ const visible = this.visibleOf(state);
64
+ if (visible.length === 0) return;
65
+ this.patch(sessionId, { selected: (state.selected + delta + visible.length) % visible.length });
66
+ }
67
+
68
+ /** 过滤后的可见项:空查询给全部,否则按名字与说明做包含匹配。 */
69
+ visibleOf(state: CommandPaletteState): readonly CommandEntry[] {
70
+ const query = state.query.trim().toLowerCase();
71
+ if (query === "") return state.entries;
72
+ return state.entries.filter(
73
+ (entry) =>
74
+ entry.name.toLowerCase().includes(query) || entry.description.toLowerCase().includes(query),
75
+ );
76
+ }
77
+
78
+ /** 执行选中项(执行完关闭;没有选中项时只关闭)。 */
79
+ async run(sessionId: string): Promise<void> {
80
+ const state = this.stateOf(sessionId);
81
+ const target = this.visibleOf(state)[state.selected];
82
+ this.close(sessionId);
83
+ if (target === undefined) return;
84
+ await this.runner.run(SessionId(sessionId), target.name);
85
+ }
86
+
87
+ private patch(sessionId: string, next: Partial<CommandPaletteState>): void {
88
+ this.states.set(sessionId, { ...this.stateOf(sessionId), ...next });
89
+ // 副本:监听器可能在通知里退订(`Array.from` 就是那份拷贝)。
90
+ for (const listener of Array.from(this.listeners)) listener();
91
+ }
92
+ }
@@ -0,0 +1,41 @@
1
+ // 命令弹层的视图:读装配进来的 `CommandPaletteStore`,渲染对应 UI。
2
+ //
3
+ // 注册由 `SlotViewBase` 完成(位置来自 `@SlotProvider` 的 `extends`),视图只写 `render()`。
4
+ //
5
+ // 为什么不直接复用上游的 `MenuView`:它的 props 绑定了上游 `InputTriggerService` 的 controller
6
+ // store(`menu: SnapshotStore<MenuState>` + pick/hover 回调),那个 controller 属于输入区触发器那一层,
7
+ // 等输入区自己的模块落地后再接。这里的 DOM 只表达「命令弹层是什么」,标记 `data-command-palette`。
8
+ import { useSyncExternalStore, type ReactNode } from "react";
9
+ import { inject } from "@morlay/zephyr";
10
+ import { SlotView } from "@morlay/zephyr-app/client";
11
+ import { CommandPaletteStore } from "./command-palette.store.ts";
12
+ import { ConversationInputOverlaySlot } from "./conversation-input-overlay.slot.ts";
13
+
14
+ /** 命令弹层:把 store 的会话状态渲染成列表,选中项带标记。 */
15
+ @SlotView()
16
+ export class CommandPaletteView extends ConversationInputOverlaySlot {
17
+ private readonly palette = inject(CommandPaletteStore);
18
+
19
+ render(): ReactNode {
20
+ const sessionId = (this.viewProps as { sessionId?: string } | undefined)?.sessionId;
21
+ if (sessionId === undefined) return null;
22
+ const state = useSyncExternalStore(
23
+ (listener) => this.palette.subscribe(listener),
24
+ () => this.palette.stateOf(sessionId),
25
+ );
26
+ if (!state.open) return null;
27
+ const visible = this.palette.visibleOf(state);
28
+ return (
29
+ <div data-command-palette="">
30
+ <ul>
31
+ {visible.map((entry, index) => (
32
+ <li key={entry.name} data-selected={index === state.selected ? "" : undefined}>
33
+ {`/${entry.name}`}
34
+ {entry.description === "" ? null : <span>{entry.description}</span>}
35
+ </li>
36
+ ))}
37
+ </ul>
38
+ </div>
39
+ );
40
+ }
41
+ }
@@ -0,0 +1,13 @@
1
+ // 上游 ui-commands client 半的**适配基类**(上游归 command 域)。
2
+ //
3
+ // 上游那一行做三件事(同一个 apply):注册命令源、把宿主目录与客户端贡献合并成候选、
4
+ // 把 command-popup 壳注册进会话输入区的 overlay。三者同源,装整行即可。
5
+ //
6
+ // 宿主侧(会话界面)的输入区行继承本类、补自己的注入(它要 inputTriggers / sessions 这些**会话域**
7
+ // 的端口)。上游的 import 只留在本包:别的域不再直连 @deepseek-ai/dsh-client-ui-commands。
8
+ import * as UiCommandsPlugin from "@deepseek-ai/dsh-client-ui-commands/client";
9
+ import { fromCordis } from "@morlay/zephyr/compat";
10
+ import { CommandUi } from "../contract/index.ts";
11
+
12
+ /** 命令 UI 行的基类:mount 由基类给出,子类只补注入与 onInit。 */
13
+ export class CommandUiRow extends fromCordis(CommandUi, UiCommandsPlugin) {}
@@ -0,0 +1,19 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { CommandEndpointClient } from "./command-endpoint.client.ts";
3
+ import { CommandPaletteStore } from "./command-palette.store.ts";
4
+ import { RemoteCommandCatalog } from "./remote-command-catalog.ts";
5
+ import { RemoteCommandRunner } from "./remote-command-runner.ts";
6
+
7
+ /**
8
+ * command 的浏览器半:RPC 客户端 + 目录/执行器的远端实现 + 命令 UI 行 + 弹层的 store 与视图。
9
+ *
10
+ * 顺序 = 依赖:端点客户端先(其余都经它走 wire);`commands` 的 namespace 面由它的 `onInit` 挂上
11
+ * (没有单独的绑定行),因此它要排在消费方之前——上游 `ui-commands` 的 `static inject` 里有
12
+ * `remote.commands`(那一行在会话域的输入区组里装,因为它的头一项依赖是 `inputTriggers`)。
13
+ */
14
+ export const provideCommandUi = provide([
15
+ CommandEndpointClient,
16
+ RemoteCommandCatalog,
17
+ RemoteCommandRunner,
18
+ CommandPaletteStore,
19
+ ]);
@@ -0,0 +1,8 @@
1
+ // 输入区浮层的位置(`conversation.input.overlay`)。
2
+ //
3
+ // 只声明类型与名字;位置本身由 `ui-conversation` 那一行注册,我们的视图通过 `extends` 它来定位。
4
+ import { SlotProvider, SlotViewBase } from "@morlay/zephyr-app/client";
5
+
6
+ /** 输入区浮层的位置(名字与上游 slot 名一致)。 */
7
+ @SlotProvider({ name: "conversation.input.overlay", multi: true, key: "command-popup" })
8
+ export abstract class ConversationInputOverlaySlot extends SlotViewBase {}
@@ -0,0 +1,11 @@
1
+ // command 的浏览器半:状态 store、位置与视图、契约的客户端形态与两个端口实现。
2
+ export { CommandUi } from "../contract/index.ts";
3
+ export { CommandUiRow } from "./command-ui.service.ts";
4
+ export { CommandPaletteStore } from "./command-palette.store.ts";
5
+ export type { CommandPaletteState } from "./command-palette.store.ts";
6
+ export { ConversationInputOverlaySlot } from "./conversation-input-overlay.slot.ts";
7
+ export { CommandPaletteView } from "./command-palette.view.tsx";
8
+ export { CommandEndpointClient } from "./command-endpoint.client.ts";
9
+ export { RemoteCommandCatalog } from "./remote-command-catalog.ts";
10
+ export { RemoteCommandRunner } from "./remote-command-runner.ts";
11
+ export { provideCommandUi } from "./command.provide.ts";
@@ -0,0 +1,17 @@
1
+ // `CommandCatalog` 的**浏览器实现**:按契约走 `remote.commands.list`。
2
+ //
3
+ // 它只依赖 `CommandEndpointClient`(契约的客户端形态),不碰宿主实现——换传输也不影响这一层。
4
+ import type { SessionId } from "@morlay/dsh-session/endpoint";
5
+ import { CommandCatalog, type CommandEntry } from "@morlay/dsh-command/contract";
6
+ import { inject, Injectable } from "@morlay/zephyr";
7
+ import { CommandEndpointClient } from "./command-endpoint.client.ts";
8
+
9
+ /** 走 remote 的命令目录。 */
10
+ @Injectable()
11
+ export class RemoteCommandCatalog extends CommandCatalog {
12
+ private readonly endpoint = inject(CommandEndpointClient);
13
+
14
+ async list(sessionId: SessionId): Promise<readonly CommandEntry[]> {
15
+ return this.endpoint.list(sessionId);
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ // `CommandRunner` 的**浏览器实现**:按契约走 `remote.commands.execute`。
2
+ import type { SessionId } from "@morlay/dsh-session/endpoint";
3
+ import { commandLineOf, type CommandExecuteValue } from "@morlay/dsh-command/endpoint";
4
+ import { CommandRunner } from "@morlay/dsh-command/contract";
5
+ import { inject, Injectable } from "@morlay/zephyr";
6
+ import { CommandEndpointClient } from "./command-endpoint.client.ts";
7
+
8
+ /** 走 remote 的命令执行器。 */
9
+ @Injectable()
10
+ export class RemoteCommandRunner extends CommandRunner {
11
+ private readonly endpoint = inject(CommandEndpointClient);
12
+
13
+ async run(sessionId: SessionId, name: string, input?: string): Promise<CommandExecuteValue> {
14
+ // wire 上是**整行**(与上游客户端一致:`execute(sessionId, line, attachments)`);`name` / `input`
15
+ // 到这一层才拼回去,规则住在 `commandLineOf`。附件本装配不消费,给空数组。
16
+ return this.endpoint.execute(sessionId, commandLineOf(name, input), []);
17
+ }
18
+ }