{"version":3,"file":"_shared.cjs","names":[],"sources":["../../../src/batteries/generation/_shared/index.ts"],"sourcesContent":["/**\n * Structural contracts and normalization helpers shared by the media generation batteries\n * (text→image + image editing).\n *\n * @module @nhtio/adk/batteries/generation/_shared\n *\n * @remarks\n * This module imports **nothing** from `@nhtio/adk` core — not even a type-only import — per\n * CONTRIBUTING.md → Design Decisions → #13 \"Battery design — no concrete core-class coupling\",\n * tier 2 (locally-declared structural duck-types). A generation adapter is *handed* an image to\n * edit at runtime (the source image, an optional mask) but never constructs a `Media` itself, so\n * it has no genuine reason to import the class: {@link GenerationMediaLike} declares the exact\n * shape it reads (`mimeType` + `asBytes()`), and a real core `Media` instance satisfies it\n * automatically, with zero import edge between the generation domain and core.\n *\n * This is the structural twin of `src/batteries/specialists/_shared/index.ts` restricted to the\n * image half (specialists' audio-specific `SpecialistPcmInput` / `DecodeAudioFn` machinery has no\n * counterpart here — generation batteries only ever consume images as input, never audio).\n */\n\nimport { isInstanceOf } from '@nhtio/adk/guards'\n\n/**\n * Structural duck-type of core `Media`: the exact shape a generation adapter reads off a media\n * value it was handed as edit input — its declared MIME type, and an async accessor for its raw\n * bytes.\n *\n * @remarks\n * A real `@nhtio/adk` `Media` instance satisfies this interface structurally (it has both a\n * `mimeType` string property and an `asBytes(): Promise<Uint8Array>` method), so callers can pass\n * a `Media` straight through without the generation domain ever importing the class. See the\n * module remarks for why this is a deliberate decoupling choice (CONTRIBUTING.md Design Decision\n * #13, tier 2).\n */\nexport interface GenerationMediaLike {\n  /** The media's declared MIME type, e.g. `'image/png'` or `'image/jpeg'`. */\n  mimeType: string\n  /** Resolves the media's raw bytes. */\n  asBytes(): Promise<Uint8Array>\n}\n\n/** Raw bytes plus an optional MIME type — the plain-object form of image input. */\nexport interface GenerationBytesInput {\n  /** The raw encoded image bytes (e.g. a PNG/JPEG/WebP buffer). */\n  bytes: Uint8Array\n  /** The MIME type of `bytes`, when known. */\n  mimeType?: string\n}\n\n/**\n * Any of the three forms a generation adapter accepts as image input (for edit calls, and for a\n * future mask parameter): a bare `Uint8Array` (MIME type unknown), a {@link GenerationBytesInput}\n * record (bytes + declared MIME), or a {@link GenerationMediaLike} (a real `Media` or any\n * duck-typed equivalent).\n */\nexport type GenerationImageInput = Uint8Array | GenerationBytesInput | GenerationMediaLike\n\n/**\n * Normalizes any {@link GenerationImageInput} form to plain bytes plus an optional MIME type.\n *\n * @remarks\n * A bare `Uint8Array` passes through with `mimeType: undefined` (the caller declared no MIME). A\n * {@link GenerationBytesInput} passes its `bytes`/`mimeType` through unchanged. A\n * {@link GenerationMediaLike} is resolved by awaiting `asBytes()` and reading `mimeType` off it.\n *\n * @param input - The image input in any accepted form.\n * @returns The normalized bytes and MIME type (MIME `undefined` only for the bare-`Uint8Array` form).\n */\nexport const toBytes = async (\n  input: GenerationImageInput\n): Promise<{ bytes: Uint8Array; mimeType?: string }> => {\n  if (isInstanceOf(input, 'Uint8Array', Uint8Array)) return { bytes: input, mimeType: undefined }\n  if (typeof (input as GenerationMediaLike).asBytes === 'function') {\n    const media = input as GenerationMediaLike\n    return { bytes: await media.asBytes(), mimeType: media.mimeType }\n  }\n  const bytesInput = input as GenerationBytesInput\n  return { bytes: bytesInput.bytes, mimeType: bytesInput.mimeType }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,UAAU,OACrB,UACsD;CACtD,IAAI,eAAA,aAAa,OAAO,cAAc,UAAU,GAAG,OAAO;EAAE,OAAO;EAAO,UAAU,KAAA;CAAU;CAC9F,IAAI,OAAQ,MAA8B,YAAY,YAAY;EAChE,MAAM,QAAQ;EACd,OAAO;GAAE,OAAO,MAAM,MAAM,QAAQ;GAAG,UAAU,MAAM;EAAS;CAClE;CACA,MAAM,aAAa;CACnB,OAAO;EAAE,OAAO,WAAW;EAAO,UAAU,WAAW;CAAS;AAClE"}