@@ -16,9 +16,17 @@ import { resolveDefaultModelForAgent } from "../agents/model-selection.js";
|
16 | 16 | import { resolveAgentTimeoutMs } from "../agents/timeout.js"; |
17 | 17 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
18 | 18 | import { createSubsystemLogger } from "../logging/subsystem.js"; |
| 19 | +import { |
| 20 | +extractLeadingHttpStatus, |
| 21 | +parseApiErrorPayload, |
| 22 | +} from "../shared/assistant-error-format.js"; |
19 | 23 | |
20 | 24 | const log = createSubsystemLogger("llm-slug-generator"); |
21 | 25 | const DEFAULT_SLUG_GENERATOR_TIMEOUT_MS = 15_000; |
| 26 | +const PROVIDER_ERROR_PREFIX_RE = |
| 27 | +/^(?:provider\s+)?(?:api|llm|model|openai|anthropic|codex|gateway)\s+(?:request\s+)?(?:error|failed|failure)\b/i; |
| 28 | +const PROVIDER_ERROR_DETAIL_RE = |
| 29 | +/\b(?:insufficient[_ -]?quota|quota (?:exceeded|exhausted)|exceeded your current quota|payment required|insufficient credits|credit balance|insufficient[_ -]?(?:balance|funds)|rate[_ -]?limit(?:ed)?|too many requests|invalid[_ -]?api[_ -]?key|incorrect api key|authentication failed|oauth token refresh failed|missing (?:token|projectid|credentials)|google cloud credentials|re-?authenticate|unauthorized|forbidden|permission_error|billing hard limit|spend(?:ing)? limit)\b/i; |
22 | 30 | |
23 | 31 | function resolveSlugGeneratorTimeoutMs(cfg: OpenClawConfig): number { |
24 | 32 | const configuredTimeoutSeconds = cfg.agents?.defaults?.timeoutSeconds; |
@@ -28,6 +36,37 @@ function resolveSlugGeneratorTimeoutMs(cfg: OpenClawConfig): number {
|
28 | 36 | return resolveAgentTimeoutMs({ cfg }); |
29 | 37 | } |
30 | 38 | |
| 39 | +function isErrorSlugPayload(payload: { text?: string; isError?: boolean } | undefined): boolean { |
| 40 | +if (!payload) { |
| 41 | +return false; |
| 42 | +} |
| 43 | +if (payload.isError === true) { |
| 44 | +return true; |
| 45 | +} |
| 46 | +const text = payload.text?.trim(); |
| 47 | +if (!text) { |
| 48 | +return false; |
| 49 | +} |
| 50 | +if (parseApiErrorPayload(text)) { |
| 51 | +return true; |
| 52 | +} |
| 53 | +const leadingStatus = extractLeadingHttpStatus(text); |
| 54 | +if (leadingStatus) { |
| 55 | +if ([401, 402, 403, 429].includes(leadingStatus.code)) { |
| 56 | +return true; |
| 57 | +} |
| 58 | +if ( |
| 59 | +leadingStatus.code === 400 && |
| 60 | +(parseApiErrorPayload(leadingStatus.rest) || |
| 61 | +PROVIDER_ERROR_PREFIX_RE.test(leadingStatus.rest) || |
| 62 | +PROVIDER_ERROR_DETAIL_RE.test(leadingStatus.rest)) |
| 63 | +) { |
| 64 | +return true; |
| 65 | +} |
| 66 | +} |
| 67 | +return PROVIDER_ERROR_PREFIX_RE.test(text) || PROVIDER_ERROR_DETAIL_RE.test(text); |
| 68 | +} |
| 69 | + |
31 | 70 | /** |
32 | 71 | * Generate a short 1-2 word filename slug from session content using LLM |
33 | 72 | */ |
@@ -80,14 +119,19 @@ Reply with ONLY the slug, nothing else. Examples: "vendor-pitch", "api-design",
|
80 | 119 | |
81 | 120 | // Extract text from payloads |
82 | 121 | if (result.payloads && result.payloads.length > 0) { |
83 | | -const text = result.payloads[0]?.text; |
| 122 | +const payload = result.payloads[0]; |
| 123 | +const text = payload?.text; |
84 | 124 | if (text) { |
| 125 | +if (isErrorSlugPayload(payload)) { |
| 126 | +return null; |
| 127 | +} |
85 | 128 | // Clean up the response - extract just the slug |
86 | 129 | const slug = normalizeLowercaseStringOrEmpty(text) |
87 | 130 | .replace(/[^a-z0-9-]/g, "-") |
88 | 131 | .replace(/-+/g, "-") |
89 | | -.replace(/^-|-$/g, "") |
90 | | -.slice(0, 30); // Max 30 chars |
| 132 | +.replace(/^-+|-+$/g, "") |
| 133 | +.slice(0, 30) |
| 134 | +.replace(/^-+|-+$/g, ""); // Max 30 chars |
91 | 135 | |
92 | 136 | return slug || null; |
93 | 137 | } |
|