@superblocksteam/vite-plugin-file-sync 2.0.178-next.2 → 2.0.179-next.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 (389) hide show
  1. package/dist/agent-tool-executor/claude-sandbox.d.ts +1 -2
  2. package/dist/agent-tool-executor/claude-sandbox.d.ts.map +1 -1
  3. package/dist/agent-tool-executor/claude-sandbox.js +1 -3
  4. package/dist/agent-tool-executor/claude-sandbox.js.map +1 -1
  5. package/dist/agent-tool-executor/claude-shell.d.ts +1 -14
  6. package/dist/agent-tool-executor/claude-shell.d.ts.map +1 -1
  7. package/dist/agent-tool-executor/claude-shell.js +7 -61
  8. package/dist/agent-tool-executor/claude-shell.js.map +1 -1
  9. package/dist/agent-tool-executor/claude-tools.d.ts +0 -4
  10. package/dist/agent-tool-executor/claude-tools.d.ts.map +1 -1
  11. package/dist/agent-tool-executor/claude-tools.js +1 -1
  12. package/dist/agent-tool-executor/claude-tools.js.map +1 -1
  13. package/dist/agent-tool-executor/codex-drafts.d.ts +1 -2
  14. package/dist/agent-tool-executor/codex-drafts.d.ts.map +1 -1
  15. package/dist/agent-tool-executor/codex-drafts.js +1 -4
  16. package/dist/agent-tool-executor/codex-drafts.js.map +1 -1
  17. package/dist/agent-tool-executor/codex-execution-policy.d.ts +1 -1
  18. package/dist/agent-tool-executor/codex-execution-policy.d.ts.map +1 -1
  19. package/dist/agent-tool-executor/codex-execution-policy.js +15 -2
  20. package/dist/agent-tool-executor/codex-execution-policy.js.map +1 -1
  21. package/dist/agent-tool-executor/native-os-sandbox.d.ts +2 -2
  22. package/dist/agent-tool-executor/native-os-sandbox.js +2 -2
  23. package/dist/agent-tool-executor/native-tool-servers.d.ts +10 -5
  24. package/dist/agent-tool-executor/native-tool-servers.d.ts.map +1 -1
  25. package/dist/agent-tool-executor/native-tool-servers.js +23 -9
  26. package/dist/agent-tool-executor/native-tool-servers.js.map +1 -1
  27. package/dist/ai-service/agent/middleware.d.ts.map +1 -1
  28. package/dist/ai-service/agent/middleware.js +1 -0
  29. package/dist/ai-service/agent/middleware.js.map +1 -1
  30. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +6 -0
  31. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
  32. package/dist/ai-service/agent/prompts/build-base-system-prompt.js +4 -0
  33. package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
  34. package/dist/ai-service/agent/prompts/project-prompt.d.ts +11 -0
  35. package/dist/ai-service/agent/prompts/project-prompt.d.ts.map +1 -0
  36. package/dist/ai-service/agent/prompts/project-prompt.js +20 -0
  37. package/dist/ai-service/agent/prompts/project-prompt.js.map +1 -0
  38. package/dist/ai-service/agent/tools/apis/test-api.d.ts +57 -0
  39. package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
  40. package/dist/ai-service/agent/tools/apis/test-api.js +1 -1
  41. package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
  42. package/dist/ai-service/agent/tools/branching/branch-tools.d.ts +2 -8
  43. package/dist/ai-service/agent/tools/branching/branch-tools.d.ts.map +1 -1
  44. package/dist/ai-service/agent/tools/branching/branch-tools.js +8 -8
  45. package/dist/ai-service/agent/tools/branching/branch-tools.js.map +1 -1
  46. package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts +1 -0
  47. package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
  48. package/dist/ai-service/agent/tools/build-capture-screenshot.js +24 -1
  49. package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
  50. package/dist/ai-service/agent/tools/build-list-files.d.ts +1 -1
  51. package/dist/ai-service/agent/tools/build-list-files.d.ts.map +1 -1
  52. package/dist/ai-service/agent/tools/build-list-files.js +14 -1
  53. package/dist/ai-service/agent/tools/build-list-files.js.map +1 -1
  54. package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts +6 -6
  55. package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts.map +1 -1
  56. package/dist/ai-service/agent/tools/search-web.d.ts +22 -0
  57. package/dist/ai-service/agent/tools/search-web.d.ts.map +1 -0
  58. package/dist/ai-service/agent/tools/search-web.js +87 -0
  59. package/dist/ai-service/agent/tools/search-web.js.map +1 -0
  60. package/dist/ai-service/attachments/artifact-reference.d.ts +14 -0
  61. package/dist/ai-service/attachments/artifact-reference.d.ts.map +1 -0
  62. package/dist/ai-service/attachments/artifact-reference.js +28 -0
  63. package/dist/ai-service/attachments/artifact-reference.js.map +1 -0
  64. package/dist/ai-service/attachments/artifact-storage.d.ts +61 -0
  65. package/dist/ai-service/attachments/artifact-storage.d.ts.map +1 -0
  66. package/dist/ai-service/attachments/artifact-storage.js +178 -0
  67. package/dist/ai-service/attachments/artifact-storage.js.map +1 -0
  68. package/dist/ai-service/attachments/native-attachment-preparations.d.ts +32 -0
  69. package/dist/ai-service/attachments/native-attachment-preparations.d.ts.map +1 -0
  70. package/dist/ai-service/attachments/native-attachment-preparations.js +80 -0
  71. package/dist/ai-service/attachments/native-attachment-preparations.js.map +1 -0
  72. package/dist/ai-service/attachments/text-upload-artifacts.d.ts +14 -10
  73. package/dist/ai-service/attachments/text-upload-artifacts.d.ts.map +1 -1
  74. package/dist/ai-service/attachments/text-upload-artifacts.js +21 -86
  75. package/dist/ai-service/attachments/text-upload-artifacts.js.map +1 -1
  76. package/dist/ai-service/attachments/upload-artifact-paths.d.ts +2 -0
  77. package/dist/ai-service/attachments/upload-artifact-paths.d.ts.map +1 -1
  78. package/dist/ai-service/attachments/upload-artifact-paths.js +2 -0
  79. package/dist/ai-service/attachments/upload-artifact-paths.js.map +1 -1
  80. package/dist/ai-service/attachments/uploaded-content-part.d.ts +1 -0
  81. package/dist/ai-service/attachments/uploaded-content-part.d.ts.map +1 -1
  82. package/dist/ai-service/attachments/uploaded-content-part.js +3 -7
  83. package/dist/ai-service/attachments/uploaded-content-part.js.map +1 -1
  84. package/dist/ai-service/attachments/validate-prompt-attachments.d.ts +12 -3
  85. package/dist/ai-service/attachments/validate-prompt-attachments.d.ts.map +1 -1
  86. package/dist/ai-service/attachments/validate-prompt-attachments.js +171 -55
  87. package/dist/ai-service/attachments/validate-prompt-attachments.js.map +1 -1
  88. package/dist/ai-service/builder-context-usage.d.ts +12 -0
  89. package/dist/ai-service/builder-context-usage.d.ts.map +1 -0
  90. package/dist/ai-service/builder-context-usage.js +23 -0
  91. package/dist/ai-service/builder-context-usage.js.map +1 -0
  92. package/dist/ai-service/builder-conversation.d.ts +65 -9
  93. package/dist/ai-service/builder-conversation.d.ts.map +1 -1
  94. package/dist/ai-service/builder-conversation.js +229 -62
  95. package/dist/ai-service/builder-conversation.js.map +1 -1
  96. package/dist/ai-service/builder-core-prompt.d.ts +23 -0
  97. package/dist/ai-service/builder-core-prompt.d.ts.map +1 -0
  98. package/dist/ai-service/builder-core-prompt.js +148 -0
  99. package/dist/ai-service/builder-core-prompt.js.map +1 -0
  100. package/dist/ai-service/builder-failure-drain.d.ts +25 -0
  101. package/dist/ai-service/builder-failure-drain.d.ts.map +1 -0
  102. package/dist/ai-service/builder-failure-drain.js +67 -0
  103. package/dist/ai-service/builder-failure-drain.js.map +1 -0
  104. package/dist/ai-service/builder-failure-notice.d.ts +21 -0
  105. package/dist/ai-service/builder-failure-notice.d.ts.map +1 -0
  106. package/dist/ai-service/builder-failure-notice.js +47 -0
  107. package/dist/ai-service/builder-failure-notice.js.map +1 -0
  108. package/dist/ai-service/builder-inference-auth.d.ts +5 -2
  109. package/dist/ai-service/builder-inference-auth.d.ts.map +1 -1
  110. package/dist/ai-service/builder-inference-auth.js +25 -4
  111. package/dist/ai-service/builder-inference-auth.js.map +1 -1
  112. package/dist/ai-service/builder-runtime-auth-metrics.d.ts +15 -0
  113. package/dist/ai-service/builder-runtime-auth-metrics.d.ts.map +1 -0
  114. package/dist/ai-service/builder-runtime-auth-metrics.js +40 -0
  115. package/dist/ai-service/builder-runtime-auth-metrics.js.map +1 -0
  116. package/dist/ai-service/builder-runtime-auth.d.ts +53 -0
  117. package/dist/ai-service/builder-runtime-auth.d.ts.map +1 -0
  118. package/dist/ai-service/builder-runtime-auth.js +166 -0
  119. package/dist/ai-service/builder-runtime-auth.js.map +1 -0
  120. package/dist/ai-service/builder-runtime.d.ts +201 -23
  121. package/dist/ai-service/builder-runtime.d.ts.map +1 -1
  122. package/dist/ai-service/builder-runtime.js +355 -109
  123. package/dist/ai-service/builder-runtime.js.map +1 -1
  124. package/dist/ai-service/builder-skills-auth.d.ts +16 -0
  125. package/dist/ai-service/builder-skills-auth.d.ts.map +1 -0
  126. package/dist/ai-service/builder-skills-auth.js +107 -0
  127. package/dist/ai-service/builder-skills-auth.js.map +1 -0
  128. package/dist/ai-service/builder-subagents.d.ts +37 -0
  129. package/dist/ai-service/builder-subagents.d.ts.map +1 -0
  130. package/dist/ai-service/builder-subagents.js +103 -0
  131. package/dist/ai-service/builder-subagents.js.map +1 -0
  132. package/dist/ai-service/builder-tool-callbacks.d.ts.map +1 -1
  133. package/dist/ai-service/builder-tool-callbacks.js +21 -4
  134. package/dist/ai-service/builder-tool-callbacks.js.map +1 -1
  135. package/dist/ai-service/builder-tools.d.ts +11 -7
  136. package/dist/ai-service/builder-tools.d.ts.map +1 -1
  137. package/dist/ai-service/builder-tools.js +89 -34
  138. package/dist/ai-service/builder-tools.js.map +1 -1
  139. package/dist/ai-service/builder-workspace.d.ts +48 -0
  140. package/dist/ai-service/builder-workspace.d.ts.map +1 -1
  141. package/dist/ai-service/builder-workspace.js +139 -19
  142. package/dist/ai-service/builder-workspace.js.map +1 -1
  143. package/dist/ai-service/chat/chat-session-store.d.ts +31 -3
  144. package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
  145. package/dist/ai-service/chat/chat-session-store.js +104 -10
  146. package/dist/ai-service/chat/chat-session-store.js.map +1 -1
  147. package/dist/ai-service/context-download.d.ts +4 -2
  148. package/dist/ai-service/context-download.d.ts.map +1 -1
  149. package/dist/ai-service/context-download.js +13 -3
  150. package/dist/ai-service/context-download.js.map +1 -1
  151. package/dist/ai-service/demo-agents/api-tools.d.ts +14 -0
  152. package/dist/ai-service/demo-agents/api-tools.d.ts.map +1 -0
  153. package/dist/ai-service/demo-agents/api-tools.js +58 -0
  154. package/dist/ai-service/demo-agents/api-tools.js.map +1 -0
  155. package/dist/ai-service/demo-agents/enabled.d.ts +7 -0
  156. package/dist/ai-service/demo-agents/enabled.d.ts.map +1 -0
  157. package/dist/ai-service/demo-agents/enabled.js +8 -0
  158. package/dist/ai-service/demo-agents/enabled.js.map +1 -0
  159. package/dist/ai-service/demo-agents/handlers.d.ts +77 -0
  160. package/dist/ai-service/demo-agents/handlers.d.ts.map +1 -0
  161. package/dist/ai-service/demo-agents/handlers.js +95 -0
  162. package/dist/ai-service/demo-agents/handlers.js.map +1 -0
  163. package/dist/ai-service/demo-agents/load-agents.d.ts +9 -0
  164. package/dist/ai-service/demo-agents/load-agents.d.ts.map +1 -0
  165. package/dist/ai-service/demo-agents/load-agents.js +76 -0
  166. package/dist/ai-service/demo-agents/load-agents.js.map +1 -0
  167. package/dist/ai-service/demo-agents/run-agent.d.ts +39 -0
  168. package/dist/ai-service/demo-agents/run-agent.d.ts.map +1 -0
  169. package/dist/ai-service/demo-agents/run-agent.js +119 -0
  170. package/dist/ai-service/demo-agents/run-agent.js.map +1 -0
  171. package/dist/ai-service/demo-agents/sessions.d.ts +5 -0
  172. package/dist/ai-service/demo-agents/sessions.d.ts.map +1 -0
  173. package/dist/ai-service/demo-agents/sessions.js +33 -0
  174. package/dist/ai-service/demo-agents/sessions.js.map +1 -0
  175. package/dist/ai-service/demo-agents/system-prompt.d.ts +12 -0
  176. package/dist/ai-service/demo-agents/system-prompt.d.ts.map +1 -0
  177. package/dist/ai-service/demo-agents/system-prompt.js +56 -0
  178. package/dist/ai-service/demo-agents/system-prompt.js.map +1 -0
  179. package/dist/ai-service/demo-agents/types.d.ts +95 -0
  180. package/dist/ai-service/demo-agents/types.d.ts.map +1 -0
  181. package/dist/ai-service/demo-agents/types.js +15 -0
  182. package/dist/ai-service/demo-agents/types.js.map +1 -0
  183. package/dist/ai-service/features.d.ts +11 -0
  184. package/dist/ai-service/features.d.ts.map +1 -1
  185. package/dist/ai-service/features.js +11 -0
  186. package/dist/ai-service/features.js.map +1 -1
  187. package/dist/ai-service/index.d.ts +202 -4
  188. package/dist/ai-service/index.d.ts.map +1 -1
  189. package/dist/ai-service/index.js +1020 -104
  190. package/dist/ai-service/index.js.map +1 -1
  191. package/dist/ai-service/judge/tools/playwright-action.d.ts +5 -5
  192. package/dist/ai-service/llm/context-v2/compaction/server-side.d.ts +5 -1
  193. package/dist/ai-service/llm/context-v2/compaction/server-side.d.ts.map +1 -1
  194. package/dist/ai-service/llm/context-v2/compaction/server-side.js +9 -2
  195. package/dist/ai-service/llm/context-v2/compaction/server-side.js.map +1 -1
  196. package/dist/ai-service/llm/context-v2/context-management.d.ts +5 -0
  197. package/dist/ai-service/llm/context-v2/context-management.d.ts.map +1 -1
  198. package/dist/ai-service/llm/context-v2/context-management.js +3 -0
  199. package/dist/ai-service/llm/context-v2/context-management.js.map +1 -1
  200. package/dist/ai-service/llm/context-v2/context-metrics.d.ts.map +1 -1
  201. package/dist/ai-service/llm/context-v2/context-metrics.js +3 -2
  202. package/dist/ai-service/llm/context-v2/context-metrics.js.map +1 -1
  203. package/dist/ai-service/llm/context-v2/manager.d.ts +2 -1
  204. package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
  205. package/dist/ai-service/llm/context-v2/manager.js +12 -1
  206. package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
  207. package/dist/ai-service/llm/context-v2/types.d.ts +10 -0
  208. package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
  209. package/dist/ai-service/llm/context-v2/types.js +43 -8
  210. package/dist/ai-service/llm/context-v2/types.js.map +1 -1
  211. package/dist/ai-service/llm/error.d.ts +16 -0
  212. package/dist/ai-service/llm/error.d.ts.map +1 -1
  213. package/dist/ai-service/llm/error.js +69 -0
  214. package/dist/ai-service/llm/error.js.map +1 -1
  215. package/dist/ai-service/llm/stream/config.d.ts +2 -2
  216. package/dist/ai-service/llm/stream/config.d.ts.map +1 -1
  217. package/dist/ai-service/llm/stream/config.js +6 -4
  218. package/dist/ai-service/llm/stream/config.js.map +1 -1
  219. package/dist/ai-service/llm/stream/observers/retry-notification.d.ts.map +1 -1
  220. package/dist/ai-service/llm/stream/observers/retry-notification.js +8 -1
  221. package/dist/ai-service/llm/stream/observers/retry-notification.js.map +1 -1
  222. package/dist/ai-service/llm/stream/orchestrator.d.ts +1 -0
  223. package/dist/ai-service/llm/stream/orchestrator.d.ts.map +1 -1
  224. package/dist/ai-service/llm/stream/orchestrator.js +53 -1
  225. package/dist/ai-service/llm/stream/orchestrator.js.map +1 -1
  226. package/dist/ai-service/llm/stream/retry-engine.d.ts +3 -1
  227. package/dist/ai-service/llm/stream/retry-engine.d.ts.map +1 -1
  228. package/dist/ai-service/llm/stream/retry-engine.js +21 -4
  229. package/dist/ai-service/llm/stream/retry-engine.js.map +1 -1
  230. package/dist/ai-service/llm/stream/retry-schedule.d.ts +27 -0
  231. package/dist/ai-service/llm/stream/retry-schedule.d.ts.map +1 -0
  232. package/dist/ai-service/llm/stream/retry-schedule.js +28 -0
  233. package/dist/ai-service/llm/stream/retry-schedule.js.map +1 -0
  234. package/dist/ai-service/llm/stream/session.d.ts +2 -0
  235. package/dist/ai-service/llm/stream/session.d.ts.map +1 -1
  236. package/dist/ai-service/llm/stream/session.js +2 -0
  237. package/dist/ai-service/llm/stream/session.js.map +1 -1
  238. package/dist/ai-service/llm/terminal-error-message.d.ts +67 -0
  239. package/dist/ai-service/llm/terminal-error-message.d.ts.map +1 -0
  240. package/dist/ai-service/llm/terminal-error-message.js +154 -0
  241. package/dist/ai-service/llm/terminal-error-message.js.map +1 -0
  242. package/dist/ai-service/native-secret-redactor.js +1 -1
  243. package/dist/ai-service/native-secret-redactor.js.map +1 -1
  244. package/dist/ai-service/native-turn-failure.d.ts +35 -0
  245. package/dist/ai-service/native-turn-failure.d.ts.map +1 -0
  246. package/dist/ai-service/native-turn-failure.js +149 -0
  247. package/dist/ai-service/native-turn-failure.js.map +1 -0
  248. package/dist/ai-service/outbound-trace-context.d.ts +18 -0
  249. package/dist/ai-service/outbound-trace-context.d.ts.map +1 -0
  250. package/dist/ai-service/outbound-trace-context.js +20 -0
  251. package/dist/ai-service/outbound-trace-context.js.map +1 -0
  252. package/dist/ai-service/policy-gate-review.d.ts +18 -3
  253. package/dist/ai-service/policy-gate-review.d.ts.map +1 -1
  254. package/dist/ai-service/policy-gate-review.js +32 -10
  255. package/dist/ai-service/policy-gate-review.js.map +1 -1
  256. package/dist/ai-service/security/secret-scanner-service.d.ts +2 -1
  257. package/dist/ai-service/security/secret-scanner-service.d.ts.map +1 -1
  258. package/dist/ai-service/security/secret-scanner-service.js +60 -9
  259. package/dist/ai-service/security/secret-scanner-service.js.map +1 -1
  260. package/dist/ai-service/security/secret-scanner.d.ts +17 -16
  261. package/dist/ai-service/security/secret-scanner.d.ts.map +1 -1
  262. package/dist/ai-service/security/secret-scanner.js +91 -159
  263. package/dist/ai-service/security/secret-scanner.js.map +1 -1
  264. package/dist/ai-service/security/trufflehog-diagnostics.d.ts +17 -0
  265. package/dist/ai-service/security/trufflehog-diagnostics.d.ts.map +1 -0
  266. package/dist/ai-service/security/trufflehog-diagnostics.js +20 -0
  267. package/dist/ai-service/security/trufflehog-diagnostics.js.map +1 -0
  268. package/dist/ai-service/security/trufflehog-process.d.ts +80 -0
  269. package/dist/ai-service/security/trufflehog-process.d.ts.map +1 -0
  270. package/dist/ai-service/security/trufflehog-process.js +305 -0
  271. package/dist/ai-service/security/trufflehog-process.js.map +1 -0
  272. package/dist/ai-service/state-machine/clark-fsm.d.ts +3 -0
  273. package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
  274. package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
  275. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts +0 -12
  276. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
  277. package/dist/ai-service/state-machine/handlers/agent-planning.js +3 -121
  278. package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
  279. package/dist/ai-service/state-machine/handlers/idle.d.ts.map +1 -1
  280. package/dist/ai-service/state-machine/handlers/idle.js +3 -2
  281. package/dist/ai-service/state-machine/handlers/idle.js.map +1 -1
  282. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
  283. package/dist/ai-service/state-machine/handlers/llm-generating.js +27 -11
  284. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
  285. package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
  286. package/dist/ai-service/state-machine/helpers/stable-peer.js +14 -5
  287. package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
  288. package/dist/ai-service/types.d.ts +2 -0
  289. package/dist/ai-service/types.d.ts.map +1 -1
  290. package/dist/ai-service/types.js.map +1 -1
  291. package/dist/ai-service/workspace-metrics.d.ts +1 -0
  292. package/dist/ai-service/workspace-metrics.d.ts.map +1 -1
  293. package/dist/ai-service/workspace-metrics.js +14 -1
  294. package/dist/ai-service/workspace-metrics.js.map +1 -1
  295. package/dist/attachment-artifacts.d.ts +4 -0
  296. package/dist/attachment-artifacts.d.ts.map +1 -0
  297. package/dist/attachment-artifacts.js +4 -0
  298. package/dist/attachment-artifacts.js.map +1 -0
  299. package/dist/dev-server-ws-smoke-client.d.ts.map +1 -1
  300. package/dist/dev-server-ws-smoke-client.js +1 -0
  301. package/dist/dev-server-ws-smoke-client.js.map +1 -1
  302. package/dist/file-sync-vite-plugin.d.ts.map +1 -1
  303. package/dist/file-sync-vite-plugin.js +51 -2
  304. package/dist/file-sync-vite-plugin.js.map +1 -1
  305. package/dist/git-service/credential-scope.d.ts +1 -0
  306. package/dist/git-service/credential-scope.d.ts.map +1 -1
  307. package/dist/git-service/credential-scope.js +56 -1
  308. package/dist/git-service/credential-scope.js.map +1 -1
  309. package/dist/index.d.ts +9 -0
  310. package/dist/index.d.ts.map +1 -1
  311. package/dist/index.js +5 -0
  312. package/dist/index.js.map +1 -1
  313. package/dist/inject-index-vite-plugin.d.ts.map +1 -1
  314. package/dist/inject-index-vite-plugin.js +2 -0
  315. package/dist/inject-index-vite-plugin.js.map +1 -1
  316. package/dist/injected-index.d.ts.map +1 -1
  317. package/dist/injected-index.js +2 -0
  318. package/dist/injected-index.js.map +1 -1
  319. package/dist/lock-service/branch-metrics.d.ts +3 -0
  320. package/dist/lock-service/branch-metrics.d.ts.map +1 -0
  321. package/dist/lock-service/branch-metrics.js +15 -0
  322. package/dist/lock-service/branch-metrics.js.map +1 -0
  323. package/dist/lock-service/index.d.ts +9 -0
  324. package/dist/lock-service/index.d.ts.map +1 -1
  325. package/dist/lock-service/index.js +55 -7
  326. package/dist/lock-service/index.js.map +1 -1
  327. package/dist/plugin-options.d.ts +7 -7
  328. package/dist/plugin-options.d.ts.map +1 -1
  329. package/dist/policy-gate-live-step.d.ts +25 -0
  330. package/dist/policy-gate-live-step.d.ts.map +1 -0
  331. package/dist/policy-gate-live-step.js +197 -0
  332. package/dist/policy-gate-live-step.js.map +1 -0
  333. package/dist/policy-gate-run-registry.d.ts +10 -0
  334. package/dist/policy-gate-run-registry.d.ts.map +1 -1
  335. package/dist/policy-gate-run-registry.js +28 -0
  336. package/dist/policy-gate-run-registry.js.map +1 -1
  337. package/dist/policy-gate-runner.d.ts +9 -1
  338. package/dist/policy-gate-runner.d.ts.map +1 -1
  339. package/dist/policy-gate-runner.js +100 -36
  340. package/dist/policy-gate-runner.js.map +1 -1
  341. package/dist/policy-gates/authorization.d.ts +9 -0
  342. package/dist/policy-gates/authorization.d.ts.map +1 -0
  343. package/dist/policy-gates/authorization.js +12 -0
  344. package/dist/policy-gates/authorization.js.map +1 -0
  345. package/dist/policy-gates/index.d.ts +5 -0
  346. package/dist/policy-gates/index.d.ts.map +1 -0
  347. package/dist/policy-gates/index.js +4 -0
  348. package/dist/policy-gates/index.js.map +1 -0
  349. package/dist/policy-gates/metrics.d.ts +23 -0
  350. package/dist/policy-gates/metrics.d.ts.map +1 -0
  351. package/dist/policy-gates/metrics.js +19 -0
  352. package/dist/policy-gates/metrics.js.map +1 -0
  353. package/dist/project-agent-tools.d.ts +23 -0
  354. package/dist/project-agent-tools.d.ts.map +1 -0
  355. package/dist/project-agent-tools.js +73 -0
  356. package/dist/project-agent-tools.js.map +1 -0
  357. package/dist/project-functions.d.ts +19 -0
  358. package/dist/project-functions.d.ts.map +1 -0
  359. package/dist/project-functions.js +70 -0
  360. package/dist/project-functions.js.map +1 -0
  361. package/dist/project-manifest.d.ts +150 -0
  362. package/dist/project-manifest.d.ts.map +1 -0
  363. package/dist/project-manifest.js +284 -0
  364. package/dist/project-manifest.js.map +1 -0
  365. package/dist/review-runner.d.ts.map +1 -1
  366. package/dist/review-runner.js +12 -14
  367. package/dist/review-runner.js.map +1 -1
  368. package/dist/socket-manager.d.ts +2 -1
  369. package/dist/socket-manager.d.ts.map +1 -1
  370. package/dist/socket-manager.js +162 -6
  371. package/dist/socket-manager.js.map +1 -1
  372. package/dist/sync-service/index.d.ts.map +1 -1
  373. package/dist/sync-service/index.js +2 -0
  374. package/dist/sync-service/index.js.map +1 -1
  375. package/dist/workspace-sync-methods.d.ts +21 -1
  376. package/dist/workspace-sync-methods.d.ts.map +1 -1
  377. package/package.json +17 -21
  378. package/dist/agent-tool-executor/claude-sandbox-placeholders.d.ts +0 -38
  379. package/dist/agent-tool-executor/claude-sandbox-placeholders.d.ts.map +0 -1
  380. package/dist/agent-tool-executor/claude-sandbox-placeholders.js +0 -132
  381. package/dist/agent-tool-executor/claude-sandbox-placeholders.js.map +0 -1
  382. package/dist/ai-service/skills/system/native.d.ts +0 -15
  383. package/dist/ai-service/skills/system/native.d.ts.map +0 -1
  384. package/dist/ai-service/skills/system/native.js +0 -32
  385. package/dist/ai-service/skills/system/native.js.map +0 -1
  386. package/dist/native-system-skills.d.ts +0 -2
  387. package/dist/native-system-skills.d.ts.map +0 -1
  388. package/dist/native-system-skills.js +0 -4
  389. package/dist/native-system-skills.js.map +0 -1
