agentix-cli 0.181.1 → 0.182.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +2 -2
  2. package/apps/mac-voice/Sources/AgentXVoice/Config.swift +9 -0
  3. package/apps/mac-voice/Sources/AgentXVoice/MiniOrbs.swift +19 -6
  4. package/apps/mac-voice/Sources/AgentXVoice/OpenRequests.swift +260 -0
  5. package/apps/mac-voice/Sources/AgentXVoice/Panel.swift +72 -5
  6. package/apps/mac-voice/Sources/AgentXVoice/PillBusy.swift +22 -4
  7. package/apps/mac-voice/Sources/AgentXVoice/PillPlacement.swift +24 -0
  8. package/apps/mac-voice/Sources/AgentXVoice/RequestsWindow.swift +401 -0
  9. package/apps/mac-voice/Sources/AgentXVoice/SettingsWindow.swift +1 -0
  10. package/apps/mac-voice/Sources/AgentXVoice/StatusMenu.swift +22 -1
  11. package/apps/mac-voice/Sources/AgentXVoice/main.swift +263 -4
  12. package/dist/{App-UXX5TGFF.js → App-XWSSUYKF.js} +2 -2
  13. package/dist/{ChatApp-X635NOAE.js → ChatApp-UT2BRHYE.js} +2 -2
  14. package/dist/{absorb-eval-4ZPDWNBA.js → absorb-eval-SFGUURBD.js} +2 -2
  15. package/dist/{adapter-Z23K544D.js → adapter-UHR7FVM7.js} +2 -2
  16. package/dist/{agent-OBRH5BJZ.js → agent-5NTFSCEO.js} +2 -2
  17. package/dist/{board-dashboard-SFXVOICJ.js → board-dashboard-7HIME2W4.js} +2090 -2248
  18. package/dist/board-dashboard-7HIME2W4.js.map +1 -0
  19. package/dist/{chunk-SDINSYTN.js → chunk-343MPMLD.js} +2 -2
  20. package/dist/{chunk-WKU7YFDV.js → chunk-4KNHLHE3.js} +2 -2
  21. package/dist/{chunk-WZUY7VGL.js → chunk-4WSJKKSA.js} +2 -2
  22. package/dist/{chunk-ZSY6PFHD.js → chunk-5NGQQOVK.js} +2 -2
  23. package/dist/{chunk-FRVFRWFN.js → chunk-5YG2ZQQW.js} +2 -2
  24. package/dist/{chunk-N6VBEITO.js → chunk-7PQQZC6B.js} +2 -2
  25. package/dist/{chunk-N6VBEITO.js.map → chunk-7PQQZC6B.js.map} +1 -1
  26. package/dist/{chunk-7RVJWLIP.js → chunk-7WGJZLVJ.js} +2 -2
  27. package/dist/{chunk-CF7CPE7K.js → chunk-BY3AUZYM.js} +2 -2
  28. package/dist/{chunk-IRZYRLXQ.js → chunk-FDX4IGLK.js} +2 -2
  29. package/dist/{chunk-SD6UDSXV.js → chunk-FYFJ7IQJ.js} +2 -2
  30. package/dist/{chunk-HBQRVCLU.js → chunk-GEFZMDDX.js} +2 -2
  31. package/dist/{chunk-TZ7GB7FI.js → chunk-H2KOXGDX.js} +2 -2
  32. package/dist/{chunk-UFUQQ5J5.js → chunk-IFHVAHQM.js} +2 -2
  33. package/dist/{chunk-LZY6YN2J.js → chunk-IGBW4VVM.js} +2 -2
  34. package/dist/{chunk-OYCMFCME.js → chunk-JNWXHOJE.js} +2 -2
  35. package/dist/{chunk-KOY3EOPH.js → chunk-MD2HCGSC.js} +36 -36
  36. package/dist/chunk-MD2HCGSC.js.map +1 -0
  37. package/dist/{chunk-PCWXHXTM.js → chunk-NIPMVM3G.js} +2 -2
  38. package/dist/{chunk-DOBTHQ32.js → chunk-NRUUT5TL.js} +2 -2
  39. package/dist/{chunk-Z2UDWVZZ.js → chunk-OKADR5QO.js} +4 -4
  40. package/dist/chunk-OKADR5QO.js.map +1 -0
  41. package/dist/{chunk-IYITREE5.js → chunk-QB6UPODO.js} +2 -2
  42. package/dist/{chunk-VK3M3TVL.js → chunk-QGNV2HA4.js} +3 -3
  43. package/dist/chunk-QGNV2HA4.js.map +1 -0
  44. package/dist/{chunk-KVAWRQBA.js → chunk-R3CDFSNF.js} +67 -67
  45. package/dist/chunk-R3CDFSNF.js.map +1 -0
  46. package/dist/{chunk-HMEFQL5P.js → chunk-RDWDDPBI.js} +4 -3
  47. package/dist/chunk-RDWDDPBI.js.map +1 -0
  48. package/dist/{chunk-QJXGJMHM.js → chunk-XHJ5SVO5.js} +234 -234
  49. package/dist/chunk-XHJ5SVO5.js.map +1 -0
  50. package/dist/chunk-XI2HH5NR.js +36 -0
  51. package/dist/chunk-XI2HH5NR.js.map +1 -0
  52. package/dist/{chunk-J56YGKUO.js → chunk-Y4TVCWWF.js} +2 -2
  53. package/dist/{chunk-33DLG4I2.js → chunk-Y5TBOMHY.js} +5 -5
  54. package/dist/{chunk-UHTIZCKU.js → chunk-YSPBVLTZ.js} +2 -2
  55. package/dist/{chunk-NI2XD6P3.js → chunk-YX4R2VGD.js} +2 -2
  56. package/dist/{chunk-U5S6IP7Z.js → chunk-Z4XVPGPZ.js} +3 -3
  57. package/dist/{chunk-DMCMV4UJ.js → chunk-ZRALOFEG.js} +2 -2
  58. package/dist/cli.js +1 -1
  59. package/dist/{client-ILPJFCTF.js → client-SQMU25PS.js} +2 -2
  60. package/dist/{config-JVWOL233.js → config-56NBA4SF.js} +2 -2
  61. package/dist/{config-mutate-WYCHP6VK.js → config-mutate-PD4O3HZ7.js} +2 -2
  62. package/dist/config-mutator-ITL64FBW.js +2 -0
  63. package/dist/{contributions-XD66HYWE.js → contributions-DKTJ623L.js} +2 -2
  64. package/dist/{doctor-DYTYJQYC.js → doctor-OI6GJZR5.js} +2 -2
  65. package/dist/{follow-up-tool-HPET6LZW.js → follow-up-tool-DYSLS6ZI.js} +2 -2
  66. package/dist/{hub-L5FFJPS3.js → hub-4HDMTSR7.js} +2 -2
  67. package/dist/index.d.ts +317 -216
  68. package/dist/index.js +1 -1
  69. package/dist/processes-M7YPWX7H.js +2 -0
  70. package/dist/{program-24C3VBSD.js → program-4GDIWCDM.js} +259 -259
  71. package/dist/program-4GDIWCDM.js.map +1 -0
  72. package/dist/{promote-XI6W27JK.js → promote-3272TZNI.js} +2 -2
  73. package/dist/{query-MGG5QKNC.js → query-7XM6V4QG.js} +2 -2
  74. package/dist/{query-settings-CALZYYWD.js → query-settings-HHVBIIVQ.js} +2 -2
  75. package/dist/{registry-XJWSLJ4O.js → registry-QL3AM3UH.js} +2 -2
  76. package/dist/{request-planner-JCRGGJUO.js → request-planner-WNEDEA7X.js} +2 -2
  77. package/dist/{review-candidates-OEBEEAEZ.js → review-candidates-TGPDJMWJ.js} +2 -2
  78. package/dist/{routing-CGH54RYG.js → routing-ALXY25NE.js} +2 -2
  79. package/dist/schedule-tool-22UBZXCG.js +2 -0
  80. package/dist/{scheduler-2K5YEV2U.js → scheduler-5PHNW243.js} +2 -2
  81. package/dist/{seat-DEL5YUOS.js → seat-ZYVVEILY.js} +2 -2
  82. package/dist/{select-MRTWSI7U.js → select-6QLEV6AC.js} +2 -2
  83. package/dist/{set-enabled-XTDCFCZY.js → set-enabled-SYYTKJPC.js} +2 -2
  84. package/dist/{sprint-tool-N7WPDX5J.js → sprint-tool-PYVHPHR2.js} +2 -2
  85. package/dist/{tool-BQEJOTF3.js → tool-GIYOYXXM.js} +2 -2
  86. package/dist/{tool-NZTJZDSB.js → tool-TDOUM3BJ.js} +2 -2
  87. package/dist/{tool-KZHWJ7BC.js → tool-ZKZ4KYJT.js} +2 -2
  88. package/dist/{wiki-YERCKD3E.js → wiki-ZRGLGMII.js} +2 -2
  89. package/dist/wiki-enrich-CTID7JQW.js +2 -0
  90. package/package.json +1 -1
  91. package/dist/board-dashboard-SFXVOICJ.js.map +0 -1
  92. package/dist/chunk-G6ZRPC6E.js +0 -36
  93. package/dist/chunk-G6ZRPC6E.js.map +0 -1
  94. package/dist/chunk-HMEFQL5P.js.map +0 -1
  95. package/dist/chunk-KOY3EOPH.js.map +0 -1
  96. package/dist/chunk-KVAWRQBA.js.map +0 -1
  97. package/dist/chunk-QJXGJMHM.js.map +0 -1
  98. package/dist/chunk-VK3M3TVL.js.map +0 -1
  99. package/dist/chunk-Z2UDWVZZ.js.map +0 -1
  100. package/dist/config-mutator-DKNHE6VP.js +0 -2
  101. package/dist/processes-EWARF6ZW.js +0 -2
  102. package/dist/program-24C3VBSD.js.map +0 -1
  103. package/dist/schedule-tool-UM3CAPDX.js +0 -2
  104. package/dist/wiki-enrich-K54LGNU3.js +0 -2
  105. /package/dist/{App-UXX5TGFF.js.map → App-XWSSUYKF.js.map} +0 -0
  106. /package/dist/{ChatApp-X635NOAE.js.map → ChatApp-UT2BRHYE.js.map} +0 -0
  107. /package/dist/{absorb-eval-4ZPDWNBA.js.map → absorb-eval-SFGUURBD.js.map} +0 -0
  108. /package/dist/{adapter-Z23K544D.js.map → adapter-UHR7FVM7.js.map} +0 -0
  109. /package/dist/{agent-OBRH5BJZ.js.map → agent-5NTFSCEO.js.map} +0 -0
  110. /package/dist/{chunk-SDINSYTN.js.map → chunk-343MPMLD.js.map} +0 -0
  111. /package/dist/{chunk-WKU7YFDV.js.map → chunk-4KNHLHE3.js.map} +0 -0
  112. /package/dist/{chunk-WZUY7VGL.js.map → chunk-4WSJKKSA.js.map} +0 -0
  113. /package/dist/{chunk-ZSY6PFHD.js.map → chunk-5NGQQOVK.js.map} +0 -0
  114. /package/dist/{chunk-FRVFRWFN.js.map → chunk-5YG2ZQQW.js.map} +0 -0
  115. /package/dist/{chunk-7RVJWLIP.js.map → chunk-7WGJZLVJ.js.map} +0 -0
  116. /package/dist/{chunk-CF7CPE7K.js.map → chunk-BY3AUZYM.js.map} +0 -0
  117. /package/dist/{chunk-IRZYRLXQ.js.map → chunk-FDX4IGLK.js.map} +0 -0
  118. /package/dist/{chunk-SD6UDSXV.js.map → chunk-FYFJ7IQJ.js.map} +0 -0
  119. /package/dist/{chunk-HBQRVCLU.js.map → chunk-GEFZMDDX.js.map} +0 -0
  120. /package/dist/{chunk-TZ7GB7FI.js.map → chunk-H2KOXGDX.js.map} +0 -0
  121. /package/dist/{chunk-UFUQQ5J5.js.map → chunk-IFHVAHQM.js.map} +0 -0
  122. /package/dist/{chunk-LZY6YN2J.js.map → chunk-IGBW4VVM.js.map} +0 -0
  123. /package/dist/{chunk-OYCMFCME.js.map → chunk-JNWXHOJE.js.map} +0 -0
  124. /package/dist/{chunk-PCWXHXTM.js.map → chunk-NIPMVM3G.js.map} +0 -0
  125. /package/dist/{chunk-DOBTHQ32.js.map → chunk-NRUUT5TL.js.map} +0 -0
  126. /package/dist/{chunk-IYITREE5.js.map → chunk-QB6UPODO.js.map} +0 -0
  127. /package/dist/{chunk-J56YGKUO.js.map → chunk-Y4TVCWWF.js.map} +0 -0
  128. /package/dist/{chunk-33DLG4I2.js.map → chunk-Y5TBOMHY.js.map} +0 -0
  129. /package/dist/{chunk-UHTIZCKU.js.map → chunk-YSPBVLTZ.js.map} +0 -0
  130. /package/dist/{chunk-NI2XD6P3.js.map → chunk-YX4R2VGD.js.map} +0 -0
  131. /package/dist/{chunk-U5S6IP7Z.js.map → chunk-Z4XVPGPZ.js.map} +0 -0
  132. /package/dist/{chunk-DMCMV4UJ.js.map → chunk-ZRALOFEG.js.map} +0 -0
  133. /package/dist/{client-ILPJFCTF.js.map → client-SQMU25PS.js.map} +0 -0
  134. /package/dist/{config-JVWOL233.js.map → config-56NBA4SF.js.map} +0 -0
  135. /package/dist/{config-mutate-WYCHP6VK.js.map → config-mutate-PD4O3HZ7.js.map} +0 -0
  136. /package/dist/{config-mutator-DKNHE6VP.js.map → config-mutator-ITL64FBW.js.map} +0 -0
  137. /package/dist/{contributions-XD66HYWE.js.map → contributions-DKTJ623L.js.map} +0 -0
  138. /package/dist/{doctor-DYTYJQYC.js.map → doctor-OI6GJZR5.js.map} +0 -0
  139. /package/dist/{follow-up-tool-HPET6LZW.js.map → follow-up-tool-DYSLS6ZI.js.map} +0 -0
  140. /package/dist/{hub-L5FFJPS3.js.map → hub-4HDMTSR7.js.map} +0 -0
  141. /package/dist/{processes-EWARF6ZW.js.map → processes-M7YPWX7H.js.map} +0 -0
  142. /package/dist/{promote-XI6W27JK.js.map → promote-3272TZNI.js.map} +0 -0
  143. /package/dist/{query-MGG5QKNC.js.map → query-7XM6V4QG.js.map} +0 -0
  144. /package/dist/{query-settings-CALZYYWD.js.map → query-settings-HHVBIIVQ.js.map} +0 -0
  145. /package/dist/{registry-XJWSLJ4O.js.map → registry-QL3AM3UH.js.map} +0 -0
  146. /package/dist/{request-planner-JCRGGJUO.js.map → request-planner-WNEDEA7X.js.map} +0 -0
  147. /package/dist/{review-candidates-OEBEEAEZ.js.map → review-candidates-TGPDJMWJ.js.map} +0 -0
  148. /package/dist/{routing-CGH54RYG.js.map → routing-ALXY25NE.js.map} +0 -0
  149. /package/dist/{schedule-tool-UM3CAPDX.js.map → schedule-tool-22UBZXCG.js.map} +0 -0
  150. /package/dist/{scheduler-2K5YEV2U.js.map → scheduler-5PHNW243.js.map} +0 -0
  151. /package/dist/{seat-DEL5YUOS.js.map → seat-ZYVVEILY.js.map} +0 -0
  152. /package/dist/{select-MRTWSI7U.js.map → select-6QLEV6AC.js.map} +0 -0
  153. /package/dist/{set-enabled-XTDCFCZY.js.map → set-enabled-SYYTKJPC.js.map} +0 -0
  154. /package/dist/{sprint-tool-N7WPDX5J.js.map → sprint-tool-PYVHPHR2.js.map} +0 -0
  155. /package/dist/{tool-BQEJOTF3.js.map → tool-GIYOYXXM.js.map} +0 -0
  156. /package/dist/{tool-NZTJZDSB.js.map → tool-TDOUM3BJ.js.map} +0 -0
  157. /package/dist/{tool-KZHWJ7BC.js.map → tool-ZKZ4KYJT.js.map} +0 -0
  158. /package/dist/{wiki-YERCKD3E.js.map → wiki-ZRGLGMII.js.map} +0 -0
  159. /package/dist/{wiki-enrich-K54LGNU3.js.map → wiki-enrich-CTID7JQW.js.map} +0 -0
