@mcoda/mswarm 0.1.57 → 0.1.60
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 +19 -0
- package/dist/codali-executor.d.ts +266 -0
- package/dist/codali-executor.d.ts.map +1 -0
- package/dist/codali-executor.js +227 -0
- package/dist/codali-executor.js.map +1 -0
- package/dist/runtime.d.ts +36 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +219 -30
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +54 -0
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/agents/AgentProtocol.d.ts +287 -0
- package/dist/vendor/codali/agents/AgentProtocol.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentProtocol.js +365 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts +23 -0
- package/dist/vendor/codali/agents/AgentResolver.d.ts.map +1 -0
- package/dist/vendor/codali/agents/AgentResolver.js +77 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts +23 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts.map +1 -0
- package/dist/vendor/codali/agents/PhaseAgentSelector.js +287 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts +37 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/EvalCommand.js +333 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts +22 -0
- package/dist/vendor/codali/cli/FeedbackCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/FeedbackCommand.js +163 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts +78 -0
- package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/RunCommand.js +2261 -0
- package/dist/vendor/codali/cli.d.ts +3 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -0
- package/dist/vendor/codali/cli.js +109 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts +107 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ArchitectPlanner.js +1726 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts +25 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderOutputParser.js +164 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts +76 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/BuilderRunner.js +1159 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts +91 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextAssembler.js +4547 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts +19 -0
- package/dist/vendor/codali/cognitive/ContextBudget.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextBudget.js +35 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts +30 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextFileLoader.js +307 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts +47 -0
- package/dist/vendor/codali/cognitive/ContextManager.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextManager.js +272 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts +18 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextRedactor.js +53 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts +22 -0
- package/dist/vendor/codali/cognitive/ContextSelector.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSelector.js +431 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts +8 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSerializer.js +882 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts +27 -0
- package/dist/vendor/codali/cognitive/ContextStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextStore.js +79 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ContextSummarizer.js +45 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts +31 -0
- package/dist/vendor/codali/cognitive/CostEstimator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CostEstimator.js +66 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts +32 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/CriticEvaluator.js +297 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts +9 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/EvidenceGate.js +75 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts +12 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenExampleIndexer.js +34 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts +33 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/GoldenSetStore.js +159 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts +7 -0
- package/dist/vendor/codali/cognitive/IntentSignals.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/IntentSignals.js +285 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts +100 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/LearningGovernance.js +276 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts +64 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/MemoryWriteback.js +287 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts +49 -0
- package/dist/vendor/codali/cognitive/PatchApplier.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchApplier.js +199 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts +35 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchInterpreter.js +100 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts +7 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PatchOutputNormalizer.js +59 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts +17 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PostMortemAnalyzer.js +131 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts +3 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/PreferenceExtraction.js +85 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts +15 -0
- package/dist/vendor/codali/cognitive/Prompts.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Prompts.js +326 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts +16 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ProviderRouting.js +24 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts +12 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/QueryExtraction.js +262 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts +13 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/RunHistoryIndexer.js +125 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts +92 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/SmartPipeline.js +4804 -0
- package/dist/vendor/codali/cognitive/Types.d.ts +474 -0
- package/dist/vendor/codali/cognitive/Types.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/Types.js +7 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +57 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -0
- package/dist/vendor/codali/cognitive/ValidationRunner.js +515 -0
- package/dist/vendor/codali/config/Config.d.ts +249 -0
- package/dist/vendor/codali/config/Config.d.ts.map +1 -0
- package/dist/vendor/codali/config/Config.js +200 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts +56 -0
- package/dist/vendor/codali/config/ConfigLoader.d.ts.map +1 -0
- package/dist/vendor/codali/config/ConfigLoader.js +1246 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +113 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/DocdexClient.js +524 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts +35 -0
- package/dist/vendor/codali/eval/EvalRunner.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalRunner.js +38 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts +81 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts.map +1 -0
- package/dist/vendor/codali/eval/EvalTaskExecutor.js +371 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts +31 -0
- package/dist/vendor/codali/eval/GateEvaluator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/GateEvaluator.js +134 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts +28 -0
- package/dist/vendor/codali/eval/MetricTypes.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricTypes.js +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts +4 -0
- package/dist/vendor/codali/eval/MetricsAggregator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/MetricsAggregator.js +97 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts +29 -0
- package/dist/vendor/codali/eval/RegressionComparator.d.ts.map +1 -0
- package/dist/vendor/codali/eval/RegressionComparator.js +155 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts +52 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportInputAdapter.js +229 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts +32 -0
- package/dist/vendor/codali/eval/ReportSerializer.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportSerializer.js +33 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts +18 -0
- package/dist/vendor/codali/eval/ReportStore.d.ts.map +1 -0
- package/dist/vendor/codali/eval/ReportStore.js +96 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts +12 -0
- package/dist/vendor/codali/eval/SuiteLoader.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteLoader.js +51 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts +56 -0
- package/dist/vendor/codali/eval/SuiteSchema.d.ts.map +1 -0
- package/dist/vendor/codali/eval/SuiteSchema.js +357 -0
- package/dist/vendor/codali/index.d.ts +11 -0
- package/dist/vendor/codali/index.d.ts.map +1 -0
- package/dist/vendor/codali/index.js +5 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.js +282 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +300 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +192 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts +12 -0
- package/dist/vendor/codali/providers/ProviderRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderRegistry.js +28 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +81 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ProviderTypes.js +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +183 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.js +1363 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts +39 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeepInvestigationErrors.js +57 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts +27 -0
- package/dist/vendor/codali/runtime/RunContext.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunContext.js +51 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts +48 -0
- package/dist/vendor/codali/runtime/RunLogQuery.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogQuery.js +36 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts +19 -0
- package/dist/vendor/codali/runtime/RunLogReader.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogReader.js +361 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts +71 -0
- package/dist/vendor/codali/runtime/RunLogger.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunLogger.js +100 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts +117 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/RunTelemetryTypes.js +299 -0
- package/dist/vendor/codali/runtime/Runner.d.ts +66 -0
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/Runner.js +215 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts +3 -0
- package/dist/vendor/codali/runtime/StoragePaths.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/StoragePaths.js +19 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts +30 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkspaceLock.js +141 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts +14 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -0
- package/dist/vendor/codali/session/InstructionLoader.js +107 -0
- package/dist/vendor/codali/session/SessionStore.d.ts +81 -0
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -0
- package/dist/vendor/codali/session/SessionStore.js +244 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts +68 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts.map +1 -0
- package/dist/vendor/codali/subagents/SubagentOrchestrator.js +150 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts +9 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolRegistry.js +263 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts +66 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolTypes.js +32 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts +3 -0
- package/dist/vendor/codali/tools/diff/DiffTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/diff/DiffTool.js +34 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +4 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +453 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts +3 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.js +141 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts +3 -0
- package/dist/vendor/codali/tools/search/SearchTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/search/SearchTool.js +46 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +3 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/shell/ShellTool.js +104 -0
- package/package.json +5 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodexCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CodexCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAmB,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqHvH,qBAAa,gBAAiB,YAAW,QAAQ;IAGnC,OAAO,CAAC,MAAM;IAF1B,IAAI,SAAe;gBAEC,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoKpE"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
const CODEX_NO_SANDBOX_ENV = "MCODA_CODEX_NO_SANDBOX";
|
|
3
|
+
const CODEX_REASONING_ENV = "MCODA_CODEX_REASONING_EFFORT";
|
|
4
|
+
const CODEX_REASONING_ENV_FALLBACK = "CODEX_REASONING_EFFORT";
|
|
5
|
+
const CODEX_STUB_ENV = "MCODA_CLI_STUB";
|
|
6
|
+
const CODEX_COMMAND_ENV = "MCODA_CODEX_COMMAND";
|
|
7
|
+
const CODEX_COMMAND_ARGS_ENV = "MCODA_CODEX_COMMAND_ARGS";
|
|
8
|
+
const ALLOWED_REASONING_EFFORTS = new Set(["low", "medium", "high"]);
|
|
9
|
+
const DEFAULT_REASONING_EFFORT = "high";
|
|
10
|
+
const normalizeReasoningEffort = (raw) => {
|
|
11
|
+
const normalized = raw.trim().toLowerCase();
|
|
12
|
+
if (!normalized)
|
|
13
|
+
return undefined;
|
|
14
|
+
const compact = normalized.replace(/[\s_-]+/g, "");
|
|
15
|
+
if (compact === "xhigh" || compact === "veryhigh" || compact === "max")
|
|
16
|
+
return "high";
|
|
17
|
+
if (compact === "xmedium" || compact === "med")
|
|
18
|
+
return "medium";
|
|
19
|
+
if (compact === "xlow" || compact === "min")
|
|
20
|
+
return "low";
|
|
21
|
+
if (ALLOWED_REASONING_EFFORTS.has(normalized))
|
|
22
|
+
return normalized;
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
const resolveSandboxArgs = () => {
|
|
26
|
+
const raw = process.env[CODEX_NO_SANDBOX_ENV];
|
|
27
|
+
if (raw === undefined || raw.trim() === "") {
|
|
28
|
+
return { args: ["--dangerously-bypass-approvals-and-sandbox"], bypass: true };
|
|
29
|
+
}
|
|
30
|
+
const normalized = raw.trim().toLowerCase();
|
|
31
|
+
if (normalized === "0") {
|
|
32
|
+
return { args: [], bypass: false };
|
|
33
|
+
}
|
|
34
|
+
return { args: ["--dangerously-bypass-approvals-and-sandbox"], bypass: true };
|
|
35
|
+
};
|
|
36
|
+
const resolveReasoningEffort = () => {
|
|
37
|
+
const raw = process.env[CODEX_REASONING_ENV] ?? process.env[CODEX_REASONING_ENV_FALLBACK];
|
|
38
|
+
if (!raw)
|
|
39
|
+
return DEFAULT_REASONING_EFFORT;
|
|
40
|
+
return normalizeReasoningEffort(raw) ?? DEFAULT_REASONING_EFFORT;
|
|
41
|
+
};
|
|
42
|
+
const parseCommandArgs = (raw) => {
|
|
43
|
+
const trimmed = raw?.trim();
|
|
44
|
+
if (!trimmed)
|
|
45
|
+
return [];
|
|
46
|
+
if (trimmed.startsWith("[")) {
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(trimmed);
|
|
49
|
+
if (Array.isArray(parsed)) {
|
|
50
|
+
return parsed
|
|
51
|
+
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
|
52
|
+
.filter((entry) => entry.length > 0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// fall through to whitespace parsing
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return trimmed.split(/\s+/).filter(Boolean);
|
|
60
|
+
};
|
|
61
|
+
const resolveCodexCommand = () => {
|
|
62
|
+
const command = process.env[CODEX_COMMAND_ENV]?.trim() || "codex";
|
|
63
|
+
const preArgs = parseCommandArgs(process.env[CODEX_COMMAND_ARGS_ENV]);
|
|
64
|
+
return { command, preArgs };
|
|
65
|
+
};
|
|
66
|
+
const formatMessages = (messages) => {
|
|
67
|
+
return messages
|
|
68
|
+
.map((message) => {
|
|
69
|
+
const name = message.name ? `(${message.name})` : "";
|
|
70
|
+
return `${message.role}${name}: ${message.content}`;
|
|
71
|
+
})
|
|
72
|
+
.join("\n\n");
|
|
73
|
+
};
|
|
74
|
+
const extractAssistantText = (parsed) => {
|
|
75
|
+
if (!parsed || typeof parsed !== "object")
|
|
76
|
+
return null;
|
|
77
|
+
const type = typeof parsed.type === "string" ? parsed.type : "";
|
|
78
|
+
const isDelta = type.includes("delta");
|
|
79
|
+
const item = parsed.item ?? parsed;
|
|
80
|
+
const contentParts = Array.isArray(item?.content)
|
|
81
|
+
? item.content.map((entry) => entry?.text ?? entry?.content ?? "").filter(Boolean)
|
|
82
|
+
: [];
|
|
83
|
+
const text = (typeof item?.text === "string" && item.text) ||
|
|
84
|
+
(typeof item?.content === "string" && item.content) ||
|
|
85
|
+
(contentParts.length ? contentParts.join("") : "") ||
|
|
86
|
+
(typeof parsed.text === "string" && parsed.text) ||
|
|
87
|
+
(typeof parsed.delta === "string" && parsed.delta);
|
|
88
|
+
if (!text)
|
|
89
|
+
return null;
|
|
90
|
+
return { text, isDelta };
|
|
91
|
+
};
|
|
92
|
+
const parseCodexOutput = (raw) => {
|
|
93
|
+
const lines = raw.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
94
|
+
let message = "";
|
|
95
|
+
for (const line of lines) {
|
|
96
|
+
try {
|
|
97
|
+
const parsed = JSON.parse(line);
|
|
98
|
+
const event = extractAssistantText(parsed);
|
|
99
|
+
if (!event)
|
|
100
|
+
continue;
|
|
101
|
+
if (event.isDelta) {
|
|
102
|
+
message += event.text;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
message = event.text;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// ignore parse errors
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!message) {
|
|
113
|
+
return lines[lines.length - 1] ?? "";
|
|
114
|
+
}
|
|
115
|
+
return message;
|
|
116
|
+
};
|
|
117
|
+
const isIgnorableStdinError = (error) => error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED";
|
|
118
|
+
export class CodexCliProvider {
|
|
119
|
+
constructor(config) {
|
|
120
|
+
this.config = config;
|
|
121
|
+
this.name = "codex-cli";
|
|
122
|
+
}
|
|
123
|
+
async generate(request) {
|
|
124
|
+
const last = request.messages[request.messages.length - 1];
|
|
125
|
+
const emitToken = (token) => {
|
|
126
|
+
if (request.onEvent) {
|
|
127
|
+
request.onEvent({ type: "token", content: token });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
request.onToken?.(token);
|
|
131
|
+
};
|
|
132
|
+
if (process.env[CODEX_STUB_ENV] === "1") {
|
|
133
|
+
const stubContent = `codex-stub:${last?.content ?? ""}`;
|
|
134
|
+
if (request.stream) {
|
|
135
|
+
emitToken(stubContent);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
message: {
|
|
139
|
+
role: "assistant",
|
|
140
|
+
content: stubContent,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const prompt = formatMessages(request.messages);
|
|
145
|
+
const resolvedModel = this.config.model?.trim();
|
|
146
|
+
if (!resolvedModel) {
|
|
147
|
+
throw new Error("AUTH_ERROR: codex-cli provider requires model from selected mcoda agent/config.");
|
|
148
|
+
}
|
|
149
|
+
const sandbox = resolveSandboxArgs();
|
|
150
|
+
const codexCommand = resolveCodexCommand();
|
|
151
|
+
const args = [...codexCommand.preArgs, ...sandbox.args, "exec", "--model", resolvedModel, "--json"];
|
|
152
|
+
if (!sandbox.bypass) {
|
|
153
|
+
args.push("--full-auto");
|
|
154
|
+
}
|
|
155
|
+
const reasoningEffort = resolveReasoningEffort();
|
|
156
|
+
if (reasoningEffort) {
|
|
157
|
+
args.push("-c", `reasoning_effort=${reasoningEffort}`);
|
|
158
|
+
args.push("-c", `model_reasoning_effort=${reasoningEffort}`);
|
|
159
|
+
}
|
|
160
|
+
const timeoutMs = Math.max(1, this.config.timeoutMs ?? 300000);
|
|
161
|
+
const childEnv = { ...process.env };
|
|
162
|
+
if (reasoningEffort) {
|
|
163
|
+
childEnv[CODEX_REASONING_ENV] = reasoningEffort;
|
|
164
|
+
childEnv[CODEX_REASONING_ENV_FALLBACK] = reasoningEffort;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
delete childEnv[CODEX_REASONING_ENV];
|
|
168
|
+
delete childEnv[CODEX_REASONING_ENV_FALLBACK];
|
|
169
|
+
}
|
|
170
|
+
return await new Promise((resolve, reject) => {
|
|
171
|
+
const child = spawn(codexCommand.command, args, { stdio: ["pipe", "pipe", "pipe"], env: childEnv });
|
|
172
|
+
let raw = "";
|
|
173
|
+
let stderr = "";
|
|
174
|
+
let lineBuffer = "";
|
|
175
|
+
let message = "";
|
|
176
|
+
let settled = false;
|
|
177
|
+
const finishResolve = (response) => {
|
|
178
|
+
if (settled)
|
|
179
|
+
return;
|
|
180
|
+
settled = true;
|
|
181
|
+
clearTimeout(timeoutHandle);
|
|
182
|
+
resolve(response);
|
|
183
|
+
};
|
|
184
|
+
const finishReject = (error) => {
|
|
185
|
+
if (settled)
|
|
186
|
+
return;
|
|
187
|
+
settled = true;
|
|
188
|
+
clearTimeout(timeoutHandle);
|
|
189
|
+
reject(error);
|
|
190
|
+
};
|
|
191
|
+
const timeoutHandle = setTimeout(() => {
|
|
192
|
+
if (settled)
|
|
193
|
+
return;
|
|
194
|
+
const reason = `AUTH_ERROR: codex CLI timed out after ${timeoutMs}ms` +
|
|
195
|
+
(stderr.trim().length > 0 ? `: ${stderr.trim()}` : "");
|
|
196
|
+
child.kill("SIGTERM");
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
if (!settled) {
|
|
199
|
+
child.kill("SIGKILL");
|
|
200
|
+
}
|
|
201
|
+
}, 500).unref();
|
|
202
|
+
finishReject(new Error(reason));
|
|
203
|
+
}, timeoutMs);
|
|
204
|
+
timeoutHandle.unref();
|
|
205
|
+
const handleLine = (line) => {
|
|
206
|
+
const trimmed = line.trim();
|
|
207
|
+
if (!trimmed)
|
|
208
|
+
return;
|
|
209
|
+
const parsedLine = (() => {
|
|
210
|
+
try {
|
|
211
|
+
return JSON.parse(trimmed);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
})();
|
|
217
|
+
const event = extractAssistantText(parsedLine);
|
|
218
|
+
if (!event)
|
|
219
|
+
return;
|
|
220
|
+
if (event.isDelta) {
|
|
221
|
+
message += event.text;
|
|
222
|
+
if (request.stream)
|
|
223
|
+
emitToken(event.text);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
message = event.text;
|
|
227
|
+
if (request.stream)
|
|
228
|
+
emitToken(event.text);
|
|
229
|
+
};
|
|
230
|
+
child.stdout.on("data", (chunk) => {
|
|
231
|
+
const text = chunk.toString();
|
|
232
|
+
raw += text;
|
|
233
|
+
lineBuffer += text;
|
|
234
|
+
const lines = lineBuffer.split(/\r?\n/);
|
|
235
|
+
lineBuffer = lines.pop() ?? "";
|
|
236
|
+
for (const line of lines) {
|
|
237
|
+
handleLine(line);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
child.stderr.on("data", (chunk) => {
|
|
241
|
+
stderr += chunk.toString();
|
|
242
|
+
});
|
|
243
|
+
child.stdin.on("error", (error) => {
|
|
244
|
+
if (settled || isIgnorableStdinError(error))
|
|
245
|
+
return;
|
|
246
|
+
finishReject(new Error(`AUTH_ERROR: codex CLI stdin failed (${error.message})`));
|
|
247
|
+
});
|
|
248
|
+
child.on("error", (error) => {
|
|
249
|
+
finishReject(new Error(`AUTH_ERROR: codex CLI failed (${error.message})`));
|
|
250
|
+
});
|
|
251
|
+
child.on("close", (code) => {
|
|
252
|
+
if (settled)
|
|
253
|
+
return;
|
|
254
|
+
if (lineBuffer.trim()) {
|
|
255
|
+
handleLine(lineBuffer);
|
|
256
|
+
}
|
|
257
|
+
if (code !== 0) {
|
|
258
|
+
finishReject(new Error(`AUTH_ERROR: codex CLI failed (exit ${code}): ${stderr || raw}`.trim()));
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const output = message.trim() || parseCodexOutput(raw).trim();
|
|
262
|
+
finishResolve({ message: { role: "assistant", content: output }, raw });
|
|
263
|
+
});
|
|
264
|
+
setImmediate(() => {
|
|
265
|
+
if (settled)
|
|
266
|
+
return;
|
|
267
|
+
const stdin = child.stdin;
|
|
268
|
+
if (!stdin || stdin.destroyed || !stdin.writable)
|
|
269
|
+
return;
|
|
270
|
+
try {
|
|
271
|
+
stdin.end(prompt);
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
const err = error;
|
|
275
|
+
if (!isIgnorableStdinError(err)) {
|
|
276
|
+
finishReject(new Error(`AUTH_ERROR: codex CLI stdin failed (${err.message})`));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Provider, ProviderConfig, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
2
|
+
export declare class OllamaRemoteProvider implements Provider {
|
|
3
|
+
private config;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(config: ProviderConfig);
|
|
6
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=OllamaRemoteProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OllamaRemoteProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OllamaRemoteProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AA2J5B,qBAAa,oBAAqB,YAAW,QAAQ;IAGvC,OAAO,CAAC,MAAM;IAF1B,IAAI,SAAmB;gBAEH,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAwKpE"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
const parseToolArgs = (raw) => {
|
|
2
|
+
if (typeof raw !== "string")
|
|
3
|
+
return raw;
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(raw);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return raw;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const isObject = (value) => {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
};
|
|
14
|
+
const toToolCalls = (value) => {
|
|
15
|
+
if (!value)
|
|
16
|
+
return [];
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
return value.flatMap((entry) => toToolCalls(entry));
|
|
19
|
+
}
|
|
20
|
+
if (!isObject(value))
|
|
21
|
+
return [];
|
|
22
|
+
if (Array.isArray(value.tool_calls)) {
|
|
23
|
+
return toToolCalls(value.tool_calls);
|
|
24
|
+
}
|
|
25
|
+
const functionPayload = isObject(value.function) ? value.function : undefined;
|
|
26
|
+
if (functionPayload && typeof functionPayload.name === "string") {
|
|
27
|
+
const rawArgs = functionPayload.arguments ?? functionPayload.args ?? {};
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
id: `call_1`,
|
|
31
|
+
name: functionPayload.name,
|
|
32
|
+
args: parseToolArgs(rawArgs),
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
const name = (typeof value.tool === "string" && value.tool) ||
|
|
37
|
+
(typeof value.name === "string" && value.name) ||
|
|
38
|
+
(typeof value.tool_name === "string" && value.tool_name);
|
|
39
|
+
if (!name)
|
|
40
|
+
return [];
|
|
41
|
+
const rawArgs = (value.args ?? value.arguments ?? value.params ?? value.parameters ?? {});
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
id: `call_1`,
|
|
45
|
+
name,
|
|
46
|
+
args: parseToolArgs(rawArgs),
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
};
|
|
50
|
+
const extractToolCallsFromContent = (content) => {
|
|
51
|
+
if (!content)
|
|
52
|
+
return [];
|
|
53
|
+
const trimmed = content.trim();
|
|
54
|
+
const jsonBlocks = [];
|
|
55
|
+
const fenceRegex = /```(?:json)?\s*([\s\S]*?)```/gi;
|
|
56
|
+
let match;
|
|
57
|
+
while ((match = fenceRegex.exec(content)) !== null) {
|
|
58
|
+
const block = match[1]?.trim();
|
|
59
|
+
if (block)
|
|
60
|
+
jsonBlocks.push(block);
|
|
61
|
+
}
|
|
62
|
+
if (jsonBlocks.length === 0 && (trimmed.startsWith("{") || trimmed.startsWith("["))) {
|
|
63
|
+
jsonBlocks.push(trimmed);
|
|
64
|
+
}
|
|
65
|
+
for (const block of jsonBlocks) {
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(block);
|
|
68
|
+
const calls = toToolCalls(parsed);
|
|
69
|
+
if (calls.length) {
|
|
70
|
+
return calls.map((call, index) => ({ ...call, id: `call_${index + 1}` }));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// ignore parsing errors
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
};
|
|
79
|
+
const normalizeBaseUrl = (baseUrl) => {
|
|
80
|
+
const root = baseUrl ?? "http://127.0.0.1:11434";
|
|
81
|
+
return root.endsWith("/") ? root : `${root}/`;
|
|
82
|
+
};
|
|
83
|
+
const parseModelNotFound = (errorBody) => {
|
|
84
|
+
const match = errorBody.match(/model ['"]?([^'"]+)['"]? not found/i);
|
|
85
|
+
return match?.[1];
|
|
86
|
+
};
|
|
87
|
+
const fetchModelTags = async (baseUrl) => {
|
|
88
|
+
const url = new URL("api/tags", baseUrl).toString();
|
|
89
|
+
const resp = await fetch(url, { method: "GET" });
|
|
90
|
+
if (!resp.ok) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const data = (await resp.json());
|
|
95
|
+
return (data.models ?? []).map((entry) => entry.name).filter((name) => Boolean(name));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const pickFallbackModel = (requested, available) => {
|
|
102
|
+
if (!available.length)
|
|
103
|
+
return undefined;
|
|
104
|
+
const normalized = requested.toLowerCase();
|
|
105
|
+
const exact = available.find((name) => name.toLowerCase() === normalized);
|
|
106
|
+
if (exact)
|
|
107
|
+
return undefined;
|
|
108
|
+
const base = requested.split(":")[0]?.toLowerCase();
|
|
109
|
+
if (!base)
|
|
110
|
+
return undefined;
|
|
111
|
+
const candidates = available.filter((name) => name.toLowerCase() === base || name.toLowerCase().startsWith(`${base}:`));
|
|
112
|
+
if (!candidates.length)
|
|
113
|
+
return undefined;
|
|
114
|
+
const latest = candidates.find((name) => name.toLowerCase() === `${base}:latest`);
|
|
115
|
+
return latest ?? candidates[0];
|
|
116
|
+
};
|
|
117
|
+
const applyResponseFormat = (body, format) => {
|
|
118
|
+
if (!format)
|
|
119
|
+
return;
|
|
120
|
+
if (format.type === "json") {
|
|
121
|
+
body.format = "json";
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (format.type === "json_schema") {
|
|
125
|
+
body.format = format.schema ?? "json";
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (format.type === "gbnf" && format.grammar) {
|
|
129
|
+
body.grammar = format.grammar;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
export class OllamaRemoteProvider {
|
|
133
|
+
constructor(config) {
|
|
134
|
+
this.config = config;
|
|
135
|
+
this.name = "ollama-remote";
|
|
136
|
+
}
|
|
137
|
+
async generate(request) {
|
|
138
|
+
const baseUrl = normalizeBaseUrl(this.config.baseUrl);
|
|
139
|
+
const url = new URL("api/chat", baseUrl).toString();
|
|
140
|
+
let resolvedModel = this.config.model;
|
|
141
|
+
const emitToken = (token) => {
|
|
142
|
+
if (request.onEvent) {
|
|
143
|
+
request.onEvent({ type: "token", content: token });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
request.onToken?.(token);
|
|
147
|
+
};
|
|
148
|
+
const buildBody = (model) => {
|
|
149
|
+
const body = {
|
|
150
|
+
model,
|
|
151
|
+
messages: request.messages.map((message) => ({
|
|
152
|
+
role: message.role,
|
|
153
|
+
content: message.content,
|
|
154
|
+
name: message.name,
|
|
155
|
+
})),
|
|
156
|
+
tools: request.tools?.map((tool) => ({
|
|
157
|
+
type: "function",
|
|
158
|
+
function: {
|
|
159
|
+
name: tool.name,
|
|
160
|
+
description: tool.description,
|
|
161
|
+
parameters: tool.inputSchema ?? {},
|
|
162
|
+
},
|
|
163
|
+
})),
|
|
164
|
+
stream: request.stream ?? false,
|
|
165
|
+
};
|
|
166
|
+
if (request.temperature !== undefined) {
|
|
167
|
+
body.options = { temperature: request.temperature };
|
|
168
|
+
}
|
|
169
|
+
applyResponseFormat(body, request.responseFormat);
|
|
170
|
+
return body;
|
|
171
|
+
};
|
|
172
|
+
const execute = async (model) => {
|
|
173
|
+
const response = await fetch(url, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: {
|
|
176
|
+
"content-type": "application/json",
|
|
177
|
+
},
|
|
178
|
+
body: JSON.stringify(buildBody(model)),
|
|
179
|
+
});
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
const errorBody = await response.text();
|
|
182
|
+
return { response, errorBody };
|
|
183
|
+
}
|
|
184
|
+
return { response };
|
|
185
|
+
};
|
|
186
|
+
let { response, errorBody } = await execute(resolvedModel);
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
const missingModel = errorBody ? parseModelNotFound(errorBody) : undefined;
|
|
189
|
+
if (response.status === 404 && missingModel) {
|
|
190
|
+
const available = await fetchModelTags(baseUrl);
|
|
191
|
+
const fallback = pickFallbackModel(resolvedModel, available);
|
|
192
|
+
if (fallback) {
|
|
193
|
+
resolvedModel = fallback;
|
|
194
|
+
const retry = await execute(resolvedModel);
|
|
195
|
+
response = retry.response;
|
|
196
|
+
errorBody = retry.errorBody;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(`Ollama error ${response.status}: ${errorBody ?? ""}`.trim());
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (request.stream) {
|
|
204
|
+
if (!response.body) {
|
|
205
|
+
throw new Error("Ollama streaming response missing body");
|
|
206
|
+
}
|
|
207
|
+
const reader = response.body.getReader();
|
|
208
|
+
const decoder = new TextDecoder();
|
|
209
|
+
let buffer = "";
|
|
210
|
+
let content = "";
|
|
211
|
+
let toolCalls;
|
|
212
|
+
const rawChunks = [];
|
|
213
|
+
while (true) {
|
|
214
|
+
const { value, done } = await reader.read();
|
|
215
|
+
if (done)
|
|
216
|
+
break;
|
|
217
|
+
buffer += decoder.decode(value, { stream: true });
|
|
218
|
+
const lines = buffer.split("\n");
|
|
219
|
+
buffer = lines.pop() ?? "";
|
|
220
|
+
for (const line of lines) {
|
|
221
|
+
const trimmed = line.trim();
|
|
222
|
+
if (!trimmed)
|
|
223
|
+
continue;
|
|
224
|
+
try {
|
|
225
|
+
const chunk = JSON.parse(trimmed);
|
|
226
|
+
rawChunks.push(chunk);
|
|
227
|
+
const message = chunk.message ?? {};
|
|
228
|
+
if (message.content) {
|
|
229
|
+
content += message.content;
|
|
230
|
+
emitToken(message.content);
|
|
231
|
+
}
|
|
232
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
233
|
+
toolCalls = message.tool_calls.map((call, index) => ({
|
|
234
|
+
id: call.id ?? `call_${index + 1}`,
|
|
235
|
+
name: call.function.name,
|
|
236
|
+
args: parseToolArgs(call.function.arguments),
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// ignore malformed chunks
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (buffer.trim()) {
|
|
246
|
+
try {
|
|
247
|
+
const chunk = JSON.parse(buffer);
|
|
248
|
+
rawChunks.push(chunk);
|
|
249
|
+
const message = chunk.message ?? {};
|
|
250
|
+
if (message.content) {
|
|
251
|
+
content += message.content;
|
|
252
|
+
emitToken(message.content);
|
|
253
|
+
}
|
|
254
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
255
|
+
toolCalls = message.tool_calls.map((call, index) => ({
|
|
256
|
+
id: call.id ?? `call_${index + 1}`,
|
|
257
|
+
name: call.function.name,
|
|
258
|
+
args: parseToolArgs(call.function.arguments),
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// ignore trailing parse errors
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
267
|
+
const fallback = extractToolCallsFromContent(content);
|
|
268
|
+
if (fallback.length) {
|
|
269
|
+
toolCalls = fallback;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
message: { role: "assistant", content },
|
|
274
|
+
toolCalls,
|
|
275
|
+
raw: rawChunks,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const raw = (await response.json());
|
|
279
|
+
const message = raw.message ?? {};
|
|
280
|
+
let toolCalls = message.tool_calls?.map((call, index) => ({
|
|
281
|
+
id: call.id ?? `call_${index + 1}`,
|
|
282
|
+
name: call.function.name,
|
|
283
|
+
args: parseToolArgs(call.function.arguments),
|
|
284
|
+
}));
|
|
285
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
286
|
+
const fallback = extractToolCallsFromContent(message.content);
|
|
287
|
+
if (fallback.length) {
|
|
288
|
+
toolCalls = fallback;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
message: {
|
|
293
|
+
role: "assistant",
|
|
294
|
+
content: message.content ?? "",
|
|
295
|
+
},
|
|
296
|
+
toolCalls,
|
|
297
|
+
raw,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Provider, ProviderConfig, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
2
|
+
export declare class OpenAiCompatibleProvider implements Provider {
|
|
3
|
+
private config;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(config: ProviderConfig);
|
|
6
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=OpenAiCompatibleProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAuD5B,qBAAa,wBAAyB,YAAW,QAAQ;IAG3C,OAAO,CAAC,MAAM;IAF1B,IAAI,SAAuB;gBAEP,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA2KpE"}
|