@@ -1,17 +1,23 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { BedrockAgentCoreClient, InvokeAgentRuntimeCommand, } from "@aws-sdk/client-bedrock-agentcore";
3
- import { context, propagation, trace } from "@opentelemetry/api";
2
+ import { context, trace } from "@opentelemetry/api";
4
3
  import { asSchema, tool } from "ai";
5
4
  import { z } from "zod";
6
5
  import { NativeBuilderModel, } from "@superblocksteam/shared";
7
- import { WORKSPACE_INGRESS_PORT, deriveWorkspaceEndpointToken, deriveWorkspaceToken, workspaceEndpointSchema, } from "@superblocksteam/workspace-sync/control";
6
+ import { BUILDER_RUNTIME_ENDPOINT_HEADER, BUILDER_RUNTIME_INVOCATIONS_PATH, BUILDER_RUNTIME_SESSION_HEADER, BUILDER_RUNTIME_SIGN_GRANT_HEADER, BUILDER_RUNTIME_SIGN_PATH, WORKSPACE_INGRESS_PORT, builderRuntimeEndpointHeaderSchema, deriveWorkspaceEndpointToken, deriveWorkspaceToken, workspaceEndpointSchema, } from "@superblocksteam/workspace-sync/control";
8
7
  import { getErrorMeta } from "../util/logger.js";
