@causyne/agent 1.20.120 → 1.20.122

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 (276) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +81 -26
  4. package/src/acp/agentCatalog.ts +73 -29
  5. package/src/acp/client.js +210 -53
  6. package/src/acp/client.ts +202 -52
  7. package/src/acp/peerProfiles.js +55 -22
  8. package/src/acp/peerProfiles.ts +51 -22
  9. package/src/acp/protocol.js +37 -8
  10. package/src/acp/protocol.ts +30 -8
  11. package/src/acp/server.js +123 -25
  12. package/src/acp/server.ts +124 -24
  13. package/src/agent/errorClassifier.js +117 -0
  14. package/src/agent/errorClassifier.ts +165 -0
  15. package/src/agent/promptIntent.js +200 -0
  16. package/src/agent/promptIntent.ts +203 -0
  17. package/src/agent/toolArgValidator.js +97 -0
  18. package/src/agent/toolArgValidator.ts +112 -0
  19. package/src/agentLoop.js +33 -344
  20. package/src/agentLoop.ts +51 -352
  21. package/src/approvalGrants.js +19 -7
  22. package/src/approvalGrants.ts +20 -7
  23. package/src/approvalPolicy.js +48 -15
  24. package/src/approvalPolicy.ts +46 -15
  25. package/src/autoUpdate.js +116 -10
  26. package/src/autoUpdate.ts +149 -10
  27. package/src/browser/causyneBrowser.js +3 -2
  28. package/src/browser/causyneBrowser.ts +3 -2
  29. package/src/browser/searchProviders.js +1 -1
  30. package/src/browser/searchProviders.ts +1 -1
  31. package/src/cliMode.js +16 -2
  32. package/src/commands.js +10 -9
  33. package/src/config.js +288 -272
  34. package/src/config.ts +342 -0
  35. package/src/configVault.js +271 -0
  36. package/src/configVault.ts +273 -0
  37. package/src/continuum/compactor.js +2 -1
  38. package/src/continuum/compactor.ts +2 -1
  39. package/src/continuum/sanitizer.js +10 -3
  40. package/src/continuum/sanitizer.ts +9 -3
  41. package/src/continuum/ui/continuumPickerView.js +3 -2
  42. package/src/continuum/ui/continuumPickerView.ts +3 -2
  43. package/src/core/contextCompactor.js +70 -11
  44. package/src/core/contextCompactor.ts +83 -11
  45. package/src/cortex/vectorDb.js +26 -15
  46. package/src/cortex/vectorDb.ts +26 -16
  47. package/src/creative/liveBridge.js +7 -5
  48. package/src/creative/liveBridge.ts +7 -5
  49. package/src/creative/studioScripts.js +16 -5
  50. package/src/creative/studioScripts.ts +14 -5
  51. package/src/decisionPolicy.js +16 -4
  52. package/src/decisionPolicy.ts +14 -4
  53. package/src/documentEngine/antiSlopAuditor.js +10 -5
  54. package/src/documentEngine/antiSlopAuditor.ts +11 -5
  55. package/src/documentEngine/documentForge.js +47 -15
  56. package/src/documentEngine/documentForge.ts +43 -14
  57. package/src/dynamicCatalogue.js +42 -73
  58. package/src/dynamicCatalogue.ts +74 -60
  59. package/src/engines/design.js +2 -1
  60. package/src/engines/design.ts +2 -1
  61. package/src/engines/film.js +4 -4
  62. package/src/engines/film.ts +2 -2
  63. package/src/engines/light.js +2 -1
  64. package/src/engines/light.ts +2 -1
  65. package/src/engines/registry.js +1 -1
  66. package/src/engines/registry.ts +1 -1
  67. package/src/engines/reverseHarness.js +4 -3
  68. package/src/engines/reverseHarness.ts +4 -3
  69. package/src/entrypoint.js +77 -4
  70. package/src/headlessCli.js +305 -0
  71. package/src/headlessCli.ts +381 -0
  72. package/src/historyPruner.js +3 -2
  73. package/src/historyPruner.ts +3 -2
  74. package/src/hooks.js +3 -0
  75. package/src/hooks.ts +3 -0
  76. package/src/implementationPlan.js +21 -11
  77. package/src/implementationPlan.ts +21 -11
  78. package/src/infra/atomicWriter.js +4 -1
  79. package/src/infra/atomicWriter.ts +4 -1
  80. package/src/launchIntent.js +1 -1
  81. package/src/launchIntent.ts +1 -1
  82. package/src/mcp/mcpClient.js +38 -11
  83. package/src/mcp/mcpClient.ts +44 -11
  84. package/src/mcp/mcpRegistry.js +2 -5
  85. package/src/mcp/mcpRegistry.ts +2 -5
  86. package/src/mcp/mcpSecurity.js +189 -0
  87. package/src/mcp/mcpSecurity.ts +190 -0
  88. package/src/memory/scopedFacts.js +1 -1
  89. package/src/memory/scopedFacts.ts +1 -1
  90. package/src/memory/symbolFolder.js +1 -1
  91. package/src/memory/symbolFolder.ts +1 -1
  92. package/src/modelRouter.js +1 -1
  93. package/src/modelRouter.ts +1 -1
  94. package/src/observer/evidence.js +10 -4
  95. package/src/observer/evidence.ts +10 -4
  96. package/src/osKeychain.js +263 -0
  97. package/src/osKeychain.ts +287 -0
  98. package/src/perception.js +3 -2
  99. package/src/perception.ts +3 -2
  100. package/src/planCache.js +2 -2
  101. package/src/planCache.ts +2 -2
  102. package/src/pluginsFactory/pluginsFactory.js +19 -11
  103. package/src/pluginsFactory/pluginsFactory.ts +18 -11
  104. package/src/promptMentions.js +2 -2
  105. package/src/promptMentions.ts +2 -2
  106. package/src/providers/acp.js +1 -1
  107. package/src/providers/acp.ts +1 -1
  108. package/src/providers/anthropic.js +328 -385
  109. package/src/providers/anthropic.ts +386 -0
  110. package/src/providers/antigravity.js +10 -4
  111. package/src/providers/antigravity.ts +10 -4
  112. package/src/providers/base.js +221 -319
  113. package/src/providers/base.ts +340 -0
  114. package/src/providers/byokHttp.js +397 -0
  115. package/src/providers/byokHttp.ts +497 -0
  116. package/src/providers/byokStream.js +748 -0
  117. package/src/providers/byokStream.ts +863 -0
  118. package/src/providers/dashscope-byok.js +98 -81
  119. package/src/providers/dashscope-byok.ts +114 -0
  120. package/src/providers/deepseek.js +74 -64
  121. package/src/providers/deepseek.ts +99 -0
  122. package/src/providers/factory.js +35 -28
  123. package/src/providers/factory.ts +40 -0
  124. package/src/providers/gemini.js +229 -253
  125. package/src/providers/gemini.ts +261 -0
  126. package/src/providers/loopGuard.js +9 -5
  127. package/src/providers/loopGuard.ts +10 -5
  128. package/src/providers/moonshot.js +71 -64
  129. package/src/providers/moonshot.ts +93 -0
  130. package/src/providers/muse.js +82 -152
  131. package/src/providers/muse.ts +122 -0
  132. package/src/providers/ollama.js +116 -93
  133. package/src/providers/ollama.ts +135 -0
  134. package/src/providers/openai-compatible.js +114 -65
  135. package/src/providers/openai-compatible.ts +139 -0
  136. package/src/providers/openai.js +22 -15
  137. package/src/providers/openai.ts +30 -0
  138. package/src/providers/openrouter.js +194 -98
  139. package/src/providers/openrouter.ts +202 -97
  140. package/src/providers/pi.js +6 -0
  141. package/src/providers/pi.ts +6 -0
  142. package/src/providers/qwen-byok.js +97 -71
  143. package/src/providers/qwen-byok.ts +113 -0
  144. package/src/providers/toolContracts.js +40 -14
  145. package/src/providers/toolContracts.ts +35 -14
  146. package/src/providers/wireNormalizer.js +78 -11
  147. package/src/providers/wireNormalizer.ts +68 -12
  148. package/src/providers/xai.js +74 -64
  149. package/src/providers/xai.ts +97 -0
  150. package/src/reliability/assetEvidence.js +4 -2
  151. package/src/reliability/assetEvidence.ts +4 -2
  152. package/src/sandbox.js +486 -530
  153. package/src/sandbox.ts +552 -0
  154. package/src/sandboxPolicy.js +1287 -0
  155. package/src/sandboxPolicy.ts +1381 -0
  156. package/src/sessionJournal.js +55 -3
  157. package/src/sessionJournal.ts +58 -3
  158. package/src/skills/skillResourceSafety.js +19 -8
  159. package/src/skills/skillResourceSafety.ts +16 -7
  160. package/src/skillsManager.js +3 -3
  161. package/src/skillsManager.ts +3 -3
  162. package/src/smartToolsUse.js +28 -4
  163. package/src/smartToolsUse.ts +29 -7
  164. package/src/stallGuard.js +45 -22
  165. package/src/stallGuard.ts +46 -22
  166. package/src/subagentJournal.js +6 -4
  167. package/src/subagentJournal.ts +6 -4
  168. package/src/textDiff.js +6 -1
  169. package/src/textDiff.ts +6 -1
  170. package/src/timeMachine.js +7 -1
  171. package/src/timeMachine.ts +7 -1
  172. package/src/tokenTracker.js +43 -28
  173. package/src/tokenTracker.ts +44 -30
  174. package/src/toolPacks.js +3 -1
  175. package/src/toolPacks.ts +3 -1
  176. package/src/tools/archive.js +245 -35
  177. package/src/tools/archive.ts +244 -35
  178. package/src/tools/computerUse.js +7 -3
  179. package/src/tools/computerUse.ts +7 -3
  180. package/src/tools/creativeApps.js +13 -8
  181. package/src/tools/creativeApps.ts +22 -9
  182. package/src/tools/deferredMcpSearch.js +26 -14
  183. package/src/tools/deferredMcpSearch.ts +26 -14
  184. package/src/tools/desktopOpen.js +69 -10
  185. package/src/tools/desktopOpen.ts +70 -11
  186. package/src/tools/documentForge.js +167 -82
  187. package/src/tools/documentForge.ts +169 -84
  188. package/src/tools/fsEdit.js +101 -30
  189. package/src/tools/fsEdit.ts +105 -32
  190. package/src/tools/fsFind.js +8 -5
  191. package/src/tools/fsFind.ts +7 -4
  192. package/src/tools/fsRead.js +119 -13
  193. package/src/tools/fsRead.ts +124 -13
  194. package/src/tools/fsWrite.js +17 -5
  195. package/src/tools/fsWrite.ts +17 -7
  196. package/src/tools/generateMediaViaApi.js +82 -19
  197. package/src/tools/generateMediaViaApi.ts +80 -19
  198. package/src/tools/memoryRecall.js +62 -11
  199. package/src/tools/memoryRecall.ts +70 -13
  200. package/src/tools/memoryWrite.js +27 -14
  201. package/src/tools/memoryWrite.ts +30 -14
  202. package/src/tools/multiEdit.js +100 -30
  203. package/src/tools/multiEdit.ts +104 -32
  204. package/src/tools/nativeEngine.js +33 -18
  205. package/src/tools/nativeEngine.ts +31 -18
  206. package/src/tools/openSourceToolProvisioner.js +49 -14
  207. package/src/tools/openSourceToolProvisioner.ts +54 -15
  208. package/src/tools/osSandbox.js +513 -0
  209. package/src/tools/osSandbox.ts +588 -0
  210. package/src/tools/payloadSanitizer.js +40 -8
  211. package/src/tools/payloadSanitizer.ts +39 -8
  212. package/src/tools/peerAgent.js +96 -34
  213. package/src/tools/peerAgent.ts +114 -37
  214. package/src/tools/persistentShell.js +8 -3
  215. package/src/tools/pluginsFactory.js +38 -6
  216. package/src/tools/pluginsFactory.ts +42 -6
  217. package/src/tools/readNativeSkill.js +10 -8
  218. package/src/tools/readNativeSkill.ts +10 -8
  219. package/src/tools/requestDecision.js +10 -3
  220. package/src/tools/requestDecision.ts +10 -3
  221. package/src/tools/resolveAutomator.js +91 -17
  222. package/src/tools/resolveAutomator.ts +102 -17
  223. package/src/tools/reverseEngineering.js +168 -41
  224. package/src/tools/reverseEngineering.ts +161 -41
  225. package/src/tools/subprocessEnv.js +197 -0
  226. package/src/tools/subprocessEnv.ts +212 -0
  227. package/src/tools/sysRun.js +108 -35
  228. package/src/tools/sysRun.ts +119 -31
  229. package/src/tools/toolDispatch.js +24 -1
  230. package/src/tools/toolDispatch.ts +21 -1
  231. package/src/tools/toolOutputStore.js +62 -23
  232. package/src/tools/toolOutputStore.ts +56 -23
  233. package/src/tools/toolScanner.js +13 -10
  234. package/src/tools/toolScanner.ts +13 -10
  235. package/src/tools/toolSelfRepair.js +94 -28
  236. package/src/tools/toolSelfRepair.ts +96 -28
  237. package/src/tools/uiForge.js +71 -6
  238. package/src/tools/uiForge.ts +74 -6
  239. package/src/tools/viewImage.js +62 -17
  240. package/src/tools/viewImage.ts +57 -12
  241. package/src/tools/visionInspector.js +15 -3
  242. package/src/tools/visionInspector.ts +15 -3
  243. package/src/tools/walkerSafety.js +2 -0
  244. package/src/tools/walkerSafety.ts +1 -0
  245. package/src/tools/webFetch.js +105 -10
  246. package/src/tools/webFetch.ts +105 -11
  247. package/src/tui/banner.js +3 -2
  248. package/src/tui/banner.ts +3 -2
  249. package/src/tui/consoleGuard.js +12 -4
  250. package/src/tui/consoleGuard.ts +9 -4
  251. package/src/tui/messageInteraction.js +2 -3
  252. package/src/tui/messageInteraction.ts +2 -3
  253. package/src/tui/modelPicker.js +1 -0
  254. package/src/tui/modelPicker.ts +1 -0
  255. package/src/tui/overlay.js +3 -1
  256. package/src/tui/overlay.ts +3 -1
  257. package/src/tui/sessionPicker.js +3 -2
  258. package/src/tui/sessionPicker.ts +3 -2
  259. package/src/tui/sessionPickerView.js +7 -1
  260. package/src/tui/sessionPickerView.ts +6 -1
  261. package/src/tui/toolOutputNormalizer.js +2 -3
  262. package/src/tui/toolOutputNormalizer.ts +4 -3
  263. package/src/tui/viewport.js +4 -4
  264. package/src/tui/viewport.ts +5 -5
  265. package/src/tui/workspaceIdentity.js +2 -1
  266. package/src/tui/workspaceIdentity.ts +2 -1
  267. package/src/uncertainty.js +8 -3
  268. package/src/uncertainty.ts +8 -3
  269. package/src/utils/paths.js +8 -5
  270. package/src/utils/paths.ts +9 -7
  271. package/src/vfeTracker.js +9 -3
  272. package/src/vfeTracker.ts +9 -3
  273. package/src/config.d.ts +0 -2
  274. package/src/providers/base.d.ts +0 -94
  275. package/src/providers/factory.d.ts +0 -1
  276. package/src/sandbox.d.ts +0 -1
