@civitai/app-sdk 0.98.0 → 0.99.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 +26 -9
- package/dist/blocks/index.js +2 -1
- package/dist/blocks/nestedDocument.d.ts +18 -13
- package/dist/blocks/nestedDocument.js +21 -15
- package/dist/blocks/types.d.ts +33 -0
- package/dist/safe-storage/index.d.ts +6 -5
- package/dist/safe-storage/index.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -363,6 +363,16 @@ flag `app-blocks-confirmed-step` (off by default), and refused for development,
|
|
|
363
363
|
review tokens — so it is exercised against the mock host, not `dev:live`. Use it through
|
|
364
364
|
`@civitai/blocks-react`'s `useRunConfirmedStep()`.
|
|
365
365
|
|
|
366
|
+
**Over budget: `overBudget` and `budget`.** A pass-through `step` or `kind: 'workflow'` estimate
|
|
367
|
+
whose submit is certain to be refused for budget (`insufficient buzz budget`) carries
|
|
368
|
+
`snapshot.overBudget: true` and `snapshot.budget`, the limit it was judged against (the
|
|
369
|
+
per-call budget for a step, the whole-workflow ceiling for a workflow). It is still a priced
|
|
370
|
+
estimate; show it beside the price and do not offer to spend. The fields are omitted when the job
|
|
371
|
+
fits, when a `stepQuote` applies, and on hosts that predate civitai/civitai#10971. A page app's
|
|
372
|
+
per-call budget comes from its manifest's `page.buzzBudgetPerGen`, clamped to the platform cap
|
|
373
|
+
(5,000): declare it well above the largest single job the app submits. A step above that cap, or a
|
|
374
|
+
`kind: 'workflow'` above its per-call limit, cannot run from an app whatever the manifest declares.
|
|
375
|
+
|
|
366
376
|
**3D outputs.** A step that produces 3D models (`polyGen`) still lists every model url in
|
|
367
377
|
`snapshot.imageUrls`; `snapshot.model3dOutputs` (and the same field on an `AppWorkflow` row)
|
|
368
378
|
labels them. Omitted when there are none.
|
|
@@ -541,10 +551,15 @@ this plugin is the only way the manifest reaches `@civitai/sdk`.
|
|
|
541
551
|
|
|
542
552
|
### Web storage in a block (`@civitai/app-sdk/safe-storage`)
|
|
543
553
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
554
|
+
A published block is framed at its own origin, `https://<blockId>.civit.ai`
|
|
555
|
+
(on its run page, at its version path `/v/<sha>/`), where web storage, IndexedDB and the rest
|
|
556
|
+
work normally, scoped to the app
|
|
557
|
+
([Frame origin and browser storage](https://developer.civitai.com/apps/guide/concepts#frame-origin)).
|
|
558
|
+
Some frames are still sandboxed **without `allow-same-origin`**: an unverified block that
|
|
559
|
+
declares an `apps:storage:shared:*` scope, and the frame a moderator reviews a
|
|
560
|
+
block in. There the document has an *opaque origin* (`self.origin === 'null'`),
|
|
561
|
+
there is no origin to key web storage against, and the platform doesn't hand
|
|
562
|
+
back an empty store — merely **reading** the property throws:
|
|
548
563
|
|
|
549
564
|
```
|
|
550
565
|
SecurityError: Failed to read the 'localStorage' property from 'Window':
|
|
@@ -583,7 +598,8 @@ round-trip probe shows they're unusable. Rules:
|
|
|
583
598
|
revoked `Proxy` or a throwing getter sitting on `localStorage` is classified,
|
|
584
599
|
not propagated.
|
|
585
600
|
- The fallback is **session-scoped** — nothing survives a reload. That's the
|
|
586
|
-
honest semantic at an opaque origin.
|
|
601
|
+
honest semantic at an opaque origin. Even at a real origin, treat storage as a
|
|
602
|
+
cache (browsers may evict it); use the
|
|
587
603
|
document store (`app.storage.collection(name)` in `@civitai/sdk`) for anything
|
|
588
604
|
durable.
|
|
589
605
|
|
|
@@ -612,9 +628,10 @@ if you want the standalone `Storage` work-alike.
|
|
|
612
628
|
### Nested documents
|
|
613
629
|
|
|
614
630
|
🔴 **A nested `<iframe src="…">` pointing at your own bundled content cannot
|
|
615
|
-
load, and no manifest change fixes it** —
|
|
616
|
-
|
|
617
|
-
serves
|
|
631
|
+
load, and no manifest change fixes it** — the static host stamps
|
|
632
|
+
`frame-ancestors` (Civitai's own sites only) + `X-Frame-Options` on every path
|
|
633
|
+
it serves, so a frame whose ancestors include your block's origin, opaque or
|
|
634
|
+
real, is refused. The full derivation, the dated external browser matrix (an
|
|
618
635
|
observation of the platform — nothing in this repo verifies it) and the known
|
|
619
636
|
limits
|
|
620
637
|
are in one place: the header of
|
|
@@ -625,7 +642,7 @@ Phaser) is a `<canvas>` plus a JS loader that normally mounts straight into the
|
|
|
625
642
|
document you hand it, which avoids the whole problem class.
|
|
626
643
|
|
|
627
644
|
When a separate document is genuinely required, fetch it and inline it as the
|
|
628
|
-
iframe's `srcdoc` — that frame
|
|
645
|
+
iframe's `srcdoc` — that frame (opaque when sandboxed, as below) carries no
|
|
629
646
|
response headers of its own:
|
|
630
647
|
|
|
631
648
|
```ts
|
package/dist/blocks/index.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* all. Build-time manifest validation lives at `@civitai/app-sdk/manifest`
|
|
9
9
|
* (node-only); see the note on `BlockManifestError` below.
|
|
10
10
|
*/
|
|
11
|
-
// FIRST import, on purpose.
|
|
11
|
+
// FIRST import, on purpose. Some block frames (moderator review; an unverified block that
|
|
12
|
+
// declares an `apps:storage:shared:*` scope) are at an opaque origin (sandbox
|
|
12
13
|
// without `allow-same-origin`), where touching `localStorage`/`sessionStorage`
|
|
13
14
|
// THROWS — including from third-party dependencies nobody can guard from the
|
|
14
15
|
// outside. Importing this repairs those globals before anything else in the
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
* bundled content by URL. Neither is a bug, and neither has a manifest-side
|
|
9
9
|
* workaround:
|
|
10
10
|
*
|
|
11
|
-
* 1. A block
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* 1. A block cannot declare `allow-same-origin` (refused at `civitai app
|
|
12
|
+
* validate` time, "forbidden outside the internal trust tier", and
|
|
13
|
+
* re-stripped host-side); the HOST decides it. A published block is now
|
|
14
|
+
* framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
|
|
15
|
+
* review frame, and an unverified block that declares an
|
|
16
|
+
* `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
|
|
17
17
|
*
|
|
18
18
|
* 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
|
|
19
19
|
* `.wasm`, archive files, all of it — carries
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
* then URL-parses it, and the string `"null"` fails that parse, returning
|
|
28
28
|
* Blocked before any source matching happens. So widening the allowlist cannot
|
|
29
29
|
* fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
|
|
30
|
-
* own.
|
|
30
|
+
* own. At a REAL origin the result is the same by derivation, NOT by the
|
|
31
|
+
* measurement below (which covers the opaque case only): the platform's
|
|
32
|
+
* `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
|
|
33
|
+
* block as an ancestor fails it.
|
|
31
34
|
*
|
|
32
35
|
* 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
|
|
33
36
|
* BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
|
|
@@ -56,11 +59,13 @@
|
|
|
56
59
|
* WHAT THIS MODULE DOES
|
|
57
60
|
* =====================
|
|
58
61
|
* The one thing that works: fetch the nested document's HTML (the static host
|
|
59
|
-
* sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch`
|
|
60
|
-
* where a frame load does not
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* its own, so neither
|
|
62
|
+
* sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
|
|
63
|
+
* succeeds where a frame load does not; from a published block's real origin
|
|
64
|
+
* the fetch of its own document is same-origin), rewrite its base URL to the
|
|
65
|
+
* absolute location it was fetched from, and hand the string to an iframe's
|
|
66
|
+
* `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
|
|
67
|
+
* policy applies to it. Its origin is the parent's only if it is not sandboxed:
|
|
68
|
+
* with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
|
|
64
69
|
*
|
|
65
70
|
* 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
|
|
66
71
|
* …) is a `<canvas>` plus a JS loader and normally mounts straight into the
|
|
@@ -152,7 +157,7 @@ export interface InjectBaseHrefResult {
|
|
|
152
157
|
*
|
|
153
158
|
* This is the whole mechanism, and the reason it is a separate function with
|
|
154
159
|
* tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
|
|
155
|
-
* inherits the embedder's
|
|
160
|
+
* inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
|
|
156
161
|
* `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
|
|
157
162
|
* missing `<base>` breaks every relative load in the document **with no error
|
|
158
163
|
* naming the base**, which is why it is pinned by its own test.
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
* bundled content by URL. Neither is a bug, and neither has a manifest-side
|
|
9
9
|
* workaround:
|
|
10
10
|
*
|
|
11
|
-
* 1. A block
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* 1. A block cannot declare `allow-same-origin` (refused at `civitai app
|
|
12
|
+
* validate` time, "forbidden outside the internal trust tier", and
|
|
13
|
+
* re-stripped host-side); the HOST decides it. A published block is now
|
|
14
|
+
* framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
|
|
15
|
+
* review frame, and an unverified block that declares an
|
|
16
|
+
* `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
|
|
17
17
|
*
|
|
18
18
|
* 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
|
|
19
19
|
* `.wasm`, archive files, all of it — carries
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
* then URL-parses it, and the string `"null"` fails that parse, returning
|
|
28
28
|
* Blocked before any source matching happens. So widening the allowlist cannot
|
|
29
29
|
* fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
|
|
30
|
-
* own.
|
|
30
|
+
* own. At a REAL origin the result is the same by derivation, NOT by the
|
|
31
|
+
* measurement below (which covers the opaque case only): the platform's
|
|
32
|
+
* `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
|
|
33
|
+
* block as an ancestor fails it.
|
|
31
34
|
*
|
|
32
35
|
* 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
|
|
33
36
|
* BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
|
|
@@ -56,11 +59,13 @@
|
|
|
56
59
|
* WHAT THIS MODULE DOES
|
|
57
60
|
* =====================
|
|
58
61
|
* The one thing that works: fetch the nested document's HTML (the static host
|
|
59
|
-
* sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch`
|
|
60
|
-
* where a frame load does not
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* its own, so neither
|
|
62
|
+
* sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
|
|
63
|
+
* succeeds where a frame load does not; from a published block's real origin
|
|
64
|
+
* the fetch of its own document is same-origin), rewrite its base URL to the
|
|
65
|
+
* absolute location it was fetched from, and hand the string to an iframe's
|
|
66
|
+
* `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
|
|
67
|
+
* policy applies to it. Its origin is the parent's only if it is not sandboxed:
|
|
68
|
+
* with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
|
|
64
69
|
*
|
|
65
70
|
* 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
|
|
66
71
|
* …) is a `<canvas>` plus a JS loader and normally mounts straight into the
|
|
@@ -125,7 +130,7 @@ export class NestedDocumentError extends Error {
|
|
|
125
130
|
*
|
|
126
131
|
* This is the whole mechanism, and the reason it is a separate function with
|
|
127
132
|
* tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
|
|
128
|
-
* inherits the embedder's
|
|
133
|
+
* inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
|
|
129
134
|
* `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
|
|
130
135
|
* missing `<base>` breaks every relative load in the document **with no error
|
|
131
136
|
* naming the base**, which is why it is pinned by its own test.
|
|
@@ -248,8 +253,9 @@ export async function fetchNestedDocument(options) {
|
|
|
248
253
|
// meaning what it means.
|
|
249
254
|
if (options.signal?.aborted)
|
|
250
255
|
throw cause;
|
|
251
|
-
throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A
|
|
252
|
-
'
|
|
256
|
+
throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A URL cross-origin to the block's frame ` +
|
|
257
|
+
'(every URL, in an opaque-origin frame) needs the host to answer with ' +
|
|
258
|
+
'Access-Control-Allow-Origin.', { code: 'network-error', url, cause });
|
|
253
259
|
}
|
|
254
260
|
if (!response.ok) {
|
|
255
261
|
throw new NestedDocumentError(`fetchNestedDocument: ${url} returned HTTP ${response.status}.`, { code: 'http-error', url, status: response.status });
|
package/dist/blocks/types.d.ts
CHANGED
|
@@ -2628,6 +2628,39 @@ export interface BlockWorkflowSnapshot {
|
|
|
2628
2628
|
* it the run is refused and you estimate again. A quote is single-use.
|
|
2629
2629
|
*/
|
|
2630
2630
|
stepQuote?: BlockStepQuote;
|
|
2631
|
+
/**
|
|
2632
|
+
* `true` on an ESTIMATE whose submit is certain to be refused for budget:
|
|
2633
|
+
* `cost.total` is above {@link BlockWorkflowSnapshot.budget}, the limit the
|
|
2634
|
+
* submit compares it with (or the token has no budget at all), and no
|
|
2635
|
+
* {@link BlockWorkflowSnapshot.stepQuote} applies. The estimate is still a
|
|
2636
|
+
* priced snapshot that resolves; show this beside the price and do not offer
|
|
2637
|
+
* to spend — the submit would refuse the job with `insufficient buzz budget`.
|
|
2638
|
+
*
|
|
2639
|
+
* Set by the pass-through `step` estimate ({@link WorkflowBodyPassThroughStep})
|
|
2640
|
+
* and the `kind: 'workflow'` estimate ({@link WorkflowBodyWorkflow}). OMITTED
|
|
2641
|
+
* when the job fits, on every other kind, and on hosts that predate
|
|
2642
|
+
* civitai/civitai#10971 — so absent means "not known to be over", never a
|
|
2643
|
+
* guarantee the submit passes.
|
|
2644
|
+
*
|
|
2645
|
+
* A batch-estimate cell never carries a `stepQuote`, so a cell can say
|
|
2646
|
+
* `overBudget` for a fixed-price job that a single estimate would return as a
|
|
2647
|
+
* viewer-confirmable `stepQuote` instead.
|
|
2648
|
+
*
|
|
2649
|
+
* A page app's per-call budget comes from its manifest's
|
|
2650
|
+
* `page.buzzBudgetPerGen`, clamped to the platform cap (5,000): declare it
|
|
2651
|
+
* well above the largest single job the app submits. A step above that cap,
|
|
2652
|
+
* or a `kind: 'workflow'` above its per-call limit, cannot run from an app
|
|
2653
|
+
* whatever the manifest declares.
|
|
2654
|
+
*/
|
|
2655
|
+
overBudget?: true;
|
|
2656
|
+
/**
|
|
2657
|
+
* The limit {@link BlockWorkflowSnapshot.overBudget} was judged against, as
|
|
2658
|
+
* the submit's gate computes it: the token's per-call budget for a
|
|
2659
|
+
* pass-through `step`, and the whole-workflow ceiling (per-call budget ×
|
|
2660
|
+
* steps, bounded) for `kind: 'workflow'`. `0` when the token has no budget.
|
|
2661
|
+
* Present only with `overBudget`.
|
|
2662
|
+
*/
|
|
2663
|
+
budget?: number;
|
|
2631
2664
|
/**
|
|
2632
2665
|
* What each 3D model in {@link BlockWorkflowSnapshot.imageUrls} IS — one label
|
|
2633
2666
|
* per model a pass-through step produced (e.g. `polyGen`).
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
|
|
8
8
|
* until it is applied there too.
|
|
9
9
|
*
|
|
10
|
-
* Civitai
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* A published Civitai App runs at its own origin, where web storage works.
|
|
11
|
+
* Some frames (moderator review; an unverified block that declares an
|
|
12
|
+
* `apps:storage:shared:*` scope) are still sandboxed WITHOUT
|
|
13
|
+
* `allow-same-origin`. Such a document has an **opaque origin**, and there is
|
|
14
|
+
* no origin to key web storage against, so the platform does not merely return
|
|
15
|
+
* an empty store — merely *reading* the property throws:
|
|
15
16
|
*
|
|
16
17
|
* SecurityError: Failed to read the 'localStorage' property from 'Window':
|
|
17
18
|
* The document is sandboxed and lacks the 'allow-same-origin' flag.
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
|
|
8
8
|
* until it is applied there too.
|
|
9
9
|
*
|
|
10
|
-
* Civitai
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* A published Civitai App runs at its own origin, where web storage works.
|
|
11
|
+
* Some frames (moderator review; an unverified block that declares an
|
|
12
|
+
* `apps:storage:shared:*` scope) are still sandboxed WITHOUT
|
|
13
|
+
* `allow-same-origin`. Such a document has an **opaque origin**, and there is
|
|
14
|
+
* no origin to key web storage against, so the platform does not merely return
|
|
15
|
+
* an empty store — merely *reading* the property throws:
|
|
15
16
|
*
|
|
16
17
|
* SecurityError: Failed to read the 'localStorage' property from 'Window':
|
|
17
18
|
* The document is sandboxed and lacks the 'allow-same-origin' flag.
|
package/package.json
CHANGED