9
8
  import { getToolOutput } from "./agent/tool-message-utils.js";
10
9
  import { movesEditor } from "./agent/tools/branching/branch-tools.js";
10
+ import { BuilderFailureDrain, } from "./builder-failure-drain.js";
11
11
  import { BuilderInferenceAuthError } from "./builder-inference-auth.js";
12
12
  import { AgentCoreToolHost } from "./builder-tool-callbacks.js";
13
13
  import { NativeCallbackOrder } from "./native-callback-order.js";
14
14
  import { NativeSecretRedactor } from "./native-secret-redactor.js";
15
+ import { OutboundTraceContext, } from "./outbound-trace-context.js";
16
+ /** Runtime control calls whose failure to authorize inference stops the turn. */
17
+ const INFERENCE_AUTH_CALLS = new Set([
18
+ "__runtime_redact",
19
+ "__runtime_inference_token",
20
+ ]);
15
21
  const executionDescriptorSchema = z
16
22
  .object({
17
23
  token: z.string().min(32).max(4096),
@@ -26,11 +32,30 @@ const executionDescriptorSchema = z
26
32
  .max(2048),
27
33
  })
28
34
  .strict();
35
+ const tokenCountSchema = z.number().int().nonnegative();
36
+ /** How full the root conversation's context window is when a turn ends. */
37
+ const contextUsageSchema = z.object({
38
+ usedTokens: tokenCountSchema,
39
+ windowTokens: tokenCountSchema,
40
+ /** Occupancy at which the harness summarizes older messages. */
41
+ compactionTokens: tokenCountSchema,
42
+ breakdown: z
43
+ .object({
44
+ systemPrompt: tokenCountSchema,
45
+ tools: tokenCountSchema,
46
+ conversation: tokenCountSchema,
47
+ })
48
+ .optional()
49
+ .catch(undefined),
50
+ });
29
51
  const usageSchema = z.object({
30
- inputTokens: z.number().int().nonnegative(),
31
- outputTokens: z.number().int().nonnegative(),
32
- cacheReadTokens: z.number().int().nonnegative().optional(),
33
- cacheWriteTokens: z.number().int().nonnegative().optional(),
52
+ inputTokens: tokenCountSchema,
53
+ outputTokens: tokenCountSchema,
54
+ cacheReadTokens: tokenCountSchema.optional(),
55
+ cacheWriteTokens: tokenCountSchema.optional(),
56
+ // Lenient: the ring is a convenience, so a shape this host does not know
57
+ // must not fail the stream parse.
58
+ context: contextUsageSchema.optional().catch(undefined),
34
59
  });