@@ -3,89 +3,106 @@ 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
-
7
- // Direct DashScope API connection for BYOK (unlike dashscope.js which is the proxy for Free Demo)
6
+ import { requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
7
+ import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
8
8
  export class DashscopeByokProvider extends LLMProvider {
9
- constructor(config) {
10
- super(config);
11
- // Use International/Singapore endpoint by default, allow override via config
12
- let url = config.baseUrl || 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
13
- if (url.endsWith('/v1')) url += '/chat/completions';
14
- else if (url.endsWith('/v1/')) url += 'chat/completions';
15
-
16
- this.baseUrl = url;
17
- this.model = canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['dashscope-byok']);
18
- this.apiKey = config.apiKey;
19
- this.visionModels = ['-vl-', '-vl', 'qwen3.6', 'qwen3.7', 'kimi-k2.5', 'kimi-k2.7'];
20
- // Qwen exposes audio on the omni and dedicated audio families only; the
21
- // -vl- vision models are image-in, text-out and reject an audio block.
22
- this.audioModels = ['-omni', 'qwen-audio', 'qwen2-audio'];
23
- }
24
-
25
- async chat(messages, options = {}) {
26
- const ALLOWED = [
27
- "qwen3.7-max", "qwen3.7-plus", "kimi-k2.7-code", "kimi-k2.6",
28
- "kimi-k2.5", "kimi-k2-thinking", "Moonshot-Kimi-K2-Instruct",
29
- "deepseek-v4-flash", "deepseek-v4-pro"
30
- ];
31
- let activeModel = this.model;
32
- if (!ALLOWED.includes(activeModel)) {
33
- activeModel = 'qwen3.7-plus';
34
- }
35
-
36
- const sanitizedMessages = this.prepareMessages(messages);
37
-
38
- const payload = {
39
- model: activeModel,
40
- messages: sanitizedMessages,
41
- temperature: options.temperature || 0.1,
42
- };
43
-
44
- if (options.jsonMode) {
45
- payload.response_format = { type: 'json_object' };
46
- }
47
-
48
- let freeFormPaths = new Map();
49
- if (options.tools && options.tools.length > 0) {
50
- const scanReport = scanAndAdaptToolsForProvider(options.tools, 'dashscope');
51
- payload.tools = scanReport.adaptedTools;
52
- payload.tool_choice = "auto";
53
- freeFormPaths = scanReport.freeFormPaths;
9
+ allowInsecureHttp;
10
+ constructor(config = {}) {
11
+ super(config);
12
+ let url = (typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '') || 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
13
+ try {
14
+ const parsed = new URL(url);
15
+ if (parsed.pathname.endsWith('/v1')) {
16
+ parsed.pathname += '/chat/completions';
17
+ url = parsed.toString();
18
+ }
19
+ else if (parsed.pathname.endsWith('/v1/')) {
20
+ parsed.pathname += 'chat/completions';
21
+ url = parsed.toString();
22
+ }
23
+ }
24
+ catch {
25
+ if (url.endsWith('/v1'))
26
+ url += '/chat/completions';
27
+ else if (url.endsWith('/v1/'))
28
+ url += 'chat/completions';
29
+ }
30
+ this.baseUrl = url;
31
+ this.allowInsecureHttp = config.allowInsecureHttp === true;
32
+ this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['dashscope-byok']) || '');
33
+ this.apiKey = config.apiKey;
34
+ this.visionModels = ['-vl-', '-vl', 'qwen3.6', 'qwen3.7', 'kimi-k2.5', 'kimi-k2.7'];
35
+ this.audioModels = ['-omni', 'qwen-audio', 'qwen2-audio'];
54
36
  }
55
-
56
- const response = await fetch(this.baseUrl, {
57
- method: 'POST',
58
- headers: {
59
- 'Content-Type': 'application/json',
60
- 'Authorization': `Bearer ${this.apiKey}`
61
- },
62
- body: JSON.stringify(payload)
63
- });
64
-
65
- if (!response.ok) {
66
- const errorData = await response.text();
67
-
68
- // Enterprise Error Handling: Detect Workspace-bound API Key configuration errors
69
- if (response.status === 401 && this.apiKey && this.apiKey.startsWith('sk-ws-')) {
70
- if (!this.baseUrl.includes('ws-')) {
71
- throw new Error(`\n[QWEN WORKSPACE CONFIGURATION ERROR]\n\nYou are using a Workspace-bound API Key (starts with sk-ws-), but you haven't configured your Workspace Base URL!\n\nAlibaba requires a specific URL for these keys.\n\nHOW TO FIX THIS:\n1. Open your computer terminal.\n2. Run command: causyne-agent config\n3. When asked for 'Custom Base URL', paste your Workspace URL from Alibaba (e.g. https://{Your-Workspace-ID}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions).\n\nAlternatively, use a Standard API Key (starts with sk-) which does not require a custom URL.`);
37
+ async chat(messages, options = {}) {
38
+ const apiKey = requireApiKey(this.apiKey, 'Qwen DashScope');
39
+ const activeModel = String(canonicalModelId(this.model || DEFAULT_MODEL_BY_PROVIDER['dashscope-byok'] || 'qwen3.7-plus') || 'qwen3.7-plus');
40
+ const sanitizedMessages = this.prepareMessages(messages);
41
+ const payload = {
42
+ model: activeModel,
43
+ messages: sanitizedMessages,
44
+ temperature: resolveTemperature(options.temperature, 0.1)
45
+ };
46
+ if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
47
+ payload['max_tokens'] = Math.floor(options.maxTokens);
48
+ }
49
+ if (options.jsonMode) {
50
+ payload['response_format'] = { type: 'json_object' };
51
+ }
52
+ let freeFormPaths = new Map();
53
+ if (options.tools && options.tools.length > 0) {
54
+ const scanReport = scanAndAdaptToolsForProvider(options.tools, 'dashscope');
55
+ payload['tools'] = scanReport.adaptedTools;
56
+ payload['tool_choice'] = 'auto';
57
+ freeFormPaths = scanReport.freeFormPaths;
72
58
  }
73
- }
74
-
75
- throw new Error(`Qwen DashScope API Error (${response.status}): ${errorData}`);
59
+ const endpoint = this.baseUrl || 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
60
+ const requestOpts = {
61
+ url: endpoint,
62
+ method: 'POST',
63
+ headers: {
64
+ 'Content-Type': 'application/json',
65
+ 'Authorization': `Bearer ${apiKey}`
66
+ },
67
+ signal: options.signal,
68
+ timeoutMs: options.timeoutMs,
69
+ providerLabel: 'Qwen DashScope',
70
+ secrets: [apiKey],
71
+ hasApiKey: true,
72
+ allowInsecureHttp: this.allowInsecureHttp,
73
+ onHttpError: ({ status }) => {
74
+ let hostHasWorkspace = false;
75
+ try {
76
+ hostHasWorkspace = new URL(endpoint).hostname.includes('ws-');
77
+ }
78
+ catch {
79
+ hostHasWorkspace = false;
80
+ }
81
+ if (status === 401 && apiKey.startsWith('sk-ws-') && !hostHasWorkspace) {
82
+ throw new Error('\n[QWEN WORKSPACE CONFIGURATION ERROR]\n\nYou are using a Workspace-bound API Key (starts with sk-ws-), but you have not configured your Workspace Base URL.\n\nAlibaba requires a specific URL for these keys.\n\nHOW TO FIX THIS:\n1. Open your computer terminal.\n2. Run command: causyne config\n3. When asked for Custom Base URL, paste your Workspace URL from Alibaba (e.g. https://{Your-Workspace-ID}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions).\n\nAlternatively, use a Standard API Key (starts with sk-) which does not require a custom URL.');
83
+ }
84
+ }
85
+ };
86
+ const data = wantsStreaming(options)
87
+ ? await streamOpenAICompatibleChat({
88
+ ...requestOpts,
89
+ payload,
90
+ onChunk: options.onChunk,
91
+ onReasoningChunk: options.onReasoningChunk
92
+ })
93
+ : await safeProviderFetchJson({
94
+ ...requestOpts,
95
+ body: JSON.stringify(payload)
96
+ });
97
+ const normalized = normalizeOpenAIChatChoiceResponse(data, {
98
+ prefix: 'call_dashscope',
99
+ freeFormPaths
100
+ });
101
+ return {
102
+ content: normalized.content,
103
+ toolCalls: normalized.toolCalls,
104
+ reasoningContent: normalized.reasoningContent,
105
+ usage: this.normalizeUsage(normalized.rawUsage)
106
+ };
76
107
  }
77
-
78
- const data = await response.json();
79
- const normalized = normalizeOpenAIChatChoiceResponse(data, {
80
- prefix: 'call_dashscope',
81
- freeFormPaths
82
- });
83
-
84
- return {
85
- content: normalized.content,
86
- toolCalls: normalized.toolCalls,
87
- reasoningContent: normalized.reasoningContent,
88
- usage: this.normalizeUsage(normalized.rawUsage)
89
- };
90
- }
91
108
  }
