@civitai/app-sdk 0.87.0 → 0.88.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.
@@ -305,6 +305,38 @@ export type BlockNavigateScope = 'app' | 'site';
305
305
  * lockstep.
306
306
  */
307
307
  export type BlockGenerationSourceImageInfo = BlockSourceImage;
308
+ /**
309
+ * What a block sends in `PERSIST_GENERATION_SOURCE`: ONE output of one of the
310
+ * calling app's OWN workflows, named by `workflowId` and `imageIndex` (an index
311
+ * into that workflow's `images`, as seen via `QUERY_APP_WORKFLOWS` /
312
+ * `useAppWorkflows()`). Never a url: the host resolves the output server-side
313
+ * from the ownership-verified workflow.
314
+ */
315
+ export interface BlockPersistGenerationSourceRequest {
316
+ workflowId: string;
317
+ imageIndex: number;
318
+ }
319
+ /**
320
+ * What the host returns from `PERSIST_GENERATION_SOURCE`
321
+ * (`GENERATION_SOURCE_PERSISTED.result`): the app's own output, saved as a
322
+ * PRIVATE, scanned generation source.
323
+ *
324
+ * `url` / `width` / `height` are a {@link BlockGenerationSourceImageInfo}, so
325
+ * the value (or that subset of it) goes straight into a `sourceImages` entry,
326
+ * or anywhere else a generation source is accepted.
327
+ *
328
+ * - The image is private to the viewer and is NOT on the app's shared grid.
329
+ * The host shows no confirm.
330
+ * - `imageId` is the persisted `Image` row id.
331
+ * - `ready` says whether the scan finished. The host waits up to about 30 s for
332
+ * it. `ready: false` means the scan is still running: a generation that uses
333
+ * the source is refused with the `source-scan-pending` error code until it
334
+ * finishes, so retry that generation later.
335
+ */
336
+ export interface BlockPersistedGenerationSource extends BlockGenerationSourceImageInfo {
337
+ imageId: number;
338
+ ready: boolean;
339
+ }
308
340
  /**
309
341
  * One image an `OPEN_IMAGE_UPLOAD { purpose: 'trainingData' }` uploaded — an
310
342
  * element of {@link BlockTrainingDataUploadResult.images}. Mirrors the host's
@@ -452,6 +484,28 @@ export interface BlockMediaUploadInfo {
452
484
  /** Duration in milliseconds, for `'video'` / `'audio'` when known. Never set for `'image'`. */
453
485
  durationMs?: number;
454
486
  }
487
+ /**
488
+ * One item's answer in a batch media upload (`MEDIA_UPLOAD_BATCH_RESULT.results`,
489
+ * via `useMediaUpload().uploadBatch`). The host answers EXACTLY ONE entry per
490
+ * item, in item order, and `index` is that item's position in the request.
491
+ *
492
+ * Exactly one of `selected` and `error` is set:
493
+ * - `selected`: the item was uploaded, the same {@link BlockMediaUploadInfo}
494
+ * `MEDIA_UPLOAD_RESULT.selected` carries;
495
+ * - `error`: the item was refused (the same per-file strings as a single
496
+ * bytes upload: too large, wrong type, `mimeType` mismatch, invalid) or its
497
+ * upload failed (`this image was refused by the upload service`,
498
+ * `media upload failed — please try again`, …). The other items are not
499
+ * affected.
500
+ */
501
+ export interface BlockMediaUploadBatchItemResult {
502
+ /** The item's position in the request's `items`. */
503
+ index: number;
504
+ /** The uploaded file. Never set beside `error`. */
505
+ selected?: BlockMediaUploadInfo;
506
+ /** Why this item was not uploaded. Never set beside `selected`. */
507
+ error?: string;
508
+ }
455
509
  /**
456
510
  * One of the model version's curated preview images, with the standard
457
511
  * gen params extracted from its source meta. Block UIs use these to let
@@ -920,9 +974,8 @@ export type WorkflowBodyTextToImage = {
920
974
  /**
921
975
  * Optional shared-storage key of the published content this generation runs on
922
976
  * behalf of. The server resolves it to the content's author for attribution
923
- * (see the G5 civitai PR). Opaque string — the block passes back the `key` it
924
- * got from `useSharedStorage()` for the content being generated against; omit
925
- * when not applicable.
977
+ * (see the G5 civitai PR). Opaque string — the block passes back the `key` of
978
+ * the shared entry the generation runs against; omit when not applicable.
926
979
  */
