@civitai/blocks-react 0.10.0 → 0.11.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.
@@ -0,0 +1,127 @@
1
+ /**
2
+ * `createLiveHost` — the LIVE sibling of {@link createMockHost}.
3
+ *
4
+ * Where `createMockHost` SYNTHESIZES every reply (no network, no real Buzz),
5
+ * `createLiveHost` FORWARDS the App-Block postMessage protocol to the REAL
6
+ * Civitai backend using a short-lived, pasted dev block token (minted via
7
+ * `POST /api/v1/blocks/dev-token`, scope doc §3 Option A). It lets `dev:live`
8
+ * run local block code against real compute / real Buzz / the real catalog —
9
+ * Phase 2 of claudedocs/app-blocks-dev-token-endpoint-scope.md (§5.2).
10
+ *
11
+ * It returns the SAME {@link MockHost} interface as `createMockHost` (so a
12
+ * harness can swap them), but `setScenario` / `buzz` are inert no-ops here —
13
+ * there are no synthetic scenarios in live mode (the backend is the source of
14
+ * truth).
15
+ *
16
+ * Mechanism (mirrors `createMockHost`):
17
+ * 1. Patches `window.parent.postMessage` via `Object.defineProperty` so the
18
+ * block's OUTBOUND messages are intercepted.
19
+ * 2. Replies as `MessageEvent`s fired from `window.location.origin` — the SDK
20
+ * `IframeTransport` DROPS any inbound message whose `origin` ≠ the allowed
21
+ * parent origin, so a block using this in dev MUST allow
22
+ * `window.location.origin` (same requirement as the mock host).
23
+ * 3. On mount, fetches `/api/v1/blocks/me` (Bearer = the dev token) for the
24
+ * viewer, decodes the token JWT payload for the block identity / scopes /
25
+ * budget / maturity, and dispatches `BLOCK_INIT`.
26
+ *
27
+ * REAL NETWORK, REAL MONEY: unlike the mock host, this calls `fetch`. The only
28
+ * network it does is (a) `GET /api/v1/blocks/me` and (b) the four
29
+ * `blocks.{estimate,submit,poll,cancel}Workflow` tRPC mutations — each with the
30
+ * Bearer dev token. A successful submit SPENDS the dev's OWN real Buzz against
31
+ * real compute. The token's per-call budget + the per-user daily cap are the
32
+ * server-side bounds (scope doc §4).
33
+ *
34
+ * SCOPE — live v1 deliberately does NOT support: pickers
35
+ * (OPEN_CHECKPOINT_PICKER / OPEN_RESOURCE_PICKER), SET_USER_CHECKPOINT, the
36
+ * App-Storage KV protocol, and an in-band Buzz purchase. Each of those replies
37
+ * with a clearly-labelled "not supported in live v1" outcome (never a fabricated
38
+ * success) and logs once. Use mock mode for those flows, or a later live
39
+ * version. See the per-message handlers below.
40
+ */
41
+ import { type BlockContext, type ColorDomain, type Theme, type ViewerInfo } from '@civitai/app-sdk/blocks';
42
+ import type { MockHost } from './mockHost.js';
43
+ /**
44
+ * Options for {@link createLiveHost}. Mirrors the {@link MockHost}-relevant
45
+ * subset of `MockHostOptions`, plus the live-only `blockToken` / `backendBaseUrl`
46
+ * / `fetchImpl`.
47
+ */
48
+ export interface LiveHostOptions {
49
+ /**
50
+ * The PASTED dev block token — a short-lived RS256 JWT minted by
51
+ * `POST /api/v1/blocks/dev-token`. v1 echoes this token on `REQUEST_TOKEN`
52
+ * (no auto-refresh); when it expires (~15min) the dev re-mints + restarts.
53
+ * VITE_-bundled, so it must be SHORT-LIVED — never an API key (scope §5.1).
54
+ */
55
+ blockToken: string;
56
+ /** Backend base URL the protocol forwards to. Default `https://civitai.com`. */
57
+ backendBaseUrl?: string;
58
+ /**
59
+ * Override the viewer used in `BLOCK_INIT` instead of fetching
60
+ * `/api/v1/blocks/me`. When omitted the host fetches the real viewer (and
61
+ * falls back to a minimal anon-ish viewer if that fetch fails).
62
+ */
63
+ viewer?: ViewerInfo | null;
64
+ /** Host theme delivered in `BLOCK_INIT` + context. Default `'dark'`. */
65
+ theme?: Theme;
66
+ /**
67
+ * The `BLOCK_INIT` context. Defaults to a PAGE context (`{ slotId: 'app.page' }`),
68
+ * since dev-token mints PAGE tokens only.
69
+ */
70
+ context?: BlockContext;
71
+ /**
72
+ * Called with every intercepted OUTBOUND message — lets a harness UI render a
73
+ * message log (same hook as the mock host's `onOutbound`).
74
+ */
75
+ onOutbound?: (msg: {
76
+ type: string;
77
+ payload?: unknown;
78
+ }) => void;
79
+ /** Override `window`. Defaults to `globalThis.window`. */
80
+ window?: Window & typeof globalThis;
81
+ /**
82
+ * Injectable `fetch` (tests pass a mock). Defaults to the global `fetch`.
83
+ */
84
+ fetchImpl?: typeof fetch;
85
+ }
86
+ /**
87
+ * Decoded payload of a block-token JWT (the claims `BlockTokenService.sign`
88
+ * stamps — see civitai `block-token.service.ts`). Everything is optional/unknown
89
+ * because the token is dev-pasted: we decode it WITHOUT signature verification
90
+ * (that's the server's job at the API boundary), purely to seed `BLOCK_INIT`.
91
+ */
92
+ interface DecodedBlockTokenPayload {
93
+ blockId?: string;
94
+ appId?: string;
95
+ appBlockId?: string;
96
+ blockInstanceId?: string;
97
+ ctx?: Record<string, unknown>;
98
+ scopes?: string[];
99
+ buzzBudget?: number;
100
+ maxBrowsingLevel?: number;
101
+ domain?: ColorDomain | null;
102
+ sub?: string;
103
+ /** Unix seconds. */
104
+ exp?: number;
105
+ }
106
+ /**
107
+ * Decode the middle (payload) segment of a JWT (base64url) WITHOUT verifying
108
+ * the signature — client-side we only need the claims to build BLOCK_INIT; the
109
+ * server re-verifies the signature on every API call. Returns `{}` on any
110
+ * malformed input (never throws).
111
+ */
112
+ export declare function decodeBlockTokenPayload(token: string): DecodedBlockTokenPayload;
113
+ /**
114
+ * Create a LIVE host that forwards the App-Block postMessage protocol to the
115
+ * real Civitai backend. Returns the same {@link MockHost} interface as
116
+ * {@link createMockHost} (so a harness can swap them); `setScenario` / `buzz`
117
+ * are no-ops (there are no synthetic scenarios in live mode).
118
+ *
119
+ * @example
120
+ * const host = createLiveHost({ blockToken: import.meta.env.VITE_LIVE_BLOCK_TOKEN });
121
+ * const uninstall = host.install();
122
+ * // … drive the block against the REAL backend (real Buzz!) …
123
+ * uninstall();
124
+ */
125
+ export declare function createLiveHost(options: LiveHostOptions): MockHost;
126
+ export {};
127
+ //# sourceMappingURL=liveHost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveHost.d.ts","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C,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,wBAAwB,CAgB/E;AA4DD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAgejE"}
@@ -0,0 +1,599 @@
1
+ /**
2
+ * `createLiveHost` — the LIVE sibling of {@link createMockHost}.
3
+ *
4
+ * Where `createMockHost` SYNTHESIZES every reply (no network, no real Buzz),
5
+ * `createLiveHost` FORWARDS the App-Block postMessage protocol to the REAL
6
+ * Civitai backend using a short-lived, pasted dev block token (minted via
7
+ * `POST /api/v1/blocks/dev-token`, scope doc §3 Option A). It lets `dev:live`
8
+ * run local block code against real compute / real Buzz / the real catalog —
9
+ * Phase 2 of claudedocs/app-blocks-dev-token-endpoint-scope.md (§5.2).
10
+ *
11
+ * It returns the SAME {@link MockHost} interface as `createMockHost` (so a
12
+ * harness can swap them), but `setScenario` / `buzz` are inert no-ops here —
13
+ * there are no synthetic scenarios in live mode (the backend is the source of
14
+ * truth).
15
+ *
16
+ * Mechanism (mirrors `createMockHost`):
17
+ * 1. Patches `window.parent.postMessage` via `Object.defineProperty` so the
18
+ * block's OUTBOUND messages are intercepted.
19
+ * 2. Replies as `MessageEvent`s fired from `window.location.origin` — the SDK
20
+ * `IframeTransport` DROPS any inbound message whose `origin` ≠ the allowed
21
+ * parent origin, so a block using this in dev MUST allow
22
+ * `window.location.origin` (same requirement as the mock host).
23
+ * 3. On mount, fetches `/api/v1/blocks/me` (Bearer = the dev token) for the
24
+ * viewer, decodes the token JWT payload for the block identity / scopes /
25
+ * budget / maturity, and dispatches `BLOCK_INIT`.
26
+ *
27
+ * REAL NETWORK, REAL MONEY: unlike the mock host, this calls `fetch`. The only
28
+ * network it does is (a) `GET /api/v1/blocks/me` and (b) the four
29
+ * `blocks.{estimate,submit,poll,cancel}Workflow` tRPC mutations — each with the
30
+ * Bearer dev token. A successful submit SPENDS the dev's OWN real Buzz against
31
+ * real compute. The token's per-call budget + the per-user daily cap are the
32
+ * server-side bounds (scope doc §4).
33
+ *
34
+ * SCOPE — live v1 deliberately does NOT support: pickers
35
+ * (OPEN_CHECKPOINT_PICKER / OPEN_RESOURCE_PICKER), SET_USER_CHECKPOINT, the
36
+ * App-Storage KV protocol, and an in-band Buzz purchase. Each of those replies
37
+ * with a clearly-labelled "not supported in live v1" outcome (never a fabricated
38
+ * success) and logs once. Use mock mode for those flows, or a later live
39
+ * version. See the per-message handlers below.
40
+ */
41
+ /** Default civitai backend the live host forwards to. */
42
+ const DEFAULT_BACKEND_BASE_URL = 'https://civitai.com';
43
+ /** Page slot id — dev-token mints page tokens (mirrors PAGE_SLOT_ID server-side). */
44
+ const PAGE_SLOT_ID = 'app.page';
45
+ /** The budgeted-spend scope the workflow procedures require. */
46
+ const BUDGETED_SCOPE = 'ai:write:budgeted';
47
+ const NOT_SUPPORTED_STORAGE = 'app-storage not supported in live v1 yet';
48
+ const NOT_SUPPORTED_PICKER = 'picker not supported in live v1 (use mock mode or v1.1)';
49
+ const NOT_SUPPORTED_USER_CHECKPOINT = 'not supported in live v1';
50
+ /**
51
+ * Decode the middle (payload) segment of a JWT (base64url) WITHOUT verifying
52
+ * the signature — client-side we only need the claims to build BLOCK_INIT; the
53
+ * server re-verifies the signature on every API call. Returns `{}` on any
54
+ * malformed input (never throws).
55
+ */
56
+ export function decodeBlockTokenPayload(token) {
57
+ try {
58
+ const parts = token.split('.');
59
+ if (parts.length < 2)
60
+ return {};
61
+ const payloadSeg = parts[1];
62
+ if (!payloadSeg)
63
+ return {};
64
+ // base64url → base64
65
+ const b64 = payloadSeg.replace(/-/g, '+').replace(/_/g, '/');
66
+ const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4);
67
+ const json = base64urlDecode(padded);
68
+ const parsed = JSON.parse(json);
69
+ if (typeof parsed !== 'object' || parsed === null)
70
+ return {};
71
+ return parsed;
72
+ }
73
+ catch {
74
+ return {};
75
+ }
76
+ }
77
+ /** base64 → utf-8 string, working in both browser (atob) + node (Buffer). */
78
+ function base64urlDecode(b64) {
79
+ if (typeof atob === 'function') {
80
+ // atob → binary string; decode as UTF-8.
81
+ const bin = atob(b64);
82
+ try {
83
+ const bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));
84
+ return new TextDecoder().decode(bytes);
85
+ }
86
+ catch {
87
+ return bin;
88
+ }
89
+ }
90
+ return Buffer.from(b64, 'base64').toString('utf-8');
91
+ }
92
+ /**
93
+ * Build the {@link WrappedToken} the host sends to the block, from the raw token
94
+ * + its decoded claims. `buzzBudget` is only attached when the token carries the
95
+ * budgeted scope (mirrors the host: it's present only with `ai:write:budgeted`).
96
+ */
97
+ function wrappedTokenFrom(raw, decoded) {
98
+ const scopes = Array.isArray(decoded.scopes) ? decoded.scopes : [];
99
+ const expiresAt = typeof decoded.exp === 'number'
100
+ ? new Date(decoded.exp * 1000).toISOString()
101
+ : new Date(Date.now() + 15 * 60_000).toISOString();
102
+ const hasBudget = scopes.includes(BUDGETED_SCOPE) && typeof decoded.buzzBudget === 'number';
103
+ return {
104
+ raw,
105
+ scopes,
106
+ expiresAt,
107
+ ...(hasBudget ? { buzzBudget: decoded.buzzBudget } : {}),
108
+ };
109
+ }
110
+ /** `true` when the token's `exp` (Unix seconds) is in the past. */
111
+ function isExpired(decoded) {
112
+ return typeof decoded.exp === 'number' && decoded.exp * 1000 < Date.now();
113
+ }
114
+ /**
115
+ * A failed-shape {@link BlockWorkflowSnapshot} the block can recover from. Used
116
+ * when a backend call errors so the block's promise resolves instead of hanging
117
+ * to its 120s timeout. `workflowId` is a non-empty sentinel because the SDK
118
+ * validator drops empty-workflowId snapshots (mirrors the host's failure shape).
119
+ */
120
+ function errorSnapshot(error) {
121
+ return { workflowId: 'failed', status: 'failed', error };
122
+ }
123
+ /**
124
+ * Create a LIVE host that forwards the App-Block postMessage protocol to the
125
+ * real Civitai backend. Returns the same {@link MockHost} interface as
126
+ * {@link createMockHost} (so a harness can swap them); `setScenario` / `buzz`
127
+ * are no-ops (there are no synthetic scenarios in live mode).
128
+ *
129
+ * @example
130
+ * const host = createLiveHost({ blockToken: import.meta.env.VITE_LIVE_BLOCK_TOKEN });
131
+ * const uninstall = host.install();
132
+ * // … drive the block against the REAL backend (real Buzz!) …
133
+ * uninstall();
134
+ */
135
+ export function createLiveHost(options) {
136
+ const maybeWin = options.window ?? globalThis.window;
137
+ if (!maybeWin) {
138
+ throw new Error('createLiveHost: no window available (call from a DOM environment).');
139
+ }
140
+ const win = maybeWin;
141
+ const rawToken = options.blockToken;
142
+ if (!rawToken || typeof rawToken !== 'string') {
143
+ // Non-fatal: the host still installs so the dev sees a clear error in the
144
+ // block, rather than a silently-dead harness.
145
+ // eslint-disable-next-line no-console
146
+ console.error('[createLiveHost] No block token supplied. Set VITE_LIVE_BLOCK_TOKEN to a dev token ' +
147
+ 'minted via POST /api/v1/blocks/dev-token.');
148
+ }
149
+ const baseUrl = (options.backendBaseUrl ?? DEFAULT_BACKEND_BASE_URL).replace(/\/+$/, '');
150
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
151
+ const theme = options.theme ?? 'dark';
152
+ const decoded = decodeBlockTokenPayload(rawToken ?? '');
153
+ if (isExpired(decoded)) {
154
+ // eslint-disable-next-line no-console
155
+ console.error('[createLiveHost] dev token expired — re-mint via POST /api/v1/blocks/dev-token and ' +
156
+ 'update VITE_LIVE_BLOCK_TOKEN. Replying with the expired token anyway; the backend ' +
157
+ 'will 401 (the honest signal).');
158
+ }
159
+ // One-time "not supported in live v1" log gating per capability.
160
+ const loggedOnce = new Set();
161
+ const logOnce = (key, message) => {
162
+ if (loggedOnce.has(key))
163
+ return;
164
+ loggedOnce.add(key);
165
+ // eslint-disable-next-line no-console
166
+ console.warn(`[createLiveHost] ${message}`);
167
+ };
168
+ /** POST a tRPC mutation (superjson, non-batched httpLink shape). */
169
+ async function callTrpcMutation(procedure, input) {
170
+ if (!fetchImpl)
171
+ return { error: 'no fetch available' };
172
+ try {
173
+ const res = await fetchImpl(`${baseUrl}/api/trpc/${procedure}`, {
174
+ method: 'POST',
175
+ headers: {
176
+ 'content-type': 'application/json',
177
+ authorization: `Bearer ${rawToken}`,
178
+ },
179
+ // Non-batched httpLink + superjson transformer wraps the input as
180
+ // `{ json: <input> }` (no `meta` for plain JSON inputs). The blocks
181
+ // procedures take `{ blockToken, body? }`.
182
+ body: JSON.stringify({ json: input }),
183
+ });
184
+ const text = await res.text();
185
+ let parsed;
186
+ try {
187
+ parsed = text.length > 0 ? JSON.parse(text) : null;
188
+ }
189
+ catch {
190
+ parsed = null;
191
+ }
192
+ if (!res.ok) {
193
+ const msg = extractTrpcError(parsed) ?? `${procedure} failed: HTTP ${res.status}`;
194
+ return { error: msg };
195
+ }
196
+ const snapshot = extractSnapshot(parsed);
197
+ if (!snapshot) {
198
+ return { error: `${procedure}: malformed response (no snapshot)` };
199
+ }
200
+ return { snapshot };
201
+ }
202
+ catch (err) {
203
+ return { error: err instanceof Error ? err.message : String(err) };
204
+ }
205
+ }
206
+ let installed = false;
207
+ let teardown = () => { };
208
+ function install() {
209
+ if (installed)
210
+ return teardown;
211
+ installed = true;
212
+ const parentOrigin = win.location.origin;
213
+ const originalParent = win.parent;
214
+ const timers = new Set();
215
+ let torn = false;
216
+ const dispatchToBlock = (data) => {
217
+ if (torn)
218
+ return;
219
+ win.dispatchEvent(new MessageEvent('message', { data, origin: parentOrigin }));
220
+ };
221
+ const after = (ms, fn) => {
222
+ const t = setTimeout(() => {
223
+ timers.delete(t);
224
+ fn();
225
+ }, ms);
226
+ timers.add(t);
227
+ };
228
+ /** Resolve the viewer for BLOCK_INIT (real fetch, or the override). */
229
+ async function resolveViewer() {
230
+ if (options.viewer !== undefined)
231
+ return options.viewer;
232
+ if (!fetchImpl)
233
+ return anonFallbackViewer();
234
+ try {
235
+ const res = await fetchImpl(`${baseUrl}/api/v1/blocks/me`, {
236
+ headers: { authorization: `Bearer ${rawToken}` },
237
+ });
238
+ if (!res.ok) {
239
+ // eslint-disable-next-line no-console
240
+ console.warn(`[createLiveHost] /api/v1/blocks/me returned HTTP ${res.status}; using a minimal ` +
241
+ 'anon-ish viewer. Check the dev token is valid + not expired.');
242
+ return anonFallbackViewer();
243
+ }
244
+ const me = (await res.json());
245
+ if (typeof me.id !== 'number')
246
+ return anonFallbackViewer();
247
+ return {
248
+ id: me.id,
249
+ username: me.username ?? null,
250
+ ...(me.status ? { status: me.status } : {}),
251
+ };
252
+ }
253
+ catch (err) {
254
+ // eslint-disable-next-line no-console
255
+ console.warn('[createLiveHost] /api/v1/blocks/me fetch failed; using a minimal anon-ish viewer.', err);
256
+ return anonFallbackViewer();
257
+ }
258
+ }
259
+ /** Dispatch BLOCK_INIT once the viewer is resolved. */
260
+ async function dispatchInit() {
261
+ const viewer = await resolveViewer();
262
+ if (torn)
263
+ return;
264
+ const baseContext = options.context ?? { slotId: PAGE_SLOT_ID };
265
+ const context = { ...baseContext, theme };
266
+ const initPayload = {
267
+ blockInstanceId: decoded.blockInstanceId ?? 'page_live',
268
+ blockId: decoded.blockId ?? 'live-block',
269
+ appId: decoded.appId ?? 'app_dev',
270
+ token: wrappedTokenFrom(rawToken ?? '', decoded),
271
+ context,
272
+ settings: { publisherSettings: {}, userSettings: {} },
273
+ viewer,
274
+ theme,
275
+ renderMode: 'iframe',
276
+ ...(decoded.domain != null ? { domain: decoded.domain } : {}),
277
+ ...(typeof decoded.maxBrowsingLevel === 'number'
278
+ ? { maxBrowsingLevel: decoded.maxBrowsingLevel }
279
+ : {}),
280
+ };
281
+ dispatchToBlock({ type: 'BLOCK_INIT', payload: initPayload });
282
+ }
283
+ const parentMock = {
284
+ postMessage: (msg) => {
285
+ if (typeof msg !== 'object' ||
286
+ msg === null ||
287
+ typeof msg.type !== 'string') {
288
+ return;
289
+ }
290
+ const typed = msg;
291
+ options.onOutbound?.({ type: typed.type, payload: typed.payload });
292
+ const requestId = typed.payload?.requestId;
293
+ switch (typed.type) {
294
+ case 'BLOCK_READY':
295
+ case 'RESIZE_IFRAME':
296
+ // Iframe resize: no host chrome to resize in dev (the harness owns
297
+ // layout). No-op, mirroring the mock host.
298
+ return;
299
+ case 'REQUEST_TOKEN': {
300
+ if (isExpired(decoded)) {
301
+ // eslint-disable-next-line no-console
302
+ console.error('[createLiveHost] REQUEST_TOKEN: dev token is expired — re-mint via ' +
303
+ 'POST /api/v1/blocks/dev-token and update VITE_LIVE_BLOCK_TOKEN. ' +
304
+ 'Replying with the expired token; the backend will 401.');
305
+ }
306
+ // v1 echoes the pasted token (no auto-refresh / re-mint).
307
+ dispatchToBlock({
308
+ type: 'TOKEN_REFRESH_RESPONSE',
309
+ payload: {
310
+ ...(requestId ? { requestId } : {}),
311
+ token: wrappedTokenFrom(rawToken ?? '', decoded),
312
+ },
313
+ });
314
+ return;
315
+ }
316
+ case 'ESTIMATE_WORKFLOW': {
317
+ const body = typed.payload?.body;
318
+ void callTrpcMutation('blocks.estimateWorkflow', { blockToken: rawToken, body }).then((r) => {
319
+ dispatchToBlock({
320
+ type: 'ESTIMATE_RESULT',
321
+ payload: {
322
+ requestId,
323
+ snapshot: r.snapshot ?? errorSnapshot(r.error ?? 'estimate failed'),
324
+ },
325
+ });
326
+ });
327
+ return;
328
+ }
329
+ case 'SUBMIT_WORKFLOW': {
330
+ const body = typed.payload?.body;
331
+ void callTrpcMutation('blocks.submitWorkflow', { blockToken: rawToken, body }).then((r) => {
332
+ dispatchToBlock({
333
+ type: 'WORKFLOW_SUBMITTED',
334
+ payload: {
335
+ requestId,
336
+ snapshot: r.snapshot ?? errorSnapshot(r.error ?? 'submit failed'),
337
+ },
338
+ });
339
+ });
340
+ return;
341
+ }
342
+ case 'POLL_WORKFLOW': {
343
+ const workflowId = typed.payload?.workflowId ?? '';
344
+ void callTrpcMutation('blocks.pollWorkflow', {
345
+ blockToken: rawToken,
346
+ workflowId,
347
+ }).then((r) => {
348
+ dispatchToBlock({
349
+ type: 'WORKFLOW_STATUS',
350
+ payload: {
351
+ requestId,
352
+ snapshot: r.snapshot ?? {
353
+ // A failed poll keeps the workflowId so the block can map
354
+ // it back to the right card.
355
+ workflowId,
356
+ status: 'failed',
357
+ error: r.error ?? 'poll failed',
358
+ },
359
+ },
360
+ });
361
+ });
362
+ return;
363
+ }
364
+ case 'CANCEL_WORKFLOW': {
365
+ const workflowId = typed.payload?.workflowId ?? '';
366
+ void callTrpcMutation('blocks.cancelWorkflow', {
367
+ blockToken: rawToken,
368
+ workflowId,
369
+ }).then((r) => {
370
+ dispatchToBlock({
371
+ type: 'WORKFLOW_CANCELED',
372
+ payload: {
373
+ requestId,
374
+ snapshot: r.snapshot ?? {
375
+ workflowId,
376
+ status: 'canceled',
377
+ error: r.error ?? 'cancel failed',
378
+ },
379
+ },
380
+ });
381
+ });
382
+ return;
383
+ }
384
+ case 'OPEN_BUZZ_PURCHASE': {
385
+ // No headless purchase contract. Deep-link the dev to the real
386
+ // purchase page and reply purchased:false (honest — we can't observe
387
+ // the out-of-band purchase). Do NOT fabricate purchased:true.
388
+ try {
389
+ win.open(`${baseUrl}/purchase/buzz`, '_blank');
390
+ }
391
+ catch {
392
+ /* window.open may be unavailable (tests) — the reply still lands */
393
+ }
394
+ // eslint-disable-next-line no-console
395
+ console.info('[createLiveHost] Opened the Buzz purchase page in a new tab. Complete the ' +
396
+ 'purchase there, then re-estimate / re-submit.');
397
+ dispatchToBlock({
398
+ type: 'BUZZ_PURCHASE_RESULT',
399
+ payload: { requestId: requestId ?? '', purchased: false },
400
+ });
401
+ return;
402
+ }
403
+ case 'OPEN_CHECKPOINT_PICKER': {
404
+ logOnce('checkpoint-picker', NOT_SUPPORTED_PICKER);
405
+ dispatchToBlock({
406
+ type: 'CHECKPOINT_PICKER_RESULT',
407
+ payload: { requestId: requestId ?? '' },
408
+ });
409
+ return;
410
+ }
411
+ case 'OPEN_RESOURCE_PICKER': {
412
+ logOnce('resource-picker', NOT_SUPPORTED_PICKER);
413
+ dispatchToBlock({
414
+ type: 'RESOURCE_PICKER_RESULT',
415
+ payload: { requestId: requestId ?? '' },
416
+ });
417
+ return;
418
+ }
419
+ case 'SET_USER_CHECKPOINT': {
420
+ logOnce('set-user-checkpoint', `SET_USER_CHECKPOINT ${NOT_SUPPORTED_USER_CHECKPOINT}`);
421
+ dispatchToBlock({
422
+ type: 'USER_CHECKPOINT_SET',
423
+ payload: { requestId: requestId ?? '', ok: false, error: NOT_SUPPORTED_USER_CHECKPOINT },
424
+ });
425
+ return;
426
+ }
427
+ case 'APP_STORAGE_GET': {
428
+ logOnce('app-storage', NOT_SUPPORTED_STORAGE);
429
+ dispatchToBlock({
430
+ type: 'APP_STORAGE_GET_RESULT',
431
+ payload: { requestId: requestId ?? '', value: null, error: NOT_SUPPORTED_STORAGE },
432
+ });
433
+ return;
434
+ }
435
+ case 'APP_STORAGE_SET': {
436
+ logOnce('app-storage', NOT_SUPPORTED_STORAGE);
437
+ dispatchToBlock({
438
+ type: 'APP_STORAGE_SET_RESULT',
439
+ payload: { requestId: requestId ?? '', ok: false, error: NOT_SUPPORTED_STORAGE },
440
+ });
441
+ return;
442
+ }
443
+ case 'APP_STORAGE_DELETE': {
444
+ logOnce('app-storage', NOT_SUPPORTED_STORAGE);
445
+ dispatchToBlock({
446
+ type: 'APP_STORAGE_DELETE_RESULT',
447
+ payload: {
448
+ requestId: requestId ?? '',
449
+ ok: false,
450
+ deleted: false,
451
+ error: NOT_SUPPORTED_STORAGE,
452
+ },
453
+ });
454
+ return;
455
+ }
456
+ case 'APP_STORAGE_LIST': {
457
+ logOnce('app-storage', NOT_SUPPORTED_STORAGE);
458
+ dispatchToBlock({
459
+ type: 'APP_STORAGE_LIST_RESULT',
460
+ payload: { requestId: requestId ?? '', keys: [], error: NOT_SUPPORTED_STORAGE },
461
+ });
462
+ return;
463
+ }
464
+ case 'APP_STORAGE_QUOTA': {
465
+ logOnce('app-storage', NOT_SUPPORTED_STORAGE);
466
+ dispatchToBlock({
467
+ type: 'APP_STORAGE_QUOTA_RESULT',
468
+ payload: {
469
+ requestId: requestId ?? '',
470
+ usedBytes: 0,
471
+ rowCount: 0,
472
+ limitBytes: 0,
473
+ limitRows: 0,
474
+ error: NOT_SUPPORTED_STORAGE,
475
+ },
476
+ });
477
+ return;
478
+ }
479
+ case 'NAVIGATE': {
480
+ const path = typed.payload?.path ?? '';
481
+ const target = typed.payload?.target ?? 'current';
482
+ // Resolve relative paths against the backend origin so an in-app
483
+ // path (`/models/123`) opens on the real site.
484
+ const url = /^https?:\/\//i.test(path) ? path : `${baseUrl}${path}`;
485
+ try {
486
+ if (target === 'new_tab') {
487
+ win.open(url, '_blank');
488
+ }
489
+ else {
490
+ win.location.assign(url);
491
+ }
492
+ }
493
+ catch {
494
+ /* navigation may be unavailable (tests) */
495
+ }
496
+ return;
497
+ }
498
+ case 'TRACK_EVENT':
499
+ case 'REQUEST_SIGN_IN':
500
+ case 'REQUEST_CONSENT':
501
+ case 'BLOCK_ERROR':
502
+ // Log + no-op. Consent is implicit in live mode (dev-as-owner; the
503
+ // scopes are already in the token), so there is no withhold / grant
504
+ // round-trip and nothing to re-mint.
505
+ return;
506
+ default:
507
+ return;
508
+ }
509
+ },
510
+ };
511
+ Object.defineProperty(win, 'parent', {
512
+ value: parentMock,
513
+ configurable: true,
514
+ writable: true,
515
+ });
516
+ // Defer one tick so the block's transport listener is registered before
517
+ // BLOCK_INIT fires (mirrors the mock host). The viewer fetch is async; the
518
+ // init lands when it resolves.
519
+ after(0, () => {
520
+ void dispatchInit();
521
+ });
522
+ teardown = () => {
523
+ if (torn)
524
+ return;
525
+ torn = true;
526
+ installed = false;
527
+ for (const t of timers)
528
+ clearTimeout(t);
529
+ timers.clear();
530
+ Object.defineProperty(win, 'parent', {
531
+ value: originalParent,
532
+ configurable: true,
533
+ writable: true,
534
+ });
535
+ };
536
+ return teardown;
537
+ }
538
+ // `setScenario` / `buzz` are inert in live mode — there are no synthetic
539
+ // scenarios (the backend is the source of truth). Kept so the returned object
540
+ // is interchangeable with a `createMockHost` handle.
541
+ const buzzHandle = {
542
+ getBalance: () => undefined,
543
+ setBalance: () => {
544
+ /* no-op in live mode */
545
+ },
546
+ };
547
+ return {
548
+ install,
549
+ setScenario: (_patch) => {
550
+ /* no-op in live mode */
551
+ },
552
+ buzz: buzzHandle,
553
+ };
554
+ }
555
+ /** A minimal anon-ish viewer used when `/api/v1/blocks/me` can't be reached. */
556
+ function anonFallbackViewer() {
557
+ return { id: 0, username: 'dev-live', status: 'active' };
558
+ }
559
+ /**
560
+ * Extract the `snapshot` from a tRPC response. Handles the superjson
561
+ * `{ result: { data: { json: T } } }` envelope AND the transformer-less
562
+ * `{ result: { data: T } }` shape, defensively (mirrors `fetchBuzzAccount`).
563
+ */
564
+ function extractSnapshot(parsed) {
565
+ if (typeof parsed !== 'object' || parsed === null)
566
+ return undefined;
567
+ const result = parsed.result;
568
+ const data = result?.data;
569
+ if (data == null)
570
+ return undefined;
571
+ // superjson: { json: { snapshot } } ; plain: { snapshot }
572
+ const unwrapped = typeof data === 'object' && data !== null && 'json' in data
573
+ ? data.json
574
+ : data;
575
+ if (typeof unwrapped !== 'object' || unwrapped === null)
576
+ return undefined;
577
+ const snapshot = unwrapped.snapshot;
578
+ if (typeof snapshot !== 'object' || snapshot === null)
579
+ return undefined;
580
+ return snapshot;
581
+ }
582
+ /**
583
+ * Extract a human-readable error message from a tRPC error response. tRPC v11
584
+ * error bodies are `{ error: { json: { message } } }` (superjson) or
585
+ * `{ error: { message } }`. Returns undefined when no message is found.
586
+ */
587
+ function extractTrpcError(parsed) {
588
+ if (typeof parsed !== 'object' || parsed === null)
589
+ return undefined;
590
+ const error = parsed.error;
591
+ if (typeof error !== 'object' || error === null)
592
+ return undefined;
593
+ const inner = 'json' in error ? error.json : error;
594
+ if (typeof inner !== 'object' || inner === null)
595
+ return undefined;
596
+ const message = inner.message;
597
+ return typeof message === 'string' ? message : undefined;
598
+ }
599
+ //# sourceMappingURL=liveHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liveHost.js","sourceRoot":"","sources":["../../src/internal/liveHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAeH,yDAAyD;AACzD,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AA2CvD,qFAAqF;AACrF,MAAM,YAAY,GAAG,UAAU,CAAC;AAEhC,gEAAgE;AAChE,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C,MAAM,qBAAqB,GAAG,0CAA0C,CAAC;AACzE,MAAM,oBAAoB,GAAG,yDAAyD,CAAC;AACvF,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AAuBjE;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,EAAE,CAAC;QAChC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,UAAU;YAAE,OAAO,EAAE,CAAC;QAC3B,qBAAqB;QACrB,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;QAC3C,IAAI,OAAO,MAA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IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,IAAI,IAAI;QACzD,CAAC,CAAE,IAA2B,CAAC,IAAI;QACnC,CAAC,CAAC,IAAI,CAAC;IACX,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC1E,MAAM,QAAQ,GAAI,SAAoC,CAAC,QAAQ,CAAC;IAChE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACxE,OAAO,QAAiC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,MAAe;IACvC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,KAAK,GAAI,MAA8B,CAAC,KAAK,CAAC;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,KAAK,GACT,MAAM,IAAI,KAAK,CAAC,CAAC,CAAE,KAA4B,CAAC,IAAI,CAAC,CAAC,CAAE,KAAiC,CAAC;IAC5F,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,OAAO,GAAI,KAA+B,CAAC,OAAO,CAAC;IACzD,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC"}
package/dist/testing.d.ts CHANGED
@@ -17,6 +17,7 @@ import { __resetTransport } from './internal/singleton.js';
17
17
  import { type MockHostOptions } from './internal/mockHost.js';
