@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.
@@ -8,7 +8,7 @@
8
8
  * Wire format: `window.postMessage({ type, payload }, targetOrigin)`.
9
9
  */
10
10
  import type { ColorDomain } from './browsingLevel.js';
11
- import type { BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockContext, BlockSettings, Theme, ViewerInfo, WorkflowBody, BlockWorkflowSnapshot, BlockEstimateBatchAggregate, BlockBuzzTransaction, BlockBuzzAccount, BlockDailyCompensationResource, BlockViewer, BlockWildcardPack, BlockWildcardPackErrorCode, BlockResourceFile, BlockResourceFileErrorCode, AppWorkflow, BlockGatedImage, BlockCollectionFollowErrorCode, BlockCollectionFollowResult, BlockPostSource, BlockCreatePostResult, BlockTrainingDataUploadResult, WorkflowBodyTraining, WorkflowBodyPassThroughStep } from './types.js';
11
+ import type { BlockCheckpointInfo, BlockResourceInfo, BlockResourcePickerType, BlockUploadedImageInfo, BlockGenerationSourceImageInfo, BlockPersistedGenerationSource, BlockImagePickerSource, BlockPickedImageInfo, BlockMediaKind, BlockMediaUploadInfo, BlockMediaUploadBatchItemResult, BlockPendingImageInfo, BlockImageScanResult, BlockUploadPurpose, BlockNavigateScope, BlockContext, BlockSettings, Theme, ViewerInfo, WorkflowBody, BlockWorkflowSnapshot, BlockEstimateBatchAggregate, BlockBuzzTransaction, BlockBuzzAccount, BlockDailyCompensationResource, BlockViewer, BlockWildcardPack, BlockWildcardPackErrorCode, BlockResourceFile, BlockResourceFileErrorCode, AppWorkflow, BlockGatedImage, BlockCollectionFollowErrorCode, BlockCollectionFollowResult, BlockPostSource, BlockCreatePostResult, BlockTrainingDataUploadResult, WorkflowBodyTraining, WorkflowBodyPassThroughStep } from './types.js';
12
12
  import type { BlockAppReaction, BlockEntityReactionErrorCode, BlockEntityReactionResult, BlockEntityReactionsResult, BlockReactionEntityType } from './reactions.js';
13
13
  /**
14
14
  * Filter params for `GET_BUZZ_TRANSACTIONS`. All optional; the host validates
@@ -234,74 +234,6 @@ export interface BlockInitPayload {
234
234
  */
235
235
  storageMode?: 'local-preview';
236
236
  }
