@mcoda/mswarm 0.1.135-codali.2 → 0.1.135-codali.32

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 (339) hide show
  1. package/README.md +5 -0
  2. package/dist/codali-executor.d.ts +19 -0
  3. package/dist/codali-executor.d.ts.map +1 -1
  4. package/dist/codali-executor.js +54 -2
  5. package/dist/codali-executor.js.map +1 -1
  6. package/dist/runtime.d.ts +3 -0
  7. package/dist/runtime.d.ts.map +1 -1
  8. package/dist/runtime.js +13 -5
  9. package/dist/runtime.js.map +1 -1
  10. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts +5 -0
  11. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts.map +1 -0
  12. package/dist/vendor/codali/cli/TerminalArtifacts.js +26 -0
  13. package/dist/vendor/codali/cli/TerminalCommand.d.ts +2 -1
  14. package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -1
  15. package/dist/vendor/codali/cli/TerminalCommand.js +436 -100
  16. package/dist/vendor/codali/cli/TerminalCredentials.js +2 -2
  17. package/dist/vendor/codali/cli/TerminalInput.d.ts +13 -0
  18. package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -1
  19. package/dist/vendor/codali/cli/TerminalInput.js +55 -7
  20. package/dist/vendor/codali/cli/TerminalModels.d.ts +6 -0
  21. package/dist/vendor/codali/cli/TerminalModels.d.ts.map +1 -0
  22. package/dist/vendor/codali/cli/TerminalModels.js +45 -0
  23. package/dist/vendor/codali/cli/TerminalPlan.d.ts +40 -0
  24. package/dist/vendor/codali/cli/TerminalPlan.d.ts.map +1 -0
  25. package/dist/vendor/codali/cli/TerminalPlan.js +37 -0
  26. package/dist/vendor/codali/cli/ToolsCommand.d.ts.map +1 -1
  27. package/dist/vendor/codali/cli/ToolsCommand.js +8 -1
  28. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts +6 -0
  29. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts.map +1 -0
  30. package/dist/vendor/codali/cli/tui/TerminalCells.js +47 -0
  31. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts +22 -0
  32. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts.map +1 -0
  33. package/dist/vendor/codali/cli/tui/TerminalEditor.js +88 -0
  34. package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts +6 -0
  35. package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts.map +1 -0
  36. package/dist/vendor/codali/cli/tui/TerminalLogo.js +26 -0
  37. package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts +5 -0
  38. package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts.map +1 -0
  39. package/dist/vendor/codali/cli/tui/TerminalMarkdown.js +118 -0
  40. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts +6 -0
  41. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts.map +1 -0
  42. package/dist/vendor/codali/cli/tui/TerminalPresentation.js +152 -0
  43. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts +50 -0
  44. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts.map +1 -0
  45. package/dist/vendor/codali/cli/tui/TerminalScreen.js +137 -0
  46. package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts +15 -0
  47. package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts.map +1 -0
  48. package/dist/vendor/codali/cli/tui/TerminalSelection.js +38 -0
  49. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts +82 -0
  50. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts.map +1 -0
  51. package/dist/vendor/codali/cli/tui/TerminalTui.js +564 -0
  52. package/dist/vendor/codali/cli.d.ts.map +1 -1
  53. package/dist/vendor/codali/cli.js +5 -3
  54. package/dist/vendor/codali/config/OrchestrationConfig.d.ts +40 -0
  55. package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
  56. package/dist/vendor/codali/config/OrchestrationConfig.js +74 -3
  57. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +2 -1
  58. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -1
  59. package/dist/vendor/codali/connectors/media/MediaJobStore.js +11 -3
  60. package/dist/vendor/codali/docdex/DocdexCatalog.d.ts +12 -0
  61. package/dist/vendor/codali/docdex/DocdexCatalog.d.ts.map +1 -0
  62. package/dist/vendor/codali/docdex/DocdexCatalog.js +30 -0
  63. package/dist/vendor/codali/docdex/DocdexClient.d.ts +9 -2
  64. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
  65. package/dist/vendor/codali/docdex/DocdexClient.js +86 -11
  66. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +4 -0
  67. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -1
  68. package/dist/vendor/codali/docdex/ManagedDocdex.js +42 -5
  69. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +1 -1
  70. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -1
  71. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +9 -6
  72. package/dist/vendor/codali/eval/TrustBenchmark.d.ts +94 -0
  73. package/dist/vendor/codali/eval/TrustBenchmark.d.ts.map +1 -0
  74. package/dist/vendor/codali/eval/TrustBenchmark.js +199 -0
  75. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
  76. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
  77. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
  78. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
  79. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
  80. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
  81. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -1
  82. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +14 -1
  83. package/dist/vendor/codali/gateway/GroundingMode.d.ts.map +1 -1
  84. package/dist/vendor/codali/gateway/GroundingMode.js +23 -3
  85. package/dist/vendor/codali/index.d.ts +1 -0
  86. package/dist/vendor/codali/index.d.ts.map +1 -1
  87. package/dist/vendor/codali/index.js +1 -0
  88. package/dist/vendor/codali/permissions/PermissionGate.d.ts +1 -1
  89. package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
  90. package/dist/vendor/codali/permissions/PermissionGate.js +45 -5
  91. package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts +11 -0
  92. package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts.map +1 -0
  93. package/dist/vendor/codali/permissions/WorkspacePermissions.js +42 -0
  94. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +1 -0
  95. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -1
  96. package/dist/vendor/codali/providers/ConfiguredModelScope.js +19 -2
  97. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +6 -0
  98. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
  99. package/dist/vendor/codali/providers/ConfiguredProvider.js +88 -34
  100. package/dist/vendor/codali/providers/ModelCapacityWait.d.ts +21 -0
  101. package/dist/vendor/codali/providers/ModelCapacityWait.d.ts.map +1 -0
  102. package/dist/vendor/codali/providers/ModelCapacityWait.js +40 -0
  103. package/dist/vendor/codali/providers/ModelServiceError.d.ts +16 -2
  104. package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
  105. package/dist/vendor/codali/providers/ModelServiceError.js +37 -5
  106. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
  107. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +26 -3
  108. package/dist/vendor/codali/providers/ProviderTypes.d.ts +6 -0
  109. package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
  110. package/dist/vendor/codali/providers/RequestSize.d.ts +5 -0
  111. package/dist/vendor/codali/providers/RequestSize.d.ts.map +1 -0
  112. package/dist/vendor/codali/providers/RequestSize.js +10 -0
  113. package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
  114. package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
  115. package/dist/vendor/codali/providers/RequestUsage.js +33 -0
  116. package/dist/vendor/codali/runtime/AnswerVerification.d.ts +17 -0
  117. package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -0
  118. package/dist/vendor/codali/runtime/AnswerVerification.js +39 -0
  119. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +1 -0
  120. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
  121. package/dist/vendor/codali/runtime/CodaliRuntime.js +1 -0
  122. package/dist/vendor/codali/runtime/CompletionReport.d.ts +2 -0
  123. package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
  124. package/dist/vendor/codali/runtime/CompletionReport.js +17 -0
  125. package/dist/vendor/codali/runtime/ComputedAnswer.d.ts +13 -0
  126. package/dist/vendor/codali/runtime/ComputedAnswer.d.ts.map +1 -0
  127. package/dist/vendor/codali/runtime/ComputedAnswer.js +75 -0
  128. package/dist/vendor/codali/runtime/ContextCompression.d.ts +38 -0
  129. package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -0
  130. package/dist/vendor/codali/runtime/ContextCompression.js +263 -0
  131. package/dist/vendor/codali/runtime/GatewayRequest.d.ts +5 -0
  132. package/dist/vendor/codali/runtime/GatewayRequest.d.ts.map +1 -0
  133. package/dist/vendor/codali/runtime/GatewayRequest.js +19 -0
  134. package/dist/vendor/codali/runtime/InspectionBudget.d.ts +11 -0
  135. package/dist/vendor/codali/runtime/InspectionBudget.d.ts.map +1 -0
  136. package/dist/vendor/codali/runtime/InspectionBudget.js +23 -0
  137. package/dist/vendor/codali/runtime/InspectionConvergence.d.ts +24 -0
  138. package/dist/vendor/codali/runtime/InspectionConvergence.d.ts.map +1 -0
  139. package/dist/vendor/codali/runtime/InspectionConvergence.js +67 -0
  140. package/dist/vendor/codali/runtime/InteractionContract.d.ts +44 -0
  141. package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -0
  142. package/dist/vendor/codali/runtime/InteractionContract.js +64 -0
  143. package/dist/vendor/codali/runtime/InteractionRouter.d.ts +73 -0
  144. package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -0
  145. package/dist/vendor/codali/runtime/InteractionRouter.js +138 -0
  146. package/dist/vendor/codali/runtime/PlanCoverage.d.ts +9 -0
  147. package/dist/vendor/codali/runtime/PlanCoverage.d.ts.map +1 -0
  148. package/dist/vendor/codali/runtime/PlanCoverage.js +12 -0
  149. package/dist/vendor/codali/runtime/PreparedDocdex.d.ts +4 -0
  150. package/dist/vendor/codali/runtime/PreparedDocdex.d.ts.map +1 -0
  151. package/dist/vendor/codali/runtime/PreparedDocdex.js +55 -0
  152. package/dist/vendor/codali/runtime/PreparedMemory.d.ts +3 -0
  153. package/dist/vendor/codali/runtime/PreparedMemory.d.ts.map +1 -0
  154. package/dist/vendor/codali/runtime/PreparedMemory.js +30 -0
  155. package/dist/vendor/codali/runtime/ProgressTracker.d.ts +1 -0
  156. package/dist/vendor/codali/runtime/ProgressTracker.d.ts.map +1 -1
  157. package/dist/vendor/codali/runtime/ProgressTracker.js +25 -5
  158. package/dist/vendor/codali/runtime/ResearchEvidence.d.ts +19 -0
  159. package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -0
  160. package/dist/vendor/codali/runtime/ResearchEvidence.js +55 -0
  161. package/dist/vendor/codali/runtime/ReviewContract.d.ts +35 -0
  162. package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
  163. package/dist/vendor/codali/runtime/ReviewContract.js +132 -0
  164. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +43 -0
  165. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
  166. package/dist/vendor/codali/runtime/ReviewCoordinator.js +134 -0
  167. package/dist/vendor/codali/runtime/ReviewSource.d.ts +3 -0
  168. package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
  169. package/dist/vendor/codali/runtime/ReviewSource.js +17 -1
  170. package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
  171. package/dist/vendor/codali/runtime/Runner.js +6 -1
  172. package/dist/vendor/codali/runtime/SessionController.d.ts +71 -5
  173. package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
  174. package/dist/vendor/codali/runtime/SessionController.js +1913 -223
  175. package/dist/vendor/codali/runtime/SpecialistTools.d.ts +6 -0
  176. package/dist/vendor/codali/runtime/SpecialistTools.d.ts.map +1 -0
  177. package/dist/vendor/codali/runtime/SpecialistTools.js +69 -0
  178. package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +4 -2
  179. package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -1
  180. package/dist/vendor/codali/runtime/StructuralEvidence.js +22 -5
  181. package/dist/vendor/codali/runtime/TaskReview.d.ts +25 -0
  182. package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
  183. package/dist/vendor/codali/runtime/TaskReview.js +109 -0
  184. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +37 -0
  185. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -1
  186. package/dist/vendor/codali/runtime/TaskReviewContext.js +18 -2
  187. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
  188. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
  189. package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -0
  190. package/dist/vendor/codali/runtime/VerificationCommand.d.ts +2 -0
  191. package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
  192. package/dist/vendor/codali/runtime/VerificationCommand.js +28 -0
  193. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
  194. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
  195. package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -0
  196. package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts +2 -0
  197. package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts.map +1 -1
  198. package/dist/vendor/codali/runtime/WorkspaceLedger.js +44 -20
  199. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -1
  200. package/dist/vendor/codali/runtime/WorkspaceLock.js +9 -1
  201. package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts.map +1 -1
  202. package/dist/vendor/codali/runtime/WorkspaceSnapshot.js +3 -2
  203. package/dist/vendor/codali/runtime/WriteSyntaxCheck.d.ts +10 -0
  204. package/dist/vendor/codali/runtime/WriteSyntaxCheck.d.ts.map +1 -0
  205. package/dist/vendor/codali/runtime/WriteSyntaxCheck.js +34 -0
  206. package/dist/vendor/codali/session/AtomicState.d.ts.map +1 -1
  207. package/dist/vendor/codali/session/AtomicState.js +15 -1
  208. package/dist/vendor/codali/session/InstructionLoader.d.ts +5 -1
  209. package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -1
  210. package/dist/vendor/codali/session/InstructionLoader.js +65 -19
  211. package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -1
  212. package/dist/vendor/codali/session/SessionStoragePath.js +34 -17
  213. package/dist/vendor/codali/session/SessionStore.d.ts +5 -1
  214. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
  215. package/dist/vendor/codali/session/SessionStore.js +11 -2
  216. package/dist/vendor/codali/session/SkillCatalog.d.ts +33 -0
  217. package/dist/vendor/codali/session/SkillCatalog.d.ts.map +1 -0
  218. package/dist/vendor/codali/session/SkillCatalog.js +197 -0
  219. package/dist/vendor/codali/session/WorkState.d.ts +11 -0
  220. package/dist/vendor/codali/session/WorkState.d.ts.map +1 -1
  221. package/dist/vendor/codali/session/WorkState.js +46 -2
  222. package/dist/vendor/codali/session/WorkTypes.d.ts +8 -0
  223. package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -1
  224. package/dist/vendor/codali/session/WorkspaceScope.d.ts +3 -0
  225. package/dist/vendor/codali/session/WorkspaceScope.d.ts.map +1 -0
  226. package/dist/vendor/codali/session/WorkspaceScope.js +19 -0
  227. package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts +19 -0
  228. package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts.map +1 -0
  229. package/dist/vendor/codali/tools/SemanticToolRetrieval.js +52 -0
  230. package/dist/vendor/codali/tools/ToolRetrieval.d.ts +7 -0
  231. package/dist/vendor/codali/tools/ToolRetrieval.d.ts.map +1 -0
  232. package/dist/vendor/codali/tools/ToolRetrieval.js +25 -0
  233. package/dist/vendor/codali/tools/ToolTypes.d.ts +2 -0
  234. package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
  235. package/dist/vendor/codali/tools/browser/BrowserSessionTool.d.ts +16 -0
  236. package/dist/vendor/codali/tools/browser/BrowserSessionTool.d.ts.map +1 -0
  237. package/dist/vendor/codali/tools/browser/BrowserSessionTool.js +326 -0
  238. package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +17 -0
  239. package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -0
  240. package/dist/vendor/codali/tools/browser/BrowserTool.js +291 -0
  241. package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts +2 -0
  242. package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts.map +1 -0
  243. package/dist/vendor/codali/tools/browser/BrowserWorker.js +121 -0
  244. package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +5 -0
  245. package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -0
  246. package/dist/vendor/codali/tools/calculation/CalculatorTool.js +163 -0
  247. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts +39 -0
  248. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts.map +1 -0
  249. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.js +98 -0
  250. package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts +8 -0
  251. package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts.map +1 -0
  252. package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +100 -0
  253. package/dist/vendor/codali/tools/deterministic/node-worker.cjs +38 -0
  254. package/dist/vendor/codali/tools/deterministic/python-worker.py +237 -0
  255. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts +4 -0
  256. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts.map +1 -0
  257. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.js +59 -0
  258. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
  259. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
  260. package/dist/vendor/codali/tools/docdex/DocdexTools.js +81 -106
  261. package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts +12 -0
  262. package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts.map +1 -0
  263. package/dist/vendor/codali/tools/documents/DocumentRuntime.js +59 -0
  264. package/dist/vendor/codali/tools/documents/DocumentTools.d.ts +19 -0
  265. package/dist/vendor/codali/tools/documents/DocumentTools.d.ts.map +1 -0
  266. package/dist/vendor/codali/tools/documents/DocumentTools.js +150 -0
  267. package/dist/vendor/codali/tools/documents/worker.py +267 -0
  268. package/dist/vendor/codali/tools/entities/AdesTool.d.ts +7 -0
  269. package/dist/vendor/codali/tools/entities/AdesTool.d.ts.map +1 -0
  270. package/dist/vendor/codali/tools/entities/AdesTool.js +59 -0
  271. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -1
  272. package/dist/vendor/codali/tools/filesystem/FileTools.js +58 -11
  273. package/dist/vendor/codali/tools/research/TnlTool.d.ts +22 -0
  274. package/dist/vendor/codali/tools/research/TnlTool.d.ts.map +1 -0
  275. package/dist/vendor/codali/tools/research/TnlTool.js +246 -0
  276. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +7 -0
  277. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
  278. package/dist/vendor/codali/tools/shell/AsyncProcess.js +9 -3
  279. package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -1
  280. package/dist/vendor/codali/tools/shell/HostToolchain.js +37 -5
  281. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +4 -2
  282. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
  283. package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +126 -27
  284. package/dist/vendor/codali/tools/shell/ShellTool.d.ts +2 -0
  285. package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
  286. package/dist/vendor/codali/tools/shell/ShellTool.js +18 -4
  287. package/dist/vendor/codali/tools/system/CalendarTool.d.ts +15 -0
  288. package/dist/vendor/codali/tools/system/CalendarTool.d.ts.map +1 -0
  289. package/dist/vendor/codali/tools/system/CalendarTool.js +44 -0
  290. package/dist/vendor/codali/tools/system/TextTool.d.ts +4 -0
  291. package/dist/vendor/codali/tools/system/TextTool.d.ts.map +1 -0
  292. package/dist/vendor/codali/tools/system/TextTool.js +39 -0
  293. package/dist/vendor/codali/tools/system/TimeTool.d.ts +4 -0
  294. package/dist/vendor/codali/tools/system/TimeTool.d.ts.map +1 -0
  295. package/dist/vendor/codali/tools/system/TimeTool.js +22 -0
  296. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts +47 -0
  297. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -0
  298. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +71 -0
  299. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts +2 -0
  300. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts.map +1 -0
  301. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.js +91 -0
  302. package/dist/vendor/codali/tools/verification/VitestTool.d.ts +6 -0
  303. package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -0
  304. package/dist/vendor/codali/tools/verification/VitestTool.js +184 -0
  305. package/dist/vendor/config/AGENTS.md +17 -0
  306. package/dist/vendor/config/deterministic/install-python.mjs +16 -0
  307. package/dist/vendor/config/deterministic/node-worker.mjs +77 -0
  308. package/dist/vendor/config/deterministic/python-worker.py +237 -0
  309. package/dist/vendor/config/deterministic/requirements.txt +6 -0
  310. package/dist/vendor/config/docdex-runtime.json +21 -0
  311. package/dist/vendor/config/docdex-tools-0.2.99.json +3977 -0
  312. package/dist/vendor/config/documents/install-python.mjs +16 -0
  313. package/dist/vendor/config/documents/requirements.txt +10 -0
  314. package/dist/vendor/config/documents/worker.py +267 -0
  315. package/dist/vendor/config/skills/architecture-design/SKILL.md +14 -0
  316. package/dist/vendor/config/skills/browser-session/SKILL.md +16 -0
  317. package/dist/vendor/config/skills/browser-use/SKILL.md +14 -0
  318. package/dist/vendor/config/skills/code-implementation/SKILL.md +18 -0
  319. package/dist/vendor/config/skills/code-review/SKILL.md +14 -0
  320. package/dist/vendor/config/skills/docdex-research/SKILL.md +18 -0
  321. package/dist/vendor/config/skills/docdex-research/references/catalog.md +111 -0
  322. package/dist/vendor/config/skills/docdex-research/references/memory.md +22 -0
  323. package/dist/vendor/config/skills/docdex-research/references/operations.md +19 -0
  324. package/dist/vendor/config/skills/docdex-research/references/retrieval.md +13 -0
  325. package/dist/vendor/config/skills/planning/SKILL.md +14 -0
  326. package/dist/vendor/config/skills/system-diagnostics/SKILL.md +14 -0
  327. package/dist/vendor/config/skills/system-services/SKILL.md +17 -0
  328. package/dist/vendor/config/skills/system-services/references/docker.md +11 -0
  329. package/dist/vendor/config/skills/system-services/references/linux.md +9 -0
  330. package/dist/vendor/config/skills/system-services/references/macos.md +9 -0
  331. package/dist/vendor/config/skills/systematic-debugging/SKILL.md +14 -0
  332. package/dist/vendor/config/skills/testing-and-verification/SKILL.md +16 -0
  333. package/dist/vendor/config/skills/tool-selection/SKILL.md +16 -0
  334. package/dist/vendor/config/skills/ui-ux-design/SKILL.md +16 -0
  335. package/dist/vendor/config/skills/ui-ux-design/references/validation.md +13 -0
  336. package/dist/vendor/config/skills/webapp-testing/SKILL.md +12 -0
  337. package/package.json +15 -5
  338. package/scripts/media_gpu_lock.py +2 -2
  339. package/scripts/native_load_guard.py +257 -0
