@civitai/blocks-react 0.63.2 → 0.65.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 +188 -6
- package/dist/hooks/useBuzzWorkflow.d.ts +20 -0
- package/dist/hooks/useBuzzWorkflow.js +32 -12
- package/dist/hooks/useCreatePostFromApp.d.ts +7 -2
- package/dist/hooks/useCreatePostFromApp.js +8 -3
- package/dist/hooks/useNestedDocument.d.ts +73 -0
- package/dist/hooks/useNestedDocument.js +160 -0
- package/dist/hooks/usePrepareTrainingDataset.d.ts +99 -0
- package/dist/hooks/usePrepareTrainingDataset.js +157 -0
- package/dist/hooks/usePublishGenerationOutputs.d.ts +6 -0
- package/dist/hooks/usePublishGenerationOutputs.js +6 -0
- package/dist/hooks/useRunTraining.d.ts +151 -0
- package/dist/hooks/useRunTraining.js +212 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/internal/liveHost.d.ts +18 -2
- package/dist/internal/liveHost.js +89 -23
- package/dist/internal/mockHost.d.ts +146 -2
- package/dist/internal/mockHost.js +309 -0
- package/dist/transport/requestTimeouts.d.ts +19 -0
- package/dist/transport/requestTimeouts.js +30 -0
- package/dist/transport/validate.d.ts +27 -0
- package/dist/transport/validate.js +189 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -59,6 +59,8 @@ export { RequestTimeoutError } from './transport/transport.js';
|
|
|
59
59
|
export { InvalidIdempotencyKeyError } from './transport/transport.js';
|
|
60
60
|
export { useCollectionFollow, CollectionFollowError, COLLECTION_FOLLOW_ERROR_CODES, isCollectionFollowErrorCode, } from './hooks/useCollectionFollow.js';
|
|
61
61
|
export { useCreatePostFromApp, CreatePostError, CREATE_POST_ERROR_CODES, isCreatePostErrorCode, } from './hooks/useCreatePostFromApp.js';
|
|
62
|
+
export { usePrepareTrainingDataset, PrepareTrainingDatasetError, PREPARE_TRAINING_DATASET_ERROR_CODES, isPrepareTrainingDatasetErrorCode, } from './hooks/usePrepareTrainingDataset.js';
|
|
63
|
+
export { useRunTraining, RunTrainingError, RUN_TRAINING_ERROR_CODES, isRunTrainingErrorCode, } from './hooks/useRunTraining.js';
|
|
62
64
|
export { useCheckpointPicker } from './hooks/useCheckpointPicker.js';
|
|
63
65
|
export { useResourcePicker } from './hooks/useResourcePicker.js';
|
|
64
66
|
export { useImageUpload } from './hooks/useImageUpload.js';
|
|
@@ -76,6 +78,10 @@ export { useDomainMaturity } from './hooks/useDomainMaturity.js';
|
|
|
76
78
|
export { SfwGate } from './hooks/SfwGate.js';
|
|
77
79
|
export { useDirectLoad } from './hooks/useDirectLoad.js';
|
|
78
80
|
export { hostToRunUrl, DIRECT_LOAD_TIMEOUT_MS } from './transport/directLoad.js';
|
|
81
|
+
// A block CANNOT frame its own bundled content by URL. This is the `srcdoc`
|
|
82
|
+
// fallback; prefer a single-document design. Why, measured, in one place:
|
|
83
|
+
// `@civitai/app-sdk`'s `src/blocks/nestedDocument.ts` header.
|
|
84
|
+
export { useNestedDocument } from './hooks/useNestedDocument.js';
|
|
79
85
|
export { useAppStorage } from './hooks/useAppStorage.js';
|
|
80
86
|
export { useSharedStorage } from './hooks/useSharedStorage.js';
|
|
81
87
|
//# sourceMappingURL=index.js.map
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
* --- BEGIN DERIVED ---
|
|
47
47
|
* fetch chokepoints ..... 2
|
|
48
48
|
* REST endpoints ........ GET /api/v1/blocks/me
|
|
49
|
-
* tRPC procedures .......
|
|
50
|
-
* switch case labels ....
|
|
49
|
+
* tRPC procedures ....... 28 = blocks.* (13) + apps.shared.* (10) + apps.storage.* (5)
|
|
50
|
+
* switch case labels .... 47, of which 10 REFUSE (enumerated under SCOPE below)
|
|
51
51
|
* --- END DERIVED ---
|
|
52
52
|
*
|
|
53
53
|
* PICKERS (Phase 1 of "make dev:live a faithful local host"): the live host
|
|
@@ -101,6 +101,17 @@
|
|
|
101
101
|
* host-chrome consent. Replies `collection-unavailable`.
|
|
102
102
|
* • CREATE_POST_FROM_APP — needs the server-resolved preview plus host-chrome
|
|
103
103
|
* confirm before a PUBLIC post is written. Replies with a refusal.
|
|
104
|
+
* • PREPARE_TRAINING_DATASET — the server refuses every `kind: 'training'`
|
|
105
|
+
* request from a dev token, so there is nothing to forward. Replies with a
|
|
106
|
+
* refusal.
|
|
107
|
+
* • RUN_TRAINING — the same dev-token refusal, plus the host-chrome consent
|
|
108
|
+
* dialog a run is confirmed in, which this harness does not have. Replies
|
|
109
|
+
* with a refusal.
|
|
110
|
+
* • PUBLISH_GENERATION_OUTPUTS — publishing requires the viewer's signed-in
|
|
111
|
+
* civitai.com session, which the local harness does not have; test
|
|
112
|
+
* publishing against the mock host — `createMockHost` or `Harness` from
|
|
113
|
+
* `@civitai/blocks-react/testing`, with the `publishImageIds` /
|
|
114
|
+
* `publishError` options. Replies with a refusal.
|
|
104
115
|
* • GET_WILDCARD_PACK — needs the session-authed resolve plus the in-tab
|
|
105
116
|
* zip/yaml parse that lives in civitai, not this SDK. Replies `parse-failed`.
|
|
106
117
|
* • OPEN_IMAGE_UPLOAD — needs the host's native modal + session-authed byte
|
|
@@ -176,6 +187,11 @@ export interface LiveHostOptions {
|
|
|
176
187
|
*/
|
|
177
188
|
onPickerReady?: (handle: PickerOverlayHandle) => void;
|
|
178
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* The reply both training bridges get in dev:live — see their handlers. One
|
|
192
|
+
* string so the two cannot drift.
|
|
193
|
+
*/
|
|
194
|
+
export declare const TRAINING_UNSUPPORTED_ERROR = "training is not supported in dev:live \u2014 use dev:mock";
|
|
179
195
|
/**
|
|
180
196
|
* Decoded payload of a block-token JWT (the claims `BlockTokenService.sign`
|
|
181
197
|
* stamps — see civitai `block-token.service.ts`). Everything is optional/unknown
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
* --- BEGIN DERIVED ---
|
|
47
47
|
* fetch chokepoints ..... 2
|
|
48
48
|
* REST endpoints ........ GET /api/v1/blocks/me
|
|
49
|
-
* tRPC procedures .......
|
|
50
|
-
* switch case labels ....
|
|
49
|
+
* tRPC procedures ....... 28 = blocks.* (13) + apps.shared.* (10) + apps.storage.* (5)
|
|
50
|
+
* switch case labels .... 47, of which 10 REFUSE (enumerated under SCOPE below)
|
|
51
51
|
* --- END DERIVED ---
|
|
52
52
|
*
|
|
53
53
|
* PICKERS (Phase 1 of "make dev:live a faithful local host"): the live host
|
|
@@ -101,6 +101,17 @@
|
|
|
101
101
|
* host-chrome consent. Replies `collection-unavailable`.
|
|
102
102
|
* • CREATE_POST_FROM_APP — needs the server-resolved preview plus host-chrome
|
|
103
103
|
* confirm before a PUBLIC post is written. Replies with a refusal.
|
|
104
|
+
* • PREPARE_TRAINING_DATASET — the server refuses every `kind: 'training'`
|
|
105
|
+
* request from a dev token, so there is nothing to forward. Replies with a
|
|
106
|
+
* refusal.
|
|
107
|
+
* • RUN_TRAINING — the same dev-token refusal, plus the host-chrome consent
|
|
108
|
+
* dialog a run is confirmed in, which this harness does not have. Replies
|
|
109
|
+
* with a refusal.
|
|
110
|
+
* • PUBLISH_GENERATION_OUTPUTS — publishing requires the viewer's signed-in
|
|
111
|
+
* civitai.com session, which the local harness does not have; test
|
|
112
|
+
* publishing against the mock host — `createMockHost` or `Harness` from
|
|
113
|
+
* `@civitai/blocks-react/testing`, with the `publishImageIds` /
|
|
114
|
+
* `publishError` options. Replies with a refusal.
|
|
104
115
|
* • GET_WILDCARD_PACK — needs the session-authed resolve plus the in-tab
|
|
105
116
|
* zip/yaml parse that lives in civitai, not this SDK. Replies `parse-failed`.
|
|
106
117
|
* • OPEN_IMAGE_UPLOAD — needs the host's native modal + session-authed byte
|
|
@@ -125,6 +136,15 @@ const DEFAULT_BACKEND_BASE_URL = 'https://civitai.com';
|
|
|
125
136
|
const PAGE_SLOT_ID = 'app.page';
|
|
126
137
|
/** The budgeted-spend scope the workflow procedures require. */
|
|
127
138
|
const BUDGETED_SCOPE = 'ai:write:budgeted';
|
|
139
|
+
/**
|
|
140
|
+
* The reply both training bridges get in dev:live — see their handlers. One
|
|
141
|
+
* string so the two cannot drift.
|
|
142
|
+
*/
|
|
143
|
+
export const TRAINING_UNSUPPORTED_ERROR = 'training is not supported in dev:live — use dev:mock';
|
|
144
|
+
/** The once-per-session console line for a refused training bridge. */
|
|
145
|
+
const trainingUnsupportedLog = (type) => `${type} is not supported in dev:live (the server refuses every training request from a ` +
|
|
146
|
+
'dev token, and a run needs the host-chrome consent dialog). Replying with a refusal. ' +
|
|
147
|
+
'Use dev:mock to exercise the training flow.';
|
|
128
148
|
/**
|
|
129
149
|
* Decode the middle (payload) segment of a JWT (base64url) WITHOUT verifying
|
|
130
150
|
* the signature — client-side we only need the claims to build BLOCK_INIT; the
|
|
@@ -962,6 +982,44 @@ export function createLiveHost(options) {
|
|
|
962
982
|
});
|
|
963
983
|
return;
|
|
964
984
|
}
|
|
985
|
+
case 'PREPARE_TRAINING_DATASET': {
|
|
986
|
+
// UNSUPPORTED in live, and here the SERVER decides it, not this
|
|
987
|
+
// harness: every `kind: 'training'` procedure refuses a dev token
|
|
988
|
+
// ("training is not available from a development or review session"
|
|
989
|
+
// — `assertTrainingRequestAllowed` in civitai/civitai), because there
|
|
990
|
+
// is no host page whose chrome can show the viewer a price. A
|
|
991
|
+
// training ESTIMATE is still forwarded (ESTIMATE_WORKFLOW above) and
|
|
992
|
+
// comes back carrying that same server refusal.
|
|
993
|
+
//
|
|
994
|
+
// FREE TEXT on the message's own reply channel; no host code is
|
|
995
|
+
// honest about "this harness cannot do it". Use dev:mock — its
|
|
996
|
+
// `trainingDatasetError` / `trainingDatasetRejected` knobs cover the
|
|
997
|
+
// refusal set.
|
|
998
|
+
if (!isRoutableRequestId(requestId))
|
|
999
|
+
return;
|
|
1000
|
+
logOnce('training-dataset', trainingUnsupportedLog('PREPARE_TRAINING_DATASET'));
|
|
1001
|
+
dispatchToBlock({
|
|
1002
|
+
type: 'TRAINING_DATASET_RESULT',
|
|
1003
|
+
payload: { requestId, error: TRAINING_UNSUPPORTED_ERROR },
|
|
1004
|
+
});
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
case 'RUN_TRAINING': {
|
|
1008
|
+
// UNSUPPORTED in live for the same server-side reason as
|
|
1009
|
+
// PREPARE_TRAINING_DATASET directly above — and doubly so: a run is
|
|
1010
|
+
// CHARGED and confirmed in host chrome this harness does not have, so
|
|
1011
|
+
// faking either half would let dev prove out a flow production does
|
|
1012
|
+
// not have. Use dev:mock — its `runTrainingError` knob covers
|
|
1013
|
+
// `declined`, `submission-unconfirmed` and the rest.
|
|
1014
|
+
if (!isRoutableRequestId(requestId))
|
|
1015
|
+
return;
|
|
1016
|
+
logOnce('training-run', trainingUnsupportedLog('RUN_TRAINING'));
|
|
1017
|
+
dispatchToBlock({
|
|
1018
|
+
type: 'TRAINING_RESULT',
|
|
1019
|
+
payload: { requestId, error: TRAINING_UNSUPPORTED_ERROR },
|
|
1020
|
+
});
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
965
1023
|
case 'GET_WILDCARD_PACK': {
|
|
966
1024
|
// UNSUPPORTED in live v1 (honest-by-design, like OPEN_BUZZ_PURCHASE):
|
|
967
1025
|
// the real host resolves the pack via a SESSION-authed proc and does
|
|
@@ -1025,29 +1083,37 @@ export function createLiveHost(options) {
|
|
|
1025
1083
|
return;
|
|
1026
1084
|
}
|
|
1027
1085
|
case 'PUBLISH_GENERATION_OUTPUTS': {
|
|
1028
|
-
//
|
|
1029
|
-
//
|
|
1030
|
-
//
|
|
1031
|
-
//
|
|
1032
|
-
//
|
|
1033
|
-
//
|
|
1034
|
-
//
|
|
1086
|
+
// UNSUPPORTED in live, for the same reason as CREATE_POST_FROM_APP
|
|
1087
|
+
// above: publishing requires the viewer's signed-in civitai.com
|
|
1088
|
+
// session, which the local harness does not have — it holds a dev
|
|
1089
|
+
// block token and has no civitai chrome to render the publish
|
|
1090
|
+
// confirm in. On civitai.com the real host resolves the workflow's
|
|
1091
|
+
// outputs, shows that confirm, and only then publishes bare,
|
|
1092
|
+
// real-scanned public Image rows.
|
|
1093
|
+
//
|
|
1094
|
+
// FREE TEXT, like the post refusal: none of the host's codes is
|
|
1095
|
+
// honest about "this harness cannot do it". `usePublishGenerationOutputs`
|
|
1096
|
+
// rejects with it as the message. Test publishing against the mock
|
|
1097
|
+
// host — `createMockHost` or `Harness` from
|
|
1098
|
+
// `@civitai/blocks-react/testing`, with the `publishImageIds` /
|
|
1099
|
+
// `publishError` options.
|
|
1035
1100
|
if (!isRoutableRequestId(requestId))
|
|
1036
1101
|
return;
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1102
|
+
logOnce('publish-outputs', 'PUBLISH_GENERATION_OUTPUTS is not supported in dev:live (publishing requires the ' +
|
|
1103
|
+
"viewer's signed-in civitai.com session, which the local harness does not have). " +
|
|
1104
|
+
'Replying with a refusal. Test publishing against the mock host — createMockHost ' +
|
|
1105
|
+
'or Harness from @civitai/blocks-react/testing, with the publishImageIds / ' +
|
|
1106
|
+
'publishError options.');
|
|
1107
|
+
dispatchToBlock({
|
|
1108
|
+
type: 'PUBLISH_RESULT',
|
|
1109
|
+
payload: {
|
|
1110
|
+
requestId,
|
|
1111
|
+
error: 'publishing generation outputs is not supported in dev:live — publishing ' +
|
|
1112
|
+
"requires the viewer's signed-in civitai.com session, which the local harness " +
|
|
1113
|
+
'does not have; test publishing against the mock host — createMockHost or ' +
|
|
1114
|
+
'Harness from @civitai/blocks-react/testing, with the publishImageIds / ' +
|
|
1115
|
+
'publishError options',
|
|
1116
|
+
},
|
|
1051
1117
|
});
|
|
1052
1118
|
return;
|
|
1053
1119
|
}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* called). Only the postMessage bridge round-trips are exercised. Never import
|
|
38
38
|
* this from production code.
|
|
39
39
|
*/
|
|
40
|
-
import { type BlockContext, type BlockResourceInfo, type BlockResourcePickerType, type BlockUploadedImageInfo, type BlockGenerationSourceImageInfo, type BuzzAccountType, type BlockBuzzTransaction, type BlockBuzzAccount, type BlockDailyCompensationResource, type BlockViewer, type BlockWildcardPack, type BlockWildcardPackErrorCode, type AppWorkflow, type BlockGatedImage, type BlockCollectionFollowErrorCode, type BlockCreatePostHostError, type BlockCreatePostResult, type ColorDomain, type SharedStorageValue, type Theme, type ViewerInfo, type WorkflowBody } from '@civitai/app-sdk/blocks';
|
|
40
|
+
import { type BlockContext, type BlockResourceInfo, type BlockResourcePickerType, type BlockUploadedImageInfo, type BlockGenerationSourceImageInfo, type BuzzAccountType, type BlockBuzzTransaction, type BlockBuzzAccount, type BlockDailyCompensationResource, type BlockViewer, type BlockWildcardPack, type BlockWildcardPackErrorCode, type AppWorkflow, type BlockPublishedModel, type BlockGatedImage, type BlockCollectionFollowErrorCode, type BlockCreatePostHostError, type BlockCreatePostResult, type BlockPrepareTrainingDatasetHostError, type BlockRunTrainingHostError, type BlockTrainingRejectionReason, type ColorDomain, type SharedStorageValue, type Theme, type ViewerInfo, type WorkflowBody } from '@civitai/app-sdk/blocks';
|
|
41
41
|
/**
|
|
42
42
|
* How submits behave. `'none'` = everything succeeds; `'all'` / `'insufficient'`
|
|
43
43
|
* = every submit RESOLVES an insufficient-Buzz `failed` snapshot, priced
|
|
@@ -178,7 +178,75 @@ export interface MockGenerationScenario {
|
|
|
178
178
|
* {@link image} when both are set.
|
|
179
179
|
*/
|
|
180
180
|
images?: string[] | ((req: WorkflowBody) => string[]);
|
|
181
|
+
/**
|
|
182
|
+
* How many trained epochs a succeeded training run reports on
|
|
183
|
+
* {@link BlockWorkflowSnapshot.trainedEpochs} — epochs `1…n`, each tagged with
|
|
184
|
+
* the run's `$type`. Applies only to a PASS-THROUGH `{ kind: 'step', $type:
|
|
185
|
+
* 'training' }` / `'imageResourceTraining'` body (tagged with that `$type`) and
|
|
186
|
+
* to a `kind: 'training'` run started through `RUN_TRAINING` (tagged
|
|
187
|
+
* `'training'`, the step the host builds for it); every other body is
|
|
188
|
+
* unaffected.
|
|
189
|
+
*
|
|
190
|
+
* Default `0`: the field is omitted, as the host omits it for a run that
|
|
191
|
+
* produced no checkpoint. Opt in with `n > 0` to simulate a finished run —
|
|
192
|
+
* it is off by default because a real run on this arm is bounded by the
|
|
193
|
+
* spend rules below, so a default success would promise what the host may
|
|
194
|
+
* not deliver.
|
|
195
|
+
*
|
|
196
|
+
* The mock never fabricates a checkpoint url: the block contract does not
|
|
197
|
+
* include one, so nothing here does either. A training snapshot's `imageUrls` stand for
|
|
198
|
+
* the run's SAMPLE images only (the same {@link image}/{@link images} knobs
|
|
199
|
+
* apply).
|
|
200
|
+
*
|
|
201
|
+
* 🔴 The real host's spend and timeout rules for this arm (see
|
|
202
|
+
* `WorkflowBodyPassThroughStep.maxBuzz` in `@civitai/app-sdk/blocks`) are
|
|
203
|
+
* NOT simulated: the mock neither quotes nor times out, so a success here
|
|
204
|
+
* says nothing about whether your run is quoted, what it costs, or whether
|
|
205
|
+
* it finishes.
|
|
206
|
+
*
|
|
207
|
+
* Snapshot-only: the app-queue read (`QUERY_APP_WORKFLOWS`) replies with the
|
|
208
|
+
* canned {@link MockHostOptions.appWorkflows} rows verbatim — they carry no
|
|
209
|
+
* body, so the mock cannot tell a training row from any other. To exercise
|
|
210
|
+
* {@link AppWorkflow.trainedEpochs}, put it on the rows you pass there.
|
|
211
|
+
*/
|
|
212
|
+
trainedEpochs?: number;
|
|
213
|
+
/**
|
|
214
|
+
* When set, a succeeded pass-through training snapshot also carries this as
|
|
215
|
+
* {@link BlockWorkflowSnapshot.publishedModel} — simulating a run the viewer
|
|
216
|
+
* has started (`published: false`) or finished (`published: true`) publishing
|
|
217
|
+
* through the model wizard. Default: unset (field omitted). For the app-queue
|
|
218
|
+
* read, put `publishedModel` (and `trainedEpochs`) on the rows you pass as
|
|
219
|
+
* `appWorkflows`.
|
|
220
|
+
*/
|
|
221
|
+
trainingPublishedModel?: BlockPublishedModel;
|
|
181
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* The training bounds the mock enforces — COPIES of `@civitai/app-sdk/blocks`'s
|
|
225
|
+
* `BLOCK_TRAINING_DATASET_MAX_ITEMS`, `BLOCK_TRAINING_CAPTION_MAX_CHARS` and
|
|
226
|
+
* `BLOCK_TRAINING_MAX_BUZZ_PER_RUN`, deliberately not value-imported: a value
|
|
227
|
+
* import of a symbol the newest PUBLISHED app-sdk lacks raises this package's
|
|
228
|
+
* peer floor (`tests/guards/blocks-react-peer-floor.test.mjs`). The copy is held
|
|
229
|
+
* to the SDK's value by `test/trainingKindFlow.test.tsx`, which imports both.
|
|
230
|
+
*/
|
|
231
|
+
export declare const MOCK_TRAINING_BOUNDS: {
|
|
232
|
+
readonly datasetMaxItems: 50;
|
|
233
|
+
readonly captionMaxChars: 1000;
|
|
234
|
+
readonly maxBuzzPerRun: 5000;
|
|
235
|
+
};
|
|
236
|
+
/** The real server's refusal for a training request from a token without the spend scope. */
|
|
237
|
+
export declare const MOCK_TRAINING_SCOPE_ERROR = "block lacks ai:write:budgeted scope";
|
|
238
|
+
/** The real server's refusal for an unknown, expired or spent quote on `RUN_TRAINING`. */
|
|
239
|
+
export declare const MOCK_TRAINING_QUOTE_GONE_ERROR = "training quote not found, expired or already used \u2014 estimate again";
|
|
240
|
+
/** The real server's refusal for a training estimate naming a dataset it does not hold. */
|
|
241
|
+
export declare const MOCK_TRAINING_DATASET_GONE_ERROR = "training dataset not found or expired";
|
|
242
|
+
/**
|
|
243
|
+
* The real server's two refusals for a dataset with NOTHING admitted
|
|
244
|
+
* (`prepareBlockTrainingDataset`): every image failed eligibility, or every
|
|
245
|
+
* eligible image failed its import. The server THROWS rather than returning
|
|
246
|
+
* `count: 0`, so a successful reply always admits at least one image.
|
|
247
|
+
*/
|
|
248
|
+
export declare const MOCK_TRAINING_NONE_ELIGIBLE_ERROR = "none of the requested images can be used for training";
|
|
249
|
+
export declare const MOCK_TRAINING_NONE_IMPORTED_ERROR = "none of the requested images could be prepared for training";
|
|
182
250
|
/**
|
|
183
251
|
* BUZZ scenario controls — simulate a balance so the insufficient-Buzz / top-up
|
|
184
252
|
* UX is exercisable. The mock host treats `balance` as a spendable wallet:
|
|
@@ -587,6 +655,82 @@ export interface MockHostOptions {
|
|
|
587
655
|
* exercised by `declined`, never by the timing or the content.
|
|
588
656
|
*/
|
|
589
657
|
createPostError?: BlockCreatePostHostError | string;
|
|
658
|
+
/**
|
|
659
|
+
* Images `PREPARE_TRAINING_DATASET` leaves out, with their reasons — what
|
|
660
|
+
* `usePrepareTrainingDataset()` reports on `rejected`. Only entries whose
|
|
661
|
+
* `imageId` the request actually named are reported, and `count` is the rest,
|
|
662
|
+
* exactly as the server derives it. Absent → every image is admitted.
|
|
663
|
+
* Live-tunable via {@link MockHost.setScenario}.
|
|
664
|
+
*
|
|
665
|
+
* When this rejects EVERY named image the reply is an `error`, as on the real
|
|
666
|
+
* server — {@link MOCK_TRAINING_NONE_ELIGIBLE_ERROR}, or
|
|
667
|
+
* {@link MOCK_TRAINING_NONE_IMPORTED_ERROR} when every image that passed
|
|
668
|
+
* eligibility was rejected with an `import-*` reason. A success never has
|
|
669
|
+
* `count: 0`.
|
|
670
|
+
*
|
|
671
|
+
* KIND-FAITHFUL, like the rest of the training path: the mock holds the
|
|
672
|
+
* datasets it prepared, an estimate naming any other `datasetId` fails as the
|
|
673
|
+
* server's does, a quote is run at most once, and every training call needs
|
|
674
|
+
* `ai:write:budgeted` on the token ({@link MockHostOptions.consentGranted}) and
|
|
675
|
+
* a signed-in viewer. What it cannot model: image ownership and moderation (it
|
|
676
|
+
* has no images), the flag, and the page-only / dev-token refusals.
|
|
677
|
+
*
|
|
678
|
+
* ⚠️ The quote↔body check is NARROWER than the server's: the mock compares only
|
|
679
|
+
* `datasetId`, while the server hashes the whole body (minus `quoteId`) and
|
|
680
|
+
* refuses any change. A body edited between estimate and run passes here and
|
|
681
|
+
* fails in production.
|
|
682
|
+
*/
|
|
683
|
+
trainingDatasetRejected?: Array<{
|
|
684
|
+
imageId: number;
|
|
685
|
+
reason: BlockTrainingRejectionReason;
|
|
686
|
+
}>;
|
|
687
|
+
/**
|
|
688
|
+
* Force `PREPARE_TRAINING_DATASET` to reply with an `error` — a
|
|
689
|
+
* {@link BlockPrepareTrainingDatasetHostError} for a host refusal, or any other
|
|
690
|
+
* string for the free-text server-message variant. Absent → it prepares.
|
|
691
|
+
* Live-tunable via {@link MockHost.setScenario}.
|
|
692
|
+
*/
|
|
693
|
+
trainingDatasetError?: BlockPrepareTrainingDatasetHostError | string;
|
|
694
|
+
/**
|
|
695
|
+
* The Buzz total a `kind: 'training'` estimate quotes. Default `500`. Above
|
|
696
|
+
* `BLOCK_TRAINING_MAX_BUZZ_PER_RUN` (5,000) the estimate fails exactly as the
|
|
697
|
+
* server's does. The run's terminal snapshot reports this as its `cost`.
|
|
698
|
+
* Live-tunable via {@link MockHost.setScenario}.
|
|
699
|
+
*/
|
|
700
|
+
trainingQuoteTotal?: number;
|
|
701
|
+
/**
|
|
702
|
+
* Force `RUN_TRAINING` to reply with an `error` instead of starting a run — a
|
|
703
|
+
* {@link BlockRunTrainingHostError} (`'declined'`: the viewer dismissed the
|
|
704
|
+
* dialog, no run; `'submission-unconfirmed'`: the run MAY exist) or any other
|
|
705
|
+
* string for a server message. Absent → the run starts.
|
|
706
|
+
*
|
|
707
|
+
* Whether the QUOTE survives follows the real flow: the host's own gate and
|
|
708
|
+
* dialog codes (`declined`, `review-mode`, `block is not ready`, `sign in to
|
|
709
|
+
* train`, `invalid training request`, `no block token`) settle before the
|
|
710
|
+
* server claims the quote, so it stays runnable; `submission-unconfirmed` and
|
|
711
|
+
* any server message settle after the claim, so it is used up — re-running it
|
|
712
|
+
* gets the quote-gone error. Live-tunable via {@link MockHost.setScenario};
|
|
713
|
+
* `undefined` clears it.
|
|
714
|
+
*
|
|
715
|
+
* 🔴 Same real gap as {@link createPostError}: the consent dialog is HOST
|
|
716
|
+
* chrome, so the mock settles immediately where the real host waits on a click.
|
|
717
|
+
*/
|
|
718
|
+
runTrainingError?: BlockRunTrainingHostError | string;
|
|
719
|
+
/**
|
|
720
|
+
* Make `RUN_TRAINING` resolve the server's spend-cap or temporary-availability
|
|
721
|
+
* refusal instead of a run:
|
|
722
|
+
* a snapshot `{ workflowId: 'failed', status: 'failed', cost: { total: <quote> },
|
|
723
|
+
* error: <this string> }` — the shape the real training submit returns when
|
|
724
|
+
* the viewer's daily / private-run Buzz cap, the per-app consent budget, the
|
|
725
|
+
* app's spend or rate limit (or its "temporarily unavailable" deny), or a
|
|
726
|
+
* dev-session cap stops the run (refunded, no run). `useRunTraining()` rejects
|
|
727
|
+
* it with `.refused`. Pass the server's text, e.g. `'daily Buzz cap reached: …'`.
|
|
728
|
+
* 🔴 The quote is CONSUMED, as on the server (it is claimed before the cap
|
|
729
|
+
* checks): running the same `quoteId` again gets the quote-gone error — estimate
|
|
730
|
+
* again. Absent → the run starts. Live-tunable via {@link MockHost.setScenario};
|
|
731
|
+
* `setScenario({ runTrainingCapRefusal: undefined })` clears it.
|
|
732
|
+
*/
|
|
733
|
+
runTrainingCapRefusal?: string;
|
|
590
734
|
/**
|
|
591
735
|
* Buzz pools a `SUBMIT_WORKFLOW` must REJECT when named in `body.accountType`
|
|
592
736
|
* — simulates the real backend's content-rating clamp. The real host throws a
|
|
@@ -751,7 +895,7 @@ export interface MockHostOptions {
|
|
|
751
895
|
* {@link MockHost.setTheme}, which pushes a real `THEME_CHANGE` — the mock of
|
|
752
896
|
* the viewer toggling dark mode with the block already mounted.)
|
|
753
897
|
*/
|
|
754
|
-
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' | 'appWorkflows' | 'appWorkflowsError' | 'publishImageIds' | 'publishError' | 'gatedImages' | 'gatedImagesError' | 'disallowedAccountTypes'>;
|
|
898
|
+
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'>;
|
|
755
899
|
/** Runtime Buzz-balance handle exposed on {@link MockHost.buzz}. */
|
|
756
900
|
export interface MockBuzzHandle {
|
|
757
901
|
/** Current simulated balance, or `undefined` when balance isn't simulated. */
|