237
- /**
238
- * The freeform value carried by one SHARED-storage entry. Unlike the per-user
239
- * `APP_STORAGE_*` KV (arbitrary JSON), the SHARED store is a structured,
240
- * append-only, community-votable list — every entry is a `{ title, body? }`
241
- * record contributed by one viewer and vote-counted across all viewers. `title`
242
- * is required; `body` is optional long-form.
243
- */
244
- export interface SharedStorageValue {
245
- title: string;
246
- body?: string;
247
- /**
248
- * Optional, opaque, app-owned structured payload stored alongside the
249
- * moderated `title`/`body`. Mirrors civitai's merged shared-storage `data`
250
- * jsonb (`appendValueInput.data`). UNMODERATED — the content-safety belt runs
251
- * on `title`/`body` only, so apps MUST keep ALL user-visible TEXT in
252
- * `title`/`body` and place ONLY opaque app structure here (e.g. a serialized
253
- * generator spec / settings blob). Counts toward the per-value byte cap + the
254
- * per-app quota. Omit when the entry carries no structured payload.
255
- */
256
- data?: unknown;
257
- }
258
- /**
259
- * Retry metadata on a RATE-LIMITED shared-storage refusal. The host adds it
260
- * beside `error` on the six write replies (`SHARED_APPEND_RESULT`,
261
- * `SHARED_UPDATE_RESULT`, `SHARED_VOTE_RESULT`, `SHARED_UNVOTE_RESULT`,
262
- * `SHARED_WITHDRAW_RESULT`, `SHARED_REPORT_RESULT`) when the server refused the
263
- * write because a per-(viewer, app) budget is empty, so a block can render the
264
- * wait instead of parsing it out of the prose `error`.
265
- *
266
- * Its PRESENCE marks the refusal as rate-limited; every other refusal omits it.
267
- * ADDITIVE + OPTIONAL: a host that predates it never sends it, so a block must
268
- * treat "absent" as "not known to be rate-limited", never as "retry now".
269
- *
270
- * Same shape as the platform's tRPC `error.data.rateLimit` and the REST 429
271
- * body's `rateLimit` (which also comes with a `Retry-After` header).
272
- */
273
- export interface SharedStorageRateLimit {
274
- /** Whole seconds until a retry can succeed. An integer, at least 1. */
275
- retryAfterSeconds: number;
276
- /** ISO-8601 instant at which a retry can succeed. */
277
- retryAt: string;
278
- }
279
- /**
280
- * One SHARED-storage entry as it appears on the wire in `SHARED_LIST_RESULT`.
281
- * `createdAt`/`updatedAt` are ISO-8601 strings; the block-side hook rehydrates
282
- * them to `Date` (mirrors `APP_STORAGE_LIST_RESULT`'s `updatedAt`). `count` is
283
- * the current vote total; `authorUserId` is the contributing viewer.
284
- */
285
- export interface SharedStorageItemWire {
286
- key: string;
287
- authorUserId: number;
288
- value: SharedStorageValue;
289
- count: number;
290
- /** ISO-8601; consumers rehydrate to Date. */
291
- createdAt: string;
292
- /** ISO-8601; consumers rehydrate to Date. */
293
- updatedAt: string;
294
- /**
295
- * Whether the REQUESTING viewer has an active up-vote on this entry. Lets a
296
- * block hydrate its vote-button state on load instead of guessing (fixes the
297
- * "double-click to unvote" bug). ADDITIVE + OPTIONAL: a host that predates
298
- * this field omits it — the block-side hook defaults a missing value to
299
- * `false`, so a new block on an old host degrades to today's behavior. An
300
- * anonymous viewer is always `false` (no per-viewer vote row). Resolved
301
- * server-side per viewer; never client-trusted.
302
- */
303
- viewerVoted?: boolean;
304
- }
305
237
  /**
306
238
  * Why a `CONSENT_UNAVAILABLE` push was sent.
307
239
  *
@@ -510,6 +442,13 @@ export type ParentToBlockMessage = {
510
442
  };
511
443
  error?: string;
512
444
  };
445
+ } | {
446
+ type: 'GENERATION_SOURCE_PERSISTED';
447
+ payload: {
448
+ requestId: string;
449
+ result?: BlockPersistedGenerationSource;
450
+ error?: string;
451
+ };
513
452
  } | {
514
453
  type: 'CREATE_POST_RESULT';
515
454
  payload: {
@@ -615,133 +554,19 @@ export type ParentToBlockMessage = {
615
554
  error?: string;
616
555
  };
617
556
  } | {
618
- type: 'USER_CHECKPOINT_SET';
619
- payload: {
620
- requestId: string;
621
- ok?: boolean;
622
- error?: string;
623
- };
624
- } | {
625
- type: 'APP_STORAGE_GET_RESULT';
626
- payload: {
627
- requestId: string;
628
- value: unknown;
629
- error?: string;
630
- };
631
- } | {
632
- type: 'APP_STORAGE_SET_RESULT';
633
- payload: {
634
- requestId: string;
635
- ok?: boolean;
636
- error?: string;
637
- sizeBytes?: number;
638
- };
639
- } | {
640
- type: 'APP_STORAGE_DELETE_RESULT';
641
- payload: {
642
- requestId: string;
643
- ok?: boolean;
644
- deleted?: boolean;
645
- error?: string;
646
- };
647
- } | {
648
- type: 'APP_STORAGE_LIST_RESULT';
649
- payload: {
650
- requestId: string;
651
- keys: Array<{
652
- key: string;
653
- updatedAt: string;
654
- }>;
655
- nextCursor?: string;
656
- error?: string;
657
- };
658
- } | {
659
- type: 'APP_STORAGE_QUOTA_RESULT';
660
- payload: {
661
- requestId: string;
662
- usedBytes: number;
663
- rowCount: number;
664
- limitBytes: number;
665
- limitRows: number;
666
- error?: string;
667
- };
668
- } | {
669
- type: 'SHARED_LIST_RESULT';
670
- payload: {
671
- requestId: string;
672
- items: SharedStorageItemWire[];
673
- nextCursor?: string;
674
- error?: string;
675
- };
676
- } | {
677
- type: 'SHARED_GET_COUNT_RESULT';
678
- payload: {
679
- requestId: string;
680
- count: number;
681
- error?: string;
682
- };
683
- } | {
684
- type: 'SHARED_GET_COUNTS_RESULT';
685
- payload: {
686
- requestId: string;
687
- counts: Record<string, number>;
688
- error?: string;
689
- };
690
- } | {
691
- type: 'SHARED_APPEND_RESULT';
692
- payload: {
693
- requestId: string;
694
- key: string;
695
- error?: string;
696
- rateLimit?: SharedStorageRateLimit;
697
- };
698
- } | {
699
- type: 'SHARED_VOTE_RESULT';
700
- payload: {
701
- requestId: string;
702
- count: number;
703
- error?: string;
704
- rateLimit?: SharedStorageRateLimit;
705
- };
706
- } | {
707
- type: 'SHARED_UNVOTE_RESULT';
708
- payload: {
709
- requestId: string;
710
- count: number;
711
- error?: string;
712
- rateLimit?: SharedStorageRateLimit;
713
- };
714
- } | {
715
- type: 'SHARED_WITHDRAW_RESULT';
716
- payload: {
717
- requestId: string;
718
- ok?: boolean;
719
- deleted?: boolean;
720
- error?: string;
721
- rateLimit?: SharedStorageRateLimit;
722
- };
723
- } | {
724
- type: 'SHARED_UPDATE_RESULT';
725
- payload: {
726
- requestId: string;
727
- ok?: boolean;
728
- error?: string;
729
- rateLimit?: SharedStorageRateLimit;
730
- };
731
- } | {
732
- type: 'SHARED_GET_RESULT';
557
+ type: 'MEDIA_UPLOAD_BATCH_RESULT';
733
558
  payload: {
734
559
  requestId: string;
735
- item: SharedStorageItemWire | null;
736
560
  error?: string;
561
+ results?: BlockMediaUploadBatchItemResult[];
562
+ expiresAt?: string;
737
563
  };
738
564
  } | {
739
- type: 'SHARED_REPORT_RESULT';
565
+ type: 'USER_CHECKPOINT_SET';
740
566
  payload: {
741
567
  requestId: string;
742
568
  ok?: boolean;
743
569
  error?: string;
744
- rateLimit?: SharedStorageRateLimit;
745
570
  };
746
571
  } | {
747
572
  type: 'SAVE_IMAGE_RESULT';
@@ -882,6 +707,13 @@ export type BlockToParentMessage = {
882
707
  imageIndexes?: number[];
883
708
  title?: string;
884
709
  };
710
+ } | {
711
+ type: 'PERSIST_GENERATION_SOURCE';
712
+ payload: {
713
+ requestId: string;
714
+ workflowId: string;
715
+ imageIndex: number;
716
+ };
885
717
  } | {
886
718
  type: 'CREATE_POST_FROM_APP';
887
719
  payload: {
@@ -1009,6 +841,22 @@ export type BlockToParentMessage = {
1009
841
  /** Bytes mode only: the type the app believes it is sending; must match the content. */
