@easbot/acp 0.3.32 → 0.3.36
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/README.en.md +134 -4
- package/README.md +211 -53
- package/dist/chunks/bootstrap-67LTURXQ.cjs +1 -0
- package/dist/chunks/bootstrap-DHON75MT.mjs +1 -0
- package/dist/chunks/cache-5PSUWHGW.cjs +1 -0
- package/dist/chunks/cache-O43SNRV2.mjs +1 -0
- package/dist/chunks/chunk-663BEBE4.cjs +1 -0
- package/dist/chunks/{chunk-VVGGER23.cjs → chunk-6VF3MZ6H.cjs} +1 -1
- package/dist/chunks/{chunk-2KOCPHVP.mjs → chunk-FAYVTNTB.mjs} +1 -1
- package/dist/chunks/chunk-FDMRPUSH.mjs +8 -0
- package/dist/chunks/{chunk-7RWES66A.cjs → chunk-H57INME2.cjs} +1 -1
- package/dist/chunks/chunk-IOEQ7YHD.cjs +8 -0
- package/dist/chunks/{chunk-RHW6YR3D.mjs → chunk-JEYD2VIG.mjs} +1 -1
- package/dist/chunks/{chunk-BNSJ6COS.cjs → chunk-OQH5ALTQ.cjs} +1 -1
- package/dist/chunks/{chunk-5HWD3B3N.cjs → chunk-PCEPFPJO.cjs} +5 -5
- package/dist/chunks/{chunk-3DHMW4DB.mjs → chunk-SWK2ITXO.mjs} +7 -7
- package/dist/chunks/{chunk-PATHHDWE.mjs → chunk-ZGY6CLVQ.mjs} +1 -1
- package/dist/chunks/chunk-ZZK2JEUF.mjs +1 -0
- package/dist/chunks/cli-handler-IU5ATLSM.cjs +1 -0
- package/dist/chunks/cli-handler-VKJJ4B6G.mjs +1 -0
- package/dist/chunks/{config-FTGKCGYZ.mjs → config-FVZNV76C.mjs} +1 -1
- package/dist/chunks/config-QMFC2VIL.cjs +1 -0
- package/dist/chunks/interfaces-CGLEY6OS.cjs +1 -0
- package/dist/chunks/interfaces-HUTPEB67.mjs +1 -0
- package/dist/chunks/{loader-6HBCWO6Y.mjs → loader-5EYZQR7W.mjs} +1 -1
- package/dist/chunks/loader-63RVAVIL.cjs +1 -0
- package/dist/chunks/{types-R3VOD4XE.cjs → types-NFMF7IZL.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.mjs +1 -1
- package/package.json +7 -7
- package/dist/chunks/bootstrap-GGS3N5CF.cjs +0 -1
- package/dist/chunks/bootstrap-MZQICOGZ.mjs +0 -1
- package/dist/chunks/cache-3R3ORBTY.cjs +0 -1
- package/dist/chunks/cache-76CBF3LU.mjs +0 -1
- package/dist/chunks/chunk-D7S7ARXV.mjs +0 -8
- package/dist/chunks/chunk-ITV7SWGU.cjs +0 -8
- package/dist/chunks/chunk-NHXAYBZH.mjs +0 -1
- package/dist/chunks/chunk-Z3YEK7DD.cjs +0 -1
- package/dist/chunks/cli-handler-6XB6B5DV.mjs +0 -1
- package/dist/chunks/cli-handler-IU3YUTOU.cjs +0 -1
- package/dist/chunks/config-ZVDYJ7TW.cjs +0 -1
- package/dist/chunks/interfaces-6ZCF5T55.cjs +0 -1
- package/dist/chunks/interfaces-TXNKX4HT.mjs +0 -1
- package/dist/chunks/loader-3KX33KJQ.cjs +0 -1
- /package/dist/chunks/{chunk-M2YU5LAI.cjs → chunk-ISDIC2R6.cjs} +0 -0
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@ English | [中文](./README.md)
|
|
|
6
6
|
|
|
7
7
|
## Version
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
9
|
+
v0.3.36
|
|
10
10
|
## Introduction
|
|
11
11
|
|
|
12
12
|
`@easbot/acp` is the **ACP adapter layer** (v0.1, split from `@easbot/agent`'s `adapter/` submodule) of the EASBot ecosystem. Built on top of [`@agentclientprotocol/sdk`](https://github.com/agentclientprotocol/typescript-sdk), it implements the server / client communication layer of the ACP protocol with multi-channel connections, JSON-RPC routing, configuration management, cache management, and a standalone CLI entry point.
|
|
@@ -27,7 +27,7 @@ v0.3.32
|
|
|
27
27
|
- **Error namespace**: `AcpError` (built on `NamedError.create` + ADR 0102 Phase 2.1 business feedback channel)
|
|
28
28
|
- **Standalone CLI**: `easbot-acp <command>` (init / start / status / doctor / config)
|
|
29
29
|
- **host ↔ package decoupling**: aligned with note / memory / codebase / skills `setGlobalAdapter / setInstanceAdapter` interfaces
|
|
30
|
-
- **Reuses existing business modules**: server / client / connection / event
|
|
30
|
+
- **Reuses existing business modules**: server / client / connection / event migrated from agent package
|
|
31
31
|
|
|
32
32
|
## Install
|
|
33
33
|
|
|
@@ -109,10 +109,33 @@ import {
|
|
|
109
109
|
getXdgData,
|
|
110
110
|
getWorktree,
|
|
111
111
|
getProjectDirectory,
|
|
112
|
+
// Gateway URL injection (2026-10-29)
|
|
113
|
+
setGatewayUrlAdapter,
|
|
114
|
+
resetGatewayUrlAdapter,
|
|
115
|
+
getGatewayUrlAdapter,
|
|
116
|
+
type GatewayUrlAdapter,
|
|
117
|
+
} from '@easbot/acp';
|
|
118
|
+
|
|
119
|
+
// Gateway auto-registration (2026-10-29, migrated from the agent CLI)
|
|
120
|
+
import {
|
|
121
|
+
getAgentAddress,
|
|
122
|
+
registerToGateway,
|
|
123
|
+
deregisterFromGateway,
|
|
124
|
+
hasRegistrationSession,
|
|
112
125
|
} from '@easbot/acp';
|
|
113
126
|
|
|
114
127
|
// Business modules (migrated from agent package)
|
|
115
128
|
import { EasBotAgent, EasbotAdapter, ChannelType, AgentStatus } from '@easbot/acp';
|
|
129
|
+
|
|
130
|
+
// Server runtime config (three-tier priority DEFAULT < env < explicit, ADR 0135)
|
|
131
|
+
import {
|
|
132
|
+
loadACPServerConfig,
|
|
133
|
+
loadACPServerConfigWithEnv,
|
|
134
|
+
applyEnvironmentOverrides,
|
|
135
|
+
loadConfigFromEnv,
|
|
136
|
+
validateEnvironmentConfig,
|
|
137
|
+
getConfigDocumentation,
|
|
138
|
+
} from '@easbot/acp';
|
|
116
139
|
```
|
|
117
140
|
|
|
118
141
|
## Quick start
|
|
@@ -191,6 +214,42 @@ Supports:
|
|
|
191
214
|
- **Deep merge + schema defaults** (`ConfigFileParse.merge(partials, ACPInfoACPConfigSchema)`)
|
|
192
215
|
- **State.holder caching** (bucketed per workspace + `AcpCache.resetState()` / `clearConfigCache()`)
|
|
193
216
|
|
|
217
|
+
### 3.1 Server runtime config: three-tier priority
|
|
218
|
+
|
|
219
|
+
`startACPServer()` resolves its config with a **DEFAULT < environment variable < explicit config**
|
|
220
|
+
three-tier priority (ADR [0135](../../docs/decisions/0135-acp-server-config-priority-and-error-semantics.md)):
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
DEFAULT_ACP_SERVER_CONFIG ← EAS_ACP_* env vars ← explicit config argument
|
|
224
|
+
lowest middle highest
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
| Environment variable | Overridden field | Accepted values |
|
|
228
|
+
| ----------------------------- | ------------------- | ------------------------------ |
|
|
229
|
+
| `EAS_ACP_CHANNEL` | `channel` | `stdio` / `http` / `websocket` |
|
|
230
|
+
| `EAS_ACP_PORT` | `port` | 1-65535 |
|
|
231
|
+
| `EAS_ACP_HOSTNAME` | `hostname` | non-empty string |
|
|
232
|
+
| `EAS_ACP_TIMEOUT` | `timeout` | positive integer (ms) |
|
|
233
|
+
| `EAS_ACP_HISTORY_SCOPE` | `historyScope` | enum value |
|
|
234
|
+
| `EAS_ACP_HISTORY_WINDOW_SIZE` | `historyWindowSize` | positive integer |
|
|
235
|
+
| `EAS_ACP_DEGRADE_POLICY` | `degradePolicy` | enum value |
|
|
236
|
+
|
|
237
|
+
Key points:
|
|
238
|
+
|
|
239
|
+
- **Env vars are not dead config** — before v0.3.32, `loadACPServerConfig` filled `DEFAULT`
|
|
240
|
+
first, so env vars were always shadowed. Fixed by `loadACPServerConfigWithEnv()` (ADR 0135).
|
|
241
|
+
- **Invalid env values are ignored, not fatal** — the env parsing layer silently skips them
|
|
242
|
+
(falling back to DEFAULT); an invalid **explicit config** still throws `InvalidArgumentError`
|
|
243
|
+
(validation is not bypassed).
|
|
244
|
+
- Programmatic entry point: `import { loadACPServerConfigWithEnv } from '@easbot/acp'`.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { loadACPServerConfigWithEnv } from '@easbot/acp';
|
|
248
|
+
|
|
249
|
+
const cfg = loadACPServerConfigWithEnv({ channel: 'websocket' });
|
|
250
|
+
// cfg.port ← EAS_ACP_PORT (when valid) → otherwise DEFAULT's 3000
|
|
251
|
+
```
|
|
252
|
+
|
|
194
253
|
### 4. L2 cache: `AcpCache` namespace
|
|
195
254
|
|
|
196
255
|
ACP subsystem owns an independent L2 config file `<workspaceDir>/.easbot/acp.json` (**does not conflict with** the global `easbot.json`). `AcpCache` namespace provides centralized in-memory caching (State.holder + fallback), same source as `NoteCache`.
|
|
@@ -352,6 +411,79 @@ setInstanceAdapter({
|
|
|
352
411
|
});
|
|
353
412
|
```
|
|
354
413
|
|
|
414
|
+
**Gateway URL injection** (new in 2026-10-29):
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
import { setGatewayUrlAdapter } from '@easbot/acp';
|
|
418
|
+
|
|
419
|
+
// Host resolves the Gateway URL and injects it
|
|
420
|
+
// (agent CLI reads gateway.json; standalone CLI reads acp.json)
|
|
421
|
+
setGatewayUrlAdapter({ url: 'ws://localhost:8080/', autoRegister: true });
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### 8. ACP → Gateway auto-registration (2026-10-29)
|
|
425
|
+
|
|
426
|
+
After the ACP Server starts it **auto-registers** with the Gateway, so other Gateway nodes can discover this Agent.
|
|
427
|
+
|
|
428
|
+
| Item | Description |
|
|
429
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------ |
|
|
430
|
+
| Trigger | Inside `EasbotAdapter.ensureACPService()` (once the server is up and the listen address is known) |
|
|
431
|
+
| Covered CLIs | `easbot acp start` (agent CLI) + `easbot-acp start` (standalone CLI) — **identical behaviour** |
|
|
432
|
+
| URL source | agent CLI → `gateway.json` (single source of truth); standalone CLI → `acp.json`'s `client.gatewayUrl` |
|
|
433
|
+
| Registered address | WebSocket channel automatically gets the `/acp` path (matches the ACP server's real endpoint) |
|
|
434
|
+
| Agent identity | `server.agentId` (recommended, stable); falls back to a random `ag_xxx` id when absent |
|
|
435
|
+
| Cycle task | Every 60s: **not registered → retry registration**; **registered → send `agent_heartbeat`** |
|
|
436
|
+
| Deregistration | Inside `EasbotAdapter.destroy()` (graceful shutdown) |
|
|
437
|
+
|
|
438
|
+
**Gateway is an optional dependency**: the ACP server listens on its own HTTP/WebSocket port, so
|
|
439
|
+
agent-clients connect directly. With no Gateway URL configured it **never connects to the Gateway**
|
|
440
|
+
(pure standalone mode, zero log noise); when configured but unreachable, registration failure is
|
|
441
|
+
downgraded to DEBUG level (`log.errorDegradable`) and never affects the ACP service.
|
|
442
|
+
|
|
443
|
+
**Agent identity (`server.agentId`)**: it is this ACP process's **unique identity** on the Gateway.
|
|
444
|
+
Configure it explicitly:
|
|
445
|
+
|
|
446
|
+
```json
|
|
447
|
+
{
|
|
448
|
+
"server": {
|
|
449
|
+
"agentId": "xiaomo",
|
|
450
|
+
"name": "小莫"
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
When absent it falls back to a random id (`ag_xxx`) generated by `Identifier.ascending('agent')` —
|
|
456
|
+
**different on every startup**, which makes stale records pile up on the Gateway.
|
|
457
|
+
|
|
458
|
+
**Two heartbeat layers, separate responsibilities (no conflict)**:
|
|
459
|
+
|
|
460
|
+
| Layer | Frame | Purpose |
|
|
461
|
+
| ------------------------ | ----------------- | -------------------------------------------------------------------------------------- |
|
|
462
|
+
| `GatewayClient` internal | `ping` / `pong` | Keeps the **WebSocket connection** alive (cross-cycle backoff reconnect) |
|
|
463
|
+
| ACP cycle task | `agent_heartbeat` | Keeps the **Agent state on the Gateway registry** (`lastHeartbeat` / `status=healthy`) |
|
|
464
|
+
|
|
465
|
+
**Retry strategy**: the `retry()` helper is deliberately **not** used — its backoff only lives inside
|
|
466
|
+
a single call and is not reused across cycles (`packages/utils/src/gateway/gateway-client.ts` already
|
|
467
|
+
hit this pitfall, see the comment there). Worse: without a follow-up task, a failed registration is
|
|
468
|
+
never retried, and since the WS stays `connected` no further `connected` event fires — the ACP agent
|
|
469
|
+
would stay invisible to the Gateway forever. Instead a **single cycle task** (60s) is used: a failed
|
|
470
|
+
registration is retried on the next cycle (natural cross-cycle backoff), and a disconnected client is
|
|
471
|
+
simply skipped (the connection layer handles backoff reconnect on its own).
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import { getAgentAddress, registerToGateway, deregisterFromGateway } from '@easbot/acp';
|
|
475
|
+
|
|
476
|
+
// Manual use (rarely needed — ensureACPService already wires it up)
|
|
477
|
+
const address = getAgentAddress(serverConfig); // 'ws://localhost:3000/acp'
|
|
478
|
+
await registerToGateway(serverConfig); // downgraded on failure, never throws
|
|
479
|
+
await deregisterFromGateway(); // idempotent
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**Dependency boundary**: the acp package does **not** depend on `@easbot/gateway` (that would drag
|
|
483
|
+
`gateway → llm → local-model-sdk`'s heavy dependencies into acp). The Gateway URL is **injected by the
|
|
484
|
+
host** (`setGatewayUrlAdapter`), following this package's existing host ↔ package decoupling pattern
|
|
485
|
+
(ADR 0066).
|
|
486
|
+
|
|
355
487
|
## CLI commands
|
|
356
488
|
|
|
357
489
|
5 sub-commands (v0.1 scope):
|
|
@@ -446,8 +578,6 @@ $ easbot acp start --channel http --port 3000
|
|
|
446
578
|
│ ├─ client/ (acp-client / stdio / http / ws subscriber) │
|
|
447
579
|
│ ├─ connection/ (registry / router / types — types is a re-export layer; source of truth in @easbot/utils) │
|
|
448
580
|
│ ├─ event/ (acp-event-bridge) │
|
|
449
|
-
│ ├─ performance/ (performance-monitor / streaming) │
|
|
450
|
-
│ ├─ error/ (error-handler / timeout-manager) │
|
|
451
581
|
│ ├─ types/ (adapter / channel / error / event) │
|
|
452
582
|
│ ├─ bootstrap/ (EasbotAdapter) │
|
|
453
583
|
│ └─ easbot-agent.ts (EasBotAgent instance) │
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## 版本
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
9
|
+
v0.3.36
|
|
10
10
|
## 简介
|
|
11
11
|
|
|
12
12
|
`@easbot/acp` 是 EASBot 生态的 **ACP 适配层**(v0.1,从 `@easbot/agent` 的 `adapter/` 子模块拆分独立)。基于 [`@agentclientprotocol/sdk`](https://github.com/agentclientprotocol/typescript-sdk),实现 ACP 协议的 server / client 通信层,提供多通道连接、JSON-RPC 路由、配置管理、缓存管理以及独立 CLI 入口。
|
|
@@ -28,7 +28,7 @@ v0.3.32
|
|
|
28
28
|
- **i18n 国际化**:`t()` / `I18n` / `registerI18nResources`(zh-CN / en-US;与 note / gateway 完全同源)
|
|
29
29
|
- **独立 CLI 入口**:`easbot-acp <command>`(init / start / status / doctor / config)
|
|
30
30
|
- **host ↔ 包解耦**:与 note / memory / codebase / skills 完全对齐的 `setGlobalAdapter / setInstanceAdapter` 接口
|
|
31
|
-
- **复用现有业务模块**:server / client / connection / event
|
|
31
|
+
- **复用现有业务模块**:server / client / connection / event 模块从 agent 包迁移而来
|
|
32
32
|
|
|
33
33
|
## 安装
|
|
34
34
|
|
|
@@ -122,10 +122,33 @@ import {
|
|
|
122
122
|
getXdgData,
|
|
123
123
|
getWorktree,
|
|
124
124
|
getProjectDirectory,
|
|
125
|
+
// Gateway 地址注入(2026-10-29)
|
|
126
|
+
setGatewayUrlAdapter,
|
|
127
|
+
resetGatewayUrlAdapter,
|
|
128
|
+
getGatewayUrlAdapter,
|
|
129
|
+
type GatewayUrlAdapter,
|
|
130
|
+
} from '@easbot/acp';
|
|
131
|
+
|
|
132
|
+
// Gateway 自动注册(2026-10-29,从 agent CLI 下沉)
|
|
133
|
+
import {
|
|
134
|
+
getAgentAddress,
|
|
135
|
+
registerToGateway,
|
|
136
|
+
deregisterFromGateway,
|
|
137
|
+
hasRegistrationSession,
|
|
125
138
|
} from '@easbot/acp';
|
|
126
139
|
|
|
127
140
|
// 业务模块(来自 agent 包拆分)
|
|
128
141
|
import { EasBotAgent, EasbotAdapter, ChannelType, AgentStatus } from '@easbot/acp';
|
|
142
|
+
|
|
143
|
+
// Server 运行时配置(三级优先级 DEFAULT < env < 显式,ADR 0135)
|
|
144
|
+
import {
|
|
145
|
+
loadACPServerConfig,
|
|
146
|
+
loadACPServerConfigWithEnv,
|
|
147
|
+
applyEnvironmentOverrides,
|
|
148
|
+
loadConfigFromEnv,
|
|
149
|
+
validateEnvironmentConfig,
|
|
150
|
+
getConfigDocumentation,
|
|
151
|
+
} from '@easbot/acp';
|
|
129
152
|
```
|
|
130
153
|
|
|
131
154
|
## 快速上手
|
|
@@ -202,6 +225,41 @@ acp 配置按优先级**从低到高**叠加(后者覆盖前者,深度合并
|
|
|
202
225
|
- **深度合并 + schema 默认值**(`ConfigFileParse.merge(partials, ACPInfoACPConfigSchema)`)
|
|
203
226
|
- **State.holder 缓存**(按 workspace 分桶 + `AcpCache.resetState()` / `clearConfigCache()`)
|
|
204
227
|
|
|
228
|
+
### 3.1 Server 运行时配置:三级优先级
|
|
229
|
+
|
|
230
|
+
`startACPServer()` 的配置解析按 **DEFAULT < 环境变量 < 显式 config** 三级优先级叠加
|
|
231
|
+
(ADR [0135](../../docs/decisions/0135-acp-server-config-priority-and-error-semantics.md)):
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
DEFAULT_ACP_SERVER_CONFIG ← EAS_ACP_* 环境变量 ← 显式 config 参数
|
|
235
|
+
最低优先级 中 最高
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
| 环境变量 | 覆盖的 config 字段 | 备注 |
|
|
239
|
+
| ----------------------------- | ------------------- | ------------------------------ |
|
|
240
|
+
| `EAS_ACP_CHANNEL` | `channel` | `stdio` / `http` / `websocket` |
|
|
241
|
+
| `EAS_ACP_PORT` | `port` | 1-65535 |
|
|
242
|
+
| `EAS_ACP_HOSTNAME` | `hostname` | 非空字符串 |
|
|
243
|
+
| `EAS_ACP_TIMEOUT` | `timeout` | 正整数(毫秒) |
|
|
244
|
+
| `EAS_ACP_HISTORY_SCOPE` | `historyScope` | 枚举值 |
|
|
245
|
+
| `EAS_ACP_HISTORY_WINDOW_SIZE` | `historyWindowSize` | 正整数 |
|
|
246
|
+
| `EAS_ACP_DEGRADE_POLICY` | `degradePolicy` | 枚举值 |
|
|
247
|
+
|
|
248
|
+
要点:
|
|
249
|
+
|
|
250
|
+
- **环境变量不是「死配置」** —— v0.3.32 之前 `loadACPServerConfig` 先填满 DEFAULT,
|
|
251
|
+
导致 env 永远被遮蔽;现已由 `loadACPServerConfigWithEnv()` 修正(ADR 0135)。
|
|
252
|
+
- **非法值被忽略而非报错** —— env 解析层对非法值静默跳过(回落 DEFAULT);
|
|
253
|
+
但**显式 config** 的非法值仍抛 `InvalidArgumentError`(校验不被绕过)。
|
|
254
|
+
- 编程式入口:`import { loadACPServerConfigWithEnv } from '@easbot/acp'`。
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { loadACPServerConfigWithEnv } from '@easbot/acp';
|
|
258
|
+
|
|
259
|
+
const cfg = loadACPServerConfigWithEnv({ channel: 'websocket' });
|
|
260
|
+
// cfg.port ← env 的 EAS_ACP_PORT(若合法)→ 否则 DEFAULT 的 3000
|
|
261
|
+
```
|
|
262
|
+
|
|
205
263
|
### 4. L2 缓存:AcpCache 命名空间
|
|
206
264
|
|
|
207
265
|
acp 子系统拥有独立的 L2 配置文件 `<workspaceDir>/.easbot/acp.json`(**不与**全局 `easbot.json` 冲突)。`AcpCache` 命名空间提供集中化的内存缓存(State.holder + 兼容降级),与 `NoteCache` 完全同源。
|
|
@@ -390,6 +448,75 @@ setInstanceAdapter({
|
|
|
390
448
|
});
|
|
391
449
|
```
|
|
392
450
|
|
|
451
|
+
**Gateway 地址注入**(2026-10-29 新增):
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
import { setGatewayUrlAdapter } from '@easbot/acp';
|
|
455
|
+
|
|
456
|
+
// 宿主解析出 Gateway 地址后注入(agent CLI 读 gateway.json;独立 CLI 读 acp.json)
|
|
457
|
+
setGatewayUrlAdapter({ url: 'ws://localhost:8080/', autoRegister: true });
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### 8. ACP → Gateway 自动注册(2026-10-29)
|
|
461
|
+
|
|
462
|
+
ACP Server 启动后会**自动注册**到 Gateway,让其他 Gateway 节点能发现本 Agent。
|
|
463
|
+
|
|
464
|
+
| 项 | 说明 |
|
|
465
|
+
| ---------- | -------------------------------------------------------------------------------------- |
|
|
466
|
+
| 注册时机 | `EasbotAdapter.ensureACPService()` 内(server 起好、监听地址确定的那一刻) |
|
|
467
|
+
| 覆盖的入口 | `easbot acp start`(agent CLI)+ `easbot-acp start`(独立 CLI)—— **两条路径行为一致** |
|
|
468
|
+
| 地址来源 | agent CLI → `gateway.json`(唯一真源);独立 CLI → `acp.json` 的 `client.gatewayUrl` |
|
|
469
|
+
| 注册地址 | WebSocket 通道自动补 `/acp` 路径(与 ACP server 实际监听端点一致) |
|
|
470
|
+
| Agent 身份 | `server.agentId`(推荐,稳定不变);缺省时回退为随机 id `ag_xxx` |
|
|
471
|
+
| 周期任务 | 每 60s 一次:**未注册 → 重试注册**;**已注册 → 发 `agent_heartbeat`** |
|
|
472
|
+
| 注销 | `EasbotAdapter.destroy()` 内(优雅退出时) |
|
|
473
|
+
|
|
474
|
+
**Gateway 是可选依赖**:ACP server 独立监听 HTTP/WebSocket 端口,agent-client 直连即可交互。
|
|
475
|
+
未配置 Gateway 地址时**完全不连 Gateway**(纯独立工作,零日志噪音);
|
|
476
|
+
配置了但连不上时,注册失败只降级为 DEBUG 级日志(`log.errorDegradable`),不影响 ACP 服务。
|
|
477
|
+
|
|
478
|
+
**Agent 身份(`server.agentId`)**:
|
|
479
|
+
|
|
480
|
+
`server.agentId` 是本 ACP 进程在 Gateway 上的**唯一身份**。建议显式配置:
|
|
481
|
+
|
|
482
|
+
```json
|
|
483
|
+
{
|
|
484
|
+
"server": {
|
|
485
|
+
"agentId": "xiaomo",
|
|
486
|
+
"name": "小莫"
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
不配置时回退为 `Identifier.ascending('agent')` 生成的随机 id(`ag_xxx`)——
|
|
492
|
+
**每次启动都不同**,会导致 Gateway 上同一条 ACP 记录不断堆积(旧记录不会自动消失)。
|
|
493
|
+
|
|
494
|
+
**两层心跳职责分离(不冲突)**:
|
|
495
|
+
|
|
496
|
+
| 层 | 帧 | 作用 |
|
|
497
|
+
| -------------------- | ----------------- | ------------------------------------------------------------------------------------ |
|
|
498
|
+
| `GatewayClient` 内部 | `ping` / `pong` | 维持 **WebSocket 连接**(断连时跨周期退避重连) |
|
|
499
|
+
| ACP 周期任务 | `agent_heartbeat` | 维持 **Gateway registry 上的 Agent 状态**(刷新 `lastHeartbeat` / `status=healthy`) |
|
|
500
|
+
|
|
501
|
+
**重试策略**:不使用 `retry()` 工具 —— 它的退避只在单次调用内有效,跨周期不复用
|
|
502
|
+
(`packages/utils/src/gateway/gateway-client.ts` 已踩过这个坑,见该文件注释),
|
|
503
|
+
且注册失败后若无后续任务,WS 一直 connected 时 ACP 将永远无法被 Gateway 发现。
|
|
504
|
+
改为**单一周期任务**(60s):注册失败 → 下一周期自动重试,天然跨周期退避;
|
|
505
|
+
未连接 → 直接跳过(连接层自行负责退避重连)。
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
import { getAgentAddress, registerToGateway, deregisterFromGateway } from '@easbot/acp';
|
|
509
|
+
|
|
510
|
+
// 手动使用(一般无需直接调用 —— ensureACPService 已自动接入)
|
|
511
|
+
const address = getAgentAddress(serverConfig); // 'ws://localhost:3000/acp'
|
|
512
|
+
await registerToGateway(serverConfig); // 连不上则降级,不抛错
|
|
513
|
+
await deregisterFromGateway(); // 幂等
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
**依赖边界**:acp 包**不依赖** `@easbot/gateway`(否则会把 `gateway → llm → local-model-sdk`
|
|
517
|
+
的重依赖拖进 acp)。Gateway 地址由**宿主注入**(`setGatewayUrlAdapter`),沿用本包既有的
|
|
518
|
+
host ↔ 包解耦范式(ADR 0066)。
|
|
519
|
+
|
|
393
520
|
## CLI 命令一览
|
|
394
521
|
|
|
395
522
|
5 个子命令(v0.1 落地范围):
|
|
@@ -483,8 +610,6 @@ $ easbot acp start --channel http --port 3000
|
|
|
483
610
|
│ ├─ client/ (acp-client / stdio / http / ws subscriber) │
|
|
484
611
|
│ ├─ connection/ (registry / router / types — types 为透出层,真源在 @easbot/utils) │
|
|
485
612
|
│ ├─ event/ (acp-event-bridge) │
|
|
486
|
-
│ ├─ performance/ (performance-monitor / streaming) │
|
|
487
|
-
│ ├─ error/ (error-handler / timeout-manager) │
|
|
488
613
|
│ ├─ types/ (adapter / channel / event — 只放纯类型,不含 error) │
|
|
489
614
|
│ ├─ bootstrap/ (EasbotAdapter) │
|
|
490
615
|
│ └─ easbot-agent.ts (EasBotAgent 实例) │
|
|
@@ -545,20 +670,16 @@ packages/acp/
|
|
|
545
670
|
│ ├── xdg-bootstrap.ts # XDG_*_HOME → tmpdir 隔离
|
|
546
671
|
│ └── cli-e2e.test.ts # 真 subprocess 端到端(跨模块)
|
|
547
672
|
└── src/**/__tests__/ # 与代码同包(与 code 一个包 + __tests__ 放里)
|
|
548
|
-
├──
|
|
549
|
-
├──
|
|
550
|
-
├──
|
|
551
|
-
├──
|
|
552
|
-
├──
|
|
553
|
-
├──
|
|
554
|
-
├──
|
|
555
|
-
├──
|
|
556
|
-
├──
|
|
557
|
-
|
|
558
|
-
├── performance/__tests__/performance-monitor.test.ts
|
|
559
|
-
├── performance/__tests__/streaming.test.ts
|
|
560
|
-
└── __tests__/interfaces.test.ts
|
|
561
|
-
└── __tests__/cli-handler.test.ts
|
|
673
|
+
├── __tests__/ # 单文件模块(interfaces / errors / lifecycle / cli-handler)
|
|
674
|
+
├── acp/__tests__/ # ACPService 协议实现
|
|
675
|
+
├── bootstrap/__tests__/ # AdapterBootstrap + Gateway 注册
|
|
676
|
+
├── cache/__tests__/ # AcpCache namespace
|
|
677
|
+
├── config/__tests__/ # 配置加载 + Zod schema
|
|
678
|
+
├── connection/__tests__/ # 连接注册表 + 会话路由
|
|
679
|
+
├── event/__tests__/ # AcpEventBridge(分派 / 内容块 / 生命周期)
|
|
680
|
+
├── i18n/__tests__/ # t() 翻译器
|
|
681
|
+
├── server/__tests__/ # HTTP / WebSocket server + RPC handler + 配置
|
|
682
|
+
└── terminal/__tests__/ # format-acp 终端渲染
|
|
562
683
|
```
|
|
563
684
|
|
|
564
685
|
**原则**(剑哥"测试用例和代码一个包"):
|
|
@@ -570,44 +691,72 @@ packages/acp/
|
|
|
570
691
|
|
|
571
692
|
### 测试统计
|
|
572
693
|
|
|
573
|
-
`pnpm --filter @easbot/acp test:run
|
|
574
|
-
|
|
575
|
-
| 文件
|
|
576
|
-
|
|
|
577
|
-
| `tests/cli-e2e.test.ts`
|
|
578
|
-
| `src/__tests__/
|
|
579
|
-
| `src/
|
|
580
|
-
| `src/
|
|
581
|
-
| `src/
|
|
582
|
-
| `src/__tests__/
|
|
583
|
-
| `src/
|
|
584
|
-
| `src/
|
|
585
|
-
| `src/
|
|
586
|
-
| `src/
|
|
587
|
-
|
|
|
588
|
-
|
|
|
694
|
+
`pnpm --filter @easbot/acp test:run` → **31 文件 / 690 passed / 0 skipped**(全绿)。
|
|
695
|
+
|
|
696
|
+
| 文件 | 用例 | 描述 |
|
|
697
|
+
| ------------------------------------------------------ | ---- | --------------------------------------------------- |
|
|
698
|
+
| `tests/cli-e2e.test.ts` | 31 | 真 subprocess 端到端 5 cmd(含 start 长驻阻塞路径) |
|
|
699
|
+
| `src/server/__tests__/config.test.ts` | 59 | 三级优先级(DEFAULT < env < 显式)+ env 解析 |
|
|
700
|
+
| `src/event/__tests__/acp-event-bridge-content.test.ts` | 52 | 内容块渲染 + 元数据 + agent 过滤 + 异常出口 |
|
|
701
|
+
| `src/connection/__tests__/registry.test.ts` | 37 | 连接注册表(生命周期 + 引用计数) |
|
|
702
|
+
| `src/__tests__/errors.test.ts` | 34 | AcpError namespace 8 个错误类 + 工厂 + 白名单 |
|
|
703
|
+
| `src/terminal/__tests__/format-acp.test.ts` | 32 | 终端渲染格式 |
|
|
704
|
+
| `src/acp/__tests__/acp-service.test.ts` | 31 | 会话协议(新建 / 加载 / 分叉 / 列表 / 配置项) |
|
|
705
|
+
| `src/config/__tests__/types.test.ts` | 31 | Zod schema 校验(Stdio / Http / WS / server) |
|
|
706
|
+
| `src/acp/__tests__/acp-service-prompt.test.ts` | 30 | prompt 消息投递 + slash command 分派 + cancel |
|
|
707
|
+
| `src/connection/__tests__/router.test.ts` | 30 | 会话路由(匹配 / 优先级 / 回落) |
|
|
708
|
+
| `src/config/__tests__/loader.test.ts` | 29 | 四层合并 + JSONC + env 替换 + 便捷访问 |
|
|
709
|
+
| `src/__tests__/cli-handler.test.ts` | 27 | 5 cmd dispatch + COMMANDS_HELP + 错误路径 |
|
|
710
|
+
| `src/i18n/__tests__/translator.test.ts` | 23 | t() 翻译 + vars 插值 + locale 优先级 4 级 |
|
|
711
|
+
| `src/__tests__/interfaces.test.ts` | 21 | IGlobal / IInstance / SDK 注入 + 便捷访问器 |
|
|
712
|
+
| `src/bootstrap/__tests__/gateway-registration.test.ts` | 21 | Gateway 注册地址口径 |
|
|
713
|
+
| `src/server/__tests__/acp-rpc-handler.test.ts` | 20 | JSON-RPC 方法分派 + 错误信封 |
|
|
714
|
+
| `src/acp/__tests__/session.test.ts` | 20 | AdapterSessionManager 生命周期 |
|
|
715
|
+
| `src/cache/__tests__/cache.test.ts` | 18 | AcpCache namespace 全 API |
|
|
716
|
+
| `src/server/__tests__/acp-server.test.ts` | 17 | 通道派发 + env 优先级 |
|
|
717
|
+
| `src/__tests__/lifecycle.test.ts` | 16 | LifecycleManager 状态机 |
|
|
718
|
+
| `src/__tests__/easbot-agent.test.ts` | 15 | EasBotAgent 适配层 |
|
|
719
|
+
| `src/server/__tests__/http-server.test.ts` | 14 | HTTP 路由层(400 / 202 / 406 / 头) |
|
|
720
|
+
| `src/server/__tests__/websocket-server-ws.test.ts` | 12 | **真实 WebSocket 客户端**走 socket 层 |
|
|
721
|
+
| `src/bootstrap/__tests__/bootstrap.test.ts` | 10 | AdapterBootstrap 复用 + channel 切换拒绝 |
|
|
722
|
+
| `src/server/__tests__/http-server-sse.test.ts` | 10 | SSE 握手 / 广播 / 心跳超时 / 断开清理 |
|
|
723
|
+
| `src/server/__tests__/websocket-server.test.ts` | 10 | WS HTTP 端点(与 HTTP 端点语义一致) |
|
|
724
|
+
| `src/server/__tests__/endpoint-url.test.ts` | 10 | 端点 URL 派生 |
|
|
725
|
+
| `src/event/__tests__/acp-event-bridge-events.test.ts` | 8 | 事件 → handler 分派映射 |
|
|
726
|
+
| `src/event/__tests__/acp-event-bridge.test.ts` | 7 | 事件流拉取 / 中断 |
|
|
727
|
+
| `src/__tests__/cli-handler-server-config.test.ts` | 6 | CLI server 配置子命令 |
|
|
589
728
|
|
|
590
729
|
### 核心模块覆盖率
|
|
591
730
|
|
|
592
|
-
`pnpm --filter @easbot/acp test:coverage
|
|
593
|
-
|
|
594
|
-
| 模块
|
|
595
|
-
|
|
|
596
|
-
| `src/
|
|
597
|
-
| `src/
|
|
598
|
-
| `src/
|
|
599
|
-
| `src/
|
|
600
|
-
| `src/
|
|
601
|
-
| `src/i18n/
|
|
602
|
-
| `src/
|
|
603
|
-
| `src/
|
|
604
|
-
| `src/
|
|
605
|
-
| `src/
|
|
606
|
-
| `src/
|
|
607
|
-
| `src/
|
|
608
|
-
|
|
|
609
|
-
|
|
610
|
-
|
|
731
|
+
`pnpm --filter @easbot/acp test:coverage` → **77.92% stmts / 67.42% branch / 77.75% funcs / 79.24% lines**。
|
|
732
|
+
|
|
733
|
+
| 模块 | Stmts | 说明 |
|
|
734
|
+
| --------------------------------------- | -------- | ---------------------------------- |
|
|
735
|
+
| `src/errors.ts` | **100%** | 错误体系 |
|
|
736
|
+
| `src/lifecycle.ts` | **100%** | 生命周期状态机 |
|
|
737
|
+
| `src/acp/session.ts` | **100%** | 会话管理器 |
|
|
738
|
+
| `src/acp/context-mode.ts` | **100%** | 上下文模式 |
|
|
739
|
+
| `src/commands/_default-config.ts` | **100%** | init 默认配置生成器 |
|
|
740
|
+
| `src/i18n/locales/*.ts` | **100%** | 翻译资源 |
|
|
741
|
+
| `src/terminal/format-acp.ts` | **100%** | 终端渲染 |
|
|
742
|
+
| `src/server/acp-rpc-handler.ts` | **100%** | RPC 方法分派 |
|
|
743
|
+
| `src/server/acp-server.ts` | **100%** | 通道派发 |
|
|
744
|
+
| `src/server/endpoint-url.ts` | **100%** | 端点 URL 派生 |
|
|
745
|
+
| `src/server/config.ts` | **97%** | 三级优先级 + env 解析 |
|
|
746
|
+
| `src/interfaces.ts` | **97%** | host ↔ 包解耦三件套 |
|
|
747
|
+
| `src/config/normalize.ts` | **94%** | 配置归一 |
|
|
748
|
+
| `src/config/loader.ts` | **90%** | 四层合并加载 |
|
|
749
|
+
| `src/connection/router.ts` | **89%** | 会话路由 |
|
|
750
|
+
| `src/server/http-server.ts` | **88%** | HTTP 路由 + SSE 通道 |
|
|
751
|
+
| `src/bootstrap/gateway-registration.ts` | **88%** | Gateway 注册 / 注销 |
|
|
752
|
+
| `src/cache/index.ts` | **86%** | AcpCache namespace |
|
|
753
|
+
| `src/connection/registry.ts` | **84%** | 连接注册表 |
|
|
754
|
+
| `src/i18n/translator.ts` | **83%** | t() 翻译 |
|
|
755
|
+
| `src/acp/acp-service.ts` | **78%** | ACP 协议实现 |
|
|
756
|
+
| `src/cli-handler.ts` | **75%** | 5 cmd dispatch + renderBanner/Help |
|
|
757
|
+
| `src/event/acp-event-bridge.ts` | **71%** | 事件桥接 |
|
|
758
|
+
|
|
759
|
+
**未覆盖模块**:`src/cli.ts`(CLI 入口,仅 `cli-e2e.test.ts` 走 subprocess 间接覆盖)、`src/easbot-agent.ts`(45%,主要走 `cli-handler` 路径)、`src/bootstrap/index.ts` 的 `start` 路径(需真实 runtime)、`src/server/websocket-server.ts` 的 upgrade 握手失败分支(非法 Upgrade 头)、`src/config/change-subscriber.ts`(40%,仅注册回调未被触发)。
|
|
611
760
|
|
|
612
761
|
### 已知 Bug 待修复(acp-tests-coverage 任务发现)
|
|
613
762
|
|
|
@@ -623,6 +772,15 @@ packages/acp/
|
|
|
623
772
|
|
|
624
773
|
详见 `.easbot/knowledge/tasks/acp-tests-coverage/findings.md §10`。
|
|
625
774
|
|
|
775
|
+
### 已修复 Bug(acp-jsdoc-test-completion 任务发现)
|
|
776
|
+
|
|
777
|
+
| ID | 位置 | 现象 | 修复 |
|
|
778
|
+
| --------- | ------------------------------------------------------------ | -------------------------------------------------------- | ------------------------------------------------------------ |
|
|
779
|
+
| **Bug F** | `src/server/acp-server.ts:51` | `EAS_ACP_*` 环境变量被 `DEFAULT` 遮蔽 —— 全部 7 个死配置 | 新增 `loadACPServerConfigWithEnv` 三级优先级入口(ADR 0135) |
|
|
780
|
+
| **Bug G** | `src/server/websocket-server.ts:421` vs `http-server.ts:258` | HTTP / WS 双通道错误状态码分叉(400 vs 200) | WS 端对齐 400 + 统一 `RPCErrorCode` 常量(ADR 0135) |
|
|
781
|
+
|
|
782
|
+
详见 [`docs/decisions/0135-acp-server-config-priority-and-error-semantics.md`](../../docs/decisions/0135-acp-server-config-priority-and-error-semantics.md)。
|
|
783
|
+
|
|
626
784
|
### 后续任务(acp-cli-format-unify)
|
|
627
785
|
|
|
628
786
|
**剑哥反馈**:"你 client 的输出 human json 参考 note 和 memory 使用 `@easbot/terminal` 实现统一风格的 format"。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkIOEQ7YHD_cjs=require('./chunk-IOEQ7YHD.cjs');require('./chunk-SNWAB3QJ.cjs'),require('./chunk-OQH5ALTQ.cjs'),require('./chunk-6VF3MZ6H.cjs'),require('./chunk-663BEBE4.cjs'),require('./chunk-DX35VSAT.cjs'),require('./chunk-ISDIC2R6.cjs');Object.defineProperty(exports,"AdapterBootstrap",{enumerable:true,get:function(){return chunkIOEQ7YHD_cjs.x}});Object.defineProperty(exports,"EasbotAdapter",{enumerable:true,get:function(){return chunkIOEQ7YHD_cjs.w}});Object.defineProperty(exports,"createAdapterEnvironmentInitializationError",{enumerable:true,get:function(){return chunkIOEQ7YHD_cjs.v}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{x as AdapterBootstrap,w as EasbotAdapter,v as createAdapterEnvironmentInitializationError}from'./chunk-FDMRPUSH.mjs';import'./chunk-B3ANZALB.mjs';import'./chunk-ZGY6CLVQ.mjs';import'./chunk-FAYVTNTB.mjs';import'./chunk-ZZK2JEUF.mjs';import'./chunk-33M2R2US.mjs';import'./chunk-HQBRVVXS.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk6VF3MZ6H_cjs=require('./chunk-6VF3MZ6H.cjs');require('./chunk-663BEBE4.cjs'),require('./chunk-ISDIC2R6.cjs');Object.defineProperty(exports,"ACP_JSON_REL_PATH",{enumerable:true,get:function(){return chunk6VF3MZ6H_cjs.q}});Object.defineProperty(exports,"AcpCache",{enumerable:true,get:function(){return chunk6VF3MZ6H_cjs.r}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{q as ACP_JSON_REL_PATH,r as AcpCache}from'./chunk-FAYVTNTB.mjs';import'./chunk-ZZK2JEUF.mjs';import'./chunk-HQBRVVXS.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var utils=require('@easbot/utils');var e=null,r=null;function f(t){e=t;}function b(){e=null;}function c(){return e||{Path:utils.Global.get()}}function y(t){r=t;}function g(){r=null;}function l(){if(r)return r;let t=utils.Filesystem.normalize(process.cwd());return {directory:t,worktree:t}}var i=utils.State.holder(()=>{try{return l().directory||"__acp_sdk_global__"}catch{return "__acp_sdk_global__"}},async()=>({override:null,fallback:null}));async function m(t){let n=await i.get();n.override=t;}async function w(){let t=await i.get();t.override=null,t.fallback=null;}async function x(){let t=await i.get();if(t.override)return t.override;if(!t.fallback){let{createEasbotClient:n}=await import('@easbot/sdk');t.fallback=n();}return t.fallback}var s=null;function I(t){s=t;}function k(){s=null;}function v(){return s}function G(){return c().Path.home||utils.Global.home()}function _(){return c().Path.data||utils.Global.data()}function A(){return utils.Filesystem.normalize(l().worktree||process.cwd())}function E(){return utils.Filesystem.normalize(l().directory||process.cwd())}exports.a=f;exports.b=b;exports.c=c;exports.d=y;exports.e=g;exports.f=l;exports.g=m;exports.h=w;exports.i=x;exports.j=I;exports.k=k;exports.l=v;exports.m=G;exports.n=_;exports.o=A;exports.p=E;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk663BEBE4_cjs=require('./chunk-663BEBE4.cjs'),fs=require('fs'),utils=require('@easbot/utils'),types=require('@easbot/types'),zod=require('zod');var b=e=>e==="local"?types.ChannelType.STDIO:e,S=zod.z.object({directory:zod.z.string().default(process.cwd()),enabled:zod.z.boolean().default(true),channel:zod.z.preprocess(b,zod.z.enum(["stdio","http","websocket"])).default("websocket"),port:zod.z.number().int().min(1).max(65535).default(3e3),hostname:zod.z.hostname().default("localhost"),timeout:zod.z.number().positive().default(3e4),name:zod.z.string().optional(),agentId:zod.z.string().optional(),stdio:zod.z.object({command:zod.z.string(),args:zod.z.array(zod.z.string())}).optional(),http:zod.z.object({baseUrl:zod.z.string().url(),timeout:zod.z.number().positive().default(6e4)}).optional(),ws:zod.z.object({url:zod.z.string().url(),timeout:zod.z.number().positive().default(3e4),batchSize:zod.z.number().positive().default(10),batchInterval:zod.z.number().positive().default(50),heartbeatInterval:zod.z.number().positive().default(3e4)}).optional(),agent:zod.z.object({agent:zod.z.string().optional(),model:zod.z.object({id:zod.z.string().min(1),options:zod.z.record(zod.z.string(),zod.z.unknown()).optional()}).optional()}).optional()}).transform(e=>({...e,channel:e.channel})),w=zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["easbot","custom"]),name:zod.z.string().optional(),agentId:zod.z.string().optional(),channel:zod.z.preprocess(b,zod.z.enum(["stdio","http","websocket"])).optional(),connection:zod.z.object({stdio:zod.z.object({command:zod.z.string(),args:zod.z.array(zod.z.string())}).optional(),http:zod.z.object({baseUrl:zod.z.string().url(),timeout:zod.z.number().positive().default(6e4)}).optional(),ws:zod.z.object({url:zod.z.string().url(),timeout:zod.z.number().positive().default(3e4),batchSize:zod.z.number().positive().default(10),batchInterval:zod.z.number().positive().default(50),heartbeatInterval:zod.z.number().positive().default(3e4)}).optional()}),autoConnect:zod.z.boolean().default(false),priority:zod.z.number().int().nonnegative().default(0)}).transform(e=>{let t=e.channel;return t||(e.connection.ws?t="websocket":e.connection.http?t="http":e.connection.stdio?t="stdio":t="websocket"),{...e,channel:t}}),y=zod.z.object({clients:zod.z.array(w).min(1),defaultClientId:zod.z.string().optional()}),r=zod.z.object({server:S.optional(),clients:y.optional(),client:zod.z.object({autoRegister:zod.z.boolean().default(true),gatewayUrl:zod.z.url().optional()}).optional()});function E(e){let t=r.safeParse(e);if(t.success)return t.data;let s=r.safeParse({});return s.success?s.data:{}}function J(e){return r.parse(e)}var a=utils.Log.create({service:"acp.cache"}),L=[".easbot","acp.json"],j=new Set;function k(){try{let t=chunk663BEBE4_cjs.f().directory;if(t&&t.length>0)return t}catch{}return process.cwd()}function l(e){return utils.Filesystem.join(e,...L)}async function O(e){let t=l(e);if(j.add(utils.Filesystem.normalize(t)),!fs.existsSync(t))return {acpJson:{},exists:false,rootDir:e};try{return {acpJson:await utils.ConfigFileParse.loadFile(t),exists:!0,rootDir:e}}catch(c){return a.warn("acp.json parse failed",{configPath:t,error:utils.errorMeta(c)}),{acpJson:void 0,exists:true,rootDir:e}}}var x=utils.State.holder(()=>{try{let t=chunk663BEBE4_cjs.f().directory;return t?utils.Filesystem.normalize(t):"__acp_cache_global__"}catch{return "__acp_cache_global__"}},async()=>O(k()));exports.r=void 0;($=>{let e=false;async function t(){return x.get()}$.state=t;function s(o){x.clear(),e=false,utils.ConfigFileParse.invalidate(o??l(k()),"acp.resetState");}$.resetState=s;function c(){P||(P=utils.ConfigFileParse.onChange(o=>{j.has(o)&&(a.info("acp.json changed externally, reloading",{configPath:o}),utils.ConfigFileParse.invalidateNormalized(o,"acp.externalChange"),s(o));}));}let P;async function U(){e||(e=true,c(),a.info("AcpCache init"),await t());}$.init=U;async function V(){return (await t()).acpJson}$.getAcpJson=V;async function H(){return (await t()).exists}$.exists=H;async function M(){return (await t()).rootDir}$.getRootDir=M;async function G(o){let d=await t(),i=l(d.rootDir),g={...d.acpJson??{},...o},f=r.safeParse(g);if(!f.success)throw a.error("acp.json validation failed on write",{configPath:i,issues:f.error.issues}),new utils.NameErrors.ValidationError({message:`acp.json validation failed: ${f.error.message}`,location:i,issues:f.error.issues});let A=utils.Filesystem.dirname(i);fs.existsSync(A)||fs.mkdirSync(A,{recursive:true});try{fs.writeFileSync(i,JSON.stringify(g,null,2),"utf-8");}catch(h){throw a.error("acp.json write failed",{configPath:i,error:utils.errorMeta(h)}),h}return s(i),a.debug("acp.json written",{configPath:i}),g}$.writeAcpJson=G;async function W(){let o=await t();return l(o.rootDir)}$.getConfigPath=W;})(exports.r||(exports.r={}));Object.defineProperty(exports,"g",{enumerable:true,get:function(){return types.ACPStdioConnectionConfigSchema}});Object.defineProperty(exports,"h",{enumerable:true,get:function(){return types.ACPHttpConnectionConfigSchema}});Object.defineProperty(exports,"i",{enumerable:true,get:function(){return types.ACPWebSocketConnectionConfigSchema}});Object.defineProperty(exports,"j",{enumerable:true,get:function(){return types.ACPConnectionConfigSchema}});Object.defineProperty(exports,"k",{enumerable:true,get:function(){return types.ACPModelConfigSchema}});Object.defineProperty(exports,"l",{enumerable:true,get:function(){return types.ACPAgentRuntimeConfigSchema}});Object.defineProperty(exports,"m",{enumerable:true,get:function(){return types.ACPInfoACPServerConfigSchema}});Object.defineProperty(exports,"n",{enumerable:true,get:function(){return types.ACPInfoACPClientsConfigSchema}});Object.defineProperty(exports,"o",{enumerable:true,get:function(){return types.ACP_DEFAULT_SERVER_CONFIG}});Object.defineProperty(exports,"p",{enumerable:true,get:function(){return types.ACP_DEFAULT_CLIENT_CONFIG}});exports.a=S;exports.b=w;exports.c=y;exports.d=r;exports.e=E;exports.f=J;exports.q=L;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {f}from'./chunk-
|
|
1
|
+
import {f}from'./chunk-ZZK2JEUF.mjs';import {existsSync,mkdirSync,writeFileSync}from'fs';import {Log,State,Filesystem,ConfigFileParse,errorMeta,NameErrors}from'@easbot/utils';import {ChannelType}from'@easbot/types';export{ACPStdioConnectionConfigSchema as g,ACPHttpConnectionConfigSchema as h,ACPWebSocketConnectionConfigSchema as i,ACPConnectionConfigSchema as j,ACPModelConfigSchema as k,ACPAgentRuntimeConfigSchema as l,ACPInfoACPServerConfigSchema as m,ACPInfoACPClientsConfigSchema as n,ACP_DEFAULT_SERVER_CONFIG as o,ACP_DEFAULT_CLIENT_CONFIG as p}from'@easbot/types';import {z}from'zod';var S=e=>e==="local"?ChannelType.STDIO:e,w=z.object({directory:z.string().default(process.cwd()),enabled:z.boolean().default(true),channel:z.preprocess(S,z.enum(["stdio","http","websocket"])).default("websocket"),port:z.number().int().min(1).max(65535).default(3e3),hostname:z.hostname().default("localhost"),timeout:z.number().positive().default(3e4),name:z.string().optional(),agentId:z.string().optional(),stdio:z.object({command:z.string(),args:z.array(z.string())}).optional(),http:z.object({baseUrl:z.string().url(),timeout:z.number().positive().default(6e4)}).optional(),ws:z.object({url:z.string().url(),timeout:z.number().positive().default(3e4),batchSize:z.number().positive().default(10),batchInterval:z.number().positive().default(50),heartbeatInterval:z.number().positive().default(3e4)}).optional(),agent:z.object({agent:z.string().optional(),model:z.object({id:z.string().min(1),options:z.record(z.string(),z.unknown()).optional()}).optional()}).optional()}).transform(e=>({...e,channel:e.channel})),y=z.object({id:z.string().min(1),type:z.enum(["easbot","custom"]),name:z.string().optional(),agentId:z.string().optional(),channel:z.preprocess(S,z.enum(["stdio","http","websocket"])).optional(),connection:z.object({stdio:z.object({command:z.string(),args:z.array(z.string())}).optional(),http:z.object({baseUrl:z.string().url(),timeout:z.number().positive().default(6e4)}).optional(),ws:z.object({url:z.string().url(),timeout:z.number().positive().default(3e4),batchSize:z.number().positive().default(10),batchInterval:z.number().positive().default(50),heartbeatInterval:z.number().positive().default(3e4)}).optional()}),autoConnect:z.boolean().default(false),priority:z.number().int().nonnegative().default(0)}).transform(e=>{let t=e.channel;return t||(e.connection.ws?t="websocket":e.connection.http?t="http":e.connection.stdio?t="stdio":t="websocket"),{...e,channel:t}}),x=z.object({clients:z.array(y).min(1),defaultClientId:z.string().optional()}),r=z.object({server:w.optional(),clients:x.optional(),client:z.object({autoRegister:z.boolean().default(true),gatewayUrl:z.url().optional()}).optional()});function J(e){let t=r.safeParse(e);if(t.success)return t.data;let s=r.safeParse({});return s.success?s.data:{}}function F(e){return r.parse(e)}var a=Log.create({service:"acp.cache"}),O=[".easbot","acp.json"],k=new Set;function R(){try{let t=f().directory;if(t&&t.length>0)return t}catch{}return process.cwd()}function l(e){return Filesystem.join(e,...O)}async function U(e){let t=l(e);if(k.add(Filesystem.normalize(t)),!existsSync(t))return {acpJson:{},exists:false,rootDir:e};try{return {acpJson:await ConfigFileParse.loadFile(t),exists:!0,rootDir:e}}catch(c){return a.warn("acp.json parse failed",{configPath:t,error:errorMeta(c)}),{acpJson:void 0,exists:true,rootDir:e}}}var v=State.holder(()=>{try{let t=f().directory;return t?Filesystem.normalize(t):"__acp_cache_global__"}catch{return "__acp_cache_global__"}},async()=>U(R())),I;(q=>{let e=false;async function t(){return v.get()}q.state=t;function s(o){v.clear(),e=false,ConfigFileParse.invalidate(o??l(R()),"acp.resetState");}q.resetState=s;function c(){d||(d=ConfigFileParse.onChange(o=>{k.has(o)&&(a.info("acp.json changed externally, reloading",{configPath:o}),ConfigFileParse.invalidateNormalized(o,"acp.externalChange"),s(o));}));}let d;async function V(){e||(e=true,c(),a.info("AcpCache init"),await t());}q.init=V;async function H(){return (await t()).acpJson}q.getAcpJson=H;async function M(){return (await t()).exists}q.exists=M;async function G(){return (await t()).rootDir}q.getRootDir=G;async function W(o){let A=await t(),i=l(A.rootDir),g={...A.acpJson??{},...o},f=r.safeParse(g);if(!f.success)throw a.error("acp.json validation failed on write",{configPath:i,issues:f.error.issues}),new NameErrors.ValidationError({message:`acp.json validation failed: ${f.error.message}`,location:i,issues:f.error.issues});let h=Filesystem.dirname(i);existsSync(h)||mkdirSync(h,{recursive:true});try{writeFileSync(i,JSON.stringify(g,null,2),"utf-8");}catch(b){throw a.error("acp.json write failed",{configPath:i,error:errorMeta(b)}),b}return s(i),a.debug("acp.json written",{configPath:i}),g}q.writeAcpJson=W;async function $(){let o=await t();return l(o.rootDir)}q.getConfigPath=$;})(I||(I={}));export{w as a,y as b,x as c,r as d,J as e,F as f,O as q,I as r};
|