codehere 0.4.0 → 0.5.0-alpha
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/LICENSE +1 -1
- package/README.md +113 -30
- package/dist/application/agents/execution-agent.js +2 -2
- package/dist/application/agents/execution-agent.js.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.d.ts +1 -0
- package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.js +10 -3
- package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
- package/dist/application/agents/planning-agent.d.ts.map +1 -1
- package/dist/application/agents/planning-agent.js +22 -10
- package/dist/application/agents/planning-agent.js.map +1 -1
- package/dist/application/agents/validation-agent.js +2 -2
- package/dist/application/agents/validation-agent.js.map +1 -1
- package/dist/application/reasoning/multi-model-planning-strategy.d.ts +21 -0
- package/dist/application/reasoning/multi-model-planning-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/multi-model-planning-strategy.js +158 -0
- package/dist/application/reasoning/multi-model-planning-strategy.js.map +1 -0
- package/dist/application/reasoning/reasoning-config.d.ts +15 -0
- package/dist/application/reasoning/reasoning-config.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-config.js +50 -0
- package/dist/application/reasoning/reasoning-config.js.map +1 -0
- package/dist/application/reasoning/reasoning-orchestrator.d.ts +18 -0
- package/dist/application/reasoning/reasoning-orchestrator.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-orchestrator.js +170 -0
- package/dist/application/reasoning/reasoning-orchestrator.js.map +1 -0
- package/dist/application/reasoning/reasoning-strategy.interface.d.ts +24 -0
- package/dist/application/reasoning/reasoning-strategy.interface.d.ts.map +1 -0
- package/dist/application/reasoning/reasoning-strategy.interface.js +6 -0
- package/dist/application/reasoning/reasoning-strategy.interface.js.map +1 -0
- package/dist/application/reasoning/role-provider-resolver.d.ts +36 -0
- package/dist/application/reasoning/role-provider-resolver.d.ts.map +1 -0
- package/dist/application/reasoning/role-provider-resolver.js +74 -0
- package/dist/application/reasoning/role-provider-resolver.js.map +1 -0
- package/dist/application/reasoning/simple-planning-strategy.d.ts +22 -0
- package/dist/application/reasoning/simple-planning-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/simple-planning-strategy.js +217 -0
- package/dist/application/reasoning/simple-planning-strategy.js.map +1 -0
- package/dist/application/reasoning/types.d.ts +65 -0
- package/dist/application/reasoning/types.d.ts.map +1 -0
- package/dist/application/reasoning/types.js +6 -0
- package/dist/application/reasoning/types.js.map +1 -0
- package/dist/application/reasoning/validator-strategy.d.ts +56 -0
- package/dist/application/reasoning/validator-strategy.d.ts.map +1 -0
- package/dist/application/reasoning/validator-strategy.js +103 -0
- package/dist/application/reasoning/validator-strategy.js.map +1 -0
- package/dist/application/services/dependency-container.d.ts +30 -6
- package/dist/application/services/dependency-container.d.ts.map +1 -1
- package/dist/application/services/dependency-container.js +96 -44
- package/dist/application/services/dependency-container.js.map +1 -1
- package/dist/application/services/intelligent-router.d.ts +6 -0
- package/dist/application/services/intelligent-router.d.ts.map +1 -1
- package/dist/application/services/intelligent-router.js +98 -9
- package/dist/application/services/intelligent-router.js.map +1 -1
- package/dist/application/use-cases/ask-question-use-case.d.ts +1 -0
- package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -1
- package/dist/application/use-cases/ask-question-use-case.js +4 -3
- package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
- package/dist/application/use-cases/planning-use-case.d.ts +14 -1
- package/dist/application/use-cases/planning-use-case.d.ts.map +1 -1
- package/dist/application/use-cases/planning-use-case.js +109 -2
- package/dist/application/use-cases/planning-use-case.js.map +1 -1
- package/dist/domain/entities/memory.d.ts.map +1 -1
- package/dist/domain/entities/task.d.ts +1 -1
- package/dist/domain/entities/task.d.ts.map +1 -1
- package/dist/domain/entities/task.js +2 -2
- package/dist/domain/entities/task.js.map +1 -1
- package/dist/domain/errors/embeddings-not-found-error.d.ts +9 -0
- package/dist/domain/errors/embeddings-not-found-error.d.ts.map +1 -0
- package/dist/domain/errors/embeddings-not-found-error.js +13 -0
- package/dist/domain/errors/embeddings-not-found-error.js.map +1 -0
- package/dist/domain/interfaces/embedding-repository.interface.d.ts +5 -0
- package/dist/domain/interfaces/embedding-repository.interface.d.ts.map +1 -1
- package/dist/domain/services/environment-mode-manager.d.ts +4 -10
- package/dist/domain/services/environment-mode-manager.d.ts.map +1 -1
- package/dist/domain/services/environment-mode-manager.js +7 -22
- package/dist/domain/services/environment-mode-manager.js.map +1 -1
- package/dist/domain/services/query-intent-classifier.d.ts.map +1 -1
- package/dist/domain/services/query-intent-classifier.js +20 -1
- package/dist/domain/services/query-intent-classifier.js.map +1 -1
- package/dist/domain/services/risk-tier-detector.d.ts +8 -9
- package/dist/domain/services/risk-tier-detector.d.ts.map +1 -1
- package/dist/domain/services/risk-tier-detector.js +53 -40
- package/dist/domain/services/risk-tier-detector.js.map +1 -1
- package/dist/embed.d.ts.map +1 -1
- package/dist/embed.js +18 -8
- package/dist/embed.js.map +1 -1
- package/dist/index.js +405 -52
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/ai/cohere-ai-service.js +4 -4
- package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
- package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -1
- package/dist/infrastructure/ai/provider-ai-service.js +7 -7
- package/dist/infrastructure/ai/provider-ai-service.js.map +1 -1
- package/dist/infrastructure/cache/query-result-cache.d.ts +14 -55
- package/dist/infrastructure/cache/query-result-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/query-result-cache.js +40 -112
- package/dist/infrastructure/cache/query-result-cache.js.map +1 -1
- package/dist/infrastructure/cache/response-cache.d.ts +10 -78
- package/dist/infrastructure/cache/response-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/response-cache.js +22 -198
- package/dist/infrastructure/cache/response-cache.js.map +1 -1
- package/dist/infrastructure/cache/security-scan-cache.d.ts +8 -49
- package/dist/infrastructure/cache/security-scan-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/security-scan-cache.js +25 -102
- package/dist/infrastructure/cache/security-scan-cache.js.map +1 -1
- package/dist/infrastructure/completion/bash-completion.d.ts +2 -3
- package/dist/infrastructure/completion/bash-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/bash-completion.js +11 -87
- package/dist/infrastructure/completion/bash-completion.js.map +1 -1
- package/dist/infrastructure/completion/fish-completion.d.ts +2 -3
- package/dist/infrastructure/completion/fish-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/fish-completion.js +15 -58
- package/dist/infrastructure/completion/fish-completion.js.map +1 -1
- package/dist/infrastructure/completion/zsh-completion.d.ts +2 -3
- package/dist/infrastructure/completion/zsh-completion.d.ts.map +1 -1
- package/dist/infrastructure/completion/zsh-completion.js +18 -73
- package/dist/infrastructure/completion/zsh-completion.js.map +1 -1
- package/dist/infrastructure/config/config-manager.d.ts +10 -0
- package/dist/infrastructure/config/config-manager.d.ts.map +1 -1
- package/dist/infrastructure/config/config-manager.js +13 -2
- package/dist/infrastructure/config/config-manager.js.map +1 -1
- package/dist/infrastructure/context/conversation-context.d.ts +27 -31
- package/dist/infrastructure/context/conversation-context.d.ts.map +1 -1
- package/dist/infrastructure/context/conversation-context.js +95 -136
- package/dist/infrastructure/context/conversation-context.js.map +1 -1
- package/dist/infrastructure/context/session-manager.d.ts +27 -11
- package/dist/infrastructure/context/session-manager.d.ts.map +1 -1
- package/dist/infrastructure/context/session-manager.js +69 -73
- package/dist/infrastructure/context/session-manager.js.map +1 -1
- package/dist/infrastructure/protocols/a2a-metadata.js +1 -1
- package/dist/infrastructure/protocols/mcp-oauth.js +1 -1
- package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -1
- package/dist/infrastructure/providers/cohere-provider.js +102 -17
- package/dist/infrastructure/providers/cohere-provider.js.map +1 -1
- package/dist/infrastructure/providers/openrouter-provider.d.ts +42 -0
- package/dist/infrastructure/providers/openrouter-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/openrouter-provider.js +401 -0
- package/dist/infrastructure/providers/openrouter-provider.js.map +1 -0
- package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -1
- package/dist/infrastructure/providers/operation-provider-resolver.js +33 -7
- package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -1
- package/dist/infrastructure/security/input-validator.d.ts.map +1 -1
- package/dist/infrastructure/security/input-validator.js +19 -6
- package/dist/infrastructure/security/input-validator.js.map +1 -1
- package/dist/infrastructure/serialization/toon-serializer.d.ts +45 -0
- package/dist/infrastructure/serialization/toon-serializer.d.ts.map +1 -0
- package/dist/infrastructure/serialization/toon-serializer.js +119 -0
- package/dist/infrastructure/serialization/toon-serializer.js.map +1 -0
- package/dist/infrastructure/storage/embeddings-path.d.ts +18 -0
- package/dist/infrastructure/storage/embeddings-path.d.ts.map +1 -0
- package/dist/infrastructure/storage/embeddings-path.js +37 -0
- package/dist/infrastructure/storage/embeddings-path.js.map +1 -0
- package/dist/infrastructure/storage/plan-repository.d.ts +2 -0
- package/dist/infrastructure/storage/plan-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/plan-repository.js +36 -73
- package/dist/infrastructure/storage/plan-repository.js.map +1 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts +10 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +37 -3
- package/dist/infrastructure/storage/sqlite-embedding-repository.js.map +1 -1
- package/dist/infrastructure/storage/task-helpers.d.ts +12 -1
- package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -1
- package/dist/infrastructure/storage/task-helpers.js +48 -8
- package/dist/infrastructure/storage/task-helpers.js.map +1 -1
- package/dist/infrastructure/storage/task-repository.d.ts +2 -1
- package/dist/infrastructure/storage/task-repository.d.ts.map +1 -1
- package/dist/infrastructure/storage/task-repository.js +14 -3
- package/dist/infrastructure/storage/task-repository.js.map +1 -1
- package/dist/infrastructure/telemetry/telemetry-service.d.ts +74 -0
- package/dist/infrastructure/telemetry/telemetry-service.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/telemetry-service.js +167 -0
- package/dist/infrastructure/telemetry/telemetry-service.js.map +1 -0
- package/dist/infrastructure/ux/capability-boundaries.d.ts +9 -37
- package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -1
- package/dist/infrastructure/ux/capability-boundaries.js +23 -148
- package/dist/infrastructure/ux/capability-boundaries.js.map +1 -1
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts +12 -54
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -1
- package/dist/infrastructure/ux/comprehensive-formatter.js +87 -182
- package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -1
- package/dist/infrastructure/ux/contextual-feature-discovery.d.ts +5 -18
- package/dist/infrastructure/ux/contextual-feature-discovery.d.ts.map +1 -1
- package/dist/infrastructure/ux/contextual-feature-discovery.js +5 -139
- package/dist/infrastructure/ux/contextual-feature-discovery.js.map +1 -1
- package/dist/infrastructure/ux/feature-discovery.d.ts +3 -33
- package/dist/infrastructure/ux/feature-discovery.d.ts.map +1 -1
- package/dist/infrastructure/ux/feature-discovery.js +5 -181
- package/dist/infrastructure/ux/feature-discovery.js.map +1 -1
- package/dist/infrastructure/ux/feedback-prompt.d.ts +15 -31
- package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -1
- package/dist/infrastructure/ux/feedback-prompt.js +30 -166
- package/dist/infrastructure/ux/feedback-prompt.js.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.d.ts +4 -6
- package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.js +35 -50
- package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
- package/dist/infrastructure/ux/review-checkpoint.d.ts +3 -1
- package/dist/infrastructure/ux/review-checkpoint.d.ts.map +1 -1
- package/dist/infrastructure/ux/review-checkpoint.js +33 -80
- package/dist/infrastructure/ux/review-checkpoint.js.map +1 -1
- package/dist/infrastructure/ux/staged-feature-intro.d.ts +14 -39
- package/dist/infrastructure/ux/staged-feature-intro.d.ts.map +1 -1
- package/dist/infrastructure/ux/staged-feature-intro.js +12 -132
- package/dist/infrastructure/ux/staged-feature-intro.js.map +1 -1
- package/dist/infrastructure/ux/syntax-highlighter.d.ts +1 -2
- package/dist/infrastructure/ux/syntax-highlighter.d.ts.map +1 -1
- package/dist/infrastructure/ux/syntax-highlighter.js +67 -148
- package/dist/infrastructure/ux/syntax-highlighter.js.map +1 -1
- package/dist/infrastructure/validation/agent-feedback.d.ts +25 -89
- package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -1
- package/dist/infrastructure/validation/agent-feedback.js +32 -204
- package/dist/infrastructure/validation/agent-feedback.js.map +1 -1
- package/dist/infrastructure/validation/agent-validation-helper.d.ts +53 -53
- package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -1
- package/dist/infrastructure/validation/agent-validation-helper.js +110 -61
- package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -1
- package/dist/infrastructure/validation/review-handler.d.ts +13 -41
- package/dist/infrastructure/validation/review-handler.d.ts.map +1 -1
- package/dist/infrastructure/validation/review-handler.js +23 -189
- package/dist/infrastructure/validation/review-handler.js.map +1 -1
- package/dist/infrastructure/validation/summary-aggregator.d.ts +25 -22
- package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -1
- package/dist/infrastructure/validation/summary-aggregator.js +47 -133
- package/dist/infrastructure/validation/summary-aggregator.js.map +1 -1
- package/dist/infrastructure/validation/summary-extractor.d.ts +13 -48
- package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -1
- package/dist/infrastructure/validation/summary-extractor.js +32 -89
- package/dist/infrastructure/validation/summary-extractor.js.map +1 -1
- package/dist/infrastructure/validation/trace-summary.d.ts +30 -57
- package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -1
- package/dist/infrastructure/validation/trace-summary.js +37 -356
- package/dist/infrastructure/validation/trace-summary.js.map +1 -1
- package/dist/monitoring.d.ts +1 -1
- package/dist/monitoring.d.ts.map +1 -1
- package/dist/monitoring.js +12 -9
- package/dist/monitoring.js.map +1 -1
- package/dist/parallel-processor.d.ts.map +1 -1
- package/dist/parallel-processor.js +124 -45
- package/dist/parallel-processor.js.map +1 -1
- package/dist/presentation/cli/commands/ask-command.d.ts +2 -0
- package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/ask-command.js +316 -129
- package/dist/presentation/cli/commands/ask-command.js.map +1 -1
- package/dist/presentation/cli/commands/config-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/config-command.js +22 -8
- package/dist/presentation/cli/commands/config-command.js.map +1 -1
- package/dist/presentation/cli/commands/decision-command.js +23 -6
- package/dist/presentation/cli/commands/decision-command.js.map +1 -1
- package/dist/presentation/cli/commands/docs-command.d.ts +3 -1
- package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/docs-command.js +13 -184
- package/dist/presentation/cli/commands/docs-command.js.map +1 -1
- package/dist/presentation/cli/commands/fix-command.d.ts +2 -0
- package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/fix-command.js +61 -276
- package/dist/presentation/cli/commands/fix-command.js.map +1 -1
- package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/help-command.js +21 -1
- package/dist/presentation/cli/commands/help-command.js.map +1 -1
- package/dist/presentation/cli/commands/memory-command.d.ts +17 -0
- package/dist/presentation/cli/commands/memory-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/memory-command.js +252 -0
- package/dist/presentation/cli/commands/memory-command.js.map +1 -0
- package/dist/presentation/cli/commands/models-command.d.ts +13 -0
- package/dist/presentation/cli/commands/models-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/models-command.js +194 -0
- package/dist/presentation/cli/commands/models-command.js.map +1 -0
- package/dist/presentation/cli/commands/orchestrate-command.d.ts +1 -0
- package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/orchestrate-command.js +129 -14
- package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -1
- package/dist/presentation/cli/commands/plan-command.d.ts +1 -0
- package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/plan-command.js +134 -25
- package/dist/presentation/cli/commands/plan-command.js.map +1 -1
- package/dist/presentation/cli/commands/product-command.d.ts +6 -4
- package/dist/presentation/cli/commands/product-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/product-command.js +12 -178
- package/dist/presentation/cli/commands/product-command.js.map +1 -1
- package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/react-command.js +5 -1
- package/dist/presentation/cli/commands/react-command.js.map +1 -1
- package/dist/presentation/cli/commands/review-command.d.ts +7 -7
- package/dist/presentation/cli/commands/review-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/review-command.js +167 -16
- package/dist/presentation/cli/commands/review-command.js.map +1 -1
- package/dist/presentation/cli/commands/run-command.d.ts +6 -8
- package/dist/presentation/cli/commands/run-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/run-command.js +182 -23
- package/dist/presentation/cli/commands/run-command.js.map +1 -1
- package/dist/presentation/cli/commands/setup-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/setup-command.js +15 -0
- package/dist/presentation/cli/commands/setup-command.js.map +1 -1
- package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/smart-command.js +74 -6
- package/dist/presentation/cli/commands/smart-command.js.map +1 -1
- package/dist/presentation/cli/commands/status-command.d.ts +3 -0
- package/dist/presentation/cli/commands/status-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/status-command.js +151 -156
- package/dist/presentation/cli/commands/status-command.js.map +1 -1
- package/dist/presentation/cli/commands/suggest-command.d.ts +3 -5
- package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/suggest-command.js +132 -19
- package/dist/presentation/cli/commands/suggest-command.js.map +1 -1
- package/dist/presentation/cli/error-display.d.ts.map +1 -1
- package/dist/presentation/cli/error-display.js +75 -17
- package/dist/presentation/cli/error-display.js.map +1 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +6 -1
- package/dist/search.js.map +1 -1
- package/dist/session.d.ts +1 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +55 -7
- package/dist/session.js.map +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +3 -0
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/git-tool.js +7 -7
- package/dist/tools/git-tool.js.map +1 -1
- package/dist/ui.d.ts +11 -0
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +54 -1
- package/dist/ui.js.map +1 -1
- package/package.json +14 -4
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: OpenRouterProvider
|
|
3
|
+
* Implements IModelProvider for OpenRouter API
|
|
4
|
+
*
|
|
5
|
+
* Phase 4D: OpenRouter Provider Implementation
|
|
6
|
+
*
|
|
7
|
+
* OpenRouter provides unified access to 400+ AI models through a single API.
|
|
8
|
+
* Supports GPT-4, Claude, Llama, Mistral, and many more models.
|
|
9
|
+
*
|
|
10
|
+
* Uses OpenRouter REST API directly (no SDK dependency) to keep dependencies minimal.
|
|
11
|
+
*/
|
|
12
|
+
import { config } from 'dotenv';
|
|
13
|
+
import { join, dirname } from 'path';
|
|
14
|
+
import { fileURLToPath } from 'url';
|
|
15
|
+
import { encoding_for_model } from 'tiktoken';
|
|
16
|
+
import { retryWithBackoff } from '../../error-handler.js';
|
|
17
|
+
// Load .env (same pattern as other providers)
|
|
18
|
+
try {
|
|
19
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = dirname(__filename);
|
|
21
|
+
const agentDir = join(__dirname, '../../../..');
|
|
22
|
+
config({ path: join(agentDir, '.env') });
|
|
23
|
+
}
|
|
24
|
+
catch { }
|
|
25
|
+
config();
|
|
26
|
+
// Token counting (using tiktoken - OpenAI's tokenizer, works for most models)
|
|
27
|
+
let tokenEncoder = null;
|
|
28
|
+
function getTokenEncoder() {
|
|
29
|
+
if (!tokenEncoder) {
|
|
30
|
+
try {
|
|
31
|
+
tokenEncoder = encoding_for_model('gpt-3.5-turbo');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
tokenEncoder = encoding_for_model('gpt-4');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return tokenEncoder;
|
|
38
|
+
}
|
|
39
|
+
function countTokens(text) {
|
|
40
|
+
try {
|
|
41
|
+
const encoder = getTokenEncoder();
|
|
42
|
+
return encoder.encode(text).length;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.warn('Warning: tiktoken failed, using character-based estimate (less accurate)');
|
|
46
|
+
return Math.ceil(text.length / 4);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* OpenRouter Provider
|
|
51
|
+
* Implements IModelProvider using OpenRouter REST API
|
|
52
|
+
*/
|
|
53
|
+
export class OpenRouterProvider {
|
|
54
|
+
id = 'openrouter';
|
|
55
|
+
name = 'OpenRouter';
|
|
56
|
+
capabilities = {
|
|
57
|
+
chat: true,
|
|
58
|
+
streaming: true,
|
|
59
|
+
embedding: false, // OpenRouter routes to model-specific endpoints (TBD)
|
|
60
|
+
embeddingQuery: false,
|
|
61
|
+
rerank: false, // OpenRouter doesn't have unified rerank API
|
|
62
|
+
toolCalling: true, // Many models support tool calling
|
|
63
|
+
};
|
|
64
|
+
apiKey;
|
|
65
|
+
baseUrl;
|
|
66
|
+
defaultChatModel;
|
|
67
|
+
constructor(apiKey) {
|
|
68
|
+
const key = apiKey || process.env.OPENROUTER_API_KEY;
|
|
69
|
+
if (!key) {
|
|
70
|
+
throw new Error('OPENROUTER_API_KEY not found in environment');
|
|
71
|
+
}
|
|
72
|
+
this.apiKey = key;
|
|
73
|
+
this.baseUrl = process.env.OPENROUTER_BASE_URL || 'https://openrouter.ai/api/v1';
|
|
74
|
+
this.defaultChatModel = process.env.CODEHERE_OPENROUTER_CHAT_MODEL || 'openai/gpt-4o-mini';
|
|
75
|
+
}
|
|
76
|
+
async getModels() {
|
|
77
|
+
// Fetch models from OpenRouter API
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
80
|
+
method: 'GET',
|
|
81
|
+
headers: {
|
|
82
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
83
|
+
'HTTP-Referer': 'https://github.com/muhammadegaa/codehere', // Optional: for analytics
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
// Fallback to known models if API call fails
|
|
88
|
+
return this.getDefaultModels();
|
|
89
|
+
}
|
|
90
|
+
const data = await response.json();
|
|
91
|
+
const models = data.data || [];
|
|
92
|
+
// Transform OpenRouter model format to ModelInfo
|
|
93
|
+
return models
|
|
94
|
+
.filter((model) => model.id && model.name)
|
|
95
|
+
.map((model) => ({
|
|
96
|
+
id: model.id,
|
|
97
|
+
name: model.name || model.id,
|
|
98
|
+
providerId: 'openrouter',
|
|
99
|
+
providerModelId: model.id,
|
|
100
|
+
contextWindow: model.context_length || 8192,
|
|
101
|
+
capabilities: {
|
|
102
|
+
chat: model.top_provider?.supports_chat !== false,
|
|
103
|
+
streaming: true,
|
|
104
|
+
embedding: false, // OpenRouter embeddings TBD
|
|
105
|
+
embeddingQuery: false,
|
|
106
|
+
rerank: false,
|
|
107
|
+
toolCalling: model.top_provider?.supports_function_calling === true,
|
|
108
|
+
},
|
|
109
|
+
}));
|
|
110
|
+
// Note: OpenRouter API returns all available models, not limited to 100
|
|
111
|
+
// The slice(0, 100) was a temporary limit that should be removed
|
|
112
|
+
// For now, we return all models from the API response
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
// Fallback to known models on error
|
|
116
|
+
console.warn('[OpenRouterProvider] Failed to fetch models, using defaults:', error instanceof Error ? error.message : String(error));
|
|
117
|
+
return this.getDefaultModels();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get default models (fallback if API call fails)
|
|
122
|
+
*/
|
|
123
|
+
getDefaultModels() {
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
id: 'openai/gpt-4o',
|
|
127
|
+
name: 'GPT-4o (via OpenRouter)',
|
|
128
|
+
providerId: 'openrouter',
|
|
129
|
+
providerModelId: 'openai/gpt-4o',
|
|
130
|
+
contextWindow: 128000,
|
|
131
|
+
capabilities: {
|
|
132
|
+
chat: true,
|
|
133
|
+
streaming: true,
|
|
134
|
+
embedding: false,
|
|
135
|
+
embeddingQuery: false,
|
|
136
|
+
rerank: false,
|
|
137
|
+
toolCalling: true,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'openai/gpt-4o-mini',
|
|
142
|
+
name: 'GPT-4o Mini (via OpenRouter)',
|
|
143
|
+
providerId: 'openrouter',
|
|
144
|
+
providerModelId: 'openai/gpt-4o-mini',
|
|
145
|
+
contextWindow: 128000,
|
|
146
|
+
capabilities: {
|
|
147
|
+
chat: true,
|
|
148
|
+
streaming: true,
|
|
149
|
+
embedding: false,
|
|
150
|
+
embeddingQuery: false,
|
|
151
|
+
rerank: false,
|
|
152
|
+
toolCalling: true,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: 'anthropic/claude-3.5-sonnet',
|
|
157
|
+
name: 'Claude 3.5 Sonnet (via OpenRouter)',
|
|
158
|
+
providerId: 'openrouter',
|
|
159
|
+
providerModelId: 'anthropic/claude-3.5-sonnet',
|
|
160
|
+
contextWindow: 200000,
|
|
161
|
+
capabilities: {
|
|
162
|
+
chat: true,
|
|
163
|
+
streaming: true,
|
|
164
|
+
embedding: false,
|
|
165
|
+
embeddingQuery: false,
|
|
166
|
+
rerank: false,
|
|
167
|
+
toolCalling: true,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: 'meta-llama/llama-3.1-70b-instruct',
|
|
172
|
+
name: 'Llama 3.1 70B (via OpenRouter)',
|
|
173
|
+
providerId: 'openrouter',
|
|
174
|
+
providerModelId: 'meta-llama/llama-3.1-70b-instruct',
|
|
175
|
+
contextWindow: 131072,
|
|
176
|
+
capabilities: {
|
|
177
|
+
chat: true,
|
|
178
|
+
streaming: true,
|
|
179
|
+
embedding: false,
|
|
180
|
+
embeddingQuery: false,
|
|
181
|
+
rerank: false,
|
|
182
|
+
toolCalling: false,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
getDefaultModel() {
|
|
188
|
+
return this.defaultChatModel;
|
|
189
|
+
}
|
|
190
|
+
async chat(prompt, options) {
|
|
191
|
+
const model = options?.model || this.defaultChatModel;
|
|
192
|
+
return await retryWithBackoff(async () => {
|
|
193
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: {
|
|
196
|
+
'Content-Type': 'application/json',
|
|
197
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
198
|
+
'HTTP-Referer': 'https://github.com/muhammadegaa/codehere', // Optional: for analytics
|
|
199
|
+
'X-Title': 'Codehere CLI', // Optional: for analytics
|
|
200
|
+
},
|
|
201
|
+
body: JSON.stringify({
|
|
202
|
+
model,
|
|
203
|
+
messages: [
|
|
204
|
+
{
|
|
205
|
+
role: 'user',
|
|
206
|
+
content: prompt,
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
temperature: options?.temperature ?? 0.7,
|
|
210
|
+
max_tokens: options?.maxTokens,
|
|
211
|
+
}),
|
|
212
|
+
});
|
|
213
|
+
if (!response.ok) {
|
|
214
|
+
const errorText = await response.text();
|
|
215
|
+
let errorMessage = `OpenRouter API error: ${response.status} ${response.statusText}`;
|
|
216
|
+
try {
|
|
217
|
+
const errorJson = JSON.parse(errorText);
|
|
218
|
+
errorMessage = errorJson.error?.message || errorMessage;
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
errorMessage = errorText || errorMessage;
|
|
222
|
+
}
|
|
223
|
+
throw new Error(errorMessage);
|
|
224
|
+
}
|
|
225
|
+
const data = await response.json();
|
|
226
|
+
const text = data.choices?.[0]?.message?.content || 'No response generated';
|
|
227
|
+
const usage = data.usage || {};
|
|
228
|
+
return {
|
|
229
|
+
text,
|
|
230
|
+
model: data.model || model,
|
|
231
|
+
usage: {
|
|
232
|
+
inputTokens: usage.prompt_tokens || countTokens(prompt),
|
|
233
|
+
outputTokens: usage.completion_tokens || countTokens(text),
|
|
234
|
+
},
|
|
235
|
+
finishReason: data.choices?.[0]?.finish_reason,
|
|
236
|
+
};
|
|
237
|
+
}, {
|
|
238
|
+
maxRetries: 5,
|
|
239
|
+
baseDelay: 2000,
|
|
240
|
+
maxDelay: 60000,
|
|
241
|
+
operationName: 'openrouter-provider-chat',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async chatStream(prompt, options, onEvent) {
|
|
245
|
+
const model = options?.model || this.defaultChatModel;
|
|
246
|
+
let fullText = '';
|
|
247
|
+
try {
|
|
248
|
+
if (onEvent) {
|
|
249
|
+
onEvent({ type: 'start' });
|
|
250
|
+
}
|
|
251
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
headers: {
|
|
254
|
+
'Content-Type': 'application/json',
|
|
255
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
256
|
+
'HTTP-Referer': 'https://github.com/muhammadegaa/codehere',
|
|
257
|
+
'X-Title': 'Codehere CLI',
|
|
258
|
+
},
|
|
259
|
+
body: JSON.stringify({
|
|
260
|
+
model,
|
|
261
|
+
messages: [
|
|
262
|
+
{
|
|
263
|
+
role: 'user',
|
|
264
|
+
content: prompt,
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
temperature: options?.temperature ?? 0.7,
|
|
268
|
+
max_tokens: options?.maxTokens,
|
|
269
|
+
stream: true,
|
|
270
|
+
}),
|
|
271
|
+
});
|
|
272
|
+
if (!response.ok) {
|
|
273
|
+
const errorText = await response.text();
|
|
274
|
+
throw new Error(`OpenRouter API error: ${response.status} ${errorText}`);
|
|
275
|
+
}
|
|
276
|
+
if (!response.body) {
|
|
277
|
+
throw new Error('No response body for streaming');
|
|
278
|
+
}
|
|
279
|
+
const reader = response.body.getReader();
|
|
280
|
+
const decoder = new TextDecoder();
|
|
281
|
+
while (true) {
|
|
282
|
+
const { done, value } = await reader.read();
|
|
283
|
+
if (done)
|
|
284
|
+
break;
|
|
285
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
286
|
+
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
287
|
+
for (const line of lines) {
|
|
288
|
+
if (line.startsWith('data: ')) {
|
|
289
|
+
const data = line.slice(6);
|
|
290
|
+
if (data === '[DONE]') {
|
|
291
|
+
if (onEvent) {
|
|
292
|
+
onEvent({ type: 'complete', text: fullText });
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
const json = JSON.parse(data);
|
|
298
|
+
const delta = json.choices?.[0]?.delta?.content;
|
|
299
|
+
if (delta) {
|
|
300
|
+
fullText += delta;
|
|
301
|
+
if (onEvent) {
|
|
302
|
+
onEvent({ type: 'delta', text: delta });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
catch (e) {
|
|
307
|
+
// Skip invalid JSON chunks
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (onEvent && !fullText) {
|
|
313
|
+
onEvent({ type: 'complete', text: fullText });
|
|
314
|
+
}
|
|
315
|
+
const inputTokens = countTokens(prompt);
|
|
316
|
+
const outputTokens = countTokens(fullText);
|
|
317
|
+
return {
|
|
318
|
+
text: fullText,
|
|
319
|
+
model: model || 'default',
|
|
320
|
+
usage: {
|
|
321
|
+
inputTokens,
|
|
322
|
+
outputTokens,
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
if (onEvent) {
|
|
328
|
+
onEvent({
|
|
329
|
+
type: 'error',
|
|
330
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async embed(_text) {
|
|
337
|
+
// OpenRouter embeddings support TBD - will route to model-specific endpoints
|
|
338
|
+
throw new Error('Embeddings not yet supported via OpenRouter. Use direct provider (Cohere/OpenAI) for embeddings.');
|
|
339
|
+
}
|
|
340
|
+
async countTokens(text, _model) {
|
|
341
|
+
return Promise.resolve(countTokens(text));
|
|
342
|
+
}
|
|
343
|
+
async isAvailable() {
|
|
344
|
+
try {
|
|
345
|
+
// Simple availability check - try a minimal API call
|
|
346
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
347
|
+
method: 'GET',
|
|
348
|
+
headers: {
|
|
349
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
return response.ok;
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
handleError(error) {
|
|
359
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
360
|
+
const lowerMessage = errorMessage.toLowerCase();
|
|
361
|
+
// Rate limiting (429)
|
|
362
|
+
if (errorMessage.includes('429') || lowerMessage.includes('rate limit') || lowerMessage.includes('rate_limit')) {
|
|
363
|
+
return {
|
|
364
|
+
type: 'rate_limit',
|
|
365
|
+
retryable: true, // OpenRouter may have retry logic
|
|
366
|
+
message: 'Rate limit exceeded',
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
// Authentication errors (401)
|
|
370
|
+
if (errorMessage.includes('401') || errorMessage.includes('Unauthorized') || lowerMessage.includes('no api key')) {
|
|
371
|
+
return {
|
|
372
|
+
type: 'auth_error',
|
|
373
|
+
retryable: false,
|
|
374
|
+
message: 'Authentication failed - check OPENROUTER_API_KEY',
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
// Quota exceeded
|
|
378
|
+
if (errorMessage.includes('quota') || errorMessage.includes('insufficient_quota') || lowerMessage.includes('insufficient credits')) {
|
|
379
|
+
return {
|
|
380
|
+
type: 'quota_exceeded',
|
|
381
|
+
retryable: false,
|
|
382
|
+
message: 'OpenRouter credits insufficient',
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
// Network errors
|
|
386
|
+
if (errorMessage.includes('network') || errorMessage.includes('timeout') || errorMessage.includes('ECONNREFUSED')) {
|
|
387
|
+
return {
|
|
388
|
+
type: 'network_error',
|
|
389
|
+
retryable: true,
|
|
390
|
+
message: errorMessage,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
// Default to retryable
|
|
394
|
+
return {
|
|
395
|
+
type: 'unknown',
|
|
396
|
+
retryable: true,
|
|
397
|
+
message: errorMessage,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
//# sourceMappingURL=openrouter-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-provider.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/openrouter-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,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BACnD,OAAO,EAAE,qBAAqB;aAC/B,CAAC;QACJ,CAAC;QAED,8BAA8B;QAC9B,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACjH,OAAO;gBACL,IAAI,EAAE,YAAY;gBAClB,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,kDAAkD;aAC5D,CAAC;QACJ,CAAC;QAED,iBAAiB;QACjB,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;YACnI,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,iCAAiC;aAC3C,CAAC;QACJ,CAAC;QAED,iBAAiB;QACjB,IAAI,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAClH,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,YAAY;aACtB,CAAC;QACJ,CAAC;QAED,uBAAuB;QACvB,OAAO;YACL,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,YAAY;SACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-provider-resolver.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/operation-provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,eAAe,CAAwC;IAC/D,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAmB;gBAGjC,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,CAAC,EAAE,uBAAuB,GAAG,IAAI,EAChD,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI;IAOvC;;;;;OAKG;IACH,eAAe,CAAC,SAAS,EAAE,aAAa,GAAG,cAAc;
|
|
1
|
+
{"version":3,"file":"operation-provider-resolver.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/operation-provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,eAAe,CAAwC;IAC/D,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAmB;gBAGjC,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,CAAC,EAAE,uBAAuB,GAAG,IAAI,EAChD,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI;IAOvC;;;;;OAKG;IACH,eAAe,CAAC,SAAS,EAAE,aAAa,GAAG,cAAc;IA4FzD;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,GAAG,IAAI;IAIhE;;OAEG;IACH,kBAAkB,IAAI,uBAAuB,GAAG,IAAI;CAGrD"}
|
|
@@ -33,9 +33,26 @@ export class OperationProviderResolver {
|
|
|
33
33
|
* @returns The IModelProvider to use for this operation
|
|
34
34
|
*/
|
|
35
35
|
resolveProvider(operation) {
|
|
36
|
+
const supportsOperation = (provider) => {
|
|
37
|
+
if (!provider)
|
|
38
|
+
return false;
|
|
39
|
+
return provider.capabilities?.[operation] === true || operation === 'chat'; // chat assumed supported if provider exists
|
|
40
|
+
};
|
|
41
|
+
const safeGet = (providerId, context) => {
|
|
42
|
+
if (!providerId)
|
|
43
|
+
return undefined;
|
|
44
|
+
const provider = this.registry.get(providerId);
|
|
45
|
+
if (provider && supportsOperation(provider)) {
|
|
46
|
+
return provider;
|
|
47
|
+
}
|
|
48
|
+
if (provider && !supportsOperation(provider)) {
|
|
49
|
+
console.warn(`[OperationProviderResolver] Provider '${providerId}' does not support '${operation}', skipping (${context})`);
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
36
53
|
// Precedence 1: FakeProvider always wins if CODEHERE_FAKE_AI=1
|
|
37
54
|
if (process.env.CODEHERE_FAKE_AI === '1') {
|
|
38
|
-
const fakeProvider =
|
|
55
|
+
const fakeProvider = safeGet('fake', 'fake');
|
|
39
56
|
if (fakeProvider) {
|
|
40
57
|
return fakeProvider;
|
|
41
58
|
}
|
|
@@ -56,16 +73,16 @@ export class OperationProviderResolver {
|
|
|
56
73
|
}
|
|
57
74
|
// If operation-specific provider is set, use it
|
|
58
75
|
if (providerId) {
|
|
59
|
-
const provider =
|
|
76
|
+
const provider = safeGet(providerId, 'operation override');
|
|
60
77
|
if (provider) {
|
|
61
78
|
return provider;
|
|
62
79
|
}
|
|
63
80
|
// If operation provider is misconfigured, fall through to next precedence
|
|
64
|
-
console.warn(`[OperationProviderResolver] Provider '${providerId}' not found for operation '${operation}', falling back to default`);
|
|
81
|
+
console.warn(`[OperationProviderResolver] Provider '${providerId}' not found or unsupported for operation '${operation}', falling back to default`);
|
|
65
82
|
}
|
|
66
83
|
// Check for default in operation config
|
|
67
84
|
if (this.operationConfig.default) {
|
|
68
|
-
const provider =
|
|
85
|
+
const provider = safeGet(this.operationConfig.default, 'config default');
|
|
69
86
|
if (provider) {
|
|
70
87
|
return provider;
|
|
71
88
|
}
|
|
@@ -73,7 +90,7 @@ export class OperationProviderResolver {
|
|
|
73
90
|
}
|
|
74
91
|
// Precedence 2b: Config default provider (if no operation override)
|
|
75
92
|
if (this.configDefault) {
|
|
76
|
-
const provider =
|
|
93
|
+
const provider = safeGet(this.configDefault, 'config default (no override)');
|
|
77
94
|
if (provider) {
|
|
78
95
|
return provider;
|
|
79
96
|
}
|
|
@@ -81,13 +98,22 @@ export class OperationProviderResolver {
|
|
|
81
98
|
// Precedence 3: Global provider env choice (CODEHERE_AI_PROVIDER)
|
|
82
99
|
const requestedProvider = process.env.CODEHERE_AI_PROVIDER?.toLowerCase();
|
|
83
100
|
if (requestedProvider) {
|
|
84
|
-
const provider =
|
|
101
|
+
const provider = safeGet(requestedProvider, 'env');
|
|
85
102
|
if (provider) {
|
|
86
103
|
return provider;
|
|
87
104
|
}
|
|
88
105
|
}
|
|
89
106
|
// Precedence 4: Registry default provider (fallback)
|
|
90
|
-
|
|
107
|
+
const defaultProvider = this.registry.getDefault();
|
|
108
|
+
if (supportsOperation(defaultProvider)) {
|
|
109
|
+
return defaultProvider;
|
|
110
|
+
}
|
|
111
|
+
// Final fallback: first provider that supports the operation
|
|
112
|
+
const candidates = this.registry.findByCapability(operation);
|
|
113
|
+
if (candidates.length > 0) {
|
|
114
|
+
return candidates[0];
|
|
115
|
+
}
|
|
116
|
+
return defaultProvider;
|
|
91
117
|
}
|
|
92
118
|
/**
|
|
93
119
|
* Set operation-level configuration (for testing or future config file support)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-provider-resolver.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/operation-provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,yBAAyB;IAC5B,eAAe,GAAmC,IAAI,CAAC;IACvD,aAAa,GAAkB,IAAI,CAAC;IACpC,QAAQ,CAAmB;IAEnC,YACE,QAA0B,EAC1B,eAAgD,EAChD,qBAAqC;QAErC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,qBAAqB,IAAI,IAAI,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,SAAwB;QACtC,+DAA+D;QAC/D,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"operation-provider-resolver.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/operation-provider-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,yBAAyB;IAC5B,eAAe,GAAmC,IAAI,CAAC;IACvD,aAAa,GAAkB,IAAI,CAAC;IACpC,QAAQ,CAAmB;IAEnC,YACE,QAA0B,EAC1B,eAAgD,EAChD,qBAAqC;QAErC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,aAAa,GAAG,qBAAqB,IAAI,IAAI,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,SAAwB;QACtC,MAAM,iBAAiB,GAAG,CAAC,QAAyB,EAAE,EAAE;YACtD,IAAI,CAAC,QAAQ;gBAAE,OAAO,KAAK,CAAC;YAC5B,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC,S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AAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAgB,CAAC,CAAC;QACpE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,MAAsC;QACvD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-validator.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/input-validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAuCnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"input-validator.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/input-validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAuCnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAyD7D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CA2B/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAyB,GAAG,gBAAgB,CAkBzG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAmBxD"}
|
|
@@ -51,11 +51,21 @@ export function validateQuery(query) {
|
|
|
51
51
|
errors.push('Null bytes not allowed in query');
|
|
52
52
|
}
|
|
53
53
|
// Check for command injection patterns
|
|
54
|
+
// Only block ACTUAL dangerous patterns, not currency symbols or normal text
|
|
54
55
|
const commandInjectionPatterns = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
// Actual command chaining (semicolon, pipe, backtick, ampersand)
|
|
57
|
+
/[;&|`]/,
|
|
58
|
+
// Command substitution with parentheses (but allow normal parentheses in text)
|
|
59
|
+
/\$\([^)]*\)/, // $(command) pattern
|
|
60
|
+
/\$\{[^}]*\}/, // ${variable} pattern (but allow ${ in normal text if not followed by command)
|
|
61
|
+
// XSS attempts
|
|
62
|
+
/<script/i,
|
|
63
|
+
/javascript:/i,
|
|
64
|
+
/on\w+\s*=/i,
|
|
65
|
+
// Shell redirection (but allow < and > in normal text)
|
|
66
|
+
/\s*[<>]\s*\w+/, // < file or > file patterns
|
|
67
|
+
// Command injection with backticks
|
|
68
|
+
/`[^`]*`/, // `command` pattern
|
|
59
69
|
];
|
|
60
70
|
for (const pattern of commandInjectionPatterns) {
|
|
61
71
|
if (pattern.test(query)) {
|
|
@@ -63,10 +73,13 @@ export function validateQuery(query) {
|
|
|
63
73
|
break;
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
|
-
// Sanitize query
|
|
76
|
+
// Sanitize query (only remove actual dangerous patterns, preserve normal text)
|
|
67
77
|
let sanitized = query
|
|
68
78
|
.replace(/\0/g, '') // Remove null bytes
|
|
69
|
-
.replace(/[
|
|
79
|
+
.replace(/[;&|`]/g, '') // Remove command chaining characters
|
|
80
|
+
.replace(/\$\([^)]*\)/g, '') // Remove command substitution $(...)
|
|
81
|
+
.replace(/\$\{[^}]*\}/g, '') // Remove command substitution ${...}
|
|
82
|
+
.replace(/`[^`]*`/g, '') // Remove backtick command execution
|
|
70
83
|
.replace(/<script/gi, '<script') // Escape script tags
|
|
71
84
|
.replace(/javascript:/gi, '') // Remove javascript protocol
|
|
72
85
|
.replace(/on\w+\s*=/gi, ''); // Remove event handlers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-validator.js","sourceRoot":"","sources":["../../../src/infrastructure/security/input-validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,yCAAyC;IACzC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;IAED,gDAAgD;IAChD,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAC5C,CAAC;IAED,uBAAuB;IACvB,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;IACrD,CAAC;IAED,iCAAiC;IACjC,MAAM,cAAc,GAAG,oBAAoB,CAAC;IAC5C,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;IACjD,CAAC;IAED,g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ase 1: Code Context Serialization for v1.0.0 MVP
|
|
5
|
+
*
|
|
6
|
+
* Benefits:
|
|
7
|
+
* - 30-60% token reduction compared to JSON
|
|
8
|
+
* - Better LLM parsing accuracy
|
|
9
|
+
* - Self-documenting structure
|
|
10
|
+
*
|
|
11
|
+
* Feature Flag: CODEHERE_USE_TOON (default: false for v1.0.0)
|
|
12
|
+
*/
|
|
13
|
+
import type { CodeChunk } from '../../domain/entities/code-chunk.js';
|
|
14
|
+
/**
|
|
15
|
+
* Serialize code chunks to TOON format
|
|
16
|
+
*
|
|
17
|
+
* TOON format for code chunks:
|
|
18
|
+
* chunks[N]{filepath,content,score,lineStart,lineEnd}:
|
|
19
|
+
* src/auth.ts,function authenticate() {...},0.95,10,60
|
|
20
|
+
* src/utils.ts,export function helper() {...},0.87,5,35
|
|
21
|
+
*
|
|
22
|
+
* @param chunks Code chunks to serialize
|
|
23
|
+
* @returns TOON-formatted string, or null if TOON is disabled or library unavailable
|
|
24
|
+
*/
|
|
25
|
+
export declare function serializeCodeChunksToToon(chunks: CodeChunk[]): Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Serialize code chunks to traditional format (fallback)
|
|
28
|
+
* Used when TOON is disabled or unavailable
|
|
29
|
+
*
|
|
30
|
+
* @param chunks Code chunks to serialize
|
|
31
|
+
* @returns Traditional formatted string
|
|
32
|
+
*/
|
|
33
|
+
export declare function serializeCodeChunksToTraditional(chunks: CodeChunk[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Serialize code chunks (TOON if enabled, traditional otherwise)
|
|
36
|
+
*
|
|
37
|
+
* @param chunks Code chunks to serialize
|
|
38
|
+
* @returns Formatted string (TOON or traditional)
|
|
39
|
+
*/
|
|
40
|
+
export declare function serializeCodeChunks(chunks: CodeChunk[]): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if TOON is available and enabled
|
|
43
|
+
*/
|
|
44
|
+
export declare function isToonAvailable(): Promise<boolean>;
|
|
45
|
+
//# sourceMappingURL=toon-serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toon-serializer.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/serialization/toon-serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AA+BrE;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmC3F;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAI5E;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAO9E;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAMxD"}
|