@civitai/blocks-react 0.67.0 → 0.68.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.
@@ -93,6 +93,23 @@ export interface MockGenerationScenario {
93
93
  * a `(body) => number`. Overrides the legacy top-level `cost`. Default `8`.
94
94
  */
95
95
  costPerGen?: CostSpec;
96
+ /**
97
+ * The app author's per-generation fee, itemised as `cost.authorFee` on a
98
+ * QUOTE — the `ESTIMATE_RESULT` and the {@link submitCapRefusal} reply — and
99
+ * added into that quote's `cost.total` on top of {@link costPerGen}, as the
100
+ * real host does. A number, or a `(body) => number`. Default `0`, which is
101
+ * reported as `authorFee: 0` ("no fee on this request").
102
+ *
103
+ * Like the real host, only a `textToImage` or registered-`step` body is
104
+ * itemised; `customComfy`, pass-through `step` and `training` quotes carry no
105
+ * `authorFee`. The succeeded snapshot's `cost.total` stays {@link costPerGen}
106
+ * (a submitted workflow reports the generation's own cost), while a simulated
107
+ * {@link MockBuzzScenario.balance} is debited `costPerGen + authorFee`.
108
+ *
109
+ * `false` simulates a host that PREDATES the field: `authorFee` is omitted
110
+ * everywhere and no fee is added — use it to test your "not itemised" branch.
111
+ */
112
+ authorFee?: CostSpec | false;
96
113
  /**
97
114
  * Synthetic latency before the SUBMITTED→succeeded transition lands, in ms.
98
115
  * A single number, or a `[min, max]` range (uniform random). Applied to the
@@ -149,6 +166,35 @@ export interface MockGenerationScenario {
149
166
  * resource-compatibility rejection) to check how your block renders one.
150
167
  */
151
168
  failEstimateMessage?: string;
169
+ /**
170
+ * How the mock answers `ESTIMATE_WORKFLOW_BATCH` (`useBatchEstimate()`), so a
171
+ * block can exercise its per-cell fallback locally.
172
+ *
173
+ * - `'supported'` (default) — prices each cell exactly as an
174
+ * `ESTIMATE_WORKFLOW` of that body would be priced (`costPerGen`,
175
+ * `failEstimate` and the training rules all apply per cell) and replies with
176
+ * the snapshots in order plus the host's aggregate.
177
+ * - `'unsupported'` — replies `{ error: 'unsupported on this host' }`, the
178
+ * host's generic answer for a message it has no handler for.
179
+ * `estimateBatch()` rejects with `BatchEstimateError` code `'unsupported'`.
180
+ * - `'silent'` — never replies, which is what a host that PREDATES the message
181
+ * does. `estimateBatch()` rejects with code `'timeout'` once its wait ends;
182
+ * pass a short `timeoutMs` to it in a test.
183
+ *
184
+ * Live-tunable via `setScenario({ generation: { batchEstimate } })`.
185
+ */
186
+ batchEstimate?: 'supported' | 'unsupported' | 'silent';
187
+ /**
188
+ * Indices of batch cells the mock answers as NOT PRICED IN TIME — the snapshot
189
+ * the host returns for a cell when the call's time budget runs out before that
190
+ * cell priced: `{ workflowId:'failed', status:'failed', error:'estimate timed out' }`
191
+ * (the host's string, held once in `BATCH_ESTIMATE_CELL_TIMEOUT_ERROR`).
192
+ * The other cells price normally and the call still resolves, so this tests a
193
+ * PARTIAL grid: the cell is `ok: false`, `timedOut: true`, with
194
+ * `WorkflowEstimateError` code `'failed'`. Applies only with
195
+ * `batchEstimate: 'supported'`. Default: unset (no cell times out).
196
+ */
197
+ batchEstimateTimedOutCells?: number[];
152
198
  /**
153
199
  * Force every SUBMIT to come back as a caught server EXCEPTION — the host's
154
200
  * real `failureSnapshot(err)` shape: `{ workflowId:'failed', status:'failed',
@@ -424,6 +470,27 @@ export interface MockSharedScenario {
424
470
  * error UX.
425
471
  */
426
472
  failNext?: number;
473
+ /**
474
+ * Refuse the next N shared WRITES (`append`/`update`/`vote`/`unvote`/
475
+ * `withdraw`/`report`) as RATE-LIMITED (counts down), the way the platform
476
+ * does when a per-(viewer, app) budget is empty: the reply carries the
477
+ * server's refusal text plus `rateLimit` metadata, so the hook rejects with
478
+ * `SharedStorageRateLimitError`. Checked before {@link failNext}, as the
479
+ * server checks the budget before attempting the write. Live-tunable via
480
+ * `setScenario({ shared: { rateLimitNext } })`.
481
+ */
482
+ rateLimitNext?: number;
483
+ /**
484
+ * The metadata a {@link rateLimitNext} refusal carries. `retryAfterSeconds`
485
+ * defaults to 60; `retryAt` defaults to now + `retryAfterSeconds`, computed
486
+ * when each refusal is sent. Pass a malformed value to exercise a block's
487
+ * fallback: the hook parses it, ignores the malformed value and throws a plain
488
+ * `Error`.
489
+ */
490
+ rateLimit?: {
491
+ retryAfterSeconds?: number;
492
+ retryAt?: string;
493
+ };
427
494
  }
