| 101 | } |
| 102 | |
| 103 | export function toProtocolTask( |
| 104 | sessionId: string, |
| 105 | info: BackgroundTaskInfo, |
| 106 | output?: TaskOutputSnapshot, |
| 107 | ): BackgroundTask { |
| 108 | const status = mapStatus(info.status); |
| 109 | const createdIso = new Date(info.startedAt).toISOString(); |
| 110 | const base: BackgroundTask = { |
| 111 | id: info.taskId, |
| 112 | session_id: sessionId, |
| 113 | kind: mapKind(info.kind), |
| 114 | description: info.description, |
| 115 | status, |
| 116 | // Agent-core has no separate creation stamp; we synthesize from |
| 117 | // startedAt — running tasks usually start immediately after creation. |
| 118 | created_at: createdIso, |
| 119 | started_at: createdIso, |
| 120 | }; |
| 121 | if (info.endedAt !== null && info.endedAt !== undefined) { |
| 122 | base.completed_at = new Date(info.endedAt).toISOString(); |
| 123 | } |
| 124 | if (info.kind === 'process' && 'command' in info && typeof info.command === 'string') { |
| 125 | base.command = info.command; |
| 126 | } |
| 127 | if (output !== undefined) { |
| 128 | base.output_preview = output.preview; |
| 129 | base.output_bytes = output.bytes; |
| 130 | } |
| 131 | return base; |
| 132 | } |
| 133 | |
| 134 | // --------------------------------------------------------------------------- |
| 135 | // Interface + implementation |