@civitai/app-sdk 0.86.0 → 0.87.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/README.md CHANGED
@@ -615,10 +615,98 @@ on one path):
615
615
  body returns your `maxBuzz` as `cost.total`, and billing settles to the real GPU
616
616
  time after the run. Show it as "up to N Buzz".
617
617
 
618
+ ### Sampler options per model family (`fetchGenerationSamplers`)
619
+
620
+ `params.sampler` on a `textToImage` body is a free string, and the valid names
621
+ depend on the model family: the SD families take `Euler a`, Chroma takes
622
+ `Euler`, Anima takes ComfyUI names such as `euler_ancestral`, and Flux.1 takes
623
+ no sampler at all. **A name the family does not offer is not refused.** The host
624
+ swaps in the family default, so a guessed sampler generates with a different one
625
+ and reports no error. Don't copy a list into your app. Read the one the on-site
626
+ generator renders:
627
+
628
+ ```ts
629
+ import { fetchGenerationSamplers, resolveGenerationSampler } from '@civitai/app-sdk/blocks';
630
+
631
+ // hostOrigin: useHostOrigin(); token: useBlockToken().raw — any block token works, no scope needed.
632
+ const catalog = await fetchGenerationSamplers({ hostOrigin, token });
633
+
634
+ // checkpoint: the checkpoint you generate against — a model block's
635
+ // context.checkpoint (BlockCheckpointInfo), or a page block's Checkpoint pick.
636
+ const lookup = resolveGenerationSampler(catalog, {
637
+ baseModel: checkpoint.baseModel,
638
+ modelVersionId: checkpoint.versionId,
639
+ });
640
+ if (!lookup.known) {
641
+ // The platform has no answer for this model (lookup.reason). Keep a free-text field.
642
+ } else if (lookup.sampler === null) {
643
+ // The generator shows no sampler control for this model: send no `sampler`.
644
+ } else {
645
+ // A drop-down: lookup.sampler.options ({ value, label }[]), preselect lookup.sampler.default.
646
+ }
647
+ ```
648
+
649
+ The route is `GET /api/v1/blocks/generation-samplers`. It returns
650
+ `{ ecosystems, baseModels }`:
651
+
652
+ - `ecosystems[key]` is `{ sampler, byModelVersion }`, keyed by ecosystem key.
653
+ `sampler` is `{ options, default }` or `null`. `byModelVersion[versionId]`
654
+ overrides it for model versions that select a different graph variant; today
655
+ that is HiDream Full, which offers `UniPC` while the rest of HiDream has no
656
+ sampler.
657
+ - `baseModels[name]` maps a base model name (`SDXL 1.0`, `Flux.1 D`, …) to its
658
+ ecosystem key.
659
+
660
+ `resolveGenerationSampler` applies them in this order:
661
+
662
+ 1. With `baseModel`, it finds the family, then that family's override for
663
+ `modelVersionId`, and otherwise the family's control. This matches the host,
664
+ which picks the graph by the checkpoint's base model and version.
665
+
666
+ 🔴 **Pass the CHECKPOINT, not a LoRA.** The host keys the sampler on the
667
+ checkpoint it generates against. A LoRA pick carries its own `baseModel` and
668
+ `versionId`, and a LoRA install's resolved checkpoint can belong to a different
669
+ family, so looking up the LoRA can show the wrong list. The host then swaps a
670
+ sampler from that list for the checkpoint family's default.
671
+ 2. With only `modelVersionId`, it uses the override that lists that version.
672
+ A version with no override needs `baseModel`.
673
+
674
+ An override of `null` means that version has no sampler. It does not fall
675
+ through to the family.
676
+
677
+ 🔴 **Unknown is not "no sampler".** A family the platform could not determine
678
+ is absent from `ecosystems`, never `null`, and the platform maps no base model
679
+ to it. `resolveGenerationSampler` reports that as `{ known: false, reason }`,
680
+ and that arm has no `sampler` property, so TypeScript makes you narrow on
681
+ `known` first. The reasons are:
682
+
683
+ - `base-model-not-in-catalog`: the base model is not in `baseModels`. This is
684
+ what a family the platform could not determine looks like, as well as a base
685
+ model the platform does not map at all.
686
+ - `family-not-in-catalog`: the base model maps to a family missing from
687
+ `ecosystems`. The platform does not send that combination. You get it when
688
+ `parseGenerationSamplers` dropped a family it could not read, or from a
689
+ catalog you built yourself.
690
+ - `base-model-required`: only a version id was given and it has no override.
691
+
692
+ **On a platform without the route**, `fetchGenerationSamplers` throws
693
+ `GenerationSamplersError` with `code: 'unsupported-platform'`, after the host
694
+ answers `404`. It never resolves to an empty catalog, which would read as "no
695
+ family has a sampler". The other codes are:
696
+
697
+ - `unauthorized` (`401`/`403`, a bad or expired block token);
698
+ - `http-error` (any other non-2xx);
699
+ - `invalid-response` (a 2xx that is not the catalog);
700
+ - `network-error` (the fetch itself failed).
701
+
702
+ An abort before the response arrives rejects with the `AbortError`. An abort
703
+ while the body is being read surfaces as `invalid-response`.
704
+
618
705
  ### Version compatibility
