@vicvic-im/agent-bot 0.0.0-stage → 0.1.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/README.md +142 -2
- package/dist/agents/acp.d.ts +42 -0
- package/dist/agents/acp.d.ts.map +1 -0
- package/dist/agents/registry.d.ts +13 -0
- package/dist/agents/registry.d.ts.map +1 -0
- package/dist/agents/types.d.ts +72 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/chunk-QQ2NXJ3L.js +92 -0
- package/dist/chunk-QQ2NXJ3L.js.map +1 -0
- package/dist/chunk-SCVC76UL.js +1331 -0
- package/dist/chunk-SCVC76UL.js.map +1 -0
- package/dist/cli.cjs +1506 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +144 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/setup.d.ts +8 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/core/chunk.d.ts +10 -0
- package/dist/core/chunk.d.ts.map +1 -0
- package/dist/core/cli-path.d.ts +8 -0
- package/dist/core/cli-path.d.ts.map +1 -0
- package/dist/core/dispatcher.d.ts +18 -0
- package/dist/core/dispatcher.d.ts.map +1 -0
- package/dist/core/gate.d.ts +3 -0
- package/dist/core/gate.d.ts.map +1 -0
- package/dist/core/lock.d.ts +10 -0
- package/dist/core/lock.d.ts.map +1 -0
- package/dist/core/queue.d.ts +27 -0
- package/dist/core/queue.d.ts.map +1 -0
- package/dist/core/state.d.ts +22 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/switch.d.ts +20 -0
- package/dist/core/switch.d.ts.map +1 -0
- package/dist/core/wire.d.ts +36 -0
- package/dist/core/wire.d.ts.map +1 -0
- package/dist/index.cjs +1464 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +1309 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +47 -4
package/README.md
CHANGED
|
@@ -1,3 +1,143 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vicvic-im/agent-bot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect a local coding agent to [vicvic.im](https://vicvic.im) as an AI contact. Supports **Claude Code**, **Codex**, **OpenCode**, and **Pi** through the [Agent Client Protocol](https://agentclientprotocol.com) (ACP).
|
|
4
|
+
|
|
5
|
+
This is the multi-agent successor to `@ccbot/cli`. It reuses the same vicvic.im bot WebSocket protocol, so the server needs no changes.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js >= 20
|
|
10
|
+
- One of the supported agents installed and authenticated **on the same machine**:
|
|
11
|
+
|
|
12
|
+
| Agent | Command prerequisite |
|
|
13
|
+
| ----------- | ---------------------------------------- |
|
|
14
|
+
| Claude Code | `claude login` or `ANTHROPIC_AUTH_TOKEN` |
|
|
15
|
+
| Codex | `codex login` |
|
|
16
|
+
| OpenCode | OpenCode >= 1.19, provider configured |
|
|
17
|
+
| Pi | Pi installed and authenticated |
|
|
18
|
+
|
|
19
|
+
ACP adapters are pinned in code:
|
|
20
|
+
|
|
21
|
+
- `@agentclientprotocol/claude-agent-acp@0.100.0`
|
|
22
|
+
- `@agentclientprotocol/codex-acp@2.5.0`
|
|
23
|
+
- `opencode acp` (OpenCode >= 1.19)
|
|
24
|
+
- `pi-acp@0.0.34` (third-party adapter)
|
|
25
|
+
|
|
26
|
+
`npx` based adapters are downloaded on first run; pre-install them globally if your network is slow.
|
|
27
|
+
|
|
28
|
+
Verified ACP capabilities (2026-11-05, local):
|
|
29
|
+
|
|
30
|
+
| Agent | resume | load | model option | usage cost | Notes |
|
|
31
|
+
| ----------- | ------ | ---- | ------------ | ---------- | ------------------------------------------------------- |
|
|
32
|
+
| Claude Code | ✅ | ✅ | ✅ | ✅ | ~13s cold start |
|
|
33
|
+
| Codex | ✅ | ✅ | ✅ | ❌ | ~100s cold start |
|
|
34
|
+
| OpenCode | ✅ | ✅ | ✅ | ✅ | set a working model; the free default may hit its limit |
|
|
35
|
+
| Pi | ❌ | ✅ | ✅ | ❌ | uses `session/load`; may include a context preamble |
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm i -g @vicvic-im/agent-bot
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
1. Create an AI Bot in vicvic.im and copy its pairing token.
|
|
46
|
+
2. In the project directory you want the agent to work in:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
vbot start
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. The first run asks for the agent, work directory, timeout, server URL, and token, then writes `vbot.json`.
|
|
53
|
+
4. Send a message to the bot from vicvic.im.
|
|
54
|
+
|
|
55
|
+
With `pm2` installed, `vbot start` runs in the background. Without pm2, or with `--foreground`, it runs in the current terminal.
|
|
56
|
+
|
|
57
|
+
## Commands
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
vbot start [--foreground] [-c <config>]
|
|
61
|
+
vbot stop [-c <config>]
|
|
62
|
+
vbot restart [-c <config>]
|
|
63
|
+
vbot status [-c <config>]
|
|
64
|
+
vbot logs [-c <config>]
|
|
65
|
+
vbot delete [-c <config>]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Chat commands:
|
|
69
|
+
|
|
70
|
+
| Command | Description |
|
|
71
|
+
| --------------- | ---------------------------------------------------- |
|
|
72
|
+
| `/new` | Drop the ACP session and start a new conversation |
|
|
73
|
+
| `/stop` | Cancel the current run and clear the queue |
|
|
74
|
+
| `/status` | Show agent, session, cwd, queue, usage, capabilities |
|
|
75
|
+
| `/agent [name]` | List or switch the agent backend |
|
|
76
|
+
| `/model [name]` | Show or switch the model (if the agent exposes it) |
|
|
77
|
+
| `/cost` | Show context usage and optional cost |
|
|
78
|
+
| `/help` | Show commands |
|
|
79
|
+
|
|
80
|
+
Unknown `/commands` are forwarded to the agent as prompts.
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
`vbot.json` in the current directory, or `~/.vbot/config.json` as a fallback:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"provider": "vicvic",
|
|
89
|
+
"vicvic": {
|
|
90
|
+
"baseUrl": "https://api.vicvic.im",
|
|
91
|
+
"token": "ccbotpk_xxx"
|
|
92
|
+
},
|
|
93
|
+
"agent": {
|
|
94
|
+
"name": "codex",
|
|
95
|
+
"cwd": "/Users/me/project",
|
|
96
|
+
"model": null
|
|
97
|
+
},
|
|
98
|
+
"timeoutMs": 3600000,
|
|
99
|
+
"logPrompt": false
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `agent.command` / `agent.args` are optional overrides. When omitted, the pinned command from the registry is used.
|
|
104
|
+
- `agent.cwd` must be an absolute existing directory.
|
|
105
|
+
- `VBOT_TOKEN` overrides `vicvic.token`, which is useful for CI or secret managers.
|
|
106
|
+
- `logPrompt` defaults to `false`; prompts are not printed to logs.
|
|
107
|
+
|
|
108
|
+
Session state is stored in `~/.vbot/state/<sha256(token)[:16]>.json`. State contains no message text and no token.
|
|
109
|
+
|
|
110
|
+
## Security
|
|
111
|
+
|
|
112
|
+
`vbot` runs the agent with **your local user permissions** and automatically approves every ACP permission request. There is no interactive approval mode. Only run it in a directory you trust, and review what the agent is allowed to access.
|
|
113
|
+
|
|
114
|
+
The pairing token is a long-lived credential. Do not commit `vbot.json`; the file is written with mode `0600` but may still be copied by backup tools.
|
|
115
|
+
|
|
116
|
+
## Differences from `@ccbot/cli`
|
|
117
|
+
|
|
118
|
+
- Multi-agent through ACP instead of Claude-only SDK.
|
|
119
|
+
- Session state is persisted; restarting `vbot` can resume the ACP session when the backend supports it.
|
|
120
|
+
- `/cost` reports ACP `usage_update` values (`used` / `size` / optional `cost`), not Claude's dollar cost.
|
|
121
|
+
- New config file (`vbot.json`) and pm2 process names (`vbot-*`); it does not read or migrate `ccbot.json`.
|
|
122
|
+
- The App's onboarding still says `npm i -g @ccbot/cli`; this is a known gap for now.
|
|
123
|
+
|
|
124
|
+
## Known limitations
|
|
125
|
+
|
|
126
|
+
- No streaming/progress messages yet: only `Processing...` and the final reply.
|
|
127
|
+
- Text only. Image and file messages are not supported by the vicvic.im bot conversation.
|
|
128
|
+
- The server's offline notice still mentions `ccbot` (the server is unchanged in this phase).
|
|
129
|
+
- Windows is not officially verified; the adapters and pm2 may need extra setup.
|
|
130
|
+
- Chat CLI messages are English, matching the existing `@ccbot/cli` developer tooling; App UI i18n is unaffected.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pnpm --filter @vicvic-im/agent-bot build
|
|
136
|
+
pnpm --filter @vicvic-im/agent-bot test
|
|
137
|
+
pnpm --filter @vicvic-im/agent-bot lint
|
|
138
|
+
|
|
139
|
+
# probe ACP capabilities of all four backends
|
|
140
|
+
pnpm --filter @vicvic-im/agent-bot exec tsx scripts/probe.ts
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
See `docs/prds/agent-bot-cli.md` for the full design.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AgentBackend, AgentCapabilities, AgentName, AgentRunRequest, AgentRunResult } from "./types.js";
|
|
2
|
+
import type { AgentConfig } from "../config.js";
|
|
3
|
+
export declare class AgentAbortError extends Error {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
6
|
+
export declare class AgentStartError extends Error {
|
|
7
|
+
readonly stderr: string;
|
|
8
|
+
constructor(message: string, stderr: string);
|
|
9
|
+
}
|
|
10
|
+
/** 通过 ACP stdio 驱动单个 coding agent 子进程。 */
|
|
11
|
+
export declare class AcpAgent implements AgentBackend {
|
|
12
|
+
readonly name: AgentName;
|
|
13
|
+
private readonly config;
|
|
14
|
+
private child;
|
|
15
|
+
private connection;
|
|
16
|
+
private ctx;
|
|
17
|
+
private startPromise;
|
|
18
|
+
private session;
|
|
19
|
+
private configOptions;
|
|
20
|
+
private initCaps;
|
|
21
|
+
private turn;
|
|
22
|
+
private stderr;
|
|
23
|
+
private sawUsageCost;
|
|
24
|
+
private pendingModel;
|
|
25
|
+
constructor(name: AgentName, config: AgentConfig);
|
|
26
|
+
capabilities(): AgentCapabilities;
|
|
27
|
+
sessionId(): string | null;
|
|
28
|
+
resetSession(): void;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
private doStart;
|
|
31
|
+
private ensureSession;
|
|
32
|
+
run(request: AgentRunRequest): Promise<AgentRunResult>;
|
|
33
|
+
cancel(): Promise<void>;
|
|
34
|
+
setModel(model: string): Promise<boolean>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
private handleUpdate;
|
|
37
|
+
private dispatchUpdate;
|
|
38
|
+
private applyContentChunk;
|
|
39
|
+
private applyToolUpdate;
|
|
40
|
+
private applyUsage;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=acp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.d.ts","sourceRoot":"","sources":["../../src/agents/acp.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,cAAc,EAEf,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,qBAAa,eAAgB,SAAQ,KAAK;;CAKzC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,MAAM,EAA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;
|
|
5
|
+
command: AgentCommand;
|
|
6
|
+
/** 需要用户自行完成的认证前置。 */
|
|
7
|
+
authHint: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const AGENTS: Record<AgentName, AgentDefinition>;
|
|
10
|
+
export declare const AGENT_NAMES: AgentName[];
|
|
11
|
+
export declare function isAgentName(value: string): value is AgentName;
|
|
12
|
+
export declare function definitionOf(name: AgentName): AgentDefinition;
|
|
13
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/agents/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI1D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;IACtB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CAqCrD,CAAC;AAEF,eAAO,MAAM,WAAW,EAA0B,SAAS,EAAE,CAAC;AAE9D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAE7D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,eAAe,CAE7D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type AgentName = "claude" | "codex" | "opencode" | "pi";
|
|
2
|
+
export interface AgentCommand {
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface Usage {
|
|
7
|
+
/** 当前上下文 token 数(ACP v1 usage_update.used)。 */
|
|
8
|
+
used: number;
|
|
9
|
+
/** 上下文窗口大小(ACP v1 usage_update.size)。 */
|
|
10
|
+
size: number;
|
|
11
|
+
/** 累计成本,单位由 agent 决定;不提供时为 null。 */
|
|
12
|
+
cost: {
|
|
13
|
+
amount: number;
|
|
14
|
+
currency: string;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
export declare const EMPTY_USAGE: Usage;
|
|
18
|
+
export type AgentEvent = {
|
|
19
|
+
type: "text";
|
|
20
|
+
text: string;
|
|
21
|
+
} | {
|
|
22
|
+
type: "thought";
|
|
23
|
+
text: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "tool";
|
|
26
|
+
name: string;
|
|
27
|
+
status: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "usage";
|
|
30
|
+
usage: Usage;
|
|
31
|
+
};
|
|
32
|
+
export interface AgentRunRequest {
|
|
33
|
+
prompt: string;
|
|
34
|
+
/** 已保存的 ACP session id;为空或后端不支持 resume 时新建。 */
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
cwd: string;
|
|
37
|
+
model?: string | null;
|
|
38
|
+
signal: AbortSignal;
|
|
39
|
+
onEvent?: (event: AgentEvent) => void;
|
|
40
|
+
}
|
|
41
|
+
export interface AgentRunResult {
|
|
42
|
+
text: string;
|
|
43
|
+
sessionId: string;
|
|
44
|
+
usage: Usage;
|
|
45
|
+
/** true 表示本次是新会话(用于提示用户上下文已重置)。 */
|
|
46
|
+
newSession: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface AgentCapabilities {
|
|
49
|
+
resume: boolean;
|
|
50
|
+
load: boolean;
|
|
51
|
+
setConfigOption: boolean;
|
|
52
|
+
usageCost: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface AgentBackend {
|
|
55
|
+
readonly name: AgentName;
|
|
56
|
+
/** 启动子进程并完成 initialize;可重复调用(已启动则直接返回)。 */
|
|
57
|
+
start(): Promise<void>;
|
|
58
|
+
/** 运行一轮 prompt。内部负责 session 新建/恢复。 */
|
|
59
|
+
run(request: AgentRunRequest): Promise<AgentRunResult>;
|
|
60
|
+
/** 取消当前 prompt。 */
|
|
61
|
+
cancel(): Promise<void>;
|
|
62
|
+
/** 切换模型;返回 false 表示当前后端不支持。 */
|
|
63
|
+
setModel(model: string): Promise<boolean>;
|
|
64
|
+
/** 丢弃当前 ACP session;下一次 run 会新建会话。 */
|
|
65
|
+
resetSession(): void;
|
|
66
|
+
/** 关闭子进程并清理资源。 */
|
|
67
|
+
close(): Promise<void>;
|
|
68
|
+
capabilities(): AgentCapabilities;
|
|
69
|
+
/** 当前 ACP session id(可能为空)。 */
|
|
70
|
+
sessionId(): string | null;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agents/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC;AAE/D,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,KAAK;IACpB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACnD;AAED,eAAO,MAAM,WAAW,EAAE,KAAwC,CAAC;AAEnE,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAA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@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENTS,
|
|
3
|
+
AGENT_NAMES,
|
|
4
|
+
DEFAULT_BASE_URL,
|
|
5
|
+
DEFAULT_TIMEOUT_MS,
|
|
6
|
+
findConfigPath,
|
|
7
|
+
isAgentName,
|
|
8
|
+
loadConfig,
|
|
9
|
+
normalizeConfig,
|
|
10
|
+
saveConfig
|
|
11
|
+
} from "./chunk-SCVC76UL.js";
|
|
12
|
+
|
|
13
|
+
// src/commands/setup.ts
|
|
14
|
+
import { existsSync } from "fs";
|
|
15
|
+
import { dirname, resolve } from "path";
|
|
16
|
+
import inquirer from "inquirer";
|
|
17
|
+
import pc from "picocolors";
|
|
18
|
+
async function ensureConfig(explicit) {
|
|
19
|
+
let found;
|
|
20
|
+
if (explicit) {
|
|
21
|
+
const explicitPath = resolve(explicit);
|
|
22
|
+
found = existsSync(explicitPath) ? explicitPath : void 0;
|
|
23
|
+
} else {
|
|
24
|
+
found = findConfigPath();
|
|
25
|
+
}
|
|
26
|
+
if (found) return loadConfig(found);
|
|
27
|
+
const target = resolve(explicit ?? "vbot.json");
|
|
28
|
+
console.log(pc.yellow("vbot.json not found, starting setup...\n"));
|
|
29
|
+
const answers = await inquirer.prompt([
|
|
30
|
+
{
|
|
31
|
+
type: "list",
|
|
32
|
+
name: "agent",
|
|
33
|
+
message: "Agent backend:",
|
|
34
|
+
choices: AGENT_NAMES.map((name) => ({
|
|
35
|
+
name: `${name} (${AGENTS[name].label})`,
|
|
36
|
+
value: name
|
|
37
|
+
}))
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "input",
|
|
41
|
+
name: "cwd",
|
|
42
|
+
message: "Work directory:",
|
|
43
|
+
default: process.cwd(),
|
|
44
|
+
validate: (value) => value.trim() ? true : "Work directory is required"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "number",
|
|
48
|
+
name: "timeoutMs",
|
|
49
|
+
message: "Timeout in ms:",
|
|
50
|
+
default: DEFAULT_TIMEOUT_MS
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "confirm",
|
|
54
|
+
name: "logPrompt",
|
|
55
|
+
message: "Log prompt content? (not recommended)",
|
|
56
|
+
default: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "input",
|
|
60
|
+
name: "baseUrl",
|
|
61
|
+
message: "vicvic.im server URL:",
|
|
62
|
+
default: DEFAULT_BASE_URL
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "password",
|
|
66
|
+
name: "token",
|
|
67
|
+
message: "Bot pairing token:",
|
|
68
|
+
validate: (value) => value.trim() ? true : "Pairing token is required"
|
|
69
|
+
}
|
|
70
|
+
]);
|
|
71
|
+
const agentName = answers.agent;
|
|
72
|
+
if (!isAgentName(agentName)) throw new Error(`Invalid agent: ${agentName}`);
|
|
73
|
+
const config = normalizeConfig(
|
|
74
|
+
{
|
|
75
|
+
provider: "vicvic",
|
|
76
|
+
vicvic: { baseUrl: answers.baseUrl.trim() || DEFAULT_BASE_URL, token: answers.token.trim() },
|
|
77
|
+
agent: { name: agentName, cwd: answers.cwd.trim() },
|
|
78
|
+
timeoutMs: answers.timeoutMs,
|
|
79
|
+
logPrompt: answers.logPrompt
|
|
80
|
+
},
|
|
81
|
+
resolve(dirname(target))
|
|
82
|
+
);
|
|
83
|
+
saveConfig(config, target);
|
|
84
|
+
console.log(pc.green(`\u2714 Config saved to ${target}
|
|
85
|
+
`));
|
|
86
|
+
return { config, path: target };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
ensureConfig
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=chunk-QQ2NXJ3L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/setup.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport inquirer from \"inquirer\";\nimport pc from \"picocolors\";\nimport {\n DEFAULT_BASE_URL,\n DEFAULT_TIMEOUT_MS,\n findConfigPath,\n loadConfig,\n normalizeConfig,\n saveConfig,\n type VbotConfig,\n} from \"../config.js\";\nimport { AGENTS, AGENT_NAMES, isAgentName } from \"../agents/registry.js\";\n\nexport interface SetupResult {\n config: VbotConfig;\n path: string;\n}\n\n/** 已有配置直接用;否则运行首次向导并写入当前目录 vbot.json。 */\nexport async function ensureConfig(explicit?: string): Promise<SetupResult> {\n let found: string | undefined;\n if (explicit) {\n const explicitPath = resolve(explicit);\n found = existsSync(explicitPath) ? explicitPath : undefined;\n } else {\n found = findConfigPath();\n }\n if (found) return loadConfig(found);\n\n const target = resolve(explicit ?? \"vbot.json\");\n console.log(pc.yellow(\"vbot.json not found, starting setup...\\n\"));\n\n const answers = await inquirer.prompt<{\n agent: string;\n cwd: string;\n timeoutMs: number;\n logPrompt: boolean;\n baseUrl: string;\n token: string;\n }>([\n {\n type: \"list\",\n name: \"agent\",\n message: \"Agent backend:\",\n choices: AGENT_NAMES.map((name) => ({\n name: `${name} (${AGENTS[name].label})`,\n value: name,\n })),\n },\n {\n type: \"input\",\n name: \"cwd\",\n message: \"Work directory:\",\n default: process.cwd(),\n validate: (value: string) => (value.trim() ? true : \"Work directory is required\"),\n },\n {\n type: \"number\",\n name: \"timeoutMs\",\n message: \"Timeout in ms:\",\n default: DEFAULT_TIMEOUT_MS,\n },\n {\n type: \"confirm\",\n name: \"logPrompt\",\n message: \"Log prompt content? (not recommended)\",\n default: false,\n },\n {\n type: \"input\",\n name: \"baseUrl\",\n message: \"vicvic.im server URL:\",\n default: DEFAULT_BASE_URL,\n },\n {\n type: \"password\",\n name: \"token\",\n message: \"Bot pairing token:\",\n validate: (value: string) => (value.trim() ? true : \"Pairing token is required\"),\n },\n ]);\n\n const agentName = answers.agent;\n if (!isAgentName(agentName)) throw new Error(`Invalid agent: ${agentName}`);\n\n const config = normalizeConfig(\n {\n provider: \"vicvic\",\n vicvic: { baseUrl: answers.baseUrl.trim() || DEFAULT_BASE_URL, token: answers.token.trim() },\n agent: { name: agentName, cwd: answers.cwd.trim() },\n timeoutMs: answers.timeoutMs,\n logPrompt: answers.logPrompt,\n },\n resolve(dirname(target))\n );\n\n saveConfig(config, target);\n console.log(pc.green(`✔ Config saved to ${target}\\n`));\n return { config, path: target };\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS,eAAe;AACjC,OAAO,cAAc;AACrB,OAAO,QAAQ;AAkBf,eAAsB,aAAa,UAAyC;AAC1E,MAAI;AACJ,MAAI,UAAU;AACZ,UAAM,eAAe,QAAQ,QAAQ;AACrC,YAAQ,WAAW,YAAY,IAAI,eAAe;AAAA,EACpD,OAAO;AACL,YAAQ,eAAe;AAAA,EACzB;AACA,MAAI,MAAO,QAAO,WAAW,KAAK;AAElC,QAAM,SAAS,QAAQ,YAAY,WAAW;AAC9C,UAAQ,IAAI,GAAG,OAAO,0CAA0C,CAAC;AAEjE,QAAM,UAAU,MAAM,SAAS,OAO5B;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,YAAY,IAAI,CAAC,UAAU;AAAA,QAClC,MAAM,GAAG,IAAI,KAAK,OAAO,IAAI,EAAE,KAAK;AAAA,QACpC,OAAO;AAAA,MACT,EAAE;AAAA,IACJ;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,QAAQ,IAAI;AAAA,MACrB,UAAU,CAAC,UAAmB,MAAM,KAAK,IAAI,OAAO;AAAA,IACtD;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAA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