@dsh-enhanced/traex-acp-provider 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 +146 -0
- package/cordis.patch.yml +3 -0
- package/lib/acp-client.d.ts +182 -0
- package/lib/acp-client.d.ts.map +1 -0
- package/lib/acp-client.js +1216 -0
- package/lib/acp-client.js.map +1 -0
- package/lib/adapter.d.ts +74 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/adapter.js +442 -0
- package/lib/adapter.js.map +1 -0
- package/lib/auth.d.ts +23 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +59 -0
- package/lib/auth.js.map +1 -0
- package/lib/catalog-cache.d.ts +73 -0
- package/lib/catalog-cache.d.ts.map +1 -0
- package/lib/catalog-cache.js +56 -0
- package/lib/catalog-cache.js.map +1 -0
- package/lib/config.d.ts +41 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +29 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +46 -0
- package/lib/index.js.map +1 -0
- package/lib/prompt.d.ts +4 -0
- package/lib/prompt.d.ts.map +1 -0
- package/lib/prompt.js +48 -0
- package/lib/prompt.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-enhanced contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @dsh-enhanced/traex-acp-provider
|
|
2
|
+
|
|
3
|
+
把同一台机器、同一 OS 用户已经登录的 TraeX / TRAE CLI 注册为 DeepSeek Harness 的 `traex-agent` provider。DSH 在这里是 **ACP client**:模型选择器会通过无 prompt 的临时 ACP 会话发现 TraeX 当前提供的模型及其逐模型 reasoning effort;每次模型请求仍会启动新的 `traex acp serve`、完成 ACP v1 握手、创建会话、再次校验模型/effort、发送 prompt,并只把 `agent_message_chunk` 文本映射回 DSH。
|
|
4
|
+
|
|
5
|
+
这不是订阅 OAuth 转接,也不是模型 API provider。认证、模型供应、网络请求和可能产生的费用均由本机 TraeX 负责;插件不读取或托管 token。仓库中的 [`@dsh-enhanced/acp`](../acp) 方向正好相反——它让 DSH 自己成为供编辑器调用的 ACP agent。
|
|
6
|
+
|
|
7
|
+
## 前置条件
|
|
8
|
+
|
|
9
|
+
需要包含 ACP server 的 TraeX 版本。先在运行 DSH 的同一用户下检查:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
traex --version
|
|
13
|
+
traex acp serve --help
|
|
14
|
+
traex login status
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`--version` 只是人工兼容记录;运行时的机器门禁是精确 `login status` 加 ACP `initialize` 返回的 protocol / agent identity / auth method,不依赖对版本文本的宽松解析。
|
|
18
|
+
|
|
19
|
+
如命令名是 `trae-cli`,可在插件配置中覆盖 `command`。首次登录应在 DSH 外单独完成,例如本机版本提供的 `traex login --sso` 或 `traex login --sso-device`;插件不会启动交互式登录或打开浏览器。
|
|
20
|
+
|
|
21
|
+
公开的 ByteDance `trae-agent` Python 项目与这里检测到的 TraeX / TRAE CLI 不是同一个运行时。只有 `acp serve` 可用且握手返回 `agentInfo.name = "traex-acp"` 的实现会被本插件接受。
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
dsh plugin --profile web add @dsh-enhanced/traex-acp-provider
|
|
27
|
+
dsh --profile web --dump-config
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
该实验性 route 默认关闭。确认本机版本、登录和 ACP 入口后设置 `enabled: true`,再在 DSH 的 provider/model 选择处选择 `traex-agent`。模型选择器会列出 TraeX 当前 ACP 会话返回的全部模型;`default` 是额外保留的别名,沿用 TraeX 当前模型。具体模型和 effort 都通过 ACP session config option 选择,不会拼进 shell 命令。
|
|
31
|
+
|
|
32
|
+
## 快速开始(5 步)
|
|
33
|
+
|
|
34
|
+
1. **确认 ACP 可用**:`traex acp serve --help` 能打开、`traex login status` 输出 `Logged in using Trae`。命令名是 `trae-cli` 时用它替换下面的 `traex`。
|
|
35
|
+
2. **安装插件**:`dsh plugin --profile web add @dsh-enhanced/traex-acp-provider`。
|
|
36
|
+
3. **开启 route**:本 route 默认关闭,需在配置里显式设 `enabled: true`(命令名不同则一并改 `command`)。
|
|
37
|
+
4. **落盘检查**:`dsh --profile web --dump-config` 确认 `enabled` 与 `command` 生效。
|
|
38
|
+
5. **选择模型调用**:在 DSH 里选 `traex-agent`,等待模型目录加载后选择 `default`(沿用 TraeX 当前模型)或任一实时发现的具体模型;支持 reasoning 的模型还会显示它自己的 effort 选项。
|
|
39
|
+
|
|
40
|
+
每次调用会启动一个新的 `traex acp serve` 进程并消耗 TraeX 侧额度。遇到报错先看下文「协议与失败策略」的错误码表。
|
|
41
|
+
|
|
42
|
+
## 配置
|
|
43
|
+
|
|
44
|
+
完整配置如下。Cordis `config` 会整段替换,覆盖时请保留仍需使用的字段:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
- id: dsh-enhanced-traex-acp-provider
|
|
48
|
+
name: '@dsh-enhanced/traex-acp-provider'
|
|
49
|
+
config:
|
|
50
|
+
enabled: true
|
|
51
|
+
command: traex
|
|
52
|
+
cwd: .
|
|
53
|
+
models: [default]
|
|
54
|
+
timeoutMs: 600000
|
|
55
|
+
authProbeTimeoutMs: 10000
|
|
56
|
+
maxAuthProbeBytes: 32768
|
|
57
|
+
killGraceMs: 3000
|
|
58
|
+
maxMessageBytes: 262144
|
|
59
|
+
maxProtocolBytes: 16777216
|
|
60
|
+
maxProtocolMessages: 10000
|
|
61
|
+
maxOutputBytes: 2097152
|
|
62
|
+
maxStderrBytes: 32768
|
|
63
|
+
maxPromptBytes: 131072
|
|
64
|
+
extraEnvNames: []
|
|
65
|
+
logDiagnostics: false
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- `enabled` 默认 `false`;只在完成本机兼容性与登录检查后显式开启。
|
|
69
|
+
- `command` 是单个可执行文件名或绝对路径;插件固定参数数组并使用 `shell: false`,不接受 shell 片段。
|
|
70
|
+
- `cwd` 是 ACP `session/new` 的工作目录;相对路径按 DSH 进程启动目录解析。
|
|
71
|
+
- `models` 是实时 ACP 目录以外需要额外展示的非权威别名列表,默认只有 `default`。它不是执行允许列表;每次请求都会在新的 ACP 会话里重新验证具体模型和 reasoning effort,不可用时失败且不会静默换模型或 effort。
|
|
72
|
+
- `timeoutMs` 覆盖握手、建会话和整轮 prompt。取消或超时时先发 ACP `session/cancel` 和 `SIGINT`,等待 `killGraceMs` 后升级为 `SIGKILL`,再等待一个等长窗口确认 `close`。仍未关闭时以 `teardown=failed` 错误结算,保留原始 abort/timeout 分类,并继续跟踪迟到的 `close`;不会伪称已完成回收。
|
|
73
|
+
- `authProbeTimeoutMs` / `maxAuthProbeBytes` 限制每次调用及目录发现前的 `traex login status`;当前 TraeX 可能把精确文本 `Logged in using Trae` 单独写入 stdout 或 stderr,这两种形式都会被接受,混合输出、ChatGPT、API key、access token、未登录与未知输出全部拒绝。
|
|
74
|
+
- `maxMessageBytes` 限制单条 NDJSON,`maxProtocolBytes` / `maxProtocolMessages` 限制整轮 ACP 输入,`maxOutputBytes` 限制助手文本;字节限制均按 UTF-8 计算。
|
|
75
|
+
- `extraEnvNames` 只允许填写要从 DSH 启动环境继承的变量名,配置中不能写变量值或 secret。
|
|
76
|
+
- API key/token、Authorization/private-key/database credential 以及 OpenAI/Codex 等 provider endpoint 变量,即使列入 `extraEnvNames` 也会被硬排除;代理 URL 中的 userinfo 会被删除,无法安全解析的含 `@` 代理值会被拒绝。
|
|
77
|
+
- `logDiagnostics` 默认为 `false`,此时对 stderr 只记录“TraeX 写入 stderr”;启用后仅记录经过常见 token/key/邮箱规则脱敏的有界尾部,仍不适合输出业务秘密。独立于该开关,插件始终会在每次请求结算时记录一条**无凭据**的生命周期诊断(阶段、prompt 是否提交、结果分类、teardown 状态、能可靠测得的毫秒级延迟指标,以及 ACP 返回时的纯数值 usage 快照),成功走 `debug`、非成功走 `info`;并在观测到模型目录时只记录**模型数量**。这些行不含 prompt、stderr 原文、认证凭据或任何 model id 原文;usage 快照可能包含 ACP 报告的 token 数量,但不会映射或转发为 DSH `TokenUsage`。
|
|
78
|
+
|
|
79
|
+
## 固定安全策略
|
|
80
|
+
|
|
81
|
+
插件只接受并启动下面这一组 server 参数:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
traex --sandbox read-only --ask-for-approval never acp serve
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
不会传 `--yolo`、`bypass_permissions` 或任意用户追加参数。ACP client 不声明文件系统或 terminal capability;TraeX 发起的每个 `session/request_permission` 都返回 `cancelled`。这让兼容 provider 默认只能读取上下文并返回文本,不应修改项目或运行需要授权的操作。
|
|
88
|
+
|
|
89
|
+
安全仍取决于 TraeX 对其配置和沙箱的正确实现。不要把 prompt 约束当作操作系统隔离;处理不可信仓库时,仍应使用只读挂载、容器或独立 OS 账号。
|
|
90
|
+
|
|
91
|
+
## 权限与数据边界
|
|
92
|
+
|
|
93
|
+
| 能力 | 行为 |
|
|
94
|
+
|---|---|
|
|
95
|
+
| 文件系统 | 把规范化后的 `cwd` 发送给 TraeX,并强制 read-only sandbox;插件本身不提供 ACP 文件读写接口。TraeX 可以读取工作区以完成任务。 |
|
|
96
|
+
| 网络 | 插件本身不直连模型服务;TraeX 会连接自己的认证、推理、更新或遥测服务。 |
|
|
97
|
+
| 子进程 | 每次请求直接启动一个 TraeX ACP stdio 子进程,`shell: false`。打开/刷新模型目录也会启动一个无 prompt 的临时 ACP 会话,依次读取各模型的 reasoning selector 后关闭。取消时先走 ACP,再回收进程组;Windows 后代进程回收为 best-effort。 |
|
|
98
|
+
| 凭据 | 不读取 TraeX auth 文件、不实现登录、不刷新或上传 token;只让 TraeX 在本机用户配置目录中使用自己的缓存凭据。 |
|
|
99
|
+
| 浏览器 | 插件不会打开浏览器;用户在插件外执行 TraeX login 时可能打开。 |
|
|
100
|
+
| ACP 权限 | 所有 permission request 均拒绝;不暴露 client-side FS、terminal 或 MCP server。 |
|
|
101
|
+
| 日志 | 不主动记录 prompt;stderr 有界且默认不输出内容。每次请求结算记录一条无凭据生命周期诊断(阶段/提交状态/结果分类/teardown、可测得的毫秒级延迟指标,以及 ACP 返回时的纯数值 usage 快照),并在观测目录时只记录模型数量。均不含 prompt、stderr 原文、认证凭据或 model id 原文;usage 快照可能包含 ACP 报告的 token 数量。 |
|
|
102
|
+
| 安装脚本 | 包内没有 install/postinstall 脚本,也不会安装或更新 TraeX。 |
|
|
103
|
+
|
|
104
|
+
## 协议与失败策略
|
|
105
|
+
|
|
106
|
+
- 只接受 ACP protocol v1 和 `traex-acp` agent identity;版本或 identity 不符时 fail closed。
|
|
107
|
+
- SDK 前的 wire guard 会追踪 JSON-RPC request id;非法 envelope、未知/重复 response id、未声明的 filesystem/terminal request 和未知 notification 都会终止该轮,不交给 SDK 宽松处理。
|
|
108
|
+
- 只转发当前 session 的文本 `agent_message_chunk`;thought、plan、tool update 不会伪装成模型文本。
|
|
109
|
+
- `end_turn`、`max_tokens`、`max_turn_requests` 是可完成终态;`refusal`、`cancelled`、断连、畸形/超限 NDJSON、无文本或缺少终态都会失败。
|
|
110
|
+
- 不自动重试。外部 agent 可能已经读取上下文或产生服务端计费,自动重试会放大副作用。
|
|
111
|
+
|
|
112
|
+
调用失败时返回的稳定 `LlmError` code 与排查:
|
|
113
|
+
|
|
114
|
+
| 错误码 | 含义 | 处理 |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `ACP_AUTH_REQUIRED` | 每次调用前的 `traex login status` 未精确报告 `Logged in using Trae` | 在同一 OS 用户下重新 `traex login`;ChatGPT/API key/access token/未登录都会被拒。 |
|
|
117
|
+
| `ACP_ENTITLEMENT_REQUIRED` | 握手成功但当前 Trae 账号没有任何可用模型 | 确认账号权益/套餐,必要时在 TraeX 侧切换账号。 |
|
|
118
|
+
| `ACP_MODEL_UNAVAILABLE` | 请求的模型不在本次 ACP 会话的 model selector 中 | 刷新模型列表或用 `default`;账号权益或 TraeX 目录可能已经变化。 |
|
|
119
|
+
| `UNSUPPORTED_REASONING_EFFORT` | 所选 effort 不属于该模型当前返回的 reasoning selector | 重新选择该模型实际显示的 effort;不同模型支持集可以不同。 |
|
|
120
|
+
| `ACP_REFUSAL` | TraeX 明确拒绝了本次请求 | 属模型侧决定,调整 prompt 后重试。 |
|
|
121
|
+
| `ACP_TIMEOUT` | 握手+建会话+整轮 prompt 超过 `timeoutMs` | 简化 prompt 或调大 `timeoutMs`。 |
|
|
122
|
+
| `ACP_OUTPUT_LIMIT` | 助手文本超过 `maxOutputBytes` | 调大 `maxOutputBytes` 或缩小任务。 |
|
|
123
|
+
| `ACP_PROTOCOL_ERROR` | protocol/identity 不符、非法 envelope、无文本或缺终态 | 确认 TraeX 版本仍提供 ACP v1 + `traex-acp` identity;升级后握手变化时插件会拒绝而非猜测。 |
|
|
124
|
+
| `ACP_PROCESS_FAILED` | 子进程非零退出或其他未归类失败 | 开 `logDiagnostics` 看脱敏 stderr;单独 `traex acp serve` 复现。 |
|
|
125
|
+
| `CLI_NOT_FOUND` | 找不到可执行文件(`ENOENT`) | 核对 `command` 名称/路径及 `PATH`。 |
|
|
126
|
+
| `INVALID_PROVIDER` | 选择了非 `traex-agent` 的 provider id | 只使用 `traex-agent`。 |
|
|
127
|
+
|
|
128
|
+
- 认证不足会返回 `ACP_AUTH_REQUIRED`,无可用权益/模型分别映射为 `ACP_ENTITLEMENT_REQUIRED` / `ACP_MODEL_UNAVAILABLE`,明确拒绝映射为 `ACP_REFUSAL`;其他稳定错误包括 `ACP_PROTOCOL_ERROR`、`ACP_TIMEOUT`、`ACP_OUTPUT_LIMIT`、`ACP_PROCESS_FAILED` 和 `CLI_NOT_FOUND`。
|
|
129
|
+
|
|
130
|
+
> 模型目录:`listModels` 会建立一个无 prompt 的临时 ACP 会话,依次选择本次目录中的每个模型,读取该模型实际返回的 reasoning selector,然后关闭会话。完整结果会在内存里做一份**非权威**、带短 TTL 的展示缓存;它不放行或拒绝执行。每次真实调用仍以新的 `session/new` 返回值为唯一执行依据,重新选择并核对模型与 effort;auth 失败、reload 或版本变化时缓存失效。日志只输出模型数量,不含 model id 原文。
|
|
131
|
+
|
|
132
|
+
## 已知限制
|
|
133
|
+
|
|
134
|
+
- DSH `0.1.0-rc.6` 暴露的是 `LlmAdapter` seam,因此本版是 text-only 兼容层,不是完整 ACP UI。TraeX 的 plan、tool call、diff、permission UI、会话列表和富内容不会进入 DSH。
|
|
135
|
+
- 每次 DSH 请求使用一个新的 TraeX 进程和 ACP session,不恢复外部历史;完整 DSH 对话会被序列化进 prompt。
|
|
136
|
+
- 暂不转发图片、音频、DSH tool schema 或 TraeX token usage。实验性的 ACP `PromptResponse.usage` 只保留显式数值字段用于内部诊断,不会映射或发送为 DSH usage chunk。
|
|
137
|
+
- TraeX 是变化中的开发工具;本实现以本机 `traecli 0.201.1 (internal edition)` 的 ACP v1 握手、逐模型 reasoning selector 与官方 ACP SDK `0.25.1` 为验证基线。升级后若 identity、模型/effort selector 或终态变化,插件会拒绝而不是猜测兼容。
|
|
138
|
+
|
|
139
|
+
## 兼容性与调研
|
|
140
|
+
|
|
141
|
+
- Node.js `^22.19.0 || >=24.0.0`
|
|
142
|
+
- DeepSeek Harness / `@deepseek-ai/dsh-llm` `>=0.1.0-rc.6 <0.2.0`
|
|
143
|
+
- Cordis `^4.0.1`
|
|
144
|
+
- Agent Client Protocol SDK `0.25.1`,protocol version `1`
|
|
145
|
+
|
|
146
|
+
TraeX、本机能力探测、公开 `trae-agent` 与 ACP 边界见 [调研记录](../../docs/traex-acp-connector-research.md);仓库基线见 [compatibility.md](../../docs/compatibility.md)。
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Readable, Writable } from 'node:stream';
|
|
2
|
+
import { type StopReason } from '@agentclientprotocol/sdk';
|
|
3
|
+
export interface TraexAcpInvocation {
|
|
4
|
+
readonly command: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly cwd: string;
|
|
7
|
+
readonly prompt: string;
|
|
8
|
+
readonly model?: string;
|
|
9
|
+
readonly reasoningEffort?: string;
|
|
10
|
+
/** Internal transport mode used by the prompt-free catalog discovery wrapper. */
|
|
11
|
+
readonly operation?: 'prompt' | 'catalog';
|
|
12
|
+
}
|
|
13
|
+
export interface TraexAcpCatalogInvocation {
|
|
14
|
+
readonly command: string;
|
|
15
|
+
readonly args: readonly string[];
|
|
16
|
+
readonly cwd: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SpawnedProcess {
|
|
19
|
+
readonly pid?: number;
|
|
20
|
+
readonly stdin: Writable;
|
|
21
|
+
readonly stdout: Readable;
|
|
22
|
+
readonly stderr: Readable;
|
|
23
|
+
readonly exitCode?: number | null;
|
|
24
|
+
readonly signalCode?: NodeJS.Signals | null;
|
|
25
|
+
kill(signal?: NodeJS.Signals | number): boolean;
|
|
26
|
+
once(event: 'spawn', listener: () => void): this;
|
|
27
|
+
once(event: 'error', listener: (error: Error) => void): this;
|
|
28
|
+
once(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
|
29
|
+
}
|
|
30
|
+
export interface SpawnOptions {
|
|
31
|
+
readonly cwd: string;
|
|
32
|
+
readonly shell: false;
|
|
33
|
+
readonly detached: boolean;
|
|
34
|
+
readonly stdio: readonly ['pipe', 'pipe', 'pipe'];
|
|
35
|
+
readonly env: NodeJS.ProcessEnv;
|
|
36
|
+
}
|
|
37
|
+
export type SpawnProcess = (command: string, args: readonly string[], options: SpawnOptions) => SpawnedProcess;
|
|
38
|
+
export interface RunTraexAcpOptions {
|
|
39
|
+
readonly signal?: AbortSignal;
|
|
40
|
+
readonly timeoutMs?: number;
|
|
41
|
+
readonly killGraceMs?: number;
|
|
42
|
+
/** Maximum size of one raw ACP NDJSON message before parsing. */
|
|
43
|
+
readonly maxMessageBytes?: number;
|
|
44
|
+
/** Maximum cumulative bytes accepted from ACP stdout. */
|
|
45
|
+
readonly maxProtocolBytes?: number;
|
|
46
|
+
/** Maximum number of ACP stdout messages accepted per invocation. */
|
|
47
|
+
readonly maxProtocolMessages?: number;
|
|
48
|
+
/** Maximum cumulative bytes emitted from agent_message_chunk text. */
|
|
49
|
+
readonly maxOutputBytes?: number;
|
|
50
|
+
/** Maximum bytes retained and reported from child stderr. */
|
|
51
|
+
readonly maxStderrBytes?: number;
|
|
52
|
+
/** Names only. Values are copied from process.env after secret-name filtering. */
|
|
53
|
+
readonly extraEnvNames?: readonly string[];
|
|
54
|
+
/** Receives the validated ACP terminal reason exactly once on success. */
|
|
55
|
+
readonly onStopReason?: (reason: TraexSuccessfulStopReason) => void;
|
|
56
|
+
readonly onDiagnostic?: (diagnostic: string) => void;
|
|
57
|
+
/** Receives credential-free lifecycle facts exactly once at settlement (success or failure); never affects settlement. */
|
|
58
|
+
readonly onSettled?: (context: ProviderFailureContext) => void;
|
|
59
|
+
/** Receives a non-authoritative model catalog observation from a normal handshake. */
|
|
60
|
+
readonly onCatalogObserved?: (observation: CatalogObservation) => void;
|
|
61
|
+
/** Adapter-measured login-probe duration, forwarded so settled metrics stay in one place. */
|
|
62
|
+
readonly authProbeDurationMs?: number;
|
|
63
|
+
readonly spawn?: SpawnProcess;
|
|
64
|
+
}
|
|
65
|
+
/** Whether the prompt was handed to the ACP stream; the only safe basis for reasoning about replay. */
|
|
66
|
+
export type PromptSubmissionState = 'not-submitted' | 'submitted' | 'unknown';
|
|
67
|
+
/** Progress of the bounded teardown attempt; `failed` means child close was not proven. */
|
|
68
|
+
export type TeardownState = 'not-started' | 'in-progress' | 'completed' | 'failed' | 'unknown';
|
|
69
|
+
/** Lifecycle phase a failure was observed in, from handshake through teardown. */
|
|
70
|
+
export type TraexLifecyclePhase = 'initialize' | 'new-session' | 'model-catalog' | 'set-model' | 'set-reasoning' | 'prompt' | 'stream' | 'terminal' | 'close-session' | 'child-close';
|
|
71
|
+
/**
|
|
72
|
+
* Credential-free lifecycle facts for one ACP invocation. Diagnostic side-channel only:
|
|
73
|
+
* it never carries prompt text, stderr, credentials, model ids or tool/plan content, and never
|
|
74
|
+
* changes settlement. It may carry aggregate numeric usage counts from a validated ACP response.
|
|
75
|
+
*/
|
|
76
|
+
export interface ProviderFailureContext {
|
|
77
|
+
readonly phase: TraexLifecyclePhase;
|
|
78
|
+
readonly promptSubmissionState: PromptSubmissionState;
|
|
79
|
+
readonly assistantTextObserved: boolean;
|
|
80
|
+
readonly teardownState: TeardownState;
|
|
81
|
+
readonly terminalReason?: string;
|
|
82
|
+
readonly exitCode?: number | null;
|
|
83
|
+
readonly signal?: NodeJS.Signals | null;
|
|
84
|
+
/** Explicit-clock-origin latency metrics; only measurable ones are present. */
|
|
85
|
+
readonly metrics?: TraexLifecycleMetrics;
|
|
86
|
+
/** Raw ACP token counts kept for internal diagnostics; never mapped to DSH TokenUsage. */
|
|
87
|
+
readonly usage?: AcpUsageSnapshot;
|
|
88
|
+
}
|
|
89
|
+
/** Latency metrics with named clock origins so they stay comparable across providers. */
|
|
90
|
+
export interface TraexLifecycleMetrics {
|
|
91
|
+
/** Local login-status probe duration. */
|
|
92
|
+
readonly authProbeDurationMs?: number;
|
|
93
|
+
/** Child `spawn` event to the first accepted ACP protocol message. */
|
|
94
|
+
readonly spawnToFirstProtocolMessageMs?: number;
|
|
95
|
+
/** Prompt submission to the first assistant text chunk. */
|
|
96
|
+
readonly promptToFirstTextMs?: number;
|
|
97
|
+
/** Prompt submission to the validated terminal stop reason. */
|
|
98
|
+
readonly promptToTerminalMs?: number;
|
|
99
|
+
/** Bounded teardown attempt start to completion or timeout settlement. */
|
|
100
|
+
readonly teardownDurationMs?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Internal snapshot of ACP's experimental `PromptResponse.usage`. Field names mirror the ACP
|
|
104
|
+
* wire shape (cumulative "across all turns") and are NOT the DSH `TokenUsage` per-call,
|
|
105
|
+
* uncached-input contract, so this is never emitted as a DSH usage chunk without semantic verification.
|
|
106
|
+
*/
|
|
107
|
+
export interface AcpUsageSnapshot {
|
|
108
|
+
readonly inputTokens: number;
|
|
109
|
+
readonly outputTokens: number;
|
|
110
|
+
readonly totalTokens: number;
|
|
111
|
+
readonly cachedReadTokens?: number;
|
|
112
|
+
readonly cachedWriteTokens?: number;
|
|
113
|
+
readonly thoughtTokens?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The explicit, unmet preconditions that must ALL be proven true before an `AcpUsageSnapshot` may be
|
|
117
|
+
* mapped to a DSH `TokenUsage` and emitted as a usage chunk. This is a verification gate, not a
|
|
118
|
+
* to-do list: until each item is confirmed against a real TraeX fixture or an official field
|
|
119
|
+
* contract, the snapshot stays an internal diagnostic and no usage chunk is emitted.
|
|
120
|
+
*
|
|
121
|
+
* Grounding (DSH contract, `@deepseek-ai/dsh-llm` `types.d.ts`):
|
|
122
|
+
* - `inputTokens`/`outputTokens` are REQUIRED numbers and must be per-call, not cumulative.
|
|
123
|
+
* - `inputTokens` must be UNCACHED input only; cache is reported separately.
|
|
124
|
+
* - a real zero must be preserved; only genuinely-absent optionals stay undefined.
|
|
125
|
+
*/
|
|
126
|
+
export declare const ACP_USAGE_DSH_MAPPING_GATE: readonly string[];
|
|
127
|
+
/**
|
|
128
|
+
* Non-authoritative snapshot of a model selector seen during a normal handshake. It exists
|
|
129
|
+
* for diagnostics/display only: it never gates a request, never feeds `resolveModel()`, and
|
|
130
|
+
* the catalog returned by the current `session/new` remains the sole execution authority.
|
|
131
|
+
*/
|
|
132
|
+
export interface CatalogObservation {
|
|
133
|
+
readonly currentValue: string;
|
|
134
|
+
readonly modelValues: readonly string[];
|
|
135
|
+
readonly models: readonly CatalogModel[];
|
|
136
|
+
/** True only when discovery inspected each model's post-selection reasoning selector. */
|
|
137
|
+
readonly completeReasoning: boolean;
|
|
138
|
+
readonly observedAt: number;
|
|
139
|
+
}
|
|
140
|
+
export interface CatalogReasoningEffort {
|
|
141
|
+
readonly id: string;
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly description?: string;
|
|
144
|
+
}
|
|
145
|
+
export interface CatalogModelReasoning {
|
|
146
|
+
readonly efforts: readonly CatalogReasoningEffort[];
|
|
147
|
+
readonly defaultEffort?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface CatalogModel {
|
|
150
|
+
readonly id: string;
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly description?: string;
|
|
153
|
+
readonly reasoning?: CatalogModelReasoning;
|
|
154
|
+
}
|
|
155
|
+
export type TraexAcpFailure = 'abort' | 'timeout' | 'protocol' | 'auth' | 'entitlement' | 'model' | 'reasoning' | 'refusal' | 'process' | 'output-limit';
|
|
156
|
+
export type TraexSuccessfulStopReason = Extract<StopReason, 'end_turn' | 'max_tokens' | 'max_turn_requests'>;
|
|
157
|
+
/** Stable, credential-free failure surfaced by the TraeX ACP transport. */
|
|
158
|
+
export declare class TraexAcpError extends Error {
|
|
159
|
+
readonly failure: TraexAcpFailure;
|
|
160
|
+
/** Original OS error code only; the untrusted process error text is never exposed. */
|
|
161
|
+
readonly systemCode?: string | undefined;
|
|
162
|
+
readonly code = "TRAEX_ACP_ERROR";
|
|
163
|
+
constructor(failure: TraexAcpFailure, message?: string,
|
|
164
|
+
/** Original OS error code only; the untrusted process error text is never exposed. */
|
|
165
|
+
systemCode?: string | undefined);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Runs a single TraeX ACP prompt and yields only text explicitly reported as
|
|
169
|
+
* `agent_message_chunk` for the newly-created session. The transport exposes no
|
|
170
|
+
* filesystem or terminal capability, rejects every permission request, never
|
|
171
|
+
* invokes a shell, and never performs an interactive authentication flow.
|
|
172
|
+
*/
|
|
173
|
+
export declare function runTraexAcpText(invocation: TraexAcpInvocation, options?: RunTraexAcpOptions): AsyncIterable<string>;
|
|
174
|
+
/**
|
|
175
|
+
* Perform a strict ACP initialize + session/new discovery without ever submitting a prompt.
|
|
176
|
+
* Every advertised model is selected inside the disposable session so model-specific reasoning
|
|
177
|
+
* efforts are captured exactly as TraeX exposes them.
|
|
178
|
+
*/
|
|
179
|
+
export declare function discoverTraexAcpModels(invocation: TraexAcpCatalogInvocation, options?: RunTraexAcpOptions): Promise<CatalogObservation>;
|
|
180
|
+
/** Environment allowlist for the local Trae tool-account executable. */
|
|
181
|
+
export declare function buildTraexEnv(extraEnvNames?: readonly string[]): NodeJS.ProcessEnv;
|
|
182
|
+
//# source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