converse-mcp-server 2.0.2-beta.1 → 2.0.2-beta.4
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/providers/codex.js +39 -45
package/package.json
CHANGED
package/src/providers/codex.js
CHANGED
|
@@ -305,71 +305,65 @@ export const codexProvider = {
|
|
|
305
305
|
debugLog('[Codex] Using reasoning_effort:', reasoning_effort);
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
//
|
|
308
|
+
// WORKAROUND: SDK's thread.run() hangs due to missing break after turn.completed
|
|
309
|
+
// Always use streaming internally, consume synchronously when stream=false
|
|
309
310
|
if (stream) {
|
|
310
|
-
debugLog('[Codex] invoke: Returning streaming generator');
|
|
311
|
-
|
|
312
|
-
debugLog('[Codex] invoke: Generator created, returning it');
|
|
313
|
-
return generator;
|
|
311
|
+
debugLog('[Codex] invoke: Returning streaming generator (async mode)');
|
|
312
|
+
return createStreamingGenerator(thread, prompt, signal, runOptions);
|
|
314
313
|
}
|
|
315
314
|
|
|
316
|
-
//
|
|
315
|
+
// Synchronous mode: consume streaming internally and return complete response
|
|
316
|
+
debugLog('[Codex] invoke: Using streaming internally for sync execution (SDK bug workaround)');
|
|
317
317
|
const startTime = Date.now();
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
turn = await thread.run(prompt);
|
|
339
|
-
const retryDuration = Date.now() - retryStartTime;
|
|
340
|
-
debugLog('[Codex] invoke: thread.run() retry returned', { retryDuration });
|
|
341
|
-
} else {
|
|
342
|
-
throw error;
|
|
318
|
+
const generator = createStreamingGenerator(thread, prompt, signal, runOptions);
|
|
319
|
+
|
|
320
|
+
let content = '';
|
|
321
|
+
let usage = null;
|
|
322
|
+
let threadIdFromStream = null;
|
|
323
|
+
|
|
324
|
+
debugLog('[Codex] invoke: Consuming stream synchronously...');
|
|
325
|
+
for await (const event of generator) {
|
|
326
|
+
debugLog('[Codex] invoke: Sync consume event', { type: event?.type });
|
|
327
|
+
|
|
328
|
+
if (event?.type === 'thread.started') {
|
|
329
|
+
threadIdFromStream = event.thread_id;
|
|
330
|
+
} else if (event?.type === 'item.completed' && event.item?.type === 'agent_message') {
|
|
331
|
+
content += event.item.text || '';
|
|
332
|
+
} else if (event?.type === 'turn.completed') {
|
|
333
|
+
usage = event.usage;
|
|
334
|
+
debugLog('[Codex] invoke: turn.completed received in sync mode');
|
|
335
|
+
break; // Exit after turn.completed
|
|
336
|
+
} else if (event?.type === 'turn.failed') {
|
|
337
|
+
throw new CodexProviderError(event.error?.message || 'Turn failed', 'TURN_FAILED');
|
|
343
338
|
}
|
|
344
339
|
}
|
|
345
|
-
const responseTime = Date.now() - startTime;
|
|
346
|
-
debugLog('[Codex] invoke: thread.run() completed', { responseTime });
|
|
347
340
|
|
|
348
|
-
|
|
349
|
-
|
|
341
|
+
const responseTime = Date.now() - startTime;
|
|
342
|
+
debugLog('[Codex] invoke: Sync execution completed', {
|
|
350
343
|
responseTime,
|
|
351
|
-
|
|
352
|
-
|
|
344
|
+
contentLength: content.length,
|
|
345
|
+
hasUsage: !!usage
|
|
353
346
|
});
|
|
354
347
|
|
|
355
348
|
return {
|
|
356
|
-
content
|
|
349
|
+
content,
|
|
357
350
|
stop_reason: StopReasons.STOP,
|
|
358
|
-
rawResponse:
|
|
351
|
+
rawResponse: { content, usage },
|
|
359
352
|
metadata: {
|
|
360
353
|
provider: 'codex',
|
|
361
354
|
model,
|
|
362
|
-
threadId: thread.id,
|
|
363
|
-
usage:
|
|
364
|
-
input_tokens:
|
|
365
|
-
output_tokens:
|
|
366
|
-
total_tokens: (
|
|
367
|
-
cached_input_tokens:
|
|
355
|
+
threadId: threadIdFromStream || thread.id,
|
|
356
|
+
usage: usage ? {
|
|
357
|
+
input_tokens: usage.input_tokens || 0,
|
|
358
|
+
output_tokens: usage.output_tokens || 0,
|
|
359
|
+
total_tokens: (usage.input_tokens || 0) + (usage.output_tokens || 0),
|
|
360
|
+
cached_input_tokens: usage.cached_input_tokens || 0
|
|
368
361
|
} : null,
|
|
369
362
|
response_time_ms: responseTime,
|
|
370
363
|
finish_reason: 'stop'
|
|
371
364
|
}
|
|
372
365
|
};
|
|
366
|
+
|
|
373
367
|
} catch (error) {
|
|
374
368
|
debugError('[Codex] Execution error', error);
|
|
375
369
|
|