619
706
 
620
707
  | `@civitai/app-sdk` | adds (blocks surface) |
621
708
  |---|---|
709
+ | `0.87.0` | `fetchGenerationSamplers` / `resolveGenerationSampler` / `parseGenerationSamplers` / `GenerationSamplersError`: the on-site generator's sampler options per model family (needs a platform that serves `GET /api/v1/blocks/generation-samplers`) |
622
710
  | `0.80.0` | `checkComfyGraph` — pre-spend check that a workflow file can run as an inline `customComfy` graph; `BLOCK_INLINE_COMFY_MAX_NODES` / `BLOCK_INLINE_COMFY_MAX_GRAPH_BYTES` |
623
711
  | `0.57.0` | `fetchNestedDocument` / `NestedDocumentError` — the `srcdoc` escape hatch for embedding your own bundled documents |
624
712
  | `0.27.0` | `@civitai/app-sdk/safe-storage` — opaque-origin `localStorage`/`sessionStorage` shim, auto-installed by the `blocks` subpath |
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Sampler options per model family — the list the on-site generator shows in
3
+ * its sampler drop-down, read from `GET /api/v1/blocks/generation-samplers`.
4
+ *
5
+ * WHY THIS EXISTS. A block's `textToImage` body takes `params.sampler` as a
6
+ * free string, and which names are valid depends on the model family (the SD
7
+ * families, Chroma, Anima's ComfyUI names, a HiDream variant…). A name the
8
+ * family does not offer is not refused: the host replaces it with the family
9
+ * default, so a guessed sampler silently generates with a different one. A
10
+ * list copied into an app drifts. The platform serves the generator's own
11
+ * list instead, derived from the same source the generator renders.
12
+ *
13
+ * WIRE SHAPE (any valid block token; no scope needed):
14
+ *
15
+ * { ecosystems: { [ecosystemKey]: { sampler: { options, default } | null,
16
+ * byModelVersion: { [versionId]: { options, default } | null } } },
17
+ * baseModels: { [baseModelName]: ecosystemKey } }
18
+ *
19
+ * THREE ANSWERS, NEVER TWO. For a given model the catalog says one of:
20
+ * - `{ options, default }` — the family (or this model version) has a sampler
21
+ * control; offer exactly these values.
22
+ * - `null` — the generator shows NO sampler control for it (Flux.1, for one).
23
+ * Send no `sampler`.
24
+ * - absent — the platform could not determine the family, or does not map
25
+ * this base model. That is "unknown", and {@link resolveGenerationSampler}
26
+ * reports it as `known: false` so it can never be read as "no sampler".
27
+ *
28
+ * OLD PLATFORM. A civitai.com that predates the route answers `404`. The getter
29
+ * throws {@link GenerationSamplersError} with `code: 'unsupported-platform'`
30
+ * rather than resolving to an empty catalog, because an empty catalog would
31
+ * read as "no family has a sampler".
32
+ */
33
+ /** The block REST route this module reads. Resolved against the host origin. */
34
+ export declare const GENERATION_SAMPLERS_API_PATH = "/api/v1/blocks/generation-samplers";
35
+ /** One drop-down entry. Send `value` as `params.sampler`; show `label`. */
36
+ export interface GenerationSamplerOption {
37
+ value: string;
38
+ label: string;
39
+ }
40
+ /** A sampler control: its options in the generator's order, plus the value a fresh form preselects. */
41
+ export interface GenerationSamplerField {
42
+ options: GenerationSamplerOption[];
43
+ default: string;
44
+ }
45
+ /** One model family (keyed by ecosystem key in {@link GenerationSamplerCatalog.ecosystems}). */
46
+ export interface GenerationSamplerFamily {
47
+ /** The family's sampler control, or `null` when the generator shows none. */
48
+ sampler: GenerationSamplerField | null;
49
+ /**
50
+ * Per-model-version overrides, keyed by model version id (as a string). A
51
+ * version listed here selects a graph variant whose sampler control differs
52
+ * from the family's; `null` means that version has none. It takes precedence
53
+ * over {@link sampler}.
54
+ */
55
+ byModelVersion: Record<string, GenerationSamplerField | null>;
56
+ }
57
+ /** What {@link fetchGenerationSamplers} resolves to. */
58
+ export interface GenerationSamplerCatalog {
59
+ /** Families by ecosystem key. A family the platform could not determine is ABSENT, never `null`. */
60
+ ecosystems: Record<string, GenerationSamplerFamily>;
61
+ /** Base model name (a checkpoint's `baseModel`) → ecosystem key. Only families present in `ecosystems` are mapped. */
62
+ baseModels: Record<string, string>;
63
+ }
64
+ /** Why {@link fetchGenerationSamplers} failed. */
65
+ export type GenerationSamplersErrorCode =
66
+ /** `404`: this platform does not serve the route yet (or `hostOrigin` is not civitai.com). */
67
+ 'unsupported-platform'
68
+ /** `401`/`403`: the block token is missing, expired or invalid. */
69
+ | 'unauthorized'
70
+ /** Any other non-2xx status. */
71
+ | 'http-error'
72
+ /** A 2xx whose body is not the catalog shape. */
73
+ | 'invalid-response'
74
+ /** The fetch itself failed — offline, DNS, TLS, CORS, no `fetch` global. */
75
+ | 'network-error';
76
+ /** Thrown by {@link fetchGenerationSamplers}. Branch on `code`, not on the message. */
77
+ export declare class GenerationSamplersError extends Error {
78
+ readonly name = "GenerationSamplersError";
79
+ readonly code: GenerationSamplersErrorCode;
80
+ /** HTTP status, when the host answered. */
81
+ readonly status: number | undefined;
82
+ constructor(message: string, options: {
83
+ code: GenerationSamplersErrorCode;
84
+ status?: number | undefined;
85
+ cause?: unknown;
86
+ });
87
+ }
88
+ /** Options for {@link fetchGenerationSamplers}. */
89
+ export interface FetchGenerationSamplersOptions {
90
+ /** The validated host origin, e.g. `useHostOrigin()` from `@civitai/blocks-react`. */
91
+ hostOrigin: string;
92
+ /** The raw block token, e.g. `useBlockToken().raw`. Any valid block token works. */
93
+ token: string;
94
+ /** Abort the request. Rejects with the underlying `AbortError`, not a `GenerationSamplersError`. */
95
+ signal?: AbortSignal;
96
+ /** Override `fetch` (tests, or a runtime without a global one). */
97
+ fetch?: typeof fetch;
98
+ }
99
+ /**
100
+ * Validate a response body into a {@link GenerationSamplerCatalog}. Exported for
101
+ * a caller that does its own fetch (for example through `@civitai/sdk`).
102
+ *
103
+ * A malformed family is DROPPED, so it reads as unknown — the same answer the
104
+ * platform gives for a family it could not determine. Unknown extra fields are
105
+ * ignored. Throws `GenerationSamplersError` (`invalid-response`) only when the
106
+ * body is not the catalog shape at all.
107
+ */
108
+ export declare function parseGenerationSamplers(body: unknown): GenerationSamplerCatalog;
109
+ /**
110
+ * Fetch the per-family sampler catalog with a block token.
111
+ *
112
+ * Throws {@link GenerationSamplersError}; on a platform without the route that
113
+ * is `code: 'unsupported-platform'`, never an empty catalog.
114
+ *
115
+ * @example
116
+ * const catalog = await fetchGenerationSamplers({ hostOrigin, token: raw });
117
+ * // checkpoint: the checkpoint you generate against (a model block's context.checkpoint), never a LoRA.
118
+ * const lookup = resolveGenerationSampler(catalog, { baseModel: checkpoint.baseModel, modelVersionId: checkpoint.versionId });
119
+ */
120
+ export declare function fetchGenerationSamplers(opts: FetchGenerationSamplersOptions): Promise<GenerationSamplerCatalog>;
121
+ /**
122
+ * Which model to look up: the CHECKPOINT you generate against (`BlockCheckpointInfo`, or a
123
+ * Checkpoint pick), never a LoRA. The host keys the sampler on the checkpoint, and a LoRA can
124
+ * belong to a different family.
125
+ */
126
+ export interface GenerationSamplerLookupInput {
127
+ baseModel?: string | null | undefined;
128
+ modelVersionId?: number | null | undefined;
129
+ }
130
+ /** Why {@link resolveGenerationSampler} could not answer. */
131
+ export type GenerationSamplerUnknownReason =
132
+ /** The catalog does not map this base model to a family. */
133
+ 'base-model-not-in-catalog'
134
+ /**
135
+ * The base model maps to a family absent from `ecosystems`. The platform never sends this
136
+ * (it maps no base model to a family it could not determine, so that case is
137
+ * `base-model-not-in-catalog`); it comes from a family the parser dropped, or a hand-built catalog.
138
+ */
139
+ | 'family-not-in-catalog'
140
+ /** Only a model version id was given, and it has no per-version override, so the family is unknown. */
141
+ | 'base-model-required';
142
+ /**
143
+ * What {@link resolveGenerationSampler} returns. Narrow on `known` before
144
+ * reading `sampler`: an unknown result has no `sampler` at all, so it cannot be
145
+ * mistaken for `null` ("this model has no sampler control").
146
+ */
147
+ export type GenerationSamplerLookup = {
148
+ known: true;
149
+ /** The control to render, or `null` when the generator shows none — send no `sampler`. */
150
+ sampler: GenerationSamplerField | null;
151
+ /** The family's ecosystem key. */
152
+ ecosystem: string;
153
+ /** Whether the answer came from a per-version override or the family. */
154
+ source: 'modelVersion' | 'family';
155
+ } | {
156
+ known: false;
157
+ reason: GenerationSamplerUnknownReason;
158
+ };
159
+ /**
160
+ * Look up the sampler control for one model. Precedence:
161
+ *
162
+ * 1. With `baseModel`: its family, then that family's override for
163
+ * `modelVersionId` if it lists one, else the family's control. This matches
164
+ * the host, which picks the graph by the checkpoint's base model.
165
+ * 2. With `modelVersionId` only: the override that lists it, in whichever
166
+ * family. A version with no override needs `baseModel`.
167
+ *
168
+ * An override of `null` means that version has no sampler control; it does not
169
+ * fall through to the family.
170
+ */
171
+ export declare function resolveGenerationSampler(catalog: GenerationSamplerCatalog, input: GenerationSamplerLookupInput): GenerationSamplerLookup;
172
+ //# sourceMappingURL=generationSamplers.d.ts.map
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Sampler options per model family — the list the on-site generator shows in
3
+ * its sampler drop-down, read from `GET /api/v1/blocks/generation-samplers`.
4
+ *
5
+ * WHY THIS EXISTS. A block's `textToImage` body takes `params.sampler` as a
6
+ * free string, and which names are valid depends on the model family (the SD
7
+ * families, Chroma, Anima's ComfyUI names, a HiDream variant…). A name the
8
+ * family does not offer is not refused: the host replaces it with the family
9
+ * default, so a guessed sampler silently generates with a different one. A
10
+ * list copied into an app drifts. The platform serves the generator's own
11
+ * list instead, derived from the same source the generator renders.
12
+ *
13
+ * WIRE SHAPE (any valid block token; no scope needed):
14
+ *
15
+ * { ecosystems: { [ecosystemKey]: { sampler: { options, default } | null,
16
+ * byModelVersion: { [versionId]: { options, default } | null } } },
17
+ * baseModels: { [baseModelName]: ecosystemKey } }
18
+ *
19
+ * THREE ANSWERS, NEVER TWO. For a given model the catalog says one of:
20
+ * - `{ options, default }` — the family (or this model version) has a sampler
21
+ * control; offer exactly these values.
22
+ * - `null` — the generator shows NO sampler control for it (Flux.1, for one).
23
+ * Send no `sampler`.
24
+ * - absent — the platform could not determine the family, or does not map
25
+ * this base model. That is "unknown", and {@link resolveGenerationSampler}
26
+ * reports it as `known: false` so it can never be read as "no sampler".
27
+ *
28
+ * OLD PLATFORM. A civitai.com that predates the route answers `404`. The getter
29
+ * throws {@link GenerationSamplersError} with `code: 'unsupported-platform'`
30
+ * rather than resolving to an empty catalog, because an empty catalog would
31
+ * read as "no family has a sampler".
32
+ */
33
+ /** The block REST route this module reads. Resolved against the host origin. */
34
+ export const GENERATION_SAMPLERS_API_PATH = '/api/v1/blocks/generation-samplers';
35
+ /** Thrown by {@link fetchGenerationSamplers}. Branch on `code`, not on the message. */
36
+ export class GenerationSamplersError extends Error {
37
+ name = 'GenerationSamplersError';
38
+ code;
39
+ /** HTTP status, when the host answered. */
40
+ status;
41
+ constructor(message, options) {
42
+ super(message, { cause: options.cause });
43
+ this.code = options.code;
44
+ this.status = options.status;
45
+ }
46
+ }
47
+ const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
48
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
49
+ /** A dictionary with no prototype, so a key like `constructor` or `__proto__` is just a key. */
50
+ function dict() {
51
+ return Object.create(null);
52
+ }
53
+ /** `undefined` = malformed. `null` is a valid value ("no sampler control"). */
54
+ function parseField(v) {
55
+ if (v === null)
56
+ return null;
57
+ if (!isRecord(v) || !Array.isArray(v.options) || typeof v.default !== 'string')
58
+ return undefined;
59
+ const options = [];
60
+ for (const o of v.options) {
61
+ if (!isRecord(o) || typeof o.value !== 'string' || typeof o.label !== 'string')
62
+ return undefined;
63
+ options.push({ value: o.value, label: o.label });
64
+ }
65
+ return { options, default: v.default };
66
+ }
67
+ function parseFamily(v) {
68
+ if (!isRecord(v) || !isRecord(v.byModelVersion))
69
+ return undefined;
70
+ const sampler = parseField(v.sampler);
71
+ if (sampler === undefined)
72
+ return undefined;
73
+ const byModelVersion = dict();
74
+ for (const [id, raw] of Object.entries(v.byModelVersion)) {
75
+ const field = parseField(raw);
76
+ // One malformed override drops the WHOLE family: keeping the rest would let
77
+ // that version fall through to the family's control, which is the wrong answer.
78
+ if (field === undefined)
79
+ return undefined;
80
+ byModelVersion[id] = field;
81
+ }
82
+ return { sampler, byModelVersion };
83
+ }
84
+ /**
85
+ * Validate a response body into a {@link GenerationSamplerCatalog}. Exported for
86
+ * a caller that does its own fetch (for example through `@civitai/sdk`).
87
+ *
88
+ * A malformed family is DROPPED, so it reads as unknown — the same answer the
89
+ * platform gives for a family it could not determine. Unknown extra fields are
90
+ * ignored. Throws `GenerationSamplersError` (`invalid-response`) only when the
91
+ * body is not the catalog shape at all.
92
+ */
93
+ export function parseGenerationSamplers(body) {
94
+ if (!isRecord(body) || !isRecord(body.ecosystems) || !isRecord(body.baseModels)) {
95
+ throw new GenerationSamplersError('generation-samplers: the response is not { ecosystems, baseModels }.', { code: 'invalid-response' });
96
+ }
97
+ const ecosystems = dict();
98
+ for (const [key, raw] of Object.entries(body.ecosystems)) {
99
+ const family = parseFamily(raw);
100
+ if (family)
101
+ ecosystems[key] = family;
102
+ }
103
+ const baseModels = dict();
104
+ for (const [name, key] of Object.entries(body.baseModels)) {
105
+ if (typeof key === 'string')
106
+ baseModels[name] = key;
107
+ }
108
+ return { ecosystems, baseModels };
109
+ }
110
+ /**
111
+ * Fetch the per-family sampler catalog with a block token.
112
+ *
113
+ * Throws {@link GenerationSamplersError}; on a platform without the route that
114
+ * is `code: 'unsupported-platform'`, never an empty catalog.
115
+ *
116
+ * @example
117
+ * const catalog = await fetchGenerationSamplers({ hostOrigin, token: raw });
118
+ * // checkpoint: the checkpoint you generate against (a model block's context.checkpoint), never a LoRA.
119
+ * const lookup = resolveGenerationSampler(catalog, { baseModel: checkpoint.baseModel, modelVersionId: checkpoint.versionId });
120
+ */
121
+ export async function fetchGenerationSamplers(opts) {
122
+ const doFetch = opts.fetch ?? (typeof fetch === 'function' ? fetch : undefined);
123
+ if (!doFetch) {
124
+ throw new GenerationSamplersError('generation-samplers: no fetch implementation available.', {
125
+ code: 'network-error',
126
+ });
127
+ }
128
+ if (!opts.hostOrigin) {
129
+ throw new TypeError('fetchGenerationSamplers: hostOrigin is required (wait for BLOCK_INIT).');
130
+ }
131
+ const url = new URL(GENERATION_SAMPLERS_API_PATH, opts.hostOrigin).toString();
132
+ let res;
133
+ try {
134
+ res = await doFetch(url, {
135
+ headers: { Authorization: `Bearer ${opts.token}` },
136
+ ...(opts.signal ? { signal: opts.signal } : {}),
137
+ });
138
+ }
139
+ catch (err) {
140
+ if (opts.signal?.aborted)
141
+ throw err;
142
+ throw new GenerationSamplersError('generation-samplers: the request failed before a response.', {
143
+ code: 'network-error',
144
+ cause: err,
145
+ });
146
+ }
147
+ if (res.status === 404) {
148
+ throw new GenerationSamplersError(`generation-samplers: ${url} answered 404. This Civitai platform does not serve the ` +
149
+ 'sampler catalog yet (or hostOrigin is not the Civitai host). Treat samplers as unknown; ' +
150
+ 'do not read this as "no samplers".', { code: 'unsupported-platform', status: 404 });
151
+ }
152
+ if (res.status === 401 || res.status === 403) {
153
+ throw new GenerationSamplersError(`generation-samplers: ${res.status} — the block token is missing, expired or invalid.`, { code: 'unauthorized', status: res.status });
154
+ }
155
+ if (!res.ok) {
156
+ throw new GenerationSamplersError(`generation-samplers: HTTP ${res.status}.`, {
157
+ code: 'http-error',
158
+ status: res.status,
159
+ });
160
+ }
161
+ let body;
162
+ try {
163
+ body = await res.json();
164
+ }
165
+ catch (err) {
166
+ throw new GenerationSamplersError('generation-samplers: the response is not JSON.', {
167
+ code: 'invalid-response',
168
+ status: res.status,
169
+ cause: err,
170
+ });
171
+ }
172
+ return parseGenerationSamplers(body);
173
+ }
174
+ /**
175
+ * Look up the sampler control for one model. Precedence:
176
+ *
177
+ * 1. With `baseModel`: its family, then that family's override for
178
+ * `modelVersionId` if it lists one, else the family's control. This matches
179
+ * the host, which picks the graph by the checkpoint's base model.
180
+ * 2. With `modelVersionId` only: the override that lists it, in whichever
181
+ * family. A version with no override needs `baseModel`.
182
+ *
183
+ * An override of `null` means that version has no sampler control; it does not
184
+ * fall through to the family.
185
+ */
186
+ export function resolveGenerationSampler(catalog, input) {
187
+ const versionKey = input.modelVersionId == null ? undefined : String(input.modelVersionId);
188
+ if (input.baseModel != null) {
189
+ if (!hasOwn(catalog.baseModels, input.baseModel)) {
190
+ return { known: false, reason: 'base-model-not-in-catalog' };
191
+ }
192
+ const ecosystem = catalog.baseModels[input.baseModel];
193
+ if (!hasOwn(catalog.ecosystems, ecosystem)) {
194
+ return { known: false, reason: 'family-not-in-catalog' };
195
+ }
196
+ const family = catalog.ecosystems[ecosystem];
197
+ if (versionKey !== undefined && hasOwn(family.byModelVersion, versionKey)) {
198
+ return { known: true, sampler: family.byModelVersion[versionKey], ecosystem, source: 'modelVersion' };
199
+ }
200
+ return { known: true, sampler: family.sampler, ecosystem, source: 'family' };
201
+ }
202
+ if (versionKey !== undefined) {
203
+ for (const [ecosystem, family] of Object.entries(catalog.ecosystems)) {
204
+ if (hasOwn(family.byModelVersion, versionKey)) {
205
+ return { known: true, sampler: family.byModelVersion[versionKey], ecosystem, source: 'modelVersion' };
206
+ }
207
+ }
208
+ }
209
+ return { known: false, reason: 'base-model-required' };
210
+ }
211
+ //# sourceMappingURL=generationSamplers.js.map
@@ -129,6 +129,14 @@ export { BLOCK_INLINE_COMFY_MAX_NODES, BLOCK_INLINE_COMFY_MAX_GRAPH_BYTES } from
129
129
  */
130
130
  export { checkComfyGraph } from './comfyGraph.js';
131
131
  export type { ComfyGraphCheck, ComfyGraphRefusal, ComfyModelFilenameInput } from './comfyGraph.js';
132
+ /**
133
+ * Sampler options per model family, from the platform's own generator source
134
+ * (`GET /api/v1/blocks/generation-samplers`). An unknown family is reported as
135
+ * unknown, never as "no sampler"; a platform without the route throws
136
+ * `unsupported-platform`.
137
+ */
138
+ export { GENERATION_SAMPLERS_API_PATH, GenerationSamplersError, fetchGenerationSamplers, parseGenerationSamplers, resolveGenerationSampler, } from './generationSamplers.js';
139
+ export type { FetchGenerationSamplersOptions, GenerationSamplerCatalog, GenerationSamplerFamily, GenerationSamplerField, GenerationSamplerLookup, GenerationSamplerLookupInput, GenerationSamplerOption, GenerationSamplersErrorCode, GenerationSamplerUnknownReason, } from './generationSamplers.js';
132
140
  /** Host bound for the App Blocks `kind: 'workflow'` body — see `WorkflowBodyWorkflow`. */
133
141
  export { BLOCK_WORKFLOW_MAX_STEPS, BLOCK_WORKFLOW_REPEAT_MAX_ITERATIONS } from './types.js';
134
142
  /**
@@ -125,6 +125,13 @@ export { BLOCK_INLINE_COMFY_MAX_NODES, BLOCK_INLINE_COMFY_MAX_GRAPH_BYTES } from
125
125
  * A Comfy estimate is a ceiling, never a price.
126
126
  */
127
127
  export { checkComfyGraph } from './comfyGraph.js';
128
+ /**
129
+ * Sampler options per model family, from the platform's own generator source
130
+ * (`GET /api/v1/blocks/generation-samplers`). An unknown family is reported as
131
+ * unknown, never as "no sampler"; a platform without the route throws
132
+ * `unsupported-platform`.
133
+ */
134
+ export { GENERATION_SAMPLERS_API_PATH, GenerationSamplersError, fetchGenerationSamplers, parseGenerationSamplers, resolveGenerationSampler, } from './generationSamplers.js';
128
135
  /** Host bound for the App Blocks `kind: 'workflow'` body — see `WorkflowBodyWorkflow`. */
129
136
  export { BLOCK_WORKFLOW_MAX_STEPS, BLOCK_WORKFLOW_REPEAT_MAX_ITERATIONS } from './types.js';
130
137
  /**
@@ -2032,6 +2032,23 @@ export interface BlockWorkflowSnapshot {
2032
2032
  * error, errorCode }` with NO `cost`. A host that predates these codes
2033
2033
  * resolves the estimate instead, priced at the step's declared estimate, so
2034
2034
  * there a registered-step estimate may not be a quote.
2035
+ * - `'source-scan-pending'` — a `kind: 'step'` or `kind: 'workflow'` input,
2036
+ * or an inline `customComfy` graph, names an image the viewer uploaded
2037
+ * whose scan has not finished. `error` reads `that image is still being
2038
+ * scanned — wait for it to finish before using it`. Estimate and submit
2039
+ * alike, before anything is reserved. Retry the same body once the
2040
+ * upload's scan verdict is `'scanned'`.
2041
+ * - `'inline-node-refused'` — an inline `customComfy` graph uses a node the
2042
+ * host does not run inline: one that reads or writes a file path, or a
2043
+ * loader whose input comes from another node, is an object, is a URL the
2044
+ * host does not fetch, or names a local file. `error` lists each node.
2045
+ * Estimate and submit alike, before anything is reserved. Change the
2046
+ * graph; `checkComfyGraph` does not detect this one.
2047
+ * - `'not-api-format'` / `'model-filenames'` — an inline `customComfy` graph
2048
+ * that is not ComfyUI API format, or whose loader names a model by
2049
+ * filename instead of an AIR. These are `checkComfyGraph`'s own codes, so
2050
+ * an app can catch them before sending. Estimate and submit alike, before
2051
+ * anything is reserved.
2035
2052
  *
2036
2053
  * 🔴 AN UNKNOWN VALUE IS POSSIBLE: the host may add codes, and the SDK's
2037
2054
  * inbound validator accepts any string here. Handle an unrecognised code as a
@@ -2460,7 +2477,25 @@ export type KnownBlockWorkflowErrorCode = 'training-quote-rejected' | 'training-
2460
2477
  * finished. Retry once the upload's scan verdict is `scanned` (with
2461
2478
  * `asyncScan`, wait for it before submitting).
2462
2479
  */
2463
- | 'source-scan-pending';
2480
+ | 'source-scan-pending'
2481
+ /**
2482
+ * An inline `customComfy` graph uses a node the host does not run inline: one
2483
+ * that reads or writes a file path, or a loader whose input is not a literal
2484
+ * value the host can check. `checkComfyGraph` does not detect this; change
2485
+ * the graph.
2486
+ */
2487
+ | 'inline-node-refused'
2488
+ /**
2489
+ * An inline `customComfy` graph is not ComfyUI API format. The same code
2490
+ * `checkComfyGraph` reports; re-export the graph in API format.
2491
+ */
2492
+ | 'not-api-format'
2493
+ /**
2494
+ * An inline `customComfy` graph's loader names a model by filename instead of
2495
+ * an AIR. The same code `checkComfyGraph` reports; use AIRs declared in
2496
+ * `resources`.
2497
+ */
2498
+ | 'model-filenames';
2464
2499
  /** One entry of {@link BlockWorkflowSnapshot.modelSubstitutions}. */
2465
2500
  export interface BlockModelSubstitution {
2466
2501
  /** The checkpoint version id the block asked for. */
package/dist/index.d.ts CHANGED
@@ -25,11 +25,11 @@
25
25
  *
26
26
  * - **`./blocks`** — importing it RUNS `./safe-storage` for its side effect
27
27
  * (repairing `localStorage`/`sessionStorage` at an opaque origin). Folding
28
- * 214 symbols and that side effect into the root would make every OAuth app
28
+ * 228 symbols and that side effect into the root would make every OAuth app
29
29
  * that writes `import { exchangeCode } from '@civitai/app-sdk'` pay for the
30
30
  * Civitai-Apps contract it does not use. Blocks and OAuth apps are disjoint
31
31
  * audiences; see this package's README.
32
- * 🔴 That 214 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 228 is ASSERTED, not merely quoted — by
33
33
  * `packages/civitai-app-sdk/test/export-surface.test.ts`, which pins
34
34
  * `surface.get('./blocks').size`. It said 119 here against a real 125 until
35
35
  * 2026-10-04, because the existing checks pin the root as an exact union and
package/dist/index.js CHANGED
@@ -25,11 +25,11 @@
25
25
  *
26
26
  * - **`./blocks`** — importing it RUNS `./safe-storage` for its side effect
27
27
  * (repairing `localStorage`/`sessionStorage` at an opaque origin). Folding
28
- * 214 symbols and that side effect into the root would make every OAuth app
28
+ * 228 symbols and that side effect into the root would make every OAuth app
29
29
  * that writes `import { exchangeCode } from '@civitai/app-sdk'` pay for the
30
30
  * Civitai-Apps contract it does not use. Blocks and OAuth apps are disjoint
31
31
  * audiences; see this package's README.
32
- * 🔴 That 214 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 228 is ASSERTED, not merely quoted — by
33
33
  * `packages/civitai-app-sdk/test/export-surface.test.ts`, which pins
34
34
  * `surface.get('./blocks').size`. It said 119 here against a real 125 until
35
35
  * 2026-10-04, because the existing checks pin the root as an exact union and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/app-sdk",
3
- "version": "0.86.0",
3
+ "version": "0.87.0",
4
4
  "description": "OAuth + PKCE, encrypted-cookie sessions, scopes, and orchestrator helpers for building third-party Civitai apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",