@causyne/agent 1.20.124 → 1.20.127

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.
Files changed (235) hide show
  1. package/bin/causyne.js +1 -1
  2. package/package.json +4 -4
  3. package/src/acp/protocol.ts +19 -1
  4. package/src/acp/server.js +282 -8
  5. package/src/acp/server.ts +284 -8
  6. package/src/agent/abortableDelay.js +2 -2
  7. package/src/agent/abortableDelay.ts +2 -2
  8. package/src/agent/errorClassifier.js +9 -1
  9. package/src/agent/errorClassifier.ts +8 -1
  10. package/src/agentLoop.js +83 -27
  11. package/src/agentLoop.ts +92 -26
  12. package/src/approvalPolicy.js +34 -10
  13. package/src/approvalPolicy.ts +42 -11
  14. package/src/browser/causyneBrowser.js +30 -3
  15. package/src/browser/causyneBrowser.ts +33 -3
  16. package/src/browser/urlPolicy.js +14 -1
  17. package/src/browser/urlPolicy.ts +12 -1
  18. package/src/cliMode.js +21 -9
  19. package/src/cliMode.ts +20 -8
  20. package/src/commands.js +188 -32
  21. package/src/commands.ts +209 -32
  22. package/src/config.js +19 -4
  23. package/src/config.ts +18 -4
  24. package/src/core/contextCompactor.js +54 -7
  25. package/src/core/contextCompactor.ts +63 -7
  26. package/src/core/goalLoop.js +257 -0
  27. package/src/core/goalLoop.ts +310 -0
  28. package/src/entrypoint.js +135 -3
  29. package/src/entrypoint.ts +136 -3
  30. package/src/game/causyneCoreBridge.js +686 -0
  31. package/src/game/causyneCoreBridge.ts +702 -0
  32. package/src/game/gameLauncher.js +287 -0
  33. package/src/game/gameLauncher.ts +352 -0
  34. package/src/game/gameProvisioner.js +425 -0
  35. package/src/game/gameProvisioner.ts +488 -0
  36. package/src/headlessCli.js +19 -12
  37. package/src/headlessCli.ts +22 -8
  38. package/src/infra/atomicWriter.js +40 -4
  39. package/src/infra/atomicWriter.ts +36 -4
  40. package/src/launchIntent.js +73 -3
  41. package/src/launchIntent.ts +76 -3
  42. package/src/lsp/lspClient.js +83 -12
  43. package/src/lsp/lspClient.ts +75 -12
  44. package/src/mcp/mcpRegistry.js +75 -8
  45. package/src/mcp/mcpRegistry.ts +70 -7
  46. package/src/memory/contextBudget.js +2 -0
  47. package/src/memory/contextBudget.ts +1 -0
  48. package/src/modelVariants.js +45 -0
  49. package/src/modelVariants.ts +54 -0
  50. package/src/outputRecovery.js +3 -2
  51. package/src/outputRecovery.ts +4 -2
  52. package/src/permissionPresets.js +327 -0
  53. package/src/permissionPresets.ts +361 -0
  54. package/src/providers/antigravity.js +62 -9
  55. package/src/providers/antigravity.ts +73 -9
  56. package/src/providers/byokHttp.js +7 -1
  57. package/src/providers/byokHttp.ts +6 -1
  58. package/src/providers/byokStream.js +21 -8
  59. package/src/providers/byokStream.ts +17 -7
  60. package/src/providers/dashscope-byok.js +21 -5
  61. package/src/providers/dashscope-byok.ts +29 -11
  62. package/src/providers/moonshot.js +26 -7
  63. package/src/providers/moonshot.ts +34 -13
  64. package/src/providers/muse.js +6 -0
  65. package/src/providers/muse.ts +8 -0
  66. package/src/providers/ollama.js +39 -7
  67. package/src/providers/ollama.ts +36 -7
  68. package/src/providers/openai-compatible.js +16 -3
  69. package/src/providers/openai-compatible.ts +13 -3
  70. package/src/providers/openai.js +62 -4
  71. package/src/providers/openai.ts +50 -4
  72. package/src/providers/openrouter.js +19 -4
  73. package/src/providers/openrouter.ts +21 -4
  74. package/src/providers/qwen-byok.js +21 -5
  75. package/src/providers/qwen-byok.ts +29 -11
  76. package/src/providers/xai.js +26 -10
  77. package/src/providers/xai.ts +34 -16
  78. package/src/reporting.js +4 -2
  79. package/src/reporting.ts +4 -2
  80. package/src/sandbox.js +34 -0
  81. package/src/sandbox.ts +43 -0
  82. package/src/scheduler/scheduler.js +372 -0
  83. package/src/scheduler/scheduler.ts +433 -0
  84. package/src/sessionSearchIndex.js +267 -0
  85. package/src/sessionSearchIndex.ts +311 -0
  86. package/src/skillsManager.js +2 -3
  87. package/src/skillsManager.ts +2 -3
  88. package/src/toolPacks.js +6 -0
  89. package/src/toolPacks.ts +6 -0
  90. package/src/tools/applyPatch.js +1 -1
  91. package/src/tools/applyPatch.ts +1 -1
  92. package/src/tools/generateMediaViaApi.js +4 -3
  93. package/src/tools/generateMediaViaApi.ts +4 -3
  94. package/src/tools/nativeEngine.js +2 -2
  95. package/src/tools/nativeEngine.ts +2 -2
  96. package/src/tools/openSourceToolProvisioner.js +2 -2
  97. package/src/tools/openSourceToolProvisioner.ts +2 -2
  98. package/src/tools/payloadSanitizer.js +0 -1
  99. package/src/tools/payloadSanitizer.ts +0 -1
  100. package/src/tools/pdfReader.js +122 -20
  101. package/src/tools/pdfReader.ts +111 -20
  102. package/src/tools/presentDeliverable.js +103 -0
  103. package/src/tools/presentDeliverable.ts +127 -0
  104. package/src/tools/ptcRuntime.js +444 -0
  105. package/src/tools/ptcRuntime.ts +490 -0
  106. package/src/tools/ptyTerminal.js +1096 -0
  107. package/src/tools/ptyTerminal.ts +1231 -0
  108. package/src/tools/registry.js +21 -12
  109. package/src/tools/registry.ts +21 -12
  110. package/src/tools/toolOutputStore.js +26 -4
  111. package/src/tools/toolOutputStore.ts +22 -4
  112. package/src/tools/webFetch.js +158 -11
  113. package/src/tools/webFetch.ts +145 -11
  114. package/src/tools/webSearch.js +123 -36
  115. package/src/tools/webSearch.ts +124 -33
  116. package/src/tui/banner.js +5 -1
  117. package/src/tui/banner.ts +6 -1
  118. package/src/tui/chatRenderer.js +1 -2
  119. package/src/tui/chatRenderer.ts +1 -2
  120. package/src/tui/completion.js +1 -0
  121. package/src/tui/completion.ts +1 -0
  122. package/src/tui/composerControls.js +111 -27
  123. package/src/tui/composerControls.ts +124 -28
  124. package/src/tui/dialogs.js +3 -16
  125. package/src/tui/dialogs.ts +3 -16
  126. package/src/tui/home.js +1 -0
  127. package/src/tui/home.ts +1 -0
  128. package/src/tui/invocation.js +1 -2
  129. package/src/tui/invocation.ts +1 -2
  130. package/src/tui/modelPicker.js +22 -12
  131. package/src/tui/modelPicker.ts +22 -12
  132. package/src/tui/overlay.js +2 -5
  133. package/src/tui/overlay.ts +2 -5
  134. package/src/tui/prompt.js +6 -4
  135. package/src/tui/prompt.ts +6 -4
  136. package/src/tui/selectList.js +4 -12
  137. package/src/tui/selectList.ts +4 -12
  138. package/src/tui/setup.js +22 -9
  139. package/src/tui/setup.ts +26 -9
  140. package/src/tui/statusLine.ts +2 -0
  141. package/src/web/client/browserPanel.js +702 -0
  142. package/src/web/client/browserPanel.ts +663 -0
  143. package/src/web/client/chatStream.js +309 -0
  144. package/src/web/client/chatStream.ts +289 -0
  145. package/src/web/client/cliPanel.js +165 -0
  146. package/src/web/client/cliPanel.ts +171 -0
  147. package/src/web/client/composer.js +204 -0
  148. package/src/web/client/composer.ts +209 -0
  149. package/src/web/client/diffPanel.js +176 -0
  150. package/src/web/client/diffPanel.ts +203 -0
  151. package/src/web/client/dom.js +220 -0
  152. package/src/web/client/dom.ts +221 -0
  153. package/src/web/client/filesAndCanvas.js +231 -0
  154. package/src/web/client/filesAndCanvas.ts +238 -0
  155. package/src/web/client/gameLauncherUi.js +78 -0
  156. package/src/web/client/gameLauncherUi.ts +78 -0
  157. package/src/web/client/main.js +301 -0
  158. package/src/web/client/main.ts +368 -0
  159. package/src/web/client/markdown.js +364 -0
  160. package/src/web/client/markdown.ts +373 -0
  161. package/src/web/client/modelPicker.js +455 -0
  162. package/src/web/client/modelPicker.ts +451 -0
  163. package/src/web/client/permissionPresetsUi.js +307 -0
  164. package/src/web/client/permissionPresetsUi.ts +333 -0
  165. package/src/web/client/sessions.js +353 -0
  166. package/src/web/client/sessions.ts +372 -0
  167. package/src/web/client/settingsModal.js +191 -0
  168. package/src/web/client/settingsModal.ts +176 -0
  169. package/src/web/client/state.js +250 -0
  170. package/src/web/client/state.ts +233 -0
  171. package/src/web/client/streamSmoother.js +127 -0
  172. package/src/web/client/streamSmoother.ts +119 -0
  173. package/src/web/client/studioLayout.js +54 -0
  174. package/src/web/client/studioLayout.ts +60 -0
  175. package/src/web/client/studioShell.js +327 -0
  176. package/src/web/client/studioShell.ts +340 -0
  177. package/src/web/client/studioStart.js +77 -0
  178. package/src/web/client/studioStart.ts +89 -0
  179. package/src/web/client/terminalPanel.js +357 -0
  180. package/src/web/client/terminalPanel.ts +345 -0
  181. package/src/web/client/turnView.js +934 -0
  182. package/src/web/client/turnView.ts +981 -0
  183. package/src/web/client/types.js +1 -0
  184. package/src/web/client/types.ts +319 -0
  185. package/src/web/client/validators.js +106 -0
  186. package/src/web/client/validators.ts +96 -0
  187. package/src/web/server/activeRuns.js +152 -0
  188. package/src/web/server/activeRuns.ts +171 -0
  189. package/src/web/server/routesBrowser.js +355 -0
  190. package/src/web/server/routesBrowser.ts +386 -0
  191. package/src/web/server/routesChat.js +304 -0
  192. package/src/web/server/routesChat.ts +347 -0
  193. package/src/web/server/routesCore.js +472 -0
  194. package/src/web/server/routesCore.ts +522 -0
  195. package/src/web/server/routesTerminal.js +162 -0
  196. package/src/web/server/routesTerminal.ts +182 -0
  197. package/src/web/server/routesWorkspace.js +510 -0
  198. package/src/web/server/routesWorkspace.ts +546 -0
  199. package/src/web/server/security.js +98 -0
  200. package/src/web/server/security.ts +108 -0
  201. package/src/web/server/sessionTranscript.js +586 -0
  202. package/src/web/server/sessionTranscript.ts +566 -0
  203. package/src/web/server/staticAssets.js +80 -0
  204. package/src/web/server/staticAssets.ts +91 -0
  205. package/src/web/server/types.js +1 -0
  206. package/src/web/server/types.ts +135 -0
  207. package/src/web/server/workspaceFiles.js +368 -0
  208. package/src/web/server/workspaceFiles.ts +363 -0
  209. package/src/web/skybridgeServer.js +76 -2449
  210. package/src/web/skybridgeServer.ts +118 -2600
  211. package/src/web/skybridgeUi.js +16 -450
  212. package/src/web/skybridgeUi.ts +16 -454
  213. package/src/web/styles/agent.css +380 -0
  214. package/src/web/styles/composer.css +193 -0
  215. package/src/web/styles/overlays.css +436 -0
  216. package/src/web/styles/shell.css +387 -0
  217. package/src/web/styles/studio.css +723 -0
  218. package/src/web/styles/thread.css +221 -0
  219. package/src/web/styles/tokens.css +94 -0
  220. package/src/web/ui/brandMark.js +73 -0
  221. package/src/web/ui/brandMark.ts +82 -0
  222. package/src/web/ui/modalsTemplate.js +139 -0
  223. package/src/web/ui/modalsTemplate.ts +139 -0
  224. package/src/web/ui/sidebarTemplate.js +63 -0
  225. package/src/web/ui/sidebarTemplate.ts +64 -0
  226. package/src/web/ui/studioTemplate.js +258 -0
  227. package/src/web/ui/studioTemplate.ts +258 -0
  228. package/src/web/ui/workspaceTemplate.js +72 -0
  229. package/src/web/ui/workspaceTemplate.ts +73 -0
  230. package/src/worktreeManager.js +16 -1
  231. package/src/worktreeManager.ts +22 -1
  232. package/src/web/skybridgeClientScript.js +0 -3951
  233. package/src/web/skybridgeClientScript.ts +0 -3952
  234. package/src/web/skybridgeStyles.js +0 -827
  235. package/src/web/skybridgeStyles.ts +0 -828
