@wu529778790/open-im 1.8.1-beta.4 → 1.8.1-beta.5
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.
|
@@ -46,7 +46,7 @@ model, permissionMode) {
|
|
|
46
46
|
// 可以添加其他选项,如 hooks, allowedTools 等
|
|
47
47
|
};
|
|
48
48
|
const baseUrl = process.env.ANTHROPIC_BASE_URL ?? '(default)';
|
|
49
|
-
log.info(`[
|
|
49
|
+
log.info(`[V2] getOrCreateSession model param=${String(model ?? '')} resolved=${resolvedModel} baseUrl=${baseUrl}`);
|
|
50
50
|
let session;
|
|
51
51
|
if (sessionId) {
|
|
52
52
|
// 尝试恢复已有会话
|
|
@@ -99,9 +99,19 @@ export class ClaudeSDKAdapter {
|
|
|
99
99
|
activeSessions.clear();
|
|
100
100
|
}
|
|
101
101
|
run(prompt, sessionId, workDir, callbacks, options) {
|
|
102
|
+
log.info(`[V2] run() entry model=${String(options?.model ?? '')} baseUrl=${process.env.ANTHROPIC_BASE_URL ?? '(default)'}`);
|
|
102
103
|
const abortController = new AbortController();
|
|
103
104
|
let streamClosed = false;
|
|
104
105
|
let actualSessionId;
|
|
106
|
+
let runSettled = false;
|
|
107
|
+
let timeoutId = null;
|
|
108
|
+
const timeoutMs = options?.timeoutMs ?? 600_000;
|
|
109
|
+
const clearRunTimeout = () => {
|
|
110
|
+
if (timeoutId !== null) {
|
|
111
|
+
clearTimeout(timeoutId);
|
|
112
|
+
timeoutId = null;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
105
115
|
const permissionMode = options?.skipPermissions
|
|
106
116
|
? 'bypassPermissions'
|
|
107
117
|
: options?.permissionMode === 'acceptEdits'
|
|
@@ -110,6 +120,15 @@ export class ClaudeSDKAdapter {
|
|
|
110
120
|
? 'plan'
|
|
111
121
|
: 'default';
|
|
112
122
|
const runSession = async () => {
|
|
123
|
+
timeoutId = setTimeout(() => {
|
|
124
|
+
if (runSettled)
|
|
125
|
+
return;
|
|
126
|
+
runSettled = true;
|
|
127
|
+
clearRunTimeout();
|
|
128
|
+
log.warn(`[ClaudeSDK] Request timeout after ${timeoutMs}ms`);
|
|
129
|
+
abortController.abort();
|
|
130
|
+
callbacks.onError(`请求超时(${Math.round(timeoutMs / 1000)}s),请重试或缩短问题。`);
|
|
131
|
+
}, timeoutMs);
|
|
113
132
|
try {
|
|
114
133
|
// 检查环境变量
|
|
115
134
|
const hasApiKey = !!process.env.ANTHROPIC_API_KEY;
|
|
@@ -118,7 +137,7 @@ export class ClaudeSDKAdapter {
|
|
|
118
137
|
log.warn('Claude SDK: No API credentials found in environment variables');
|
|
119
138
|
}
|
|
120
139
|
log.info(`[V2] Session: ${sessionId ?? 'new'}, prompt="${prompt.slice(0, 50)}..."`);
|
|
121
|
-
log.info(`
|
|
140
|
+
log.info(`[V2] model param=${String(options?.model ?? '')} baseUrl=${process.env.ANTHROPIC_BASE_URL ?? '(default)'}`);
|
|
122
141
|
// 获取或创建会话
|
|
123
142
|
const { session } = await getOrCreateSession(sessionId, workDir, options?.model, permissionMode);
|
|
124
143
|
// 发送用户消息
|
|
@@ -185,6 +204,8 @@ export class ClaudeSDKAdapter {
|
|
|
185
204
|
log.info(`[V2] Result: subtype=${m.subtype}, num_turns=${m.num_turns}, sessionId=${actualSessionId ?? 'unknown'}`);
|
|
186
205
|
// 检查会话错误
|
|
187
206
|
if (!success) {
|
|
207
|
+
runSettled = true;
|
|
208
|
+
clearRunTimeout();
|
|
188
209
|
const noConvErr = errs.find((e) => e.includes('No conversation found') || e.includes('session not found'));
|
|
189
210
|
if (noConvErr) {
|
|
190
211
|
log.warn(`Session ${actualSessionId} not found, may need to create new one`);
|
|
@@ -211,6 +232,8 @@ export class ClaudeSDKAdapter {
|
|
|
211
232
|
result.accumulated = accumulated;
|
|
212
233
|
result.result = accumulated;
|
|
213
234
|
}
|
|
235
|
+
runSettled = true;
|
|
236
|
+
clearRunTimeout();
|
|
214
237
|
callbacks.onComplete(result);
|
|
215
238
|
return;
|
|
216
239
|
}
|
|
@@ -218,6 +241,8 @@ export class ClaudeSDKAdapter {
|
|
|
218
241
|
// 如果流正常结束但没有收到 result 消息
|
|
219
242
|
if (!streamClosed && accumulated) {
|
|
220
243
|
log.info('Stream ended without result message, using accumulated text');
|
|
244
|
+
runSettled = true;
|
|
245
|
+
clearRunTimeout();
|
|
221
246
|
callbacks.onComplete({
|
|
222
247
|
success: true,
|
|
223
248
|
result: accumulated,
|
|
@@ -237,8 +262,11 @@ export class ClaudeSDKAdapter {
|
|
|
237
262
|
catch (err) {
|
|
238
263
|
if (abortController.signal.aborted) {
|
|
239
264
|
log.info('Session run aborted');
|
|
265
|
+
clearRunTimeout();
|
|
240
266
|
return;
|
|
241
267
|
}
|
|
268
|
+
runSettled = true;
|
|
269
|
+
clearRunTimeout();
|
|
242
270
|
const errorObj = err;
|
|
243
271
|
const msg = errorObj.message || String(err);
|
|
244
272
|
log.error(`Claude SDK V2 error: ${msg}`);
|
package/dist/telegram/client.js
CHANGED
|
@@ -20,10 +20,30 @@ export async function initTelegram(config, setupHandlers) {
|
|
|
20
20
|
setupHandlers(bot);
|
|
21
21
|
const me = (await bot.telegram.getMe());
|
|
22
22
|
botUsername = me.username;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const launchWithRetry = async (attempt = 1) => {
|
|
24
|
+
try {
|
|
25
|
+
await bot.launch();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
log.error("Telegram polling error:", err);
|
|
29
|
+
try {
|
|
30
|
+
bot.stop("Telegram polling error");
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
/* ignore */
|
|
34
|
+
}
|
|
35
|
+
const maxAttempts = 10;
|
|
36
|
+
const delayMs = Math.min(5000 * attempt, 60000);
|
|
37
|
+
if (attempt < maxAttempts) {
|
|
38
|
+
log.info(`Telegram reconnect in ${Math.round(delayMs / 1000)}s (attempt ${attempt}/${maxAttempts})`);
|
|
39
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
40
|
+
return launchWithRetry(attempt + 1);
|
|
41
|
+
}
|
|
42
|
+
log.error("Telegram gave up reconnecting, exiting");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
void launchWithRetry();
|
|
27
47
|
log.info("Telegram bot launched");
|
|
28
48
|
}
|
|
29
49
|
export function stopTelegram() {
|