@strands-agents/cli 0.2.3 → 0.3.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 (453) hide show
  1. package/README.md +217 -133
  2. package/bin/strands.js +1 -5
  3. package/dist/src/{tui/strands-backend.js → agent/backend.js} +90 -28
  4. package/dist/src/agent/backend.js.map +1 -0
  5. package/dist/src/{tui/background/activity.js → agent/background.js} +173 -6
  6. package/dist/src/agent/background.js.map +1 -0
  7. package/dist/src/{tui/agent-configuration.js → agent/configuration.js} +62 -105
  8. package/dist/src/agent/configuration.js.map +1 -0
  9. package/dist/src/agent/context.js +112 -0
  10. package/dist/src/agent/context.js.map +1 -0
  11. package/dist/src/{tui/chat/sdk-projector.js → agent/events.js} +6 -5
  12. package/dist/src/agent/events.js.map +1 -0
  13. package/dist/src/{tui/permissions/file-change-preview.js → agent/file-changes.js} +10 -8
  14. package/dist/src/agent/file-changes.js.map +1 -0
  15. package/dist/src/agent/mcp.js +436 -0
  16. package/dist/src/agent/mcp.js.map +1 -0
  17. package/dist/src/agent/messaging.js +424 -0
  18. package/dist/src/agent/messaging.js.map +1 -0
  19. package/dist/src/agent/permission-rules.js +267 -0
  20. package/dist/src/agent/permission-rules.js.map +1 -0
  21. package/dist/src/agent/permissions.js +288 -0
  22. package/dist/src/agent/permissions.js.map +1 -0
  23. package/dist/src/agent/runtime.js +524 -0
  24. package/dist/src/agent/runtime.js.map +1 -0
  25. package/dist/src/{tui/workspace → agent}/sandbox.js +92 -25
  26. package/dist/src/agent/sandbox.js.map +1 -0
  27. package/dist/src/{tui/chat → agent}/shell.js +1 -1
  28. package/dist/src/agent/shell.js.map +1 -0
  29. package/dist/src/{tui → agent}/skills.js +37 -56
  30. package/dist/src/agent/skills.js.map +1 -0
  31. package/dist/src/{tui/builtin-tools.js → agent/tools.js} +2 -3
  32. package/dist/src/agent/tools.js.map +1 -0
  33. package/dist/src/agent/types.js.map +1 -0
  34. package/dist/src/{tui/voice/session.js → agent/voice.js} +221 -224
  35. package/dist/src/agent/voice.js.map +1 -0
  36. package/dist/src/{tui/acp/projection.js → cli/acp-events.js} +19 -4
  37. package/dist/src/cli/acp-events.js.map +1 -0
  38. package/dist/src/{tui/project/acp.js → cli/acp-python.js} +41 -18
  39. package/dist/src/cli/acp-python.js.map +1 -0
  40. package/dist/src/{tui/acp/server.js → cli/acp.js} +149 -46
  41. package/dist/src/cli/acp.js.map +1 -0
  42. package/dist/src/cli/arguments.js +8 -3
  43. package/dist/src/cli/arguments.js.map +1 -1
  44. package/dist/src/{console.js → cli/console.js} +69 -4
  45. package/dist/src/cli/console.js.map +1 -0
  46. package/dist/src/cli/invocation.js +75 -44
  47. package/dist/src/cli/invocation.js.map +1 -1
  48. package/dist/src/cli/run.js +66 -38
  49. package/dist/src/cli/run.js.map +1 -1
  50. package/dist/src/{tui → cli}/telemetry.js +2 -2
  51. package/dist/src/{tui → cli}/telemetry.js.map +1 -1
  52. package/dist/src/cli/update.js +35 -7
  53. package/dist/src/cli/update.js.map +1 -1
  54. package/dist/src/{tui/mcp/config.js → config/mcp.js} +25 -35
  55. package/dist/src/config/mcp.js.map +1 -0
  56. package/dist/src/{tui → config}/settings.js +78 -130
  57. package/dist/src/config/settings.js.map +1 -0
  58. package/dist/src/config/source.js +87 -0
  59. package/dist/src/config/source.js.map +1 -0
  60. package/dist/src/{tui/config.js → config/store.js} +178 -49
  61. package/dist/src/config/store.js.map +1 -0
  62. package/dist/src/{tui/workspace → config}/trust.js +12 -16
  63. package/dist/src/config/trust.js.map +1 -0
  64. package/dist/src/logging.js +3 -4
  65. package/dist/src/logging.js.map +1 -1
  66. package/dist/src/{tui/provider → model}/aws-config.js +13 -4
  67. package/dist/src/model/aws-config.js.map +1 -0
  68. package/dist/src/{tui/provider/bedrock-catalog.js → model/bedrock.js} +70 -3
  69. package/dist/src/model/bedrock.js.map +1 -0
  70. package/dist/src/{tui/provider → model}/discovery.js +11 -10
  71. package/dist/src/model/discovery.js.map +1 -0
  72. package/dist/src/{tui/provider → model}/environment.js +19 -16
  73. package/dist/src/model/environment.js.map +1 -0
  74. package/dist/src/{tui/model/display.js → model/metadata.js} +6 -1
  75. package/dist/src/model/metadata.js.map +1 -0
  76. package/dist/src/model/packages.js.map +1 -0
  77. package/dist/src/{tui/model → model}/runtime.js +31 -62
  78. package/dist/src/model/runtime.js.map +1 -0
  79. package/dist/src/{tui/model → model}/selection.js +9 -15
  80. package/dist/src/model/selection.js.map +1 -0
  81. package/dist/src/{tui/package-version.js → package-version.js} +6 -0
  82. package/dist/src/package-version.js.map +1 -0
  83. package/dist/src/paths.js +23 -0
  84. package/dist/src/paths.js.map +1 -0
  85. package/dist/src/project/archive.js +461 -0
  86. package/dist/src/project/archive.js.map +1 -0
  87. package/dist/src/{tui/project → project}/export.js +249 -72
  88. package/dist/src/project/export.js.map +1 -0
  89. package/dist/src/{tui/project → project}/import.js +58 -6
  90. package/dist/src/project/import.js.map +1 -0
  91. package/dist/src/{tui/project → project}/module-loader.js +1 -5
  92. package/dist/src/project/module-loader.js.map +1 -0
  93. package/dist/src/{tui/project → project}/packaging.js +25 -8
  94. package/dist/src/project/packaging.js.map +1 -0
  95. package/dist/src/project/portability.js +455 -0
  96. package/dist/src/project/portability.js.map +1 -0
  97. package/dist/src/{tui/project → project}/python.js +46 -31
  98. package/dist/src/project/python.js.map +1 -0
  99. package/dist/src/{tui/project → project}/source.js +45 -26
  100. package/dist/src/project/source.js.map +1 -0
  101. package/dist/src/project/typescript-backend.js +733 -0
  102. package/dist/src/project/typescript-backend.js.map +1 -0
  103. package/dist/src/project/typescript-worker.js +488 -0
  104. package/dist/src/project/typescript-worker.js.map +1 -0
  105. package/dist/src/{tui/project → project}/typescript.js +19 -7
  106. package/dist/src/project/typescript.js.map +1 -0
  107. package/dist/src/project/watch.js +33 -0
  108. package/dist/src/project/watch.js.map +1 -0
  109. package/dist/src/{tui/project → project}/worker.py +358 -106
  110. package/dist/src/session/agent-definition.js +35 -0
  111. package/dist/src/session/agent-definition.js.map +1 -0
  112. package/dist/src/session/catalog.js +156 -0
  113. package/dist/src/session/catalog.js.map +1 -0
  114. package/dist/src/{tui/session → session}/context.js +45 -5
  115. package/dist/src/session/context.js.map +1 -0
  116. package/dist/src/{tui/session → session}/desktop-profile.js +1 -0
  117. package/dist/src/session/desktop-profile.js.map +1 -0
  118. package/dist/src/{tui/session → session}/sessions.js +126 -27
  119. package/dist/src/session/sessions.js.map +1 -0
  120. package/dist/src/terminal/arguments.js +53 -0
  121. package/dist/src/terminal/arguments.js.map +1 -0
  122. package/dist/src/{tui/terminal → terminal}/composer.js +51 -24
  123. package/dist/src/terminal/composer.js.map +1 -0
  124. package/dist/src/terminal/directory-picker.js +182 -0
  125. package/dist/src/terminal/directory-picker.js.map +1 -0
  126. package/dist/src/terminal/ink.js.map +1 -0
  127. package/dist/src/terminal/mouse-input.js.map +1 -0
  128. package/dist/src/terminal/npm.js.map +1 -0
  129. package/dist/src/terminal/open-editor.js +40 -0
  130. package/dist/src/terminal/open-editor.js.map +1 -0
  131. package/dist/src/terminal/open-url.js +26 -0
  132. package/dist/src/terminal/open-url.js.map +1 -0
  133. package/dist/src/terminal/process-tree.js.map +1 -0
  134. package/dist/src/terminal/shell-output.js.map +1 -0
  135. package/dist/src/{tui/terminal → terminal}/terminal.js +40 -2
  136. package/dist/src/terminal/terminal.js.map +1 -0
  137. package/dist/src/{tui/terminal/sanitize.js → terminal/text.js} +40 -6
  138. package/dist/src/terminal/text.js.map +1 -0
  139. package/dist/src/terminal/theme-detection.js +197 -0
  140. package/dist/src/terminal/theme-detection.js.map +1 -0
  141. package/dist/src/{tui/view/fade-in.js → ui/animation.js} +26 -1
  142. package/dist/src/ui/animation.js.map +1 -0
  143. package/dist/src/ui/app.js +176 -0
  144. package/dist/src/ui/app.js.map +1 -0
  145. package/dist/src/ui/chat/attachments.js +135 -0
  146. package/dist/src/ui/chat/attachments.js.map +1 -0
  147. package/dist/src/{tui → ui}/chat/commands.js +55 -7
  148. package/dist/src/ui/chat/commands.js.map +1 -0
  149. package/dist/src/{tui → ui}/chat/controller.js +1176 -345
  150. package/dist/src/ui/chat/controller.js.map +1 -0
  151. package/dist/src/ui/chat/conversations.js +692 -0
  152. package/dist/src/ui/chat/conversations.js.map +1 -0
  153. package/dist/src/{tui → ui}/chat/help.js +11 -5
  154. package/dist/src/ui/chat/help.js.map +1 -0
  155. package/dist/src/ui/chat/panel-state.js +513 -0
  156. package/dist/src/ui/chat/panel-state.js.map +1 -0
  157. package/dist/src/{tui → ui}/chat/projector.js +93 -8
  158. package/dist/src/ui/chat/projector.js.map +1 -0
  159. package/dist/src/ui/chat/prompt.js +176 -0
  160. package/dist/src/ui/chat/prompt.js.map +1 -0
  161. package/dist/src/ui/chat/runtime.js +589 -0
  162. package/dist/src/ui/chat/runtime.js.map +1 -0
  163. package/dist/src/ui/chat/screen.js +1907 -0
  164. package/dist/src/ui/chat/screen.js.map +1 -0
  165. package/dist/src/{tui/chat/controller-helpers.js → ui/chat/state.js} +39 -3
  166. package/dist/src/ui/chat/state.js.map +1 -0
  167. package/dist/src/ui/chat/stream-presentation.js.map +1 -0
  168. package/dist/src/ui/chat/transcript-turn.js +189 -0
  169. package/dist/src/ui/chat/transcript-turn.js.map +1 -0
  170. package/dist/src/{tui/view → ui/chat}/transcript.js +66 -6
  171. package/dist/src/ui/chat/transcript.js.map +1 -0
  172. package/dist/src/ui/chat/types.js +2 -0
  173. package/dist/src/ui/chat/types.js.map +1 -0
  174. package/dist/src/ui/chat/view.js +249 -0
  175. package/dist/src/ui/chat/view.js.map +1 -0
  176. package/dist/src/ui/chat/voice.js +388 -0
  177. package/dist/src/ui/chat/voice.js.map +1 -0
  178. package/dist/src/ui/footer.js +110 -0
  179. package/dist/src/ui/footer.js.map +1 -0
  180. package/dist/src/{tui/view → ui}/frog-canvas.js +47 -50
  181. package/dist/src/ui/frog-canvas.js.map +1 -0
  182. package/dist/src/{tui/view → ui}/frog-drawing.js +36 -29
  183. package/dist/src/ui/frog-drawing.js.map +1 -0
  184. package/dist/src/{tui/view/frog-intro-renderer.js → ui/frog-renderer.js} +63 -46
  185. package/dist/src/ui/frog-renderer.js.map +1 -0
  186. package/dist/src/{tui/view/frog-easter-egg.js → ui/frog.js} +34 -6
  187. package/dist/src/ui/frog.js.map +1 -0
  188. package/dist/src/ui/interaction.js +525 -0
  189. package/dist/src/ui/interaction.js.map +1 -0
  190. package/dist/src/{tui/view → ui}/markdown.js +12 -9
  191. package/dist/src/ui/markdown.js.map +1 -0
  192. package/dist/src/ui/mcp-diagnostics.js +56 -0
  193. package/dist/src/ui/mcp-diagnostics.js.map +1 -0
  194. package/dist/src/ui/media.js +59 -0
  195. package/dist/src/ui/media.js.map +1 -0
  196. package/dist/src/ui/panels/agents.js +97 -0
  197. package/dist/src/ui/panels/agents.js.map +1 -0
  198. package/dist/src/ui/panels/configuration.js +201 -0
  199. package/dist/src/ui/panels/configuration.js.map +1 -0
  200. package/dist/src/ui/panels/context.js +102 -0
  201. package/dist/src/ui/panels/context.js.map +1 -0
  202. package/dist/src/ui/panels/export.js +17 -0
  203. package/dist/src/ui/panels/export.js.map +1 -0
  204. package/dist/src/ui/panels/help.js +22 -0
  205. package/dist/src/ui/panels/help.js.map +1 -0
  206. package/dist/src/ui/panels/models.js +180 -0
  207. package/dist/src/ui/panels/models.js.map +1 -0
  208. package/dist/src/ui/panels/panel.js +122 -0
  209. package/dist/src/ui/panels/panel.js.map +1 -0
  210. package/dist/src/ui/panels/permissions.js +90 -0
  211. package/dist/src/ui/panels/permissions.js.map +1 -0
  212. package/dist/src/ui/panels/sessions.js +54 -0
  213. package/dist/src/ui/panels/sessions.js.map +1 -0
  214. package/dist/src/ui/panels/settings.js +125 -0
  215. package/dist/src/ui/panels/settings.js.map +1 -0
  216. package/dist/src/ui/panels/shared.js +50 -0
  217. package/dist/src/ui/panels/shared.js.map +1 -0
  218. package/dist/src/ui/panels/tasks.js +15 -0
  219. package/dist/src/ui/panels/tasks.js.map +1 -0
  220. package/dist/src/ui/panels/voice.js +142 -0
  221. package/dist/src/ui/panels/voice.js.map +1 -0
  222. package/dist/src/{tui/permissions/settings.js → ui/permission-options.js} +13 -2
  223. package/dist/src/ui/permission-options.js.map +1 -0
  224. package/dist/src/{tui/view → ui}/presentation.js +170 -112
  225. package/dist/src/ui/presentation.js.map +1 -0
  226. package/dist/src/{tui → ui}/run.js +173 -36
  227. package/dist/src/ui/run.js.map +1 -0
  228. package/dist/src/{tui/view/setup-wizard/settings-panel.js → ui/setup/form.js} +6 -6
  229. package/dist/src/ui/setup/form.js.map +1 -0
  230. package/dist/src/ui/setup/menu.js +133 -0
  231. package/dist/src/ui/setup/menu.js.map +1 -0
  232. package/dist/src/{tui/view/setup-wizard → ui/setup}/providers.js +157 -20
  233. package/dist/src/ui/setup/providers.js.map +1 -0
  234. package/dist/src/{tui/view/setup-wizard → ui/setup}/steps.js +193 -147
  235. package/dist/src/ui/setup/steps.js.map +1 -0
  236. package/dist/src/ui/setup/wizard.js +2075 -0
  237. package/dist/src/ui/setup/wizard.js.map +1 -0
  238. package/dist/src/ui/startup.js +147 -0
  239. package/dist/src/ui/startup.js.map +1 -0
  240. package/dist/src/{tui/terminal/size.js → ui/terminal-size.js} +1 -1
  241. package/dist/src/ui/terminal-size.js.map +1 -0
  242. package/dist/src/ui/text-input.js +50 -0
  243. package/dist/src/ui/text-input.js.map +1 -0
  244. package/dist/src/{tui/view → ui}/theme.js +24 -31
  245. package/dist/src/ui/theme.js.map +1 -0
  246. package/dist/src/ui/update.js +126 -0
  247. package/dist/src/ui/update.js.map +1 -0
  248. package/dist/src/usage.js +0 -5
  249. package/dist/src/usage.js.map +1 -1
  250. package/dist/src/values.js +5 -0
  251. package/dist/src/values.js.map +1 -0
  252. package/package.json +16 -8
  253. package/src/agent/voice-sidecar.py +730 -0
  254. package/dist/src/console.js.map +0 -1
  255. package/dist/src/tui/acp/projection.js.map +0 -1
  256. package/dist/src/tui/acp/server.js.map +0 -1
  257. package/dist/src/tui/agent-configuration.js.map +0 -1
  258. package/dist/src/tui/background/activity.js.map +0 -1
  259. package/dist/src/tui/background/inbox.js +0 -120
  260. package/dist/src/tui/background/inbox.js.map +0 -1
  261. package/dist/src/tui/background/tasks.js +0 -98
  262. package/dist/src/tui/background/tasks.js.map +0 -1
  263. package/dist/src/tui/builtin-tools.js.map +0 -1
  264. package/dist/src/tui/chat/commands.js.map +0 -1
  265. package/dist/src/tui/chat/controller-helpers.js.map +0 -1
  266. package/dist/src/tui/chat/controller.js.map +0 -1
  267. package/dist/src/tui/chat/help.js.map +0 -1
  268. package/dist/src/tui/chat/panels.js +0 -407
  269. package/dist/src/tui/chat/panels.js.map +0 -1
  270. package/dist/src/tui/chat/projector.js.map +0 -1
  271. package/dist/src/tui/chat/sdk-projector.js.map +0 -1
  272. package/dist/src/tui/chat/shell.js.map +0 -1
  273. package/dist/src/tui/chat/types.js +0 -2
  274. package/dist/src/tui/chat/types.js.map +0 -1
  275. package/dist/src/tui/config.js.map +0 -1
  276. package/dist/src/tui/configuration-instructions.js +0 -14
  277. package/dist/src/tui/configuration-instructions.js.map +0 -1
  278. package/dist/src/tui/mcp/config.js.map +0 -1
  279. package/dist/src/tui/mcp.js +0 -98
  280. package/dist/src/tui/mcp.js.map +0 -1
  281. package/dist/src/tui/memory-options.js +0 -10
  282. package/dist/src/tui/memory-options.js.map +0 -1
  283. package/dist/src/tui/messaging.js +0 -193
  284. package/dist/src/tui/messaging.js.map +0 -1
  285. package/dist/src/tui/model/context.js +0 -69
  286. package/dist/src/tui/model/context.js.map +0 -1
  287. package/dist/src/tui/model/display.js.map +0 -1
  288. package/dist/src/tui/model/runtime.js.map +0 -1
  289. package/dist/src/tui/model/selection.js.map +0 -1
  290. package/dist/src/tui/npm.js.map +0 -1
  291. package/dist/src/tui/package-version.js.map +0 -1
  292. package/dist/src/tui/permissions/file-change-preview.js.map +0 -1
  293. package/dist/src/tui/permissions/policy.js +0 -222
  294. package/dist/src/tui/permissions/policy.js.map +0 -1
  295. package/dist/src/tui/permissions/settings.js.map +0 -1
  296. package/dist/src/tui/project/acp.js.map +0 -1
  297. package/dist/src/tui/project/archive.js +0 -241
  298. package/dist/src/tui/project/archive.js.map +0 -1
  299. package/dist/src/tui/project/configuration-secrets.js +0 -107
  300. package/dist/src/tui/project/configuration-secrets.js.map +0 -1
  301. package/dist/src/tui/project/configuration.js +0 -201
  302. package/dist/src/tui/project/configuration.js.map +0 -1
  303. package/dist/src/tui/project/export.js.map +0 -1
  304. package/dist/src/tui/project/import.js.map +0 -1
  305. package/dist/src/tui/project/module-loader.js.map +0 -1
  306. package/dist/src/tui/project/packaging.js.map +0 -1
  307. package/dist/src/tui/project/portable-dependencies.js +0 -34
  308. package/dist/src/tui/project/portable-dependencies.js.map +0 -1
  309. package/dist/src/tui/project/portable-mcp.js +0 -118
  310. package/dist/src/tui/project/portable-mcp.js.map +0 -1
  311. package/dist/src/tui/project/python.js.map +0 -1
  312. package/dist/src/tui/project/run.js +0 -116
  313. package/dist/src/tui/project/run.js.map +0 -1
  314. package/dist/src/tui/project/source.js.map +0 -1
  315. package/dist/src/tui/project/typescript.js.map +0 -1
  316. package/dist/src/tui/provider/aws-client.js +0 -67
  317. package/dist/src/tui/provider/aws-client.js.map +0 -1
  318. package/dist/src/tui/provider/aws-config.js.map +0 -1
  319. package/dist/src/tui/provider/bedrock-catalog.js.map +0 -1
  320. package/dist/src/tui/provider/discovery.js.map +0 -1
  321. package/dist/src/tui/provider/environment.js.map +0 -1
  322. package/dist/src/tui/provider/packages.js.map +0 -1
  323. package/dist/src/tui/run.js.map +0 -1
  324. package/dist/src/tui/runtime.js +0 -524
  325. package/dist/src/tui/runtime.js.map +0 -1
  326. package/dist/src/tui/session/agent-definition.js +0 -100
  327. package/dist/src/tui/session/agent-definition.js.map +0 -1
  328. package/dist/src/tui/session/catalog.js +0 -159
  329. package/dist/src/tui/session/catalog.js.map +0 -1
  330. package/dist/src/tui/session/context.js.map +0 -1
  331. package/dist/src/tui/session/conversation-helpers.js +0 -46
  332. package/dist/src/tui/session/conversation-helpers.js.map +0 -1
  333. package/dist/src/tui/session/conversations.js +0 -471
  334. package/dist/src/tui/session/conversations.js.map +0 -1
  335. package/dist/src/tui/session/desktop-profile.js.map +0 -1
  336. package/dist/src/tui/session/options.js +0 -44
  337. package/dist/src/tui/session/options.js.map +0 -1
  338. package/dist/src/tui/session/sessions.js.map +0 -1
  339. package/dist/src/tui/session/voice.js +0 -353
  340. package/dist/src/tui/session/voice.js.map +0 -1
  341. package/dist/src/tui/settings.js.map +0 -1
  342. package/dist/src/tui/skills.js.map +0 -1
  343. package/dist/src/tui/steering.js +0 -67
  344. package/dist/src/tui/steering.js.map +0 -1
  345. package/dist/src/tui/strands-backend.js.map +0 -1
  346. package/dist/src/tui/stream-presentation.js.map +0 -1
  347. package/dist/src/tui/terminal/composer.js.map +0 -1
  348. package/dist/src/tui/terminal/directory-picker.js +0 -76
  349. package/dist/src/tui/terminal/directory-picker.js.map +0 -1
  350. package/dist/src/tui/terminal/ink.js.map +0 -1
  351. package/dist/src/tui/terminal/mouse-input.js.map +0 -1
  352. package/dist/src/tui/terminal/open-url.js +0 -21
  353. package/dist/src/tui/terminal/open-url.js.map +0 -1
  354. package/dist/src/tui/terminal/process-tree.js.map +0 -1
  355. package/dist/src/tui/terminal/sanitize.js.map +0 -1
  356. package/dist/src/tui/terminal/shell-output.js.map +0 -1
  357. package/dist/src/tui/terminal/size.js.map +0 -1
  358. package/dist/src/tui/terminal/terminal.js.map +0 -1
  359. package/dist/src/tui/update-check.js +0 -37
  360. package/dist/src/tui/update-check.js.map +0 -1
  361. package/dist/src/tui/view/agents-panel.js +0 -21
  362. package/dist/src/tui/view/agents-panel.js.map +0 -1
  363. package/dist/src/tui/view/app.js +0 -1061
  364. package/dist/src/tui/view/app.js.map +0 -1
  365. package/dist/src/tui/view/chat-root.js +0 -49
  366. package/dist/src/tui/view/chat-root.js.map +0 -1
  367. package/dist/src/tui/view/chat-view.js +0 -145
  368. package/dist/src/tui/view/chat-view.js.map +0 -1
  369. package/dist/src/tui/view/command-palette.js +0 -15
  370. package/dist/src/tui/view/command-palette.js.map +0 -1
  371. package/dist/src/tui/view/custom-theme-editor.js +0 -301
  372. package/dist/src/tui/view/custom-theme-editor.js.map +0 -1
  373. package/dist/src/tui/view/effort-panel.js +0 -15
  374. package/dist/src/tui/view/effort-panel.js.map +0 -1
  375. package/dist/src/tui/view/export-panel.js +0 -14
  376. package/dist/src/tui/view/export-panel.js.map +0 -1
  377. package/dist/src/tui/view/fade-in.js.map +0 -1
  378. package/dist/src/tui/view/frog-canvas.js.map +0 -1
  379. package/dist/src/tui/view/frog-drawing.js.map +0 -1
  380. package/dist/src/tui/view/frog-easter-egg.js.map +0 -1
  381. package/dist/src/tui/view/frog-intro-renderer.js.map +0 -1
  382. package/dist/src/tui/view/help-footer.js +0 -48
  383. package/dist/src/tui/view/help-footer.js.map +0 -1
  384. package/dist/src/tui/view/interaction.js +0 -352
  385. package/dist/src/tui/view/interaction.js.map +0 -1
  386. package/dist/src/tui/view/markdown.js.map +0 -1
  387. package/dist/src/tui/view/mcp-trust-prompt.js +0 -17
  388. package/dist/src/tui/view/mcp-trust-prompt.js.map +0 -1
  389. package/dist/src/tui/view/media.js +0 -70
  390. package/dist/src/tui/view/media.js.map +0 -1
  391. package/dist/src/tui/view/model-panel.js +0 -77
  392. package/dist/src/tui/view/model-panel.js.map +0 -1
  393. package/dist/src/tui/view/panel-components.js +0 -17
  394. package/dist/src/tui/view/panel-components.js.map +0 -1
  395. package/dist/src/tui/view/panels.js +0 -139
  396. package/dist/src/tui/view/panels.js.map +0 -1
  397. package/dist/src/tui/view/presentation.js.map +0 -1
  398. package/dist/src/tui/view/prompt-editor.js +0 -82
  399. package/dist/src/tui/view/prompt-editor.js.map +0 -1
  400. package/dist/src/tui/view/provider-list.js +0 -14
  401. package/dist/src/tui/view/provider-list.js.map +0 -1
  402. package/dist/src/tui/view/rename-panel.js +0 -11
  403. package/dist/src/tui/view/rename-panel.js.map +0 -1
  404. package/dist/src/tui/view/sessions-panel.js +0 -15
  405. package/dist/src/tui/view/sessions-panel.js.map +0 -1
  406. package/dist/src/tui/view/settings-panel.js +0 -146
  407. package/dist/src/tui/view/settings-panel.js.map +0 -1
  408. package/dist/src/tui/view/setup-wizard/brand.js +0 -34
  409. package/dist/src/tui/view/setup-wizard/brand.js.map +0 -1
  410. package/dist/src/tui/view/setup-wizard/index.js +0 -1638
  411. package/dist/src/tui/view/setup-wizard/index.js.map +0 -1
  412. package/dist/src/tui/view/setup-wizard/opening-menu.js +0 -99
  413. package/dist/src/tui/view/setup-wizard/opening-menu.js.map +0 -1
  414. package/dist/src/tui/view/setup-wizard/path-completion.js +0 -53
  415. package/dist/src/tui/view/setup-wizard/path-completion.js.map +0 -1
  416. package/dist/src/tui/view/setup-wizard/profile-fields.js +0 -29
  417. package/dist/src/tui/view/setup-wizard/profile-fields.js.map +0 -1
  418. package/dist/src/tui/view/setup-wizard/progress.js +0 -43
  419. package/dist/src/tui/view/setup-wizard/progress.js.map +0 -1
  420. package/dist/src/tui/view/setup-wizard/providers.js.map +0 -1
  421. package/dist/src/tui/view/setup-wizard/settings-panel.js.map +0 -1
  422. package/dist/src/tui/view/setup-wizard/steps.js.map +0 -1
  423. package/dist/src/tui/view/setup-wizard/types.js.map +0 -1
  424. package/dist/src/tui/view/setup-wizard/use-provider-discovery.js +0 -143
  425. package/dist/src/tui/view/setup-wizard/use-provider-discovery.js.map +0 -1
  426. package/dist/src/tui/view/startup-view.js +0 -79
  427. package/dist/src/tui/view/startup-view.js.map +0 -1
  428. package/dist/src/tui/view/text-input.js +0 -33
  429. package/dist/src/tui/view/text-input.js.map +0 -1
  430. package/dist/src/tui/view/theme-detection.js +0 -45
  431. package/dist/src/tui/view/theme-detection.js.map +0 -1
  432. package/dist/src/tui/view/theme.js.map +0 -1
  433. package/dist/src/tui/view/transcript-layout.js +0 -60
  434. package/dist/src/tui/view/transcript-layout.js.map +0 -1
  435. package/dist/src/tui/view/transcript-turn.js +0 -135
  436. package/dist/src/tui/view/transcript-turn.js.map +0 -1
  437. package/dist/src/tui/view/transcript.js.map +0 -1
  438. package/dist/src/tui/view/use-party-frame.js +0 -15
  439. package/dist/src/tui/view/use-party-frame.js.map +0 -1
  440. package/dist/src/tui/view/use-spinner.js +0 -14
  441. package/dist/src/tui/view/use-spinner.js.map +0 -1
  442. package/dist/src/tui/voice/session.js.map +0 -1
  443. package/dist/src/tui/workspace/sandbox.js.map +0 -1
  444. package/dist/src/tui/workspace/trust.js.map +0 -1
  445. package/src/tui/voice/sidecar.py +0 -631
  446. /package/dist/src/{tui/view/setup-wizard → agent}/types.js +0 -0
  447. /package/dist/src/{tui/provider → model}/packages.js +0 -0
  448. /package/dist/src/{tui/terminal → terminal}/ink.js +0 -0
  449. /package/dist/src/{tui/terminal → terminal}/mouse-input.js +0 -0
  450. /package/dist/src/{tui → terminal}/npm.js +0 -0
  451. /package/dist/src/{tui/terminal → terminal}/process-tree.js +0 -0
  452. /package/dist/src/{tui/terminal → terminal}/shell-output.js +0 -0
  453. /package/dist/src/{tui → ui/chat}/stream-presentation.js +0 -0
