(event: AgentTracePartEntry)
| 132 | const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); |
| 133 | |
| 134 | function convertAgentTraceToUiChunk(event: AgentTracePartEntry): UIMessageChunk | null { |
| 135 | const payload = (event.part ?? {}) as Record<string, unknown>; |
| 136 | const type = typeof payload.type === 'string' ? payload.type : undefined; |
| 137 | if (!type) { |
| 138 | return null; |
| 139 | } |
| 140 | |
| 141 | const baseMessageId = |
| 142 | typeof payload.messageId === 'string' && payload.messageId.length > 0 |
| 143 | ? payload.messageId |
| 144 | : event.agentRunId; |
| 145 | |
| 146 | if (type === 'message-start') { |
| 147 | return { |
| 148 | type: 'start', |
| 149 | messageId: baseMessageId, |
| 150 | messageMetadata: { |
| 151 | workflowRunId: event.workflowRunId, |
| 152 | nodeRef: event.nodeRef, |
| 153 | role: typeof payload.role === 'string' ? payload.role : 'assistant', |
| 154 | sequence: event.sequence, |
| 155 | }, |
| 156 | }; |
| 157 | } |
| 158 | |
| 159 | if (type === 'text-start') { |
| 160 | return { |
| 161 | type: 'text-start', |
| 162 | id: ensureString(payload.id) ?? baseMessageId, |
| 163 | }; |
| 164 | } |
| 165 | |
| 166 | if (type === 'data-text-start') { |
| 167 | return { |
| 168 | type: 'text-start', |
| 169 | id: ensureString(payload.id) ?? baseMessageId, |
| 170 | }; |
| 171 | } |
| 172 | |
| 173 | if (type === 'text-end') { |
| 174 | return { |
| 175 | type: 'text-end', |
| 176 | id: ensureString(payload.id) ?? baseMessageId, |
| 177 | }; |
| 178 | } |
| 179 | |
| 180 | if (type === 'data-text-end') { |
| 181 | return { |
| 182 | type: 'text-end', |
| 183 | id: ensureString(payload.id) ?? baseMessageId, |
| 184 | }; |
| 185 | } |
| 186 | |
| 187 | if (type === 'text-delta') { |
| 188 | return { |
| 189 | type: 'text-delta', |
| 190 | id: ensureString(payload.id) ?? baseMessageId, |
| 191 | delta: typeof payload.textDelta === 'string' ? payload.textDelta : '', |
no test coverage detected