@hiper2d/ai-agents 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/images.js +21 -4
- package/dist/images.js.map +1 -1
- package/dist/images.mjs +21 -4
- package/dist/images.mjs.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +41 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/images.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/images/types.ts","../src/images/framing.ts","../src/images/sheet-detection.ts","../src/images/image-catalog.ts","../src/images/google-image.ts","../src/images/portrait-sheet.ts"],"sourcesContent":["/**\n * Shared shapes for the portrait-sheet pipeline. Coordinates are SHEET pixels unless\n * stated otherwise; a card is portrait 3:4 and the circle inside it is card-relative.\n */\n\n/** A rectangle in image pixels (sharp's `extract` shape). */\nexport interface ImageRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nexport interface ImageSize {\n width: number;\n height: number;\n}\n\n/** The round avatar inside a card. `x` and `d` are fractions of the card's width,\n * `y` a fraction of its height. */\nexport interface AvatarCircle {\n x: number;\n y: number;\n d: number;\n}\n\n/** Where a portrait comes from on its sheet: the card cut and the circle in it. */\nexport interface AvatarFraming {\n card: ImageRect;\n circle: AvatarCircle;\n}\n\n/** The portion of an image to display, as fractions of its width/height. */\nexport interface ImageFocus {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n// Cards are portrait 3:4 (a poster's shape), stored at this size.\nexport const CARD_ASPECT = 3 / 4; // width / height\nexport const CARD_WIDTH_PX = 600;\nexport const CARD_HEIGHT_PX = 800;\n// Where the circle starts on a freshly cut card: 86% of its width, centred,\n// near the top — wide enough to take in a chin or beard (0.72 cut them off).\nexport const DEFAULT_AVATAR_CIRCLE: AvatarCircle = { x: 0.07, y: 0.02, d: 0.86 };\n// A card narrower than this fraction of the sheet's height upscales too much.\nexport const MIN_CARD_HEIGHT_FRACTION = 0.12;\n\n/** One character on a portrait sheet. */\nexport interface PortraitCell {\n /** Stable id the caller stores the crop under; never drawn into the image. */\n key: string;\n /** Character name, for logs and prompt guidance; never drawn into the image. */\n label: string;\n /** One-line visual description for this cell (gender, name, appearance). */\n prompt: string;\n}\n\n/** A card cut from a drawn sheet. */\nexport interface PortraitSlice {\n key: string;\n label: string;\n jpeg: Buffer;\n /** The framing the slicer chose: the card on the sheet and the default circle. */\n framing: AvatarFraming;\n}\n\n/** The kept sheet: the grid image itself (re-encoded), its size and the cells\n * the cards were cut from — enough to re-cut any card later at a new framing. */\nexport interface DrawnSheet {\n jpeg: Buffer;\n width: number;\n height: number;\n cells: ImageRect[];\n /** false = no divider lines were found and the cells are the equal split of the\n * requested grid; true = the cells between the lines the model actually drew. */\n detected: boolean;\n}\n\nexport interface GeneratedImage {\n buffer: Buffer;\n costUSD: number;\n}\n\n/**\n * The slice of sharp's API the pipeline uses. The library never imports sharp — a\n * native module the host installs and passes in (`(await import('sharp')).default`) —\n * so text-only consumers pull in nothing new.\n */\nexport type SharpLike = (input: Buffer) => {\n resize(options: { width: number; withoutEnlargement?: boolean }): SharpPipeline;\n resize(width: number, height: number): SharpPipeline;\n greyscale(): SharpPipeline;\n extract(rect: ImageRect): SharpPipeline;\n jpeg(options: { quality: number; mozjpeg?: boolean }): SharpPipeline;\n raw(): SharpPipeline;\n toBuffer(): Promise<Buffer>;\n toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: { width: number; height: number } }>;\n metadata(): Promise<{ width?: number; height?: number }>;\n};\n\nexport type SharpPipeline = ReturnType<SharpLike>;\n","import {\n AvatarCircle,\n AvatarFraming,\n CARD_ASPECT,\n DEFAULT_AVATAR_CIRCLE,\n ImageFocus,\n ImageRect,\n ImageSize,\n MIN_CARD_HEIGHT_FRACTION,\n} from './types';\n\n/**\n * Pure framing geometry, shared by the slicer (server), reframe validation (server)\n * and renderers/editors (browser). No I/O here.\n *\n * Coordinates: a card is an ImageRect in SHEET pixels (portrait 3:4); the circle is\n * card-relative (x, d = fractions of the card's width, y = fraction of its height).\n * An ImageFocus is what a renderer needs: the fraction of an image to show, so the\n * same avatar component can show a circle cut out of a stored card OR out of a\n * static preset sheet.\n */\n\nconst clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v));\n\n/** Largest 3:4 card that fits a cell, centered horizontally and top-aligned:\n * portraits are busts with the head near the top, so the top edge is the\n * anchor that keeps the face in. */\nexport function cardInCell(cell: ImageRect): ImageRect {\n const width = Math.floor(Math.min(cell.width, cell.height * CARD_ASPECT));\n const height = Math.min(cell.height, Math.round(width / CARD_ASPECT));\n return {\n left: Math.round(cell.left + (cell.width - width) / 2),\n top: cell.top,\n width,\n height,\n };\n}\n\nexport function defaultFraming(cell: ImageRect): AvatarFraming {\n return { card: cardInCell(cell), circle: { ...DEFAULT_AVATAR_CIRCLE } };\n}\n\n/** Keeps the circle inside its card. */\nexport function fitCircle(circle: AvatarCircle): AvatarCircle {\n const d = clamp(circle.d, 0.15, 1);\n return {\n d,\n x: clamp(circle.x, 0, 1 - d),\n y: clamp(circle.y, 0, 1 - d * CARD_ASPECT),\n };\n}\n\n/** Snaps a card to a valid 3:4 rectangle inside the sheet, at least the\n * minimum size. Width is the free variable; height follows the aspect. */\nexport function fitCard(card: ImageRect, sheet: ImageSize): ImageRect {\n const minHeight = Math.max(16, Math.round(sheet.height * MIN_CARD_HEIGHT_FRACTION));\n const maxHeight = Math.min(sheet.height, sheet.width / CARD_ASPECT);\n const height = Math.round(clamp(card.height, minHeight, maxHeight));\n const width = Math.round(height * CARD_ASPECT);\n return {\n width,\n height,\n left: Math.round(clamp(card.left, 0, sheet.width - width)),\n top: Math.round(clamp(card.top, 0, sheet.height - height)),\n };\n}\n\nexport function fitFraming(framing: AvatarFraming, sheet: ImageSize): AvatarFraming {\n return { card: fitCard(framing.card, sheet), circle: fitCircle(framing.circle) };\n}\n\n/** True when the framing is a well-formed object with finite numbers. Shape\n * only — call fitFraming for the geometric bounds. */\nexport function isFramingShape(value: unknown): value is AvatarFraming {\n if (!value || typeof value !== 'object') return false;\n const f = value as any;\n const rect = f.card, circle = f.circle;\n const num = (v: unknown) => typeof v === 'number' && Number.isFinite(v);\n return !!rect && !!circle\n && num(rect.left) && num(rect.top) && num(rect.width) && num(rect.height)\n && rect.width > 0 && rect.height > 0\n && num(circle.x) && num(circle.y) && num(circle.d) && circle.d > 0;\n}\n\n/** The circle as a focus on the CARD image itself (a stored card cut). */\nexport function circleFocus(circle: AvatarCircle): ImageFocus {\n const c = fitCircle(circle);\n return { x: c.x, y: c.y, w: c.d, h: c.d * CARD_ASPECT };\n}\n\n/** The card as a focus on its sheet. */\nexport function cardFocus(card: ImageRect, sheet: ImageSize): ImageFocus {\n return {\n x: card.left / sheet.width,\n y: card.top / sheet.height,\n w: card.width / sheet.width,\n h: card.height / sheet.height,\n };\n}\n\n/** The circle as a focus on the SHEET (card and circle composed) — how a preset\n * mannequin renders straight off a static sheet. */\nexport function circleFocusOnSheet(framing: AvatarFraming, sheet: ImageSize): ImageFocus {\n const c = fitCircle(framing.circle);\n const card = framing.card;\n const side = c.d * card.width; // the circle is square, in sheet px\n return {\n x: (card.left + c.x * card.width) / sheet.width,\n y: (card.top + c.y * card.height) / sheet.height,\n w: side / sheet.width,\n h: side / sheet.height,\n };\n}\n\n/** CSS `background-size` / `background-position` that shows exactly `focus`\n * of an image inside a box. */\nexport function focusToBackground(focus: ImageFocus): { backgroundSize: string; backgroundPosition: string } {\n const axis = (pos: number, ext: number) => ext >= 1 ? 50 : (pos / (1 - ext)) * 100;\n return {\n backgroundSize: `${(100 / focus.w).toFixed(3)}% ${(100 / focus.h).toFixed(3)}%`,\n backgroundPosition: `${axis(focus.x, focus.w).toFixed(3)}% ${axis(focus.y, focus.h).toFixed(3)}%`,\n };\n}\n","import { ImageRect } from \"./types\";\n\n/**\n * Finds the cells of a drawn portrait sheet from its pixels.\n *\n * The prompt asks for equal cells separated by thin dark divider lines, but\n * the model draws the lines where it likes: on a correctly drawn 4x4 sheet\n * the rows measured 497 / 485 / 428 / 382 px where equal splits assumed 448\n * (2026-09-02), so fixed-interval slicing cut lower rows through the previous\n * character's chest. The lines themselves are crisp — near-black across the\n * full width — so they are easy to find, and the cells between them are the\n * real ones. Columns have always measured exact; rows drift.\n *\n * Pure over a greyscale byte plane so it is testable without sharp.\n */\n\nexport interface GreyPlane {\n width: number;\n height: number;\n // width*height bytes, row-major, 0 = black.\n data: Uint8Array;\n}\n\nexport interface SheetGrid {\n cells: ImageRect[]; // row-major\n cols: number;\n rows: number;\n // false = no usable divider lines were found and this is the equal split\n // of the REQUESTED grid. true = the cells between the lines the model\n // actually drew, which may be a different grid than requested (a 4x4\n // request has come back as 4x3 and as 6x3) — the sheet is the truth.\n detected: boolean;\n}\n\n// A pixel darker than this is \"line\"; a scanline with more than this share\n// of dark pixels is a divider. Cell backgrounds are flat muted colours, well\n// above the threshold, and the dark portrait clothing never spans a full line.\nconst DARK_MAX = 60;\nconst DIVIDER_SHARE = 0.85;\n// Darkness alone stopped being enough with Nano Banana 2.1 (2026-10-21): its\n// \"muted\" backgrounds measured 40-58 on the grey plane, so whole cells read as\n// dark and a 4x3 sheet came back as 5x3 with the cast cut through the seams\n// (a divider at x=1800 was swallowed by a 200 px dark run and dropped as too\n// thick, while a walking stick and two patches of navy background passed as\n// lines). A line pixel must therefore also be darker than BOTH flanks of its\n// scanline — the mean over a window this far out on each side, outside any\n// line (lines are ≤ ~9 px) — by at least LINE_CONTRAST. Lines are near-black\n// (0-30), backgrounds ≥ 40 right next to them; a dark object inside a cell\n// (stick, hair, hood edge) has a dark flank on at least one side.\nconst LINE_CONTRAST = 20;\nconst FLANK_FROM = 6;\nconst FLANK_TO = 15;\n// The contrast test fails the other way on a dark art style (a space station,\n// a polar night, 2026-10-21): lines of 1-30 between backgrounds of 30-50 are\n// not 20 darker than their flanks, and a 5x3 sheet read as 2x1. So the\n// requested grid is tried FIRST: the model draws equal cells, and when every\n// equal-split position has a dark line within this share of the cell pitch,\n// those lines are the grid — no contrast needed. Only a sheet that fails\n// that check goes through the general line search below.\nconst GRID_LINE_TOLERANCE = 0.08;\nconst GRID_LINE_SHARE = 0.9;\n// A scanline next to a confirmed line belongs to it only when its mean is\n// within this of the line's: a name plate (15 vs a 20 line) does, the dark\n// top of a space-station cell (40 vs a 2 line) does not.\nconst LINE_MEAN_MARGIN = 15;\n// Pixels kept clear of a divider when cutting (anti-aliased edges).\nconst DIVIDER_INSET = 4;\n// A real divider is a thin line (~7 px on a 2400 px sheet). Thinner runs are\n// specks (a dark hairline inside a hooded figure once passed as a row line).\n// Thicker runs up to a small share of the sheet are still boundaries: the\n// model sometimes adds a dark name plate under each portrait despite the\n// no-text rule, and the plate belongs OUTSIDE the cell. Beyond that share a\n// dark run is a dark art style's background, not a boundary.\nconst DIVIDER_MIN_THICKNESS = 3;\nconst DIVIDER_MAX_THICKNESS_SHARE = 0.08;\n// A span between lines narrower than this share of the sheet can't hold a\n// face; the line that would create it is not a cell boundary.\nconst MIN_SPAN_SHARE = 0.12;\n\ninterface Run { start: number; end: number }\n\nfunction runs(indices: number[]): Run[] {\n const out: Run[] = [];\n for (const i of indices) {\n const last = out[out.length - 1];\n if (last && i === last.end + 1) last.end = i;\n else out.push({start: i, end: i});\n }\n return out;\n}\n\n/** Divider runs along one axis, measured over a window of the other axis (a\n * band of rows for columns, the full height by default). Border runs and\n * runs that aren't line-shaped are dropped.\n *\n * Two readings are merged. Dark runs (every scanline mostly below DARK_MAX)\n * are kept when the run as a whole stands out from the plane just outside it\n * — that is the thin line, and the line with a name plate hugging it. Thin\n * contrast runs (scanlines darker than both their flanks at a fixed distance)\n * find a line that a dark background or a dark cast has fused into one run\n * too thick to be a boundary. */\nfunction lineRuns(plane: GreyPlane, axis: 'rows' | 'cols', from: number, to: number): Run[] {\n const {width, height, data} = plane;\n const extent = axis === 'rows' ? height : width;\n const span = to - from;\n // Pixel k of scanline i (k runs across the window, i along the axis).\n const at = axis === 'rows'\n ? (i: number, k: number) => data[i * width + k]\n : (i: number, k: number) => data[k * width + i];\n const clamp = (i: number) => Math.min(extent - 1, Math.max(0, i));\n const flankMean = (i: number, k: number, dir: -1 | 1, start: number, end: number): number => {\n let sum = 0;\n for (let d = start; d <= end; d++) sum += at(clamp(i + dir * d), k);\n return sum / (end - start + 1);\n };\n const maxThickness = extent * DIVIDER_MAX_THICKNESS_SHARE;\n const lineShaped = (r: Run) => {\n const t = r.end - r.start + 1;\n return r.start > 2 && r.end < extent - 3 && t >= DIVIDER_MIN_THICKNESS && t <= maxThickness;\n };\n\n const dark: number[] = [];\n const contrast: number[] = [];\n for (let i = 0; i < extent; i++) {\n let darkCount = 0, contrastCount = 0;\n for (let k = from; k < to; k++) {\n const v = at(i, k);\n if (v >= DARK_MAX) continue;\n darkCount++;\n const flank = Math.min(flankMean(i, k, -1, FLANK_FROM, FLANK_TO), flankMean(i, k, 1, FLANK_FROM, FLANK_TO));\n if (v < flank - LINE_CONTRAST) contrastCount++;\n }\n if (darkCount / span > DIVIDER_SHARE) dark.push(i);\n if (contrastCount / span > DIVIDER_SHARE) contrast.push(i);\n }\n\n // Dark runs that stand out from what lies just outside them: the run's\n // mean across its scanlines (a soft stroke has no single dark centre)\n // against the flanks beyond either end. The brighter flank decides: a row\n // line has the previous row's shoulders (often dark clothing) right above\n // it, and the next row's headroom below — measured 0.54-0.82 of the width\n // against the darker flank, 0.98+ against the brighter; the false runs\n // (stick, background patch, hood) reach 0.69.\n const standsOut = (r: Run) => {\n const thickness = r.end - r.start + 1;\n const before = r.start - 1, after = r.end + 1;\n let count = 0;\n for (let k = from; k < to; k++) {\n let sum = 0;\n for (let i = r.start; i <= r.end; i++) sum += at(i, k);\n const flank = Math.max(flankMean(before, k, -1, FLANK_FROM - 1, FLANK_TO - 1), flankMean(after, k, 1, FLANK_FROM - 1, FLANK_TO - 1));\n if (sum / thickness < flank - LINE_CONTRAST) count++;\n }\n return count / span > DIVIDER_SHARE;\n };\n const kept = runs(dark).filter(lineShaped).filter(standsOut);\n\n // Contrast runs, added where no kept run already covers them. They are not\n // widened over neighbouring dark scanlines: with a dark background that\n // would push the cut into the cell, and the inset already clears the\n // stroke's anti-aliased edge.\n for (const seed of runs(contrast).filter(lineShaped)) {\n if (kept.some(k => k.start <= seed.end && seed.start <= k.end)) continue;\n kept.push(seed);\n }\n return kept.sort((a, b) => a.start - b.start);\n}\n\n/** Lines that would leave a sliver on either side are not boundaries. */\nfunction dropSliverMakers(lines: Run[], extent: number): Run[] {\n const minSpan = extent * MIN_SPAN_SHARE;\n const kept: Run[] = [];\n let cursor = 0;\n for (const line of lines) {\n if (line.start - cursor < minSpan || extent - (line.end + 1) < minSpan) continue;\n kept.push(line);\n cursor = line.end + 1;\n }\n return kept;\n}\n\n/** Divider runs across the whole plane: row lines over the full width,\n * column lines over the full height. */\nexport function findDividers(plane: GreyPlane): {rows: Run[]; cols: Run[]} {\n return {\n rows: dropSliverMakers(lineRuns(plane, 'rows', 0, plane.width), plane.height),\n cols: dropSliverMakers(lineRuns(plane, 'cols', 0, plane.height), plane.width),\n };\n}\n\n/** Cells between dividers along one axis, from the border to the first line,\n * line to line, last line to the border. */\nfunction spans(dividers: Run[], extent: number): {start: number; end: number}[] {\n const out: {start: number; end: number}[] = [];\n let cursor = 0;\n for (const d of dividers) {\n out.push({start: cursor, end: d.start});\n cursor = d.end + 1;\n }\n out.push({start: cursor, end: extent});\n return out;\n}\n\nexport function equalSplitGrid(width: number, height: number, cols: number, rows: number): SheetGrid {\n const cellW = Math.floor(width / cols), cellH = Math.floor(height / rows);\n const cells: ImageRect[] = [];\n for (let r = 0; r < rows; r++) {\n for (let c = 0; c < cols; c++) {\n cells.push(inset({left: c * cellW, top: r * cellH, width: cellW, height: cellH}, 8));\n }\n }\n return {cells, cols, rows, detected: false};\n}\n\nfunction inset(rect: ImageRect, by: number): ImageRect {\n return {left: rect.left + by, top: rect.top + by, width: Math.max(1, rect.width - 2 * by), height: Math.max(1, rect.height - 2 * by)};\n}\n\ninterface Scanlines { shares: Float32Array; means: Float32Array }\n\n/** Per scanline along one axis, over the full extent of the other: the share\n * of dark pixels and the mean value. */\nfunction scanlines(plane: GreyPlane, axis: 'rows' | 'cols'): Scanlines {\n const {width, height, data} = plane;\n const extent = axis === 'rows' ? height : width;\n const span = axis === 'rows' ? width : height;\n const shares = new Float32Array(extent), means = new Float32Array(extent);\n for (let i = 0; i < extent; i++) {\n let count = 0, sum = 0;\n if (axis === 'rows') {\n const base = i * width;\n for (let x = 0; x < width; x++) { const v = data[base + x]; sum += v; if (v < DARK_MAX) count++; }\n } else {\n for (let y = 0; y < height; y++) { const v = data[y * width + i]; sum += v; if (v < DARK_MAX) count++; }\n }\n shares[i] = count / span;\n means[i] = sum / span;\n }\n return {shares, means};\n}\n\n/** The dark line nearest an expected position, within the tolerance, or\n * null. The run is the darkest scanline plus its neighbours that are as\n * dark as it, near enough — the stroke and a name plate hugging it, not the\n * dark cell top beside it. Where even that is too thick to be a line (a\n * black art style all around) the line is a 7 px stroke at the darkest\n * scanline. */\nfunction lineNear(lines: Scanlines, position: number, tolerance: number, maxThickness: number): Run | null {\n const {shares, means} = lines;\n const extent = shares.length;\n const lo = Math.max(3, Math.round(position - tolerance));\n const hi = Math.min(extent - 4, Math.round(position + tolerance));\n let at = -1;\n for (let i = lo; i <= hi; i++) if (at < 0 || shares[i] > shares[at] || (shares[i] === shares[at] && means[i] < means[at])) at = i;\n if (at < 0 || shares[at] < GRID_LINE_SHARE) return null;\n const partOfLine = (i: number) => shares[i] >= GRID_LINE_SHARE && means[i] <= means[at] + LINE_MEAN_MARGIN;\n let start = at, end = at;\n while (start - 1 >= 3 && partOfLine(start - 1)) start--;\n while (end + 1 <= extent - 4 && partOfLine(end + 1)) end++;\n if (end - start + 1 > maxThickness) return {start: Math.max(3, at - 3), end: Math.min(extent - 4, at + 3)};\n return {start, end};\n}\n\n/** The requested grid confirmed on the pixels: a dark line near every\n * equal-split position on both axes. Null when any line is missing. */\nexport function confirmGrid(plane: GreyPlane, cols: number, rows: number): SheetGrid | null {\n const {width, height} = plane;\n const find = (axis: 'rows' | 'cols', count: number): Run[] | null => {\n const extent = axis === 'rows' ? height : width;\n const scan = scanlines(plane, axis);\n const pitch = extent / count;\n const lines: Run[] = [];\n for (let k = 1; k < count; k++) {\n const line = lineNear(scan, k * pitch, pitch * GRID_LINE_TOLERANCE, extent * DIVIDER_MAX_THICKNESS_SHARE);\n if (!line) return null;\n lines.push(line);\n }\n return lines;\n };\n const colLines = find('cols', cols);\n if (!colLines) return null;\n const rowLines = find('rows', rows);\n if (!rowLines) return null;\n const cells: ImageRect[] = [];\n for (const band of spans(rowLines, height)) {\n for (const x of spans(colLines, width)) {\n cells.push(inset({left: x.start, top: band.start, width: x.end - x.start, height: band.end - band.start}, DIVIDER_INSET));\n }\n }\n return {cells, cols, rows, detected: true};\n}\n\n/**\n * The sheet's cells. The requested grid is confirmed on the pixels first\n * (`confirmGrid`); the model draws it as asked far more often than not, and\n * that check needs no assumptions about the art style. Otherwise the divider\n * lines the model drew are read wherever they form a plausible grid, even\n * when that grid differs from the cols x rows that were asked for — the\n * model keeps row-major order, so the drawn cells still map to the\n * characters in sequence. Row lines are found over the full width; column\n * lines are found PER ROW BAND, because the model has drawn rows with\n * different column layouts (and a column line that stops short of the last\n * row). A band without lines of its own borrows the layout of the band\n * above it. The equal split of the requested grid is the last resort when\n * no lines are found at all (the caller logs it; the kept sheet lets the\n * owner reframe by hand either way).\n */\nexport function detectSheetGrid(plane: GreyPlane, cols: number, rows: number): SheetGrid {\n const confirmed = confirmGrid(plane, cols, rows);\n if (confirmed) return confirmed;\n const {width, height} = plane;\n const rowLines = dropSliverMakers(lineRuns(plane, 'rows', 0, width), height);\n const bands = spans(rowLines, height);\n const cells: ImageRect[] = [];\n let previous: Run[] | null = null;\n let colCount = 0;\n for (const band of bands) {\n let colLines = dropSliverMakers(lineRuns(plane, 'cols', band.start, band.end), width);\n if (colLines.length === 0 && previous) colLines = previous;\n previous = colLines;\n const xs = spans(colLines, width);\n colCount = Math.max(colCount, xs.length);\n for (const x of xs) {\n cells.push(inset({left: x.start, top: band.start, width: x.end - x.start, height: band.end - band.start}, DIVIDER_INSET));\n }\n }\n if (colCount < 2) return equalSplitGrid(width, height, cols, rows);\n return {cells, cols: colCount, rows: bands.length, detected: true};\n}\n\n/** What findDividers saw, for the mismatch log line. */\nexport function describeDividers(plane: GreyPlane): string {\n const d = findDividers(plane);\n const fmt = (r: Run[]) => r.map(x => `${x.start}-${x.end}`).join(',') || 'none';\n return `rows@${fmt(d.rows)} cols@${fmt(d.cols)}`;\n}\n","/**\n * Image-generation models: platform-side, never user-selected. Prices per 1M tokens from\n * ai.google.dev/gemini-api/docs/pricing.\n *\n * Nano Banana 2.1 (default since 0.26.0, 2026-10-20): image output bills by size — 1120\n * tokens at 1K, 1680 at 2K, 3780 at 4K — and the model thinks before drawing, which bills\n * as TEXT output (~650-750 thought tokens at the default `medium` level, none at `minimal`;\n * measured live 2026-10-20). One 1K image ≈ $0.040, one 2K image ≈ $0.058.\n *\n * Gemini 3.1 Flash Image (the previous default, kept selectable) bills a flat ~1120 image\n * tokens regardless of size, ≈ $0.067 an image.\n */\nexport const IMAGE_MODEL_CONSTANTS = {\n GEMINI_NANO_BANANA: 'gemini-nano-banana-2.1',\n GEMINI_FLASH_IMAGE: 'gemini-3.1-flash-image',\n} as const;\n\nexport type ImageModelId = typeof IMAGE_MODEL_CONSTANTS[keyof typeof IMAGE_MODEL_CONSTANTS];\n\nexport interface ImageModelPricing {\n imageOutputPricePerM: number;\n textInputPricePerM: number;\n /** Text and thinking output. Absent = the model bills none (or we never measured it). */\n textOutputPricePerM?: number;\n}\n\nexport const IMAGE_MODEL_PRICING: Record<ImageModelId, ImageModelPricing> = {\n [IMAGE_MODEL_CONSTANTS.GEMINI_NANO_BANANA]: {\n imageOutputPricePerM: 30,\n textInputPricePerM: 1.5,\n textOutputPricePerM: 7.5,\n },\n [IMAGE_MODEL_CONSTANTS.GEMINI_FLASH_IMAGE]: {\n imageOutputPricePerM: 60,\n textInputPricePerM: 0.5,\n },\n};\n\nexport const DEFAULT_IMAGE_MODEL: ImageModelId = IMAGE_MODEL_CONSTANTS.GEMINI_NANO_BANANA;\n\n/**\n * Cost of one image call from the usage Gemini reports. `textOutputTokens` is the text\n * the model wrote next to the image plus its thought tokens.\n */\nexport function calculateImageCost(model: ImageModelId, imageOutputTokens: number, textInputTokens: number, textOutputTokens: number = 0): number {\n const pricing = IMAGE_MODEL_PRICING[model];\n return parseFloat((\n imageOutputTokens / 1_000_000 * pricing.imageOutputPricePerM +\n textInputTokens / 1_000_000 * pricing.textInputPricePerM +\n textOutputTokens / 1_000_000 * (pricing.textOutputPricePerM ?? 0)\n ).toFixed(6));\n}\n","import { calculateImageCost, DEFAULT_IMAGE_MODEL, ImageModelId } from './image-catalog';\nimport { GeneratedImage } from './types';\n\nexport type ImageAspectRatio = '1:1' | '3:4' | '4:3' | '3:2' | '2:3' | '16:9' | '9:16';\n\nexport interface GenerateImageOptions {\n /** Labeled reference JPEGs (an established scene, character portraits) that\n * anchor the drawing to a known style, place or faces. */\n references?: { label: string; jpeg: Buffer }[];\n imageSize?: '1K' | '2K' | '4K';\n model?: ImageModelId;\n /** How much the model thinks before drawing (Nano Banana 2.1; `medium` is the API\n * default). Thought tokens bill as text output, so `minimal` is the cheap draft mode. */\n thinkingLevel?: 'minimal' | 'medium' | 'high';\n /** Test seam / custom transport; defaults to the global fetch. */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Gemini's Interactions API blocks a drawing in two shapes (both seen in production,\n * 2026-10-13):\n *\n * - **HTTP 400** with `{\"error\": {\"message\": \"Image generation blocked due to safety\n * violations. Please modify your input and retry.\", \"code\": \"Unable to show the generated\n * image. The image was filtered out because it violated Google's Generative AI Prohibited\n * Use policy …\"}}` — or \"Request blocked due to prohibited content guidelines …\". This is\n * what an explicit prompt gets.\n * - **HTTP 200** with no image block, `status: \"failed\" | \"incomplete\"` and an `errors[]`\n * entry whose `code` names the block (https://ai.google.dev/gemini-api/docs/api-errors,\n * \"Generation blocked\"): `image_safety`, `image_prohibited_content`, `image_recitation`,\n * `image_other`, plus the text-side `safety`, `prohibited_content`, `recitation`,\n * `blocklist`, `spii`, `content_blocked`. `no_image` is a plain generation failure.\n *\n * Deliberately NOT a `ModelRefusalError` subclass: this subpath is bundled apart from the\n * main entry, so an `instanceof` against the main entry's class would never match. Hosts\n * check `isImageRefusalError(error)` (by name) instead. Not retryable on the same prompt.\n */\nexport class ImageRefusalError extends Error {\n /** The block code as Gemini sent it: an `errors[].code` (a URI or bare `snake_case`\n * name) on the HTTP 200 shape, or `http_400` on the error-body shape. */\n public code: string;\n /** Gemini's human-readable message, when it sent one. */\n public reason?: string;\n public model: string;\n\n constructor(model: string, code: string, reason?: string) {\n super(`${model} declined to draw the image (${describeBlockCode(code)})${reason ? `: ${reason}` : ''}`);\n this.name = 'ImageRefusalError';\n this.model = model;\n this.code = code;\n this.reason = reason;\n }\n}\n\n/** Works across bundle copies and serialization boundaries (checks the name, not the class). */\nexport function isImageRefusalError(error: unknown): error is ImageRefusalError {\n return !!error && typeof error === 'object' && (error as { name?: unknown }).name === 'ImageRefusalError';\n}\n\nconst BLOCK_CODE_MARKERS = ['safety', 'prohibited', 'recitation', 'blocklist', 'spii', 'content_blocked', 'image_other'];\n\n/** Wording Gemini uses in a 400 body or a text block when it filtered the drawing. */\nconst BLOCK_TEXT = /blocked|safety violation|prohibited|filtered out|prohibited use policy/i;\n\n/** The trailing identifier of a code URI such as `https://…/api-errors#image_safety`. */\nfunction describeBlockCode(code: string): string {\n const tail = code.split(/[#/]/).filter(Boolean).pop() ?? code;\n return tail.toLowerCase();\n}\n\nfunction isBlockCode(code: string): boolean {\n const tail = describeBlockCode(code);\n return BLOCK_CODE_MARKERS.some(marker => tail.includes(marker));\n}\n\n/** Gemini's messages end in a markdown link to the policy; keep the sentence, drop the link. */\nfunction trimReason(text: string): string {\n return text.replace(/\\s*\\[[^\\]]*\\]\\([^)]*\\)[^.]*\\.?/g, '').trim().slice(0, 300);\n}\n\n/**\n * One image-model call on Gemini's Interactions API. Pure — no auth, no billing —\n * and the result reports its cost so the host decides whom to charge. The usage block\n * reports image tokens by modality, the text the model wrote inside `total_output_tokens`,\n * and thinking apart as `total_thought_tokens` (shape verified live 2026-10-20).\n *\n * Throws `ImageRefusalError` when Gemini blocked the drawing (see the class), and a\n * plain `Error` naming the HTTP status, or the interaction status and error code, for\n * anything else.\n */\nexport async function generateImage(apiKey: string, prompt: string, aspectRatio: ImageAspectRatio, opts: GenerateImageOptions = {}): Promise<GeneratedImage> {\n const model = opts.model ?? DEFAULT_IMAGE_MODEL;\n const input: any[] = [{ type: 'text', text: prompt }];\n for (const ref of opts.references ?? []) {\n input.push({ type: 'text', text: ref.label });\n input.push({ type: 'image', mime_type: 'image/jpeg', data: ref.jpeg.toString('base64') });\n }\n const doFetch = opts.fetchImpl ?? fetch;\n const res = await doFetch('https://generativelanguage.googleapis.com/v1beta/interactions', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'x-goog-api-key': apiKey },\n body: JSON.stringify({\n model,\n input,\n response_format: { type: 'image', mime_type: 'image/jpeg', aspect_ratio: aspectRatio, image_size: opts.imageSize ?? '2K' },\n ...(opts.thinkingLevel ? { generation_config: { thinking_level: opts.thinkingLevel } } : {}),\n }),\n });\n if (!res.ok) {\n throw httpError(model, res.status, await res.text());\n }\n const json: any = await res.json();\n const b64 = (json.steps || [])\n .flatMap((s: any) => s.content || [])\n .find((c: any) => c.type === 'image' && c.data)?.data;\n if (!b64) throw imagelessReplyError(model, json);\n\n const usage = json.usage || {};\n const imageTokens = (usage.output_tokens_by_modality || [])\n .filter((m: any) => m.modality === 'image')\n .reduce((sum: number, m: any) => sum + (m.tokens || 0), 0);\n const inputTokens = usage.total_input_tokens || 0;\n const textTokens = Math.max(0, (usage.total_output_tokens || 0) - imageTokens) + (usage.total_thought_tokens || 0);\n\n return { buffer: Buffer.from(b64, 'base64'), costUSD: calculateImageCost(model, imageTokens, inputTokens, textTokens) };\n}\n\n/** Classifies a non-2xx reply: a 400 whose body says the drawing was filtered is a refusal. */\nfunction httpError(model: string, status: number, body: string): Error {\n if (status === 400) {\n let error: { message?: unknown; code?: unknown } | undefined;\n try { error = JSON.parse(body)?.error; } catch { /* not JSON */ }\n const message = typeof error?.message === 'string' ? error.message : '';\n const code = typeof error?.code === 'string' ? error.code : '';\n if (BLOCK_TEXT.test(message) || BLOCK_TEXT.test(code)) {\n return new ImageRefusalError(model, 'http_400', trimReason(message || code));\n }\n }\n return new Error(`Image request failed: HTTP ${status} ${body.slice(0, 600)}`);\n}\n\n/** Classifies an HTTP 200 reply that carried no image block. */\nfunction imagelessReplyError(model: string, json: any): Error {\n const errors: { code?: unknown; message?: unknown }[] = Array.isArray(json?.errors) ? json.errors : [];\n const codes = errors.map(e => String(e?.code ?? '')).filter(Boolean);\n const messages = errors.map(e => (typeof e?.message === 'string' ? e.message.trim() : '')).filter(Boolean);\n const block = codes.find(isBlockCode);\n if (block) {\n return new ImageRefusalError(model, block, messages[0] ? trimReason(messages[0]) : undefined);\n }\n // A reply with no errors[] sometimes explains itself in a text block instead.\n const text: string = (json?.steps || [])\n .flatMap((s: any) => s.content || [])\n .filter((c: any) => c.type === 'text' && typeof c.text === 'string')\n .map((c: any) => c.text.trim())\n .join(' ')\n .slice(0, 300);\n if (!codes.length && BLOCK_TEXT.test(text)) {\n return new ImageRefusalError(model, 'text_block', trimReason(text));\n }\n const status = typeof json?.status === 'string' ? json.status : 'unknown';\n const detail = [\n codes.length ? `code ${codes.map(describeBlockCode).join(', ')}` : '',\n messages[0]?.slice(0, 300) ?? '',\n text ? `text \"${text}\"` : '',\n ].filter(Boolean).join('; ');\n return new Error(`Image response contained no image data (status ${status}${detail ? `; ${detail}` : ''})`);\n}\n","import { generateImage, GenerateImageOptions } from './google-image';\nimport { defaultFraming } from './framing';\nimport { describeDividers, detectSheetGrid, equalSplitGrid } from './sheet-detection';\nimport { CARD_HEIGHT_PX, CARD_WIDTH_PX, DrawnSheet, ImageRect, PortraitCell, PortraitSlice, SharpLike } from './types';\n\n/**\n * Portrait sheets: one image-model call draws a whole cast as a grid of bust\n * portraits, and the grid is cut into one card per character. One call costs the\n * same whether it draws one face or sixteen, so this is the cheap way to give\n * every character in a game a portrait in a single consistent style.\n *\n * Nothing here touches storage or billing: the host stores the cards and the kept\n * sheet (so a card can be re-cut later at a new framing) and charges whoever it\n * likes for `costUSD`. sharp is passed in, never imported.\n */\n\n/**\n * Grid dimensions by cell count on the 4:3 canvas. Cells must come out\n * square-to-portrait: asked for 4x4 (landscape 600x448 cells) the model redrew the\n * sheet as 4x3, 6x3 and once as an irregular two-layout sheet — every time towards\n * taller cells. 5x3 keeps 480x597 cells for 13-15; 17 cells get 6x3 (400x600, 2:3,\n * one of the shapes the model volunteered). Never 4x4: it silently cut a 17-cell\n * cast to 16. Never 3x3 either (2026-10-18): on the 4:3 canvas its cells are\n * landscape (800x600) and the model kept redrawing the 9-cell sheet as 4x3 with\n * square cells — the smallest game (7 bots + human + GM = 9) tripped\n * AVATAR_GRID_MISMATCH every time. 9 cells now get 4x3 with three fillers.\n */\nexport function gridFor(cells: number): { cols: number; rows: number } {\n if (cells <= 6) return { cols: 3, rows: 2 };\n if (cells <= 8) return { cols: 4, rows: 2 };\n if (cells <= 12) return { cols: 4, rows: 3 };\n if (cells <= 15) return { cols: 5, rows: 3 };\n if (cells <= 18) return { cols: 6, rows: 3 };\n throw new Error(`Portrait sheet cannot hold ${cells} cells (max 18)`);\n}\n\nexport const DEFAULT_FILLER_PROMPT = `\"Stranger\" — an anonymous hooded figure fitting the setting, face hidden in shadow`;\n\n/**\n * Pads a cast out to a full grid: the model draws exactly cols x rows cells, so the\n * spare ones get an anonymous filler that is drawn and discarded.\n */\nexport function padCells(cells: PortraitCell[], fillerPrompt: string = DEFAULT_FILLER_PROMPT): { cells: PortraitCell[]; cols: number; rows: number; realCount: number } {\n const { cols, rows } = gridFor(cells.length);\n const padded = [...cells];\n for (let i = padded.length; i < cols * rows; i++) {\n padded.push({ key: `__filler${i}`, label: 'Stranger', prompt: fillerPrompt });\n }\n return { cells: padded, cols, rows, realCount: cells.length };\n}\n\nexport interface PortraitSheetPrompt {\n cells: PortraitCell[];\n cols: number;\n rows: number;\n /** What the sheet is for, e.g. \"a social deduction game\" — one noun phrase. */\n purpose: string;\n /** The world the characters live in: a title and a short description. */\n setting: { title: string; description: string };\n /** Player-chosen art direction, already sanitized by the host. Replaces the\n * model's free choice of style. */\n artStyle?: string;\n}\n\n/**\n * The sheet prompt. The wording is load-bearing: equal cells with thin dark\n * divider lines are what the slicer finds, one flat muted background per cell keeps\n * the lines detectable in any art style, and the no-text rule is repeated because\n * the model otherwise typesets names and bios into the image.\n */\nexport function buildPortraitSheetPrompt(spec: PortraitSheetPrompt): string {\n const { cells, cols, rows, purpose, setting, artStyle } = spec;\n const cellLines = cells.map(\n (c, i) => `Cell ${i + 1}: ${c.prompt}. Its own distinct flat solid muted background color.`\n ).join('\\n');\n\n // A player style leads the prompt and is restated at the end: the sheet\n // framing (grid, bust portraits, flat backgrounds) otherwise pulls the model\n // toward drawn character-sheet art whatever style was asked for (an\n // \"ultra-realism\" game came out as comic portraits). The grid wording stays\n // intact — it is what the slicer relies on — but is declared layout only.\n const styleLead = artStyle\n ? `Art style, chosen by the player — it governs every portrait: \"${artStyle}\". Each cell must look made in that style: a photographic or cinematic style means real photographs, a painted style means paintings.\\n\\n`\n : '';\n const styleLine = artStyle\n ? `Render every portrait in the player's art style above. Apply it consistently to every portrait: same rendering technique, same palette family, same lighting.`\n : `Choose ONE cohesive illustration style that fits this setting and apply it consistently to every portrait: same rendering technique, same palette family, same lighting.`;\n const styleTail = artStyle ? `\\n\\nEvery cell must be fully in this art style: \"${artStyle}\" — and still carry no names or text of any kind.` : '';\n\n return `${styleLead}A character portrait sheet for ${purpose}, rendered as a single image: a precise grid of exactly ${cells.length} rectangular cells, ${cols} columns and ${rows} rows, all cells exactly equal size, separated by thin dark divider lines. Each cell contains one bust portrait (head and shoulders) of a different character, centered in its cell.\n\nSetting — \"${setting.title}\": ${setting.description}\n\n${styleLine} Every face must be distinct and memorable, and match its character description. No character may span more than one cell. Give each cell its own flat solid muted desaturated background color, different from its neighbors. Row-major order, left to right, top to bottom:\n\n${cellLines}\n\nThe character descriptions above are guidance for the drawing only — NEVER render them as text. Absolutely no text anywhere in the image: no names, no labels, no captions, no letters, no writing of any kind — and no lettering on clothing, equipment, insignia or logos.${styleTail}`;\n}\n\n// The model returns ~2.4 MB loosely-compressed JPEGs; at this width and quality a\n// sheet is ~400 KB (~530 KB as base64), under a 1 MiB document limit with cells\n// still ~500 px tall.\nexport const SHEET_MAX_WIDTH = 2400;\nexport const SHEET_JPEG_QUALITY = 85;\nexport const SHEET_MAX_BASE64_BYTES = 900_000;\n\n/** Why a sheet's cells did not come out as requested; the host decides how loudly to log. */\nexport interface SheetMismatch {\n kind: 'no-dividers' | 'different-grid';\n message: string;\n detail: Record<string, unknown>;\n}\n\nexport interface SliceSheetOptions {\n onMismatch?: (mismatch: SheetMismatch) => void;\n /** Long edge the sheet is normalized to before cutting; defaults to SHEET_MAX_WIDTH. */\n maxWidth?: number;\n}\n\n/**\n * Cuts the cards out of a drawn sheet and keeps the sheet. Cells come from the\n * divider lines the model drew (equal split as a last resort); each card is the\n * largest 3:4 rectangle in its cell, top-anchored, with the default circle — the\n * framing the host can let a user move later.\n */\nexport async function sliceSheet(\n sharp: SharpLike,\n raw: Buffer,\n cells: PortraitCell[],\n count: number,\n cols: number,\n rows: number,\n opts: SliceSheetOptions = {},\n): Promise<{ slices: PortraitSlice[]; sheet: DrawnSheet }> {\n // Normalise the working resolution first so cells, cards and the stored sheet\n // all share one pixel space.\n const grid: Buffer = await sharp(raw).resize({ width: opts.maxWidth ?? SHEET_MAX_WIDTH, withoutEnlargement: true }).toBuffer();\n const { data, info } = await sharp(grid).greyscale().raw().toBuffer({ resolveWithObject: true });\n const width = info.width, height = info.height;\n if (width < 100 * cols || height < 100 * rows) throw new Error(`Portrait sheet has unusable dimensions ${width}x${height}`);\n\n const plane = { width, height, data: new Uint8Array(data.buffer, data.byteOffset, data.length) };\n const gridCells = detectSheetGrid(plane, cols, rows);\n if (!gridCells.detected) {\n opts.onMismatch?.({\n kind: 'no-dividers',\n message: `no divider lines found on the ${cols}x${rows} sheet; using equal split`,\n detail: { width, height, dividers: describeDividers(plane) },\n });\n } else if (gridCells.cols !== cols || gridCells.rows !== rows) {\n // The model drew a different grid than asked. Its cells are still in row-major\n // order, so they are used as drawn; only characters past the last drawn cell\n // fall back to the equal split.\n opts.onMismatch?.({\n kind: 'different-grid',\n message: `sheet drawn as ${gridCells.cols}x${gridCells.rows}, requested ${cols}x${rows}; using the drawn cells`,\n detail: { width, height, drawnCells: gridCells.cells.length, needed: count },\n });\n }\n const fallback = equalSplitGrid(width, height, cols, rows).cells;\n\n const slices: PortraitSlice[] = [];\n for (let i = 0; i < count; i++) {\n const framing = defaultFraming(gridCells.cells[i] ?? fallback[i]);\n const jpeg = await cutCard(sharp, grid, framing.card);\n slices.push({ key: cells[i].key, label: cells[i].label, jpeg, framing });\n }\n\n let sheetJpeg: Buffer = await sharp(grid).jpeg({ quality: SHEET_JPEG_QUALITY, mozjpeg: true }).toBuffer();\n if (sheetJpeg.length * 4 / 3 > SHEET_MAX_BASE64_BYTES) {\n sheetJpeg = await sharp(grid).jpeg({ quality: 72, mozjpeg: true }).toBuffer();\n }\n return {\n slices,\n sheet: { jpeg: sheetJpeg, width, height, cells: gridCells.cells.slice(0, count), detected: gridCells.detected },\n };\n}\n\n/** Cuts one card out of a stored sheet at the given framing. */\nexport async function cutCard(sharp: SharpLike, sheet: Buffer, card: ImageRect): Promise<Buffer> {\n return sharp(sheet)\n .extract(card)\n .resize(CARD_WIDTH_PX, CARD_HEIGHT_PX)\n .jpeg({ quality: 85 })\n .toBuffer();\n}\n\nexport interface DrawPortraitSheetSpec extends Omit<PortraitSheetPrompt, 'cols' | 'rows'> {\n /** Prompt for the cells that pad the cast out to a full grid. */\n fillerPrompt?: string;\n}\n\nexport interface DrawPortraitSheetOptions extends SliceSheetOptions {\n image?: Pick<GenerateImageOptions, 'model' | 'imageSize' | 'thinkingLevel' | 'fetchImpl'>;\n}\n\nexport interface DrawnPortraitSheet {\n portraits: PortraitSlice[];\n sheet: DrawnSheet;\n /** What the image call cost, reported for the host's billing. */\n costUSD: number;\n}\n\n/**\n * The whole pipeline: lay the cast out on a grid, draw it in one call, cut the\n * cards. Filler cells are drawn and discarded; `portraits` has exactly one entry\n * per input cell, in order.\n */\nexport async function drawPortraitSheet(apiKey: string, sharp: SharpLike, spec: DrawPortraitSheetSpec, opts: DrawPortraitSheetOptions = {}): Promise<DrawnPortraitSheet> {\n const { cells, cols, rows, realCount } = padCells(spec.cells, spec.fillerPrompt);\n const prompt = buildPortraitSheetPrompt({ cells, cols, rows, purpose: spec.purpose, setting: spec.setting, artStyle: spec.artStyle });\n const image = await generateImage(apiKey, prompt, '4:3', opts.image);\n const { slices, sheet } = await sliceSheet(sharp, image.buffer, cells, realCount, cols, rows, opts);\n return { portraits: slices, sheet, costUSD: image.costUSD };\n}\n"],"mappings":";AAyCO,IAAM,cAAc,IAAI;AACxB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AAGvB,IAAM,wBAAsC,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AAExE,IAAM,2BAA2B;;;AC1BxC,IAAM,QAAQ,CAAC,GAAW,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,CAAC;AAK9E,SAAS,WAAW,MAA4B;AACnD,QAAM,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,OAAO,KAAK,SAAS,WAAW,CAAC;AACxE,QAAM,SAAS,KAAK,IAAI,KAAK,QAAQ,KAAK,MAAM,QAAQ,WAAW,CAAC;AACpE,SAAO;AAAA,IACH,M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MAAM,MAAM,UAAU,IAAI,SAAS,KAAK,OAAO,KAAK,YAAY;AAC/E,QAAM,SAAS,yBAAyB,EAAE,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,SAAS,KAAK,SAAS,UAAU,KAAK,SAAS,CAAC;AACpI,QAAM,QAAQ,MAAM,cAAc,QAAQ,QAAQ,OAAO,KAAK,KAAK;AACnE,QAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,WAAW,OAAO,MAAM,QAAQ,OAAO,WAAW,MAAM,MAAM,IAAI;AAClG,SAAO,EAAE,WAAW,QAAQ,OAAO,SAAS,MAAM,QAAQ;AAC9D;","names":["clamp"]}
|
|
1
|
+
{"version":3,"sources":["../src/images/types.ts","../src/images/framing.ts","../src/images/sheet-detection.ts","../src/images/image-catalog.ts","../src/images/google-image.ts","../src/images/portrait-sheet.ts"],"sourcesContent":["/**\n * Shared shapes for the portrait-sheet pipeline. Coordinates are SHEET pixels unless\n * stated otherwise; a card is portrait 3:4 and the circle inside it is card-relative.\n */\n\n/** A rectangle in image pixels (sharp's `extract` shape). */\nexport interface ImageRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nexport interface ImageSize {\n width: number;\n height: number;\n}\n\n/** The round avatar inside a card. `x` and `d` are fractions of the card's width,\n * `y` a fraction of its height. */\nexport interface AvatarCircle {\n x: number;\n y: number;\n d: number;\n}\n\n/** Where a portrait comes from on its sheet: the card cut and the circle in it. */\nexport interface AvatarFraming {\n card: ImageRect;\n circle: AvatarCircle;\n}\n\n/** The portion of an image to display, as fractions of its width/height. */\nexport interface ImageFocus {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n// Cards are portrait 3:4 (a poster's shape), stored at this size.\nexport const CARD_ASPECT = 3 / 4; // width / height\nexport const CARD_WIDTH_PX = 600;\nexport const CARD_HEIGHT_PX = 800;\n// Where the circle starts on a freshly cut card: 86% of its width, centred,\n// near the top — wide enough to take in a chin or beard (0.72 cut them off).\nexport const DEFAULT_AVATAR_CIRCLE: AvatarCircle = { x: 0.07, y: 0.02, d: 0.86 };\n// A card narrower than this fraction of the sheet's height upscales too much.\nexport const MIN_CARD_HEIGHT_FRACTION = 0.12;\n\n/** One character on a portrait sheet. */\nexport interface PortraitCell {\n /** Stable id the caller stores the crop under; never drawn into the image. */\n key: string;\n /** Character name, for logs and prompt guidance; never drawn into the image. */\n label: string;\n /** One-line visual description for this cell (gender, name, appearance). */\n prompt: string;\n}\n\n/** A card cut from a drawn sheet. */\nexport interface PortraitSlice {\n key: string;\n label: string;\n jpeg: Buffer;\n /** The framing the slicer chose: the card on the sheet and the default circle. */\n framing: AvatarFraming;\n}\n\n/** The kept sheet: the grid image itself (re-encoded), its size and the cells\n * the cards were cut from — enough to re-cut any card later at a new framing. */\nexport interface DrawnSheet {\n jpeg: Buffer;\n width: number;\n height: number;\n cells: ImageRect[];\n /** false = no divider lines were found and the cells are the equal split of the\n * requested grid; true = the cells between the lines the model actually drew. */\n detected: boolean;\n}\n\nexport interface GeneratedImage {\n buffer: Buffer;\n costUSD: number;\n}\n\n/**\n * The slice of sharp's API the pipeline uses. The library never imports sharp — a\n * native module the host installs and passes in (`(await import('sharp')).default`) —\n * so text-only consumers pull in nothing new.\n */\nexport type SharpLike = (input: Buffer) => {\n resize(options: { width: number; withoutEnlargement?: boolean }): SharpPipeline;\n resize(width: number, height: number): SharpPipeline;\n greyscale(): SharpPipeline;\n extract(rect: ImageRect): SharpPipeline;\n jpeg(options: { quality: number; mozjpeg?: boolean }): SharpPipeline;\n raw(): SharpPipeline;\n toBuffer(): Promise<Buffer>;\n toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: { width: number; height: number } }>;\n metadata(): Promise<{ width?: number; height?: number }>;\n};\n\nexport type SharpPipeline = ReturnType<SharpLike>;\n","import {\n AvatarCircle,\n AvatarFraming,\n CARD_ASPECT,\n DEFAULT_AVATAR_CIRCLE,\n ImageFocus,\n ImageRect,\n ImageSize,\n MIN_CARD_HEIGHT_FRACTION,\n} from './types';\n\n/**\n * Pure framing geometry, shared by the slicer (server), reframe validation (server)\n * and renderers/editors (browser). No I/O here.\n *\n * Coordinates: a card is an ImageRect in SHEET pixels (portrait 3:4); the circle is\n * card-relative (x, d = fractions of the card's width, y = fraction of its height).\n * An ImageFocus is what a renderer needs: the fraction of an image to show, so the\n * same avatar component can show a circle cut out of a stored card OR out of a\n * static preset sheet.\n */\n\nconst clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v));\n\n/** Largest 3:4 card that fits a cell, centered horizontally and top-aligned:\n * portraits are busts with the head near the top, so the top edge is the\n * anchor that keeps the face in. */\nexport function cardInCell(cell: ImageRect): ImageRect {\n const width = Math.floor(Math.min(cell.width, cell.height * CARD_ASPECT));\n const height = Math.min(cell.height, Math.round(width / CARD_ASPECT));\n return {\n left: Math.round(cell.left + (cell.width - width) / 2),\n top: cell.top,\n width,\n height,\n };\n}\n\nexport function defaultFraming(cell: ImageRect): AvatarFraming {\n return { card: cardInCell(cell), circle: { ...DEFAULT_AVATAR_CIRCLE } };\n}\n\n/** Keeps the circle inside its card. */\nexport function fitCircle(circle: AvatarCircle): AvatarCircle {\n const d = clamp(circle.d, 0.15, 1);\n return {\n d,\n x: clamp(circle.x, 0, 1 - d),\n y: clamp(circle.y, 0, 1 - d * CARD_ASPECT),\n };\n}\n\n/** Snaps a card to a valid 3:4 rectangle inside the sheet, at least the\n * minimum size. Width is the free variable; height follows the aspect. */\nexport function fitCard(card: ImageRect, sheet: ImageSize): ImageRect {\n const minHeight = Math.max(16, Math.round(sheet.height * MIN_CARD_HEIGHT_FRACTION));\n const maxHeight = Math.min(sheet.height, sheet.width / CARD_ASPECT);\n const height = Math.round(clamp(card.height, minHeight, maxHeight));\n const width = Math.round(height * CARD_ASPECT);\n return {\n width,\n height,\n left: Math.round(clamp(card.left, 0, sheet.width - width)),\n top: Math.round(clamp(card.top, 0, sheet.height - height)),\n };\n}\n\nexport function fitFraming(framing: AvatarFraming, sheet: ImageSize): AvatarFraming {\n return { card: fitCard(framing.card, sheet), circle: fitCircle(framing.circle) };\n}\n\n/** True when the framing is a well-formed object with finite numbers. Shape\n * only — call fitFraming for the geometric bounds. */\nexport function isFramingShape(value: unknown): value is AvatarFraming {\n if (!value || typeof value !== 'object') return false;\n const f = value as any;\n const rect = f.card, circle = f.circle;\n const num = (v: unknown) => typeof v === 'number' && Number.isFinite(v);\n return !!rect && !!circle\n && num(rect.left) && num(rect.top) && num(rect.width) && num(rect.height)\n && rect.width > 0 && rect.height > 0\n && num(circle.x) && num(circle.y) && num(circle.d) && circle.d > 0;\n}\n\n/** The circle as a focus on the CARD image itself (a stored card cut). */\nexport function circleFocus(circle: AvatarCircle): ImageFocus {\n const c = fitCircle(circle);\n return { x: c.x, y: c.y, w: c.d, h: c.d * CARD_ASPECT };\n}\n\n/** The card as a focus on its sheet. */\nexport function cardFocus(card: ImageRect, sheet: ImageSize): ImageFocus {\n return {\n x: card.left / sheet.width,\n y: card.top / sheet.height,\n w: card.width / sheet.width,\n h: card.height / sheet.height,\n };\n}\n\n/** The circle as a focus on the SHEET (card and circle composed) — how a preset\n * mannequin renders straight off a static sheet. */\nexport function circleFocusOnSheet(framing: AvatarFraming, sheet: ImageSize): ImageFocus {\n const c = fitCircle(framing.circle);\n const card = framing.card;\n const side = c.d * card.width; // the circle is square, in sheet px\n return {\n x: (card.left + c.x * card.width) / sheet.width,\n y: (card.top + c.y * card.height) / sheet.height,\n w: side / sheet.width,\n h: side / sheet.height,\n };\n}\n\n/** CSS `background-size` / `background-position` that shows exactly `focus`\n * of an image inside a box. */\nexport function focusToBackground(focus: ImageFocus): { backgroundSize: string; backgroundPosition: string } {\n const axis = (pos: number, ext: number) => ext >= 1 ? 50 : (pos / (1 - ext)) * 100;\n return {\n backgroundSize: `${(100 / focus.w).toFixed(3)}% ${(100 / focus.h).toFixed(3)}%`,\n backgroundPosition: `${axis(focus.x, focus.w).toFixed(3)}% ${axis(focus.y, focus.h).toFixed(3)}%`,\n };\n}\n","import { ImageRect } from \"./types\";\n\n/**\n * Finds the cells of a drawn portrait sheet from its pixels.\n *\n * The prompt asks for equal cells separated by thin dark divider lines, but\n * the model draws the lines where it likes: on a correctly drawn 4x4 sheet\n * the rows measured 497 / 485 / 428 / 382 px where equal splits assumed 448\n * (2026-09-02), so fixed-interval slicing cut lower rows through the previous\n * character's chest. The lines themselves are crisp — near-black across the\n * full width — so they are easy to find, and the cells between them are the\n * real ones. Columns have always measured exact; rows drift.\n *\n * Pure over a greyscale byte plane so it is testable without sharp.\n */\n\nexport interface GreyPlane {\n width: number;\n height: number;\n // width*height bytes, row-major, 0 = black.\n data: Uint8Array;\n}\n\nexport interface SheetGrid {\n cells: ImageRect[]; // row-major\n cols: number;\n rows: number;\n // false = no usable divider lines were found and this is the equal split\n // of the REQUESTED grid. true = the cells between the lines the model\n // actually drew, which may be a different grid than requested (a 4x4\n // request has come back as 4x3 and as 6x3) — the sheet is the truth.\n detected: boolean;\n}\n\n// A pixel darker than this is \"line\"; a scanline with more than this share\n// of dark pixels is a divider. Cell backgrounds are flat muted colours, well\n// above the threshold, and the dark portrait clothing never spans a full line.\nconst DARK_MAX = 60;\nconst DIVIDER_SHARE = 0.85;\n// Darkness alone stopped being enough with Nano Banana 2.1 (2026-10-21): its\n// \"muted\" backgrounds measured 40-58 on the grey plane, so whole cells read as\n// dark and a 4x3 sheet came back as 5x3 with the cast cut through the seams\n// (a divider at x=1800 was swallowed by a 200 px dark run and dropped as too\n// thick, while a walking stick and two patches of navy background passed as\n// lines). A line pixel must therefore also be darker than BOTH flanks of its\n// scanline — the mean over a window this far out on each side, outside any\n// line (lines are ≤ ~9 px) — by at least LINE_CONTRAST. Lines are near-black\n// (0-30), backgrounds ≥ 40 right next to them; a dark object inside a cell\n// (stick, hair, hood edge) has a dark flank on at least one side.\nconst LINE_CONTRAST = 20;\nconst FLANK_FROM = 6;\nconst FLANK_TO = 15;\n// The contrast test fails the other way on a dark art style (a space station,\n// a polar night, 2026-10-21): lines of 1-30 between backgrounds of 30-50 are\n// not 20 darker than their flanks, and a 5x3 sheet read as 2x1. So the\n// requested grid is tried FIRST: the model draws equal cells, and when every\n// equal-split position has a dark line within this share of the cell pitch,\n// those lines are the grid — no contrast needed. Only a sheet that fails\n// that check goes through the general line search below.\nconst GRID_LINE_TOLERANCE = 0.08;\nconst GRID_LINE_SHARE = 0.9;\n// Nano Banana 2.1 also draws sketchy ink borders 2-3 px thin with gaps\n// (2026-10-25): on two correct sheets the lines measured 0.79-0.88 dark\n// across their length, one line under GRID_LINE_SHARE was enough to fail\n// the confirmation, and the general search then read a 5x3 sheet as 2x2 —\n// three portraits cut from the wrong rectangles. A line this sketchy is\n// still accepted when it is darker than the brighter of its flanks by\n// LINE_CONTRAST (the cell background, or the paper gutter beside it); a\n// dark art style, where lines barely contrast, still needs the full share.\nconst SKETCH_LINE_SHARE = 0.7;\n// A scanline next to a confirmed line belongs to it only when its mean is\n// within this of the line's: a name plate (15 vs a 20 line) does, the dark\n// top of a space-station cell (40 vs a 2 line) does not.\nconst LINE_MEAN_MARGIN = 15;\n// Pixels kept clear of a divider when cutting (anti-aliased edges).\nconst DIVIDER_INSET = 4;\n// A real divider is a thin line (~7 px on a 2400 px sheet). Thinner runs are\n// specks (a dark hairline inside a hooded figure once passed as a row line).\n// Thicker runs up to a small share of the sheet are still boundaries: the\n// model sometimes adds a dark name plate under each portrait despite the\n// no-text rule, and the plate belongs OUTSIDE the cell. Beyond that share a\n// dark run is a dark art style's background, not a boundary.\nconst DIVIDER_MIN_THICKNESS = 3;\nconst DIVIDER_MAX_THICKNESS_SHARE = 0.08;\n// A span between lines narrower than this share of the sheet can't hold a\n// face; the line that would create it is not a cell boundary.\nconst MIN_SPAN_SHARE = 0.12;\n\ninterface Run { start: number; end: number }\n\nfunction runs(indices: number[]): Run[] {\n const out: Run[] = [];\n for (const i of indices) {\n const last = out[out.length - 1];\n if (last && i === last.end + 1) last.end = i;\n else out.push({start: i, end: i});\n }\n return out;\n}\n\n/** Divider runs along one axis, measured over a window of the other axis (a\n * band of rows for columns, the full height by default). Border runs and\n * runs that aren't line-shaped are dropped.\n *\n * Two readings are merged. Dark runs (every scanline mostly below DARK_MAX)\n * are kept when the run as a whole stands out from the plane just outside it\n * — that is the thin line, and the line with a name plate hugging it. Thin\n * contrast runs (scanlines darker than both their flanks at a fixed distance)\n * find a line that a dark background or a dark cast has fused into one run\n * too thick to be a boundary. */\nfunction lineRuns(plane: GreyPlane, axis: 'rows' | 'cols', from: number, to: number): Run[] {\n const {width, height, data} = plane;\n const extent = axis === 'rows' ? height : width;\n const span = to - from;\n // Pixel k of scanline i (k runs across the window, i along the axis).\n const at = axis === 'rows'\n ? (i: number, k: number) => data[i * width + k]\n : (i: number, k: number) => data[k * width + i];\n const clamp = (i: number) => Math.min(extent - 1, Math.max(0, i));\n const flankMean = (i: number, k: number, dir: -1 | 1, start: number, end: number): number => {\n let sum = 0;\n for (let d = start; d <= end; d++) sum += at(clamp(i + dir * d), k);\n return sum / (end - start + 1);\n };\n const maxThickness = extent * DIVIDER_MAX_THICKNESS_SHARE;\n const lineShaped = (r: Run) => {\n const t = r.end - r.start + 1;\n return r.start > 2 && r.end < extent - 3 && t >= DIVIDER_MIN_THICKNESS && t <= maxThickness;\n };\n\n const dark: number[] = [];\n const contrast: number[] = [];\n for (let i = 0; i < extent; i++) {\n let darkCount = 0, contrastCount = 0;\n for (let k = from; k < to; k++) {\n const v = at(i, k);\n if (v >= DARK_MAX) continue;\n darkCount++;\n const flank = Math.min(flankMean(i, k, -1, FLANK_FROM, FLANK_TO), flankMean(i, k, 1, FLANK_FROM, FLANK_TO));\n if (v < flank - LINE_CONTRAST) contrastCount++;\n }\n if (darkCount / span > DIVIDER_SHARE) dark.push(i);\n if (contrastCount / span > DIVIDER_SHARE) contrast.push(i);\n }\n\n // Dark runs that stand out from what lies just outside them: the run's\n // mean across its scanlines (a soft stroke has no single dark centre)\n // against the flanks beyond either end. The brighter flank decides: a row\n // line has the previous row's shoulders (often dark clothing) right above\n // it, and the next row's headroom below — measured 0.54-0.82 of the width\n // against the darker flank, 0.98+ against the brighter; the false runs\n // (stick, background patch, hood) reach 0.69.\n const standsOut = (r: Run) => {\n const thickness = r.end - r.start + 1;\n const before = r.start - 1, after = r.end + 1;\n let count = 0;\n for (let k = from; k < to; k++) {\n let sum = 0;\n for (let i = r.start; i <= r.end; i++) sum += at(i, k);\n const flank = Math.max(flankMean(before, k, -1, FLANK_FROM - 1, FLANK_TO - 1), flankMean(after, k, 1, FLANK_FROM - 1, FLANK_TO - 1));\n if (sum / thickness < flank - LINE_CONTRAST) count++;\n }\n return count / span > DIVIDER_SHARE;\n };\n const kept = runs(dark).filter(lineShaped).filter(standsOut);\n\n // Contrast runs, added where no kept run already covers them. They are not\n // widened over neighbouring dark scanlines: with a dark background that\n // would push the cut into the cell, and the inset already clears the\n // stroke's anti-aliased edge.\n for (const seed of runs(contrast).filter(lineShaped)) {\n if (kept.some(k => k.start <= seed.end && seed.start <= k.end)) continue;\n kept.push(seed);\n }\n return kept.sort((a, b) => a.start - b.start);\n}\n\n/** Lines that would leave a sliver on either side are not boundaries. */\nfunction dropSliverMakers(lines: Run[], extent: number): Run[] {\n const minSpan = extent * MIN_SPAN_SHARE;\n const kept: Run[] = [];\n let cursor = 0;\n for (const line of lines) {\n if (line.start - cursor < minSpan || extent - (line.end + 1) < minSpan) continue;\n kept.push(line);\n cursor = line.end + 1;\n }\n return kept;\n}\n\n/** Divider runs across the whole plane: row lines over the full width,\n * column lines over the full height. */\nexport function findDividers(plane: GreyPlane): {rows: Run[]; cols: Run[]} {\n return {\n rows: dropSliverMakers(lineRuns(plane, 'rows', 0, plane.width), plane.height),\n cols: dropSliverMakers(lineRuns(plane, 'cols', 0, plane.height), plane.width),\n };\n}\n\n/** Cells between dividers along one axis, from the border to the first line,\n * line to line, last line to the border. */\nfunction spans(dividers: Run[], extent: number): {start: number; end: number}[] {\n const out: {start: number; end: number}[] = [];\n let cursor = 0;\n for (const d of dividers) {\n out.push({start: cursor, end: d.start});\n cursor = d.end + 1;\n }\n out.push({start: cursor, end: extent});\n return out;\n}\n\nexport function equalSplitGrid(width: number, height: number, cols: number, rows: number): SheetGrid {\n const cellW = Math.floor(width / cols), cellH = Math.floor(height / rows);\n const cells: ImageRect[] = [];\n for (let r = 0; r < rows; r++) {\n for (let c = 0; c < cols; c++) {\n cells.push(inset({left: c * cellW, top: r * cellH, width: cellW, height: cellH}, 8));\n }\n }\n return {cells, cols, rows, detected: false};\n}\n\nfunction inset(rect: ImageRect, by: number): ImageRect {\n return {left: rect.left + by, top: rect.top + by, width: Math.max(1, rect.width - 2 * by), height: Math.max(1, rect.height - 2 * by)};\n}\n\ninterface Scanlines { shares: Float32Array; means: Float32Array }\n\n/** Per scanline along one axis, over the full extent of the other: the share\n * of dark pixels and the mean value. */\nfunction scanlines(plane: GreyPlane, axis: 'rows' | 'cols'): Scanlines {\n const {width, height, data} = plane;\n const extent = axis === 'rows' ? height : width;\n const span = axis === 'rows' ? width : height;\n const shares = new Float32Array(extent), means = new Float32Array(extent);\n for (let i = 0; i < extent; i++) {\n let count = 0, sum = 0;\n if (axis === 'rows') {\n const base = i * width;\n for (let x = 0; x < width; x++) { const v = data[base + x]; sum += v; if (v < DARK_MAX) count++; }\n } else {\n for (let y = 0; y < height; y++) { const v = data[y * width + i]; sum += v; if (v < DARK_MAX) count++; }\n }\n shares[i] = count / span;\n means[i] = sum / span;\n }\n return {shares, means};\n}\n\n/** The dark line nearest an expected position, within the tolerance, or\n * null. The run is the darkest scanline plus its neighbours that are as\n * dark as it, near enough — the stroke and a name plate hugging it, not the\n * dark cell top beside it. Where even that is too thick to be a line (a\n * black art style all around) the line is a 7 px stroke at the darkest\n * scanline. A sketchy line (SKETCH_LINE_SHARE) counts only when the run\n * stands out from the brighter of its flanks. */\nfunction lineNear(lines: Scanlines, position: number, tolerance: number, maxThickness: number): Run | null {\n const {shares, means} = lines;\n const extent = shares.length;\n const lo = Math.max(3, Math.round(position - tolerance));\n const hi = Math.min(extent - 4, Math.round(position + tolerance));\n let at = -1;\n for (let i = lo; i <= hi; i++) if (at < 0 || shares[i] > shares[at] || (shares[i] === shares[at] && means[i] < means[at])) at = i;\n if (at < 0 || shares[at] < SKETCH_LINE_SHARE) return null;\n const minShare = shares[at] >= GRID_LINE_SHARE ? GRID_LINE_SHARE : SKETCH_LINE_SHARE;\n const partOfLine = (i: number) => shares[i] >= minShare && means[i] <= means[at] + LINE_MEAN_MARGIN;\n let start = at, end = at;\n while (start - 1 >= 3 && partOfLine(start - 1)) start--;\n while (end + 1 <= extent - 4 && partOfLine(end + 1)) end++;\n const run = end - start + 1 > maxThickness\n ? {start: Math.max(3, at - 3), end: Math.min(extent - 4, at + 3)}\n : {start, end};\n if (minShare === SKETCH_LINE_SHARE && !standsOutByMean(lines, run)) return null;\n return run;\n}\n\n/** Whether a run is darker than the brighter of its flanks (the scanline\n * means over the same window lineRuns uses) by LINE_CONTRAST. */\nfunction standsOutByMean(lines: Scanlines, run: Run): boolean {\n const {means} = lines;\n const extent = means.length;\n const clamp = (i: number) => Math.min(extent - 1, Math.max(0, i));\n const flank = (from: number, dir: -1 | 1): number => {\n let sum = 0;\n for (let d = FLANK_FROM - 1; d <= FLANK_TO - 1; d++) sum += means[clamp(from + dir * d)];\n return sum / (FLANK_TO - FLANK_FROM + 1);\n };\n let sum = 0;\n for (let i = run.start; i <= run.end; i++) sum += means[i];\n const runMean = sum / (run.end - run.start + 1);\n return runMean < Math.max(flank(run.start - 1, -1), flank(run.end + 1, 1)) - LINE_CONTRAST;\n}\n\n/** The requested grid confirmed on the pixels: a dark line near every\n * equal-split position on both axes. Null when any line is missing. */\nexport function confirmGrid(plane: GreyPlane, cols: number, rows: number): SheetGrid | null {\n const {width, height} = plane;\n const find = (axis: 'rows' | 'cols', count: number): Run[] | null => {\n const extent = axis === 'rows' ? height : width;\n const scan = scanlines(plane, axis);\n const pitch = extent / count;\n const lines: Run[] = [];\n for (let k = 1; k < count; k++) {\n const line = lineNear(scan, k * pitch, pitch * GRID_LINE_TOLERANCE, extent * DIVIDER_MAX_THICKNESS_SHARE);\n if (!line) return null;\n lines.push(line);\n }\n return lines;\n };\n const colLines = find('cols', cols);\n if (!colLines) return null;\n const rowLines = find('rows', rows);\n if (!rowLines) return null;\n const cells: ImageRect[] = [];\n for (const band of spans(rowLines, height)) {\n for (const x of spans(colLines, width)) {\n cells.push(inset({left: x.start, top: band.start, width: x.end - x.start, height: band.end - band.start}, DIVIDER_INSET));\n }\n }\n return {cells, cols, rows, detected: true};\n}\n\n/**\n * The sheet's cells. The requested grid is confirmed on the pixels first\n * (`confirmGrid`); the model draws it as asked far more often than not, and\n * that check needs no assumptions about the art style. Otherwise the divider\n * lines the model drew are read wherever they form a plausible grid, even\n * when that grid differs from the cols x rows that were asked for — the\n * model keeps row-major order, so the drawn cells still map to the\n * characters in sequence. Row lines are found over the full width; column\n * lines are found PER ROW BAND, because the model has drawn rows with\n * different column layouts (and a column line that stops short of the last\n * row). A band without lines of its own borrows the layout of the band\n * above it. The equal split of the requested grid is the last resort when\n * no lines are found at all (the caller logs it; the kept sheet lets the\n * owner reframe by hand either way).\n */\nexport function detectSheetGrid(plane: GreyPlane, cols: number, rows: number): SheetGrid {\n const confirmed = confirmGrid(plane, cols, rows);\n if (confirmed) return confirmed;\n const {width, height} = plane;\n const rowLines = dropSliverMakers(lineRuns(plane, 'rows', 0, width), height);\n const bands = spans(rowLines, height);\n const cells: ImageRect[] = [];\n let previous: Run[] | null = null;\n let colCount = 0;\n for (const band of bands) {\n let colLines = dropSliverMakers(lineRuns(plane, 'cols', band.start, band.end), width);\n if (colLines.length === 0 && previous) colLines = previous;\n previous = colLines;\n const xs = spans(colLines, width);\n colCount = Math.max(colCount, xs.length);\n for (const x of xs) {\n cells.push(inset({left: x.start, top: band.start, width: x.end - x.start, height: band.end - band.start}, DIVIDER_INSET));\n }\n }\n if (colCount < 2) return equalSplitGrid(width, height, cols, rows);\n return {cells, cols: colCount, rows: bands.length, detected: true};\n}\n\n/** What findDividers saw, for the mismatch log line. */\nexport function describeDividers(plane: GreyPlane): string {\n const d = findDividers(plane);\n const fmt = (r: Run[]) => r.map(x => `${x.start}-${x.end}`).join(',') || 'none';\n return `rows@${fmt(d.rows)} cols@${fmt(d.cols)}`;\n}\n","/**\n * Image-generation models: platform-side, never user-selected. Prices per 1M tokens from\n * ai.google.dev/gemini-api/docs/pricing.\n *\n * Nano Banana 2.1 (default since 0.26.0, 2026-10-20): image output bills by size — 1120\n * tokens at 1K, 1680 at 2K, 3780 at 4K — and the model thinks before drawing, which bills\n * as TEXT output (~650-750 thought tokens at the default `medium` level, none at `minimal`;\n * measured live 2026-10-20). One 1K image ≈ $0.040, one 2K image ≈ $0.058.\n *\n * Gemini 3.1 Flash Image (the previous default, kept selectable) bills a flat ~1120 image\n * tokens regardless of size, ≈ $0.067 an image.\n */\nexport const IMAGE_MODEL_CONSTANTS = {\n GEMINI_NANO_BANANA: 'gemini-nano-banana-2.1',\n GEMINI_FLASH_IMAGE: 'gemini-3.1-flash-image',\n} as const;\n\nexport type ImageModelId = typeof IMAGE_MODEL_CONSTANTS[keyof typeof IMAGE_MODEL_CONSTANTS];\n\nexport interface ImageModelPricing {\n imageOutputPricePerM: number;\n textInputPricePerM: number;\n /** Text and thinking output. Absent = the model bills none (or we never measured it). */\n textOutputPricePerM?: number;\n}\n\nexport const IMAGE_MODEL_PRICING: Record<ImageModelId, ImageModelPricing> = {\n [IMAGE_MODEL_CONSTANTS.GEMINI_NANO_BANANA]: {\n imageOutputPricePerM: 30,\n textInputPricePerM: 1.5,\n textOutputPricePerM: 7.5,\n },\n [IMAGE_MODEL_CONSTANTS.GEMINI_FLASH_IMAGE]: {\n imageOutputPricePerM: 60,\n textInputPricePerM: 0.5,\n },\n};\n\nexport const DEFAULT_IMAGE_MODEL: ImageModelId = IMAGE_MODEL_CONSTANTS.GEMINI_NANO_BANANA;\n\n/**\n * Cost of one image call from the usage Gemini reports. `textOutputTokens` is the text\n * the model wrote next to the image plus its thought tokens.\n */\nexport function calculateImageCost(model: ImageModelId, imageOutputTokens: number, textInputTokens: number, textOutputTokens: number = 0): number {\n const pricing = IMAGE_MODEL_PRICING[model];\n return parseFloat((\n imageOutputTokens / 1_000_000 * pricing.imageOutputPricePerM +\n textInputTokens / 1_000_000 * pricing.textInputPricePerM +\n textOutputTokens / 1_000_000 * (pricing.textOutputPricePerM ?? 0)\n ).toFixed(6));\n}\n","import { calculateImageCost, DEFAULT_IMAGE_MODEL, ImageModelId } from './image-catalog';\nimport { GeneratedImage } from './types';\n\nexport type ImageAspectRatio = '1:1' | '3:4' | '4:3' | '3:2' | '2:3' | '16:9' | '9:16';\n\nexport interface GenerateImageOptions {\n /** Labeled reference JPEGs (an established scene, character portraits) that\n * anchor the drawing to a known style, place or faces. */\n references?: { label: string; jpeg: Buffer }[];\n imageSize?: '1K' | '2K' | '4K';\n model?: ImageModelId;\n /** How much the model thinks before drawing (Nano Banana 2.1; `medium` is the API\n * default). Thought tokens bill as text output, so `minimal` is the cheap draft mode. */\n thinkingLevel?: 'minimal' | 'medium' | 'high';\n /** Test seam / custom transport; defaults to the global fetch. */\n fetchImpl?: typeof fetch;\n}\n\n/**\n * Gemini's Interactions API blocks a drawing in two shapes (both seen in production,\n * 2026-10-13):\n *\n * - **HTTP 400** with `{\"error\": {\"message\": \"Image generation blocked due to safety\n * violations. Please modify your input and retry.\", \"code\": \"Unable to show the generated\n * image. The image was filtered out because it violated Google's Generative AI Prohibited\n * Use policy …\"}}` — or \"Request blocked due to prohibited content guidelines …\". This is\n * what an explicit prompt gets.\n * - **HTTP 200** with no image block, `status: \"failed\" | \"incomplete\"` and an `errors[]`\n * entry whose `code` names the block (https://ai.google.dev/gemini-api/docs/api-errors,\n * \"Generation blocked\"): `image_safety`, `image_prohibited_content`, `image_recitation`,\n * `image_other`, plus the text-side `safety`, `prohibited_content`, `recitation`,\n * `blocklist`, `spii`, `content_blocked`. `no_image` is a plain generation failure.\n *\n * Deliberately NOT a `ModelRefusalError` subclass: this subpath is bundled apart from the\n * main entry, so an `instanceof` against the main entry's class would never match. Hosts\n * check `isImageRefusalError(error)` (by name) instead. Not retryable on the same prompt.\n */\nexport class ImageRefusalError extends Error {\n /** The block code as Gemini sent it: an `errors[].code` (a URI or bare `snake_case`\n * name) on the HTTP 200 shape, or `http_400` on the error-body shape. */\n public code: string;\n /** Gemini's human-readable message, when it sent one. */\n public reason?: string;\n public model: string;\n\n constructor(model: string, code: string, reason?: string) {\n super(`${model} declined to draw the image (${describeBlockCode(code)})${reason ? `: ${reason}` : ''}`);\n this.name = 'ImageRefusalError';\n this.model = model;\n this.code = code;\n this.reason = reason;\n }\n}\n\n/** Works across bundle copies and serialization boundaries (checks the name, not the class). */\nexport function isImageRefusalError(error: unknown): error is ImageRefusalError {\n return !!error && typeof error === 'object' && (error as { name?: unknown }).name === 'ImageRefusalError';\n}\n\nconst BLOCK_CODE_MARKERS = ['safety', 'prohibited', 'recitation', 'blocklist', 'spii', 'content_blocked', 'image_other'];\n\n/** Wording Gemini uses in a 400 body or a text block when it filtered the drawing. */\nconst BLOCK_TEXT = /blocked|safety violation|prohibited|filtered out|prohibited use policy/i;\n\n/** The trailing identifier of a code URI such as `https://…/api-errors#image_safety`. */\nfunction describeBlockCode(code: string): string {\n const tail = code.split(/[#/]/).filter(Boolean).pop() ?? code;\n return tail.toLowerCase();\n}\n\nfunction isBlockCode(code: string): boolean {\n const tail = describeBlockCode(code);\n return BLOCK_CODE_MARKERS.some(marker => tail.includes(marker));\n}\n\n/** Gemini's messages end in a markdown link to the policy; keep the sentence, drop the link. */\nfunction trimReason(text: string): string {\n return text.replace(/\\s*\\[[^\\]]*\\]\\([^)]*\\)[^.]*\\.?/g, '').trim().slice(0, 300);\n}\n\n/**\n * One image-model call on Gemini's Interactions API. Pure — no auth, no billing —\n * and the result reports its cost so the host decides whom to charge. The usage block\n * reports image tokens by modality, the text the model wrote inside `total_output_tokens`,\n * and thinking apart as `total_thought_tokens` (shape verified live 2026-10-20).\n *\n * Throws `ImageRefusalError` when Gemini blocked the drawing (see the class), and a\n * plain `Error` naming the HTTP status, or the interaction status and error code, for\n * anything else.\n */\nexport async function generateImage(apiKey: string, prompt: string, aspectRatio: ImageAspectRatio, opts: GenerateImageOptions = {}): Promise<GeneratedImage> {\n const model = opts.model ?? DEFAULT_IMAGE_MODEL;\n const input: any[] = [{ type: 'text', text: prompt }];\n for (const ref of opts.references ?? []) {\n input.push({ type: 'text', text: ref.label });\n input.push({ type: 'image', mime_type: 'image/jpeg', data: ref.jpeg.toString('base64') });\n }\n const doFetch = opts.fetchImpl ?? fetch;\n const res = await doFetch('https://generativelanguage.googleapis.com/v1beta/interactions', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'x-goog-api-key': apiKey },\n body: JSON.stringify({\n model,\n input,\n response_format: { type: 'image', mime_type: 'image/jpeg', aspect_ratio: aspectRatio, image_size: opts.imageSize ?? '2K' },\n ...(opts.thinkingLevel ? { generation_config: { thinking_level: opts.thinkingLevel } } : {}),\n }),\n });\n if (!res.ok) {\n throw httpError(model, res.status, await res.text());\n }\n const json: any = await res.json();\n const b64 = (json.steps || [])\n .flatMap((s: any) => s.content || [])\n .find((c: any) => c.type === 'image' && c.data)?.data;\n if (!b64) throw imagelessReplyError(model, json);\n\n const usage = json.usage || {};\n const imageTokens = (usage.output_tokens_by_modality || [])\n .filter((m: any) => m.modality === 'image')\n .reduce((sum: number, m: any) => sum + (m.tokens || 0), 0);\n const inputTokens = usage.total_input_tokens || 0;\n const textTokens = Math.max(0, (usage.total_output_tokens || 0) - imageTokens) + (usage.total_thought_tokens || 0);\n\n return { buffer: Buffer.from(b64, 'base64'), costUSD: calculateImageCost(model, imageTokens, inputTokens, textTokens) };\n}\n\n/** Classifies a non-2xx reply: a 400 whose body says the drawing was filtered is a refusal. */\nfunction httpError(model: string, status: number, body: string): Error {\n if (status === 400) {\n let error: { message?: unknown; code?: unknown } | undefined;\n try { error = JSON.parse(body)?.error; } catch { /* not JSON */ }\n const message = typeof error?.message === 'string' ? error.message : '';\n const code = typeof error?.code === 'string' ? error.code : '';\n if (BLOCK_TEXT.test(message) || BLOCK_TEXT.test(code)) {\n return new ImageRefusalError(model, 'http_400', trimReason(message || code));\n }\n }\n return new Error(`Image request failed: HTTP ${status} ${body.slice(0, 600)}`);\n}\n\n/** Classifies an HTTP 200 reply that carried no image block. */\nfunction imagelessReplyError(model: string, json: any): Error {\n const errors: { code?: unknown; message?: unknown }[] = Array.isArray(json?.errors) ? json.errors : [];\n const codes = errors.map(e => String(e?.code ?? '')).filter(Boolean);\n const messages = errors.map(e => (typeof e?.message === 'string' ? e.message.trim() : '')).filter(Boolean);\n const block = codes.find(isBlockCode);\n if (block) {\n return new ImageRefusalError(model, block, messages[0] ? trimReason(messages[0]) : undefined);\n }\n // A reply with no errors[] sometimes explains itself in a text block instead.\n const text: string = (json?.steps || [])\n .flatMap((s: any) => s.content || [])\n .filter((c: any) => c.type === 'text' && typeof c.text === 'string')\n .map((c: any) => c.text.trim())\n .join(' ')\n .slice(0, 300);\n if (!codes.length && BLOCK_TEXT.test(text)) {\n return new ImageRefusalError(model, 'text_block', trimReason(text));\n }\n const status = typeof json?.status === 'string' ? json.status : 'unknown';\n const detail = [\n codes.length ? `code ${codes.map(describeBlockCode).join(', ')}` : '',\n messages[0]?.slice(0, 300) ?? '',\n text ? `text \"${text}\"` : '',\n ].filter(Boolean).join('; ');\n return new Error(`Image response contained no image data (status ${status}${detail ? `; ${detail}` : ''})`);\n}\n","import { generateImage, GenerateImageOptions } from './google-image';\nimport { defaultFraming } from './framing';\nimport { describeDividers, detectSheetGrid, equalSplitGrid } from './sheet-detection';\nimport { CARD_HEIGHT_PX, CARD_WIDTH_PX, DrawnSheet, ImageRect, PortraitCell, PortraitSlice, SharpLike } from './types';\n\n/**\n * Portrait sheets: one image-model call draws a whole cast as a grid of bust\n * portraits, and the grid is cut into one card per character. One call costs the\n * same whether it draws one face or sixteen, so this is the cheap way to give\n * every character in a game a portrait in a single consistent style.\n *\n * Nothing here touches storage or billing: the host stores the cards and the kept\n * sheet (so a card can be re-cut later at a new framing) and charges whoever it\n * likes for `costUSD`. sharp is passed in, never imported.\n */\n\n/**\n * Grid dimensions by cell count on the 4:3 canvas. Cells must come out\n * square-to-portrait: asked for 4x4 (landscape 600x448 cells) the model redrew the\n * sheet as 4x3, 6x3 and once as an irregular two-layout sheet — every time towards\n * taller cells. 5x3 keeps 480x597 cells for 13-15; 17 cells get 6x3 (400x600, 2:3,\n * one of the shapes the model volunteered). Never 4x4: it silently cut a 17-cell\n * cast to 16. Never 3x3 either (2026-10-18): on the 4:3 canvas its cells are\n * landscape (800x600) and the model kept redrawing the 9-cell sheet as 4x3 with\n * square cells — the smallest game (7 bots + human + GM = 9) tripped\n * AVATAR_GRID_MISMATCH every time. 9 cells now get 4x3 with three fillers.\n */\nexport function gridFor(cells: number): { cols: number; rows: number } {\n if (cells <= 6) return { cols: 3, rows: 2 };\n if (cells <= 8) return { cols: 4, rows: 2 };\n if (cells <= 12) return { cols: 4, rows: 3 };\n if (cells <= 15) return { cols: 5, rows: 3 };\n if (cells <= 18) return { cols: 6, rows: 3 };\n throw new Error(`Portrait sheet cannot hold ${cells} cells (max 18)`);\n}\n\nexport const DEFAULT_FILLER_PROMPT = `\"Stranger\" — an anonymous hooded figure fitting the setting, face hidden in shadow`;\n\n/**\n * Pads a cast out to a full grid: the model draws exactly cols x rows cells, so the\n * spare ones get an anonymous filler that is drawn and discarded.\n */\nexport function padCells(cells: PortraitCell[], fillerPrompt: string = DEFAULT_FILLER_PROMPT): { cells: PortraitCell[]; cols: number; rows: number; realCount: number } {\n const { cols, rows } = gridFor(cells.length);\n const padded = [...cells];\n for (let i = padded.length; i < cols * rows; i++) {\n padded.push({ key: `__filler${i}`, label: 'Stranger', prompt: fillerPrompt });\n }\n return { cells: padded, cols, rows, realCount: cells.length };\n}\n\nexport interface PortraitSheetPrompt {\n cells: PortraitCell[];\n cols: number;\n rows: number;\n /** What the sheet is for, e.g. \"a social deduction game\" — one noun phrase. */\n purpose: string;\n /** The world the characters live in: a title and a short description. */\n setting: { title: string; description: string };\n /** Player-chosen art direction, already sanitized by the host. Replaces the\n * model's free choice of style. */\n artStyle?: string;\n}\n\n/**\n * The sheet prompt. The wording is load-bearing: equal cells with thin dark\n * divider lines are what the slicer finds, one flat muted background per cell keeps\n * the lines detectable in any art style, and the no-text rule is repeated because\n * the model otherwise typesets names and bios into the image.\n */\nexport function buildPortraitSheetPrompt(spec: PortraitSheetPrompt): string {\n const { cells, cols, rows, purpose, setting, artStyle } = spec;\n const cellLines = cells.map(\n (c, i) => `Cell ${i + 1}: ${c.prompt}. Its own distinct flat solid muted background color.`\n ).join('\\n');\n\n // A player style leads the prompt and is restated at the end: the sheet\n // framing (grid, bust portraits, flat backgrounds) otherwise pulls the model\n // toward drawn character-sheet art whatever style was asked for (an\n // \"ultra-realism\" game came out as comic portraits). The grid wording stays\n // intact — it is what the slicer relies on — but is declared layout only.\n const styleLead = artStyle\n ? `Art style, chosen by the player — it governs every portrait: \"${artStyle}\". Each cell must look made in that style: a photographic or cinematic style means real photographs, a painted style means paintings.\\n\\n`\n : '';\n const styleLine = artStyle\n ? `Render every portrait in the player's art style above. Apply it consistently to every portrait: same rendering technique, same palette family, same lighting.`\n : `Choose ONE cohesive illustration style that fits this setting and apply it consistently to every portrait: same rendering technique, same palette family, same lighting.`;\n const styleTail = artStyle ? `\\n\\nEvery cell must be fully in this art style: \"${artStyle}\" — and still carry no names or text of any kind.` : '';\n\n return `${styleLead}A character portrait sheet for ${purpose}, rendered as a single image: a precise grid of exactly ${cells.length} rectangular cells, ${cols} columns and ${rows} rows, all cells exactly equal size, separated by thin dark divider lines. Each cell contains one bust portrait (head and shoulders) of a different character, centered in its cell.\n\nSetting — \"${setting.title}\": ${setting.description}\n\n${styleLine} Every face must be distinct and memorable, and match its character description. No character may span more than one cell. Give each cell its own flat solid muted desaturated background color, different from its neighbors. Row-major order, left to right, top to bottom:\n\n${cellLines}\n\nThe character descriptions above are guidance for the drawing only — NEVER render them as text. Absolutely no text anywhere in the image: no names, no labels, no captions, no letters, no writing of any kind — and no lettering on clothing, equipment, insignia or logos.${styleTail}`;\n}\n\n// The model returns ~2.4 MB loosely-compressed JPEGs; at this width and quality a\n// sheet is ~400 KB (~530 KB as base64), under a 1 MiB document limit with cells\n// still ~500 px tall.\nexport const SHEET_MAX_WIDTH = 2400;\nexport const SHEET_JPEG_QUALITY = 85;\nexport const SHEET_MAX_BASE64_BYTES = 900_000;\n\n/** Why a sheet's cells did not come out as requested; the host decides how loudly to log. */\nexport interface SheetMismatch {\n kind: 'no-dividers' | 'different-grid';\n message: string;\n detail: Record<string, unknown>;\n}\n\nexport interface SliceSheetOptions {\n onMismatch?: (mismatch: SheetMismatch) => void;\n /** Long edge the sheet is normalized to before cutting; defaults to SHEET_MAX_WIDTH. */\n maxWidth?: number;\n}\n\n/**\n * Cuts the cards out of a drawn sheet and keeps the sheet. Cells come from the\n * divider lines the model drew (equal split as a last resort); each card is the\n * largest 3:4 rectangle in its cell, top-anchored, with the default circle — the\n * framing the host can let a user move later.\n */\nexport async function sliceSheet(\n sharp: SharpLike,\n raw: Buffer,\n cells: PortraitCell[],\n count: number,\n cols: number,\n rows: number,\n opts: SliceSheetOptions = {},\n): Promise<{ slices: PortraitSlice[]; sheet: DrawnSheet }> {\n // Normalise the working resolution first so cells, cards and the stored sheet\n // all share one pixel space.\n const grid: Buffer = await sharp(raw).resize({ width: opts.maxWidth ?? SHEET_MAX_WIDTH, withoutEnlargement: true }).toBuffer();\n const { data, info } = await sharp(grid).greyscale().raw().toBuffer({ resolveWithObject: true });\n const width = info.width, height = info.height;\n if (width < 100 * cols || height < 100 * rows) throw new Error(`Portrait sheet has unusable dimensions ${width}x${height}`);\n\n const plane = { width, height, data: new Uint8Array(data.buffer, data.byteOffset, data.length) };\n const gridCells = detectSheetGrid(plane, cols, rows);\n if (!gridCells.detected) {\n opts.onMismatch?.({\n kind: 'no-dividers',\n message: `no divider lines found on the ${cols}x${rows} sheet; using equal split`,\n detail: { width, height, dividers: describeDividers(plane) },\n });\n } else if (gridCells.cols !== cols || gridCells.rows !== rows) {\n // The model drew a different grid than asked. Its cells are still in row-major\n // order, so they are used as drawn; only characters past the last drawn cell\n // fall back to the equal split.\n opts.onMismatch?.({\n kind: 'different-grid',\n message: `sheet drawn as ${gridCells.cols}x${gridCells.rows}, requested ${cols}x${rows}; using the drawn cells`,\n detail: { width, height, drawnCells: gridCells.cells.length, needed: count },\n });\n }\n const fallback = equalSplitGrid(width, height, cols, rows).cells;\n\n const slices: PortraitSlice[] = [];\n for (let i = 0; i < count; i++) {\n const framing = defaultFraming(gridCells.cells[i] ?? fallback[i]);\n const jpeg = await cutCard(sharp, grid, framing.card);\n slices.push({ key: cells[i].key, label: cells[i].label, jpeg, framing });\n }\n\n let sheetJpeg: Buffer = await sharp(grid).jpeg({ quality: SHEET_JPEG_QUALITY, mozjpeg: true }).toBuffer();\n if (sheetJpeg.length * 4 / 3 > SHEET_MAX_BASE64_BYTES) {\n sheetJpeg = await sharp(grid).jpeg({ quality: 72, mozjpeg: true }).toBuffer();\n }\n return {\n slices,\n sheet: { jpeg: sheetJpeg, width, height, cells: gridCells.cells.slice(0, count), detected: gridCells.detected },\n };\n}\n\n/** Cuts one card out of a stored sheet at the given framing. */\nexport async function cutCard(sharp: SharpLike, sheet: Buffer, card: ImageRect): Promise<Buffer> {\n return sharp(sheet)\n .extract(card)\n .resize(CARD_WIDTH_PX, CARD_HEIGHT_PX)\n .jpeg({ quality: 85 })\n .toBuffer();\n}\n\nexport interface DrawPortraitSheetSpec extends Omit<PortraitSheetPrompt, 'cols' | 'rows'> {\n /** Prompt for the cells that pad the cast out to a full grid. */\n fillerPrompt?: string;\n}\n\nexport interface DrawPortraitSheetOptions extends SliceSheetOptions {\n image?: Pick<GenerateImageOptions, 'model' | 'imageSize' | 'thinkingLevel' | 'fetchImpl'>;\n}\n\nexport interface DrawnPortraitSheet {\n portraits: PortraitSlice[];\n sheet: DrawnSheet;\n /** What the image call cost, reported for the host's billing. */\n costUSD: number;\n}\n\n/**\n * The whole pipeline: lay the cast out on a grid, draw it in one call, cut the\n * cards. Filler cells are drawn and discarded; `portraits` has exactly one entry\n * per input cell, in order.\n */\nexport async function drawPortraitSheet(apiKey: string, sharp: SharpLike, spec: DrawPortraitSheetSpec, opts: DrawPortraitSheetOptions = {}): Promise<DrawnPortraitSheet> {\n const { cells, cols, rows, realCount } = padCells(spec.cells, spec.fillerPrompt);\n const prompt = buildPortraitSheetPrompt({ cells, cols, rows, purpose: spec.purpose, setting: spec.setting, artStyle: spec.artStyle });\n const image = await generateImage(apiKey, prompt, '4:3', opts.image);\n const { slices, sheet } = await sliceSheet(sharp, image.buffer, cells, realCount, cols, rows, opts);\n return { portraits: slices, sheet, costUSD: image.costUSD };\n}\n"],"mappings":";AAyCO,IAAM,cAAc,IAAI;AACxB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AAGvB,IAAM,wBAAsC,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK;AAExE,IAAM,2BAA2B;;;AC1BxC,IAAM,QAAQ,CAAC,GAAW,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,CAAC;AAK9E,SAAS,WAAW,MAA4B;AACnD,QAAM,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,OAAO,KAAK,SAAS,WAAW,CAAC;AACxE,QAAM,SAAS,KAAK,IAAI,KAAK,QAAQ,KAAK,MAAM,QAAQ,WAAW,CAAC;AACpE,SAAO;AAAA,IACH,MAAM,KAAK,MAAM,KAAK,QAAQ,KAAK,QAAQ,SAAS,CAAC;AAAA,IACrD,KAAK,KAAK;AAAA,IACV;AAAA,IACA;AAAA,EACJ;AACJ;AAEO,SAAS,eAAe,MAAgC;AAC3D,SAAO,EAAE,MAAM,WAAW,IAAI,GAAG,QAAQ,EAAE,GAAG,sBAAsB,EAAE;AAC1E;AAGO,SAAS,UAAU,QAAoC;AAC1D,QAAM,IAAI,MA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nD,gBAAY,MAAM,MAAM,IAAI,EAAE,KAAK,EAAE,SAAS,IAAI,SAAS,KAAK,CAAC,EAAE,SAAS;AAAA,EAChF;AACA,SAAO;AAAA,IACH;AAAA,IACA,OAAO,EAAE,MAAM,WAAW,OAAO,QAAQ,OAAO,UAAU,MAAM,MAAM,GAAG,KAAK,GAAG,UAAU,UAAU,SAAS;AAAA,EAClH;AACJ;AAGA,eAAsB,QAAQ,OAAkB,OAAe,MAAkC;AAC7F,SAAO,MAAM,KAAK,EACb,QAAQ,IAAI,EACZ,OAAO,eAAe,cAAc,EACpC,KAAK,EAAE,SAAS,GAAG,CAAC,EACpB,SAAS;AAClB;AAuBA,eAAsB,kBAAkB,QAAgB,OAAkB,MAA6B,OAAiC,CAAC,GAAgC;AACrK,QAAM,EAAE,OAAO,MAAM,MAAM,UAAU,IAAI,SAAS,KAAK,OAAO,KAAK,YAAY;AAC/E,QAAM,SAAS,yBAAyB,EAAE,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,SAAS,KAAK,SAAS,UAAU,KAAK,SAAS,CAAC;AACpI,QAAM,QAAQ,MAAM,cAAc,QAAQ,QAAQ,OAAO,KAAK,KAAK;AACnE,QAAM,EAAE,QAAQ,MAAM,IAAI,MAAM,WAAW,OAAO,MAAM,QAAQ,OAAO,WAAW,MAAM,MAAM,IAAI;AAClG,SAAO,EAAE,WAAW,QAAQ,OAAO,SAAS,MAAM,QAAQ;AAC9D;","names":["clamp","sum"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -580,7 +580,9 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
580
580
|
* alias for thinking_budget (low = 4,096, medium = 16,384, xhigh = 262,144 tokens) and the
|
|
581
581
|
* two are mutually exclusive — sending both is a 400. QwenAgent sends the budget instead,
|
|
582
582
|
* because 1,024 is tighter than the lowest level effort can express.
|
|
583
|
-
* MiniMax
|
|
583
|
+
* - MiniMax M3.1 Flash (platform.minimax.io text-chat-openai reference, 2026-10-27):
|
|
584
|
+
* low|medium|high|xhigh|max, default max, top-level `reasoning_effort` on Chat Completions;
|
|
585
|
+
* "none" → 400. Only M3.1 Flash honours it — M3 and M2.x ignore the field.
|
|
584
586
|
*/
|
|
585
587
|
type OpenAIReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
586
588
|
type AnthropicReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
@@ -592,6 +594,7 @@ type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'ma
|
|
|
592
594
|
type MistralReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
593
595
|
type XaiReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh';
|
|
594
596
|
type KimiReasoningEffort = 'low' | 'high' | 'max';
|
|
597
|
+
type MiniMaxReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
595
598
|
/** The shared scale, lowest first. */
|
|
596
599
|
declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
|
|
597
600
|
declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
|
|
@@ -604,6 +607,7 @@ declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
|
|
|
604
607
|
declare const MISTRAL_REASONING_EFFORTS: readonly MistralReasoningEffort[];
|
|
605
608
|
declare const XAI_REASONING_EFFORTS: readonly XaiReasoningEffort[];
|
|
606
609
|
declare const KIMI_REASONING_EFFORTS: readonly KimiReasoningEffort[];
|
|
610
|
+
declare const MINIMAX_REASONING_EFFORTS: readonly MiniMaxReasoningEffort[];
|
|
607
611
|
/** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
|
|
608
612
|
declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
|
|
609
613
|
declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
|
|
@@ -616,6 +620,7 @@ declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
|
|
|
616
620
|
declare const toMistralEffort: (effort: ReasoningEffort) => MistralReasoningEffort;
|
|
617
621
|
declare const toXaiEffort: (effort: ReasoningEffort) => XaiReasoningEffort;
|
|
618
622
|
declare const toKimiEffort: (effort: ReasoningEffort) => KimiReasoningEffort;
|
|
623
|
+
declare const toMiniMaxEffort: (effort: ReasoningEffort) => MiniMaxReasoningEffort;
|
|
619
624
|
|
|
620
625
|
/**
|
|
621
626
|
* Unified token usage utilities for all AI providers
|
|
@@ -1858,4 +1863,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1858
1863
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1859
1864
|
}
|
|
1860
1865
|
|
|
1861
|
-
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
|
1866
|
+
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -580,7 +580,9 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
580
580
|
* alias for thinking_budget (low = 4,096, medium = 16,384, xhigh = 262,144 tokens) and the
|
|
581
581
|
* two are mutually exclusive — sending both is a 400. QwenAgent sends the budget instead,
|
|
582
582
|
* because 1,024 is tighter than the lowest level effort can express.
|
|
583
|
-
* MiniMax
|
|
583
|
+
* - MiniMax M3.1 Flash (platform.minimax.io text-chat-openai reference, 2026-10-27):
|
|
584
|
+
* low|medium|high|xhigh|max, default max, top-level `reasoning_effort` on Chat Completions;
|
|
585
|
+
* "none" → 400. Only M3.1 Flash honours it — M3 and M2.x ignore the field.
|
|
584
586
|
*/
|
|
585
587
|
type OpenAIReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
586
588
|
type AnthropicReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
@@ -592,6 +594,7 @@ type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'ma
|
|
|
592
594
|
type MistralReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
593
595
|
type XaiReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh';
|
|
594
596
|
type KimiReasoningEffort = 'low' | 'high' | 'max';
|
|
597
|
+
type MiniMaxReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
595
598
|
/** The shared scale, lowest first. */
|
|
596
599
|
declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
|
|
597
600
|
declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
|
|
@@ -604,6 +607,7 @@ declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
|
|
|
604
607
|
declare const MISTRAL_REASONING_EFFORTS: readonly MistralReasoningEffort[];
|
|
605
608
|
declare const XAI_REASONING_EFFORTS: readonly XaiReasoningEffort[];
|
|
606
609
|
declare const KIMI_REASONING_EFFORTS: readonly KimiReasoningEffort[];
|
|
610
|
+
declare const MINIMAX_REASONING_EFFORTS: readonly MiniMaxReasoningEffort[];
|
|
607
611
|
/** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
|
|
608
612
|
declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
|
|
609
613
|
declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
|
|
@@ -616,6 +620,7 @@ declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
|
|
|
616
620
|
declare const toMistralEffort: (effort: ReasoningEffort) => MistralReasoningEffort;
|
|
617
621
|
declare const toXaiEffort: (effort: ReasoningEffort) => XaiReasoningEffort;
|
|
618
622
|
declare const toKimiEffort: (effort: ReasoningEffort) => KimiReasoningEffort;
|
|
623
|
+
declare const toMiniMaxEffort: (effort: ReasoningEffort) => MiniMaxReasoningEffort;
|
|
619
624
|
|
|
620
625
|
/**
|
|
621
626
|
* Unified token usage utilities for all AI providers
|
|
@@ -1858,4 +1863,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1858
1863
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1859
1864
|
}
|
|
1860
1865
|
|
|
1861
|
-
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
|
1866
|
+
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_REQUEST_TIMEOUT_MS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MINIMAX_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, type MiniMaxReasoningEffort, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelTimeoutError, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMiniMaxEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ __export(src_exports, {
|
|
|
61
61
|
LLM_CONSTANTS: () => LLM_CONSTANTS,
|
|
62
62
|
MESSAGE_ROLE: () => MESSAGE_ROLE,
|
|
63
63
|
META_REASONING_EFFORTS: () => META_REASONING_EFFORTS,
|
|
64
|
+
MINIMAX_REASONING_EFFORTS: () => MINIMAX_REASONING_EFFORTS,
|
|
64
65
|
MISTRAL_REASONING_EFFORTS: () => MISTRAL_REASONING_EFFORTS,
|
|
65
66
|
MODEL_PRICING: () => MODEL_PRICING,
|
|
66
67
|
MetaAgent: () => MetaAgent,
|
|
@@ -167,6 +168,7 @@ __export(src_exports, {
|
|
|
167
168
|
toGlmEffort: () => toGlmEffort,
|
|
168
169
|
toKimiEffort: () => toKimiEffort,
|
|
169
170
|
toMetaEffort: () => toMetaEffort,
|
|
171
|
+
toMiniMaxEffort: () => toMiniMaxEffort,
|
|
170
172
|
toMistralEffort: () => toMistralEffort,
|
|
171
173
|
toOpenAIEffort: () => toOpenAIEffort,
|
|
172
174
|
toXaiEffort: () => toXaiEffort,
|
|
@@ -1445,20 +1447,29 @@ var SupportedAiModels = {
|
|
|
1445
1447
|
thinkingBudgetTokens: 1024,
|
|
1446
1448
|
tags: ["slow", "cheap"]
|
|
1447
1449
|
},
|
|
1448
|
-
// MiniMax M3 (OpenAI-compatible endpoint, 1M context).
|
|
1449
|
-
//
|
|
1450
|
-
//
|
|
1451
|
-
//
|
|
1452
|
-
//
|
|
1453
|
-
//
|
|
1454
|
-
// Temperature
|
|
1450
|
+
// MiniMax M3.1 Flash (OpenAI-compatible endpoint, 1M context). `minimax` repointed 2026-10-27
|
|
1451
|
+
// from MiniMax-M3 ($0.30/$1.20 after the permanent 50% off, 25s single-sample turn, 60s
|
|
1452
|
+
// timeouts in prod on 2026-10-25 and 10-27) to MiniMax-M3.1-Flash: half the price
|
|
1453
|
+
// ($0.15/$0.60), and the first MiniMax model with an effort dial — low|medium|high|xhigh|max,
|
|
1454
|
+
// provider default max, so it is pinned. Thinking is always on (`thinking: disabled` → 400),
|
|
1455
|
+
// thinking arrives in `reasoning_content` because the agent sends `reasoning_split: true`
|
|
1456
|
+
// (M3.1 rejects false). Temperature and top_p are documented as ignored ("not supported
|
|
1457
|
+
// yet", always 1 / 0.95), so the entry sets none and the agent sends none.
|
|
1458
|
+
// Live 2026-10-27 at medium: the all-providers sweep ran the schema ask in 3.1s, prose in
|
|
1459
|
+
// 1.7s and the 8-character scene (363 output tokens) in 2.4s — ~150 tok/s, the fastest
|
|
1460
|
+
// provider in the sweep that day (Kimi Highspeed's scene takes 8s); a 3.2k-token game
|
|
1461
|
+
// prompt with a two-sentence JSON reply took 1.9-2.1s at every effort level vs 3.5s for M3.
|
|
1462
|
+
// Tagged `fast` rather than `very-fast`: the sweep straddles the 3s line and production
|
|
1463
|
+
// turns carry 10k+ tokens of context. Launched 2026-09-27 as Token-Plan-only (the
|
|
1464
|
+
// 2026-10-02 probe got `unknown model` on the pay-as-you-go key); on the key since at
|
|
1465
|
+
// least 2026-10-27.
|
|
1455
1466
|
[LLM_CONSTANTS.MINIMAX]: {
|
|
1456
|
-
displayName: "MiniMax M3",
|
|
1457
|
-
modelApiName: "MiniMax-M3",
|
|
1467
|
+
displayName: "MiniMax M3.1 Flash",
|
|
1468
|
+
modelApiName: "MiniMax-M3.1-Flash",
|
|
1458
1469
|
apiKeyName: API_KEY_CONSTANTS.MINIMAX,
|
|
1459
1470
|
hasThinking: true,
|
|
1460
|
-
|
|
1461
|
-
tags: ["
|
|
1471
|
+
reasoningEffort: "medium",
|
|
1472
|
+
tags: ["fast", "cheap"]
|
|
1462
1473
|
},
|
|
1463
1474
|
// Meta Muse Spark 1.3 (added 2026-09-12) on Meta's own Model API — Standard tier, i.e.
|
|
1464
1475
|
// the private model id (the `-contributor` id is a quarter of the price but Meta trains
|
|
@@ -1775,18 +1786,14 @@ var MODEL_PRICING = {
|
|
|
1775
1786
|
outputPrice: 0.47,
|
|
1776
1787
|
cacheHitPrice: 0.016
|
|
1777
1788
|
},
|
|
1778
|
-
// MiniMax M3. Rates from platform.minimax.io/docs/guides/pricing-paygo (2026-
|
|
1779
|
-
//
|
|
1780
|
-
// (≥512 input tokens), hits reported in
|
|
1781
|
-
//
|
|
1789
|
+
// MiniMax M3.1 Flash. Rates from platform.minimax.io/docs/guides/pricing-paygo (2026-10-27,
|
|
1790
|
+
// USD): one tier across the 1M window (M3 had ≤512k / >512k tiers; the page lists none for
|
|
1791
|
+
// M3.1 Flash). Caching is automatic (≥512 input tokens), hits reported in
|
|
1792
|
+
// prompt_tokens_details.cached_tokens; no write fee listed.
|
|
1782
1793
|
[SupportedAiModels[LLM_CONSTANTS.MINIMAX].modelApiName]: {
|
|
1783
|
-
inputPrice: 0.
|
|
1784
|
-
outputPrice:
|
|
1785
|
-
cacheHitPrice: 0.
|
|
1786
|
-
extendedContextInputPrice: 0.6,
|
|
1787
|
-
extendedContextOutputPrice: 2.4,
|
|
1788
|
-
extendedContextCacheHitPrice: 0.12,
|
|
1789
|
-
extendedContextThresholdTokens: 512e3
|
|
1794
|
+
inputPrice: 0.15,
|
|
1795
|
+
outputPrice: 0.6,
|
|
1796
|
+
cacheHitPrice: 0.015
|
|
1790
1797
|
},
|
|
1791
1798
|
// Meta Muse Spark 1.3, Standard tier. Rates from ai.developer.meta.com/docs/pricing-rate-limits
|
|
1792
1799
|
// (2026-09-12): no long-context premium at any point of the 1M window; reasoning tokens bill
|
|
@@ -1816,7 +1823,7 @@ var HYBRID_THINKING_API_NAMES = /* @__PURE__ */ new Set([
|
|
|
1816
1823
|
// hybrid by the same definition: we force reasoning on, so they carry the multiplier.
|
|
1817
1824
|
SupportedAiModels[LLM_CONSTANTS.QWEN_MAX].modelApiName,
|
|
1818
1825
|
SupportedAiModels[LLM_CONSTANTS.QWEN_FLASH].modelApiName,
|
|
1819
|
-
|
|
1826
|
+
// MiniMax left the set 2026-10-27: M3.1 Flash cannot turn thinking off (M3 could).
|
|
1820
1827
|
// Mistral reasons only when asked (`reasoning_effort`), and we always ask — hybrid by the
|
|
1821
1828
|
// same definition as Qwen. Added 2026-09-18 when the Mistral entries went thinking-on.
|
|
1822
1829
|
SupportedAiModels[LLM_CONSTANTS.MISTRAL_SMALL].modelApiName
|
|
@@ -1889,6 +1896,7 @@ var META_REASONING_EFFORTS = ["minimal", "low", "medium", "high", "xhigh", "max"
|
|
|
1889
1896
|
var MISTRAL_REASONING_EFFORTS = ["high"];
|
|
1890
1897
|
var XAI_REASONING_EFFORTS = ["low", "medium", "high", "xhigh"];
|
|
1891
1898
|
var KIMI_REASONING_EFFORTS = ["low", "high", "max"];
|
|
1899
|
+
var MINIMAX_REASONING_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
1892
1900
|
function clampReasoningEffort(effort, allowed) {
|
|
1893
1901
|
const rank = REASONING_EFFORT_SCALE.indexOf(effort);
|
|
1894
1902
|
let best = allowed[0];
|
|
@@ -1912,6 +1920,7 @@ var toFuguEffort = (effort) => clampReasoningEffort(effort, FUGU_REASONING_EFFOR
|
|
|
1912
1920
|
var toMistralEffort = (effort) => clampReasoningEffort(effort, MISTRAL_REASONING_EFFORTS);
|
|
1913
1921
|
var toXaiEffort = (effort) => clampReasoningEffort(effort, XAI_REASONING_EFFORTS);
|
|
1914
1922
|
var toKimiEffort = (effort) => clampReasoningEffort(effort, KIMI_REASONING_EFFORTS);
|
|
1923
|
+
var toMiniMaxEffort = (effort) => clampReasoningEffort(effort, MINIMAX_REASONING_EFFORTS);
|
|
1915
1924
|
|
|
1916
1925
|
// src/pricing/token-usage-utils.ts
|
|
1917
1926
|
function extractTokenUsage(response) {
|
|
@@ -5229,10 +5238,10 @@ var MiniMaxAgent = class extends AbstractAgent {
|
|
|
5229
5238
|
get defaultParams() {
|
|
5230
5239
|
return {
|
|
5231
5240
|
model: this.model,
|
|
5232
|
-
temperature: this.temperature,
|
|
5241
|
+
...this.temperature !== void 0 ? { temperature: this.temperature } : {},
|
|
5233
5242
|
stream: false,
|
|
5234
|
-
// MiniMax deprecates max_tokens in favor of max_completion_tokens (
|
|
5235
|
-
// far above anything a turn needs).
|
|
5243
|
+
// MiniMax deprecates max_tokens in favor of max_completion_tokens (the M-series max is
|
|
5244
|
+
// 512K, far above anything a turn needs).
|
|
5236
5245
|
max_completion_tokens: this.maxOutputTokens
|
|
5237
5246
|
};
|
|
5238
5247
|
}
|
|
@@ -5254,7 +5263,9 @@ var MiniMaxAgent = class extends AbstractAgent {
|
|
|
5254
5263
|
thinkingParams() {
|
|
5255
5264
|
return {
|
|
5256
5265
|
thinking: { type: this.enableThinking ? "adaptive" : "disabled" },
|
|
5257
|
-
reasoning_split: true
|
|
5266
|
+
reasoning_split: true,
|
|
5267
|
+
// Provider default is max; the catalog pins M3.1 Flash to medium. Older models ignore it.
|
|
5268
|
+
...this.enableThinking && this.reasoningEffort ? { reasoning_effort: toMiniMaxEffort(this.reasoningEffort) } : {}
|
|
5258
5269
|
};
|
|
5259
5270
|
}
|
|
5260
5271
|
convertToOpenAIMessages(messages) {
|
|
@@ -5667,7 +5678,7 @@ var AgentFactory = class {
|
|
|
5667
5678
|
case LLM_CONSTANTS.QWEN_MAX:
|
|
5668
5679
|
case LLM_CONSTANTS.QWEN_FLASH:
|
|
5669
5680
|
return new QwenAgent(name, instruction, model.modelApiName, key, model.temperature, shouldEnableThinking);
|
|
5670
|
-
// MiniMax M3 — adaptive thinking
|
|
5681
|
+
// MiniMax M3.1 Flash — always-on adaptive thinking, effort from the catalog
|
|
5671
5682
|
case LLM_CONSTANTS.MINIMAX:
|
|
5672
5683
|
return new MiniMaxAgent(name, instruction, model.modelApiName, key, model.temperature, shouldEnableThinking);
|
|
5673
5684
|
// Meta Muse Spark — Responses API with encrypted reasoning replay, effort from the catalog
|
|
@@ -5719,6 +5730,7 @@ var AgentFactory = class {
|
|
|
5719
5730
|
LLM_CONSTANTS,
|
|
5720
5731
|
MESSAGE_ROLE,
|
|
5721
5732
|
META_REASONING_EFFORTS,
|
|
5733
|
+
MINIMAX_REASONING_EFFORTS,
|
|
5722
5734
|
MISTRAL_REASONING_EFFORTS,
|
|
5723
5735
|
MODEL_PRICING,
|
|
5724
5736
|
MetaAgent,
|
|
@@ -5825,6 +5837,7 @@ var AgentFactory = class {
|
|
|
5825
5837
|
toGlmEffort,
|
|
5826
5838
|
toKimiEffort,
|
|
5827
5839
|
toMetaEffort,
|
|
5840
|
+
toMiniMaxEffort,
|
|
5828
5841
|
toMistralEffort,
|
|
5829
5842
|
toOpenAIEffort,
|
|
5830
5843
|
toXaiEffort,
|