@acp-router/cli 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/lib/cache.d.ts +9 -0
- package/lib/cache.d.ts.map +1 -0
- package/lib/cache.js +32 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +19 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +38 -0
- package/package.json +20 -0
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SessionCacheStore } from '@acp-router/core';
|
|
2
|
+
export declare class FileSessionCache implements SessionCacheStore {
|
|
3
|
+
private path;
|
|
4
|
+
private dir;
|
|
5
|
+
get(key: string): Promise<string | null>;
|
|
6
|
+
set(key: string, value: string): Promise<void>;
|
|
7
|
+
private readAll;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,OAAO,CAAC,IAAI,CAAsD;IAClE,OAAO,CAAC,GAAG,CAA6B;IAElC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAOtC,OAAO;CAQtB"}
|
package/lib/cache.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export class FileSessionCache {
|
|
5
|
+
path = join(homedir(), '.config', 'acp-router.cache.json');
|
|
6
|
+
dir = join(homedir(), '.config');
|
|
7
|
+
async get(key) {
|
|
8
|
+
try {
|
|
9
|
+
const raw = await readFile(this.path, 'utf-8');
|
|
10
|
+
const data = JSON.parse(raw);
|
|
11
|
+
return data[key] ?? null;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async set(key, value) {
|
|
18
|
+
const data = await this.readAll();
|
|
19
|
+
data[key] = value;
|
|
20
|
+
await mkdir(this.dir, { recursive: true });
|
|
21
|
+
await writeFile(this.path, JSON.stringify(data, null, 2), 'utf-8');
|
|
22
|
+
}
|
|
23
|
+
async readAll() {
|
|
24
|
+
try {
|
|
25
|
+
const raw = await readFile(this.path, 'utf-8');
|
|
26
|
+
return JSON.parse(raw);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAIrE,wBAAsB,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC,CAcxD"}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { normalizeConfig } from '@acp-router/core';
|
|
5
|
+
const CONFIG_PATH = join(homedir(), '.config', 'acp-router.json');
|
|
6
|
+
export async function loadConfig() {
|
|
7
|
+
const raw = await readFile(CONFIG_PATH, 'utf-8');
|
|
8
|
+
const parsed = JSON.parse(raw);
|
|
9
|
+
return normalizeConfig({
|
|
10
|
+
allowList: Array.isArray(parsed.allowList) ? parsed.allowList : [],
|
|
11
|
+
defaultAgentId: typeof parsed.defaultAgentId === 'string' ? parsed.defaultAgentId : undefined,
|
|
12
|
+
agents: typeof parsed.agents === 'object' && parsed.agents ? parsed.agents : {},
|
|
13
|
+
session: { cwd: typeof parsed.cwd === 'string' ? parsed.cwd : undefined },
|
|
14
|
+
telegram: {
|
|
15
|
+
token: typeof parsed.telegramToken === 'string' ? parsed.telegramToken : undefined,
|
|
16
|
+
permissionTimeoutMs: typeof parsed.telegramPermissionTimeoutMs === 'number' ? parsed.telegramPermissionTimeoutMs : undefined
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NodeAgentLauncher, RouterCore, logger } from '@acp-router/core';
|
|
2
|
+
import { TelegramAdapter } from '@acp-router/adapter-telegram';
|
|
3
|
+
import { FileSessionCache } from './cache.js';
|
|
4
|
+
import { loadConfig } from './config.js';
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = await loadConfig();
|
|
7
|
+
if (!config.telegram?.token)
|
|
8
|
+
throw new Error('Config: telegramToken is required');
|
|
9
|
+
const agents = Object.entries(config.agents).map(([id, agent]) => ({
|
|
10
|
+
id,
|
|
11
|
+
name: agent.name ?? id,
|
|
12
|
+
description: agent.description,
|
|
13
|
+
command: agent.command,
|
|
14
|
+
args: agent.args,
|
|
15
|
+
env: agent.env,
|
|
16
|
+
cwd: agent.cwd
|
|
17
|
+
}));
|
|
18
|
+
if (!agents.length)
|
|
19
|
+
throw new Error('Config: agents is required');
|
|
20
|
+
const defaultAgentId = config.defaultAgentId && config.agents[config.defaultAgentId]
|
|
21
|
+
? config.defaultAgentId
|
|
22
|
+
: agents[0]?.id;
|
|
23
|
+
if (!defaultAgentId)
|
|
24
|
+
throw new Error('Config: no agents available');
|
|
25
|
+
const adapter = new TelegramAdapter(config.telegram.token, config.allowList);
|
|
26
|
+
const launcher = new NodeAgentLauncher();
|
|
27
|
+
const cache = new FileSessionCache();
|
|
28
|
+
logger.info({ defaultAgentId }, 'Starting ACP router');
|
|
29
|
+
const router = new RouterCore(adapter, launcher, { source: 'config', fetchedAt: new Date().toISOString(), agents }, cache, {
|
|
30
|
+
agentId: defaultAgentId,
|
|
31
|
+
cwd: config.session.cwd ?? process.cwd()
|
|
32
|
+
}, { timeoutMs: config.telegram?.permissionTimeoutMs ?? null });
|
|
33
|
+
await router.init();
|
|
34
|
+
}
|
|
35
|
+
main().catch((err) => {
|
|
36
|
+
logger.error({ err }, 'ACP router failed');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acp-router/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -p tsconfig.json"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@acp-router/adapter-telegram": "0.1.0",
|
|
15
|
+
"@acp-router/core": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|