@@ -0,0 +1,114 @@
1
+ import { canonicalModelId } from '../modelIds.js';
2
+ import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
+ import { LLMProvider, type ChatOptions, type ChatResponse, type ProviderConfig } from './base.js';
4
+ import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
+ import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
+ import {
7
+ requireApiKey,
8
+ resolveTemperature,
9
+ safeProviderFetchJson
10
+ } from './byokHttp.js';
11
+ import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
12
+
13
+ export class DashscopeByokProvider extends LLMProvider {
14
+ allowInsecureHttp: boolean;
15
+
16
+ constructor(config: ProviderConfig = {}) {
17
+ super(config);
18
+ let url = (typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '') || 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
19
+ try {
20
+ const parsed = new URL(url);
21
+ if (parsed.pathname.endsWith('/v1')) {
22
+ parsed.pathname += '/chat/completions';
23
+ url = parsed.toString();
24
+ } else if (parsed.pathname.endsWith('/v1/')) {
25
+ parsed.pathname += 'chat/completions';
26
+ url = parsed.toString();
27
+ }
28
+ } catch {
29
+ if (url.endsWith('/v1')) url += '/chat/completions';
30
+ else if (url.endsWith('/v1/')) url += 'chat/completions';
31
+ }
32
+
33
+ this.baseUrl = url;
34
+ this.allowInsecureHttp = config.allowInsecureHttp === true;
35
+ this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['dashscope-byok']) || '');
36
+ this.apiKey = config.apiKey;
37
+ this.visionModels = ['-vl-', '-vl', 'qwen3.6', 'qwen3.7', 'kimi-k2.5', 'kimi-k2.7'];
38
+ this.audioModels = ['-omni', 'qwen-audio', 'qwen2-audio'];
39
+ }
40
+
41
+ override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
42
+ const apiKey = requireApiKey(this.apiKey, 'Qwen DashScope');
43
+ const activeModel = String(canonicalModelId(this.model || DEFAULT_MODEL_BY_PROVIDER['dashscope-byok'] || 'qwen3.7-plus') || 'qwen3.7-plus');
44
+ const sanitizedMessages = this.prepareMessages(messages);
45
+
46
+ const payload: Record<string, any> = {
47
+ model: activeModel,
48
+ messages: sanitizedMessages,
49
+ temperature: resolveTemperature(options.temperature, 0.1)
50
+ };
51
+
52
+ if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
53
+ payload['max_tokens'] = Math.floor(options.maxTokens);
54
+ }
55
+
56
+ if (options.jsonMode) {
57
+ payload['response_format'] = { type: 'json_object' };
58
+ }
59
+
60
+ let freeFormPaths = new Map<string, string[][]>();
61
+ if (options.tools && options.tools.length > 0) {
62
+ const scanReport = scanAndAdaptToolsForProvider(options.tools, 'dashscope');
63
+ payload['tools'] = scanReport.adaptedTools;
64
+ payload['tool_choice'] = 'auto';
65
+ freeFormPaths = scanReport.freeFormPaths;
66
+ }
67
+
68
+ const endpoint = this.baseUrl || 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions';
69
+ const requestOpts = {
70
+ url: endpoint,
71
+ method: 'POST',
72
+ headers: {
73
+ 'Content-Type': 'application/json',
74
+ 'Authorization': `Bearer ${apiKey}`
75
+ },
76
+ signal: options.signal,
77
+ timeoutMs: options.timeoutMs,
78
+ providerLabel: 'Qwen DashScope',
79
+ secrets: [apiKey],
80
+ hasApiKey: true,
81
+ allowInsecureHttp: this.allowInsecureHttp,
82
+ onHttpError: ({ status }: { status: number }) => {
83
+ let hostHasWorkspace = false;
84
+ try { hostHasWorkspace = new URL(endpoint).hostname.includes('ws-'); } catch { hostHasWorkspace = false; }
85
+ if (status === 401 && apiKey.startsWith('sk-ws-') && !hostHasWorkspace) {
86
+ throw new Error('\n[QWEN WORKSPACE CONFIGURATION ERROR]\n\nYou are using a Workspace-bound API Key (starts with sk-ws-), but you have not configured your Workspace Base URL.\n\nAlibaba requires a specific URL for these keys.\n\nHOW TO FIX THIS:\n1. Open your computer terminal.\n2. Run command: causyne config\n3. When asked for Custom Base URL, paste your Workspace URL from Alibaba (e.g. https://{Your-Workspace-ID}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions).\n\nAlternatively, use a Standard API Key (starts with sk-) which does not require a custom URL.');
87
+ }
88
+ }
89
+ };
90
+
91
+ const data = wantsStreaming(options)
92
+ ? await streamOpenAICompatibleChat({
93
+ ...requestOpts,
94
+ payload,
95
+ onChunk: options.onChunk,
96
+ onReasoningChunk: options.onReasoningChunk
97
+ })
98
+ : await safeProviderFetchJson({
99
+ ...requestOpts,
100
+ body: JSON.stringify(payload)
101
+ });
102
+ const normalized = normalizeOpenAIChatChoiceResponse(data, {
103
+ prefix: 'call_dashscope',
104
+ freeFormPaths
105
+ });
106
+
107
+ return {
108
+ content: normalized.content,
109
+ toolCalls: normalized.toolCalls,
110
+ reasoningContent: normalized.reasoningContent,
111
+ usage: this.normalizeUsage(normalized.rawUsage)
112
+ };
113
+ }
114
+ }
@@ -3,72 +3,82 @@ 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
-
6
+ import { requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
7
+ import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
7
8
  export class DeepSeekProvider extends LLMProvider {
8
- constructor(config) {
9
- super(config);
10
- this.baseUrl = 'https://api.deepseek.com/v1/chat/completions';
11
- this.model = canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['deepseek']);
12
- // The deepseek-chat line is text-only; only the VL builds accept images.
13
- this.visionModels = ['-vl'];
14
- // DeepSeek exposes no audio input endpoint.
15
- this.audioModels = [];
16
- }
17
-
18
- async chat(messages, options = {}) {
19
- const sanitizedMessages = this.prepareMessages(messages);
20
-
21
- const payload = {
22
- model: this.model,
23
- messages: sanitizedMessages,
24
- temperature: options.temperature || 0.1,
25
- };
26
-
27
- if (options.jsonMode) {
28
- payload.response_format = { type: 'json_object' };
9
+ allowInsecureHttp;
10
+ constructor(config = {}) {
11
+ super(config);
12
+ const customUrl = typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
13
+ this.baseUrl = customUrl || 'https://api.deepseek.com/v1/chat/completions';
14
+ this.allowInsecureHttp = config.allowInsecureHttp === true;
15
+ this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['deepseek']) || '');
16
+ this.visionModels = ['-vl'];
17
+ this.audioModels = [];
18
+ this.preserveReasoningContent = true;
29
19
  }
30
-
31
- let targetUrl = this.baseUrl;
32
- let headers = {
33
- 'Content-Type': 'application/json'
34
- };
35
-
36
- if (this.apiKey) {
37
- headers['Authorization'] = `Bearer ${this.apiKey}`;
38
- } else {
39
- throw new Error("API key is required.");
20
+ isReasonerModel() {
21
+ const lowered = (this.model || '').trim().toLowerCase();
22
+ return lowered.includes('reasoner') || lowered.startsWith('deepseek-r1');
40
23
  }
41
-
42
- let freeFormPaths = new Map();
43
- if (options.tools && options.tools.length > 0) {
44
- const scanReport = scanAndAdaptToolsForProvider(options.tools, 'deepseek');
45
- payload.tools = scanReport.adaptedTools;
46
- payload.tool_choice = "auto";
47
- freeFormPaths = scanReport.freeFormPaths;
24
+ async chat(messages, options = {}) {
25
+ const apiKey = requireApiKey(this.apiKey, 'DeepSeek');
26
+ const sanitizedMessages = this.prepareMessages(messages);
27
+ const payload = {
28
+ model: this.model,
29
+ messages: sanitizedMessages
30
+ };
31
+ if (!this.isReasonerModel()) {
32
+ payload['temperature'] = resolveTemperature(options.temperature, 0.1);
33
+ }
34
+ if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
35
+ payload['max_tokens'] = Math.floor(options.maxTokens);
36
+ }
37
+ if (options.jsonMode) {
38
+ payload['response_format'] = { type: 'json_object' };
39
+ }
40
+ let freeFormPaths = new Map();
41
+ if (options.tools && options.tools.length > 0) {
42
+ const scanReport = scanAndAdaptToolsForProvider(options.tools, 'deepseek');
43
+ payload['tools'] = scanReport.adaptedTools;
44
+ payload['tool_choice'] = 'auto';
45
+ freeFormPaths = scanReport.freeFormPaths;
46
+ }
47
+ const endpoint = this.baseUrl || 'https://api.deepseek.com/v1/chat/completions';
48
+ const requestOpts = {
49
+ url: endpoint,
50
+ method: 'POST',
51
+ headers: {
52
+ 'Content-Type': 'application/json',
53
+ 'Authorization': `Bearer ${apiKey}`
54
+ },
55
+ signal: options.signal,
56
+ timeoutMs: options.timeoutMs,
57
+ providerLabel: 'DeepSeek',
58
+ secrets: [apiKey],
59
+ hasApiKey: true,
60
+ allowInsecureHttp: this.allowInsecureHttp
61
+ };
62
+ const data = wantsStreaming(options)
63
+ ? await streamOpenAICompatibleChat({
64
+ ...requestOpts,
65
+ payload,
66
+ onChunk: options.onChunk,
67
+ onReasoningChunk: options.onReasoningChunk
68
+ })
69
+ : await safeProviderFetchJson({
70
+ ...requestOpts,
71
+ body: JSON.stringify(payload)
72
+ });
73
+ const normalized = normalizeOpenAIChatChoiceResponse(data, {
74
+ prefix: 'call_deepseek',
75
+ freeFormPaths
76
+ });
77
+ return {
78
+ content: normalized.content,
79
+ toolCalls: normalized.toolCalls,
80
+ reasoningContent: normalized.reasoningContent,
81
+ usage: this.normalizeUsage(normalized.rawUsage)
82
+ };
48
83
  }
49
-
50
- const response = await fetch(targetUrl, {
51
- method: 'POST',
52
- headers: headers,
53
- body: JSON.stringify(payload)
54
- });
55
-
56
- if (!response.ok) {
57
- const errorData = await response.text();
58
- throw new Error(`DeepSeek API Error (${response.status}): ${errorData}`);
59
- }
60
-
61
- const data = await response.json();
62
- const normalized = normalizeOpenAIChatChoiceResponse(data, {
63
- prefix: 'call_deepseek',
64
- freeFormPaths
65
- });
66
-
67
- return {
68
- content: normalized.content,
69
- toolCalls: normalized.toolCalls,
70
- reasoningContent: normalized.reasoningContent,
71
- usage: this.normalizeUsage(normalized.rawUsage)
72
- };
73
- }
74
84
  }
