devinfra-bridge 0.0.0-stage → 0.1.0-alpha.1
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 +60 -2
- package/dist/agents/registry.d.ts +2 -0
- package/dist/agents/types.d.ts +8 -0
- package/dist/auth/bytedcli-provider.d.ts +22 -0
- package/dist/auth/credential-provider.d.ts +13 -0
- package/dist/auth/direct-jwt-provider.d.ts +14 -0
- package/dist/config/load.d.ts +7 -0
- package/dist/config/types.d.ts +27 -0
- package/dist/daemon/daemon.d.ts +10 -0
- package/dist/daemon/single-instance.d.ts +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +835 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +853 -0
- package/dist/proxy/errors.d.ts +7 -0
- package/dist/proxy/forward-messages.d.ts +3 -0
- package/dist/proxy/headers.d.ts +3 -0
- package/dist/proxy/server.d.ts +21 -0
- package/dist/util/logger.d.ts +13 -0
- package/dist/util/paths.d.ts +1 -0
- package/dist/util/subprocess.d.ts +6 -0
- package/dist/version.d.ts +1 -0
- package/docs/acceptance.md +49 -0
- package/docs/development.md +97 -0
- package/package.json +46 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 devinfra-bridge 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
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# devinfra_bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本机 proxy daemon:接收 Claude Code 的原生 Messages 请求,附加机器已有的 ByteCloud JWT,转发到固定 llm gateway。使用 TypeScript,要求 Node.js >=22;无生产 npm 依赖。当前实际验收环境为 Node.js 22,构建目标为 node22。
|
|
4
|
+
|
|
5
|
+
## 开发与运行
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm ci
|
|
9
|
+
npm run typecheck
|
|
10
|
+
npm run lint
|
|
11
|
+
npm test
|
|
12
|
+
npm run build
|
|
13
|
+
node dist/main.js --version --json
|
|
14
|
+
node dist/main.js serve --config /absolute/path/bridge.json
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`bridge.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"config_version": 1,
|
|
22
|
+
"gateway_origin": "https://your-gateway.example",
|
|
23
|
+
"auth": {
|
|
24
|
+
"mode": "bytedcli",
|
|
25
|
+
"executable": "/absolute/path/bytedcli"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`state_root` 可选,默认 `~/.local/state/devinfra-bridge`。使用同一 OS 用户及其认证环境启动 daemon;bytedcli 子进程继承 `BYTEDCLI_CLOUD_SITE` / `BYTEDCLI_PROFILE`,无 site 覆盖,固定 `--as user`,不执行登录、不读取 refresh token。
|
|
31
|
+
|
|
32
|
+
正常启动后 stdout 输出一行就绪 JSON。固定监听 `127.0.0.1:18765`;端口占用则退出。用 SIGINT/SIGTERM 停止,最多 10 秒排空 HTTP 请求,随后清理资源。
|
|
33
|
+
|
|
34
|
+
## 首版行为
|
|
35
|
+
|
|
36
|
+
- 只转发 `POST /v1/messages`(可带 `?beta=true`);原始 body、model、effort、thinking、工具字段、JSON/SSE 字节不转换。
|
|
37
|
+
- 替换员工 JWT header,附加 `x-use-agent-plan: 1`、`X-Devinfra-Agent: claude-code`;剥离客户端 Authorization、x-api-key、Cookie 等凭据。
|
|
38
|
+
- `devinfra-bridge:cc` 是 CC 配置中的固定占位 token,本版不校验;来源 header 表示服务路由,不能证明发送进程身份。
|
|
39
|
+
- 背压、取消、分阶段超时;401 等上游错误原样返回,模型请求不自动重试。
|
|
40
|
+
- `/v1/models`、`count_tokens`、管理接口返回 404;CLI、安装、模型配置、配置恢复、目录查询由其他项目负责。
|
|
41
|
+
|
|
42
|
+
更多见 [开发说明](docs/development.md)、[验收说明](docs/acceptance.md)和 [实施计划](docs/superpowers/plans/2026-11-09-cc-gateway-integration.md)。
|
|
43
|
+
|
|
44
|
+
## npm 包与发布
|
|
45
|
+
|
|
46
|
+
包名 `devinfra-bridge`,首版 `0.1.0-alpha.1`,MIT 许可证。发布到公网 npm 的 `alpha` 标签,供外部 CLI 联调;真实 CC + Gateway 验收见验收说明。
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 开发时验证发布产物,不上传;当前功能分支也能运行
|
|
50
|
+
npm run publish:dry
|
|
51
|
+
|
|
52
|
+
# 在 main/master/develop 发布;脚本先检查,最后确认后才上传
|
|
53
|
+
./scripts/publish.sh
|
|
54
|
+
|
|
55
|
+
# 确认需要从其他分支发布时,只跳过分支检查
|
|
56
|
+
./scripts/publish.sh --force
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
脚本不会自动修改版本、暂存或提交。预发布版本自动使用 alpha/beta/rc/next 标签,正式版本使用 latest;检查包括 typecheck、lint、测试、构建与解包运行。`npm publish` 本身也通过 `prepublishOnly` 执行这些检查。
|
|
60
|
+
|
|
61
|
+
外部 CLI 可添加依赖 `devinfra-bridge@alpha`,通过 Node.js >=22 启动安装包中的 `dist/main.js serve --config ...`,或导入 `startDaemon`。本包没有 `bin` 命令,用户 CLI 在独立项目中提供。
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ProxyContext } from "../proxy/server.js";
|
|
3
|
+
export interface AgentRoute {
|
|
4
|
+
agent: string;
|
|
5
|
+
path: string;
|
|
6
|
+
method: string;
|
|
7
|
+
forward(req: IncomingMessage, res: ServerResponse, context: ProxyContext, signal: AbortSignal, agent: string): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CredentialProvider } from "./credential-provider.js";
|
|
2
|
+
export declare const JWT_ARGS: string[];
|
|
3
|
+
export interface BytedcliOptions {
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
outputBytes?: number;
|
|
6
|
+
cacheMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class BytedcliProvider implements CredentialProvider {
|
|
9
|
+
private readonly executable;
|
|
10
|
+
private readonly controller;
|
|
11
|
+
private pending?;
|
|
12
|
+
private cached?;
|
|
13
|
+
private readonly timeoutMs;
|
|
14
|
+
private readonly outputBytes;
|
|
15
|
+
private readonly cacheMs;
|
|
16
|
+
constructor(executable: string, options?: BytedcliOptions);
|
|
17
|
+
getJwt({ signal }?: {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
private acquire;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthConfig } from "../config/types.js";
|
|
2
|
+
export interface CredentialProvider {
|
|
3
|
+
getJwt(options?: {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}): Promise<string>;
|
|
6
|
+
close(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class CredentialError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(code: string);
|
|
11
|
+
}
|
|
12
|
+
export declare function validateJwt(value: unknown): string;
|
|
13
|
+
export declare function createCredentialProvider(config: AuthConfig): CredentialProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthConfig } from "../config/types.js";
|
|
2
|
+
import { type CredentialProvider } from "./credential-provider.js";
|
|
3
|
+
export declare class DirectJwtProvider implements CredentialProvider {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private closed;
|
|
6
|
+
private readonly snapshot?;
|
|
7
|
+
constructor(config: Exclude<AuthConfig, {
|
|
8
|
+
mode: "bytedcli";
|
|
9
|
+
}>);
|
|
10
|
+
getJwt({ signal }?: {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}): Promise<string>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DaemonConfig } from "./types.js";
|
|
2
|
+
export declare class ConfigError extends Error {
|
|
3
|
+
readonly code = "INVALID_CONFIG";
|
|
4
|
+
}
|
|
5
|
+
export declare function parseDaemonConfig(value: unknown): DaemonConfig;
|
|
6
|
+
export declare function loadDaemonConfig(path: string): Promise<DaemonConfig>;
|
|
7
|
+
export declare function assertSupportedNode(version?: string): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const HOST = "127.0.0.1";
|
|
2
|
+
export declare const PORT = 18765;
|
|
3
|
+
export declare const CC_PLACEHOLDER_TOKEN = "devinfra-bridge:cc";
|
|
4
|
+
export type AuthConfig = {
|
|
5
|
+
mode: "bytedcli";
|
|
6
|
+
executable: string;
|
|
7
|
+
} | {
|
|
8
|
+
mode: "direct-jwt";
|
|
9
|
+
file: string;
|
|
10
|
+
} | {
|
|
11
|
+
mode: "direct-jwt";
|
|
12
|
+
env: string;
|
|
13
|
+
};
|
|
14
|
+
export interface DaemonConfig {
|
|
15
|
+
configVersion: 1;
|
|
16
|
+
gatewayOrigin: string;
|
|
17
|
+
stateRoot: string;
|
|
18
|
+
auth: AuthConfig;
|
|
19
|
+
}
|
|
20
|
+
export interface ProxyLimits {
|
|
21
|
+
bodyBytes: number;
|
|
22
|
+
bodyIdleMs: number;
|
|
23
|
+
concurrency: number;
|
|
24
|
+
headersMs: number;
|
|
25
|
+
streamIdleMs: number;
|
|
26
|
+
}
|
|
27
|
+
export declare const DEFAULT_LIMITS: Readonly<ProxyLimits>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DaemonConfig, HOST, PORT } from "../config/types.js";
|
|
2
|
+
export interface DaemonHandle {
|
|
3
|
+
instanceId: string;
|
|
4
|
+
host: typeof HOST;
|
|
5
|
+
port: typeof PORT;
|
|
6
|
+
close(options?: {
|
|
7
|
+
drainMs?: number;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function startDaemon(config: DaemonConfig): Promise<DaemonHandle>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { assertSupportedNode, loadDaemonConfig, parseDaemonConfig } from "./config/load.js";
|
|
2
|
+
export { CC_PLACEHOLDER_TOKEN, HOST, PORT } from "./config/types.js";
|
|
3
|
+
export type { AuthConfig, DaemonConfig } from "./config/types.js";
|
|
4
|
+
export { startDaemon } from "./daemon/daemon.js";
|
|
5
|
+
export type { DaemonHandle } from "./daemon/daemon.js";
|
|
6
|
+
export type { CredentialProvider } from "./auth/credential-provider.js";
|