|
2 | 2 | * Builds embedded-agent payload objects from attempt inputs and outcomes. |
3 | 3 | */ |
4 | 4 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
| 5 | +import { buildCodexLoginRecovery } from "../../../auto-reply/codex-login-recovery.js"; |
5 | 6 | import type { SourceReplyDeliveryMode } from "../../../auto-reply/get-reply-options.types.js"; |
6 | 7 | import { |
7 | 8 | createHeartbeatToolResponsePayload, |
@@ -33,6 +34,7 @@ import { |
33 | 34 | sanitizeAssistantFinalAnswerText, |
34 | 35 | sanitizeAssistantVisibleText, |
35 | 36 | } from "../../../shared/text/assistant-visible-text.js"; |
| 37 | +import { classifyOAuthRefreshFailure } from "../../auth-profiles/oauth-refresh-failure.js"; |
36 | 38 | import { |
37 | 39 | BILLING_ERROR_USER_MESSAGE, |
38 | 40 | formatAssistantErrorText, |
@@ -219,19 +221,25 @@ export function buildEmbeddedRunPayloads(params: { |
219 | 221 | const rawErrorMessage = lastAssistantNeedsErrorSurface |
220 | 222 | ? normalizeOptionalString(assistantForPayload?.errorMessage) |
221 | 223 | : undefined; |
| 224 | + const oauthRefreshFailure = rawErrorMessage ? classifyOAuthRefreshFailure(rawErrorMessage) : null; |
| 225 | + const codexLoginRecovery = buildCodexLoginRecovery({ |
| 226 | + provider: oauthRefreshFailure?.provider ?? params.provider, |
| 227 | + oauthReason: oauthRefreshFailure?.reason, |
| 228 | + }); |
222 | 229 | const errorText = |
223 | 230 | assistantForPayload && lastAssistantNeedsErrorSurface |
224 | 231 | ? suppressFailureArtifacts |
225 | 232 | ? undefined |
226 | 233 | : lastAssistantErrored || rawErrorMessage |
227 | | - ? formatUserFacingAssistantErrorText(assistantForPayload, { |
| 234 | + ? (codexLoginRecovery?.hint ?? |
| 235 | + formatUserFacingAssistantErrorText(assistantForPayload, { |
228 | 236 | cfg: params.config, |
229 | 237 | sessionKey: params.sessionKey, |
230 | 238 | provider: params.provider, |
231 | 239 | providerOwner: params.providerOwner, |
232 | 240 | model: params.model, |
233 | 241 | authMode: params.authMode, |
234 | | - }) |
| 242 | + })) |
235 | 243 | : formatAssistantErrorText(assistantForPayload, { |
236 | 244 | cfg: params.config, |
237 | 245 | sessionKey: params.sessionKey, |
@@ -262,7 +270,11 @@ export function buildEmbeddedRunPayloads(params: { |
262 | 270 | isTimeoutErrorMessage(rawErrorMessage) && |
263 | 271 | errorText === SYNTHESIZED_TIMEOUT_ERROR_TEXT; |
264 | 272 | if (errorText && !deferAssistantTimeoutError) { |
265 | | - replyItems.push({ text: errorText, isError: true }); |
| 273 | + replyItems.push({ |
| 274 | + text: errorText, |
| 275 | + isError: true, |
| 276 | + ...(codexLoginRecovery ? { presentation: codexLoginRecovery.presentation } : {}), |
| 277 | + }); |
266 | 278 | } |
267 | 279 | const reasoningText = |
268 | 280 | suppressAssistantArtifacts || runAborted || lastAssistantNeedsErrorSurface |
|
0 commit comments