428
495
  /**
429
496
  * Drives `createMockHost`. Every field is optional with a sensible default so
@@ -477,6 +544,18 @@ export interface MockHostOptions {
477
544
  * for that type. Defaults to a curated Checkpoint + LoRA pick.
478
545
  */
479
546
  cannedPicks?: Partial<Record<BlockResourcePickerType, CannedPick | null>>;
547
+ /**
548
+ * What a MULTI-select `OPEN_RESOURCE_PICKER` (`multiple: { max }`, LoRA only)
549
+ * answers with: these picks, in this order, cut to the request's `max` (itself
550
+ * clamped to 5) — the real host's `selectedResources`. `null` or `[]`
551
+ * simulates a dismissed picker (→ an empty list). Defaults to two curated
552
+ * LoRAs, or to `[]` when `cannedPicks.LORA` is `null`, so one "the viewer
553
+ * dismissed" setting covers both pick modes.
554
+ *
555
+ * The mock applies the real host's refusals too: `multiple` with a Checkpoint,
556
+ * or a `max` that is not a whole number ≥ 1, is answered with an `error`.
557
+ */
558
+ cannedMultiPicks?: CannedPick[] | null;
480
559
  /**
481
560
  * The canned moderated image returned from `OPEN_IMAGE_UPLOAD` when the block
482
561
  * requests `purpose:'display'` (the default) — what `useImageUpload().open()`
@@ -1054,7 +1133,7 @@ export interface MockHostOptions {
1054
1133
  * {@link MockHost.setTheme}, which pushes a real `THEME_CHANGE` — the mock of
1055
1134
  * the viewer toggling dark mode with the block already mounted.)
1056
1135
  */
1057
- export type MockHostScenarioPatch = Pick<MockHostOptions, 'consentGrantable' | 'failMode' | 'cost' | 'pollsUntilDone' | 'cannedPicks' | 'cannedImageUpload' | 'cannedGenerationSourceUpload' | 'cannedImageScan' | 'generation' | 'buzz' | 'storage' | 'shared' | 'buzzBalanceError' | 'viewerResult' | 'viewerError' | 'buzzTransactions' | 'buzzAccounts' | 'dailyCompensation' | 'buzzReadError' | 'wildcardPack' | 'wildcardPackError' | 'collectionFollowError' | 'createPostResult' | 'createPostError' | 'trainingDatasetRejected' | 'trainingDatasetError' | 'trainingQuoteTotal' | 'runTrainingError' | 'runTrainingCapRefusal' | 'appWorkflows' | 'appWorkflowsError' | 'publishImageIds' | 'publishError' | 'gatedImages' | 'gatedImagesError' | 'disallowedAccountTypes' | 'saveImageError' | 'uploadImageBytesResult' | 'uploadImageBytesError'>;
1136
+ export type MockHostScenarioPatch = Pick<MockHostOptions, 'consentGrantable' | 'failMode' | 'cost' | 'pollsUntilDone' | 'cannedPicks' | 'cannedMultiPicks' | 'cannedImageUpload' | 'cannedGenerationSourceUpload' | 'cannedImageScan' | 'generation' | 'buzz' | 'storage' | 'shared' | 'buzzBalanceError' | 'viewerResult' | 'viewerError' | 'buzzTransactions' | 'buzzAccounts' | 'dailyCompensation' | 'buzzReadError' | 'wildcardPack' | 'wildcardPackError' | 'collectionFollowError' | 'createPostResult' | 'createPostError' | 'trainingDatasetRejected' | 'trainingDatasetError' | 'trainingQuoteTotal' | 'runTrainingError' | 'runTrainingCapRefusal' | 'appWorkflows' | 'appWorkflowsError' | 'publishImageIds' | 'publishError' | 'gatedImages' | 'gatedImagesError' | 'disallowedAccountTypes' | 'saveImageError' | 'uploadImageBytesResult' | 'uploadImageBytesError'>;
1058
1137
  /** Runtime Buzz-balance handle exposed on {@link MockHost.buzz}. */
1059
1138
  export interface MockBuzzHandle {
1060
1139
  /** Current simulated balance, or `undefined` when balance isn't simulated. */
@@ -1099,7 +1178,7 @@ export declare function disallowedAccountError(accountType: BuzzAccountType): st
1099
1178
  /**
1100
1179
  * Reads the URL query toggles the gen-matrix dev harness uses, so a starter's
1101
1180
  * dev harness keeps working with `?viewer/?consent/?fail/?theme/?pick/?pickCkpt`.
1102
- * Layer-1 additions: `?balance/?latency/?costPerGen/?failNext/?failRate/?seed`
1181
+ * Layer-1 additions: `?balance/?latency/?costPerGen/?authorFee/?failNext/?failRate/?seed`
1103
1182
  * map onto the new scenario groups so a dev can flip out-of-Buzz /
1104
1183
  * failures / latency without editing code. `?capRefusal=1` (or `=<text>`) sets
1105
1184
  * {@link MockGenerationScenario.submitCapRefusal}.