| |
| |
| |
| |
| |
| |
| |
|
|
| |
| export function trimTrailingSlash(url) { |
| return url.endsWith("/") ? url.slice(0, -1) : url; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function extractResponseTranscript(response) { |
| const output = response?.output; |
| if (!Array.isArray(output)) return ""; |
| |
| const parts = []; |
| for (const item of output) { |
| for (const part of item?.content ?? []) { |
| const text = part?.transcript ?? part?.text; |
| if (typeof text === "string" && text.trim()) parts.push(text.trim()); |
| } |
| } |
| return parts.join(" ").trim(); |
| } |
|
|
| |
| export function base64FromArrayBuffer(buf) { |
| const bytes = new Uint8Array(buf); |
| |
| let binary = ""; |
| const chunk = 0x8000; |
| for (let i = 0; i < bytes.length; i += chunk) { |
| binary += String.fromCharCode.apply(null, ( |
| (bytes.subarray(i, i + chunk)) |
| )); |
| } |
| return btoa(binary); |
| } |
|
|
| |
| export function base64ToBytes(b64) { |
| const binary = atob(b64); |
| const len = binary.length; |
| const out = new Uint8Array(len); |
| for (let i = 0; i < len; i++) out[i] = binary.charCodeAt(i); |
| return out; |
| } |