dsh-auto-flow 0.1.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.
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/cordis.patch.yml +33 -0
- package/lib/client.js +5820 -0
- package/lib/index.d.ts +134 -0
- package/lib/index.js +592 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +314 -0
- package/lib/typert.remote-client.d.ts +32 -0
- package/lib/typert.remote-client.js +201 -0
- package/lib/types.d.ts +106 -0
- package/lib/types.js +1 -0
- package/package.json +133 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ExecKillResult, ExecReadResult, ExecRequest, ExecResult, Greeting } from "./types.js";
|
|
2
|
+
import { Context, Service } from "@deepseek-ai/cordis";
|
|
3
|
+
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
4
|
+
import z from "@deepseek-ai/schemastery";
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
/** dsh-auto-flow 的插件配置。 */
|
|
7
|
+
interface Config {
|
|
8
|
+
/** 问候前缀。 */
|
|
9
|
+
prefix?: string;
|
|
10
|
+
/** 单条 `exec` 命令允许的最大 UTF-8 字节长度。 */
|
|
11
|
+
maxCommandBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
declare module '@deepseek-ai/cordis' {
|
|
14
|
+
interface Context {
|
|
15
|
+
/** 示例服务(Host 提供,浏览器经 @Remote 调用)。 */
|
|
16
|
+
autoFlow: AutoFlowService;
|
|
17
|
+
}
|
|
18
|
+
interface Events {
|
|
19
|
+
/**
|
|
20
|
+
* 一次问候已提交(域事件,跨插件实时通知 seam)。发出方在 `send` 提交后
|
|
21
|
+
* emit;其它插件可 `ctx.on('autoFlow/recorded', ...)` 订阅。
|
|
22
|
+
* @mode emit
|
|
23
|
+
*/
|
|
24
|
+
'autoFlow/recorded'(payload: {
|
|
25
|
+
readonly greeting: Greeting;
|
|
26
|
+
}): void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 消息来源归属(MessageSourceMap)示例:若本插件要让「模型消息」归属到自己
|
|
31
|
+
* (如经 `exec.deferContext` 注入的用户消息),在此新增一个 kind 并在
|
|
32
|
+
* UserMessage.source 里使用。问候走会话事件而非模型消息,故此处仅声明词汇、
|
|
33
|
+
* 不强制接线(参考 @deepseek-ai/dsh-goal 的 goal 来源声明)。
|
|
34
|
+
*/
|
|
35
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
36
|
+
interface MessageSourceMap {}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 示例服务:类本身就是插件——static inject / Config 是 Cordis 类插件的约定,
|
|
40
|
+
* 构造器里的注册(工具/事件/设置/命令)随插件卸载自动回收。
|
|
41
|
+
*
|
|
42
|
+
* 平台服务消费方式(跨插件协作走 Cordis 服务、禁止互相 import):
|
|
43
|
+
* - 必需依赖用 `static inject`(tools);
|
|
44
|
+
* - 可选依赖用 `ctx.inject([...], cb)`(settings / commands / systemPrompt /
|
|
45
|
+
* autoFlowFormatter)——服务缺失时插件照常加载;
|
|
46
|
+
* - shell / sandboxPolicy 是可选服务:用 `ctx.get(...)` 读取,未组合时
|
|
47
|
+
* `exec` 报错、插件其余部分照常工作;
|
|
48
|
+
* - 持久层异步打开走 `[Service.init]`(storageDomain 可选:缺省退化为内存态)。
|
|
49
|
+
*/
|
|
50
|
+
declare class AutoFlowService extends TypertRemoteService {
|
|
51
|
+
/** 依赖的服务;缺失时 Loader 会等待其出现。 */
|
|
52
|
+
static inject: string[];
|
|
53
|
+
/** Config 的 Schema(Cordis 类插件约定:Loader 读类静态 `Config` 校验注入并补齐默认值;
|
|
54
|
+
* 模块级同名导出不会被 Loader 识别——生成插件请把 Schema 放在类上)。 */
|
|
55
|
+
static Config: z<Config>;
|
|
56
|
+
/** 校验后的配置(settings scope 可在运行时覆盖,故非 readonly)。 */
|
|
57
|
+
private resolved;
|
|
58
|
+
/** 问候的内存视图(domain storage 是持久层)。 */
|
|
59
|
+
private readonly greetings;
|
|
60
|
+
/** 已打开的持久化领域;无后端时保持 null(内存态兜底)。 */
|
|
61
|
+
private storage;
|
|
62
|
+
/** 第二包提供的格式化服务;未安装第二包时保持 null(可选依赖)。 */
|
|
63
|
+
private formatter;
|
|
64
|
+
/** 最近一次提交的问候(由 `autoFlow/recorded` 监听器维护,供 @Remote last)。 */
|
|
65
|
+
private lastRecorded;
|
|
66
|
+
/** 后台进程句柄(@Remote 轻执行自管;不依赖 ctx.jobs,见 exec 说明)。 */
|
|
67
|
+
private readonly background;
|
|
68
|
+
private nextBgId;
|
|
69
|
+
private nextId;
|
|
70
|
+
constructor(ctx: Context, config?: Config);
|
|
71
|
+
/**
|
|
72
|
+
* 异步初始化钩子(Cordis 类插件约定):构造完成后运行。持久层在这里打开——
|
|
73
|
+
* 与 @deepseek-ai/dsh-message-feedback 的 `[Service.init]` 同构;storageDomain
|
|
74
|
+
* 是可选服务,缺失时保持内存态兜底。
|
|
75
|
+
*/
|
|
76
|
+
protected [Service.init](): Promise<void>;
|
|
77
|
+
/** 模型工具:复用 @Remote send;presentCall + presentResult 双态展示。 */
|
|
78
|
+
private registerTool;
|
|
79
|
+
/** 设置:同一份 Config schema 注册为可编辑 namespace,入口配置作为 base 层。 */
|
|
80
|
+
private registerSettings;
|
|
81
|
+
/** 从持久化领域恢复内存视图与自增 id。 */
|
|
82
|
+
private hydrateFromStorage;
|
|
83
|
+
/** 斜杠命令:用户键入 /auto-flow 后直接进 handler(不经过模型)。 */
|
|
84
|
+
private registerCommand;
|
|
85
|
+
/** 系统提示词:贡献一条模型可见指引(name 唯一、order 升序拼接)。 */
|
|
86
|
+
private registerSystemPrompt;
|
|
87
|
+
/** 事件:监听自身域事件维护 lastRecorded 缓存(演示 ctx.on —— 监听器随 fiber 回收)。
|
|
88
|
+
* 其它插件也可 ctx.on('autoFlow/recorded', ...) 订阅,实现跨插件实时通知。 */
|
|
89
|
+
private registerEvents;
|
|
90
|
+
/** 卸载时回收所有未结束的后台进程(@Remote 轻执行自管句柄,必须随 fiber 清理)。 */
|
|
91
|
+
private registerBackgroundCleanup;
|
|
92
|
+
/** 跨插件服务消费:第二包(dsh-auto-flow-core)可选提供 autoFlowFormatter。
|
|
93
|
+
* 用 ctx.inject 而非 static inject——第二包未安装时插件照常加载(send 走无格式化兜底)。 */
|
|
94
|
+
private registerCore;
|
|
95
|
+
/**
|
|
96
|
+
* 追加一条问候并返回记录(写透 domain storage;若有第二包则先格式化;提交后发域事件)。
|
|
97
|
+
*
|
|
98
|
+
* 不追加自定义会话事件:harness 的 session 持久化读路径会拒绝 `KNOWN_SESSION_EVENT_TYPES`
|
|
99
|
+
* 之外的事件类型(除非信封标记 `ignorable`,而 `Session.append` 无此参数),把插件
|
|
100
|
+
* 自定义事件写进会话日志会导致该会话在重启后无法打开。
|
|
101
|
+
*/
|
|
102
|
+
send(text: string): Promise<Greeting>;
|
|
103
|
+
/** 返回全部问候记录(内存视图,已由 domain storage 水合)。 */
|
|
104
|
+
list(): Promise<Greeting[]>;
|
|
105
|
+
/** 返回最近一次提交的问候(由域事件监听器维护),首次提交前为 null。 */
|
|
106
|
+
last(): Promise<Greeting | null>;
|
|
107
|
+
/**
|
|
108
|
+
* 执行一条命令行(宿主内经 ctx.shell,与 bash 工具同一执行器,绝不经过模型)。
|
|
109
|
+
* 输出只回调用方、不进会话日志。@Remote 严格契约保证浏览器端完整类型与校验。
|
|
110
|
+
*
|
|
111
|
+
* 相比模型工具(@deepseek-ai/dsh-tool-bash)的 shell 面,@Remote 轻执行只能拿到
|
|
112
|
+
* 能映射过来的子集:timeoutMs / stdoutMaxBytes / sandboxPolicy / 后台任务 / 结果保真。
|
|
113
|
+
* 模型工具专属的 seam(shellEnv.collect 需要 ToolExecution、sandbox 升级需要 approval
|
|
114
|
+
* + callId、abort 需要 ToolExecution.signal)不适用于 @Remote,此处不做。
|
|
115
|
+
*
|
|
116
|
+
* 注意:@Remote 方法不能带 `agent: Agent` 参数——第三方仓库的 typert 生成器无法解析
|
|
117
|
+
* `agent` lookup(其 wire 类型 SessionId 是 branded 类型,官方 monorepo 内才可用)。
|
|
118
|
+
* 因此沙箱策略退化为「部署默认」(`sandboxPolicy.resolve()` 无 session)。
|
|
119
|
+
*
|
|
120
|
+
* 后台执行不走 ctx.jobs(那是给模型工具 job_output/job_kill 用的,需要 agent owner +
|
|
121
|
+
* dsh-tool-jobs 控制器,@Remote 里拿不到):直接用 `shell.start()` 拿 ShellProcess
|
|
122
|
+
* 句柄,自管在 this.background Map 里,execRead/execKill 直接操作句柄;卸载时统一 kill。
|
|
123
|
+
*
|
|
124
|
+
* shell / sandboxPolicy 是可选依赖:未组合时抛对应 RemoteError,插件其余照常。
|
|
125
|
+
*/
|
|
126
|
+
exec(request: ExecRequest): Promise<ExecResult>;
|
|
127
|
+
/** 读后台进程的下一次增量/终态输出(自管 ShellProcess 句柄,不依赖 ctx.jobs)。 */
|
|
128
|
+
execRead(jobId: string): Promise<ExecReadResult>;
|
|
129
|
+
/** 请求取消后台进程(自管 ShellProcess 句柄,不依赖 ctx.jobs)。 */
|
|
130
|
+
execKill(jobId: string): Promise<ExecKillResult>;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { AutoFlowService, AutoFlowService as default, Config };
|
|
134
|
+
//# sourceMappingURL=index.d.ts.map
|