@hybridaione/hybridclaw 0.27.2 → 0.28.1

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 (294) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +17 -13
  3. package/SECURITY.md +11 -0
  4. package/config.example.json +14 -2
  5. package/console/dist/assets/apps-C1v9uVsi.css +1 -0
  6. package/console/dist/assets/apps-D2SypHV9.js +1 -0
  7. package/console/dist/assets/chat-ByRN1fI0.js +4 -0
  8. package/console/dist/assets/chat-sidebar-CRmaDdTt.js +5 -0
  9. package/console/dist/assets/{index-B7ZQvYLH.js → index-CXajfe7-.js} +38 -37
  10. package/console/dist/assets/index-DV7JemOI.css +1 -0
  11. package/console/dist/assets/{terminal-CJP-btmG.js → terminal-CWAbt7tC.js} +1 -1
  12. package/console/dist/index.html +2 -2
  13. package/console/package.json +1 -1
  14. package/container/dist/index.js +4 -0
  15. package/container/dist/index.js.map +1 -1
  16. package/container/dist/providers/anthropic.js +103 -15
  17. package/container/dist/providers/anthropic.js.map +1 -1
  18. package/container/dist/providers/auxiliary.js +1 -3
  19. package/container/dist/providers/auxiliary.js.map +1 -1
  20. package/container/dist/providers/hybridai.js +44 -1
  21. package/container/dist/providers/hybridai.js.map +1 -1
  22. package/container/dist/types.js.map +1 -1
  23. package/container/npm-shrinkwrap.json +2 -2
  24. package/container/package-lock.json +2 -2
  25. package/container/package.json +1 -1
  26. package/container/shared/message-tool-channels.d.ts +1 -0
  27. package/container/shared/message-tool-channels.js +2 -0
  28. package/container/src/index.ts +6 -0
  29. package/container/src/providers/anthropic.ts +134 -23
  30. package/container/src/providers/auxiliary.ts +1 -4
  31. package/container/src/providers/hybridai.ts +58 -2
  32. package/container/src/types.ts +8 -0
  33. package/dist/a2a/a2a-inbound.d.ts.map +1 -1
  34. package/dist/a2a/a2a-inbound.js +23 -27
  35. package/dist/a2a/a2a-inbound.js.map +1 -1
  36. package/dist/a2a/a2a-inbox-dispatch-store.d.ts +47 -0
  37. package/dist/a2a/a2a-inbox-dispatch-store.d.ts.map +1 -0
  38. package/dist/a2a/a2a-inbox-dispatch-store.js +175 -0
  39. package/dist/a2a/a2a-inbox-dispatch-store.js.map +1 -0
  40. package/dist/a2a/a2a-inbox-dispatcher.d.ts +49 -0
  41. package/dist/a2a/a2a-inbox-dispatcher.d.ts.map +1 -0
  42. package/dist/a2a/a2a-inbox-dispatcher.js +456 -0
  43. package/dist/a2a/a2a-inbox-dispatcher.js.map +1 -0
  44. package/dist/a2a/a2a-outbox-persistence.d.ts +16 -0
  45. package/dist/a2a/a2a-outbox-persistence.d.ts.map +1 -1
  46. package/dist/a2a/a2a-outbox-persistence.js +25 -0
  47. package/dist/a2a/a2a-outbox-persistence.js.map +1 -1
  48. package/dist/a2a/identity-resolver.d.ts.map +1 -1
  49. package/dist/a2a/identity-resolver.js +2 -4
  50. package/dist/a2a/identity-resolver.js.map +1 -1
  51. package/dist/a2a/identity.d.ts +2 -0
  52. package/dist/a2a/identity.d.ts.map +1 -1
  53. package/dist/a2a/identity.js +38 -0
  54. package/dist/a2a/identity.js.map +1 -1
  55. package/dist/a2a/runtime.d.ts.map +1 -1
  56. package/dist/a2a/runtime.js +11 -4
  57. package/dist/a2a/runtime.js.map +1 -1
  58. package/dist/a2a/webhook-inbound.d.ts.map +1 -1
  59. package/dist/a2a/webhook-inbound.js +6 -39
  60. package/dist/a2a/webhook-inbound.js.map +1 -1
  61. package/dist/agent/delegation-manager.d.ts +1 -1
  62. package/dist/agent/delegation-manager.d.ts.map +1 -1
  63. package/dist/agent/delegation-manager.js +2 -1
  64. package/dist/agent/delegation-manager.js.map +1 -1
  65. package/dist/agent/prompt-hooks.d.ts.map +1 -1
  66. package/dist/agent/prompt-hooks.js +4 -0
  67. package/dist/agent/prompt-hooks.js.map +1 -1
  68. package/dist/audit/audit-trail.js +2 -2
  69. package/dist/audit/audit-trail.js.map +1 -1
  70. package/dist/channels/channel-registry.d.ts.map +1 -1
  71. package/dist/channels/channel-registry.js +5 -1
  72. package/dist/channels/channel-registry.js.map +1 -1
  73. package/dist/channels/channel.d.ts +3 -2
  74. package/dist/channels/channel.d.ts.map +1 -1
  75. package/dist/channels/channel.js +10 -0
  76. package/dist/channels/channel.js.map +1 -1
  77. package/dist/channels/discord/delivery.d.ts.map +1 -1
  78. package/dist/channels/discord/delivery.js +35 -7
  79. package/dist/channels/discord/delivery.js.map +1 -1
  80. package/dist/channels/discord/inbound.d.ts +1 -0
  81. package/dist/channels/discord/inbound.d.ts.map +1 -1
  82. package/dist/channels/discord/inbound.js +3 -0
  83. package/dist/channels/discord/inbound.js.map +1 -1
  84. package/dist/channels/discord/runtime.d.ts.map +1 -1
  85. package/dist/channels/discord/runtime.js +5 -2
  86. package/dist/channels/discord/runtime.js.map +1 -1
  87. package/dist/channels/discord/stream.d.ts +2 -0
  88. package/dist/channels/discord/stream.d.ts.map +1 -1
  89. package/dist/channels/discord/stream.js +79 -23
  90. package/dist/channels/discord/stream.js.map +1 -1
  91. package/dist/channels/discord-webhook/delivery.d.ts.map +1 -1
  92. package/dist/channels/discord-webhook/delivery.js +2 -1
  93. package/dist/channels/discord-webhook/delivery.js.map +1 -1
  94. package/dist/channels/line/auth.d.ts +23 -0
  95. package/dist/channels/line/auth.d.ts.map +1 -0
  96. package/dist/channels/line/auth.js +127 -0
  97. package/dist/channels/line/auth.js.map +1 -0
  98. package/dist/channels/line/connection.d.ts +14 -0
  99. package/dist/channels/line/connection.d.ts.map +1 -0
  100. package/dist/channels/line/connection.js +190 -0
  101. package/dist/channels/line/connection.js.map +1 -0
  102. package/dist/channels/line/delivery.d.ts +9 -0
  103. package/dist/channels/line/delivery.d.ts.map +1 -0
  104. package/dist/channels/line/delivery.js +30 -0
  105. package/dist/channels/line/delivery.js.map +1 -0
  106. package/dist/channels/line/inbound.d.ts +17 -0
  107. package/dist/channels/line/inbound.d.ts.map +1 -0
  108. package/dist/channels/line/inbound.js +32 -0
  109. package/dist/channels/line/inbound.js.map +1 -0
  110. package/dist/channels/line/pairing-state.d.ts +16 -0
  111. package/dist/channels/line/pairing-state.d.ts.map +1 -0
  112. package/dist/channels/line/pairing-state.js +44 -0
  113. package/dist/channels/line/pairing-state.js.map +1 -0
  114. package/dist/channels/line/prompt-adapter.d.ts +3 -0
  115. package/dist/channels/line/prompt-adapter.d.ts.map +1 -0
  116. package/dist/channels/line/prompt-adapter.js +15 -0
  117. package/dist/channels/line/prompt-adapter.js.map +1 -0
  118. package/dist/channels/line/runtime.d.ts +17 -0
  119. package/dist/channels/line/runtime.d.ts.map +1 -0
  120. package/dist/channels/line/runtime.js +128 -0
  121. package/dist/channels/line/runtime.js.map +1 -0
  122. package/dist/channels/line/target.d.ts +5 -0
  123. package/dist/channels/line/target.d.ts.map +1 -0
  124. package/dist/channels/line/target.js +27 -0
  125. package/dist/channels/line/target.js.map +1 -0
  126. package/dist/channels/message/tool-actions.d.ts.map +1 -1
  127. package/dist/channels/message/tool-actions.js +41 -1
  128. package/dist/channels/message/tool-actions.js.map +1 -1
  129. package/dist/channels/message-tool-advertising.d.ts.map +1 -1
  130. package/dist/channels/message-tool-advertising.js +1 -0
  131. package/dist/channels/message-tool-advertising.js.map +1 -1
  132. package/dist/channels/prompt-adapters.d.ts.map +1 -1
  133. package/dist/channels/prompt-adapters.js +3 -0
  134. package/dist/channels/prompt-adapters.js.map +1 -1
  135. package/dist/channels/slack/runtime.d.ts.map +1 -1
  136. package/dist/channels/slack/runtime.js +45 -0
  137. package/dist/channels/slack/runtime.js.map +1 -1
  138. package/dist/channels/slack-webhook/delivery.d.ts.map +1 -1
  139. package/dist/channels/slack-webhook/delivery.js +2 -1
  140. package/dist/channels/slack-webhook/delivery.js.map +1 -1
  141. package/dist/channels/whatsapp/inbound.d.ts.map +1 -1
  142. package/dist/channels/whatsapp/inbound.js +21 -4
  143. package/dist/channels/whatsapp/inbound.js.map +1 -1
  144. package/dist/cli/auth-command.d.ts.map +1 -1
  145. package/dist/cli/auth-command.js +24 -2
  146. package/dist/cli/auth-command.js.map +1 -1
  147. package/dist/cli/channels-command.d.ts.map +1 -1
  148. package/dist/cli/channels-command.js +42 -2
  149. package/dist/cli/channels-command.js.map +1 -1
  150. package/dist/cli/help.d.ts +2 -0
  151. package/dist/cli/help.d.ts.map +1 -1
  152. package/dist/cli/help.js +42 -0
  153. package/dist/cli/help.js.map +1 -1
  154. package/dist/cli/line-api.d.ts +8 -0
  155. package/dist/cli/line-api.d.ts.map +1 -0
  156. package/dist/cli/line-api.js +8 -0
  157. package/dist/cli/line-api.js.map +1 -0
  158. package/dist/cli/token-command.d.ts +2 -0
  159. package/dist/cli/token-command.d.ts.map +1 -0
  160. package/dist/cli/token-command.js +149 -0
  161. package/dist/cli/token-command.js.map +1 -0
  162. package/dist/cli.d.ts.map +1 -1
  163. package/dist/cli.js +7 -0
  164. package/dist/cli.js.map +1 -1
  165. package/dist/config/config.d.ts +2 -0
  166. package/dist/config/config.d.ts.map +1 -1
  167. package/dist/config/config.js +6 -2
  168. package/dist/config/config.js.map +1 -1
  169. package/dist/config/runtime-config.d.ts +17 -1
  170. package/dist/config/runtime-config.d.ts.map +1 -1
  171. package/dist/config/runtime-config.js +73 -4
  172. package/dist/config/runtime-config.js.map +1 -1
  173. package/dist/gateway/a2a-inbox-dispatch.d.ts +3 -0
  174. package/dist/gateway/a2a-inbox-dispatch.d.ts.map +1 -0
  175. package/dist/gateway/a2a-inbox-dispatch.js +68 -0
  176. package/dist/gateway/a2a-inbox-dispatch.js.map +1 -0
  177. package/dist/gateway/gateway-admin-tokens.d.ts +31 -0
  178. package/dist/gateway/gateway-admin-tokens.d.ts.map +1 -0
  179. package/dist/gateway/gateway-admin-tokens.js +128 -0
  180. package/dist/gateway/gateway-admin-tokens.js.map +1 -0
  181. package/dist/gateway/gateway-chat-service.js +47 -11
  182. package/dist/gateway/gateway-chat-service.js.map +1 -1
  183. package/dist/gateway/gateway-http-server.d.ts.map +1 -1
  184. package/dist/gateway/gateway-http-server.js +1878 -78
  185. package/dist/gateway/gateway-http-server.js.map +1 -1
  186. package/dist/gateway/gateway-service.d.ts +10 -2
  187. package/dist/gateway/gateway-service.d.ts.map +1 -1
  188. package/dist/gateway/gateway-service.js +263 -162
  189. package/dist/gateway/gateway-service.js.map +1 -1
  190. package/dist/gateway/gateway-types.d.ts +22 -0
  191. package/dist/gateway/gateway-types.d.ts.map +1 -1
  192. package/dist/gateway/gateway-types.js.map +1 -1
  193. package/dist/gateway/gateway-url-utils.d.ts +14 -0
  194. package/dist/gateway/gateway-url-utils.d.ts.map +1 -1
  195. package/dist/gateway/gateway-url-utils.js +28 -0
  196. package/dist/gateway/gateway-url-utils.js.map +1 -1
  197. package/dist/gateway/gateway.js +124 -2
  198. package/dist/gateway/gateway.js.map +1 -1
  199. package/dist/gateway/hatching-completion.d.ts +1 -0
  200. package/dist/gateway/hatching-completion.d.ts.map +1 -1
  201. package/dist/gateway/hatching-completion.js +8 -0
  202. package/dist/gateway/hatching-completion.js.map +1 -1
  203. package/dist/gateway/msteams-tab.d.ts +36 -0
  204. package/dist/gateway/msteams-tab.d.ts.map +1 -0
  205. package/dist/gateway/msteams-tab.js +116 -0
  206. package/dist/gateway/msteams-tab.js.map +1 -0
  207. package/dist/gateway/openai-compatible-response.d.ts +3 -1
  208. package/dist/gateway/openai-compatible-response.d.ts.map +1 -1
  209. package/dist/gateway/openai-compatible-response.js +6 -3
  210. package/dist/gateway/openai-compatible-response.js.map +1 -1
  211. package/dist/gateway/openai-compatible.d.ts +1 -0
  212. package/dist/gateway/openai-compatible.d.ts.map +1 -1
  213. package/dist/gateway/openai-compatible.js +74 -1
  214. package/dist/gateway/openai-compatible.js.map +1 -1
  215. package/dist/gateway/proactive-delivery.d.ts.map +1 -1
  216. package/dist/gateway/proactive-delivery.js +3 -0
  217. package/dist/gateway/proactive-delivery.js.map +1 -1
  218. package/dist/memory/apps.d.ts +1 -0
  219. package/dist/memory/apps.d.ts.map +1 -1
  220. package/dist/memory/apps.js +18 -0
  221. package/dist/memory/apps.js.map +1 -1
  222. package/dist/memory/chunk.d.ts.map +1 -1
  223. package/dist/memory/chunk.js +29 -9
  224. package/dist/memory/chunk.js.map +1 -1
  225. package/dist/memory/db.d.ts +44 -1
  226. package/dist/memory/db.d.ts.map +1 -1
  227. package/dist/memory/db.js +194 -2
  228. package/dist/memory/db.js.map +1 -1
  229. package/dist/providers/auxiliary.d.ts.map +1 -1
  230. package/dist/providers/auxiliary.js +1 -3
  231. package/dist/providers/auxiliary.js.map +1 -1
  232. package/dist/providers/model-metadata.d.ts.map +1 -1
  233. package/dist/providers/model-metadata.js +6 -0
  234. package/dist/providers/model-metadata.js.map +1 -1
  235. package/dist/scheduler/scheduler.d.ts.map +1 -1
  236. package/dist/scheduler/scheduler.js +3 -0
  237. package/dist/scheduler/scheduler.js.map +1 -1
  238. package/dist/security/admin-rbac.d.ts +14 -13
  239. package/dist/security/admin-rbac.d.ts.map +1 -1
  240. package/dist/security/admin-rbac.js +77 -0
  241. package/dist/security/admin-rbac.js.map +1 -1
  242. package/dist/security/api-tokens.d.ts +38 -0
  243. package/dist/security/api-tokens.d.ts.map +1 -0
  244. package/dist/security/api-tokens.js +208 -0
  245. package/dist/security/api-tokens.js.map +1 -0
  246. package/dist/security/app-publications.d.ts +64 -0
  247. package/dist/security/app-publications.d.ts.map +1 -0
  248. package/dist/security/app-publications.js +307 -0
  249. package/dist/security/app-publications.js.map +1 -0
  250. package/dist/security/token-verifier.d.ts +3 -0
  251. package/dist/security/token-verifier.d.ts.map +1 -0
  252. package/dist/security/token-verifier.js +49 -0
  253. package/dist/security/token-verifier.js.map +1 -0
  254. package/dist/session/session-context.d.ts.map +1 -1
  255. package/dist/session/session-context.js +1 -0
  256. package/dist/session/session-context.js.map +1 -1
  257. package/dist/session/session-reset.d.ts.map +1 -1
  258. package/dist/session/session-reset.js +3 -0
  259. package/dist/session/session-reset.js.map +1 -1
  260. package/dist/session/token-efficiency.d.ts +2 -0
  261. package/dist/session/token-efficiency.d.ts.map +1 -1
  262. package/dist/session/token-efficiency.js +2 -2
  263. package/dist/session/token-efficiency.js.map +1 -1
  264. package/dist/skills/skill-manifest.d.ts.map +1 -1
  265. package/dist/skills/skill-manifest.js +1 -0
  266. package/dist/skills/skill-manifest.js.map +1 -1
  267. package/dist/tui-skill-config.d.ts +1 -1
  268. package/dist/tui-skill-config.d.ts.map +1 -1
  269. package/dist/tui-skill-config.js +1 -0
  270. package/dist/tui-skill-config.js.map +1 -1
  271. package/dist/update.d.ts.map +1 -1
  272. package/dist/update.js +13 -5
  273. package/dist/update.js.map +1 -1
  274. package/docs/content/README.md +30 -3
  275. package/docs/content/channels/README.md +1 -0
  276. package/docs/content/channels/admin-console.md +8 -0
  277. package/docs/content/channels/line.md +82 -0
  278. package/docs/content/channels/overview.md +3 -0
  279. package/docs/content/developer-guide/admin-access-control.md +7 -0
  280. package/docs/content/getting-started/first-channel.md +3 -0
  281. package/docs/content/guides/README.md +2 -0
  282. package/docs/content/guides/a2a-peer-pairing.md +260 -0
  283. package/docs/content/navigation.json +4 -0
  284. package/docs/content/reference/commands.md +41 -0
  285. package/docs/content/reference/configuration.md +6 -2
  286. package/docs/static/teams-color.png +0 -0
  287. package/docs/static/teams-outline.png +0 -0
  288. package/npm-shrinkwrap.json +164 -6
  289. package/package.json +6 -1
  290. package/console/dist/assets/apps-_oJDy7mi.js +0 -1
  291. package/console/dist/assets/apps-fd_S5yFK.css +0 -1
  292. package/console/dist/assets/chat-DtbW21G6.js +0 -4
  293. package/console/dist/assets/chat-sidebar-ZV6o-A2S.js +0 -5
  294. package/console/dist/assets/index-BIPFwWNZ.css +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,104 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.28.1](https://github.com/HybridAIOne/hybridclaw/tree/v0.28.1) - 2026-07-10
6
+
7
+ ### Added
8
+
9
+ - **LINE personal-account self-chat channel**: Operators can link a personal
10
+ LINE account through an explicitly warned unofficial QR flow and use only
11
+ that account's self-chat for agent turns. Auth tokens, E2EE state, and sync
12
+ cursors persist across restarts; sender/recipient checks, reply-prefix loop
13
+ prevention, process locking, self-only outbound enforcement, CLI setup and
14
+ reset commands, and admin-console QR status keep the transport scoped to the
15
+ linked account.
16
+
17
+ ### Fixed
18
+
19
+ - **Onboarding autostart visibility and retry**: First-run assistant-only
20
+ sessions are preserved while bootstrap autostart is active or awaiting the
21
+ user's reply, and temporary provider failures can retry without consuming a
22
+ hatching turn or hiding the onboarding opener.
23
+ - **Channel delivery size limits**: Long replies now obey the configured hard
24
+ character and line limits across Discord replies, streams, and webhooks plus
25
+ Slack webhooks. The shared chunker safely splits unbroken text and Unicode,
26
+ reserves room for closing code fences, and reopens fenced blocks in the next
27
+ chunk.
28
+ - **Duplicate channel turn dispatch**: Discord ignores metadata-only message
29
+ updates, Slack coalesces twin `message` and `app_mention` events while
30
+ retaining attachments, and WhatsApp resolves alternate phone JIDs for LID
31
+ senders so one inbound message does not start duplicate or misidentified
32
+ turns.
33
+ - **Auxiliary model output caps**: Explicit task-level `maxTokens` values are
34
+ preserved even when model discovery has no provider maximum, preventing
35
+ auxiliary calls from silently losing their requested output limit.
36
+ - **Anthropic thinking traces**: Direct Anthropic and HybridAI-routed Claude
37
+ streams preserve structured thinking content through tool-call continuations
38
+ and expose it to the chat activity trace instead of dropping it between
39
+ turns.
40
+ - **CLI self-update output and footprint**: npm self-updates omit development
41
+ dependencies and suppress non-actionable deprecation, funding, and audit
42
+ noise while continuing to surface installation errors.
43
+
44
+ ## [0.28.0](https://github.com/HybridAIOne/hybridclaw/tree/v0.28.0) - 2026-07-08
45
+
46
+ ### Added
47
+
48
+ - **A2A inbox dispatch and reply-back chat**: Trusted inbound A2A messages now
49
+ persist through the gateway dispatch store, route to the target local agent,
50
+ and send the agent's reply back to the originating instance when reverse
51
+ trust is present. The origin chat renders a compact delivery-status chip while
52
+ the envelope is sent, received, and waiting for the remote reply.
53
+ - **Scoped API tokens**: Operators can create, list, and revoke gateway API
54
+ tokens with explicit action, scope, role, or roles claims from the new
55
+ `hybridclaw token` CLI and `/admin/tokens` console page. Tokens support
56
+ expiry timestamps, one-time reveal, metadata-only listing, route-level RBAC,
57
+ and audit events for creation and revocation.
58
+ - **Delegated OpenAI-compatible job retrieval**: Delegated
59
+ `/v1/chat/completions` requests now expose `hybridclaw.delegation` metadata,
60
+ return `X-HybridClaw-Delegation-Id` for non-streaming acknowledgements, and
61
+ can be polled at `GET /v1/chat/completions/{completion-id}` until the queued
62
+ job completes, fails, or is cancelled.
63
+ - **Published apps and Teams sharing**: Apps can now be published from the Apps
64
+ gallery as scoped sharing links, optional password-protected links, or
65
+ Microsoft Teams tabs. Publications are persisted with revocation, expiry,
66
+ embed-host, and live-data bridge controls, and Teams tabs validate Entra SSO
67
+ viewers before rendering shared app content.
68
+ - **A2A peer-pairing guide**: Public docs now include a browser pairing
69
+ walkthrough and deterministic two-instance curl smoke test for trusted A2A
70
+ chat, reverse trust, and reply delivery.
71
+
72
+ ### Changed
73
+
74
+ - **Admin token roles and presets**: The token surfaces now prefer current
75
+ least-privilege admin role bundles and clearer action grants while preserving
76
+ compatibility role names where needed.
77
+ - **OpenAI-compatible delegated acknowledgements**: Streaming and
78
+ non-streaming delegated completions carry consistent delegation metadata so
79
+ local eval harnesses and compatible clients can correlate queued work with
80
+ later retrieval.
81
+
82
+ ### Fixed
83
+
84
+ - **Config watcher scope and EMFILE resilience**: The runtime-config file
85
+ watcher now starts only in the long-running gateway process instead of in
86
+ every CLI invocation, so one-shot commands such as `hybridclaw gateway
87
+ status` no longer create `fs.watch` handles or interleave
88
+ `[runtime-config] watcher error: EMFILE` retry noise into their output.
89
+ When the gateway's watcher does fail (for example `EMFILE: too many open
90
+ files`), config hot-reload now falls back to descriptor-free stat polling
91
+ instead of going dark after ten failed watcher restarts.
92
+
93
+ `Manifesto: Principle VIII - A coworker doesn't break overnight.`
94
+ - **A2A chat delivery stability**: Remote A2A replies now appear in the origin
95
+ chat, local A2A smoke replies are stable, inbound audience resolution works
96
+ behind public tunnels, and the delivery chip remains coherent across history
97
+ reloads while disappearing after the remote reply is stored.
98
+ - **API token verifier hardening**: Gateway API tokens now use salted scrypt
99
+ verifiers and CodeQL-clean validation paths instead of raw token hashes.
100
+ - **App view token scope**: Console app-view tokens are scoped to the app route
101
+ they authorize, reducing token reuse across unrelated app views.
102
+
5
103
  ## [0.27.2](https://github.com/HybridAIOne/hybridclaw/tree/v0.27.2) - 2026-07-06
6
104
 
7
105
  ### Fixed
package/README.md CHANGED
@@ -59,9 +59,9 @@ HybridClaw on HybridAI Cloud in a few minutes at
59
59
  | --- | --- |
60
60
  | A first run that becomes useful quickly | Guided hatching with setup links, tailored first-job suggestions, optional onboarding-specific model routing, welcome-email handoff, and structured audit events |
61
61
  | Business workflows that survive real use | Production skill helpers with fixtures, eval scenarios, targeted tests, approval tiers, and a `Qwen/Qwen3.6-27B-FP8` validation baseline |
62
- | Generated work artifacts you can reuse | An Apps gallery for self-contained HTML apps, dashboards, documents, games, tools, and live connector-backed views |
63
- | Multi-agent workflows across installations | Local agents, hosted proxy agents, A2A trust, explicit addressing, inbound envelopes, and admin-visible peer pairing |
64
- | Credentials the model cannot read | Encrypted runtime secrets and SecretRef-backed execution paths that keep raw keys and passwords out of prompts and tool results |
62
+ | Generated work artifacts you can reuse | An Apps gallery for self-contained HTML apps, dashboards, documents, games, tools, live connector-backed views, sharing links, and Teams tabs |
63
+ | Multi-agent workflows across installations | Local agents, hosted proxy agents, A2A trust, explicit addressing, inbound envelopes, reply-back delivery, and admin-visible peer pairing |
64
+ | Credentials the model cannot read | Encrypted runtime secrets, SecretRef-backed execution paths, and scoped gateway API tokens that keep raw keys and passwords out of prompts and tool results |
65
65
  | Assistants that can act, not just chat | A gateway, web chat, Apps gallery, TUI, admin console, scheduler, tools, and OpenAI-compatible API behind one local service |
66
66
  | Control over sensitive work | Approval policy, sandbox boundaries, output guardrails, and hash-chained audit trails |
67
67
  | Agents that fit existing teams | Discord, Slack, Teams, Telegram, WhatsApp, email, voice, web, and more through the same runtime |
@@ -104,8 +104,8 @@ After the gateway starts, open:
104
104
  | Surface | URL / command | Use it for |
105
105
  | --- | --- | --- |
106
106
  | Web Chat | `http://127.0.0.1:9090/chat` | Chat, slash commands, model and agent switching |
107
- | Apps Gallery | `http://127.0.0.1:9090/apps` | Generated web apps, documents, games, tools, and live connector-backed views |
108
- | Admin Console | `http://127.0.0.1:9090/admin` | Channels, connectors, agents, approvals, audit, config, secrets, skills, distillation |
107
+ | Apps Gallery | `http://127.0.0.1:9090/apps` | Generated web apps, documents, games, tools, live connector-backed views, and sharing |
108
+ | Admin Console | `http://127.0.0.1:9090/admin` | Channels, connectors, agents, approvals, audit, config, secrets, tokens, skills, distillation |
109
109
  | Agents UI | `http://127.0.0.1:9090/agents` | Agent fleet overview and prompt-file editing |
110
110
  | TUI | `hybridclaw tui` | Terminal chat, approvals, status, resume |
111
111
  | OpenAI-compatible API | `http://127.0.0.1:9090/v1/chat/completions` | Local evals and compatible clients |
@@ -126,11 +126,11 @@ npm run desktop
126
126
  | Area | Built in |
127
127
  | --- | --- |
128
128
  | Skills | 79 bundled skills, production business helpers, eval fixtures, packaged skill lifecycle, and human-distillation workflows |
129
- | Channels | Discord, Slack, Signal, WhatsApp, Telegram, Microsoft Teams, email, iMessage, fax, Twilio voice, web, and incoming webhooks |
129
+ | Channels | Discord, Slack, Signal, WhatsApp, LINE self-chat, Telegram, Microsoft Teams, email, iMessage, fax, Twilio voice, web, and incoming webhooks |
130
130
  | Runtime | Gateway service, TUI client, web chat, Apps gallery, admin console, loopback OpenAI-compatible API, Docker or host execution |
131
- | Governance | Encrypted runtime secrets, SecretRef credential isolation, approval policies, sandbox controls, audit trails with hash-chain integrity |
131
+ | Governance | Encrypted runtime secrets, scoped API tokens, SecretRef credential isolation, approval policies, sandbox controls, audit trails with hash-chain integrity |
132
132
  | Memory | Local memory files, SQLite persistence, semantic recall, session compaction, optional HybridAI cloud memory sync |
133
- | Agents | Guided hatching, per-agent workspaces, models, budgets, prompt files, explicit addressing, proxy agents, A2A trust, peer-instance communication |
133
+ | Agents | Guided hatching, per-agent workspaces, models, budgets, prompt files, explicit addressing, proxy agents, A2A trust, peer-instance communication, reply delivery status |
134
134
  | Extensibility | Packaged business skills, plugins, MCP servers, admin connector flows, SecretRef-backed HTTP tools |
135
135
 
136
136
  ## Product Strengths
@@ -144,7 +144,8 @@ npm run desktop
144
144
  normal default. Its lifecycle is searchable in audit as onboarding events.
145
145
  - **Multi-agent operations**: agents can coordinate across local workspaces,
146
146
  hosted HybridAI proxies, and trusted peer HybridClaw instances with A2A
147
- pairing, explicit addressing, inbound envelopes, and admin-visible trust.
147
+ pairing, explicit addressing, inbound envelopes, reply-back delivery status,
148
+ and admin-visible trust.
148
149
  - **Prompt-level credential isolation**: encrypted secrets and SecretRefs keep
149
150
  credential values out of model context while tools receive only the scoped
150
151
  credential material needed at execution time.
@@ -153,7 +154,8 @@ npm run desktop
153
154
  memory, policy, and audit model.
154
155
  - **Generated apps from chat**: describe an app, dashboard, document, game, or
155
156
  tool in web chat; HybridClaw saves the generated HTML artifact into the Apps
156
- gallery and can refresh live apps through read-only connector calls.
157
+ gallery, refreshes live apps through read-only connector calls, and can share
158
+ apps through expiring links or Microsoft Teams tabs.
157
159
  - **Secure by default**: LLM output is treated as untrusted, risky actions
158
160
  route through approval policy, and every sensitive boundary is visible in
159
161
  audit.
@@ -161,8 +163,9 @@ npm run desktop
161
163
  named OpenAI-compatible endpoints from the same model picker and config
162
164
  surface.
163
165
  - **Operator visibility**: `/admin` covers channels, connectors, approvals,
164
- audit, statistics, output guard, secrets, fleet topology, A2A inbox/trust,
165
- distillation, and browser PDF previews without requiring shell access.
166
+ audit, statistics, output guard, secrets, scoped tokens, fleet topology, A2A
167
+ inbox/trust, distillation, and browser PDF previews without requiring shell
168
+ access.
166
169
  - **Business-ready extension model**: packaged skills, plugins, MCP servers,
167
170
  and SecretRef-backed HTTP tools share the same approval and credential
168
171
  boundaries.
@@ -175,6 +178,7 @@ npm run desktop
175
178
  hybridclaw gateway status
176
179
  hybridclaw tui --resume <sessionId>
177
180
  hybridclaw config get <key>
181
+ hybridclaw token list
178
182
  hybridclaw skill list
179
183
  hybridclaw agent list
180
184
  hybridclaw doctor
@@ -236,7 +240,7 @@ Core pieces:
236
240
  | Build desktop releases | [Desktop Release Builds](https://hybridaione.github.io/hybridclaw/docs/developer-guide/desktop-release) |
237
241
  | Contribute | [CONTRIBUTING.md](./CONTRIBUTING.md), [docs/content/README.md](./docs/content/README.md) |
238
242
 
239
- Latest release: [v0.27.2](https://github.com/HybridAIOne/hybridclaw/releases/tag/v0.27.2).
243
+ Latest release: [v0.28.1](https://github.com/HybridAIOne/hybridclaw/releases/tag/v0.28.1).
240
244
  Release notes: [CHANGELOG.md](./CHANGELOG.md)
241
245
 
242
246
  ## Development
package/SECURITY.md CHANGED
@@ -186,6 +186,17 @@ dependency from `@whiskeysockets/baileys` to `libsignal`; replacing that
186
186
  dependency with a registry-only package should be prioritized before enabling
187
187
  npm's `allow-git` restriction.
188
188
 
189
+ The optional-at-runtime LINE personal-account channel uses version-pinned JSR
190
+ tarballs from `https://npm.jsr.io` because JSR packages are not resolvable from
191
+ the default npm registry when consumers install the published CLI. The direct
192
+ LINEJS package and its two JSR runtime packages are all pinned to immutable
193
+ versioned tarball URLs, recorded with integrity hashes in both lockfiles, and
194
+ the dependency policy accepts only this narrow `npm.jsr.io` URL shape. Apache
195
+ Thrift is overridden to `0.23.0` to exclude the high-severity vulnerable range
196
+ pulled by LINEJS's declared dependency. The signature-audit helper routes only
197
+ the `@jsr` scope to JSR so npm can verify JSR registry signatures while keeping
198
+ all other packages on the npm registry.
199
+
189
200
  Recommended dependency update workflow:
190
201
 
191
202
  ```bash
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": 32,
2
+ "version": 34,
3
3
  "security": {
4
4
  "trustModelAccepted": false,
5
5
  "trustModelAcceptedAt": "",
@@ -84,6 +84,7 @@
84
84
  "threema": [],
85
85
  "voice": [],
86
86
  "whatsapp": [],
87
+ "line": [],
87
88
  "email": []
88
89
  },
89
90
  "speechToText": {
@@ -106,7 +107,8 @@
106
107
  "voice": "This is a live phone call. Produce plain spoken text only.\nKeep each reply short and conversational, usually one or two short sentences.\nAbsolutely no markdown, bullets, numbered lists, headings, code fences, tables, JSON, or decorative formatting.\nDo not narrate internal reasoning, planning, tool usage, or stage directions. Say only what the caller should hear.\nDo not spell punctuation, formatting marks, or raw URLs unless the caller explicitly asks for exact characters.",
107
108
  "whatsapp": "",
108
109
  "email": "",
109
- "imessage": ""
110
+ "imessage": "",
111
+ "line": ""
110
112
  },
111
113
  "adaptiveSkills": {
112
114
  "enabled": false,
@@ -186,6 +188,12 @@
186
188
  "port": 3978,
187
189
  "path": "/api/msteams/messages"
188
190
  },
191
+ "tab": {
192
+ "enabled": false,
193
+ "ssoAppId": "",
194
+ "appIdUri": "",
195
+ "allowFrom": []
196
+ },
189
197
  "groupPolicy": "allowlist",
190
198
  "dmPolicy": "allowlist",
191
199
  "allowFrom": [],
@@ -278,6 +286,10 @@
278
286
  "ackReaction": "👀",
279
287
  "mediaMaxMb": 20
280
288
  },
289
+ "line": {
290
+ "enabled": false,
291
+ "textChunkLimit": 5000
292
+ },
281
293
  "voice": {
282
294
  "enabled": false,
283
295
  "provider": "twilio",
@@ -0,0 +1 @@
1
+ ._scroll_1ygk6_1{flex:auto;min-height:0;overflow-y:auto}._page_1ygk6_7{box-sizing:border-box;flex-direction:column;gap:20px;width:100%;max-width:1100px;margin:0 auto;padding:28px 24px 48px;display:flex}._topbar_1ygk6_18{justify-content:space-between;align-items:center;gap:16px;display:flex}._topbarLeft_1ygk6_25{align-items:center;gap:10px;display:flex}._mobileTrigger_1ygk6_31{flex-shrink:0}._title_1ygk6_35{letter-spacing:-.01em;color:var(--foreground);margin:0;font-size:1.75rem;font-weight:700}._toolbar_1ygk6_43{align-items:center;gap:12px;display:flex}._searchWrap_1ygk6_49{flex:1;align-items:center;display:flex;position:relative}._searchIcon_1ygk6_56{width:18px;height:18px;color:var(--muted-foreground);pointer-events:none;position:absolute;left:14px}._searchInput_1ygk6_65{box-sizing:border-box;border:1px solid var(--border);background:var(--card);width:100%;color:var(--foreground);border-radius:12px;padding:12px 14px 12px 42px;font-size:.9375rem}._searchInput_1ygk6_65:focus{border-color:var(--ring);box-shadow:var(--shadow-focus);outline:none}._filterTrigger_1ygk6_82{border:1px solid var(--border);background:var(--card);color:var(--foreground);white-space:nowrap;border-radius:12px;align-items:center;gap:8px;padding:10px 14px;font-size:.875rem;display:inline-flex}._filterTrigger_1ygk6_82 svg{width:16px;height:16px;color:var(--muted-foreground)}._newAppTrigger_1ygk6_101{border-radius:var(--radius-sm,10px);background:var(--foreground);color:var(--background);white-space:nowrap;border:none;align-items:center;gap:6px;padding:9px 14px;font-size:.875rem;font-weight:500;display:inline-flex}._newAppTrigger_1ygk6_101 svg{width:15px;height:15px}._newAppItem_1ygk6_120{text-align:left;flex-direction:column;gap:2px;display:flex}._newAppItemTitle_1ygk6_127{color:var(--foreground);font-size:.875rem;font-weight:600}._newAppItemHint_1ygk6_133{color:var(--muted-foreground);font-size:.75rem}._grid_1ygk6_138{grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:16px;margin:0;padding:0;list-style:none;display:grid}._card_1ygk6_147{border:1px solid var(--border);background:var(--card);height:100%;box-shadow:var(--shadow-card);border-radius:14px;transition:border-color .12s;display:flex;position:relative}._card_1ygk6_147:hover{border-color:var(--border-strong)}._cardMain_1ygk6_162{text-align:left;cursor:pointer;color:inherit;background:0 0;border:none;border-radius:14px;flex-direction:column;flex:1;gap:12px;padding:18px;display:flex}._cardTop_1ygk6_176{justify-content:space-between;align-items:center;gap:8px;display:flex}._cardGlyph_1ygk6_183{background:var(--muted);width:38px;height:38px;color:var(--foreground);border-radius:10px;justify-content:center;align-items:center;display:inline-flex}._kindBadge_1ygk6_194,._kindBadgeLive_1ygk6_195{border:1px solid var(--border);color:var(--muted-foreground);background:var(--muted);text-transform:uppercase;letter-spacing:.03em;border-radius:999px;padding:2px 8px;font-size:.6875rem;font-weight:600}._kindBadgeLive_1ygk6_195{color:var(--accent-foreground,var(--foreground));background:var(--accent-soft,var(--accent));border-color:var(--accent,var(--border-strong))}._cardActions_1ygk6_213{opacity:0;gap:4px;transition:opacity .12s;display:flex;position:absolute;top:10px;right:10px}._card_1ygk6_147:hover ._cardActions_1ygk6_213,._cardActions_1ygk6_213:focus-within{opacity:1}._cardAction_1ygk6_213{background:var(--card);width:30px;height:30px;color:var(--muted-foreground);cursor:pointer;border:none;border-radius:8px;justify-content:center;align-items:center;display:inline-flex}._cardAction_1ygk6_213:hover{background:var(--nav-hover);color:var(--foreground)}._cardActionIcon_1ygk6_246{width:16px;height:16px}._inlineIcon_1ygk6_251{vertical-align:-2px;width:15px;height:15px}._cardGlyph_1ygk6_183 svg{width:22px;height:22px}._cardBody_1ygk6_262{flex-direction:column;flex:1;gap:6px;display:flex}._cardTitle_1ygk6_269{color:var(--foreground);font-size:1rem;font-weight:650;line-height:1.3}._cardDesc_1ygk6_276{color:var(--muted-foreground);-webkit-line-clamp:3;line-clamp:3;-webkit-box-orient:vertical;font-size:.8125rem;line-height:1.45;display:-webkit-box;overflow:hidden}._cardMeta_1ygk6_287{color:var(--muted-foreground);flex-wrap:wrap;align-items:center;gap:6px;font-size:.75rem;display:flex}._cardCategory_1ygk6_296{color:var(--foreground);font-weight:600}._cardDot_1ygk6_301{opacity:.5}._cardDelete_1ygk6_305{width:30px;height:30px;color:var(--muted-foreground);cursor:pointer;opacity:0;background:0 0;border:none;border-radius:8px;justify-content:center;align-items:center;transition:opacity .12s;display:inline-flex;position:absolute;top:10px;right:10px}._card_1ygk6_147:hover ._cardDelete_1ygk6_305,._cardDelete_1ygk6_305:focus-visible{opacity:1}._cardDelete_1ygk6_305:hover{background:var(--danger-soft);color:var(--danger)}._cardDeleteIcon_1ygk6_333{width:16px;height:16px}._buildingBanner_1ygk6_338{border:1px solid var(--border);background:var(--accent-soft,var(--card));color:var(--foreground);border-radius:12px;align-items:center;gap:10px;padding:12px 16px;font-size:.875rem;display:flex}._buildingSpinner_1ygk6_350{border:2px solid var(--border-strong);border-top-color:var(--primary);border-radius:50%;flex-shrink:0;width:16px;height:16px;animation:.7s linear infinite _appsSpin_1ygk6_1}@keyframes _appsSpin_1ygk6_1{to{transform:rotate(360deg)}}._empty_1ygk6_367{text-align:center;border:1px dashed var(--border);background:var(--card);border-radius:16px;flex-direction:column;align-items:center;gap:12px;padding:64px 24px;display:flex}._emptyGlyph_1ygk6_379{background:var(--muted);width:48px;height:48px;color:var(--muted-foreground);border-radius:12px;justify-content:center;align-items:center;display:inline-flex}._emptyGlyph_1ygk6_379 svg{width:26px;height:26px}._emptyTitle_1ygk6_395{color:var(--foreground);margin:0;font-size:1.125rem;font-weight:650}._emptyText_1ygk6_402{max-width:420px;color:var(--muted-foreground);margin:0 0 8px;font-size:.9375rem}._newDialog_1ygk6_410{width:min(720px,94vw);max-width:min(720px,94vw)}._categoryGrid_1ygk6_415{grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px;margin-top:8px;display:grid}._categoryTile_1ygk6_422{border:1px solid var(--border);background:var(--card);cursor:pointer;text-align:left;border-radius:12px;flex-direction:column;gap:8px;min-height:110px;padding:16px;transition:border-color .12s,background .12s;display:flex}._categoryTile_1ygk6_422:hover{border-color:var(--border-strong);background:var(--nav-hover)}._categoryGlyph_1ygk6_443{background:var(--muted);width:40px;height:40px;color:var(--foreground);border-radius:10px;justify-content:center;align-items:center;display:inline-flex}._categoryGlyph_1ygk6_443 svg{width:23px;height:23px}._dialogTitleIcon_1ygk6_459{vertical-align:-5px;width:22px;height:22px;color:var(--foreground);justify-content:center;align-items:center;margin-right:8px;display:inline-flex}._dialogTitleIcon_1ygk6_459 svg{width:20px;height:20px}._examples_1ygk6_475{flex-direction:column;gap:8px;margin-top:12px;display:flex}._examplesLabel_1ygk6_482{text-transform:uppercase;letter-spacing:.04em;color:var(--muted-foreground);font-size:.75rem;font-weight:600}._exampleChips_1ygk6_490{flex-wrap:wrap;gap:8px;display:flex}._exampleChip_1ygk6_490{border:1px solid var(--border);background:var(--card);color:var(--foreground);cursor:pointer;border-radius:999px;padding:6px 12px;font-size:.8125rem;transition:border-color .12s,background .12s}._exampleChip_1ygk6_490:hover{border-color:var(--border-strong);background:var(--nav-hover)}._exampleChip_1ygk6_490:disabled{opacity:.5;cursor:not-allowed}._categoryLabel_1ygk6_519{color:var(--foreground);font-size:.9375rem;font-weight:650}._categoryHint_1ygk6_525{color:var(--muted-foreground);font-size:.75rem;line-height:1.4}._promptInput_1ygk6_531{box-sizing:border-box;border:1px solid var(--border);background:var(--input,var(--card));width:100%;color:var(--foreground);resize:vertical;border-radius:12px;min-height:120px;margin-top:8px;padding:12px 14px;font-family:inherit;font-size:.9375rem}._promptInput_1ygk6_531:focus{border-color:var(--ring);box-shadow:var(--shadow-focus);outline:none}._secondaryButton_1ygk6_552{border:1px solid var(--border);background:var(--card);color:var(--foreground);cursor:pointer;border-radius:10px;justify-content:center;align-items:center;gap:6px;padding:8px 14px;font-size:.875rem;text-decoration:none;display:inline-flex}._secondaryButton_1ygk6_552:hover{border-color:var(--border-strong);background:var(--nav-hover)}._secondaryButton_1ygk6_552:disabled{opacity:.5;cursor:not-allowed}._shareDialog_1ygk6_578{width:min(560px,94vw);max-width:min(560px,94vw)}._shareModes_1ygk6_583,._exposureActions_1ygk6_584{flex-wrap:wrap;gap:8px;display:flex}._shareMode_1ygk6_583,._shareModeActive_1ygk6_591{border:1px solid var(--border);background:var(--card);min-height:36px;color:var(--foreground);cursor:pointer;border-radius:8px;justify-content:center;align-items:center;padding:8px 12px;font-size:.875rem;display:inline-flex}._shareModeActive_1ygk6_591{border-color:var(--foreground);background:var(--foreground);color:var(--background)}._shareField_1ygk6_611{color:var(--foreground);flex-direction:column;gap:6px;font-size:.8125rem;font-weight:600;display:flex}._shareField_1ygk6_611 input,._shareResult_1ygk6_621 input,._shareTextarea_1ygk6_622{box-sizing:border-box;border:1px solid var(--border);background:var(--input,var(--card));width:100%;color:var(--foreground);font:inherit;border-radius:8px;padding:10px 12px}._shareTextarea_1ygk6_622{resize:vertical;min-height:74px}._exposureBox_1ygk6_638{border:1px solid var(--border);background:var(--muted);border-radius:8px;flex-direction:column;gap:10px;padding:12px;display:flex}._exposureBox_1ygk6_638 p{color:var(--muted-foreground);margin:0;font-size:.875rem;line-height:1.45}._teamsSetupNotice_1ygk6_655{border:1px solid var(--border);background:var(--muted);border-radius:8px;gap:8px;padding:12px;font-size:.875rem;display:grid}._teamsSetupNotice_1ygk6_655 strong{color:var(--foreground)}._teamsSetupNotice_1ygk6_655 p{color:var(--muted-foreground);margin:0;line-height:1.45}._teamsSetupNoticeFooter_1ygk6_675{color:var(--muted-foreground);flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px 12px;font-size:.8125rem;display:flex}._teamsSetupNoticeFooter_1ygk6_675 a{color:var(--foreground);text-underline-offset:3px;font-weight:700;text-decoration:underline}._shareResult_1ygk6_621{align-items:center;gap:8px;display:flex}._advancedShare_1ygk6_698{color:var(--muted-foreground);padding-top:2px;font-size:.875rem}._advancedShare_1ygk6_698 summary{cursor:pointer;margin-bottom:8px}._advancedSharePanel_1ygk6_709{flex-direction:column;gap:12px;display:flex}._advancedShareGrid_1ygk6_715{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;display:grid}._publicationList_1ygk6_721{flex-direction:column;gap:8px;padding-top:4px;display:flex}._publicationListTitle_1ygk6_728{text-transform:uppercase;letter-spacing:.04em;color:var(--muted-foreground);font-size:.75rem;font-weight:700}._publicationRow_1ygk6_736{border-top:1px solid var(--border);justify-content:space-between;align-items:center;gap:10px;padding:8px 0;font-size:.875rem;display:flex}._viewerDialog_1ygk6_747{flex-direction:column;width:min(1100px,95vw);max-width:min(1100px,95vw);height:86vh;padding:0;display:flex;overflow:hidden}._viewerHeader_1ygk6_757{z-index:2;border-bottom:1px solid var(--border);background:var(--panel-bg);justify-content:space-between;align-items:center;gap:16px;padding:14px 16px;display:flex;position:relative}._viewerTitle_1ygk6_769{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:1rem;font-weight:650;overflow:hidden}._viewerActions_1ygk6_778{z-index:3;flex-shrink:0;align-items:center;gap:8px;display:flex;position:relative}._viewerFrame_1ygk6_787{z-index:1;background:#fff;border:none;flex:1;width:100%;min-height:0;position:relative}@media (width<=640px){._toolbar_1ygk6_43,._shareResult_1ygk6_621,._publicationRow_1ygk6_736{flex-direction:column;align-items:stretch}._advancedShareGrid_1ygk6_715{grid-template-columns:1fr}}
@@ -0,0 +1 @@
1
+ import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,a as n,n as r,o as i,r as a}from"./query-o_Dd9s85.js";import{l as o}from"./router-DoNPHesn.js";import{D as s,H as c,J as l,L as u,O as d,T as f,X as p,Y as m,at as h,bt as g,ct as _,dt as v,et as y,gt as b,ht as x,it as S,j as C,k as w,mt as T,nt as E,ot as D,pt as O,q as k,r as A,rt as j,tt as M,wt as N}from"./index-CXajfe7-.js";import{A as P,C as F,D as ee,E as I,O as L,S as R,T as te,_ as z,i as B,k as V,m as H,n as U,r as W,t as G,v as K,w as q,x as J,y as ne}from"./chat-sidebar-CRmaDdTt.js";var Y=e(t(),1),X={scroll:`_scroll_1ygk6_1`,page:`_page_1ygk6_7`,topbar:`_topbar_1ygk6_18`,topbarLeft:`_topbarLeft_1ygk6_25`,mobileTrigger:`_mobileTrigger_1ygk6_31`,title:`_title_1ygk6_35`,toolbar:`_toolbar_1ygk6_43`,searchWrap:`_searchWrap_1ygk6_49`,searchIcon:`_searchIcon_1ygk6_56`,searchInput:`_searchInput_1ygk6_65`,filterTrigger:`_filterTrigger_1ygk6_82`,newAppTrigger:`_newAppTrigger_1ygk6_101`,newAppItem:`_newAppItem_1ygk6_120`,newAppItemTitle:`_newAppItemTitle_1ygk6_127`,newAppItemHint:`_newAppItemHint_1ygk6_133`,grid:`_grid_1ygk6_138`,card:`_card_1ygk6_147`,cardMain:`_cardMain_1ygk6_162`,cardTop:`_cardTop_1ygk6_176`,cardGlyph:`_cardGlyph_1ygk6_183`,kindBadge:`_kindBadge_1ygk6_194`,kindBadgeLive:`_kindBadgeLive_1ygk6_195`,cardActions:`_cardActions_1ygk6_213`,cardAction:`_cardAction_1ygk6_213`,cardActionIcon:`_cardActionIcon_1ygk6_246`,inlineIcon:`_inlineIcon_1ygk6_251`,cardBody:`_cardBody_1ygk6_262`,cardTitle:`_cardTitle_1ygk6_269`,cardDesc:`_cardDesc_1ygk6_276`,cardMeta:`_cardMeta_1ygk6_287`,cardCategory:`_cardCategory_1ygk6_296`,cardDot:`_cardDot_1ygk6_301`,cardDelete:`_cardDelete_1ygk6_305`,cardDeleteIcon:`_cardDeleteIcon_1ygk6_333`,buildingBanner:`_buildingBanner_1ygk6_338`,buildingSpinner:`_buildingSpinner_1ygk6_350`,appsSpin:`_appsSpin_1ygk6_1`,empty:`_empty_1ygk6_367`,emptyGlyph:`_emptyGlyph_1ygk6_379`,emptyTitle:`_emptyTitle_1ygk6_395`,emptyText:`_emptyText_1ygk6_402`,newDialog:`_newDialog_1ygk6_410`,categoryGrid:`_categoryGrid_1ygk6_415`,categoryTile:`_categoryTile_1ygk6_422`,categoryGlyph:`_categoryGlyph_1ygk6_443`,dialogTitleIcon:`_dialogTitleIcon_1ygk6_459`,examples:`_examples_1ygk6_475`,examplesLabel:`_examplesLabel_1ygk6_482`,exampleChips:`_exampleChips_1ygk6_490`,exampleChip:`_exampleChip_1ygk6_490`,categoryLabel:`_categoryLabel_1ygk6_519`,categoryHint:`_categoryHint_1ygk6_525`,promptInput:`_promptInput_1ygk6_531`,secondaryButton:`_secondaryButton_1ygk6_552`,shareDialog:`_shareDialog_1ygk6_578`,shareModes:`_shareModes_1ygk6_583`,exposureActions:`_exposureActions_1ygk6_584`,shareMode:`_shareMode_1ygk6_583`,shareModeActive:`_shareModeActive_1ygk6_591`,shareField:`_shareField_1ygk6_611`,shareResult:`_shareResult_1ygk6_621`,shareTextarea:`_shareTextarea_1ygk6_622`,exposureBox:`_exposureBox_1ygk6_638`,teamsSetupNotice:`_teamsSetupNotice_1ygk6_655`,teamsSetupNoticeFooter:`_teamsSetupNoticeFooter_1ygk6_675`,advancedShare:`_advancedShare_1ygk6_698`,advancedSharePanel:`_advancedSharePanel_1ygk6_709`,advancedShareGrid:`_advancedShareGrid_1ygk6_715`,publicationList:`_publicationList_1ygk6_721`,publicationListTitle:`_publicationListTitle_1ygk6_728`,publicationRow:`_publicationRow_1ygk6_736`,viewerDialog:`_viewerDialog_1ygk6_747`,viewerHeader:`_viewerHeader_1ygk6_757`,viewerTitle:`_viewerTitle_1ygk6_769`,viewerActions:`_viewerActions_1ygk6_778`,viewerFrame:`_viewerFrame_1ygk6_787`},Z=i();function re(){let e=b(),t=s(),i=o(),c=n(),l=(0,Y.useRef)(f()).current,[u,p]=(0,Y.useState)(``),[m,_]=(0,Y.useState)(`user`),[v,w]=(0,Y.useState)(null),T=u.trim(),O=a({queryKey:[`apps-chat-recent`,e.token,l,T,m],queryFn:()=>H(e.token,l,`web`,T?B.maxSearchResults:B.maxRecentSessions,T||void 0,m),staleTime:1e4,enabled:x(e)}),k=r({mutationFn:t=>g(e.token,t),onSuccess:async()=>{w(null),await c.invalidateQueries({queryKey:[`apps-chat-recent`]}),t.success(`Conversation deleted.`)},onError:e=>{t.error(`Delete failed: ${C(e)}`)}});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(G,{sessions:O.data?.sessions??[],activeSessionId:``,onNewChat:()=>i({to:`/chat`}),onOpenSession:e=>i({to:`/chat/$sessionId`,params:{sessionId:e}}),onRequestDeleteSession:e=>w(e),deleteDisabled:k.isPending,searchQuery:u,onSearchQueryChange:p,recentScope:m,onRecentScopeChange:_,isLoading:O.isFetching,onRefreshRecent:()=>{O.refetch()}}),(0,Z.jsx)(y,{open:v!==null,onOpenChange:e=>{e||w(null)},children:(0,Z.jsxs)(E,{size:`sm`,role:`alertdialog`,children:[(0,Z.jsxs)(h,{children:[(0,Z.jsx)(D,{children:`Delete conversation?`}),(0,Z.jsxs)(j,{children:[`“`,v?.title||`Untitled`,`” will be permanently removed.`]})]}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(M,{children:`Cancel`}),(0,Z.jsx)(d,{variant:`danger`,disabled:k.isPending,onClick:()=>v&&k.mutate(v.sessionId),children:k.isPending?`Deleting…`:`Delete`})]})]})})]})}var Q=[{slug:`apps`,label:`Apps & websites`,hint:`Internal tools, portals, landing pages`,seedNoun:`web app or website`,examples:[`A client onboarding portal with step-by-step progress`,`A SaaS pricing page with a monthly/annual toggle`,`An internal team directory with search`]},{slug:`documents`,label:`Documents & templates`,hint:`Proposals, reports, printable templates`,seedNoun:`document or template`,examples:[`A consulting invoice with line items and totals`,`A quarterly business review one-pager`,`A statement-of-work proposal template`]},{slug:`games`,label:`Games`,hint:`Playable browser games`,seedNoun:`browser game`,examples:[`A product-knowledge quiz game for new hires`,`A typing-speed trainer`,`A memory match game`]},{slug:`productivity`,label:`Productivity tools`,hint:`Calculators, trackers, dashboards`,seedNoun:`productivity tool`,examples:[`A SaaS MRR and churn dashboard`,`A meeting-cost calculator`,`A project ROI calculator`]},{slug:`creative`,label:`Creative projects`,hint:`Brand assets, mockups, visuals`,seedNoun:`creative project`,examples:[`A branded social media post mockup`,`A pitch-deck cover slide`,`A simple drawing canvas`]},{slug:`quiz`,label:`Quiz or survey`,hint:`Lead capture, feedback, assessments`,seedNoun:`quiz or survey`,examples:[`A lead-qualification survey with scoring`,`An employee eNPS survey`,`A customer CSAT form`]},{slug:`scratch`,label:`Start from scratch`,hint:`Describe anything you can imagine`,seedNoun:null,examples:[]}],ie=new Map(Q.map(e=>[e.slug,e]));function ae(e){return ie.get(e)?.label??`App`}function oe(){let{token:e}=b(),t=s(),i=o(),f=n(),[g,_]=(0,Y.useState)(``),[v,x]=(0,Y.useState)(`all`),[w,N]=(0,Y.useState)(null),[P,F]=(0,Y.useState)(null),[ee,R]=(0,Y.useState)(``),[te,B]=(0,Y.useState)(0),[V,H]=(0,Y.useState)(null),[U,W]=(0,Y.useState)(null),G=(0,Y.useRef)(null),J=a({queryKey:[`apps`,e],queryFn:()=>L(e),retry:!1});function oe(e,t){let n=ie.get(e)?.seedNoun??null;N(null),i({to:`/chat`,search:{prompt:K(n,t),send:`1`,app:`1`,kind:`web`,...e===`scratch`?{}:{category:e}}})}function ue(e){N(null),i({to:`/chat`,search:{prompt:ne(e),send:`1`,app:`1`,kind:`live`}})}async function $(t){let[n,r]=await Promise.all([I(e,t),z(e,t)]);return R(r),F(n.app),n.app}async function fe(e){if(e.kind!==`live`){t.error(`Only live apps can refresh connector data.`);return}if(!(P?.id===e.id&&G.current?.refreshData()))try{await $(e.id),B(e=>e+1)}catch(e){t.error(`Could not refresh app: ${C(e)}`)}}let me=r({mutationFn:t=>q(e,t),onSuccess:async(e,n)=>{await f.invalidateQueries({queryKey:[`apps`]}),P?.id===n&&(F(null),R(``)),H(null),t.success(`App deleted.`)},onError:e=>{t.error(`Delete failed: ${C(e)}`)}}),he=J.data?.apps??[],ge=(0,Y.useMemo)(()=>{let e=g.trim().toLowerCase();return he.filter(t=>v!==`all`&&t.category!==v?!1:e?t.title.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e):!0)},[he,g,v]);async function _e(e){try{await $(e.id)}catch(e){t.error(`Could not open app: ${C(e)}`)}}function ve(){F(null),R(``)}let ye=v===`all`?`All`:ae(v);return(0,Z.jsxs)(c,{children:[(0,Z.jsxs)(`div`,{className:A.chatPage,children:[(0,Z.jsx)(re,{}),(0,Z.jsx)(`div`,{className:A.chatMain,children:(0,Z.jsx)(`div`,{className:X.scroll,children:(0,Z.jsxs)(`div`,{className:X.page,children:[(0,Z.jsxs)(`header`,{className:X.topbar,children:[(0,Z.jsxs)(`div`,{className:X.topbarLeft,children:[(0,Z.jsx)(u,{className:X.mobileTrigger}),(0,Z.jsx)(`h1`,{className:X.title,children:`Apps`})]}),(0,Z.jsxs)(k,{children:[(0,Z.jsxs)(p,{className:X.newAppTrigger,children:[`+ New app`,(0,Z.jsx)(T,{"aria-hidden":`true`})]}),(0,Z.jsxs)(l,{align:`end`,children:[(0,Z.jsx)(m,{onSelect:()=>N(`web`),children:(0,Z.jsxs)(`span`,{className:X.newAppItem,children:[(0,Z.jsx)(`span`,{className:X.newAppItemTitle,children:`Web app`}),(0,Z.jsx)(`span`,{className:X.newAppItemHint,children:`Self-contained app, document, game, or tool`})]})}),(0,Z.jsx)(m,{onSelect:()=>N(`live`),children:(0,Z.jsxs)(`span`,{className:X.newAppItem,children:[(0,Z.jsx)(`span`,{className:X.newAppItemTitle,children:`Live app`}),(0,Z.jsx)(`span`,{className:X.newAppItemHint,children:`Uses your connectors and can be refreshed`})]})})]})]})]}),(0,Z.jsxs)(`div`,{className:X.toolbar,children:[(0,Z.jsxs)(`div`,{className:X.searchWrap,children:[(0,Z.jsx)(O,{className:X.searchIcon,"aria-hidden":`true`}),(0,Z.jsx)(`input`,{type:`search`,className:X.searchInput,placeholder:`Search apps…`,value:g,onChange:e=>_(e.target.value),"aria-label":`Search apps`})]}),(0,Z.jsxs)(k,{children:[(0,Z.jsxs)(p,{className:X.filterTrigger,children:[(0,Z.jsxs)(`span`,{children:[`Filter: `,(0,Z.jsx)(`strong`,{children:ye})]}),(0,Z.jsx)(T,{"aria-hidden":`true`})]}),(0,Z.jsxs)(l,{align:`end`,children:[(0,Z.jsx)(m,{active:v===`all`,onSelect:()=>x(`all`),children:`All`}),Q.map(e=>(0,Z.jsx)(m,{active:v===e.slug,onSelect:()=>x(e.slug),children:e.label},e.slug))]})]})]}),J.isPending?(0,Z.jsx)(`div`,{className:`empty-state`,children:`Loading apps…`}):J.isError?(0,Z.jsxs)(`div`,{className:`empty-state`,children:[`Failed to load apps: `,C(J.error)]}):ge.length===0?(0,Z.jsx)(se,{hasApps:he.length>0,onCreate:()=>N(`web`)}):(0,Z.jsx)(`ul`,{className:X.grid,children:ge.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(ce,{app:e,onOpen:()=>_e(e),onShare:()=>W(e),onDelete:()=>H(e),onRefresh:()=>fe(e)})},e.id))})]})})})]}),(0,Z.jsx)(le,{kind:w,onClose:()=>N(null),onStartWeb:oe,onStartLive:ue}),(0,Z.jsx)(pe,{app:P,token:ee,onClose:ve,frameRef:G,refreshNonce:te,onRefresh:P?()=>fe(P):void 0,onShare:P?()=>W(P):void 0}),(0,Z.jsx)(de,{app:U,token:e,onClose:()=>W(null),onChanged:async()=>{await f.invalidateQueries({queryKey:[`apps`]}),P&&F((await I(e,P.id)).app)}}),(0,Z.jsx)(y,{open:V!==null,onOpenChange:e=>{e||H(null)},children:(0,Z.jsxs)(E,{size:`sm`,role:`alertdialog`,children:[(0,Z.jsxs)(h,{children:[(0,Z.jsx)(D,{children:`Delete app?`}),(0,Z.jsxs)(j,{children:[`“`,V?.title,`” will be permanently removed from the gallery.`]})]}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(M,{className:X.secondaryButton,children:`Cancel`}),(0,Z.jsx)(d,{variant:`danger`,disabled:me.isPending,onClick:()=>V&&me.mutate(V.id),children:me.isPending?`Deleting…`:`Delete`})]})]})})]})}function se(e){return(0,Z.jsxs)(`div`,{className:X.empty,children:[(0,Z.jsx)(`div`,{className:X.emptyGlyph,"aria-hidden":`true`,children:(0,Z.jsx)(U,{category:`scratch`})}),(0,Z.jsx)(`h2`,{className:X.emptyTitle,children:e.hasApps?`No matching apps`:`No apps yet`}),(0,Z.jsx)(`p`,{className:X.emptyText,children:e.hasApps?`Try a different search or filter.`:`Describe an app, document, tool, or report and HybridClaw builds it for you.`}),e.hasApps?null:(0,Z.jsx)(d,{onClick:e.onCreate,children:`+ New app`})]})}function ce(e){let{app:t}=e,n=t.kind===`live`;return(0,Z.jsxs)(`div`,{className:X.card,children:[(0,Z.jsxs)(`button`,{type:`button`,className:X.cardMain,onClick:e.onOpen,children:[(0,Z.jsxs)(`div`,{className:X.cardTop,children:[(0,Z.jsx)(`div`,{className:X.cardGlyph,"aria-hidden":`true`,children:(0,Z.jsx)(U,{category:t.category})}),(0,Z.jsx)(`span`,{className:n?X.kindBadgeLive:X.kindBadge,title:n?`Connector-aware, refreshable`:void 0,children:n?`Live`:`Web`})]}),(0,Z.jsxs)(`div`,{className:X.cardBody,children:[(0,Z.jsx)(`span`,{className:X.cardTitle,children:t.title}),t.description?(0,Z.jsx)(`span`,{className:X.cardDesc,children:t.description}):null]}),(0,Z.jsxs)(`div`,{className:X.cardMeta,children:[(0,Z.jsx)(`span`,{className:X.cardCategory,children:ae(t.category)}),(0,Z.jsx)(`span`,{className:X.cardDot,children:`·`}),(0,Z.jsx)(`span`,{children:w(t.createdAt)}),(0,Z.jsx)(`span`,{className:X.cardDot,children:`·`}),(0,Z.jsx)(`span`,{children:t.visibility===`public`?`Shared`:`Not shared`})]})]}),(0,Z.jsxs)(`div`,{className:X.cardActions,children:[(0,Z.jsx)(`button`,{type:`button`,className:X.cardAction,"aria-label":`Share ${t.title}`,title:`Share`,onClick:e.onShare,children:(0,Z.jsx)(v,{className:X.cardActionIcon})}),n?(0,Z.jsx)(`button`,{type:`button`,className:X.cardAction,"aria-label":`Refresh ${t.title}`,title:`Refresh with latest data`,onClick:e.onRefresh,children:(0,Z.jsx)(W,{className:X.cardActionIcon})}):null,(0,Z.jsx)(`button`,{type:`button`,className:X.cardAction,"aria-label":`Delete ${t.title}`,title:`Delete`,onClick:e.onDelete,children:(0,Z.jsx)(_,{className:X.cardActionIcon})})]})]})}function le(e){let[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(``),a=e.kind!==null;(0,Y.useEffect)(()=>{a&&(n(null),i(``))},[a,e.kind]);let o=t?ie.get(t):void 0,s=e.kind===`web`&&t===null;return(0,Z.jsx)(y,{open:a,onOpenChange:t=>{t||e.onClose()},children:(0,Z.jsx)(E,{className:X.newDialog,children:s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(h,{children:[(0,Z.jsx)(D,{children:`Create a web app`}),(0,Z.jsx)(j,{children:`Pick a category to get started, or start from scratch with your own idea.`})]}),(0,Z.jsx)(`div`,{className:X.categoryGrid,children:Q.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:X.categoryTile,onClick:()=>n(e.slug),children:[(0,Z.jsx)(`span`,{className:X.categoryGlyph,"aria-hidden":`true`,children:(0,Z.jsx)(U,{category:e.slug})}),(0,Z.jsx)(`span`,{className:X.categoryLabel,children:e.label}),(0,Z.jsx)(`span`,{className:X.categoryHint,children:e.hint})]},e.slug))})]}):e.kind===`live`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(h,{children:[(0,Z.jsx)(D,{children:`Create a live app`}),(0,Z.jsx)(j,{children:`HybridClaw checks your connected tools (MCP), suggests apps that use them, then builds one you can refresh. Add a starting idea (optional).`})]}),(0,Z.jsx)(`textarea`,{className:X.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A dashboard of my upcoming meetings and unread priority emails`,onChange:e=>i(e.target.value),rows:4}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(`button`,{type:`button`,className:X.secondaryButton,onClick:e.onClose,children:`Cancel`}),(0,Z.jsx)(d,{onClick:()=>e.onStartLive(r.trim()),children:`Start building →`})]})]}):t?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(h,{children:[(0,Z.jsxs)(D,{children:[(0,Z.jsx)(`span`,{className:X.dialogTitleIcon,"aria-hidden":`true`,children:(0,Z.jsx)(U,{category:t})}),o?.label]}),(0,Z.jsx)(j,{children:`Add a starting idea (optional). HybridClaw opens a chat, asks a few questions, then builds it for you.`})]}),(0,Z.jsx)(`textarea`,{className:X.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A client onboarding portal that tracks setup steps and shows progress`,onChange:e=>i(e.target.value),rows:4}),o&&o.examples.length>0?(0,Z.jsxs)(`div`,{className:X.examples,children:[(0,Z.jsx)(`span`,{className:X.examplesLabel,children:`Examples`}),(0,Z.jsx)(`div`,{className:X.exampleChips,children:o.examples.map(e=>(0,Z.jsx)(`button`,{type:`button`,className:X.exampleChip,onClick:()=>i(e),children:e},e))})]}):null,(0,Z.jsxs)(S,{children:[(0,Z.jsx)(`button`,{type:`button`,className:X.secondaryButton,onClick:()=>n(null),children:`← Back`}),(0,Z.jsx)(d,{onClick:()=>e.onStartWeb(t,r.trim()),children:`Start building →`})]})]}):null})})}function ue(e){return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}function $(e,t){let n=e.trim();if(!n)return;let r=Number(n);if(!Number.isFinite(r)||r<=0)throw Error(`${t} must be a positive number.`);return r}function de(e){let t=s(),n=e.app,[i,o]=(0,Y.useState)(`link`),[c,l]=(0,Y.useState)(``),[u,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(``),[v,b]=(0,Y.useState)(``),[x,w]=(0,Y.useState)(``),[T,O]=(0,Y.useState)(``),[k,A]=(0,Y.useState)(!1),I=n!==null,L=a({queryKey:[`app-publications`,e.token,n?.id],enabled:I&&!!n,queryFn:()=>ee(e.token,n?.id||``),retry:!1}),R=a({queryKey:[`msteams-tab-status`,e.token],enabled:I&&i===`teams`,queryFn:()=>N(e.token),retry:!1});(0,Y.useEffect)(()=>{I&&(o(`link`),l(``),f(!1),m(``),_(``),b(``),w(``),O(``),A(!1))},[I,n?.id]);let z=r({mutationFn:async()=>{if(!n)throw Error(`No app selected.`);let t=$(v,`Link expiry`),r=$(x,`Session length`);return F(e.token,n.id,{kind:i,...i===`password`?{password:c}:{},embedHosts:ue(p),...i===`company`||i===`teams`?{allowFrom:ue(g)}:{},...r?{ttlSeconds:Math.round(r*60)}:{},...t?{expiresAt:new Date(Date.now()+t*24*60*60*1e3).toISOString()}:{},allowBridge:n.kind===`live`&&u,acknowledgeAnonymousBridge:n.kind===`live`&&u&&(i===`link`||i===`password`)})},onSuccess:async n=>{O(n.url),t.success(i===`teams`?`Teams sharing enabled.`:`Sharing link created.`),await L.refetch(),await e.onChanged()},onError:e=>{t.error(`Share failed: ${C(e)}`)}}),B=r({mutationFn:async()=>{if(!n)throw Error(`No app selected.`);return P(e.token,n.id,{visibility:`private`})},onSuccess:async()=>{O(``),t.success(`Sharing stopped.`),await L.refetch(),await e.onChanged()},onError:e=>{t.error(`Stop sharing failed: ${C(e)}`)}}),H=r({mutationFn:async t=>{if(!n)throw Error(`No app selected.`);return V(e.token,n.id,t.id)},onSuccess:async()=>{t.success(`Sharing link revoked.`),await L.refetch(),await e.onChanged()},onError:e=>{t.error(`Revoke failed: ${C(e)}`)}});async function U(){if(T)try{await navigator.clipboard.writeText(T),t.success(i===`teams`?`Teams link copied.`:`Link copied.`)}catch{t.error(`Could not copy link.`)}}function W(){let e=R.data;if(!e||!n){window.open(T,`_blank`,`noopener,noreferrer`);return}let t=encodeURIComponent(JSON.stringify({subEntityId:n.id,contentUrl:T}));window.open(`https://teams.microsoft.com/l/entity/${encodeURIComponent(e.orgAppId)}/${encodeURIComponent(e.orgAppEntityId)}?context=${t}`,`_blank`,`noopener,noreferrer`)}async function G(){if(!(!n||k)){A(!0);try{let t=await te(e.token,n.id),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=`hybridclaw-${n.id}-teams.zip`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}catch(e){t.error(`Download failed: ${C(e)}`)}finally{A(!1)}}}let K=(L.data?.publications??[]).filter(e=>!e.revokedAt),q=R.data,J=!!(q?.enabled&&q.tenantId&&q.ssoAppId&&q.appIdUri&&q.publicOrigin),ne=!z.isPending&&(i===`link`||i===`company`||i===`teams`||c.trim().length>0);return(0,Z.jsx)(y,{open:I,onOpenChange:t=>{t||e.onClose()},children:(0,Z.jsxs)(E,{className:X.shareDialog,children:[(0,Z.jsxs)(h,{children:[(0,Z.jsxs)(D,{children:[`Share `,n?.title]}),(0,Z.jsx)(j,{children:`Choose who can open this app outside the console.`})]}),(0,Z.jsxs)(`div`,{className:X.shareModes,children:[(0,Z.jsx)(`button`,{type:`button`,className:i===`link`?X.shareModeActive:X.shareMode,onClick:()=>o(`link`),children:`Anyone with the link`}),(0,Z.jsx)(`button`,{type:`button`,className:i===`company`?X.shareModeActive:X.shareMode,onClick:()=>o(`company`),children:`Anyone in my company`}),(0,Z.jsx)(`button`,{type:`button`,className:i===`teams`?X.shareModeActive:X.shareMode,onClick:()=>o(`teams`),children:`Add to Teams`}),(0,Z.jsx)(`button`,{type:`button`,className:i===`password`?X.shareModeActive:X.shareMode,onClick:()=>o(`password`),children:`Password`})]}),i===`teams`?(0,Z.jsxs)(`div`,{className:X.teamsSetupNotice,children:[(0,Z.jsx)(`strong`,{children:`Set up the Teams app in Channels first.`}),(0,Z.jsx)(`p`,{children:`Add to Teams uses the org Teams app. Open Channels, Microsoft Teams, App Setup, finish the Entra SSO setup, and upload the org app package before sharing individual apps here.`}),(0,Z.jsxs)(`div`,{className:X.teamsSetupNoticeFooter,children:[(0,Z.jsx)(`a`,{href:`/admin/channels`,children:`Open Microsoft Teams settings`}),R.isFetching?(0,Z.jsx)(`span`,{children:`Checking Teams setup…`}):R.isError?(0,Z.jsx)(`span`,{children:`Setup status unavailable.`}):q?(0,Z.jsxs)(`span`,{children:[`Teams app setup: `,J?`ready`:`incomplete`]}):null]})]}):null,i===`password`?(0,Z.jsxs)(`label`,{className:X.shareField,children:[(0,Z.jsx)(`span`,{children:`Password`}),(0,Z.jsx)(`input`,{type:`password`,value:c,autoComplete:`new-password`,onChange:e=>l(e.target.value)})]}):null,n?.kind===`live`?(0,Z.jsxs)(`div`,{className:X.exposureBox,children:[(0,Z.jsxs)(`p`,{children:[`This app pulls live data from your connected tools.`,i===`link`||i===`password`?` Anyone with this link would see that data whenever they open it.`:` Shared viewers would see that data whenever they open it.`]}),(0,Z.jsxs)(`div`,{className:X.exposureActions,children:[(0,Z.jsx)(`button`,{type:`button`,className:u?X.shareMode:X.shareModeActive,onClick:()=>f(!1),children:`Share a static snapshot`}),(0,Z.jsx)(`button`,{type:`button`,className:u?X.shareModeActive:X.shareMode,onClick:()=>f(!0),children:`Share live data anyway`})]})]}):null,T?(0,Z.jsxs)(`div`,{className:X.shareResult,children:[(0,Z.jsx)(`input`,{readOnly:!0,value:T,"aria-label":i===`teams`?`Teams link`:`Sharing link`}),i===`teams`?(0,Z.jsx)(d,{onClick:W,children:`Open in Teams`}):(0,Z.jsx)(d,{onClick:U,children:`Copy link`})]}):null,(0,Z.jsxs)(`details`,{className:X.advancedShare,children:[(0,Z.jsx)(`summary`,{children:`More options`}),(0,Z.jsxs)(`div`,{className:X.advancedSharePanel,children:[(0,Z.jsxs)(`label`,{className:X.shareField,children:[(0,Z.jsx)(`span`,{children:`Embed on websites`}),(0,Z.jsx)(`textarea`,{className:X.shareTextarea,value:p,placeholder:`https://dashboard.example.com`,rows:2,onChange:e=>m(e.target.value)})]}),i===`company`||i===`teams`?(0,Z.jsxs)(`label`,{className:X.shareField,children:[(0,Z.jsx)(`span`,{children:`Limit to people`}),(0,Z.jsx)(`textarea`,{className:X.shareTextarea,value:g,placeholder:`person@example.com`,rows:2,onChange:e=>_(e.target.value)})]}):null,(0,Z.jsxs)(`div`,{className:X.advancedShareGrid,children:[(0,Z.jsxs)(`label`,{className:X.shareField,children:[(0,Z.jsx)(`span`,{children:`Link expires after`}),(0,Z.jsx)(`input`,{type:`number`,min:`1`,step:`1`,value:v,placeholder:`Days`,onChange:e=>b(e.target.value)})]}),(0,Z.jsxs)(`label`,{className:X.shareField,children:[(0,Z.jsx)(`span`,{children:`Viewer session length`}),(0,Z.jsx)(`input`,{type:`number`,min:`1`,step:`1`,value:x,placeholder:`Minutes`,onChange:e=>w(e.target.value)})]})]}),i===`teams`?(0,Z.jsx)(`button`,{type:`button`,className:X.secondaryButton,disabled:!n||k,onClick:G,children:k?`Downloading…`:`Download standalone Teams app`}):null]})]}),K.length>0?(0,Z.jsxs)(`div`,{className:X.publicationList,children:[(0,Z.jsx)(`span`,{className:X.publicationListTitle,children:`Shared links`}),K.map(e=>(0,Z.jsxs)(`div`,{className:X.publicationRow,children:[(0,Z.jsx)(`span`,{children:fe(e)}),(0,Z.jsx)(`button`,{type:`button`,className:X.secondaryButton,disabled:H.isPending,onClick:()=>H.mutate(e),children:`Revoke`})]},e.id))]}):null,(0,Z.jsxs)(S,{children:[n?.visibility===`public`||K.length>0?(0,Z.jsx)(`button`,{type:`button`,className:X.secondaryButton,disabled:B.isPending,onClick:()=>B.mutate(),children:B.isPending?`Stopping…`:`Stop sharing`}):null,(0,Z.jsx)(M,{className:X.secondaryButton,children:`Close`}),(0,Z.jsx)(d,{disabled:!ne,onClick:()=>z.mutate(),children:z.isPending?`Creating…`:i===`teams`?`Add to Teams`:`Share`})]})]})})}function fe(e){return e.policy.kind===`password`?`Password-protected link`:e.policy.kind===`oidc`?e.embedHosts.some(e=>e.includes(`teams`))?`In Teams`:`Anyone in my company`:`Anyone with the link`}function pe(e){let{app:t}=e;return(0,Z.jsx)(y,{open:t!==null,onOpenChange:t=>{t||e.onClose()},children:(0,Z.jsxs)(E,{className:X.viewerDialog,"aria-label":`App preview`,children:[(0,Z.jsxs)(`div`,{className:X.viewerHeader,children:[(0,Z.jsx)(D,{className:X.viewerTitle,children:t?.title}),(0,Z.jsxs)(`div`,{className:X.viewerActions,children:[t&&t.kind===`live`&&e.onRefresh?(0,Z.jsxs)(`button`,{type:`button`,className:X.secondaryButton,onClick:t=>{t.stopPropagation(),e.onRefresh?.()},children:[(0,Z.jsx)(W,{className:X.inlineIcon}),` Refresh`]}):null,t&&e.onShare?(0,Z.jsxs)(`button`,{type:`button`,className:X.secondaryButton,onClick:t=>{t.stopPropagation(),e.onShare?.()},children:[(0,Z.jsx)(v,{className:X.inlineIcon}),` Share`]}):null,t&&e.token?(0,Z.jsx)(`a`,{className:X.secondaryButton,href:R(t.id,e.token),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open in new tab ↗`}):null,(0,Z.jsx)(M,{className:X.secondaryButton,onClick:e=>e.stopPropagation(),children:`Close`})]})]}),t&&e.token?(0,Z.jsx)(J,{ref:e.frameRef,appId:t.id,className:X.viewerFrame,refreshNonce:e.refreshNonce,title:t.title,token:e.token}):null]})})}export{oe as AppsPage};
@@ -0,0 +1,4 @@
1
+ import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,a as n,n as r,o as i,r as a}from"./query-o_Dd9s85.js";import{d as o,l as s,u as c}from"./router-DoNPHesn.js";import{$ as l,A as u,C as d,Ct as f,Dt as p,E as m,Et as h,H as g,L as _,Mt as v,N as y,O as b,P as ee,Q as x,S,St as C,T as w,Tt as te,Z as T,_ as E,a as D,at as ne,b as re,bt as ie,c as ae,d as oe,et as O,f as se,ft as k,g as A,gt as j,h as ce,ht as le,i as ue,it as de,j as M,jt as fe,l as pe,lt as me,m as he,n as ge,nt as _e,o as ve,ot as ye,p as N,r as P,rt as be,s as xe,st as F,t as Se,tt as Ce,u as we,ut as Te,w as I,x as Ee,y as De}from"./index-CXajfe7-.js";import{S as Oe,_ as ke,a as Ae,b as je,c as Me,d as Ne,f as Pe,g as Fe,h as Ie,i as Le,l as Re,m as ze,o as Be,p as L,s as Ve,t as He,u as Ue,v as We,x as Ge}from"./chat-sidebar-CRmaDdTt.js";var R=e(t(),1);function Ke(e,t){let[n,r]=(0,R.useState)(e);return(0,R.useEffect)(()=>{let n=window.setTimeout(()=>{r(e)},t);return()=>{window.clearTimeout(n)}},[e,t]),n}var qe=`[A-Za-z0-9._-]+(?:@[A-Za-z0-9._-]+@[A-Za-z0-9._-]+)?`,Je=String.raw`(?=$|[\s:.,!?;)\]}])`;RegExp(`^@(${qe})${Je}`,`u`);var z=RegExp(`@(${qe})${Je}`,`gu`);function Ye(e){let t=[];for(let n of e.matchAll(z)){let r=n[0],i=n[1]??``,a=n.index??0;if(!i)continue;let o=a===0?``:e[a-1];o&&!/[\s([{]/u.test(o)||t.push({mention:r,agentId:i,index:a})}return t}var Xe=new Map;function B(e){return String(e??``).trim().toLowerCase()}function Ze(e){let t=e.trim().split(/\r?\n/).map(e=>e.trim()),n=t[0]?.match(/^(Delivered|Queued for delivery) to `([^`]+)`\.$/);if(!n)return null;let r=t.find(e=>e.startsWith(`Message: `))?.match(/^Message: `([^`]+)`$/),i=t.find(e=>e.startsWith(`Thread: `))?.match(/^Thread: `([^`]+)`$/),a=n[2]?.trim(),o=r?.[1]?.trim(),s=i?.[1]?.trim();return!a||!o||!s?null:{messageId:o,threadId:s,recipientAgentId:a,status:n[1]===`Delivered`?`delivered`:`pending`}}function Qe(e){let t=new Map,n=new Set;return e.forEach((e,r)=>{if(e.a2aDelivery){let n=B(e.a2aDelivery.recipientAgentId);if(!n)return;let i=t.get(n)??[];i.push(r),t.set(n,i);return}if(e.role!==`assistant`)return;let i=B(e.assistantPresentation?.agentId);if(!i)return;let a=t.get(i)?.shift();a!==void 0&&n.add(a)}),n.size===0?e:e.filter((e,t)=>!n.has(t))}function $e(e,t){if(!e||!Array.isArray(e.steps)||e.steps.length===0)return null;let n=[];for(let t of e.steps){if(t.kind===`thinking`){n.push({kind:`thinking`,text:t.text});continue}if(t.kind===`draft`){n.push({kind:`draft`,text:t.text});continue}n.push({kind:`tool`,toolName:t.toolName,status:`done`,...t.argsPreview?{argsPreview:t.argsPreview}:{},...t.resultPreview?{resultPreview:t.resultPreview}:{},...typeof t.durationMs==`number`?{durationMs:t.durationMs}:{}})}return{id:I(),role:`trace`,content:``,sessionId:t,steps:n,done:!0,startedAt:0,...typeof e.elapsedMs==`number`?{finishedAt:e.elapsedMs}:{}}}function V(e,t){let n=e.sessionId??t,r=new Map((e.branchFamilies??[]).map(e=>[`${e.anchorSessionId}:${e.anchorMessageId}`,e.variants])),i=new Map;for(let[e,t]of r.entries()){let r=t.find(e=>e.sessionId===n);r&&i.set(r.messageId,e)}let a=e.history??[],o=B(e.agentId),s=null,c=[];return a.forEach((e,t)=>{let r=a.slice(t+1).find(e=>e.role!==`system`),l=B(r?.agent_id??r?.assistantPresentation?.agentId),u=e.role===`user`&&r?.role===`assistant`&&l&&l!==o?r?.assistantPresentation??null:null;e.role===`user`&&(s=e.content);let d=e.role===`user`?e.content:e.role===`assistant`?s:null,f={id:I(),role:e.role,content:e.content,rawContent:e.content,sessionId:n,messageId:e.id??null,media:[],artifacts:e.artifacts??[],replayRequest:d===null?null:{content:d,media:[]},assistantPresentation:e.assistantPresentation??null,addressedAgentPresentation:u,responseRating:e.response_rating??null,branchKey:e.id!==void 0&&e.id!==null?i.get(e.id)??null:null,a2aDelivery:e.role===`assistant`?Ze(e.content):null};if(e.role===`assistant`){let t=$e(e.activityTrace,n);t&&c.push(t)}c.push(f)}),{messages:Qe(c),branchFamilies:r,requestedSessionId:t,resolvedSessionId:n,agentId:e.agentId?.trim()||null,bootstrapAutostart:e.bootstrapAutostart??null}}function H(e,t){return[`chat-history`,e,t]}async function et(e,t,n,r){return V(await L(e,t,80,n,r),t)}var tt=new Map;function nt(e,t){return`${e}\u0000${t}`}function U(e,t){let n=nt(e,t),r=tt.get(n);return r||(r={objectUrl:null,loading:!1,promise:null,listeners:new Set},tt.set(n,r)),r}function W(e){for(let t of e.listeners)t()}function rt(e,t){let n=t?.trim(),r=e.trim();if(!n)return null;let i=U(r,n);return i.objectUrl?Promise.resolve(i.objectUrl):i.promise?i.promise:(i.loading=!0,i.promise=Re(r,n).then(e=>{let t=URL.createObjectURL(e);return i.objectUrl=t,i.loading=!1,i.promise=null,W(i),t}).catch(()=>(i.objectUrl=null,i.loading=!1,i.promise=null,W(i),null)),W(i),i.promise)}function G(e){let t=e.token.trim(),n=e.imageUrl?.trim()??``,[r,i]=(0,R.useState)(()=>{if(!n)return{objectUrl:null,loading:!1};let e=U(t,n);return{objectUrl:e.objectUrl,loading:e.loading}});return(0,R.useEffect)(()=>{if(!n){i({objectUrl:null,loading:!1});return}let e=U(t,n),r=()=>{i({objectUrl:e.objectUrl,loading:e.loading})};return e.listeners.add(r),r(),rt(t,n),()=>{e.listeners.delete(r)}},[t,n]),r}var K=i();function it(){return(0,K.jsx)(`svg`,{"aria-hidden":`true`,focusable:`false`,viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,K.jsx)(`path`,{d:`m6 9 6 6 6-6`})})}function at(e){let t=e.agents.find(t=>t.id===e.selectedAgentId),n=t?.name?.trim()||t?.id||`Agent`,{localAgents:r,remoteGroups:i}=(0,R.useMemo)(()=>{let t=e.agents.filter(e=>e.source?.type!==`remote`),n=new Map;for(let t of e.agents){if(t.source?.type!==`remote`)continue;let e=t.source.instanceId;n.set(e,[...n.get(e)??[],t])}return{localAgents:t,remoteGroups:[...n.entries()]}},[e.agents]),a=i.length>0;return e.agents.length===0?null:(0,K.jsxs)(ue,{value:e.selectedAgentId,disabled:e.disabled,onValueChange:t=>{if(!t||t===e.selectedAgentId)return;let n=e.agents.find(e=>e.id===t);n&&e.onSwitch(n)},children:[(0,K.jsxs)(se,{className:P.composerPill,"aria-label":`Switch agent`,disabled:e.disabled,children:[(0,K.jsx)(N,{children:n}),(0,K.jsx)(ae,{className:P.composerPillChevron,children:(0,K.jsx)(it,{})})]}),(0,K.jsxs)(D,{className:P.agentSelectPopup,children:[a?(0,K.jsxs)(ve,{children:[(0,K.jsx)(xe,{children:`Local`}),r.map(t=>(0,K.jsx)(ot,{agent:t,token:e.token},t.id))]}):r.map(t=>(0,K.jsx)(ot,{agent:t,token:e.token},t.id)),i.map(([t,n])=>(0,K.jsxs)(ve,{children:[(0,K.jsxs)(xe,{className:P.remoteAgentGroupLabel,children:[(0,K.jsx)(k,{"aria-hidden":`true`,className:P.remoteAgentGroupIcon,width:13,height:13}),(0,K.jsx)(`span`,{children:t})]}),n.map(t=>(0,K.jsx)(ot,{agent:t,token:e.token},t.id))]},t))]})]})}function ot(e){let t=e.agent.name?.trim()||e.agent.id,n=e.agent.source?.type===`remote`;return(0,K.jsxs)(pe,{value:e.agent.id,textValue:t,className:P.agentSelectItem,children:[(0,K.jsx)(st,{agent:e.agent,token:e.token}),n?(0,K.jsxs)(we,{children:[(0,K.jsx)(`span`,{className:P.agentSelectItemText,children:t}),(0,K.jsx)(oe,{children:e.agent.id})]}):(0,K.jsx)(`span`,{className:P.agentSelectItemText,children:t})]})}function st(e){let t=e.agent.imageUrl?.trim(),n=G({token:e.token??``,imageUrl:t});return n.objectUrl?(0,K.jsx)(`img`,{className:P.agentSelectAvatar,src:n.objectUrl,alt:``}):t?(0,K.jsx)(`span`,{className:P.agentSelectAvatarLoading,"aria-hidden":`true`}):null}function ct(e,t){let n=e.lastIndexOf(`
2
+ `,t-1)+1,r=-1;for(let i=n;i<t;i++)e[i]===`/`&&(i===n||/\s/.test(e[i-1]))&&(r=i);return r===-1?null:{query:e.slice(r+1,t),tokenStart:r}}function lt(e,t){return`${e}-opt-${t}`}function ut({mode:e,kind:t=`slash`,suggestions:n,activeIdx:r,query:i,listboxId:a,token:o,onSelect:s,onActiveChange:c}){(0,R.useEffect)(()=>{e!==`list`||n.length===0||document.getElementById(lt(a,r))?.scrollIntoView({block:`nearest`})},[r,e,n.length,a]);let u=i.trim().toLowerCase(),d=t===`agent`?`@`:`/`,f=t===`agent`?`Agents`:`Slash commands`,p=t===`agent`?`No agents match ${d}${i}`:`No commands match ${d}${i}`;return(0,K.jsx)(l,{side:`top`,focusOnOpen:`none`,closeOnEscape:!1,closeOnOutsideClick:!0,sideOffset:4,className:P.slashSuggestions,children:(0,K.jsxs)(he,{className:P.slashSuggestionsScroll,children:[(0,K.jsx)(E,{id:a,role:`listbox`,"aria-label":f,className:P.slashSuggestionsList,children:e===`list`?n.map((e,n)=>(0,K.jsxs)(`div`,{id:lt(a,n),className:F(P.suggestionItem,t===`agent`&&P.suggestionItemAgent,n===r&&P.suggestionItemActive,(e.depth??1)>=2&&P.suggestionItemSub),role:`option`,tabIndex:-1,"aria-selected":n===r,onMouseDown:t=>{t.preventDefault(),s(e)},onMouseEnter:()=>c(n),title:e.description||void 0,children:[t===`agent`?(0,K.jsx)(dt,{item:e,token:o}):null,(0,K.jsxs)(`span`,{className:P.suggestionText,children:[(0,K.jsx)(`span`,{className:P.suggestionLabel,children:q(e.label,u)}),e.description?(0,K.jsx)(`span`,{className:P.suggestionDesc,children:e.description}):null]})]},e.id)):(0,K.jsx)(`div`,{className:P.suggestionEmpty,role:`status`,children:p})}),(0,K.jsx)(ce,{children:(0,K.jsx)(A,{})})]})})}function dt(e){let t=e.item.imageUrl?.trim(),n=G({token:e.token??``,imageUrl:t});return n.objectUrl?(0,K.jsx)(`img`,{className:P.suggestionAvatar,src:n.objectUrl,alt:``}):t?(0,K.jsx)(`span`,{className:P.suggestionAvatarLoading,"aria-hidden":`true`}):null}var ft=/<[^>]+>|\[[^\]]+\]/g;function q(e,t){let n=[],r=0,i=0,a=(e,r)=>{if(!e)return;let a=r?P.suggestionLabelMono:void 0,o=t?e.toLowerCase().indexOf(t):-1;n.push(o===-1?(0,K.jsx)(`span`,{className:a,children:e},i++):(0,K.jsxs)(`span`,{className:a,children:[e.slice(0,o),(0,K.jsx)(`mark`,{className:P.suggestionMatch,children:e.slice(o,o+t.length)}),e.slice(o+t.length)]},i++))};for(let t of e.matchAll(ft)){let n=t.index??0;a(e.slice(r,n),!1),a(t[0],!0),r=n+t[0].length}return a(e.slice(r),!1),n}var pt=RegExp(`(?:^|[\\s([{])@([A-Za-z0-9._-]*(?:@[A-Za-z0-9._-]*){0,2})$`,`u`),mt=RegExp(`@(${qe})(?=$|[\\s:])`,`gu`),ht=RegExp(`^@${qe}(?=$|[\\s:])\\s*`,`u`);function J(e,t){let n=e.slice(0,t),r=pt.exec(n);if(!r)return null;let i=r[1]??``;return{tokenStart:n.length-i.length-1,query:i}}function gt(e){let t=(0,R.useRef)(null),n=(0,R.useRef)(null),r=(0,R.useRef)(null),[i,a]=(0,R.useState)([]),[o,s]=(0,R.useState)(0),[c,l]=(0,R.useState)([]),[d,f]=(0,R.useState)(`slash`),[p,m]=(0,R.useState)(0),[h,g]=(0,R.useState)(`closed`),[_,v]=(0,R.useState)(``),[y,b]=(0,R.useState)(``),[ee,C]=(0,R.useState)(0),w=(0,R.useRef)(null),te=(0,R.useRef)(null),E=(0,R.useRef)(null),D=(0,R.useRef)(0),ne=(0,R.useRef)(null),re=(0,R.useId)(),ie=h!==`closed`,ae=h===`closed`?``:d===`agent`?h===`list`?`${u(c.length,`agent`)} available`:`No agents match @${_}`:h===`list`?`${u(c.length,`command`)} available`:`No commands match /${_}`;(0,R.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),E.current&&clearTimeout(E.current),D.current+=1},[]),(0,R.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect().height;!Number.isFinite(t)||t<=0||document.documentElement.style.setProperty(`--chat-composer-height`,`${Math.ceil(t)}px`)};t();let n=typeof ResizeObserver>`u`?null:new ResizeObserver(t);return n?.observe(e),window.addEventListener(`resize`,t),()=>{n?.disconnect(),window.removeEventListener(`resize`,t),document.documentElement.style.removeProperty(`--chat-composer-height`)}},[]);let oe=(0,R.useRef)(e.isStreaming);(0,R.useEffect)(()=>{oe.current&&!e.isStreaming&&t.current?.focus(),oe.current=e.isStreaming},[e.isStreaming]);let O=(0,R.useCallback)(()=>{let e=t.current;e&&(e.style.height=`36px`,e.style.height=`${Math.max(36,Math.min(e.scrollHeight,180))}px`)},[]),se=(0,R.useCallback)(()=>{let e=t.current;e&&C(e.selectionStart??e.value.length)},[]),k=(0,R.useCallback)(e=>{let n=()=>{let n=t.current;if(!n)return;let r=Math.max(0,Math.min(e,n.value.length));n.focus(),n.setSelectionRange(r,r),C(r)};n(),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{E.current=null,n()},0)},[]);(0,R.useEffect)(()=>{let n=e.initialValue?.trim()||``;if(w.current===n||(w.current=n,!n))return;let r=t.current;r&&(r.value=n,r.setSelectionRange(n.length,n.length),b(n),C(n.length),g(`closed`),D.current+=1,O(),r.focus())},[e.initialValue,O]);let A=(0,R.useCallback)(()=>{te.current&&=(clearTimeout(te.current),null),D.current+=1},[]),j=(0,R.useCallback)(()=>{A(),g(`closed`)},[A]),ce=(0,R.useCallback)(async t=>{let n=D.current;try{let r=await Ne(e.token,t||void 0);if(n!==D.current)return;let i=r.commands??[];l(i),m(0),v(t),i.length>0?g(`list`):g(t===``?`closed`:`empty`)}catch{if(n!==D.current)return;l([]),g(`closed`)}},[e.token]),le=(0,R.useCallback)(t=>{let n=t.trim().toLowerCase();return(e.agents??[]).filter(e=>n?e.id.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n):!0).map(e=>{let t=e.name?.trim();return{id:`agent:${e.id}`,label:`@${e.id}`,insertText:`@${e.id}`,description:t&&t!==e.id?t:``,imageUrl:e.imageUrl??null}})},[e.agents]);(0,R.useEffect)(()=>{for(let t of e.agents??[])rt(e.token,t.imageUrl)},[e.agents,e.token]);let ue=()=>{O();let n=t.current;if(!n)return;b(n.value);let r=n.selectionStart??n.value.length;C(r);let i=ct(n.value,r);if(i){let e=i.query.trim();f(`slash`),A(),te.current=setTimeout(()=>{ce(e)},150);return}let a=J(n.value,r);if(a&&(e.agents?.length??0)>0){A();let e=le(a.query);l(e),f(`agent`),m(0),v(a.query),g(e.length>0?`list`:a.query===``?`closed`:`empty`)}else j()},de=e=>{let n=t.current;if(!n)return;let r=n.value,i=n.selectionStart??r.length,a=e.insertText.replace(/\s+$/,``),o=n.value.length;if(d===`agent`){let e=J(r,i);if(e){let t=r.slice(0,e.tokenStart),s=r.slice(i),c=s.startsWith(` `)?a:`${a} `;n.value=t+c+s,o=t.length+c.length,n.setSelectionRange(o,o)}else n.value=`${a} `,o=n.value.length,n.setSelectionRange(o,o);b(n.value),C(o),j(),O(),n.focus();return}let s=ct(r,i);if(s){let e=r.slice(0,s.tokenStart),t=r.slice(i),c=t.startsWith(` `)?a:`${a} `;n.value=e+c+t,o=e.length+c.length,n.setSelectionRange(o,o)}else n.value=`${a} `,o=n.value.length,n.setSelectionRange(o,o);b(n.value),C(o),j(),O(),n.focus()},M=(0,R.useCallback)(e=>{let n=t.current;if(!n)return;let r=`${`@${e}`} `,i=n.value,a=ht.exec(i),o;o=i.trim()?a?`${r}${i.slice(a[0].length).trimStart()}`:`${r}${i.trimStart()}`:r,n.value=o,b(n.value),C(r.length),j(),O(),k(r.length)},[j,O,k]),fe=()=>{if(e.isStreaming){e.onStop();return}let n=(t.current?.value??``).trim();!n&&i.length===0||o>0||(e.onSend(n,i),t.current&&(t.current.value=``),b(``),C(0),a([]),j(),O())},pe=()=>{let e=t.current,n=ne.current;!e||!n||(n.scrollTop=e.scrollTop,n.scrollLeft=e.scrollLeft)},me=e=>{if(!(e.nativeEvent.isComposing||e.nativeEvent.keyCode===229)){if(h===`list`&&c.length>0){if(e.key===`ArrowDown`){e.preventDefault(),m(e=>(e+1)%c.length);return}if(e.key===`ArrowUp`){e.preventDefault(),m(e=>(e-1+c.length)%c.length);return}if(e.key===`Home`){e.preventDefault(),m(0);return}if(e.key===`End`){e.preventDefault(),m(c.length-1);return}if(e.key===`Tab`){e.preventDefault(),de(c[p]);return}}if(e.key===`Escape`){let t=ie;if(j(),t){e.preventDefault();return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),fe())}},he=e=>{let t=S(e.clipboardData);t.length>0&&(e.preventDefault(),_e(t))},_e=async t=>{s(e=>e+t.length);try{let n=await e.onUploadFiles(t);n.length>0&&a(e=>[...e,...n])}finally{s(e=>Math.max(0,e-t.length))}},ve=e=>{let t=Array.from(e.target.files??[]);t.length>0&&_e(t),e.target.value=``},ye=e=>{a(t=>t.filter((t,n)=>n!==e))},N=e.agents??[],be=(0,R.useMemo)(()=>new Map(N.map(e=>[e.id,e])),[N]),xe=e.selectedAgentId??``,Se=e.models??[],Ce=e.selectedModelId??``;return(0,K.jsxs)(`div`,{className:P.composerWrapper,ref:r,children:[(0,K.jsxs)(T,{open:ie,onOpenChange:e=>{e||j()},children:[(0,K.jsxs)(`div`,{className:P.composer,children:[i.length>0||o>0?(0,K.jsxs)(`div`,{className:P.pendingMediaRow,children:[i.map((e,t)=>(0,K.jsxs)(`span`,{className:P.mediaChip,children:[(0,K.jsx)(`span`,{className:P.mediaChipName,children:e.filename}),(0,K.jsx)(`button`,{type:`button`,className:P.mediaChipRemove,onClick:()=>ye(t),children:`×`})]},e.path)),o>0?(0,K.jsx)(`span`,{className:P.mediaChip,children:`Uploading…`}):null]}):null,(0,K.jsxs)(x,{className:P.composerInputWrap,children:[y?(0,K.jsx)(`div`,{ref:ne,className:P.composerInputOverlay,"aria-hidden":`true`,children:(0,K.jsx)(Y,{value:y,caretIndex:ee,agents:be,token:e.token})}):null,(0,K.jsx)(`textarea`,{ref:t,className:F(P.composerInput,y&&P.composerInputHasOverlay),rows:1,placeholder:`Message HybridClaw`,disabled:e.isStreaming,onInput:ue,onSelect:se,onClick:se,onKeyUp:se,onFocus:se,onKeyDown:me,onPaste:he,onScroll:pe,"aria-label":`Message input`,role:`combobox`,"aria-autocomplete":`list`,"aria-haspopup":`listbox`,"aria-controls":re,"aria-expanded":ie,"aria-activedescendant":h===`list`&&c.length>0?lt(re,p):void 0})]}),(0,K.jsxs)(`div`,{className:P.composerActions,children:[(0,K.jsxs)(`div`,{className:P.composerLeftActions,children:[(0,K.jsx)(`button`,{type:`button`,className:P.attachButton,onClick:()=>n.current?.click(),"aria-label":`Attach files`,children:`+`}),(0,K.jsx)(at,{agents:N,selectedAgentId:xe,token:e.token,disabled:e.isStreaming,onSwitch:t=>{if(t.source?.type===`remote`){M(t.id);return}e.onAgentSwitch?.(t.id)}}),(0,K.jsx)(ge,{models:Se,selectedModelId:Ce,disabled:e.isStreaming,onSwitch:t=>e.onModelSwitch?.(t)})]}),(0,K.jsx)(`button`,{type:`button`,className:F(P.sendButton,e.isStreaming&&P.stopping),onClick:fe,"aria-label":e.isStreaming?`Stop`:`Send message`,children:e.isStreaming?(0,K.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,K.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,K.jsx)(`path`,{d:`M12 19V5`}),(0,K.jsx)(`path`,{d:`m5 12 7-7 7 7`})]})}),(0,K.jsx)(`input`,{ref:n,type:`file`,hidden:!0,multiple:!0,onChange:ve})]})]}),h===`closed`?null:(0,K.jsx)(ut,{mode:h,kind:d,suggestions:c,activeIdx:p,query:_,listboxId:re,token:e.token,onSelect:de,onActiveChange:m})]}),(0,K.jsx)(`div`,{className:P.slashLiveRegion,"aria-live":`polite`,"aria-atomic":`true`,children:ae})]})}function Y(e){let t=[],n=0,r=0,i=!1,a=Math.max(0,Math.min(e.caretIndex,e.value.length)),o=()=>{i||=(t.push((0,K.jsx)(`span`,{className:P.composerOverlayCaret,"aria-hidden":`true`},`caret-${r++}`)),!0)},s=(e,n)=>{let r=n+e.length;if(a<n||a>r){t.push(e);return}let i=a-n;i>0&&t.push(e.slice(0,i)),o(),i<e.length&&t.push(e.slice(i))};for(let i of e.value.matchAll(mt)){let c=i[0],l=i[1]??``,u=i.index??0,d=u+c.length,f=e.agents.get(l);f&&(u>n&&s(e.value.slice(n,u),n),a>u&&a<d?s(c,u):(a===u&&o(),t.push((0,K.jsx)(_t,{mention:c,imageUrl:f.imageUrl??null,token:e.token},`mention-${r++}`)),a===d&&o()),n=d)}return n<e.value.length&&s(e.value.slice(n),n),!i&&a===e.value.length&&o(),t.length>0?t:e.value}function _t(e){let t=G({token:e.token,imageUrl:e.imageUrl});return(0,K.jsxs)(`span`,{className:P.composerMentionPill,children:[t.objectUrl?(0,K.jsx)(`img`,{className:P.composerMentionAvatar,src:t.objectUrl,alt:``}):null,(0,K.jsx)(`span`,{children:e.mention})]})}var X={wrap:`_wrap_jrif0_1`,trigger:`_trigger_jrif0_11`,ring:`_ring_jrif0_33`,ringTrack:`_ringTrack_jrif0_37`,ringFill:`_ringFill_jrif0_43`,ringFillNominal:`_ringFillNominal_jrif0_52`,ringFillWarn:`_ringFillWarn_jrif0_56`,ringFillDanger:`_ringFillDanger_jrif0_60`,ringLabel:`_ringLabel_jrif0_64`,ringLabelUnknown:`_ringLabelUnknown_jrif0_77`,popover:`_popover_jrif0_81`,popoverTitle:`_popoverTitle_jrif0_112`,popoverTitleValue:`_popoverTitleValue_jrif0_121`,popoverRow:`_popoverRow_jrif0_126`,popoverRowValue:`_popoverRowValue_jrif0_133`,popoverProgress:`_popoverProgress_jrif0_138`,popoverProgressFill:`_popoverProgressFill_jrif0_148`,popoverProgressFillWarn:`_popoverProgressFillWarn_jrif0_157`,popoverProgressFillDanger:`_popoverProgressFillDanger_jrif0_161`,popoverFoot:`_popoverFoot_jrif0_165`},vt=14,yt=2*Math.PI*vt;function Z(e){if(e==null)return`n/a`;let t=Math.abs(e);return t>=1e6?`${(t>=1e7?(e/1e6).toFixed(0):(e/1e6).toFixed(1)).replace(/\.0$/,``)}M`:t>=1e3?`${(t>=1e4?(e/1e3).toFixed(0):(e/1e3).toFixed(1)).replace(/\.0$/,``)}k`:String(Math.round(e))}function bt(e){return e==null||!Number.isFinite(e)?0:Math.max(0,Math.min(100,e))}function xt(e){return e==null?`nominal`:e>=90?`danger`:e>=70?`warn`:`nominal`}function St(e){let t=e.sessionId,n=e.enabled&&!!t,r=a({queryKey:[`chat-context`,e.token,t],queryFn:()=>Pe(e.token,t),enabled:n,staleTime:15e3,refetchOnWindowFocus:!1}).data?.snapshot??null,i=r?.contextUsagePercent??null,o=bt(i),s=xt(i),c=r?.contextBudgetTokens!=null&&r.contextUsedTokens!=null,l=c?yt*(1-o/100):yt,u=i!=null&&Number.isFinite(i)?Math.max(0,Math.round(i)):null,d=u==null?`–`:`${u}%`,f=r&&c&&u!=null?`Context usage ${u} percent (${Z(r.contextUsedTokens)} of ${Z(r.contextBudgetTokens)} tokens)`:`Context usage unavailable`;return(0,K.jsxs)(`div`,{className:X.wrap,children:[(0,K.jsxs)(`button`,{type:`button`,className:X.trigger,"aria-label":f,children:[(0,K.jsxs)(`svg`,{width:34,height:34,viewBox:`0 0 34 34`,className:X.ring,"aria-hidden":`true`,children:[(0,K.jsx)(`circle`,{cx:17,cy:17,r:vt,className:X.ringTrack}),(0,K.jsx)(`circle`,{cx:17,cy:17,r:vt,className:F(X.ringFill,s===`warn`&&X.ringFillWarn,s===`danger`&&X.ringFillDanger,s===`nominal`&&X.ringFillNominal),strokeDasharray:yt,strokeDashoffset:l})]}),(0,K.jsx)(`span`,{className:F(X.ringLabel,u==null&&X.ringLabelUnknown),children:d})]}),(0,K.jsxs)(`div`,{role:`tooltip`,className:X.popover,children:[(0,K.jsxs)(`div`,{className:X.popoverTitle,children:[(0,K.jsx)(`span`,{children:`Context`}),(0,K.jsx)(`span`,{className:X.popoverTitleValue,children:r?.model||`unknown model`})]}),r&&c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:X.popoverProgress,children:(0,K.jsx)(`div`,{className:F(X.popoverProgressFill,s===`warn`&&X.popoverProgressFillWarn,s===`danger`&&X.popoverProgressFillDanger),style:{width:`${o}%`}})}),(0,K.jsxs)(`div`,{className:X.popoverRow,children:[(0,K.jsx)(`span`,{children:`Used`}),(0,K.jsxs)(`span`,{className:X.popoverRowValue,children:[Z(r.contextUsedTokens),` /`,` `,Z(r.contextBudgetTokens),` tokens`]})]}),(0,K.jsxs)(`div`,{className:X.popoverRow,children:[(0,K.jsx)(`span`,{children:`Headroom`}),(0,K.jsxs)(`span`,{className:X.popoverRowValue,children:[Z(r.contextRemainingTokens),` tokens`]})]})]}):(0,K.jsxs)(`div`,{className:X.popoverRow,children:[(0,K.jsx)(`span`,{children:`Used`}),(0,K.jsx)(`span`,{className:X.popoverRowValue,children:r?.contextUsedTokens==null?`no usage recorded yet`:`${Z(r.contextUsedTokens)} tokens`})]}),(0,K.jsxs)(`div`,{className:X.popoverRow,children:[(0,K.jsx)(`span`,{children:`Compactions`}),(0,K.jsx)(`span`,{className:X.popoverRowValue,children:r?`${r.compactionCount} · ${Z(r.compactionMessageThreshold)} msgs / ${Z(r.compactionTokenBudget)} tokens`:`n/a`})]}),(0,K.jsxs)(`div`,{className:X.popoverFoot,children:[`Run `,(0,K.jsx)(`code`,{children:`/context`}),` for full details · `,(0,K.jsx)(`code`,{children:`/compact`}),` to archive older history.`]})]})]})}var Q=2e3,Ct=1200,wt=200,Tt=60;function Et(e){return e===`delivered`||e===`failed`}var Dt={sending:`Sending`,received:`Received`,waiting:`Waiting`,failed:`Delivery failed`},$=new Map;function Ot(e,t){for($.has(e)&&$.delete(e),$.set(e,t);$.size>wt;){let e=$.keys().next().value;if(!e)break;$.delete(e)}}function kt(e,t){return e===`failed`||t===`failed`?`failed`:e===`delivered`||t===`delivered`?`delivered`:e===`pending`||t===`pending`?`pending`:`unknown`}function At(e,t){return e===`failed`?`failed`:e===`delivered`?t?.state===`delivered`?t.displayState:`received`:`sending`}function jt(e,t){let n=$.get(e)??null,r=kt(t,n?.state??null);return{state:r,displayState:At(r,n),detail:r===n?.state?n.detail:null}}function Mt(e){let{descriptor:t,token:n}=e,{messageId:r,status:i}=t,[a]=(0,R.useState)(()=>jt(r,i)),[o,s]=(0,R.useState)(a.state),[c,l]=(0,R.useState)(a.displayState),[u,d]=(0,R.useState)(a.detail);return(0,R.useEffect)(()=>{let e=jt(r,i);s(e.state),l(e.displayState),d(e.detail)},[r,i]),(0,R.useEffect)(()=>{if(o===`failed`){l(`failed`),Ot(r,{state:o,displayState:`failed`,detail:u});return}if(o!==`delivered`){l(`sending`),Ot(r,{state:o,displayState:`sending`,detail:u});return}let e=$.get(r);if(e?.state===`delivered`&&e.displayState===`waiting`){l(`waiting`);return}l(`received`),Ot(r,{state:o,displayState:`received`,detail:u});let t=window.setTimeout(()=>{l(`waiting`),Ot(r,{state:o,displayState:`waiting`,detail:u})},Ct);return()=>window.clearTimeout(t)},[u,r,o]),(0,R.useEffect)(()=>{if(Et(o))return;let e=!1,t=0,i=null,a=async()=>{t+=1;try{let i=await C(n,r);if(e)return;if(i.status!==`unknown`){s(i.status);let e=i.status===`failed`?i.lastError||(i.lastStatusCode?`HTTP ${i.lastStatusCode}`:null):null;d(e),Ot(r,{state:i.status,displayState:At(i.status,null),detail:e})}if(Et(i.status)||t>=Tt)return}catch{if(e||t>=Tt)return}i=setTimeout(()=>void a(),Q)};return a(),()=>{e=!0,i&&clearTimeout(i)}},[r,n,o]),(0,K.jsxs)(`div`,{className:F(P.a2aDeliveryChip,c===`received`&&P.a2aDeliveryChipDelivered,c===`failed`&&P.a2aDeliveryChipFailed),role:`status`,"aria-live":`polite`,title:u??void 0,children:[(0,K.jsx)(`span`,{className:F(P.a2aDeliveryDot,(c===`sending`||c===`waiting`)&&P.a2aDeliveryDotPulse)}),(0,K.jsx)(`span`,{children:Dt[c]}),u?(0,K.jsxs)(`span`,{className:P.a2aDeliveryDetail,children:[`· `,u]}):null]})}var Nt=[{label:`Trust session`,action:`session`,isAvailable:e=>e.allowSession===!0},{label:`Trust agent`,action:`agent`,isAvailable:e=>e.allowAgent===!0},{label:`Always allow`,action:`all`,isAvailable:e=>e.allowAll===!0}],Pt=/^([^:\n]{2,44}):\s+(.+)$/,Ft=/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+/i;function It(e){return e===`yellow`?`Amber`:e===`red`?`Red`:null}function Lt(e){return/^reply\b/i.test(e)||/^approval expires\b/i.test(e)||/^approval id\b/i.test(e)}function Rt(e){let t=e.trim();return/^proposed action$/i.test(t)?`Request`:/^why$/i.test(t)?`Reason`:t}function zt(e){let t=[],n,r=e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);for(let e of r){if(Lt(e)||/^classifier reasoning$/i.test(e)||/^if you skip this/i.test(e))continue;let r=e.match(Pt);if(r){let e=Rt(r[1]??``);/^classifier reasoning$/i.test(e)||t.push({label:e,value:r[2]??``});continue}n??=e}return{introLine:n,rows:t}}function Bt(e){let t=[],n=new Set,r=(e,r)=>{let i=e.trim(),a=String(r??``).trim();if(!i||!a)return;let o=`${i.toLowerCase()}:${a}`;n.has(o)||(n.add(o),t.push({label:i,value:a}))};e.intent&&r(`Action`,e.intent),e.commandPreview&&r(Ft.test(e.commandPreview)?`Request`:`Preview`,e.commandPreview),e.toolName&&r(`Tool`,e.toolName);for(let t of zt(e.prompt).rows)r(t.label,t.value);if(r(`Approval ID`,e.approvalId),e.expiresAt&&Number.isFinite(e.expiresAt)){let t=new Date(e.expiresAt);Number.isNaN(t.getTime())||r(`Expires`,t.toLocaleTimeString())}return t}function Vt(e){let{introLine:t}=zt(e.prompt);return t||(e.summary?e.summary.split(/\r?\n/)[0]??``:e.intent?`Confirmation required for ${e.intent}.`:`Confirmation required before this action can continue.`)}function Ht(e){let{approval:t}=e,n=(0,R.useMemo)(()=>Bt(t),[t]),r=(0,R.useMemo)(()=>Vt(t),[t]),i=Nt.filter(e=>e.isAvailable(t)),a=It(t.approvalTier),o=n=>{e.onAction(n,t.approvalId)};return(0,K.jsxs)(`div`,{className:P.approvalCard,children:[(0,K.jsxs)(`div`,{className:P.approvalHeader,children:[a?(0,K.jsx)(`span`,{className:P.approvalTier,children:a}):null,(0,K.jsx)(`span`,{className:P.approvalTitle,children:`Confirmation required`})]}),(0,K.jsx)(`p`,{className:P.approvalIntro,children:r}),n.length>0?(0,K.jsx)(`dl`,{className:P.approvalDetails,children:n.map(e=>(0,K.jsxs)(`div`,{className:P.approvalDetailRow,children:[(0,K.jsx)(`dt`,{children:e.label}),(0,K.jsx)(`dd`,{children:e.value})]},`${e.label}:${e.value}`))}):null,(0,K.jsxs)(`div`,{className:P.approvalPrimaryActions,children:[(0,K.jsx)(b,{size:`sm`,disabled:e.busy,onClick:()=>o(`once`),children:`Allow once`}),(0,K.jsx)(b,{variant:`danger`,size:`sm`,disabled:e.busy,onClick:()=>o(`deny`),children:`Cancel`})]}),i.length>0?(0,K.jsx)(`div`,{className:P.approvalTrustActions,children:i.map(t=>(0,K.jsx)(b,{variant:`outline`,size:`sm`,className:P.approvalAllow,disabled:e.busy,onClick:()=>o(t.action),children:t.label},t.action))}):null]})}function Ut(e){if(e<1e3)return`${Math.max(0,Math.round(e))}ms`;let t=e/1e3;if(t<10)return`${t.toFixed(1)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}function Wt(e,t,n){if(!e.done){let e=t.slice().reverse().find(e=>e.kind!==`draft`)??t[t.length-1];return e?.kind===`tool`&&e.status===`running`?`${e.toolName}…`:e?.kind===`thinking`?`Thinking…`:`Working…`}let r=t.filter(e=>e.kind===`tool`).length,i=t.some(e=>e.kind===`thinking`),a=[];r>0?(a.push(`${r} tool call${r===1?``:`s`}`),i&&a.push(`thinking`)):i?a.push(`Thought`):t.some(e=>e.kind===`draft`)&&a.push(`Agent activity`);let o=e.finishedAt?e.finishedAt-e.startedAt:0;return n&&o>=1e3&&a.push(Ut(o)),a.join(` · `)||`Agent activity`}function Gt(e){let t=(0,R.useMemo)(()=>Se(e.text,{highlight:!1}),[e.text]);return(0,K.jsx)(`div`,{className:P.traceDraftInterim,children:(0,K.jsx)(`div`,{className:P.markdownContent,dangerouslySetInnerHTML:{__html:t}})})}function Kt(e){let{step:t,live:n}=e;if(t.kind===`draft`)return(0,K.jsx)(Gt,{text:t.text});if(t.kind===`thinking`)return(0,K.jsxs)(`div`,{className:P.traceStep,children:[(0,K.jsx)(`span`,{className:P.traceStepMarker,"aria-hidden":`true`,children:(0,K.jsx)(`span`,{className:P.traceDot})}),(0,K.jsx)(`div`,{className:P.traceThinkingText,children:t.text})]});let r=n&&t.status===`running`;return(0,K.jsxs)(`div`,{className:P.traceStep,children:[(0,K.jsx)(`span`,{className:P.traceStepMarker,"aria-hidden":`true`,children:(0,K.jsx)(`span`,{className:F(P.traceDot,r&&P.traceDotRunning)})}),(0,K.jsxs)(`div`,{className:P.traceStepBody,children:[(0,K.jsxs)(`div`,{className:P.traceToolLine,children:[(0,K.jsx)(`span`,{className:P.traceToolName,children:t.toolName}),t.argsPreview?(0,K.jsx)(`span`,{className:P.traceToolPreview,title:t.argsPreview,children:t.argsPreview}):null,typeof t.durationMs==`number`?(0,K.jsx)(`span`,{className:P.traceToolDuration,children:Ut(t.durationMs)}):null]}),t.resultPreview?(0,K.jsx)(`div`,{className:P.traceToolResult,title:t.resultPreview,children:t.resultPreview}):null]})]})}function qt(e){let{message:t,steps:n}=e,[r,i]=(0,R.useState)(null);if((0,R.useEffect)(()=>{t.done&&i(null)},[t.done]),n.length===0)return null;let a=r??!t.done;return(0,K.jsxs)(`div`,{className:P.traceBlock,children:[(0,K.jsxs)(`button`,{type:`button`,className:P.traceHeader,"aria-expanded":a,"aria-label":a?`Collapse agent activity`:`Expand agent activity`,onClick:()=>i(!a),children:[(0,K.jsx)(`span`,{className:F(P.traceChevron,a&&P.traceChevronOpen),"aria-hidden":`true`,children:`›`}),(0,K.jsx)(`span`,{className:F(P.traceSummary,!t.done&&P.traceSummaryLive),children:Wt(t,n,!0)})]}),a?(0,K.jsx)(`div`,{className:P.traceSteps,children:n.map((e,n)=>(0,K.jsx)(Kt,{step:e,live:!t.done},n))}):null]})}var Jt=(0,R.memo)(function(e){let{message:t}=e;return t.steps.length===0?null:(0,K.jsx)(`div`,{className:P.traceSequence,children:(0,K.jsx)(qt,{message:t,steps:t.steps})})}),Yt=120;function Xt(e,t,n){let[r,i]=(0,R.useState)(e),a=(0,R.useRef)(e),o=(0,R.useRef)(null);a.current=e,(0,R.useEffect)(()=>{if(!t){o.current!==null&&(window.clearTimeout(o.current),o.current=null),i(``);return}if(!n){o.current!==null&&(window.clearTimeout(o.current),o.current=null),i(e);return}o.current!==null||e===r||(o.current=window.setTimeout(()=>{o.current=null,(0,R.startTransition)(()=>{i(a.current)})},Yt))},[e,t,n,r]),(0,R.useEffect)(()=>()=>{o.current!==null&&window.clearTimeout(o.current)},[]);let s=t?n?r:e:``;return(0,R.useMemo)(()=>t?Se(s,{highlight:!n}):``,[t,s,n])}var Zt=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>`,Qt=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>`,$t=`<svg viewBox="0 0 24 24" width="11" height="11" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 7-5 5 5 5"/><path d="m15 7 5 5-5 5"/><path d="m13.5 5-3 14"/></svg>`,en=/^\/([A-Za-z0-9][A-Za-z0-9._-]*)(?=$|[\s:.,!?;)\]}])/u,tn=new Set([`text`,`plaintext`,`plain`,`txt`]);function nn(e){let t=e.querySelector(`code`)?.className.match(/language-([\w#.+-]+)/)?.[1]??``;return tn.has(t)?``:t}function rn(e){if(e.querySelector(`button[data-copy-btn]`))return;let t=nn(e);if(t){e.classList.add(P.codeBlockLabeled);let n=document.createElement(`span`);n.className=P.codeLangLabel,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=$t;let r=document.createElement(`span`);r.textContent=t,n.appendChild(r),e.appendChild(n)}let n=document.createElement(`button`);n.type=`button`,n.dataset.copyBtn=``,n.className=P.codeCopyButton,n.innerHTML=Zt;let r=e=>{n.setAttribute(`aria-label`,e),n.title=e};r(`Copy code`);let i=null;n.addEventListener(`click`,()=>{Ee((e.querySelector(`code`)??e).textContent??``).then(e=>{e&&(n.innerHTML=Qt,n.classList.add(P.codeCopyButtonDone),r(`Copied`),i!==null&&window.clearTimeout(i),i=window.setTimeout(()=>{n.innerHTML=Zt,n.classList.remove(P.codeCopyButtonDone),r(`Copy code`)},1500))})}),e.appendChild(n)}function an(){let e=(0,R.useRef)(null);return(0,R.useCallback)(t=>{if(e.current?.disconnect(),e.current=null,!t)return;let n=()=>{for(let e of t.querySelectorAll(`pre`))rn(e)};n();let r=new MutationObserver(n);r.observe(t,{childList:!0,subtree:!0}),e.current=r},[])}function on(e,t){let n=t.split(`;`)[0]?.trim().toLowerCase()||``;return!n||n!==`application/pdf`&&!n.startsWith(`image/`)&&!n.startsWith(`video/`)||e.type.toLowerCase()===n?e:new Blob([e],{type:n})}function sn(e){let{artifact:t,token:n}=e,r=(0,R.useRef)(null),[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(!1),c=(t.mimeType??``).toLowerCase(),l=t.filename??`artifact`,u=c.startsWith(`image/`),d=c.startsWith(`video/`)||/\.(mp4|m4v|mov|webm)$/i.test(t.filename??``)||/\.(mp4|m4v|mov|webm)$/i.test(t.path??``),f=c===`application/pdf`||/\.pdf$/i.test(t.filename??``)||/\.pdf$/i.test(t.path??``),p=u||d||f;(0,R.useEffect)(()=>{let e=r.current;if(r.current=null,e&&URL.revokeObjectURL(e),a(null),!p||!t.path)return;let i=!1;return Ue(n,t.path).then(e=>{if(i)return;let t=URL.createObjectURL(on(e,c));r.current=t,a(t)}).catch(()=>{i||a(null)}),()=>{i=!0;let e=r.current;r.current=null,e&&URL.revokeObjectURL(e)}},[t.path,p,c,n]);let m=o?`Downloading…`:`Download`,h=async()=>{if(!(!t.path||o)){s(!0);try{let e=i??URL.createObjectURL(await Ue(n,t.path)),r=document.createElement(`a`);r.href=e,r.download=t.filename??`artifact`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove(),i||window.setTimeout(()=>URL.revokeObjectURL(e),0)}catch{}finally{s(!1)}}};return(0,K.jsxs)(`div`,{className:F(P.artifactCard,i&&P.artifactCardWithPreview),children:[(0,K.jsxs)(`div`,{className:P.artifactHeader,children:[(0,K.jsx)(`span`,{className:P.artifactFilename,children:l}),t.type?(0,K.jsx)(`span`,{className:P.artifactBadge,children:t.type}):null,t.path?(0,K.jsx)(`button`,{type:`button`,className:P.artifactDownload,disabled:o,onClick:()=>{h()},children:m}):null]}),u&&i?(0,K.jsx)(`div`,{className:P.artifactPreview,children:(0,K.jsx)(`img`,{src:i,alt:l})}):null,f&&i?(0,K.jsx)(`div`,{className:F(P.artifactPreview,P.artifactPdfPreview),children:(0,K.jsx)(`iframe`,{src:i,title:`${l} preview`,sandbox:``})}):null,d&&i?(0,K.jsx)(`div`,{className:F(P.artifactPreview,P.artifactVideoPreview),children:(0,K.jsx)(`video`,{controls:!0,preload:`metadata`,src:i,children:(0,K.jsxs)(`a`,{href:i,download:l,children:[`Download `,l]})})}):null]})}function cn(e){let t=(0,R.useRef)(null),[n,r]=(0,R.useState)(null);return(0,R.useEffect)(()=>{let n=t.current;if(t.current=null,n&&URL.revokeObjectURL(n),r(null),!e.imageUrl)return;let i=!1;return Re(e.token,e.imageUrl).then(e=>{if(i)return;let n=URL.createObjectURL(e);t.current=n,r(n)}).catch(()=>{i||r(null)}),()=>{i=!0;let e=t.current;t.current=null,e&&URL.revokeObjectURL(e)}},[e.imageUrl,e.token]),n}var ln=(0,R.memo)(function(e){let{message:t,token:n}=e,[r,i]=(0,R.useState)(!1),a=()=>{e.onCopy(t.rawContent??t.content),i(!0),setTimeout(()=>i(!1),900)},o=(0,R.useMemo)(()=>{let e=new Map;return(t.artifacts??[]).map(t=>{let n=[t.path,t.filename,t.mimeType,t.type].filter(Boolean),r=n.length>0?n.join(`|`):`artifact`,i=e.get(r)??0;return e.set(r,i+1),{artifact:t,key:`${r}:${i}`}})},[t.artifacts]),s=t.role===`approval`,c=t.role===`draft`,l=!!t.a2aDelivery,u=s&&!!t.pendingApproval,d=!l&&(t.role===`assistant`||c||t.role===`command`||s&&!u),f=Xt(t.content,d,e.isStreaming),p=an(),m=t.assistantPresentation,h=m?.displayName??`Assistant`,g=cn({token:n,imageUrl:m?.imageUrl});if(t.role===`trace`)return(0,K.jsx)(Jt,{message:t});if(t.role===`thinking`)return(0,K.jsxs)(`div`,{className:P.thinking,role:`status`,"aria-label":`Assistant is thinking`,children:[(0,K.jsx)(`span`,{className:P.thinkingDot}),(0,K.jsx)(`span`,{className:P.thinkingDot}),(0,K.jsx)(`span`,{className:P.thinkingDot})]});if(c)return(0,K.jsx)(`div`,{className:P.traceDraftInterim,children:(0,K.jsx)(`div`,{ref:p,className:P.markdownContent,dangerouslySetInnerHTML:{__html:f}})});let _=t.role===`user`,v=t.role===`assistant`,y=_||l||t.content.trim().length>0||o.length===0||s,ee=F(P.messageBlock,_&&P.messageBlockUser,(v||t.role===`system`||t.role===`command`||s)&&P.messageBlockAssistant),x=F(P.bubble,_&&P.bubbleUser,(v||s)&&P.bubbleAssistant,s&&P.bubbleApproval,t.role===`system`&&P.bubbleSystem,t.role===`command`&&P.bubbleCommand,l&&P.bubbleA2AStatus);return(0,K.jsxs)(`div`,{className:ee,children:[v&&!l?(0,K.jsxs)(`div`,{className:P.agentLabel,children:[g?(0,K.jsx)(`img`,{className:P.agentAvatar,src:g,alt:``}):(0,K.jsx)(`span`,{className:P.agentInitial,children:h.charAt(0).toUpperCase()}),(0,K.jsx)(`span`,{children:h})]}):null,y?(0,K.jsx)(`div`,{className:x,children:l&&t.a2aDelivery?(0,K.jsx)(Mt,{descriptor:t.a2aDelivery,token:n}):u&&t.pendingApproval?(0,K.jsx)(Ht,{approval:t.pendingApproval,busy:e.approvalBusy,onAction:e.onApprovalAction}):d?(0,K.jsx)(`div`,{ref:p,className:P.markdownContent,dangerouslySetInnerHTML:{__html:f}}):_?(0,K.jsx)(un,{content:je(t.content),presentation:t.addressedAgentPresentation,skillInvocationTargets:e.skillInvocationTargets,token:n}):t.content}):null,o.map(({artifact:e,key:t})=>(0,K.jsx)(sn,{artifact:e,token:n},t)),!e.isStreaming&&!l?(0,K.jsxs)(`div`,{className:P.messageActions,children:[v&&t.replayRequest?(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:P.actionButton,title:`Regenerate`,"aria-label":`Regenerate response`,onClick:()=>e.onRegenerate(t),children:`↻`}):null,v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:F(P.actionButton,t.responseRating===`up`&&P.actionButtonSelected),title:t.responseRating===`up`?`Clear thumbs up`:`Thumbs up`,"aria-label":t.responseRating===`up`?`Clear thumbs up rating`:`Rate response thumbs up`,"aria-pressed":t.responseRating===`up`,"data-rating-locked":t.responseRating?`true`:void 0,disabled:e.ratingBusy===!0||!t.messageId||t.responseRating===`down`,onClick:()=>e.onRate?.(t,t.responseRating===`up`?null:`up`),children:(0,K.jsx)(me,{width:`13`,height:`13`,filled:t.responseRating===`up`})}),(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:F(P.actionButton,t.responseRating===`down`&&P.actionButtonSelected),title:t.responseRating===`down`?`Clear thumbs down`:`Thumbs down`,"aria-label":t.responseRating===`down`?`Clear thumbs down rating`:`Rate response thumbs down`,"aria-pressed":t.responseRating===`down`,"data-rating-locked":t.responseRating?`true`:void 0,disabled:e.ratingBusy===!0||!t.messageId||t.responseRating===`up`,onClick:()=>e.onRate?.(t,t.responseRating===`down`?null:`down`),children:(0,K.jsx)(Te,{width:`13`,height:`13`,filled:t.responseRating===`down`})})]}):null,(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:F(P.actionButton,r&&P.actionButtonSuccess),title:`Copy`,"aria-label":r?`Copied`:`Copy message`,onClick:a,children:r?`✓`:`⧉`}),_?(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:P.actionButton,title:`Edit`,"aria-label":`Edit message`,onClick:()=>e.onEdit(t),children:`✎`}):null,e.branchInfo&&e.branchInfo.total>1?(0,K.jsxs)(`div`,{className:P.branchSwitcher,children:[(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:P.branchButton,"aria-label":`Previous branch`,disabled:e.branchInfo.current<=1,onClick:()=>e.onBranchNav(t,-1),children:`‹`}),(0,K.jsxs)(`span`,{children:[e.branchInfo.current,`/`,e.branchInfo.total]}),(0,K.jsx)(b,{variant:`ghost`,size:`icon`,className:P.branchButton,"aria-label":`Next branch`,disabled:e.branchInfo.current>=e.branchInfo.total,onClick:()=>e.onBranchNav(t,1),children:`›`})]}):null]}):null]})});function un(e){let t=Ye(e.content),n=[],r=0;for(let[i,a]of t.entries()){a.index>r&&dn(n,e.content.slice(r,a.index),`text-${i}`,r===0,e.skillInvocationTargets);let t=e.presentation?.agentId?.toLowerCase()===a.agentId.toLowerCase()?e.presentation:null;n.push((0,K.jsx)(fn,{mention:a.mention,imageUrl:t?.imageUrl??null,token:e.token},`${a.index}-${i}`)),r=a.index+a.mention.length}return r<e.content.length&&dn(n,e.content.slice(r),`text-tail`,r===0,e.skillInvocationTargets),(0,K.jsx)(K.Fragment,{children:n})}function dn(e,t,n,r,i){if(!t)return;if(!r||!i){e.push(t);return}let a=en.exec(t),o=a?.[1]??``,s=i.get(o.toLowerCase());if(!a||!o||!s){e.push(t);return}let c=a[0];e.push((0,K.jsx)(`a`,{className:P.userSkillCommandLink,href:`/admin/skills/${encodeURIComponent(s)}`,children:c},`${n}-skill-command`));let l=t.slice(c.length);l&&e.push(l)}function fn(e){let t=cn({token:e.token,imageUrl:e.imageUrl});return(0,K.jsxs)(`span`,{className:P.userAgentMentionPill,children:[t?(0,K.jsx)(`img`,{className:P.userAgentMentionAvatar,src:t,alt:``}):null,(0,K.jsx)(`span`,{children:e.mention})]})}function pn(e){let[t,n]=(0,R.useState)(e.initial);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`textarea`,{className:P.editArea,value:t,onChange:e=>n(e.target.value),"aria-label":`Edit message`,autoFocus:!0}),(0,K.jsxs)(`div`,{className:P.editButtons,children:[(0,K.jsx)(b,{onClick:()=>e.onSave(t.trim()),disabled:!t.trim(),children:`Save`}),(0,K.jsx)(b,{variant:`ghost`,onClick:e.onCancel,children:`Cancel`})]})]})}function mn(){let e=o({strict:!1}),t=s(),n=e.sessionId,r=(0,R.useRef)(null),i=(0,R.useRef)(new Set);if(!n&&!r.current){let e=d();r.current=e,i.current.add(e)}let a=n??r.current??``,c=(0,R.useRef)(a);c.current=a,(0,R.useEffect)(()=>{n&&(r.current=null)},[n]),(0,R.useEffect)(()=>{a&&m(a)},[a]);let l=(0,R.useCallback)(()=>c.current,[]),u=(0,R.useCallback)((e,n)=>t({to:`/chat/$sessionId`,params:{sessionId:e},...n}),[t]);return(0,R.useEffect)(()=>{n||!a||u(a,{replace:!0})},[u,a,n]),{sessionId:a,getSessionId:l,navigateToSession:u,switchToSession:(0,R.useCallback)((e,t)=>(r.current=e,c.current=e,u(e,t)),[u]),startFreshChat:(0,R.useCallback)(e=>{let t=d();return r.current=t,c.current=t,i.current.add(t),u(t,e),t},[u]),ensureSessionForSend:(0,R.useCallback)(()=>{if(c.current)return c.current;let e=d();return r.current=e,c.current=e,i.current.add(e),u(e,{replace:!0}),e},[u]),isLocallyCreatedSession:(0,R.useCallback)(e=>i.current.has(e),[]),handleSessionIdCorrection:(0,R.useCallback)(e=>{e!==c.current&&u(e,{replace:!0})},[u])}}async function hn(e,t){let n=await fetch(e,{method:`POST`,headers:{...p(t.token,t.body),Accept:`application/x-ndjson`},body:JSON.stringify(t.body),signal:t.signal});n.ok||await fe(n);let{callbacks:r}=t,i=e=>{let t=String(e||``).trim();if(!t)return null;let n;try{n=JSON.parse(t)}catch{return console.warn(`Ignoring malformed chat stream line`,t),null}return!n||typeof n!=`object`?null:n.type===`text`&&typeof n.delta==`string`?(r.onTextDelta(n.delta,n),null):n.type===`thinking`&&typeof n.delta==`string`?(r.onThinkingDelta?.(n.delta),null):n.type===`tool`&&typeof n.toolName==`string`&&(n.phase===`start`||n.phase===`finish`)?(r.onToolEvent?.(n),null):n.type===`approval`&&typeof n.approvalId==`string`&&typeof n.prompt==`string`?(r.onApproval(n),null):n.type===`result`&&n.result&&typeof n.result==`object`?n.result:typeof n.status==`string`&&Array.isArray(n.toolsUsed)?n:null};if(!n.body){let e=await n.text().catch(()=>``),t=null;for(let n of e.split(`
3
+ `)){let e=i(n);e&&(t=e)}if(!t)throw Error(`Chat stream ended without a result payload.`);return t}let a=n.body.getReader(),o=new TextDecoder,s=``,c=null,l=(e=!1)=>{let t=s.split(`
4
+ `),n=e?t.pop()??``:null;s=e?``:t.pop()??``;for(let e of t){let t=i(e);t&&(c=t)}if(e&&n?.trim()){let e=i(n);e&&(c=e)}};try{for(;;){let{done:e,value:t}=await a.read();if(e)break;s+=o.decode(t,{stream:!0}),l()}s+=o.decode(),l(!0)}finally{a.releaseLock()}if(!c)throw Error(`Chat stream ended without a result payload.`);return c}var gn=[2e3,5e3,8e3,12e3,16e3,2e4,24e3,3e4,45e3,6e4];function _n(e){let t=e.trim().split(/\s+/),n=t[0]?.replace(/^\/+/,``).toLowerCase(),r=t[1]?.toLowerCase();return(n===`agent`||n===`agents`)&&(r===`create`||r===`install`)}function vn(e){let t=e.trim().split(/\s+/),n=t[0]?.replace(/^\/+/,``).toLowerCase();if(n!==`agent`&&n!==`agents`||t[1]?.toLowerCase()!==`switch`)return null;let r=t[2]?.trim();return r&&!/\s/.test(r)?r:null}function yn(e){return/^Session agent set to\b/i.test(e.trim())}function bn(e){return/\bBOOTSTRAP\.md\b/i.test(e)}function xn(e){let{token:t,userId:r,getSessionId:i,setError:a,refreshRecent:o,onSessionIdCorrection:s,onModelResolved:c,onAppsCaptured:l,resolveAddressedAgentPresentation:u}=e,d=n(),f=(0,R.useRef)(null),[p,m]=(0,R.useState)(!1),[h,g]=(0,R.useState)(null),[_,v]=(0,R.useState)(null),y=(0,R.useCallback)((e,n)=>{let r=H(t,e);d.setQueryData(r,t=>{let r=t?.messages??[],i=typeof n==`function`?n(r):n;return i===r?t:{messages:i,branchFamilies:t?.branchFamilies??new Map,requestedSessionId:t?.requestedSessionId??e,resolvedSessionId:t?.resolvedSessionId??e,agentId:t?.agentId??null,bootstrapAutostart:t?.bootstrapAutostart??null}})},[d,t]);return{sendMessage:(0,R.useCallback)(async(e,n,p)=>{if(f.current)return a(`Wait for the current run to finish before sending another message.`),!1;let h=i(),_=e=>y(h,e),b=p?.hideUser?null:I(),ee=I(),x=I(),S=I(),C={controller:new AbortController,sessionId:h,messageRole:`assistant`,assistantText:``,lastRenderedText:``,pendingApproval:null,trace:[],traceVersion:0,lastRenderedTraceVersion:0,renderFrame:0,stopping:!1};if(f.current=C,a(``),g(S),v(h),m(!0),d.cancelQueries({queryKey:H(t,h),exact:!0}),b){let t=u?.(e)??null,r={id:b,role:`user`,content:e,rawContent:e,sessionId:h,media:n,artifacts:[],replayRequest:{content:e,media:n},addressedAgentPresentation:t};_(e=>[...e,r])}_(e=>[...e,{id:x,role:`trace`,content:``,sessionId:h,steps:[],done:!1,startedAt:Date.now()},{id:ee,role:`thinking`,content:``,sessionId:h}]);let w=()=>{C.renderFrame=0;let e=C.traceVersion!==C.lastRenderedTraceVersion;if(C.assistantText===C.lastRenderedText&&!C.pendingApproval&&!e)return;C.lastRenderedText=C.assistantText,C.lastRenderedTraceVersion=C.traceVersion;let t=C.assistantText,n=C.pendingApproval,r=C.messageRole===`assistant`&&!n&&C.trace.length>0?`draft`:C.messageRole,i=e?C.trace.map(e=>({...e})):null;_(e=>{let a=i?e.map(e=>e.id===x&&e.role===`trace`?{...e,steps:i}:e):e;if(!t&&!n)return a.filter(e=>e.id!==S);let o=a.filter(e=>e.id!==ee),s=o.find(e=>e.id===S);return s?o.map(e=>e===s?{...e,role:r,content:t,pendingApproval:n}:e):[...o,{id:S,role:r,content:t,sessionId:C.sessionId,artifacts:[],pendingApproval:n}]})},te=()=>{C.renderFrame&&=(cancelAnimationFrame(C.renderFrame),0),w()},T=()=>{C.renderFrame||=requestAnimationFrame(w)},E=e=>{if(!e)return;let t=C.trace.at(-1);t?.kind===`thinking`?t.text+=e:C.trace.push({kind:`thinking`,text:e}),C.traceVersion+=1,T()},D=()=>{let e=C.assistantText.trim();e.trim()&&(C.trace.push({kind:`draft`,text:e}),C.assistantText=``,C.lastRenderedText=``)},ne=e=>{if(e.phase===`start`)D(),C.trace.push({kind:`tool`,toolName:e.toolName,status:`running`,argsPreview:e.preview||void 0});else{let t;for(let n=C.trace.length-1;n>=0;n--){let r=C.trace[n];if(r?.kind===`tool`&&r.status===`running`&&r.toolName===e.toolName){t=r;break}}t?(t.status=`done`,t.durationMs=e.durationMs,t.resultPreview=e.preview||void 0):C.trace.push({kind:`tool`,toolName:e.toolName,status:`done`,durationMs:e.durationMs,resultPreview:e.preview||void 0})}C.traceVersion+=1,T()},ie=e=>{if(C.trace.length===0)return e.filter(e=>e.id!==x);let t=C.trace.map(e=>({...e}));return e.map(e=>e.id===x&&e.role===`trace`?{...e,steps:t,done:!0,finishedAt:Date.now()}:e)};try{let i=await hn(`/api/chat`,{token:t,body:{sessionId:h,channelId:`web`,userId:r,username:`web`,content:e,stream:!0,...n.length>0?{media:n}:{},...p?.appBuild?{appBuild:!0}:{},...p?.appCategory?{appCategory:p.appCategory}:{},...p?.appKind?{appKind:p.appKind}:{}},signal:C.controller.signal,callbacks:{onTextDelta:(e,t)=>{t?.outputPresentation?.visible!==!1&&(C.assistantText+=e,T())},onApproval:e=>{C.pendingApproval=e,C.messageRole=`approval`,C.assistantText.trim()||(C.assistantText=re(e)),T()},onThinkingDelta:E,onToolEvent:ne}});if(i.status===`error`)throw Error(i.error??`Unknown error`);i.sessionId&&i.sessionId!==h&&s(i.sessionId);let a=i.model?.trim();a&&c?.(a),p?.appBuild&&i.apps&&i.apps.length>0&&l?.(i.apps),te();let u=i.result??C.assistantText??``,f=C.pendingApproval,m=i.artifacts??[],g=typeof i.addressEnvelope?.to==`string`?i.addressEnvelope.to:null;if(!i.messageRole)throw Error(`Gateway chat result is missing messageRole.`);let v=i.messageRole,y=v===`command`&&u.trim().length===0&&m.length===0,x=i.outputPresentation?.visible===!1&&m.length===0&&!f,w=(t,r,a)=>({...a,id:t,role:v,content:u,sessionId:r,messageId:i.assistantMessageId??null,artifacts:m,assistantPresentation:i.assistantPresentation??null,pendingApproval:f,responseRating:null,replayRequest:{content:e,media:n},a2aDelivery:i.a2aDelivery??null});_(e=>{let t=ie(e).filter(e=>e.id!==ee),n=t.some(e=>e.id===S),r=e=>e.id===S?w(S,i.sessionId??e.sessionId,e):b&&e.id===b&&e.role===`user`?{...e,addressedAgentPresentation:g?i.assistantPresentation??null:null,messageId:e.messageId??i.userMessageId??null,sessionId:i.sessionId??e.sessionId}:e;if(y||x)return t.filter(e=>e.id!==S).map(r);let a=t.map(r);return n?a:[...a,w(S,i.sessionId??C.sessionId)]}),o();let D=v===`command`&&yn(u)?vn(e):null;if(D){let e=i.sessionId??h,n=H(t,e);d.setQueryData(n,e=>e&&{...e,agentId:D,bootstrapAutostart:bn(u)?{status:`starting`,fileName:`BOOTSTRAP.md`}:e.bootstrapAutostart}),d.invalidateQueries({queryKey:n,refetchType:`none`}),d.invalidateQueries({queryKey:[`chat-context`,t,e]})}if(v===`command`&&_n(e)&&d.invalidateQueries({queryKey:[`agents-list`,t]}),i.a2aDelivery){let e=H(t,i.sessionId??h);for(let t of gn)window.setTimeout(()=>{d.invalidateQueries({queryKey:e})},t)}}catch(e){C.renderFrame&&cancelAnimationFrame(C.renderFrame);let t=M(e);_(e=>{let n=ie(e).filter(e=>e.id!==ee);return C.stopping?n:[...n,{id:I(),role:`system`,content:`Error: ${t}`,sessionId:h}]})}finally{f.current=null,v(null),m(!1),g(null)}return!0},[t,r,i,y,s,c,l,u,d,a,o]),stopRequest:(0,R.useCallback)(async()=>{let e=f.current;if(!(!e||e.stopping)){e.stopping=!0;try{await Me(t,e.sessionId,r,[`stop`])}catch(e){a(`Failed to stop: ${M(e)}`)}finally{e.controller.abort()}}},[t,r,a]),isStreaming:p,streamingMsgId:h,activeSessionId:_,isActive:(0,R.useCallback)(()=>f.current!==null,[])}}var Sn=120,Cn=220;function wn(){let e=(0,R.useRef)(null),t=(0,R.useRef)(null),n=(0,R.useRef)(null),r=(0,R.useRef)(0),[i,a]=(0,R.useState)(!0),o=(0,R.useRef)(!0),s=(0,R.useRef)(!1),c=(0,R.useCallback)(e=>{o.current!==e&&(o.current=e,a(e))},[]),l=(0,R.useCallback)((e,t)=>{let n=Math.max(0,e.scrollHeight-e.clientHeight),r=Math.max(0,Math.min(t,n));r!==e.scrollTop&&(s.current=!0,e.scrollTop=r)},[]),u=(0,R.useCallback)(()=>{let t=e.current;!t||!o.current||t.scrollHeight<=t.clientHeight||l(t,t.scrollHeight)},[l]),d=(0,R.useCallback)(n=>{if(t.current?.abort(),t.current=null,e.current=n,!n)return;let r=new AbortController;t.current=r,n.addEventListener(`scroll`,()=>{if(s.current){s.current=!1;return}c(n.scrollHeight-n.scrollTop-n.clientHeight<=Sn)},{passive:!0,signal:r.signal}),u()},[c,u]),f=(0,R.useCallback)(e=>{if(n.current?.disconnect(),n.current=null,!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>u());t.observe(e),n.current=t},[u]),p=(0,R.useCallback)(()=>{let t=e.current;if(!t)return;if(r.current&&=(cancelAnimationFrame(r.current),0),c(!0),typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){l(t,t.scrollHeight);return}let n=t.scrollTop;if(t.scrollHeight-t.clientHeight-n<=0)return;let i=performance.now(),a=()=>{let t=e.current;if(!t){r.current=0;return}let o=Math.min(1,(performance.now()-i)/Cn),s=1-(1-o)**3;l(t,n+(t.scrollHeight-t.clientHeight-n)*s),r.current=o<1?requestAnimationFrame(a):0};r.current=requestAnimationFrame(a)},[c,l]),m=(0,R.useCallback)(()=>{c(!0);let t=e.current;t&&l(t,t.scrollHeight)},[c,l]);return(0,R.useEffect)(()=>()=>{t.current?.abort(),n.current?.disconnect(),r.current&&cancelAnimationFrame(r.current)},[]),{scrollRef:d,contentRef:f,isPinned:i,jumpToBottom:p,resetToBottom:m}}var Tn=[],En=[],Dn=5e3,On=`bootstrap-autostart-thinking`,kn=1500,An=`Ready to claw through your to-do list?`,jn=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function Mn(){let e=new URLSearchParams(window.location.search).get(`agent`)?.trim();return e&&jn.test(e)?e:``}function Nn(e,t){let n=new Map;if(t.size===0)return n;for(let r of e){let e=r.branchKey;if(!e)continue;let i=t.get(e);if(!i||i.length<2)continue;let a=i.findIndex(e=>e.sessionId===r.sessionId);a<0||n.set(r.id,{current:a+1,total:i.length})}return n}function Pn(e,t,n=``,r=`user`){return[`chat-recent`,e,t,n,r]}function Fn(e,t){return[`chat-recent`,e,t]}function In(e,t){return[`chat-context`,e,t]}var Ln=`hybridclaw.appBuildSessions`;function Rn(){try{let e=localStorage.getItem(Ln);return e?new Map(Object.entries(JSON.parse(e))):new Map}catch{return new Map}}function zn(e){try{localStorage.setItem(Ln,JSON.stringify(Object.fromEntries(e)))}catch{}}function Bn(){let e=j(),t=s(),i=n(),o=(0,R.useRef)(w()).current,l=c({strict:!1}),[u]=(0,R.useState)(()=>{let e=l.kind,t=e===`live`?`live`:e===`web`?`web`:void 0;return{prompt:l.prompt??``,autoSend:l.send===`1`,appBuild:l.app===`1`,appCategory:l.category,appKind:t}}),d=(0,R.useRef)(Rn()),p=(0,R.useCallback)((e,t)=>{d.current.set(e,t),zn(d.current)},[]),m=u.autoSend?``:u.prompt,b=(0,R.useMemo)(Mn,[]),[x,S]=(0,R.useState)({message:``,version:0}),C=x.message,T=(0,R.useCallback)(e=>{S(t=>({message:typeof e==`function`?e(t.message):e,version:t.version+1}))},[]),[E,D]=(0,R.useState)(!1),[re,ae]=(0,R.useState)(null),[oe,se]=(0,R.useState)(!1),[k,A]=(0,R.useState)(null),[ce,ue]=(0,R.useState)(!1),[fe,pe]=(0,R.useState)(b||null),[me,he]=(0,R.useState)(``),[ge,ve]=(0,R.useState)(`user`),[N,xe]=(0,R.useState)(null),[F,Se]=(0,R.useState)(``),we=(0,R.useRef)(null),Te=Ke(F,160).trim(),{scrollRef:je,contentRef:Ne,isPinned:Re,jumpToBottom:L,resetToBottom:Ue}=wn(),qe=(0,R.useRef)(null),Je=(0,R.useRef)(null);(0,R.useEffect)(()=>{let e=()=>{let e=window.visualViewport?.height??window.innerHeight;!Number.isFinite(e)||e<=0||(document.documentElement.style.setProperty(`--chat-visual-viewport-height`,`${Math.round(e)}px`),document.scrollingElement?.scrollTo({left:0}),document.body.scrollLeft=0,document.documentElement.scrollLeft=0)};return e(),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e),document.documentElement.style.removeProperty(`--chat-visual-viewport-height`)}},[]);let{sessionId:z,getSessionId:B,navigateToSession:Ze,switchToSession:Qe,startFreshChat:$e,ensureSessionForSend:V,handleSessionIdCorrection:tt}=mn();b&&z&&!we.current&&(we.current=z);let nt=z&&we.current===z?b:``,U=(0,R.useCallback)(()=>{i.invalidateQueries({queryKey:Fn(e.token,o)}),i.invalidateQueries({queryKey:H(e.token,B()),refetchType:`none`})},[i,e.token,o,B]),W=le(e),rt=ee(e.token),G=a({queryKey:[`app-status`,e.token],queryFn:()=>v(e.token),staleTime:1/0,enabled:W,initialData:e.status===`ready`&&e.gatewayStatus?e.gatewayStatus:void 0}),it=a({queryKey:[`agents-list`,e.token],queryFn:()=>f(e.token),staleTime:3e4,enabled:W}),at=a({queryKey:[`models`,e.token],queryFn:()=>te(e.token),staleTime:3e4,enabled:W}),ot=a({queryKey:[`skills`,e.token],queryFn:()=>h(e.token),staleTime:6e4,retry:!1,enabled:W});(0,R.useEffect)(()=>{he(G.data?.defaultModel?.trim()??``)},[z,G.data?.defaultModel]),(0,R.useEffect)(()=>{G.error&&(console.error(`Failed to load gateway status for chat page`,G.error),T(`Failed to load the default agent. New chats will use main until gateway status loads.`))},[G.error,T]),(0,R.useEffect)(()=>{at.error&&(console.error(`Failed to load models list for chat page`,at.error),T(`Failed to load the model list. Model switching is unavailable.`))},[at.error,T]);let st=a({queryKey:Pn(e.token,o,Te,ge),queryFn:()=>ze(e.token,o,`web`,Te?Le.maxSearchResults:Le.maxRecentSessions,Te||void 0,ge),staleTime:1e4,enabled:W}),ct=st.data?.sessions??[],lt=(0,R.useMemo)(()=>(it.data??[]).map(e=>({id:e.id,name:e.name,imageUrl:e.imageUrl??null,emptyChatHeader:e.emptyChatHeader??null,source:e.source})),[it.data]),ut=(0,R.useMemo)(()=>new Map((ot.data?.skills??[]).filter(e=>e.userInvocable).map(e=>[e.name.toLowerCase(),e.name])),[ot.data?.skills]),dt=(0,R.useCallback)(e=>{let t=Ye(e);for(let e of t){let t=lt.find(t=>t.id.toLowerCase()===e.agentId.toLowerCase());if(t)return{agentId:t.id,displayName:t.name??t.id,imageUrl:t.imageUrl??null}}return null},[lt]),ft=at.data?.models??En,[q,pt]=(0,R.useState)(null),[mt,ht]=(0,R.useState)(``),J=xn({token:e.token,userId:o,getSessionId:B,setError:T,refreshRecent:U,onSessionIdCorrection:tt,onModelResolved:he,onAppsCaptured:e=>pt(e[e.length-1]??null),resolveAddressedAgentPresentation:dt});(0,R.useEffect)(()=>{let t=!0;if(ht(``),q)return ke(e.token,q.id).then(e=>{t&&ht(e)}).catch(e=>{t&&(pt(null),T(`Could not open app preview: ${M(e)}`))}),()=>{t=!1}},[e.token,q,T]),(0,R.useEffect)(()=>{let e=x.message;if(D(!1),!e)return;let t=window.setTimeout(()=>{D(!0)},Dn),n=window.setTimeout(()=>{T(``),D(!1)},5200);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[x,T]);let Y=a({queryKey:H(e.token,z),queryFn:()=>et(e.token,z,o,nt||void 0),enabled:W&&!!z,staleTime:1/0}),_t=a({queryKey:In(e.token,z),queryFn:()=>Pe(e.token,z),enabled:W&&!!z,staleTime:15e3,refetchOnWindowFocus:!1}),X=Y.data?.messages??Tn,vt=Y.data?.bootstrapAutostart?.status===`starting`,yt=(0,R.useMemo)(()=>vt?[...X,{id:On,role:`thinking`,content:``,sessionId:z}]:X,[vt,X,z]),Z=Y.data?.branchFamilies??Xe,bt=fe?.trim().toLowerCase()||Y.data?.agentId?.trim().toLowerCase()||G.data?.defaultAgentId?.trim().toLowerCase()||`main`,xt=lt.find(e=>e.id.toLowerCase()===bt)?.emptyChatHeader?.trim()||An,Q=r({mutationFn:t=>ie(e.token,t),onSuccess:t=>{if(!t.deleted){T(`Delete failed: session was not found.`);return}let n=t.sessionId;i.removeQueries({queryKey:H(e.token,n)}),i.removeQueries({queryKey:In(e.token,n)}),i.invalidateQueries({queryKey:Fn(e.token,o)}),i.invalidateQueries({queryKey:[`overview`],refetchType:`none`}),xe(null),n===B()&&$e({replace:!0})},onError:e=>{T(`Delete failed: ${M(e)}`)}}),Ct=r({mutationFn:t=>{if(!t.message.messageId)throw Error(`This response cannot be rated right now.`);return Ie(e.token,{sessionId:t.message.sessionId,messageId:t.message.messageId,userId:o,rating:t.rating})},onSuccess:(t,n)=>{let r=n.message.sessionId;i.setQueryData(H(e.token,r),e=>e&&{...e,messages:e.messages.map(e=>e.messageId===t.messageId?{...e,responseRating:t.rating}:e)})},onError:e=>{T(`Rating failed: ${M(e)}`)}});(0,R.useEffect)(()=>{let e=_t.data?.snapshot?.model?.trim()??``;e&&he(e)},[_t.data?.snapshot?.model]),(0,R.useEffect)(()=>{if(b&&we.current===z){pe(b);return}pe(null)},[b,z]),(0,R.useEffect)(()=>{Y.error&&T(M(Y.error))},[Y.error,T]),(0,R.useEffect)(()=>{if(Y.data?.bootstrapAutostart?.status!==`starting`||Y.isFetching)return;let e=window.setTimeout(()=>{Y.refetch()},kn);return()=>window.clearTimeout(e)},[Y.data?.bootstrapAutostart?.status,Y.isFetching,Y.refetch]),(0,R.useEffect)(()=>{if(!k)return;let e=document.body.style.overflow,t=document.activeElement;document.body.style.overflow=`hidden`,Je.current?.focus();let n=e=>{if(e.key===`Escape`){e.preventDefault(),A(null);return}if(e.key!==`Tab`)return;let t=Array.from(qe.current?.querySelectorAll(`a[href], button:not(:disabled)`)??[]);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r?.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n?.focus())};return document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`keydown`,n),document.body.style.overflow=e,t instanceof HTMLElement&&t.focus()}},[k]),(0,R.useEffect)(()=>{if(Y.isPending||Y.fetchStatus!==`idle`||Y.data?.requestedSessionId!==z)return;let e=Y.data?.resolvedSessionId;!e||e===z||Ze(e,{replace:!0})},[Y.data?.requestedSessionId,Y.data?.resolvedSessionId,Y.fetchStatus,Y.isPending,z,Ze]);let wt=(0,R.useMemo)(()=>Nn(X,Z),[X,Z]),Tt=(0,R.useRef)(!1);(0,R.useEffect)(()=>{Tt.current&&!J.isStreaming&&z&&i.invalidateQueries({queryKey:In(e.token,z)}),Tt.current=J.isStreaming},[J.isStreaming,i,e.token,z]),(0,R.useEffect)(()=>{z&&Ue()},[z,Ue]);let Et=(0,R.useCallback)(async(t,n)=>{if(!t.messageId||!t.sessionId){T(`This message cannot be edited right now.`);return}ae(null);try{let r=await Be(e.token,t.sessionId,t.messageId);i.invalidateQueries({queryKey:H(e.token,t.sessionId),refetchType:`none`}),await i.ensureQueryData({queryKey:H(e.token,r.sessionId),queryFn:()=>et(e.token,r.sessionId,o)}),await Qe(r.sessionId),J.sendMessage(n,t.media??[])}catch(e){T(M(e))}},[e.token,i,T,Qe,J.sendMessage,o]),Dt=(0,R.useCallback)(e=>{e.replayRequest&&(L(),J.sendMessage(e.replayRequest.content,e.replayRequest.media,{hideUser:!0}))},[L,J.sendMessage]),$=(0,R.useCallback)(async(e,t)=>{let n=De(e,t);if(n){se(!0);try{L(),await J.sendMessage(n,[],{hideUser:!0})}finally{se(!1)}}},[L,J.sendMessage]),Ot=(0,R.useCallback)((e,t)=>{Ct.mutate({message:e,rating:t})},[Ct]),kt=(0,R.useCallback)(async t=>{let n=await Promise.allSettled(t.map(t=>Fe(e.token,t))),r=[];for(let e of n)e.status===`fulfilled`&&e.value.media?r.push(e.value.media):e.status===`rejected`&&T(M(e.reason));return r},[e.token,T]),At=(0,R.useCallback)(t=>{Ae(e.token,{channelId:`web`,keepSessionId:t}).then(t=>{if(t.deletedCount!==0){for(let n of t.deletedSessionIds)i.removeQueries({queryKey:H(e.token,n)}),i.removeQueries({queryKey:In(e.token,n)});i.invalidateQueries({queryKey:Fn(e.token,o)}),i.invalidateQueries({queryKey:[`overview`],refetchType:`none`})}}).catch(e=>{console.warn(`Failed to clean up no-user chat session`,e)})},[e.token,i,o]),jt=(0,R.useCallback)(()=>{if(J.isActive()){T(`Stop the current run before starting a new chat.`);return}At($e()),U()},[J.isActive,$e,At,U,T]),Mt=(0,R.useCallback)((e,n)=>{let r=/^\/apps?\b[ \t]*([\s\S]*)$/i.exec(e.trim());if(r&&n.length===0){let e=r[1].trim();if(!e){t({to:`/apps`});return}p(V(),{kind:`web`}),L(),J.sendMessage(We(null,e),[],{appBuild:!0,appKind:`web`});return}let i=V();L();let a=d.current.get(i);if(a){J.sendMessage(e,n,{appBuild:!0,...a.category?{appCategory:a.category}:{},...a.kind?{appKind:a.kind}:{}});return}J.sendMessage(e,n)},[V,L,t,p,J.sendMessage]),Nt=(0,R.useRef)(!1);(0,R.useEffect)(()=>{if(Nt.current||!u.autoSend)return;let e=u.prompt.trim();e&&W&&Y.isFetched&&(Nt.current=!0,window.history.replaceState(null,``,window.location.pathname),u.appBuild&&p(V(),{category:u.appCategory,kind:u.appKind}),Mt(e,[]))},[u,W,Y.isFetched,V,p,Mt]);let Pt=(0,R.useCallback)((t,n)=>{let r=n.trim();r&&i.setQueryData(H(e.token,t),e=>{let n=e?.messages??[];return n.some(e=>e.role===`command`&&(e.rawContent||e.content).trim()===r)?e:{messages:[...n,{id:I(),role:`command`,content:r,rawContent:r,sessionId:t,artifacts:[],replayRequest:null}],branchFamilies:e?.branchFamilies??new Map,requestedSessionId:e?.requestedSessionId??t,resolvedSessionId:t,agentId:e?.agentId??null,bootstrapAutostart:e?.bootstrapAutostart??null}})},[e.token,i]),Ft=(0,R.useCallback)(async t=>{let n=H(e.token,t);return i.fetchQuery({queryKey:n,queryFn:()=>et(e.token,t,o),staleTime:0}).catch(e=>(console.warn(`Failed to prefetch chat history before appending switch result`,e),null))},[e.token,i,o]),It=(0,R.useCallback)(async(t,n,r,a)=>{if(!n||/\s/.test(n))return;if(J.isActive()){T(a);return}V();let s=B();try{let a=await Me(e.token,s,o,[...t,n]),c=a.sessionId?.trim()||s,l=await Ft(c);Pt(c,a.text),c!==s&&await Qe(c,{replace:!0}),i.invalidateQueries({queryKey:In(e.token,c)}),t[0]===`agent`&&t[1]===`switch`&&l?.bootstrapAutostart?.fileName===`BOOTSTRAP.md`&&(l.bootstrapAutostart.status===`idle`||l.bootstrapAutostart.status===`starting`)&&(i.setQueryData(H(e.token,c),e=>e&&{...e,bootstrapAutostart:{status:`starting`,fileName:`BOOTSTRAP.md`}}),L()),U(),r(n)}catch(e){T(M(e))}},[Pt,e.token,V,Ft,B,L,i,U,T,J.isActive,Qe,o]),Lt=(0,R.useCallback)(e=>It([`agent`,`switch`],e,pe,`Could not switch agent — stop the current run and try again.`),[It]),Rt=(0,R.useCallback)(e=>It([`model`,`set`],e,he,`Could not switch model — stop the current run and try again.`),[It]),zt=(0,R.useCallback)(e=>{if(J.isActive()){T(`Stop the current run before switching chats.`);return}Ze(e)},[J.isActive,Ze,T]),Bt=(0,R.useCallback)(e=>J.activeSessionId===e?(T(`Stop the current run before deleting this chat.`),!1):!Q.isPending,[Q.isPending,J.activeSessionId,T]),Vt=(0,R.useCallback)(e=>{Bt(e.sessionId)&&xe(e)},[Bt]),Ht=(0,R.useCallback)(()=>{if(!N)throw Error(`Delete confirmation is missing a session.`);Bt(N.sessionId)&&Q.mutate(N.sessionId)},[Bt,Q,N]),Ut=(0,R.useCallback)(t=>{t!==B()&&i.prefetchQuery({queryKey:H(e.token,t),queryFn:()=>et(e.token,t,o),staleTime:3e4})},[i,e.token,B,o]),Wt=(0,R.useCallback)(()=>{i.invalidateQueries({queryKey:Pn(e.token,o,Te,ge)})},[i,e.token,o,Te,ge]),Gt=(0,R.useCallback)(async()=>{let t=B();if(!t){T(`Open or send a chat before creating a mobile QR code.`);return}ue(!0);try{A(await Ve(e.token,{userId:o,sessionId:t,baseUrl:window.location.origin}))}catch(e){T(M(e))}finally{ue(!1)}},[e.token,B,o,T]),Kt=(0,R.useCallback)(e=>{ae(e.id)},[]),qt=(0,R.useCallback)((e,t)=>{let n=e.branchKey;if(!n)return;let r=Z.get(n);if(!r||r.length<2)return;let i=r.findIndex(t=>t.sessionId===e.sessionId);if(i<0)return;let a=i+t;if(a<0||a>=r.length)return;let o=r[a];o&&zt(o.sessionId)},[Z,zt]),Jt=yt.length===0,Yt=Y.isFetching,Xt={sessions:ct,activeSessionId:z,onNewChat:jt,onOpenSession:zt,onHoverSession:Ut,onRequestDeleteSession:Vt,deleteDisabled:Q.isPending,isPending:Yt,searchQuery:F,onSearchQueryChange:Se,recentScope:ge,onRecentScopeChange:ve,isLoading:st.isFetching,onRefreshRecent:Wt};return(0,K.jsx)(g,{children:(0,K.jsxs)(`div`,{className:P.chatPage,"aria-busy":Yt,children:[(0,K.jsx)(He,{...Xt}),(0,K.jsxs)(`div`,{className:P.chatMain,children:[(0,K.jsxs)(`div`,{className:P.chatTopbar,children:[(0,K.jsx)(_,{className:P.chatMobileTrigger}),(0,K.jsx)(St,{sessionId:z,token:e.token,enabled:W}),(0,K.jsx)(`button`,{type:`button`,className:P.mobileQrButton,onClick:()=>void Gt(),disabled:ce,"aria-label":`Show mobile QR code`,title:`Show mobile QR code`,children:(0,K.jsxs)(`span`,{"aria-hidden":`true`,className:P.mobileQrIcon,children:[(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{}),(0,K.jsx)(`span`,{})]})}),(0,K.jsx)(y,{items:rt})]}),k?(0,K.jsx)(`div`,{className:P.mobileQrOverlay,children:(0,K.jsxs)(`div`,{ref:qe,className:P.mobileQrDialog,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`mobile-qr-title`,children:[(0,K.jsxs)(`div`,{className:P.mobileQrHeader,children:[(0,K.jsx)(`h2`,{id:`mobile-qr-title`,children:`Open on mobile`}),(0,K.jsx)(`button`,{ref:Je,type:`button`,className:P.mobileQrClose,onClick:()=>A(null),"aria-label":`Close mobile QR code`,children:`x`})]}),(0,K.jsx)(`div`,{className:P.mobileQrImage,children:(0,K.jsx)(`img`,{src:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(k.qrSvg)}`,alt:`Mobile session QR code`})}),(0,K.jsx)(`a`,{className:P.mobileQrLink,href:k.launchUrl,children:`Open link`})]})}):null,Jt?(0,K.jsx)(`div`,{className:P.emptyState,children:(0,K.jsx)(`h1`,{className:P.greeting,children:xt})}):(0,K.jsx)(`div`,{className:P.messageArea,ref:je,children:(0,K.jsx)(`div`,{className:P.messageList,ref:Ne,children:yt.map(t=>re===t.id&&t.role!==`thinking`&&t.role!==`trace`&&t.role!==`draft`?(0,K.jsx)(`div`,{className:P.messageBlock,children:(0,K.jsx)(pn,{initial:t.rawContent??t.content,onSave:e=>void Et(t,e),onCancel:()=>ae(null)})},t.id):(0,K.jsx)(ln,{message:t,token:e.token,isStreaming:t.id===J.streamingMsgId,onCopy:Ee,onEdit:Kt,onRegenerate:Dt,onRate:Ot,ratingBusy:Ct.isPending&&Ct.variables?.message.id===t.id,skillInvocationTargets:ut,onApprovalAction:$,approvalBusy:oe,branchInfo:wt.get(t.id)??null,onBranchNav:qt},t.id))})}),!Jt&&!Re?(0,K.jsxs)(`button`,{type:`button`,className:P.jumpToLatest,onClick:L,"aria-label":`Jump to latest message`,children:[(0,K.jsx)(`span`,{"aria-hidden":`true`,children:`↓`}),(0,K.jsx)(`span`,{children:`Latest`})]}):null,C?(0,K.jsx)(`div`,{className:`${P.errorBanner} ${E?P.errorBannerExiting:``}`,children:C}):null,(0,K.jsx)(gt,{isStreaming:J.isStreaming,onSend:Mt,onStop:()=>void J.stopRequest(),onUploadFiles:kt,token:e.token,agents:lt,selectedAgentId:bt,onAgentSwitch:e=>void Lt(e),models:ft,selectedModelId:me,onModelSwitch:e=>void Rt(e),initialValue:m})]}),(0,K.jsx)(O,{open:N!==null,onOpenChange:e=>{!e&&!Q.isPending&&xe(null)},children:(0,K.jsxs)(_e,{size:`sm`,role:`alertdialog`,preventCloseOnOutsideClick:Q.isPending,children:[(0,K.jsxs)(ne,{children:[(0,K.jsx)(ye,{children:`Delete session?`}),(0,K.jsx)(be,{children:`This permanently removes the conversation and associated session records.`})]}),(0,K.jsxs)(de,{children:[(0,K.jsx)(Ce,{className:`ghost-button`,disabled:Q.isPending,children:`Cancel`}),(0,K.jsx)(`button`,{type:`button`,className:`danger-button`,disabled:Q.isPending,onClick:Ht,children:Q.isPending?`Deleting...`:`Delete`})]})]})}),(0,K.jsx)(O,{open:q!==null,onOpenChange:e=>{e||pt(null)},children:(0,K.jsxs)(_e,{className:P.appPreviewDialog,"aria-label":`App preview`,children:[(0,K.jsxs)(`div`,{className:P.appPreviewHeader,children:[(0,K.jsx)(ye,{className:P.appPreviewTitle,children:q?.title}),(0,K.jsxs)(`div`,{className:P.appPreviewActions,children:[(0,K.jsx)(`button`,{type:`button`,className:P.appPreviewLink,onClick:()=>{pt(null),t({to:`/apps`})},children:`View in Apps`}),q&&mt?(0,K.jsx)(`a`,{className:P.appPreviewLink,href:Oe(q.id,mt),target:`_blank`,rel:`noreferrer`,children:`Open in new tab ↗`}):null,(0,K.jsx)(Ce,{className:P.appPreviewLink,children:`Close`})]})]}),q&&mt?(0,K.jsx)(Ge,{appId:q.id,className:P.appPreviewFrame,title:q.title,token:mt}):null]})})]})})}export{Bn as ChatPage};
@@ -0,0 +1,5 @@
1
+ import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,o as n}from"./query-o_Dd9s85.js";import{l as r}from"./router-DoNPHesn.js";import{B as i,Dt as a,F as o,G as s,I as c,K as l,Ot as u,R as d,U as f,V as p,W as m,ct as ee,gt as h,jt as g,k as _,r as v,st as y,vt as te,xt as ne,yt as b,z as x}from"./index-CXajfe7-.js";var S=e(t(),1);function C(e,t={}){let n=new URLSearchParams;t.category&&t.category!==`all`&&n.set(`category`,t.category),t.search?.trim()&&n.set(`q`,t.search.trim());let r=n.toString();return u(`/api/apps${r?`?${r}`:``}`,{token:e})}function w(e,t){return u(`/api/apps/${encodeURIComponent(t)}`,{token:e})}function T(e,t){return u(`/api/apps/${encodeURIComponent(t)}`,{token:e,method:`DELETE`})}function E(e,t,n){return u(`/api/apps/${encodeURIComponent(t)}`,{token:e,method:`PATCH`,body:n})}function D(e,t){return u(`/api/apps/${encodeURIComponent(t)}/publications`,{token:e})}function O(e,t,n){return u(`/api/apps/${encodeURIComponent(t)}/publications`,{token:e,method:`POST`,body:n})}function k(e,t,n){return u(`/api/apps/${encodeURIComponent(t)}/publications/${encodeURIComponent(n)}`,{token:e,method:`DELETE`})}async function A(e,t){let n=await fetch(`/api/apps/${encodeURIComponent(t)}/teams-manifest`,{headers:a(e)});return n.ok||await g(n),n.blob()}function j(e,t,n){return u(`/api/apps/${encodeURIComponent(t)}/bridge/tool`,{token:e,method:`POST`,body:n})}function M(e,t){let n=new URLSearchParams({token:t});return`/api/apps/${encodeURIComponent(e)}/view?${n.toString()}`}var N=n();function P(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function F(e){if(!P(e)||e.type!==`hybridclaw:live-app-tool-call`||typeof e.appId!=`string`||typeof e.requestId!=`string`||typeof e.toolName!=`string`)return null;let t=e.arguments;return t!==void 0&&!P(t)?null:{type:`hybridclaw:live-app-tool-call`,appId:e.appId,requestId:e.requestId,toolName:e.toolName,...t===void 0?{}:{arguments:t}}}var I=(0,S.forwardRef)(function(e,t){let n=(0,S.useRef)(null),r=(0,S.useRef)(!1),i=(0,S.useRef)(e.appId);i.current!==e.appId&&(i.current=e.appId,r.current=!1);let a=(0,S.useCallback)(()=>{let t=n.current?.contentWindow;return!t||!r.current?!1:(t.postMessage({type:`hybridclaw:live-app-refresh`,appId:e.appId},`*`),!0)},[e.appId]);return(0,S.useImperativeHandle)(t,()=>({refreshData:a}),[a]),(0,S.useEffect)(()=>{let t=!0,r=(t,r)=>{let i=n.current?.contentWindow;i&&i.postMessage({type:`hybridclaw:live-app-tool-result`,appId:e.appId,requestId:t,...r},`*`)},i=i=>{if(i.source!==n.current?.contentWindow)return;let a=F(i.data);!a||a.appId!==e.appId||j(e.token,e.appId,{toolName:a.toolName,arguments:a.arguments??{}}).then(e=>{t&&r(a.requestId,{ok:!0,payload:e})}).catch(e=>{t&&r(a.requestId,{ok:!1,error:e instanceof Error?e.message:String(e)})})};return window.addEventListener(`message`,i),()=>{t=!1,window.removeEventListener(`message`,i)}},[e.appId,e.token]),(0,S.useEffect)(()=>{!e.refreshNonce||!r.current||a()},[a,e.refreshNonce]),(0,N.jsx)(`iframe`,{ref:n,className:e.className,title:e.title,src:M(e.appId,e.token),sandbox:`allow-scripts allow-forms allow-popups allow-modals allow-downloads`,onLoad:()=>{r.current=!0,e.refreshNonce&&a()}},e.appId)}),L=`
2
+
3
+ <<<APP_BUILD_DIRECTIVE>>>
4
+ `;function R(e){let t=e.indexOf(L);return t===-1?e:e.slice(0,t).trimEnd()}var z='Build one self-contained, fully client-side HTML file (no backend), and save it into the workspace `apps/` folder (e.g. apps/<short-name>.html). Default to React via CDN — load React, ReactDOM, and Babel standalone from a CDN and put your JSX in an inline <script type="text/babel"> so it stays a single HTML file. Use a different stack only if I ask. Design it with care — if you have a frontend-design skill, use it; otherwise apply strong fundamentals (clear layout, sensible typography, responsive, accessible, modern). When you finish, the app is automatically published to my Apps gallery and opened as a preview with its own link — no external hosting needed, so just build it.',B='For live refresh inside the Apps viewer, never call `/api/mcp/...` or other gateway URLs directly. Generated HTML runs in a sandbox and must use `window.hybridclaw.callMcpTool("<namespaced_mcp_tool>", { ... })` (or `window.hybridclaw.callTool`) from its refresh action. Register the same refresh function with `window.hybridclaw.setRefreshHandler(refresh)` when that API exists, so the Apps viewer Refresh button updates data in place instead of rebuilding the app. Shared apps may receive server-verified viewer details at `window.hybridclaw.context.user`; use it only when present. Keep an embedded snapshot fallback so the app still works outside the Apps viewer or when the bridge is unavailable.';function V(e,t){return`${e}${L}${t.join(`
5
+ `)}`}function H(e,t){let n=t.trim();return n?V(e?`Let's build a ${e} web app. Here's my idea: ${n}`:`Let's build a web app. Here's my idea: ${n}`,[`Don't ask me a list of questions — use best-practice defaults for anything I didn't specify, and don't suggest a different app (I already know what I want).`,`First propose a short plan (your key decisions, a few bullets), then wait for my OK and build it. ${z}`]):V(e?`Let's build a ${e} web app.`:`Let's build a web app.`,[`Ask me one quick question about what I want, then propose a short plan, wait for my OK, and build it.`,z])}function U(e){let t=e.trim(),n=`build it as a live app that embeds the latest data pulled from those connectors, with a refresh action. ${B} ${z}`,r=`Assume my connected MCP servers / tools are the data source: if a relevant connector is available, use it directly to fetch the data — do not ask me which data source or connector to use.`;return t?V(`I want to create a live app that uses my connected tools. Here's my idea: ${t}`,[r,`Don't ask me a list of questions — use best-practice defaults for anything I didn't specify (scope, fields, sorting, refresh), and don't suggest a different app (I already know what I want). Tell me only if something essential is missing.`,`First propose a short plan (your key decisions, a few bullets), then wait for my OK and ${n}`]):V(`I want to create a live app that uses my connected tools.`,[r,`Suggest the most useful live app or dashboard you can build with my connectors (briefly list a couple of options and recommend one).`,`Once I pick, propose a short plan, wait for my OK, and ${n}`])}var W=1800*1e3;async function G(e,t){let n=new Date(Date.now()+W).toISOString();return(await b(e,{label:`App view ${t.slice(0,48)}`,claims:{actions:[`apps.view`,`apps.bridge`],appIds:[t]},expiresAt:n})).token}function K(e,t,n=`web`,r=10,i,a){let o=new URLSearchParams({userId:t,channelId:n,limit:String(r)});return i&&o.set(`q`,i),a&&o.set(`scope`,a),u(`/api/chat/recent?${o.toString()}`,{token:e})}function re(e,t){let n=new URLSearchParams({channelId:t.channelId||`web`});return t.keepSessionId&&n.set(`keepSessionId`,t.keepSessionId),u(`/api/chat/cleanup?${n.toString()}`,{token:e,method:`POST`})}function q(e,t,n=80,r,i){let a=new URLSearchParams({sessionId:t,limit:String(n)});return r&&a.set(`userId`,r),i?.trim()&&a.set(`agentId`,i.trim()),u(`/api/history?${a.toString()}`,{token:e})}function J(e,t){return u(`/api/chat/context?${new URLSearchParams({sessionId:t}).toString()}`,{token:e})}function Y(e,t){return u(t?`/api/chat/commands?q=${encodeURIComponent(t)}`:`/api/chat/commands`,{token:e})}function X(e,t){return u(`/api/chat/mobile-qr`,{token:e,method:`POST`,body:t})}function ie(e,t,n){return u(`/api/chat/branch`,{token:e,method:`POST`,body:{sessionId:t,beforeMessageId:n}})}function ae(e,t){return u(`/api/chat/rating`,{token:e,method:`POST`,body:t})}function oe(e,t,n,r){return u(`/api/command`,{token:e,method:`POST`,body:te({sessionId:t,args:r,userId:n,username:`web`})})}function se(e,t){return u(`/api/media/upload`,{token:e,method:`POST`,rawBody:t,extraHeaders:{"Content-Type":t.type||`application/octet-stream`,"X-Hybridclaw-Filename":encodeURIComponent(t.name||`upload`)}})}function ce(e){return`/api/artifact?${new URLSearchParams({path:e}).toString()}`}function le(e){return e}async function Z(e,t){let n=await fetch(t,{headers:a(e),cache:`no-store`});if(!n.ok){let e=(n.headers.get(`content-type`)||``).toLowerCase().trim(),t=`${n.status} ${n.statusText}`;if(e.includes(`application/json`)){let e=await n.json().catch(()=>null);t=e?.error||e?.text||t}else{let e=(await n.text().catch(()=>``)).trim();e&&(t=e)}throw n.status===401&&ne(t),Error(t)}return n.blob()}async function ue(e,t){return Z(e,ce(t))}function de(e,t){return Z(e,le(t))}var fe={maxRecentSessions:10,maxSearchResults:50};function Q(e){let{children:t,...n}=e;return(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,strokeLinejoin:`round`,width:`100%`,height:`100%`,"aria-hidden":`true`,...n,children:t})}function pe(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`rect`,{x:`4`,y:`4`,width:`7`,height:`7`,rx:`1.5`}),(0,N.jsx)(`rect`,{x:`13`,y:`4`,width:`7`,height:`7`,rx:`1.5`}),(0,N.jsx)(`rect`,{x:`4`,y:`13`,width:`7`,height:`7`,rx:`1.5`}),(0,N.jsx)(`rect`,{x:`13`,y:`13`,width:`7`,height:`7`,rx:`1.5`})]})}function me(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`path`,{d:`M20 11a8 8 0 1 0-2.3 5.7`}),(0,N.jsx)(`path`,{d:`M20 5v6h-6`})]})}function $(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`rect`,{x:`3.5`,y:`5`,width:`17`,height:`14`,rx:`2`}),(0,N.jsx)(`path`,{d:`M3.5 9h17`}),(0,N.jsx)(`path`,{d:`M6.5 7h.01M8.5 7h.01`})]})}function he(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`path`,{d:`M7 3h7l4 4v14H7z`}),(0,N.jsx)(`path`,{d:`M14 3v4h4`}),(0,N.jsx)(`path`,{d:`M9.5 12h5M9.5 15h5M9.5 9h2`})]})}function ge(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`rect`,{x:`3`,y:`8`,width:`18`,height:`9`,rx:`4.5`}),(0,N.jsx)(`path`,{d:`M7 11.5v3M5.5 13h3`}),(0,N.jsx)(`path`,{d:`M15.5 12h.01M17.5 14h.01`})]})}function _e(e){return(0,N.jsx)(Q,{...e,children:(0,N.jsx)(`path`,{d:`M13 3 5 13h6l-1 8 8-10h-6z`})})}function ve(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`path`,{d:`M3 21c0-3 2-4 4-4 1.5 0 2.5 1 2.5 2.5S8 21 6 21z`}),(0,N.jsx)(`path`,{d:`M9 17 19.5 6.5a2.1 2.1 0 0 0-3-3L6 14`})]})}function ye(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`rect`,{x:`5`,y:`4`,width:`14`,height:`17`,rx:`2`}),(0,N.jsx)(`path`,{d:`M9 4.5h6V7H9z`}),(0,N.jsx)(`path`,{d:`m8.5 12 1.5 1.5 2.5-3`}),(0,N.jsx)(`path`,{d:`M14.5 12.5h2`})]})}function be(e){return(0,N.jsxs)(Q,{...e,children:[(0,N.jsx)(`path`,{d:`M12 4v6M9 7h6`}),(0,N.jsx)(`path`,{d:`M6 16.5 7 19l2.5 1L7 21l-1 2.5L5 21l-2.5-1L5 19z`,transform:`translate(0 -3)`}),(0,N.jsx)(`path`,{d:`M17 13l.7 1.8 1.8.7-1.8.7L17 18l-.7-1.8-1.8-.7 1.8-.7z`})]})}var xe={apps:$,documents:he,games:ge,productivity:_e,creative:ve,quiz:ye,scratch:be};function Se(e){let{category:t,...n}=e;return(0,N.jsx)(xe[t]??$,{...n})}function Ce(e){let t=h(),n=m(),a=r(),u=e.searchQuery.trim().length>0;return(0,S.useEffect)(()=>{n.openMobile&&e.onRefreshRecent?.()},[e.onRefreshRecent,n.openMobile]),(0,N.jsxs)(d,{side:`left`,collapsible:`icon`,children:[(0,N.jsxs)(p,{children:[(0,N.jsxs)(`div`,{className:s.headerRow,children:[(0,N.jsx)(o,{}),(0,N.jsx)(f,{className:s.sidebarToggle})]}),(0,N.jsxs)(`button`,{type:`button`,className:v.newChatButton,onClick:e.onNewChat,children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`+`}),(0,N.jsx)(`span`,{children:`New Conversation`})]}),(0,N.jsxs)(`button`,{type:`button`,className:v.newChatButton,onClick:()=>a({to:`/apps`}),children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,className:v.navLinkIcon,children:(0,N.jsx)(pe,{})}),(0,N.jsx)(`span`,{children:`Apps`})]}),(0,N.jsx)(`div`,{className:v.sidebarSearchWrap,children:(0,N.jsx)(`input`,{type:`search`,className:v.sidebarSearch,value:e.searchQuery,onChange:t=>e.onSearchQueryChange(t.target.value),placeholder:`Search`,"aria-label":`Search conversations`})})]}),(0,N.jsx)(x,{children:(0,N.jsx)(we,{...e,isSearching:u})}),(0,N.jsx)(i,{children:(0,N.jsxs)(`div`,{className:s.footerBlock,children:[(0,N.jsx)(c,{version:t.gatewayStatus?.version}),(0,N.jsx)(l,{labelClassName:s.themeToggleLabel})]})})]})}function we(e){return(0,N.jsxs)(`div`,{className:v.chatSidebarContent,children:[(0,N.jsxs)(`div`,{className:v.sidebarListHeader,children:[(0,N.jsx)(`div`,{className:v.sidebarLabel,children:e.isSearching?`Search Results`:`Recent Chats`}),(0,N.jsx)(`div`,{className:v.sidebarScopeToggle,children:[`user`,`all`].map(t=>(0,N.jsx)(`button`,{type:`button`,className:y(v.sidebarScopeButton,e.recentScope===t&&v.sidebarScopeButtonActive),"aria-pressed":e.recentScope===t,onClick:()=>e.onRecentScopeChange(t),children:t===`user`?`User`:`All`},t))})]}),e.isLoading&&e.isSearching?(0,N.jsx)(`div`,{className:v.sidebarStatus,children:`Searching...`}):e.sessions.length===0?(0,N.jsx)(`div`,{className:v.sidebarStatus,children:e.isSearching?`No matching conversations.`:`No recent chats yet.`}):(0,N.jsx)(`ul`,{className:v.sessionList,"aria-live":`polite`,children:e.sessions.map(t=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`div`,{className:v.sessionItemRow,children:[(0,N.jsxs)(`button`,{type:`button`,className:y(v.sessionItem,t.sessionId===e.activeSessionId&&v.sessionItemActive,t.sessionId===e.activeSessionId&&e.isPending&&v.sessionItemPending),"aria-current":t.sessionId===e.activeSessionId?`page`:void 0,onMouseEnter:()=>e.onHoverSession?.(t.sessionId),onClick:()=>e.onOpenSession(t.sessionId),children:[(0,N.jsx)(`span`,{className:v.sessionTitle,children:t.title||`Untitled`}),t.searchSnippet?(0,N.jsx)(`span`,{className:v.sessionSnippet,children:t.searchSnippet}):null,(0,N.jsx)(`span`,{className:v.sessionTime,children:_(t.lastActive)})]}),(0,N.jsx)(`button`,{type:`button`,className:v.sessionDeleteButton,"aria-label":`Delete ${t.title||`Untitled`} session`,title:`Delete session`,disabled:e.deleteDisabled,onClick:()=>e.onRequestDeleteSession(t),children:(0,N.jsx)(ee,{className:v.sessionDeleteIcon})})]})},t.sessionId))})]})}export{E as A,O as C,D,w as E,C as O,M as S,A as T,G as _,re as a,R as b,oe as c,Y as d,J as f,se as g,ae as h,fe as i,k,de as l,K as m,Se as n,ie as o,q as p,me as r,X as s,Ce as t,ue as u,H as v,T as w,I as x,U as y};