linco-connect 1.1.6 → 1.1.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 +83 -19
package/package.json
CHANGED
package/src/agents/codex.js
CHANGED
|
@@ -54,6 +54,7 @@ function runAppServerTurn(input, ws, session, config) {
|
|
|
54
54
|
session.sawPartialAssistantText = false;
|
|
55
55
|
session.codexAssistantEnded = false;
|
|
56
56
|
session.codexEmittedAgentMessageIds = new Set();
|
|
57
|
+
session.codexToolStates = new Map();
|
|
57
58
|
resetCodexAssistantText(session);
|
|
58
59
|
session._lastWs = ws;
|
|
59
60
|
session._lastConfig = config;
|
|
@@ -358,6 +359,68 @@ function hasCodexAgentMessageEmitted(session, itemId) {
|
|
|
358
359
|
return Boolean(id && session.codexEmittedAgentMessageIds?.has(id));
|
|
359
360
|
}
|
|
360
361
|
|
|
362
|
+
function ensureCodexToolStates(session) {
|
|
363
|
+
if (!(session.codexToolStates instanceof Map)) {
|
|
364
|
+
session.codexToolStates = new Map();
|
|
365
|
+
}
|
|
366
|
+
return session.codexToolStates;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function codexToolStateFor(session, id) {
|
|
370
|
+
const toolId = String(id || '').trim();
|
|
371
|
+
if (!toolId) return null;
|
|
372
|
+
const states = ensureCodexToolStates(session);
|
|
373
|
+
return states.get(toolId) || null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function setCodexToolState(session, id, next) {
|
|
377
|
+
const toolId = String(id || '').trim();
|
|
378
|
+
if (!toolId) return;
|
|
379
|
+
const states = ensureCodexToolStates(session);
|
|
380
|
+
const previous = states.get(toolId) || {};
|
|
381
|
+
states.set(toolId, {
|
|
382
|
+
...previous,
|
|
383
|
+
...next,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function emitCodexToolCall(ws, session, tool) {
|
|
388
|
+
if (!ws) return false;
|
|
389
|
+
const id = String(tool.id || '').trim();
|
|
390
|
+
const existing = codexToolStateFor(session, id);
|
|
391
|
+
if (existing?.phase === 'completed' || existing?.phase === 'started') {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
const name = String(tool.name || existing?.name || 'tool').trim() || 'tool';
|
|
395
|
+
const input = tool.input ?? existing?.input ?? '';
|
|
396
|
+
send(ws, 'tool_call', { id, name, input });
|
|
397
|
+
setCodexToolState(session, id, { phase: 'started', name, input });
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function emitCodexToolResult(ws, session, tool) {
|
|
402
|
+
if (!ws) return false;
|
|
403
|
+
const id = String(tool.id || '').trim();
|
|
404
|
+
const existing = codexToolStateFor(session, id);
|
|
405
|
+
if (existing?.phase === 'completed') return false;
|
|
406
|
+
|
|
407
|
+
const name = String(tool.name || existing?.name || 'tool').trim() || 'tool';
|
|
408
|
+
const input = tool.input ?? existing?.input ?? '';
|
|
409
|
+
if (id && existing?.phase !== 'started') {
|
|
410
|
+
emitCodexToolCall(ws, session, { id, name, input });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const output = tool.output ?? '';
|
|
414
|
+
send(ws, 'tool_result', { id, output });
|
|
415
|
+
setCodexToolState(session, id, {
|
|
416
|
+
phase: 'completed',
|
|
417
|
+
name,
|
|
418
|
+
input,
|
|
419
|
+
output,
|
|
420
|
+
});
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
361
424
|
function shouldAppendCompletedAgentMessage(session, params) {
|
|
362
425
|
const itemId = codexAgentMessageId(params);
|
|
363
426
|
if (itemId) return !hasCodexAgentMessageEmitted(session, itemId);
|
|
@@ -514,14 +577,12 @@ function handleServerRequest(message, session) {
|
|
|
514
577
|
|
|
515
578
|
// Tool call from server request
|
|
516
579
|
if (method === 'item/tool/call') {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
});
|
|
524
|
-
}
|
|
580
|
+
const toolName = params.name || params.tool || '';
|
|
581
|
+
emitCodexToolCall(ws, session, {
|
|
582
|
+
id: String(message.id),
|
|
583
|
+
name: toolName,
|
|
584
|
+
input: JSON.stringify(params.input || {}).slice(0, 300),
|
|
585
|
+
});
|
|
525
586
|
sendJsonRpc(session.codexAppServer, {
|
|
526
587
|
jsonrpc: '2.0',
|
|
527
588
|
id: message.id,
|
|
@@ -605,16 +666,19 @@ function handleAppServerMessage(message, session) {
|
|
|
605
666
|
session._log?.info('codex item completed', { itemType, item: summarizeCodexItemForLog(params.item) });
|
|
606
667
|
if (itemType === 'toolCall' || itemType === 'commandExecution' || itemType === 'webSearch') {
|
|
607
668
|
const itemId = params.item?.id || params.itemId || '';
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
669
|
+
const isCommand = itemType === 'commandExecution';
|
|
670
|
+
const isWebSearch = itemType === 'webSearch';
|
|
671
|
+
const toolName = isCommand ? 'exec' : isWebSearch ? 'webSearch' : (params.item?.name || params.item?.tool || '');
|
|
672
|
+
const toolInput = isCommand
|
|
673
|
+
? (params.item?.command || '')
|
|
674
|
+
: isWebSearch
|
|
675
|
+
? (params.item?.query || params.item?.input || params.item?.arguments || {})
|
|
676
|
+
: (params.item?.input || params.item?.arguments || {});
|
|
615
677
|
const output = params.item?.output || params.item?.result || params.item?.results || params.output || params.result || '';
|
|
616
|
-
|
|
678
|
+
emitCodexToolResult(ws, session, {
|
|
617
679
|
id: itemId,
|
|
680
|
+
name: toolName,
|
|
681
|
+
input: typeof toolInput === 'string' ? toolInput : JSON.stringify(toolInput).slice(0, 300),
|
|
618
682
|
output: typeof output === 'string' ? output : JSON.stringify(output).slice(0, 1000),
|
|
619
683
|
});
|
|
620
684
|
return;
|
|
@@ -652,7 +716,7 @@ function handleAppServerMessage(message, session) {
|
|
|
652
716
|
if (method === 'tool/start' || method === 'tool_call') {
|
|
653
717
|
const toolName = params.name || params.tool || '';
|
|
654
718
|
if (toolName) {
|
|
655
|
-
|
|
719
|
+
emitCodexToolCall(ws, session, {
|
|
656
720
|
id: params.id || params.toolId || '',
|
|
657
721
|
name: toolName,
|
|
658
722
|
input: params.input || params.arguments || {},
|
|
@@ -662,7 +726,7 @@ function handleAppServerMessage(message, session) {
|
|
|
662
726
|
}
|
|
663
727
|
|
|
664
728
|
if (method === 'tool/completed' || method === 'tool_result') {
|
|
665
|
-
|
|
729
|
+
emitCodexToolResult(ws, session, {
|
|
666
730
|
id: params.id || params.toolId || '',
|
|
667
731
|
output: params.output || params.result || '',
|
|
668
732
|
});
|
|
@@ -683,7 +747,7 @@ function handleAppServerMessage(message, session) {
|
|
|
683
747
|
: (params.item?.input || params.item?.arguments || {});
|
|
684
748
|
const itemId = params.item?.id || params.itemId || '';
|
|
685
749
|
if (toolName) {
|
|
686
|
-
|
|
750
|
+
emitCodexToolCall(ws, session, {
|
|
687
751
|
id: itemId,
|
|
688
752
|
name: toolName,
|
|
689
753
|
input: typeof toolInput === 'string' ? toolInput : JSON.stringify(toolInput).slice(0, 300),
|