35
60
  /**
36
61
  * Workspace state on an AgentCore `finish` event. Not strict: the runtime may
@@ -47,7 +72,25 @@ const workspaceFinishSchema = z.object({
47
72
  * the VM's `/sb-dev-updates`; `workspace.open` returns it.
48
73
  */
49
74
  internalToken: z.string().min(1).max(4096).optional(),
75
+ /** `workspace.open` from a runtime that accepts a turn's `ownerId`. */
76
+ ownerScoped: z.boolean().optional(),
50
77
  });
78
+ /**
79
+ * Why a native turn failed, as the runtime classifies it. Mirrors the
80
+ * runtime's wire enum; the host and runtime deploy independently, so a value
81
+ * this host does not know reads as `unknown`.
82
+ */
83
+ const runtimeFailureReasonSchema = z.enum([
84
+ "context_window_exceeded",
85
+ "usage_limit_exceeded",
86
+ "inference_rejected",
87
+ "inference_unavailable",
88
+ "stream_interrupted",
89
+ "attachment_limit_exceeded",
90
+ "attachment_unavailable",
91
+ "attachment_unsupported",
92
+ "unknown",
93
+ ]);
51
94
  const eventSchema = z.discriminatedUnion("type", [
52
95
  z.object({ type: z.literal("session"), sessionId: z.string().min(1) }),
53
96
  z.object({ type: z.literal("callback-ready"), id: z.string().uuid() }),
@@ -62,6 +105,9 @@ const eventSchema = z.discriminatedUnion("type", [
62
105
  toolCallId: z.string(),
63
106
  toolName: z.string(),
64
107
  input: z.unknown(),
108
+ // The sub-agent call this call was made inside. Lenient: grouping is a
109
+ // convenience and must not fail the stream parse.
110
+ parentToolCallId: z.string().optional().catch(undefined),
65
111
  }),
66
112
  z.object({
67
113
  type: z.literal("tool-result"),
@@ -81,19 +127,46 @@ const eventSchema = z.discriminatedUnion("type", [
81
127
  type: z.literal("error"),
82
128
  message: z.string(),
83
129
  code: z.string().optional(),
130
+ // Lenient: an unrecognized value must not fail the stream parse.
131
+ reason: runtimeFailureReasonSchema.catch("unknown").optional(),
132
+ // Set when the invocation failed before its turn began to run.
133
+ beforeTurn: z.boolean().optional().catch(undefined),
134
+ // Older runtimes marked beforeTurn only before session acquisition.
135
+ runSubmitted: z.boolean().optional().catch(true),
84
136
  }),
85
137
  ]);
138
+ /** A bounded runtime failure; user advice is owned by the shared failure taxonomy. */
86
139
  export class BuilderRuntimeError extends Error {
87
140
  code;
88
- constructor(code) {
89
- super(code === "SESSION_EXPIRED"
90
- ? "The native builder session expired. Start a new chat to continue."
91
- : code === "SESSION_SCOPE_CHANGED"
92
- ? "The active chat changed, so this request stopped. Reconnect to the editor before sending another prompt."
93
- : "Native builder runtime failed");
141
+ beforeTurn;
142
+ runSubmitted;
143
+ cleanupConfirmed;
144
+ cleanupOutcome;
145
+ reason;
146
+ constructor(code, reason = "unknown",
147
+ /** Whether the invocation failed before its turn began to run. */
148
+ beforeTurn = false,
149
+ /** Whether the session recorded this run ID before the failure. */
150
+ runSubmitted = false,
151
+ /** Whether the runtime acknowledged completing cleanup for this invocation. */
152
+ cleanupConfirmed = true,
153
+ /** The terminal cleanup observation when confirmation failed. */
154
+ cleanupOutcome) {
155
+ super("The builder runtime reported a failure");
94
156
  this.code = code;
157
+ this.beforeTurn = beforeTurn;
158
+ this.runSubmitted = runSubmitted;
159
+ this.cleanupConfirmed = cleanupConfirmed;
160
+ this.cleanupOutcome = cleanupOutcome;
161
+ // Re-validated: a caller can still pass an unchecked wire value.
162
+ this.reason = runtimeFailureReasonSchema.catch("unknown").parse(reason);
163
+ }
164
+ /** Preserves the reported failure while forbidding an automatic retry. */
165
+ withUnconfirmedCleanup(outcome = "stream_failed") {
166
+ return new BuilderRuntimeError(this.code, this.reason, this.beforeTurn, this.runSubmitted, false, outcome);
95
167
  }
96
- static log(error, logger) {
168
+ /** Logs the safe failure classification and its invocation-attempt context. */
169
+ static log(error, logger, attempt) {
97
170
  const code = error instanceof BuilderRuntimeError
98
171
  ? z
99
172
  .enum([
@@ -108,12 +181,32 @@ export class BuilderRuntimeError extends Error {
108
181
  ])
109
182
  .safeParse(error.code)
110
183
  : undefined;
184
+ const reason = error instanceof BuilderRuntimeError
185
+ ? runtimeFailureReasonSchema.catch("unknown").parse(error.reason)
186
+ : undefined;
111
187
  logger.warn("Native builder operation failed", {
112
188
  ...getErrorMeta(error),
113
189
  ...(code && { "failure.code": code.success ? code.data : "unknown" }),
190
+ ...(reason && { "failure.reason": reason }),
191
+ ...(error instanceof BuilderRuntimeError && {
192
+ "failure.before_turn": error.beforeTurn,
193
+ "failure.run_submitted": error.runSubmitted,
194
+ "failure.cleanup_confirmed": error.cleanupConfirmed,
195
+ ...(error.cleanupOutcome && {
196
+ "failure.cleanup_outcome": error.cleanupOutcome,
197
+ }),
198
+ }),
199
+ ...(attempt && {
200
+ "retry.attempt": attempt.attempt,
201
+ "retry.will_retry": attempt.willRetry,
202
+ }),
114
203
  });
115
204
  }
116
205
  }
206
+ /** An AWS SDK service error, which carries the HTTP status AgentCore answered. */
207
+ const awsServiceErrorSchema = z.object({
208
+ $metadata: z.object({ httpStatusCode: z.number().int() }),
209
+ });
117
210
  /** A non-2xx answer from the local runtime, before any event streamed. */
118
211
  export class BuilderRuntimeHttpError extends Error {
119
212
  status;
@@ -121,18 +214,20 @@ export class BuilderRuntimeHttpError extends Error {
121
214
  super(`Native builder runtime answered HTTP ${status}`);
122
215
  this.status = status;
123
216
  }
217
+ /** The HTTP status a local runtime or AgentCore failure carries, if any. */
218
+ static statusOf(error) {
219
+ if (error instanceof BuilderRuntimeHttpError)
220
+ return error.status;
221
+ return awsServiceErrorSchema.safeParse(error).data?.$metadata
222
+ .httpStatusCode;
223
+ }
124
224
  }
125
225
  /**
126
226
  * The W3C trace context of `ctx` as invocation payload fields. Empty when no
127
227
  * propagator is installed or `ctx` holds no span.
128
228
  */
129
229
  export function invocationTraceContext(ctx = context.active()) {
130
- const carrier = {};
131
- propagation.inject(ctx, carrier);
132
- return {
133
- ...(carrier.traceparent && { traceparent: carrier.traceparent }),
134
- ...(carrier.tracestate && { tracestate: carrier.tracestate }),
135
- };
230
+ return OutboundTraceContext.fields(ctx);
136
231
  }
137
232
  /**
138
233
  * AgentCore returned no session endpoint for `workspace.open`: the runtime is
@@ -146,25 +241,11 @@ export class WorkspaceEndpointMissingError extends Error {
146
241
  this.name = "WorkspaceEndpointMissingError";
147
242
  }
148
243
  }
149
- /**
150
- * The URL that reaches `port` in the VM. AgentCore returns the session
151
- * endpoint without a port, and that bare host answers AccessDenied; each
152
- * allowed port is addressed as `<port>--<host>`. A URL that already names a
153
- * port is kept as it is.
154
- */
155
- export function sessionEndpointForPort(sessionEndpointUrl, port) {
156
- const url = new URL(sessionEndpointUrl);
157
- if (!/^\d+--/.test(url.hostname))
158
- url.hostname = `${port}--${url.hostname}`;
159
- return url.origin;
160
- }
244
+ export { sessionEndpointForPort } from "@superblocksteam/workspace-sync/control";
161
245
  export class BuilderRuntime {
162
246
  harness;
163
- runtimeArn;
164
- qualifier;
165
247
  callback;
166
248
  remoteEnvironment;
167
- region;
168
249
  localUrl;
169
250
  localToken;
170
251
  execution;
@@ -174,9 +255,7 @@ export class BuilderRuntime {
174
255
  static configuredHarnesses(env) {
175
256
  return ["codex", "claude_code"].filter((harness) => {
176
257
  try {
177
- const runtime = this.fromEnvironment(env, true, "", "/", harness);
178
- runtime?.client?.destroy();
179
- return runtime !== undefined;
258
+ return this.fromEnvironment(env, true, "", "/", harness) !== undefined;
180
259
  }
181
260
  catch {
182
261
  return false;
@@ -188,26 +267,20 @@ export class BuilderRuntime {
188
267
  get model() {
189
268
  return this.selectedModel ?? NativeBuilderModel.resolve(this.harness);
190
269
  }
191
- client;
192
- constructor(harness, runtimeArn, qualifier, callback, remoteEnvironment, region, localUrl, localToken, execution,
270
+ constructor(harness, callback, remoteEnvironment, localUrl, localToken, execution,
193
271
  /** Keys the workspace token; see {@link workspaceEdge}. */
194
272
  workspaceSecret = "",
195
273
  /** The local VM ingress, overriding the default next to `localUrl`. */
196
274
  localWorkspaceUrl, selectedModel) {
197
275
  this.harness = harness;
198
- this.runtimeArn = runtimeArn;
199
- this.qualifier = qualifier;
200
276
  this.callback = callback;
201
277
  this.remoteEnvironment = remoteEnvironment;
202
- this.region = region;
203
278
  this.localUrl = localUrl;
204
279
  this.localToken = localToken;
205
280
  this.execution = execution;
206
281
  this.workspaceSecret = workspaceSecret;
207
282
  this.localWorkspaceUrl = localWorkspaceUrl;
208
283
  this.selectedModel = selectedModel;
209
- if (!localUrl)
210
- this.client = new BedrockAgentCoreClient({ region, maxAttempts: 1 });
211
284
  }
212
285
  static fromEnvironment(env, splitMode, applicationId, appRootDirPath, harness = env.SUPERBLOCKS_BUILDER_HARNESS ?? "clark", execution) {
213
286
  if (harness === "clark")
@@ -217,6 +290,8 @@ export class BuilderRuntime {
217
290
  if (!splitMode)
218
291
  throw new Error("Native builder requires split live-edit mode");
219
292
  const prefix = harness === "codex" ? "CODEX" : "CLAUDE";
293
+ // The runtime ARN only says the harness is on: the server invokes its own
294
+ // configured runtime, so this process never names one to AgentCore.
220
295
  const runtimeArn = env[`SUPERBLOCKS_AGENTCORE_${prefix}_RUNTIME_ARN`] ?? "";
221
296
  const match = /^arn:aws(?:-us-gov|-cn)?:bedrock-agentcore:([a-z0-9-]+):[0-9]{12}:runtime\/[A-Za-z][A-Za-z0-9_-]*$/.exec(runtimeArn);
222
297
  let localUrl = env.SUPERBLOCKS_BUILDER_RUNTIME_URL;
@@ -247,7 +322,7 @@ export class BuilderRuntime {
247
322
  throw new Error("Native builder requires an execution control token of at least 32 characters");
248
323
  if (!appRootDirPath?.startsWith("/"))
249
324
  throw new Error("Native builder requires an absolute application root");
250
- return new BuilderRuntime(harness, runtimeArn, qualifier, {
325
+ return new BuilderRuntime(harness, {
251
326
  url: this.websocketUrl(env.SUPERBLOCKS_BUILDER_CALLBACK_URL, "/sb-updates", !!localUrl),
252
327
  token: randomBytes(32).toString("hex"),
253
328
  appId: applicationId,
@@ -257,13 +332,13 @@ export class BuilderRuntime {
257
332
  : (env.SUPERBLOCKS_CLAUDE_TOOL_SERVER_URL ??
258
333
  env.SUPERBLOCKS_CODEX_EXEC_SERVER_URL), "/sb-dev-exec", !!localUrl),
259
334
  cwd: appRootDirPath,
260
- }, match?.[1], localUrl, env.SUPERBLOCKS_BUILDER_RUNTIME_TOKEN, execution, env.SUPERBLOCKS_AGENT_TOOL_TOKEN, env.SUPERBLOCKS_BUILDER_WORKSPACE_URL || undefined);
335
+ }, localUrl, env.SUPERBLOCKS_BUILDER_RUNTIME_TOKEN, execution, env.SUPERBLOCKS_AGENT_TOOL_TOKEN, env.SUPERBLOCKS_BUILDER_WORKSPACE_URL || undefined);
261
336
  }
262
337
  withModel(preferredModel) {
263
338
  const model = NativeBuilderModel.resolve(this.harness, preferredModel);
264
339
  if (model === this.model)
265
340
  return this;
266
- return new BuilderRuntime(this.harness, this.runtimeArn, this.qualifier, this.callback, this.remoteEnvironment, this.region, this.localUrl, this.localToken, this.execution, this.workspaceSecret, this.localWorkspaceUrl, model);
341
+ return new BuilderRuntime(this.harness, this.callback, this.remoteEnvironment, this.localUrl, this.localToken, this.execution, this.workspaceSecret, this.localWorkspaceUrl, model);
267
342
  }
268
343
  static isLoopback(url) {
269
344
  return ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname);
@@ -280,6 +355,32 @@ export class BuilderRuntime {
280
355
  throw new Error(`Native builder requires a wss URL ending in ${pathname}`);
281
356
  return url.toString();
282
357
  }
358
+ /**
359
+ * A hidden control tool that mints a fresh credential for the runtime in the VM. When the
360
+ * mint finds the chat or branch changed, `onScopeChanged` receives the failure that stops the turn.
361
+ */
362
+ credentialRenewalTool(credential, refresh, turnSignal, onScopeChanged) {
363
+ return tool({
364
+ inputSchema: z.object({}).strict(),
365
+ execute: async (_input, { abortSignal }) => {
366
+ if (!refresh)
367
+ throw new Error(`Native builder has no ${credential} refresh path`);
368
+ try {
369
+ const token = await refresh(abortSignal ?? turnSignal);
370
+ return { token: z.string().min(1).parse(token) };
371
+ }
372
+ catch (error) {
373
+ if (error instanceof BuilderInferenceAuthError)
374
+ onScopeChanged(new BuilderRuntimeError(error.code));
375
+ throw error;
376
+ }
377
+ },
378
+ toModelOutput: ({ output }) => ({
379
+ type: "json",
380
+ value: { token: output.token },
381
+ }),
382
+ });
383
+ }
283
384
  providerFor(_model) {
284
385
  return this.harness === "codex" ? "openai" : "anthropic";
285
386
  }
@@ -288,34 +389,70 @@ export class BuilderRuntime {
288
389
  throw new Error("Native model tools cannot use the reserved runtime namespace");
289
390
  if (!options.inference?.token || !/^[a-f0-9]{64}$/.test(options.actorId))
290
391
  throw new Error("Native builder requires scoped inference credentials and actor identity");
392
+ if (!options.skills?.token)
393
+ throw new Error("Native builder requires Skills credentials");
291
394
  const inferenceUrl = new URL(options.inference.url);
292
- if (!(inferenceUrl.protocol === "https:" ||
395
+ const skillsUrl = new URL(options.skills.url);
396
+ const isValidProxyUrl = (url) => (url.protocol === "https:" ||
293
397
  (this.localUrl &&
294
- inferenceUrl.protocol === "http:" &&
295
- BuilderRuntime.isLoopback(inferenceUrl))) ||
296
- inferenceUrl.username ||
297
- inferenceUrl.password ||
298
- inferenceUrl.search ||
299
- inferenceUrl.hash)
398
+ url.protocol === "http:" &&
399
+ BuilderRuntime.isLoopback(url))) &&
400
+ !url.username &&
401
+ !url.password &&
402
+ !url.search &&
403
+ !url.hash;
404
+ if (!isValidProxyUrl(inferenceUrl))
300
405
  throw new Error("Invalid native inference proxy URL");
406
+ if (!isValidProxyUrl(skillsUrl))
407
+ throw new Error("Invalid native Skills proxy URL");
301
408
  // A workspace turn's tools run in the VM, not on a remote environment,
302
409
  // so there is no DEV execution to authorize.
303
410
  const execution = options.workspaceLocal ? undefined : this.execution;
304
411
  if (!execution && !options.workspaceLocal)
305
412
  throw new Error("Native builder requires DEV execution authorization");
306
413
  const callbacks = new NativeCallbackOrder();
414
+ let restoredAttachments;
307
415
  const callbackResults = new Map();
308
416
  let inferenceFailure;
417
+ let skillsFailure;
309
418
  const closeTools = this.toolHost.register({
310
419
  traceContext: options.traceContext,
311
420
  runId: options.runId,
312
421
  concurrentTools: new Set([
313
422
  ...(options.concurrentTools ?? []),
314
423
  "__runtime_redact",
424
+ "__runtime_skills_token",
425
+ "__runtime_inference_token",
315
426
  ]),
316
427
  tools: {
317
428
  ...options.tools,
318
429
  ...options.callbackTools,
430
+ __runtime_attachment: tool({
431
+ inputSchema: z
432
+ .object({
433
+ index: z.number().int().nonnegative().optional(),
434
+ offset: z.number().int().nonnegative().optional(),
435
+ history: z.boolean().optional(),
436
+ })
437
+ .strict(),
438
+ execute: async ({ index, offset, history }) => {
439
+ const files = history
440
+ ? await (restoredAttachments ??=
441
+ options.restoreAttachments?.() ?? Promise.resolve([]))
442
+ : (options.attachments ?? []);
443
+ if (index === undefined)
444
+ return { count: files.length };
445
+ const file = files[index];
446
+ if (!file || offset === undefined || offset > file.bytes.byteLength)
447
+ throw new Error("Attachment is unavailable");
448
+ return {
449
+ fileName: file.fileName,
450
+ mimeType: file.mimeType,
451
+ sizeBytes: file.bytes.byteLength,
452
+ data: Buffer.from(file.bytes.subarray(offset, offset + 256 * 1024)).toString("base64"),
453
+ };
454
+ },
455
+ }),
319
456
  __runtime_redact: tool({
320
457
  inputSchema: z
321
458
  .object({
@@ -354,6 +491,12 @@ export class BuilderRuntime {
354
491
  }),
355
492
  }),
356
493
  }),
494
+ __runtime_skills_token: this.credentialRenewalTool("Skills", options.refreshSkills?.bind(options), options.signal, (failure) => {
495
+ skillsFailure = failure;
496
+ }),
497
+ __runtime_inference_token: this.credentialRenewalTool("inference", options.refreshInference?.bind(options), options.signal, (failure) => {
498
+ inferenceFailure = failure;
499
+ }),
357
500
  },
358
501
  messages: [],
359
502
  signal: options.signal,
@@ -374,7 +517,8 @@ export class BuilderRuntime {
374
517
  }
375
518
  const stopReason = movesEditor(result.output)
376
519
  ? "branch_navigation"
377
- : result.toolName === "__runtime_redact" && inferenceFailure
520
+ : (INFERENCE_AUTH_CALLS.has(result.toolName) && inferenceFailure) ||
521
+ (result.toolName === "__runtime_skills_token" && skillsFailure)
378
522
  ? "inference_auth_failure"
379
523
  : undefined;
380
524
  if (stopReason)
@@ -386,6 +530,7 @@ export class BuilderRuntime {
386
530
  });
387
531
  let mustRevoke = false;
388
532
  let failure;
533
+ let invoked = false;
389
534
  try {
390
535
  options.signal.throwIfAborted();
391
536
  mustRevoke = !!execution;
@@ -396,19 +541,29 @@ export class BuilderRuntime {
396
541
  name,
397
542
  description: tool.description ?? "",
398
543
  inputSchema: await asSchema(tool.inputSchema).jsonSchema,
544
+ ...(options.concurrentTools?.has(name) && { readOnly: true }),
399
545
  })));
400
546
  const payload = JSON.stringify({
401
547
  provider: this.providerFor(this.model),
402
548
  model: this.model,
403
549
  mode: options.mode ?? "build",
404
550
  prompt: options.prompt,
551
+ ...(options.attachments?.length && {
552
+ attachmentCount: options.attachments.length,
553
+ }),
405
554
  system: options.system,
406
555
  tools,
407
- capabilities: { planMessages: true, orderedCallbacks: true },
556
+ capabilities: {
557
+ planMessages: true,
558
+ orderedCallbacks: true,
559
+ ...(options.restoreAttachments && { attachmentHistory: true }),
560
+ },
408
561
  conversationId: options.conversationId,
409
562
  actorId: options.actorId,
563
+ ...(options.ownerId && { ownerId: options.ownerId }),
410
564
  sessionId: options.sessionId,
411
565
  inference: options.inference,
566
+ skills: options.skills,
412
567
  callback: { ...this.callback, runId: options.runId },
413
568
  ...(options.workspaceLocal
414
569
  ? { workspace: { local: true } }
@@ -419,24 +574,33 @@ export class BuilderRuntime {
419
574
  });
420
575
  const body = await this.invokeRaw({
421
576
  payload,
422
- runtimeSessionId: options.workspaceSessionKey ?? options.conversationId,
577
+ session: options.workspaceSessionKey ? "workspace" : "chat",
578
+ access: options.access,
423
579
  signal: options.signal,
424
580
  });
581
+ invoked = true;
425
582
  await this.consume(body, {
426
583
  ...options,
427
584
  onEvent: (event) => {
428
585
  if (inferenceFailure)
429
586
  throw inferenceFailure;
587
+ if (skillsFailure)
588
+ throw skillsFailure;
430
589
  return options.onEvent(event);
431
590
  },
432
591
  }, callbacks, callbackResults);
433
592
  if (inferenceFailure)
434
593
  throw inferenceFailure;
594
+ if (skillsFailure)
595
+ throw skillsFailure;
435
596
  }
436
597
  catch (error) {
437
- failure = { error: inferenceFailure ?? error };
598
+ failure = { error: inferenceFailure ?? skillsFailure ?? error };
438
599
  }
439
600
  finally {
601
+ // Before the tools close, so the VM stops instead of failing its next callback.
602
+ if (invoked && options.signal.aborted)
603
+ await this.cancelTurn(options);
440
604
  closeTools();
441
605
  callbackResults.clear();
442
606
  }
@@ -451,6 +615,30 @@ export class BuilderRuntime {
451
615
  if (failure)
452
616
  throw failure.error;
453
617
  }
618
+ /**
619
+ * Tells the VM to stop run `runId`. AgentCore keeps an invocation running
620
+ * after its caller hangs up, so aborting our stream alone leaves the turn
621
+ * going. Best effort: a runtime without `turn.cancel` answers 422.
622
+ */
623
+ async cancelTurn(options) {
624
+ try {
625
+ const body = await this.invokeRaw({
626
+ payload: JSON.stringify({
627
+ kind: "turn.cancel",
628
+ provider: this.providerFor(this.model),
629
+ runId: options.runId,
630
+ actorId: options.actorId,
631
+ }),
632
+ session: options.workspaceSessionKey ? "workspace" : "chat",
633
+ access: options.access,
634
+ signal: AbortSignal.timeout(5_000),
635
+ });
636
+ await body[Symbol.asyncIterator]().return?.();
637
+ }
638
+ catch {
639
+ // The turn still ends when the VM's next callback finds the run closed.
640
+ }
641
+ }
454
642
  /**
455
643
  * The workspace edge's base URL (no path) and the token the VM presents to
456
644
  * it and accepts from it, for one workspace session. The edge is the
@@ -473,15 +661,17 @@ export class BuilderRuntime {
473
661
  }
474
662
  /**
475
663
  * Posts a `workspace.open` payload and resolves where the VM's ingress is
476
- * reachable: AgentCore's session endpoint (SigV4), or for the local
664
+ * reachable: the AgentCore session endpoint the server opened, with the
665
+ * grant the edge presents to the server for each signature, or for the local
477
666
  * transport `SUPERBLOCKS_BUILDER_WORKSPACE_URL`, else the ingress port on
478
667
  * the local runtime's host. Throws {@link WorkspaceEndpointMissingError}
479
- * when AgentCore returns no session endpoint.
668
+ * when AgentCore returned no session endpoint.
480
669
  */
481
- async invokeWorkspaceOpen({ payload, sessionKey, signal, }) {
482
- const { body, sessionEndpointUrl } = await this.send({
670
+ async invokeWorkspaceOpen({ payload, sessionKey, access, signal, }) {
671
+ const { body, endpoint } = await this.send({
483
672
  payload,
484
- runtimeSessionId: sessionKey,
673
+ session: "workspace",
674
+ access,
485
675
  signal,
486
676
  });
487
677
  if (this.localUrl)
@@ -494,7 +684,7 @@ export class BuilderRuntime {
494
684
  sessionKey,
495
685
  }),
496
686
  };
497
- if (!sessionEndpointUrl) {
687
+ if (!endpoint || !access) {
498
688
  void body[Symbol.asyncIterator]()
499
689
  .return?.()
500
690
  .catch(() => { });
@@ -504,16 +694,26 @@ export class BuilderRuntime {
504
694
  body,
505
695
  endpoint: workspaceEndpointSchema.parse({
506
696
  auth: "sigv4",
507
- url: sessionEndpointForPort(sessionEndpointUrl, WORKSPACE_INGRESS_PORT),
508
- region: this.region,
697
+ url: endpoint.url,
698
+ region: endpoint.region,
509
699
  sessionKey,
700
+ signer: {
701
+ url: new URL(BUILDER_RUNTIME_SIGN_PATH, access.serverUrl).toString(),
702
+ grant: endpoint.grant,
703
+ },
510
704
  }),
511
705
  };
512
706
  }
513
707
  async invokeRaw(options) {
514
708
  return (await this.send(options)).body;
515
709
  }
516
- async send({ payload, runtimeSessionId, signal, }) {
710
+ /**
711
+ * Sends one invocation: to the local runtime in development, otherwise to
712
+ * the Superblocks server, which picks the runtime and the runtime session
713
+ * (`session` only says which of the token's two it is) and invokes AgentCore
714
+ * with its own credentials. This process holds none.
715
+ */
716
+ async send({ payload, session, access, signal, }) {
517
717
  if (this.localUrl) {
518
718
  const response = await fetch(this.localUrl, {
519
719
  method: "POST",
@@ -526,31 +726,53 @@ export class BuilderRuntime {
526
726
  },
527
727
  body: payload,
528
728
  });
529
- if (!response.ok) {
530
- await response.body?.cancel();
531
- throw new BuilderRuntimeHttpError(response.status);
532
- }
533
- if (!response.body ||
534
- !response.headers.get("content-type")?.includes("text/event-stream")) {
729
+ return { body: await BuilderRuntime.eventStream(response) };
730
+ }
731
+ if (!access)
732
+ throw new Error("The native builder runtime needs server access");
733
+ for (let attempt = 0;; attempt++) {
734
+ const response = await fetch(new URL(BUILDER_RUNTIME_INVOCATIONS_PATH, access.serverUrl), {
735
+ method: "POST",
736
+ redirect: "error",
737
+ signal,
738
+ headers: {
739
+ Authorization: `Bearer ${await access.token(signal, { refresh: attempt > 0 })}`,
740
+ "Content-Type": "application/json",
741
+ Accept: "text/event-stream",
742
+ [BUILDER_RUNTIME_SESSION_HEADER]: session,
743
+ },
744
+ body: payload,
745
+ });
746
+ // A lapsed or revoked token: one more try with a new one.
747
+ if (response.status === 401 && attempt === 0) {
535
748
  await response.body?.cancel();
536
- throw new Error("Native builder returned an invalid response");
749
+ continue;
537
750
  }
538
- return { body: response.body };
751
+ const body = await BuilderRuntime.eventStream(response);
752
+ const endpointHeader = response.headers.get(BUILDER_RUNTIME_ENDPOINT_HEADER);
753
+ const grant = response.headers.get(BUILDER_RUNTIME_SIGN_GRANT_HEADER);
754
+ const endpoint = endpointHeader && grant
755
+ ? builderRuntimeEndpointHeaderSchema.safeParse(JSON.parse(endpointHeader))
756
+ : undefined;
757
+ return {
758
+ body,
759
+ ...(endpoint?.success &&
760
+ grant && { endpoint: { ...endpoint.data, grant } }),
761
+ };
539
762
  }
540
- const result = await this.client.send(new InvokeAgentRuntimeCommand({
541
- agentRuntimeArn: this.runtimeArn,
542
- qualifier: this.qualifier,
543
- runtimeSessionId,
544
- contentType: "application/json",
545
- accept: "text/event-stream",
546
- payload: new TextEncoder().encode(payload),
547
- }), { abortSignal: signal });
548
- if (!result.response || !result.contentType?.includes("text/event-stream"))
763
+ }
764
+ /** The event-stream body of a runtime answer; throws on anything else. */
765
+ static async eventStream(response) {
766
+ if (!response.ok) {
767
+ await response.body?.cancel();
768
+ throw new BuilderRuntimeHttpError(response.status);
769
+ }
770
+ if (!response.body ||
771
+ !response.headers.get("content-type")?.includes("text/event-stream")) {
772
+ await response.body?.cancel();
549
773
  throw new Error("Native builder returned an invalid response");
550
- return {
551
- body: result.response,
552
- sessionEndpointUrl: result.sessionEndpointUrl,
553
- };
774
+ }
775
+ return response.body;
554
776
  }
555
777
  /**
556
778
  * Reads validated SSE events from a runtime body, ending after `finish`.
@@ -602,29 +824,53 @@ export class BuilderRuntime {
602
824
  }
603
825
  }
604
826
  async consume(body, options, callbacks, callbackResults) {
605
- for await (const event of BuilderRuntime.readEvents(body, options.signal)) {
606
- if (event.type === "error")
607
- throw new BuilderRuntimeError(event.code ?? "INVOCATION_FAILED");
608
- if ((event.type === "tool-call" || event.type === "tool-result") &&
609
- event.toolName.startsWith("__runtime_"))
610
- continue;
611
- if (event.type === "tool-result" &&
612
- callbackResults.get(event.toolCallId) === event.toolName)
613
- continue;
614
- await options.onEvent(event.type === "tool-call"
827
+ let failure;
828
+ const cleanup = new BuilderFailureDrain(options.signal);
829
+ try {
830
+ for await (const event of BuilderRuntime.readEvents(body, cleanup.signal)) {
831
+ if (event.type === "error" && !failure) {
832
+ failure = new BuilderRuntimeError(event.code ?? "INVOCATION_FAILED", event.reason, event.beforeTurn === true, event.runSubmitted === true);
833
+ cleanup.start();
834
+ }
835
+ // A finish confirms the runtime released its run before another invocation.
836
+ if (failure && event.type === "finish")
837
+ cleanup.finish();
838
+ if (failure)
839
+ continue;
840
+ await this.forwardEvent(event, options, callbacks, callbackResults);
841
+ }
842
+ }
843
+ catch (error) {
844
+ if (!failure || options.signal.aborted)
845
+ throw error;
846
+ throw failure.withUnconfirmedCleanup(cleanup.outcome);
847
+ }
848
+ finally {
849
+ cleanup.close();
850
+ }
851
+ if (failure)
852
+ throw failure;
853
+ }
854
+ async forwardEvent(event, options, callbacks, callbackResults) {
855
+ if ((event.type === "tool-call" || event.type === "tool-result") &&
856
+ event.toolName.startsWith("__runtime_"))
857
+ return;
858
+ if (event.type === "tool-result" &&
859
+ callbackResults.get(event.toolCallId) === event.toolName)
860
+ return;
861
+ await options.onEvent(event.type === "tool-call"
862
+ ? {
863
+ ...event,
864
+ input: await this.secrets.redact(event.input, options.signal),
865
+ }
866
+ : event.type === "tool-result"
615
867
  ? {
616
868
  ...event,
617
- input: await this.secrets.redact(event.input, options.signal),
869
+ output: await this.secrets.redact(event.output, options.signal),
618
870
  }
619
- : event.type === "tool-result"
620
- ? {
621
- ...event,
622
- output: await this.secrets.redact(event.output, options.signal),
623
- }
624
- : event);
625
- if (event.type === "tool-call")
626
- callbacks.arrive(event.toolCallId);
627
- }
871
+ : event);
872
+ if (event.type === "tool-call")
873
+ callbacks.arrive(event.toolCallId);
628
874
  }
629
875
  }
630
876
  //# sourceMappingURL=builder-runtime.js.map