@abot-ai/runtime 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (443) hide show
  1. package/dist/src/capabilities/tool-request-resources.d.ts +3 -0
  2. package/dist/src/cli/abot.js +2 -0
  3. package/dist/src/cli/host-companion-bundle.mjs +751 -333
  4. package/dist/src/computer-access/collection-consent.d.ts +9 -0
  5. package/dist/src/computer-access/collection-consent.js +47 -0
  6. package/dist/src/computer-access/command-output-capture.d.ts +17 -6
  7. package/dist/src/computer-access/command-output-capture.js +134 -68
  8. package/dist/src/computer-access/command-output-protection.d.ts +17 -0
  9. package/dist/src/computer-access/command-output-protection.js +59 -0
  10. package/dist/src/computer-access/companion/command-output.d.ts +1 -0
  11. package/dist/src/computer-access/companion/command-output.js +23 -6
  12. package/dist/src/computer-access/companion/install-link-macos.js +2 -1
  13. package/dist/src/computer-access/companion/native-notifications.js +3 -2
  14. package/dist/src/computer-access/companion/native-session.js +6 -2
  15. package/dist/src/computer-access/companion/observation-filter.js +2 -26
  16. package/dist/src/computer-access/companion/observation-process.d.ts +2 -0
  17. package/dist/src/computer-access/companion/observation-process.js +51 -25
  18. package/dist/src/computer-access/companion/observation-redaction.d.ts +2 -7
  19. package/dist/src/computer-access/companion/observation-redaction.js +2 -111
  20. package/dist/src/computer-access/companion/secret-protection-protocol.d.ts +6 -0
  21. package/dist/src/computer-access/companion/secret-protection-protocol.js +6 -0
  22. package/dist/src/computer-access/computer/companion-sessions.js +7 -6
  23. package/dist/src/computer-access/computer/unix-native-process.js +23 -11
  24. package/dist/src/computer-access/handlers.d.ts +2 -1
  25. package/dist/src/computer-access/handlers.js +79 -11
  26. package/dist/src/computer-access/host-observation.d.ts +3 -3
  27. package/dist/src/computer-access/native-observation-connection.d.ts +12 -0
  28. package/dist/src/computer-access/native-observation-connection.js +78 -0
  29. package/dist/src/computer-access/native-observation-ownership.d.ts +6 -0
  30. package/dist/src/computer-access/native-observation-ownership.js +55 -0
  31. package/dist/src/computer-access/native-observation-shutdown.d.ts +7 -0
  32. package/dist/src/computer-access/native-observation-shutdown.js +58 -0
  33. package/dist/src/computer-access/observation-source.d.ts +6 -0
  34. package/dist/src/computer-access/observation-source.js +10 -0
  35. package/dist/src/computer-access/security/desktop-result.d.ts +8 -0
  36. package/dist/src/computer-access/security/desktop-result.js +146 -0
  37. package/dist/src/computer-access/security/observed-error.d.ts +2 -0
  38. package/dist/src/computer-access/security/observed-error.js +10 -0
  39. package/dist/src/computer-access/security/secret-text.d.ts +7 -0
  40. package/dist/src/computer-access/security/secret-text.js +111 -0
  41. package/dist/src/computer-access/security/system-results.d.ts +2 -0
  42. package/dist/src/computer-access/security/system-results.js +53 -0
  43. package/dist/src/computer-access/system-result-protection.d.ts +11 -0
  44. package/dist/src/computer-access/system-result-protection.js +1 -0
  45. package/dist/src/model-gateway/observability/provider-response-capture.d.ts +60 -0
  46. package/dist/src/model-gateway/observability/provider-response-capture.js +68 -0
  47. package/dist/src/model-gateway/observability/provider-response-prefix.d.ts +7 -0
  48. package/dist/src/model-gateway/observability/provider-response-prefix.js +14 -0
  49. package/dist/src/model-gateway/observability/provider-response-tail.d.ts +8 -0
  50. package/dist/src/model-gateway/observability/provider-response-tail.js +28 -0
  51. package/dist/src/model-gateway/observability/provider-sse-diagnostics.d.ts +30 -0
  52. package/dist/src/model-gateway/observability/provider-sse-diagnostics.js +119 -0
  53. package/dist/src/model-gateway/observability/provider-trace.js +30 -8
  54. package/dist/src/model-gateway/providers/ollama/adapter.js +8 -2
  55. package/dist/src/model-gateway/providers/ollama/stream-normalizer.js +70 -50
  56. package/dist/src/model-gateway/providers/ollama/stream-termination.d.ts +6 -0
  57. package/dist/src/model-gateway/providers/ollama/stream-termination.js +20 -0
  58. package/dist/src/model-gateway/providers/openai/adapter.js +9 -7
  59. package/dist/src/model-gateway/providers/openai/diagnostics.d.ts +0 -1
  60. package/dist/src/model-gateway/providers/openai/diagnostics.js +0 -9
  61. package/dist/src/model-gateway/providers/openai/function-output.d.ts +11 -0
  62. package/dist/src/model-gateway/providers/openai/function-output.js +37 -0
  63. package/dist/src/model-gateway/providers/openai/function-result.d.ts +7 -0
  64. package/dist/src/model-gateway/providers/openai/function-result.js +35 -0
  65. package/dist/src/model-gateway/providers/openai/message-output-policy.d.ts +3 -0
  66. package/dist/src/model-gateway/providers/openai/message-output-policy.js +16 -0
  67. package/dist/src/model-gateway/providers/openai/payload.d.ts +0 -2
  68. package/dist/src/model-gateway/providers/openai/payload.js +6 -23
  69. package/dist/src/model-gateway/providers/openai/response-lifetime.d.ts +2 -0
  70. package/dist/src/model-gateway/providers/openai/response-lifetime.js +64 -0
  71. package/dist/src/model-gateway/providers/openai/sse-data.d.ts +9 -0
  72. package/dist/src/model-gateway/providers/openai/sse-data.js +67 -0
  73. package/dist/src/model-gateway/providers/openai/stream-normalizer.d.ts +10 -22
  74. package/dist/src/model-gateway/providers/openai/stream-normalizer.js +78 -79
  75. package/dist/src/model-gateway/providers/openai/stream.js +13 -41
  76. package/dist/src/model-gateway/providers/openai/structured-message-output.d.ts +42 -0
  77. package/dist/src/model-gateway/providers/openai/structured-message-output.js +175 -0
  78. package/dist/src/model-gateway/server.js +5 -1
  79. package/dist/src/plugin-contract/index.d.ts +1 -0
  80. package/dist/src/plugin-contract/index.js +1 -0
  81. package/dist/src/plugin-contract/manifest.d.ts +2 -0
  82. package/dist/src/plugin-contract/manifest.js +1 -0
  83. package/dist/src/plugin-contract/platform-compatibility.d.ts +16 -0
  84. package/dist/src/plugin-contract/platform-compatibility.js +3 -0
  85. package/dist/src/plugin-sdk/computer-access.d.ts +4 -0
  86. package/dist/src/plugin-sdk/computer-access.js +1 -0
  87. package/dist/src/plugin-sdk/files-windows/process.d.ts +3 -0
  88. package/dist/src/plugin-sdk/files-windows/process.js +93 -0
  89. package/dist/src/plugin-sdk/files-windows/read-script.d.ts +1 -0
  90. package/dist/src/plugin-sdk/files-windows/read-script.js +43 -0
  91. package/dist/src/plugin-sdk/files-windows/read.d.ts +6 -0
  92. package/dist/src/plugin-sdk/files-windows/read.js +56 -0
  93. package/dist/src/plugin-sdk/files-windows/result.d.ts +4 -0
  94. package/dist/src/plugin-sdk/files-windows/result.js +67 -0
  95. package/dist/src/plugin-sdk/files.js +4 -0
  96. package/dist/src/plugin-sdk/index.d.ts +1 -0
  97. package/dist/src/plugin-sdk/index.js +1 -0
  98. package/dist/src/plugin-sdk/mutation-result.d.ts +7 -0
  99. package/dist/src/plugin-sdk/mutation-result.js +11 -0
  100. package/dist/src/runtime/adapters/long-term-memory/file-lock/acquisition.js +20 -3
  101. package/dist/src/runtime/adapters/long-term-memory/file-lock/owner-record.js +3 -1
  102. package/dist/src/runtime/adapters/long-term-memory/file-lock/path-observation.d.ts +3 -0
  103. package/dist/src/runtime/adapters/long-term-memory/file-lock/path-observation.js +20 -0
  104. package/dist/src/runtime/adapters/long-term-memory/file-lock/snapshot.js +7 -3
  105. package/dist/src/runtime/adapters/passive-learning-runtime.d.ts +1 -1
  106. package/dist/src/runtime/adapters/passive-learning-runtime.js +3 -3
  107. package/dist/src/runtime/adapters/runtime-observation-connection.d.ts +5 -0
  108. package/dist/src/runtime/adapters/runtime-observation-connection.js +13 -0
  109. package/dist/src/runtime/local-host/windows-private-access.js +2 -0
  110. package/dist/src/runtime/passive-learning/application-catalog.js +3 -1
  111. package/dist/src/runtime/passive-learning/collection-source.js +7 -0
  112. package/dist/src/runtime/passive-learning/service.js +2 -3
  113. package/dist/src/runtime/passive-learning/status-projection.d.ts +2 -0
  114. package/dist/src/runtime/passive-learning/status-projection.js +9 -0
  115. package/dist/src/runtime/plugins/installation/package.d.ts +8 -0
  116. package/dist/src/runtime/plugins/installation/package.js +2 -0
  117. package/dist/src/runtime/plugins/installation/service.d.ts +7 -0
  118. package/dist/src/runtime/plugins/loader.js +24 -14
  119. package/dist/src/runtime/plugins/manifest-platform-compatibility.d.ts +2 -0
  120. package/dist/src/runtime/plugins/manifest-platform-compatibility.js +39 -0
  121. package/dist/src/runtime/plugins/manifest-validator.js +9 -1
  122. package/dist/src/runtime/plugins/platform-compatibility.d.ts +4 -0
  123. package/dist/src/runtime/plugins/platform-compatibility.js +44 -0
  124. package/dist/src/runtime/request/approval-wait/activation-events.js +19 -7
  125. package/dist/src/runtime/request/approval-wait/execution-compaction-restore.d.ts +20 -0
  126. package/dist/src/runtime/request/approval-wait/execution-compaction-restore.js +118 -0
  127. package/dist/src/runtime/request/approval-wait/super-compaction-restore.js +2 -1
  128. package/dist/src/runtime/request/prepared-execution.js +3 -0
  129. package/dist/src/runtime/steps/execution-agent/capability-result-context.d.ts +6 -0
  130. package/dist/src/runtime/steps/execution-agent/capability-result-context.js +29 -0
  131. package/dist/src/runtime/steps/execution-agent/format.js +2 -3
  132. package/dist/src/runtime/steps/execution-agent/input.js +1 -1
  133. package/dist/src/runtime/steps/execution-agent/prompt.js +5 -5
  134. package/dist/src/runtime/steps/execution-agent/response-prompt.js +1 -0
  135. package/dist/src/runtime/steps/execution-agent/state-context.d.ts +2 -3
  136. package/dist/src/runtime/steps/execution-agent/state-context.js +26 -35
  137. package/dist/src/runtime/steps/execution-agent/work-plan-contract.d.ts +1 -3
  138. package/dist/src/runtime/steps/execution-agent/work-plan-contract.js +0 -55
  139. package/dist/src/runtime/steps/execution-agent/work-plan-schema.d.ts +3 -0
  140. package/dist/src/runtime/steps/execution-agent/work-plan-schema.js +61 -0
  141. package/dist/src/sessions/durable-session-commit.js +3 -3
  142. package/dist/src/sessions/prepared-session-replacement.d.ts +6 -0
  143. package/dist/src/sessions/prepared-session-replacement.js +46 -0
  144. package/dist/src/sessions/session-store.js +3 -3
  145. package/dist/src/shared/passive-observation-self-exclusion.d.ts +5 -0
  146. package/dist/src/shared/passive-observation-self-exclusion.js +37 -0
  147. package/dist/src/shared/windows-file-io/authority-script.d.ts +1 -0
  148. package/dist/src/shared/windows-file-io/authority-script.js +94 -0
  149. package/dist/src/shared/windows-file-io/native-script.d.ts +2 -0
  150. package/dist/src/shared/windows-file-io/native-script.js +120 -0
  151. package/dist/src/shared/windows-file-io/read-bytes-script.d.ts +1 -0
  152. package/dist/src/shared/windows-file-io/read-bytes-script.js +18 -0
  153. package/dist/src/shared/windows-job-object.d.ts +2 -0
  154. package/dist/src/shared/windows-job-object.js +66 -0
  155. package/dist/src/web-ui/app/app-bootstrap.js +14 -1
  156. package/dist/src/web-ui/app/app-state.js +0 -7
  157. package/dist/src/web-ui/app/app.js +53 -156
  158. package/dist/src/web-ui/app/components/automations/node-inspector.js +3 -2
  159. package/dist/src/web-ui/app/components/automations/step-editor-dialog.js +3 -0
  160. package/dist/src/web-ui/app/components/composer-submission-notice.js +50 -0
  161. package/dist/src/web-ui/app/components/config-workspace/model-plugin-permissions.js +7 -1
  162. package/dist/src/web-ui/app/components/config-workspace/workspace-mutations.js +22 -2
  163. package/dist/src/web-ui/app/components/home-guidance/daily-review.js +2 -2
  164. package/dist/src/web-ui/app/components/home-guidance/home-guidance.js +20 -6
  165. package/dist/src/web-ui/app/components/model-setup/context-window-feedback.js +53 -0
  166. package/dist/src/web-ui/app/components/model-setup/save-flow.js +3 -1
  167. package/dist/src/web-ui/app/components/model-setup/save-outcome.js +1 -0
  168. package/dist/src/web-ui/app/components/model-setup/wizard.js +12 -0
  169. package/dist/src/web-ui/app/components/passive-learning/activity-controls.js +4 -0
  170. package/dist/src/web-ui/app/components/passive-learning/collection-access.js +35 -0
  171. package/dist/src/web-ui/app/components/passive-learning/collection-consent-dialog.js +59 -0
  172. package/dist/src/web-ui/app/components/passive-learning/collection-consent-gate.js +94 -0
  173. package/dist/src/web-ui/app/components/passive-learning/computer-update-notice.js +6 -0
  174. package/dist/src/web-ui/app/components/passive-learning/failure-copy.js +1 -0
  175. package/dist/src/web-ui/app/components/passive-learning/home.js +7 -2
  176. package/dist/src/web-ui/app/components/passive-learning/macos-collection-restart-notice.js +1 -0
  177. package/dist/src/web-ui/app/components/passive-learning/memory.js +2 -4
  178. package/dist/src/web-ui/app/components/passive-learning/workspace-view.js +2 -2
  179. package/dist/src/web-ui/app/components/plugins/compatibility.js +13 -0
  180. package/dist/src/web-ui/app/components/plugins/discovery-rendering.js +9 -1
  181. package/dist/src/web-ui/app/components/plugins/installation-compatibility.js +7 -0
  182. package/dist/src/web-ui/app/components/plugins/installation.js +2 -1
  183. package/dist/src/web-ui/app/components/plugins/rendering.js +3 -0
  184. package/dist/src/web-ui/app/components/reasoning-override-prompt.js +82 -0
  185. package/dist/src/web-ui/app/components/runtime-config-activation.js +22 -8
  186. package/dist/src/web-ui/app/components/runtime-setup/optional-steps.js +7 -4
  187. package/dist/src/web-ui/app/components/runtime-setup/plugins.js +3 -1
  188. package/dist/src/web-ui/app/components/runtime-setup/rendering.js +6 -4
  189. package/dist/src/web-ui/app/components/runtime-setup-guide.d.ts +1 -0
  190. package/dist/src/web-ui/app/components/schedules/form.js +10 -8
  191. package/dist/src/web-ui/app/components/schedules/workspace.js +23 -4
  192. package/dist/src/web-ui/app/components/session-sidebar-sections.js +2 -2
  193. package/dist/src/web-ui/app/components/spark-chat/handoff-actions.js +9 -3
  194. package/dist/src/web-ui/app/components/spark-chat/placement.js +4 -7
  195. package/dist/src/web-ui/app/components/spark-chat/settings.js +7 -3
  196. package/dist/src/web-ui/app/components/system-host/macos-permissions.js +2 -0
  197. package/dist/src/web-ui/app/components/system-host/native-windows-access.js +50 -0
  198. package/dist/src/web-ui/app/components/system-host/rendering.js +3 -0
  199. package/dist/src/web-ui/app/components/workspace-storage-notice.js +37 -0
  200. package/dist/src/web-ui/app/configuration-environment-refresh.js +27 -34
  201. package/dist/src/web-ui/app/configuration-feature.js +9 -1
  202. package/dist/src/web-ui/app/controllers/app-event-bindings.js +38 -105
  203. package/dist/src/web-ui/app/controllers/chat-request-controller.d.ts +28 -0
  204. package/dist/src/web-ui/app/controllers/chat-request-controller.js +34 -66
  205. package/dist/src/web-ui/app/controllers/composer-attachments-controller.d.ts +15 -40
  206. package/dist/src/web-ui/app/controllers/composer-attachments-controller.js +26 -69
  207. package/dist/src/web-ui/app/controllers/composer-draft-view.d.ts +27 -0
  208. package/dist/src/web-ui/app/controllers/composer-draft-view.js +48 -0
  209. package/dist/src/web-ui/app/controllers/composer-drafts.d.ts +55 -0
  210. package/dist/src/web-ui/app/controllers/composer-drafts.js +120 -0
  211. package/dist/src/web-ui/app/controllers/composer-feature.d.ts +65 -0
  212. package/dist/src/web-ui/app/controllers/composer-feature.js +124 -0
  213. package/dist/src/web-ui/app/controllers/composer-queue-controller.d.ts +33 -94
  214. package/dist/src/web-ui/app/controllers/composer-queue-controller.js +185 -251
  215. package/dist/src/web-ui/app/controllers/composer-submission-lifecycle.d.ts +48 -0
  216. package/dist/src/web-ui/app/controllers/composer-submission-lifecycle.js +97 -0
  217. package/dist/src/web-ui/app/controllers/composer-submit-controller.d.ts +30 -61
  218. package/dist/src/web-ui/app/controllers/composer-submit-controller.js +56 -138
  219. package/dist/src/web-ui/app/controllers/composer-surface-controller.js +6 -0
  220. package/dist/src/web-ui/app/controllers/composer-workspace-controller.d.ts +22 -40
  221. package/dist/src/web-ui/app/controllers/composer-workspace-controller.js +49 -165
  222. package/dist/src/web-ui/app/controllers/conversation-navigation-intent.js +15 -0
  223. package/dist/src/web-ui/app/controllers/conversation-request-hydration.js +20 -17
  224. package/dist/src/web-ui/app/controllers/conversation-session-controller.d.ts +1 -2
  225. package/dist/src/web-ui/app/controllers/conversation-session-controller.js +49 -22
  226. package/dist/src/web-ui/app/controllers/conversation-workspace-activation.js +27 -0
  227. package/dist/src/web-ui/app/controllers/daily-memory-review.js +15 -16
  228. package/dist/src/web-ui/app/controllers/environment-transition.js +126 -0
  229. package/dist/src/web-ui/app/controllers/environment-workspace-preparation.js +18 -0
  230. package/dist/src/web-ui/app/controllers/home-composer-feature.d.ts +14 -36
  231. package/dist/src/web-ui/app/controllers/home-composer-feature.js +17 -114
  232. package/dist/src/web-ui/app/controllers/home-conversation-activation.js +6 -8
  233. package/dist/src/web-ui/app/controllers/passive-learning-controller.js +56 -0
  234. package/dist/src/web-ui/app/controllers/projects-controller.d.ts +1 -1
  235. package/dist/src/web-ui/app/controllers/projects-controller.js +6 -1
  236. package/dist/src/web-ui/app/controllers/reasoning-mode-controller.js +174 -0
  237. package/dist/src/web-ui/app/controllers/runtime-selection-controller.d.ts +7 -0
  238. package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +20 -155
  239. package/dist/src/web-ui/app/controllers/session-controller.js +33 -17
  240. package/dist/src/web-ui/app/controllers/session-pin-updates.js +14 -0
  241. package/dist/src/web-ui/app/controllers/session-sidebar-controller.js +12 -14
  242. package/dist/src/web-ui/app/controllers/spark-chat-sync.js +2 -2
  243. package/dist/src/web-ui/app/controllers/steer-controller.js +9 -7
  244. package/dist/src/web-ui/app/controllers/tool-permission-mode-controller.js +1 -1
  245. package/dist/src/web-ui/app/controllers/workspace-conversation-opener.js +34 -0
  246. package/dist/src/web-ui/app/dashboard-feature.js +3 -2
  247. package/dist/src/web-ui/app/lib/reasoning-controls.js +35 -0
  248. package/dist/src/web-ui/app/lib/session-composer-queue-ownership.js +58 -0
  249. package/dist/src/web-ui/app/lib/session-composer-queue.d.ts +12 -0
  250. package/dist/src/web-ui/app/lib/session-composer-queue.js +25 -6
  251. package/dist/src/web-ui/app/passive-learning-feature.js +16 -3
  252. package/dist/src/web-ui/app/schedules-feature.js +5 -3
  253. package/dist/src/web-ui/app/services/client-preferences.d.ts +18 -10
  254. package/dist/src/web-ui/app/services/client-preferences.js +25 -16
  255. package/dist/src/web-ui/app/services/home-guidance-preferences.js +13 -13
  256. package/dist/src/web-ui/app/services/reasoning-override.js +12 -0
  257. package/dist/src/web-ui/app/services/runtime-web-client/automations.js +10 -2
  258. package/dist/src/web-ui/app/services/runtime-web-client/memory.js +7 -2
  259. package/dist/src/web-ui/app/services/runtime-web-client/system-host.js +2 -0
  260. package/dist/src/web-ui/app/services/runtime-web-client.d.ts +2 -0
  261. package/dist/src/web-ui/app/services/runtime-web-client.js +2 -0
  262. package/dist/src/web-ui/app/services/server-composer-queue.js +32 -0
  263. package/dist/src/web-ui/app/services/session-sidebar-preferences.js +5 -5
  264. package/dist/src/web-ui/app/services/workspace-state-storage.js +116 -0
  265. package/dist/src/web-ui/app/services/workspace-state.js +27 -0
  266. package/dist/src/web-ui/app/spark-chat-conversation.js +34 -45
  267. package/dist/src/web-ui/app/spark-chat-feature.js +10 -4
  268. package/dist/src/web-ui/app/styles/21-composer-controls.css +16 -0
  269. package/dist/src/web-ui/app/styles/41-plugin-management.css +8 -0
  270. package/dist/src/web-ui/app/styles/42-model-plugin-permissions.css +1 -0
  271. package/dist/src/web-ui/app/styles/49-collection-consent.css +30 -0
  272. package/dist/src/web-ui/app/styles/64-workspace-storage.css +23 -0
  273. package/dist/src/web-ui/app/styles.css +2 -0
  274. package/dist/src/web-ui/client-state/contracts.d.ts +15 -0
  275. package/dist/src/web-ui/client-state/contracts.js +13 -0
  276. package/dist/src/web-ui/client-state/preference-shapes.d.ts +2 -0
  277. package/dist/src/web-ui/client-state/preference-shapes.js +80 -0
  278. package/dist/src/web-ui/client-state/preferences.d.ts +3 -0
  279. package/dist/src/web-ui/client-state/preferences.js +84 -0
  280. package/dist/src/web-ui/client-state/queue.d.ts +3 -0
  281. package/dist/src/web-ui/client-state/queue.js +43 -0
  282. package/dist/src/web-ui/client-state/routes.d.ts +7 -0
  283. package/dist/src/web-ui/client-state/routes.js +58 -0
  284. package/dist/src/web-ui/client-state/store.d.ts +14 -0
  285. package/dist/src/web-ui/client-state/store.js +88 -0
  286. package/dist/src/web-ui/local-runtime/configuration-activation-source.js +2 -0
  287. package/dist/src/web-ui/local-runtime/http.js +11 -2
  288. package/dist/src/web-ui/local-runtime/model-context-capacity-error.d.ts +14 -0
  289. package/dist/src/web-ui/local-runtime/model-context-capacity-error.js +28 -0
  290. package/dist/src/web-ui/local-runtime/model-setup-context-window.d.ts +15 -0
  291. package/dist/src/web-ui/local-runtime/model-setup-context-window.js +25 -0
  292. package/dist/src/web-ui/local-runtime/model-setup-routes.js +2 -0
  293. package/dist/src/web-ui/local-runtime/model-setup-service.js +5 -2
  294. package/dist/src/web-ui/local-runtime/model-setup-validation.d.ts +1 -0
  295. package/dist/src/web-ui/local-runtime/model-setup-validation.js +14 -7
  296. package/dist/src/web-ui/local-runtime/request-body-error.d.ts +11 -0
  297. package/dist/src/web-ui/local-runtime/request-body-error.js +14 -0
  298. package/dist/src/web-ui/local-runtime/request-control-observation.js +2 -2
  299. package/dist/src/web-ui/local-runtime/request-execution.js +18 -18
  300. package/dist/src/web-ui/local-runtime/runtime-setup-connection-edit.d.ts +2 -0
  301. package/dist/src/web-ui/local-runtime/runtime-setup-connection-edit.js +35 -22
  302. package/dist/src/web-ui/local-runtime/runtime-setup-context-window.d.ts +2 -9
  303. package/dist/src/web-ui/local-runtime/runtime-setup-context-window.js +4 -27
  304. package/dist/src/web-ui/local-runtime/runtime-setup-credentials.d.ts +15 -1
  305. package/dist/src/web-ui/local-runtime/runtime-setup-credentials.js +30 -11
  306. package/dist/src/web-ui/local-runtime/runtime-setup-edit-files.d.ts +20 -0
  307. package/dist/src/web-ui/local-runtime/runtime-setup-edit-files.js +104 -0
  308. package/dist/src/web-ui/local-runtime/runtime-setup-edit-journal.d.ts +29 -0
  309. package/dist/src/web-ui/local-runtime/runtime-setup-edit-journal.js +151 -0
  310. package/dist/src/web-ui/local-runtime/runtime-setup-edit-recovery.d.ts +7 -0
  311. package/dist/src/web-ui/local-runtime/runtime-setup-edit-recovery.js +87 -0
  312. package/dist/src/web-ui/local-runtime/runtime-setup-edit-transaction.d.ts +3 -0
  313. package/dist/src/web-ui/local-runtime/runtime-setup-edit-transaction.js +37 -0
  314. package/dist/src/web-ui/local-runtime/runtime-setup-service.js +4 -0
  315. package/dist/src/web-ui/local-runtime-backend.js +14 -0
  316. package/dist/src/web-ui/plugin-management-catalog.d.ts +3 -1
  317. package/dist/src/web-ui/plugin-management-catalog.js +3 -1
  318. package/dist/src/web-ui/plugin-management-service.d.ts +1 -0
  319. package/dist/src/web-ui/plugin-removal-service.d.ts +1 -0
  320. package/dist/src/web-ui/server-readiness.d.ts +3 -0
  321. package/dist/src/web-ui/server-readiness.js +36 -0
  322. package/dist/src/web-ui/server.d.ts +2 -0
  323. package/dist/src/web-ui/server.js +23 -1
  324. package/dist/src/web-ui/system-host-service.js +13 -2
  325. package/dist/src/web-ui/system-host-setup/collection-consent-route.d.ts +3 -0
  326. package/dist/src/web-ui/system-host-setup/collection-consent-route.js +30 -0
  327. package/docs/installation.md +44 -5
  328. package/docs/plugins.md +145 -4
  329. package/docs/tool-execution-result-evidence-contract.md +57 -0
  330. package/docs/windows-companion-store.md +5 -0
  331. package/package.json +4 -2
  332. package/plugins/capability-brief/plugin.json +4 -0
  333. package/plugins/code-outline/README.md +20 -0
  334. package/plugins/code-outline/plugin.json +1 -0
  335. package/plugins/code-outline/source/index.ts +16 -20
  336. package/plugins/code-outline/source/read-failure.ts +40 -0
  337. package/plugins/code-outline/src/index.cjs +614 -29
  338. package/plugins/document-reader/README.md +33 -0
  339. package/plugins/document-reader/plugin.json +1 -0
  340. package/plugins/document-reader/source/pdf-contract.ts +57 -0
  341. package/plugins/document-reader/source/pdf-parser.ts +139 -0
  342. package/plugins/document-reader/source/pdf-process-main.ts +56 -0
  343. package/plugins/document-reader/source/pdf-process.ts +207 -0
  344. package/plugins/document-reader/source/pdf-result.ts +79 -0
  345. package/plugins/document-reader/source/pdf-worker.ts +39 -303
  346. package/plugins/document-reader/source/pdf.ts +4 -1
  347. package/plugins/document-reader/source/read-failure.ts +37 -0
  348. package/plugins/document-reader/source/reader.ts +3 -19
  349. package/plugins/document-reader/src/index.cjs +995 -211
  350. package/plugins/exec/README.md +19 -0
  351. package/plugins/exec/plugin.json +4 -3
  352. package/plugins/exec/skills/exec_skill/SKILL.md +3 -2
  353. package/plugins/exec/source/filesystem-file-observer.ts +98 -0
  354. package/plugins/exec/source/filesystem-observer.ts +8 -79
  355. package/plugins/exec/source/output-files.ts +12 -6
  356. package/plugins/exec/source/paths.ts +3 -1
  357. package/plugins/exec/source/process-manager.ts +8 -24
  358. package/plugins/exec/source/shell-platform.ts +19 -3
  359. package/plugins/exec/source/shell-process.ts +55 -0
  360. package/plugins/exec/source/windows-job-source.ts +1 -0
  361. package/plugins/exec/source/windows-shell-bootstrap.ts +20 -0
  362. package/plugins/exec/src/index.cjs +252 -96
  363. package/plugins/filesystem/README.md +65 -0
  364. package/plugins/filesystem/plugin.json +6 -2
  365. package/plugins/filesystem/source/atomic-write.ts +2 -0
  366. package/plugins/filesystem/source/bounded-io.ts +80 -306
  367. package/plugins/filesystem/source/directory-sample.ts +2 -0
  368. package/plugins/filesystem/source/errors.ts +14 -0
  369. package/plugins/filesystem/source/file-observation.ts +151 -0
  370. package/plugins/filesystem/source/file-version.ts +41 -0
  371. package/plugins/filesystem/source/index.ts +6 -0
  372. package/plugins/filesystem/source/mutation-coordinator.ts +1 -0
  373. package/plugins/filesystem/source/windows/authority-script.ts +1 -0
  374. package/plugins/filesystem/source/windows/native-script.ts +1 -0
  375. package/plugins/filesystem/source/windows/operations.ts +197 -0
  376. package/plugins/filesystem/source/windows/process.ts +214 -0
  377. package/plugins/filesystem/source/windows/publication-script.ts +29 -0
  378. package/plugins/filesystem/source/windows/read-script.ts +63 -0
  379. package/plugins/filesystem/source/windows/request-availability.ts +67 -0
  380. package/plugins/filesystem/source/windows/source.ts +42 -0
  381. package/plugins/filesystem/source/windows/storage-script.ts +11 -0
  382. package/plugins/filesystem/source/windows/streams-script.ts +24 -0
  383. package/plugins/filesystem/source/windows/write-script.ts +86 -0
  384. package/plugins/filesystem/src/index.cjs +1208 -322
  385. package/plugins/json-inspector/README.md +18 -0
  386. package/plugins/json-inspector/plugin.json +1 -0
  387. package/plugins/json-inspector/source/index.ts +16 -19
  388. package/plugins/json-inspector/source/read-failure.ts +42 -0
  389. package/plugins/json-inspector/src/index.cjs +612 -27
  390. package/plugins/local-search/README.md +29 -0
  391. package/plugins/local-search/plugin.json +1 -0
  392. package/plugins/local-search/source/errors.ts +2 -0
  393. package/plugins/local-search/source/paths.ts +3 -0
  394. package/plugins/local-search/source/ripgrep-process.ts +31 -5
  395. package/plugins/local-search/source/ripgrep.ts +3 -3
  396. package/plugins/local-search/source/windows-authority.ts +99 -0
  397. package/plugins/local-search/source/windows-search-lease.ts +49 -0
  398. package/plugins/local-search/source/windows-search-process.ts +91 -0
  399. package/plugins/local-search/source/windows-search-script.ts +52 -0
  400. package/plugins/local-search/src/index.cjs +595 -26
  401. package/plugins/memory/plugin.json +4 -0
  402. package/plugins/memory/source/lock-directory-claim.ts +56 -0
  403. package/plugins/memory/source/lock-owner-file.ts +71 -0
  404. package/plugins/memory/source/lock-path-observation.ts +26 -0
  405. package/plugins/memory/source/prepared-memory-replacement.ts +40 -0
  406. package/plugins/memory/source/store-lock.ts +12 -7
  407. package/plugins/memory/source/store.ts +3 -2
  408. package/plugins/memory/src/index.cjs +174 -25
  409. package/plugins/project-orientation/README.md +23 -0
  410. package/plugins/project-orientation/plugin.json +1 -0
  411. package/plugins/project-orientation/source/index.ts +12 -9
  412. package/plugins/project-orientation/source/inspection-failure.ts +70 -0
  413. package/plugins/project-orientation/source/manifest-summary.ts +9 -2
  414. package/plugins/project-orientation/source/tree.ts +6 -0
  415. package/plugins/project-orientation/src/index.cjs +647 -31
  416. package/plugins/system/README.md +51 -15
  417. package/plugins/system/plugin.json +5 -1
  418. package/plugins/system/skills/system_actions/SKILL.md +1 -1
  419. package/plugins/system/source/command-working-directory.ts +47 -0
  420. package/plugins/system/source/computer/handlers.ts +13 -9
  421. package/plugins/system/source/computer/observation-result.ts +10 -5
  422. package/plugins/system/source/computer/request-computers.ts +10 -3
  423. package/plugins/system/source/computer/request-modules.ts +3 -6
  424. package/plugins/system/source/computer/runtime-platform.ts +18 -0
  425. package/plugins/system/source/host-dispatch.ts +18 -2
  426. package/plugins/system/source/index.ts +5 -3
  427. package/plugins/system/source/local-command-output-retention.ts +16 -0
  428. package/plugins/system/source/local-command-output.ts +16 -8
  429. package/plugins/system/source/request-system-modules.ts +12 -2
  430. package/plugins/system/source/request-target-snapshot.ts +2 -1
  431. package/plugins/system/source/security/desktop-result.ts +177 -0
  432. package/plugins/system/source/security/observed-error.ts +10 -0
  433. package/plugins/system/source/security/secret-text.ts +118 -0
  434. package/plugins/system/source/security/system-results.ts +62 -0
  435. package/plugins/system/source/security/windows-output-directory.ts +82 -0
  436. package/plugins/system/src/index.cjs +837 -151
  437. package/plugins/system-probe/plugin.json +8 -2
  438. package/plugins/system-probe/source/disk-path.ts +8 -0
  439. package/plugins/system-probe/source/index.ts +10 -5
  440. package/plugins/system-probe/source/machine-load.ts +33 -0
  441. package/plugins/system-probe/source/metrics.ts +6 -8
  442. package/plugins/system-probe/src/index.cjs +49 -16
  443. package/plugins/web/plugin.json +4 -0
