chatccc 0.2.134 → 0.2.135
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 +1 -1
- package/src/adapters/claude-adapter.ts +13 -11
package/package.json
CHANGED
|
@@ -333,6 +333,7 @@ class ClaudeAdapter implements ToolAdapter {
|
|
|
333
333
|
async createSession(cwd: string): Promise<CreateSessionResult> {
|
|
334
334
|
logMcpConfig();
|
|
335
335
|
const abortController = new AbortController();
|
|
336
|
+
let sessionId: string | undefined;
|
|
336
337
|
const stream = query({
|
|
337
338
|
prompt: "ok",
|
|
338
339
|
options: buildSdkOptions({
|
|
@@ -351,22 +352,21 @@ class ClaudeAdapter implements ToolAdapter {
|
|
|
351
352
|
try {
|
|
352
353
|
for await (const raw of stream) {
|
|
353
354
|
const msg = toMessageLike(raw);
|
|
354
|
-
if (msg.session_id) {
|
|
355
|
-
|
|
355
|
+
if (msg.session_id && !sessionId) {
|
|
356
|
+
sessionId = msg.session_id;
|
|
356
357
|
await this.metaStore.set(sessionId, {
|
|
357
358
|
cwd: msg.cwd ?? cwd,
|
|
358
359
|
model: msg.model,
|
|
359
360
|
}).catch(() => {});
|
|
360
361
|
const ts = new Date().toISOString();
|
|
361
362
|
console.log(`[${ts}] [CLAUDE-SDK] createSession: ${sessionId}`);
|
|
362
|
-
return { sessionId };
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
} finally {
|
|
366
|
-
abortController.abort();
|
|
367
366
|
stream.close();
|
|
368
367
|
}
|
|
369
368
|
|
|
369
|
+
if (sessionId) return { sessionId };
|
|
370
370
|
throw new Error("No session ID in Claude init event");
|
|
371
371
|
}
|
|
372
372
|
|
|
@@ -380,6 +380,7 @@ class ClaudeAdapter implements ToolAdapter {
|
|
|
380
380
|
const abortController = new AbortController();
|
|
381
381
|
const removeAbortListener = bridgeAbortSignal(signal, abortController);
|
|
382
382
|
if (abortController.signal.aborted) return;
|
|
383
|
+
let aborted = false;
|
|
383
384
|
|
|
384
385
|
const stream = query({
|
|
385
386
|
prompt: buildClaudePromptText(userText),
|
|
@@ -400,7 +401,10 @@ class ClaudeAdapter implements ToolAdapter {
|
|
|
400
401
|
|
|
401
402
|
try {
|
|
402
403
|
for await (const raw of stream) {
|
|
403
|
-
if (abortController.signal.aborted)
|
|
404
|
+
if (abortController.signal.aborted) {
|
|
405
|
+
aborted = true;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
404
408
|
|
|
405
409
|
const msg = toMessageLike(raw);
|
|
406
410
|
if (msg.type === "system" && msg.subtype === "init" && msg.session_id) {
|
|
@@ -414,15 +418,13 @@ class ClaudeAdapter implements ToolAdapter {
|
|
|
414
418
|
|
|
415
419
|
const normalized = normalizeSdkMessage(msg);
|
|
416
420
|
if (normalized) yield normalized;
|
|
417
|
-
|
|
418
|
-
if (msg.type === "result") {
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
421
|
}
|
|
422
422
|
} finally {
|
|
423
423
|
removeAbortListener?.();
|
|
424
|
-
abortController.
|
|
425
|
-
|
|
424
|
+
if (aborted || abortController.signal.aborted) {
|
|
425
|
+
abortController.abort();
|
|
426
|
+
stream.close();
|
|
427
|
+
}
|
|
426
428
|
}
|
|
427
429
|
}
|
|
428
430
|
|