agentix-cli 0.193.0 → 0.194.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-YCRGMNAT.js} +1405 -5252
- package/dist/board-dashboard-YCRGMNAT.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-462FRP7L.js → chunk-S42KBXNO.js} +332 -319
- package/dist/chunk-S42KBXNO.js.map +1 -0
- 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-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-IDRN5TAM.js} +238 -238
- package/dist/program-IDRN5TAM.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
|
@@ -9,6 +9,11 @@ import Foundation
|
|
|
9
9
|
/// agent that is still thinking waits behind the first and goes when it
|
|
10
10
|
/// answers.
|
|
11
11
|
///
|
|
12
|
+
/// The daemon keeps the list too (GET /voice/requests): each row has its
|
|
13
|
+
/// daemon id (`key`), so it survives a restart of the app or the daemon,
|
|
14
|
+
/// and heard on one client is heard on all of them. `sync` merges what the
|
|
15
|
+
/// daemon says into what the app holds.
|
|
16
|
+
///
|
|
12
17
|
/// Kept free of AppKit and SwiftUI so the tests can check it without a
|
|
13
18
|
/// window. The answers themselves live with the app; this holds what the
|
|
14
19
|
/// list and the pill show.
|
|
@@ -28,14 +33,23 @@ struct OpenRequests {
|
|
|
28
33
|
struct Request: Equatable, Identifiable {
|
|
29
34
|
let id: Int
|
|
30
35
|
let agentID: String
|
|
31
|
-
/// The words as heard.
|
|
32
|
-
|
|
36
|
+
/// The words as heard: the last ones asked, after a follow-up.
|
|
37
|
+
var question: String
|
|
33
38
|
let sentAt: Date
|
|
34
39
|
var phase: Phase
|
|
35
40
|
/// When it started thinking, or when its answer came back.
|
|
36
41
|
var since: Date
|
|
37
42
|
/// Played or opened: its answer, or why it failed, has been seen.
|
|
38
43
|
var heard = false
|
|
44
|
+
/// Its id on the daemon; nil until the daemon has it, or when the
|
|
45
|
+
/// daemon could not be reached.
|
|
46
|
+
var key: String? = nil
|
|
47
|
+
/// Run by this app: its /ask is ours, so the daemon's word on its
|
|
48
|
+
/// state waits for that answer. A row found on the daemon is not.
|
|
49
|
+
var local = true
|
|
50
|
+
/// A follow-up spoken while it was thinking: asked as soon as the
|
|
51
|
+
/// answer is back.
|
|
52
|
+
var pending: String? = nil
|
|
39
53
|
|
|
40
54
|
/// An answer or a failure the owner has not seen yet.
|
|
41
55
|
var isNew: Bool {
|
|
@@ -53,8 +67,8 @@ struct OpenRequests {
|
|
|
53
67
|
private(set) var requests: [Request] = []
|
|
54
68
|
private var nextID = 1
|
|
55
69
|
|
|
56
|
-
/// Heard requests kept in the list
|
|
57
|
-
///
|
|
70
|
+
/// Heard requests kept in the list; the oldest heard ones leave by
|
|
71
|
+
/// themselves, as they do on the daemon (voice-requests-api.ts).
|
|
58
72
|
static let keptHeard = 8
|
|
59
73
|
|
|
60
74
|
func request(_ id: Int) -> Request? { requests.first { $0.id == id } }
|
|
@@ -71,6 +85,57 @@ struct OpenRequests {
|
|
|
71
85
|
return id
|
|
72
86
|
}
|
|
73
87
|
|
|
88
|
+
// MARK: Following up
|
|
89
|
+
|
|
90
|
+
/// What a follow-up does to its row.
|
|
91
|
+
enum Follow: Equatable {
|
|
92
|
+
/// Ask again now, with the new words.
|
|
93
|
+
case ask
|
|
94
|
+
/// Wait behind another request for the same agent.
|
|
95
|
+
case waits
|
|
96
|
+
/// Go once the answer it is thinking about is back.
|
|
97
|
+
case after
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// A follow-up spoken with this row picked: it continues the row; no
|
|
101
|
+
/// new row is added. A row done (answered or failed) asks again with
|
|
102
|
+
/// these words, not heard, or waits when its agent has another request
|
|
103
|
+
/// out. A row waiting its turn takes the words into the question not
|
|
104
|
+
/// asked yet. A row thinking keeps them for when its answer is back,
|
|
105
|
+
/// and that answer is not played (as when the owner talks over a turn).
|
|
106
|
+
/// Nil when the row is gone.
|
|
107
|
+
mutating func follow(_ id: Int, with words: String, at now: Date) -> Follow? {
|
|
108
|
+
guard let i = requests.firstIndex(where: { $0.id == id }) else { return nil }
|
|
109
|
+
switch requests[i].phase {
|
|
110
|
+
case .waiting:
|
|
111
|
+
requests[i].question += " " + words
|
|
112
|
+
return .waits
|
|
113
|
+
case .thinking:
|
|
114
|
+
requests[i].pending = requests[i].pending.map { $0 + " " + words } ?? words
|
|
115
|
+
return .after
|
|
116
|
+
case .answered, .failed:
|
|
117
|
+
let agent = requests[i].agentID
|
|
118
|
+
let busy = requests.contains { $0.id != id && $0.agentID == agent && $0.isOpen }
|
|
119
|
+
requests[i].question = words
|
|
120
|
+
requests[i].phase = busy ? .waiting : .thinking
|
|
121
|
+
requests[i].since = now
|
|
122
|
+
requests[i].heard = false
|
|
123
|
+
requests[i].local = true
|
|
124
|
+
return busy ? .waits : .ask
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// The answer is back on a row with a follow-up kept: the follow-up is
|
|
129
|
+
/// its question now and it thinks again. False when none was kept.
|
|
130
|
+
mutating func takePending(_ id: Int, at now: Date) -> Bool {
|
|
131
|
+
guard let i = requests.firstIndex(where: { $0.id == id }), let words = requests[i].pending else { return false }
|
|
132
|
+
requests[i].question = words
|
|
133
|
+
requests[i].pending = nil
|
|
134
|
+
requests[i].phase = .thinking
|
|
135
|
+
requests[i].since = now
|
|
136
|
+
return true
|
|
137
|
+
}
|
|
138
|
+
|
|
74
139
|
/// The answer came back.
|
|
75
140
|
mutating func answered(_ id: Int, at now: Date) {
|
|
76
141
|
update(id) { $0.phase = .answered; $0.since = now }
|
|
@@ -82,12 +147,13 @@ struct OpenRequests {
|
|
|
82
147
|
}
|
|
83
148
|
|
|
84
149
|
/// The oldest request waiting for `agentID`, now thinking, if there is
|
|
85
|
-
/// one and nothing else for that agent is.
|
|
150
|
+
/// one and nothing else for that agent is. This app runs it.
|
|
86
151
|
mutating func startNext(for agentID: String, at now: Date) -> Int? {
|
|
87
152
|
guard !requests.contains(where: { $0.agentID == agentID && $0.phase == .thinking }),
|
|
88
153
|
let i = requests.firstIndex(where: { $0.agentID == agentID && $0.phase == .waiting }) else { return nil }
|
|
89
154
|
requests[i].phase = .thinking
|
|
90
155
|
requests[i].since = now
|
|
156
|
+
requests[i].local = true
|
|
91
157
|
return requests[i].id
|
|
92
158
|
}
|
|
93
159
|
|
|
@@ -101,11 +167,125 @@ struct OpenRequests {
|
|
|
101
167
|
}
|
|
102
168
|
}
|
|
103
169
|
|
|
170
|
+
/// The daemon took the row's words for something else (the floor
|
|
171
|
+
/// holder's sound). A follow-up kept while it thought is the owner's own
|
|
172
|
+
/// words, so it is not lost: the row asks it now and stays. With none
|
|
173
|
+
/// kept, the row leaves. True when the row asks again.
|
|
174
|
+
mutating func dropped(_ id: Int, at now: Date) -> Bool {
|
|
175
|
+
if takePending(id, at: now) { return true }
|
|
176
|
+
remove(id)
|
|
177
|
+
return false
|
|
178
|
+
}
|
|
179
|
+
|
|
104
180
|
/// Gone without a trace: the daemon took the words for something else.
|
|
105
181
|
mutating func remove(_ id: Int) {
|
|
106
182
|
requests.removeAll { $0.id == id }
|
|
107
183
|
}
|
|
108
184
|
|
|
185
|
+
/// The daemon has the request under `key`.
|
|
186
|
+
mutating func setKey(_ id: Int, _ key: String) {
|
|
187
|
+
update(id) { $0.key = key }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func request(key: String) -> Request? { requests.first { $0.key == key } }
|
|
191
|
+
|
|
192
|
+
// MARK: Closing
|
|
193
|
+
|
|
194
|
+
/// Close a row: it leaves the list. Returned so Undo can put it back.
|
|
195
|
+
@discardableResult
|
|
196
|
+
mutating func close(_ id: Int) -> Request? {
|
|
197
|
+
guard let r = request(id) else { return nil }
|
|
198
|
+
requests.removeAll { $0.id == id }
|
|
199
|
+
return r
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Undo a close: the row goes back to its place, by when it was sent.
|
|
203
|
+
mutating func restore(_ r: Request) {
|
|
204
|
+
guard request(r.id) == nil else { return }
|
|
205
|
+
let at = requests.firstIndex { $0.sentAt > r.sentAt } ?? requests.endIndex
|
|
206
|
+
requests.insert(r, at: at)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// "Close heard": every heard answer and every failure leaves.
|
|
210
|
+
@discardableResult
|
|
211
|
+
mutating func closeHeard() -> [Request] {
|
|
212
|
+
let gone = requests.filter { r in
|
|
213
|
+
if case .failed = r.phase { return true }
|
|
214
|
+
return r.phase == .answered && r.heard
|
|
215
|
+
}
|
|
216
|
+
let ids = Set(gone.map(\.id))
|
|
217
|
+
requests.removeAll { ids.contains($0.id) }
|
|
218
|
+
return gone
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// What closing a row asks first: a row still with its agent asks
|
|
222
|
+
/// whether to let it finish or stop it; anything else closes at once.
|
|
223
|
+
static func closeNeedsConfirm(_ r: Request) -> Bool { r.phase == .thinking }
|
|
224
|
+
|
|
225
|
+
// MARK: The daemon's list
|
|
226
|
+
|
|
227
|
+
/// One row of GET /voice/requests.
|
|
228
|
+
struct Remote: Equatable {
|
|
229
|
+
let key: String
|
|
230
|
+
let agentID: String
|
|
231
|
+
let question: String
|
|
232
|
+
let sentAt: Date
|
|
233
|
+
let since: Date
|
|
234
|
+
/// "waiting", "thinking", "answered" or "failed".
|
|
235
|
+
let state: String
|
|
236
|
+
let heard: Bool
|
|
237
|
+
let error: String?
|
|
238
|
+
|
|
239
|
+
var phase: Phase {
|
|
240
|
+
switch state {
|
|
241
|
+
case "waiting": return .waiting
|
|
242
|
+
case "answered": return .answered
|
|
243
|
+
case "failed": return .failed(error ?? "Something went wrong.")
|
|
244
|
+
default: return .thinking
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// Merge the daemon's open rows. A row heard elsewhere is heard here,
|
|
250
|
+
/// and one continued elsewhere has its new words and is not heard; a
|
|
251
|
+
/// row the daemon no longer lists was closed elsewhere and leaves; a
|
|
252
|
+
/// row only the daemon has (after the app restarted) joins. The state
|
|
253
|
+
/// of a row this app is running is the app's until its /ask answers.
|
|
254
|
+
/// Rows the daemon doesn't have yet (no key) are left alone. Returns
|
|
255
|
+
/// the ids that joined.
|
|
256
|
+
@discardableResult
|
|
257
|
+
mutating func sync(_ remote: [Remote]) -> [Int] {
|
|
258
|
+
let byKey = Dictionary(remote.map { ($0.key, $0) }, uniquingKeysWith: { a, _ in a })
|
|
259
|
+
requests.removeAll { r in r.key.map { byKey[$0] == nil } ?? false }
|
|
260
|
+
for i in requests.indices {
|
|
261
|
+
guard let key = requests[i].key, let theirs = byKey[key] else { continue }
|
|
262
|
+
if theirs.heard { requests[i].heard = true }
|
|
263
|
+
guard !requests[i].local else { continue }
|
|
264
|
+
if requests[i].phase != theirs.phase {
|
|
265
|
+
requests[i].phase = theirs.phase
|
|
266
|
+
requests[i].since = theirs.since
|
|
267
|
+
}
|
|
268
|
+
// Continued on another client: its new words, not heard.
|
|
269
|
+
requests[i].question = theirs.question
|
|
270
|
+
requests[i].heard = theirs.heard
|
|
271
|
+
}
|
|
272
|
+
var joined: [Int] = []
|
|
273
|
+
for theirs in remote where request(key: theirs.key) == nil {
|
|
274
|
+
let id = nextID
|
|
275
|
+
nextID += 1
|
|
276
|
+
restore(Request(id: id, agentID: theirs.agentID, question: theirs.question, sentAt: theirs.sentAt,
|
|
277
|
+
phase: theirs.phase, since: theirs.since, heard: theirs.heard,
|
|
278
|
+
key: theirs.key, local: false))
|
|
279
|
+
joined.append(id)
|
|
280
|
+
}
|
|
281
|
+
return joined
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// This app runs a row it found on the daemon (one waiting its turn).
|
|
285
|
+
mutating func adopt(_ id: Int) {
|
|
286
|
+
update(id) { $0.local = true }
|
|
287
|
+
}
|
|
288
|
+
|
|
109
289
|
private mutating func update(_ id: Int, _ change: (inout Request) -> Void) {
|
|
110
290
|
guard let i = requests.firstIndex(where: { $0.id == id }) else { return }
|
|
111
291
|
change(&requests[i])
|
|
@@ -138,9 +318,62 @@ struct OpenRequests {
|
|
|
138
318
|
}
|
|
139
319
|
|
|
140
320
|
/// The rows in the order drawn: by when each was sent, the newest next
|
|
141
|
-
/// to the pill. Rows never move when a state changes.
|
|
142
|
-
|
|
143
|
-
|
|
321
|
+
/// to the pill. Rows never move when a state changes. With `agentID`,
|
|
322
|
+
/// that agent's rows only.
|
|
323
|
+
func rows(newestLast: Bool, agentID: String? = nil) -> [Request] {
|
|
324
|
+
let mine = agentID.map { a in requests.filter { $0.agentID == a } } ?? requests
|
|
325
|
+
return newestLast ? mine : mine.reversed()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// MARK: Grouped by agent
|
|
329
|
+
|
|
330
|
+
/// Up to this many rows the list is flat; past it, one row per agent.
|
|
331
|
+
static let flatUpTo = 5
|
|
332
|
+
|
|
333
|
+
var grouped: Bool { requests.count > Self.flatUpTo }
|
|
334
|
+
|
|
335
|
+
/// One agent's rows, as one row of the grouped list.
|
|
336
|
+
struct Group: Equatable {
|
|
337
|
+
let agentID: String
|
|
338
|
+
/// Oldest first.
|
|
339
|
+
let requests: [Request]
|
|
340
|
+
|
|
341
|
+
/// Stable while any of its rows stays, and never a request's id:
|
|
342
|
+
/// the negative of its oldest row's.
|
|
343
|
+
var id: Int { -(requests.map(\.id).min() ?? 0) }
|
|
344
|
+
var newCount: Int { requests.filter(\.isNew).count }
|
|
345
|
+
var latest: Request { requests.max { $0.sentAt < $1.sentAt }! }
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// One group per agent, ordered by its newest row, the newest next to
|
|
349
|
+
/// the pill.
|
|
350
|
+
func groups(newestLast: Bool) -> [Group] {
|
|
351
|
+
var order: [String] = []
|
|
352
|
+
var byAgent: [String: [Request]] = [:]
|
|
353
|
+
for r in requests {
|
|
354
|
+
if byAgent[r.agentID] == nil { order.append(r.agentID) }
|
|
355
|
+
byAgent[r.agentID, default: []].append(r)
|
|
356
|
+
}
|
|
357
|
+
let groups = order.map { Group(agentID: $0, requests: byAgent[$0]!) }
|
|
358
|
+
.sorted { $0.latest.sentAt < $1.latest.sentAt }
|
|
359
|
+
return newestLast ? groups : groups.reversed()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/// A group's state, after the agent's name: what most needs the owner
|
|
363
|
+
/// first. "2 new", "Thinking", "Waiting its turn", else how many.
|
|
364
|
+
static func groupState(_ g: Group) -> String {
|
|
365
|
+
if g.newCount > 0 { return newBadge(g.newCount) }
|
|
366
|
+
if g.requests.contains(where: { $0.phase == .thinking }) { return "Thinking" }
|
|
367
|
+
if g.requests.contains(where: { $0.phase == .waiting }) { return "Waiting its turn" }
|
|
368
|
+
return requestsCount(g.requests.count)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/// "1 request", "4 requests".
|
|
372
|
+
static func requestsCount(_ n: Int) -> String { "\(n) request\(n == 1 ? "" : "s")" }
|
|
373
|
+
|
|
374
|
+
/// What VoiceOver reads for a group row.
|
|
375
|
+
static func groupVoiceOver(name: String, _ g: Group) -> String {
|
|
376
|
+
"\(name). \(requestsCount(g.requests.count)). \(groupState(g)). Last asked: \(flatLower(g.latest.question))."
|
|
144
377
|
}
|
|
145
378
|
|
|
146
379
|
// MARK: Words
|
|
@@ -220,6 +453,41 @@ struct OpenRequests {
|
|
|
220
453
|
/// How long those lines stay before the pill goes back to its own.
|
|
221
454
|
static let noteSeconds: TimeInterval = 4
|
|
222
455
|
|
|
456
|
+
/// The pill's line after a follow-up: it went into the picked row.
|
|
457
|
+
static let followNote = "Added to the same request"
|
|
458
|
+
|
|
459
|
+
/// The pill's line once a row is picked: the next words go to its agent
|
|
460
|
+
/// and continue that conversation.
|
|
461
|
+
static func continueNote(name: String) -> String { "\(name) · Hold ⌥Space to continue it" }
|
|
462
|
+
|
|
463
|
+
/// The line after a close, with Undo beside it.
|
|
464
|
+
static func closedNote(name: String) -> String { "Closed \(name)’s request" }
|
|
465
|
+
|
|
466
|
+
/// How long Undo stays after a close.
|
|
467
|
+
static let undoSeconds: TimeInterval = 5
|
|
468
|
+
|
|
469
|
+
/// The confirm a thinking row turns into when closed.
|
|
470
|
+
static func stillThinking(name: String) -> String { "\(name) is still thinking" }
|
|
471
|
+
static let letItFinish = "Close, let it finish"
|
|
472
|
+
static func stopAgent(name: String) -> String { "Stop \(name)" }
|
|
473
|
+
static let keep = "Keep"
|
|
474
|
+
|
|
475
|
+
// MARK: Failed, loading, unreachable
|
|
476
|
+
|
|
477
|
+
/// Under a failed row once picked: the same words to the same agent.
|
|
478
|
+
static let askAgain = "Ask again"
|
|
479
|
+
|
|
480
|
+
/// The list while the daemon does not answer.
|
|
481
|
+
static let unreachableTitle = "Can’t reach AgentX on this Mac"
|
|
482
|
+
static let unreachableBody = "Your open requests are kept by AgentX and come back when it answers. Trying again every few seconds."
|
|
483
|
+
|
|
484
|
+
/// The pill's line when the daemon stops answering.
|
|
485
|
+
static let unreachableNote = "AgentX isn’t answering · Requests come back when it does"
|
|
486
|
+
|
|
487
|
+
/// The list shows placeholder rows only when the daemon has not
|
|
488
|
+
/// answered the first read after this long.
|
|
489
|
+
static let loadingAfter: TimeInterval = 0.5
|
|
490
|
+
|
|
223
491
|
// MARK: Picking a row
|
|
224
492
|
|
|
225
493
|
enum Pick: Equatable {
|