erosolar-cli 1.5.2 → 1.5.4
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/config/security-deployment.json +54 -0
- package/dist/bin/adapters/node/index.js +33 -0
- package/dist/bin/adapters/types.js +1 -0
- package/dist/bin/alpha-zero/agentWrapper.js +165 -0
- package/dist/bin/alpha-zero/codeEvaluator.js +272 -0
- package/dist/bin/alpha-zero/competitiveRunner.js +219 -0
- package/dist/bin/alpha-zero/index.js +98 -0
- package/dist/bin/alpha-zero/introspection.js +298 -0
- package/dist/bin/alpha-zero/metricsTracker.js +207 -0
- package/dist/bin/alpha-zero/security/core.js +269 -0
- package/dist/bin/alpha-zero/security/google.js +308 -0
- package/dist/bin/alpha-zero/security/googleLoader.js +40 -0
- package/dist/bin/alpha-zero/security/index.js +31 -0
- package/dist/bin/alpha-zero/security/simulation.js +274 -0
- package/dist/bin/alpha-zero/selfModification.js +231 -0
- package/dist/bin/alpha-zero/types.js +30 -0
- package/dist/bin/bin/erosolar-optimized.js +205 -0
- package/dist/bin/capabilities/agentSpawningCapability.js +116 -0
- package/dist/bin/capabilities/bashCapability.js +22 -0
- package/dist/bin/capabilities/cloudCapability.js +36 -0
- package/dist/bin/capabilities/codeAnalysisCapability.js +22 -0
- package/dist/bin/capabilities/codeQualityCapability.js +23 -0
- package/dist/bin/capabilities/dependencySecurityCapability.js +22 -0
- package/dist/bin/capabilities/devCapability.js +22 -0
- package/dist/bin/capabilities/editCapability.js +28 -0
- package/dist/bin/capabilities/emailCapability.js +20 -0
- package/dist/bin/capabilities/enhancedGitCapability.js +221 -0
- package/dist/bin/capabilities/filesystemCapability.js +22 -0
- package/dist/bin/capabilities/globCapability.js +28 -0
- package/dist/bin/capabilities/interactionCapability.js +20 -0
- package/dist/bin/capabilities/learnCapability.js +22 -0
- package/dist/bin/capabilities/mcpCapability.js +20 -0
- package/dist/bin/capabilities/notebookCapability.js +28 -0
- package/dist/bin/capabilities/planningCapability.js +27 -0
- package/dist/bin/capabilities/refactoringCapability.js +23 -0
- package/dist/bin/capabilities/repoChecksCapability.js +22 -0
- package/dist/bin/capabilities/searchCapability.js +22 -0
- package/dist/bin/capabilities/skillCapability.js +76 -0
- package/dist/bin/capabilities/taskManagementCapability.js +20 -0
- package/dist/bin/capabilities/testingCapability.js +23 -0
- package/dist/bin/capabilities/toolManifest.js +159 -0
- package/dist/bin/capabilities/toolRegistry.js +114 -0
- package/dist/bin/capabilities/webCapability.js +20 -0
- package/dist/bin/config.js +139 -0
- package/dist/bin/contracts/v1/agent.js +7 -0
- package/dist/bin/contracts/v1/agentProfileManifest.js +8 -0
- package/dist/bin/contracts/v1/agentRules.js +9 -0
- package/dist/bin/contracts/v1/toolAccess.js +8 -0
- package/dist/bin/core/agent.js +362 -0
- package/dist/bin/core/agentProfileManifest.js +187 -0
- package/dist/bin/core/agentProfiles.js +34 -0
- package/dist/bin/core/agentRulebook.js +135 -0
- package/dist/bin/core/agentSchemaLoader.js +233 -0
- package/dist/bin/core/contextManager.js +412 -0
- package/dist/bin/core/contextWindow.js +122 -0
- package/dist/bin/core/customCommands.js +80 -0
- package/dist/bin/core/errors/apiKeyErrors.js +114 -0
- package/dist/bin/core/errors/errorTypes.js +340 -0
- package/dist/bin/core/errors/safetyValidator.js +304 -0
- package/dist/bin/core/errors.js +32 -0
- package/dist/bin/core/modelDiscovery.js +755 -0
- package/dist/bin/core/preferences.js +224 -0
- package/dist/bin/core/schemaValidator.js +92 -0
- package/dist/bin/core/secretStore.js +199 -0
- package/dist/bin/core/sessionStore.js +187 -0
- package/dist/bin/core/toolRuntime.js +290 -0
- package/dist/bin/core/types.js +1 -0
- package/dist/bin/erosolar-optimized.d.ts +12 -0
- package/dist/bin/erosolar-optimized.d.ts.map +1 -0
- package/dist/bin/erosolar-optimized.js +239 -0
- package/dist/bin/erosolar-optimized.js.map +1 -0
- package/dist/bin/erosolar.js +14 -0
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/bin/headless/headlessApp.js +172 -0
- package/dist/bin/mcp/config.js +202 -0
- package/dist/bin/mcp/stdioClient.js +172 -0
- package/dist/bin/mcp/toolBridge.js +104 -0
- package/dist/bin/mcp/types.js +1 -0
- package/dist/bin/plugins/index.js +113 -0
- package/dist/bin/plugins/providers/anthropic/index.js +25 -0
- package/dist/bin/plugins/providers/deepseek/index.js +24 -0
- package/dist/bin/plugins/providers/google/index.js +26 -0
- package/dist/bin/plugins/providers/index.js +19 -0
- package/dist/bin/plugins/providers/ollama/index.js +59 -0
- package/dist/bin/plugins/providers/openai/index.js +26 -0
- package/dist/bin/plugins/providers/xai/index.js +24 -0
- package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +8 -0
- package/dist/bin/plugins/tools/bash/localBashPlugin.js +13 -0
- package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +13 -0
- package/dist/bin/plugins/tools/cloud/cloudPlugin.js +13 -0
- package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +13 -0
- package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +13 -0
- package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +11 -0
- package/dist/bin/plugins/tools/development/devPlugin.js +13 -0
- package/dist/bin/plugins/tools/edit/editPlugin.js +14 -0
- package/dist/bin/plugins/tools/email/emailPlugin.js +11 -0
- package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +8 -0
- package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +13 -0
- package/dist/bin/plugins/tools/glob/globPlugin.js +14 -0
- package/dist/bin/plugins/tools/index.js +2 -0
- package/dist/bin/plugins/tools/interaction/interactionPlugin.js +11 -0
- package/dist/bin/plugins/tools/learn/learnPlugin.js +13 -0
- package/dist/bin/plugins/tools/mcp/mcpPlugin.js +8 -0
- package/dist/bin/plugins/tools/nodeDefaults.js +56 -0
- package/dist/bin/plugins/tools/notebook/notebookPlugin.js +14 -0
- package/dist/bin/plugins/tools/planning/planningPlugin.js +14 -0
- package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +11 -0
- package/dist/bin/plugins/tools/registry.js +57 -0
- package/dist/bin/plugins/tools/search/localSearchPlugin.js +13 -0
- package/dist/bin/plugins/tools/skills/skillPlugin.js +8 -0
- package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +11 -0
- package/dist/bin/plugins/tools/testing/testingPlugin.js +11 -0
- package/dist/bin/plugins/tools/web/webPlugin.js +11 -0
- package/dist/bin/providers/anthropicProvider.js +329 -0
- package/dist/bin/providers/googleProvider.js +203 -0
- package/dist/bin/providers/openaiChatCompletionsProvider.js +208 -0
- package/dist/bin/providers/openaiResponsesProvider.js +249 -0
- package/dist/bin/providers/providerFactory.js +24 -0
- package/dist/bin/runtime/agentController.js +321 -0
- package/dist/bin/runtime/agentHost.js +153 -0
- package/dist/bin/runtime/agentSession.js +195 -0
- package/dist/bin/runtime/node.js +10 -0
- package/dist/bin/runtime/universal.js +28 -0
- package/dist/bin/shell/bracketedPasteManager.js +350 -0
- package/dist/bin/shell/fileChangeTracker.js +65 -0
- package/dist/bin/shell/interactiveShell.js +2908 -0
- package/dist/bin/shell/liveStatus.js +78 -0
- package/dist/bin/shell/shellApp.js +290 -0
- package/dist/bin/shell/systemPrompt.js +60 -0
- package/dist/bin/shell/updateManager.js +108 -0
- package/dist/bin/skills/skillRepository.js +236 -0
- package/dist/bin/skills/types.js +1 -0
- package/dist/bin/subagents/taskRunner.js +269 -0
- package/dist/bin/tools/backgroundBashTools.js +211 -0
- package/dist/bin/tools/bashTools.js +159 -0
- package/dist/bin/tools/cloudTools.js +864 -0
- package/dist/bin/tools/codeAnalysisTools.js +641 -0
- package/dist/bin/tools/codeQualityTools.js +294 -0
- package/dist/bin/tools/dependencyTools.js +282 -0
- package/dist/bin/tools/devTools.js +238 -0
- package/dist/bin/tools/diffUtils.js +137 -0
- package/dist/bin/tools/editTools.js +134 -0
- package/dist/bin/tools/emailTools.js +448 -0
- package/dist/bin/tools/fileTools.js +282 -0
- package/dist/bin/tools/globTools.js +173 -0
- package/dist/bin/tools/grepTools.js +332 -0
- package/dist/bin/tools/interactionTools.js +170 -0
- package/dist/bin/tools/learnTools.js +1818 -0
- package/dist/bin/tools/notebookEditTools.js +196 -0
- package/dist/bin/tools/planningTools.js +46 -0
- package/dist/bin/tools/refactoringTools.js +293 -0
- package/dist/bin/tools/repoChecksTools.js +160 -0
- package/dist/bin/tools/searchTools.js +206 -0
- package/dist/bin/tools/skillTools.js +177 -0
- package/dist/bin/tools/taskManagementTools.js +156 -0
- package/dist/bin/tools/testingTools.js +232 -0
- package/dist/bin/tools/webTools.js +480 -0
- package/dist/bin/ui/ShellUIAdapter.js +459 -0
- package/dist/bin/ui/UnifiedUIController.js +183 -0
- package/dist/bin/ui/animation/AnimationScheduler.js +430 -0
- package/dist/bin/ui/codeHighlighter.js +854 -0
- package/dist/bin/ui/designSystem.js +121 -0
- package/dist/bin/ui/display.js +1222 -0
- package/dist/bin/ui/interrupts/InterruptManager.js +437 -0
- package/dist/bin/ui/layout.js +139 -0
- package/dist/bin/ui/orchestration/StatusOrchestrator.js +403 -0
- package/dist/bin/ui/outputMode.js +38 -0
- package/dist/bin/ui/persistentPrompt.js +183 -0
- package/dist/bin/ui/richText.js +338 -0
- package/dist/bin/ui/shortcutsHelp.js +87 -0
- package/dist/bin/ui/telemetry/UITelemetry.js +443 -0
- package/dist/bin/ui/textHighlighter.js +210 -0
- package/dist/bin/ui/theme.js +116 -0
- package/dist/bin/ui/toolDisplay.js +423 -0
- package/dist/bin/ui/toolDisplayAdapter.js +357 -0
- package/dist/bin/workspace.js +106 -0
- package/dist/bin/workspace.validator.js +213 -0
- package/dist/capabilities/cloudCapability.d.ts +13 -0
- package/dist/capabilities/cloudCapability.d.ts.map +1 -0
- package/dist/capabilities/cloudCapability.js +38 -0
- package/dist/capabilities/cloudCapability.js.map +1 -0
- package/dist/capabilities/index.d.ts +1 -0
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +1 -0
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/offensiveSecurityCapability.d.ts +26 -0
- package/dist/capabilities/offensiveSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/offensiveSecurityCapability.js +58 -0
- package/dist/capabilities/offensiveSecurityCapability.js.map +1 -0
- package/dist/capabilities/realSecurityCapability.d.ts +26 -0
- package/dist/capabilities/realSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/realSecurityCapability.js +53 -0
- package/dist/capabilities/realSecurityCapability.js.map +1 -0
- package/dist/capabilities/securityCapability.d.ts +32 -0
- package/dist/capabilities/securityCapability.d.ts.map +1 -0
- package/dist/capabilities/securityCapability.js +57 -0
- package/dist/capabilities/securityCapability.js.map +1 -0
- package/dist/capabilities/ultimateSecurityCapability.d.ts +42 -0
- package/dist/capabilities/ultimateSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/ultimateSecurityCapability.js +96 -0
- package/dist/capabilities/ultimateSecurityCapability.js.map +1 -0
- package/dist/core/LazyLoader.d.ts +129 -0
- package/dist/core/LazyLoader.d.ts.map +1 -0
- package/dist/core/LazyLoader.js +240 -0
- package/dist/core/LazyLoader.js.map +1 -0
- package/dist/core/intelligenceTools.d.ts +19 -0
- package/dist/core/intelligenceTools.d.ts.map +1 -0
- package/dist/core/intelligenceTools.js +453 -0
- package/dist/core/intelligenceTools.js.map +1 -0
- package/dist/core/operationalTools.d.ts +19 -0
- package/dist/core/operationalTools.d.ts.map +1 -0
- package/dist/core/operationalTools.js +467 -0
- package/dist/core/operationalTools.js.map +1 -0
- package/dist/offensive/core/offensive-engine.d.ts +171 -0
- package/dist/offensive/core/offensive-engine.d.ts.map +1 -0
- package/dist/offensive/core/offensive-engine.js +345 -0
- package/dist/offensive/core/offensive-engine.js.map +1 -0
- package/dist/offensive/core/offensive-integration.d.ts +129 -0
- package/dist/offensive/core/offensive-integration.d.ts.map +1 -0
- package/dist/offensive/core/offensive-integration.js +364 -0
- package/dist/offensive/core/offensive-integration.js.map +1 -0
- package/dist/offensive/core/offensive-tools.d.ts +55 -0
- package/dist/offensive/core/offensive-tools.d.ts.map +1 -0
- package/dist/offensive/core/offensive-tools.js +438 -0
- package/dist/offensive/core/offensive-tools.js.map +1 -0
- package/dist/offensive/offensive-cli.d.ts +48 -0
- package/dist/offensive/offensive-cli.d.ts.map +1 -0
- package/dist/offensive/offensive-cli.js +233 -0
- package/dist/offensive/offensive-cli.js.map +1 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/tools/cloud/cloudPlugin.d.ts +3 -0
- package/dist/plugins/tools/cloud/cloudPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/cloud/cloudPlugin.js +14 -0
- package/dist/plugins/tools/cloud/cloudPlugin.js.map +1 -0
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +2 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/security/advanced-persistence-research.d.ts +92 -0
- package/dist/security/advanced-persistence-research.d.ts.map +1 -0
- package/dist/security/advanced-persistence-research.js +195 -0
- package/dist/security/advanced-persistence-research.js.map +1 -0
- package/dist/security/apt-simulation-cli.d.ts +57 -0
- package/dist/security/apt-simulation-cli.d.ts.map +1 -0
- package/dist/security/apt-simulation-cli.js +278 -0
- package/dist/security/apt-simulation-cli.js.map +1 -0
- package/dist/security/apt-simulation-engine-complete.d.ts +97 -0
- package/dist/security/apt-simulation-engine-complete.d.ts.map +1 -0
- package/dist/security/apt-simulation-engine-complete.js +441 -0
- package/dist/security/apt-simulation-engine-complete.js.map +1 -0
- package/dist/security/apt-simulation-engine.d.ts +97 -0
- package/dist/security/apt-simulation-engine.d.ts.map +1 -0
- package/dist/security/apt-simulation-engine.js +441 -0
- package/dist/security/apt-simulation-engine.js.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
- package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
- package/dist/security/authorization/securityAuthorization.d.ts +88 -0
- package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
- package/dist/security/authorization/securityAuthorization.js +172 -0
- package/dist/security/authorization/securityAuthorization.js.map +1 -0
- package/dist/security/authorization.d.ts +45 -0
- package/dist/security/authorization.d.ts.map +1 -0
- package/dist/security/authorization.js +128 -0
- package/dist/security/authorization.js.map +1 -0
- package/dist/security/comprehensive-security-research.d.ts +84 -0
- package/dist/security/comprehensive-security-research.d.ts.map +1 -0
- package/dist/security/comprehensive-security-research.js +211 -0
- package/dist/security/comprehensive-security-research.js.map +1 -0
- package/dist/security/offensive/exploitationEngine.d.ts +54 -0
- package/dist/security/offensive/exploitationEngine.d.ts.map +1 -0
- package/dist/security/offensive/exploitationEngine.js +263 -0
- package/dist/security/offensive/exploitationEngine.js.map +1 -0
- package/dist/security/persistence-analyzer.d.ts +56 -0
- package/dist/security/persistence-analyzer.d.ts.map +1 -0
- package/dist/security/persistence-analyzer.js +187 -0
- package/dist/security/persistence-analyzer.js.map +1 -0
- package/dist/security/persistence-cli.d.ts +36 -0
- package/dist/security/persistence-cli.d.ts.map +1 -0
- package/dist/security/persistence-cli.js +160 -0
- package/dist/security/persistence-cli.js.map +1 -0
- package/dist/security/persistence-research.d.ts +100 -0
- package/dist/security/persistence-research.d.ts.map +1 -0
- package/dist/security/persistence-research.js +372 -0
- package/dist/security/persistence-research.js.map +1 -0
- package/dist/security/real/networkExploitation.d.ts +92 -0
- package/dist/security/real/networkExploitation.d.ts.map +1 -0
- package/dist/security/real/networkExploitation.js +316 -0
- package/dist/security/real/networkExploitation.js.map +1 -0
- package/dist/security/real/persistenceImplementation.d.ts +62 -0
- package/dist/security/real/persistenceImplementation.d.ts.map +1 -0
- package/dist/security/real/persistenceImplementation.js +323 -0
- package/dist/security/real/persistenceImplementation.js.map +1 -0
- package/dist/security/real/vulnerabilityScanner.d.ts +73 -0
- package/dist/security/real/vulnerabilityScanner.d.ts.map +1 -0
- package/dist/security/real/vulnerabilityScanner.js +341 -0
- package/dist/security/real/vulnerabilityScanner.js.map +1 -0
- package/dist/security/research/persistenceResearch.d.ts +97 -0
- package/dist/security/research/persistenceResearch.d.ts.map +1 -0
- package/dist/security/research/persistenceResearch.js +282 -0
- package/dist/security/research/persistenceResearch.js.map +1 -0
- package/dist/security/security-testing-framework.d.ts +120 -0
- package/dist/security/security-testing-framework.d.ts.map +1 -0
- package/dist/security/security-testing-framework.js +372 -0
- package/dist/security/security-testing-framework.js.map +1 -0
- package/dist/security/simulation/attackSimulation.d.ts +93 -0
- package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
- package/dist/security/simulation/attackSimulation.js +341 -0
- package/dist/security/simulation/attackSimulation.js.map +1 -0
- package/dist/shell/bracketedPasteManager.d.ts +76 -0
- package/dist/shell/bracketedPasteManager.d.ts.map +1 -1
- package/dist/shell/bracketedPasteManager.js +267 -9
- package/dist/shell/bracketedPasteManager.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +34 -1
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +304 -24
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/taskCompletionDetector.d.ts +101 -0
- package/dist/shell/taskCompletionDetector.d.ts.map +1 -0
- package/dist/shell/taskCompletionDetector.js +343 -0
- package/dist/shell/taskCompletionDetector.js.map +1 -0
- package/dist/tools/cloudTools.d.ts +57 -0
- package/dist/tools/cloudTools.d.ts.map +1 -0
- package/dist/tools/cloudTools.js +865 -0
- package/dist/tools/cloudTools.js.map +1 -0
- package/dist/tools/enhancedSecurityTools.d.ts +19 -0
- package/dist/tools/enhancedSecurityTools.d.ts.map +1 -0
- package/dist/tools/enhancedSecurityTools.js +215 -0
- package/dist/tools/enhancedSecurityTools.js.map +1 -0
- package/dist/tools/offensiveSecurityTools.d.ts +16 -0
- package/dist/tools/offensiveSecurityTools.d.ts.map +1 -0
- package/dist/tools/offensiveSecurityTools.js +285 -0
- package/dist/tools/offensiveSecurityTools.js.map +1 -0
- package/dist/tools/realSecurityTools.d.ts +18 -0
- package/dist/tools/realSecurityTools.d.ts.map +1 -0
- package/dist/tools/realSecurityTools.js +468 -0
- package/dist/tools/realSecurityTools.js.map +1 -0
- package/dist/tools/securityTools.d.ts +20 -0
- package/dist/tools/securityTools.d.ts.map +1 -0
- package/dist/tools/securityTools.js +449 -0
- package/dist/tools/securityTools.js.map +1 -0
- package/package.json +27 -12
- package/scripts/deploy-security-capabilities.js +178 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
export class OpenAIChatCompletionsProvider {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
const clientConfig = {
|
|
5
|
+
apiKey: options.apiKey,
|
|
6
|
+
};
|
|
7
|
+
if (options.baseURL) {
|
|
8
|
+
clientConfig.baseURL = options.baseURL;
|
|
9
|
+
}
|
|
10
|
+
this.client = new OpenAI(clientConfig);
|
|
11
|
+
this.id = options.providerId ?? 'openai';
|
|
12
|
+
this.model = options.model;
|
|
13
|
+
}
|
|
14
|
+
async generate(messages, tools) {
|
|
15
|
+
const request = {
|
|
16
|
+
model: this.model,
|
|
17
|
+
messages: mapMessages(messages),
|
|
18
|
+
tools: tools.length ? tools.map(mapTool) : undefined,
|
|
19
|
+
stream: false,
|
|
20
|
+
};
|
|
21
|
+
const completion = await this.client.chat.completions.create(request);
|
|
22
|
+
assertHasChoices(completion);
|
|
23
|
+
const choice = completion.choices[0];
|
|
24
|
+
const usage = mapUsage(completion.usage);
|
|
25
|
+
if (!choice) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'message',
|
|
28
|
+
content: '',
|
|
29
|
+
usage,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const toolCalls = (choice.message.tool_calls ?? []).map(mapToolCall);
|
|
33
|
+
const content = extractMessageContent(choice);
|
|
34
|
+
if (toolCalls.length > 0) {
|
|
35
|
+
return {
|
|
36
|
+
type: 'tool_calls',
|
|
37
|
+
toolCalls,
|
|
38
|
+
content,
|
|
39
|
+
usage,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
type: 'message',
|
|
44
|
+
content,
|
|
45
|
+
usage,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function mapMessages(messages) {
|
|
50
|
+
const params = [];
|
|
51
|
+
for (const message of messages) {
|
|
52
|
+
switch (message.role) {
|
|
53
|
+
case 'system':
|
|
54
|
+
case 'user': {
|
|
55
|
+
params.push({
|
|
56
|
+
role: message.role,
|
|
57
|
+
content: message.content,
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'assistant': {
|
|
62
|
+
params.push({
|
|
63
|
+
role: 'assistant',
|
|
64
|
+
content: message.content,
|
|
65
|
+
tool_calls: message.toolCalls?.map((call, index) => ({
|
|
66
|
+
id: call.id || `call_${index}`,
|
|
67
|
+
type: 'function',
|
|
68
|
+
function: {
|
|
69
|
+
name: call.name,
|
|
70
|
+
arguments: JSON.stringify(call.arguments ?? {}),
|
|
71
|
+
},
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case 'tool': {
|
|
77
|
+
params.push({
|
|
78
|
+
role: 'tool',
|
|
79
|
+
content: message.content,
|
|
80
|
+
tool_call_id: message.toolCallId,
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
function mapTool(definition) {
|
|
91
|
+
const parameters = definition.parameters ??
|
|
92
|
+
{
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {},
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
type: 'function',
|
|
98
|
+
function: {
|
|
99
|
+
name: definition.name,
|
|
100
|
+
description: definition.description,
|
|
101
|
+
parameters,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function extractMessageContent(choice) {
|
|
106
|
+
const message = choice.message;
|
|
107
|
+
const content = message?.content;
|
|
108
|
+
if (typeof content === 'string' && content.trim()) {
|
|
109
|
+
return content.trim();
|
|
110
|
+
}
|
|
111
|
+
const refusal = message?.refusal;
|
|
112
|
+
if (typeof refusal === 'string' && refusal.trim()) {
|
|
113
|
+
return refusal.trim();
|
|
114
|
+
}
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
function mapToolCall(call) {
|
|
118
|
+
let parsed = {};
|
|
119
|
+
const rawArgs = call.function.arguments ?? '{}';
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(rawArgs);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
// Try to recover malformed JSON (common with some models)
|
|
125
|
+
const recovered = tryRecoverMalformedJson(rawArgs);
|
|
126
|
+
if (recovered) {
|
|
127
|
+
parsed = recovered;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Log warning for debugging but continue with empty args
|
|
131
|
+
console.warn(`[tool-call] Failed to parse arguments for ${call.function.name}: ${rawArgs.slice(0, 100)}...`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
id: call.id ?? call.function.name,
|
|
136
|
+
name: call.function.name,
|
|
137
|
+
arguments: parsed,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Try to recover malformed JSON from tool call arguments.
|
|
142
|
+
* Some models return truncated or malformed JSON that can be fixed.
|
|
143
|
+
*/
|
|
144
|
+
function tryRecoverMalformedJson(raw) {
|
|
145
|
+
if (!raw || !raw.trim()) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const attempts = [
|
|
149
|
+
// Try adding missing closing braces/quotes
|
|
150
|
+
raw + '"}',
|
|
151
|
+
raw + '}',
|
|
152
|
+
raw + '"' + '}',
|
|
153
|
+
raw + '"}}',
|
|
154
|
+
raw + '}}',
|
|
155
|
+
];
|
|
156
|
+
for (const attempt of attempts) {
|
|
157
|
+
try {
|
|
158
|
+
const parsed = JSON.parse(attempt);
|
|
159
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
160
|
+
return parsed;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Continue to next attempt
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Try regex extraction as last resort
|
|
168
|
+
try {
|
|
169
|
+
const pairs = raw.matchAll(/"([^"]+)":\s*(?:"([^"]*)"?|(\d+(?:\.\d+)?)|(\btrue\b|\bfalse\b|\bnull\b))/g);
|
|
170
|
+
const result = {};
|
|
171
|
+
for (const match of pairs) {
|
|
172
|
+
const [, key, strVal, numVal, boolVal] = match;
|
|
173
|
+
if (key) {
|
|
174
|
+
if (strVal !== undefined) {
|
|
175
|
+
result[key] = strVal;
|
|
176
|
+
}
|
|
177
|
+
else if (numVal) {
|
|
178
|
+
result[key] = numVal.includes('.') ? parseFloat(numVal) : parseInt(numVal, 10);
|
|
179
|
+
}
|
|
180
|
+
else if (boolVal) {
|
|
181
|
+
result[key] = boolVal === 'true' ? true : boolVal === 'false' ? false : null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (Object.keys(result).length > 0) {
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// Regex extraction failed
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
function mapUsage(usage) {
|
|
195
|
+
if (!usage) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
inputTokens: usage.prompt_tokens,
|
|
200
|
+
outputTokens: usage.completion_tokens,
|
|
201
|
+
totalTokens: usage.total_tokens,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function assertHasChoices(result) {
|
|
205
|
+
if (!('choices' in result)) {
|
|
206
|
+
throw new Error('Streaming responses are not supported in this runtime.');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
export class OpenAIResponsesProvider {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
const clientConfig = {
|
|
5
|
+
apiKey: options.apiKey,
|
|
6
|
+
};
|
|
7
|
+
if (options.baseURL) {
|
|
8
|
+
clientConfig.baseURL = options.baseURL;
|
|
9
|
+
}
|
|
10
|
+
this.client = new OpenAI(clientConfig);
|
|
11
|
+
this.id = options.providerId ?? 'openai';
|
|
12
|
+
this.model = options.model;
|
|
13
|
+
this.reasoningEffort = options.reasoningEffort;
|
|
14
|
+
this.textVerbosity = options.textVerbosity;
|
|
15
|
+
}
|
|
16
|
+
async generate(messages, tools) {
|
|
17
|
+
const request = {
|
|
18
|
+
model: this.model,
|
|
19
|
+
input: mapMessages(messages),
|
|
20
|
+
tools: tools.length ? tools.map(mapTool) : undefined,
|
|
21
|
+
stream: false,
|
|
22
|
+
};
|
|
23
|
+
if (this.reasoningEffort) {
|
|
24
|
+
request.reasoning = { effort: this.reasoningEffort };
|
|
25
|
+
}
|
|
26
|
+
if (this.textVerbosity) {
|
|
27
|
+
request.text = { verbosity: this.textVerbosity };
|
|
28
|
+
}
|
|
29
|
+
const response = await this.client.responses.create(request);
|
|
30
|
+
assertHasOutput(response);
|
|
31
|
+
const toolCalls = response.output.filter(isFunctionCall).map(mapToolCall);
|
|
32
|
+
const usage = mapUsage(response.usage);
|
|
33
|
+
if (toolCalls.length > 0) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'tool_calls',
|
|
36
|
+
toolCalls,
|
|
37
|
+
content: extractTextContent(response),
|
|
38
|
+
usage,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
type: 'message',
|
|
43
|
+
content: extractTextContent(response),
|
|
44
|
+
usage,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async *generateStream(messages, tools) {
|
|
48
|
+
const request = {
|
|
49
|
+
model: this.model,
|
|
50
|
+
input: mapMessages(messages),
|
|
51
|
+
tools: tools.length ? tools.map(mapTool) : undefined,
|
|
52
|
+
stream: true,
|
|
53
|
+
};
|
|
54
|
+
if (this.reasoningEffort) {
|
|
55
|
+
request.reasoning = { effort: this.reasoningEffort };
|
|
56
|
+
}
|
|
57
|
+
if (this.textVerbosity) {
|
|
58
|
+
request.text = { verbosity: this.textVerbosity };
|
|
59
|
+
}
|
|
60
|
+
const stream = await this.client.responses.create(request);
|
|
61
|
+
// Track tool calls being built
|
|
62
|
+
const pendingToolCalls = new Map();
|
|
63
|
+
for await (const event of stream) {
|
|
64
|
+
switch (event.type) {
|
|
65
|
+
case 'response.output_text.delta':
|
|
66
|
+
if (event.delta) {
|
|
67
|
+
yield { type: 'content', content: event.delta };
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case 'response.function_call_arguments.delta':
|
|
71
|
+
if (event.call_id) {
|
|
72
|
+
const existing = pendingToolCalls.get(event.call_id);
|
|
73
|
+
if (existing) {
|
|
74
|
+
existing.arguments += event.delta ?? '';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
pendingToolCalls.set(event.call_id, {
|
|
78
|
+
name: event.name ?? '',
|
|
79
|
+
arguments: event.delta ?? '',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case 'response.function_call_arguments.done':
|
|
85
|
+
if (event.call_id) {
|
|
86
|
+
const pending = pendingToolCalls.get(event.call_id);
|
|
87
|
+
if (pending) {
|
|
88
|
+
let parsed = {};
|
|
89
|
+
try {
|
|
90
|
+
parsed = JSON.parse(pending.arguments || '{}');
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
parsed = {};
|
|
94
|
+
}
|
|
95
|
+
yield {
|
|
96
|
+
type: 'tool_call',
|
|
97
|
+
toolCall: {
|
|
98
|
+
id: event.call_id,
|
|
99
|
+
name: event.name ?? pending.name,
|
|
100
|
+
arguments: parsed,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
pendingToolCalls.delete(event.call_id);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
case 'response.done':
|
|
108
|
+
if (event.response?.usage) {
|
|
109
|
+
const usage = mapUsage(event.response.usage);
|
|
110
|
+
if (usage) {
|
|
111
|
+
yield { type: 'usage', usage };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
yield { type: 'done' };
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function mapMessages(messages) {
|
|
121
|
+
const input = [];
|
|
122
|
+
for (const message of messages) {
|
|
123
|
+
switch (message.role) {
|
|
124
|
+
case 'system':
|
|
125
|
+
case 'user':
|
|
126
|
+
case 'assistant': {
|
|
127
|
+
input.push({
|
|
128
|
+
role: message.role,
|
|
129
|
+
content: message.content,
|
|
130
|
+
type: 'message',
|
|
131
|
+
});
|
|
132
|
+
if (message.role === 'assistant') {
|
|
133
|
+
for (const call of message.toolCalls ?? []) {
|
|
134
|
+
input.push({
|
|
135
|
+
type: 'function_call',
|
|
136
|
+
call_id: call.id,
|
|
137
|
+
name: call.name,
|
|
138
|
+
arguments: JSON.stringify(call.arguments ?? {}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'tool': {
|
|
145
|
+
input.push({
|
|
146
|
+
type: 'function_call_output',
|
|
147
|
+
call_id: message.toolCallId,
|
|
148
|
+
output: message.content,
|
|
149
|
+
});
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return input;
|
|
157
|
+
}
|
|
158
|
+
function mapTool(definition) {
|
|
159
|
+
return {
|
|
160
|
+
type: 'function',
|
|
161
|
+
name: definition.name,
|
|
162
|
+
description: definition.description,
|
|
163
|
+
parameters: (definition.parameters ?? {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {},
|
|
166
|
+
}),
|
|
167
|
+
strict: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function extractTextContent(response) {
|
|
171
|
+
const primary = collectOutputText(response.output);
|
|
172
|
+
if (primary) {
|
|
173
|
+
return primary;
|
|
174
|
+
}
|
|
175
|
+
const aggregated = typeof response.output_text === 'string' ? response.output_text.trim() : '';
|
|
176
|
+
if (aggregated) {
|
|
177
|
+
return aggregated;
|
|
178
|
+
}
|
|
179
|
+
const refusal = collectRefusalText(response.output);
|
|
180
|
+
if (refusal) {
|
|
181
|
+
return refusal;
|
|
182
|
+
}
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
function collectOutputText(output) {
|
|
186
|
+
const chunks = [];
|
|
187
|
+
for (const item of output) {
|
|
188
|
+
if (!isOutputMessage(item)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
for (const block of item.content) {
|
|
192
|
+
if (block.type === 'output_text') {
|
|
193
|
+
chunks.push(block.text);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return chunks.join('\n').trim();
|
|
198
|
+
}
|
|
199
|
+
function collectRefusalText(output) {
|
|
200
|
+
for (const item of output) {
|
|
201
|
+
if (!isOutputMessage(item)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
for (const block of item.content) {
|
|
205
|
+
if (isRefusal(block) && block.refusal?.trim()) {
|
|
206
|
+
return block.refusal.trim();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return '';
|
|
211
|
+
}
|
|
212
|
+
function mapToolCall(call) {
|
|
213
|
+
let parsed = {};
|
|
214
|
+
try {
|
|
215
|
+
parsed = JSON.parse(call.arguments ?? '{}');
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
parsed = {};
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
id: call.call_id ?? call.id ?? '',
|
|
222
|
+
name: call.name,
|
|
223
|
+
arguments: parsed,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function mapUsage(usage) {
|
|
227
|
+
if (!usage) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
inputTokens: usage.input_tokens,
|
|
232
|
+
outputTokens: usage.output_tokens,
|
|
233
|
+
totalTokens: usage.total_tokens,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function isFunctionCall(item) {
|
|
237
|
+
return item.type === 'function_call';
|
|
238
|
+
}
|
|
239
|
+
function isOutputMessage(item) {
|
|
240
|
+
return item.type === 'message';
|
|
241
|
+
}
|
|
242
|
+
function isRefusal(block) {
|
|
243
|
+
return block.type === 'refusal';
|
|
244
|
+
}
|
|
245
|
+
function assertHasOutput(response) {
|
|
246
|
+
if (!('output' in response)) {
|
|
247
|
+
throw new Error('Streaming responses are not supported in this runtime.');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const registry = new Map();
|
|
2
|
+
export function registerProvider(id, factory, options = {}) {
|
|
3
|
+
if (!id?.trim()) {
|
|
4
|
+
throw new Error('Provider id cannot be blank.');
|
|
5
|
+
}
|
|
6
|
+
if (registry.has(id) && !options.override) {
|
|
7
|
+
throw new Error(`Provider "${id}" is already registered.`);
|
|
8
|
+
}
|
|
9
|
+
registry.set(id, factory);
|
|
10
|
+
}
|
|
11
|
+
export function createProvider(config) {
|
|
12
|
+
const factory = registry.get(config.provider);
|
|
13
|
+
if (!factory) {
|
|
14
|
+
const known = Array.from(registry.keys()).sort().join(', ');
|
|
15
|
+
throw new Error(`Provider "${config.provider}" is not registered. Registered providers: ${known || 'none'}.`);
|
|
16
|
+
}
|
|
17
|
+
return factory(config);
|
|
18
|
+
}
|
|
19
|
+
export function listRegisteredProviders() {
|
|
20
|
+
return Array.from(registry.keys());
|
|
21
|
+
}
|
|
22
|
+
export function hasProvider(id) {
|
|
23
|
+
return registry.has(id);
|
|
24
|
+
}
|