@@ -10,6 +10,7 @@ private enum TaskEventType {
1010 static let completed : Int32 = 4
1111 static let failed : Int32 = 5
1212 static let cancelled : Int32 = 6
13+ static let output : Int32 = 7
1314}
1415
1516/// Derives a stable non-zero draft ID from a task ID string.
@@ -23,7 +24,7 @@ func draftId(for taskId: String) -> Int {
2324
2425private let taskEventNames : [ Int32 : String ] = [
2526 0 : " STARTED " , 1 : " ACTIVITY " , 2 : " PROGRESS " , 3 : " CLARIFICATION " ,
26- 4 : " COMPLETED " , 5 : " FAILED " , 6 : " CANCELLED " ,
27+ 4 : " COMPLETED " , 5 : " FAILED " , 6 : " CANCELLED " , 7 : " OUTPUT " ,
2728]
2829
2930func handleTaskEvent( ctx: PluginContext , taskId: String , eventType: Int32 , eventJSON: String ) {
@@ -71,6 +72,10 @@ func handleTaskEvent(ctx: PluginContext, taskId: String, eventType: Int32, event
7172 case TaskEventType . cancelled:
7273 handleCancelled ( token: token, chatId: chatId, task: task, isPrivate: isPrivate)
7374
75+ case TaskEventType . output:
76+ handleOutput (
77+ token: token, chatId: chatId, task: task, isPrivate: isPrivate, eventJSON: eventJSON)
78+
7479 default :
7580 logWarn ( " Unknown task event type \( eventType) for task \( taskId) " )
7681 }
@@ -276,3 +281,26 @@ private func handleCancelled(token: String, chatId: String, task: TaskRow, isPri
276281 DatabaseManager . updateTask ( taskId: task. taskId, status: " cancelled " )
277282 logInfo ( " Task \( task. taskId) cancelled for chat \( chatId) " )
278283}
284+
285+ private func handleOutput(
286+ token: String , chatId: String , task: TaskRow , isPrivate: Bool , eventJSON: String
287+ ) {
288+ guard let event = parseJSON ( eventJSON, as: TaskOutputEvent . self) ,
289+ let text = event. text, !text. isEmpty
290+ else {
291+ logDebug ( " handleOutput: task \( task. taskId) failed to parse output event or empty text " )
292+ return
293+ }
294+
295+ logDebug ( " handleOutput: task \( task. taskId) text= \( text. count) chars " )
296+
297+ if isPrivate {
298+ _ = telegramSendMessageDraft (
299+ token: token, chatId: chatId,
300+ draftId: draftId ( for: task. taskId) ,
301+ text: String ( text. prefix ( 4096 ) )
302+ )
303+ } else {
304+ telegramSendChatAction ( token: token, chatId: chatId)
305+ }
306+ }
0 commit comments