|
| 1 | +import type { CloudTaskPermissionRequestUpdate } from "@shared/types"; |
1 | 2 | import type { StoredLogEntry } from "@shared/types/session-events"; |
2 | 3 | import { net } from "electron"; |
3 | 4 | import { inject, injectable, preDestroy } from "inversify"; |
@@ -122,6 +123,24 @@ function isSseErrorEvent(data: unknown): data is SseErrorEventData { |
122 | 123 | ); |
123 | 124 | } |
124 | 125 |
|
| 126 | +interface PermissionRequestEventData { |
| 127 | + type: "permission_request"; |
| 128 | + requestId: string; |
| 129 | + toolCall: CloudTaskPermissionRequestUpdate["toolCall"]; |
| 130 | + options: CloudTaskPermissionRequestUpdate["options"]; |
| 131 | +} |
| 132 | + |
| 133 | +function isPermissionRequestEvent( |
| 134 | + data: unknown, |
| 135 | +): data is PermissionRequestEventData { |
| 136 | + return ( |
| 137 | + typeof data === "object" && |
| 138 | + data !== null && |
| 139 | + (data as { type?: string }).type === "permission_request" && |
| 140 | + typeof (data as { requestId?: string }).requestId === "string" |
| 141 | + ); |
| 142 | +} |
| 143 | + |
125 | 144 | function createStreamStatusError(status: number): CloudTaskStreamError { |
126 | 145 | switch (status) { |
127 | 146 | case 401: |
@@ -682,6 +701,18 @@ export class CloudTaskService extends TypedEventEmitter<CloudTaskEvents> { |
682 | 701 | return; |
683 | 702 | } |
684 | 703 |
|
| 704 | + if (isPermissionRequestEvent(event.data)) { |
| 705 | + this.emit(CloudTaskEvent.Update, { |
| 706 | + taskId: watcher.taskId, |
| 707 | + runId: watcher.runId, |
| 708 | + kind: "permission_request" as const, |
| 709 | + requestId: event.data.requestId, |
| 710 | + toolCall: event.data.toolCall, |
| 711 | + options: event.data.options, |
| 712 | + }); |
| 713 | + return; |
| 714 | + } |
| 715 | + |
685 | 716 | watcher.pendingLogEntries.push(event.data as StoredLogEntry); |
686 | 717 | if (watcher.pendingLogEntries.length >= EVENT_BATCH_MAX_SIZE) { |
687 | 718 | this.flushLogBatch(key); |
|
0 commit comments