@@ -0,0 +1,99 @@
1
+ import { canonicalModelId } from '../modelIds.js';
2
+ import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
+ import { LLMProvider, type ChatOptions, type ChatResponse, type ProviderConfig } from './base.js';
4
+ import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
+ import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
+ import {
7
+ requireApiKey,
8
+ resolveTemperature,
9
+ safeProviderFetchJson
10
+ } from './byokHttp.js';
11
+ import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
12
+
13
+ export class DeepSeekProvider extends LLMProvider {
14
+ allowInsecureHttp: boolean;
15
+
16
+ constructor(config: ProviderConfig = {}) {
17
+ super(config);
18
+ const customUrl = typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
19
+ this.baseUrl = customUrl || 'https://api.deepseek.com/v1/chat/completions';
20
+ this.allowInsecureHttp = config.allowInsecureHttp === true;
21
+ this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['deepseek']) || '');
22
+ this.visionModels = ['-vl'];
23
+ this.audioModels = [];
24
+ this.preserveReasoningContent = true;
25
+ }
26
+
27
+ isReasonerModel(): boolean {
28
+ const lowered = (this.model || '').trim().toLowerCase();
29
+ return lowered.includes('reasoner') || lowered.startsWith('deepseek-r1');
30
+ }
31
+
32
+ override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
33
+ const apiKey = requireApiKey(this.apiKey, 'DeepSeek');
34
+ const sanitizedMessages = this.prepareMessages(messages);
35
+
36
+ const payload: Record<string, any> = {
37
+ model: this.model,
38
+ messages: sanitizedMessages
39
+ };
40
+ if (!this.isReasonerModel()) {
41
+ payload['temperature'] = resolveTemperature(options.temperature, 0.1);
42
+ }
43
+
44
+ if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
45
+ payload['max_tokens'] = Math.floor(options.maxTokens);
46
+ }
47
+
48
+ if (options.jsonMode) {
49
+ payload['response_format'] = { type: 'json_object' };
50
+ }
51
+
52
+ let freeFormPaths = new Map<string, string[][]>();
53
+ if (options.tools && options.tools.length > 0) {
54
+ const scanReport = scanAndAdaptToolsForProvider(options.tools, 'deepseek');
55
+ payload['tools'] = scanReport.adaptedTools;
56
+ payload['tool_choice'] = 'auto';
57
+ freeFormPaths = scanReport.freeFormPaths;
58
+ }
59
+
60
+ const endpoint = this.baseUrl || 'https://api.deepseek.com/v1/chat/completions';
61
+ const requestOpts = {
62
+ url: endpoint,
63
+ method: 'POST',
64
+ headers: {
65
+ 'Content-Type': 'application/json',
66
+ 'Authorization': `Bearer ${apiKey}`
67
+ },
68
+ signal: options.signal,
69
+ timeoutMs: options.timeoutMs,
70
+ providerLabel: 'DeepSeek',
71
+ secrets: [apiKey],
72
+ hasApiKey: true,
73
+ allowInsecureHttp: this.allowInsecureHttp
74
+ };
75
+
76
+ const data = wantsStreaming(options)
77
+ ? await streamOpenAICompatibleChat({
78
+ ...requestOpts,
79
+ payload,
80
+ onChunk: options.onChunk,
81
+ onReasoningChunk: options.onReasoningChunk
82
+ })
83
+ : await safeProviderFetchJson({
84
+ ...requestOpts,
85
+ body: JSON.stringify(payload)
86
+ });
87
+ const normalized = normalizeOpenAIChatChoiceResponse(data, {
88
+ prefix: 'call_deepseek',
89
+ freeFormPaths
90
+ });
91
+
92
+ return {
93
+ content: normalized.content,
94
+ toolCalls: normalized.toolCalls,
95
+ reasoningContent: normalized.reasoningContent,
96
+ usage: this.normalizeUsage(normalized.rawUsage)
97
+ };
98
+ }
99
+ }
@@ -1,10 +1,3 @@
1
- // Provider construction, in one place.
2
- //
3
-
4
-
5
- // ("can the selected model hear?"), and a second copy would drift the moment a
6
-
7
-
8
1
  import { OpenAIProvider } from './openai.js';
