@noorm/marie-cli 0.1.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.
Files changed (193) hide show
  1. package/JOY_ZONING.md +200 -0
  2. package/LICENSE.md +190 -0
  3. package/README.md +94 -0
  4. package/dist/cli-new/components/App.js +138 -0
  5. package/dist/cli-new/components/App.js.map +1 -0
  6. package/dist/cli-new/components/ApprovalDialog.js +31 -0
  7. package/dist/cli-new/components/ApprovalDialog.js.map +1 -0
  8. package/dist/cli-new/components/Banner.js +23 -0
  9. package/dist/cli-new/components/Banner.js.map +1 -0
  10. package/dist/cli-new/components/ChatArea.js +49 -0
  11. package/dist/cli-new/components/ChatArea.js.map +1 -0
  12. package/dist/cli-new/components/Header.js +20 -0
  13. package/dist/cli-new/components/Header.js.map +1 -0
  14. package/dist/cli-new/components/InputArea.js +97 -0
  15. package/dist/cli-new/components/InputArea.js.map +1 -0
  16. package/dist/cli-new/components/MessageBubble.js +114 -0
  17. package/dist/cli-new/components/MessageBubble.js.map +1 -0
  18. package/dist/cli-new/components/SessionSwitcher.js +46 -0
  19. package/dist/cli-new/components/SessionSwitcher.js.map +1 -0
  20. package/dist/cli-new/components/SetupWizard.js +283 -0
  21. package/dist/cli-new/components/SetupWizard.js.map +1 -0
  22. package/dist/cli-new/components/ToolCallDisplay.js +45 -0
  23. package/dist/cli-new/components/ToolCallDisplay.js.map +1 -0
  24. package/dist/cli-new/hooks/useGit.js +99 -0
  25. package/dist/cli-new/hooks/useGit.js.map +1 -0
  26. package/dist/cli-new/hooks/useMarie.js +249 -0
  27. package/dist/cli-new/hooks/useMarie.js.map +1 -0
  28. package/dist/cli-new/hooks/useSessions.js +75 -0
  29. package/dist/cli-new/hooks/useSessions.js.map +1 -0
  30. package/dist/cli-new/index.js +52 -0
  31. package/dist/cli-new/index.js.map +1 -0
  32. package/dist/cli-new/styles/theme.js +68 -0
  33. package/dist/cli-new/styles/theme.js.map +1 -0
  34. package/dist/cli-new/types/cli.js +2 -0
  35. package/dist/cli-new/types/cli.js.map +1 -0
  36. package/dist/extension.cjs +655 -0
  37. package/dist/monolith/adapters/CliMarieAdapter.js +72 -0
  38. package/dist/monolith/adapters/CliMarieAdapter.js.map +1 -0
  39. package/dist/monolith/adapters/VscodeMarieAdapter.js +81 -0
  40. package/dist/monolith/adapters/VscodeMarieAdapter.js.map +1 -0
  41. package/dist/monolith/cli/CliFileSystemPort.js +83 -0
  42. package/dist/monolith/cli/CliFileSystemPort.js.map +1 -0
  43. package/dist/monolith/cli/MarieToolDefinitionsCLI.js +438 -0
  44. package/dist/monolith/cli/MarieToolDefinitionsCLI.js.map +1 -0
  45. package/dist/monolith/cli/index.js +272 -0
  46. package/dist/monolith/cli/index.js.map +1 -0
  47. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js +80 -0
  48. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js.map +1 -0
  49. package/dist/monolith/cli/services/JoyServiceCLI.js +63 -0
  50. package/dist/monolith/cli/services/JoyServiceCLI.js.map +1 -0
  51. package/dist/monolith/cli/storage.js +119 -0
  52. package/dist/monolith/cli/storage.js.map +1 -0
  53. package/dist/monolith/domain/joy/JoyTools.js +513 -0
  54. package/dist/monolith/domain/joy/JoyTools.js.map +1 -0
  55. package/dist/monolith/domain/joy/RitualService.js +51 -0
  56. package/dist/monolith/domain/joy/RitualService.js.map +1 -0
  57. package/dist/monolith/domain/marie/MarieTypes.js +2 -0
  58. package/dist/monolith/domain/marie/MarieTypes.js.map +1 -0
  59. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js +230 -0
  60. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js.map +1 -0
  61. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js +207 -0
  62. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js.map +1 -0
  63. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js +129 -0
  64. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js.map +1 -0
  65. package/dist/monolith/infrastructure/ai/context/ContextManager.js +118 -0
  66. package/dist/monolith/infrastructure/ai/context/ContextManager.js.map +1 -0
  67. package/dist/monolith/infrastructure/ai/core/FileSystemPort.js +2 -0
  68. package/dist/monolith/infrastructure/ai/core/FileSystemPort.js.map +1 -0
  69. package/dist/monolith/infrastructure/ai/core/GhostPort.js +2 -0
  70. package/dist/monolith/infrastructure/ai/core/GhostPort.js.map +1 -0
  71. package/dist/monolith/infrastructure/ai/core/MarieAscensionTypes.js +2 -0
  72. package/dist/monolith/infrastructure/ai/core/MarieAscensionTypes.js.map +1 -0
  73. package/dist/monolith/infrastructure/ai/core/MarieEngine.js +590 -0
  74. package/dist/monolith/infrastructure/ai/core/MarieEngine.js.map +1 -0
  75. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js +161 -0
  76. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js.map +1 -0
  77. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js +121 -0
  78. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js.map +1 -0
  79. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js +256 -0
  80. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js.map +1 -0
  81. package/dist/monolith/infrastructure/ai/core/MariePulseService.js +67 -0
  82. package/dist/monolith/infrastructure/ai/core/MariePulseService.js.map +1 -0
  83. package/dist/monolith/infrastructure/ai/core/MarieResponse.js +101 -0
  84. package/dist/monolith/infrastructure/ai/core/MarieResponse.js.map +1 -0
  85. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js +86 -0
  86. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js.map +1 -0
  87. package/dist/monolith/infrastructure/ai/core/MarieSession.js +202 -0
  88. package/dist/monolith/infrastructure/ai/core/MarieSession.js.map +1 -0
  89. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js +58 -0
  90. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js.map +1 -0
  91. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js +127 -0
  92. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js.map +1 -0
  93. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js +548 -0
  94. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js.map +1 -0
  95. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js +2 -0
  96. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js.map +1 -0
  97. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js +125 -0
  98. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js.map +1 -0
  99. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js +30 -0
  100. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js.map +1 -0
  101. package/dist/monolith/infrastructure/ai/providers/AIProvider.js +2 -0
  102. package/dist/monolith/infrastructure/ai/providers/AIProvider.js.map +1 -0
  103. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js +148 -0
  104. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js.map +1 -0
  105. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js +208 -0
  106. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js.map +1 -0
  107. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js +404 -0
  108. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js.map +1 -0
  109. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js +283 -0
  110. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js.map +1 -0
  111. package/dist/monolith/infrastructure/config/ConfigService.js +398 -0
  112. package/dist/monolith/infrastructure/config/ConfigService.js.map +1 -0
  113. package/dist/monolith/infrastructure/services/MarieMemoryStore.js +140 -0
  114. package/dist/monolith/infrastructure/services/MarieMemoryStore.js.map +1 -0
  115. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js +1568 -0
  116. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js.map +1 -0
  117. package/dist/monolith/infrastructure/tools/PureStreamParser.js +147 -0
  118. package/dist/monolith/infrastructure/tools/PureStreamParser.js.map +1 -0
  119. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js +223 -0
  120. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js.map +1 -0
  121. package/dist/monolith/infrastructure/tools/ToolRegistry.js +29 -0
  122. package/dist/monolith/infrastructure/tools/ToolRegistry.js.map +1 -0
  123. package/dist/monolith/infrastructure/tools/ToolUtils.js +59 -0
  124. package/dist/monolith/infrastructure/tools/ToolUtils.js.map +1 -0
  125. package/dist/monolith/plumbing/analysis/CodeHealthService.js +146 -0
  126. package/dist/monolith/plumbing/analysis/CodeHealthService.js.map +1 -0
  127. package/dist/monolith/plumbing/analysis/ComplexityService.js +43 -0
  128. package/dist/monolith/plumbing/analysis/ComplexityService.js.map +1 -0
  129. package/dist/monolith/plumbing/analysis/DependencyService.js +51 -0
  130. package/dist/monolith/plumbing/analysis/DependencyService.js.map +1 -0
  131. package/dist/monolith/plumbing/analysis/DiscoveryService.js +49 -0
  132. package/dist/monolith/plumbing/analysis/DiscoveryService.js.map +1 -0
  133. package/dist/monolith/plumbing/analysis/JoyMapService.js +66 -0
  134. package/dist/monolith/plumbing/analysis/JoyMapService.js.map +1 -0
  135. package/dist/monolith/plumbing/analysis/LintService.js +132 -0
  136. package/dist/monolith/plumbing/analysis/LintService.js.map +1 -0
  137. package/dist/monolith/plumbing/analysis/MarieSentinelService.js +276 -0
  138. package/dist/monolith/plumbing/analysis/MarieSentinelService.js.map +1 -0
  139. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js +119 -0
  140. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js.map +1 -0
  141. package/dist/monolith/plumbing/analysis/SurgicalMender.js +70 -0
  142. package/dist/monolith/plumbing/analysis/SurgicalMender.js.map +1 -0
  143. package/dist/monolith/plumbing/analysis/TestService.js +104 -0
  144. package/dist/monolith/plumbing/analysis/TestService.js.map +1 -0
  145. package/dist/monolith/plumbing/filesystem/FileService.js +406 -0
  146. package/dist/monolith/plumbing/filesystem/FileService.js.map +1 -0
  147. package/dist/monolith/plumbing/filesystem/PathResolver.js +26 -0
  148. package/dist/monolith/plumbing/filesystem/PathResolver.js.map +1 -0
  149. package/dist/monolith/plumbing/git/GitService.js +71 -0
  150. package/dist/monolith/plumbing/git/GitService.js.map +1 -0
  151. package/dist/monolith/plumbing/lsp/SymbolService.js +36 -0
  152. package/dist/monolith/plumbing/lsp/SymbolService.js.map +1 -0
  153. package/dist/monolith/plumbing/terminal/ProcessRegistry.js +31 -0
  154. package/dist/monolith/plumbing/terminal/ProcessRegistry.js.map +1 -0
  155. package/dist/monolith/plumbing/terminal/TerminalService.js +180 -0
  156. package/dist/monolith/plumbing/terminal/TerminalService.js.map +1 -0
  157. package/dist/monolith/plumbing/ui/DecorationService.js +54 -0
  158. package/dist/monolith/plumbing/ui/DecorationService.js.map +1 -0
  159. package/dist/monolith/plumbing/utils/ErrorUtils.js +11 -0
  160. package/dist/monolith/plumbing/utils/ErrorUtils.js.map +1 -0
  161. package/dist/monolith/plumbing/utils/JsonUtils.js +360 -0
  162. package/dist/monolith/plumbing/utils/JsonUtils.js.map +1 -0
  163. package/dist/monolith/plumbing/utils/PrefixTree.js +153 -0
  164. package/dist/monolith/plumbing/utils/PrefixTree.js.map +1 -0
  165. package/dist/monolith/plumbing/utils/RetryUtils.js +141 -0
  166. package/dist/monolith/plumbing/utils/RetryUtils.js.map +1 -0
  167. package/dist/monolith/plumbing/utils/StreamTagDetector.js +128 -0
  168. package/dist/monolith/plumbing/utils/StreamTagDetector.js.map +1 -0
  169. package/dist/monolith/plumbing/utils/StringUtils.js +97 -0
  170. package/dist/monolith/plumbing/utils/StringUtils.js.map +1 -0
  171. package/dist/monolith/plumbing/utils/TimeoutUtils.js +21 -0
  172. package/dist/monolith/plumbing/utils/TimeoutUtils.js.map +1 -0
  173. package/dist/monolith/runtime/MarieRuntime.js +354 -0
  174. package/dist/monolith/runtime/MarieRuntime.js.map +1 -0
  175. package/dist/monolith/runtime/RuntimeAdapterBase.js +59 -0
  176. package/dist/monolith/runtime/RuntimeAdapterBase.js.map +1 -0
  177. package/dist/monolith/runtime/providerFactory.js +11 -0
  178. package/dist/monolith/runtime/providerFactory.js.map +1 -0
  179. package/dist/monolith/runtime/types.js +2 -0
  180. package/dist/monolith/runtime/types.js.map +1 -0
  181. package/dist/monolith/services/HealthService.js +38 -0
  182. package/dist/monolith/services/HealthService.js.map +1 -0
  183. package/dist/monolith/services/JoyAutomationService.js +131 -0
  184. package/dist/monolith/services/JoyAutomationService.js.map +1 -0
  185. package/dist/monolith/services/JoyLogService.js +48 -0
  186. package/dist/monolith/services/JoyLogService.js.map +1 -0
  187. package/dist/monolith/services/JoyService.js +190 -0
  188. package/dist/monolith/services/JoyService.js.map +1 -0
  189. package/dist/monolith/services/MarieGhostService.js +168 -0
  190. package/dist/monolith/services/MarieGhostService.js.map +1 -0
  191. package/dist/monolith/services/MarieSCMProvider.js +41 -0
  192. package/dist/monolith/services/MarieSCMProvider.js.map +1 -0
  193. package/package.json +168 -0