@@ -0,0 +1,16 @@
1
+ /** Content authoring consumes one message even when its wire format is plain text. */
2
+ export function requiresSingleMessageOutput(request, payload) {
3
+ if (request.modelStep === "tool_payload.raw")
4
+ return true;
5
+ return hasStructuredTextFormat(payload);
6
+ }
7
+ function hasStructuredTextFormat(payload) {
8
+ const text = readRecord(payload.text);
9
+ const format = readRecord(text?.format);
10
+ return format?.type === "json_schema" || format?.type === "json_object";
11
+ }
12
+ function readRecord(value) {
13
+ if (value === null || typeof value !== "object" || Array.isArray(value))
14
+ return undefined;
15
+ return value;
16
+ }
@@ -1,9 +1,7 @@
1
1
  import { type OpenAISchemaProjectionDiagnostic } from "../../structured-output/projection.js";
2
2
  import type { ModelGatewayRequest } from "../../types.js";
3
- import type { ModelProviderInputTokenMeasurement } from "../contracts.js";
4
3
  export type OpenAIPayloadBuildOptions = Readonly<{
5
4
  onFormatProjection?: (diagnostics: readonly OpenAISchemaProjectionDiagnostic[]) => void;
6
- inputTokenMeasurement?: ModelProviderInputTokenMeasurement;
7
5
  }>;