@@ -59,6 +59,14 @@ export class MuseProvider extends OpenAICompatibleProvider {
59
59
  this.reasoningEffort = clampReasoningEffort(config.reasoningEffort, this.model);
60
60
  }
61
61
 
62
+ override supportsReasoningEffort(): boolean {
63
+ return /^muse-spark/i.test((this.model || '').trim());
64
+ }
65
+
66
+ override resolvePayloadReasoningEffort(): string | null {
67
+ return clampReasoningEffort(this.reasoningEffort, this.model);
68
+ }
69
+
62
70
  override audioAlternative(): string | null {
63
71
  if (this.supportsAudio) return null;
64
72
  return isContributorModel(this.model) ? 'muse-spark-1.2-contributor' : 'muse-spark-1.2';
@@ -271,8 +271,11 @@ export class OllamaProvider extends LLMProvider {
271
271
  if (this.reasoningEffort) {
272
272
  const loweredModel = (this.model || '').toLowerCase();
273
273
  if (loweredModel.includes('gpt-oss')) {
274
- if (['low', 'medium', 'high'].includes(this.reasoningEffort)) {
275
- thinkParam = this.reasoningEffort;
274
+ const mapped = this.reasoningEffort === 'minimal'
275
+ ? 'low'
276
+ : (['xhigh', 'max', 'ultra'].includes(this.reasoningEffort) ? 'high' : this.reasoningEffort);
277
+ if (['low', 'medium', 'high'].includes(mapped)) {
278
+ thinkParam = mapped;
276
279
  }
277
280
  }
278
281
  else if (meta?.supportsThinking !== false && (meta?.supportsThinking === true || /qwen3|qwen-3|deepseek-r1|qwq|magistral|cogito/i.test(loweredModel))) {
@@ -284,7 +287,7 @@ export class OllamaProvider extends LLMProvider {
284
287
  }
285
288
  }
286
289
  }
287
- const buildPayload = (useNativeTools) => ({
290
+ const buildPayload = (useNativeTools, includeThink = true) => ({
288
291
  model: this.model,
289
292
  messages: !useNativeTools && hasTools
290
293
  ? this.injectTextToolContracts(sanitizedMessages, options.tools)
@@ -292,7 +295,7 @@ export class OllamaProvider extends LLMProvider {
292
295
  stream: false,
293
296
  keep_alive: '10m',
294
297
  options: ollamaOptions,
295
- ...(thinkParam !== undefined ? { think: thinkParam } : {}),
298
+ ...(includeThink && thinkParam !== undefined ? { think: thinkParam } : {}),
296
299
  ...(useNativeTools && adaptedTools ? { tools: adaptedTools } : {}),
297
300
  ...(options.jsonMode ? { format: 'json' } : {})
298
301
  });
@@ -320,20 +323,49 @@ export class OllamaProvider extends LLMProvider {
320
323
  }));
321
324
  let data;
322
325
  const tryingNativeTools = hasTools && !skipNativeTools;
326
+ let useThink = thinkParam !== undefined;
323
327
  try {
324
- data = await runRequest(buildPayload(tryingNativeTools));
328
+ data = await runRequest(buildPayload(tryingNativeTools, useThink));
325
329
  }
326
330
  catch (err) {
327
331
  const msg = err instanceof Error ? err.message : String(err);
328
332
  const status = err instanceof ProviderHttpError ? err.status : (typeof err?.status === 'number' ? err.status : null);
329
- if (tryingNativeTools && status === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(msg)) {
333
+ if (useThink && status === 400 && /(?:does not support thinking|invalid.*think|unknown field.*think|\bthink\b)/i.test(msg)) {
334
+ useThink = false;
335
+ const existing = ollamaMetaCache.get(cacheKey);
336
+ ollamaMetaCache.set(cacheKey, {
337
+ ...(existing ?? { fetchedAt: Date.now() }),
338
+ supportsThinking: false,
339
+ fetchedAt: Date.now()
340
+ });
341
+ try {
342
+ data = await runRequest(buildPayload(tryingNativeTools, false));
343
+ }
344
+ catch (retryErr) {
345
+ const retryMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
346
+ const retryStatus = retryErr instanceof ProviderHttpError ? retryErr.status : (typeof retryErr?.status === 'number' ? retryErr.status : null);
347
+ if (tryingNativeTools && retryStatus === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(retryMsg)) {
348
+ const latest = ollamaMetaCache.get(cacheKey);
349
+ ollamaMetaCache.set(cacheKey, {
350
+ ...(latest ?? { fetchedAt: Date.now() }),
351
+ supportsTools: false,
352
+ fetchedAt: Date.now()
353
+ });
354
+ data = await runRequest(buildPayload(false, false));
355
+ }
356
+ else {
357
+ throw retryErr;
358
+ }
359
+ }
360
+ }
361
+ else if (tryingNativeTools && status === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(msg)) {
330
362
  const existing = ollamaMetaCache.get(cacheKey);
331
363
  ollamaMetaCache.set(cacheKey, {
332
364
  ...(existing ?? { fetchedAt: Date.now() }),
333
365
  supportsTools: false,
334
366
  fetchedAt: Date.now()
335
367
  });
336
- data = await runRequest(buildPayload(false));
368
+ data = await runRequest(buildPayload(false, useThink));
337
369
  }
338
370
  else if (status === 404 && /model\b.*not found|pull/i.test(msg)) {
339
371
  throw new ProviderHttpError(`Ollama model "${this.model}" is not installed locally. Run \`ollama pull ${this.model}\` or select an installed model with /model.`, { status: 404 });
@@ -300,8 +300,11 @@ export class OllamaProvider extends LLMProvider {
300
300
  if (this.reasoningEffort) {
301
301
  const loweredModel = (this.model || '').toLowerCase();
302
302
  if (loweredModel.includes('gpt-oss')) {
303
- if (['low', 'medium', 'high'].includes(this.reasoningEffort)) {
304
- thinkParam = this.reasoningEffort;
303
+ const mapped = this.reasoningEffort === 'minimal'
304
+ ? 'low'
305
+ : (['xhigh', 'max', 'ultra'].includes(this.reasoningEffort) ? 'high' : this.reasoningEffort);
306
+ if (['low', 'medium', 'high'].includes(mapped)) {
307
+ thinkParam = mapped;
305
308
  }
306
309
  } else if (meta?.supportsThinking !== false && (meta?.supportsThinking === true || /qwen3|qwen-3|deepseek-r1|qwq|magistral|cogito/i.test(loweredModel))) {
307
310
  if (this.reasoningEffort === 'off' || this.reasoningEffort === 'none') {
@@ -312,7 +315,7 @@ export class OllamaProvider extends LLMProvider {
312
315
  }
313
316
  }
314
317
 
315
- const buildPayload = (useNativeTools: boolean): Record<string, any> => ({
318
+ const buildPayload = (useNativeTools: boolean, includeThink = true): Record<string, any> => ({
316
319
  model: this.model,
317
320
  messages: !useNativeTools && hasTools
318
321
  ? this.injectTextToolContracts(sanitizedMessages, options.tools!)
@@ -320,7 +323,7 @@ export class OllamaProvider extends LLMProvider {
320
323
  stream: false,
321
324
  keep_alive: '10m',
322
325
  options: ollamaOptions,
323
- ...(thinkParam !== undefined ? { think: thinkParam } : {}),
326
+ ...(includeThink && thinkParam !== undefined ? { think: thinkParam } : {}),
324
327
  ...(useNativeTools && adaptedTools ? { tools: adaptedTools } : {}),
325
328
  ...(options.jsonMode ? { format: 'json' } : {})
326
329
  });
@@ -353,19 +356,45 @@ export class OllamaProvider extends LLMProvider {
353
356
 
354
357
  let data: Record<string, any>;
355
358
  const tryingNativeTools = hasTools && !skipNativeTools;
359
+ let useThink = thinkParam !== undefined;
356
360
  try {
357
- data = await runRequest(buildPayload(tryingNativeTools));
361
+ data = await runRequest(buildPayload(tryingNativeTools, useThink));
358
362
  } catch (err: unknown) {
359
363
  const msg = err instanceof Error ? err.message : String(err);
360
364
  const status = err instanceof ProviderHttpError ? err.status : (typeof (err as any)?.status === 'number' ? (err as any).status : null);
361
- if (tryingNativeTools && status === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(msg)) {
365
+ if (useThink && status === 400 && /(?:does not support thinking|invalid.*think|unknown field.*think|\bthink\b)/i.test(msg)) {
366
+ useThink = false;
367
+ const existing = ollamaMetaCache.get(cacheKey);
368
+ ollamaMetaCache.set(cacheKey, {
369
+ ...(existing ?? { fetchedAt: Date.now() }),
370
+ supportsThinking: false,
371
+ fetchedAt: Date.now()
372
+ });
373
+ try {
374
+ data = await runRequest(buildPayload(tryingNativeTools, false));
375
+ } catch (retryErr: unknown) {
376
+ const retryMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
377
+ const retryStatus = retryErr instanceof ProviderHttpError ? retryErr.status : (typeof (retryErr as any)?.status === 'number' ? (retryErr as any).status : null);
378
+ if (tryingNativeTools && retryStatus === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(retryMsg)) {
379
+ const latest = ollamaMetaCache.get(cacheKey);
380
+ ollamaMetaCache.set(cacheKey, {
381
+ ...(latest ?? { fetchedAt: Date.now() }),
382
+ supportsTools: false,
383
+ fetchedAt: Date.now()
384
+ });
385
+ data = await runRequest(buildPayload(false, false));
386
+ } else {
387
+ throw retryErr;
388
+ }
389
+ }
390
+ } else if (tryingNativeTools && status === 400 && /does not support tools|tool[s ]+not supported|unknown field.*tools/i.test(msg)) {
362
391
  const existing = ollamaMetaCache.get(cacheKey);
363
392
  ollamaMetaCache.set(cacheKey, {
364
393
  ...(existing ?? { fetchedAt: Date.now() }),
365
394
  supportsTools: false,
366
395
  fetchedAt: Date.now()
367
396
  });
368
- data = await runRequest(buildPayload(false));
397
+ data = await runRequest(buildPayload(false, useThink));
369
398
  } else if (status === 404 && /model\b.*not found|pull/i.test(msg)) {
370
399
  throw new ProviderHttpError(
371
400
  `Ollama model "${this.model}" is not installed locally. Run \`ollama pull ${this.model}\` or select an installed model with /model.`,
@@ -69,6 +69,18 @@ export class OpenAICompatibleProvider extends LLMProvider {
69
69
  || lowered.includes('deepseek-r1')
70
70
  || lowered.includes('reasoning');
71
71
  }
72
+ resolvePayloadReasoningEffort() {
73
+ const raw = typeof this.reasoningEffort === 'string' ? this.reasoningEffort.trim().toLowerCase() : '';
74
+ if (!raw || raw === 'off' || raw === 'none')
75
+ return null;
76
+ if (raw === 'low' || raw === 'medium' || raw === 'high')
77
+ return raw;
78
+ if (raw === 'minimal')
79
+ return 'low';
80
+ if (raw === 'xhigh' || raw === 'max' || raw === 'ultra')
81
+ return 'high';
82
+ return null;
83
+ }
72
84
  async chat(messages, options = {}) {
73
85
  const opts = options && typeof options === 'object' ? options : {};
74
86
  const endpoint = this.baseUrl || 'https://api.openai.com/v1/chat/completions';
@@ -82,8 +94,9 @@ export class OpenAICompatibleProvider extends LLMProvider {
82
94
  if (!this.rejectsSamplingParameters()) {
83
95
  payload['temperature'] = resolveTemperature(opts.temperature, 0.1);
84
96
  }
85
- if (this.reasoningEffort && this.reasoningEffort !== 'off' && this.supportsReasoningEffort()) {
86
- payload['reasoning_effort'] = this.reasoningEffort;
97
+ const effectiveEffort = this.supportsReasoningEffort() ? this.resolvePayloadReasoningEffort() : null;
98
+ if (effectiveEffort && effectiveEffort !== 'off') {
99
+ payload['reasoning_effort'] = effectiveEffort;
87
100
  }
88
101
  if (typeof opts.maxTokens === 'number' && Number.isFinite(opts.maxTokens) && opts.maxTokens >= 1) {
89
102
  const tokenLimit = Math.floor(opts.maxTokens);
@@ -157,7 +170,7 @@ export class OpenAICompatibleProvider extends LLMProvider {
157
170
  const rejectedReasoningEffort = 'reasoning_effort' in payload
158
171
  && err instanceof ProviderHttpError
159
172
  && err.status === 400
160
- && /(?:reasoning_effort|unrecognized|unknown field|extra inputs|not permitted|unsupported parameter)/i.test(err.message);
173
+ && /(?:reasoning_effort|effort|unrecognized|unknown field|extra inputs|not permitted|unsupported parameter|not supported|does not support|invalid value|must be one of)/i.test(err.message);
161
174
  if (!rejectedReasoningEffort)
162
175
  throw err;
163
176
  const fallbackPayload = { ...payload };
@@ -81,6 +81,15 @@ export class OpenAICompatibleProvider extends LLMProvider {
81
81
  || lowered.includes('reasoning');
82
82
  }
83
83
 
84
+ resolvePayloadReasoningEffort(): string | null {
85
+ const raw = typeof this.reasoningEffort === 'string' ? this.reasoningEffort.trim().toLowerCase() : '';
86
+ if (!raw || raw === 'off' || raw === 'none') return null;
87
+ if (raw === 'low' || raw === 'medium' || raw === 'high') return raw;
88
+ if (raw === 'minimal') return 'low';
89
+ if (raw === 'xhigh' || raw === 'max' || raw === 'ultra') return 'high';
90
+ return null;
91
+ }
92
+
84
93
  override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
85
94
  const opts = options && typeof options === 'object' ? options : {};
86
95
  const endpoint = this.baseUrl || 'https://api.openai.com/v1/chat/completions';
@@ -95,8 +104,9 @@ export class OpenAICompatibleProvider extends LLMProvider {
95
104
  payload['temperature'] = resolveTemperature(opts.temperature, 0.1);
96
105
  }
97
106
 
98
- if (this.reasoningEffort && this.reasoningEffort !== 'off' && this.supportsReasoningEffort()) {
99
- payload['reasoning_effort'] = this.reasoningEffort;
107
+ const effectiveEffort = this.supportsReasoningEffort() ? this.resolvePayloadReasoningEffort() : null;
108
+ if (effectiveEffort && effectiveEffort !== 'off') {
109
+ payload['reasoning_effort'] = effectiveEffort;
100
110
  }
101
111
 
102
112
  if (typeof opts.maxTokens === 'number' && Number.isFinite(opts.maxTokens) && opts.maxTokens >= 1) {
@@ -176,7 +186,7 @@ export class OpenAICompatibleProvider extends LLMProvider {
176
186
  const rejectedReasoningEffort = 'reasoning_effort' in payload
177
187
  && err instanceof ProviderHttpError
178
188
  && err.status === 400
179
- && /(?:reasoning_effort|unrecognized|unknown field|extra inputs|not permitted|unsupported parameter)/i.test(err.message);
189
+ && /(?:reasoning_effort|effort|unrecognized|unknown field|extra inputs|not permitted|unsupported parameter|not supported|does not support|invalid value|must be one of)/i.test(err.message);
180
190
  if (!rejectedReasoningEffort) throw err;
181
191
  const fallbackPayload = { ...payload };
182
192
  delete fallbackPayload['reasoning_effort'];
@@ -1,6 +1,64 @@
1
1
  import { canonicalModelId } from '../modelIds.js';
2
2
  import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
3
  import { OpenAICompatibleProvider } from './openai-compatible.js';
4
+ export function clampOpenAIReasoningEffort(rawEffort, model) {
5
+ const requested = typeof rawEffort === 'string' ? rawEffort.trim().toLowerCase() : '';
6
+ if (!requested)
7
+ return null;
8
+ const lowered = typeof model === 'string' ? model.trim().toLowerCase() : '';
9
+ if (!lowered || lowered.includes('-chat'))
10
+ return null;
11
+ // o1-pro / o3-pro / o4-pro only accept medium | high
12
+ if (/^o[134]-pro(?:$|[-.])/.test(lowered)) {
13
+ if (requested === 'off' || requested === 'none')
14
+ return null;
15
+ if (requested === 'minimal' || requested === 'low' || requested === 'medium')
16
+ return 'medium';
17
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested))
18
+ return 'high';
19
+ return null;
20
+ }
21
+ // o1 / o3 / o4-mini only accept low | medium | high
22
+ if (/^o[134](?:$|[-.])/.test(lowered)) {
23
+ if (requested === 'off' || requested === 'none')
24
+ return null;
25
+ if (requested === 'minimal' || requested === 'low')
26
+ return 'low';
27
+ if (requested === 'medium')
28
+ return 'medium';
29
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested))
30
+ return 'high';
31
+ return null;
32
+ }
33
+ // GPT-5.2+ / GPT-6 / Codex accept none | low | medium | high | xhigh (plus off -> none)
34
+ if (/^gpt-[56](?:$|[-.])/.test(lowered)) {
35
+ const supportsXhigh = /^gpt-5\.[2-9]|^gpt-6|codex/i.test(lowered);
36
+ if (supportsXhigh) {
37
+ if (requested === 'off' || requested === 'none')
38
+ return 'none';
39
+ if (requested === 'minimal' || requested === 'low')
40
+ return 'low';
41
+ if (requested === 'medium')
42
+ return 'medium';
43
+ if (requested === 'high')
44
+ return 'high';
45
+ if (['xhigh', 'max', 'ultra'].includes(requested))
46
+ return 'xhigh';
47
+ return null;
48
+ }
49
+ // GPT-5.0 / 5.1 accept minimal | low | medium | high
50
+ if (requested === 'off' || requested === 'none' || requested === 'minimal')
51
+ return 'minimal';
52
+ if (requested === 'low')
53
+ return 'low';
54
+ if (requested === 'medium')
55
+ return 'medium';
56
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested))
57
+ return 'high';
58
+ return null;
59
+ }
60
+ return null;
61
+ }
4
62
  export class OpenAIProvider extends OpenAICompatibleProvider {
5
63
  constructor(config = {}) {
6
64
  super(config);
@@ -13,10 +71,10 @@ export class OpenAIProvider extends OpenAICompatibleProvider {
13
71
  this.audioModels = ['gpt-4o-audio', 'gpt-4o-mini-audio', 'gpt-audio', 'gpt-realtime'];
14
72
  this.audioPayloadFormat = 'openai';
15
73
  this.preserveReasoningContent = false;
16
- const allowedEfforts = new Set(['low', 'medium', 'high', 'xhigh', 'minimal', 'none', 'off']);
17
- if (this.reasoningEffort && !allowedEfforts.has(this.reasoningEffort)) {
18
- this.reasoningEffort = null;
19
- }
74
+ this.reasoningEffort = clampOpenAIReasoningEffort(this.reasoningEffort, this.model);
75
+ }
76
+ resolvePayloadReasoningEffort() {
77
+ return clampOpenAIReasoningEffort(this.reasoningEffort, this.model);
20
78
  }
21
79
  rejectsSamplingParameters() {
22
80
  const lowered = (this.model || '').trim().toLowerCase();
@@ -3,6 +3,51 @@ import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
3
  import type { ProviderConfig } from './base.js';
4
4
  import { OpenAICompatibleProvider } from './openai-compatible.js';
5
5
 
6
+ export function clampOpenAIReasoningEffort(rawEffort: unknown, model: unknown): string | null {
7
+ const requested = typeof rawEffort === 'string' ? rawEffort.trim().toLowerCase() : '';
8
+ if (!requested) return null;
9
+ const lowered = typeof model === 'string' ? model.trim().toLowerCase() : '';
10
+ if (!lowered || lowered.includes('-chat')) return null;
11
+
12
+ // o1-pro / o3-pro / o4-pro only accept medium | high
13
+ if (/^o[134]-pro(?:$|[-.])/.test(lowered)) {
14
+ if (requested === 'off' || requested === 'none') return null;
15
+ if (requested === 'minimal' || requested === 'low' || requested === 'medium') return 'medium';
16
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested)) return 'high';
17
+ return null;
18
+ }
19
+
20
+ // o1 / o3 / o4-mini only accept low | medium | high
21
+ if (/^o[134](?:$|[-.])/.test(lowered)) {
22
+ if (requested === 'off' || requested === 'none') return null;
23
+ if (requested === 'minimal' || requested === 'low') return 'low';
24
+ if (requested === 'medium') return 'medium';
25
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested)) return 'high';
26
+ return null;
27
+ }
28
+
29
+ // GPT-5.2+ / GPT-6 / Codex accept none | low | medium | high | xhigh (plus off -> none)
30
+ if (/^gpt-[56](?:$|[-.])/.test(lowered)) {
31
+ const supportsXhigh = /^gpt-5\.[2-9]|^gpt-6|codex/i.test(lowered);
32
+ if (supportsXhigh) {
33
+ if (requested === 'off' || requested === 'none') return 'none';
34
+ if (requested === 'minimal' || requested === 'low') return 'low';
35
+ if (requested === 'medium') return 'medium';
36
+ if (requested === 'high') return 'high';
37
+ if (['xhigh', 'max', 'ultra'].includes(requested)) return 'xhigh';
38
+ return null;
39
+ }
40
+ // GPT-5.0 / 5.1 accept minimal | low | medium | high
41
+ if (requested === 'off' || requested === 'none' || requested === 'minimal') return 'minimal';
42
+ if (requested === 'low') return 'low';
43
+ if (requested === 'medium') return 'medium';
44
+ if (['high', 'xhigh', 'max', 'ultra'].includes(requested)) return 'high';
45
+ return null;
46
+ }
47
+
48
+ return null;
49
+ }
50
+
6
51
  export class OpenAIProvider extends OpenAICompatibleProvider {
7
52
  constructor(config: ProviderConfig = {}) {
8
53
  super(config);
@@ -14,10 +59,11 @@ export class OpenAIProvider extends OpenAICompatibleProvider {
14
59
  this.audioModels = ['gpt-4o-audio', 'gpt-4o-mini-audio', 'gpt-audio', 'gpt-realtime'];
15
60
  this.audioPayloadFormat = 'openai';
16
61
  this.preserveReasoningContent = false;
17
- const allowedEfforts = new Set(['low', 'medium', 'high', 'xhigh', 'minimal', 'none', 'off']);
18
- if (this.reasoningEffort && !allowedEfforts.has(this.reasoningEffort)) {
19
- this.reasoningEffort = null;
20
- }
62
+ this.reasoningEffort = clampOpenAIReasoningEffort(this.reasoningEffort, this.model);
63
+ }
64
+
65
+ override resolvePayloadReasoningEffort(): string | null {
66
+ return clampOpenAIReasoningEffort(this.reasoningEffort, this.model);
21
67
  }
22
68
 
23
69
  override rejectsSamplingParameters(): boolean {
@@ -167,7 +167,7 @@ export class OpenRouterProvider extends LLMProvider {
167
167
  'X-Title': 'Causyne Agent'
168
168
  };
169
169
  const endpoint = this.baseUrl || OPENROUTER_CHAT_ENDPOINT;
170
- const executeForModel = async (targetModel, useNativeTools) => {
170
+ const executeForModel = async (targetModel, useNativeTools, includeReasoning = true) => {
171
171
  if (this.freeOnly) {
172
172
  this.assertFreeModel(targetModel);
173
173
  }
@@ -191,7 +191,7 @@ export class OpenRouterProvider extends LLMProvider {
191
191
  if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
192
192
  payload['max_tokens'] = Math.floor(options.maxTokens);
193
193
  }
194
- if (this.reasoningEffort) {
194
+ if (includeReasoning && this.reasoningEffort) {
195
195
  if (this.reasoningEffort === 'off' || this.reasoningEffort === 'none') {
196
196
  payload['reasoning'] = { enabled: false };
197
197
  }
@@ -255,8 +255,23 @@ export class OpenRouterProvider extends LLMProvider {
255
255
  }
256
256
  };
257
257
  const runWithToolFallback = async (targetModel) => {
258
+ const runWithReasoningFallback = async (useNativeTools) => {
259
+ try {
260
+ return await executeForModel(targetModel, useNativeTools, true);
261
+ }
262
+ catch (err) {
263
+ const msg = err instanceof Error ? err.message : String(err);
264
+ const status = err instanceof ProviderHttpError ? err.status : null;
265
+ const rejectedReasoning = Boolean(this.reasoningEffort)
266
+ && (status === 400 || status === 404)
267
+ && /(?:reasoning|effort|require_parameters|no endpoints found|unsupported|invalid)/i.test(msg);
268
+ if (!rejectedReasoning)
269
+ throw err;
270
+ return await executeForModel(targetModel, useNativeTools, false);
271
+ }
272
+ };
258
273
  try {
259
- return await executeForModel(targetModel, hasTools);
274
+ return await runWithReasoningFallback(hasTools);
260
275
  }
261
276
  catch (err) {
262
277
  const msg = err instanceof Error ? err.message : String(err);
@@ -264,7 +279,7 @@ export class OpenRouterProvider extends LLMProvider {
264
279
  if (hasTools
265
280
  && (status === 400 || status === 404)
266
281
  && /(?:does not support tool|support tool use|tool[s ]+not supported|no endpoints found.*tool|require_parameters)/i.test(msg)) {
267
- return await executeForModel(targetModel, false);
282
+ return await runWithReasoningFallback(false);
268
283
  }
269
284
  throw err;
270
285
  }
@@ -200,7 +200,11 @@ export class OpenRouterProvider extends LLMProvider {
200
200
  };
201
201
  const endpoint = this.baseUrl || OPENROUTER_CHAT_ENDPOINT;
202
202
 
203
- const executeForModel = async (targetModel: string, useNativeTools: boolean): Promise<ChatResponse> => {
203
+ const executeForModel = async (
204
+ targetModel: string,
205
+ useNativeTools: boolean,
206
+ includeReasoning = true
207
+ ): Promise<ChatResponse> => {
204
208
  if (this.freeOnly) {
205
209
  this.assertFreeModel(targetModel);
206
210
  }
@@ -224,7 +228,7 @@ export class OpenRouterProvider extends LLMProvider {
224
228
  if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
225
229
  payload['max_tokens'] = Math.floor(options.maxTokens);
226
230
  }
227
- if (this.reasoningEffort) {
231
+ if (includeReasoning && this.reasoningEffort) {
228
232
  if (this.reasoningEffort === 'off' || this.reasoningEffort === 'none') {
229
233
  payload['reasoning'] = { enabled: false };
230
234
  } else if (['minimal', 'low', 'medium', 'high', 'xhigh'].includes(this.reasoningEffort)) {
@@ -286,8 +290,21 @@ export class OpenRouterProvider extends LLMProvider {
286
290
  };
287
291
 
288
292
  const runWithToolFallback = async (targetModel: string): Promise<ChatResponse> => {
293
+ const runWithReasoningFallback = async (useNativeTools: boolean): Promise<ChatResponse> => {
294
+ try {
295
+ return await executeForModel(targetModel, useNativeTools, true);
296
+ } catch (err: unknown) {
297
+ const msg = err instanceof Error ? err.message : String(err);
298
+ const status = err instanceof ProviderHttpError ? err.status : null;
299
+ const rejectedReasoning = Boolean(this.reasoningEffort)
300
+ && (status === 400 || status === 404)
301
+ && /(?:reasoning|effort|require_parameters|no endpoints found|unsupported|invalid)/i.test(msg);
302
+ if (!rejectedReasoning) throw err;
303
+ return await executeForModel(targetModel, useNativeTools, false);
304
+ }
305
+ };
289
306
  try {
290
- return await executeForModel(targetModel, hasTools);
307
+ return await runWithReasoningFallback(hasTools);
291
308
  } catch (err: unknown) {
292
309
  const msg = err instanceof Error ? err.message : String(err);
293
310
  const status = err instanceof ProviderHttpError ? err.status : null;
@@ -296,7 +313,7 @@ export class OpenRouterProvider extends LLMProvider {
296
313
  && (status === 400 || status === 404)
297
314
  && /(?:does not support tool|support tool use|tool[s ]+not supported|no endpoints found.*tool|require_parameters)/i.test(msg)
298
315
  ) {
299
- return await executeForModel(targetModel, false);
316
+ return await runWithReasoningFallback(false);
300
317
  }
301
318
  throw err;
302
319
  }
@@ -3,7 +3,7 @@ import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
3
  import { LLMProvider } from './base.js';
4
4
  import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
5
  import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
- import { requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
6
+ import { ProviderHttpError, requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
7
7
  import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
8
8
  import { resolveBudgetTokensForVariant } from '../modelVariants.js';
9
9
  export class QwenByokProvider extends LLMProvider {
@@ -108,17 +108,33 @@ export class QwenByokProvider extends LLMProvider {
108
108
  }
109
109
  }
110
110
  };
111
- const data = wantsStreaming(options)
111
+ const runQwenRequest = async (reqPayload) => (wantsStreaming(options)
112
112
  ? await streamOpenAICompatibleChat({
113
113
  ...requestOpts,
114
- payload,
114
+ payload: reqPayload,
115
115
  onChunk: options.onChunk,
116
116
  onReasoningChunk: options.onReasoningChunk
117
117
  })
118
118
  : await safeProviderFetchJson({
119
119
  ...requestOpts,
120
- body: JSON.stringify(payload)
121
- });
120
+ body: JSON.stringify(reqPayload)
121
+ }));
122
+ let data;
123
+ try {
124
+ data = await runQwenRequest(payload);
125
+ }
126
+ catch (err) {
127
+ const rejectedThinking = ('enable_thinking' in payload || 'thinking_budget' in payload)
128
+ && err instanceof ProviderHttpError
129
+ && err.status === 400
130
+ && /(?:enable_thinking|thinking_budget|thinking|unsupported|not supported|invalid|unknown)/i.test(err.message);
131
+ if (!rejectedThinking)
132
+ throw err;
133
+ const fallbackPayload = { ...payload };
134
+ delete fallbackPayload['enable_thinking'];
135
+ delete fallbackPayload['thinking_budget'];
136
+ data = await runQwenRequest(fallbackPayload);
137
+ }
122
138
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
123
139
  prefix: 'call_qwen',
124
140
  freeFormPaths
@@ -4,6 +4,7 @@ import { LLMProvider, type ChatOptions, type ChatResponse, type ProviderConfig }
4
4
  import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
5
  import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
6
  import {
7
+ ProviderHttpError,
7
8
  requireApiKey,
8
9
  resolveTemperature,
9
10
  safeProviderFetchJson
@@ -115,17 +116,34 @@ export class QwenByokProvider extends LLMProvider {
115
116
  }
116
117
  };
117
118
 
118
- const data = wantsStreaming(options)
119
- ? await streamOpenAICompatibleChat({
120
- ...requestOpts,
121
- payload,
122
- onChunk: options.onChunk,
123
- onReasoningChunk: options.onReasoningChunk
124
- })
125
- : await safeProviderFetchJson({
126
- ...requestOpts,
127
- body: JSON.stringify(payload)
128
- });
119
+ const runQwenRequest = async (reqPayload: Record<string, any>) => (
120
+ wantsStreaming(options)
121
+ ? await streamOpenAICompatibleChat({
122
+ ...requestOpts,
123
+ payload: reqPayload,
124
+ onChunk: options.onChunk,
125
+ onReasoningChunk: options.onReasoningChunk
126
+ })
127
+ : await safeProviderFetchJson({
128
+ ...requestOpts,
129
+ body: JSON.stringify(reqPayload)
130
+ })
131
+ );
132
+
133
+ let data: Record<string, any>;
134
+ try {
135
+ data = await runQwenRequest(payload);
136
+ } catch (err: unknown) {
137
+ const rejectedThinking = ('enable_thinking' in payload || 'thinking_budget' in payload)
138
+ && err instanceof ProviderHttpError
139
+ && err.status === 400
140
+ && /(?:enable_thinking|thinking_budget|thinking|unsupported|not supported|invalid|unknown)/i.test(err.message);
141
+ if (!rejectedThinking) throw err;
142
+ const fallbackPayload = { ...payload };
143
+ delete fallbackPayload['enable_thinking'];
144
+ delete fallbackPayload['thinking_budget'];
145
+ data = await runQwenRequest(fallbackPayload);
146
+ }
129
147
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
130
148
  prefix: 'call_qwen',
131
149
  freeFormPaths