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.

Files changed (297) hide show
  1. package/README.md +223 -42
  2. package/dist/application/agents/documentation-agent.d.ts +24 -0
  3. package/dist/application/agents/documentation-agent.d.ts.map +1 -0
  4. package/dist/application/agents/documentation-agent.js +399 -0
  5. package/dist/application/agents/documentation-agent.js.map +1 -0
  6. package/dist/application/agents/execution-agent.d.ts +11 -0
  7. package/dist/application/agents/execution-agent.d.ts.map +1 -1
  8. package/dist/application/agents/execution-agent.js +289 -80
  9. package/dist/application/agents/execution-agent.js.map +1 -1
  10. package/dist/application/agents/multi-agent-orchestrator.d.ts +3 -0
  11. package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
  12. package/dist/application/agents/multi-agent-orchestrator.js +86 -0
  13. package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
  14. package/dist/application/agents/planning-agent.d.ts +3 -0
  15. package/dist/application/agents/planning-agent.d.ts.map +1 -1
  16. package/dist/application/agents/planning-agent.js +132 -64
  17. package/dist/application/agents/planning-agent.js.map +1 -1
  18. package/dist/application/agents/product-requirements-agent.d.ts +21 -0
  19. package/dist/application/agents/product-requirements-agent.d.ts.map +1 -0
  20. package/dist/application/agents/product-requirements-agent.js +247 -0
  21. package/dist/application/agents/product-requirements-agent.js.map +1 -0
  22. package/dist/application/agents/validation-agent.d.ts +5 -1
  23. package/dist/application/agents/validation-agent.d.ts.map +1 -1
  24. package/dist/application/agents/validation-agent.js +156 -21
  25. package/dist/application/agents/validation-agent.js.map +1 -1
  26. package/dist/application/services/dependency-container.d.ts +22 -2
  27. package/dist/application/services/dependency-container.d.ts.map +1 -1
  28. package/dist/application/services/dependency-container.js +144 -6
  29. package/dist/application/services/dependency-container.js.map +1 -1
  30. package/dist/application/services/intelligent-router.d.ts +13 -0
  31. package/dist/application/services/intelligent-router.d.ts.map +1 -1
  32. package/dist/application/services/intelligent-router.js +300 -87
  33. package/dist/application/services/intelligent-router.js.map +1 -1
  34. package/dist/application/use-cases/ask-question-use-case.d.ts +19 -0
  35. package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -1
  36. package/dist/application/use-cases/ask-question-use-case.js +125 -46
  37. package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
  38. package/dist/application/use-cases/edit-file-use-case.d.ts.map +1 -1
  39. package/dist/application/use-cases/edit-file-use-case.js +16 -1
  40. package/dist/application/use-cases/edit-file-use-case.js.map +1 -1
  41. package/dist/domain/entities/documentation.d.ts +35 -0
  42. package/dist/domain/entities/documentation.d.ts.map +1 -0
  43. package/dist/domain/entities/documentation.js +6 -0
  44. package/dist/domain/entities/documentation.js.map +1 -0
  45. package/dist/domain/entities/product-requirements.d.ts +50 -0
  46. package/dist/domain/entities/product-requirements.d.ts.map +1 -0
  47. package/dist/domain/entities/product-requirements.js +6 -0
  48. package/dist/domain/entities/product-requirements.js.map +1 -0
  49. package/dist/domain/entities/task.d.ts +152 -0
  50. package/dist/domain/entities/task.d.ts.map +1 -0
  51. package/dist/domain/entities/task.js +61 -0
  52. package/dist/domain/entities/task.js.map +1 -0
  53. package/dist/domain/interfaces/agent.interface.d.ts +15 -0
  54. package/dist/domain/interfaces/agent.interface.d.ts.map +1 -0
  55. package/dist/domain/interfaces/agent.interface.js +6 -0
  56. package/dist/domain/interfaces/agent.interface.js.map +1 -0
  57. package/dist/domain/services/environment-mode-manager.d.ts +18 -0
  58. package/dist/domain/services/environment-mode-manager.d.ts.map +1 -0
  59. package/dist/domain/services/environment-mode-manager.js +37 -0
  60. package/dist/domain/services/environment-mode-manager.js.map +1 -0
  61. package/dist/domain/services/risk-tier-detector.d.ts +18 -0
  62. package/dist/domain/services/risk-tier-detector.d.ts.map +1 -0
  63. package/dist/domain/services/risk-tier-detector.js +65 -0
  64. package/dist/domain/services/risk-tier-detector.js.map +1 -0
  65. package/dist/formatter.d.ts.map +1 -1
  66. package/dist/formatter.js +10 -3
  67. package/dist/formatter.js.map +1 -1
  68. package/dist/index.js +103 -129
  69. package/dist/index.js.map +1 -1
  70. package/dist/infrastructure/ai/cohere-ai-service.d.ts.map +1 -1
  71. package/dist/infrastructure/ai/cohere-ai-service.js +15 -2
  72. package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
  73. package/dist/infrastructure/ai/fake-ai-service.d.ts +22 -0
  74. package/dist/infrastructure/ai/fake-ai-service.d.ts.map +1 -0
  75. package/dist/infrastructure/ai/fake-ai-service.js +59 -0
  76. package/dist/infrastructure/ai/fake-ai-service.js.map +1 -0
  77. package/dist/infrastructure/ai/provider-ai-service.d.ts +59 -0
  78. package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -0
  79. package/dist/infrastructure/ai/provider-ai-service.js +477 -0
  80. package/dist/infrastructure/ai/provider-ai-service.js.map +1 -0
  81. package/dist/infrastructure/cache/embedding-cache.d.ts +13 -1
  82. package/dist/infrastructure/cache/embedding-cache.d.ts.map +1 -1
  83. package/dist/infrastructure/cache/embedding-cache.js +80 -9
  84. package/dist/infrastructure/cache/embedding-cache.js.map +1 -1
  85. package/dist/infrastructure/cache/response-cache.d.ts +86 -0
  86. package/dist/infrastructure/cache/response-cache.d.ts.map +1 -0
  87. package/dist/infrastructure/cache/response-cache.js +224 -0
  88. package/dist/infrastructure/cache/response-cache.js.map +1 -0
  89. package/dist/infrastructure/context/conversation-context.d.ts +58 -0
  90. package/dist/infrastructure/context/conversation-context.d.ts.map +1 -0
  91. package/dist/infrastructure/context/conversation-context.js +170 -0
  92. package/dist/infrastructure/context/conversation-context.js.map +1 -0
  93. package/dist/infrastructure/context/session-manager.d.ts +26 -0
  94. package/dist/infrastructure/context/session-manager.d.ts.map +1 -0
  95. package/dist/infrastructure/context/session-manager.js +98 -0
  96. package/dist/infrastructure/context/session-manager.js.map +1 -0
  97. package/dist/infrastructure/cost/cost-tracker.d.ts +1 -0
  98. package/dist/infrastructure/cost/cost-tracker.d.ts.map +1 -1
  99. package/dist/infrastructure/cost/cost-tracker.js +12 -5
  100. package/dist/infrastructure/cost/cost-tracker.js.map +1 -1
  101. package/dist/infrastructure/governance/nist-ai-rmf.d.ts +6 -8
  102. package/dist/infrastructure/governance/nist-ai-rmf.d.ts.map +1 -1
  103. package/dist/infrastructure/governance/nist-ai-rmf.js +6 -8
  104. package/dist/infrastructure/governance/nist-ai-rmf.js.map +1 -1
  105. package/dist/infrastructure/governance/policy-as-code.d.ts +6 -8
  106. package/dist/infrastructure/governance/policy-as-code.d.ts.map +1 -1
  107. package/dist/infrastructure/governance/policy-as-code.js +6 -8
  108. package/dist/infrastructure/governance/policy-as-code.js.map +1 -1
  109. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts +7 -9
  110. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts.map +1 -1
  111. package/dist/infrastructure/governance/prompt-to-code-lineage.js +7 -9
  112. package/dist/infrastructure/governance/prompt-to-code-lineage.js.map +1 -1
  113. package/dist/infrastructure/providers/cohere-provider.d.ts +39 -0
  114. package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -0
  115. package/dist/infrastructure/providers/cohere-provider.js +359 -0
  116. package/dist/infrastructure/providers/cohere-provider.js.map +1 -0
  117. package/dist/infrastructure/providers/fake-provider.d.ts +43 -0
  118. package/dist/infrastructure/providers/fake-provider.d.ts.map +1 -0
  119. package/dist/infrastructure/providers/fake-provider.js +130 -0
  120. package/dist/infrastructure/providers/fake-provider.js.map +1 -0
  121. package/dist/infrastructure/providers/local-llm-provider.d.ts +49 -0
  122. package/dist/infrastructure/providers/local-llm-provider.d.ts.map +1 -0
  123. package/dist/infrastructure/providers/local-llm-provider.js +330 -0
  124. package/dist/infrastructure/providers/local-llm-provider.js.map +1 -0
  125. package/dist/infrastructure/providers/model-config.types.d.ts +70 -0
  126. package/dist/infrastructure/providers/model-config.types.d.ts.map +1 -0
  127. package/dist/infrastructure/providers/model-config.types.js +9 -0
  128. package/dist/infrastructure/providers/model-config.types.js.map +1 -0
  129. package/dist/infrastructure/providers/model-provider.interface.d.ts +113 -0
  130. package/dist/infrastructure/providers/model-provider.interface.d.ts.map +1 -0
  131. package/dist/infrastructure/providers/model-provider.interface.js +8 -0
  132. package/dist/infrastructure/providers/model-provider.interface.js.map +1 -0
  133. package/dist/infrastructure/providers/openai-provider.d.ts +38 -0
  134. package/dist/infrastructure/providers/openai-provider.d.ts.map +1 -0
  135. package/dist/infrastructure/providers/openai-provider.js +413 -0
  136. package/dist/infrastructure/providers/openai-provider.js.map +1 -0
  137. package/dist/infrastructure/providers/operation-provider-resolver.d.ts +48 -0
  138. package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -0
  139. package/dist/infrastructure/providers/operation-provider-resolver.js +105 -0
  140. package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -0
  141. package/dist/infrastructure/providers/provider-config-loader.d.ts +37 -0
  142. package/dist/infrastructure/providers/provider-config-loader.d.ts.map +1 -0
  143. package/dist/infrastructure/providers/provider-config-loader.js +120 -0
  144. package/dist/infrastructure/providers/provider-config-loader.js.map +1 -0
  145. package/dist/infrastructure/providers/provider-registry.d.ts +53 -0
  146. package/dist/infrastructure/providers/provider-registry.d.ts.map +1 -0
  147. package/dist/infrastructure/providers/provider-registry.js +88 -0
  148. package/dist/infrastructure/providers/provider-registry.js.map +1 -0
  149. package/dist/infrastructure/storage/task-helpers.d.ts +58 -0
  150. package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -0
  151. package/dist/infrastructure/storage/task-helpers.js +157 -0
  152. package/dist/infrastructure/storage/task-helpers.js.map +1 -0
  153. package/dist/infrastructure/storage/task-repository.d.ts +67 -0
  154. package/dist/infrastructure/storage/task-repository.d.ts.map +1 -0
  155. package/dist/infrastructure/storage/task-repository.js +205 -0
  156. package/dist/infrastructure/storage/task-repository.js.map +1 -0
  157. package/dist/infrastructure/ux/bi-directional-learning.d.ts +22 -0
  158. package/dist/infrastructure/ux/bi-directional-learning.d.ts.map +1 -1
  159. package/dist/infrastructure/ux/bi-directional-learning.js +144 -7
  160. package/dist/infrastructure/ux/bi-directional-learning.js.map +1 -1
  161. package/dist/infrastructure/ux/capability-boundaries.d.ts +50 -0
  162. package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -0
  163. package/dist/infrastructure/ux/capability-boundaries.js +167 -0
  164. package/dist/infrastructure/ux/capability-boundaries.js.map +1 -0
  165. package/dist/infrastructure/ux/comprehensive-formatter.d.ts +63 -0
  166. package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -0
  167. package/dist/infrastructure/ux/comprehensive-formatter.js +212 -0
  168. package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -0
  169. package/dist/infrastructure/ux/feedback-prompt.d.ts +42 -0
  170. package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -0
  171. package/dist/infrastructure/ux/feedback-prompt.js +181 -0
  172. package/dist/infrastructure/ux/feedback-prompt.js.map +1 -0
  173. package/dist/infrastructure/ux/hitl-review-portal.d.ts.map +1 -1
  174. package/dist/infrastructure/ux/hitl-review-portal.js +4 -1
  175. package/dist/infrastructure/ux/hitl-review-portal.js.map +1 -1
  176. package/dist/infrastructure/ux/hitl-validation.d.ts +35 -0
  177. package/dist/infrastructure/ux/hitl-validation.d.ts.map +1 -1
  178. package/dist/infrastructure/ux/hitl-validation.js +86 -0
  179. package/dist/infrastructure/ux/hitl-validation.js.map +1 -1
  180. package/dist/infrastructure/ux/progress-indicator.d.ts +2 -1
  181. package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
  182. package/dist/infrastructure/ux/progress-indicator.js +13 -3
  183. package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
  184. package/dist/infrastructure/ux/proportional-friction.d.ts +73 -0
  185. package/dist/infrastructure/ux/proportional-friction.d.ts.map +1 -0
  186. package/dist/infrastructure/ux/proportional-friction.js +200 -0
  187. package/dist/infrastructure/ux/proportional-friction.js.map +1 -0
  188. package/dist/infrastructure/validation/agent-feedback.d.ts +115 -0
  189. package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -0
  190. package/dist/infrastructure/validation/agent-feedback.js +227 -0
  191. package/dist/infrastructure/validation/agent-feedback.js.map +1 -0
  192. package/dist/infrastructure/validation/agent-validation-helper.d.ts +75 -0
  193. package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -0
  194. package/dist/infrastructure/validation/agent-validation-helper.js +88 -0
  195. package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -0
  196. package/dist/infrastructure/validation/feedback-stats.d.ts +99 -0
  197. package/dist/infrastructure/validation/feedback-stats.d.ts.map +1 -0
  198. package/dist/infrastructure/validation/feedback-stats.js +173 -0
  199. package/dist/infrastructure/validation/feedback-stats.js.map +1 -0
  200. package/dist/infrastructure/validation/review-handler.d.ts +54 -0
  201. package/dist/infrastructure/validation/review-handler.d.ts.map +1 -0
  202. package/dist/infrastructure/validation/review-handler.js +206 -0
  203. package/dist/infrastructure/validation/review-handler.js.map +1 -0
  204. package/dist/infrastructure/validation/summary-aggregator.d.ts +42 -0
  205. package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -0
  206. package/dist/infrastructure/validation/summary-aggregator.js +156 -0
  207. package/dist/infrastructure/validation/summary-aggregator.js.map +1 -0
  208. package/dist/infrastructure/validation/summary-extractor.d.ts +59 -0
  209. package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -0
  210. package/dist/infrastructure/validation/summary-extractor.js +102 -0
  211. package/dist/infrastructure/validation/summary-extractor.js.map +1 -0
  212. package/dist/infrastructure/validation/trace-summary.d.ts +72 -0
  213. package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -0
  214. package/dist/infrastructure/validation/trace-summary.js +371 -0
  215. package/dist/infrastructure/validation/trace-summary.js.map +1 -0
  216. package/dist/infrastructure/validation/trust-config.d.ts +27 -0
  217. package/dist/infrastructure/validation/trust-config.d.ts.map +1 -0
  218. package/dist/infrastructure/validation/trust-config.js +113 -0
  219. package/dist/infrastructure/validation/trust-config.js.map +1 -0
  220. package/dist/infrastructure/xai/attention-visualizer.d.ts +6 -8
  221. package/dist/infrastructure/xai/attention-visualizer.d.ts.map +1 -1
  222. package/dist/infrastructure/xai/attention-visualizer.js +6 -8
  223. package/dist/infrastructure/xai/attention-visualizer.js.map +1 -1
  224. package/dist/infrastructure/xai/cot-visualizer.d.ts +6 -9
  225. package/dist/infrastructure/xai/cot-visualizer.d.ts.map +1 -1
  226. package/dist/infrastructure/xai/cot-visualizer.js +6 -9
  227. package/dist/infrastructure/xai/cot-visualizer.js.map +1 -1
  228. package/dist/infrastructure/xai/decision-tree-log.d.ts +6 -10
  229. package/dist/infrastructure/xai/decision-tree-log.d.ts.map +1 -1
  230. package/dist/infrastructure/xai/decision-tree-log.js +6 -10
  231. package/dist/infrastructure/xai/decision-tree-log.js.map +1 -1
  232. package/dist/infrastructure/xai/interactive-xai.d.ts +6 -8
  233. package/dist/infrastructure/xai/interactive-xai.d.ts.map +1 -1
  234. package/dist/infrastructure/xai/interactive-xai.js +6 -8
  235. package/dist/infrastructure/xai/interactive-xai.js.map +1 -1
  236. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts +6 -9
  237. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts.map +1 -1
  238. package/dist/infrastructure/xai/uncertainty-quantifier.js +6 -9
  239. package/dist/infrastructure/xai/uncertainty-quantifier.js.map +1 -1
  240. package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
  241. package/dist/presentation/cli/commands/ask-command.js +84 -2
  242. package/dist/presentation/cli/commands/ask-command.js.map +1 -1
  243. package/dist/presentation/cli/commands/docs-command.d.ts +12 -0
  244. package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -0
  245. package/dist/presentation/cli/commands/docs-command.js +196 -0
  246. package/dist/presentation/cli/commands/docs-command.js.map +1 -0
  247. package/dist/presentation/cli/commands/fix-command.d.ts +8 -0
  248. package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -0
  249. package/dist/presentation/cli/commands/fix-command.js +309 -0
  250. package/dist/presentation/cli/commands/fix-command.js.map +1 -0
  251. package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
  252. package/dist/presentation/cli/commands/help-command.js +2 -0
  253. package/dist/presentation/cli/commands/help-command.js.map +1 -1
  254. package/dist/presentation/cli/commands/orchestrate-command.d.ts +1 -0
  255. package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -1
  256. package/dist/presentation/cli/commands/orchestrate-command.js +53 -0
  257. package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -1
  258. package/dist/presentation/cli/commands/plan-command.d.ts +1 -0
  259. package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -1
  260. package/dist/presentation/cli/commands/plan-command.js +80 -3
  261. package/dist/presentation/cli/commands/plan-command.js.map +1 -1
  262. package/dist/presentation/cli/commands/product-command.d.ts +12 -0
  263. package/dist/presentation/cli/commands/product-command.d.ts.map +1 -0
  264. package/dist/presentation/cli/commands/product-command.js +188 -0
  265. package/dist/presentation/cli/commands/product-command.js.map +1 -0
  266. package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
  267. package/dist/presentation/cli/commands/react-command.js +3 -1
  268. package/dist/presentation/cli/commands/react-command.js.map +1 -1
  269. package/dist/presentation/cli/commands/review-command.d.ts +14 -0
  270. package/dist/presentation/cli/commands/review-command.d.ts.map +1 -0
  271. package/dist/presentation/cli/commands/review-command.js +22 -0
  272. package/dist/presentation/cli/commands/review-command.js.map +1 -0
  273. package/dist/presentation/cli/commands/run-command.d.ts +15 -0
  274. package/dist/presentation/cli/commands/run-command.d.ts.map +1 -0
  275. package/dist/presentation/cli/commands/run-command.js +29 -0
  276. package/dist/presentation/cli/commands/run-command.js.map +1 -0
  277. package/dist/presentation/cli/commands/smart-command.d.ts +3 -1
  278. package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
  279. package/dist/presentation/cli/commands/smart-command.js +92 -6
  280. package/dist/presentation/cli/commands/smart-command.js.map +1 -1
  281. package/dist/presentation/cli/commands/status-command.d.ts +11 -0
  282. package/dist/presentation/cli/commands/status-command.d.ts.map +1 -0
  283. package/dist/presentation/cli/commands/status-command.js +176 -0
  284. package/dist/presentation/cli/commands/status-command.js.map +1 -0
  285. package/dist/presentation/cli/commands/suggest-command.d.ts +13 -0
  286. package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -0
  287. package/dist/presentation/cli/commands/suggest-command.js +25 -0
  288. package/dist/presentation/cli/commands/suggest-command.js.map +1 -0
  289. package/dist/presentation/cli/error-display.d.ts.map +1 -1
  290. package/dist/presentation/cli/error-display.js +43 -0
  291. package/dist/presentation/cli/error-display.js.map +1 -1
  292. package/dist/session.js +19 -2
  293. package/dist/session.js.map +1 -1
  294. package/dist/ui.d.ts.map +1 -1
  295. package/dist/ui.js +8 -5
  296. package/dist/ui.js.map +1 -1
  297. package/package.json +10 -2
