@cdmbase/cdecli-agent-client

中文文档
0.4.1发布于 2026/09/12MITTypeScriptES Module零依赖近 30 天下载 2288

TypeScript client for cdecli-agent (POST /v1/cdecli/exec). Ships alongside the Go agent server.

原始使用文档
文档目录8 节
  1. Install
  2. Why
  3. Layers
  4. Usage
  5. Agent chat with a skill
  6. Wire contract
  7. HTTP keep-alive
  8. Development

@cdmbase/cdecli-agent-client

npm

TypeScript client for the cdecli-agent Go HTTP server.

Ships in the same repo as the agent server (src/serve/cdecli_exec.go) so the wire protocol and client move together — every protocol change lands as one PR.

Install

yarn add @cdmbase/cdecli-agent-client
# optional: enable HTTP keep-alive on Node
yarn add undici

Why

A thin, dependency-light wrapper around the cdecli-agent wire protocol (POST /v1/cdecli/exec). Owns the sentinel parser, auth header logic, and credential-key picker so callers don't re-implement them.

Layers

CdecliAgentClient       ← transport (fetch + headers + JSON)
    │
    ├─ CdecliConnectorClient    ← cdecli connector run/install/list/actions
    ├─ CdecliAgentChatClient    ← cdecli agent --skill … --mode … -m … (native session/chat protocol)
    ├─ CdecliAgentRunnerClient  ← cdecli agent -m … run as a child cdecli via /v1/cdecli/exec
    └─ CdecliSearchClient       ← cdecli connector search …

Usage

import {
    CdecliAgentClient,
    CdecliConnectorClient,
} from '@cdmbase/cdecli-agent-client';

const transport = new CdecliAgentClient({
    endpoint: process.env.CDECLI_AGENT_ENDPOINT ?? 'https://your-cdecli-agent.example.com',
});
const connectors = new CdecliConnectorClient(transport);

const result = await connectors.runAction({
    userToken: userJwt,            // bearer for per-user $HOME isolation
    connector: 'github',
    action: 'GITHUB_LIST_ISSUES',
    params: { repo: 'owner/repo' },
    credentialId: 'fb-cred-id',    // optional vault lookup
});

if (result.successful) {
    console.log(result.data);
} else {
    console.error(result.error);
}

Agent chat with a skill

The SDK equivalent of

cdecli agent --endpoint https://cdecli-agent.cdebase.dev \
  --skill yantra-video-studio --no-tui --mode auto \
  -m "$(cat birthday-brief.txt)" > run.log

is CdecliAgentChatClient. It speaks the agent's native protocol - the same one the CLI uses when it delegates to a remote agent: POST /v1/agent/session creates a session with the skill pre-activated, then POST /v1/agent/chat streams the turn as server-sent events with the permission mode attached. There is no TUI to turn off and no child cdecli process.

import { readFile } from 'node:fs/promises';
import { CdecliAgentClient, CdecliAgentChatClient } from '@cdmbase/cdecli-agent-client';

const transport = new CdecliAgentClient({ endpoint: 'https://cdecli-agent.cdebase.dev' });
const agent = new CdecliAgentChatClient(transport);

const result = await agent.run({
    userToken: userJwt,               // --token / auth.json access token
    skill: 'yantra-video-studio',     // --skill
    permissionMode: 'auto',           // --mode auto (unattended)
    message: await readFile('birthday-brief.txt', 'utf8'), // -m
    onChunk: (text) => process.stdout.write(text),         // the streamed reply
    onStatus: (status) => console.error(`[${status}]`),
});

console.log(result.sessionId, result.text.length, result.outputs);
  • run() creates the session and sends one turn; pass sessionId to continue an existing session (createSession, chat, cancel, and closeSession are also exposed for multi-turn control).
  • One skill is activated per session, as on the CLI's delegated path. The skill must already exist on the agent (GET /v1/skills); the SDK does not push local skill folders the way the CLI does.
  • permissionMode is the --mode vocabulary: ask | edit | plan | auto | bypass (yolo = bypass). auto is what an unattended job wants.
  • onEvent receives every decoded event (delta, output, status, tool_call, tool_result, tool_input_delta, ask_user, error, done). A clarifying question the agent parks on arrives as ask_user with the decoded payload, and is stripped from the visible text; answer it with another chat() on the same session.
  • A server-side failure rejects with CdecliAgentChatError, which keeps the sessionId and the partialText streamed before the error.
  • Sessions are pinned to the pod that created them: the client replays the ingress's sticky cookie per session, so a shared transport can serve many users without pinning them all to one pod.

CdecliAgentRunnerClient.run() remains for callers that want a child cdecli agent -m … on the agent through /v1/cdecli/exec; it now also accepts permissionMode (--mode).

Wire contract

Matches src/serve/cdecli_exec.go::ExecRequest in this repo. Accepts either args (argv) or shell_command (POSIX line). Response shape is { stdout, stderr, exit_code, error? }.

Drift policy: every change to the Go ExecRequest / ExecResponse struct in src/serve/cdecli_exec.go must update src/types.ts in the same PR.

HTTP keep-alive

On Node, the default fetchImpl uses a process-wide undici.Agent (connections: 128, keepAliveTimeout: 30s) shared across all tenants. JWTs and session ids live in per-request headers, so pooling is safe.

Disable with CDECLI_AGENT_KEEPALIVE=0.

Development

cd packages/cdecli-agent-client
yarn install
yarn build
yarn test

This package is standalone — not part of any workspace. It pulls its own node_modules and is published independently of the Go binary.

版本与发布记录

@cdmbase/cdecli-agent-client 共发布 7 个版本,首次发布于 2026/05/16;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.4.1latest2026/09/121 个月前
0.4.02026/07/213 个月前
0.3.12026/07/193 个月前
0.3.02026/05/265 个月前
0.2.02026/05/205 个月前
0.1.12026/05/165 个月前

关于 @cdmbase/cdecli-agent-client 的常见问题

@cdmbase/cdecli-agent-client 是什么?

TypeScript client for cdecli-agent (POST /v1/cdecli/exec). Ships alongside the Go agent server.

如何安装 @cdmbase/cdecli-agent-client?

在项目目录运行 npm install @cdmbase/cdecli-agent-client,或使用 pnpm add / yarn add / bun add。

@cdmbase/cdecli-agent-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cdmbase/cdecli-agent-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cdmbase/cdecli-agent-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cdmbase/cdecli-agent-client 可以商用吗?

@cdmbase/cdecli-agent-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cdmbase/cdecli-agent-client 的下载量有多少?

根据 npm 官方下载统计,@cdmbase/cdecli-agent-client 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,288 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cdmbase/cdecli-agent-client 还在维护吗?

最新版本 0.4.1 发布于 2026/09/12(1 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。