@causyne/agent 1.20.124 → 1.20.128
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/bin/causyne.js +1 -1
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +6 -4
- package/src/acp/protocol.ts +19 -1
- package/src/acp/server.js +282 -8
- package/src/acp/server.ts +284 -8
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +9 -1
- package/src/agent/errorClassifier.ts +8 -1
- package/src/agentLoop.js +142 -53
- package/src/agentLoop.ts +151 -50
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +61 -3
- package/src/browser/causyneBrowser.ts +65 -3
- package/src/browser/urlPolicy.js +14 -1
- package/src/browser/urlPolicy.ts +12 -1
- package/src/cliMode.js +21 -9
- package/src/cliMode.ts +20 -8
- package/src/commands.js +365 -45
- package/src/commands.ts +403 -45
- package/src/config.js +19 -4
- package/src/config.ts +18 -4
- package/src/core/contextCompactor.js +54 -7
- package/src/core/contextCompactor.ts +63 -7
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/entrypoint.js +135 -3
- package/src/entrypoint.ts +136 -3
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/headlessCli.js +19 -12
- package/src/headlessCli.ts +22 -8
- package/src/infra/atomicWriter.js +40 -4
- package/src/infra/atomicWriter.ts +36 -4
- package/src/launchIntent.js +73 -3
- package/src/launchIntent.ts +76 -3
- package/src/lsp/lspClient.js +83 -12
- package/src/lsp/lspClient.ts +75 -12
- package/src/mcp/mcpRegistry.js +75 -8
- package/src/mcp/mcpRegistry.ts +70 -7
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +40 -0
- package/src/memory/episodicStore.ts +46 -0
- package/src/memory.js +67 -0
- package/src/memory.ts +65 -0
- package/src/modelVariants.js +45 -0
- package/src/modelVariants.ts +54 -0
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/personalization.js +365 -0
- package/src/personalization.ts +471 -0
- package/src/projectInstructions.js +30 -10
- package/src/projectInstructions.ts +31 -12
- package/src/providers/acp.js +3 -2
- package/src/providers/acp.ts +3 -2
- package/src/providers/antigravity.js +64 -9
- package/src/providers/antigravity.ts +75 -9
- package/src/providers/byokHttp.js +7 -1
- package/src/providers/byokHttp.ts +6 -1
- package/src/providers/byokStream.js +21 -8
- package/src/providers/byokStream.ts +17 -7
- package/src/providers/dashscope-byok.js +21 -5
- package/src/providers/dashscope-byok.ts +29 -11
- package/src/providers/moonshot.js +26 -7
- package/src/providers/moonshot.ts +34 -13
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +39 -7
- package/src/providers/ollama.ts +36 -7
- package/src/providers/openai-compatible.js +16 -3
- package/src/providers/openai-compatible.ts +13 -3
- package/src/providers/openai.js +62 -4
- package/src/providers/openai.ts +50 -4
- package/src/providers/openrouter.js +19 -4
- package/src/providers/openrouter.ts +21 -4
- package/src/providers/qwen-byok.js +21 -5
- package/src/providers/qwen-byok.ts +29 -11
- package/src/providers/xai.js +26 -10
- package/src/providers/xai.ts +34 -16
- package/src/reporting.js +4 -2
- package/src/reporting.ts +4 -2
- package/src/sandbox.js +34 -0
- package/src/sandbox.ts +43 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/toolPacks.js +6 -0
- package/src/toolPacks.ts +6 -0
- package/src/tools/applyPatch.js +1 -1
- package/src/tools/applyPatch.ts +1 -1
- package/src/tools/generateMediaViaApi.js +4 -3
- package/src/tools/generateMediaViaApi.ts +4 -3
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +122 -20
- package/src/tools/pdfReader.ts +111 -20
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1108 -0
- package/src/tools/ptyTerminal.ts +1245 -0
- package/src/tools/registry.js +21 -12
- package/src/tools/registry.ts +21 -12
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/webFetch.js +158 -11
- package/src/tools/webFetch.ts +145 -11
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/chatRenderer.js +1 -2
- package/src/tui/chatRenderer.ts +1 -2
- package/src/tui/completion.js +1 -0
- package/src/tui/completion.ts +1 -0
- package/src/tui/composerControls.js +111 -27
- package/src/tui/composerControls.ts +124 -28
- package/src/tui/dialogs.js +3 -16
- package/src/tui/dialogs.ts +3 -16
- package/src/tui/home.js +1 -0
- package/src/tui/home.ts +1 -0
- package/src/tui/invocation.js +1 -2
- package/src/tui/invocation.ts +1 -2
- package/src/tui/modelPicker.js +22 -12
- package/src/tui/modelPicker.ts +22 -12
- package/src/tui/overlay.js +2 -5
- package/src/tui/overlay.ts +2 -5
- package/src/tui/prompt.js +6 -4
- package/src/tui/prompt.ts +6 -4
- package/src/tui/selectList.js +4 -12
- package/src/tui/selectList.ts +4 -12
- package/src/tui/setup.js +22 -9
- package/src/tui/setup.ts +26 -9
- package/src/tui/statusLine.ts +2 -0
- package/src/web/client/browserPanel.js +905 -0
- package/src/web/client/browserPanel.ts +872 -0
- package/src/web/client/chatStream.js +321 -0
- package/src/web/client/chatStream.ts +297 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +271 -0
- package/src/web/client/dom.ts +272 -0
- package/src/web/client/filesAndCanvas.js +233 -0
- package/src/web/client/filesAndCanvas.ts +240 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +316 -0
- package/src/web/client/main.ts +391 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +824 -0
- package/src/web/client/settingsModal.ts +959 -0
- package/src/web/client/state.js +280 -0
- package/src/web/client/state.ts +259 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +89 -0
- package/src/web/client/studioLayout.ts +103 -0
- package/src/web/client/studioShell.js +660 -0
- package/src/web/client/studioShell.ts +672 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +606 -0
- package/src/web/client/terminalPanel.ts +632 -0
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +322 -0
- package/src/web/client/validators.js +147 -0
- package/src/web/client/validators.ts +140 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +409 -0
- package/src/web/server/routesBrowser.ts +435 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +104 -0
- package/src/web/server/staticAssets.ts +116 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeServer.js +78 -2448
- package/src/web/skybridgeServer.ts +120 -2600
- package/src/web/skybridgeUi.js +20 -450
- package/src/web/skybridgeUi.ts +24 -455
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +935 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +951 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +388 -0
- package/src/web/ui/modalsTemplate.ts +388 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +256 -0
- package/src/web/ui/studioTemplate.ts +256 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +16 -1
- package/src/worktreeManager.ts +22 -1
- package/src/web/skybridgeClientScript.js +0 -3951
- package/src/web/skybridgeClientScript.ts +0 -3952
- package/src/web/skybridgeStyles.js +0 -827
- package/src/web/skybridgeStyles.ts +0 -828
|
@@ -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
|
|
@@ -45,8 +46,11 @@ export class MoonshotProvider extends LLMProvider {
|
|
|
45
46
|
payload['thinking'] = { type: 'disabled' };
|
|
46
47
|
} else {
|
|
47
48
|
payload['thinking'] = { type: 'enabled' };
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const mappedEffort = this.reasoningEffort === 'minimal'
|
|
50
|
+
? 'low'
|
|
51
|
+
: (['xhigh', 'max', 'ultra'].includes(this.reasoningEffort) ? 'high' : this.reasoningEffort);
|
|
52
|
+
if (['low', 'medium', 'high'].includes(mappedEffort)) {
|
|
53
|
+
payload['reasoning_effort'] = mappedEffort;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
}
|
|
@@ -96,17 +100,34 @@ export class MoonshotProvider extends LLMProvider {
|
|
|
96
100
|
}
|
|
97
101
|
};
|
|
98
102
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
const runMoonshotRequest = async (reqPayload: Record<string, any>) => (
|
|
104
|
+
wantsStreaming(options)
|
|
105
|
+
? await streamOpenAICompatibleChat({
|
|
106
|
+
...requestOpts,
|
|
107
|
+
payload: reqPayload,
|
|
108
|
+
onChunk: options.onChunk,
|
|
109
|
+
onReasoningChunk: options.onReasoningChunk
|
|
110
|
+
})
|
|
111
|
+
: await safeProviderFetchJson({
|
|
112
|
+
...requestOpts,
|
|
113
|
+
body: JSON.stringify(reqPayload)
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
let data: Record<string, any>;
|
|
118
|
+
try {
|
|
119
|
+
data = await runMoonshotRequest(payload);
|
|
120
|
+
} catch (err: unknown) {
|
|
121
|
+
const rejectedReasoning = ('thinking' in payload || 'reasoning_effort' in payload)
|
|
122
|
+
&& err instanceof ProviderHttpError
|
|
123
|
+
&& err.status === 400
|
|
124
|
+
&& /(?:thinking|reasoning_effort|effort|unsupported|not supported|invalid|unknown)/i.test(err.message);
|
|
125
|
+
if (!rejectedReasoning) throw err;
|
|
126
|
+
const fallbackPayload = { ...payload };
|
|
127
|
+
delete fallbackPayload['thinking'];
|
|
128
|
+
delete fallbackPayload['reasoning_effort'];
|
|
129
|
+
data = await runMoonshotRequest(fallbackPayload);
|
|
130
|
+
}
|
|
110
131
|
const normalized = normalizeOpenAIChatChoiceResponse(data, {
|
|
111
132
|
prefix: 'call_moonshot',
|
|
112
133
|
freeFormPaths
|
package/src/providers/muse.js
CHANGED
|
@@ -45,6 +45,12 @@ export class MuseProvider extends OpenAICompatibleProvider {
|
|
|
45
45
|
this.contextTokens = MUSE_CONTEXT_TOKENS;
|
|
46
46
|
this.reasoningEffort = clampReasoningEffort(config.reasoningEffort, this.model);
|
|
47
47
|
}
|
|
48
|
+
supportsReasoningEffort() {
|
|
49
|
+
return /^muse-spark/i.test((this.model || '').trim());
|
|
50
|
+
}
|
|
51
|
+
resolvePayloadReasoningEffort() {
|
|
52
|
+
return clampReasoningEffort(this.reasoningEffort, this.model);
|
|
53
|
+
}
|
|
48
54
|
audioAlternative() {
|
|
49
55
|
if (this.supportsAudio)
|
|
50
56
|
return null;
|
package/src/providers/muse.ts
CHANGED
|
@@ -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';
|
package/src/providers/ollama.js
CHANGED
|
@@ -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
|
-
|
|
275
|
-
|
|
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 (
|
|
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 });
|
package/src/providers/ollama.ts
CHANGED
|
@@ -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
|
-
|
|
304
|
-
|
|
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 (
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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'];
|
package/src/providers/openai.js
CHANGED
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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();
|
package/src/providers/openai.ts
CHANGED
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|