@@ -0,0 +1,125 @@
1
+ /**
2
+ * REASONING BUDGET - Clean Fix Pattern
3
+ *
4
+ * Principles:
5
+ * 1. Unlimited internal reasoning depth
6
+ * 2. Hard output schema enforcement
7
+ * 3. Max 3 self-reflection iterations
8
+ * 4. Separate thinking from acting
9
+ */
10
+ export class ReasoningBudget {
11
+ iterations = [];
12
+ static MAX_SELF_REFLECTIONS = 3;
13
+ actionFrozen = false;
14
+ /**
15
+ * Add a reasoning iteration.
16
+ * Returns false if max iterations reached.
17
+ */
18
+ think(thought, proposedAction) {
19
+ if (this.iterations.length >= ReasoningBudget.MAX_SELF_REFLECTIONS) {
20
+ return false;
21
+ }
22
+ this.iterations.push({
23
+ iteration: this.iterations.length + 1,
24
+ thought,
25
+ proposedAction,
26
+ });
27
+ return true;
28
+ }
29
+ /**
30
+ * Freeze the proposed action.
31
+ * No more mutations allowed after this.
32
+ */
33
+ freezeAction() {
34
+ this.actionFrozen = true;
35
+ }
36
+ /**
37
+ * Check if action is frozen (thinking phase complete).
38
+ */
39
+ isActionFrozen() {
40
+ return this.actionFrozen;
41
+ }
42
+ /**
43
+ * Validate output against expected schema.
44
+ * If invalid, reject - no negotiation.
45
+ */
46
+ validateOutput(output, validator) {
47
+ return validator(output);
48
+ }
49
+ /**
50
+ * Get all reasoning iterations for logging/debugging.
51
+ */
52
+ getIterations() {
53
+ return this.iterations;
54
+ }
55
+ /**
56
+ * Get current iteration count.
57
+ */
58
+ getIterationCount() {
59
+ return this.iterations.length;
60
+ }
61
+ /**
62
+ * Check if budget is exhausted.
63
+ */
64
+ isExhausted() {
65
+ return this.iterations.length >= ReasoningBudget.MAX_SELF_REFLECTIONS;
66
+ }
67
+ /**
68
+ * Produce final result with schema validation.
69
+ */
70
+ produceResult(output, validator) {
71
+ const schemaValidated = this.validateOutput(output, validator);
72
+ return {
73
+ iterations: this.iterations,
74
+ finalOutput: output,
75
+ schemaValidated,
76
+ actionFrozen: this.actionFrozen,
77
+ };
78
+ }
79
+ /**
80
+ * Reset for new reasoning session.
81
+ */
82
+ reset() {
83
+ this.iterations = [];
84
+ this.actionFrozen = false;
85
+ }
86
+ }
87
+ /**
88
+ * Schema validators for common outputs.
89
+ */
90
+ export const SchemaValidators = {
91
+ /**
92
+ * Validate tool call schema.
93
+ */
94
+ isToolCall: (o) => {
95
+ if (typeof o !== "object" || o === null)
96
+ return false;
97
+ const obj = o;
98
+ return (typeof obj.name === "string" &&
99
+ typeof obj.input === "object" &&
100
+ obj.input !== null);
101
+ },
102
+ /**
103
+ * Validate patch proposal schema.
104
+ */
105
+ isPatchProposal: (o) => {
106
+ if (typeof o !== "object" || o === null)
107
+ return false;
108
+ const obj = o;
109
+ return (typeof obj.targetFile === "string" &&
110
+ ["write", "replace", "delete"].includes(obj.operation) &&
111
+ typeof obj.reason === "string");
112
+ },
113
+ /**
114
+ * Validate analysis result schema.
115
+ */
116
+ isAnalysisResult: (o) => {
117
+ if (typeof o !== "object" || o === null)
118
+ return false;
119
+ const obj = o;
120
+ return (Array.isArray(obj.findings) &&
121
+ Array.isArray(obj.recommendations) &&
122
+ typeof obj.confidence === "number");
123
+ },
124
+ };
125
+ //# sourceMappingURL=ReasoningBudget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReasoningBudget.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/ReasoningBudget.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAeH,MAAM,OAAO,eAAe;IAClB,UAAU,GAAyB,EAAE,CAAC;IACtC,MAAM,CAAU,oBAAoB,GAAG,CAAC,CAAC;IACzC,YAAY,GAAG,KAAK,CAAC;IAE7B;;;OAGG;IACI,KAAK,CAAC,OAAe,EAAE,cAAuB;QACnD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,eAAe,CAAC,oBAAoB,EAAE,CAAC;YACnE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YACrC,OAAO;YACP,cAAc;SACf,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,cAAc,CACnB,MAAe,EACf,SAAiC;QAEjC,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC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AG,CAAC,MAAM,KAAK,QAAQ,CAC/B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,gBAAgB,EAAE,CAChB,CAAU,EAKV,EAAE;QACF,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QACtD,MAAM,GAAG,GAAG,CAA4B,CAAC;QACzC,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;YAC3B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;YAClC,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,CACnC,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { backupFile, restoreFile, clearBackups, rollbackAll, readFile, writeFile, deleteFile, } from "../../../plumbing/filesystem/FileService.js";
2
+ /**
3
+ * VscodeFileSystemPort - Implementation of FileSystemPort for the VS Code extension.
4
+ * Delegates all operations to the existing FileService which uses vscode.workspace.fs.
5
+ */
6
+ export class VscodeFileSystemPort {
7
+ type = "vscode";
8
+ async readFile(path, signal) {
9
+ return readFile(path, undefined, undefined, signal);
10
+ }
11
+ async writeFile(path, content, signal) {
12
+ return writeFile(path, content, signal);
13
+ }
14
+ async deleteFile(path) {
15
+ return deleteFile(path);
16
+ }
17
+ async backupFile(path) {
18
+ return backupFile(path);
19
+ }
20
+ async restoreFile(path) {
21
+ return restoreFile(path);
22
+ }
23
+ async rollbackAll() {
24
+ return rollbackAll();
25
+ }
26
+ clearBackups() {
27
+ clearBackups();
28
+ }
29
+ }
30
+ //# sourceMappingURL=VscodeFileSystemPort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VscodeFileSystemPort.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/core/VscodeFileSystemPort.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,SAAS,EACT,UAAU,GACX,MAAM,6CAA6C,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IACf,IAAI,GAAG,QAAQ,CAAC;IAChC,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,MAAoB;QAC/C,OAAO,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,SAAS,CACb,IAAY,EACZ,OAAe,EACf,MAAoB;QAEpB,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAY;QAC5B,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,WAAW,EAAE,CAAC;IACvB,CAAC;IAED,YAAY;QACV,YAAY,EAAE,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AIProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIProvider.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/providers/AIProvider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,148 @@
1
+ import Anthropic from "@anthropic-ai/sdk";
2
+ import { ConfigService } from "../../config/ConfigService.js";
3
+ import { JsonUtils } from "../../../plumbing/utils/JsonUtils.js";
4
+ export class AnthropicProvider {
5
+ client;
6
+ constructor(apiKey) {
7
+ this.client = new Anthropic({ apiKey });
8
+ }
9
+ async createMessage(params) {
10
+ const response = await this.client.messages.create({
11
+ model: params.model,
12
+ max_tokens: params.max_tokens || 1024,
13
+ system: params.system,
14
+ messages: params.messages,
15
+ tools: params.tools,
16
+ });
17
+ if (!response.content || response.content.length === 0) {
18
+ throw new Error("Anthropic API returned an empty content array.");
19
+ }
20
+ const toolUses = response.content
21
+ .filter((c) => c.type === "tool_use")
22
+ .map((c) => ({
23
+ id: c.id,
24
+ name: c.name,
25
+ input: c.input,
26
+ }));
27
+ return {
28
+ role: "assistant",
29
+ content: response.content,
30
+ tool_uses: toolUses.length > 0 ? toolUses : undefined,
31
+ };
32
+ }
33
+ async createMessageStream(params, onUpdate, signal) {
34
+ const startTime = Date.now();
35
+ onUpdate({ type: "run_started", timestamp: startTime });
36
+ onUpdate({
37
+ type: "stage_change",
38
+ stage: "thinking",
39
+ label: "Processing request...",
40
+ });
41
+ const stream = await this.client.messages.create({
42
+ model: params.model,
43
+ max_tokens: params.max_tokens || 1024,
44
+ system: params.system,
45
+ messages: params.messages,
46
+ tools: params.tools,
47
+ stream: true,
48
+ }, { signal });
49
+ // Use array buffers to avoid string concatenation overhead
50
+ const contentBuffer = [];
51
+ const toolCalls = {};
52
+ let hasStartedContent = false;
53
+ for await (const chunk of stream) {
54
+ if (chunk.type === "content_block_delta" &&
55
+ chunk.delta.type === "text_delta") {
56
+ if (!hasStartedContent) {
57
+ hasStartedContent = true;
58
+ onUpdate({
59
+ type: "stage_change",
60
+ stage: "responding",
61
+ label: "Generating response...",
62
+ });
63
+ }
64
+ const text = chunk.delta.text;
65
+ contentBuffer.push(text);
66
+ onUpdate({ type: "content_delta", text });
67
+ }
68
+ else if (chunk.type === "content_block_start" &&
69
+ chunk.content_block.type === "tool_use") {
70
+ onUpdate({
71
+ type: "stage_change",
72
+ stage: "calling_tool",
73
+ label: "Using tool...",
74
+ });
75
+ toolCalls[chunk.index] = {
76
+ id: chunk.content_block.id,
77
+ name: chunk.content_block.name,
78
+ inputParts: [],
79
+ };
80
+ onUpdate({
81
+ type: "tool_call_delta",
82
+ index: chunk.index,
83
+ id: chunk.content_block.id,
84
+ name: chunk.content_block.name,
85
+ });
86
+ }
87
+ else if (chunk.type === "content_block_delta" &&
88
+ chunk.delta.type === "input_json_delta") {
89
+ const toolCall = toolCalls[chunk.index];
90
+ if (toolCall) {
91
+ toolCall.inputParts.push(chunk.delta.partial_json);
92
+ onUpdate({
93
+ type: "tool_call_delta",
94
+ index: chunk.index,
95
+ argumentsDelta: chunk.delta.partial_json,
96
+ });
97
+ }
98
+ }
99
+ else if (chunk.type === "message_delta" && chunk.usage) {
100
+ onUpdate({
101
+ type: "usage",
102
+ usage: {
103
+ inputTokens: chunk.usage.input_tokens ?? undefined,
104
+ outputTokens: chunk.usage.output_tokens ?? undefined,
105
+ totalTokens: (chunk.usage.input_tokens ?? 0) +
106
+ (chunk.usage.output_tokens ?? 0),
107
+ },
108
+ });
109
+ }
110
+ }
111
+ const endTime = Date.now();
112
+ onUpdate({
113
+ type: "run_completed",
114
+ timestamp: endTime,
115
+ durationMs: endTime - startTime,
116
+ });
117
+ // Join array buffers into final strings
118
+ const fullContent = contentBuffer.join("");
119
+ const finalToolUses = Object.values(toolCalls).map((tc) => ({
120
+ id: tc.id,
121
+ name: tc.name,
122
+ input: JsonUtils.safeParseJson(tc.inputParts.join("")),
123
+ }));
124
+ return {
125
+ role: "assistant",
126
+ content: fullContent,
127
+ tool_uses: finalToolUses.length > 0 ? finalToolUses : undefined,
128
+ };
129
+ }
130
+ /**
131
+ * Efficiently estimates tokens via character count.
132
+ * Uses ConfigService.getTokensPerChar() (default 0.25 tokens/char).
133
+ */
134
+ estimateTokens(text) {
135
+ const tokensPerChar = ConfigService.getTokensPerChar();
136
+ return Math.ceil(text.length * tokensPerChar);
137
+ }
138
+ async listModels() {
139
+ return [
140
+ { id: "claude-3-5-sonnet-20241022", name: "Claude 3.5 Sonnet (Latest)" },
141
+ { id: "claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku" },
142
+ { id: "claude-3-opus-20240229", name: "Claude 3 Opus" },
143
+ { id: "claude-3-sonnet-20240229", name: "Claude 3 Sonnet" },
144
+ { id: "claude-3-haiku-20240307", name: "Claude 3 Haiku" },
145
+ ];
146
+ }
147
+ }
148
+ //# sourceMappingURL=AnthropicProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnthropicProvider.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/providers/AnthropicProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAO1C,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjE,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAY;IAE1B,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAuB;QACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YACjD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI;YACrC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO;aAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;aACpC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACX,EAAE,EAAE,CAAC,CAAC,EAAE;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E,CAAC,CAAC;SACvD,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,WAAW;YACpB,SAAS,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;SAChE,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,IAAY;QACzB,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO;YACL,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,4BAA4B,EAAE;YACxE,EAAE,EAAE,EAAE,2BAA2B,EAAE,IAAI,EAAE,kBAAkB,EAAE;YAC7D,EAAE,EAAE,EAAE,wBAAwB,EAAE,IAAI,EAAE,eAAe,EAAE;YACvD,EAAE,EAAE,EAAE,0BAA0B,EAAE,IAAI,EAAE,iBAAiB,EAAE;YAC3D,EAAE,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAAE,gBAAgB,EAAE;SAC1D,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,208 @@
1
+ import Cerebras from "@cerebras/cerebras_cloud_sdk";
2
+ import { ConfigService } from "../../config/ConfigService.js";
3
+ import { JsonUtils } from "../../../plumbing/utils/JsonUtils.js";
4
+ import { getErrorMessage } from "../../../plumbing/utils/ErrorUtils.js";
5
+ export class CerebrasProvider {
6
+ client;
7
+ constructor(apiKey) {
8
+ this.client = new Cerebras({ apiKey });
9
+ }
10
+ async createMessage(params) {
11
+ try {
12
+ const response = await this.client.chat.completions.create({
13
+ model: params.model,
14
+ messages: this.convertMessages(params.messages),
15
+ tools: this.convertTools(params.tools),
16
+ max_tokens: params.max_tokens || 1024,
17
+ });
18
+ const completion = response;
19
+ const choice = completion.choices[0].message;
20
+ if (choice.tool_calls && choice.tool_calls.length > 0) {
21
+ return {
22
+ role: "assistant",
23
+ content: choice.content || "",
24
+ tool_uses: choice.tool_calls.map((tc) => ({
25
+ id: tc.id,
26
+ name: tc.function.name,
27
+ input: JsonUtils.safeParseJson(tc.function.arguments),
28
+ })),
29
+ };
30
+ }
31
+ return {
32
+ role: "assistant",
33
+ content: choice.content || "",
34
+ };
35
+ }
36
+ catch (error) {
37
+ throw new Error(`Cerebras API Error: ${getErrorMessage(error)}`);
38
+ }
39
+ }
40
+ async createMessageStream(params, onUpdate, signal) {
41
+ const startTime = Date.now();
42
+ onUpdate({ type: "run_started", timestamp: startTime });
43
+ onUpdate({
44
+ type: "stage_change",
45
+ stage: "thinking",
46
+ label: "Processing request...",
47
+ });
48
+ try {
49
+ // Cerebras SDK does not natively support AbortSignal in the create method yet,
50
+ // but we can handle the stream consumption loop and break if aborted.
51
+ const stream = await this.client.chat.completions.create({
52
+ model: params.model,
53
+ messages: this.convertMessages(params.messages),
54
+ tools: this.convertTools(params.tools),
55
+ max_tokens: params.max_tokens || 1024,
56
+ stream: true,
57
+ }, { abortSignal: signal });
58
+ // Use array buffers to avoid string concatenation overhead
59
+ const contentBuffer = [];
60
+ const toolCalls = {};
61
+ let hasStartedContent = false;
62
+ for await (const chunk of stream) {
63
+ if (signal?.aborted) {
64
+ throw new Error("Cerebras request aborted by user.");
65
+ }
66
+ const chunkData = chunk;
67
+ const delta = chunkData.choices[0]?.delta;
68
+ if (!delta)
69
+ continue;
70
+ if (delta.content) {
71
+ if (!hasStartedContent) {
72
+ hasStartedContent = true;
73
+ onUpdate({
74
+ type: "stage_change",
75
+ stage: "responding",
76
+ label: "Generating response...",
77
+ });
78
+ }
79
+ contentBuffer.push(delta.content);
80
+ onUpdate({ type: "content_delta", text: delta.content });
81
+ }
82
+ if (delta.tool_calls) {
83
+ onUpdate({
84
+ type: "stage_change",
85
+ stage: "calling_tool",
86
+ label: "Using tool...",
87
+ });
88
+ for (const tc of delta.tool_calls) {
89
+ const index = tc.index;
90
+ if (tc.id) {
91
+ toolCalls[index] = {
92
+ id: tc.id,
93
+ name: tc.function?.name || "",
94
+ inputParts: [],
95
+ };
96
+ onUpdate({
97
+ type: "tool_call_delta",
98
+ index: index,
99
+ id: tc.id,
100
+ name: tc.function?.name,
101
+ });
102
+ }
103
+ if (tc.function?.arguments) {
104
+ if (toolCalls[index]) {
105
+ toolCalls[index].inputParts.push(tc.function.arguments);
106
+ }
107
+ onUpdate({
108
+ type: "tool_call_delta",
109
+ index: index,
110
+ argumentsDelta: tc.function.arguments,
111
+ });
112
+ }
113
+ }
114
+ }
115
+ if (chunk.usage) {
116
+ const usage = chunk.usage;
117
+ onUpdate({
118
+ type: "usage",
119
+ usage: {
120
+ inputTokens: usage.prompt_tokens,
121
+ outputTokens: usage.completion_tokens,
122
+ totalTokens: usage.total_tokens,
123
+ },
124
+ });
125
+ }
126
+ }
127
+ const endTime = Date.now();
128
+ onUpdate({
129
+ type: "run_completed",
130
+ timestamp: endTime,
131
+ durationMs: endTime - startTime,
132
+ });
133
+ // Join array buffers into final strings
134
+ const fullContent = contentBuffer.join("");
135
+ const finalToolUses = Object.values(toolCalls).map((tc) => ({
136
+ id: tc.id,
137
+ name: tc.name,
138
+ input: JsonUtils.safeParseJson(tc.inputParts.join("")),
139
+ }));
140
+ const blocks = [];
141
+ if (fullContent)
142
+ blocks.push({ type: "text", text: fullContent });
143
+ return {
144
+ role: "assistant",
145
+ content: blocks.length > 0 ? blocks : fullContent,
146
+ tool_uses: finalToolUses.length > 0 ? finalToolUses : undefined,
147
+ };
148
+ }
149
+ catch (error) {
150
+ throw new Error(`Cerebras Stream Error: ${getErrorMessage(error)}`);
151
+ }
152
+ }
153
+ estimateTokens(text) {
154
+ return Math.ceil(text.length * ConfigService.getTokensPerChar());
155
+ }
156
+ async listModels() {
157
+ // Hardcoded list for now as Cerebras is compatible with Llama models
158
+ return [
159
+ { id: "llama3.1-8b", name: "Llama 3.1 8B" },
160
+ { id: "llama3.1-70b", name: "Llama 3.1 70B" },
161
+ ];
162
+ }
163
+ convertMessages(messages) {
164
+ // Convert Anthropic-style messages to OpenAI/Cerebras format
165
+ return messages.map((msg) => {
166
+ if (Array.isArray(msg.content)) {
167
+ // Handle tools/text blocks
168
+ const content = msg.content.map((block) => {
169
+ if (block.type === "text")
170
+ return { type: "text", text: block.text };
171
+ // ... other block conversions if necessary, Cerebras expects standard OpenAI format usually
172
+ return block;
173
+ });
174
+ // Simplification: join text parts if valid
175
+ const textParts = msg.content
176
+ .filter((c) => c.type === "text")
177
+ .map((c) => c.text)
178
+ .join("");
179
+ // Check for tool result
180
+ const toolResult = msg.content.find((c) => c.type === "tool_result");
181
+ if (toolResult) {
182
+ return {
183
+ role: "tool",
184
+ tool_call_id: toolResult.tool_use_id,
185
+ content: typeof toolResult.content === "string"
186
+ ? toolResult.content
187
+ : JSON.stringify(toolResult.content),
188
+ };
189
+ }
190
+ return { role: msg.role, content: textParts };
191
+ }
192
+ return { role: msg.role, content: msg.content };
193
+ });
194
+ }
195
+ convertTools(tools) {
196
+ if (!tools)
197
+ return undefined;
198
+ return tools.map((tool) => ({
199
+ type: "function",
200
+ function: {
201
+ name: tool.name,
202
+ description: tool.description,
203
+ parameters: tool.input_schema,
204
+ },
205
+ }));
206
+ }
207
+ }
208
+ //# sourceMappingURL=CerebrasProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CerebrasProvider.js","sourceRoot":"","sources":["../../../../../src/monolith/infrastructure/ai/providers/CerebrasProvider.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,8BAA8B,CAAC;AAOpD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAW;IAEzB,YAAY,MAAc;QACxB,IAA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