@@ -0,0 +1,359 @@
1
+ /**
2
+ * Provider Layer: CohereProvider
3
+ * Thin wrapper implementing IModelProvider for Cohere API
4
+ *
5
+ * Phase 4A: Foundation Implementation (No Behavior Change)
6
+ *
7
+ * TODO: In Phase 4B, integrate with CohereAIService context compression and prompt building.
8
+ * For now, this is a minimal wrapper that preserves existing Cohere behavior.
9
+ */
10
+ import { CohereClient } from 'cohere-ai';
11
+ import { config } from 'dotenv';
12
+ import { join, dirname } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+ import { encoding_for_model } from 'tiktoken';
15
+ import { retryWithBackoff, cohereCircuitBreaker } from '../../error-handler.js';
16
+ // Load .env (same pattern as CohereAIService)
17
+ try {
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = dirname(__filename);
20
+ const agentDir = join(__dirname, '../../../..');
21
+ config({ path: join(agentDir, '.env') });
22
+ }
23
+ catch { }
24
+ config();
25
+ // Token counting (same as CohereAIService for consistency)
26
+ let tokenEncoder = null;
27
+ function getTokenEncoder() {
28
+ if (!tokenEncoder) {
29
+ try {
30
+ tokenEncoder = encoding_for_model('gpt-3.5-turbo');
31
+ }
32
+ catch {
33
+ tokenEncoder = encoding_for_model('gpt-4');
34
+ }
35
+ }
36
+ return tokenEncoder;
37
+ }
38
+ function countTokens(text) {
39
+ try {
40
+ const encoder = getTokenEncoder();
41
+ return encoder.encode(text).length;
42
+ }
43
+ catch (error) {
44
+ console.warn('Warning: tiktoken failed, using character-based estimate (less accurate)');
45
+ return Math.ceil(text.length / 4);
46
+ }
47
+ }
48
+ /**
49
+ * Cohere Provider
50
+ * Minimal wrapper around CohereClient implementing IModelProvider
51
+ */
52
+ export class CohereProvider {
53
+ id = 'cohere';
54
+ name = 'Cohere';
55
+ capabilities = {
56
+ chat: true,
57
+ streaming: true,
58
+ embedding: true,
59
+ embeddingQuery: true, // Cohere supports separate query embeddings
60
+ rerank: true,
61
+ toolCalling: true, // Cohere supports tool calling
62
+ };
63
+ client;
64
+ constructor(apiKey) {
65
+ const key = apiKey || process.env.COHERE_API_KEY;
66
+ if (!key) {
67
+ throw new Error('COHERE_API_KEY not found in environment');
68
+ }
69
+ this.client = new CohereClient({ token: key });
70
+ }
71
+ async getModels() {
72
+ // TODO: In Phase 4B, fetch available models from Cohere API if possible
73
+ // For now, return known Cohere models
74
+ return [
75
+ {
76
+ id: 'command-r-plus',
77
+ name: 'Command R+',
78
+ providerId: 'cohere',
79
+ providerModelId: 'command-r-plus',
80
+ contextWindow: 128000,
81
+ capabilities: {
82
+ chat: true,
83
+ streaming: true,
84
+ embedding: false,
85
+ embeddingQuery: false,
86
+ rerank: false,
87
+ toolCalling: true,
88
+ },
89
+ },
90
+ {
91
+ id: 'embed-english-v3',
92
+ name: 'Embed English v3.0',
93
+ providerId: 'cohere',
94
+ providerModelId: 'embed-english-v3.0',
95
+ contextWindow: 512,
96
+ capabilities: {
97
+ chat: false,
98
+ streaming: false,
99
+ embedding: true,
100
+ embeddingQuery: true,
101
+ rerank: false,
102
+ toolCalling: false,
103
+ },
104
+ },
105
+ {
106
+ id: 'rerank-english-v3',
107
+ name: 'Rerank English v3.0',
108
+ providerId: 'cohere',
109
+ providerModelId: 'rerank-english-v3.0',
110
+ contextWindow: 4096,
111
+ capabilities: {
112
+ chat: false,
113
+ streaming: false,
114
+ embedding: false,
115
+ embeddingQuery: false,
116
+ rerank: true,
117
+ toolCalling: false,
118
+ },
119
+ },
120
+ ];
121
+ }
122
+ getDefaultModel() {
123
+ return 'command-r-plus';
124
+ }
125
+ async chat(prompt, options) {
126
+ const model = options?.model || this.getDefaultModel();
127
+ return await retryWithBackoff(async () => {
128
+ return await cohereCircuitBreaker.execute(async () => {
129
+ const response = await this.client.chat({
130
+ message: prompt,
131
+ ...(model ? { model } : {}),
132
+ temperature: options?.temperature ?? 0.7,
133
+ ...(options?.maxTokens ? { maxTokens: options.maxTokens } : {}),
134
+ });
135
+ const text = response.text || 'No response generated';
136
+ const inputTokens = countTokens(prompt);
137
+ const outputTokens = countTokens(text);
138
+ return {
139
+ text,
140
+ model: model || 'default',
141
+ usage: {
142
+ inputTokens,
143
+ outputTokens,
144
+ },
145
+ };
146
+ });
147
+ }, {
148
+ maxRetries: 5,
149
+ baseDelay: 2000,
150
+ maxDelay: 60000,
151
+ operationName: 'cohere-provider-chat',
152
+ });
153
+ }
154
+ async chatStream(prompt, options, onEvent) {
155
+ const model = options?.model || this.getDefaultModel();
156
+ let fullText = '';
157
+ try {
158
+ if (onEvent) {
159
+ onEvent({ type: 'start' });
160
+ }
161
+ // Check if Cohere SDK supports streaming
162
+ if (typeof this.client.chatStream === 'function') {
163
+ const stream = await this.client.chatStream({
164
+ message: prompt,
165
+ ...(model ? { model } : {}),
166
+ temperature: options?.temperature ?? 0.7,
167
+ });
168
+ for await (const event of stream) {
169
+ if (event.eventType === 'text-generation' || event.type === 'text') {
170
+ const token = event.text || event.delta || '';
171
+ if (token) {
172
+ fullText += token;
173
+ if (onEvent) {
174
+ onEvent({ type: 'delta', text: token });
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ else {
181
+ // Fallback: Use regular chat
182
+ const response = await this.chat(prompt, options);
183
+ fullText = response.text;
184
+ // Simulate streaming by sending chunks
185
+ if (onEvent && fullText.length > 0) {
186
+ const chunkSize = 10;
187
+ for (let i = 0; i < fullText.length; i += chunkSize) {
188
+ const chunk = fullText.substring(i, i + chunkSize);
189
+ onEvent({ type: 'delta', text: chunk });
190
+ if (fullText.length > chunkSize * 2) {
191
+ await new Promise(resolve => setTimeout(resolve, 50));
192
+ }
193
+ }
194
+ }
195
+ }
196
+ if (onEvent) {
197
+ onEvent({ type: 'complete' });
198
+ }
199
+ const inputTokens = countTokens(prompt);
200
+ const outputTokens = countTokens(fullText);
201
+ return {
202
+ text: fullText,
203
+ model: model || 'default',
204
+ usage: {
205
+ inputTokens,
206
+ outputTokens,
207
+ },
208
+ };
209
+ }
210
+ catch (error) {
211
+ if (onEvent) {
212
+ onEvent({
213
+ type: 'error',
214
+ error: error instanceof Error ? error : new Error(String(error)),
215
+ });
216
+ }
217
+ throw error;
218
+ }
219
+ }
220
+ async embed(text) {
221
+ const texts = Array.isArray(text) ? text : [text];
222
+ return await retryWithBackoff(async () => {
223
+ return await cohereCircuitBreaker.execute(async () => {
224
+ const response = await this.client.embed({
225
+ texts,
226
+ model: 'embed-english-v3.0',
227
+ inputType: 'search_document',
228
+ });
229
+ const embeddings = response.embeddings;
230
+ if (texts.length === 1) {
231
+ return embeddings[0];
232
+ }
233
+ return embeddings;
234
+ });
235
+ }, {
236
+ maxRetries: 5,
237
+ baseDelay: 2000,
238
+ maxDelay: 60000,
239
+ operationName: 'cohere-provider-embed',
240
+ });
241
+ }
242
+ async embedQuery(query) {
243
+ return await retryWithBackoff(async () => {
244
+ return await cohereCircuitBreaker.execute(async () => {
245
+ const response = await this.client.embed({
246
+ texts: [query],
247
+ model: 'embed-english-v3.0',
248
+ inputType: 'search_query',
249
+ });
250
+ const embeddings = response.embeddings;
251
+ if (Array.isArray(embeddings)) {
252
+ if (embeddings.length === 0) {
253
+ throw new Error('No embedding returned for query');
254
+ }
255
+ return embeddings[0] || [];
256
+ }
257
+ else {
258
+ const embeddingsArray = embeddings.float || [];
259
+ if (embeddingsArray.length === 0) {
260
+ throw new Error('No embedding returned for query');
261
+ }
262
+ return embeddingsArray[0] || [];
263
+ }
264
+ });
265
+ }, {
266
+ maxRetries: 5,
267
+ baseDelay: 2000,
268
+ maxDelay: 60000,
269
+ operationName: 'cohere-provider-embed-query',
270
+ });
271
+ }
272
+ async rerank(query, documents, options) {
273
+ if (documents.length === 0) {
274
+ return {
275
+ results: [],
276
+ model: 'rerank-english-v3.0',
277
+ };
278
+ }
279
+ // Cohere Rerank API has limits, so we cap at 100 documents
280
+ const documentsToRerank = documents.slice(0, 100);
281
+ const topN = Math.min(options?.topN ?? 10, documentsToRerank.length);
282
+ const model = options?.model || 'rerank-english-v3.0';
283
+ return await retryWithBackoff(async () => {
284
+ return await cohereCircuitBreaker.execute(async () => {
285
+ const response = await this.client.rerank({
286
+ model,
287
+ query,
288
+ documents: documentsToRerank,
289
+ topN,
290
+ });
291
+ const results = (response.results || []).map((result) => ({
292
+ index: result.index,
293
+ relevanceScore: result.relevanceScore || 0,
294
+ }));
295
+ return {
296
+ results,
297
+ model,
298
+ };
299
+ });
300
+ }, {
301
+ maxRetries: 3,
302
+ baseDelay: 2000,
303
+ maxDelay: 30000,
304
+ operationName: 'cohere-provider-rerank',
305
+ });
306
+ }
307
+ async countTokens(text, _model) {
308
+ // TODO: In Phase 4B, use Cohere-specific tokenizer if available
309
+ // For now, use same tiktoken approach as CohereAIService
310
+ return Promise.resolve(countTokens(text));
311
+ }
312
+ async isAvailable() {
313
+ try {
314
+ // Simple availability check - try to get models
315
+ await this.getModels();
316
+ return true;
317
+ }
318
+ catch {
319
+ return false;
320
+ }
321
+ }
322
+ handleError(error) {
323
+ if (error && typeof error === 'object') {
324
+ const err = error;
325
+ // Check for rate limiting (429)
326
+ if (err.statusCode === 429 || err.status === 429) {
327
+ return {
328
+ type: 'rate_limit',
329
+ retryable: false,
330
+ message: 'Rate limit exceeded',
331
+ };
332
+ }
333
+ // Check for trial key quota
334
+ const errorMsg = err.message || String(error);
335
+ if (errorMsg.includes('Trial key') && errorMsg.includes('1000 API calls')) {
336
+ return {
337
+ type: 'quota_exceeded',
338
+ retryable: false,
339
+ message: 'Trial API key has reached monthly limit (1000 calls/month)',
340
+ };
341
+ }
342
+ // Check for authentication errors
343
+ if (err.statusCode === 401 || err.status === 401) {
344
+ return {
345
+ type: 'auth_error',
346
+ retryable: false,
347
+ message: 'Authentication failed - check API key',
348
+ };
349
+ }
350
+ }
351
+ // Default to retryable error
352
+ return {
353
+ type: 'unknown',
354
+ retryable: true,
355
+ message: error instanceof Error ? error.message : String(error),
356
+ };
357
+ }
358
+ }
359
+ //# sourceMappingURL=cohere-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cohere-provider.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/cohere-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,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,UAAU,CAAC;AAW9C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,8CAA8C;AAC9C,IAAI,CAAC;IACH,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAChD,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC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BAA4B;YAC5B,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9C,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBAC1E,OAAO;oBACL,IAAI,EAAE,gBAAgB;oBACtB,SAAS,EAAE,KAAK;oBAChB,OAAO,EAAE,4DAA4D;iBACtE,CAAC;YACJ,CAAC;YAED,kCAAkC;YAClC,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACjD,OAAO;oBACL,IAAI,EAAE,YAAY;oBAClB,SAAS,EAAE,KAAK;oBAChB,OAAO,EAAE,uCAAuC;iBACjD,CAAC;YACJ,CAAC;QACH,CAAC;QAED,6BAA6B;QAC7B,OAAO;YACL,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAChE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Provider Layer: FakeProvider
3
+ * Deterministic test provider implementing IModelProvider
4
+ *
5
+ * Phase 4D: FakeProvider Implementation
6
+ * Provides deterministic outputs for testing and local demos without external API calls
7
+ */
8
+ import type { IModelProvider, ProviderCapabilities, ModelInfo, ChatOptions, ChatResponse, StreamEvent, RerankResponse } from './model-provider.interface.js';
9
+ /**
10
+ * FakeProvider
11
+ * Deterministic provider for testing and demos
12
+ *
13
+ * Behavior:
14
+ * - Chat: Returns deterministic responses based on query
15
+ * - Streaming: Simulates streaming by sending words incrementally
16
+ * - Embeddings: Returns fixed-size zero vectors (768 dimensions)
17
+ * - Rerank: Returns documents in original order with fake scores
18
+ * - No external HTTP calls
19
+ */
20
+ export declare class FakeProvider implements IModelProvider {
21
+ readonly id = "fake";
22
+ readonly name = "Fake Provider";
23
+ readonly capabilities: ProviderCapabilities;
24
+ private defaultModel;
25
+ getModels(): Promise<ModelInfo[]>;
26
+ getDefaultModel(): string;
27
+ chat(prompt: string, options?: ChatOptions): Promise<ChatResponse>;
28
+ chatStream(prompt: string, options?: ChatOptions, onEvent?: (event: StreamEvent) => void): Promise<ChatResponse>;
29
+ embed(text: string | string[]): Promise<number[] | number[][]>;
30
+ embedQuery(query: string): Promise<number[]>;
31
+ rerank(query: string, documents: string[], options?: {
32
+ topN?: number;
33
+ model?: string;
34
+ }): Promise<RerankResponse>;
35
+ countTokens(text: string, _model?: string): Promise<number>;
36
+ isAvailable(): Promise<boolean>;
37
+ handleError?(error: unknown): {
38
+ type: string;
39
+ retryable: boolean;
40
+ message: string;
41
+ };
42
+ }
43
+ //# sourceMappingURL=fake-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-provider.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/fake-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EAEf,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,qBAAa,YAAa,YAAW,cAAc;IACjD,QAAQ,CAAC,EAAE,UAAU;IACrB,QAAQ,CAAC,IAAI,mBAAmB;IAEhC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAOzC;IAEF,OAAO,CAAC,YAAY,CAAmB;IAEjC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAavC,eAAe,IAAI,MAAM;IAInB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAqBlE,UAAU,CACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACrC,OAAO,CAAC,YAAY,CAAC;IA0BlB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;IAY9D,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAM5C,MAAM,CACV,KAAK,EAAE,MAAM,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;IAgBpB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM3D,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAKrC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CASpF"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Provider Layer: FakeProvider
3
+ * Deterministic test provider implementing IModelProvider
4
+ *
5
+ * Phase 4D: FakeProvider Implementation
6
+ * Provides deterministic outputs for testing and local demos without external API calls
7
+ */
8
+ /**
9
+ * FakeProvider
10
+ * Deterministic provider for testing and demos
11
+ *
12
+ * Behavior:
13
+ * - Chat: Returns deterministic responses based on query
14
+ * - Streaming: Simulates streaming by sending words incrementally
15
+ * - Embeddings: Returns fixed-size zero vectors (768 dimensions)
16
+ * - Rerank: Returns documents in original order with fake scores
17
+ * - No external HTTP calls
18
+ */
19
+ export class FakeProvider {
20
+ id = 'fake';
21
+ name = 'Fake Provider';
22
+ capabilities = {
23
+ chat: true,
24
+ streaming: true,
25
+ embedding: true,
26
+ embeddingQuery: true,
27
+ rerank: true,
28
+ toolCalling: false,
29
+ };
30
+ defaultModel = 'fake-model-v1';
31
+ async getModels() {
32
+ return [
33
+ {
34
+ id: 'fake-model-v1',
35
+ name: 'Fake Model v1',
36
+ providerId: this.id,
37
+ providerModelId: 'fake-model-v1',
38
+ contextWindow: 4096,
39
+ capabilities: { ...this.capabilities },
40
+ },
41
+ ];
42
+ }
43
+ getDefaultModel() {
44
+ return this.defaultModel;
45
+ }
46
+ async chat(prompt, options) {
47
+ // Deterministic response based on prompt
48
+ // Truncate prompt to first 80 chars for consistency with FakeAIService
49
+ const promptPreview = prompt.length > 80 ? prompt.substring(0, 80) + '...' : prompt;
50
+ const text = `FAKE_RESPONSE: ${promptPreview}`;
51
+ // Simple token counting (character-based estimate)
52
+ const inputTokens = Math.ceil(prompt.length / 4);
53
+ const outputTokens = Math.ceil(text.length / 4);
54
+ return {
55
+ text,
56
+ model: options?.model || this.defaultModel,
57
+ usage: {
58
+ inputTokens,
59
+ outputTokens,
60
+ },
61
+ finishReason: 'stop',
62
+ };
63
+ }
64
+ async chatStream(prompt, options, onEvent) {
65
+ // Get the full response first
66
+ const response = await this.chat(prompt, options);
67
+ if (onEvent) {
68
+ onEvent({ type: 'start' });
69
+ // Simulate streaming by sending words incrementally
70
+ const words = response.text.split(' ');
71
+ for (let i = 0; i < words.length; i++) {
72
+ const word = words[i];
73
+ const isLast = i === words.length - 1;
74
+ const delta = isLast ? word : word + ' ';
75
+ // Small delay to simulate streaming
76
+ await new Promise(resolve => setTimeout(resolve, 10));
77
+ onEvent({ type: 'delta', text: delta });
78
+ }
79
+ onEvent({ type: 'complete', text: response.text });
80
+ }
81
+ return response;
82
+ }
83
+ async embed(text) {
84
+ // Return deterministic fake embeddings (all zeros, 768 dimensions)
85
+ // Matches FakeAIService behavior
86
+ const embeddingSize = 768;
87
+ if (Array.isArray(text)) {
88
+ return text.map(() => new Array(embeddingSize).fill(0));
89
+ }
90
+ return new Array(embeddingSize).fill(0);
91
+ }
92
+ async embedQuery(query) {
93
+ // Return deterministic fake query embedding (768 dimensions)
94
+ // Matches FakeAIService behavior
95
+ return new Array(768).fill(0);
96
+ }
97
+ async rerank(query, documents, options) {
98
+ // Return documents in original order with fake decreasing scores
99
+ // Matches FakeAIService behavior: 0.9, 0.8, 0.7, ...
100
+ const topN = Math.min(options?.topN || 10, documents.length);
101
+ const results = Array.from({ length: topN }, (_, i) => ({
102
+ index: i,
103
+ relevanceScore: 0.9 - (i * 0.1),
104
+ text: documents[i],
105
+ }));
106
+ return {
107
+ results,
108
+ model: options?.model || this.defaultModel,
109
+ };
110
+ }
111
+ async countTokens(text, _model) {
112
+ // Simple character-based token estimation (4 chars per token)
113
+ // Matches behavior used in other providers
114
+ return Math.ceil(text.length / 4);
115
+ }
116
+ async isAvailable() {
117
+ // Fake provider is always available (no external dependencies)
118
+ return true;
119
+ }
120
+ handleError(error) {
121
+ // Fake provider shouldn't have errors, but handle gracefully
122
+ const errorMessage = error instanceof Error ? error.message : String(error);
123
+ return {
124
+ type: 'unknown',
125
+ retryable: false,
126
+ message: `FakeProvider error: ${errorMessage}`,
127
+ };
128
+ }
129
+ }
130
+ //# sourceMappingURL=fake-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-provider.js","sourceRoot":"","sources":["../../../src/infrastructure/providers/fake-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IACd,EAAE,GAAG,MAAM,CAAC;IACZ,IAAI,GAAG,eAAe,CAAC;IAEvB,YAAY,GAAyB;QAC5C,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,KAAK;KACnB,CAAC;IAEM,YAAY,GAAG,eAAe,CAAC;IAEvC,KAAK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
@@ -0,0 +1,49 @@
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 type { IModelProvider, ProviderCapabilities, ModelInfo, ChatOptions, ChatResponse, StreamEvent, RerankResponse } from './model-provider.interface.js';
9
+ /**
10
+ * LocalLLMProvider
11
+ * Implements IModelProvider for OpenAI-compatible local endpoints
12
+ *
13
+ * Designed for:
14
+ * - Ollama (http://localhost:11434)
15
+ * - LM Studio (http://localhost:1234)
16
+ * - On-prem OpenAI-compatible gateways
17
+ *
18
+ * API Assumptions:
19
+ * - POST {baseUrl}/v1/chat/completions (OpenAI-compatible)
20
+ * - POST {baseUrl}/v1/embeddings (OpenAI-compatible)
21
+ * - Streaming via Server-Sent Events (SSE) if supported
22
+ */
23
+ export declare class LocalLLMProvider implements IModelProvider {
24
+ readonly id = "local";
25
+ readonly name = "Local LLM Provider";
26
+ readonly capabilities: ProviderCapabilities;
27
+ private baseUrl;
28
+ private defaultChatModel;
29
+ private defaultEmbedModel;
30
+ constructor(baseUrl?: string, defaultChatModel?: string, defaultEmbedModel?: string);
31
+ getModels(): Promise<ModelInfo[]>;
32
+ getDefaultModel(): string;
33
+ chat(prompt: string, options?: ChatOptions): Promise<ChatResponse>;
34
+ chatStream(prompt: string, options?: ChatOptions, onEvent?: (event: StreamEvent) => void): Promise<ChatResponse>;
35
+ embed(text: string | string[]): Promise<number[] | number[][]>;
36
+ embedQuery(query: string): Promise<number[]>;
37
+ rerank?(_query: string, _documents: string[], _options?: {
38
+ topN?: number;
39
+ model?: string;
40
+ }): Promise<RerankResponse>;
41
+ countTokens(text: string, _model?: string): Promise<number>;
42
+ isAvailable(): Promise<boolean>;
43
+ handleError?(error: unknown): {
44
+ type: string;
45
+ retryable: boolean;
46
+ message: string;
47
+ };
48
+ }
49
+ //# sourceMappingURL=local-llm-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-llm-provider.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/providers/local-llm-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EAEf,MAAM,+BAA+B,CAAC;AA2BvC;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IACrD,QAAQ,CAAC,EAAE,WAAW;IACtB,QAAQ,CAAC,IAAI,wBAAwB;IAErC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAOzC;IAEF,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,iBAAiB,CAAS;gBAGhC,OAAO,CAAC,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,MAAM,EACzB,iBAAiB,CAAC,EAAE,MAAM;IActB,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAevC,eAAe,IAAI,MAAM;IAInB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAqDlE,UAAU,CACd,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACrC,OAAO,CAAC,YAAY,CAAC;IA8FlB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;IAuC9D,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOlD,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,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