@@ -0,0 +1,730 @@
1
+ # /// script
2
+ # requires-python = ">=3.12,<3.15"
3
+ # dependencies = [
4
+ # "strands-agents[bidi,bidi-aec,bidi-io,bidi-openai,bidi-pyaudio]==1.60.0",
5
+ # ]
6
+ # ///
7
+
8
+ """Bidirectional audio sidecar for the Strands CLI voice runtime."""
9
+
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import asyncio
14
+ import json
15
+ import logging
16
+ import math
17
+ import os
18
+ import signal
19
+ import sys
20
+ import threading
21
+ import time
22
+ from array import array
23
+ from pathlib import Path
24
+ from typing import Any, Literal, cast
25
+
26
+ import boto3
27
+
28
+ PORTAUDIO_INSTALL_GUIDANCE = (
29
+ "Audio is unavailable: PyAudio could not load the PortAudio system library.\n"
30
+ "Install PortAudio, restart the CLI, and try /voice again:\n"
31
+ " macOS brew install portaudio\n"
32
+ " Ubuntu sudo apt-get install libportaudio2\n"
33
+ " Fedora sudo dnf install portaudio\n"
34
+ " Arch sudo pacman -S portaudio"
35
+ )
36
+
37
+ try:
38
+ # Import PyAudio before the strands.bidi imports below, which reach the same native
39
+ # library: on a first run without PortAudio installed (#5413) the PyAudio wheel is
40
+ # present but its native dependency is not, and the import raises OSError. The TUI
41
+ # surfaces this process's stderr, so print the install steps and exit instead of
42
+ # showing a traceback.
43
+ import pyaudio # pyright: ignore[reportMissingModuleSource]
44
+ except OSError as error:
45
+ sys.stderr.write(f"{PORTAUDIO_INSTALL_GUIDANCE}\nDetails: {error}\n")
46
+ raise SystemExit(1) from error
47
+
48
+ from strands import tool
49
+ from strands.bidi import BidiAgent # pyright: ignore[reportMissingImports]
50
+ from strands.bidi.io import AudioIO, AudioProcessorConfig, ConsoleIO # pyright: ignore[reportMissingImports]
51
+ from strands.bidi.models import BedrockNovaSonicModel, OpenAIRealtimeModel # pyright: ignore[reportMissingImports]
52
+ from strands.bidi.types import ( # pyright: ignore[reportMissingImports]
53
+ AudioDelta,
54
+ BidiAudioDeltaEvent,
55
+ BidiBargeInEvent,
56
+ BidiConnectionRestartEvent,
57
+ BidiConnectionStartEvent,
58
+ BidiConnectionStopEvent,
59
+ BidiOutputEvent,
60
+ BidiResponseStartEvent,
61
+ BidiResponseStopEvent,
62
+ BidiToolUseBlocksEvent,
63
+ BidiTranscriptBlockEvent,
64
+ BidiTranscriptDeltaEvent,
65
+ InputStream,
66
+ OutputStream,
67
+ )
68
+ from strands.types.tools import ToolResultBlock, ToolSpec # pyright: ignore[reportAttributeAccessIssue]
69
+
70
+ DEFAULT_MODELS = {
71
+ "bedrock": "amazon.nova-2-5-sonic",
72
+ "openai": "gpt-realtime-2.1",
73
+ }
74
+ DEFAULT_VOICES = {
75
+ "bedrock": "tiffany",
76
+ "openai": "coral",
77
+ }
78
+ OPENAI_TRANSCRIPTION_MODEL = "gpt-transcribe"
79
+ DEFAULT_ENDPOINTING_SENSITIVITY = "LOW"
80
+ OPENAI_SILENCE_DURATION_MS = {
81
+ "HIGH": 350,
82
+ "MEDIUM": 500,
83
+ "LOW": 800,
84
+ }
85
+ SYSTEM_PROMPT = """
86
+ You are Strands Voice, the user's persistent real-time conversational supervisor over the active
87
+ Strands harness coding agent.
88
+
89
+ At the beginning of every response, call route_voice_turn exactly once:
90
+ - conversation: casual conversation, a general question you can answer confidently, or a
91
+ clarification that needs no workspace state, live information, tools, or external action.
92
+ - status: a question about what the harness agent is doing, what happened, or whether work finished.
93
+ - delegate: any request to inspect, change, run, search, research, create, fix, continue, or otherwise
94
+ act through the harness agent.
95
+ - cancel: a clear request to stop the harness agent's current work.
96
+ - narration: only for an internal grounded harness update.
97
+
98
+ For delegation, preserve the user's complete request. The harness agent owns files, tools, approvals,
99
+ coding work, and detailed execution. Do not claim that work started, changed, finished, or failed
100
+ unless the routing result says so. After routing, respond naturally and briefly. Continue talking
101
+ with the user while harness work runs. If the user interrupts you, stop speaking and listen.
102
+ """.strip()
103
+ NARRATION_PROMPT = """
104
+ Route this internal request as narration, then give the user a concise, natural update. Preserve the
105
+ grounded facts, omit awkward markdown and code syntax, and do not invent progress.
106
+
107
+ <harness_update>
108
+ {text}
109
+ </harness_update>
110
+ """.strip()
111
+ INPUT_LEVEL_FLOOR_DB = -60.0
112
+ INPUT_LEVEL_INTERVAL_SECONDS = 0.08
113
+
114
+
115
+ def emit(event_type: str, **payload: Any) -> None:
116
+ """Write one event to the Node parent process."""
117
+ print(json.dumps({"type": event_type, **payload}, default=str, separators=(",", ":")), flush=True)
118
+
119
+
120
+ class SupervisorBridge:
121
+ """Resolve BiDi routing tools through the Node conversation manager."""
122
+
123
+ def __init__(self) -> None:
124
+ self._next_request_id = 0
125
+ self._pending: dict[str, asyncio.Future[Any]] = {}
126
+
127
+ async def request(self, action: str, **payload: Any) -> Any:
128
+ """Send one supervisor request and await its correlated result."""
129
+ self._next_request_id += 1
130
+ request_id = f"supervisor-{self._next_request_id}"
131
+ future = asyncio.get_running_loop().create_future()
132
+ self._pending[request_id] = future
133
+ emit("supervisor_request", request_id=request_id, action=action, **payload)
134
+ try:
135
+ return await asyncio.wait_for(future, timeout=30)
136
+ finally:
137
+ self._pending.pop(request_id, None)
138
+
139
+ def resolve(self, command: dict[str, Any]) -> None:
140
+ """Resolve a pending request from a parent control message."""
141
+ request_id = str(command.get("request_id", ""))
142
+ future = self._pending.get(request_id)
143
+ if future is None or future.done():
144
+ return
145
+ if command.get("ok") is True:
146
+ future.set_result(command.get("result"))
147
+ else:
148
+ future.set_exception(RuntimeError(str(command.get("error", "The harness action failed."))))
149
+
150
+ def cancel(self) -> None:
151
+ """Cancel unresolved requests during shutdown."""
152
+ for future in self._pending.values():
153
+ if not future.done():
154
+ future.cancel()
155
+ self._pending.clear()
156
+
157
+
158
+ _supervisor_bridge: SupervisorBridge | None = None
159
+
160
+
161
+ def supervisor_bridge() -> SupervisorBridge:
162
+ """Return the bridge for the active sidecar session."""
163
+ if _supervisor_bridge is None:
164
+ raise RuntimeError("The voice supervisor is not connected.")
165
+ return _supervisor_bridge
166
+
167
+
168
+ VoiceTurnIntent = Literal["conversation", "status", "delegate", "cancel", "narration"]
169
+
170
+
171
+ @tool
172
+ async def route_voice_turn(intent: VoiceTurnIntent, request: str) -> Any:
173
+ """Route every voice turn before responding.
174
+
175
+ Args:
176
+ intent: Whether this turn is conversation, status, delegation, cancellation, or narration.
177
+ request: The user's complete request or the supplied grounded harness update.
178
+ """
179
+ text = request.strip()
180
+ if intent == "conversation":
181
+ return {"mode": "conversation", "instruction": "Answer the user directly, naturally, and briefly."}
182
+ if intent == "status":
183
+ return await supervisor_bridge().request("get_current_work")
184
+ if intent == "cancel":
185
+ return await supervisor_bridge().request("cancel_current_work")
186
+ if not text:
187
+ raise ValueError("The routed request cannot be empty.")
188
+ if intent == "delegate":
189
+ return await supervisor_bridge().request("send_instruction", instruction=text)
190
+ return {
191
+ "mode": "narration",
192
+ "instruction": "Summarize this grounded update naturally without adding facts.",
193
+ "content": text,
194
+ }
195
+
196
+
197
+ class RoutedNovaSonicModel(BedrockNovaSonicModel):
198
+ """Require one routing tool call before each spoken response."""
199
+
200
+ def _get_prompt_start_event(self, tools: list[ToolSpec]) -> str:
201
+ event = json.loads(super()._get_prompt_start_event(tools))
202
+ tool_configuration = event["event"]["promptStart"].get("toolConfiguration")
203
+ if tool_configuration is not None:
204
+ tool_configuration["toolChoice"] = {"tool": {"name": "route_voice_turn"}}
205
+ return json.dumps(event, separators=(",", ":"))
206
+
207
+
208
+ class RoutedOpenAIRealtimeModel(OpenAIRealtimeModel):
209
+ """Require routing for user turns and allow speech after the routing result."""
210
+
211
+ def __init__(self, **kwargs: Any) -> None:
212
+ self._route_result_pending = False
213
+ super().__init__(**kwargs)
214
+
215
+ async def _send_tool_result(self, tool_result: ToolResultBlock) -> None:
216
+ # The SDK may defer response.create until the active response stops.
217
+ self._route_result_pending = True
218
+ await super()._send_tool_result(tool_result)
219
+
220
+ async def _send_event(self, event: dict[str, Any]) -> None:
221
+ routed_response = self._route_result_pending and event.get("type") == "response.create"
222
+ if routed_response:
223
+ event = {**event, "response": {**event.get("response", {}), "tool_choice": "none"}}
224
+ await super()._send_event(event)
225
+ if routed_response:
226
+ self._route_result_pending = False
227
+
228
+
229
+ class MutableAudioInput:
230
+ """Capture microphone audio while allowing mute and level reporting."""
231
+
232
+ def __init__(self, input_stream: InputStream) -> None:
233
+ self._input_stream = input_stream
234
+ self._muted = False
235
+ self._smoothed_level = 0.0
236
+ self._last_level_emit = 0.0
237
+
238
+ async def start(self, agent: BidiAgent) -> None:
239
+ """Start microphone capture."""
240
+ await self._input_stream.start(agent)
241
+
242
+ async def stop(self) -> None:
243
+ """Stop microphone capture."""
244
+ await self._input_stream.stop()
245
+
246
+ async def __call__(self) -> AudioDelta:
247
+ """Return captured audio, replacing it with silence while muted."""
248
+ event = await self._input_stream()
249
+ if not isinstance(event, AudioDelta):
250
+ raise TypeError(f"Expected audio input, received {type(event).__name__}.")
251
+ audio = event.source.get("bytes")
252
+ if not isinstance(audio, bytes):
253
+ raise TypeError("Expected microphone audio bytes.")
254
+ self._report_input_level(audio)
255
+ if not self._muted:
256
+ return event
257
+ return AudioDelta(format=event.format, source={"bytes": bytes(len(audio))})
258
+
259
+ def set_muted(self, muted: bool) -> None:
260
+ """Enable or disable microphone audio."""
261
+ self._muted = muted
262
+ if muted:
263
+ self._smoothed_level = 0.0
264
+ self._emit_input_level(0.0, INPUT_LEVEL_FLOOR_DB)
265
+
266
+ def _report_input_level(self, audio: bytes) -> None:
267
+ now = time.monotonic()
268
+ if now - self._last_level_emit < INPUT_LEVEL_INTERVAL_SECONDS:
269
+ return
270
+ self._last_level_emit = now
271
+ if self._muted:
272
+ self._emit_input_level(0.0, INPUT_LEVEL_FLOOR_DB)
273
+ return
274
+ if len(audio) < 2:
275
+ self._smoothed_level = 0.0
276
+ self._emit_input_level(0.0, INPUT_LEVEL_FLOOR_DB)
277
+ return
278
+
279
+ samples = array("h")
280
+ samples.frombytes(audio[: len(audio) - (len(audio) % 2)])
281
+ if sys.byteorder != "little":
282
+ samples.byteswap()
283
+
284
+ rms = math.sqrt(sum(sample * sample for sample in samples) / len(samples)) / 32768.0
285
+ db = max(INPUT_LEVEL_FLOOR_DB, 20.0 * math.log10(max(rms, 1e-6)))
286
+ level = (db - INPUT_LEVEL_FLOOR_DB) / -INPUT_LEVEL_FLOOR_DB
287
+ smoothing = 0.45 if level > self._smoothed_level else 0.2
288
+ self._smoothed_level += (level - self._smoothed_level) * smoothing
289
+ smoothed_db = INPUT_LEVEL_FLOOR_DB + self._smoothed_level * -INPUT_LEVEL_FLOOR_DB
290
+ self._emit_input_level(self._smoothed_level, smoothed_db)
291
+
292
+ @staticmethod
293
+ def _emit_input_level(level: float, db: float) -> None:
294
+ emit("input_level", level=round(level, 3), db=round(db, 1))
295
+
296
+
297
+ class SidecarControl:
298
+ """Read newline-delimited control messages from the Node parent process."""
299
+
300
+ def __init__(self) -> None:
301
+ self._commands: asyncio.Queue[dict[str, Any]] = asyncio.Queue()
302
+ self._loop: asyncio.AbstractEventLoop | None = None
303
+ self._stopped = threading.Event()
304
+
305
+ async def start(self) -> None:
306
+ """Start reading control messages."""
307
+ self._loop = asyncio.get_running_loop()
308
+ threading.Thread(target=self._read_lines, name="voice-sidecar-control", daemon=True).start()
309
+
310
+ async def stop(self) -> None:
311
+ """Stop reading control messages."""
312
+ self._stopped.set()
313
+ self._loop = None
314
+
315
+ async def next(self) -> dict[str, Any]:
316
+ """Wait for the next control message."""
317
+ return await self._commands.get()
318
+
319
+ def _read_lines(self) -> None:
320
+ while not self._stopped.is_set():
321
+ line = sys.stdin.readline()
322
+ if not line:
323
+ self._enqueue({"type": "stop"})
324
+ return
325
+ try:
326
+ command = json.loads(line)
327
+ except json.JSONDecodeError as error:
328
+ self._enqueue({"type": "control_error", "message": str(error)})
329
+ continue
330
+ if isinstance(command, dict):
331
+ self._enqueue(command)
332
+
333
+ def _enqueue(self, command: dict[str, Any]) -> None:
334
+ loop = self._loop
335
+ if loop is not None and not loop.is_closed():
336
+ loop.call_soon_threadsafe(self._commands.put_nowait, command)
337
+
338
+
339
+ class JsonEventOutput:
340
+ """Project the stable Bidi event stream onto the CLI sidecar protocol."""
341
+
342
+ def __init__(self) -> None:
343
+ self._transcripts: dict[str, str] = {}
344
+
345
+ async def start(self, agent: BidiAgent) -> None:
346
+ """Prepare event projection."""
347
+ del agent
348
+
349
+ async def stop(self) -> None:
350
+ """Clear incomplete transcripts."""
351
+ self._transcripts.clear()
352
+
353
+ async def __call__(self, event: BidiOutputEvent) -> None:
354
+ """Emit the subset of events consumed by the Node parent."""
355
+ if isinstance(event, BidiConnectionStartEvent):
356
+ emit("connection_start", connection_id=event.connection_id, model=event.model)
357
+ elif isinstance(event, BidiConnectionRestartEvent):
358
+ self._transcripts.clear()
359
+ emit(
360
+ "connection_restart",
361
+ reason=event.reason,
362
+ turn_interrupted=event.turn_interrupted,
363
+ error=str(event.timeout_error) if event.timeout_error is not None else None,
364
+ )
365
+ elif isinstance(event, BidiTranscriptDeltaEvent):
366
+ transcript = f"{self._transcripts.get(event.content_id, '')}{event.delta}"
367
+ self._transcripts[event.content_id] = transcript
368
+ emit(
369
+ "transcript",
370
+ role=event.role,
371
+ current_transcript=transcript,
372
+ is_final=False,
373
+ )
374
+ elif isinstance(event, BidiTranscriptBlockEvent):
375
+ self._transcripts.pop(event.content_id, None)
376
+ emit(
377
+ "transcript",
378
+ role=event.role,
379
+ current_transcript=event.transcript,
380
+ is_final=True,
381
+ )
382
+ elif isinstance(event, BidiConnectionStopEvent):
383
+ self._transcripts.clear()
384
+ emit("connection_stop", connection_id=event.connection_id, reason=event.reason)
385
+
386
+
387
+ class _SilentOutput:
388
+ """Suppress the console output bundled with AudioIO."""
389
+
390
+ async def start(self, agent: BidiAgent) -> None:
391
+ del agent
392
+
393
+ async def stop(self) -> None:
394
+ return
395
+
396
+ async def __call__(self, event: BidiOutputEvent) -> None:
397
+ del event
398
+
399
+
400
+ class _SilentConsoleIO:
401
+ """Provide AudioIO with a console that never writes to the terminal."""
402
+
403
+ def output(self) -> OutputStream:
404
+ """Return a no-op output stream."""
405
+ return _SilentOutput()
406
+
407
+
408
+ class ControlledAudioOutput:
409
+ """Play conversational and narrated replies with interruption handling."""
410
+
411
+ def __init__(self, output_stream: OutputStream) -> None:
412
+ self._output_stream = output_stream
413
+ self._response_id: str | None = None
414
+ self._playback: Literal["stopped", "ready", "playing"] = "stopped"
415
+ self._tool_response = False
416
+ self._interrupted_response_id: str | None = None
417
+ self._idle = asyncio.Event()
418
+
419
+ async def start(self, agent: BidiAgent) -> None:
420
+ """Start speaker output."""
421
+ await self._output_stream.start(agent)
422
+
423
+ async def stop(self) -> None:
424
+ """Stop speaker output."""
425
+ await self._output_stream.stop()
426
+ self._interrupted_response_id = None
427
+ self._finish_response(idle=False)
428
+
429
+ async def __call__(self, event: BidiOutputEvent) -> None:
430
+ """Route response audio according to the current playback request."""
431
+ if isinstance(event, BidiConnectionStartEvent):
432
+ self._interrupted_response_id = None
433
+ self._finish_response()
434
+ elif isinstance(event, BidiResponseStartEvent):
435
+ self._response_id = event.response_id
436
+ self._idle.clear()
437
+ self._playback = "ready"
438
+ self._tool_response = False
439
+ elif isinstance(event, BidiToolUseBlocksEvent):
440
+ self._tool_response = True
441
+ elif isinstance(event, BidiAudioDeltaEvent):
442
+ self._tool_response = False
443
+ if self._playback == "stopped":
444
+ return
445
+ if self._playback == "ready":
446
+ self._playback = "playing"
447
+ emit("speech_output_start")
448
+ await self._output_stream(event)
449
+ elif isinstance(event, BidiBargeInEvent):
450
+ await self._output_stream(event)
451
+ if self._response_id is None:
452
+ self._idle.clear()
453
+ return
454
+ if self._playback == "playing":
455
+ emit("speech_output_interrupted")
456
+ self._interrupted_response_id = self._response_id
457
+ self._finish_response(idle=False)
458
+ elif isinstance(event, BidiResponseStopEvent):
459
+ if event.response_id == self._interrupted_response_id:
460
+ self._interrupted_response_id = None
461
+ return
462
+ if self._tool_response:
463
+ self._finish_response(idle=False)
464
+ return
465
+ if self._playback == "playing":
466
+ emit("speech_output_complete", response_id=event.response_id)
467
+ self._finish_response()
468
+ elif isinstance(event, (BidiConnectionRestartEvent, BidiConnectionStopEvent)):
469
+ await self.stop_speaking()
470
+ self._interrupted_response_id = None
471
+ self._finish_response(idle=False)
472
+
473
+ async def wait_until_idle(self) -> None:
474
+ """Wait until the model finishes its current response."""
475
+ await self._idle.wait()
476
+
477
+ def mark_response_pending(self) -> None:
478
+ """Reserve playback before a programmatic response is submitted."""
479
+ self._finish_response(idle=False)
480
+
481
+ async def stop_speaking(self) -> None:
482
+ """Clear speaker output without ending the model's turn."""
483
+ was_speaking = self._playback == "playing"
484
+ await self._output_stream(BidiBargeInEvent())
485
+ self._playback = "stopped"
486
+ if was_speaking:
487
+ emit("speech_output_stopped")
488
+
489
+ def _finish_response(self, *, idle: bool = True) -> None:
490
+ self._response_id = None
491
+ self._playback = "stopped"
492
+ self._tool_response = False
493
+ if idle:
494
+ self._idle.set()
495
+ else:
496
+ self._idle.clear()
497
+
498
+
499
+ def parse_args() -> argparse.Namespace:
500
+ """Parse sidecar configuration."""
501
+ parser = argparse.ArgumentParser(description="Run the Strands CLI bidirectional voice supervisor.")
502
+ parser.add_argument("--provider", choices=["bedrock", "openai"], default="bedrock")
503
+ parser.add_argument("--model")
504
+ parser.add_argument("--region", help="AWS region; defaults to the active AWS configuration.")
505
+ parser.add_argument("--voice")
506
+ parser.add_argument(
507
+ "--endpointing-sensitivity",
508
+ choices=["HIGH", "MEDIUM", "LOW"],
509
+ default=DEFAULT_ENDPOINTING_SENSITIVITY,
510
+ )
511
+ parser.add_argument("--input-device", type=int)
512
+ parser.add_argument("--output-device", type=int)
513
+ parser.add_argument("--muted", action="store_true")
514
+ parser.add_argument("--list-devices", action="store_true")
515
+ parser.add_argument(
516
+ "--check", action="store_true", help="Validate credentials and audio devices without connecting."
517
+ )
518
+ return parser.parse_args()
519
+
520
+
521
+ def audio_devices() -> list[dict[str, Any]]:
522
+ """List local audio devices."""
523
+ try:
524
+ audio = pyaudio.PyAudio()
525
+ except OSError as error:
526
+ # Same first-run dead end as the import, for layouts where PyAudio imports but the
527
+ # PortAudio init fails; --check would otherwise show a bare OSError.
528
+ raise OSError(f"{PORTAUDIO_INSTALL_GUIDANCE}\nDetails: {error}") from error
529
+ try:
530
+ devices = []
531
+ for index in range(audio.get_device_count()):
532
+ info = audio.get_device_info_by_index(index)
533
+ devices.append(
534
+ {
535
+ "index": index,
536
+ "name": info.get("name"),
537
+ "input_channels": int(info.get("maxInputChannels", 0)),
538
+ "output_channels": int(info.get("maxOutputChannels", 0)),
539
+ "default_sample_rate": int(info.get("defaultSampleRate", 0)),
540
+ }
541
+ )
542
+ return devices
543
+ finally:
544
+ audio.terminate()
545
+
546
+
547
+ def preflight(args: argparse.Namespace) -> tuple[str | None, list[dict[str, Any]]]:
548
+ """Validate credentials, region, and local audio devices."""
549
+ args.model = args.model or DEFAULT_MODELS[args.provider]
550
+ args.voice = args.voice or DEFAULT_VOICES[args.provider]
551
+ region: str | None = None
552
+ if args.provider == "bedrock":
553
+ session = boto3.Session()
554
+ if session.get_credentials() is None:
555
+ raise RuntimeError("AWS credentials were not found. Configure Bedrock with /setup, then try again.")
556
+ region = (
557
+ args.region
558
+ or session.region_name
559
+ or os.getenv("AWS_REGION")
560
+ or os.getenv("AWS_DEFAULT_REGION")
561
+ or "us-east-1"
562
+ )
563
+ elif not os.getenv("OPENAI_API_KEY"):
564
+ raise RuntimeError("OPENAI_API_KEY is not configured. Add OpenAI credentials with /setup, then try again.")
565
+
566
+ devices = audio_devices()
567
+ if not any(device["input_channels"] > 0 for device in devices):
568
+ raise RuntimeError("No microphone input device was found.")
569
+ if not any(device["output_channels"] > 0 for device in devices):
570
+ raise RuntimeError("No speaker output device was found.")
571
+
572
+ emit(
573
+ "preflight",
574
+ ok=True,
575
+ provider=args.provider,
576
+ model=args.model,
577
+ region=region,
578
+ cwd=str(Path.cwd()),
579
+ input_device=args.input_device,
580
+ output_device=args.output_device,
581
+ device_count=len(devices),
582
+ )
583
+ return region, devices
584
+
585
+
586
+ async def run_voice(args: argparse.Namespace, region: str | None) -> None:
587
+ """Run the sidecar until the parent, signal, or model ends the session."""
588
+ global _supervisor_bridge
589
+ bridge = SupervisorBridge()
590
+ _supervisor_bridge = bridge
591
+ if args.provider == "bedrock":
592
+ model = RoutedNovaSonicModel(
593
+ model_id=args.model,
594
+ region=region,
595
+ voice=args.voice,
596
+ params={
597
+ "turnDetectionConfiguration": {
598
+ "endpointingSensitivity": args.endpointing_sensitivity,
599
+ }
600
+ },
601
+ )
602
+ else:
603
+ model = RoutedOpenAIRealtimeModel(
604
+ model_id=args.model,
605
+ transcription_model_id=OPENAI_TRANSCRIPTION_MODEL,
606
+ voice=args.voice,
607
+ params={
608
+ "tool_choice": {"type": "function", "name": "route_voice_turn"},
609
+ "audio": {
610
+ "input": {
611
+ "turn_detection": {
612
+ "silence_duration_ms": OPENAI_SILENCE_DURATION_MS[args.endpointing_sensitivity],
613
+ }
614
+ }
615
+ },
616
+ },
617
+ )
618
+ audio = AudioIO(
619
+ audio_processor=AudioProcessorConfig(),
620
+ console=cast(ConsoleIO, _SilentConsoleIO()),
621
+ input_device_index=args.input_device,
622
+ output_device_index=args.output_device,
623
+ )
624
+ agent = BidiAgent(
625
+ model=model,
626
+ tools=[route_voice_turn],
627
+ system_prompt=SYSTEM_PROMPT,
628
+ name="Strands Voice",
629
+ )
630
+ audio_input = MutableAudioInput(audio.input())
631
+ audio_input.set_muted(args.muted)
632
+ audio_output = ControlledAudioOutput(audio.output())
633
+ event_output = JsonEventOutput()
634
+ control = SidecarControl()
635
+ narrations: asyncio.Queue[str] = asyncio.Queue()
636
+ stop_requested = asyncio.Event()
637
+ loop = asyncio.get_running_loop()
638
+ registered_signals: list[signal.Signals] = []
639
+
640
+ for signal_number in (signal.SIGINT, signal.SIGTERM):
641
+ try:
642
+ loop.add_signal_handler(signal_number, stop_requested.set)
643
+ registered_signals.append(signal_number)
644
+ except NotImplementedError:
645
+ pass
646
+
647
+ async def run_controls() -> None:
648
+ while True:
649
+ command = await control.next()
650
+ command_type = command.get("type")
651
+ if command_type == "set_muted":
652
+ muted = command.get("muted") is True
653
+ audio_input.set_muted(muted)
654
+ emit("mute_changed", muted=muted)
655
+ elif command_type == "narrate":
656
+ text = str(command.get("text", "")).strip()
657
+ if not text:
658
+ emit("control_error", message="The narration command requires non-empty text.")
659
+ continue
660
+ await narrations.put(text)
661
+ elif command_type == "supervisor_result":
662
+ bridge.resolve(command)
663
+ elif command_type == "stop_speaking":
664
+ await audio_output.stop_speaking()
665
+ elif command_type == "stop":
666
+ return
667
+ elif command_type == "control_error":
668
+ emit("control_error", message=command.get("message"))
669
+ else:
670
+ emit("control_error", message=f"Unknown control message: {command_type}")
671
+
672
+ async def run_narrations() -> None:
673
+ while True:
674
+ text = await narrations.get()
675
+ await audio_output.wait_until_idle()
676
+ audio_output.mark_response_pending()
677
+ try:
678
+ await agent.send(NARRATION_PROMPT.format(text=text))
679
+ except BaseException:
680
+ await audio_output.stop_speaking()
681
+ raise
682
+
683
+ tasks: list[asyncio.Task[Any]] = []
684
+ await control.start()
685
+ try:
686
+ tasks = [
687
+ asyncio.create_task(agent.run(inputs=[audio_input], outputs=[audio_output, event_output])),
688
+ asyncio.create_task(run_controls()),
689
+ asyncio.create_task(run_narrations()),
690
+ asyncio.create_task(stop_requested.wait()),
691
+ ]
692
+ done, _ = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
693
+ for task in done:
694
+ if task is tasks[3] or task.cancelled():
695
+ continue
696
+ task.result()
697
+ finally:
698
+ for task in tasks:
699
+ task.cancel()
700
+ await asyncio.gather(*tasks, return_exceptions=True)
701
+ bridge.cancel()
702
+ _supervisor_bridge = None
703
+ await control.stop()
704
+ for signal_number in registered_signals:
705
+ loop.remove_signal_handler(signal_number)
706
+
707
+
708
+ def main() -> int:
709
+ """Run the voice sidecar."""
710
+ logging.basicConfig(level=logging.WARNING, stream=sys.stderr)
711
+ args = parse_args()
712
+
713
+ try:
714
+ region, devices = preflight(args)
715
+ if args.list_devices:
716
+ for device in devices:
717
+ emit("audio_device", **device)
718
+ if args.check or args.list_devices:
719
+ return 0
720
+ asyncio.run(run_voice(args, region))
721
+ return 0
722
+ except KeyboardInterrupt:
723
+ return 0
724
+ except Exception as error:
725
+ emit("fatal_error", code=type(error).__name__, message=str(error))
726
+ return 1
727
+
728
+
729
+ if __name__ == "__main__":
730
+ raise SystemExit(main())