agentix-cli 0.198.0 → 0.200.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 (144) hide show
  1. package/apps/mac-voice/Sources/AgentXVoice/AgentClient.swift +7 -2
  2. package/apps/mac-voice/Sources/AgentXVoice/AnswerView.swift +19 -8
  3. package/apps/mac-voice/Sources/AgentXVoice/Artifacts.swift +54 -0
  4. package/apps/mac-voice/Sources/AgentXVoice/Markdown.swift +3 -0
  5. package/apps/mac-voice/Sources/AgentXVoice/PanelAnswer.swift +3 -2
  6. package/apps/mac-voice/Sources/AgentXVoice/main.swift +7 -7
  7. package/dist/{App-ODMLQITV.js → App-AUKNCAVD.js} +2 -2
  8. package/dist/{ChatApp-MJBOQWUM.js → ChatApp-KYQIQZ6Q.js} +2 -2
  9. package/dist/{absorb-eval-QSUGLOOO.js → absorb-eval-TJN5WUYZ.js} +2 -2
  10. package/dist/{adapter-BJLSEQ6M.js → adapter-VLNSNP6C.js} +2 -2
  11. package/dist/{agent-QJPWZDTL.js → agent-KXHSNUNY.js} +2 -2
  12. package/dist/{board-dashboard-LZRJJ3DZ.js → board-dashboard-QKOJEHXS.js} +479 -377
  13. package/dist/board-dashboard-QKOJEHXS.js.map +1 -0
  14. package/dist/{chunk-IJYCPFLZ.js → chunk-25U5MNNF.js} +2 -2
  15. package/dist/{chunk-GB7NAOZ4.js → chunk-4MJOSO7T.js} +2 -2
  16. package/dist/{chunk-VX3IZAF6.js → chunk-64UGFZPX.js} +2 -2
  17. package/dist/{chunk-C3LKB4N7.js → chunk-6QVUXEVK.js} +2 -2
  18. package/dist/{chunk-SUVJA67A.js → chunk-6RJ7ERGC.js} +2 -2
  19. package/dist/{chunk-V2DCI2JL.js → chunk-7VHE7WLJ.js} +3 -3
  20. package/dist/{chunk-I5KOLVB6.js → chunk-AHJ6FEHW.js} +2 -2
  21. package/dist/{chunk-2AP2F6S5.js → chunk-AKDJGDLN.js} +3 -3
  22. package/dist/{chunk-GL26HRDW.js → chunk-APULKE2J.js} +2 -2
  23. package/dist/{chunk-LOFMZHJN.js → chunk-BNTN3LKN.js} +2 -2
  24. package/dist/{chunk-CAYGWXWJ.js → chunk-EM72LW2F.js} +58 -57
  25. package/dist/chunk-EM72LW2F.js.map +1 -0
  26. package/dist/{chunk-BZ3AXEZW.js → chunk-J4AMQF7D.js} +2 -2
  27. package/dist/{chunk-PM4Y6ZBW.js → chunk-K34LYNGN.js} +2 -2
  28. package/dist/{chunk-QHICHZFK.js → chunk-KE4SLJTC.js} +2 -2
  29. package/dist/chunk-KOZSBUXJ.js +3 -0
  30. package/dist/{chunk-BIJ3JIWG.js.map → chunk-KOZSBUXJ.js.map} +1 -1
  31. package/dist/{chunk-D64VFKUU.js → chunk-LBIU3OWW.js} +5 -5
  32. package/dist/{chunk-XRCWM7JA.js → chunk-M6EQBW2F.js} +2 -2
  33. package/dist/{chunk-QF5B5O7K.js → chunk-MJHFGJFW.js} +304 -304
  34. package/dist/chunk-MJHFGJFW.js.map +1 -0
  35. package/dist/{chunk-4FY2NOCD.js → chunk-O672XL5L.js} +2 -2
  36. package/dist/{chunk-MA5ZF4YY.js → chunk-ORAQRC6A.js} +2 -2
  37. package/dist/{chunk-PIY23C2Z.js → chunk-QISI5WM2.js} +2 -2
  38. package/dist/{chunk-C5QQW2L7.js → chunk-QMFNIUW7.js} +2 -2
  39. package/dist/chunk-QTOOFB4N.js +118 -0
  40. package/dist/chunk-QTOOFB4N.js.map +1 -0
  41. package/dist/{chunk-3KHXOLF5.js → chunk-R5TCPLWF.js} +2 -2
  42. package/dist/{chunk-KQ5UJTQR.js → chunk-RW2JLP5P.js} +2 -2
  43. package/dist/{chunk-GGFL7HVN.js → chunk-SXL6R3HH.js} +2 -2
  44. package/dist/{chunk-HYJWN6L5.js → chunk-TBSPEM7I.js} +2 -2
  45. package/dist/{chunk-H3NGVXOL.js → chunk-UBLPD6DK.js} +2 -2
  46. package/dist/{chunk-SHNGAN3L.js → chunk-W764F42W.js} +2 -2
  47. package/dist/cli.js +1 -1
  48. package/dist/{client-WAPDTJ5B.js → client-FXU56BIM.js} +2 -2
  49. package/dist/config-IOQKEH47.js +2 -0
  50. package/dist/{config-mutate-ZADHR76X.js → config-mutate-633Q77K3.js} +2 -2
  51. package/dist/{config-mutator-GJFZWC43.js → config-mutator-LRZHJ3UN.js} +2 -2
  52. package/dist/{contributions-RROXRQEV.js → contributions-3AE43OSI.js} +2 -2
  53. package/dist/{doctor-DKUDMNK3.js → doctor-KCRL67QL.js} +2 -2
  54. package/dist/{follow-up-tool-OKKSNVCJ.js → follow-up-tool-WLDWTZRW.js} +2 -2
  55. package/dist/{hub-5X33WEIO.js → hub-PG4OFRIQ.js} +2 -2
  56. package/dist/index.d.ts +112 -0
  57. package/dist/index.js +1 -1
  58. package/dist/{program-4QVJE2JD.js → program-MPUDRWBH.js} +242 -242
  59. package/dist/program-MPUDRWBH.js.map +1 -0
  60. package/dist/{promote-YETAZYXW.js → promote-DLM7N6V2.js} +2 -2
  61. package/dist/{query-IE5EVVY4.js → query-TBQGAIZG.js} +2 -2
  62. package/dist/{query-settings-TF4H7EZS.js → query-settings-U6XNO5V4.js} +2 -2
  63. package/dist/{registry-OBQMRAYY.js → registry-DGGJJOVA.js} +2 -2
  64. package/dist/{request-planner-V6J5EISV.js → request-planner-YQ4RTZNU.js} +2 -2
  65. package/dist/{review-candidates-MTZEBOP5.js → review-candidates-OE5HDVWI.js} +2 -2
  66. package/dist/{routing-KWZ3X6ZV.js → routing-RAG6I37K.js} +2 -2
  67. package/dist/schedule-tool-O5FJXSKO.js +2 -0
  68. package/dist/{scheduler-ST37UR5V.js → scheduler-TGP4B5KZ.js} +2 -2
  69. package/dist/{seat-RFFUE7RT.js → seat-74G2KLZQ.js} +2 -2
  70. package/dist/{select-DCG457CP.js → select-P7565K5D.js} +2 -2
  71. package/dist/{set-enabled-TD3MPUDH.js → set-enabled-DE3TKKEK.js} +2 -2
  72. package/dist/{sprint-tool-OQ55FHX3.js → sprint-tool-CK3SD4NZ.js} +2 -2
  73. package/dist/{tool-RJJKMW5D.js → tool-DWKCESVE.js} +2 -2
  74. package/dist/{tool-JIRXLLQN.js → tool-X6DAR3KL.js} +2 -2
  75. package/dist/{tool-FQE7ZGBT.js → tool-XGB3PMXA.js} +2 -2
  76. package/dist/{wiki-OAWT7LND.js → wiki-E45S2K6F.js} +2 -2
  77. package/dist/wiki-enrich-LREINNTK.js +2 -0
  78. package/package.json +1 -1
  79. package/dist/board-dashboard-LZRJJ3DZ.js.map +0 -1
  80. package/dist/chunk-BIJ3JIWG.js +0 -3
  81. package/dist/chunk-CAYGWXWJ.js.map +0 -1
  82. package/dist/chunk-H7SPRPDG.js +0 -116
  83. package/dist/chunk-H7SPRPDG.js.map +0 -1
  84. package/dist/chunk-QF5B5O7K.js.map +0 -1
  85. package/dist/config-NYFW5P4W.js +0 -2
  86. package/dist/program-4QVJE2JD.js.map +0 -1
  87. package/dist/schedule-tool-ZSQTA3IW.js +0 -2
  88. package/dist/wiki-enrich-QVZMYHVY.js +0 -2
  89. /package/dist/{App-ODMLQITV.js.map → App-AUKNCAVD.js.map} +0 -0
  90. /package/dist/{ChatApp-MJBOQWUM.js.map → ChatApp-KYQIQZ6Q.js.map} +0 -0
  91. /package/dist/{absorb-eval-QSUGLOOO.js.map → absorb-eval-TJN5WUYZ.js.map} +0 -0
  92. /package/dist/{adapter-BJLSEQ6M.js.map → adapter-VLNSNP6C.js.map} +0 -0
  93. /package/dist/{agent-QJPWZDTL.js.map → agent-KXHSNUNY.js.map} +0 -0
  94. /package/dist/{chunk-IJYCPFLZ.js.map → chunk-25U5MNNF.js.map} +0 -0
  95. /package/dist/{chunk-GB7NAOZ4.js.map → chunk-4MJOSO7T.js.map} +0 -0
  96. /package/dist/{chunk-VX3IZAF6.js.map → chunk-64UGFZPX.js.map} +0 -0
  97. /package/dist/{chunk-C3LKB4N7.js.map → chunk-6QVUXEVK.js.map} +0 -0
  98. /package/dist/{chunk-SUVJA67A.js.map → chunk-6RJ7ERGC.js.map} +0 -0
  99. /package/dist/{chunk-V2DCI2JL.js.map → chunk-7VHE7WLJ.js.map} +0 -0
  100. /package/dist/{chunk-I5KOLVB6.js.map → chunk-AHJ6FEHW.js.map} +0 -0
  101. /package/dist/{chunk-2AP2F6S5.js.map → chunk-AKDJGDLN.js.map} +0 -0
  102. /package/dist/{chunk-GL26HRDW.js.map → chunk-APULKE2J.js.map} +0 -0
  103. /package/dist/{chunk-LOFMZHJN.js.map → chunk-BNTN3LKN.js.map} +0 -0
  104. /package/dist/{chunk-BZ3AXEZW.js.map → chunk-J4AMQF7D.js.map} +0 -0
  105. /package/dist/{chunk-PM4Y6ZBW.js.map → chunk-K34LYNGN.js.map} +0 -0
  106. /package/dist/{chunk-QHICHZFK.js.map → chunk-KE4SLJTC.js.map} +0 -0
  107. /package/dist/{chunk-D64VFKUU.js.map → chunk-LBIU3OWW.js.map} +0 -0
  108. /package/dist/{chunk-XRCWM7JA.js.map → chunk-M6EQBW2F.js.map} +0 -0
  109. /package/dist/{chunk-4FY2NOCD.js.map → chunk-O672XL5L.js.map} +0 -0
  110. /package/dist/{chunk-MA5ZF4YY.js.map → chunk-ORAQRC6A.js.map} +0 -0
  111. /package/dist/{chunk-PIY23C2Z.js.map → chunk-QISI5WM2.js.map} +0 -0
  112. /package/dist/{chunk-C5QQW2L7.js.map → chunk-QMFNIUW7.js.map} +0 -0
  113. /package/dist/{chunk-3KHXOLF5.js.map → chunk-R5TCPLWF.js.map} +0 -0
  114. /package/dist/{chunk-KQ5UJTQR.js.map → chunk-RW2JLP5P.js.map} +0 -0
  115. /package/dist/{chunk-GGFL7HVN.js.map → chunk-SXL6R3HH.js.map} +0 -0
  116. /package/dist/{chunk-HYJWN6L5.js.map → chunk-TBSPEM7I.js.map} +0 -0
  117. /package/dist/{chunk-H3NGVXOL.js.map → chunk-UBLPD6DK.js.map} +0 -0
  118. /package/dist/{chunk-SHNGAN3L.js.map → chunk-W764F42W.js.map} +0 -0
  119. /package/dist/{client-WAPDTJ5B.js.map → client-FXU56BIM.js.map} +0 -0
  120. /package/dist/{config-NYFW5P4W.js.map → config-IOQKEH47.js.map} +0 -0
  121. /package/dist/{config-mutate-ZADHR76X.js.map → config-mutate-633Q77K3.js.map} +0 -0
  122. /package/dist/{config-mutator-GJFZWC43.js.map → config-mutator-LRZHJ3UN.js.map} +0 -0
  123. /package/dist/{contributions-RROXRQEV.js.map → contributions-3AE43OSI.js.map} +0 -0
  124. /package/dist/{doctor-DKUDMNK3.js.map → doctor-KCRL67QL.js.map} +0 -0
  125. /package/dist/{follow-up-tool-OKKSNVCJ.js.map → follow-up-tool-WLDWTZRW.js.map} +0 -0
  126. /package/dist/{hub-5X33WEIO.js.map → hub-PG4OFRIQ.js.map} +0 -0
  127. /package/dist/{promote-YETAZYXW.js.map → promote-DLM7N6V2.js.map} +0 -0
  128. /package/dist/{query-IE5EVVY4.js.map → query-TBQGAIZG.js.map} +0 -0
  129. /package/dist/{query-settings-TF4H7EZS.js.map → query-settings-U6XNO5V4.js.map} +0 -0
  130. /package/dist/{registry-OBQMRAYY.js.map → registry-DGGJJOVA.js.map} +0 -0
  131. /package/dist/{request-planner-V6J5EISV.js.map → request-planner-YQ4RTZNU.js.map} +0 -0
  132. /package/dist/{review-candidates-MTZEBOP5.js.map → review-candidates-OE5HDVWI.js.map} +0 -0
  133. /package/dist/{routing-KWZ3X6ZV.js.map → routing-RAG6I37K.js.map} +0 -0
  134. /package/dist/{schedule-tool-ZSQTA3IW.js.map → schedule-tool-O5FJXSKO.js.map} +0 -0
  135. /package/dist/{scheduler-ST37UR5V.js.map → scheduler-TGP4B5KZ.js.map} +0 -0
  136. /package/dist/{seat-RFFUE7RT.js.map → seat-74G2KLZQ.js.map} +0 -0
  137. /package/dist/{select-DCG457CP.js.map → select-P7565K5D.js.map} +0 -0
  138. /package/dist/{set-enabled-TD3MPUDH.js.map → set-enabled-DE3TKKEK.js.map} +0 -0
  139. /package/dist/{sprint-tool-OQ55FHX3.js.map → sprint-tool-CK3SD4NZ.js.map} +0 -0
  140. /package/dist/{tool-RJJKMW5D.js.map → tool-DWKCESVE.js.map} +0 -0
  141. /package/dist/{tool-JIRXLLQN.js.map → tool-X6DAR3KL.js.map} +0 -0
  142. /package/dist/{tool-FQE7ZGBT.js.map → tool-XGB3PMXA.js.map} +0 -0
  143. /package/dist/{wiki-OAWT7LND.js.map → wiki-E45S2K6F.js.map} +0 -0
  144. /package/dist/{wiki-enrich-QVZMYHVY.js.map → wiki-enrich-LREINNTK.js.map} +0 -0
