linco-connect 1.0.5 → 1.0.7
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/agents/codex.js +22 -9
package/package.json
CHANGED
package/src/agents/codex.js
CHANGED
|
@@ -43,6 +43,7 @@ function runAppServerTurn(input, ws, session, config) {
|
|
|
43
43
|
session.isTurnActive = true;
|
|
44
44
|
session.currentInputForNoOutput = input;
|
|
45
45
|
session.sawPartialAssistantText = false;
|
|
46
|
+
session.codexAssistantEnded = false;
|
|
46
47
|
resetCodexAssistantText(session);
|
|
47
48
|
session._lastWs = ws;
|
|
48
49
|
session._lastConfig = config;
|
|
@@ -257,6 +258,13 @@ function startNewThread(session, agentConfig) {
|
|
|
257
258
|
});
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
function sendCodexAssistantEnd(ws, session) {
|
|
262
|
+
if (session.codexAssistantEnded) return;
|
|
263
|
+
session.codexAssistantEnded = true;
|
|
264
|
+
flushCodexAssistantText(ws, session);
|
|
265
|
+
send(ws, 'assistant_end', {});
|
|
266
|
+
}
|
|
267
|
+
|
|
260
268
|
function clearTurnState(session) {
|
|
261
269
|
flushCodexAssistantText(session._lastWs, session);
|
|
262
270
|
session.isTurnActive = false;
|
|
@@ -275,6 +283,7 @@ function ensureCodexStreamState(session) {
|
|
|
275
283
|
}
|
|
276
284
|
|
|
277
285
|
function appendCodexAssistantText(text, ws, session, ensureAssistantStarted) {
|
|
286
|
+
if (session.codexAssistantEnded) return;
|
|
278
287
|
const state = ensureCodexStreamState(session);
|
|
279
288
|
state.onStart = ensureAssistantStarted;
|
|
280
289
|
appendTextStream(text, ws, state);
|
|
@@ -529,21 +538,21 @@ function handleAppServerMessage(message, session) {
|
|
|
529
538
|
if (text && !session.sawPartialAssistantText) {
|
|
530
539
|
appendCodexAssistantText(text, ws, session, () => send(ws, 'assistant_start', {}));
|
|
531
540
|
}
|
|
532
|
-
// Safety fallback: if turn/completed doesn't
|
|
533
|
-
// clear isTurnActive so the next message doesn't get stuck.
|
|
541
|
+
// Safety fallback: if turn/completed never arrives, clear isTurnActive so the next message doesn't get stuck.
|
|
534
542
|
if (session.turnCompletedTimerId) clearTimeout(session.turnCompletedTimerId);
|
|
535
543
|
session.turnCompletedTimerId = setTimeout(() => {
|
|
536
544
|
if (session.isTurnActive) {
|
|
537
545
|
session.isTurnActive = false;
|
|
538
546
|
session.currentInputForNoOutput = null;
|
|
539
547
|
if (session.sawPartialAssistantText) {
|
|
540
|
-
|
|
541
|
-
|
|
548
|
+
sendCodexAssistantEnd(ws, session);
|
|
549
|
+
} else {
|
|
550
|
+
sendSystem(ws, 'Codex 本次执行没有输出。');
|
|
542
551
|
}
|
|
543
552
|
const cfg = session._lastConfig;
|
|
544
553
|
if (cfg) drainQueue(ws, session, cfg);
|
|
545
554
|
}
|
|
546
|
-
},
|
|
555
|
+
}, 10000);
|
|
547
556
|
return;
|
|
548
557
|
}
|
|
549
558
|
|
|
@@ -555,8 +564,7 @@ function handleAppServerMessage(message, session) {
|
|
|
555
564
|
updateCodexSessionStats(session, params);
|
|
556
565
|
clearTurnState(session);
|
|
557
566
|
if (session.sawPartialAssistantText) {
|
|
558
|
-
|
|
559
|
-
send(ws, 'assistant_end', {});
|
|
567
|
+
sendCodexAssistantEnd(ws, session);
|
|
560
568
|
} else {
|
|
561
569
|
sendSystem(ws, 'Codex 本次执行没有输出。');
|
|
562
570
|
}
|
|
@@ -636,13 +644,17 @@ function updateCodexSessionStats(session, params = {}) {
|
|
|
636
644
|
updateAgentSessionHistory(session);
|
|
637
645
|
}
|
|
638
646
|
|
|
647
|
+
function isCodexAssistantMessageType(type) {
|
|
648
|
+
return ['agentMessage', 'agent_message', 'message'].includes(type);
|
|
649
|
+
}
|
|
650
|
+
|
|
639
651
|
function extractFinalText(params) {
|
|
640
652
|
if (typeof params.text === 'string') return params.text;
|
|
641
653
|
if (typeof params.delta === 'string') return params.delta;
|
|
642
654
|
if (Array.isArray(params.content)) {
|
|
643
655
|
return params.content.map(item => typeof item === 'string' ? item : item?.text || '').join('');
|
|
644
656
|
}
|
|
645
|
-
if (params.item?.type
|
|
657
|
+
if (isCodexAssistantMessageType(params.item?.type) && typeof params.item.text === 'string') {
|
|
646
658
|
return params.item.text;
|
|
647
659
|
}
|
|
648
660
|
return '';
|
|
@@ -725,6 +737,7 @@ function runExecTurn(input, ws, session, config) {
|
|
|
725
737
|
session.isTurnActive = true;
|
|
726
738
|
session.currentInputForNoOutput = input;
|
|
727
739
|
session.sawPartialAssistantText = false;
|
|
740
|
+
session.codexAssistantEnded = false;
|
|
728
741
|
resetCodexAssistantText(session);
|
|
729
742
|
|
|
730
743
|
const agentConfig = config.agents?.codex || {};
|
|
@@ -856,7 +869,7 @@ function extractText(event) {
|
|
|
856
869
|
if (Array.isArray(event.content)) {
|
|
857
870
|
return event.content.map(item => typeof item === 'string' ? item : item?.text || '').join('');
|
|
858
871
|
}
|
|
859
|
-
if (typeof event.item?.text === 'string' &&
|
|
872
|
+
if (typeof event.item?.text === 'string' && isCodexAssistantMessageType(event.item.type)) {
|
|
860
873
|
return event.item.text;
|
|
861
874
|
}
|
|
862
875
|
if (event.item?.type === 'message' && Array.isArray(event.item.content)) {
|