18
18
  export { __resetTransport as resetTransport };
19
19
  export { createMockHost, readMockHostUrlOptions, type MockHost, type MockHostOptions, type MockHostFailMode, type MockHostScenarioPatch, type MockGenerationScenario, type MockBuzzScenario, type MockBuzzHandle, type MockStorageScenario, type CostSpec, type ImageSpec, type CannedPick, } from './internal/mockHost.js';
20
+ export { createLiveHost, decodeBlockTokenPayload, type LiveHostOptions, } from './internal/liveHost.js';
20
21
  /**
21
22
  * Builds a `MessageEvent` that mimics a parent-frame postMessage so tests can
22
23
  * exercise `IframeTransport.handleMessage` without a real cross-frame setup.
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,IAAI,cAAc,EAAE,CAAC;AAE9C,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAE7E;AAOD;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,sDAAsD;IACtD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,EACtB,QAAQ,EACR,eAAs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;AAED,+FAA+F;AAC/F,eAAO,MAAM,gBAAgB,gBAAU,CAAC"}
package/dist/testing.js CHANGED
@@ -18,6 +18,7 @@ import { __resetTransport } from './internal/singleton.js';
18
18
  import { createMockHost, readMockHostUrlOptions, } from './internal/mockHost.js';
19
19
  export { __resetTransport as resetTransport };
20
20
  export { createMockHost, readMockHostUrlOptions, } from './internal/mockHost.js';
21
+ export { createLiveHost, decodeBlockTokenPayload, } from './internal/liveHost.js';
21
22
  /**
22
23
  * Builds a `MessageEvent` that mimics a parent-frame postMessage so tests can
23
24
  * exercise `IframeTransport.handleMessage` without a real cross-frame setup.
@@ -72,7 +73,11 @@ export function Harness({ children, applyUrlToggles = true, showLog = true, ...o
72
73
  const anon = opts.viewer === null;
73
74
  const theme = opts.theme ?? 'dark';
74
75
  const consent = opts.consentGranted ? 'granted' : 'withheld';
75
- return (_jsxs("div", { "data-harness": "true", style: { position: 'relative', width: '100vw', minHeight: '100dvh' }, children: [_jsx("main", { "data-harness-frame": "true", style: { width: '100%', minHeight: '100%' }, children: children }), showLog && (_jsxs("details", { style: harnessLogStyle, children: [_jsxs("summary", { style: { cursor: 'pointer' }, children: ["DEV HARNESS \u00B7 viewer=", anon ? 'anon' : 'dev-viewer', " \u00B7 consent=", consent, " \u00B7 theme=", theme, " \u00B7 outbound:", outbound.length] }), _jsx("pre", { style: { margin: 0, maxHeight: 200, overflow: 'auto' }, children: outbound.length === 0
76
+ return (_jsxs("div", { "data-harness": "true", style: { position: 'relative', width: '100vw', minHeight: '100dvh' }, children: [_jsx("main", { "data-harness-frame": "true", style: { width: '100%', minHeight: '100%', paddingBottom: showLog ? 56 : 0 }, children: children }), showLog && (
77
+ // pointerEvents:none on the wrapper so the badge's bounding box can't
78
+ // steal clicks from content beneath it; re-enabled on the interactive
79
+ // bits (summary toggles the log; pre is scrollable/selectable).
80
+ _jsxs("details", { style: harnessLogStyle, children: [_jsxs("summary", { style: { cursor: 'pointer', pointerEvents: 'auto' }, children: ["DEV HARNESS \u00B7 viewer=", anon ? 'anon' : 'dev-viewer', " \u00B7 consent=", consent, " \u00B7 theme=", theme, " \u00B7 outbound:", outbound.length] }), _jsx("pre", { style: { margin: 0, maxHeight: 200, overflow: 'auto', pointerEvents: 'auto' }, children: outbound.length === 0
76
81
  ? '// no outbound messages yet'
77
82
  : outbound
78
83
  .map((m, i) => `${i + 1}. ${m.type} ${JSON.stringify(m.payload ?? {})}`)
@@ -85,6 +90,7 @@ const harnessLogStyle = {
85
90
  bottom: 8,
86
91
  right: 8,
87
92
  zIndex: 9999,
93
+ pointerEvents: 'none',
88
94
  maxWidth: 520,
89
95
  background: 'rgba(17,17,17,0.92)',
90
96
  color: '#7fc',
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,IAAI,cAAc,EAAE,CAAC;AAE9C,OAAO,EACL,cAAc,EACd,sBAAsB,GAYvB,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa,EAAE,MAAc;IAC7D,OAAO,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC;AA0BD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,OAAO,CAAC,EACtB,QAAQ,EACR,eAAe,GAAG,IAAI,EACtB,OAAO,GAAG,IAAI,EACd,GAAG,OAAO,EACG;IACb,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,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,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,sBAAa,OAAO,oBAAW,KAAK,uBAC5E,QAAQ,CAAC,MAAM,IACjB,EACV,cAAK,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,YAC/E,QAAQ,CAAC,MAAM,KAAK,CAAC;4BACpB,CAAC,CAAC,6BAA6B;4BAC/B,CAAC,CAAC,QAAQ;iCACL,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;iCACvE,IAAI,CAAC,IAAI,CAAC,GACb,IACE,CACX,IACG,CACP,CAAC;AACJ,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,MAAM,eAAe,GAAG;IACtB,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,GAAG;IACb,UAAU,EAAE,qBAAqB;IACjC,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,yCAAyC;IACrD,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,CAAC;CACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/blocks-react",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "React hooks and iframe transport for Civitai App Blocks. Pairs with @civitai/app-sdk/blocks.",
5
5
  "license": "MIT",
6
6
  "type": "module",