@@ -30,6 +30,8 @@ enum AgentClient {
30
30
  /// The daemon took the words for the floor holder's own sound
31
31
  /// (#924): no agent was asked and nothing is said back.
32
32
  var dropped = false
33
+ /// Files the agent declared (#1670), shown under the text.
34
+ var artifacts: [Artifact] = []
33
35
  }
34
36
 
35
37
  /// What, if anything, to say about the step now running.
@@ -305,6 +307,7 @@ enum AgentClient {
305
307
  let error: String?
306
308
  let duration: Int?
307
309
  let dropped: String?
310
+ let artifacts: [Artifact]?
308
311
  }
309
312
  let reply = try? JSONDecoder().decode(Reply.self, from: data)
310
313
  let voice = reply?.voice
@@ -328,7 +331,9 @@ enum AgentClient {
328
331
  throw VoiceError.api("daemon HTTP \(status): \(detail)")
329
332
  }
330
333
  if let err = reply?.error, !err.isEmpty { throw VoiceError.api(err) }
331
- guard let text = reply?.text ?? reply?.full, !text.isEmpty else {
334
+ // An answer that is only a file has no words to say, and is not empty.
335
+ let files = reply?.artifacts ?? []
336
+ guard let text = reply?.text ?? reply?.full, !text.isEmpty || !files.isEmpty else {
332
337
  throw VoiceError.api("agent returned an empty answer")
333
338
  }
334
339
  let buttons = (reply?.ui?.buttons ?? []).map { ($0.label, $0.url) }
@@ -343,7 +348,7 @@ enum AgentClient {
343
348
  return Answer(text: text, written: reply?.full,
344
349
  buttons: buttons + extra, imageURL: image,
345
350
  durationMs: reply?.duration, agentID: reply?.agentId, voice: voice,
346
- presenceMode: reply?.presence?.mode)
351
+ presenceMode: reply?.presence?.mode, artifacts: files)
347
352
  }