@@ -1,11 +1,14 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
+ import { setTimeout as delay } from "node:timers/promises";
3
4
  import { CryptoHelper, PathHelper, mswarmClientProductHeaders } from "@mcoda/shared";
4
5
  import { resolveCredential } from "../runcontext/CredentialFile.js";
5
6
  import { resolveBinding } from "../config/OrchestrationConfig.js";
6
7
  import { OpenAiCompatibleProvider } from "./OpenAiCompatibleProvider.js";
7
8
  import { ModelServiceError } from "./ModelServiceError.js";
9
+ import { parseRequestUsage } from "./RequestUsage.js";
8
10
  import { registerSecretValue } from "../runtime/SecretRedaction.js";
11
+ import { estimateProviderInputTokens } from "./RequestSize.js";
9
12
  export const normalizeModelCaller = (caller = {}) => {
10
13
  const clientIdentity = caller.clientIdentity?.trim();
11
14
  const clientProduct = caller.clientProduct?.trim().toLowerCase() ?? "codali";
@@ -107,25 +110,46 @@ export class ModelServiceClient {
107
110
  options.signal?.removeEventListener("abort", abort);
108
111
  }
109
112
  }
113
+ /** Retry only read-only discovery on explicit temporary service failures.
114
+ * Never reuse this for submission, reconciliation mutations or auth denials. */
115
+ async discoveryJson(url, signal) {
116
+ for (let attempt = 0;; attempt++) {
117
+ signal?.throwIfAborted();
118
+ try {
119
+ return await this.json(url, { signal });
120
+ }
121
+ catch (error) {
122
+ signal?.throwIfAborted();
123
+ if (!(error instanceof ModelServiceError) || error.code !== "service_unavailable" || attempt >= 2)
124
+ throw error;
125
+ const retryAfterMs = (error.retryAfterSeconds ?? 0) * 1000;
126
+ if (retryAfterMs > 5000)
127
+ throw error;
128
+ await delay(Math.max(attempt === 0 ? 250 : 750, retryAfterMs), undefined, { signal });
129
+ }
130
+ }
131
+ }
110
132
  async catalog(signal, refresh = false) {
111
133
  const credential = await this.credential();
112
134
  const key = createHash("sha256").update(credential ?? "anonymous").digest("hex");
113
135
  if (!refresh && this.cache?.key === key && this.cache.expires > Date.now())
114
136
  return this.cache.entries;
115
137
  const base = new URL(this.provider.baseUrl);
116
- const url = this.provider.catalogUrl ?? (this.provider.adapter === "mswarm" ? new URL("/v1/swarm/self-hosted/agents", base).toString() : `${this.provider.baseUrl.replace(/\/$/, "")}/models`);
117
- const payload = record(await this.json(url, { signal }));
138
+ const url = this.provider.catalogUrl ?? (this.provider.adapter === "mswarm" ? new URL("/v1/swarm/self-hosted/agents?include_load_balanced=true", base).toString() : `${this.provider.baseUrl.replace(/\/$/, "")}/models`);
139
+ const payload = record(await this.discoveryJson(url, signal));
118
140
  const items = payload.agents ?? payload.data;
119
141
  if (!Array.isArray(items))
120
142
  throw new Error("Invalid model catalog response");
121
143
  const entries = items.map(item => {
122
144
  const raw = record(item);
123
- const aliases = [raw.slug, raw.public_model_id, raw.default_model, raw.id].filter((v) => typeof v === "string" && !!v);
145
+ const aliases = [raw.slug, raw.public_model_id, raw.default_model, raw.id, ...(raw.pool_scope === "owner" ? [raw.canonical_model_id] : [])].filter((v) => typeof v === "string" && !!v);
124
146
  return { id: aliases[0] ?? "", aliases, backend: raw.adapter === "strata-local" ? "strata" : typeof raw.backend === "string" ? raw.backend : typeof raw.adapter === "string" ? raw.adapter : undefined,
125
147
  health: String(raw.health_status ?? "unknown"), supportsTools: raw.supports_tools === true,
126
148
  contextWindow: typeof raw.context_window === "number" ? raw.context_window : undefined,
127
149
  operations: Array.isArray(raw.operations) ? raw.operations.map(v => typeof v === "string" ? v : String(record(v).type ?? "")) : [], raw };
128
150
  }).filter(x => x.id);
151
+ entries.sort((a, b) => Number(b.raw.pool_scope === "owner") - Number(a.raw.pool_scope === "owner")
152
+ || Number(b.raw.member_count ?? 0) - Number(a.raw.member_count ?? 0) || a.id.localeCompare(b.id));
129
153
  this.cache = { key, expires: Date.now() + 30000, entries };
130
154
  return entries;
131
155
  }
