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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "converse-mcp-server",
3
- "version": "2.0.2-beta.1",
3
+ "version": "2.0.2-beta.4",
4
4
  "description": "Converse MCP Server - Converse with other LLMs with chat and consensus tools",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -305,71 +305,65 @@ export const codexProvider = {
305
305
  debugLog('[Codex] Using reasoning_effort:', reasoning_effort);
306
306
  }
307
307
 
308
- // Use streaming when requested
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
- const generator = createStreamingGenerator(thread, prompt, signal, runOptions);
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
- // Non-streaming execution (disabled due to SDK bug - see above)
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
- debugLog('[Codex] invoke: Starting non-streaming execution with thread.run()', {
319
- threadId: thread.id,
320
- hasRunOptions: !!Object.keys(runOptions).length,
321
- promptLength: prompt.length
322
- });
323
-
324
- // Try with reasoning_effort, fallback without if SDK doesn't support it
325
- let turn;
326
- try {
327
- debugLog('[Codex] invoke: Calling thread.run() (awaiting response)...');
328
- const runStartTime = Date.now();
329
- turn = await thread.run(prompt, runOptions);
330
- const runDuration = Date.now() - runStartTime;
331
- debugLog('[Codex] invoke: thread.run() returned', { runDuration, hasTurn: !!turn });
332
- } catch (error) {
333
- debugLog('[Codex] invoke: thread.run() threw error', { message: error.message });
334
- if (reasoning_effort && (error.message?.includes('reasoningEffort') || error.message?.includes('unknown option'))) {
335
- debugLog('[Codex] reasoning_effort not supported by this SDK version, retrying without it');
336
- debugLog('[Codex] invoke: Retrying thread.run() without reasoning_effort...');
337
- const retryStartTime = Date.now();
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
- debugLog('[Codex] Non-streaming execution completed', {
349
- threadId: thread.id,
341
+ const responseTime = Date.now() - startTime;
342
+ debugLog('[Codex] invoke: Sync execution completed', {
350
343
  responseTime,
351
- usage: turn.usage,
352
- hasContent: !!turn.finalResponse
344
+ contentLength: content.length,
345
+ hasUsage: !!usage
353
346
  });
354
347
 
355
348
  return {
356
- content: turn.finalResponse || '',
349
+ content,
357
350
  stop_reason: StopReasons.STOP,
358
- rawResponse: turn,
351
+ rawResponse: { content, usage },
359
352
  metadata: {
360
353
  provider: 'codex',
361
354
  model,
362
- threadId: thread.id, // Store for continuation
363
- usage: turn.usage ? {
364
- input_tokens: turn.usage.input_tokens || 0,
365
- output_tokens: turn.usage.output_tokens || 0,
366
- total_tokens: (turn.usage.input_tokens || 0) + (turn.usage.output_tokens || 0),
367
- cached_input_tokens: turn.usage.cached_input_tokens || 0
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