@strands-agents/cli 0.2.4 → 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
@@ -1,631 +0,0 @@
1
- # /// script
2
- # requires-python = ">=3.12,<3.14"
3
- # dependencies = [
4
- # "strands-agents[bidi,bidi-aec,bidi-pyaudio] @ git+https://github.com/strands-agents/harness-sdk.git@647128383ea9ba4598d3cf47e376642091d339d9#subdirectory=strands-py",
5
- # ]
6
- # ///
7
-
8
- """Nova Sonic audio sidecar for the Strands CLI voice runtime."""
9
-
10
- from __future__ import annotations
11
-
12
- import argparse
13
- import asyncio
14
- import base64
15
- import json
16
- import logging
17
- import math
18
- import os
19
- import signal
20
- import sys
21
- import time
22
- from array import array
23
- from pathlib import Path
24
- from typing import Any
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.experimental.bidi import (
50
- AudioProcessorConfig,
51
- BidiAgent,
52
- BidiAudioInputEvent,
53
- BidiAudioIO,
54
- BidiAudioStreamEvent,
55
- BidiConnectionCloseEvent,
56
- BidiConnectionRestartEvent,
57
- BidiConnectionStartEvent,
58
- BidiErrorEvent,
59
- BidiInterruptionEvent,
60
- BidiResponseCompleteEvent,
61
- BidiResponseStartEvent,
62
- BidiTextInputEvent,
63
- BidiTranscriptStreamEvent,
64
- BidiUsageEvent,
65
- )
66
- from strands.experimental.bidi.models import BidiNovaSonicModel
67
- from strands.experimental.bidi.types.events import BidiOutputEvent
68
- from strands.experimental.bidi.types.io import BidiInput, BidiOutput
69
- from strands.experimental.hooks.events import BidiAfterToolCallEvent, BidiBeforeToolCallEvent
70
- from strands.hooks import HookProvider
71
-
72
- DEFAULT_MODEL = "amazon.nova-2-5-sonic"
73
- DEFAULT_ENDPOINTING_SENSITIVITY = "LOW"
74
- DEFAULT_SYSTEM_PROMPT = """
75
- You are Strands harness, a concise coding assistant in a live voice conversation.
76
- Keep spoken answers short unless the user asks for detail.
77
- Use current_working_directory whenever the user asks where you are working.
78
- The user may speak over you or send typed text during the conversation.
79
- """.strip()
80
- SIDECAR_SYSTEM_PROMPT = """
81
- You are a speech transcription transport for a separate coding agent.
82
- Listen carefully to the user and keep each response to one short acknowledgement.
83
- Do not answer questions, use tools, or attempt coding work.
84
- """.strip()
85
- SPEAK_PROMPT = """
86
- Read the coding assistant response below aloud naturally.
87
- Preserve its meaning and do not add commentary.
88
- Skip markdown punctuation, URLs, and code syntax that would be awkward to speak.
89
-
90
- <coding_assistant_response>
91
- {text}
92
- </coding_assistant_response>
93
- """.strip()
94
- INPUT_LEVEL_FLOOR_DB = -60.0
95
- INPUT_LEVEL_INTERVAL_SECONDS = 0.08
96
-
97
-
98
- def emit(event_type: str, **payload: Any) -> None:
99
- print(json.dumps({"type": event_type, **payload}, default=str, separators=(",", ":")), flush=True)
100
-
101
-
102
- @tool
103
- def current_working_directory() -> str:
104
- """Return the absolute working directory for this voice session."""
105
- return str(Path.cwd())
106
-
107
-
108
- class TypedTextInput(BidiInput):
109
- """Read optional text input while microphone streaming remains active."""
110
-
111
- def __init__(self) -> None:
112
- self._lines: asyncio.Queue[str] = asyncio.Queue()
113
- self._loop: asyncio.AbstractEventLoop | None = None
114
- self._file_descriptor = sys.stdin.fileno()
115
-
116
- async def start(self, agent: BidiAgent) -> None:
117
- del agent
118
- self._loop = asyncio.get_running_loop()
119
- self._loop.add_reader(self._file_descriptor, self._read_line)
120
- print("text> ", end="", file=sys.stderr, flush=True)
121
-
122
- async def stop(self) -> None:
123
- if self._loop is not None:
124
- self._loop.remove_reader(self._file_descriptor)
125
- self._loop = None
126
-
127
- async def __call__(self) -> BidiTextInputEvent:
128
- text = (await self._lines.get()).strip()
129
- if not text:
130
- return await self()
131
- print("text> ", end="", file=sys.stderr, flush=True)
132
- return BidiTextInputEvent(text=text)
133
-
134
- def _read_line(self) -> None:
135
- line = sys.stdin.readline()
136
- if line:
137
- self._lines.put_nowait(line)
138
-
139
-
140
- class MutableAudioInput(BidiInput):
141
- """Replace captured audio with silence while the sidecar is muted."""
142
-
143
- def __init__(self, input_: BidiInput, report_levels: bool) -> None:
144
- self._input = input_
145
- self._muted = False
146
- self._report_levels = report_levels
147
- self._smoothed_level = 0.0
148
- self._last_level_emit = 0.0
149
-
150
- async def start(self, agent: BidiAgent) -> None:
151
- await self._input.start(agent)
152
-
153
- async def stop(self) -> None:
154
- await self._input.stop()
155
-
156
- async def __call__(self) -> BidiAudioInputEvent:
157
- event = await self._input()
158
- if not isinstance(event, BidiAudioInputEvent):
159
- raise TypeError(f"Expected audio input, received {type(event).__name__}.")
160
- audio = base64.b64decode(event.audio)
161
- self._report_input_level(audio)
162
- if not self._muted:
163
- return event
164
- return BidiAudioInputEvent(
165
- audio=base64.b64encode(bytes(len(audio))).decode("utf-8"),
166
- format=event.format,
167
- sample_rate=event.sample_rate,
168
- channels=event.channels,
169
- )
170
-
171
- def set_muted(self, muted: bool) -> None:
172
- self._muted = muted
173
- if muted:
174
- self._smoothed_level = 0.0
175
- self._emit_input_level(0.0, INPUT_LEVEL_FLOOR_DB)
176
-
177
- def _report_input_level(self, audio: bytes) -> None:
178
- if not self._report_levels or self._muted:
179
- return
180
- now = time.monotonic()
181
- if now - self._last_level_emit < INPUT_LEVEL_INTERVAL_SECONDS:
182
- return
183
- self._last_level_emit = now
184
- if len(audio) < 2:
185
- self._smoothed_level = 0.0
186
- self._emit_input_level(0.0, INPUT_LEVEL_FLOOR_DB)
187
- return
188
-
189
- samples = array("h")
190
- samples.frombytes(audio[: len(audio) - (len(audio) % 2)])
191
- if sys.byteorder != "little":
192
- samples.byteswap()
193
-
194
- rms = math.sqrt(sum(sample * sample for sample in samples) / len(samples)) / 32768.0
195
- db = max(INPUT_LEVEL_FLOOR_DB, 20.0 * math.log10(max(rms, 1e-6)))
196
- level = (db - INPUT_LEVEL_FLOOR_DB) / -INPUT_LEVEL_FLOOR_DB
197
- smoothing = 0.45 if level > self._smoothed_level else 0.2
198
- self._smoothed_level += (level - self._smoothed_level) * smoothing
199
- smoothed_db = INPUT_LEVEL_FLOOR_DB + self._smoothed_level * -INPUT_LEVEL_FLOOR_DB
200
- self._emit_input_level(self._smoothed_level, smoothed_db)
201
-
202
- def _emit_input_level(self, level: float, db: float) -> None:
203
- if self._report_levels:
204
- emit("input_level", level=round(level, 3), db=round(db, 1))
205
-
206
-
207
- class SidecarControl:
208
- """Read newline-delimited control messages from the Node parent process."""
209
-
210
- def __init__(self) -> None:
211
- self._commands: asyncio.Queue[dict[str, Any]] = asyncio.Queue()
212
- self._loop: asyncio.AbstractEventLoop | None = None
213
- self._file_descriptor = sys.stdin.fileno()
214
-
215
- async def start(self) -> None:
216
- self._loop = asyncio.get_running_loop()
217
- self._loop.add_reader(self._file_descriptor, self._read_line)
218
-
219
- async def stop(self) -> None:
220
- if self._loop is not None:
221
- self._loop.remove_reader(self._file_descriptor)
222
- self._loop = None
223
-
224
- async def next(self) -> dict[str, Any]:
225
- return await self._commands.get()
226
-
227
- def _read_line(self) -> None:
228
- line = sys.stdin.readline()
229
- if not line:
230
- self._commands.put_nowait({"type": "stop", "reason": "stdin_closed"})
231
- return
232
- try:
233
- command = json.loads(line)
234
- except json.JSONDecodeError as error:
235
- emit("control_error", message=str(error))
236
- return
237
- if isinstance(command, dict):
238
- self._commands.put_nowait(command)
239
-
240
-
241
- class JsonEventOutput(BidiOutput):
242
- """Project useful Bidi events to JSON without dumping audio payloads."""
243
-
244
- def __init__(self) -> None:
245
- self._audio_started = False
246
- self._last_usage_total = -100
247
-
248
- async def __call__(self, event: BidiOutputEvent) -> None:
249
- if isinstance(event, BidiConnectionStartEvent):
250
- emit("connection_start", connection_id=event.connection_id, model=event.model)
251
- elif isinstance(event, BidiConnectionRestartEvent):
252
- emit("connection_restart", error=str(event.timeout_error))
253
- elif isinstance(event, BidiResponseStartEvent):
254
- self._audio_started = False
255
- emit("response_start", response_id=event.response_id)
256
- elif isinstance(event, BidiAudioStreamEvent):
257
- if not self._audio_started:
258
- self._audio_started = True
259
- emit(
260
- "audio_output_start",
261
- format=event.format,
262
- sample_rate=event.sample_rate,
263
- channels=event.channels,
264
- )
265
- elif isinstance(event, BidiTranscriptStreamEvent):
266
- emit(
267
- "transcript",
268
- role=event.role,
269
- text=event.text,
270
- is_final=event.is_final,
271
- current_transcript=event.current_transcript,
272
- )
273
- elif isinstance(event, BidiInterruptionEvent):
274
- self._audio_started = False
275
- emit("interruption", reason=event.reason)
276
- elif isinstance(event, BidiResponseCompleteEvent):
277
- self._audio_started = False
278
- emit("response_complete", response_id=event.response_id, stop_reason=event.stop_reason)
279
- elif isinstance(event, BidiUsageEvent):
280
- if event.total_tokens - self._last_usage_total >= 100:
281
- self._last_usage_total = event.total_tokens
282
- emit(
283
- "usage",
284
- input_tokens=event.input_tokens,
285
- output_tokens=event.output_tokens,
286
- total_tokens=event.total_tokens,
287
- )
288
- elif isinstance(event, BidiConnectionCloseEvent):
289
- emit("connection_close", connection_id=event.connection_id, reason=event.reason)
290
- elif isinstance(event, BidiErrorEvent):
291
- emit("error", code=event.code, message=event.message, details=event.details)
292
-
293
-
294
- class ControlledAudioOutput(BidiOutput):
295
- """Play only responses explicitly requested by the Node parent process."""
296
-
297
- def __init__(self, output: BidiOutput) -> None:
298
- self._output = output
299
- self._response_id: str | None = None
300
- self._play_current = False
301
- self._audio_started = False
302
- self._armed = False
303
- self._idle = asyncio.Event()
304
- self._idle.set()
305
-
306
- async def start(self, agent: BidiAgent) -> None:
307
- await self._output.start(agent)
308
-
309
- async def stop(self) -> None:
310
- await self._output.stop()
311
-
312
- async def __call__(self, event: BidiOutputEvent) -> None:
313
- if isinstance(event, BidiResponseStartEvent):
314
- if not self._idle.is_set() and event.response_id == self._response_id:
315
- return
316
- self._response_id = event.response_id
317
- self._idle.clear()
318
- self._play_current = self._armed
319
- self._armed = False
320
- self._audio_started = False
321
- return
322
- if isinstance(event, BidiAudioStreamEvent):
323
- if not self._play_current:
324
- return
325
- if not self._audio_started:
326
- self._audio_started = True
327
- emit("speech_output_start")
328
- await self._output(event)
329
- return
330
- if isinstance(event, BidiTranscriptStreamEvent):
331
- if event.role == "assistant" and event.is_final and not self._idle.is_set():
332
- if self._play_current:
333
- emit("speech_output_complete", response_id=self._response_id)
334
- self._finish_response()
335
- return
336
- if isinstance(event, BidiInterruptionEvent):
337
- await self._output(event)
338
- if self._play_current:
339
- emit("speech_output_interrupted", reason=event.reason)
340
- self._finish_response()
341
- return
342
- if isinstance(event, BidiResponseCompleteEvent):
343
- if self._play_current:
344
- emit("speech_output_complete", response_id=event.response_id)
345
- self._finish_response()
346
-
347
- async def wait_until_idle(self) -> None:
348
- await self._idle.wait()
349
-
350
- def arm_next_response(self) -> None:
351
- self._armed = True
352
-
353
- async def stop_speaking(self) -> None:
354
- was_speaking = self._play_current or self._armed
355
- await self._output(BidiInterruptionEvent(reason="user_speech"))
356
- self._play_current = False
357
- self._audio_started = False
358
- self._armed = False
359
- if was_speaking:
360
- emit("speech_output_stopped")
361
-
362
- def _finish_response(self) -> None:
363
- self._response_id = None
364
- self._play_current = False
365
- self._audio_started = False
366
- self._armed = False
367
- self._idle.set()
368
-
369
-
370
- class ToolEventHooks(HookProvider):
371
- """Emit definitive tool lifecycle events from hooks."""
372
-
373
- def register_hooks(self, registry: Any, **_: Any) -> None:
374
- registry.add_callback(BidiBeforeToolCallEvent, self._before_tool)
375
- registry.add_callback(BidiAfterToolCallEvent, self._after_tool)
376
-
377
- def _before_tool(self, event: BidiBeforeToolCallEvent) -> None:
378
- emit(
379
- "tool_start",
380
- tool_use_id=event.tool_use.get("toolUseId"),
381
- name=event.tool_use.get("name"),
382
- input=event.tool_use.get("input", {}),
383
- )
384
-
385
- def _after_tool(self, event: BidiAfterToolCallEvent) -> None:
386
- emit(
387
- "tool_finish",
388
- tool_use_id=event.tool_use.get("toolUseId"),
389
- name=event.tool_use.get("name"),
390
- result=event.result,
391
- )
392
-
393
-
394
- def parse_args() -> argparse.Namespace:
395
- parser = argparse.ArgumentParser(description="Exercise Strands Bidi with Nova Sonic and local audio.")
396
- parser.add_argument("--model", default=DEFAULT_MODEL)
397
- parser.add_argument("--region", help="AWS region; defaults to the active AWS configuration.")
398
- parser.add_argument("--voice", default="tiffany")
399
- parser.add_argument(
400
- "--endpointing-sensitivity",
401
- choices=["HIGH", "MEDIUM", "LOW"],
402
- default=DEFAULT_ENDPOINTING_SENSITIVITY,
403
- )
404
- parser.add_argument("--input-device", type=int)
405
- parser.add_argument("--output-device", type=int)
406
- parser.add_argument("--list-devices", action="store_true")
407
- parser.add_argument("--sidecar", action="store_true", help="Run as the Strands CLI transcription sidecar.")
408
- parser.add_argument(
409
- "--check", action="store_true", help="Validate credentials and audio devices without connecting."
410
- )
411
- return parser.parse_args()
412
-
413
-
414
- def audio_devices() -> list[dict[str, Any]]:
415
- try:
416
- audio = pyaudio.PyAudio()
417
- except OSError as error:
418
- # Same first-run dead end as the import, for layouts where PyAudio imports but the
419
- # PortAudio init fails; --check would otherwise show a bare OSError.
420
- raise OSError(f"{PORTAUDIO_INSTALL_GUIDANCE}\nDetails: {error}") from error
421
- try:
422
- devices = []
423
- for index in range(audio.get_device_count()):
424
- info = audio.get_device_info_by_index(index)
425
- devices.append(
426
- {
427
- "index": index,
428
- "name": info.get("name"),
429
- "input_channels": int(info.get("maxInputChannels", 0)),
430
- "output_channels": int(info.get("maxOutputChannels", 0)),
431
- "default_sample_rate": int(info.get("defaultSampleRate", 0)),
432
- }
433
- )
434
- return devices
435
- finally:
436
- audio.terminate()
437
-
438
-
439
- def preflight(args: argparse.Namespace) -> tuple[str, list[dict[str, Any]]]:
440
- credentials = boto3.Session().get_credentials()
441
- if credentials is None:
442
- raise RuntimeError("AWS credentials were not found.")
443
-
444
- region: str = (
445
- args.region
446
- or boto3.Session().region_name
447
- or os.getenv("AWS_REGION")
448
- or os.getenv("AWS_DEFAULT_REGION")
449
- or "us-east-1"
450
- )
451
- devices = audio_devices()
452
- if not any(device["input_channels"] > 0 for device in devices):
453
- raise RuntimeError("No microphone input device was found.")
454
- if not args.sidecar and not any(device["output_channels"] > 0 for device in devices):
455
- raise RuntimeError("No speaker output device was found.")
456
-
457
- emit(
458
- "preflight",
459
- ok=True,
460
- model=args.model,
461
- region=region,
462
- cwd=str(Path.cwd()),
463
- input_device=args.input_device,
464
- output_device=args.output_device,
465
- device_count=len(devices),
466
- )
467
- return region, devices
468
-
469
-
470
- async def run_voice(args: argparse.Namespace, region: str) -> None:
471
- model = BidiNovaSonicModel(
472
- model_id=args.model,
473
- provider_config={
474
- "audio": {"voice": args.voice},
475
- "turn_detection": {"endpointingSensitivity": args.endpointing_sensitivity},
476
- },
477
- client_config={"region": region},
478
- )
479
- audio = BidiAudioIO(
480
- processor=AudioProcessorConfig(),
481
- input_device_index=args.input_device,
482
- output_device_index=args.output_device,
483
- )
484
- agent = BidiAgent(
485
- model=model,
486
- tools=[] if args.sidecar else [current_working_directory],
487
- system_prompt=SIDECAR_SYSTEM_PROMPT if args.sidecar else DEFAULT_SYSTEM_PROMPT,
488
- hooks=[] if args.sidecar else [ToolEventHooks()],
489
- name="Strands Voice",
490
- )
491
- audio_input = MutableAudioInput(audio.input(), report_levels=args.sidecar)
492
- text_input = TypedTextInput()
493
- audio_output = audio.output()
494
- controlled_audio_output = ControlledAudioOutput(audio_output)
495
- json_output = JsonEventOutput()
496
- sidecar_control = SidecarControl() if args.sidecar else None
497
- inputs = [audio_input] if args.sidecar else [audio_input, text_input]
498
- outputs = [controlled_audio_output if args.sidecar else audio_output, json_output]
499
- stop_requested = asyncio.Event()
500
- loop = asyncio.get_running_loop()
501
-
502
- def request_stop(reason: str) -> None:
503
- if stop_requested.is_set():
504
- return
505
- emit("session_stop_requested", reason=reason)
506
- stop_requested.set()
507
-
508
- for signal_number in (signal.SIGINT, signal.SIGTERM):
509
- loop.add_signal_handler(signal_number, request_stop, signal.Signals(signal_number).name.lower())
510
-
511
- async def run_input(input_: BidiInput) -> None:
512
- while True:
513
- await agent.send(await input_())
514
-
515
- async def run_output() -> None:
516
- async for event in agent.receive():
517
- await asyncio.gather(*(output(event) for output in outputs))
518
- request_stop("connection_closed")
519
-
520
- async def run_controls() -> None:
521
- assert sidecar_control is not None
522
- while True:
523
- command = await sidecar_control.next()
524
- command_type = command.get("type")
525
- if command_type == "set_muted":
526
- muted = bool(command.get("muted"))
527
- audio_input.set_muted(muted)
528
- emit("mute_changed", muted=muted)
529
- elif command_type == "speak":
530
- text = str(command.get("text", "")).strip()
531
- if not text:
532
- emit("control_error", message="The speak command requires non-empty text.")
533
- continue
534
- await controlled_audio_output.wait_until_idle()
535
- controlled_audio_output.arm_next_response()
536
- await agent.send(BidiTextInputEvent(text=SPEAK_PROMPT.format(text=text)))
537
- emit("speech_output_queued")
538
- elif command_type == "stop_speaking":
539
- await controlled_audio_output.stop_speaking()
540
- elif command_type == "stop":
541
- request_stop(str(command.get("reason", "parent_request")))
542
- return
543
- else:
544
- emit("control_error", message=f"Unknown control message: {command_type}")
545
-
546
- emit(
547
- "session_start",
548
- model=args.model,
549
- region=region,
550
- voice=args.voice,
551
- endpointing_sensitivity=args.endpointing_sensitivity,
552
- )
553
- if not args.sidecar:
554
- print(
555
- "Voice session starting. Speak normally, type at the text> prompt, interrupt while the assistant speaks, "
556
- "and press Ctrl+C to stop.",
557
- file=sys.stderr,
558
- flush=True,
559
- )
560
- workers: list[asyncio.Task[None]] = []
561
- stop_waiter: asyncio.Task[bool] | None = None
562
- started = False
563
- try:
564
- await agent.start()
565
- started = True
566
- for channel in [*inputs, *outputs]:
567
- await channel.start(agent)
568
- if sidecar_control is not None:
569
- await sidecar_control.start()
570
-
571
- workers = [
572
- *(asyncio.create_task(run_input(input_)) for input_ in inputs),
573
- asyncio.create_task(run_output()),
574
- *([asyncio.create_task(run_controls())] if sidecar_control is not None else []),
575
- ]
576
- stop_waiter = asyncio.create_task(stop_requested.wait())
577
- done, _ = await asyncio.wait([stop_waiter, *workers], return_when=asyncio.FIRST_COMPLETED)
578
- for task in done:
579
- if task is stop_waiter or task.cancelled():
580
- continue
581
- task.result()
582
- finally:
583
- if stop_waiter is not None:
584
- stop_waiter.cancel()
585
- for worker in workers:
586
- worker.cancel()
587
- await asyncio.gather(*workers, return_exceptions=True)
588
- if stop_waiter is not None:
589
- await asyncio.gather(stop_waiter, return_exceptions=True)
590
- for channel in [*inputs, *outputs, *([sidecar_control] if sidecar_control is not None else [])]:
591
- try:
592
- await channel.stop()
593
- except Exception as error:
594
- emit("cleanup_error", component=type(channel).__name__, message=str(error))
595
- if started:
596
- # The experimental Nova client can hang while writing protocol end events after cancellation.
597
- # Clearing the connection ID skips those writes; BidiAgent.stop still closes the stream and loop.
598
- if hasattr(agent.model, "_connection_id"):
599
- agent.model._connection_id = None # pyright: ignore[reportAttributeAccessIssue]
600
- try:
601
- await asyncio.wait_for(agent.stop(), timeout=10)
602
- except TimeoutError:
603
- emit("cleanup_error", component="BidiAgent", message="Timed out while stopping the agent loop.")
604
- except Exception as error:
605
- emit("cleanup_error", component="BidiAgent", message=str(error))
606
- emit("session_stopped")
607
-
608
-
609
- def main() -> int:
610
- logging.basicConfig(level=logging.WARNING, stream=sys.stderr)
611
- args = parse_args()
612
-
613
- try:
614
- region, devices = preflight(args)
615
- if args.list_devices:
616
- for device in devices:
617
- emit("audio_device", **device)
618
- if args.check or args.list_devices:
619
- return 0
620
- asyncio.run(run_voice(args, region))
621
- return 0
622
- except KeyboardInterrupt:
623
- emit("session_stop", reason="keyboard_interrupt")
624
- return 0
625
- except Exception as error:
626
- emit("fatal_error", code=type(error).__name__, message=str(error))
627
- return 1
628
-
629
-
630
- if __name__ == "__main__":
631
- raise SystemExit(main())
File without changes
File without changes
File without changes