agentix-cli 0.193.0 → 0.195.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.
- package/README.md +1 -1
- package/apps/mac-helper/Sources/AgentXHelper/Presence.swift +70 -6
- package/apps/mac-helper/Sources/AgentXHelper/PresenceTag.swift +42 -5
- package/apps/mac-helper/Sources/AgentXHelper/main.swift +2 -1
- package/apps/mac-voice/Sources/AgentXVoice/AgentClient.swift +107 -4
- package/apps/mac-voice/Sources/AgentXVoice/Config.swift +0 -9
- package/apps/mac-voice/Sources/AgentXVoice/HistoryWindow.swift +3 -2
- package/apps/mac-voice/Sources/AgentXVoice/OpenRequests.swift +276 -8
- package/apps/mac-voice/Sources/AgentXVoice/RequestsWindow.swift +357 -26
- package/apps/mac-voice/Sources/AgentXVoice/SettingsWindow.swift +27 -0
- package/apps/mac-voice/Sources/AgentXVoice/StatusMenu.swift +17 -2
- package/apps/mac-voice/Sources/AgentXVoice/VoiceSettings.swift +23 -1
- package/apps/mac-voice/Sources/AgentXVoice/main.swift +335 -30
- package/dist/{App-6TNGC3UR.js → App-HBM52GXI.js} +2 -2
- package/dist/{ChatApp-FUDLZ6HZ.js → ChatApp-N4P7M2TD.js} +2 -2
- package/dist/{absorb-eval-YSWPPGQF.js → absorb-eval-HRWWPKT3.js} +2 -2
- package/dist/{adapter-EEBNOFDS.js → adapter-X6T3YBUB.js} +2 -2
- package/dist/{agent-QX2POUEM.js → agent-3B4RMEDI.js} +2 -2
- package/dist/{board-dashboard-VVFHNABJ.js → board-dashboard-ZIDDOCOO.js} +1866 -6115
- package/dist/board-dashboard-ZIDDOCOO.js.map +1 -0
- package/dist/{chunk-2O72AHK5.js → chunk-2GCPSAXQ.js} +2 -2
- package/dist/{chunk-KHKG7H6Q.js → chunk-2KYGPVTX.js} +2 -2
- package/dist/chunk-3FZ6WHKX.js +2 -0
- package/dist/{chunk-MQRAQJSS.js.map → chunk-3FZ6WHKX.js.map} +1 -1
- package/dist/{chunk-HNA4BW47.js → chunk-6NQ7KYJH.js} +2 -2
- package/dist/{chunk-Z2NYUCTE.js → chunk-7L54Z4EH.js} +2 -2
- package/dist/{chunk-EH7Y2W77.js → chunk-BOCLWYWL.js} +2 -2
- package/dist/chunk-F2FJXKDG.js +7 -0
- package/dist/{chunk-DS2ZIVIH.js.map → chunk-F2FJXKDG.js.map} +1 -1
- package/dist/{chunk-OYXB6KZX.js → chunk-F3CMNSON.js} +2 -2
- package/dist/{chunk-52NME3AU.js → chunk-FO762MEC.js} +2 -2
- package/dist/{chunk-AAL5WIXB.js → chunk-HNZEXUNM.js} +2 -2
- package/dist/{chunk-H5XBQWAI.js → chunk-HOZZUN47.js} +2 -2
- package/dist/chunk-I45E5TLK.js +934 -0
- package/dist/chunk-I45E5TLK.js.map +1 -0
- package/dist/{chunk-Q7ZPW55P.js → chunk-K2BEV3BD.js} +2 -2
- package/dist/{chunk-QTBFMRJ2.js → chunk-KE6BF4ZJ.js} +2 -2
- package/dist/{chunk-DACZSUCN.js → chunk-KXJRXRSD.js} +2 -2
- package/dist/{chunk-TDZDIDFG.js → chunk-LQIF2OHS.js} +2 -2
- package/dist/chunk-M2E3CNFS.js +38 -0
- package/dist/chunk-M2E3CNFS.js.map +1 -0
- package/dist/{chunk-22WO5X4L.js → chunk-MB5CBY2C.js} +106 -106
- package/dist/chunk-MB5CBY2C.js.map +1 -0
- package/dist/{chunk-JGZ6CA5L.js → chunk-MC3ZZA5G.js} +2 -2
- package/dist/{chunk-PSP3NAFU.js → chunk-OEG476JY.js} +79 -76
- package/dist/chunk-OEG476JY.js.map +1 -0
- package/dist/{chunk-6ZAQ3IT5.js → chunk-P6WSD2UR.js} +23 -23
- package/dist/chunk-P6WSD2UR.js.map +1 -0
- package/dist/{chunk-GLYBXXO7.js → chunk-PMSL4A5Y.js} +3 -3
- package/dist/{chunk-VK2TW3RL.js → chunk-PO2SORKY.js} +2 -2
- package/dist/{chunk-N56EHPTR.js → chunk-PX7PWXBI.js} +2 -2
- package/dist/{chunk-EI3TZ52P.js → chunk-RW5FKJRE.js} +2 -2
- package/dist/{chunk-6FUWODBV.js → chunk-UOIWIVU3.js} +2 -2
- package/dist/{chunk-2VQ3VKBR.js → chunk-VX4PSOKU.js} +2 -2
- package/dist/{chunk-FEXG2PKQ.js → chunk-XH36J3Z2.js} +2 -2
- package/dist/{chunk-462FRP7L.js → chunk-XQF7UUZK.js} +332 -319
- package/dist/chunk-XQF7UUZK.js.map +1 -0
- package/dist/{chunk-MQV3IU6F.js → chunk-ZALVAXQ4.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{client-5USANRIL.js → client-YN3T56NM.js} +2 -2
- package/dist/{config-N7DHUZMH.js → config-G7T3TMWE.js} +2 -2
- package/dist/{config-mutate-OVUXNS5X.js → config-mutate-6CRKZQVQ.js} +2 -2
- package/dist/config-mutator-7VS3J5BY.js +2 -0
- package/dist/{contributions-LTDE6UOQ.js → contributions-6VZ4OXJ5.js} +2 -2
- package/dist/{doctor-C3DTKR7C.js → doctor-GFZZTK7C.js} +2 -2
- package/dist/{follow-up-tool-NCFOTJ5Y.js → follow-up-tool-NVP56W7E.js} +2 -2
- package/dist/{hub-F3X7NL4B.js → hub-B434CABZ.js} +2 -2
- package/dist/index.d.ts +38 -6
- package/dist/index.js +1 -1
- package/dist/{program-6HWZZ2D3.js → program-DW6VZ6LN.js} +238 -238
- package/dist/program-DW6VZ6LN.js.map +1 -0
- package/dist/{promote-FSOPSHJ4.js → promote-3P6PGJOW.js} +2 -2
- package/dist/{query-UDRKDTSB.js → query-E4V7TS5S.js} +2 -2
- package/dist/{query-settings-DJGEGG62.js → query-settings-C5UBKJMN.js} +2 -2
- package/dist/{registry-AVGT5KPR.js → registry-IG324PR3.js} +2 -2
- package/dist/{request-planner-SAQX26AR.js → request-planner-G6IAUMSE.js} +2 -2
- package/dist/{review-candidates-67MPNU42.js → review-candidates-ZL2SJXWC.js} +2 -2
- package/dist/{routing-7DUO5PI7.js → routing-2IBIZYQU.js} +2 -2
- package/dist/schedule-tool-QCTT2R3B.js +2 -0
- package/dist/{scheduler-3IADVHIN.js → scheduler-ZGB7IKZQ.js} +2 -2
- package/dist/{seat-YWSYQBCW.js → seat-CFY7LMPS.js} +2 -2
- package/dist/{select-PA7AHZ3W.js → select-MU52ACKG.js} +2 -2
- package/dist/self-ELWZIMVY.js +2 -0
- package/dist/{set-enabled-DD6L2ZQ6.js → set-enabled-XRNSYEI3.js} +2 -2
- package/dist/{sprint-tool-PKJA6LYF.js → sprint-tool-E4MABD2N.js} +2 -2
- package/dist/{tool-WJ72TBMV.js → tool-V5Z4KWK7.js} +2 -2
- package/dist/{tool-PJSLWK45.js → tool-W6M7GYRZ.js} +2 -2
- package/dist/{tool-KOGZBOCR.js → tool-ZYVT4VUU.js} +2 -2
- package/dist/{wiki-HQBMWH23.js → wiki-VP6XRWIS.js} +2 -2
- package/dist/wiki-enrich-LUFXPUYY.js +2 -0
- package/package.json +1 -1
- package/dist/board-dashboard-VVFHNABJ.js.map +0 -1
- package/dist/chunk-22WO5X4L.js.map +0 -1
- package/dist/chunk-462FRP7L.js.map +0 -1
- package/dist/chunk-6ZAQ3IT5.js.map +0 -1
- package/dist/chunk-BKTKJNCR.js +0 -36
- package/dist/chunk-BKTKJNCR.js.map +0 -1
- package/dist/chunk-DS2ZIVIH.js +0 -7
- package/dist/chunk-MQRAQJSS.js +0 -2
- package/dist/chunk-PSP3NAFU.js.map +0 -1
- package/dist/chunk-RDENYWNG.js +0 -898
- package/dist/chunk-RDENYWNG.js.map +0 -1
- package/dist/config-mutator-OK7CDCHW.js +0 -2
- package/dist/program-6HWZZ2D3.js.map +0 -1
- package/dist/schedule-tool-LZOW5SVQ.js +0 -2
- package/dist/self-KACQLLDA.js +0 -2
- package/dist/wiki-enrich-7RPM5DQF.js +0 -2
- /package/dist/{App-6TNGC3UR.js.map → App-HBM52GXI.js.map} +0 -0
- /package/dist/{ChatApp-FUDLZ6HZ.js.map → ChatApp-N4P7M2TD.js.map} +0 -0
- /package/dist/{absorb-eval-YSWPPGQF.js.map → absorb-eval-HRWWPKT3.js.map} +0 -0
- /package/dist/{adapter-EEBNOFDS.js.map → adapter-X6T3YBUB.js.map} +0 -0
- /package/dist/{agent-QX2POUEM.js.map → agent-3B4RMEDI.js.map} +0 -0
- /package/dist/{chunk-2O72AHK5.js.map → chunk-2GCPSAXQ.js.map} +0 -0
- /package/dist/{chunk-KHKG7H6Q.js.map → chunk-2KYGPVTX.js.map} +0 -0
- /package/dist/{chunk-HNA4BW47.js.map → chunk-6NQ7KYJH.js.map} +0 -0
- /package/dist/{chunk-Z2NYUCTE.js.map → chunk-7L54Z4EH.js.map} +0 -0
- /package/dist/{chunk-EH7Y2W77.js.map → chunk-BOCLWYWL.js.map} +0 -0
- /package/dist/{chunk-OYXB6KZX.js.map → chunk-F3CMNSON.js.map} +0 -0
- /package/dist/{chunk-52NME3AU.js.map → chunk-FO762MEC.js.map} +0 -0
- /package/dist/{chunk-AAL5WIXB.js.map → chunk-HNZEXUNM.js.map} +0 -0
- /package/dist/{chunk-H5XBQWAI.js.map → chunk-HOZZUN47.js.map} +0 -0
- /package/dist/{chunk-Q7ZPW55P.js.map → chunk-K2BEV3BD.js.map} +0 -0
- /package/dist/{chunk-QTBFMRJ2.js.map → chunk-KE6BF4ZJ.js.map} +0 -0
- /package/dist/{chunk-DACZSUCN.js.map → chunk-KXJRXRSD.js.map} +0 -0
- /package/dist/{chunk-TDZDIDFG.js.map → chunk-LQIF2OHS.js.map} +0 -0
- /package/dist/{chunk-JGZ6CA5L.js.map → chunk-MC3ZZA5G.js.map} +0 -0
- /package/dist/{chunk-GLYBXXO7.js.map → chunk-PMSL4A5Y.js.map} +0 -0
- /package/dist/{chunk-VK2TW3RL.js.map → chunk-PO2SORKY.js.map} +0 -0
- /package/dist/{chunk-N56EHPTR.js.map → chunk-PX7PWXBI.js.map} +0 -0
- /package/dist/{chunk-EI3TZ52P.js.map → chunk-RW5FKJRE.js.map} +0 -0
- /package/dist/{chunk-6FUWODBV.js.map → chunk-UOIWIVU3.js.map} +0 -0
- /package/dist/{chunk-2VQ3VKBR.js.map → chunk-VX4PSOKU.js.map} +0 -0
- /package/dist/{chunk-FEXG2PKQ.js.map → chunk-XH36J3Z2.js.map} +0 -0
- /package/dist/{chunk-MQV3IU6F.js.map → chunk-ZALVAXQ4.js.map} +0 -0
- /package/dist/{client-5USANRIL.js.map → client-YN3T56NM.js.map} +0 -0
- /package/dist/{config-N7DHUZMH.js.map → config-G7T3TMWE.js.map} +0 -0
- /package/dist/{config-mutate-OVUXNS5X.js.map → config-mutate-6CRKZQVQ.js.map} +0 -0
- /package/dist/{config-mutator-OK7CDCHW.js.map → config-mutator-7VS3J5BY.js.map} +0 -0
- /package/dist/{contributions-LTDE6UOQ.js.map → contributions-6VZ4OXJ5.js.map} +0 -0
- /package/dist/{doctor-C3DTKR7C.js.map → doctor-GFZZTK7C.js.map} +0 -0
- /package/dist/{follow-up-tool-NCFOTJ5Y.js.map → follow-up-tool-NVP56W7E.js.map} +0 -0
- /package/dist/{hub-F3X7NL4B.js.map → hub-B434CABZ.js.map} +0 -0
- /package/dist/{promote-FSOPSHJ4.js.map → promote-3P6PGJOW.js.map} +0 -0
- /package/dist/{query-UDRKDTSB.js.map → query-E4V7TS5S.js.map} +0 -0
- /package/dist/{query-settings-DJGEGG62.js.map → query-settings-C5UBKJMN.js.map} +0 -0
- /package/dist/{registry-AVGT5KPR.js.map → registry-IG324PR3.js.map} +0 -0
- /package/dist/{request-planner-SAQX26AR.js.map → request-planner-G6IAUMSE.js.map} +0 -0
- /package/dist/{review-candidates-67MPNU42.js.map → review-candidates-ZL2SJXWC.js.map} +0 -0
- /package/dist/{routing-7DUO5PI7.js.map → routing-2IBIZYQU.js.map} +0 -0
- /package/dist/{schedule-tool-LZOW5SVQ.js.map → schedule-tool-QCTT2R3B.js.map} +0 -0
- /package/dist/{scheduler-3IADVHIN.js.map → scheduler-ZGB7IKZQ.js.map} +0 -0
- /package/dist/{seat-YWSYQBCW.js.map → seat-CFY7LMPS.js.map} +0 -0
- /package/dist/{select-PA7AHZ3W.js.map → select-MU52ACKG.js.map} +0 -0
- /package/dist/{self-KACQLLDA.js.map → self-ELWZIMVY.js.map} +0 -0
- /package/dist/{set-enabled-DD6L2ZQ6.js.map → set-enabled-XRNSYEI3.js.map} +0 -0
- /package/dist/{sprint-tool-PKJA6LYF.js.map → sprint-tool-E4MABD2N.js.map} +0 -0
- /package/dist/{tool-WJ72TBMV.js.map → tool-V5Z4KWK7.js.map} +0 -0
- /package/dist/{tool-PJSLWK45.js.map → tool-W6M7GYRZ.js.map} +0 -0
- /package/dist/{tool-KOGZBOCR.js.map → tool-ZYVT4VUU.js.map} +0 -0
- /package/dist/{wiki-HQBMWH23.js.map → wiki-VP6XRWIS.js.map} +0 -0
- /package/dist/{wiki-enrich-7RPM5DQF.js.map → wiki-enrich-LUFXPUYY.js.map} +0 -0
|
@@ -40,6 +40,10 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
40
40
|
private var settings: VoiceSettings?
|
|
41
41
|
/// The agent a per-agent shortcut is asking; nil for the talk key.
|
|
42
42
|
private var forcedAgent: String?
|
|
43
|
+
/// The open request picked in the list: words to its agent continue
|
|
44
|
+
/// it rather than add a row (#1455). Ends when the row closes or the
|
|
45
|
+
/// words go to another agent.
|
|
46
|
+
private var picked: Int?
|
|
43
47
|
/// Set by a stop: the answer being spoken ends without reopening the mic.
|
|
44
48
|
private var silenced = false
|
|
45
49
|
private var busy = false
|
|
@@ -102,6 +106,17 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
102
106
|
private var hoverOpen: DispatchWorkItem?
|
|
103
107
|
/// Puts the pill back to rest after a passing line.
|
|
104
108
|
private var noteReset: DispatchWorkItem?
|
|
109
|
+
/// Counts changes this app sends to the daemon's list: a read of the
|
|
110
|
+
/// list that started before one of them is stale and is dropped.
|
|
111
|
+
private var requestsEpoch = 0
|
|
112
|
+
/// Did the daemon answer the last read of the list? Nil before the
|
|
113
|
+
/// first answer.
|
|
114
|
+
private var daemonReachable: Bool?
|
|
115
|
+
/// The row closed last, with its answer, while Undo shows.
|
|
116
|
+
private var lastClosed: (request: OpenRequests.Request, answer: AgentClient.Answer?)?
|
|
117
|
+
private var undoReset: DispatchWorkItem?
|
|
118
|
+
/// voice.answers is "play": an answer plays as soon as it is back.
|
|
119
|
+
private var playsAtOnce: Bool { settings?.general.answers == "play" }
|
|
105
120
|
|
|
106
121
|
// An agent ringing the owner (#321).
|
|
107
122
|
private let callWatcher = CallWatcher()
|
|
@@ -127,10 +142,10 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
127
142
|
private var activeCall: IncomingCall?
|
|
128
143
|
|
|
129
144
|
/// /ask, counted in flight for the menu while it thinks.
|
|
130
|
-
private func ask(_ heard: String, agent: String, handsFree: Bool = false) async throws -> AgentClient.Answer {
|
|
145
|
+
private func ask(_ heard: String, agent: String, handsFree: Bool = false, request: String? = nil) async throws -> AgentClient.Answer {
|
|
131
146
|
track(agent, 1)
|
|
132
147
|
defer { track(agent, -1) }
|
|
133
|
-
return try await AgentClient.ask(heard, agent: agent, handsFree: handsFree)
|
|
148
|
+
return try await AgentClient.ask(heard, agent: agent, handsFree: handsFree, request: request)
|
|
134
149
|
}
|
|
135
150
|
|
|
136
151
|
/// The floor was taken, renewed or freed (#924). A recording takes
|
|
@@ -226,7 +241,7 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
226
241
|
// Hold to talk; release sends. With a row picked by the keyboard in
|
|
227
242
|
// the open-requests list, the words go to that row's agent.
|
|
228
243
|
let talk = Hotkey(id: 1,
|
|
229
|
-
onPress: { [weak self] in self?.
|
|
244
|
+
onPress: { [weak self] in self?.talkFromList(); self?.startListening() },
|
|
230
245
|
onRelease: { [weak self] in self?.stopAndSend() })
|
|
231
246
|
register(talk, spec(keys?.talk, "opt+space"), "talk")
|
|
232
247
|
hotkey = talk
|
|
@@ -282,6 +297,7 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
282
297
|
character.setShown(asCharacter)
|
|
283
298
|
character.strolls = saved.general.stroll == true
|
|
284
299
|
character.animates = IdlePlay.gap(saved.general.animations)
|
|
300
|
+
statusMenu.playsAnswersAtOnce = saved.general.answers == "play"
|
|
285
301
|
if !asCharacter { panel.detach() }
|
|
286
302
|
idleWords()
|
|
287
303
|
// voice.startReduced is how the assistant starts: read once. With
|
|
@@ -504,6 +520,28 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
504
520
|
requestsWindow.rows = { [weak self] newestLast in self?.listRows(newestLast: newestLast) ?? [] }
|
|
505
521
|
requestsWindow.pillFrame = { [weak self] in self?.panel.frame ?? .zero }
|
|
506
522
|
requestsWindow.model.onPick = { [weak self] id in self?.pick(id) }
|
|
523
|
+
requestsWindow.model.onClose = { [weak self] id in self?.closeRow(id) }
|
|
524
|
+
requestsWindow.model.onConfirm = { [weak self] id, choice in self?.confirmClose(id, choice) }
|
|
525
|
+
requestsWindow.model.onUndo = { [weak self] in self?.undoClose() }
|
|
526
|
+
requestsWindow.model.onCloseHeard = { [weak self] in self?.closeHeard() }
|
|
527
|
+
requestsWindow.model.onHistory = { [weak self] agent in
|
|
528
|
+
self?.requestsWindow.dismissList()
|
|
529
|
+
HistoryWindow.shared.show(agent: agent)
|
|
530
|
+
}
|
|
531
|
+
requestsWindow.model.onAskAgain = { [weak self] id in self?.askAgain(id) }
|
|
532
|
+
requestsWindow.model.onRetry = { [weak self] in Task { @MainActor in await self?.syncRequests() } }
|
|
533
|
+
requestsWindow.model.onDashboard = {
|
|
534
|
+
if let url = URL(string: Config.dashboardURL + "/admin") { NSWorkspace.shared.open(url) }
|
|
535
|
+
}
|
|
536
|
+
statusMenu.onPlayAtOnce = { [weak self] on in self?.setPlayAtOnce(on) }
|
|
537
|
+
// The daemon keeps the list (#1455): read it now and every few
|
|
538
|
+
// seconds, for rows kept across a restart and heard elsewhere.
|
|
539
|
+
Task { @MainActor [weak self] in
|
|
540
|
+
while true {
|
|
541
|
+
await self?.syncRequests()
|
|
542
|
+
try? await Task.sleep(for: .seconds(5))
|
|
543
|
+
}
|
|
544
|
+
}
|
|
507
545
|
panel.onOpenList = { [weak self] in self?.openList(keyboard: false) }
|
|
508
546
|
panel.onHover = { [weak self] inside in self?.pillHover(inside) }
|
|
509
547
|
statusMenu.onOpenRequests = { [weak self] in self?.openList(keyboard: true) }
|
|
@@ -947,13 +985,44 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
947
985
|
// --- Open requests (#1455) ---
|
|
948
986
|
|
|
949
987
|
/// Send a request and move on: it runs on its own, or waits behind the
|
|
950
|
-
/// one its agent is still thinking about.
|
|
988
|
+
/// one its agent is still thinking about. With a row picked for that
|
|
989
|
+
/// agent, the words continue that row instead.
|
|
951
990
|
private func send(_ heard: String, agent: String) {
|
|
991
|
+
if let id = picked, requests.request(id)?.agentID == agent {
|
|
992
|
+
follow(id, heard)
|
|
993
|
+
return
|
|
994
|
+
}
|
|
995
|
+
picked = nil
|
|
952
996
|
let id = requests.add(agentID: agent, question: heard, at: Date())
|
|
953
|
-
|
|
954
|
-
|
|
997
|
+
let waits = requests.request(id)?.phase == .waiting
|
|
998
|
+
Log.info("request \(id) → \(agent)\(waits ? " (waits its turn)" : ""): \(heard)")
|
|
955
999
|
requestsChanged()
|
|
956
1000
|
note("\(statusMenu.name(of: agent)) · \(OpenRequests.sentNote)")
|
|
1001
|
+
// The daemon keeps the row too, so it outlives the app and every
|
|
1002
|
+
// client sees it. Without the daemon the app's own list goes on.
|
|
1003
|
+
requestsEpoch += 1
|
|
1004
|
+
Task { @MainActor in
|
|
1005
|
+
if let key = await AgentClient.openRequest(agentID: agent, question: heard, waiting: waits) {
|
|
1006
|
+
requests.setKey(id, key)
|
|
1007
|
+
}
|
|
1008
|
+
if !waits, requests.request(id)?.phase == .thinking { run(id) }
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/// A follow-up for the picked row: it asks again in the same row, waits
|
|
1013
|
+
/// its agent's turn, or goes once the answer in flight is back.
|
|
1014
|
+
private func follow(_ id: Int, _ heard: String) {
|
|
1015
|
+
guard let how = requests.follow(id, with: heard, at: Date()), let r = requests.request(id) else { return }
|
|
1016
|
+
Log.info("request \(id) continued (\(how)) → \(r.agentID): \(heard)")
|
|
1017
|
+
answers[id] = nil
|
|
1018
|
+
requestsChanged()
|
|
1019
|
+
note("\(statusMenu.name(of: r.agentID)) · \(OpenRequests.followNote)")
|
|
1020
|
+
guard how != .after else { return }
|
|
1021
|
+
requestsEpoch += 1
|
|
1022
|
+
Task { @MainActor in
|
|
1023
|
+
if let key = r.key { await AgentClient.continueRequest(key, question: r.question, waiting: how == .waits) }
|
|
1024
|
+
if how == .ask, requests.request(id)?.phase == .thinking { run(id) }
|
|
1025
|
+
}
|
|
957
1026
|
}
|
|
958
1027
|
|
|
959
1028
|
/// Ask the agent. The answer waits as not heard, with a soft sound, or
|
|
@@ -963,13 +1032,31 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
963
1032
|
guard let r = requests.request(id) else { return }
|
|
964
1033
|
Task { @MainActor in
|
|
965
1034
|
let result: Result<AgentClient.Answer, Error>
|
|
966
|
-
do { result = .success(try await ask(r.question, agent: r.agentID)) }
|
|
1035
|
+
do { result = .success(try await ask(r.question, agent: r.agentID, request: requests.request(id)?.key)) }
|
|
967
1036
|
catch { result = .failure(error) }
|
|
968
1037
|
let now = Date()
|
|
1038
|
+
// Words spoken while it thought go now, in the same row; the
|
|
1039
|
+
// answer they talked over is not played (it stays in History).
|
|
1040
|
+
// When the daemon dropped the first words, the kept follow-up
|
|
1041
|
+
// still goes: it is the owner's own words, not lost with them.
|
|
1042
|
+
let dropped = (try? result.get())?.dropped == true
|
|
1043
|
+
let again = dropped ? requests.dropped(id, at: now) : requests.takePending(id, at: now)
|
|
1044
|
+
if dropped && !again {
|
|
1045
|
+
Log.info("request \(id): the daemon took the words for the floor holder's sound")
|
|
1046
|
+
}
|
|
1047
|
+
if again {
|
|
1048
|
+
Log.info("request \(id): asking the follow-up kept while it thought\(dropped ? " (the first words were dropped)" : "")")
|
|
1049
|
+
requestsChanged()
|
|
1050
|
+
if let key = requests.request(id)?.key, let q = requests.request(id)?.question {
|
|
1051
|
+
requestsEpoch += 1
|
|
1052
|
+
await AgentClient.continueRequest(key, question: q, waiting: false)
|
|
1053
|
+
}
|
|
1054
|
+
run(id)
|
|
1055
|
+
return
|
|
1056
|
+
}
|
|
969
1057
|
switch result {
|
|
970
1058
|
case .success(let answer) where answer.dropped:
|
|
971
|
-
|
|
972
|
-
requests.remove(id)
|
|
1059
|
+
break // the row already left in requests.dropped
|
|
973
1060
|
case .success(let answer):
|
|
974
1061
|
Log.info("request \(id) answered (\(answer.agentID ?? r.agentID)): \(answer.text)")
|
|
975
1062
|
answers[id] = answer
|
|
@@ -981,7 +1068,7 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
981
1068
|
if let next = requests.startNext(for: r.agentID, at: now) { run(next) }
|
|
982
1069
|
requestsChanged()
|
|
983
1070
|
guard let done = requests.request(id) else { return }
|
|
984
|
-
if done.phase == .answered &&
|
|
1071
|
+
if done.phase == .answered && playsAtOnce {
|
|
985
1072
|
await waitForFloor(r.agentID, ownTurn: false)
|
|
986
1073
|
if requests.request(id)?.heard == false { play(id) }
|
|
987
1074
|
return
|
|
@@ -1005,7 +1092,10 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1005
1092
|
else { note(OpenRequests.readyNote(name: name)) }
|
|
1006
1093
|
// Quiet while notifications are held, while someone holds the floor,
|
|
1007
1094
|
// and while the microphone is open, which would hear it.
|
|
1008
|
-
|
|
1095
|
+
// The sound picked in Settings › General › Answers (voice.readySound).
|
|
1096
|
+
if !Hold.isOn && !floorWatcher.state.held && !recorder.isRecording {
|
|
1097
|
+
NSSound(named: settings?.general.readySound ?? "Pop")?.play()
|
|
1098
|
+
}
|
|
1009
1099
|
}
|
|
1010
1100
|
|
|
1011
1101
|
/// A passing line on the pill at rest, back to the pill's own after
|
|
@@ -1032,6 +1122,12 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1032
1122
|
// Rows that left the list take their answers with them.
|
|
1033
1123
|
let kept = Set(requests.requests.map(\.id))
|
|
1034
1124
|
answers = answers.filter { kept.contains($0.key) }
|
|
1125
|
+
if let id = picked, !kept.contains(id) { picked = nil }
|
|
1126
|
+
requestsWindow.model.total = requests.requests.count
|
|
1127
|
+
requestsWindow.model.hasHeard = requests.requests.contains { r in
|
|
1128
|
+
if case .failed = r.phase { return true }
|
|
1129
|
+
return r.phase == .answered && r.heard
|
|
1130
|
+
}
|
|
1035
1131
|
publishThinking()
|
|
1036
1132
|
refreshBusy()
|
|
1037
1133
|
panel.showNew(requests.newCount)
|
|
@@ -1039,9 +1135,20 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1039
1135
|
requestsWindow.reload()
|
|
1040
1136
|
}
|
|
1041
1137
|
|
|
1042
|
-
/// The
|
|
1043
|
-
|
|
1044
|
-
|
|
1138
|
+
/// The talk key pressed: with a request selected in the open list,
|
|
1139
|
+
/// the words go to its agent and continue it; with an agent's row
|
|
1140
|
+
/// selected, or an agent opened, they go to that agent as a new
|
|
1141
|
+
/// request. With the list shut, the row picked last stays picked.
|
|
1142
|
+
private func talkFromList() {
|
|
1143
|
+
if let id = requestsWindow.selectedRow, let r = requests.request(id) {
|
|
1144
|
+
picked = id
|
|
1145
|
+
forcedAgent = r.agentID
|
|
1146
|
+
} else if let agent = requestsWindow.selectedAgent {
|
|
1147
|
+
picked = nil
|
|
1148
|
+
forcedAgent = agent
|
|
1149
|
+
} else {
|
|
1150
|
+
forcedAgent = nil
|
|
1151
|
+
}
|
|
1045
1152
|
}
|
|
1046
1153
|
|
|
1047
1154
|
/// Open the list: by a click (no keyboard), or by ⌘⌥O or the menu
|
|
@@ -1051,6 +1158,20 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1051
1158
|
hoverOpen = nil
|
|
1052
1159
|
if keyboard { summonPill() }
|
|
1053
1160
|
requestsWindow.open(.pinned, select: keyboard ? requests.firstSelection : nil)
|
|
1161
|
+
loadingIfSlow()
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/// Placeholder rows in the list, only while the daemon has not
|
|
1165
|
+
/// answered its first read half a second after the list opened.
|
|
1166
|
+
private func loadingIfSlow() {
|
|
1167
|
+
guard daemonReachable == nil else { return }
|
|
1168
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + OpenRequests.loadingAfter) { [weak self] in
|
|
1169
|
+
MainActor.assumeIsolated {
|
|
1170
|
+
guard let self, self.daemonReachable == nil, self.requestsWindow.isOpen else { return }
|
|
1171
|
+
self.requestsWindow.model.status = .loading
|
|
1172
|
+
self.requestsWindow.reload()
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1054
1175
|
}
|
|
1055
1176
|
|
|
1056
1177
|
/// Half a second on the pill opens the list, while there is a request
|
|
@@ -1059,11 +1180,13 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1059
1180
|
hoverOpen?.cancel()
|
|
1060
1181
|
hoverOpen = nil
|
|
1061
1182
|
guard inside else { requestsWindow.pointerLeft(); return }
|
|
1062
|
-
|
|
1183
|
+
// voice.listOnHover off: only a click or ⌘⌥O opens it.
|
|
1184
|
+
guard settings?.general.listOnHover != false, !requests.requests.isEmpty, !requestsWindow.isOpen, !recorder.isRecording else { return }
|
|
1063
1185
|
let open = DispatchWorkItem { [weak self] in
|
|
1064
1186
|
MainActor.assumeIsolated {
|
|
1065
1187
|
guard let self, self.panel.hovering, !self.recorder.isRecording else { return }
|
|
1066
1188
|
self.requestsWindow.open(.hover)
|
|
1189
|
+
self.loadingIfSlow()
|
|
1067
1190
|
}
|
|
1068
1191
|
}
|
|
1069
1192
|
hoverOpen = open
|
|
@@ -1073,7 +1196,30 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1073
1196
|
/// The list's rows, as OpenRequests words them.
|
|
1074
1197
|
private func listRows(newestLast: Bool) -> [RequestsModel.Row] {
|
|
1075
1198
|
let now = Date()
|
|
1076
|
-
|
|
1199
|
+
let opened = requestsWindow.model.opened
|
|
1200
|
+
if let opened { requestsWindow.model.openedName = statusMenu.name(of: opened) }
|
|
1201
|
+
if opened == nil && requests.grouped {
|
|
1202
|
+
return requests.groups(newestLast: newestLast).map { g in
|
|
1203
|
+
let name = statusMenu.name(of: g.agentID)
|
|
1204
|
+
let cue: RequestsModel.Row.Cue
|
|
1205
|
+
if g.requests.contains(where: { $0.isNew && $0.phase == .answered }) { cue = .ready }
|
|
1206
|
+
else if g.requests.contains(where: \.isNew) { cue = .failed }
|
|
1207
|
+
else if g.requests.contains(where: { $0.phase == .thinking }) { cue = .thinking }
|
|
1208
|
+
else if g.requests.contains(where: { $0.phase == .waiting }) { cue = .waiting }
|
|
1209
|
+
else { cue = .heard }
|
|
1210
|
+
let state = OpenRequests.groupState(g)
|
|
1211
|
+
let count = OpenRequests.requestsCount(g.requests.count)
|
|
1212
|
+
let latest = OpenRequests.firstWords(g.latest.question)
|
|
1213
|
+
return RequestsModel.Row(
|
|
1214
|
+
id: g.id, name: name, state: state,
|
|
1215
|
+
words: state == count ? latest : count + " · " + latest,
|
|
1216
|
+
ago: OpenRequests.ago(Int(now.timeIntervalSince(g.latest.sentAt))),
|
|
1217
|
+
cue: cue, isNew: g.newCount > 0,
|
|
1218
|
+
tint: statusMenu.color(of: g.agentID), colors: statusMenu.palette(of: g.agentID),
|
|
1219
|
+
voiceOver: OpenRequests.groupVoiceOver(name: name, g), action: "Open", agent: g.agentID)
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return requests.rows(newestLast: newestLast, agentID: opened).map { r in
|
|
1077
1223
|
let name = statusMenu.name(of: r.agentID)
|
|
1078
1224
|
let cue: RequestsModel.Row.Cue
|
|
1079
1225
|
let action: String?
|
|
@@ -1083,31 +1229,76 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1083
1229
|
case .answered: cue = r.heard ? .heard : .ready; action = r.heard ? "Show the answer" : "Listen"
|
|
1084
1230
|
case .failed: cue = .failed; action = "See why"
|
|
1085
1231
|
}
|
|
1232
|
+
var reason: String?
|
|
1233
|
+
if case .failed(let why) = r.phase { reason = why }
|
|
1086
1234
|
return RequestsModel.Row(
|
|
1087
1235
|
id: r.id, name: name, state: OpenRequests.stateWords(r, now: now),
|
|
1088
1236
|
words: OpenRequests.firstWords(r.question),
|
|
1089
1237
|
ago: OpenRequests.ago(Int(now.timeIntervalSince(r.sentAt))),
|
|
1090
1238
|
cue: cue, isNew: r.isNew,
|
|
1091
1239
|
tint: statusMenu.color(of: r.agentID), colors: statusMenu.palette(of: r.agentID),
|
|
1092
|
-
voiceOver: OpenRequests.voiceOver(name: name, r, now: now), action: action)
|
|
1240
|
+
voiceOver: OpenRequests.voiceOver(name: name, r, now: now), action: action, reason: reason)
|
|
1093
1241
|
}
|
|
1094
1242
|
}
|
|
1095
1243
|
|
|
1096
1244
|
/// 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
|
|
1245
|
+
/// shows its text again (Listen again plays it), a failure opens in
|
|
1246
|
+
/// place with why and Ask again. Its agent becomes the one the next
|
|
1247
|
+
/// words go to, so they continue that conversation: the daemon runs
|
|
1248
|
+
/// every request in the phone's conversation with the agent, so it is
|
|
1249
|
+
/// the same session and thread as the phone's.
|
|
1098
1250
|
private func pick(_ id: Int) {
|
|
1099
1251
|
guard let r = requests.request(id) else { return }
|
|
1100
|
-
|
|
1101
|
-
|
|
1252
|
+
statusMenu.choose(r.agentID)
|
|
1253
|
+
picked = id
|
|
1254
|
+
let name = statusMenu.name(of: r.agentID)
|
|
1255
|
+
if case .reason = OpenRequests.pick(r) {
|
|
1256
|
+
markHeard(id)
|
|
1257
|
+
requestsWindow.model.selected = id
|
|
1258
|
+
requestsWindow.model.expanded = requestsWindow.model.expanded == id ? nil : id
|
|
1259
|
+
requestsWindow.reload()
|
|
1260
|
+
return
|
|
1261
|
+
}
|
|
1102
1262
|
requestsWindow.dismissList()
|
|
1103
|
-
switch
|
|
1104
|
-
case .nothing:
|
|
1105
|
-
case .listen: play(id)
|
|
1106
|
-
case .show: showAgain(id)
|
|
1107
|
-
case .reason
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1263
|
+
switch OpenRequests.pick(r) {
|
|
1264
|
+
case .nothing: note(OpenRequests.continueNote(name: name))
|
|
1265
|
+
case .listen: withAnswer(id) { [weak self] in self?.play(id) }
|
|
1266
|
+
case .show: withAnswer(id) { [weak self] in self?.showAgain(id) }
|
|
1267
|
+
case .reason: break
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
/// "Ask again" on a failed row: the same words, in the same row, as a
|
|
1272
|
+
/// follow-up (it waits its turn if the agent has another request out).
|
|
1273
|
+
private func askAgain(_ id: Int) {
|
|
1274
|
+
guard let r = requests.request(id), case .failed = r.phase else { return }
|
|
1275
|
+
requestsWindow.model.expanded = nil
|
|
1276
|
+
picked = id
|
|
1277
|
+
Log.info("request \(id): asked again (\(r.agentID))")
|
|
1278
|
+
follow(id, r.question)
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/// Heard here and, through the daemon, on every client.
|
|
1282
|
+
private func markHeard(_ id: Int) {
|
|
1283
|
+
requests.heard(id)
|
|
1284
|
+
requestsChanged()
|
|
1285
|
+
guard let key = requests.request(id)?.key else { return }
|
|
1286
|
+
requestsEpoch += 1
|
|
1287
|
+
Task { await AgentClient.requestHeard(key) }
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/// Run `then` once the row's answer is here: a row found on the
|
|
1291
|
+
/// daemon (after a restart) fetches the answer it kept.
|
|
1292
|
+
private func withAnswer(_ id: Int, then: @escaping () -> Void) {
|
|
1293
|
+
if answers[id] != nil { then(); return }
|
|
1294
|
+
guard let key = requests.request(id)?.key else { return }
|
|
1295
|
+
Task { @MainActor in
|
|
1296
|
+
guard let answer = await AgentClient.requestAnswer(key) else {
|
|
1297
|
+
note("That answer is no longer kept. Open History to find it.")
|
|
1298
|
+
return
|
|
1299
|
+
}
|
|
1300
|
+
answers[id] = answer
|
|
1301
|
+
then()
|
|
1111
1302
|
}
|
|
1112
1303
|
}
|
|
1113
1304
|
|
|
@@ -1116,8 +1307,7 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1116
1307
|
/// the stop shortcut, stops it.
|
|
1117
1308
|
private func play(_ id: Int) {
|
|
1118
1309
|
guard let r = requests.request(id), let answer = answers[id] else { return }
|
|
1119
|
-
|
|
1120
|
-
requestsChanged()
|
|
1310
|
+
markHeard(id)
|
|
1121
1311
|
let agent = answer.agentID ?? r.agentID
|
|
1122
1312
|
Log.info("request \(id): playing (\(agent))")
|
|
1123
1313
|
endReplay()
|
|
@@ -1155,6 +1345,121 @@ final class App: NSObject, NSApplicationDelegate {
|
|
|
1155
1345
|
panel.showAnswer(spoken: answer.text, written: answer.written,
|
|
1156
1346
|
buttons: answer.buttons, imageURL: answer.imageURL)
|
|
1157
1347
|
shownAnswer = (answer.text, answer.agentID ?? r.agentID, answer.voice)
|
|
1348
|
+
note(OpenRequests.continueNote(name: statusMenu.name(of: r.agentID)))
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// --- Closing a row ---
|
|
1352
|
+
|
|
1353
|
+
/// The row's ×, or ⌘⌫ on it. A row still thinking asks first; the
|
|
1354
|
+
/// rest close at once, with Undo.
|
|
1355
|
+
private func closeRow(_ id: Int) {
|
|
1356
|
+
guard let r = requests.request(id) else { return }
|
|
1357
|
+
if OpenRequests.closeNeedsConfirm(r) { requestsWindow.model.confirming = id; return }
|
|
1358
|
+
close(id, stop: false)
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/// The confirm's answer for a thinking row.
|
|
1362
|
+
private func confirmClose(_ id: Int, _ choice: RequestsModel.CloseChoice) {
|
|
1363
|
+
requestsWindow.model.confirming = nil
|
|
1364
|
+
switch choice {
|
|
1365
|
+
case .letItFinish: close(id, stop: false)
|
|
1366
|
+
case .stop: close(id, stop: true)
|
|
1367
|
+
case .keep: return
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/// The row leaves the list, here and on the daemon. `stop` also stops
|
|
1372
|
+
/// its agent; never the default. A closed row's answer, when it comes,
|
|
1373
|
+
/// goes to History with no sound.
|
|
1374
|
+
private func close(_ id: Int, stop: Bool) {
|
|
1375
|
+
guard let r = requests.close(id) else { return }
|
|
1376
|
+
lastClosed = (r, answers[id])
|
|
1377
|
+
requestsChanged()
|
|
1378
|
+
Log.info("request \(id) closed\(stop ? ", stopping \(r.agentID)" : "")")
|
|
1379
|
+
if let key = r.key {
|
|
1380
|
+
requestsEpoch += 1
|
|
1381
|
+
Task { await AgentClient.closeRequest(key, stop: stop) }
|
|
1382
|
+
}
|
|
1383
|
+
offerUndo(OpenRequests.closedNote(name: statusMenu.name(of: r.agentID)))
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/// "Close heard": every heard answer and every failure.
|
|
1387
|
+
private func closeHeard() {
|
|
1388
|
+
let gone = requests.closeHeard()
|
|
1389
|
+
guard !gone.isEmpty else { return }
|
|
1390
|
+
requestsChanged()
|
|
1391
|
+
requestsEpoch += 1
|
|
1392
|
+
Task { await AgentClient.closeHeardRequests() }
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/// "Closed Ops’s request · Undo" for five seconds.
|
|
1396
|
+
private func offerUndo(_ text: String) {
|
|
1397
|
+
undoReset?.cancel()
|
|
1398
|
+
requestsWindow.model.undo = text
|
|
1399
|
+
requestsWindow.reload()
|
|
1400
|
+
let reset = DispatchWorkItem { [weak self] in
|
|
1401
|
+
MainActor.assumeIsolated {
|
|
1402
|
+
self?.requestsWindow.model.undo = nil
|
|
1403
|
+
self?.lastClosed = nil
|
|
1404
|
+
self?.requestsWindow.reload()
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
undoReset = reset
|
|
1408
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + OpenRequests.undoSeconds, execute: reset)
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
private func undoClose() {
|
|
1412
|
+
undoReset?.cancel()
|
|
1413
|
+
requestsWindow.model.undo = nil
|
|
1414
|
+
requestsWindow.reload()
|
|
1415
|
+
guard let closed = lastClosed else { return }
|
|
1416
|
+
let (r, answer) = (closed.request, closed.answer)
|
|
1417
|
+
lastClosed = nil
|
|
1418
|
+
requests.restore(r)
|
|
1419
|
+
if let answer { answers[r.id] = answer }
|
|
1420
|
+
requestsChanged()
|
|
1421
|
+
if let key = r.key {
|
|
1422
|
+
requestsEpoch += 1
|
|
1423
|
+
Task { await AgentClient.reopenRequest(key) }
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// --- The daemon's list ---
|
|
1428
|
+
|
|
1429
|
+
/// Read the daemon's list and merge it: rows heard or closed on another
|
|
1430
|
+
/// client, and rows kept across a restart of the app or the daemon.
|
|
1431
|
+
private func syncRequests() async {
|
|
1432
|
+
let epoch = requestsEpoch
|
|
1433
|
+
let read = await AgentClient.openRequests()
|
|
1434
|
+
let reachable: Bool
|
|
1435
|
+
if case .unreachable = read { reachable = false } else { reachable = true }
|
|
1436
|
+
if reachable != daemonReachable {
|
|
1437
|
+
// Stopped answering: once, on the pill. The rows stay; the
|
|
1438
|
+
// list says they come back when AgentX does.
|
|
1439
|
+
if !reachable && daemonReachable == true { note(OpenRequests.unreachableNote) }
|
|
1440
|
+
daemonReachable = reachable
|
|
1441
|
+
requestsWindow.model.status = reachable ? .ready : .unreachable
|
|
1442
|
+
requestsWindow.reload()
|
|
1443
|
+
}
|
|
1444
|
+
guard case .rows(let remote) = read, epoch == requestsEpoch else { return }
|
|
1445
|
+
let before = requests.requests
|
|
1446
|
+
requests.sync(remote)
|
|
1447
|
+
// A row found waiting its turn goes once its agent is free.
|
|
1448
|
+
let now = Date()
|
|
1449
|
+
for agent in Set(requests.requests.filter { $0.phase == .waiting }.map(\.agentID)) {
|
|
1450
|
+
if let next = requests.startNext(for: agent, at: now) { run(next) }
|
|
1451
|
+
}
|
|
1452
|
+
if requests.requests != before { requestsChanged() }
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
/// "Play answers at once" in the menu: saved as voice.answers.
|
|
1456
|
+
private func setPlayAtOnce(_ on: Bool) {
|
|
1457
|
+
Task { @MainActor in
|
|
1458
|
+
switch await AgentClient.saveSettings(["general": ["answers": on ? "play" : "wait"]]) {
|
|
1459
|
+
case .success(let saved): apply(saved)
|
|
1460
|
+
case .failure(let failure): Log.warn("answers setting: \(failure.message)")
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1158
1463
|
}
|
|
1159
1464
|
|
|
1160
1465
|
/// Someone holds the floor (#924): the answer is kept, and shown and
|
|
@@ -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-
|
|
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-2GCPSAXQ.js";import"./chunk-P6WSD2UR.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-
|
|
8
|
+
//# sourceMappingURL=App-HBM52GXI.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-
|
|
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-2GCPSAXQ.js";import"./chunk-P6WSD2UR.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-
|
|
7
|
+
//# sourceMappingURL=ChatApp-N4P7M2TD.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-
|
|
2
|
-
//# sourceMappingURL=absorb-eval-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-7L54Z4EH.js";import"./chunk-F3CMNSON.js";import"./chunk-PMSL4A5Y.js";import"./chunk-JTFCU5LH.js";import"./chunk-6NQ7KYJH.js";import"./chunk-WPNRDEHW.js";import"./chunk-LUOW2YHY.js";import"./chunk-4LWFJ4MZ.js";import"./chunk-BIJHMWXK.js";import"./chunk-2KYGPVTX.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-P6WSD2UR.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-HRWWPKT3.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-
|
|
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-LQIF2OHS.js";import"./chunk-P6WSD2UR.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-TDZDIDFG.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-
|
|
12
|
+
//# sourceMappingURL=adapter-X6T3YBUB.js.map
|