9
2
  import { AnthropicProvider } from './anthropic.js';
10
3
  import { GeminiProvider } from './gemini.js';
@@ -20,26 +13,40 @@ import { AcpProvider, isAcpProvider } from './acp.js';
20
13
  import { PiProvider, isPiProvider } from './pi.js';
21
14
  import { AntigravityProvider, isAntigravityProvider } from './antigravity.js';
22
15
  import { OpenRouterProvider } from './openrouter.js';
23
-
24
16
  export function createProvider(config) {
25
- const p = config.provider?.toLowerCase();
26
- if (p === 'openai') return new OpenAIProvider(config);
27
- if (p === 'anthropic') return new AnthropicProvider(config);
28
- if (p === 'gemini') return new GeminiProvider(config);
29
- if (p === 'ollama') return new OllamaProvider(config);
30
- if (p === 'deepseek') return new DeepSeekProvider(config);
31
- if (p === 'dashscope-byok' || p === 'dashscope') return new DashscopeByokProvider(config);
32
- if (p === 'qwen') return new QwenByokProvider(config);
33
- if (p === 'openai-compatible') return new OpenAICompatibleProvider(config);
34
- if (p === 'xai' || p === 'grok') return new XAIProvider(config);
35
- if (p === 'moonshot' || p === 'kimi') return new MoonshotProvider(config);
36
- // Meta Model API. 'meta' and 'muse' both reach it: the vendor is Meta, the
37
- // model family is Muse, and users say either.
38
- if (p === 'muse' || p === 'meta') return new MuseProvider(config);
39
- if (p === 'openrouter' || p === 'openrouter-free') return new OpenRouterProvider(config);
40
- if (isAcpProvider(p)) return new AcpProvider(config);
41
- if (isPiProvider(p)) return new PiProvider(config);
42
- if (isAntigravityProvider(p)) return new AntigravityProvider(config);
43
-
44
- throw new Error("API Key Required. Causyne is a 100% Sovereign BYOK Engine. Please configure your API Provider and Key in Settings.");
17
+ if (!config || typeof config !== 'object') {
18
+ throw new Error('API Key Required. Causyne is a 100% Sovereign BYOK Engine. Please configure your API Provider and Key in Settings.');
19
+ }
20
+ const p = typeof config.provider === 'string' ? config.provider.trim().toLowerCase() : undefined;
21
+ if (p === 'openai')
22
+ return new OpenAIProvider(config);
23
+ if (p === 'anthropic')
24
+ return new AnthropicProvider(config);
25
+ if (p === 'gemini')
26
+ return new GeminiProvider(config);
27
+ if (p === 'ollama')
28
+ return new OllamaProvider(config);
29
+ if (p === 'deepseek')
30
+ return new DeepSeekProvider(config);
31
+ if (p === 'dashscope-byok' || p === 'dashscope')
32
+ return new DashscopeByokProvider(config);
33
+ if (p === 'qwen')
34
+ return new QwenByokProvider(config);
35
+ if (p === 'openai-compatible')
36
+ return new OpenAICompatibleProvider(config);
37
+ if (p === 'xai' || p === 'grok')
38
+ return new XAIProvider(config);
39
+ if (p === 'moonshot' || p === 'kimi')
40
+ return new MoonshotProvider(config);
41
+ if (p === 'muse' || p === 'meta')
42
+ return new MuseProvider(config);
43
+ if (p === 'openrouter' || p === 'openrouter-free')
44
+ return new OpenRouterProvider(config);
45
+ if (isAcpProvider(p))
46
+ return new AcpProvider(config);
47
+ if (isPiProvider(p))
48
+ return new PiProvider(config);
49
+ if (isAntigravityProvider(p))
50
+ return new AntigravityProvider(config);
51
+ throw new Error('API Key Required. Causyne is a 100% Sovereign BYOK Engine. Please configure your API Provider and Key in Settings.');
45
52
  }