@donotlb/imagen-sdk 0.2.0 → 0.2.2
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/client.d.ts +0 -1
- package/dist/contracts.js +0 -4
- package/dist/image-models/registry.d.ts +0 -13
- package/dist/image-models/registry.js +0 -2
- package/dist/image-models/size.d.ts +0 -16
- package/dist/image-models/size.js +0 -18
- package/dist/image-models/types.d.ts +0 -10
- package/dist/image-models/types.js +0 -10
- package/dist/service-jwt.d.ts +0 -5
- package/dist/service-jwt.js +0 -5
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { ImagenGenerationAccepted, ImagenGenerationCancelAccepted, ImagenGe
|
|
|
2
2
|
export interface ImagenClientOptions {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
serviceJwtSecret: string;
|
|
5
|
-
/** This caller's service identity (JWT `iss`). Defaults to `tutu`. */
|
|
6
5
|
clientName?: string;
|
|
7
6
|
fetch?: typeof fetch;
|
|
8
7
|
}
|
package/dist/contracts.js
CHANGED
|
@@ -18,10 +18,6 @@ export const imagenGenerationRequestSchema = z.object({
|
|
|
18
18
|
count: z.int().min(1).max(4).optional(),
|
|
19
19
|
}).strict(),
|
|
20
20
|
output: z.object({
|
|
21
|
-
// Opaque namespace owned by the caller. Imagen does not interpret its
|
|
22
|
-
// structure; it only normalizes it and owns the leaf filename
|
|
23
|
-
// (`${jobId}-${index}.${ext}`). Callers should treat the returned
|
|
24
|
-
// `storageKey` as a read-only opaque value.
|
|
25
21
|
storageKeyPrefix: z.string().trim().min(1).max(1024),
|
|
26
22
|
}).strict(),
|
|
27
23
|
callback: z.object({
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import type { AspectRatio, ImageModelId, ImageQuality, Resolution } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* The provider's hard limits on an output size; size derivation honours all of
|
|
4
|
-
* these. {@link ImageModelSpec.resolutionLongEdge} and {@link SizeConstraints.maxPixels}
|
|
5
|
-
* together bound the worst-case (largest) pixel count of a resolution tier.
|
|
6
|
-
*/
|
|
7
2
|
export interface SizeConstraints {
|
|
8
|
-
/** Longest edge the provider accepts, in pixels. */
|
|
9
3
|
maxEdge: number;
|
|
10
|
-
/** Both edges must be a multiple of this. */
|
|
11
4
|
edgeMultiple: number;
|
|
12
5
|
minPixels: number;
|
|
13
6
|
maxPixels: number;
|
|
14
|
-
/** Long edge / short edge must not exceed this. */
|
|
15
7
|
maxAspectRatio: number;
|
|
16
8
|
}
|
|
17
9
|
export interface ImageModelSpec {
|
|
@@ -20,11 +12,6 @@ export interface ImageModelSpec {
|
|
|
20
12
|
resolutions: readonly Resolution[];
|
|
21
13
|
aspectRatios: readonly AspectRatio[];
|
|
22
14
|
constraints: SizeConstraints;
|
|
23
|
-
/**
|
|
24
|
-
* Target long-edge (px) each resolution tier aims for before the constraints
|
|
25
|
-
* clamp it. Square/near-square 4K is pulled below 3840 by the pixel ceiling;
|
|
26
|
-
* thin ratios at 1K are pushed up by the pixel floor.
|
|
27
|
-
*/
|
|
28
15
|
resolutionLongEdge: Record<Resolution, number>;
|
|
29
16
|
}
|
|
30
17
|
export declare function getModelSpec(model: ImageModelId): ImageModelSpec;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ASPECT_RATIOS, IMAGE_QUALITIES, RESOLUTIONS } from './types.js';
|
|
2
|
-
// gpt-image-2 constraints, from OpenAI's image generation guide: max edge 3840,
|
|
3
|
-
// edges multiple of 16, long:short <= 3:1, total pixels in [655_360, 8_294_400].
|
|
4
2
|
const GPT_IMAGE_2 = {
|
|
5
3
|
id: 'openai/gpt-image-2',
|
|
6
4
|
qualities: IMAGE_QUALITIES,
|
|
@@ -3,21 +3,5 @@ export interface ResolvedSize {
|
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Derive the concrete pixel size to request for a (ratio, resolution) choice,
|
|
8
|
-
* honouring every model constraint: the resolution tier sets a target long
|
|
9
|
-
* edge, which is then clamped into the pixel floor/ceiling and rounded so both
|
|
10
|
-
* edges are a valid multiple. The long edge is anchored to the tier, so the
|
|
11
|
-
* canonical OpenAI sizes fall out exactly (e.g. 2K 16:9 -> 2048x1152, 4K 16:9
|
|
12
|
-
* -> 3840x2160), while squarer ratios at 4K are pulled down by the 8.29MP
|
|
13
|
-
* ceiling and thin ratios at 1K are pushed up by the 655K floor.
|
|
14
|
-
*
|
|
15
|
-
* `auto` ratio resolves to a square (1:1) at the chosen resolution: the
|
|
16
|
-
* resolution selector is always honoured and the billed tier always matches the
|
|
17
|
-
* pixels actually requested. (gpt-image-2's own `size: auto` would let the model
|
|
18
|
-
* pick the aspect but ignore our resolution choice, so we default the aspect
|
|
19
|
-
* ourselves instead.)
|
|
20
|
-
*/
|
|
21
6
|
export declare function resolveImageSize(model: ImageModelId, aspectRatio: AspectRatio, resolution: Resolution): ResolvedSize;
|
|
22
|
-
/** Format a resolved size as the provider's `WIDTHxHEIGHT` size string. */
|
|
23
7
|
export declare function formatSize(size: ResolvedSize | 'auto'): string;
|
|
@@ -2,21 +2,6 @@ import { getModelSpec } from './registry.js';
|
|
|
2
2
|
function roundToMultiple(value, multiple) {
|
|
3
3
|
return Math.max(multiple, Math.round(value / multiple) * multiple);
|
|
4
4
|
}
|
|
5
|
-
/**
|
|
6
|
-
* Derive the concrete pixel size to request for a (ratio, resolution) choice,
|
|
7
|
-
* honouring every model constraint: the resolution tier sets a target long
|
|
8
|
-
* edge, which is then clamped into the pixel floor/ceiling and rounded so both
|
|
9
|
-
* edges are a valid multiple. The long edge is anchored to the tier, so the
|
|
10
|
-
* canonical OpenAI sizes fall out exactly (e.g. 2K 16:9 -> 2048x1152, 4K 16:9
|
|
11
|
-
* -> 3840x2160), while squarer ratios at 4K are pulled down by the 8.29MP
|
|
12
|
-
* ceiling and thin ratios at 1K are pushed up by the 655K floor.
|
|
13
|
-
*
|
|
14
|
-
* `auto` ratio resolves to a square (1:1) at the chosen resolution: the
|
|
15
|
-
* resolution selector is always honoured and the billed tier always matches the
|
|
16
|
-
* pixels actually requested. (gpt-image-2's own `size: auto` would let the model
|
|
17
|
-
* pick the aspect but ignore our resolution choice, so we default the aspect
|
|
18
|
-
* ourselves instead.)
|
|
19
|
-
*/
|
|
20
5
|
export function resolveImageSize(model, aspectRatio, resolution) {
|
|
21
6
|
const { constraints: c, resolutionLongEdge } = getModelSpec(model);
|
|
22
7
|
const [rw, rh] = aspectRatio === 'auto'
|
|
@@ -26,7 +11,6 @@ export function resolveImageSize(model, aspectRatio, resolution) {
|
|
|
26
11
|
const ratioShort = Math.min(rw, rh);
|
|
27
12
|
let longEdge = resolutionLongEdge[resolution];
|
|
28
13
|
let shortEdge = (longEdge * ratioShort) / ratioLong;
|
|
29
|
-
// Scale into the pixel band before rounding.
|
|
30
14
|
const pixels = longEdge * shortEdge;
|
|
31
15
|
if (pixels > c.maxPixels) {
|
|
32
16
|
const scale = Math.sqrt(c.maxPixels / pixels);
|
|
@@ -40,7 +24,6 @@ export function resolveImageSize(model, aspectRatio, resolution) {
|
|
|
40
24
|
}
|
|
41
25
|
longEdge = roundToMultiple(Math.min(longEdge, c.maxEdge), c.edgeMultiple);
|
|
42
26
|
shortEdge = roundToMultiple(shortEdge, c.edgeMultiple);
|
|
43
|
-
// Rounding can nudge past the ceiling/floor; step back into range.
|
|
44
27
|
while (longEdge * shortEdge > c.maxPixels) {
|
|
45
28
|
if (longEdge >= shortEdge)
|
|
46
29
|
longEdge -= c.edgeMultiple;
|
|
@@ -58,7 +41,6 @@ export function resolveImageSize(model, aspectRatio, resolution) {
|
|
|
58
41
|
? { width: longEdge, height: shortEdge }
|
|
59
42
|
: { width: shortEdge, height: longEdge };
|
|
60
43
|
}
|
|
61
|
-
/** Format a resolved size as the provider's `WIDTHxHEIGHT` size string. */
|
|
62
44
|
export function formatSize(size) {
|
|
63
45
|
return size === 'auto' ? 'auto' : `${size.width}x${size.height}`;
|
|
64
46
|
}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical image-model vocabulary for the Imagen service contract — the
|
|
3
|
-
* aspect-ratio / resolution / quality unions defined exactly once and shared by
|
|
4
|
-
* every consumer (the Imagen service and its SDK clients).
|
|
5
|
-
*
|
|
6
|
-
* `quality` is deliberately three tiers — `auto` was dropped at the product
|
|
7
|
-
* layer (callers should pick a concrete tier before submitting work to Imagen).
|
|
8
|
-
* A consumer's database may keep a legacy `auto` enum value for historical rows,
|
|
9
|
-
* but nothing new is written with it.
|
|
10
|
-
*/
|
|
11
1
|
export declare const IMAGE_MODEL_IDS: readonly ["openai/gpt-image-2"];
|
|
12
2
|
export type ImageModelId = typeof IMAGE_MODEL_IDS[number];
|
|
13
3
|
export declare const IMAGE_QUALITIES: readonly ["low", "medium", "high"];
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical image-model vocabulary for the Imagen service contract — the
|
|
3
|
-
* aspect-ratio / resolution / quality unions defined exactly once and shared by
|
|
4
|
-
* every consumer (the Imagen service and its SDK clients).
|
|
5
|
-
*
|
|
6
|
-
* `quality` is deliberately three tiers — `auto` was dropped at the product
|
|
7
|
-
* layer (callers should pick a concrete tier before submitting work to Imagen).
|
|
8
|
-
* A consumer's database may keep a legacy `auto` enum value for historical rows,
|
|
9
|
-
* but nothing new is written with it.
|
|
10
|
-
*/
|
|
11
1
|
export const IMAGE_MODEL_IDS = ['openai/gpt-image-2'];
|
|
12
2
|
export const IMAGE_QUALITIES = ['low', 'medium', 'high'];
|
|
13
3
|
export const RESOLUTIONS = ['1k', '2k', '4k'];
|
package/dist/service-jwt.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { JWTPayload } from 'jose';
|
|
2
|
-
/**
|
|
3
|
-
* Identity of the service that calls Imagen. Imagen is generic infrastructure;
|
|
4
|
-
* the caller's name is configurable. `tutu` is the default because it is the
|
|
5
|
-
* first consumer, but any client can set its own name via `SERVICE_CLIENT_NAME`.
|
|
6
|
-
*/
|
|
7
2
|
export declare const DEFAULT_SERVICE_CLIENT_NAME = "tutu";
|
|
8
3
|
export declare class ServiceJwtError extends Error {
|
|
9
4
|
constructor(message?: string);
|
package/dist/service-jwt.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { jwtVerify, SignJWT } from 'jose';
|
|
2
2
|
const DEFAULT_MAX_TTL_SECONDS = 5 * 60;
|
|
3
3
|
const CLOCK_TOLERANCE_SECONDS = 5;
|
|
4
|
-
/**
|
|
5
|
-
* Identity of the service that calls Imagen. Imagen is generic infrastructure;
|
|
6
|
-
* the caller's name is configurable. `tutu` is the default because it is the
|
|
7
|
-
* first consumer, but any client can set its own name via `SERVICE_CLIENT_NAME`.
|
|
8
|
-
*/
|
|
9
4
|
export const DEFAULT_SERVICE_CLIENT_NAME = 'tutu';
|
|
10
5
|
export class ServiceJwtError extends Error {
|
|
11
6
|
constructor(message = 'Invalid service token') {
|