chatccc 0.2.111 → 0.2.113
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/package.json
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
import { spawn, type ChildProcess } from "node:child_process";
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
10
10
|
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
-
import { join } from "node:path";
|
|
11
|
+
import { join, dirname } from "node:path";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
13
14
|
|
|
14
15
|
import type {
|
|
15
16
|
ToolAdapter,
|
|
@@ -19,7 +20,6 @@ import type {
|
|
|
19
20
|
SessionInfo,
|
|
20
21
|
ToolPromptOptions,
|
|
21
22
|
} from "./adapter-interface.ts";
|
|
22
|
-
import { PROJECT_ROOT } from "../config.ts";
|
|
23
23
|
import { killProcessTree } from "./proc-tree-kill.ts";
|
|
24
24
|
import {
|
|
25
25
|
defaultClaudeSessionMetaStore,
|
|
@@ -30,13 +30,48 @@ import {
|
|
|
30
30
|
// 常量
|
|
31
31
|
// ---------------------------------------------------------------------------
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
33
|
+
/** 根据当前平台动态解析 claude-agent-sdk 二进制路径 */
|
|
34
|
+
function resolveClaudeBinary(): string {
|
|
35
|
+
const platform = process.platform; // 'win32', 'linux', 'darwin'
|
|
36
|
+
const arch = process.arch; // 'x64', 'arm64'
|
|
37
|
+
|
|
38
|
+
// 通过 Node 模块解析找到 SDK 主包目录,确保测试和生产环境一致
|
|
39
|
+
const _require = createRequire(import.meta.url);
|
|
40
|
+
const sdkMainDir = dirname(_require.resolve("@anthropic-ai/claude-agent-sdk"));
|
|
41
|
+
|
|
42
|
+
// 读取 manifest.json 获取各平台二进制文件名
|
|
43
|
+
let platforms: Record<string, { binary: string }> | null = null;
|
|
44
|
+
try {
|
|
45
|
+
const manifest = JSON.parse(
|
|
46
|
+
readFileSync(join(sdkMainDir, "manifest.json"), "utf-8"),
|
|
47
|
+
) as { platforms?: Record<string, { binary: string }> };
|
|
48
|
+
platforms = manifest.platforms ?? null;
|
|
49
|
+
} catch { /* manifest 缺失时用默认规则推断 */ }
|
|
50
|
+
|
|
51
|
+
// Linux 上需区分 musl / glibc,先检测 musl 变体
|
|
52
|
+
const candidates: string[] = [];
|
|
53
|
+
if (platform === "linux") {
|
|
54
|
+
candidates.push(`${platform}-${arch}-musl`, `${platform}-${arch}`);
|
|
55
|
+
} else {
|
|
56
|
+
candidates.push(`${platform}-${arch}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const triple of candidates) {
|
|
60
|
+
const binaryName = platforms?.[triple]?.binary
|
|
61
|
+
?? (platform === "win32" ? "claude.exe" : "claude");
|
|
62
|
+
const pkgDir = join(sdkMainDir, "..", `claude-agent-sdk-${triple}`);
|
|
63
|
+
if (!existsSync(pkgDir)) continue;
|
|
64
|
+
const exePath = join(pkgDir, binaryName);
|
|
65
|
+
if (existsSync(exePath)) return exePath;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
throw new Error(
|
|
69
|
+
`No Claude CLI binary found for platform ${platform}-${arch}. ` +
|
|
70
|
+
`Tried: ${candidates.map((c) => `@anthropic-ai/claude-agent-sdk-${c}`).join(", ")}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const CLAUDE_EXE = resolveClaudeBinary();
|
|
40
75
|
|
|
41
76
|
// ---------------------------------------------------------------------------
|
|
42
77
|
// 类型别名(CLI JSONL 消息格式,与旧 SDK 消息格式兼容)
|
package/src/agent-file-rpc.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { extname, isAbsolute, resolve } from "node:path";
|
|
|
3
3
|
import { stat } from "node:fs/promises";
|
|
4
4
|
|
|
5
5
|
import { getTenantAccessToken, sendFileReply, sendTextReply } from "./feishu-platform.ts";
|
|
6
|
-
import { ts } from "./config.ts";
|
|
6
|
+
import { ts, resolveDefaultAgentTool } from "./config.ts";
|
|
7
7
|
import { readUtf8JsonBody } from "./agent-rpc-body.ts";
|
|
8
8
|
import { getAdapterForTool } from "./session.ts";
|
|
9
9
|
import { getChatsForSession } from "./session-chat-binding.ts";
|
|
@@ -77,7 +77,7 @@ export async function handleAgentFileRequest(
|
|
|
77
77
|
try {
|
|
78
78
|
const { getSessionTool } = await import("./session.ts");
|
|
79
79
|
const tool = await getSessionTool(sessionId);
|
|
80
|
-
const adapter = getAdapterForTool(tool ??
|
|
80
|
+
const adapter = getAdapterForTool(tool ?? resolveDefaultAgentTool());
|
|
81
81
|
const info = await adapter.getSessionInfo(sessionId);
|
|
82
82
|
if (!info?.cwd) {
|
|
83
83
|
jsonReply(res, 400, { ok: false, error: "Cannot determine cwd for session" });
|
package/src/agent-image-rpc.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { extname, isAbsolute, resolve } from "node:path";
|
|
|
3
3
|
import { stat } from "node:fs/promises";
|
|
4
4
|
|
|
5
5
|
import { getTenantAccessToken, sendImageReply, sendTextReply } from "./feishu-platform.ts";
|
|
6
|
-
import { ts } from "./config.ts";
|
|
6
|
+
import { ts, resolveDefaultAgentTool } from "./config.ts";
|
|
7
7
|
import { readUtf8JsonBody } from "./agent-rpc-body.ts";
|
|
8
8
|
import { getAdapterForTool } from "./session.ts";
|
|
9
9
|
import { getChatsForSession } from "./session-chat-binding.ts";
|
|
@@ -73,7 +73,7 @@ export async function handleAgentImageRequest(
|
|
|
73
73
|
try {
|
|
74
74
|
const { getSessionTool } = await import("./session.ts");
|
|
75
75
|
const tool = await getSessionTool(sessionId);
|
|
76
|
-
const adapter = getAdapterForTool(tool ??
|
|
76
|
+
const adapter = getAdapterForTool(tool ?? resolveDefaultAgentTool());
|
|
77
77
|
const info = await adapter.getSessionInfo(sessionId);
|
|
78
78
|
if (!info?.cwd) {
|
|
79
79
|
jsonReply(res, 400, { ok: false, error: "Cannot determine cwd for session" });
|
package/src/feishu-api.ts
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
CURSOR_SESSION_PREFIX,
|
|
15
15
|
CODEX_SESSION_PREFIX,
|
|
16
16
|
ts,
|
|
17
|
+
resolveDefaultAgentTool,
|
|
18
|
+
toolDisplayName,
|
|
17
19
|
} from "./config.ts";
|
|
18
20
|
import { applyPrivacy } from "./privacy.ts";
|
|
19
21
|
import { buildHelpCard } from "./cards.ts";
|
|
@@ -950,7 +952,10 @@ export async function sendRestartCard(token: string): Promise<void> {
|
|
|
950
952
|
|
|
951
953
|
console.log(`[${ts()}] [RESTART] Latest active chat: ${latestChatId} (mtime=${new Date(latestTime).toISOString()})`);
|
|
952
954
|
|
|
953
|
-
const restartCard = buildHelpCard("", {
|
|
955
|
+
const restartCard = buildHelpCard("", {
|
|
956
|
+
greeting: "Bot 已启动完成,可以继续使用。",
|
|
957
|
+
defaultToolLabel: toolDisplayName(resolveDefaultAgentTool()),
|
|
958
|
+
});
|
|
954
959
|
await fetch(`${BASE_URL}/im/v1/messages?receive_id_type=chat_id`, {
|
|
955
960
|
method: "POST",
|
|
956
961
|
headers: {
|