@@ -88,6 +88,21 @@ final class App: NSObject, NSApplicationDelegate {
88
88
  /// would hear the next answer as the listener's words.
89
89
  private var openAsides = 0
90
90
 
91
+ // Send and move on (#1455): a request outside a call runs on its own,
92
+ // and its answer waits in the open-requests list until it is picked.
93
+
94
+ /// Every request sent outside a call, until it has been heard.
95
+ private var requests = OpenRequests()
96
+ /// Each answered request's answer, until its row leaves the list.
97
+ private var answers: [Int: AgentClient.Answer] = [:]
98
+ /// The list beside the pill.
99
+ private let requestsWindow = RequestsWindow()
100
+ private var listHotkey: Hotkey?
101
+ /// Opens the list after half a second's hover on the pill.
102
+ private var hoverOpen: DispatchWorkItem?
103
+ /// Puts the pill back to rest after a passing line.
104
+ private var noteReset: DispatchWorkItem?
105
+
91
106
  // An agent ringing the owner (#321).
92
107
  private let callWatcher = CallWatcher()
93
108
  private let guideWatcher = GuideWatcher()
@@ -153,6 +168,7 @@ final class App: NSObject, NSApplicationDelegate {
153
168
  private func publishThinking() {
154
169
  var counts = inFlight
155
170
  for (agent, words) in waitingAsides { counts[agent, default: 0] += words.count }
171
+ for (agent, n) in requests.waiting { counts[agent, default: 0] += n }
156
172
  statusMenu.thinking = counts
157
173
  }
158
174
 
@@ -166,9 +182,11 @@ final class App: NSObject, NSApplicationDelegate {
166
182
  let queue = statusMenu.queue
167
183
  var snap = PillBusy.Snapshot()
168
184
  snap.inFlight = inFlight
169
- snap.waiting = waitingAsides.mapValues(\.count)
185
+ snap.waiting = waitingAsides.mapValues(\.count).merging(requests.waiting, uniquingKeysWith: +)
170
186
  snap.playing = queue?.playing?.agentId
171
187
  snap.toSpeak = queue?.waiting.compactMap(\.agentId) ?? []
188
+ snap.ready = requests.readyAgents
189
+ snap.failed = requests.failedAgents
172
190
  let items = PillBusy.items(snap, order: busyOrder)
173
191
  busyOrder = items.map(\.agentID)
174
192
  let mainActive = recorder.isRecording || busy || asideSpeaker != nil
@@ -205,9 +223,10 @@ final class App: NSObject, NSApplicationDelegate {
205
223
  else { Log.warn("shortcut \(spec.text ?? "?") for \(what) is taken by another app") }
206
224
  }
207
225
 
208
- // Hold to talk; release sends.
226
+ // Hold to talk; release sends. With a row picked by the keyboard in
227
+ // the open-requests list, the words go to that row's agent.
209
228
  let talk = Hotkey(id: 1,
210
- onPress: { [weak self] in self?.forcedAgent = nil; self?.startListening() },
229
+ onPress: { [weak self] in self?.forcedAgent = self?.listAgent; self?.startListening() },
211
230
  onRelease: { [weak self] in self?.stopAndSend() })
212
231
  register(talk, spec(keys?.talk, "opt+space"), "talk")
213
232
  hotkey = talk
@@ -229,6 +248,11 @@ final class App: NSObject, NSApplicationDelegate {
229
248
  register(menu, HotkeySpec("cmd+opt+a")!, "the menu")
230
249
  menuHotkey = menu
231
250
 
251
+ // The open-requests list, with the keyboard in it (#1455).
252
+ let list = Hotkey(id: 5, onPress: {}, onRelease: { [weak self] in self?.openList(keyboard: true) })
253
+ register(list, HotkeySpec("cmd+opt+o")!, "open requests")
254
+ listHotkey = list
255
+
232
256
  // Hold an agent's own shortcut to ask it; the target stays.
233
257
  for (i, agent) in (settings?.agents ?? []).enumerated() {
234
258
  guard let text = agent.voice.hotkey, let s = HotkeySpec(text) else { continue }
@@ -243,7 +267,7 @@ final class App: NSObject, NSApplicationDelegate {
243
267
 
244
268
  /// Dropping a Hotkey unregisters it.
245
269
  private func unregisterHotkeys() {
246
- hotkey = nil; pasteHotkey = nil; stopHotkey = nil; menuHotkey = nil
270
+ hotkey = nil; pasteHotkey = nil; stopHotkey = nil; menuHotkey = nil; listHotkey = nil
247
271
  agentHotkeys.removeAll()
248
272
  }
249
273
 
@@ -361,6 +385,7 @@ final class App: NSObject, NSApplicationDelegate {
361
385
  if ringingCall != nil { endRinging { await CallClient.decline($0) } }
362
386
  if activeCall != nil { hangUp() }
363
387
  panel.dismiss()
388
+ requestsWindow.dismissList()
364
389
  character.setHidden(true)
365
390
  if recorder.isRecording {
366
391
  stopPolling()
@@ -474,6 +499,17 @@ final class App: NSObject, NSApplicationDelegate {
474
499
  return self.statusMenu.palette(of: self.shownAgent)
475
500
  }
476
501
  panel.answer.onOpenChat = { [weak self] in self?.openChat() }
502
+ // The open-requests list (#1455): a click on the mini orbs or "1 new",
503
+ // half a second's hover, ⌘⌥O or the menu opens it.
504
+ requestsWindow.rows = { [weak self] newestLast in self?.listRows(newestLast: newestLast) ?? [] }
505
+ requestsWindow.pillFrame = { [weak self] in self?.panel.frame ?? .zero }
506
+ requestsWindow.model.onPick = { [weak self] id in self?.pick(id) }
507
+ panel.onOpenList = { [weak self] in self?.openList(keyboard: false) }
508
+ panel.onHover = { [weak self] inside in self?.pillHover(inside) }
509
+ statusMenu.onOpenRequests = { [weak self] in self?.openList(keyboard: true) }
510
+ statusMenu.shortcut = { [weak self] id in
511
+ self?.settings?.agents.first(where: { $0.id == id })?.voice.hotkey.map(HotkeySpec.display)
512
+ }
477
513
  panel.answer.onListenAgain = { [weak self] in self?.listenAgain() }
478
514
  statusMenu.pillVisible = { [weak self] in self?.panel.isVisible ?? false }
479
515
  statusMenu.onHidePill = { [weak self] in self?.dismissPill() }
@@ -760,6 +796,7 @@ final class App: NSObject, NSApplicationDelegate {
760
796
  // two ways of talking never fight over the microphone.
761
797
  stopPolling()
762
798
  play.end("the talk key")
799
+ requestsWindow.dismissList()
763
800
  guard !recorder.isRecording else { return }
764
801
  // A dismissed pill comes back with the talk key.
765
802
  summonPill()
@@ -864,6 +901,15 @@ final class App: NSObject, NSApplicationDelegate {
864
901
  statusMenu.learn(addressed)
865
902
  agent = addressed.agentID
866
903
  }
904
+ // Send and move on (#1455): outside a call, a request runs on its
905
+ // own and the pill is free for the next one at once. Its answer
906
+ // waits in the open-requests list as not heard.
907
+ if activeCall == nil {
908
+ if !midTurn { busy = false }
909
+ if Self.isStop(heard) { stopSpeaking(); return }
910
+ send(heard, agent: agent)
911
+ return
912
+ }
867
913
  if midTurn {
868
914
  // Another agent: ask it alongside ours rather than waiting.
869
915
  if agent != turnAgent && !Self.isStop(heard) {
@@ -898,6 +944,219 @@ final class App: NSObject, NSApplicationDelegate {
898
944
  }
899
945
  }
900
946
 
947
+ // --- Open requests (#1455) ---
948
+
949
+ /// Send a request and move on: it runs on its own, or waits behind the
950
+ /// one its agent is still thinking about.
951
+ private func send(_ heard: String, agent: String) {
952
+ let id = requests.add(agentID: agent, question: heard, at: Date())
953
+ Log.info("request \(id) → \(agent)\(requests.request(id)?.phase == .waiting ? " (waits its turn)" : ""): \(heard)")
954
+ if requests.request(id)?.phase == .thinking { run(id) }
955
+ requestsChanged()
956
+ note("\(statusMenu.name(of: agent)) · \(OpenRequests.sentNote)")
957
+ }
958
+
959
+ /// Ask the agent. The answer waits as not heard, with a soft sound, or
960
+ /// plays at once with "Play answers at once" ticked. The agent's next
961
+ /// request goes as soon as this one is back.
962
+ private func run(_ id: Int) {
963
+ guard let r = requests.request(id) else { return }
964
+ Task { @MainActor in
965
+ let result: Result<AgentClient.Answer, Error>
966
+ do { result = .success(try await ask(r.question, agent: r.agentID)) }
967
+ catch { result = .failure(error) }
968
+ let now = Date()
969
+ switch result {
970
+ case .success(let answer) where answer.dropped:
971
+ Log.info("request \(id): the daemon took the words for the floor holder's sound")
972
+ requests.remove(id)
973
+ case .success(let answer):
974
+ Log.info("request \(id) answered (\(answer.agentID ?? r.agentID)): \(answer.text)")
975
+ answers[id] = answer
976
+ requests.answered(id, at: now)
977
+ case .failure(let error):
978
+ Log.warn("request \(id) failed (\(r.agentID)): \(error.localizedDescription)")
979
+ requests.failed(id, reason: Self.reason(error), at: now)
980
+ }
981
+ if let next = requests.startNext(for: r.agentID, at: now) { run(next) }
982
+ requestsChanged()
983
+ guard let done = requests.request(id) else { return }
984
+ if done.phase == .answered && Config.playAnswersAtOnce {
985
+ await waitForFloor(r.agentID, ownTurn: false)
986
+ if requests.request(id)?.heard == false { play(id) }
987
+ return
988
+ }
989
+ cue(done)
990
+ }
991
+ }
992
+
993
+ /// Why a request failed, in a line the list and the pill can show.
994
+ private static func reason(_ error: Error) -> String {
995
+ let text = error.localizedDescription.trimmingCharacters(in: .whitespacesAndNewlines)
996
+ guard !text.isEmpty else { return "Something went wrong." }
997
+ return text.count > 140 ? String(text.prefix(139)) + "…" : text
998
+ }
999
+
1000
+ /// An answer is back, or a request failed: one soft sound, and a line
1001
+ /// on the pill for a few seconds. Nothing plays.
1002
+ private func cue(_ r: OpenRequests.Request) {
1003
+ let name = statusMenu.name(of: r.agentID)
1004
+ if case .failed = r.phase { note(OpenRequests.failedNote(name: name)) }
1005
+ else { note(OpenRequests.readyNote(name: name)) }
1006
+ // Quiet while notifications are held, while someone holds the floor,
1007
+ // and while the microphone is open, which would hear it.
1008
+ if !Hold.isOn && !floorWatcher.state.held && !recorder.isRecording { NSSound(named: "Pop")?.play() }
1009
+ }
1010
+
1011
+ /// A passing line on the pill at rest, back to the pill's own after
1012
+ /// a few seconds. Not over listening, a turn, a call or an answer
1013
+ /// being said.
1014
+ private func note(_ text: String) {
1015
+ guard !recorder.isRecording, !busy, asideSpeaker == nil, activeCall == nil, ringingCall == nil else { return }
1016
+ noteReset?.cancel()
1017
+ panel.render(.note(text))
1018
+ let reset = DispatchWorkItem { [weak self] in
1019
+ MainActor.assumeIsolated {
1020
+ guard let self, case .note(let shown) = self.panel.current, shown == text,
1021
+ !self.recorder.isRecording, !self.busy else { return }
1022
+ self.panel.render(self.rest)
1023
+ }
1024
+ }
1025
+ noteReset = reset
1026
+ DispatchQueue.main.asyncAfter(deadline: .now() + OpenRequests.noteSeconds, execute: reset)
1027
+ }
1028
+
1029
+ /// The pill and the list follow the requests: the mini orbs, "1 new",
1030
+ /// the menu's states and the list's rows.
1031
+ private func requestsChanged() {
1032
+ // Rows that left the list take their answers with them.
1033
+ let kept = Set(requests.requests.map(\.id))
1034
+ answers = answers.filter { kept.contains($0.key) }
1035
+ publishThinking()
1036
+ refreshBusy()
1037
+ panel.showNew(requests.newCount)
1038
+ statusMenu.ready = requests.readyAgents
1039
+ requestsWindow.reload()
1040
+ }
1041
+
1042
+ /// The agent of the row the keyboard is on in the open list.
1043
+ private var listAgent: String? {
1044
+ requestsWindow.selectedRow.flatMap { requests.request($0)?.agentID }
1045
+ }
1046
+
1047
+ /// Open the list: by a click (no keyboard), or by ⌘⌥O or the menu
1048
+ /// (the keyboard lands on the oldest answer not heard yet).
1049
+ private func openList(keyboard: Bool) {
1050
+ hoverOpen?.cancel()
1051
+ hoverOpen = nil
1052
+ if keyboard { summonPill() }
1053
+ requestsWindow.open(.pinned, select: keyboard ? requests.firstSelection : nil)
1054
+ }
1055
+
1056
+ /// Half a second on the pill opens the list, while there is a request
1057
+ /// to show; leaving the pill lets a list opened that way go.
1058
+ private func pillHover(_ inside: Bool) {
1059
+ hoverOpen?.cancel()
1060
+ hoverOpen = nil
1061
+ guard inside else { requestsWindow.pointerLeft(); return }
1062
+ guard !requests.requests.isEmpty, !requestsWindow.isOpen, !recorder.isRecording else { return }
1063
+ let open = DispatchWorkItem { [weak self] in
1064
+ MainActor.assumeIsolated {
1065
+ guard let self, self.panel.hovering, !self.recorder.isRecording else { return }
1066
+ self.requestsWindow.open(.hover)
1067
+ }
1068
+ }
1069
+ hoverOpen = open
1070
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: open)
1071
+ }
1072
+
1073
+ /// The list's rows, as OpenRequests words them.
1074
+ private func listRows(newestLast: Bool) -> [RequestsModel.Row] {
1075
+ let now = Date()
1076
+ return requests.rows(newestLast: newestLast).map { r in
1077
+ let name = statusMenu.name(of: r.agentID)
1078
+ let cue: RequestsModel.Row.Cue
1079
+ let action: String?
1080
+ switch r.phase {
1081
+ case .waiting: cue = .waiting; action = nil
1082
+ case .thinking: cue = .thinking; action = nil
1083
+ case .answered: cue = r.heard ? .heard : .ready; action = r.heard ? "Show the answer" : "Listen"
1084
+ case .failed: cue = .failed; action = "See why"
1085
+ }
1086
+ return RequestsModel.Row(
1087
+ id: r.id, name: name, state: OpenRequests.stateWords(r, now: now),
1088
+ words: OpenRequests.firstWords(r.question),
1089
+ ago: OpenRequests.ago(Int(now.timeIntervalSince(r.sentAt))),
1090
+ cue: cue, isNew: r.isNew,
1091
+ tint: statusMenu.color(of: r.agentID), colors: statusMenu.palette(of: r.agentID),
1092
+ voiceOver: OpenRequests.voiceOver(name: name, r, now: now), action: action)
1093
+ }
1094
+ }
1095
+
1096
+ /// A row picked in the list: an answer not heard plays, a heard one
1097
+ /// shows its text again (Listen again plays it), a failure says why.
1098
+ private func pick(_ id: Int) {
1099
+ guard let r = requests.request(id) else { return }
1100
+ let action = OpenRequests.pick(r)
1101
+ guard action != .nothing else { return }
1102
+ requestsWindow.dismissList()
1103
+ switch action {
1104
+ case .nothing: return
1105
+ case .listen: play(id)
1106
+ case .show: showAgain(id)
1107
+ case .reason(let why):
1108
+ requests.heard(id)
1109
+ requestsChanged()
1110
+ note("\(statusMenu.name(of: r.agentID)) couldn’t answer: \(why)")
1111
+ }
1112
+ }
1113
+
1114
+ /// Play an answer: heard from now on, its text in the pill, said in
1115
+ /// its agent's voice on the daemon's speaking queue. Listen again, or
1116
+ /// the stop shortcut, stops it.
1117
+ private func play(_ id: Int) {
1118
+ guard let r = requests.request(id), let answer = answers[id] else { return }
1119
+ requests.heard(id)
1120
+ requestsChanged()
1121
+ let agent = answer.agentID ?? r.agentID
1122
+ Log.info("request \(id): playing (\(agent))")
1123
+ endReplay()
1124
+ // An open microphone would take the answer for the listener's words.
1125
+ if recorder.isRecording {
1126
+ stopPolling()
1127
+ _ = recorder.stop()
1128
+ }
1129
+ if AnswerView.isWorthShowing(spoken: answer.text, written: answer.written,
1130
+ buttons: answer.buttons, imageURL: answer.imageURL) {
1131
+ panel.showAnswer(spoken: answer.text, written: answer.written,
1132
+ buttons: answer.buttons, imageURL: answer.imageURL)
1133
+ }
1134
+ shownAnswer = (answer.text, agent, answer.voice)
1135
+ noteReset?.cancel()
1136
+ let onScreen = !busy
1137
+ if onScreen { asideSpeaker = agent; panel.render(.saying(answer.text)) }
1138
+ panel.answer.setReplaying(true)
1139
+ let line = Task { await Speech.say(answer.text, agentID: agent, kind: "answer", voice: answer.voice) }
1140
+ replaying = line
1141
+ Task { @MainActor [weak self] in
1142
+ await line.value
1143
+ guard let self else { return }
1144
+ if self.replaying == line { self.endReplay() }
1145
+ if onScreen && self.asideSpeaker == agent {
1146
+ self.asideSpeaker = nil
1147
+ if !self.busy && !self.recorder.isRecording { self.panel.render(self.rest) }
1148
+ }
1149
+ }
1150
+ }
1151
+
1152
+ /// A heard answer again: its text in the pill, with Listen again.
1153
+ private func showAgain(_ id: Int) {
1154
+ guard let r = requests.request(id), let answer = answers[id] else { return }
1155
+ panel.showAnswer(spoken: answer.text, written: answer.written,
1156
+ buttons: answer.buttons, imageURL: answer.imageURL)
1157
+ shownAnswer = (answer.text, answer.agentID ?? r.agentID, answer.voice)
1158
+ }
1159
+
901
1160
  /// Someone holds the floor (#924): the answer is kept, and shown and
902
1161
  /// said once it is free. Until then nothing of it is on screen.
903
1162
  private func waitForFloor(_ agent: String?, ownTurn: Bool = true) async {
@@ -1,8 +1,8 @@
1
- import{a as F,b as L,c as U,d as N,e as O,f as H,g as j}from"./chunk-U2CKL755.js";import{b as B,c as D,d as A,e as P,g as M}from"./chunk-LZY6YN2J.js";import"./chunk-KOY3EOPH.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{useEffect as R,useReducer as V,useRef as G}from"react";import{Box as i,Text as o,useApp as W,useInput as J}from"ink";import{randomUUID as z}from"crypto";async function*q(e){let r=[];e.type&&r.push(`type=${encodeURIComponent(e.type)}`);let t=`${e.baseUrl.replace(/\/+$/,"")}/events${r.length?`?${r.join("&")}`:""}`,n={Accept:"text/event-stream"};e.token&&(n.Authorization=`Bearer ${e.token}`);let s=await fetch(t,{headers:n,signal:e.signal});if(!s.ok||!s.body)throw new Error(`SSE connect failed: HTTP ${s.status}`);let u=s.body.getReader(),p=new TextDecoder,y="";try{for(;;){let{done:f,value:l}=await u.read();if(f)return;y+=p.decode(l,{stream:!0});let d;for(;(d=y.indexOf(`
1
+ import{a as F,b as L,c as U,d as N,e as O,f as H,g as j}from"./chunk-U2CKL755.js";import{b as B,c as D,d as A,e as P,g as M}from"./chunk-IGBW4VVM.js";import"./chunk-MD2HCGSC.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{useEffect as R,useReducer as V,useRef as G}from"react";import{Box as i,Text as o,useApp as W,useInput as J}from"ink";import{randomUUID as z}from"crypto";async function*q(e){let r=[];e.type&&r.push(`type=${encodeURIComponent(e.type)}`);let t=`${e.baseUrl.replace(/\/+$/,"")}/events${r.length?`?${r.join("&")}`:""}`,n={Accept:"text/event-stream"};e.token&&(n.Authorization=`Bearer ${e.token}`);let s=await fetch(t,{headers:n,signal:e.signal});if(!s.ok||!s.body)throw new Error(`SSE connect failed: HTTP ${s.status}`);let u=s.body.getReader(),p=new TextDecoder,y="";try{for(;;){let{done:f,value:l}=await u.read();if(f)return;y+=p.decode(l,{stream:!0});let d;for(;(d=y.indexOf(`
2
2
 
3
3
  `))>=0;){let h=y.slice(0,d);y=y.slice(d+2);let m=X(h);m&&(yield m)}}}finally{try{u.releaseLock()}catch{}}}function X(e){let r="message",t="";for(let s of e.split(`
4
4
  `))s.startsWith("event: ")?r=s.slice(7):s.startsWith("data: ")&&(t=s.slice(6));if(!t)return null;let n;try{n=JSON.parse(t)}catch{n=t}return{event:r,data:n}}import{jsx as a,jsxs as c}from"react/jsx-runtime";function $(e,r){return r<=0||e<0?0:e>=r?r-1:e}function E(){return`tui:${z().slice(0,12)}`}function k(e,r){let t=[...e,r];return t.length>50&&t.splice(0,t.length-50),t}function Y(e,r){switch(r.type){case"agents":return{...e,agents:r.data,cursor:{...e.cursor,agents:$(e.cursor.agents,r.data.length)}};case"processes":return{...e,processes:r.data,cursor:{...e.cursor,processes:$(e.cursor.processes,r.data.length)}};case"crons":return{...e,crons:r.data};case"event":{let t=[r.row,...e.events];t.length>200&&(t.length=200);let n=e.channels;return r.channelTally&&(n=new Map(e.channels),n.set(r.channelTally.channel,r.channelTally)),{...e,events:t,channels:n}}case"connError":return{...e,connError:r.error};case"tick":return{...e,lastTick:Date.now()};case"focus":return{...e,focus:r.pane};case"cursor":{let t=r.pane==="agents"?e.agents.length:r.pane==="processes"?e.processes.length:e.events.length;return{...e,cursor:{...e.cursor,[r.pane]:$(e.cursor[r.pane]+r.delta,t)}}}case"bottomRight":return{...e,bottomRight:r.pane};case"chatStart":return{...e,chat:{active:!0,agentId:r.agentId,chatId:E(),history:[],text:"",status:"idle",error:null}};case"chatExit":return{...e,chat:{...e.chat,active:!1}};case"chatClear":return{...e,chat:{...e.chat,chatId:E(),history:[],text:"",status:"idle",error:null}};case"chatText":return{...e,chat:{...e.chat,text:r.text}};case"chatSubmitStart":return{...e,chat:{...e.chat,history:k(e.chat.history,r.you),text:"",status:"sending",error:null}};case"chatSubmitDone":return{...e,chat:{...e.chat,history:k(e.chat.history,r.reply),status:"idle",error:null}};case"chatSubmitError":return{...e,chat:{...e.chat,history:k(e.chat.history,{role:"error",text:r.error,at:Date.now()}),status:"idle",error:r.error}};case"chatStreamStart":{let t=k(e.chat.history,r.you),n=k(t,{role:"agent",text:"",at:Date.now(),streaming:!0,tools:[]});return{...e,chat:{...e.chat,history:n,text:"",status:"sending",error:null}}}case"chatStreamDelta":{let t=e.chat.history.slice(),n=t[t.length-1];return n?.role==="agent"&&n.streaming&&(t[t.length-1]={...n,text:n.text+r.text}),{...e,chat:{...e.chat,history:t}}}case"chatStreamThinking":{let t=e.chat.history.slice(),n=t[t.length-1];return n?.role==="agent"&&n.streaming&&(t[t.length-1]={...n,thinking:(n.thinking??"")+r.text}),{...e,chat:{...e.chat,history:t}}}case"chatStreamTool":{let t=e.chat.history.slice(),n=t[t.length-1];return n?.role==="agent"&&n.streaming&&(t[t.length-1]={...n,tools:[...n.tools??[],{name:r.name,arg:r.arg,error:r.error}]}),{...e,chat:{...e.chat,history:t}}}case"chatStreamEnd":{let t=e.chat.history.slice(),n=t[t.length-1];return n?.role==="agent"&&n.streaming&&(t[t.length-1]=r.error?{...n,streaming:!1,role:"error",text:r.error}:{...n,streaming:!1,elapsedMs:r.elapsedMs,outTokens:r.outTokens}),{...e,chat:{...e.chat,history:t,status:"idle",error:r.error??null}}}case"toast":return{...e,toast:{text:r.text,color:r.color,at:Date.now()}};case"clearToast":return{...e,toast:null}}}var _={agents:[],processes:[],crons:[],events:[],channels:new Map,connError:null,lastTick:0,focus:"agents",cursor:{agents:0,processes:0,events:0},bottomRight:"crons",chat:{active:!1,agentId:null,chatId:E(),history:[],text:"",status:"idle",error:null},toast:null};function be({conn:e,pollMs:r=3e3}){let[t,n]=V(Y,_),{exit:s}=W(),u=G(null),p=G(null),y=t.agents.map(l=>l.id),f=t.chat.active?L(t.chat.text,y,process.cwd()):null;return R(()=>{if(!t.toast)return;let l=setTimeout(()=>n({type:"clearToast"}),3500);return()=>clearTimeout(l)},[t.toast]),J((l,d)=>{if(t.chat.active){if(d.escape){n({type:"chatExit"});return}if(d.ctrl&&l==="l"){n({type:"chatClear"});return}if(d.tab){let m=U(t.chat.text,p,y,process.cwd());m!==null&&n({type:"chatText",text:m});return}if(d.backspace||d.delete){p.current=null,n({type:"chatText",text:t.chat.text.slice(0,-1)});return}if(d.ctrl||d.meta)return;let h=N(l??"",d.return,t.chat.text);if(h.kind==="paste"||h.kind==="type"){p.current=null,n({type:"chatText",text:t.chat.text+h.text});return}if(h.kind==="continue"){n({type:"chatText",text:h.buffer});return}if(h.kind==="submit"){let m=h.text.trim(),g=t.chat.agentId;if(!m||!g||t.chat.status==="sending"){n({type:"chatText",text:""});return}p.current=null;let b=Date.now(),w=t.chat.chatId;n({type:"chatStreamStart",you:{role:"you",text:m,at:b}}),(async()=>{try{let C=await M(e,g,m,{channel:"tui",chatId:w,onText:x=>n({type:"chatStreamDelta",text:x}),onThinking:x=>n({type:"chatStreamThinking",text:x}),onTool:x=>{x.status==="start"&&x.name?n({type:"chatStreamTool",name:x.name,arg:x.arg}):x.status==="result"&&x.error&&n({type:"chatStreamTool",name:x.name??"tool",error:!0})}});n({type:"chatStreamEnd",elapsedMs:Date.now()-b,outTokens:C.usage?.outputTokens,error:C.error})}catch(C){n({type:"chatStreamEnd",elapsedMs:Date.now()-b,error:C?.message||String(C)})}})();return}return}if(l==="q"||d.ctrl&&l==="c"){u.current?.abort(),s();return}if(d.tab){let h=["agents","processes","events"],m=h.indexOf(t.focus);n({type:"focus",pane:h[(m+1)%h.length]});return}if(l==="a"){n({type:"focus",pane:"agents"});return}if(l==="p"){n({type:"focus",pane:"processes"});return}if(l==="e"){n({type:"focus",pane:"events"});return}if(l==="c"){n({type:"bottomRight",pane:t.bottomRight==="crons"?"channels":"crons"});return}if(d.upArrow){n({type:"cursor",pane:t.focus,delta:-1});return}if(d.downArrow){n({type:"cursor",pane:t.focus,delta:1});return}if(d.return&&t.focus==="agents"){let h=t.agents[t.cursor.agents];if(!h){n({type:"toast",text:"no agent selected",color:"yellow"});return}n({type:"chatStart",agentId:h.id});return}if(l==="k"&&t.focus==="processes"){let h=t.processes[t.cursor.processes];if(!h){n({type:"toast",text:"no process selected",color:"yellow"});return}(async()=>{try{await P(e,h.key,"tui"),n({type:"toast",text:`killed ${h.key.agentId}/${h.key.channel}/${h.key.chatId}`,color:"green"})}catch(m){n({type:"toast",text:`kill failed: ${m?.message||m}`,color:"red"})}})();return}}),R(()=>{let l=new AbortController;u.current=l;let d=!1,h=async()=>{try{let[g,b,w]=await Promise.all([B(e,l.signal).catch(()=>[]),D(e,l.signal).catch(()=>[]),A(e,l.signal).catch(()=>[])]);if(d)return;n({type:"agents",data:g}),n({type:"processes",data:b}),n({type:"crons",data:w}),n({type:"tick"}),n({type:"connError",error:null})}catch(g){d||n({type:"connError",error:g?.message||String(g)})}};h();let m=setInterval(h,r);return()=>{d=!0,clearInterval(m),l.abort()}},[e.baseUrl,e.token,r]),R(()=>{let l=!1,d=new AbortController,h=new Map;return(async()=>{let m=500;for(;!l;){try{for await(let g of q({baseUrl:e.baseUrl,token:e.token,signal:d.signal})){let b=ae(g),w;if(g.event==="channel"&&typeof g.data?.channel=="string"){let S=h.get(g.data.channel)??{channel:g.data.channel,inbound:0,outbound:0,lastAt:0,lastPreview:""},C=S.inbound+(g.data.direction==="in"?1:0),x=S.outbound+(g.data.direction==="out"?1:0);w={channel:g.data.channel,inbound:C,outbound:x,lastAt:b.at,lastPreview:(g.data.textPreview||"").slice(0,60)},h.set(g.data.channel,w)}n({type:"event",row:b,channelTally:w}),m=500}}catch(g){if(l)return;n({type:"connError",error:`events: ${g?.message||g}`})}await new Promise(g=>setTimeout(g,m)),m=Math.min(m*2,1e4)}})(),()=>{l=!0,d.abort()}},[e.baseUrl,e.token]),c(i,{flexDirection:"column",width:"100%",children:[a(K,{conn:e,lastTick:t.lastTick,connError:t.connError,chat:t.chat}),c(i,{flexDirection:"row",flexGrow:1,children:[c(i,{flexDirection:"column",width:"50%",children:[a(v,{title:"AGENTS",focused:!t.chat.active&&t.focus==="agents",children:a(Z,{rows:t.agents,cursor:t.cursor.agents,focused:!t.chat.active&&t.focus==="agents",talkingTo:t.chat.active?t.chat.agentId:null})}),a(v,{title:"PROCESSES",focused:!t.chat.active&&t.focus==="processes",children:a(ee,{rows:t.processes,cursor:t.cursor.processes,focused:!t.chat.active&&t.focus==="processes"})})]}),t.chat.active?a(oe,{chat:t.chat,suggest:f,agents:t.agents}):c(i,{flexDirection:"column",width:"50%",children:[a(v,{title:"LIVE EVENTS",focused:t.focus==="events",children:a(ne,{rows:t.events,cursor:t.cursor.events,focused:t.focus==="events"})}),a(v,{title:t.bottomRight==="crons"?"CRONS / SCHEDULES":"CHANNELS",focused:!1,children:t.bottomRight==="crons"?a(te,{rows:t.crons}):a(re,{rows:Array.from(t.channels.values())})})]})]}),a(Q,{focus:t.focus,bottomRight:t.bottomRight,chat:t.chat,toast:t.toast})]})}function K({conn:e,lastTick:r,connError:t,chat:n}){let s=t?c(o,{color:"red",children:["\u25CF ",t]}):r===0?a(o,{color:"yellow",children:"\u25CF connecting\u2026"}):a(o,{color:"green",children:"\u25CF live"}),u=n.active?c(o,{color:"green",bold:!0,children:["CHAT @",n.agentId]}):a(o,{bold:!0,children:"agentx tui"});return c(i,{paddingX:1,justifyContent:"space-between",children:[a(i,{children:u}),a(o,{dimColor:!0,children:e.baseUrl}),a(i,{children:s})]})}function Q({focus:e,bottomRight:r,chat:t,toast:n}){let s=t.active?["[Enter] send","[Esc] exit chat","[Ctrl-L] new session"]:[`[Tab/a/p/e] focus (now: ${e})`,e==="agents"?"[Enter] chat":null,e==="processes"?"[k] kill":null,`[c] ${r==="crons"?"\u2192channels":"\u2192crons"}`,"[\u2191/\u2193] move","[q] quit"].filter(Boolean);return c(i,{paddingX:1,borderStyle:"single",borderTop:!0,borderBottom:!1,borderLeft:!1,borderRight:!1,justifyContent:"space-between",children:[a(o,{dimColor:!0,children:s.join(" \xB7 ")}),n?a(o,{color:n.color,children:n.text}):a(o,{children:" "})]})}function v({title:e,focused:r,children:t}){return c(i,{flexDirection:"column",width:"100%",borderStyle:r?"double":"single",borderColor:r?"cyan":void 0,paddingX:1,children:[c(o,{bold:!0,color:r?"cyan":"white",children:[e,r?" \u25CF":""]}),a(i,{flexDirection:"column",marginTop:1,children:t})]})}function I(e,r){return e&&r?{inverse:!0}:{}}function Z({rows:e,cursor:r,focused:t,talkingTo:n}){return e.length===0?a(o,{dimColor:!0,children:"no agents"}):a(i,{flexDirection:"column",children:e.slice(0,12).map((s,u)=>{let p=I(t,u===r),y=s.errors>0?"red":s.active>0?"yellow":"green",f=s.id===n;return c(i,{children:[a(o,{...p,color:y,children:"\u25CF"}),c(o,{...p,children:[" ",T(s.name,14)]}),c(o,{...p,children:[T(s.tier,6)," "]}),c(o,{...p,children:[s.active,"/",s.total]}),s.errors>0?c(o,{...p,color:"red",children:[" err=",s.errors]}):null,f?a(o,{color:"green",children:" \u2194 chatting"}):null]},s.id)})})}function ee({rows:e,cursor:r,focused:t}){if(e.length===0)return a(o,{dimColor:!0,children:"no live processes"});let n=Date.now();return a(i,{flexDirection:"column",children:e.slice(0,12).map((s,u)=>{let p=I(t,u===r),y=Math.max(0,Math.round((n-(s.lastTurnAt||s.spawnedAt))/1e3)),f=s.state==="dead"?"red":s.state==="warm-hot"?"green":"yellow";return c(i,{children:[a(o,{...p,color:f,children:T(s.state,10)}),a(o,{...p,children:T(s.key.agentId,12)}),a(o,{...p,children:T(s.key.channel,10)}),c(o,{...p,children:[s.turnCount,"t ",y,"s"]})]},`${s.key.agentId}-${s.key.channel}-${s.key.chatId}-${u}`)})})}function te({rows:e}){return e.length===0?a(o,{dimColor:!0,children:"no crons"}):a(i,{flexDirection:"column",children:e.slice(0,12).map(r=>{let t=r.enabled?r.consecutiveErrors>0?a(o,{color:"red",children:"err"}):a(o,{color:"green",children:"ok"}):a(o,{dimColor:!0,children:"off"}),n=r.nextRun?new Date(r.nextRun).toLocaleTimeString():"\u2014";return c(i,{children:[a(o,{children:T(r.id,16)}),a(o,{dimColor:!0,children:T(r.schedule,12)}),a(o,{children:T(n,10)}),a(i,{children:t})]},r.id)})})}function re({rows:e}){if(e.length===0)return a(o,{dimColor:!0,children:"(waiting for channel events\u2026)"});let r=[...e].sort((t,n)=>n.lastAt-t.lastAt);return a(i,{flexDirection:"column",children:r.slice(0,12).map(t=>c(i,{children:[a(o,{children:T(t.channel,12)}),c(o,{color:"cyan",children:["\u2190",T(String(t.inbound),4)]}),c(o,{color:"magenta",children:["\u2192",T(String(t.outbound),4)]}),a(o,{dimColor:!0,children:t.lastPreview})]},t.channel))})}function ne({rows:e,cursor:r,focused:t}){return e.length===0?a(o,{dimColor:!0,children:"(waiting for events\u2026)"}):a(i,{flexDirection:"column",children:e.slice(0,18).map((n,s)=>{let u=I(t,s===r);return c(i,{children:[a(o,{...u,dimColor:!0,children:new Date(n.at).toLocaleTimeString().padEnd(10)}),a(o,{...u,color:ce(n.kind),children:T(n.kind,8)}),a(o,{...u,children:n.line})]},`${n.at}-${s}`)})})}function oe({chat:e,suggest:r,agents:t}){let n=e.history.slice(-14),s=t.find(f=>f.id===e.agentId),u=H(s?.tier??"",s?.model),p=e.status==="sending"?[...e.history].reverse().find(f=>f.role==="agent"&&f.streaming):void 0,y=e.status==="sending"?a(O,{startedAt:p?.at??Date.now(),phase:p?.text?"responding":"thinking",indent:""}):e.error?c(o,{color:"red",children:["\u25CF ",e.error]}):a(o,{dimColor:!0,children:"\u25CF ready"});return c(i,{flexDirection:"column",width:"50%",borderStyle:"double",borderColor:"green",paddingX:1,children:[c(i,{justifyContent:"space-between",children:[c(o,{bold:!0,color:"green",children:["CHAT \xB7 @",e.agentId]}),a(i,{children:y})]}),c(o,{children:[c(o,{color:u.color,bold:!0,children:[u.glyph," ",u.label]}),s?.model?c(o,{dimColor:!0,children:[" ",j(s.model)]}):null,c(o,{dimColor:!0,children:[" \xB7 ",e.chatId]})]}),a(i,{flexDirection:"column",flexGrow:1,marginTop:1,children:n.length===0?a(o,{dimColor:!0,children:"(type a message and press Enter \u2014 Esc exits, Ctrl-L starts fresh)"}):n.map((f,l)=>a(se,{turn:f,agentId:e.agentId},`${f.at}-${l}`))}),r?c(o,{dimColor:!0,children:[a(o,{color:"cyan",children:"\u21B9"})," ",r.items.slice(0,5).map((f,l)=>l===0?a(o,{color:"cyan",children:f},l):c(o,{children:[" ",f]},l))]}):null,c(i,{children:[a(o,{color:"cyan",children:"you \u203A "}),a(o,{children:e.text}),a(o,{inverse:!0,children:" "})]})]})}function se({turn:e,agentId:r}){if(e.role==="you")return c(i,{flexDirection:"column",marginBottom:1,children:[a(o,{color:"cyan",children:"you"}),e.text.split(`
5
5
  `).map((s,u)=>c(o,{children:[" ",s]},u))]});if(e.role==="error")return c(i,{flexDirection:"column",marginBottom:1,children:[a(o,{color:"red",children:"error"}),c(o,{color:"red",children:[" ",e.text]})]});let t=e.elapsedMs!=null?` \xB7 ${(e.elapsedMs/1e3).toFixed(1)}s${e.outTokens!=null?`, ${e.outTokens} tok`:""}`:e.streaming?" \xB7 \u2026":"",n=F(e.text,58,{balance:e.streaming});return c(i,{flexDirection:"column",marginBottom:1,children:[c(o,{color:"green",children:["@",r??"agent",a(o,{dimColor:!0,children:t})]}),e.thinking?e.thinking.split(`
6
6
  `).filter(s=>s.trim()).slice(-2).map((s,u)=>c(o,{dimColor:!0,italic:!0,children:[" ",s]},`th${u}`)):null,(e.tools??[]).map((s,u)=>c(o,{color:s.error?"red":"green",children:[" \u25CF ",c(o,{bold:!s.error,dimColor:s.error,children:[s.name,s.arg?c(o,{dimColor:!0,children:["(",s.arg,")"]}):null,s.error?" failed":""]})]},`tool${u}`)),n.split(`
7
7
  `).slice(0,14).map((s,u)=>c(o,{children:[" ",s]},u))]})}function ae(e){let r=e.data??{},t=typeof r.at=="string"||typeof r.at=="number"?new Date(r.at).getTime():Date.now(),n="";switch(e.event){case"run":n=`${r.phase??""} ${r.workflowId??""} ${(r.runId??"").slice(0,8)} ${r.nodeId??""}`.trim();break;case"task":n=`${r.phase??""} ${r.workflowId??""} ${Array.isArray(r.assignedTo)?r.assignedTo.join(","):""} ${r.title?`"${r.title}"`:""}`.trim();break;case"signal":n=`${r.name??""} (${r.scope??""}) ${r.workflowId??""}`.trim();break;case"mesh":n=`${r.peer??""} ${r.healthy?"healthy":"lost"} ${r.delta??""}`.trim();break;case"channel":{n=`${r.direction==="in"?"\u2190":"\u2192"} ${r.channel??""}:${r.chatId??""} ${r.textPreview??""}`.trim();break}case"status":n=`node=${r.node??""} agents=${r.agents??0} active=${(r.active??[]).length}`;break;default:n=typeof r=="string"?r:JSON.stringify(r).slice(0,80)}return{at:Number.isFinite(t)?t:Date.now(),kind:e.event,line:n}}function ce(e){switch(e){case"run":return"cyan";case"task":return"magenta";case"signal":return"green";case"mesh":return"blue";case"channel":return"yellow";default:return"white"}}function T(e,r){let t=(e??"").toString();return t.length>=r?t.slice(0,r-1)+" ":t+" ".repeat(r-t.length)}export{be as App};
8
- //# sourceMappingURL=App-UXX5TGFF.js.map
8
+ //# sourceMappingURL=App-XWSSUYKF.js.map
@@ -1,7 +1,7 @@
1
- import{a as Y,b as Z,c as _,d as ee,e as te,f as ne,g as re}from"./chunk-U2CKL755.js";import{b as Q,g as X}from"./chunk-LZY6YN2J.js";import"./chunk-KOY3EOPH.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{useCallback as oe,useMemo as H,useRef as P,useState as k}from"react";import{Box as g,Text as t,useApp as he,useInput as xe,useStdout as Te}from"ink";import{randomUUID as se}from"crypto";var m={accent:"cyan",agent:"green",working:"magenta",error:"red",muted:"gray"},q="\u25C7 agentx",F="\u258C";import{jsx as c,jsxs as o}from"react/jsx-runtime";var ie="/help /agent <id> /agents /clear /who /exit",be=[{cmd:"/agent",desc:"switch the target agent (/agent <id>)"},{cmd:"/agents",desc:"list registered agents"},{cmd:"/clear",desc:"start a fresh session"},{cmd:"/who",desc:"show agent + chat id"},{cmd:"/help",desc:"list commands"},{cmd:"/exit",desc:"quit the chat"}];function Pe({conn:n,agentId:p,channel:f,chatId:a,agents:h}){let{exit:w}=he(),{stdout:O}=Te(),V=Math.max(40,Math.min((O?.columns||80)-4,100)),[z,U]=k([]),[$,S]=k(null),[T,le]=k(p),[A,ae]=k(h),[E,ue]=k(a),[y,x]=k(""),[J,de]=k(""),W=P([]),u=P(-1),M=P(null),R=P(null),v=$?.live??!1,j=H(()=>Z(y,A.map(s=>s.id),process.cwd()),[y,A]),N=H(()=>{let s=/^\/(\w*)$/.exec(y);if(!s)return null;let e=be.filter(r=>r.cmd.slice(1).startsWith(s[1].toLowerCase()));return e.length?e:null},[y]),b=s=>de(s),K=oe(s=>{let e=se().slice(0,8),r=Date.now(),i=new AbortController;R.current=i;let d={id:e,you:s,agentId:T,segs:[],live:!0,startedAt:r};S({...d});let L=()=>S({...d,segs:d.segs.map(C=>({...C}))});(async()=>{try{let C=await X(n,T,s,{channel:f,chatId:E,signal:i.signal,onText:l=>{let I=d.segs[d.segs.length-1];I&&I.type==="text"?I.content=(I.content??"")+l:d.segs.push({type:"text",content:l}),L()},onThinking:l=>{d.thinking=(d.thinking??"")+l,L()},onTool:l=>{l.status==="start"&&l.name?(d.segs.push({type:"tool",name:l.name,arg:l.arg}),L()):l.status==="result"&&l.error&&(d.segs.push({type:"tool",name:l.name??"tool",error:!0}),L())}});U(l=>[...l,{...d,live:!1,elapsedMs:Date.now()-r,outTokens:C.usage?.outputTokens,error:C.error}]),S(null)}catch(C){let l=i.signal.aborted||C?.name==="AbortError";U(I=>[...I,{...d,live:!1,elapsedMs:Date.now()-r,interrupted:l,error:l?void 0:C?.message||String(C)}]),S(null)}finally{R.current===i&&(R.current=null)}})()},[n,T,f,E]),me=oe(s=>{let e=s.trim();if(e){if(W.current.push(e),u.current=-1,e==="/exit"||e==="/quit"){w();return}if(e==="/help"){b(ie);return}if(e==="/who"){b(`@${T} \xB7 chatId=${E} \xB7 channel=${f}`);return}if(e==="/clear"){let r=`chat-cli:${se().slice(0,12)}`;ue(r),U([]),b(`fresh chatId=${r} (warm process dropped)`);return}if(e==="/agents"){Q(n).then(r=>{ae(r),b(r.map(i=>i.id===T?`[${i.id}]`:i.id).join(" "))}).catch(r=>b(`failed to list agents: ${r?.message||r}`));return}if(e.startsWith("/agent ")){let r=e.slice(7).replace(/^@/,"").trim();if(!r){b("usage: /agent <id>");return}if(!A.find(i=>i.id===r)){b(`unknown agent: @${r}`);return}le(r),b(`now talking to @${r}`);return}if(e.startsWith("/")){b(`unknown command \xB7 ${ie}`);return}K(e)}},[n,T,A,f,E,w,K]);xe((s,e)=>{if(e.ctrl&&s==="c"){w();return}if(e.escape){if(v&&R.current){R.current.abort();return}w();return}if(e.tab){if(N){x(N[0].cmd+" ");return}let i=_(y,M,A.map(d=>d.id),process.cwd());i!==null&&(x(i),u.current=-1);return}if(e.upArrow){let i=W.current;if(!i.length)return;u.current=u.current<0?i.length-1:Math.max(0,u.current-1),x(i[u.current]??"");return}if(e.downArrow){let i=W.current;if(u.current<0)return;if(u.current=u.current+1,u.current>=i.length){u.current=-1,x("");return}x(i[u.current]??"");return}if(e.backspace||e.delete){M.current=null,x(i=>i.slice(0,-1));return}if(e.ctrl||e.meta)return;let r=ee(s??"",e.return,y);switch(r.kind){case"paste":M.current=null,x(i=>i+r.text),u.current=-1;return;case"type":M.current=null,x(i=>i+r.text),u.current=-1;return;case"continue":x(r.buffer);return;case"submit":if(v)return;M.current=null,x(""),me(r.text);return;case"none":return}});let G=v?m.working:m.accent,ge=y.length?y.split(`
1
+ import{a as Y,b as Z,c as _,d as ee,e as te,f as ne,g as re}from"./chunk-U2CKL755.js";import{b as Q,g as X}from"./chunk-IGBW4VVM.js";import"./chunk-MD2HCGSC.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{useCallback as oe,useMemo as H,useRef as P,useState as k}from"react";import{Box as g,Text as t,useApp as he,useInput as xe,useStdout as Te}from"ink";import{randomUUID as se}from"crypto";var m={accent:"cyan",agent:"green",working:"magenta",error:"red",muted:"gray"},q="\u25C7 agentx",F="\u258C";import{jsx as c,jsxs as o}from"react/jsx-runtime";var ie="/help /agent <id> /agents /clear /who /exit",be=[{cmd:"/agent",desc:"switch the target agent (/agent <id>)"},{cmd:"/agents",desc:"list registered agents"},{cmd:"/clear",desc:"start a fresh session"},{cmd:"/who",desc:"show agent + chat id"},{cmd:"/help",desc:"list commands"},{cmd:"/exit",desc:"quit the chat"}];function Pe({conn:n,agentId:p,channel:f,chatId:a,agents:h}){let{exit:w}=he(),{stdout:O}=Te(),V=Math.max(40,Math.min((O?.columns||80)-4,100)),[z,U]=k([]),[$,S]=k(null),[T,le]=k(p),[A,ae]=k(h),[E,ue]=k(a),[y,x]=k(""),[J,de]=k(""),W=P([]),u=P(-1),M=P(null),R=P(null),v=$?.live??!1,j=H(()=>Z(y,A.map(s=>s.id),process.cwd()),[y,A]),N=H(()=>{let s=/^\/(\w*)$/.exec(y);if(!s)return null;let e=be.filter(r=>r.cmd.slice(1).startsWith(s[1].toLowerCase()));return e.length?e:null},[y]),b=s=>de(s),K=oe(s=>{let e=se().slice(0,8),r=Date.now(),i=new AbortController;R.current=i;let d={id:e,you:s,agentId:T,segs:[],live:!0,startedAt:r};S({...d});let L=()=>S({...d,segs:d.segs.map(C=>({...C}))});(async()=>{try{let C=await X(n,T,s,{channel:f,chatId:E,signal:i.signal,onText:l=>{let I=d.segs[d.segs.length-1];I&&I.type==="text"?I.content=(I.content??"")+l:d.segs.push({type:"text",content:l}),L()},onThinking:l=>{d.thinking=(d.thinking??"")+l,L()},onTool:l=>{l.status==="start"&&l.name?(d.segs.push({type:"tool",name:l.name,arg:l.arg}),L()):l.status==="result"&&l.error&&(d.segs.push({type:"tool",name:l.name??"tool",error:!0}),L())}});U(l=>[...l,{...d,live:!1,elapsedMs:Date.now()-r,outTokens:C.usage?.outputTokens,error:C.error}]),S(null)}catch(C){let l=i.signal.aborted||C?.name==="AbortError";U(I=>[...I,{...d,live:!1,elapsedMs:Date.now()-r,interrupted:l,error:l?void 0:C?.message||String(C)}]),S(null)}finally{R.current===i&&(R.current=null)}})()},[n,T,f,E]),me=oe(s=>{let e=s.trim();if(e){if(W.current.push(e),u.current=-1,e==="/exit"||e==="/quit"){w();return}if(e==="/help"){b(ie);return}if(e==="/who"){b(`@${T} \xB7 chatId=${E} \xB7 channel=${f}`);return}if(e==="/clear"){let r=`chat-cli:${se().slice(0,12)}`;ue(r),U([]),b(`fresh chatId=${r} (warm process dropped)`);return}if(e==="/agents"){Q(n).then(r=>{ae(r),b(r.map(i=>i.id===T?`[${i.id}]`:i.id).join(" "))}).catch(r=>b(`failed to list agents: ${r?.message||r}`));return}if(e.startsWith("/agent ")){let r=e.slice(7).replace(/^@/,"").trim();if(!r){b("usage: /agent <id>");return}if(!A.find(i=>i.id===r)){b(`unknown agent: @${r}`);return}le(r),b(`now talking to @${r}`);return}if(e.startsWith("/")){b(`unknown command \xB7 ${ie}`);return}K(e)}},[n,T,A,f,E,w,K]);xe((s,e)=>{if(e.ctrl&&s==="c"){w();return}if(e.escape){if(v&&R.current){R.current.abort();return}w();return}if(e.tab){if(N){x(N[0].cmd+" ");return}let i=_(y,M,A.map(d=>d.id),process.cwd());i!==null&&(x(i),u.current=-1);return}if(e.upArrow){let i=W.current;if(!i.length)return;u.current=u.current<0?i.length-1:Math.max(0,u.current-1),x(i[u.current]??"");return}if(e.downArrow){let i=W.current;if(u.current<0)return;if(u.current=u.current+1,u.current>=i.length){u.current=-1,x("");return}x(i[u.current]??"");return}if(e.backspace||e.delete){M.current=null,x(i=>i.slice(0,-1));return}if(e.ctrl||e.meta)return;let r=ee(s??"",e.return,y);switch(r.kind){case"paste":M.current=null,x(i=>i+r.text),u.current=-1;return;case"type":M.current=null,x(i=>i+r.text),u.current=-1;return;case"continue":x(r.buffer);return;case"submit":if(v)return;M.current=null,x(""),me(r.text);return;case"none":return}});let G=v?m.working:m.accent,ge=y.length?y.split(`
2
2
  `):[""],B=A.find(s=>s.id===T),D=ne(B?.tier??"",B?.model),pe=O?.rows||24,fe=z.slice(-40);return o(g,{flexDirection:"column",height:pe,children:[o(g,{flexDirection:"column",flexGrow:1,justifyContent:"flex-end",overflow:"hidden",children:[z.length===0&&!$?o(g,{flexDirection:"column",children:[o(t,{children:[c(t,{color:m.accent,bold:!0,children:q}),c(t,{dimColor:!0,children:" \u2014 chat with "}),o(t,{color:m.accent,children:["@",T]}),c(t,{dimColor:!0,children:" via "}),o(t,{color:D.color,bold:!0,children:[D.glyph," ",D.label]}),B?.model?o(t,{dimColor:!0,children:[" (",B.model,")"]}):null]}),c(t,{dimColor:!0,children:"streaming \xB7 markdown \xB7 tools \xB7 type a message, or / for commands"})]}):null,fe.map(s=>c(ce,{turn:s,width:V},s.id)),$?c(ce,{turn:$,width:V}):null]}),N?c(g,{flexDirection:"column",marginTop:1,children:N.map((s,e)=>o(g,{children:[c(t,{color:e===0?m.accent:m.muted,bold:e===0,children:s.cmd.padEnd(10)}),c(t,{dimColor:!0,children:s.desc})]},s.cmd))}):j?o(g,{marginTop:1,children:[c(t,{color:m.accent,children:"\u21B9 "}),j.items.map((s,e)=>o(t,{color:e===0?m.accent:m.muted,children:[s,e<j.items.length-1?" ":""]},e))]}):J?c(g,{marginTop:1,children:c(t,{dimColor:!0,children:J})}):null,c(g,{borderStyle:"single",borderColor:G,borderLeft:!1,borderRight:!1,borderDimColor:!v,width:"100%",children:c(g,{flexDirection:"column",width:"100%",children:ge.map((s,e,r)=>o(g,{children:[c(t,{color:G,bold:!0,children:e===0?"\u203A ":" "}),c(t,{children:s}),e===r.length-1&&!v?c(t,{color:G,children:"\u258F"}):null]},e))})}),o(g,{justifyContent:"space-between",children:[o(t,{children:[c(t,{color:m.accent,bold:!0,children:q}),o(t,{dimColor:!0,children:[" \xB7 @",T," \xB7 "]}),o(t,{color:D.color,bold:!0,children:[D.glyph," ",D.label]}),B?.model?o(t,{dimColor:!0,children:[" ",re(B.model)]}):null]}),o(t,{dimColor:!0,children:["\u21B5 send / cmds @ mention esc ",v?"stop":"exit"]})]})]})}function ce({turn:n,width:p}){let f=H(()=>ye(n,p),[n,p]),a=n.segs.some(h=>h.type==="text"&&h.content);return o(g,{flexDirection:"column",marginBottom:1,children:[o(t,{color:m.accent,bold:!0,children:[F," you"]}),n.you.split(`
3
3
  `).map((h,w)=>o(t,{color:"white",children:[" ",h]},`u${w}`)),o(t,{color:m.agent,bold:!0,children:[F," ",n.agentId??"agent"]}),n.thinking?c(g,{flexDirection:"column",children:we(n.thinking,n.live?3:2).map((h,w)=>o(t,{dimColor:!0,italic:!0,children:[" ",h]},`th${w}`))}):null,f,n.live?c(te,{startedAt:n.startedAt,phase:a?"responding":"thinking",hint:"esc to interrupt"}):n.interrupted?o(t,{dimColor:!0,children:[" \u2298 interrupted \xB7 ",(n.elapsedMs/1e3).toFixed(1),"s"]}):n.error?o(t,{color:"red",children:[" \u2717 ",n.error]}):n.elapsedMs!=null?o(t,{dimColor:!0,children:[" \xB7 ",(n.elapsedMs/1e3).toFixed(1),"s",n.outTokens!=null?`, ${n.outTokens} tok`:""]}):null]})}function we(n,p){return n.split(`
4
4
  `).filter(a=>a.trim()).slice(-p)}function ye(n,p){let f=[];return n.segs.forEach((a,h)=>{a.type==="tool"?f.push(o(t,{color:a.error?"red":"green",children:[" ","\u25CF ",o(t,{bold:!a.error,dimColor:a.error,children:[a.name,a.arg?o(t,{dimColor:!0,children:["(",a.arg,")"]}):null,a.error?" failed":""]})]},h)):a.content&&f.push(c(t,{children:Ce(Y(a.content,p,{balance:n.live}))},h))}),f}function Ce(n){return n.split(`
5
5
  `).map(p=>p.length?" "+p:p).join(`
6
6
  `)}export{Pe as ChatApp};
7
- //# sourceMappingURL=ChatApp-X635NOAE.js.map
7
+ //# sourceMappingURL=ChatApp-UT2BRHYE.js.map
@@ -1,2 +1,2 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-CF7CPE7K.js";import"./chunk-UHTIZCKU.js";import"./chunk-U5S6IP7Z.js";import"./chunk-JTFCU5LH.js";import"./chunk-IYITREE5.js";import"./chunk-WPNRDEHW.js";import"./chunk-LUOW2YHY.js";import"./chunk-4LWFJ4MZ.js";import"./chunk-BIJHMWXK.js";import"./chunk-NI2XD6P3.js";import"./chunk-72SZI2UW.js";import"./chunk-FCPTN6NF.js";import"./chunk-MCI3DIWW.js";import"./chunk-QUFIUXMQ.js";import"./chunk-BERWTVG2.js";import"./chunk-QOYAX2FT.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-KOY3EOPH.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-RGDKHYY2.js";import"./chunk-QIJLFPWE.js";export{i as JUDGE_ENTRY_CHARS,e as WEAK_CITATION,j as buildJudgePrompt,l as buildScorecard,f as checkArticle,n as envelopeUsage,h as findDuplicates,k as parseJudgeReply,b as pickSample,m as renderScorecard,a as seededRandom,o as summariseRuns,d as termOverlap,c as terms,g as uncitedWithFacts};
2
- //# sourceMappingURL=absorb-eval-4ZPDWNBA.js.map
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-BY3AUZYM.js";import"./chunk-YSPBVLTZ.js";import"./chunk-Z4XVPGPZ.js";import"./chunk-JTFCU5LH.js";import"./chunk-QB6UPODO.js";import"./chunk-WPNRDEHW.js";import"./chunk-LUOW2YHY.js";import"./chunk-4LWFJ4MZ.js";import"./chunk-BIJHMWXK.js";import"./chunk-YX4R2VGD.js";import"./chunk-72SZI2UW.js";import"./chunk-FCPTN6NF.js";import"./chunk-MCI3DIWW.js";import"./chunk-QUFIUXMQ.js";import"./chunk-BERWTVG2.js";import"./chunk-QOYAX2FT.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-MD2HCGSC.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-RGDKHYY2.js";import"./chunk-QIJLFPWE.js";export{i as JUDGE_ENTRY_CHARS,e as WEAK_CITATION,j as buildJudgePrompt,l as buildScorecard,f as checkArticle,n as envelopeUsage,h as findDuplicates,k as parseJudgeReply,b as pickSample,m as renderScorecard,a as seededRandom,o as summariseRuns,d as termOverlap,c as terms,g as uncitedWithFacts};
2
+ //# sourceMappingURL=absorb-eval-SFGUURBD.js.map
@@ -1,4 +1,4 @@
1
- import{a as m,b as d,c as g,d as f,e as h,i as b,j as y}from"./chunk-WZUY7VGL.js";import"./chunk-KOY3EOPH.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{ImapFlow as P}from"imapflow";import M from"postal-mime";var w=8e3;async function x(n){let e=await M.parse(n),t=e.from&&"address"in e.from?e.from:void 0,r=t?.address?.trim().toLowerCase();if(!r)return null;let i=l=>e.headers.find(u=>u.key===l)?.value??"",s=p(e.references??"");if(e.inReplyTo)for(let l of p(e.inReplyTo))s.includes(l)||s.push(l);let a=i("auto-submitted").toLowerCase(),c=i("precedence").toLowerCase(),o=C(e.text??N(e.html??""));return{from:r,fromName:t?.name||void 0,subject:(e.subject??"").trim(),messageId:e.messageId?p(e.messageId)[0]:void 0,references:s,text:o.length>w?`${o.slice(0,w)}
1
+ import{a as m,b as d,c as g,d as f,e as h,i as b,j as y}from"./chunk-4WSJKKSA.js";import"./chunk-MD2HCGSC.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-QIJLFPWE.js";import{ImapFlow as P}from"imapflow";import M from"postal-mime";var w=8e3;async function x(n){let e=await M.parse(n),t=e.from&&"address"in e.from?e.from:void 0,r=t?.address?.trim().toLowerCase();if(!r)return null;let i=l=>e.headers.find(u=>u.key===l)?.value??"",s=p(e.references??"");if(e.inReplyTo)for(let l of p(e.inReplyTo))s.includes(l)||s.push(l);let a=i("auto-submitted").toLowerCase(),c=i("precedence").toLowerCase(),o=C(e.text??N(e.html??""));return{from:r,fromName:t?.name||void 0,subject:(e.subject??"").trim(),messageId:e.messageId?p(e.messageId)[0]:void 0,references:s,text:o.length>w?`${o.slice(0,w)}
2
2
  [\u2026 the rest of the mail was cut]`:o,automatic:a!==""&&a!=="no"||["bulk","junk","list","auto_reply"].includes(c)||i("list-id")!==""||/^(mailer-daemon|postmaster|no-?reply)@/.test(r)}}function p(n){return n.match(/<[^<>\s]+>/g)??[]}function C(n){let e=n.replace(/\r\n/g,`
3
3
  `).split(`
4
4
  `),t=[];for(let r=0;r<e.length;r++){let i=e[r];if(/^On .{4,200}wrote:\s*$/.test(i)||/^On .{4,200}$/.test(i)&&/wrote:\s*$/.test(e[r+1]??"")||/^-{2,}\s*Original Message\s*-{2,}/i.test(i))break;/^>/.test(i)||t.push(i)}return t.join(`
@@ -9,4 +9,4 @@ import{a as m,b as d,c as g,d as f,e as h,i as b,j as y}from"./chunk-WZUY7VGL.js
9
9
  Subject: ${n.subject||"(none)"}
10
10
 
11
11
  ${n.text||"(no text)"}`}var A=class{constructor(e,t=()=>{}){this.opts=e;this.log=t}name="email";handler=null;timers=[];polling=new Set;failures=new Map;onMessage(e){this.handler=e}async start(){for(let[e,t]of Object.entries(this.opts.accounts)){this.poll(e);let r=setInterval(()=>{this.poll(e)},t.pollSeconds*1e3);r.unref?.(),this.timers.push(r)}}async stop(){for(let e of this.timers)clearInterval(e);this.timers=[]}health(){let e=[...this.failures];return e.length?{up:!1,reason:e.map(([t,r])=>`${t}: ${r}`).join("; ")}:{up:!0}}async poll(e){let t=this.opts.accounts[e];if(!t||this.polling.has(e))return 0;this.polling.add(e);let r=0;try{r=await this.pollAccount(e,t),this.failures.delete(e)}catch(i){let s=String(i?.message??i).slice(0,200);this.failures.get(e)!==s&&this.log(`[email] ${e}: ${s}`),this.failures.set(e,s)}finally{this.polling.delete(e)}return r}client(e){if(this.opts.imapClient)return this.opts.imapClient(e);let{imap:t}=b(e);return new P({host:t.host,port:t.port,secure:t.secure,auth:{user:t.user,pass:t.password},logger:!1})}async pollAccount(e,t){let r=this.client(t),i=[],s=g(this.opts.root,e);await r.connect();try{let c=await r.getMailboxLock(t.mailbox);try{let o=r.mailbox;if(!o)throw new Error(`cannot open ${t.mailbox}`);let l=String(o.uidValidity);if(!s||s.uidValidity!==l)return f(this.opts.root,e,{uidValidity:l,lastUid:o.uidNext-1}),0;if(o.uidNext-1>s.lastUid)for await(let u of r.fetch(`${s.lastUid+1}:*`,{uid:!0,source:!0},{uid:!0}))u.uid>s.lastUid&&u.source&&i.push({uid:u.uid,source:u.source})}finally{c.release()}}finally{await r.logout().catch(()=>r.close())}let a=0;for(let{uid:c,source:o}of i.sort((l,u)=>l.uid-u.uid))await this.handle(e,t,c,o)&&a++,s={uidValidity:s.uidValidity,lastUid:c},f(this.opts.root,e,s);return a}async handle(e,t,r,i){let s=await x(i).catch(()=>null);return s?s.from===t.address.toLowerCase()?!1:s.automatic?(this.log(`[email] ${e}: automatic mail from ${s.from} skipped`),!1):v(s.from,t.allowFrom)?(d(this.opts.root,$(e,s,m(this.opts.root,s.from))),this.handler?(await this.handler({id:s.messageId??`${e}:${r}`,channel:"email",accountId:e,sender:{id:s.from,name:s.fromName||s.from,username:s.from},text:T(s),timestamp:new Date,resolvedAgent:t.agent,channelMeta:{channel:"email",facts:[`This is an email to ${t.address}. Your reply is sent as an email${t.send==="auto"?"":" once the owner approves it"}.`]}}),!0):!1):(this.log(`[email] ${e}: ${s.from} is not in allowFrom, dropped`),!1):(this.log(`[email] ${e}: mail ${r} has no sender, skipped`),!1)}async send(e){let t=m(this.opts.root,e.chatId);if(!t)throw new Error(`no email from ${e.chatId} to reply to`);let r=this.opts.accounts[t.account];if(!r)throw new Error(`email account "${t.account}" is not set up`);let i=j(t),s=e.agentId??r.agent;if(r.send==="auto")return y(r,r.name||this.opts.agentName?.(s)||s,{to:t.to,toName:t.toName,subject:i.subject,inReplyTo:i.inReplyTo,references:i.references,text:e.text});let a=h(this.opts.root,{agent:s,account:t.account,to:t.to,to_name:t.toName,subject:i.subject,in_reply_to:i.inReplyTo,references:i.references,text:e.text});return this.log(`[email] reply to ${t.to} waits for approval: email:${a.id}`),this.opts.onDraft?.(a),`draft:${a.id}`}};export{A as EmailAdapter};
12
- //# sourceMappingURL=adapter-Z23K544D.js.map
12
+ //# sourceMappingURL=adapter-UHR7FVM7.js.map
@@ -1,2 +1,2 @@
1
- import{A as a,B as b,C as c}from"./chunk-FRVFRWFN.js";import"./chunk-SFQUP3BP.js";import"./chunk-QOYAX2FT.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-JHCI6XCJ.js";import"./chunk-DSYKYZMT.js";import"./chunk-QIJLFPWE.js";export{a as createAgentContext,b as generate,c as generateStream};
2
- //# sourceMappingURL=agent-OBRH5BJZ.js.map
1
+ import{A as a,B as b,C as c}from"./chunk-5YG2ZQQW.js";import"./chunk-SFQUP3BP.js";import"./chunk-QOYAX2FT.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-JHCI6XCJ.js";import"./chunk-DSYKYZMT.js";import"./chunk-QIJLFPWE.js";export{a as createAgentContext,b as generate,c as generateStream};
2
+ //# sourceMappingURL=agent-5NTFSCEO.js.map