;(function (global) { 'use strict' const classes = ['cancelled', 'timeout', 'network', 'http_4xx', 'http_5xx', 'storage', 'validation', 'scheduler', 'lifecycle', 'unknown'] function text(value, max) { return value === undefined || value === null ? '' : String(value).slice(0, max || 160) } function classify(value) { const source = value || {} const raw = text(source.errorClass || source.category || source.code, 40).toLowerCase() const status = Number(source.status || (source.details && source.details.status)) || 0 if (status >= 400 && status < 500) return 'http_4xx' if (status >= 500) return 'http_5xx' if (classes.indexOf(raw) >= 0) return raw if (/401|403|permission/.test(raw)) return 'http_4xx' if (/404|4\d\d/.test(raw)) return 'http_4xx' if (/5\d\d/.test(raw)) return 'http_5xx' return 'unknown' } function create(input) { const source = input || {} return { timestamp: Number(source.timestamp) || Date.now(), runId: text(source.runId, 120), scope: text(source.scope || source.source || 'runtime', 60), operation: text(source.operation, 80), taskId: text(source.taskId, 120), nodeId: text(source.nodeId, 120), status: text(source.status || source.state, 40), errorClass: classify(source), retryable: !!source.retryable, attempt: Math.max(0, Number(source.attempt) || 0), retryCount: Math.max(0, Number(source.retryCount) || 0), durationMs: Math.max(0, Number(source.durationMs) || 0), message: text(source.message || source.error, 240), } } function list(values, limit) { return (Array.isArray(values) ? values : []).slice(-(limit || 100)).map(create) } global.IWBRuntimeDiagnosticRecord = { classes, classify, create, list } })(typeof window !== 'undefined' ? window : globalThis)