927
980
  sharedContentKey?: string;
928
981
  /**
@@ -1292,6 +1345,27 @@ export type WorkflowBodyStep = {
1292
1345
  * package would drift against it silently.
1293
1346
  */
1294
1347
  params: Record<string, unknown>;
1348
+ /**
1349
+ * Optional Buzz pool to try FIRST for this job. The host puts it at the front of
1350
+ * the pools this app may spend and keeps the others as fallback, so a job the
1351
+ * picked pool cannot cover alone still runs (an SFW app may spend `blue` and
1352
+ * `green`; a mature app `blue` and `yellow`). Omit it for the host's default
1353
+ * order, blue first.
1354
+ *
1355
+ * A pick outside the app's allowed pools is REFUSED, with an error naming the
1356
+ * pool, on the estimate and the submit alike, before anything is priced or
1357
+ * reserved. Estimate with the same pick you submit with: the estimate prices
1358
+ * that order.
1359
+ *
1360
+ * 🔴 It does NOT guarantee an unrestricted output. When the picked pool runs
1361
+ * out the fallback pays, and a fallback to `blue` can still leave a mature
1362
+ * output restricted.
1363
+ *
1364
+ * Top-level, NOT inside `params` — a pool is not a step parameter, and the
1365
+ * step's own `.strict()` param schema would refuse it there. A host predating
1366
+ * this field refuses it as an unknown key.
1367
+ */
1368
+ accountType?: BuzzAccountType;
1295
1369
  };
1296
1370
  /**
1297
1371
  * The PASS-THROUGH ARM of the `kind: 'step'` member — the block names an
@@ -1455,6 +1529,28 @@ export type WorkflowBodyPassThroughStep = {
1455
1529
  * (`quoteId` itself is excluded from that comparison).
1456
1530
  */
1457
1531
  quoteId?: string;
1532
+ /**
1533
+ * Optional Buzz pool to try FIRST for this job. The host puts it at the front of
1534
+ * the pools this app may spend and keeps the others as fallback, so a job the
1535
+ * picked pool cannot cover alone still runs (an SFW app may spend `blue` and
1536
+ * `green`; a mature app `blue` and `yellow`). Omit it for the host's default
1537
+ * order, blue first.
1538
+ *
1539
+ * A pick outside the app's allowed pools is REFUSED, with an error naming the
1540
+ * pool, on the estimate and the submit alike, before anything is priced or
1541
+ * reserved. Estimate with the same pick you submit with: the estimate prices
1542
+ * that order.
1543
+ *
1544
+ * 🔴 It does NOT guarantee an unrestricted output. When the picked pool runs
1545
+ * out the fallback pays, and a fallback to `blue` can still leave a mature
1546
+ * output restricted.
1547
+ *
1548
+ * Never forwarded into {@link input}. On a CONFIRMED run it is part of the
1549
+ * body the quote is bound to: submit with the pool you estimated with, or the
1550
+ * run is refused as a changed body. A host predating this field refuses it as
1551
+ * an unknown key.
1552
+ */
1553
+ accountType?: BuzzAccountType;
1458
1554
  };
1459
1555
  /**
1460
1556
  * Ceiling on what ONE viewer-confirmed pass-through job may cost, in Buzz. Host
@@ -1667,6 +1763,28 @@ export type WorkflowBodyWorkflow = {
1667
1763
  * place to put a prompt or a seed that several steps share.
1668
1764
  */
1669
1765
  arguments?: Record<string, unknown>;
1766
+ /**
1767
+ * Optional Buzz pool to try FIRST for this job. The host puts it at the front of
1768
+ * the pools this app may spend and keeps the others as fallback, so a job the
1769
+ * picked pool cannot cover alone still runs (an SFW app may spend `blue` and
1770
+ * `green`; a mature app `blue` and `yellow`). Omit it for the host's default
1771
+ * order, blue first.
1772
+ *
1773
+ * A pick outside the app's allowed pools is REFUSED, with an error naming the
1774
+ * pool, on the estimate and the submit alike, before anything is priced or
1775
+ * reserved. Estimate with the same pick you submit with: the estimate prices
1776
+ * that order.
1777
+ *
1778
+ * 🔴 It does NOT guarantee an unrestricted output. When the picked pool runs
1779
+ * out the fallback pays, and a fallback to `blue` can still leave a mature
1780
+ * output restricted.
1781
+ *
1782
+ * ONE pick for the whole workflow, not per step: the orchestrator takes a
1783
+ * single list of pools per workflow, so a step cannot name its own (a step
1784
+ * carrying `accountType` is refused). A host predating this field refuses it
1785
+ * as an unknown key.
1786
+ */
1787
+ accountType?: BuzzAccountType;
1670
1788
  };