348
353
 
349
354
  // MARK: Open requests
@@ -25,6 +25,10 @@ final class AnswerView: NSView {
25
25
  private let thumb = NSImageView()
26
26
  private let actions = NSStackView()
27
27
  private var source = ""
28
+ /// The answer has files under its text, so it is not empty even
29
+ /// without words.
30
+ private var hasFiles = false
31
+ private var isEmpty: Bool { source.isEmpty && !hasFiles }
28
32
 
29
33
  /// The answer's natural height, measured after it renders. The pill
30
34
  /// grows to it, up to its maximum.
@@ -116,8 +120,9 @@ final class AnswerView: NSView {
116
120
  /// Worth showing when there is rich content, a URL you could click, or
117
121
  /// materially more written than was spoken. Otherwise the speech was
118
122
  /// the whole answer.
119
- static func isWorthShowing(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?) -> Bool {
120
- if !buttons.isEmpty || imageURL != nil { return true }
123
+ static func isWorthShowing(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?,
124
+ artifacts: [Artifact] = []) -> Bool {
125
+ if !buttons.isEmpty || imageURL != nil || !artifacts.isEmpty { return true }
121
126
  let text = (written?.isEmpty == false ? written! : spoken)
122
127
  if text.range(of: #"https?://"#, options: .regularExpression) != nil { return true }
123
128
  // Speech drops formatting, so written is often a little longer for
@@ -133,9 +138,14 @@ final class AnswerView: NSView {
133
138
  /// URLs and formatting the spoken form had to drop. `onHeight` follows
134
139
  /// once it has rendered.
135
140
  @MainActor
136
- func show(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?) {
141
+ func show(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?,
142
+ artifacts: [Artifact] = []) {
137
143
  source = (written?.isEmpty == false ? written! : spoken)
138
- web.loadHTMLString(Markdown.page(Markdown.toHTML(source), css: Brand.cardCSS), baseURL: nil)
144
+ // The files the agent declared, under the text (#1670), served by
145
+ // the daemon over loopback.
146
+ hasFiles = !artifacts.isEmpty
147
+ let files = Artifacts.html(artifacts, base: Config.daemonURL)
148
+ web.loadHTMLString(Markdown.page(Markdown.toHTML(source) + files, css: Brand.cardCSS + Artifacts.css), baseURL: nil)
139
149
 
140
150
  links.arrangedSubviews.forEach { links.removeArrangedSubview($0); $0.removeFromSuperview() }
141
151
  for (label, url) in buttons.prefix(4) {
@@ -155,7 +165,7 @@ final class AnswerView: NSView {
155
165
  URLSession.shared.dataTask(with: u) { [weak self] data, _, _ in
156
166
  guard let data, let img = NSImage(data: data) else { return }
157
167
  Task { @MainActor in
158
- guard let self, self.source.isEmpty == false else { return }
168
+ guard let self, !self.isEmpty else { return }
159
169
  self.thumb.image = img
160
170
  self.thumb.isHidden = false
161
171
  self.measure()
@@ -169,6 +179,7 @@ final class AnswerView: NSView {
169
179
  @MainActor
170
180
  func clear() {
171
181
  source = ""
182
+ hasFiles = false
172
183
  web.loadHTMLString("", baseURL: nil)
173
184
  thumb.isHidden = true
174
185
  links.arrangedSubviews.forEach { links.removeArrangedSubview($0); $0.removeFromSuperview() }
@@ -181,7 +192,7 @@ final class AnswerView: NSView {
181
192
  + " return b.scrollHeight + parseFloat(s.marginTop) + parseFloat(s.marginBottom) })()"
182
193
  web.evaluateJavaScript(js) { [weak self] value, _ in
183
194
  MainActor.assumeIsolated {
184
- guard let self, !self.source.isEmpty else { return }
195
+ guard let self, !self.isEmpty else { return }
185
196
  let text = CGFloat((value as? NSNumber)?.doubleValue ?? 120)
186
197
  let extra = (self.links.arrangedSubviews.isEmpty ? 0 : Self.linkRow)
187
198
  + (self.thumb.isHidden ? 0 : Self.imageHeight + 16)
@@ -197,7 +208,7 @@ final class AnswerView: NSView {
197
208
  actions.layer?.borderColor = NSColor.separatorColor.cgColor
198
209
  actions.layer?.borderWidth = 1 / (window?.backingScaleFactor ?? 2)
199
210
  }
200
- actions.isHidden = source.isEmpty
211
+ actions.isHidden = isEmpty
201
212
  }
202
213
  override func mouseExited(with event: NSEvent) { actions.isHidden = true }
203
214
 
@@ -231,7 +242,7 @@ final class AnswerView: NSView {
231
242
 
232
243
  extension AnswerView: WKNavigationDelegate {
233
244
  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
234
- MainActor.assumeIsolated { if !source.isEmpty { measure() } }
245
+ MainActor.assumeIsolated { if !isEmpty { measure() } }
235
246
  }
236
247
 
237
248
  /// Links open in the real browser. A pill is not a place to read a web
@@ -0,0 +1,54 @@
1
+ import Foundation
2
+
3
+ /// A file an agent declared in its answer (#1670): the same
4
+ /// `<agentx-artifact>` line the phone app shows. /ask takes the line out of
5
+ /// the text and lists the file with the daemon path that serves it, or no
6
+ /// path when this computer can't serve it.
7
+ struct Artifact: Decodable, Equatable {
8
+ let name: String
9
+ let mime: String
10
+ /// image, audio, video or file.
11
+ let kind: String
12
+ /// Relative to the daemon; nil when the file is not available here.
13
+ let url: String?
14
+ }
15
+
16
+ enum Artifacts {
17
+ /// The files as HTML, under the answer's text: pictures inline, sound
18
+ /// and video with a player, anything else as an Open link. Each box has
19
+ /// a fixed height, so the answer measures right before media has loaded.
20
+ static func html(_ list: [Artifact], base: String) -> String {
21
+ guard !list.isEmpty else { return "" }
22
+ let items = list.map { a -> String in
23
+ let name = escape(a.name)
24
+ guard let path = a.url else {
25
+ return "<p class=\"ax-missing\">File not available: \(name)</p>"
26
+ }
27
+ let src = escape(base + path)
28
+ switch a.kind {
29
+ case "image": return "<img class=\"ax-media\" src=\"\(src)\" alt=\"\(name)\">"
30
+ case "video": return "<video class=\"ax-media\" src=\"\(src)\" controls preload=\"metadata\"></video>"
31
+ case "audio": return "<audio src=\"\(src)\" controls preload=\"metadata\"></audio><p class=\"ax-name\">\(name)</p>"
32
+ default: return "<p><a href=\"\(src)\">Open \(name)</a></p>"
33
+ }
34
+ }
35
+ return "<div class=\"ax-files\">" + items.joined() + "</div>"
36
+ }
37
+
38
+ /// Added to the card's styles.
39
+ static let css = """
40
+ .ax-files { margin-top: 8px; }
41
+ .ax-media { display: block; width: 100%; height: 180px; object-fit: contain;
42
+ margin: 6px 0; border-radius: 6px; background: color-mix(in srgb, canvastext 6%, transparent); }
43
+ audio { display: block; width: 100%; height: 32px; margin: 6px 0 0; }
44
+ .ax-name, .ax-missing { margin: 2px 0 6px; font-size: 12px; opacity: 0.7; }
45
+ img.md-img { display: block; max-width: 100%; height: 180px; object-fit: contain; margin: 6px 0; }
46
+ """
47
+
48
+ private static func escape(_ s: String) -> String {
49
+ s.replacingOccurrences(of: "&", with: "&amp;")
50
+ .replacingOccurrences(of: "<", with: "&lt;")
51
+ .replacingOccurrences(of: ">", with: "&gt;")
52
+ .replacingOccurrences(of: "\"", with: "&quot;")
53
+ }
54
+ }
@@ -109,6 +109,9 @@ enum Markdown {
109
109
  s = replace(s, #"`([^`]+)`"#, "<code>$1</code>")
110
110
  s = replace(s, #"\*\*([^*]+)\*\*"#, "<strong>$1</strong>")
111
111
  s = replace(s, #"(?<![\*\w])\*([^*]+)\*(?![\*\w])"#, "<em>$1</em>")
112
+ // A picture on the web, before links: `![alt](https://...)` is a
113
+ // link with a `!` in front.
114
+ s = replace(s, #"!\[([^\]"]*)\]\((https?://[^)\s"]+)\)"#, "<img class=\"md-img\" alt=\"$1\" src=\"$2\">")
112
115
  s = replace(s, #"\[([^\]]+)\]\(([^)\s]+)\)"#, "<a href=\"$2\">$1</a>")
113
116
  // Bare URLs, but not ones already inside an href.
114
117
  s = replace(s, #"(?<!["=])\b(https?://[^\s<)]+)"#, "<a href=\"$1\">$1</a>")
@@ -14,9 +14,10 @@ extension Panel {
14
14
  /// Show an answer. The pill grows once it has been measured. A pill
15
15
  /// the person dismissed stays dismissed.
16
16
  @MainActor
17
- func showAnswer(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?) {
17
+ func showAnswer(spoken: String, written: String?, buttons: [(String, String)], imageURL: String?,
18
+ artifacts: [Artifact] = []) {
18
19
  guard !dismissed else { return }
19
- answer.show(spoken: spoken, written: written, buttons: buttons, imageURL: imageURL)
20
+ answer.show(spoken: spoken, written: written, buttons: buttons, imageURL: imageURL, artifacts: artifacts)
20
21
  }
21
22
 
22
23
  /// Grow, or resize while grown, to fit an answer `answerHeight` tall.
@@ -1317,9 +1317,9 @@ final class App: NSObject, NSApplicationDelegate {
1317
1317
  _ = recorder.stop()
1318
1318
  }
1319
1319
  if AnswerView.isWorthShowing(spoken: answer.text, written: answer.written,
1320
- buttons: answer.buttons, imageURL: answer.imageURL) {
1320
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts) {
1321
1321
  panel.showAnswer(spoken: answer.text, written: answer.written,
1322
- buttons: answer.buttons, imageURL: answer.imageURL)
1322
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts)
1323
1323
  }
1324
1324
  shownAnswer = (answer.text, agent, answer.voice)
1325
1325
  noteReset?.cancel()
@@ -1343,7 +1343,7 @@ final class App: NSObject, NSApplicationDelegate {
1343
1343
  private func showAgain(_ id: Int) {
1344
1344
  guard let r = requests.request(id), let answer = answers[id] else { return }
1345
1345
  panel.showAnswer(spoken: answer.text, written: answer.written,
1346
- buttons: answer.buttons, imageURL: answer.imageURL)
1346
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts)
1347
1347
  shownAnswer = (answer.text, answer.agentID ?? r.agentID, answer.voice)
1348
1348
  note(OpenRequests.continueNote(name: statusMenu.name(of: r.agentID)))
1349
1349
  }
@@ -1517,9 +1517,9 @@ final class App: NSObject, NSApplicationDelegate {
1517
1517
  case .success(let answer):
1518
1518
  Log.info("aside answer (\(answer.agentID ?? agent)): \(answer.text)")
1519
1519
  if AnswerView.isWorthShowing(spoken: answer.text, written: answer.written,
1520
- buttons: answer.buttons, imageURL: answer.imageURL) {
1520
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts) {
1521
1521
  panel.showAnswer(spoken: answer.text, written: answer.written,
1522
- buttons: answer.buttons, imageURL: answer.imageURL)
1522
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts)
1523
1523
  shownAnswer = (answer.text, answer.agentID ?? agent, answer.voice)
1524
1524
  }
1525
1525
  // Nothing else on screen: the pill shows this answer, its
@@ -1589,9 +1589,9 @@ final class App: NSObject, NSApplicationDelegate {
1589
1589
  // text than was read aloud. A card that opens on every
1590
1590
  // "Ok." teaches you to ignore it.
1591
1591
  if AnswerView.isWorthShowing(spoken: answer.text, written: answer.written,
1592
- buttons: answer.buttons, imageURL: answer.imageURL) {
1592
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts) {
1593
1593
  panel.showAnswer(spoken: answer.text, written: answer.written,
1594
- buttons: answer.buttons, imageURL: answer.imageURL)
1594
+ buttons: answer.buttons, imageURL: answer.imageURL, artifacts: answer.artifacts)
1595
1595
  shownAnswer = (answer.text, answer.agentID, voice)
1596
1596
  } else {
1597
1597
  panel.collapse()
@@ -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-PIY23C2Z.js";import"./chunk-H7SPRPDG.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-QISI5WM2.js";import"./chunk-QTOOFB4N.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-ODMLQITV.js.map
8
+ //# sourceMappingURL=App-AUKNCAVD.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-PIY23C2Z.js";import"./chunk-H7SPRPDG.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-QISI5WM2.js";import"./chunk-QTOOFB4N.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-MJBOQWUM.js.map
7
+ //# sourceMappingURL=ChatApp-KYQIQZ6Q.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-SHNGAN3L.js";import"./chunk-GGFL7HVN.js";import"./chunk-V2DCI2JL.js";import"./chunk-JTFCU5LH.js";import"./chunk-XRCWM7JA.js";import"./chunk-WPNRDEHW.js";import"./chunk-LUOW2YHY.js";import"./chunk-4LWFJ4MZ.js";import"./chunk-BIJHMWXK.js";import"./chunk-SUVJA67A.js";import"./chunk-72SZI2UW.js";import"./chunk-FCPTN6NF.js";import"./chunk-MCI3DIWW.js";import"./chunk-QUFIUXMQ.js";import"./chunk-BERWTVG2.js";import"./chunk-AHWWJ7AF.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-H7SPRPDG.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-QSUGLOOO.js.map
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-W764F42W.js";import"./chunk-SXL6R3HH.js";import"./chunk-7VHE7WLJ.js";import"./chunk-JTFCU5LH.js";import"./chunk-M6EQBW2F.js";import"./chunk-WPNRDEHW.js";import"./chunk-LUOW2YHY.js";import"./chunk-4LWFJ4MZ.js";import"./chunk-BIJHMWXK.js";import"./chunk-6RJ7ERGC.js";import"./chunk-72SZI2UW.js";import"./chunk-FCPTN6NF.js";import"./chunk-MCI3DIWW.js";import"./chunk-QUFIUXMQ.js";import"./chunk-BERWTVG2.js";import"./chunk-AHWWJ7AF.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import"./chunk-QTOOFB4N.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-TJN5WUYZ.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-BIJ3JIWG.js";import"./chunk-H7SPRPDG.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-KOZSBUXJ.js";import"./chunk-QTOOFB4N.js";import"./chunk-VJ5HC63R.js";import"./chunk-UEEB3UTU.js";import"./chunk-YSCT6DPR.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-BIJ3JIWG.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-BJLSEQ6M.js.map
12
+ //# sourceMappingURL=adapter-VLNSNP6C.js.map
@@ -1,2 +1,2 @@
1
- import{A as a,B as b,C as c}from"./chunk-VX3IZAF6.js";import"./chunk-SFQUP3BP.js";import"./chunk-AHWWJ7AF.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-QJPWZDTL.js.map
1
+ import{A as a,B as b,C as c}from"./chunk-64UGFZPX.js";import"./chunk-SFQUP3BP.js";import"./chunk-AHWWJ7AF.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-KXHSNUNY.js.map