8
6
  export declare function buildOpenAIResponsesPayload(requestBody: ModelGatewayRequest, payloadOptions?: OpenAIPayloadBuildOptions): Record<string, unknown>;
9
7
  export declare function buildOpenAIInputTokenCountPayload(requestBody: ModelGatewayRequest): Record<string, unknown>;
@@ -1,9 +1,8 @@
1
- import { resolveModelStepOutputTokenLimit } from "../../../shared/model-step-registry.js";
2
1
  import { openAIImageContents, projectOpenAIImageMessage } from "./image-content.js";
3
2
  import { isAssistantToolCallMessage, isToolResultMessage, validateModelGatewayMessages, } from "../../protocol/message-contract.js";
4
3
  import { resolveModelInvocation } from "../../policy/invocation-policy.js";
5
4
  import { projectOpenAIResponsesFormat, resolveModelGatewayFormat, } from "../../structured-output/projection.js";
6
- import { resolveProviderEnvelopeInputTokens } from "../envelope-budget.js";
5
+ import { projectOpenAIFunctionOutput } from "./function-output.js";
7
6
  function prependInstructionInput(params) {
8
7
  const instructions = (params.instructions ?? [])
9
8
  .map((line) => line.trim())
@@ -70,9 +69,6 @@ function readFiniteNumber(value) {
70
69
  ? value
71
70
  : undefined;
72
71
  }
73
- function hasExplicitlyDisabledOpenAIReasoning(invocation) {
74
- return invocation.profile.supportsThinking === true && invocation.think === "none";
75
- }
76
72
  export function buildOpenAIResponsesPayload(requestBody, payloadOptions = {}) {
77
73
  validateModelGatewayMessages(requestBody.messages);
78
74
  const invocation = resolveModelInvocation(requestBody);
@@ -103,26 +99,14 @@ export function buildOpenAIResponsesPayload(requestBody, payloadOptions = {}) {
103
99
  if (shouldProjectOpenAIReasoning) {
104
100
  payload.reasoning = { effort: reasoningEffort };
105
101
  }
106
- if (formatProjection.format) {
107
- payload.text = { format: formatProjection.format };
108
- }
109
- // Without an explicit provider disable, hidden reasoning may consume output.
110
- // A missing or false control declaration does not disable provider defaults.
111
- if (!hasExplicitlyDisabledOpenAIReasoning(invocation)) {
102
+ const functionOutput = projectOpenAIFunctionOutput(requestBody.modelStep, formatProjection.format);
103
+ if (functionOutput) {
104
+ Object.assign(payload, functionOutput);
112
105
  return payload;
113
106
  }
114
- const outputTokenLimit = resolveModelStepOutputTokenLimit(requestBody.modelStep);
115
- if (outputTokenLimit === undefined) {
116
- return payload;
107
+ if (formatProjection.format) {
108
+ payload.text = { format: formatProjection.format };
117
109
  }
118
- const { inputTokens } = resolveProviderEnvelopeInputTokens({
119
- payload,
120
- tokenEstimation: invocation.profile.context.tokenEstimation,
121
- ...(payloadOptions.inputTokenMeasurement
122
- ? { measurement: payloadOptions.inputTokenMeasurement }
123
- : {}),
124
- });
125
- payload.max_output_tokens = Math.max(1, Math.min(outputTokenLimit, invocation.profile.contextWindowTokens - inputTokens));
126
110
  return payload;
127
111
  }
128
112
  export function buildOpenAIInputTokenCountPayload(requestBody) {
@@ -130,6 +114,5 @@ export function buildOpenAIInputTokenCountPayload(requestBody) {
130
114
  delete payload.stream;
131
115
  delete payload.temperature;
132
116
  delete payload.top_p;
133
- delete payload.max_output_tokens;
134
117
  return payload;
135
118
  }
@@ -0,0 +1,2 @@
1
+ import { type OpenAIResponsesStreamOptions } from "./stream-normalizer.js";
2
+ export declare function bindOpenAIResponseLifetime(response: Response, options?: Pick<OpenAIResponsesStreamOptions, "functionOutputName">): Response;
@@ -0,0 +1,64 @@
1
+ import { OpenAISseDataDecoder } from "./sse-data.js";
2
+ import { OpenAIResponsesStreamNormalizer } from "./stream-normalizer.js";
3
+ function observeResponseFrame(data, normalizer) {
4
+ if (data === "[DONE]") {
5
+ normalizer.finish();
6
+ return;
7
+ }
8
+ let event;
9
+ try {
10
+ event = JSON.parse(data);
11
+ }
12
+ catch {
13
+ return;
14
+ }
15
+ normalizer.consume(event);
16
+ }
17
+ // End the one upstream body before tracing tees it. All consumers therefore
18
+ // receive the terminal bytes and EOF, even if the provider keeps HTTP open.
19
+ export function bindOpenAIResponseLifetime(response, options = {}) {
20
+ if (!response.ok || !response.body)
21
+ return response;
22
+ const reader = response.body.getReader();
23
+ const decoder = new OpenAISseDataDecoder();
24
+ const normalizer = new OpenAIResponsesStreamNormalizer(options);
25
+ let stopped = false;
26
+ const cancelUpstream = (reason) => {
27
+ stopped = true;
28
+ // Cleanup must not make protocol completion wait on transport teardown.
29
+ void reader.cancel(reason).catch(() => { });
30
+ reader.releaseLock();
31
+ };
32
+ const body = new ReadableStream({
33
+ async pull(controller) {
34
+ try {
35
+ const { done, value } = await reader.read();
36
+ if (stopped)
37
+ return;
38
+ if (done) {
39
+ stopped = true;
40
+ controller.close();
41
+ reader.releaseLock();
42
+ return;
43
+ }
44
+ for (const data of decoder.accept(value))
45
+ observeResponseFrame(data, normalizer);
46
+ controller.enqueue(value);
47
+ if (!normalizer.hasTerminated)
48
+ return;
49
+ controller.close();
50
+ cancelUpstream();
51
+ }
52
+ catch (error) {
53
+ if (stopped)
54
+ return;
55
+ controller.error(error);
56
+ cancelUpstream(error);
57
+ }
58
+ },
59
+ cancel: cancelUpstream,
60
+ });
61
+ return new Response(body, {
62
+ status: response.status, statusText: response.statusText, headers: response.headers,
63
+ });
64
+ }
@@ -0,0 +1,9 @@
1
+ export declare class OpenAISseDataDecoder {
2
+ private readonly decoder;
3
+ private line;
4
+ private data;
5
+ private afterCr;
6
+ accept(bytes: Uint8Array): string[];
7
+ private acceptLine;
8
+ }
9
+ export declare function readOpenAIDataFrames(body: ReadableStream<Uint8Array>): AsyncGenerator<string>;
@@ -0,0 +1,67 @@
1
+ // Decode complete SSE data frames identically for response lifetime and output.
2
+ // Event names are metadata; the Responses payload owns its typed event.
3
+ export class OpenAISseDataDecoder {
4
+ decoder = new TextDecoder();
5
+ line = "";
6
+ data = [];
7
+ afterCr = false;
8
+ accept(bytes) {
9
+ const text = this.decoder.decode(bytes, { stream: true });
10
+ const frames = [];
11
+ let start = 0;
12
+ for (let index = 0; index < text.length; index += 1) {
13
+ const char = text[index];
14
+ if (this.afterCr) {
15
+ this.afterCr = false;
16
+ if (char === "\n") {
17
+ start = index + 1;
18
+ continue;
19
+ }
20
+ }
21
+ if (char !== "\r" && char !== "\n")
22
+ continue;
23
+ this.line += text.slice(start, index);
24
+ this.acceptLine(frames);
25
+ this.line = "";
26
+ this.afterCr = char === "\r";
27
+ start = index + 1;
28
+ }
29
+ this.line += text.slice(start);
30
+ return frames;
31
+ }
32
+ acceptLine(frames) {
33
+ if (!this.line) {
34
+ if (this.data.length)
35
+ frames.push(this.data.join("\n"));
36
+ this.data = [];
37
+ return;
38
+ }
39
+ const colon = this.line.indexOf(":");
40
+ const field = colon < 0 ? this.line : this.line.slice(0, colon);
41
+ if (field !== "data")
42
+ return;
43
+ const value = colon < 0 ? "" : this.line.slice(colon + 1);
44
+ this.data.push(value.startsWith(" ") ? value.slice(1) : value);
45
+ }
46
+ }
47
+ export async function* readOpenAIDataFrames(body) {
48
+ const reader = body.getReader();
49
+ const decoder = new OpenAISseDataDecoder();
50
+ let reachedEof = false;
51
+ try {
52
+ while (true) {
53
+ const { done, value } = await reader.read();
54
+ if (done) {
55
+ reachedEof = true;
56
+ return;
57
+ }
58
+ yield* decoder.accept(value);
59
+ }
60
+ }
61
+ finally {
62
+ // A tee branch cannot await cancellation before the other readers finish.
63
+ if (!reachedEof)
64
+ void reader.cancel().catch(() => { });
65
+ reader.releaseLock();
66
+ }
67
+ }
@@ -1,25 +1,10 @@
1
1
  import type { ModelTokenUsage } from "../../types.js";
2
2
  import type { ModelProviderEventSink } from "../contracts.js";
3
- export type OpenAIMessageOutputNormalizationDiagnostic = Readonly<{
4
- outcome: "additional_message_outputs_ignored";
5
- outputCount: number;
6
- selectedOutput: Readonly<{
7
- itemId: string | null;
8
- outputIndex: number | null;
9
- arrivalOrder: number;
10
- textByteCount: number;
11
- }>;
12
- ignoredOutputCount: number;
13
- sampledIgnoredOutputs: readonly Readonly<{
14
- itemId: string | null;
15
- outputIndex: number | null;
16
- arrivalOrder: number;
17
- textByteCount: number;
18
- }>[];
19
- omittedIgnoredOutputCount: number;
20
- }>;
3
+ import { type OpenAIMessageOutputNormalizationDiagnostic } from "./structured-message-output.js";
4
+ export type { OpenAIMessageOutputNormalizationDiagnostic } from "./structured-message-output.js";
21
5
  export type OpenAIResponsesStreamOptions = Readonly<{
22
6
  structuredOutput?: boolean;
7
+ functionOutputName?: string;
23
8
  onMessageOutputDiagnostic?: (diagnostic: OpenAIMessageOutputNormalizationDiagnostic) => void;
24
9
  }>;
25
10
  export type NormalizedOpenAIStreamEvent = {
@@ -36,16 +21,19 @@ export type NormalizedOpenAIStreamEvent = {
36
21
  };
37
22
  export declare class OpenAIResponsesStreamNormalizer {
38
23
  private readonly options;
39
- private readonly outputs;
40
- private primaryOutputKey;
24
+ private readonly structuredOutput;
41
25
  private terminal;
42
26
  constructor(options: OpenAIResponsesStreamOptions);
27
+ get hasTerminated(): boolean;
43
28
  consume(data: unknown): NormalizedOpenAIStreamEvent[];
44
29
  finish(): NormalizedOpenAIStreamEvent[];
45
30
  private consumeTextDelta;
46
31
  private consumeIncompleteResponse;
47
- private getMessageOutput;
32
+ private consumeMessageItem;
33
+ end(): NormalizedOpenAIStreamEvent[];
34
+ private finishStructuredOutput;
35
+ private fail;
36
+ private finishFunctionOutput;
48
37
  private complete;
49
- private emitAdditionalOutputDiagnostic;
50
38
  }
51
39
  export declare function writeNormalizedOpenAIEvents(events: readonly NormalizedOpenAIStreamEvent[], sink: ModelProviderEventSink): void;
@@ -1,33 +1,10 @@
1
+ import { readOpenAIFunctionResult } from "./function-result.js";
1
2
  import { buildModelTokenUsage } from "../../protocol/usage.js";
2
- const OPENAI_IGNORED_MESSAGE_OUTPUT_DIAGNOSTIC_LIMIT = 8;
3
+ import { OpenAIStructuredMessageOutput, } from "./structured-message-output.js";
3
4
  function readRecord(value) {
4
5
  const isRecord = value !== null && typeof value === "object" && !Array.isArray(value);
5
6
  return isRecord ? value : {};
6
7
  }
7
- function resolveMessageOutputKey(params) {
8
- if (params.itemId !== null) {
9
- return `item:${params.itemId}`;
10
- }
11
- if (params.outputIndex !== null) {
12
- return `output:${params.outputIndex}`;
13
- }
14
- return "unidentified-message-output";
15
- }
16
- function readOpenAIMessageOutputIdentity(event) {
17
- const itemId = typeof event.item_id === "string" && event.item_id.length > 0
18
- ? event.item_id
19
- : null;
20
- const outputIndex = typeof event.output_index === "number" &&
21
- Number.isInteger(event.output_index) &&
22
- event.output_index >= 0
23
- ? event.output_index
24
- : null;
25
- return {
26
- key: resolveMessageOutputKey({ itemId, outputIndex }),
27
- itemId,
28
- outputIndex,
29
- };
30
- }
31
8
  function readOpenAIUsage(data) {
32
9
  const event = readRecord(data);
33
10
  const response = readRecord(event.response);
@@ -58,24 +35,42 @@ function readOpenAIIncompleteReason(data) {
58
35
  ? reason.trim()
59
36
  : "unknown_reason";
60
37
  }
38
+ function isMessageItemEvent(event) {
39
+ return event.type === "response.output_item.added" || event.type === "response.output_item.done";
40
+ }
41
+ function contentEvents(texts) {
42
+ return texts.map((text) => ({ type: "content", text }));
43
+ }
44
+ function isStreamError(event) {
45
+ return event.type === "error";
46
+ }
61
47
  export class OpenAIResponsesStreamNormalizer {
62
48
  options;
63
- outputs = new Map();
64
- primaryOutputKey;
49
+ structuredOutput = new OpenAIStructuredMessageOutput();
65
50
  terminal = false;
66
51
  constructor(options) {
67
52
  this.options = options;
68
53
  }
54
+ get hasTerminated() {
55
+ return this.terminal;
56
+ }
69
57
  consume(data) {
70
58
  if (this.terminal) {
71
59
  return [];
72
60
  }
73
61
  const event = readRecord(data);
62
+ const isFailedResponse = event.type === "response.failed";
63
+ if (isFailedResponse) {
64
+ return this.fail(readOpenAIError(event.response));
65
+ }
74
66
  if (event.type === "response.output_text.delta") {
75
67
  return this.consumeTextDelta(event);
76
68
  }
69
+ if (isMessageItemEvent(event)) {
70
+ return this.consumeMessageItem(event);
71
+ }
77
72
  if (event.type === "response.completed") {
78
- return this.complete(readOpenAIUsage(data));
73
+ return this.complete(readOpenAIUsage(data), undefined, event.response);
79
74
  }
80
75
  if (event.type === "response.incomplete") {
81
76
  return this.consumeIncompleteResponse(data);
@@ -87,9 +82,14 @@ export class OpenAIResponsesStreamNormalizer {
87
82
  return [];
88
83
  }
89
84
  finish() {
85
+ const events = this.end();
86
+ if (this.terminal)
87
+ return events;
90
88
  return this.complete(undefined);
91
89
  }
92
90
  consumeTextDelta(event) {
91
+ if (this.options.functionOutputName)
92
+ return [];
93
93
  const delta = typeof event.delta === "string" ? event.delta : "";
94
94
  if (!delta) {
95
95
  return [];
@@ -97,41 +97,69 @@ export class OpenAIResponsesStreamNormalizer {
97
97
  if (!this.options.structuredOutput) {
98
98
  return [{ type: "content", text: delta }];
99
99
  }
100
- const output = this.getMessageOutput(event);
101
- output.textByteCount += Buffer.byteLength(delta, "utf8");
102
- return output.key === this.primaryOutputKey
103
- ? [{ type: "content", text: delta }]
104
- : [];
100
+ return contentEvents(this.structuredOutput.consumeDelta(event, delta));
105
101
  }
106
102
  consumeIncompleteResponse(data) {
107
103
  const reason = readOpenAIIncompleteReason(data);
108
- if (reason === "max_output_tokens") {
109
- return this.complete(readOpenAIUsage(data), reason);
104
+ if (!this.options.functionOutputName && reason === "max_output_tokens") {
105
+ return this.complete(readOpenAIUsage(data), reason, readRecord(data).response);
110
106
  }
111
107
  this.terminal = true;
112
108
  return [{ type: "error", error: `openai response incomplete: ${reason}` }];
113
109
  }
114
- getMessageOutput(event) {
115
- const identity = readOpenAIMessageOutputIdentity(event);
116
- let output = this.outputs.get(identity.key);
117
- if (!output) {
118
- output = {
119
- ...identity,
120
- arrivalOrder: this.outputs.size + 1,
121
- textByteCount: 0,
122
- };
123
- this.outputs.set(identity.key, output);
124
- this.primaryOutputKey ??= identity.key;
125
- }
126
- return output;
110
+ consumeMessageItem(event) {
111
+ if (this.options.functionOutputName)
112
+ return [];
113
+ if (!this.options.structuredOutput)
114
+ return [];
115
+ return contentEvents(this.structuredOutput.observeItem(event));
116
+ }
117
+ // Transport endings cannot authorize decisions or payloads. Ordinary text
118
+ // retains its legacy partial-output behavior.
119
+ end() {
120
+ if (this.terminal)
121
+ return [];
122
+ if (this.options.functionOutputName)
123
+ return this.fail("openai function response not completed");
124
+ const requiresCompletedMessage = this.options.structuredOutput === true;
125
+ if (requiresCompletedMessage)
126
+ return this.fail("openai response not completed");
127
+ return [];
128
+ }
129
+ finishStructuredOutput(response) {
130
+ if (!this.options.structuredOutput)
131
+ return [];
132
+ const pending = this.structuredOutput.observeResponse(response);
133
+ const result = this.structuredOutput.finish();
134
+ if (result.error)
135
+ return [{ type: "error", error: result.error }];
136
+ const diagnostic = this.structuredOutput.diagnostic();
137
+ if (diagnostic)
138
+ this.options.onMessageOutputDiagnostic?.(diagnostic);
139
+ return contentEvents([...pending, ...result.text]);
127
140
  }
128
- complete(usage, doneReason) {
141
+ fail(error) {
142
+ this.terminal = true;
143
+ return [{ type: "error", error }];
144
+ }
145
+ finishFunctionOutput(response, name) {
146
+ const result = readOpenAIFunctionResult(response, name);
147
+ if ("error" in result)
148
+ return [{ type: "error", error: result.error }];
149
+ return [{ type: "content", text: result.text }];
150
+ }
151
+ complete(usage, doneReason, response) {
129
152
  if (this.terminal) {
130
153
  return [];
131
154
  }
132
- this.emitAdditionalOutputDiagnostic();
155
+ const pending = this.options.functionOutputName
156
+ ? this.finishFunctionOutput(response, this.options.functionOutputName)
157
+ : this.finishStructuredOutput(response);
133
158
  this.terminal = true;
159
+ if (pending.some(isStreamError))
160
+ return pending;
134
161
  return [
162
+ ...pending,
135
163
  {
136
164
  type: "done",
137
165
  done: true,
@@ -140,35 +168,6 @@ export class OpenAIResponsesStreamNormalizer {
140
168
  },
141
169
  ];
142
170
  }
143
- emitAdditionalOutputDiagnostic() {
144
- const hasAdditionalStructuredOutputs = this.options.structuredOutput && this.outputs.size > 1;
145
- if (!hasAdditionalStructuredOutputs) {
146
- return;
147
- }
148
- const outputs = [...this.outputs.values()];
149
- const selectedOutput = outputs[0];
150
- const ignoredOutputs = outputs.slice(1);
151
- this.options.onMessageOutputDiagnostic?.({
152
- outcome: "additional_message_outputs_ignored",
153
- outputCount: outputs.length,
154
- selectedOutput: {
155
- itemId: selectedOutput.itemId?.slice(0, 160) ?? null,
156
- outputIndex: selectedOutput.outputIndex,
157
- arrivalOrder: selectedOutput.arrivalOrder,
158
- textByteCount: selectedOutput.textByteCount,
159
- },
160
- ignoredOutputCount: ignoredOutputs.length,
161
- sampledIgnoredOutputs: ignoredOutputs
162
- .slice(0, OPENAI_IGNORED_MESSAGE_OUTPUT_DIAGNOSTIC_LIMIT)
163
- .map(({ itemId, outputIndex, arrivalOrder, textByteCount }) => ({
164
- itemId: itemId?.slice(0, 160) ?? null,
165
- outputIndex,
166
- arrivalOrder,
167
- textByteCount,
168
- })),
169
- omittedIgnoredOutputCount: Math.max(0, ignoredOutputs.length - OPENAI_IGNORED_MESSAGE_OUTPUT_DIAGNOSTIC_LIMIT),
170
- });
171
- }
172
171
  }
173
172
  export function writeNormalizedOpenAIEvents(events, sink) {
174
173
  for (const event of events) {
@@ -1,47 +1,11 @@
1
+ import { readOpenAIDataFrames } from "./sse-data.js";
1
2
  import { OpenAIResponsesStreamNormalizer, writeNormalizedOpenAIEvents, } from "./stream-normalizer.js";
2
- function parseSseEvents(buffer) {
3
- const events = [];
4
- let remaining = buffer;
5
- let boundaryIndex;
6
- while ((boundaryIndex = remaining.indexOf("\n\n")) !== -1) {
7
- events.push(remaining.slice(0, boundaryIndex));
8
- remaining = remaining.slice(boundaryIndex + 2);
9
- }
10
- return { events, rest: remaining };
11
- }
12
- function readSseData(eventBlock) {
13
- return eventBlock
14
- .split(/\r?\n/)
15
- .map((line) => line.trim())
16
- .filter((line) => line.startsWith("data:"))
17
- .map((line) => line.slice("data:".length).trim())
18
- .filter(Boolean);
19
- }
20
- async function* readOpenAIDataLines(body) {
21
- const reader = body.getReader();
22
- const decoder = new TextDecoder();
23
- let buffer = "";
24
- while (true) {
25
- const { done, value } = await reader.read();
26
- buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
27
- const parsed = parseSseEvents(buffer);
28
- buffer = parsed.rest;
29
- for (const eventBlock of parsed.events) {
30
- for (const dataLine of readSseData(eventBlock)) {
31
- yield dataLine;
32
- }
33
- }
34
- if (done) {
35
- break;
36
- }
37
- }
38
- }
39
3
  export async function forwardOpenAIResponsesStream(body, sink, options = {}) {
40
4
  const normalizer = new OpenAIResponsesStreamNormalizer(options);
41
- for await (const dataLine of readOpenAIDataLines(body)) {
5
+ for await (const dataLine of readOpenAIDataFrames(body)) {
42
6
  if (dataLine === "[DONE]") {
43
7
  writeNormalizedOpenAIEvents(normalizer.finish(), sink);
44
- continue;
8
+ break;
45
9
  }
46
10
  try {
47
11
  const event = JSON.parse(dataLine);
@@ -50,7 +14,10 @@ export async function forwardOpenAIResponsesStream(body, sink, options = {}) {
50
14
  catch {
51
15
  // Keep gateway behavior: ignore malformed upstream stream chunks.
52
16
  }
17
+ if (normalizer.hasTerminated)
18
+ break;
53
19
  }
20
+ writeNormalizedOpenAIEvents(normalizer.end(), sink);
54
21
  }
55
22
  function applyCollectedEvent(collected, event) {
56
23
  switch (event.type) {
@@ -68,12 +35,12 @@ function applyCollectedEvent(collected, event) {
68
35
  export async function collectOpenAIResponsesStream(body, options = {}) {
69
36
  const normalizer = new OpenAIResponsesStreamNormalizer(options);
70
37
  const collected = { text: "" };
71
- for await (const dataLine of readOpenAIDataLines(body)) {
38
+ for await (const dataLine of readOpenAIDataFrames(body)) {
72
39
  if (dataLine === "[DONE]") {
73
40
  for (const event of normalizer.finish()) {
74
41
  applyCollectedEvent(collected, event);
75
42
  }
76
- continue;
43
+ break;
77
44
  }
78
45
  let event;
79
46
  try {
@@ -86,6 +53,11 @@ export async function collectOpenAIResponsesStream(body, options = {}) {
86
53
  for (const normalized of normalizer.consume(event)) {
87
54
  applyCollectedEvent(collected, normalized);
88
55
  }
56
+ if (normalizer.hasTerminated)
57
+ break;
58
+ }
59
+ for (const event of normalizer.end()) {
60
+ applyCollectedEvent(collected, event);
89
61
  }
90
62
  return {
91
63
  text: collected.text,
@@ -0,0 +1,42 @@
1
+ type MessagePhase = "commentary" | "final_answer";
2
+ type OutputDiagnostic = Readonly<{
3
+ itemId: string | null;
4
+ outputIndex: number | null;
5
+ arrivalOrder: number;
6
+ textByteCount: number;
7
+ phase?: MessagePhase;
8
+ }>;
9
+ export type OpenAIMessageOutputNormalizationDiagnostic = Readonly<{
10
+ outcome: "additional_message_outputs_ignored";
11
+ outputCount: number;
12
+ selectedOutput: OutputDiagnostic;
13
+ ignoredOutputCount: number;
14
+ sampledIgnoredOutputs: readonly OutputDiagnostic[];
15
+ omittedIgnoredOutputCount: number;
16
+ }>;
17
+ /** One invocation's structured result; never infer its phase from generated text. */
18
+ export declare class OpenAIStructuredMessageOutput {
19
+ private readonly outputs;
20
+ private readonly byItemId;
21
+ private readonly byOutputIndex;
22
+ private unidentifiedOutput;
23
+ private firstTextOutput;
24
+ private selectedOutput;
25
+ private hasExplicitPhase;
26
+ private nextOutputOrder;
27
+ private nextChunkSequence;
28
+ observeItem(event: Record<string, unknown>): string[];
29
+ observeResponse(value: unknown): string[];
30
+ consumeDelta(event: Record<string, unknown>, text: string): string[];
31
+ finish(): {
32
+ text: string[];
33
+ error?: string;
34
+ };
35
+ diagnostic(): OpenAIMessageOutputNormalizationDiagnostic | undefined;
36
+ private selectFinalOutput;
37
+ private takeSelectedText;
38
+ private mergeOutputs;
39
+ private reconcileOutputs;
40
+ private resolveOutput;
41
+ }
42
+ export {};