@mcoda/mswarm 0.1.134 → 0.1.135-codali.11

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 (273) hide show
  1. package/README.md +40 -0
  2. package/dist/codali-executor.d.ts +76 -0
  3. package/dist/codali-executor.d.ts.map +1 -1
  4. package/dist/codali-executor.js +122 -8
  5. package/dist/codali-executor.js.map +1 -1
  6. package/dist/invocation-token.d.ts.map +1 -1
  7. package/dist/invocation-token.js +1 -0
  8. package/dist/invocation-token.js.map +1 -1
  9. package/dist/native-reasoning.d.ts +8 -0
  10. package/dist/native-reasoning.d.ts.map +1 -0
  11. package/dist/native-reasoning.js +18 -0
  12. package/dist/native-reasoning.js.map +1 -0
  13. package/dist/runtime.d.ts +23 -1
  14. package/dist/runtime.d.ts.map +1 -1
  15. package/dist/runtime.js +187 -17
  16. package/dist/runtime.js.map +1 -1
  17. package/dist/server.d.ts +3 -1
  18. package/dist/server.d.ts.map +1 -1
  19. package/dist/server.js +58 -8
  20. package/dist/server.js.map +1 -1
  21. package/dist/vendor/codali/agents/RoleResolution.d.ts.map +1 -1
  22. package/dist/vendor/codali/agents/RoleResolution.js +4 -4
  23. package/dist/vendor/codali/api/CodaliApi.d.ts +16 -0
  24. package/dist/vendor/codali/api/CodaliApi.d.ts.map +1 -1
  25. package/dist/vendor/codali/api/CodaliApi.js +39 -10
  26. package/dist/vendor/codali/cli/AskCommand.d.ts +3 -0
  27. package/dist/vendor/codali/cli/AskCommand.d.ts.map +1 -1
  28. package/dist/vendor/codali/cli/AskCommand.js +76 -13
  29. package/dist/vendor/codali/cli/RunCommand.d.ts +4 -0
  30. package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -1
  31. package/dist/vendor/codali/cli/RunCommand.js +110 -24
  32. package/dist/vendor/codali/cli/TerminalCommand.d.ts +35 -0
  33. package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -0
  34. package/dist/vendor/codali/cli/TerminalCommand.js +618 -0
  35. package/dist/vendor/codali/cli/TerminalCredentials.d.ts +3 -0
  36. package/dist/vendor/codali/cli/TerminalCredentials.d.ts.map +1 -0
  37. package/dist/vendor/codali/cli/TerminalCredentials.js +89 -0
  38. package/dist/vendor/codali/cli/TerminalInput.d.ts +24 -0
  39. package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -0
  40. package/dist/vendor/codali/cli/TerminalInput.js +98 -0
  41. package/dist/vendor/codali/cli/TerminalText.d.ts +10 -0
  42. package/dist/vendor/codali/cli/TerminalText.d.ts.map +1 -0
  43. package/dist/vendor/codali/cli/TerminalText.js +53 -0
  44. package/dist/vendor/codali/cli.d.ts.map +1 -1
  45. package/dist/vendor/codali/cli.js +33 -4
  46. package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts +34 -0
  47. package/dist/vendor/codali/cognitive/ConfiguredPipeline.d.ts.map +1 -0
  48. package/dist/vendor/codali/cognitive/ConfiguredPipeline.js +50 -0
  49. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +4 -0
  50. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -1
  51. package/dist/vendor/codali/cognitive/ValidationRunner.js +18 -41
  52. package/dist/vendor/codali/config/NodeOrchestration.d.ts +21 -0
  53. package/dist/vendor/codali/config/NodeOrchestration.d.ts.map +1 -0
  54. package/dist/vendor/codali/config/NodeOrchestration.js +54 -0
  55. package/dist/vendor/codali/config/OrchestrationConfig.d.ts +100 -0
  56. package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -0
  57. package/dist/vendor/codali/config/OrchestrationConfig.js +245 -0
  58. package/dist/vendor/codali/connectors/mcp/McpClient.d.ts +3 -1
  59. package/dist/vendor/codali/connectors/mcp/McpClient.d.ts.map +1 -1
  60. package/dist/vendor/codali/connectors/mcp/McpClient.js +3 -2
  61. package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts +2 -2
  62. package/dist/vendor/codali/connectors/mcp/McpServerRegistry.d.ts.map +1 -1
  63. package/dist/vendor/codali/connectors/mcp/McpServerRegistry.js +39 -16
  64. package/dist/vendor/codali/connectors/mcp/McpToolAdapter.js +2 -2
  65. package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts +6 -0
  66. package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.d.ts.map +1 -0
  67. package/dist/vendor/codali/connectors/media/ConfiguredMediaTools.js +41 -0
  68. package/dist/vendor/codali/connectors/media/ImageGenerationTool.js +3 -3
  69. package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts +5 -0
  70. package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.d.ts.map +1 -0
  71. package/dist/vendor/codali/connectors/media/MediaArtifactReceipt.js +65 -0
  72. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +68 -0
  73. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -0
  74. package/dist/vendor/codali/connectors/media/MediaJobStore.js +199 -0
  75. package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts +2 -0
  76. package/dist/vendor/codali/connectors/media/MediaJobWorker.d.ts.map +1 -0
  77. package/dist/vendor/codali/connectors/media/MediaJobWorker.js +65 -0
  78. package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts +6 -0
  79. package/dist/vendor/codali/connectors/media/RemoteMediaJob.d.ts.map +1 -0
  80. package/dist/vendor/codali/connectors/media/RemoteMediaJob.js +80 -0
  81. package/dist/vendor/codali/docdex/DocdexClient.d.ts +18 -1
  82. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
  83. package/dist/vendor/codali/docdex/DocdexClient.js +135 -19
  84. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +29 -0
  85. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -0
  86. package/dist/vendor/codali/docdex/ManagedDocdex.js +215 -0
  87. package/dist/vendor/codali/docdex/ManagedRuntime.d.ts +28 -0
  88. package/dist/vendor/codali/docdex/ManagedRuntime.d.ts.map +1 -0
  89. package/dist/vendor/codali/docdex/ManagedRuntime.js +212 -0
  90. package/dist/vendor/codali/eval/EvaluationProcess.d.ts +13 -0
  91. package/dist/vendor/codali/eval/EvaluationProcess.d.ts.map +1 -0
  92. package/dist/vendor/codali/eval/EvaluationProcess.js +76 -0
  93. package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts +34 -0
  94. package/dist/vendor/codali/eval/LongWorkflowJourney.d.ts.map +1 -0
  95. package/dist/vendor/codali/eval/LongWorkflowJourney.js +243 -0
  96. package/dist/vendor/codali/eval/PlanningCorpus.d.ts +45 -0
  97. package/dist/vendor/codali/eval/PlanningCorpus.d.ts.map +1 -0
  98. package/dist/vendor/codali/eval/PlanningCorpus.js +189 -0
  99. package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts +13 -0
  100. package/dist/vendor/codali/eval/PlanningCorpusRunner.d.ts.map +1 -0
  101. package/dist/vendor/codali/eval/PlanningCorpusRunner.js +89 -0
  102. package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts +36 -0
  103. package/dist/vendor/codali/eval/TerminalCorpusRunner.d.ts.map +1 -0
  104. package/dist/vendor/codali/eval/TerminalCorpusRunner.js +222 -0
  105. package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts +26 -0
  106. package/dist/vendor/codali/eval/TerminalTaskCorpus.d.ts.map +1 -0
  107. package/dist/vendor/codali/eval/TerminalTaskCorpus.js +105 -0
  108. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +11 -0
  109. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -0
  110. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +119 -0
  111. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
  112. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
  113. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
  114. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
  115. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
  116. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
  117. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts +4 -0
  118. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -0
  119. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +136 -0
  120. package/dist/vendor/codali/gateway/CodaliGateway.d.ts +2 -0
  121. package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
  122. package/dist/vendor/codali/gateway/CodaliGateway.js +11 -1
  123. package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts +23 -0
  124. package/dist/vendor/codali/gateway/ConfiguredGateway.d.ts.map +1 -0
  125. package/dist/vendor/codali/gateway/ConfiguredGateway.js +44 -0
  126. package/dist/vendor/codali/gateway/GatewayTracer.d.ts +1 -1
  127. package/dist/vendor/codali/gateway/GatewayTracer.d.ts.map +1 -1
  128. package/dist/vendor/codali/gateway/GatewayTracer.js +2 -27
  129. package/dist/vendor/codali/index.d.ts +24 -0
  130. package/dist/vendor/codali/index.d.ts.map +1 -1
  131. package/dist/vendor/codali/index.js +13 -0
  132. package/dist/vendor/codali/permissions/PermissionGate.d.ts +44 -0
  133. package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -0
  134. package/dist/vendor/codali/permissions/PermissionGate.js +97 -0
  135. package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts +43 -0
  136. package/dist/vendor/codali/providers/ConfiguredEmbeddings.d.ts.map +1 -0
  137. package/dist/vendor/codali/providers/ConfiguredEmbeddings.js +87 -0
  138. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +70 -0
  139. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -0
  140. package/dist/vendor/codali/providers/ConfiguredModelScope.js +129 -0
  141. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +84 -0
  142. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -0
  143. package/dist/vendor/codali/providers/ConfiguredProvider.js +271 -0
  144. package/dist/vendor/codali/providers/ModelServiceError.d.ts +15 -0
  145. package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -0
  146. package/dist/vendor/codali/providers/ModelServiceError.js +69 -0
  147. package/dist/vendor/codali/providers/MswarmWorkerProvider.d.ts.map +1 -1
  148. package/dist/vendor/codali/providers/MswarmWorkerProvider.js +4 -0
  149. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
  150. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +97 -50
  151. package/dist/vendor/codali/providers/ProviderTypes.d.ts +14 -0
  152. package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
  153. package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
  154. package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
  155. package/dist/vendor/codali/providers/RequestUsage.js +33 -0
  156. package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts +6 -0
  157. package/dist/vendor/codali/runtime/CodaliJobRuntime.d.ts.map +1 -1
  158. package/dist/vendor/codali/runtime/CodaliJobRuntime.js +36 -1
  159. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +29 -0
  160. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
  161. package/dist/vendor/codali/runtime/CodaliRuntime.js +70 -1
  162. package/dist/vendor/codali/runtime/CompletionReport.d.ts +5 -0
  163. package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -0
  164. package/dist/vendor/codali/runtime/CompletionReport.js +12 -0
  165. package/dist/vendor/codali/runtime/ProgressTracker.d.ts +17 -0
  166. package/dist/vendor/codali/runtime/ProgressTracker.d.ts.map +1 -0
  167. package/dist/vendor/codali/runtime/ProgressTracker.js +27 -0
  168. package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts +12 -0
  169. package/dist/vendor/codali/runtime/RequestedTestEvidence.d.ts.map +1 -0
  170. package/dist/vendor/codali/runtime/RequestedTestEvidence.js +16 -0
  171. package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts +13 -0
  172. package/dist/vendor/codali/runtime/RequiredRetrieval.d.ts.map +1 -0
  173. package/dist/vendor/codali/runtime/RequiredRetrieval.js +25 -0
  174. package/dist/vendor/codali/runtime/ReviewContract.d.ts +35 -0
  175. package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
  176. package/dist/vendor/codali/runtime/ReviewContract.js +132 -0
  177. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +41 -0
  178. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
  179. package/dist/vendor/codali/runtime/ReviewCoordinator.js +126 -0
  180. package/dist/vendor/codali/runtime/ReviewSource.d.ts +9 -0
  181. package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -0
  182. package/dist/vendor/codali/runtime/ReviewSource.js +54 -0
  183. package/dist/vendor/codali/runtime/Runner.d.ts +7 -0
  184. package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
  185. package/dist/vendor/codali/runtime/Runner.js +220 -171
  186. package/dist/vendor/codali/runtime/SecretRedaction.d.ts +11 -0
  187. package/dist/vendor/codali/runtime/SecretRedaction.d.ts.map +1 -0
  188. package/dist/vendor/codali/runtime/SecretRedaction.js +85 -0
  189. package/dist/vendor/codali/runtime/SessionController.d.ts +150 -0
  190. package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -0
  191. package/dist/vendor/codali/runtime/SessionController.js +1487 -0
  192. package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +22 -0
  193. package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -0
  194. package/dist/vendor/codali/runtime/StructuralEvidence.js +87 -0
  195. package/dist/vendor/codali/runtime/TaskReview.d.ts +25 -0
  196. package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
  197. package/dist/vendor/codali/runtime/TaskReview.js +84 -0
  198. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +71 -0
  199. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -0
  200. package/dist/vendor/codali/runtime/TaskReviewContext.js +50 -0
  201. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
  202. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
  203. package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -0
  204. package/dist/vendor/codali/runtime/ValidationOutput.d.ts +5 -0
  205. package/dist/vendor/codali/runtime/ValidationOutput.d.ts.map +1 -0
  206. package/dist/vendor/codali/runtime/ValidationOutput.js +32 -0
  207. package/dist/vendor/codali/runtime/VerificationCommand.d.ts +5 -0
  208. package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -0
  209. package/dist/vendor/codali/runtime/VerificationCommand.js +76 -0
  210. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
  211. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
  212. package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -0
  213. package/dist/vendor/codali/runtime/WorkStatusPage.d.ts +15 -0
  214. package/dist/vendor/codali/runtime/WorkStatusPage.d.ts.map +1 -0
  215. package/dist/vendor/codali/runtime/WorkStatusPage.js +58 -0
  216. package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts +13 -0
  217. package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts.map +1 -0
  218. package/dist/vendor/codali/runtime/WorkspaceLedger.js +145 -0
  219. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -1
  220. package/dist/vendor/codali/runtime/WorkspaceLock.js +20 -17
  221. package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts +13 -0
  222. package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts.map +1 -0
  223. package/dist/vendor/codali/runtime/WorkspaceSnapshot.js +88 -0
  224. package/dist/vendor/codali/session/AtomicState.d.ts +13 -0
  225. package/dist/vendor/codali/session/AtomicState.d.ts.map +1 -0
  226. package/dist/vendor/codali/session/AtomicState.js +123 -0
  227. package/dist/vendor/codali/session/SessionStoragePath.d.ts +15 -0
  228. package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -0
  229. package/dist/vendor/codali/session/SessionStoragePath.js +101 -0
  230. package/dist/vendor/codali/session/SessionStore.d.ts +9 -0
  231. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
  232. package/dist/vendor/codali/session/SessionStore.js +181 -47
  233. package/dist/vendor/codali/session/WorkState.d.ts +32 -0
  234. package/dist/vendor/codali/session/WorkState.d.ts.map +1 -0
  235. package/dist/vendor/codali/session/WorkState.js +399 -0
  236. package/dist/vendor/codali/session/WorkTypes.d.ts +102 -0
  237. package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -0
  238. package/dist/vendor/codali/session/WorkTypes.js +1 -0
  239. package/dist/vendor/codali/tools/ToolRegistry.d.ts +2 -0
  240. package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
  241. package/dist/vendor/codali/tools/ToolRegistry.js +12 -2
  242. package/dist/vendor/codali/tools/ToolTypes.d.ts +16 -0
  243. package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
  244. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
  245. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
  246. package/dist/vendor/codali/tools/docdex/DocdexTools.js +17 -2
  247. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -1
  248. package/dist/vendor/codali/tools/filesystem/FileTools.js +30 -10
  249. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +19 -0
  250. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -0
  251. package/dist/vendor/codali/tools/shell/AsyncProcess.js +94 -0
  252. package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts +13 -0
  253. package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.d.ts.map +1 -0
  254. package/dist/vendor/codali/tools/shell/DarwinRuntimeLibraries.js +130 -0
  255. package/dist/vendor/codali/tools/shell/HostToolchain.d.ts +19 -0
  256. package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -0
  257. package/dist/vendor/codali/tools/shell/HostToolchain.js +266 -0
  258. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +15 -0
  259. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -0
  260. package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +138 -0
  261. package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
  262. package/dist/vendor/codali/tools/shell/ShellTool.js +9 -29
  263. package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts +3 -0
  264. package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.d.ts.map +1 -0
  265. package/dist/vendor/codali/tools/shell/ShellWorkingDirectory.js +30 -0
  266. package/package.json +31 -29
  267. package/scripts/backend-http-drain.mjs +152 -0
  268. package/scripts/media_gpu_lock.py +238 -0
  269. package/scripts/native_load_guard.py +257 -0
  270. package/scripts/stable-audio-3-openai-server.py +45 -14
  271. package/scripts/stable-diffusion-cpp-openai-server.py +34 -4
  272. package/scripts/stable-diffusion-cpp-webm-duration.patch +22 -0
  273. package/scripts/wan22-openai-server.py +97 -18
