@yitom/acp-client 0.1.12 → 0.1.13

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.
@@ -9,6 +9,8 @@ export declare function provisionCustomProviderCodexHome(provider: StoredAcpProv
9
9
  export interface CodexRuntimeAdapter extends GenericRuntimeAdapter {
10
10
  probeQuota?: (options?: {
11
11
  sessionId?: string;
12
+ dataDir?: string;
13
+ env?: NodeJS.ProcessEnv;
12
14
  }) => Promise<AcpAgentQuota | null>;
13
15
  id: 'codex-acp';
14
16
  probeAuth: () => CodexAuthPreflight;
@@ -0,0 +1,50 @@
1
+ import type { AcpDeepseekProviderSavePayload, AcpDeepseekProviderStatus, AppError } from "../../contracts";
2
+ import { type Result } from "../../contracts";
3
+ /**
4
+ * DeepSeek(dsh)端点与凭证的本地落库。
5
+ *
6
+ * 存在的意义:用户本机没有登录 harness、也没有 `DEEPSEEK_API_KEY` 时,
7
+ * 宿主可以弹一个「URL + Token」表单,填完即可连接——不必要求用户先去装/登
8
+ * harness 桌面端。落库只保存我们自己的 JSON,不碰 `$DSH_HOME/.credentials.yaml`;
9
+ * spawn 时再转成 harness 官方认的环境变量(`DEEPSEEK_BASE_URL` /
10
+ * `DEEPSEEK_API_KEY`,见 dsh-llm-deepseek 的 BASE_URL_ENV 与 credentials 优先级)。
11
+ *
12
+ * 优先级(高 → 低):
13
+ * 1. 调用方显式传入的 `env`(AcpClient options.env)——CI/多租户场景用;
14
+ * 2. 本表单落库(本文件);
15
+ * 3. 进程环境里的同名变量;
16
+ * 4. harness 自身登录(`$DSH_HOME/.credentials.yaml`)。
17
+ */
18
+ /** 官方端点:harness 走 Anthropic 兼容的 Messages API,路径必须带 `/anthropic`。 */
19
+ export declare const DEEPSEEK_OFFICIAL_BASE_URL = "https://api.deepseek.com/anthropic";
20
+ /** harness 家目录:`DSH_HOME` 优先,缺省 `~/.dsh`(与 dsh 自身口径一致)。 */
21
+ export declare function resolveDshHome(env?: NodeJS.ProcessEnv): string;
22
+ export declare function resolveDshCredentialsFile(env?: NodeJS.ProcessEnv): string;
23
+ /**
24
+ * 从 harness 凭证库的 `refs:` 块读某个名字的明文值(如 `DEEPSEEK_API_KEY`)。
25
+ * 只认顶层 `refs:` 下的缩进行,读到下一个顶层键即停;读不到返回 null。
26
+ * 用于配额探针:用户只登录了 harness、没导出环境变量时也能查余额。
27
+ */
28
+ export declare function readHarnessCredential(name: string, env?: NodeJS.ProcessEnv): string | null;
29
+ /** 用户手填官方域名(无路径)时也接受:补成 Anthropic 兼容端点。 */
30
+ export declare function normalizeDeepseekBaseUrl(raw?: string): string;
31
+ export interface StoredDeepseekProvider {
32
+ baseUrl: string;
33
+ apiKey: string;
34
+ }
35
+ /** 读取完整配置(含 Key),仅内部使用;文件缺失/损坏返回 null。 */
36
+ export declare function readStoredDeepseekProvider(dir?: string): StoredDeepseekProvider | null;
37
+ /** 供 UI 的脱敏状态(Key 不回传)。 */
38
+ export declare function getDeepseekProviderStatus(dir?: string): AcpDeepseekProviderStatus;
39
+ /**
40
+ * 保存表单:`baseUrl` 留空回落官方端点;`apiKey` 留空保留原 Key
41
+ * (只切端点、不重填 Token 的常见操作)。
42
+ */
43
+ export declare function saveDeepseekProvider(payload: AcpDeepseekProviderSavePayload, dir?: string): Result<AcpDeepseekProviderStatus, AppError>;
44
+ export declare function clearDeepseekProvider(dir?: string): Result<void, AppError>;
45
+ /**
46
+ * 落库配置 → spawn 环境变量。
47
+ * `currentEnv` 已有的同名键不覆盖(显式调用方环境优先)。
48
+ * 返回空对象表示没有可注入的配置。
49
+ */
50
+ export declare function buildDeepseekProviderEnv(stored: StoredDeepseekProvider | null, currentEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * DeepSeek(dsh)ACP 的可迁移引导层。
3
+ *
4
+ * 目标:换一台机器只靠「装依赖 + 登录」就能跑通,不依赖任何本机手工改动。
5
+ *
6
+ * 两个会阻断迁移的点,都在这里解决:
7
+ * 1. `dsh-acp-app` 自带补丁把会话默认模型写死成 `deepseek-v4-flash`,而该 id
8
+ * 不在 provider catalog 里(catalog 只有 `deepseek-flash` = V4.1-Flash 与
9
+ * `deepseek-v4-pro`)。以前靠改 `$DSH_HOME/profiles/acp/cordis.patch.yml`,
10
+ * 换机即失效;这里改为在 spawn 时用启动器自带的 `--patch <file>` 覆盖层,
11
+ * 补丁文件由 SDK 写到系统临时目录,随代码走、不碰用户 profile。
12
+ * 2. bunx 把包装进临时目录,harness 的 `$DSH_HOME/profiles/node_modules` 会软链
13
+ * 过去,临时目录被清理后 profile 断链。这里约定一个按平台取的用户级稳定
14
+ * 安装目录(`scripts/setup-dsh-acp.mjs` 负责装进去),存在即优先使用,
15
+ * 于是同一份代码在 Windows / macOS / Linux 上都能自解析到稳定入口。
16
+ */
17
+ /** 与桌面端对齐的默认 dsh 版本;`DSH_RUNTIME_VERSION` 可覆盖。 */
18
+ export declare const DSH_ACP_PINNED_VERSION = "0.2.1-rc.2";
19
+ /** V4.1-Flash 在官方 provider catalog 中的 id(1017 只是桌面端 UI 徽标)。 */
20
+ export declare const DSH_ACP_DEFAULT_MODEL = "deepseek-flash";
21
+ /** 默认 provider;account 路线可用 `DSH_PROVIDER=deepseek-account`。 */
22
+ export declare const DSH_ACP_DEFAULT_PROVIDER = "deepseek-official";
23
+ /**
24
+ * 用户级稳定安装根目录(跨平台):
25
+ * - Windows:`%LOCALAPPDATA%\acp-dsh`
26
+ * - macOS:`~/Library/Application Support/acp-dsh`
27
+ * - Linux/其它:`$XDG_DATA_HOME/acp-dsh`(缺省 `~/.local/share/acp-dsh`)
28
+ * `DSH_RUNTIME_DIR` 可整体覆盖(便携安装、CI 或测试用)。
29
+ */
30
+ export declare function resolveDshRuntimeRoot(env?: NodeJS.ProcessEnv): string;
31
+ /** 稳定安装内 dsh 入口的绝对路径。 */
32
+ export declare function resolveManagedDshEntry(env?: NodeJS.ProcessEnv, version?: string): string;
33
+ /**
34
+ * 版本比较(够用的 semver 语义):数字段逐个比;同号时正式版 > 预发布版;
35
+ * 预发布段按数字/字典序。用于「用户装了多个版本时自动取最高」。
36
+ */
37
+ export declare function compareDshVersions(a: string, b: string): number;
38
+ /**
39
+ * 实际使用的稳定安装版本:
40
+ * 1. `DSH_RUNTIME_VERSION` 显式指定;
41
+ * 2. 否则扫描运行时根目录,取**已装版本里最高的一个**——用户用
42
+ * `setup-dsh-acp.mjs --version X` 升上去后,acp-client 无需改代码即可自动跟上;
43
+ * 3. 一个都没有时回落到内置 pin(此时 `hasManagedDshRuntime` 为 false,走 bunx)。
44
+ */
45
+ export declare function resolveManagedDshVersion(env?: NodeJS.ProcessEnv): string;
46
+ /** 稳定安装是否已就位;命中即可免 bunx 冷启动。 */
47
+ export declare function hasManagedDshRuntime(env?: NodeJS.ProcessEnv): boolean;
48
+ export interface AcpModelOverride {
49
+ provider: string;
50
+ model: string;
51
+ }
52
+ /**
53
+ * 模型覆盖意图:`DSH_ACP_MODEL_PATCH=off|0|false|none` 关闭;
54
+ * `DSH_PROVIDER` / `DSH_MODEL` 可改目标(默认 deepseek-official / deepseek-flash)。
55
+ */
56
+ export declare function resolveAcpModelOverride(env?: NodeJS.ProcessEnv): AcpModelOverride | null;
57
+ /** 生成启动器 `--patch` 用的覆盖层(与 profile 的 cordis.patch.yml 同格式)。 */
58
+ export declare function buildAcpModelPatch(override: AcpModelOverride): string;
59
+ /**
60
+ * 把模型覆盖层写到系统临时目录并返回路径;写失败返回 null(spawn 不带 --patch)。
61
+ * 按 provider/model 缓存,重复 connect 不重复写盘。
62
+ */
63
+ export declare function ensureAcpModelPatchFile(env?: NodeJS.ProcessEnv): string | null;
64
+ /** 测试/长驻进程切换环境时清缓存。 */
65
+ export declare function resetAcpModelPatchCache(): void;
@@ -1,34 +1,73 @@
1
1
  import type { CodexAuthPreflight } from "../../contracts";
2
2
  import type { GenericRuntimeAdapter } from '../index';
3
+ export * from './dsh-acp-bootstrap';
4
+ export * from './deepseek-provider';
5
+ export * from './quota';
3
6
  /**
4
- * DeepSeek 运行时适配器(`bunx @deepseek-ai/dsh --profile acp`)。
7
+ * DeepSeek 运行时适配器(`dsh --profile acp`)。
5
8
  *
6
- * 凭证复用:harness 自身凭证(`DEEPSEEK_API_KEY` / harness 配置,
7
- * 全部留在官方位置,我方不存)。harness 的 ACP `authMethods` 为空,
8
- * 连接门闩天然走 `skip_auth`;此处探测仅供诊断展示。
9
- * 模型经 session 到达(顶层 `models` 方言由 session-open 合成 model 选项),无需额外动作。
9
+ * 启动目标按优先级:
10
+ * 1. `DSH_BIN`:显式 dsh 入口(`.js` 走当前 node,其余按可执行文件);
11
+ * 2. 用户级稳定安装(`scripts/setup-dsh-acp.mjs` 装到 `resolveDshRuntimeRoot()`,
12
+ * 命中即用当前 node 直跑,见 `dsh-acp-bootstrap.ts`);
13
+ * 3. `DSH_PACKAGE`:npm 包定位符覆盖(如 pin `@deepseek-ai/dsh@0.2.1-rc.2`);
14
+ * 4. 缺省 `bunx -y @deepseek-ai/dsh@latest --profile acp`。
10
15
  *
11
- * 缺 key 预检(仿 cursor `resolveSpawnCommand` 为 null 即拦的 precedent):
12
- * 本机缺 key 时 harness 极可能直接退出(stdio 关闭→传输层报 connection
13
- * closed),故经 `resolveSpawnBlocker` 在 spawn 前判停,回带中文动作指引。
14
- * 同族 `DSH_*` 仅认文档明确的变量——当前仅认 `DEEPSEEK_API_KEY`(预检)
15
- * 与 `DSH_PACKAGE`(包定位符覆盖,见 `resolveDeepseekSpawnCommand`)。
16
+ * 不依赖本机手工改动:dsh 的 ACP 应用把默认模型写死成不存在的
17
+ * `deepseek-v4-flash`,这里统一追加启动器自带的 `--patch <临时文件>` 覆盖层
18
+ * (`DSH_ACP_MODEL_PATCH=off` 可关;`DSH_PROVIDER` / `DSH_MODEL` 可改目标)。
19
+ * 换机后只需「装依赖 + 登录(或导出 DEEPSEEK_API_KEY)」即可复现,不需要改
20
+ * `$DSH_HOME/profiles/acp/cordis.patch.yml`。
21
+ *
22
+ * 用稳定安装的原因:bunx 把包装进临时目录,harness 的
23
+ * `$DSH_HOME/profiles/node_modules` 会把这些包软链到该临时目录;临时目录被系统
24
+ * 清理后 profile 立刻断链(实测 `bunx-<id>@deepseek-ai/dsh@latest` 已消失)。
25
+ *
26
+ * 凭证:harness 自身凭证(`DEEPSEEK_API_KEY` 或 `$DSH_HOME/.credentials.yaml`
27
+ * 里的登录记录,全部留在官方位置,我方不存)。harness 的 ACP `authMethods`
28
+ * 为空,连接门闩天然走 `skip_auth`;此处探测仅供诊断与预检。
29
+ *
30
+ * 缺凭证预检(仿 cursor `resolveSpawnCommand` 为 null 即拦的 precedent):
31
+ * 本机既无 key 也无 harness 登录记录时 harness 极可能直接退出(stdio 关闭→
32
+ * 传输层报 connection closed),故经 `resolveSpawnBlocker` 在 spawn 前判停,
33
+ * 回带中文动作指引。只认文档明确的变量:`DEEPSEEK_API_KEY`(预检)、
34
+ * `DSH_HOME`(凭证库位置)、`DSH_PACKAGE` / `DSH_BIN` / `DSH_RUNTIME_DIR`
35
+ * (启动目标覆盖)。
16
36
  *
17
37
  * 上游坏包逃生(实锤:dsh 0.1.5-rc.2 内依赖 `…-documentpreview@^0.1.5-rc.3`,
18
38
  * 而该包最高仅 0.1.6-alpha.1,上游缺 rc.3,自解析依赖失败退出):
19
39
  * 设 `DSH_PACKAGE` pin 旧版(如 `@deepseek-ai/dsh@0.1.4`)即可绕过。
40
+ *
41
+ * 模型口径:ACP `session/new` 的 model 选项值是 `["provider","model"]` 的 JSON
42
+ * 串;官方 catalog 里 V4.1-Flash 的 id 是 `deepseek-flash`(桌面端 1017 徽标
43
+ * 只是 UI 标签,不是模型版本)。ACP 应用自带的补丁把默认模型写成了
44
+ * `deepseek-v4-flash`,需要 profile 层覆盖,见 docs/api-reference.md。
20
45
  */
21
46
  export declare function buildDeepseekMissingKeyMessage(): string;
22
- export declare function resolveDeepseekSpawnBlocker(env?: NodeJS.ProcessEnv): string | null;
47
+ /** harness 家目录:`DSH_HOME` 优先,缺省 `~/.dsh`(与 dsh 自身口径一致)。 */
48
+ export { resolveDshCredentialsFile, resolveDshHome } from './deepseek-provider';
49
+ /**
50
+ * harness 凭证库是否至少有一条记录。
51
+ * `records:` 为空集合或缺文件即视为未登录;只有记录块内的缩进行才算数,
52
+ * 遇到下一个顶层键立即停止,避免把别的顶层字段误判成凭证。
53
+ */
54
+ export declare function hasDshCredentials(env?: NodeJS.ProcessEnv): boolean;
55
+ /**
56
+ * 预检判停:显式 env 有 key、宿主表单已落库、或 harness 自己已登录,三者其一即放行。
57
+ * `dataDir` 用于读 URL+Token 表单落库;不传则只看 env 与 harness 凭证库。
58
+ */
59
+ export declare function resolveDeepseekSpawnBlocker(env?: NodeJS.ProcessEnv, dataDir?: string): string | null;
23
60
  /**
24
61
  * 包定位符覆盖(`DSH_PACKAGE`,缺省 `@deepseek-ai/dsh`,沿 contracts 常量口径):
25
62
  * 最小校验——非空、无空白、无 shell 元字符(`;&|$()` 等),非法回落缺省并 dev warn。
26
63
  * 经 `resolveSpawnCommand` 风格返回 spawn 目标覆盖(precedent 照抄 cursor)。
27
64
  */
28
65
  export declare function resolveDeepseekPackage(env?: NodeJS.ProcessEnv): string;
66
+ /** 稳定安装的 dsh 入口覆盖(`DSH_BIN`);非法值回落 null 走包解析。 */
67
+ export declare function resolveDeepseekBin(env?: NodeJS.ProcessEnv): string | null;
29
68
  export declare function resolveDeepseekSpawnCommand(env?: NodeJS.ProcessEnv): {
30
69
  command: string;
31
70
  args: string[];
32
71
  };
33
- export declare function probeDeepseekAuth(): CodexAuthPreflight;
72
+ export declare function probeDeepseekAuth(env?: NodeJS.ProcessEnv, dataDir?: string): CodexAuthPreflight;
34
73
  export declare const deepseekAdapter: GenericRuntimeAdapter;
@@ -0,0 +1,24 @@
1
+ import type { AcpAgentQuota } from '../../contracts/quota';
2
+ /**
3
+ * DeepSeek 账户余额探针。
4
+ *
5
+ * ACP 协议本身**没有**余额接口(只有 `usage_update` 的上下文用量事件,见
6
+ * `QuotaCache`),所以余额走 DeepSeek 官方 `GET /user/balance`(Bearer API Key)。
7
+ * 这与 harness 无关:用户既可以通过 URL+Token 表单、环境变量,也可以只登录
8
+ * harness(凭证库 `refs.DEEPSEEK_API_KEY`)——三者都能查到同一份余额。
9
+ *
10
+ * 余额接口挂在 API 根上,不在 harness 的 `/anthropic` 兼容端点下,所以这里会把
11
+ * 配置的 base URL 归一化掉 `/anthropic` 后缀。
12
+ */
13
+ export interface DeepseekQuotaOptions {
14
+ runtimeId?: string;
15
+ env?: NodeJS.ProcessEnv;
16
+ dataDir?: string;
17
+ fetchImpl?: typeof fetch;
18
+ timeoutMs?: number;
19
+ }
20
+ /** 解析可用于查余额的 Key:显式 env > 表单落库 > harness 凭证库。 */
21
+ export declare function resolveDeepseekQuotaKey(options?: DeepseekQuotaOptions): string | null;
22
+ /** 余额接口的 API 根(去掉 harness 的 `/anthropic` 兼容路径)。 */
23
+ export declare function resolveDeepseekApiBase(options?: DeepseekQuotaOptions): string;
24
+ export declare function probeDeepseekQuota(options?: DeepseekQuotaOptions): Promise<AcpAgentQuota | null>;
@@ -15,10 +15,15 @@ export interface GenericRuntimeAdapter {
15
15
  beforeSpawn?: () => Promise<void>;
16
16
  /** 仅冷启动(无温进程可用、即将 spawn)时调用一次;各 runtime 自理副作用 */
17
17
  onColdStart?: () => Promise<void>;
18
- probeAuth: () => CodexAuthPreflight;
18
+ probeAuth: (context?: {
19
+ env?: NodeJS.ProcessEnv;
20
+ dataDir?: string;
21
+ }) => CodexAuthPreflight;
19
22
  /** 运行时配额探针(5h 限制、周额度、余额),与会话生命周期解耦 */
20
23
  probeQuota?: (options?: {
21
24
  sessionId?: string;
25
+ dataDir?: string;
26
+ env?: NodeJS.ProcessEnv;
22
27
  }) => Promise<AcpAgentQuota | null>;
23
28
  /**
24
29
  * 预 spawn 接线点(冷启动 spawn 前调用一次):
@@ -37,9 +42,24 @@ export interface GenericRuntimeAdapter {
37
42
  * 返回非空字符串表示直接判停,`acp-connection.ts` 以该文案回带
38
43
  * `ACP_SPAWN_ERROR`,不触达 spawn(如 deepseek 缺 DEEPSEEK_API_KEY 时
39
44
  * harness 秒退,stdio 关闭即裸 `ACP connection closed`)。
45
+ * 上下文带宿主显式 env 与 dataDir:运行时可有自己的凭证落库(如 DeepSeek
46
+ * 的 URL+Token 表单),预检必须与 spawn 用同一份事实,否则会出现
47
+ * “表单填了却仍被判停”。
40
48
  * 缺省(undefined)/返回空表示放行;抛错时按放行处理(防御性回落),不断连接。
41
49
  */
42
- resolveSpawnBlocker?: () => string | null | undefined;
50
+ resolveSpawnBlocker?: (context?: {
51
+ env?: NodeJS.ProcessEnv;
52
+ dataDir?: string;
53
+ }) => string | null | undefined;
54
+ /**
55
+ * 运行时自有凭证落库 → 追加 spawn 环境(缺省不注入)。
56
+ * 在代理/调用方 env 合成之后合并;`currentEnv` 已含的键由实现方决定是否覆盖
57
+ * (DeepSeek 的做法是显式 env 优先,落库只补空缺)。
58
+ */
59
+ getProviderEnv?: (context: {
60
+ dataDir: string;
61
+ env: NodeJS.ProcessEnv;
62
+ }) => NodeJS.ProcessEnv | undefined;
43
63
  getSpawnEnv?: (proxySettings?: Partial<AcpProxySettings>) => {
44
64
  env: NodeJS.ProcessEnv;
45
65
  envRemove: string[];
@@ -9,8 +9,17 @@ export declare function parseRateLimitsFromStatusText(text: string, runtimeId?:
9
9
  export declare class QuotaCache {
10
10
  private bySession;
11
11
  private byRuntime;
12
+ /** ACP `usage_update` 的上下文占用(token 用量),与余额探针分账存放 */
13
+ private usageBySession;
14
+ private usageByRuntime;
12
15
  observe(params: unknown, defaultRuntimeId?: string): AcpAgentQuota | null;
13
16
  set(quota: AcpAgentQuota, sessionId?: string): void;
14
17
  get(sessionId?: string, runtimeId?: string): AcpAgentQuota | undefined;
18
+ /**
19
+ * 把 `usage_update` 的上下文占用并入配额对象(读取时合并,不覆盖余额):
20
+ * 有余额时作为 `extraWindows` 的 `Context` 窗口;没有余额但有用量时,
21
+ * 单独给出一个以 Context 为主窗口的配额,避免 UI 一片空白。
22
+ */
23
+ applyContextUsage(quota: AcpAgentQuota | null | undefined, sessionId?: string, runtimeId?: string): AcpAgentQuota | null;
15
24
  clear(): void;
16
25
  }