@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.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +117 -0
- package/src/agent/errorClassifier.ts +165 -0
- package/src/agent/promptIntent.js +200 -0
- package/src/agent/promptIntent.ts +203 -0
- package/src/agent/toolArgValidator.js +97 -0
- package/src/agent/toolArgValidator.ts +112 -0
- package/src/agentLoop.js +33 -344
- package/src/agentLoop.ts +51 -352
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +116 -10
- package/src/autoUpdate.ts +149 -10
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/cliMode.js +16 -2
- package/src/commands.js +10 -9
- package/src/config.js +288 -272
- package/src/config.ts +342 -0
- package/src/configVault.js +271 -0
- package/src/configVault.ts +273 -0
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +305 -0
- package/src/headlessCli.ts +381 -0
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- package/src/mcp/mcpClient.js +38 -11
- package/src/mcp/mcpClient.ts +44 -11
- package/src/mcp/mcpRegistry.js +2 -5
- package/src/mcp/mcpRegistry.ts +2 -5
- package/src/mcp/mcpSecurity.js +189 -0
- package/src/mcp/mcpSecurity.ts +190 -0
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +263 -0
- package/src/osKeychain.ts +287 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +328 -385
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +397 -0
- package/src/providers/byokHttp.ts +497 -0
- package/src/providers/byokStream.js +748 -0
- package/src/providers/byokStream.ts +863 -0
- package/src/providers/dashscope-byok.js +98 -81
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +74 -64
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +229 -253
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +71 -64
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +116 -93
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +114 -65
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +194 -98
- package/src/providers/openrouter.ts +202 -97
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +97 -71
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +74 -64
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +486 -530
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +1287 -0
- package/src/sandboxPolicy.ts +1381 -0
- package/src/sessionJournal.js +55 -3
- package/src/sessionJournal.ts +58 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +513 -0
- package/src/tools/osSandbox.ts +588 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +108 -35
- package/src/tools/sysRun.ts +119 -31
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
package/src/providers/muse.js
CHANGED
|
@@ -1,169 +1,99 @@
|
|
|
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
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Meta Model API — the Muse family.
|
|
7
|
-
*
|
|
8
|
-
* Drop-in OpenAI-compatible, so this extends the compatible provider rather
|
|
9
|
-
* than reimplementing the wire format. Everything below is the part that is
|
|
10
|
-
* NOT generic: which models can see, which can hear, which reasoning levels a
|
|
11
|
-
* given tier will actually accept, and how wide the context is.
|
|
12
|
-
*
|
|
13
|
-
* Model IDs verified against the live status page (all seven operational):
|
|
14
|
-
* muse-spark-1.3, muse-spark-1.3-contributor, muse-spark-1.2,
|
|
15
|
-
* muse-spark-1.2-contributor, muse-spark-1.1, muse-image-1.0,
|
|
16
|
-
* muse-voice-transcribe-1.0.
|
|
17
|
-
*/
|
|
18
|
-
|
|
4
|
+
import { safeProviderFetchJson } from './byokHttp.js';
|
|
19
5
|
export const MUSE_BASE_URL = 'https://api.meta.ai/v1';
|
|
20
|
-
|
|
21
|
-
/** Every Muse Spark model shares this. Not a guess — it is the published spec. */
|
|
22
6
|
export const MUSE_CONTEXT_TOKENS = 1_048_576;
|
|
23
|
-
|
|
24
|
-
/** The image and speech models, which are not chat models and are reached elsewhere. */
|
|
25
7
|
export const MUSE_IMAGE_MODEL = 'muse-image-1.0';
|
|
26
8
|
export const MUSE_TRANSCRIBE_MODEL = 'muse-voice-transcribe-1.0';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Chat models, newest first, with what each one can actually do.
|
|
30
|
-
*
|
|
31
|
-
* `audio: false` on 1.3 is not caution, it is the documented state: "Audio
|
|
32
|
-
* understanding in Muse Spark 1.3 is currently not fully supported, and
|
|
33
|
-
* response quality for requests including audio content may be degraded."
|
|
34
|
-
* Advertising it would send a voice clip into a model that answers badly and
|
|
35
|
-
* charges for it — worse than declining, because the user cannot tell a
|
|
36
|
-
* degraded answer from a wrong one.
|
|
37
|
-
*/
|
|
38
9
|
export const MUSE_CHAT_MODELS = [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
10
|
+
{ id: 'muse-spark-1.3', tier: 'standard', audio: false, recommended: true },
|
|
11
|
+
{ id: 'muse-spark-1.3-contributor', tier: 'contributor', audio: false },
|
|
12
|
+
{ id: 'muse-spark-1.2', tier: 'standard', audio: true },
|
|
13
|
+
{ id: 'muse-spark-1.2-contributor', tier: 'contributor', audio: true },
|
|
14
|
+
{ id: 'muse-spark-1.1', tier: 'standard', audio: true }
|
|
44
15
|
];
|
|
45
|
-
|
|
46
|
-
/** Models that accept audio, as bare id prefixes for LLMProvider.supportsAudio. */
|
|
47
16
|
const AUDIO_CAPABLE = MUSE_CHAT_MODELS.filter((m) => m.audio).map((m) => m.id);
|
|
48
|
-
|
|
49
|
-
/** Is this a Contributor-tier model? Its inputs and outputs train Meta's models. */
|
|
50
17
|
export function isContributorModel(model) {
|
|
51
|
-
|
|
18
|
+
return String(model || '').toLowerCase().endsWith('-contributor');
|
|
52
19
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Reasoning effort the model will actually accept.
|
|
56
|
-
*
|
|
57
|
-
* `"max"` is Standard tier only. Sending it to a `-contributor` model is a
|
|
58
|
-
* rejected request, and a rejected request in the middle of an agent loop looks
|
|
59
|
-
* to the user like the agent broke — so it is stepped down here, once, where
|
|
60
|
-
* the reason can be written down.
|
|
61
|
-
*/
|
|
20
|
+
const VALID_MUSE_EFFORTS = new Set(['low', 'medium', 'high', 'max', 'off']);
|
|
62
21
|
export function clampReasoningEffort(effort, model) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
22
|
+
const requested = String(effort || '').trim().toLowerCase();
|
|
23
|
+
if (!requested || !VALID_MUSE_EFFORTS.has(requested))
|
|
24
|
+
return null;
|
|
25
|
+
if (requested === 'off')
|
|
26
|
+
return 'off';
|
|
27
|
+
if (requested === 'max' && isContributorModel(model))
|
|
28
|
+
return 'high';
|
|
29
|
+
return requested;
|
|
67
30
|
}
|
|
68
|
-
|
|
69
31
|
export class MuseProvider extends OpenAICompatibleProvider {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
async transcribeAudio(base64, mimeType = 'audio/wav') {
|
|
138
|
-
if (!base64 || !this.apiKey) return null;
|
|
139
|
-
|
|
140
|
-
const extension = String(mimeType).includes('mp3') ? 'mp3'
|
|
141
|
-
: String(mimeType).includes('mp4') || String(mimeType).includes('m4a') ? 'm4a'
|
|
142
|
-
: String(mimeType).includes('ogg') ? 'ogg'
|
|
143
|
-
: String(mimeType).includes('webm') ? 'webm'
|
|
144
|
-
: 'wav';
|
|
145
|
-
|
|
146
|
-
const form = new FormData();
|
|
147
|
-
form.append('model', MUSE_TRANSCRIBE_MODEL);
|
|
148
|
-
form.append('file', new Blob([Buffer.from(base64, 'base64')], { type: mimeType }), `clip.${extension}`);
|
|
149
|
-
|
|
150
|
-
const response = await fetch(this.transcribeUrl, {
|
|
151
|
-
method: 'POST',
|
|
152
|
-
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
153
|
-
body: form
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
if (!response.ok) {
|
|
157
|
-
const detail = await response.text();
|
|
158
|
-
throw new Error(`Muse Voice Transcribe (${response.status}): ${detail.slice(0, 400)}`);
|
|
32
|
+
contextTokens;
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
super(config);
|
|
35
|
+
if (!config.baseUrl)
|
|
36
|
+
this.baseUrl = `${MUSE_BASE_URL}/chat/completions`;
|
|
37
|
+
this.providerLabel = 'Meta (Muse)';
|
|
38
|
+
this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['muse']) || '');
|
|
39
|
+
this.visionModels = ['muse-spark'];
|
|
40
|
+
this.imagePayloadFormat = 'openai';
|
|
41
|
+
this.audioModels = AUDIO_CAPABLE;
|
|
42
|
+
this.audioPayloadFormat = 'openai';
|
|
43
|
+
this.maxAudioSeconds = null;
|
|
44
|
+
this.maxAudioBytes = null;
|
|
45
|
+
this.contextTokens = MUSE_CONTEXT_TOKENS;
|
|
46
|
+
this.reasoningEffort = clampReasoningEffort(config.reasoningEffort, this.model);
|
|
47
|
+
}
|
|
48
|
+
audioAlternative() {
|
|
49
|
+
if (this.supportsAudio)
|
|
50
|
+
return null;
|
|
51
|
+
return isContributorModel(this.model) ? 'muse-spark-1.2-contributor' : 'muse-spark-1.2';
|
|
52
|
+
}
|
|
53
|
+
get transcribeModel() {
|
|
54
|
+
return MUSE_TRANSCRIBE_MODEL;
|
|
55
|
+
}
|
|
56
|
+
get transcribeUrl() {
|
|
57
|
+
return `${MUSE_BASE_URL}/asr/transcribe`;
|
|
58
|
+
}
|
|
59
|
+
get canTranscribe() {
|
|
60
|
+
const key = typeof this.apiKey === 'string' ? this.apiKey.trim() : '';
|
|
61
|
+
return Boolean(key) && process.env.CAUSYNE_MUSE_ASR === '1';
|
|
62
|
+
}
|
|
63
|
+
async transcribeAudio(base64, mimeType = 'audio/wav', options = {}) {
|
|
64
|
+
const key = typeof this.apiKey === 'string' ? this.apiKey.trim() : '';
|
|
65
|
+
if (typeof base64 !== 'string' || !base64.trim() || !key)
|
|
66
|
+
return null;
|
|
67
|
+
const maxAudioBytes = 25 * 1024 * 1024;
|
|
68
|
+
const audioBuf = Buffer.from(base64, 'base64');
|
|
69
|
+
if (audioBuf.byteLength === 0 || audioBuf.byteLength > maxAudioBytes) {
|
|
70
|
+
throw new Error(`Muse Voice Transcribe audio clip exceeds maximum size (${maxAudioBytes} bytes).`);
|
|
71
|
+
}
|
|
72
|
+
const extension = String(mimeType).includes('mp3') ? 'mp3'
|
|
73
|
+
: String(mimeType).includes('mp4') || String(mimeType).includes('m4a') ? 'm4a'
|
|
74
|
+
: String(mimeType).includes('ogg') ? 'ogg'
|
|
75
|
+
: String(mimeType).includes('webm') ? 'webm'
|
|
76
|
+
: 'wav';
|
|
77
|
+
const form = new FormData();
|
|
78
|
+
form.append('model', MUSE_TRANSCRIBE_MODEL);
|
|
79
|
+
form.append('file', new Blob([audioBuf], { type: mimeType }), `clip.${extension}`);
|
|
80
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
81
|
+
const data = await safeProviderFetchJson({
|
|
82
|
+
url: this.transcribeUrl,
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
85
|
+
body: form,
|
|
86
|
+
signal: opts['signal'],
|
|
87
|
+
timeoutMs: opts['timeoutMs'],
|
|
88
|
+
providerLabel: 'Muse Voice Transcribe',
|
|
89
|
+
secrets: [key],
|
|
90
|
+
hasApiKey: true,
|
|
91
|
+
allowInsecureHttp: this.allowInsecureHttp
|
|
92
|
+
});
|
|
93
|
+
const safeData = data && typeof data === 'object' ? data : {};
|
|
94
|
+
const text = safeData['text']
|
|
95
|
+
|| safeData['transcript']
|
|
96
|
+
|| (Array.isArray(safeData['turns']) ? safeData['turns'].map((t) => (t && typeof t === 'object' && typeof t.text === 'string' ? t.text : '')).filter(Boolean).join(' ') : '');
|
|
97
|
+
return String(text || '').trim() || null;
|
|
159
98
|
}
|
|
160
|
-
|
|
161
|
-
const data = await response.json();
|
|
162
|
-
// Accept the shapes a transcription endpoint plausibly answers in, rather
|
|
163
|
-
// than betting the feature on one field name.
|
|
164
|
-
const text = data.text
|
|
165
|
-
|| data.transcript
|
|
166
|
-
|| (Array.isArray(data.turns) ? data.turns.map((t) => t.text).filter(Boolean).join(' ') : '');
|
|
167
|
-
return String(text || '').trim() || null;
|
|
168
|
-
}
|
|
169
99
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { canonicalModelId } from '../modelIds.js';
|
|
2
|
+
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
3
|
+
import type { ProviderConfig } from './base.js';
|
|
4
|
+
import { OpenAICompatibleProvider } from './openai-compatible.js';
|
|
5
|
+
import { safeProviderFetchJson } from './byokHttp.js';
|
|
6
|
+
|
|
7
|
+
export const MUSE_BASE_URL = 'https://api.meta.ai/v1';
|
|
8
|
+
export const MUSE_CONTEXT_TOKENS = 1_048_576;
|
|
9
|
+
export const MUSE_IMAGE_MODEL = 'muse-image-1.0';
|
|
10
|
+
export const MUSE_TRANSCRIBE_MODEL = 'muse-voice-transcribe-1.0';
|
|
11
|
+
|
|
12
|
+
export interface MuseChatModelSpec {
|
|
13
|
+
id: string;
|
|
14
|
+
tier: 'standard' | 'contributor';
|
|
15
|
+
audio: boolean;
|
|
16
|
+
recommended?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MUSE_CHAT_MODELS: readonly MuseChatModelSpec[] = [
|
|
20
|
+
{ id: 'muse-spark-1.3', tier: 'standard', audio: false, recommended: true },
|
|
21
|
+
{ id: 'muse-spark-1.3-contributor', tier: 'contributor', audio: false },
|
|
22
|
+
{ id: 'muse-spark-1.2', tier: 'standard', audio: true },
|
|
23
|
+
{ id: 'muse-spark-1.2-contributor', tier: 'contributor', audio: true },
|
|
24
|
+
{ id: 'muse-spark-1.1', tier: 'standard', audio: true }
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const AUDIO_CAPABLE: string[] = MUSE_CHAT_MODELS.filter((m) => m.audio).map((m) => m.id);
|
|
28
|
+
|
|
29
|
+
export function isContributorModel(model: unknown): boolean {
|
|
30
|
+
return String(model || '').toLowerCase().endsWith('-contributor');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const VALID_MUSE_EFFORTS = new Set(['low', 'medium', 'high', 'max', 'off']);
|
|
34
|
+
|
|
35
|
+
export function clampReasoningEffort(effort: unknown, model: unknown): string | null {
|
|
36
|
+
const requested = String(effort || '').trim().toLowerCase();
|
|
37
|
+
if (!requested || !VALID_MUSE_EFFORTS.has(requested)) return null;
|
|
38
|
+
if (requested === 'off') return 'off';
|
|
39
|
+
if (requested === 'max' && isContributorModel(model)) return 'high';
|
|
40
|
+
return requested;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class MuseProvider extends OpenAICompatibleProvider {
|
|
44
|
+
contextTokens: number;
|
|
45
|
+
|
|
46
|
+
constructor(config: ProviderConfig = {}) {
|
|
47
|
+
super(config);
|
|
48
|
+
|
|
49
|
+
if (!config.baseUrl) this.baseUrl = `${MUSE_BASE_URL}/chat/completions`;
|
|
50
|
+
this.providerLabel = 'Meta (Muse)';
|
|
51
|
+
this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['muse']) || '');
|
|
52
|
+
this.visionModels = ['muse-spark'];
|
|
53
|
+
this.imagePayloadFormat = 'openai';
|
|
54
|
+
this.audioModels = AUDIO_CAPABLE;
|
|
55
|
+
this.audioPayloadFormat = 'openai';
|
|
56
|
+
this.maxAudioSeconds = null;
|
|
57
|
+
this.maxAudioBytes = null;
|
|
58
|
+
this.contextTokens = MUSE_CONTEXT_TOKENS;
|
|
59
|
+
this.reasoningEffort = clampReasoningEffort(config.reasoningEffort, this.model);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override audioAlternative(): string | null {
|
|
63
|
+
if (this.supportsAudio) return null;
|
|
64
|
+
return isContributorModel(this.model) ? 'muse-spark-1.2-contributor' : 'muse-spark-1.2';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get transcribeModel(): string {
|
|
68
|
+
return MUSE_TRANSCRIBE_MODEL;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get transcribeUrl(): string {
|
|
72
|
+
return `${MUSE_BASE_URL}/asr/transcribe`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override get canTranscribe(): boolean {
|
|
76
|
+
const key = typeof this.apiKey === 'string' ? this.apiKey.trim() : '';
|
|
77
|
+
return Boolean(key) && process.env.CAUSYNE_MUSE_ASR === '1';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
override async transcribeAudio(
|
|
81
|
+
base64?: string,
|
|
82
|
+
mimeType = 'audio/wav',
|
|
83
|
+
options: Record<string, any> = {}
|
|
84
|
+
): Promise<string | null> {
|
|
85
|
+
const key = typeof this.apiKey === 'string' ? this.apiKey.trim() : '';
|
|
86
|
+
if (typeof base64 !== 'string' || !base64.trim() || !key) return null;
|
|
87
|
+
const maxAudioBytes = 25 * 1024 * 1024;
|
|
88
|
+
const audioBuf = Buffer.from(base64, 'base64');
|
|
89
|
+
if (audioBuf.byteLength === 0 || audioBuf.byteLength > maxAudioBytes) {
|
|
90
|
+
throw new Error(`Muse Voice Transcribe audio clip exceeds maximum size (${maxAudioBytes} bytes).`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const extension = String(mimeType).includes('mp3') ? 'mp3'
|
|
94
|
+
: String(mimeType).includes('mp4') || String(mimeType).includes('m4a') ? 'm4a'
|
|
95
|
+
: String(mimeType).includes('ogg') ? 'ogg'
|
|
96
|
+
: String(mimeType).includes('webm') ? 'webm'
|
|
97
|
+
: 'wav';
|
|
98
|
+
|
|
99
|
+
const form = new FormData();
|
|
100
|
+
form.append('model', MUSE_TRANSCRIBE_MODEL);
|
|
101
|
+
form.append('file', new Blob([audioBuf], { type: mimeType }), `clip.${extension}`);
|
|
102
|
+
|
|
103
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
104
|
+
const data: Record<string, any> = await safeProviderFetchJson({
|
|
105
|
+
url: this.transcribeUrl,
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
108
|
+
body: form,
|
|
109
|
+
signal: opts['signal'],
|
|
110
|
+
timeoutMs: opts['timeoutMs'],
|
|
111
|
+
providerLabel: 'Muse Voice Transcribe',
|
|
112
|
+
secrets: [key],
|
|
113
|
+
hasApiKey: true,
|
|
114
|
+
allowInsecureHttp: this.allowInsecureHttp
|
|
115
|
+
});
|
|
116
|
+
const safeData = data && typeof data === 'object' ? data : {};
|
|
117
|
+
const text = safeData['text']
|
|
118
|
+
|| safeData['transcript']
|
|
119
|
+
|| (Array.isArray(safeData['turns']) ? safeData['turns'].map((t: any) => (t && typeof t === 'object' && typeof t.text === 'string' ? t.text : '')).filter(Boolean).join(' ') : '');
|
|
120
|
+
return String(text || '').trim() || null;
|
|
121
|
+
}
|
|
122
|
+
}
|
package/src/providers/ollama.js
CHANGED
|
@@ -2,102 +2,125 @@ import { canonicalModelId } from '../modelIds.js';
|
|
|
2
2
|
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
3
3
|
import { LLMProvider } from './base.js';
|
|
4
4
|
import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
|
|
5
|
-
import {
|
|
6
|
-
normalizeMessagesForOllama,
|
|
7
|
-
normalizeOpenAIToolCalls,
|
|
8
|
-
extractTextToolCalls
|
|
9
|
-
} from './wireNormalizer.js';
|
|
5
|
+
import { normalizeMessagesForOllama, normalizeOpenAIToolCalls, extractTextToolCalls } from './wireNormalizer.js';
|
|
10
6
|
import { stripToolCallMarkup } from '../implementationPlan.js';
|
|
11
|
-
|
|
7
|
+
import { resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
|
|
8
|
+
import { streamOllamaChat, wantsStreaming } from './byokStream.js';
|
|
12
9
|
export class OllamaProvider extends LLMProvider {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (block.type === 'text') {
|
|
36
|
-
text.push(block.text);
|
|
37
|
-
} else if (block.type === 'image' && block.source?.type === 'base64') {
|
|
38
|
-
images.push(block.source.data);
|
|
39
|
-
} else if (block.type === 'image_url' && typeof block.image_url?.url === 'string') {
|
|
40
|
-
const encoded = block.image_url.url.split('base64,')[1];
|
|
41
|
-
if (encoded) images.push(encoded);
|
|
42
|
-
}
|
|
10
|
+
allowInsecureHttp;
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
super(config);
|
|
13
|
+
const rawUrl = typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
|
|
14
|
+
let resolvedUrl = rawUrl || 'http://localhost:11434/api/chat';
|
|
15
|
+
if (rawUrl) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = new URL(rawUrl);
|
|
18
|
+
if (parsed.pathname === '' || parsed.pathname === '/') {
|
|
19
|
+
parsed.pathname = '/api/chat';
|
|
20
|
+
resolvedUrl = parsed.toString();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
resolvedUrl = rawUrl;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.baseUrl = resolvedUrl;
|
|
28
|
+
this.allowInsecureHttp = config.allowInsecureHttp === true;
|
|
29
|
+
this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['ollama']) || '');
|
|
30
|
+
this.visionModels = ['llava', 'vision', 'bakllava', 'moondream', 'minicpm-v', 'gemma3', 'qwen2.5vl', 'qwen3-vl'];
|
|
31
|
+
this.audioModels = [];
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
33
|
+
normalizeImageBlocks(msg) {
|
|
34
|
+
if (!Array.isArray(msg.content))
|
|
35
|
+
return msg;
|
|
36
|
+
const text = [];
|
|
37
|
+
const images = [];
|
|
38
|
+
for (const block of msg.content) {
|
|
39
|
+
if (!block || typeof block !== 'object')
|
|
40
|
+
continue;
|
|
41
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
42
|
+
text.push(block.text);
|
|
43
|
+
}
|
|
44
|
+
else if (block.type === 'image' && block.source?.type === 'base64') {
|
|
45
|
+
images.push(block.source.data);
|
|
46
|
+
}
|
|
47
|
+
else if (block.type === 'image_url' && typeof block.image_url?.url === 'string') {
|
|
48
|
+
const encoded = block.image_url.url.split('base64,')[1];
|
|
49
|
+
if (encoded)
|
|
50
|
+
images.push(encoded);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const normalized = { ...msg, content: text.join('\n') };
|
|
54
|
+
if (images.length > 0)
|
|
55
|
+
normalized['images'] = images;
|
|
56
|
+
return normalized;
|
|
67
57
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
async chat(messages, options = {}) {
|
|
59
|
+
const sanitizedMessages = normalizeMessagesForOllama(this.prepareMessages(messages));
|
|
60
|
+
const ollamaOptions = {
|
|
61
|
+
temperature: resolveTemperature(options.temperature, 0.1)
|
|
62
|
+
};
|
|
63
|
+
if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
|
|
64
|
+
ollamaOptions['num_predict'] = Math.floor(options.maxTokens);
|
|
65
|
+
}
|
|
66
|
+
const payload = {
|
|
67
|
+
model: this.model,
|
|
68
|
+
messages: sanitizedMessages,
|
|
69
|
+
stream: false,
|
|
70
|
+
options: ollamaOptions,
|
|
71
|
+
...(options.jsonMode ? { format: 'json' } : {})
|
|
72
|
+
};
|
|
73
|
+
let freeFormPaths = new Map();
|
|
74
|
+
if (options.tools && options.tools.length > 0) {
|
|
75
|
+
const scanReport = scanAndAdaptToolsForProvider(options.tools, 'ollama');
|
|
76
|
+
payload['tools'] = scanReport.adaptedTools;
|
|
77
|
+
freeFormPaths = scanReport.freeFormPaths;
|
|
78
|
+
}
|
|
79
|
+
const endpoint = this.baseUrl || 'http://localhost:11434/api/chat';
|
|
80
|
+
const trimmedKey = typeof this.apiKey === 'string' ? this.apiKey.trim() : '';
|
|
81
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
82
|
+
if (trimmedKey)
|
|
83
|
+
headers['Authorization'] = `Bearer ${trimmedKey}`;
|
|
84
|
+
const requestOpts = {
|
|
85
|
+
url: endpoint,
|
|
86
|
+
method: 'POST',
|
|
87
|
+
headers,
|
|
88
|
+
signal: options.signal,
|
|
89
|
+
timeoutMs: options.timeoutMs,
|
|
90
|
+
providerLabel: 'Ollama',
|
|
91
|
+
secrets: trimmedKey ? [trimmedKey] : [],
|
|
92
|
+
hasApiKey: Boolean(trimmedKey),
|
|
93
|
+
allowInsecureHttp: this.allowInsecureHttp
|
|
94
|
+
};
|
|
95
|
+
const data = wantsStreaming(options)
|
|
96
|
+
? await streamOllamaChat({
|
|
97
|
+
...requestOpts,
|
|
98
|
+
payload,
|
|
99
|
+
onChunk: options.onChunk,
|
|
100
|
+
onReasoningChunk: options.onReasoningChunk
|
|
101
|
+
})
|
|
102
|
+
: await safeProviderFetchJson({
|
|
103
|
+
...requestOpts,
|
|
104
|
+
body: JSON.stringify(payload)
|
|
105
|
+
});
|
|
106
|
+
let content = typeof data['message']?.content === 'string' ? data['message'].content : '';
|
|
107
|
+
const reasoningContent = typeof data['message']?.thinking === 'string' ? data['message'].thinking.trim() : '';
|
|
108
|
+
let toolCalls = normalizeOpenAIToolCalls(data['message']?.tool_calls, freeFormPaths, 'call_ollama');
|
|
109
|
+
if (toolCalls.length === 0 && content) {
|
|
110
|
+
const extracted = extractTextToolCalls(content, 'call_ollama_text', freeFormPaths);
|
|
111
|
+
if (extracted.length > 0) {
|
|
112
|
+
toolCalls = extracted;
|
|
113
|
+
content = stripToolCallMarkup(content).trim();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
content,
|
|
118
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
119
|
+
...(reasoningContent ? { reasoningContent } : {}),
|
|
120
|
+
usage: {
|
|
121
|
+
promptTokens: typeof data['prompt_eval_count'] === 'number' && Number.isFinite(data['prompt_eval_count']) && data['prompt_eval_count'] > 0 ? data['prompt_eval_count'] : 0,
|
|
122
|
+
completionTokens: typeof data['eval_count'] === 'number' && Number.isFinite(data['eval_count']) && data['eval_count'] > 0 ? data['eval_count'] : 0
|
|
123
|
+
}
|
|
124
|
+
};
|
|
78
125
|
}
|
|
79
|
-
|
|
80
|
-
const data = await response.json();
|
|
81
|
-
|
|
82
|
-
// Ollama returns tool calls with no id and object arguments instead of JSON strings.
|
|
83
|
-
// Normalize through wireNormalizer so sanitizeSequences and toolSelfRepair see one contract.
|
|
84
|
-
let content = typeof data.message?.content === 'string' ? data.message.content : '';
|
|
85
|
-
let toolCalls = normalizeOpenAIToolCalls(data.message?.tool_calls, freeFormPaths, 'call_ollama');
|
|
86
|
-
if (toolCalls.length === 0 && content) {
|
|
87
|
-
const extracted = extractTextToolCalls(content, 'call_ollama_text', freeFormPaths);
|
|
88
|
-
if (extracted.length > 0) {
|
|
89
|
-
toolCalls = extracted;
|
|
90
|
-
content = stripToolCallMarkup(content).trim();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
content,
|
|
96
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
97
|
-
usage: {
|
|
98
|
-
promptTokens: data.prompt_eval_count || 0,
|
|
99
|
-
completionTokens: data.eval_count || 0
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
126
|
}
|