| 30 | // Temporary AI SDK bridge: Copilot billing survives only in raw provider chunks here. |
| 31 | // Move this extraction into @opencode-ai/llm when Copilot is handled by the native runtime. |
| 32 | function copilotTotalNanoAiu(value: unknown) { |
| 33 | if (!value || typeof value !== "object") return |
| 34 | const raw = value as Record<string, unknown> |
| 35 | const response = |
| 36 | raw.response && typeof raw.response === "object" ? (raw.response as Record<string, unknown>) : undefined |
| 37 | const usage = raw.copilot_usage ?? response?.copilot_usage |
| 38 | if (!usage || typeof usage !== "object") return |
| 39 | const total = (usage as Record<string, unknown>).total_nano_aiu |
| 40 | if (typeof total !== "number" || !Number.isFinite(total) || total < 0) return |
| 41 | return total |
| 42 | } |
| 43 | |
| 44 | function usage(value: unknown) { |
| 45 | if (!value || typeof value !== "object") return undefined |