@@ -1,4 +1,5 @@
1
1
  import { truncateToolResult } from "../tools/TruncateResult.js";
2
+ import { ModelServiceError } from "../providers/ModelServiceError.js";
2
3
  export class RunnerBudgetError extends Error {
3
4
  constructor(code, metadata) {
4
5
  super(code === "runner_timeout_exceeded"
@@ -38,196 +39,244 @@ export class Runner {
38
39
  this.onToken = options.onToken;
39
40
  this.streamFlushMs = options.streamFlushMs;
40
41
  this.timeoutMs = options.timeoutMs;
42
+ this.continueAfterFinal = options.continueAfterFinal;
43
+ this.onMessages = options.onMessages;
41
44
  this.logger = options.logger;
45
+ this.signal = options.signal ?? options.context.signal;
42
46
  }
43
47
  async run(initialMessages) {
44
- const messages = [...initialMessages];
45
- let toolCallsExecuted = 0;
46
- let usageTotals;
47
- const deadline = this.timeoutMs ? Date.now() + this.timeoutMs : undefined;
48
- const emitEvent = (event) => {
49
- if (this.onEvent) {
50
- this.onEvent(event);
51
- return;
52
- }
53
- if (event.type === "token") {
54
- this.onToken?.(event.content);
55
- }
56
- };
57
- const emitStatus = (phase, message) => {
58
- this.onEvent?.({ type: "status", phase, message });
59
- };
60
- const recordUsage = (usage) => {
61
- if (!usage)
62
- return;
63
- if (!usageTotals)
64
- usageTotals = {};
65
- if (usage.inputTokens !== undefined) {
66
- usageTotals.inputTokens = (usageTotals.inputTokens ?? 0) + usage.inputTokens;
67
- }
68
- if (usage.outputTokens !== undefined) {
69
- usageTotals.outputTokens = (usageTotals.outputTokens ?? 0) + usage.outputTokens;
70
- }
71
- if (usage.totalTokens !== undefined) {
72
- usageTotals.totalTokens = (usageTotals.totalTokens ?? 0) + usage.totalTokens;
73
- }
74
- };
75
- const timeRemaining = () => {
76
- if (!deadline)
77
- return undefined;
78
- return deadline - Date.now();
79
- };
80
- const throwBudgetError = async (code, step) => {
81
- const error = new RunnerBudgetError(code, {
82
- step,
83
- tool_calls_executed: toolCallsExecuted,
84
- max_steps: this.maxSteps,
85
- max_tool_calls: this.maxToolCalls,
86
- timeout_ms: this.timeoutMs,
87
- });
88
- if (this.logger) {
89
- await this.logger.log("runner_budget_failure", error.metadata);
90
- }
91
- throw error;
92
- };
93
- const withTimeout = async (promise, label) => {
94
- const remaining = timeRemaining();
95
- if (remaining === undefined)
96
- return promise;
97
- if (remaining <= 0) {
98
- await throwBudgetError("runner_timeout_exceeded", -1);
99
- }
100
- let timeoutId;
101
- const timeoutPromise = new Promise((_, reject) => {
102
- timeoutId = setTimeout(() => reject(new Error("Runner timeout exceeded")), remaining);
103
- });
104
- try {
105
- return await Promise.race([promise, timeoutPromise]);
106
- }
107
- catch (error) {
108
- if (error instanceof Error && /Runner timeout exceeded/i.test(error.message)) {
109
- await throwBudgetError("runner_timeout_exceeded", -1);
48
+ this.signal?.throwIfAborted();
49
+ const abortController = new AbortController();
50
+ const onAbort = () => abortController.abort(this.signal?.reason);
51
+ this.signal?.addEventListener("abort", onAbort, { once: true });
52
+ const timeout = this.timeoutMs ? setTimeout(() => abortController.abort(new Error("Runner timeout exceeded")), this.timeoutMs) : undefined;
53
+ const signal = abortController.signal;
54
+ try {
55
+ const messages = [...initialMessages];
56
+ let toolCallsExecuted = 0;
57
+ let usageTotals;
58
+ const deadline = this.timeoutMs ? Date.now() + this.timeoutMs : undefined;
59
+ const emitEvent = (event) => {
60
+ if (signal.aborted)
61
+ return;
62
+ if (this.onEvent) {
63
+ this.onEvent(event);
64
+ return;
65
+ }
66
+ if (event.type === "token") {
67
+ this.onToken?.(event.content);
68
+ }
69
+ };
70
+ const emitStatus = (phase, message) => {
71
+ this.onEvent?.({ type: "status", phase, message });
72
+ };
73
+ const recordUsage = (usage) => {
74
+ if (!usage)
75
+ return;
76
+ if (!usageTotals)
77
+ usageTotals = {};
78
+ if (usage.inputTokens !== undefined) {
79
+ usageTotals.inputTokens = (usageTotals.inputTokens ?? 0) + usage.inputTokens;
80
+ }
81
+ if (usage.outputTokens !== undefined) {
82
+ usageTotals.outputTokens = (usageTotals.outputTokens ?? 0) + usage.outputTokens;
83
+ }
84
+ if (usage.totalTokens !== undefined) {
85
+ usageTotals.totalTokens = (usageTotals.totalTokens ?? 0) + usage.totalTokens;
86
+ }
87
+ };
88
+ const timeRemaining = () => {
89
+ if (!deadline)
90
+ return undefined;
91
+ return deadline - Date.now();
92
+ };
93
+ const throwBudgetError = async (code, step) => {
94
+ const error = new RunnerBudgetError(code, {
95
+ step,
96
+ tool_calls_executed: toolCallsExecuted,
97
+ max_steps: this.maxSteps,
98
+ max_tool_calls: this.maxToolCalls,
99
+ timeout_ms: this.timeoutMs,
100
+ });
101
+ if (this.logger) {
102
+ await this.logger.log("runner_budget_failure", error.metadata);
110
103
  }
111
104
  throw error;
112
- }
113
- finally {
114
- if (timeoutId)
115
- clearTimeout(timeoutId);
116
- }
117
- };
118
- for (let step = 0; step < this.maxSteps; step += 1) {
119
- if (deadline && timeRemaining() <= 0) {
120
- await throwBudgetError("runner_timeout_exceeded", step);
121
- }
122
- const toolSpecs = this.tools.describe().map((tool) => ({
123
- name: tool.name,
124
- description: tool.description,
125
- inputSchema: tool.inputSchema,
126
- }));
127
- const finalSummaryStep = this.finalStepWithoutTools && step > 0 && step === this.maxSteps - 1;
128
- const allowTools = toolSpecs.length > 0 && this.toolChoice !== "none" && !finalSummaryStep;
129
- emitStatus("thinking");
130
- if (this.logger) {
131
- await this.logger.log("provider_request", {
132
- provider: this.provider.name,
133
- messages,
134
- tools: allowTools ? toolSpecs : [],
135
- toolChoice: allowTools ? this.toolChoice ?? "auto" : "none",
136
- responseFormat: this.responseFormat,
137
- temperature: this.temperature,
138
- maxTokens: this.maxTokens,
139
- stream: this.stream ?? false,
105
+ };
106
+ const withTimeout = async (promise, label) => {
107
+ const remaining = timeRemaining();
108
+ if (remaining !== undefined && remaining <= 0) {
109
+ await throwBudgetError("runner_timeout_exceeded", -1);
110
+ }
111
+ let timeoutId;
112
+ const timeoutPromise = new Promise((_, reject) => {
113
+ if (remaining !== undefined)
114
+ timeoutId = setTimeout(() => reject(new Error("Runner timeout exceeded")), remaining);
140
115
  });
141
- }
142
- const response = await withTimeout(this.provider.generate({
143
- messages,
144
- tools: allowTools ? toolSpecs : undefined,
145
- toolChoice: allowTools ? this.toolChoice ?? "auto" : finalSummaryStep ? "none" : undefined,
146
- maxTokens: this.maxTokens,
147
- temperature: this.temperature,
148
- responseFormat: this.responseFormat,
149
- stream: this.stream,
150
- onEvent: emitEvent,
151
- onToken: (token) => emitEvent({ type: "token", content: token }),
152
- streamFlushMs: this.streamFlushMs,
153
- }), "provider");
154
- recordUsage(response.usage);
155
- messages.push({
156
- ...response.message,
157
- ...(response.toolCalls?.length ? { toolCalls: response.toolCalls } : {}),
158
- });
159
- if (this.logger) {
160
- await this.logger.log("provider_response", {
161
- message: response.message,
162
- toolCalls: response.toolCalls,
163
- usage: response.usage,
116
+ let onCancel;
117
+ const cancelled = new Promise((_, reject) => {
118
+ // Provider streams may not honor AbortSignal; never accept their late reply.
119
+ // Tools are allowed to finish their cancellation cleanup before unlocking.
120
+ if (label === "provider") {
121
+ onCancel = () => reject(signal.reason ?? new Error("Cancelled"));
122
+ signal.addEventListener("abort", onCancel, { once: true });
123
+ if (signal.aborted)
124
+ onCancel();
125
+ }
164
126
  });
165
- }
166
- if (!response.toolCalls || response.toolCalls.length === 0) {
167
- return {
168
- finalMessage: response.message,
169
- messages,
170
- toolCallsExecuted,
171
- usage: usageTotals,
172
- };
173
- }
174
- for (const call of response.toolCalls) {
175
- if (toolCallsExecuted >= this.maxToolCalls) {
176
- await throwBudgetError("runner_tool_call_limit_exceeded", step);
127
+ try {
128
+ return await Promise.race([promise, timeoutPromise, cancelled]);
177
129
  }
178
- toolCallsExecuted += 1;
179
- emitStatus("executing", call.name);
180
- this.onEvent?.({ type: "tool_call", name: call.name, args: call.args });
181
- const result = await withTimeout(this.tools.execute(call.name, call.args, this.context), "tool");
182
- const toolError = result.error;
183
- let content = result.ok
184
- ? result.output
185
- : `ERROR[${toolError?.code ?? "tool_execution_failed"}]: ${toolError?.message ?? "tool failed"}`;
186
- if (result.ok && this.maxToolResultChars && this.maxToolResultChars > 0) {
187
- const limit = Math.max(1, Math.floor(this.maxToolResultChars / response.toolCalls.length));
188
- let structured = result.data;
189
- if (structured === undefined) {
190
- try {
191
- structured = JSON.parse(content);
192
- }
193
- catch { /* Plain-text tool output. */ }
130
+ catch (error) {
131
+ if (error instanceof Error && /Runner timeout exceeded/i.test(error.message)) {
132
+ await throwBudgetError("runner_timeout_exceeded", -1);
194
133
  }
195
- content = truncateToolResult(structured, content, limit).text;
134
+ throw error;
135
+ }
136
+ finally {
137
+ if (timeoutId)
138
+ clearTimeout(timeoutId);
139
+ if (onCancel)
140
+ signal.removeEventListener("abort", onCancel);
196
141
  }
197
- messages.push(buildToolMessage(call, content));
198
- this.onEvent?.({
199
- type: "tool_result",
200
- name: call.name,
201
- output: content,
202
- ok: result.ok,
203
- errorCode: toolError?.code,
204
- retryable: toolError?.retryable,
142
+ };
143
+ for (let step = 0; step < this.maxSteps; step += 1) {
144
+ signal.throwIfAborted();
145
+ if (deadline && timeRemaining() <= 0) {
146
+ await throwBudgetError("runner_timeout_exceeded", step);
147
+ }
148
+ const toolSpecs = this.tools.describe().map((tool) => ({
149
+ name: tool.name,
150
+ description: tool.description,
151
+ inputSchema: tool.inputSchema,
152
+ }));
153
+ const finalSummaryStep = this.finalStepWithoutTools && step > 0 && step === this.maxSteps - 1;
154
+ const allowTools = toolSpecs.length > 0 && this.toolChoice !== "none" && !finalSummaryStep;
155
+ emitStatus("thinking");
156
+ if (this.logger) {
157
+ await this.logger.log("provider_request", {
158
+ provider: this.provider.name,
159
+ messages,
160
+ tools: allowTools ? toolSpecs : [],
161
+ toolChoice: allowTools ? this.toolChoice ?? "auto" : "none",
162
+ responseFormat: this.responseFormat,
163
+ temperature: this.temperature,
164
+ maxTokens: this.maxTokens,
165
+ stream: this.stream ?? false,
166
+ });
167
+ }
168
+ const response = await withTimeout(this.provider.generate({
169
+ signal,
170
+ messages,
171
+ tools: allowTools ? toolSpecs : undefined,
172
+ toolChoice: allowTools ? this.toolChoice ?? "auto" : finalSummaryStep ? "none" : undefined,
173
+ maxTokens: this.maxTokens,
174
+ temperature: this.temperature,
175
+ responseFormat: this.responseFormat,
176
+ stream: this.stream,
177
+ onEvent: emitEvent,
178
+ onToken: (token) => emitEvent({ type: "token", content: token }),
179
+ streamFlushMs: this.streamFlushMs,
180
+ }), "provider").catch((error) => {
181
+ if (error instanceof ModelServiceError)
182
+ error.completedModelCalls = step;
183
+ throw error;
184
+ });
185
+ recordUsage(response.usage);
186
+ signal.throwIfAborted();
187
+ messages.push({
188
+ ...response.message,
189
+ ...(response.toolCalls?.length ? { toolCalls: response.toolCalls } : {}),
205
190
  });
191
+ await this.onMessages?.([...messages]);
206
192
  if (this.logger) {
207
- await this.logger.log("tool_call", {
193
+ await this.logger.log("provider_response", {
194
+ message: response.message,
195
+ toolCalls: response.toolCalls,
196
+ usage: response.usage,
197
+ });
198
+ }
199
+ if (!response.toolCalls || response.toolCalls.length === 0) {
200
+ const continuation = await this.continueAfterFinal?.(response.message);
201
+ if (continuation) {
202
+ messages.push({ role: "user", content: continuation });
203
+ continue;
204
+ }
205
+ return {
206
+ finalMessage: response.message,
207
+ messages,
208
+ toolCallsExecuted,
209
+ usage: usageTotals,
210
+ };
211
+ }
212
+ for (const call of response.toolCalls) {
213
+ signal.throwIfAborted();
214
+ if (toolCallsExecuted >= this.maxToolCalls) {
215
+ await throwBudgetError("runner_tool_call_limit_exceeded", step);
216
+ }
217
+ toolCallsExecuted += 1;
218
+ emitStatus("executing", call.name);
219
+ this.onEvent?.({ type: "tool_call", name: call.name, args: call.args });
220
+ const result = await withTimeout(this.tools.execute(call.name, call.args, { ...this.context, signal }), "tool");
221
+ const toolError = result.error;
222
+ let content = result.ok
223
+ ? result.output
224
+ : `ERROR[${toolError?.code ?? "tool_execution_failed"}]: ${toolError?.message ?? "tool failed"}`;
225
+ if (result.ok && this.maxToolResultChars && this.maxToolResultChars > 0) {
226
+ const limit = Math.max(1, Math.floor(this.maxToolResultChars / response.toolCalls.length));
227
+ let structured = result.data;
228
+ if (structured === undefined) {
229
+ try {
230
+ structured = JSON.parse(content);
231
+ }
232
+ catch { /* Plain-text tool output. */ }
233
+ }
234
+ content = truncateToolResult(structured, content, limit).text;
235
+ }
236
+ if (result.invocationReceipt) {
237
+ content += `\n\n[Tool metadata: invocation receipt ID ${result.invocationReceipt.id}; receiptRef=${result.invocationReceipt.reference}]`;
238
+ }
239
+ messages.push(buildToolMessage(call, content));
240
+ await this.onMessages?.([...messages]);
241
+ this.onEvent?.({
242
+ type: "tool_result",
208
243
  name: call.name,
244
+ output: content,
209
245
  ok: result.ok,
210
- error: toolError?.message,
211
- error_code: toolError?.code,
212
- error_category: toolError?.category,
213
- error_retryable: toolError?.retryable,
214
- error_details: toolError?.details,
246
+ errorCode: toolError?.code,
247
+ retryable: toolError?.retryable,
215
248
  });
216
- if (toolError) {
217
- await this.logger.logSafetyEvent({
218
- phase: "act",
219
- category: "tool",
220
- code: toolError.code,
221
- disposition: toolError.retryable ? "retryable" : "non_retryable",
222
- tool: call.name,
223
- message: toolError.message,
224
- details: toolError.details,
249
+ if (this.logger) {
250
+ await this.logger.log("tool_call", {
251
+ name: call.name,
252
+ ok: result.ok,
253
+ error: toolError?.message,
254
+ error_code: toolError?.code,
255
+ error_category: toolError?.category,
256
+ error_retryable: toolError?.retryable,
257
+ error_details: toolError?.details,
225
258
  });
259
+ if (toolError) {
260
+ await this.logger.logSafetyEvent({
261
+ phase: "act",
262
+ category: "tool",
263
+ code: toolError.code,
264
+ disposition: toolError.retryable ? "retryable" : "non_retryable",
265
+ tool: call.name,
266
+ message: toolError.message,
267
+ details: toolError.details,
268
+ });
269
+ }
226
270
  }
227
271
  }
228
272
  }
273
+ await throwBudgetError("runner_step_limit_exceeded", this.maxSteps);
274
+ throw new Error("unreachable_runner_budget_path");
275
+ }
276
+ finally {
277
+ if (timeout)
278
+ clearTimeout(timeout);
279
+ this.signal?.removeEventListener("abort", onAbort);
229
280
  }
230
- await throwBudgetError("runner_step_limit_exceeded", this.maxSteps);
231
- throw new Error("unreachable_runner_budget_path");
232
281
  }
233
282
  }
@@ -0,0 +1,11 @@
1
+ /** Register credentials when resolved; do not scan or expose unrelated environment values. */
2
+ export declare const registerSecretValue: (value: string) => void;
3
+ export declare const redactSecretValues: (value: string) => string;
4
+ /** Hold incomplete credential-shaped words so split chunks cannot expose a prefix or tail. */
5
+ export declare class StreamingSecretRedactor {
6
+ private pending;
7
+ private droppingWord;
8
+ write(chunk: string): string;
9
+ finish(): string;
10
+ }
11
+ //# sourceMappingURL=SecretRedaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecretRedaction.d.ts","sourceRoot":"","sources":["../../src/runtime/SecretRedaction.ts"],"names":[],"mappings":"AAaA,8FAA8F;AAC9F,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,IAEnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAKlD,CAAC;AAEF,8FAA8F;AAC9F,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,YAAY,CAAS;IAC7B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IA4B5B,MAAM,IAAI,MAAM;CAUjB"}
@@ -0,0 +1,85 @@
1
+ const knownSecrets = new Set();
2
+ const patterns = [
3
+ /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,
4
+ /\bsk-[A-Za-z0-9_-]{16,}\b/g,
5
+ /\bsk_[A-Za-z0-9]+_[A-Za-z0-9_]{8,}\b/g,
6
+ /\bgh[pousr]_[A-Za-z0-9_]{20,}\b/g,
7
+ /\bglpat-[A-Za-z0-9_-]{16,}\b/g,
8
+ /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
9
+ /\bAKIA[0-9A-Z]{16}\b/g,
10
+ /\bAIza[0-9A-Za-z_-]{30,}\b/g,
11
+ /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g,
12
+ ];
13
+ /** Register credentials when resolved; do not scan or expose unrelated environment values. */
14
+ export const registerSecretValue = (value) => {
15
+ if (value.length >= 4) {
16
+ knownSecrets.add(value);
17
+ knownSecrets.add(JSON.stringify(value).slice(1, -1));
18
+ }
19
+ };
20
+ export const redactSecretValues = (value) => {
21
+ let output = value;
22
+ for (const secret of [...knownSecrets].sort((a, b) => b.length - a.length))
23
+ output = output.split(secret).join("[redacted]");
24
+ for (const pattern of patterns)
25
+ output = output.replace(pattern, "[redacted]");
26
+ return output;
27
+ };
28
+ /** Hold incomplete credential-shaped words so split chunks cannot expose a prefix or tail. */
29
+ export class StreamingSecretRedactor {
30
+ constructor() {
31
+ this.pending = "";
32
+ this.droppingWord = false;
33
+ }
34
+ write(chunk) {
35
+ if (this.droppingWord) {
36
+ const boundary = chunk.search(/[^A-Za-z0-9._~+/=-]/);
37
+ if (boundary < 0)
38
+ return "";
39
+ chunk = chunk.slice(boundary);
40
+ this.droppingWord = false;
41
+ }
42
+ this.pending += chunk;
43
+ let cutoff = this.pending.search(/[A-Za-z0-9._~+/=-]*$/);
44
+ const bearer = /\bBearer\s+[A-Za-z0-9._~+/=-]*$/i.exec(this.pending);
45
+ if (bearer)
46
+ cutoff = Math.min(cutoff, bearer.index);
47
+ for (const secret of knownSecrets) {
48
+ // An exact credential may contain spaces/punctuation, unlike a bearer word.
49
+ for (let at = this.pending.indexOf(secret); at >= 0; at = this.pending.indexOf(secret, at + 1)) {
50
+ if (at < cutoff && at + secret.length > cutoff)
51
+ cutoff = at;
52
+ }
53
+ for (let size = Math.min(secret.length - 1, this.pending.length); size > 0; size--) {
54
+ if (this.pending.endsWith(secret.slice(0, size))) {
55
+ cutoff = Math.min(cutoff, this.pending.length - size);
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ let output = redactSecretValues(this.pending.slice(0, cutoff));
61
+ this.pending = this.pending.slice(cutoff);
62
+ // Never release a truncated prefix; discard an oversized unbroken token.
63
+ const longestCredential = Math.max(0, ...[...knownSecrets].map(secret => secret.length));
64
+ if (this.pending.length > Math.max(65536, longestCredential)) {
65
+ output += "[redacted oversized token]";
66
+ this.pending = "";
67
+ this.droppingWord = true;
68
+ }
69
+ return output;
70
+ }
71
+ finish() {
72
+ let output = redactSecretValues(this.pending);
73
+ for (const secret of knownSecrets) {
74
+ for (let size = Math.min(secret.length - 1, output.length); size >= 4; size--) {
75
+ if (output.endsWith(secret.slice(0, size))) {
76
+ output = `${output.slice(0, -size)}[redacted]`;
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ this.pending = "";
82
+ this.droppingWord = false;
83
+ return output;
84
+ }
85
+ }