@@ -134,6 +158,14 @@ export class ModelServiceClient {
134
158
  return { available: false };
135
159
  return this.json(this.provider.usageUrl ?? new URL("/v1/swarm/runtime/usage-limits", this.provider.baseUrl).toString(), { signal });
136
160
  }
161
+ async requestUsage(requestId, signal) {
162
+ if (this.provider.adapter !== "mswarm")
163
+ throw new Error("Provider has no authenticated request receipt contract");
164
+ if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId))
165
+ throw new Error("Invalid request UUID");
166
+ const url = new URL(`/v1/swarm/self-hosted/requests/${encodeURIComponent(requestId)}/receipts`, this.provider.baseUrl);
167
+ return parseRequestUsage(requestId, await this.json(url.href, { signal, timeoutMs: 10000 }));
168
+ }
137
169
  /** The proxy and selected node must both advertise this transport contract.
138
170
  * A model's supports_reasoning flag alone says nothing about request forwarding. */
139
171
  async requireNativeReasoning(modelId, parameters, signal) {
@@ -143,7 +175,7 @@ export class ModelServiceClient {
143
175
  endpoint.pathname = endpoint.pathname.replace(/\/$/, "");
144
176
  endpoint.pathname = ["", "/v1"].includes(endpoint.pathname)
145
177
  ? "/v1/swarm/self-hosted/openai/models" : `${endpoint.pathname}/models`;
146
- const payload = record(await this.json(endpoint.href, { signal }).catch(error => {
178
+ const payload = record(await this.discoveryJson(endpoint.href, signal).catch(error => {
147
179
  throw new NativeReasoningTransportError(`Native reasoning preflight failed before inference: ${error instanceof Error ? error.message : String(error)}`);
148
180
  }));
149
181
  const models = Array.isArray(payload.data) ? payload.data.map(record) : [];
@@ -182,53 +214,75 @@ export class ConfiguredProvider {
182
214
  async select(operation, signal, requireTools = false) {
183
215
  const candidates = resolveBinding(this.resolved.config, this.binding, operation);
184
216
  const reasons = [];
217
+ const refreshed = new Set();
185
218
  for (const candidate of candidates) {
186
219
  const { id, model } = candidate;
187
- const catalog = await this.client(model.provider).catalog(signal);
188
- const actual = catalog.find(entry => entry.aliases.includes(model.catalogId));
189
- if (!actual) {
190
- reasons.push(`${id}: not entitled/advertised`);
191
- continue;
192
- }
193
- if (!["healthy", "unknown", "ready"].includes(actual.health)) {
194
- reasons.push(`${id}: ${actual.health}`);
195
- continue;
196
- }
197
- if (model.backend && actual.backend !== model.backend) {
198
- reasons.push(`${id}: backend identity not verified`);
199
- continue;
200
- }
201
- if (actual.operations.length && !actual.operations.includes(operation)) {
202
- reasons.push(`${id}: unsupported operation`);
203
- continue;
204
- }
205
- if (requireTools && (!model.supportsTools || this.resolved.config.providers[model.provider].adapter === "mswarm" && !actual.supportsTools)) {
206
- reasons.push(`${id}: tools unavailable`);
207
- continue;
220
+ const client = this.client(model.provider);
221
+ let catalog = await client.catalog(signal);
222
+ for (;;) {
223
+ // A canonical model alias can identify several pools/backends. Inspect
224
+ // every matching entry, but never widen an explicitly pinned pool ID.
225
+ const exact = catalog.filter(entry => entry.id === model.catalogId);
226
+ const matches = exact.length ? exact : catalog.filter(entry => entry.aliases.includes(model.catalogId));
227
+ let transient = false;
228
+ const failures = [];
229
+ for (const actual of matches) {
230
+ if (model.backend && actual.backend !== model.backend) {
231
+ failures.push("backend identity not verified");
232
+ continue;
233
+ }
234
+ if (actual.operations.length && !actual.operations.includes(operation)) {
235
+ failures.push("unsupported operation");
236
+ continue;
237
+ }
238
+ if (requireTools && (!model.supportsTools || this.resolved.config.providers[model.provider].adapter === "mswarm" && !actual.supportsTools)) {
239
+ failures.push("tools unavailable");
240
+ continue;
241
+ }
242
+ if (!["healthy", "unknown", "ready"].includes(actual.health)) {
243
+ failures.push(actual.health);
244
+ transient || (transient = ["unreachable", "unhealthy", "offline"].includes(actual.health));
245
+ continue;
246
+ }
247
+ return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
248
+ }
249
+ // Revalidate temporary health once instead of failing from a stale
250
+ // 30-second cache. Entitlement/quota/capability denials remain final.
251
+ if (transient && !refreshed.has(model.provider)) {
252
+ refreshed.add(model.provider);
253
+ catalog = await client.catalog(signal, true);
254
+ continue;
255
+ }
256
+ reasons.push(`${id}: ${failures.join(", ") || "not entitled/advertised"}`);
257
+ break;
208
258
  }
209
- return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
210
259
  }
211
260
  throw new Error(`No eligible configured ${this.binding} route: ${reasons.join("; ")}`);
212
261
  }
213
262
  async generate(request) {
214
263
  request.signal?.throwIfAborted();
264
+ const requestId = request.requestId ?? randomUUID();
265
+ if (typeof requestId !== "string" || !/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId)) {
266
+ throw new Error("Model requestId must be a UUID for this inference attempt");
267
+ }
215
268
  const { id, model, provider, actual } = await this.select("chat.completions", request.signal, !!request.tools?.length);
216
- const invocation = { id: randomUUID(), binding: this.binding, configHash: this.resolved.hash, modelId: id, catalogId: model.catalogId, backend: actual.backend, host: model.host };
269
+ const invocation = { id: requestId, binding: this.binding, configHash: this.resolved.hash, modelId: id, catalogId: model.catalogId, resolvedCatalogId: actual.id, backend: actual.backend, host: model.host };
217
270
  const nativeReasoning = this.options.effort ? model.reasoning?.[this.options.effort] : undefined;
218
271
  if (nativeReasoning)
219
272
  invocation.nativeReasoningRequest = { ...nativeReasoning };
220
273
  if (nativeReasoning)
221
- await this.client(model.provider).requireNativeReasoning(model.catalogId, Object.keys(nativeReasoning), request.signal);
222
- const maxTokens = Math.min(request.maxTokens ?? model.maxOutputTokens, model.maxOutputTokens);
223
- const inputEstimate = Math.ceil(JSON.stringify([request.messages, request.tools]).length / 3);
224
- if (inputEstimate + maxTokens > Math.min(model.contextWindow, actual.contextWindow ?? model.contextWindow))
274
+ await this.client(model.provider).requireNativeReasoning(actual.id, Object.keys(nativeReasoning), request.signal);
275
+ const inputEstimate = estimateProviderInputTokens(request);
276
+ const available = Math.floor(Math.min(model.contextWindow, actual.contextWindow ?? model.contextWindow) - inputEstimate);
277
+ if (available < 128)
225
278
  throw new Error("Context budget exceeded; checkpoint and compact before continuing");
226
- const bounded = { ...request, maxTokens, stream: request.stream === true && model.supportsStreaming === true };
279
+ const maxTokens = Math.min(request.maxTokens ?? model.maxOutputTokens, model.maxOutputTokens, available);
280
+ const bounded = { ...request, requestId, maxTokens, stream: request.stream === true && model.supportsStreaming === true };
227
281
  await this.options.beforeRequest?.(invocation, bounded);
228
282
  const adapter = new OpenAiCompatibleProvider({
229
- model: model.catalogId, baseUrl: provider.baseUrl, apiKey: this.credentials[model.provider] ?? await providerCredential(provider), timeoutMs: 300000,
283
+ model: provider.adapter === "mswarm" ? actual.id : model.catalogId, baseUrl: provider.baseUrl, apiKey: this.credentials[model.provider] ?? await providerCredential(provider), timeoutMs: 86400000,
230
284
  supportsStreaming: model.supportsStreaming ?? true, supportsTools: model.supportsTools,
231
- headers: provider.adapter === "mswarm" ? modelCallerHeaders(this.caller) : undefined, retryTransient: false,
285
+ headers: provider.adapter === "mswarm" ? { ...modelCallerHeaders(this.caller), "x-request-id": requestId } : undefined, retryTransient: false,
232
286
  extraBody: nativeReasoning,
233
287
  });
234
288
  const result = await adapter.generate(bounded);
@@ -0,0 +1,21 @@
1
+ import { ModelServiceError } from "./ModelServiceError.js";
2
+ import type { ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
3
+ export declare const MODEL_CAPACITY_WAIT_MS: number;
4
+ /** An explicit shared-pool refusal: the service rejected the request before any
5
+ * inference ran, so it costs nothing and waiting is the correct response. */
6
+ export declare const isCapacityRefusal: (error: unknown) => error is ModelServiceError;
7
+ /** Delay before the next capacity retry, or undefined when waiting should stop.
8
+ * Long Retry-After values remain refusals rather than silent multi-minute stalls. */
9
+ export declare function capacityRetryDelayMs(error: unknown, attempt: number, waitedMs: number, maxWaitMs?: number, random?: () => number): number | undefined;
10
+ /** Shared capacity policy for callers without Codali's session recovery, so a
11
+ * comparison arm is not failed by contention the other arm waits through. */
12
+ export declare function generateWithCapacityWait(generate: (request: ProviderRequest) => Promise<ProviderResponse>, request: ProviderRequest, options?: {
13
+ maxWaitMs?: number;
14
+ onWait?: (details: {
15
+ attempt: number;
16
+ waitMs: number;
17
+ waitedMs: number;
18
+ error: ModelServiceError;
19
+ }) => void | Promise<void>;
20
+ }): Promise<ProviderResponse>;
21
+ //# sourceMappingURL=ModelCapacityWait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelCapacityWait.d.ts","sourceRoot":"","sources":["../../src/providers/ModelCapacityWait.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAIlD;6EAC6E;AAC7E,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,iBAC4C,CAAC;AAEzG;qFACqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,SAAyB,EAAE,MAAM,eAAc,GAAG,MAAM,GAAG,SAAS,CAOpK;AAED;6EAC6E;AAC7E,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,eAAe,EACxI,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,iBAAiB,CAAA;KAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAa9L"}
@@ -0,0 +1,40 @@
1
+ import { setTimeout as delay } from "node:timers/promises";
2
+ import { ModelServiceError } from "./ModelServiceError.js";
3
+ export const MODEL_CAPACITY_WAIT_MS = 30 * 60000;
4
+ const MAX_HONORED_RETRY_AFTER_SECONDS = 30;
5
+ const MAX_BACKOFF_MS = 60000;
6
+ /** An explicit shared-pool refusal: the service rejected the request before any
7
+ * inference ran, so it costs nothing and waiting is the correct response. */
8
+ export const isCapacityRefusal = (error) => error instanceof ModelServiceError
9
+ && error.code === "rate_limited" && (error.responseReason === "capacity_busy" || error.status === 429);
10
+ /** Delay before the next capacity retry, or undefined when waiting should stop.
11
+ * Long Retry-After values remain refusals rather than silent multi-minute stalls. */
12
+ export function capacityRetryDelayMs(error, attempt, waitedMs, maxWaitMs = MODEL_CAPACITY_WAIT_MS, random = Math.random) {
13
+ if (!isCapacityRefusal(error))
14
+ return undefined;
15
+ const retryAfter = error.retryAfterSeconds ?? 0;
16
+ if (retryAfter > MAX_HONORED_RETRY_AFTER_SECONDS)
17
+ return undefined;
18
+ const backoff = Math.min(MAX_BACKOFF_MS, 2000 * 2 ** Math.min(attempt, 10)) * (0.75 + random() * 0.5);
19
+ const waitMs = Math.round(Math.max(backoff, retryAfter * 1000));
20
+ return waitedMs + waitMs > maxWaitMs ? undefined : waitMs;
21
+ }
22
+ /** Shared capacity policy for callers without Codali's session recovery, so a
23
+ * comparison arm is not failed by contention the other arm waits through. */
24
+ export async function generateWithCapacityWait(generate, request, options = {}) {
25
+ let waitedMs = 0;
26
+ for (let attempt = 0;; attempt++) {
27
+ try {
28
+ return await generate(request);
29
+ }
30
+ catch (error) {
31
+ const waitMs = capacityRetryDelayMs(error, attempt, waitedMs, options.maxWaitMs);
32
+ if (waitMs === undefined)
33
+ throw error;
34
+ request.signal?.throwIfAborted();
35
+ await options.onWait?.({ attempt: attempt + 1, waitMs, waitedMs, error: error });
36
+ await delay(waitMs, undefined, { signal: request.signal });
37
+ waitedMs += waitMs;
38
+ }
39
+ }
40
+ }
@@ -1,10 +1,24 @@
1
- export type ModelServiceErrorCode = "authentication_failed" | "entitlement_missing" | "quota_exhausted" | "rate_limited" | "service_unavailable" | "model_unavailable" | "invalid_request";
1
+ export type ModelServiceErrorCode = "authentication_failed" | "entitlement_missing" | "quota_exhausted" | "rate_limited" | "service_unavailable" | "model_unavailable" | "invalid_request" | "request_conflict" | "invalid_response" | "context_length_exceeded";
2
2
  /** Transport diagnostics contain stable classifications, never an upstream body. */
3
3
  export declare class ModelServiceError extends Error {
4
4
  readonly code: ModelServiceErrorCode;
5
5
  readonly status: number;
6
6
  readonly retryAfterSeconds?: number | undefined;
7
- constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined);
7
+ readonly nativeContextRefused: boolean;
8
+ readonly responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined;
9
+ /** A rejected completion can still carry real usage and recoverable prose.
10
+ * Partial tool arguments are deliberately never exposed for execution. */
11
+ responseUsage?: {
12
+ inputTokens?: number;
13
+ outputTokens?: number;
14
+ totalTokens?: number;
15
+ };
16
+ partialText?: string;
17
+ /** Set by Runner, not inferred from an HTTP status or upstream payload. */
18
+ completedModelCalls?: number;
19
+ constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined, nativeContextRefused?: boolean, responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined);
20
+ /** A relay may already have sent HTTP 200 headers when the model fails. */
21
+ static fromRelayError(error: unknown): ModelServiceError | undefined;
8
22
  static fromResponse(response: Response): Promise<ModelServiceError>;
9
23
  }
10
24
  //# sourceMappingURL=ModelServiceError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelServiceError.d.ts","sourceRoot":"","sources":["../../src/providers/ModelServiceError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,iBAAiB,CAAC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AAoB,UAAQ,EAAW,cAAc,CAAC,EAAE,cAAc,GAAG,mBAAmB,GAAG,eAAe,YAAA;IAOzH,2EAA2E;IAC3E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;WAOvD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA6B1E"}
@@ -1,14 +1,40 @@
1
+ function nativeContextRefusal(error) {
2
+ if (error.type !== "invalid_request_error" || typeof error.message !== "string" || error.message.length > 1024)
3
+ return false;
4
+ // Strata currently emits this pre-generation refusal without a machine code.
5
+ // Match only its bounded numeric diagnostics; never retain prompt text.
6
+ return /^request exceeds the context window: prompt \(\d{1,10} tokens\) leaves no room to answer in the context \(\d{1,10}\); requests are never truncated$/.test(error.message)
7
+ || /^request exceeds the context window: prompt \(\d{1,10} tokens\) \+ max tokens \(\d{1,10}\) exceeds the context \(\d{1,10}\); requests are never truncated\. Send a smaller max_tokens \(at most \d{1,10} here\), or add "fit_max_tokens": true to the model's strata-<model>\.json to shorten it to the room left \(#545\)$/.test(error.message);
8
+ }
1
9
  /** Transport diagnostics contain stable classifications, never an upstream body. */
2
10
  export class ModelServiceError extends Error {
3
- constructor(code, status, retryAfterSeconds) {
4
- super(`Model service HTTP ${status}: ${code}${code === "authentication_failed" ? "; authenticate with codali login" : ""}`);
11
+ constructor(code, status, retryAfterSeconds, nativeContextRefused = false, responseReason) {
12
+ super(`Model service HTTP ${status}: ${code}${responseReason === "output_limit" ? "; the model reached its per-response output limit before finishing. No partial tool call was executed; continue with smaller file patches" : responseReason === "incomplete_stream" ? "; the response stream ended before completion. No partial tool call was executed" : code === "authentication_failed" ? "; authenticate with codali login" : code === "context_length_exceeded" ? "; checkpoint and reduce context before continuing" : ""}`);
5
13
  this.code = code;
6
14
  this.status = status;
7
15
  this.retryAfterSeconds = retryAfterSeconds;
16
+ this.nativeContextRefused = nativeContextRefused;
17
+ this.responseReason = responseReason;
8
18
  this.name = "ModelServiceError";
19
+ if (responseReason === "capacity_busy")
20
+ this.message += "; all compatible model workers are busy; retry after capacity becomes available";
21
+ if (code === "request_conflict")
22
+ this.message += "; the service reported a request conflict. Completion and usage are unconfirmed; inspect request status before retrying";
23
+ }
24
+ /** A relay may already have sent HTTP 200 headers when the model fails. */
25
+ static fromRelayError(error) {
26
+ if (!error || typeof error !== "object")
27
+ return undefined;
28
+ const code = error.code;
29
+ if (code === "context_length_exceeded" || code === "invalid_response" || code === "rate_limited")
30
+ return new ModelServiceError(code, 200);
31
+ return undefined;
9
32
  }
10
33
  static async fromResponse(response) {
11
34
  let serverCode = "";
35
+ let contextRefused = false;
36
+ let nativeRefused = false;
37
+ let capacityBusy = false;
12
38
  if (response.body) {
13
39
  const reader = response.body.getReader();
14
40
  const chunks = [];
@@ -26,6 +52,9 @@ export class ModelServiceError extends Error {
26
52
  const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
27
53
  if (typeof (payload.error?.code ?? payload.code) === "string")
28
54
  serverCode = String(payload.error?.code ?? payload.code);
55
+ capacityBusy = response.status === 409 && serverCode === "conflict" && payload.details?.reason_code === "all_compatible_nodes_busy";
56
+ nativeRefused = response.status === 400 && !!payload.error && nativeContextRefusal(payload.error);
57
+ contextRefused = response.status === 400 && (serverCode === "context_length_exceeded" || nativeRefused);
29
58
  }
30
59
  catch { /* The status still supplies a safe classification. */ }
31
60
  finally {
@@ -36,10 +65,13 @@ export class ModelServiceError extends Error {
36
65
  const code = response.status === 401 ? "authentication_failed"
37
66
  : response.status === 403 ? "entitlement_missing"
38
67
  : ["quota_exceeded", "quota_exhausted", "insufficient_quota", "credits_exhausted", "insufficient_credits"].includes(serverCode) || response.status === 402 ? "quota_exhausted"
39
- : response.status === 429 ? "rate_limited"
68
+ : response.status === 429 || capacityBusy ? "rate_limited"
40
69
  : response.status === 404 ? "model_unavailable"
41
- : response.status >= 500 ? "service_unavailable" : "invalid_request";
70
+ : contextRefused ? "context_length_exceeded"
71
+ : ["structured_output_failed", "invalid_response"].includes(serverCode) ? "invalid_response"
72
+ : response.status === 409 ? "request_conflict"
73
+ : response.status >= 500 ? "service_unavailable" : "invalid_request";
42
74
  const retry = Number(response.headers.get("retry-after"));
43
- return new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : undefined);
75
+ return new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : capacityBusy ? 2 : undefined, nativeRefused, capacityBusy ? "capacity_busy" : undefined);
44
76
  }
45
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAkK5B,eAAO,MAAM,uBAAuB,GAClC,KAAK,MAAM,EACX,MAAM,WAAW,EACjB,aAAa,eAAe,KAC3B,OAAO,CAAC,QAAQ,CAclB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,QAAQ;IAS3C,OAAO,CAAC,MAAM;IAR1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAuB;IAC3B,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,sBAAsB,CAAoC;gBAE9C,MAAM,EAAE,cAAc;IAWpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoPnE,OAAO,CAAC,WAAW;CA0BpB"}
1
+ {"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAmK5B,eAAO,MAAM,uBAAuB,GAClC,KAAK,MAAM,EACX,MAAM,WAAW,EACjB,aAAa,eAAe,KAC3B,OAAO,CAAC,QAAQ,CAclB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,QAAQ;IAS3C,OAAO,CAAC,MAAM;IAR1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAuB;IAC3B,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,sBAAsB,CAAoC;gBAE9C,MAAM,EAAE,cAAc;IAWpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyQnE,OAAO,CAAC,WAAW;CA0BpB"}
@@ -175,7 +175,14 @@ export class OpenAiCompatibleProvider {
175
175
  : undefined;
176
176
  const messages = request.messages.map((message) => ({
177
177
  role: message.role,
178
- content: modelContextText(message.content),
178
+ content: message.images?.length ? [
179
+ { type: "text", text: modelContextText(message.content) },
180
+ ...message.images.map(image => {
181
+ if (message.role !== "user" || !/^data:image\/png;base64,[A-Za-z0-9+/]+=*$/.test(image.dataUrl) || image.dataUrl.length > 3000000)
182
+ throw new Error("Only bounded user PNG images are supported");
183
+ return { type: "image_url", image_url: { url: image.dataUrl } };
184
+ }),
185
+ ] : modelContextText(message.content),
179
186
  name: message.name,
180
187
  tool_call_id: message.toolCallId,
181
188
  tool_calls: message.toolCalls?.map((call) => ({
@@ -276,6 +283,9 @@ export class OpenAiCompatibleProvider {
276
283
  }
277
284
  const chunk = JSON.parse(data);
278
285
  if (chunk.error) {
286
+ const classified = ModelServiceError.fromRelayError(chunk.error);
287
+ if (classified)
288
+ throw classified;
279
289
  const detail = typeof chunk.error === "string" ? chunk.error : JSON.stringify(chunk.error);
280
290
  throw new Error(`OpenAI-compatible stream error: ${this.config.apiKey ? detail.split(this.config.apiKey).join("[redacted]").slice(0, 600) : detail.slice(0, 600)}`);
281
291
  }
@@ -329,8 +339,12 @@ export class OpenAiCompatibleProvider {
329
339
  await reader.cancel().catch(() => undefined);
330
340
  reader.releaseLock();
331
341
  }
332
- if ((!ended && !finishReason) || finishReason === "length")
333
- throw new Error("Model stream ended before a complete response");
342
+ if ((!ended && !finishReason) || finishReason === "length") {
343
+ const error = new ModelServiceError("invalid_response", 200, undefined, false, finishReason === "length" ? "output_limit" : "incomplete_stream");
344
+ error.responseUsage = usage ? { inputTokens: usage.prompt_tokens, outputTokens: usage.completion_tokens, totalTokens: usage.total_tokens } : undefined;
345
+ error.partialText = content || undefined;
346
+ throw error;
347
+ }
334
348
  if (!content && !toolCallMap.size)
335
349
  throw new Error("Model stream returned no content or tool calls");
336
350
  for (const call of toolCallMap.values()) {
@@ -362,6 +376,9 @@ export class OpenAiCompatibleProvider {
362
376
  // A relay can send HTTP 200 keepalives before inference fails. Inspect
363
377
  // the final envelope instead of treating those headers as success.
364
378
  if (raw?.error) {
379
+ const classified = ModelServiceError.fromRelayError(raw.error);
380
+ if (classified)
381
+ throw classified;
365
382
  const error = raw.error;
366
383
  const record = typeof error === "object" && error !== null
367
384
  ? error
@@ -374,6 +391,12 @@ export class OpenAiCompatibleProvider {
374
391
  ? message.split(this.config.apiKey).join("[redacted]") : message;
375
392
  throw new Error(redacted.slice(0, 600));
376
393
  }
394
+ if (raw?.choices?.[0]?.finish_reason === "length") {
395
+ const error = new ModelServiceError("invalid_response", 200, undefined, false, "output_limit");
396
+ error.responseUsage = raw.usage ? { inputTokens: raw.usage.prompt_tokens, outputTokens: raw.usage.completion_tokens, totalTokens: raw.usage.total_tokens } : undefined;
397
+ error.partialText = raw.choices[0].message?.content || undefined;
398
+ throw error;
399
+ }
377
400
  const choice = raw?.choices?.[0]?.message;
378
401
  if (!choice) {
379
402
  throw new Error("OpenAI-compatible response missing choices");
@@ -41,6 +41,10 @@ export interface ProviderResponseFormat {
41
41
  export interface ProviderMessage {
42
42
  role: ProviderRole;
43
43
  content: string;
44
+ /** Host-read bounded PNG screenshots; never arbitrary URLs fetched by the model service. */
45
+ images?: Array<{
46
+ dataUrl: string;
47
+ }>;
44
48
  name?: string;
45
49
  toolCallId?: string;
46
50
  /** Assistant calls retained alongside the matching tool result messages. */
@@ -52,6 +56,8 @@ export interface ProviderUsage {
52
56
  totalTokens?: number;
53
57
  }
54
58
  export interface ProviderRequest {
59
+ /** Unique UUID for this inference attempt, retained by the caller for accounting. */
60
+ requestId?: string;
55
61
  signal?: AbortSignal;
56
62
  messages: ProviderMessage[];
57
63
  tools?: ProviderToolDefinition[];
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderTypes.d.ts","sourceRoot":"","sources":["../../src/providers/ProviderTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EAClC,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAE9E,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAClD;IACE,IAAI,EAA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,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,iCAAiC,CAAC;IAChD,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,sBAAsB,CAAC,EAAE,iCAAiC,CAAC;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,yBAAyB,GAAI,UAAU,QAAQ,KAAG,OAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ProviderRequest } from "./ProviderTypes.js";
2
+ /** Image bytes are not text tokens. Reserve conservatively for bounded screenshots;
3
+ * actual server tokenization and receipts remain authoritative. */
4
+ export declare function estimateProviderInputTokens(request: Pick<ProviderRequest, "messages" | "tools" | "responseFormat">): number;
5
+ //# sourceMappingURL=RequestSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestSize.d.ts","sourceRoot":"","sources":["../../src/providers/RequestSize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;mEACmE;AACnE,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,OAAO,GAAG,gBAAgB,CAAC,GAAG,MAAM,CAO3H"}
@@ -0,0 +1,10 @@
1
+ /** Image bytes are not text tokens. Reserve conservatively for bounded screenshots;
2
+ * actual server tokenization and receipts remain authoritative. */
3
+ export function estimateProviderInputTokens(request) {
4
+ let imageTokens = 0;
5
+ const messages = request.messages.map(({ images, ...message }) => {
6
+ imageTokens += (images?.length ?? 0) * 8192;
7
+ return message;
8
+ });
9
+ return Math.ceil(JSON.stringify({ messages, tools: request.tools, responseFormat: request.responseFormat }).length / 3) + imageTokens;
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { ProviderUsage } from "./ProviderTypes.js";
2
+ export interface RequestUsageReceipt {
3
+ requestId: string;
4
+ complete: boolean;
5
+ invocationIds: string[];
6
+ usage?: Required<ProviderUsage>;
7
+ reason?: string;
8
+ }
9
+ /** A partial page, active attempt or absent counter cannot settle a reservation. */
10
+ export declare function parseRequestUsage(requestId: string, payload: unknown): RequestUsageReceipt;
11
+ //# sourceMappingURL=RequestUsage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestUsage.d.ts","sourceRoot":"","sources":["../../src/providers/RequestUsage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAuB1F"}
@@ -0,0 +1,33 @@
1
+ /** A partial page, active attempt or absent counter cannot settle a reservation. */
2
+ export function parseRequestUsage(requestId, payload) {
3
+ const value = payload;
4
+ if (!value || value.schema_version !== 1 || value.client_request_id !== requestId ||
5
+ typeof value.truncated !== "boolean" || !Array.isArray(value.invocations) ||
6
+ value.invocations.length === 0 || value.invocations.length > 16)
7
+ throw new Error("Invalid request usage receipt");
8
+ const ids = new Set();
9
+ let complete = !value.truncated;
10
+ const usage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
11
+ const valid = (n) => Number.isSafeInteger(n) && n >= 0;
12
+ for (const item of value.invocations) {
13
+ const row = item;
14
+ if (!row || typeof row.id !== "string" || !row.id || row.id.length > 256 || ids.has(row.id) ||
15
+ row.operation !== "chat.completions" || !["reserved", "queued", "leased", "started", "success", "failed", "timeout"].includes(String(row.status))) {
16
+ throw new Error("Invalid request usage invocation");
17
+ }
18
+ ids.add(row.id);
19
+ const tokens = row.usage;
20
+ if (!["success", "failed", "timeout"].includes(String(row.status)) || !tokens ||
21
+ !valid(tokens.prompt_tokens) || !valid(tokens.completion_tokens) || !valid(tokens.total_tokens) ||
22
+ tokens.total_tokens < tokens.prompt_tokens + tokens.completion_tokens) {
23
+ complete = false;
24
+ continue;
25
+ }
26
+ usage.inputTokens += tokens.prompt_tokens;
27
+ usage.outputTokens += tokens.completion_tokens;
28
+ usage.totalTokens += tokens.total_tokens;
29
+ }
30
+ if (!Object.values(usage).every(valid))
31
+ throw new Error("Request usage exceeds safe accounting bounds");
32
+ return { requestId, complete, invocationIds: [...ids], ...(complete ? { usage } : { reason: "Server receipt is incomplete, active, or has unreported usage" }) };
33
+ }
@@ -0,0 +1,17 @@
1
+ export interface ExecutedAnswerCode {
2
+ language: "sql" | "javascript" | "typescript" | "python";
3
+ content: string;
4
+ }
5
+ /** Detect presentation drift, not semantic correctness. A passing execution
6
+ * says nothing about code the model subsequently rewrites in its final answer. */
7
+ export declare function unmatchedExecutedCode(text: string, executed: ExecutedAnswerCode[]): string[];
8
+ /** Recognize only unambiguous standalone source/test pairs. This suggests a
9
+ * verifier invocation; it never executes quoted code or grants permission. */
10
+ export declare function answerTestBundle(text: string): {
11
+ runner: "node" | "python";
12
+ files: Array<{
13
+ path: string;
14
+ content: string;
15
+ }>;
16
+ } | undefined;
17
+ //# sourceMappingURL=AnswerVerification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnswerVerification.d.ts","sourceRoot":"","sources":["../../src/runtime/AnswerVerification.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IAAG,QAAQ,EAAE,KAAK,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAAE;AAElH;kFACkF;AAClF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,CAU5F;AAED;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,SAAS,CAmBzI"}
@@ -0,0 +1,39 @@
1
+ /** Detect presentation drift, not semantic correctness. A passing execution
2
+ * says nothing about code the model subsequently rewrites in its final answer. */
3
+ export function unmatchedExecutedCode(text, executed) {
4
+ const normalize = (value) => value.replace(/\r\n/g, "\n").trim();
5
+ const aliases = { sql: "sql", js: "javascript", mjs: "javascript", javascript: "javascript", ts: "typescript", typescript: "typescript", py: "python", python: "python" };
6
+ const unmatched = new Set();
7
+ for (const match of text.matchAll(/^```(sql|javascript|js|mjs|typescript|ts|python|py)\s*\n([\s\S]*?)^```\s*$/gm)) {
8
+ const language = aliases[match[1]], code = normalize(match[2]);
9
+ const candidates = executed.filter(item => item.language === language);
10
+ if (code && candidates.length && !candidates.some(item => language === "sql" ? normalize(item.content) === code : normalize(item.content).includes(code)))
11
+ unmatched.add(language);
12
+ }
13
+ return [...unmatched];
14
+ }
15
+ /** Recognize only unambiguous standalone source/test pairs. This suggests a
16
+ * verifier invocation; it never executes quoted code or grants permission. */
17
+ export function answerTestBundle(text) {
18
+ const blocks = [...text.matchAll(/^```(javascript|js|mjs|python|py)\s*\n([\s\S]*?)^```\s*$/gm)]
19
+ .map(match => ({ language: match[1], content: match[2] }));
20
+ if (blocks.length !== 2 || blocks.some(block => block.content.length > 24000))
21
+ return;
22
+ const [source, tests] = blocks;
23
+ if ([source, tests].every(block => ["javascript", "js", "mjs"].includes(block.language))
24
+ && /\bexport\b/.test(source.content) && /["']node:test["']/.test(tests.content)) {
25
+ const imports = [...tests.content.matchAll(/\bfrom\s*["']([^"']+)["']/g)].map(match => match[1]);
26
+ const local = imports.filter(value => !value.startsWith("node:"));
27
+ if (local.length !== 1 || !/^\.\/[A-Za-z0-9_-]+\.(?:mjs|js)$/.test(local[0]))
28
+ return;
29
+ const name = local[0].slice(2);
30
+ if (name === "answer.test.mjs")
31
+ return;
32
+ return { runner: "node", files: [{ path: name, content: source.content }, { path: "answer.test.mjs", content: tests.content }] };
33
+ }
34
+ if ([source, tests].every(block => ["python", "py"].includes(block.language))
35
+ && /\bunittest\.TestCase\b/.test(tests.content) && !/^\s*from\s+/m.test(tests.content)
36
+ && [...tests.content.matchAll(/^\s*import\s+([^\n]+)/gm)].every(match => match[1].trim() === "unittest")) {
37
+ return { runner: "python", files: [{ path: "test_answer.py", content: `${source.content}\n${tests.content}` }] };
38
+ }
39
+ }