codehere 0.3.0 → 0.4.0
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.
Potentially problematic release.
This version of codehere might be problematic. Click here for more details.
- package/README.md +223 -42
- package/dist/application/agents/documentation-agent.d.ts +24 -0
- package/dist/application/agents/documentation-agent.d.ts.map +1 -0
- package/dist/application/agents/documentation-agent.js +399 -0
- package/dist/application/agents/documentation-agent.js.map +1 -0
- package/dist/application/agents/execution-agent.d.ts +11 -0
- package/dist/application/agents/execution-agent.d.ts.map +1 -1
- package/dist/application/agents/execution-agent.js +289 -80
- package/dist/application/agents/execution-agent.js.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.d.ts +3 -0
- package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
- package/dist/application/agents/multi-agent-orchestrator.js +86 -0
- package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
- package/dist/application/agents/planning-agent.d.ts +3 -0
- package/dist/application/agents/planning-agent.d.ts.map +1 -1
- package/dist/application/agents/planning-agent.js +132 -64
- package/dist/application/agents/planning-agent.js.map +1 -1
- package/dist/application/agents/product-requirements-agent.d.ts +21 -0
- package/dist/application/agents/product-requirements-agent.d.ts.map +1 -0
- package/dist/application/agents/product-requirements-agent.js +247 -0
- package/dist/application/agents/product-requirements-agent.js.map +1 -0
- package/dist/application/agents/validation-agent.d.ts +5 -1
- package/dist/application/agents/validation-agent.d.ts.map +1 -1
- package/dist/application/agents/validation-agent.js +156 -21
- package/dist/application/agents/validation-agent.js.map +1 -1
- package/dist/application/services/dependency-container.d.ts +22 -2
- package/dist/application/services/dependency-container.d.ts.map +1 -1
- package/dist/application/services/dependency-container.js +144 -6
- package/dist/application/services/dependency-container.js.map +1 -1
- package/dist/application/services/intelligent-router.d.ts +13 -0
- package/dist/application/services/intelligent-router.d.ts.map +1 -1
- package/dist/application/services/intelligent-router.js +300 -87
- package/dist/application/services/intelligent-router.js.map +1 -1
- package/dist/application/use-cases/ask-question-use-case.d.ts +19 -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 +125 -46
- package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
- package/dist/application/use-cases/edit-file-use-case.d.ts.map +1 -1
- package/dist/application/use-cases/edit-file-use-case.js +16 -1
- package/dist/application/use-cases/edit-file-use-case.js.map +1 -1
- package/dist/domain/entities/documentation.d.ts +35 -0
- package/dist/domain/entities/documentation.d.ts.map +1 -0
- package/dist/domain/entities/documentation.js +6 -0
- package/dist/domain/entities/documentation.js.map +1 -0
- package/dist/domain/entities/product-requirements.d.ts +50 -0
- package/dist/domain/entities/product-requirements.d.ts.map +1 -0
- package/dist/domain/entities/product-requirements.js +6 -0
- package/dist/domain/entities/product-requirements.js.map +1 -0
- package/dist/domain/entities/task.d.ts +152 -0
- package/dist/domain/entities/task.d.ts.map +1 -0
- package/dist/domain/entities/task.js +61 -0
- package/dist/domain/entities/task.js.map +1 -0
- package/dist/domain/interfaces/agent.interface.d.ts +15 -0
- package/dist/domain/interfaces/agent.interface.d.ts.map +1 -0
- package/dist/domain/interfaces/agent.interface.js +6 -0
- package/dist/domain/interfaces/agent.interface.js.map +1 -0
- package/dist/domain/services/environment-mode-manager.d.ts +18 -0
- package/dist/domain/services/environment-mode-manager.d.ts.map +1 -0
- package/dist/domain/services/environment-mode-manager.js +37 -0
- package/dist/domain/services/environment-mode-manager.js.map +1 -0
- package/dist/domain/services/risk-tier-detector.d.ts +18 -0
- package/dist/domain/services/risk-tier-detector.d.ts.map +1 -0
- package/dist/domain/services/risk-tier-detector.js +65 -0
- package/dist/domain/services/risk-tier-detector.js.map +1 -0
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +10 -3
- package/dist/formatter.js.map +1 -1
- package/dist/index.js +103 -129
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/ai/cohere-ai-service.d.ts.map +1 -1
- package/dist/infrastructure/ai/cohere-ai-service.js +15 -2
- package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
- package/dist/infrastructure/ai/fake-ai-service.d.ts +22 -0
- package/dist/infrastructure/ai/fake-ai-service.d.ts.map +1 -0
- package/dist/infrastructure/ai/fake-ai-service.js +59 -0
- package/dist/infrastructure/ai/fake-ai-service.js.map +1 -0
- package/dist/infrastructure/ai/provider-ai-service.d.ts +59 -0
- package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -0
- package/dist/infrastructure/ai/provider-ai-service.js +477 -0
- package/dist/infrastructure/ai/provider-ai-service.js.map +1 -0
- package/dist/infrastructure/cache/embedding-cache.d.ts +13 -1
- package/dist/infrastructure/cache/embedding-cache.d.ts.map +1 -1
- package/dist/infrastructure/cache/embedding-cache.js +80 -9
- package/dist/infrastructure/cache/embedding-cache.js.map +1 -1
- package/dist/infrastructure/cache/response-cache.d.ts +86 -0
- package/dist/infrastructure/cache/response-cache.d.ts.map +1 -0
- package/dist/infrastructure/cache/response-cache.js +224 -0
- package/dist/infrastructure/cache/response-cache.js.map +1 -0
- package/dist/infrastructure/context/conversation-context.d.ts +58 -0
- package/dist/infrastructure/context/conversation-context.d.ts.map +1 -0
- package/dist/infrastructure/context/conversation-context.js +170 -0
- package/dist/infrastructure/context/conversation-context.js.map +1 -0
- package/dist/infrastructure/context/session-manager.d.ts +26 -0
- package/dist/infrastructure/context/session-manager.d.ts.map +1 -0
- package/dist/infrastructure/context/session-manager.js +98 -0
- package/dist/infrastructure/context/session-manager.js.map +1 -0
- package/dist/infrastructure/cost/cost-tracker.d.ts +1 -0
- package/dist/infrastructure/cost/cost-tracker.d.ts.map +1 -1
- package/dist/infrastructure/cost/cost-tracker.js +12 -5
- package/dist/infrastructure/cost/cost-tracker.js.map +1 -1
- package/dist/infrastructure/governance/nist-ai-rmf.d.ts +6 -8
- package/dist/infrastructure/governance/nist-ai-rmf.d.ts.map +1 -1
- package/dist/infrastructure/governance/nist-ai-rmf.js +6 -8
- package/dist/infrastructure/governance/nist-ai-rmf.js.map +1 -1
- package/dist/infrastructure/governance/policy-as-code.d.ts +6 -8
- package/dist/infrastructure/governance/policy-as-code.d.ts.map +1 -1
- package/dist/infrastructure/governance/policy-as-code.js +6 -8
- package/dist/infrastructure/governance/policy-as-code.js.map +1 -1
- package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts +7 -9
- package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts.map +1 -1
- package/dist/infrastructure/governance/prompt-to-code-lineage.js +7 -9
- package/dist/infrastructure/governance/prompt-to-code-lineage.js.map +1 -1
- package/dist/infrastructure/providers/cohere-provider.d.ts +39 -0
- package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/cohere-provider.js +359 -0
- package/dist/infrastructure/providers/cohere-provider.js.map +1 -0
- package/dist/infrastructure/providers/fake-provider.d.ts +43 -0
- package/dist/infrastructure/providers/fake-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/fake-provider.js +130 -0
- package/dist/infrastructure/providers/fake-provider.js.map +1 -0
- package/dist/infrastructure/providers/local-llm-provider.d.ts +49 -0
- package/dist/infrastructure/providers/local-llm-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/local-llm-provider.js +330 -0
- package/dist/infrastructure/providers/local-llm-provider.js.map +1 -0
- package/dist/infrastructure/providers/model-config.types.d.ts +70 -0
- package/dist/infrastructure/providers/model-config.types.d.ts.map +1 -0
- package/dist/infrastructure/providers/model-config.types.js +9 -0
- package/dist/infrastructure/providers/model-config.types.js.map +1 -0
- package/dist/infrastructure/providers/model-provider.interface.d.ts +113 -0
- package/dist/infrastructure/providers/model-provider.interface.d.ts.map +1 -0
- package/dist/infrastructure/providers/model-provider.interface.js +8 -0
- package/dist/infrastructure/providers/model-provider.interface.js.map +1 -0
- package/dist/infrastructure/providers/openai-provider.d.ts +38 -0
- package/dist/infrastructure/providers/openai-provider.d.ts.map +1 -0
- package/dist/infrastructure/providers/openai-provider.js +413 -0
- package/dist/infrastructure/providers/openai-provider.js.map +1 -0
- package/dist/infrastructure/providers/operation-provider-resolver.d.ts +48 -0
- package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -0
- package/dist/infrastructure/providers/operation-provider-resolver.js +105 -0
- package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -0
- package/dist/infrastructure/providers/provider-config-loader.d.ts +37 -0
- package/dist/infrastructure/providers/provider-config-loader.d.ts.map +1 -0
- package/dist/infrastructure/providers/provider-config-loader.js +120 -0
- package/dist/infrastructure/providers/provider-config-loader.js.map +1 -0
- package/dist/infrastructure/providers/provider-registry.d.ts +53 -0
- package/dist/infrastructure/providers/provider-registry.d.ts.map +1 -0
- package/dist/infrastructure/providers/provider-registry.js +88 -0
- package/dist/infrastructure/providers/provider-registry.js.map +1 -0
- package/dist/infrastructure/storage/task-helpers.d.ts +58 -0
- package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -0
- package/dist/infrastructure/storage/task-helpers.js +157 -0
- package/dist/infrastructure/storage/task-helpers.js.map +1 -0
- package/dist/infrastructure/storage/task-repository.d.ts +67 -0
- package/dist/infrastructure/storage/task-repository.d.ts.map +1 -0
- package/dist/infrastructure/storage/task-repository.js +205 -0
- package/dist/infrastructure/storage/task-repository.js.map +1 -0
- package/dist/infrastructure/ux/bi-directional-learning.d.ts +22 -0
- package/dist/infrastructure/ux/bi-directional-learning.d.ts.map +1 -1
- package/dist/infrastructure/ux/bi-directional-learning.js +144 -7
- package/dist/infrastructure/ux/bi-directional-learning.js.map +1 -1
- package/dist/infrastructure/ux/capability-boundaries.d.ts +50 -0
- package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -0
- package/dist/infrastructure/ux/capability-boundaries.js +167 -0
- package/dist/infrastructure/ux/capability-boundaries.js.map +1 -0
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts +63 -0
- package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -0
- package/dist/infrastructure/ux/comprehensive-formatter.js +212 -0
- package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -0
- package/dist/infrastructure/ux/feedback-prompt.d.ts +42 -0
- package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -0
- package/dist/infrastructure/ux/feedback-prompt.js +181 -0
- package/dist/infrastructure/ux/feedback-prompt.js.map +1 -0
- package/dist/infrastructure/ux/hitl-review-portal.d.ts.map +1 -1
- package/dist/infrastructure/ux/hitl-review-portal.js +4 -1
- package/dist/infrastructure/ux/hitl-review-portal.js.map +1 -1
- package/dist/infrastructure/ux/hitl-validation.d.ts +35 -0
- package/dist/infrastructure/ux/hitl-validation.d.ts.map +1 -1
- package/dist/infrastructure/ux/hitl-validation.js +86 -0
- package/dist/infrastructure/ux/hitl-validation.js.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.d.ts +2 -1
- package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
- package/dist/infrastructure/ux/progress-indicator.js +13 -3
- package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
- package/dist/infrastructure/ux/proportional-friction.d.ts +73 -0
- package/dist/infrastructure/ux/proportional-friction.d.ts.map +1 -0
- package/dist/infrastructure/ux/proportional-friction.js +200 -0
- package/dist/infrastructure/ux/proportional-friction.js.map +1 -0
- package/dist/infrastructure/validation/agent-feedback.d.ts +115 -0
- package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -0
- package/dist/infrastructure/validation/agent-feedback.js +227 -0
- package/dist/infrastructure/validation/agent-feedback.js.map +1 -0
- package/dist/infrastructure/validation/agent-validation-helper.d.ts +75 -0
- package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -0
- package/dist/infrastructure/validation/agent-validation-helper.js +88 -0
- package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -0
- package/dist/infrastructure/validation/feedback-stats.d.ts +99 -0
- package/dist/infrastructure/validation/feedback-stats.d.ts.map +1 -0
- package/dist/infrastructure/validation/feedback-stats.js +173 -0
- package/dist/infrastructure/validation/feedback-stats.js.map +1 -0
- package/dist/infrastructure/validation/review-handler.d.ts +54 -0
- package/dist/infrastructure/validation/review-handler.d.ts.map +1 -0
- package/dist/infrastructure/validation/review-handler.js +206 -0
- package/dist/infrastructure/validation/review-handler.js.map +1 -0
- package/dist/infrastructure/validation/summary-aggregator.d.ts +42 -0
- package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -0
- package/dist/infrastructure/validation/summary-aggregator.js +156 -0
- package/dist/infrastructure/validation/summary-aggregator.js.map +1 -0
- package/dist/infrastructure/validation/summary-extractor.d.ts +59 -0
- package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -0
- package/dist/infrastructure/validation/summary-extractor.js +102 -0
- package/dist/infrastructure/validation/summary-extractor.js.map +1 -0
- package/dist/infrastructure/validation/trace-summary.d.ts +72 -0
- package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -0
- package/dist/infrastructure/validation/trace-summary.js +371 -0
- package/dist/infrastructure/validation/trace-summary.js.map +1 -0
- package/dist/infrastructure/validation/trust-config.d.ts +27 -0
- package/dist/infrastructure/validation/trust-config.d.ts.map +1 -0
- package/dist/infrastructure/validation/trust-config.js +113 -0
- package/dist/infrastructure/validation/trust-config.js.map +1 -0
- package/dist/infrastructure/xai/attention-visualizer.d.ts +6 -8
- package/dist/infrastructure/xai/attention-visualizer.d.ts.map +1 -1
- package/dist/infrastructure/xai/attention-visualizer.js +6 -8
- package/dist/infrastructure/xai/attention-visualizer.js.map +1 -1
- package/dist/infrastructure/xai/cot-visualizer.d.ts +6 -9
- package/dist/infrastructure/xai/cot-visualizer.d.ts.map +1 -1
- package/dist/infrastructure/xai/cot-visualizer.js +6 -9
- package/dist/infrastructure/xai/cot-visualizer.js.map +1 -1
- package/dist/infrastructure/xai/decision-tree-log.d.ts +6 -10
- package/dist/infrastructure/xai/decision-tree-log.d.ts.map +1 -1
- package/dist/infrastructure/xai/decision-tree-log.js +6 -10
- package/dist/infrastructure/xai/decision-tree-log.js.map +1 -1
- package/dist/infrastructure/xai/interactive-xai.d.ts +6 -8
- package/dist/infrastructure/xai/interactive-xai.d.ts.map +1 -1
- package/dist/infrastructure/xai/interactive-xai.js +6 -8
- package/dist/infrastructure/xai/interactive-xai.js.map +1 -1
- package/dist/infrastructure/xai/uncertainty-quantifier.d.ts +6 -9
- package/dist/infrastructure/xai/uncertainty-quantifier.d.ts.map +1 -1
- package/dist/infrastructure/xai/uncertainty-quantifier.js +6 -9
- package/dist/infrastructure/xai/uncertainty-quantifier.js.map +1 -1
- package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/ask-command.js +84 -2
- package/dist/presentation/cli/commands/ask-command.js.map +1 -1
- package/dist/presentation/cli/commands/docs-command.d.ts +12 -0
- package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/docs-command.js +196 -0
- package/dist/presentation/cli/commands/docs-command.js.map +1 -0
- package/dist/presentation/cli/commands/fix-command.d.ts +8 -0
- package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/fix-command.js +309 -0
- package/dist/presentation/cli/commands/fix-command.js.map +1 -0
- package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/help-command.js +2 -0
- package/dist/presentation/cli/commands/help-command.js.map +1 -1
- 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 +53 -0
- 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 +80 -3
- package/dist/presentation/cli/commands/plan-command.js.map +1 -1
- package/dist/presentation/cli/commands/product-command.d.ts +12 -0
- package/dist/presentation/cli/commands/product-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/product-command.js +188 -0
- package/dist/presentation/cli/commands/product-command.js.map +1 -0
- package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/react-command.js +3 -1
- package/dist/presentation/cli/commands/react-command.js.map +1 -1
- package/dist/presentation/cli/commands/review-command.d.ts +14 -0
- package/dist/presentation/cli/commands/review-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/review-command.js +22 -0
- package/dist/presentation/cli/commands/review-command.js.map +1 -0
- package/dist/presentation/cli/commands/run-command.d.ts +15 -0
- package/dist/presentation/cli/commands/run-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/run-command.js +29 -0
- package/dist/presentation/cli/commands/run-command.js.map +1 -0
- package/dist/presentation/cli/commands/smart-command.d.ts +3 -1
- package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
- package/dist/presentation/cli/commands/smart-command.js +92 -6
- package/dist/presentation/cli/commands/smart-command.js.map +1 -1
- package/dist/presentation/cli/commands/status-command.d.ts +11 -0
- package/dist/presentation/cli/commands/status-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/status-command.js +176 -0
- package/dist/presentation/cli/commands/status-command.js.map +1 -0
- package/dist/presentation/cli/commands/suggest-command.d.ts +13 -0
- package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -0
- package/dist/presentation/cli/commands/suggest-command.js +25 -0
- package/dist/presentation/cli/commands/suggest-command.js.map +1 -0
- package/dist/presentation/cli/error-display.d.ts.map +1 -1
- package/dist/presentation/cli/error-display.js +43 -0
- package/dist/presentation/cli/error-display.js.map +1 -1
- package/dist/session.js +19 -2
- package/dist/session.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +8 -5
- package/dist/ui.js.map +1 -1
- package/package.json +10 -2
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: LocalLLMProvider
|
|
3
|
+
* OpenAI-compatible local LLM provider (Ollama, LM Studio, on-prem gateways)
|
|
4
|
+
*
|
|
5
|
+
* Phase 4E: Local LLM Provider Implementation
|
|
6
|
+
* Supports any OpenAI-compatible endpoint for chat and embeddings
|
|
7
|
+
*/
|
|
8
|
+
import { retryWithBackoff } from '../../error-handler.js';
|
|
9
|
+
import { encoding_for_model } from 'tiktoken';
|
|
10
|
+
// Token counting (tiktoken for OpenAI-compatible models)
|
|
11
|
+
let tokenEncoder = null;
|
|
12
|
+
function getTokenEncoder() {
|
|
13
|
+
if (!tokenEncoder) {
|
|
14
|
+
try {
|
|
15
|
+
tokenEncoder = encoding_for_model('gpt-3.5-turbo'); // OpenAI-compatible encoding
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
tokenEncoder = encoding_for_model('gpt-4'); // Fallback
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return tokenEncoder;
|
|
22
|
+
}
|
|
23
|
+
function countTokens(text) {
|
|
24
|
+
try {
|
|
25
|
+
const encoder = getTokenEncoder();
|
|
26
|
+
return encoder.encode(text).length;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn('Warning: tiktoken failed for LocalLLMProvider, using character-based estimate (less accurate)');
|
|
30
|
+
return Math.ceil(text.length / 4);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* LocalLLMProvider
|
|
35
|
+
* Implements IModelProvider for OpenAI-compatible local endpoints
|
|
36
|
+
*
|
|
37
|
+
* Designed for:
|
|
38
|
+
* - Ollama (http://localhost:11434)
|
|
39
|
+
* - LM Studio (http://localhost:1234)
|
|
40
|
+
* - On-prem OpenAI-compatible gateways
|
|
41
|
+
*
|
|
42
|
+
* API Assumptions:
|
|
43
|
+
* - POST {baseUrl}/v1/chat/completions (OpenAI-compatible)
|
|
44
|
+
* - POST {baseUrl}/v1/embeddings (OpenAI-compatible)
|
|
45
|
+
* - Streaming via Server-Sent Events (SSE) if supported
|
|
46
|
+
*/
|
|
47
|
+
export class LocalLLMProvider {
|
|
48
|
+
id = 'local';
|
|
49
|
+
name = 'Local LLM Provider';
|
|
50
|
+
capabilities = {
|
|
51
|
+
chat: true,
|
|
52
|
+
streaming: true, // Assume streaming is supported (will gracefully fall back if not)
|
|
53
|
+
embedding: true,
|
|
54
|
+
embeddingQuery: false, // Local LLMs typically don't have separate query embeddings
|
|
55
|
+
rerank: false, // Local LLMs typically don't have rerank
|
|
56
|
+
toolCalling: false, // Not supported initially
|
|
57
|
+
};
|
|
58
|
+
baseUrl;
|
|
59
|
+
defaultChatModel;
|
|
60
|
+
defaultEmbedModel;
|
|
61
|
+
constructor(baseUrl, defaultChatModel, defaultEmbedModel) {
|
|
62
|
+
this.baseUrl = baseUrl || process.env.CODEHERE_LOCAL_BASE_URL || '';
|
|
63
|
+
if (!this.baseUrl) {
|
|
64
|
+
throw new Error('CODEHERE_LOCAL_BASE_URL not found in environment for LocalLLMProvider initialization.');
|
|
65
|
+
}
|
|
66
|
+
// Remove trailing slash if present
|
|
67
|
+
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
68
|
+
this.defaultChatModel = defaultChatModel || process.env.CODEHERE_LOCAL_MODEL || 'local-default';
|
|
69
|
+
this.defaultEmbedModel = defaultEmbedModel || process.env.CODEHERE_LOCAL_EMBED_MODEL || this.defaultChatModel;
|
|
70
|
+
}
|
|
71
|
+
async getModels() {
|
|
72
|
+
// Return a basic model info for the configured model
|
|
73
|
+
// In the future, could query the local endpoint for available models
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
id: this.defaultChatModel,
|
|
77
|
+
name: `Local Model: ${this.defaultChatModel}`,
|
|
78
|
+
providerId: this.id,
|
|
79
|
+
providerModelId: this.defaultChatModel,
|
|
80
|
+
contextWindow: 4096, // Conservative default, actual may vary
|
|
81
|
+
capabilities: { ...this.capabilities },
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
getDefaultModel() {
|
|
86
|
+
return this.defaultChatModel;
|
|
87
|
+
}
|
|
88
|
+
async chat(prompt, options) {
|
|
89
|
+
const model = options?.model || this.defaultChatModel;
|
|
90
|
+
return await retryWithBackoff(async () => {
|
|
91
|
+
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/json',
|
|
95
|
+
},
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
model,
|
|
98
|
+
messages: [{ role: 'user', content: prompt }],
|
|
99
|
+
temperature: options?.temperature ?? 0.7,
|
|
100
|
+
max_tokens: options?.maxTokens,
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
const errorText = await response.text();
|
|
105
|
+
let errorMessage = `Local LLM API error: ${response.status} ${errorText}`;
|
|
106
|
+
try {
|
|
107
|
+
const errorJson = JSON.parse(errorText);
|
|
108
|
+
errorMessage = errorJson.error?.message || errorMessage;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// ignore
|
|
112
|
+
}
|
|
113
|
+
throw new Error(errorMessage);
|
|
114
|
+
}
|
|
115
|
+
const data = await response.json();
|
|
116
|
+
const text = data.choices?.[0]?.message?.content || 'No response generated';
|
|
117
|
+
const usage = data.usage || {};
|
|
118
|
+
return {
|
|
119
|
+
text,
|
|
120
|
+
model: data.model || model,
|
|
121
|
+
usage: {
|
|
122
|
+
inputTokens: usage.prompt_tokens || countTokens(prompt),
|
|
123
|
+
outputTokens: usage.completion_tokens || countTokens(text),
|
|
124
|
+
},
|
|
125
|
+
finishReason: data.choices?.[0]?.finish_reason,
|
|
126
|
+
};
|
|
127
|
+
}, {
|
|
128
|
+
maxRetries: 3, // Fewer retries for local endpoints
|
|
129
|
+
baseDelay: 1000,
|
|
130
|
+
maxDelay: 5000,
|
|
131
|
+
operationName: 'local-llm-provider-chat',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async chatStream(prompt, options, onEvent) {
|
|
135
|
+
const model = options?.model || this.defaultChatModel;
|
|
136
|
+
let fullText = '';
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: {
|
|
141
|
+
'Content-Type': 'application/json',
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify({
|
|
144
|
+
model,
|
|
145
|
+
messages: [{ role: 'user', content: prompt }],
|
|
146
|
+
temperature: options?.temperature ?? 0.7,
|
|
147
|
+
max_tokens: options?.maxTokens,
|
|
148
|
+
stream: true,
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
151
|
+
if (!response.ok || !response.body) {
|
|
152
|
+
const errorText = await response.text();
|
|
153
|
+
let errorMessage = `Local LLM API error: ${response.status} ${errorText}`;
|
|
154
|
+
try {
|
|
155
|
+
const errorJson = JSON.parse(errorText);
|
|
156
|
+
errorMessage = errorJson.error?.message || errorMessage;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// ignore
|
|
160
|
+
}
|
|
161
|
+
if (onEvent) {
|
|
162
|
+
onEvent({ type: 'error', error: new Error(errorMessage) });
|
|
163
|
+
}
|
|
164
|
+
throw new Error(errorMessage);
|
|
165
|
+
}
|
|
166
|
+
if (onEvent) {
|
|
167
|
+
onEvent({ type: 'start' });
|
|
168
|
+
}
|
|
169
|
+
const reader = response.body.getReader();
|
|
170
|
+
const decoder = new TextDecoder('utf-8');
|
|
171
|
+
while (true) {
|
|
172
|
+
const { done, value } = await reader.read();
|
|
173
|
+
if (done)
|
|
174
|
+
break;
|
|
175
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
176
|
+
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
177
|
+
for (const line of lines) {
|
|
178
|
+
if (line.startsWith('data: ')) {
|
|
179
|
+
const data = line.substring(6);
|
|
180
|
+
if (data === '[DONE]') {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const json = JSON.parse(data);
|
|
185
|
+
const delta = json.choices?.[0]?.delta?.content;
|
|
186
|
+
if (delta) {
|
|
187
|
+
fullText += delta;
|
|
188
|
+
if (onEvent) {
|
|
189
|
+
onEvent({ type: 'delta', text: delta });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
// Ignore parse errors for malformed SSE chunks
|
|
195
|
+
console.warn('Error parsing stream chunk:', e);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (onEvent) {
|
|
201
|
+
onEvent({ type: 'complete', text: fullText });
|
|
202
|
+
}
|
|
203
|
+
const inputTokens = await this.countTokens(prompt, model);
|
|
204
|
+
const outputTokens = await this.countTokens(fullText, model);
|
|
205
|
+
return {
|
|
206
|
+
text: fullText,
|
|
207
|
+
model: model,
|
|
208
|
+
usage: {
|
|
209
|
+
inputTokens,
|
|
210
|
+
outputTokens,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (onEvent) {
|
|
216
|
+
onEvent({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async embed(text) {
|
|
222
|
+
const texts = Array.isArray(text) ? text : [text];
|
|
223
|
+
const model = this.defaultEmbedModel;
|
|
224
|
+
return await retryWithBackoff(async () => {
|
|
225
|
+
const response = await fetch(`${this.baseUrl}/v1/embeddings`, {
|
|
226
|
+
method: 'POST',
|
|
227
|
+
headers: {
|
|
228
|
+
'Content-Type': 'application/json',
|
|
229
|
+
},
|
|
230
|
+
body: JSON.stringify({
|
|
231
|
+
model,
|
|
232
|
+
input: texts,
|
|
233
|
+
}),
|
|
234
|
+
});
|
|
235
|
+
if (!response.ok) {
|
|
236
|
+
const errorText = await response.text();
|
|
237
|
+
throw new Error(`Local LLM API error: ${response.status} ${errorText}`);
|
|
238
|
+
}
|
|
239
|
+
const data = await response.json();
|
|
240
|
+
const embeddings = data.data?.map((item) => item.embedding) || [];
|
|
241
|
+
if (texts.length === 1) {
|
|
242
|
+
return embeddings[0];
|
|
243
|
+
}
|
|
244
|
+
return embeddings;
|
|
245
|
+
}, {
|
|
246
|
+
maxRetries: 3,
|
|
247
|
+
baseDelay: 1000,
|
|
248
|
+
maxDelay: 5000,
|
|
249
|
+
operationName: 'local-llm-provider-embed',
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
async embedQuery(query) {
|
|
253
|
+
// Local LLMs typically don't have separate query embeddings
|
|
254
|
+
// Fall back to regular embed
|
|
255
|
+
const result = await this.embed(query);
|
|
256
|
+
return Array.isArray(result[0]) ? result[0] : result;
|
|
257
|
+
}
|
|
258
|
+
rerank(_query, _documents, _options) {
|
|
259
|
+
// Local LLMs typically don't have rerank
|
|
260
|
+
// ProviderAIService will handle this gracefully by falling back to original order
|
|
261
|
+
throw new Error('LocalLLMProvider does not support rerank directly.');
|
|
262
|
+
}
|
|
263
|
+
async countTokens(text, _model) {
|
|
264
|
+
return Promise.resolve(countTokens(text));
|
|
265
|
+
}
|
|
266
|
+
async isAvailable() {
|
|
267
|
+
try {
|
|
268
|
+
// Simple availability check - try to list models or health check
|
|
269
|
+
// Many local endpoints have a /v1/models endpoint
|
|
270
|
+
const response = await fetch(`${this.baseUrl}/v1/models`, {
|
|
271
|
+
method: 'GET',
|
|
272
|
+
});
|
|
273
|
+
return response.ok;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// If /v1/models doesn't exist, try a simple chat completion check
|
|
277
|
+
try {
|
|
278
|
+
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
279
|
+
method: 'POST',
|
|
280
|
+
headers: {
|
|
281
|
+
'Content-Type': 'application/json',
|
|
282
|
+
},
|
|
283
|
+
body: JSON.stringify({
|
|
284
|
+
model: this.defaultChatModel,
|
|
285
|
+
messages: [{ role: 'user', content: 'test' }],
|
|
286
|
+
max_tokens: 1,
|
|
287
|
+
}),
|
|
288
|
+
});
|
|
289
|
+
return response.ok;
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
handleError(error) {
|
|
297
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
298
|
+
// Network errors (connection refused, timeout)
|
|
299
|
+
if (errorMessage.includes('network') || errorMessage.includes('timeout') || errorMessage.includes('ECONNREFUSED') || errorMessage.includes('fetch failed')) {
|
|
300
|
+
return {
|
|
301
|
+
type: 'network_error',
|
|
302
|
+
retryable: true,
|
|
303
|
+
message: 'Network error connecting to local LLM endpoint',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// Invalid request (400, 404, etc.)
|
|
307
|
+
if (errorMessage.includes('400') || errorMessage.includes('404') || errorMessage.includes('invalid_request_error')) {
|
|
308
|
+
return {
|
|
309
|
+
type: 'invalid_request',
|
|
310
|
+
retryable: false,
|
|
311
|
+
message: 'Invalid request to local LLM API',
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
// Server errors (500, 502, 503)
|
|
315
|
+
if (errorMessage.includes('500') || errorMessage.includes('502') || errorMessage.includes('503')) {
|
|
316
|
+
return {
|
|
317
|
+
type: 'server_error',
|
|
318
|
+
retryable: true,
|
|
319
|
+
message: 'Local LLM server error',
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
// Default to unknown and retryable
|
|
323
|
+
return {
|
|
324
|
+
type: 'unknown',
|
|
325
|
+
retryable: true,
|
|
326
|
+
message: errorMessage,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=local-llm-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-llm-provider.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/local-llm-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAAE,gBAAgB,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f,OAAO,EAAE,YAAY;SACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: Model Configuration Types
|
|
3
|
+
* Provider-agnostic model configuration structures
|
|
4
|
+
*
|
|
5
|
+
* Phase 4A: Foundation Implementation (No Behavior Change)
|
|
6
|
+
* Minimal types for internal use only - no CLI/config file changes yet
|
|
7
|
+
*/
|
|
8
|
+
import type { ProviderCapabilities } from './model-provider.interface.js';
|
|
9
|
+
/**
|
|
10
|
+
* Provider model configuration
|
|
11
|
+
*/
|
|
12
|
+
export interface ProviderModelConfig {
|
|
13
|
+
id: string;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
defaultModel?: string;
|
|
18
|
+
models: {
|
|
19
|
+
[modelId: string]: {
|
|
20
|
+
providerModelId: string;
|
|
21
|
+
contextWindow: number;
|
|
22
|
+
capabilities: ProviderCapabilities;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Operation-specific provider selection
|
|
28
|
+
*/
|
|
29
|
+
export interface OperationProviderConfig {
|
|
30
|
+
chat?: string;
|
|
31
|
+
embedding?: string;
|
|
32
|
+
rerank?: string;
|
|
33
|
+
default?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Enhanced model configuration
|
|
37
|
+
*
|
|
38
|
+
* Phase 4A: Types only - not yet wired into config files
|
|
39
|
+
*/
|
|
40
|
+
export interface ModelConfig {
|
|
41
|
+
/** Default provider selection */
|
|
42
|
+
defaultProvider: string;
|
|
43
|
+
/** Operation-specific provider selection */
|
|
44
|
+
operationProviders?: OperationProviderConfig;
|
|
45
|
+
/** Provider configurations */
|
|
46
|
+
providers: {
|
|
47
|
+
[providerId: string]: ProviderModelConfig;
|
|
48
|
+
};
|
|
49
|
+
/** Fallback provider chain (for future) */
|
|
50
|
+
fallbackProviders?: string[];
|
|
51
|
+
/** Model selection per use case (for future) */
|
|
52
|
+
useCaseModels?: {
|
|
53
|
+
planning?: string;
|
|
54
|
+
chat?: string;
|
|
55
|
+
reasoning?: string;
|
|
56
|
+
default?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Minimal provider configuration for Phase 4A
|
|
61
|
+
* Internal use only - not yet exposed to users
|
|
62
|
+
*/
|
|
63
|
+
export interface MinimalProviderConfig {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
apiKey?: string;
|
|
67
|
+
baseUrl?: string;
|
|
68
|
+
defaultModel?: string;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=model-config.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-config.types.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/model-config.types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE;QACN,CAAC,OAAO,EAAE,MAAM,GAAG;YACjB,eAAe,EAAE,MAAM,CAAC;YACxB,aAAa,EAAE,MAAM,CAAC;YACtB,YAAY,EAAE,oBAAoB,CAAC;SACpC,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IAExB,4CAA4C;IAC5C,kBAAkB,CAAC,EAAE,uBAAuB,CAAC;IAE7C,8BAA8B;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CAAC;KAC3C,CAAC;IAEF,2CAA2C;IAC3C,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,gDAAgD;IAChD,aAAa,CAAC,EAAE;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: Model Configuration Types
|
|
3
|
+
* Provider-agnostic model configuration structures
|
|
4
|
+
*
|
|
5
|
+
* Phase 4A: Foundation Implementation (No Behavior Change)
|
|
6
|
+
* Minimal types for internal use only - no CLI/config file changes yet
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=model-config.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-config.types.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/model-config.types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: IModelProvider Interface
|
|
3
|
+
* Core abstraction for any AI model provider
|
|
4
|
+
*
|
|
5
|
+
* Phase 4A: Foundation Implementation (No Behavior Change)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Core provider capabilities
|
|
9
|
+
*/
|
|
10
|
+
export interface ProviderCapabilities {
|
|
11
|
+
chat: boolean;
|
|
12
|
+
streaming: boolean;
|
|
13
|
+
embedding: boolean;
|
|
14
|
+
embeddingQuery: boolean;
|
|
15
|
+
rerank: boolean;
|
|
16
|
+
toolCalling: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Model information
|
|
20
|
+
*/
|
|
21
|
+
export interface ModelInfo {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
providerId: string;
|
|
25
|
+
providerModelId: string;
|
|
26
|
+
contextWindow: number;
|
|
27
|
+
capabilities: ProviderCapabilities;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Chat options
|
|
31
|
+
*/
|
|
32
|
+
export interface ChatOptions {
|
|
33
|
+
temperature?: number;
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
model?: string;
|
|
36
|
+
stream?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Chat response
|
|
40
|
+
*/
|
|
41
|
+
export interface ChatResponse {
|
|
42
|
+
text: string;
|
|
43
|
+
model: string;
|
|
44
|
+
usage?: {
|
|
45
|
+
inputTokens: number;
|
|
46
|
+
outputTokens: number;
|
|
47
|
+
};
|
|
48
|
+
finishReason?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Streaming event
|
|
52
|
+
*/
|
|
53
|
+
export interface StreamEvent {
|
|
54
|
+
type: 'start' | 'delta' | 'complete' | 'error';
|
|
55
|
+
text?: string;
|
|
56
|
+
error?: Error;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Rerank result
|
|
60
|
+
*/
|
|
61
|
+
export interface RerankResult {
|
|
62
|
+
index: number;
|
|
63
|
+
relevanceScore: number;
|
|
64
|
+
text?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Rerank response
|
|
68
|
+
*/
|
|
69
|
+
export interface RerankResponse {
|
|
70
|
+
results: RerankResult[];
|
|
71
|
+
model: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Core provider interface
|
|
75
|
+
*
|
|
76
|
+
* Phase 4A: Minimal implementation - wraps existing CohereAIService behavior
|
|
77
|
+
*/
|
|
78
|
+
export interface IModelProvider {
|
|
79
|
+
/** Provider identifier */
|
|
80
|
+
readonly id: string;
|
|
81
|
+
/** Provider display name */
|
|
82
|
+
readonly name: string;
|
|
83
|
+
/** Provider capabilities */
|
|
84
|
+
readonly capabilities: ProviderCapabilities;
|
|
85
|
+
/** Available models */
|
|
86
|
+
getModels(): Promise<ModelInfo[]>;
|
|
87
|
+
/** Get default model */
|
|
88
|
+
getDefaultModel(): string;
|
|
89
|
+
/** Chat completion */
|
|
90
|
+
chat(prompt: string, options?: ChatOptions): Promise<ChatResponse>;
|
|
91
|
+
/** Streaming chat completion */
|
|
92
|
+
chatStream?(prompt: string, options?: ChatOptions, onEvent?: (event: StreamEvent) => void): Promise<ChatResponse>;
|
|
93
|
+
/** Generate embeddings (documents) */
|
|
94
|
+
embed(text: string | string[]): Promise<number[] | number[][]>;
|
|
95
|
+
/** Generate query embedding (optional, provider-specific) */
|
|
96
|
+
embedQuery?(query: string): Promise<number[]>;
|
|
97
|
+
/** Rerank documents (optional) */
|
|
98
|
+
rerank?(query: string, documents: string[], options?: {
|
|
99
|
+
topN?: number;
|
|
100
|
+
model?: string;
|
|
101
|
+
}): Promise<RerankResponse>;
|
|
102
|
+
/** Count tokens (provider-specific tokenizer) */
|
|
103
|
+
countTokens(text: string, model?: string): Promise<number>;
|
|
104
|
+
/** Check if provider is available */
|
|
105
|
+
isAvailable(): Promise<boolean>;
|
|
106
|
+
/** Get provider-specific error handler (optional) */
|
|
107
|
+
handleError?(error: unknown): {
|
|
108
|
+
type: string;
|
|
109
|
+
retryable: boolean;
|
|
110
|
+
message: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=model-provider.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-provider.interface.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/model-provider.interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,oBAAoB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAGlB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IAC/C,IA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AM,EACb,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1C,OAAO,CAAC,cAAc,CAAC,CAAC;IAE3B,iDAAiD;IACjD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D,qCAAqC;IACrC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC,qDAAqD;IACrD,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-provider.interface.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/model-provider.interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Layer: OpenAIProvider
|
|
3
|
+
* Implements IModelProvider for OpenAI API
|
|
4
|
+
*
|
|
5
|
+
* Phase 4C: OpenAI Provider Implementation
|
|
6
|
+
*
|
|
7
|
+
* Uses OpenAI REST API directly (no SDK dependency) to keep dependencies minimal.
|
|
8
|
+
* Supports GPT-4, GPT-3.5, and text-embedding models.
|
|
9
|
+
*/
|
|
10
|
+
import type { IModelProvider, ProviderCapabilities, ModelInfo, ChatOptions, ChatResponse, StreamEvent } from './model-provider.interface.js';
|
|
11
|
+
/**
|
|
12
|
+
* OpenAI Provider
|
|
13
|
+
* Implements IModelProvider using OpenAI REST API
|
|
14
|
+
*/
|
|
15
|
+
export declare class OpenAIProvider implements IModelProvider {
|
|
16
|
+
readonly id = "openai";
|
|
17
|
+
readonly name = "OpenAI";
|
|
18
|
+
readonly capabilities: ProviderCapabilities;
|
|
19
|
+
private apiKey;
|
|
20
|
+
private baseUrl;
|
|
21
|
+
private defaultChatModel;
|
|
22
|
+
private defaultEmbedModel;
|
|
23
|
+
constructor(apiKey?: string, baseUrl?: string);
|
|
24
|
+
getModels(): Promise<ModelInfo[]>;
|
|
25
|
+
getDefaultModel(): string;
|
|
26
|
+
chat(prompt: string, options?: ChatOptions): Promise<ChatResponse>;
|
|
27
|
+
chatStream(prompt: string, options?: ChatOptions, onEvent?: (event: StreamEvent) => void): Promise<ChatResponse>;
|
|
28
|
+
embed(text: string | string[]): Promise<number[] | number[][]>;
|
|
29
|
+
embedQuery(query: string): Promise<number[]>;
|
|
30
|
+
countTokens(text: string, _model?: string): Promise<number>;
|
|
31
|
+
isAvailable(): Promise<boolean>;
|
|
32
|
+
handleError?(error: unknown): {
|
|
33
|
+
type: string;
|
|
34
|
+
retryable: boolean;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=openai-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/openai-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EAEZ,MAAM,+BAA+B,CAAC;AAmCvC;;;GAGG;AACH,qBAAa,cAAe,YAAW,cAAc;IACnD,QAAQ,CAAC,EAAE,YAAY;IACvB,QAAQ,CAAC,IAAI,YAAY;IAEzB,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAOzC;IAEF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,MAAM,CAAC,EAAE,MAAM,EAAE,O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