1671
1789
  /** Ceiling on what ONE confirmed `kind: 'training'` run may cost, in Buzz. Host constant `BLOCK_TRAINING_MAX_BUZZ_PER_RUN`. */
1672
1790
  export declare const BLOCK_TRAINING_MAX_BUZZ_PER_RUN = 5000;
@@ -2032,9 +2150,10 @@ export interface BlockWorkflowSnapshot {
2032
2150
  * error, errorCode }` with NO `cost`. A host that predates these codes
2033
2151
  * resolves the estimate instead, priced at the step's declared estimate, so
2034
2152
  * 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
2153
+ * - `'source-scan-pending'` — a `kind: 'textToImage'` source image, a
2154
+ * `kind: 'step'` or `kind: 'workflow'` input, or an inline `customComfy`
2155
+ * graph, names an image the viewer uploaded (or a source kept with
2156
+ * `PERSIST_GENERATION_SOURCE`) whose scan has not finished. `error` reads `that image is still being
2038
2157
  * scanned — wait for it to finish before using it`. Estimate and submit
2039
2158
  * alike, before anything is reserved. Retry the same body once the
2040
2159
  * upload's scan verdict is `'scanned'`.
@@ -2355,6 +2474,73 @@ export interface BlockWorkflowSnapshot {
2355
2474
  * an estimate (which creates no workflow) and on a host that predates it.
2356
2475
  */
2357
2476
  steps?: BlockWorkflowStepSnapshot[];
2477
+ /**
2478
+ * Where the run is right now: a summary of the ONE step that is queued or
2479
+ * running, for a progress bar or an "N ahead, starts ~HH:MM" line. The host
2480
+ * reads it off ALL of the workflow's orchestrator steps, so a single-step kind
2481
+ * (`textToImage`, `step`, `customComfy`, `training`) has one too, not only a
2482
+ * `kind: 'workflow'` run. It picks the first step with a queue position, else
2483
+ * the first `processing` step. See {@link BlockWorkflowEta} for each field.
2484
+ *
2485
+ * - **An object** while the workflow is not terminal and a step is queued or
2486
+ * running.
2487
+ * - **ABSENT OR `null` — READ THEM THE SAME.** The host OMITS the field when
2488
+ * it has nothing to report rather than sending `null`. That covers:
2489
+ * - a terminal workflow (`succeeded`, `failed`, `expired`, `canceled`);
2490
+ * - a workflow with no step queued or running;
2491
+ * - a host that predates the field;
2492
+ * - a rate-limited poll the host could not serve. That reply carries
2493
+ * {@link BlockWorkflowSnapshot.throttled}, and `watch` drops it rather
2494
+ * than passing it to `onUpdate`, so an app on `watch` never sees its
2495
+ * missing `eta`.
2496
+ *
2497
+ * 🔴 THE QUEUE POSITION DOES NOT MOVE ON ITS OWN BETWEEN STATUS CHANGES. A held
2498
+ * poll (`watch`) returns early when the workflow's status, a step's progress or
2499
+ * a job event changes, NOT when the queue ahead of a waiting step drains. So
2500
+ * while a step is queued, `queuedAhead` and its estimates refresh at most once
2501
+ * per held poll (about every 15 s). Once the step runs, `progress` moves
2502
+ * promptly.
2503
+ *
2504
+ * Every value in it is an ESTIMATE from the orchestrator's scheduler. Do not
2505
+ * gate on it; `status` is still the only thing that says the run is done.
2506
+ *
2507
+ * ```tsx
2508
+ * await watch(workflowId, {
2509
+ * onUpdate: (s) => {
2510
+ * const eta = s.eta;
2511
+ * if (!eta) return; // absent: keep the last line (watch resolves when terminal)
2512
+ * if (eta.progress !== null) return setBar(eta.progress); // running
2513
+ * const at = eta.startsAt ? new Date(eta.startsAt) : null;
2514
+ * setLine(
2515
+ * `${eta.queuedAhead ?? '?'} ahead` +
2516
+ * (at ? `, starts ~${at.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}` : ''),
2517
+ * );
2518
+ * },
2519
+ * });
2520
+ * ```
2521
+ *
2522
+ * 🔴 A MALFORMED VALUE IS DROPPED, NOT FATAL. `@civitai/blocks-react` removes
2523
+ * an `eta` that does not have this shape (and likewise a malformed `queue`,
2524
+ * `progress`, `startedAt` or `completedAt` on a step) and delivers the rest of
2525
+ * the snapshot, so a bad estimate never costs an app its status or outputs.
2526
+ */
2527
+ eta?: BlockWorkflowEta | null;
2528
+ /**
2529
+ * A poll the host could not serve; NOT A REAL UPDATE. The host answers a poll
2530
+ * it refused (rate-limited) with `{ workflowId, status: 'processing',
2531
+ * throttled: true }` without reading the workflow, so its `status` is a
2532
+ * placeholder and everything else is missing. A real snapshot never carries
2533
+ * the field.
2534
+ *
2535
+ * `useBuzzWorkflow().watch` already handles it: it does not pass such a reply
2536
+ * to `onUpdate`, keeps the previous real snapshot as its result, and polls
2537
+ * again. `poll()` returns it as is (so check the flag) but does not replace
2538
+ * the hook's `result` with it. On a cancel it means the cancel was NOT
2539
+ * issued: `cancel()` rejects with `WorkflowCancelNotIssuedError`, and the
2540
+ * caller retries. Absent on a host that predates the marker,
2541
+ * whose throttled reply is `{ workflowId, status: 'processing' }`.
2542
+ */
2543
+ throttled?: true;
2358
2544
  }
2359
2545
  /** One entry of {@link BlockWorkflowSnapshot.steps}. */
2360
2546
  export interface BlockWorkflowStepSnapshot {
@@ -2376,6 +2562,101 @@ export interface BlockWorkflowStepSnapshot {
2376
2562
  output?: unknown;
2377
2563
  /** Why this step failed. Diagnostic text; do not render it verbatim. */
2378
2564
  error?: string;
2565
+ /**
2566
+ * The step's place in the orchestrator's queue. PRESENT ONLY WHILE THE STEP
2567
+ * IS QUEUED (waiting for a worker). Absent (read it as `null`) once the step
2568
+ * has started, once it or the workflow is terminal, and on a host that
2569
+ * predates the field. Its position refreshes at most once per held poll —
2570
+ * see {@link BlockWorkflowSnapshot.eta}. See {@link BlockWorkflowStepQueue}.
2571
+ */
2572
+ queue?: BlockWorkflowStepQueue | null;
2573
+ /**
2574
+ * How much of this step is done, as a FRACTION from `0` to `1` (not a
2575
+ * percentage). Absent or `null` (the same thing) when the orchestrator
2576
+ * reports none, once the step or the workflow is terminal, on a host that
2577
+ * predates the field, and for every step type whose orchestrator value is not
2578
+ * a fraction of the whole step. The host reports it only for image and video
2579
+ * generation (`textToImage`, `imageGen`, `videoGen`); multi-phase types such
2580
+ * as training restart at 0 in each phase, so they get none.
2581
+ */
2582
+ progress?: number | null;
2583
+ /**
2584
+ * When the step started running, as an ISO-8601 string. Absent or `null`
2585
+ * (the same thing) until it has started, and on a host that predates the
2586
+ * field.
2587
+ */
2588
+ startedAt?: string | null;
2589
+ /**
2590
+ * When the step finished, as an ISO-8601 string. Absent or `null` (the same
2591
+ * thing) until it is terminal, and on a host that predates the field.
2592
+ */
2593
+ completedAt?: string | null;
2594
+ }
2595
+ /**
2596
+ * The values the host sends today in {@link BlockWorkflowStepQueue.support}
2597
+ * and {@link BlockWorkflowEta.support}: whether the orchestrator can estimate
2598
+ * this step's queue at all.
2599
+ *
2600
+ * - `'available'` — there is capacity for the step and the estimates are the
2601
+ * scheduler's own.
2602
+ * - `'unavailable'` — NO CAPACITY RIGHT NOW: no worker that can run the step
2603
+ * is available, so the step waits until one is. The estimates, when given,
2604
+ * are least reliable here.
2605
+ * - `'unsupported'` — the orchestrator does not estimate queues for this kind
2606
+ * of step; the position and times are `null`.
2607
+ *
2608
+ * 🔴 AN UNKNOWN VALUE IS POSSIBLE: the field is typed as these plus any string,
2609
+ * and the SDK's inbound validator accepts any string. Treat an unrecognised
2610
+ * value like `'unsupported'`.
2611
+ */
2612
+ export type KnownBlockWorkflowQueueSupport = 'unsupported' | 'unavailable' | 'available';
2613
+ /**
2614
+ * One step's place in the orchestrator's queue — {@link
2615
+ * BlockWorkflowStepSnapshot.queue}, present only while the step is queued.
2616
+ *
2617
+ * Every time is an ISO-8601 string and an ESTIMATE, and any of them may be
2618
+ * `null` when the orchestrator has none.
2619
+ */
2620
+ export interface BlockWorkflowStepQueue {
2621
+ /** How many jobs are ahead of this step in the queue (a whole number ≥ 0), or `null` when unknown. */
2622
+ precedingJobs: number | null;
2623
+ /** When the step is expected to start running. An estimate. */
2624
+ estimatedStartAt: string | null;
2625
+ /** When the step is expected to finish. An estimate. */
2626
+ estimatedCompleteAt: string | null;
2627
+ /** Whether these estimates exist at all — see {@link KnownBlockWorkflowQueueSupport}. */
2628
+ support: KnownBlockWorkflowQueueSupport | (string & {});
2629
+ }
2630
+ /**
2631
+ * {@link BlockWorkflowSnapshot.eta}: a summary of the step that is queued or
2632
+ * running now (the first queued step, else the first running step).
2633
+ *
2634
+ * WHILE QUEUED, `queuedAhead`, `startsAt`, `completesAt` and `support` come
2635
+ * from the step's queue and `progress` is `null`. WHILE RUNNING, those four
2636
+ * are `null` and `progress` moves. Every time is an ISO-8601 string and an
2637
+ * ESTIMATE. All six keys are always present when the object is.
2638
+ */
2639
+ export interface BlockWorkflowEta {
2640
+ /** The {@link BlockWorkflowStepSnapshot.name} of the step this summarises. */
2641
+ stepName: string;
2642
+ /** How many jobs are ahead of that step in the queue (a whole number ≥ 0), or `null` when unknown. */
2643
+ queuedAhead: number | null;
2644
+ /** When the step is expected to start. An estimate; `null` once it is running or when unknown. */
2645
+ startsAt: string | null;
2646
+ /** When the step is expected to finish. An estimate; `null` once it is running or when unknown. */
2647
+ completesAt: string | null;
2648
+ /**
2649
+ * How much of the step is done, as a FRACTION from `0` to `1`. `null` while
2650
+ * it is queued, when the orchestrator reports none, and for step types other
2651
+ * than image and video generation (see
2652
+ * {@link BlockWorkflowStepSnapshot.progress}).
2653
+ */
2654
+ progress: number | null;
2655
+ /**
2656
+ * The step's {@link BlockWorkflowStepQueue.support}, or `null` when the host
2657
+ * has none. `'unavailable'` means no capacity right now.
2658
+ */
2659
+ support: KnownBlockWorkflowQueueSupport | (string & {}) | null;
2379
2660
  }
2380
2661
  /**
2381
2662
  * The run total a BATCH estimate reports beside its per-cell snapshots
@@ -3360,7 +3641,7 @@ export type BlockManifest = BlockManifestV1;
3360
3641
  * DATE WIRE CAVEAT: `date` is documented as ISO-8601 to match the SDK's
3361
3642
  * wire convention, BUT the host currently forwards the raw tRPC `result` over a
3362
3643
  * structured-clone `postMessage` (it does NOT `.toISOString()`-map it the way
3363
- * the `SHARED_LIST` bridge does), so at runtime `date` arrives as a `Date`
3644
+ * the removed `SHARED_LIST` bridge did), so at runtime `date` arrives as a `Date`
3364
3645
  * INSTANCE. The block-side guard + `useBuzzTransactions` hook tolerate BOTH a
3365
3646
  * `Date` and an ISO string (rehydrating to `Date`), so either representation
3366
3647
  * round-trips correctly. See `civitai-blocks-react`'s `isValidBuzzTransactionsResult`.
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
- * 228 symbols and that side effect into the root would make every OAuth app
28
+ * 229 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 228 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 229 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
- * 228 symbols and that side effect into the root would make every OAuth app
28
+ * 229 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 228 is ASSERTED, not merely quoted — by
32
+ * 🔴 That 229 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.87.0",
3
+ "version": "0.88.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",