@yeaft/webchat-agent 0.0.15 → 0.0.16
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/claude.js +7 -3
- package/connection.js +2 -2
- package/conversation.js +1 -1
- package/package.json +1 -1
package/claude.js
CHANGED
|
@@ -346,12 +346,13 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
|
|
|
346
346
|
// stream-json 模式下 Claude 进程是持久运行的,for-await 在 result 后继续等待
|
|
347
347
|
// 不清空 state.query 和 state.inputStream,下次用户消息直接通过同一个 inputStream 发送
|
|
348
348
|
state.turnResultReceived = true;
|
|
349
|
-
sendOutput(conversationId, message);
|
|
350
|
-
|
|
351
349
|
resultHandled = true;
|
|
352
350
|
state.turnActive = false;
|
|
353
351
|
|
|
354
|
-
|
|
352
|
+
// ★ await 确保 result 和 turn_completed 消息确实发送成功
|
|
353
|
+
// 不 await 会导致 encrypt 失败时消息静默丢失,前端卡在"思考中"
|
|
354
|
+
await sendOutput(conversationId, message);
|
|
355
|
+
await ctx.sendToServer({
|
|
355
356
|
type: 'turn_completed',
|
|
356
357
|
conversationId,
|
|
357
358
|
claudeSessionId: state.claudeSessionId,
|
|
@@ -369,6 +370,9 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
|
|
|
369
370
|
} catch (error) {
|
|
370
371
|
if (error.name === 'AbortError') {
|
|
371
372
|
console.log(`[SDK] Query aborted for ${conversationId}`);
|
|
373
|
+
} else if (resultHandled) {
|
|
374
|
+
// Turn 已正常完成,进程退出产生的 error 不发送给用户
|
|
375
|
+
console.warn(`[SDK] Ignoring post-result error for ${conversationId}: ${error.message}`);
|
|
372
376
|
} else {
|
|
373
377
|
console.error(`[SDK] Error for ${conversationId}:`, error.message);
|
|
374
378
|
sendError(conversationId, error.message);
|
package/connection.js
CHANGED
|
@@ -273,7 +273,7 @@ async function handleMessage(msg) {
|
|
|
273
273
|
const pkgName = ctx.pkgName || '@yeaft/webchat-agent';
|
|
274
274
|
// Check latest version (async to avoid blocking heartbeat)
|
|
275
275
|
const latestVersion = await new Promise((resolve, reject) => {
|
|
276
|
-
execFile('npm', ['view', pkgName, 'version'], { stdio: 'pipe' }, (err, stdout) => {
|
|
276
|
+
execFile('npm', ['view', pkgName, 'version'], { stdio: 'pipe', shell: true }, (err, stdout) => {
|
|
277
277
|
if (err) reject(err); else resolve(stdout.toString().trim());
|
|
278
278
|
});
|
|
279
279
|
});
|
|
@@ -285,7 +285,7 @@ async function handleMessage(msg) {
|
|
|
285
285
|
console.log(`[Agent] Upgrading from ${ctx.agentVersion} to ${latestVersion}...`);
|
|
286
286
|
// Use async execFile to avoid blocking event loop (heartbeat must keep running)
|
|
287
287
|
await new Promise((resolve, reject) => {
|
|
288
|
-
execFile('npm', ['install', '-g', `${pkgName}@latest`], { stdio: 'pipe' }, (err) => {
|
|
288
|
+
execFile('npm', ['install', '-g', `${pkgName}@latest`], { stdio: 'pipe', shell: true }, (err) => {
|
|
289
289
|
if (err) reject(err); else resolve();
|
|
290
290
|
});
|
|
291
291
|
});
|
package/conversation.js
CHANGED