1010
842
  mimeType?: string;
1011
843
  };
844
+ } | {
845
+ type: 'OPEN_MEDIA_UPLOAD_BATCH';
846
+ payload: {
847
+ requestId: string;
848
+ /** Required. The only accepted value today. */
849
+ purpose: 'generationSource';
850
+ /** 1 to 1200 files, answered in this order. */
851
+ items: Array<{
852
+ /** What the bytes are. An unknown value is refused for that item. */
853
+ kind: BlockMediaKind;
854
+ /** The file. A typed-array view or an empty buffer is refused for that item. */
855
+ bytes: ArrayBuffer;
856
+ /** Optional: the type the app believes it is sending; must match the content. */
857
+ mimeType?: string;
858
+ }>;
859
+ };
1012
860
  } | {
1013
861
  type: 'SET_USER_CHECKPOINT';
1014
862
  payload: {
@@ -1039,102 +887,6 @@ export type BlockToParentMessage = {
1039
887
  eventName: string;
1040
888
  properties?: Record<string, unknown>;
1041
889
  };
1042
- } | {
1043
- type: 'APP_STORAGE_GET';
1044
- payload: {
1045
- requestId: string;
1046
- key: string;
1047
- };
1048
- } | {
1049
- type: 'APP_STORAGE_SET';
1050
- payload: {
1051
- requestId: string;
1052
- key: string;
1053
- value: unknown;
1054
- };
1055
- } | {
1056
- type: 'APP_STORAGE_DELETE';
1057
- payload: {
1058
- requestId: string;
1059
- key: string;
1060
- };
1061
- } | {
1062
- type: 'APP_STORAGE_LIST';
1063
- payload: {
1064
- requestId: string;
1065
- prefix?: string;
1066
- limit?: number;
1067
- cursor?: string;
1068
- };
1069
- } | {
1070
- type: 'APP_STORAGE_QUOTA';
1071
- payload: {
1072
- requestId: string;
1073
- };
1074
- } | {
1075
- type: 'SHARED_LIST';
1076
- payload: {
1077
- requestId: string;
1078
- prefix?: string;
1079
- limit?: number;
1080
- cursor?: string;
1081
- };
1082
- } | {
1083
- type: 'SHARED_GET_COUNT';
1084
- payload: {
1085
- requestId: string;
1086
- key: string;
1087
- };
1088
- } | {
1089
- type: 'SHARED_GET_COUNTS';
1090
- payload: {
1091
- requestId: string;
1092
- keys: string[];
1093
- };
1094
- } | {
1095
- type: 'SHARED_APPEND';
1096
- payload: {
1097
- requestId: string;
1098
- value: SharedStorageValue;
1099
- };
1100
- } | {
1101
- type: 'SHARED_VOTE';
1102
- payload: {
1103
- requestId: string;
1104
- key: string;
1105
- };
1106
- } | {
1107
- type: 'SHARED_UNVOTE';
1108
- payload: {
1109
- requestId: string;
1110
- key: string;
1111
- };
1112
- } | {
1113
- type: 'SHARED_WITHDRAW';
1114
- payload: {
1115
- requestId: string;
1116
- key: string;
1117
- };
1118
- } | {
1119
- type: 'SHARED_UPDATE';
1120
- payload: {
1121
- requestId: string;
1122
- key: string;
1123
- value: SharedStorageValue;
1124
- };
1125
- } | {
1126
- type: 'SHARED_GET';
1127
- payload: {
1128
- requestId: string;
1129
- key: string;
1130
- };
1131
- } | {
1132
- type: 'SHARED_REPORT';
1133
- payload: {
1134
- requestId: string;
1135
- key: string;
1136
- reason?: string;
1137
- };
1138
890
  } | {
1139
891
  type: 'SAVE_IMAGE';
1140
892
  payload: {
@@ -1231,7 +983,7 @@ export type BlockToParentMessageType = BlockToParentMessage['type'];
1231
983
  * it is a measurement, not an invariant, and civitai's own compile-time gate
1232
984
  * (published SDK union ⊆ `keyof INVENTORY`) is what holds one direction of it.
1233
985
  */
1234
- export declare const BLOCK_TO_PARENT_MESSAGE_TYPES: readonly ["BLOCK_HELLO", "BLOCK_READY", "BLOCK_ERROR", "BLOCK_MESSAGE_REJECTED", "REQUEST_TOKEN", "RESIZE_IFRAME", "SUBMIT_WORKFLOW", "ESTIMATE_WORKFLOW", "ESTIMATE_WORKFLOW_BATCH", "POLL_WORKFLOW", "CANCEL_WORKFLOW", "OPEN_BUZZ_PURCHASE", "GET_BUZZ_BALANCE", "GET_VIEWER", "GET_BUZZ_TRANSACTIONS", "GET_BUZZ_ACCOUNTS", "GET_DAILY_COMPENSATION", "GET_WILDCARD_PACK", "GET_RESOURCE_FILE", "QUERY_APP_WORKFLOWS", "PUBLISH_GENERATION_OUTPUTS", "CREATE_POST_FROM_APP", "RUN_TRAINING", "RUN_CONFIRMED_STEP", "GET_IMAGES_BY_IDS", "CANCEL_APP_WORKFLOW", "OPEN_CHECKPOINT_PICKER", "OPEN_RESOURCE_PICKER", "OPEN_IMAGE_UPLOAD", "OPEN_IMAGE_PICKER", "OPEN_MEDIA_UPLOAD", "SET_USER_CHECKPOINT", "NAVIGATE", "REQUEST_SIGN_IN", "REQUEST_CONSENT", "TRACK_EVENT", "APP_STORAGE_GET", "APP_STORAGE_SET", "APP_STORAGE_DELETE", "APP_STORAGE_LIST", "APP_STORAGE_QUOTA", "SHARED_LIST", "SHARED_GET_COUNT", "SHARED_GET_COUNTS", "SHARED_APPEND", "SHARED_VOTE", "SHARED_UNVOTE", "SHARED_WITHDRAW", "SHARED_UPDATE", "SHARED_GET", "SHARED_REPORT", "SAVE_IMAGE", "SET_COLLECTION_FOLLOW", "SET_ENTITY_REACTION", "GET_ENTITY_REACTIONS"];
986
+ export declare const BLOCK_TO_PARENT_MESSAGE_TYPES: readonly ["BLOCK_HELLO", "BLOCK_READY", "BLOCK_ERROR", "BLOCK_MESSAGE_REJECTED", "REQUEST_TOKEN", "RESIZE_IFRAME", "SUBMIT_WORKFLOW", "ESTIMATE_WORKFLOW", "ESTIMATE_WORKFLOW_BATCH", "POLL_WORKFLOW", "CANCEL_WORKFLOW", "OPEN_BUZZ_PURCHASE", "GET_BUZZ_BALANCE", "GET_VIEWER", "GET_BUZZ_TRANSACTIONS", "GET_BUZZ_ACCOUNTS", "GET_DAILY_COMPENSATION", "GET_WILDCARD_PACK", "GET_RESOURCE_FILE", "QUERY_APP_WORKFLOWS", "PUBLISH_GENERATION_OUTPUTS", "PERSIST_GENERATION_SOURCE", "CREATE_POST_FROM_APP", "RUN_TRAINING", "RUN_CONFIRMED_STEP", "GET_IMAGES_BY_IDS", "CANCEL_APP_WORKFLOW", "OPEN_CHECKPOINT_PICKER", "OPEN_RESOURCE_PICKER", "OPEN_IMAGE_UPLOAD", "OPEN_IMAGE_PICKER", "OPEN_MEDIA_UPLOAD", "OPEN_MEDIA_UPLOAD_BATCH", "SET_USER_CHECKPOINT", "NAVIGATE", "REQUEST_SIGN_IN", "REQUEST_CONSENT", "TRACK_EVENT", "SAVE_IMAGE", "SET_COLLECTION_FOLLOW", "SET_ENTITY_REACTION", "GET_ENTITY_REACTIONS"];
1235
987
  /**
1236
988
  * The bucket a message type falls into when the protocol does not declare it.
1237
989
  *
@@ -70,6 +70,7 @@ export const BLOCK_TO_PARENT_MESSAGE_TYPES = [
70
70
  'GET_RESOURCE_FILE',
71
71
  'QUERY_APP_WORKFLOWS',
72
72
  'PUBLISH_GENERATION_OUTPUTS',
73
+ 'PERSIST_GENERATION_SOURCE',
73
74
  'CREATE_POST_FROM_APP',
74
75
  'RUN_TRAINING',
75
76
  'RUN_CONFIRMED_STEP',
@@ -80,26 +81,12 @@ export const BLOCK_TO_PARENT_MESSAGE_TYPES = [
80
81
  'OPEN_IMAGE_UPLOAD',
81
82
  'OPEN_IMAGE_PICKER',
82
83
  'OPEN_MEDIA_UPLOAD',
84
+ 'OPEN_MEDIA_UPLOAD_BATCH',
83
85
  'SET_USER_CHECKPOINT',
84
86
  'NAVIGATE',
85
87
  'REQUEST_SIGN_IN',
86
88
  'REQUEST_CONSENT',
87
89
  'TRACK_EVENT',
88
- 'APP_STORAGE_GET',
89
- 'APP_STORAGE_SET',
90
- 'APP_STORAGE_DELETE',
91
- 'APP_STORAGE_LIST',
92
- 'APP_STORAGE_QUOTA',
93
- 'SHARED_LIST',
94
- 'SHARED_GET_COUNT',
95
- 'SHARED_GET_COUNTS',
96
- 'SHARED_APPEND',
97
- 'SHARED_VOTE',
98
- 'SHARED_UNVOTE',
99
- 'SHARED_WITHDRAW',
100
- 'SHARED_UPDATE',
101
- 'SHARED_GET',
102
- 'SHARED_REPORT',
103
90
  'SAVE_IMAGE',
104
91
  'SET_COLLECTION_FOLLOW',
105
92
  'SET_ENTITY_REACTION',