@fias/create-fias-plugin 1.4.3 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fias/create-fias-plugin",
3
- "version": "1.4.3",
3
+ "version": "1.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -179,7 +179,9 @@ import { useFiasDataStore } from '@fias/arche-sdk';
179
179
  function MyComponent() {
180
180
  const dataStore = useFiasDataStore();
181
181
 
182
- // Collection management
182
+ // Collection management. PREFER declaring collections in fias-plugin.json
183
+ // (see "Declaring your collections" below) — createCollection is capped at
184
+ // 10/minute, so scaffolding several at startup can silently lose the tail.
183
185
  await dataStore.createCollection('scores', { userScope: 'user' }); // or 'shared'
184
186
  const collections = await dataStore.listCollections();
185
187
  await dataStore.deleteCollection('scores');
@@ -236,6 +238,24 @@ await dataStore.batch([
236
238
  ]);
237
239
  ```
238
240
 
241
+ ### Declaring your collections (preferred)
242
+
243
+ List the collections your plugin needs in `fias-plugin.json` and the platform creates them once at publish, before your plugin ever runs:
244
+
245
+ ```jsonc
246
+ "collections": [
247
+ { "name": "scores", "scope": "user" },
248
+ { "name": "ledger", "scope": "workspace", "readMinRole": "member" },
249
+ { "name": "recipes", "scope": "shared", "writePolicy": "author", "searchable": { "field": "text" } }
250
+ ]
251
+ ```
252
+
253
+ `scope` is `user` | `shared` | `workspace`. `readMinRole` / `writeMinRole` are workspace-only; `writePolicy` is shared-only; `searchable` names the text field to embed. Same options as `createCollection`, checked by `fias-dev validate` before you publish.
254
+
255
+ Why this and not `createCollection` at startup: the runtime op is capped at **10 per minute** while an arche may hold **50** collections, so a plugin creating several on mount can exceed the cap and lose the rest **with no error** — surfacing later as `COLLECTION_NOT_FOUND` on an unrelated call. Declaring has no such window, and a mistake fails your publish instead of a user's session.
256
+
257
+ Re-publishing is safe: existing collections are left alone, a stricter role floor is applied, a looser one is refused, and a collection you stop declaring is kept (never deleted — it may hold user data). Keep using `createCollection` for collections whose names you only know at runtime.
258
+
239
259
  **Rate limits (per minute):** `put` 120, `get` 300, `query` 60, `delete` 60, `batch` 30, `createCollection` 10
240
260
 
241
261
  **Error handling:** Data store calls can reject on infrastructure errors or limit violations. Always use `try/catch`. Common error codes: `COLLECTION_NOT_FOUND`, `DOCUMENT_TOO_LARGE`, `STORAGE_LIMIT_REACHED`, `RATE_LIMIT`.
@@ -724,6 +744,7 @@ if ('canceled' in picked) {
724
744
  const granted = await userDocs.list(); // all granted docs
725
745
  const { document, content } = await userDocs.get(id, { includeContent: true }); // text docs
726
746
  const { url } = await userDocs.getDownloadUrl(id); // binary docs (images, PDFs)
747
+ const { bytes } = await userDocs.getBytes(id); // raw bytes for PROCESSING binary docs
727
748
  ```
728
749
 
729
750
  **The consent model (what to tell your users):**
@@ -732,7 +753,55 @@ const { url } = await userDocs.getDownloadUrl(id); // binary docs (images, PDFs)
732
753
  - After revocation, `get`/`getDownloadUrl` reject with `DOCUMENT_NOT_FOUND` — handle that path gracefully (drop the document from your UI; do not retry in a loop).
733
754
  - `proprietary`-sensitivity documents are never grantable (they don't even appear in the picker).
734
755
  - Every read is audited by the platform; a new document _version_ is a new documentId, so a re-pick is needed after the user replaces a document.
735
- - Not available in the builder preview or the dev harness — `pick()` resolves `{ canceled: true }` there. Test the flow in the published plugin with your own documents.
756
+ - `getDownloadUrl` is for DISPLAY (`<img src>`); your iframe cannot fetch the URL (CSP). To process binary content (parse a PDF, transform an image), use `getBytes(id)` — size-capped at 15 MB (`CONSENTED_DOCUMENT_TOO_LARGE` names the cap; ask the user to open the file manually instead). `getBytes` has a tighter per-minute budget than the rest of the family because it can move megabytes: read sequentially, and surface a rate-limit error rather than retrying in a loop.
757
+ - Revocation behaves differently per method: `getBytes` and `get` re-check the grant on every call, so they start failing immediately. A URL already handed out by `getDownloadUrl` keeps working until it expires (1 hour) — that is the documented contract, not a bug.
758
+ - **Testable in the dev harness (mock mode).** `pick()` grants a small fixture set — a text file, a real PDF, and one deliberately over the 15 MB cap — and `list` / `get` / `getDownloadUrl` / `getBytes` all resolve against it, including the refusals (`BINARY_DOCUMENT` on a text read of a PDF, `CONSENTED_DOCUMENT_TOO_LARGE`, `DOCUMENT_NOT_FOUND`). Run the harness with `FIAS_HARNESS_VAULT_PICK=canceled` to exercise the cancel branch. Not available in the builder preview — `pick()` resolves `{ canceled: true }` there.
759
+
760
+ ### `useFiasAIActions()` — Let the platform's Fias AI assistant operate your plugin
761
+
762
+ **Permission:** `ai:actions`
763
+
764
+ The platform assistant (the Fias AI button in the host header) can perform actions inside your plugin — but only ones you declare. Declared actions become the assistant's tools while your plugin is open; a user can say "rotate the selected pages" and the assistant calls your handler.
765
+
766
+ There are two declaration lanes, one shape:
767
+
768
+ - **Manifest (static, every plugin):** a `fiasAI: { description, actions: [...] }` block in `fias-plugin.json`. Fixed at publish and reviewed with your submission.
769
+ - **Runtime (this hook, trusted arches only):** declare/extend actions from code. The host silently ignores runtime declarations from non-trusted arches — manifest actions still work there, and this hook still handles their dispatches.
770
+
771
+ ```tsx
772
+ import { useFiasAIActions } from '@fias/arche-sdk';
773
+
774
+ useFiasAIActions({
775
+ description: 'Once a document is open, the assistant can rotate its pages.',
776
+ actions: [
777
+ {
778
+ id: 'rotate_pages', // lowercase snake_case — becomes the tool name
779
+ description: 'Rotate the selected pages 90° clockwise.',
780
+ parameterSchema: { type: 'object', properties: {} },
781
+ availableWhen: { documentOpen: true }, // hidden until the state says so
782
+ },
783
+ ],
784
+ state: { documentOpen: doc !== null }, // small, flag-shaped — NOT your data
785
+ onAction: async (actionId, params) => {
786
+ if (actionId === 'rotate_pages') {
787
+ if (!doc) throw new Error('No document is open.'); // ALWAYS re-check
788
+ await rotateSelected();
789
+ return;
790
+ }
791
+ throw new Error(`Unknown action ${actionId}`);
792
+ },
793
+ });
794
+ ```
795
+
796
+ Rules that matter:
797
+
798
+ - **Throw to report failure.** The assistant awaits `onAction` before telling the model the action applied — a batch ("do this to each file") stops on the failing step only if you throw.
799
+ - **Re-check preconditions in `onAction`.** `availableWhen` filtering is presentation; a stale turn can still dispatch a hidden verb.
800
+ - **Keep `state` tiny** (`{documentOpen: true}`, `hasPages: true`) — it is embedded in the assistant's prompt every turn and oversized snapshots are dropped.
801
+ - **UI state only.** Actions manipulate what the user could do in your interface; anything touching server state stays in your own code paths.
802
+ - `requiresConfirmation: true` makes the assistant ask the user before dispatching. It escalates only — nothing can skip a confirmation the platform requires.
803
+ - Manifest actions win id collisions with runtime ones; the merged list is capped at 50.
804
+ - The assistant is not present in the builder preview or the dev harness — declarations are accepted but nothing dispatches until the published plugin runs with the Fias AI window.
736
805
 
737
806
  ### `useArcheAssets()` — Contributor-published asset library
738
807
 
@@ -756,6 +825,40 @@ const fresh = await getUrl(assetId);
756
825
 
757
826
  Cache the `assetId`; refresh `signedUrl` via `getUrl()` rather than persisting URLs across sessions.
758
827
 
828
+ ### `useCommunityAssets()` — User-published images, visible to this arche's users
829
+
830
+ **Permissions:** `assets:community:read` (browse/view) · `assets:community:publish` (publish/unpublish/listMine)
831
+ **Returns:** `CommunityAssetsApi`
832
+
833
+ The only way one user's content reaches another user. A user publishes an image **they created here**, and after moderation every authenticated user of **this arche** (and no other) can see it. Free to publish.
834
+
835
+ ```tsx
836
+ import { useCommunityAssets, useImageGeneration } from '@fias/arche-sdk';
837
+
838
+ const { publish, publishMany, listCommunity, listMine, getUrls, unpublish } = useCommunityAssets();
839
+ const { generate } = useImageGeneration();
840
+
841
+ // 1. The user makes something, then shares it
842
+ const image = await generate({ prompt: 'a sleepy blue whale' });
843
+ const asset = await publish({ fileId: image.fileId, title: 'Sleepy whale', tags: ['page-art'] });
844
+ // asset.status === 'pending_moderation' ← NOT visible to others yet
845
+
846
+ // 2. Browse what the community published
847
+ const { assets, nextCursor } = await listCommunity({ limit: 30, tag: 'page-art' });
848
+
849
+ // 3. Sign a whole gallery in ONE call (URLs last ~5 min; the hook refreshes them)
850
+ const urls = await getUrls(assets.map((a) => a.assetId));
851
+ // urls[i]: { assetId, url, expiresAt } → drop straight into <img src={url} />
852
+ ```
853
+
854
+ Three things to design around:
855
+
856
+ 1. **Publishing is not instant.** `publish()` returns `status: 'pending_moderation'`. It shows up in `listCommunity()` only once approved — so show the author their own pending item via `listMine()` instead of optimistically adding it to the community feed.
857
+ 2. **Batch your URLs.** Use `getUrls()` for a gallery or a multi-page book. Thirteen separate `getUrl()` calls against a ~5-minute TTL is the shape this exists to avoid. Ids that were taken down or aren't published yet are simply omitted — render around the gap.
858
+ 3. **Structure goes in the Data Store.** Which asset belongs on which page/level lives in a `shared`-scope Data Store collection holding `assetId`s. Community Assets stores the bytes and nothing queryable — `tags` plus cursor paging is the whole query surface, deliberately.
859
+
860
+ Only images the user made or uploaded in **their own** Fias files can be published (pass the `fileId` from a `useImageGeneration()` result). PNG/JPEG/WebP only; every image is re-encoded to a canonical PNG with metadata stripped. Publishers can `unpublish()` their own assets, and any user can `report()` one for review.
861
+
759
862
  ### `useFiasStore()` — In-app purchases (IAP)
760
863
 
761
864
  **Permission:** `store:purchase`
@@ -925,6 +1028,91 @@ await fias.dataStore.listCollections();
925
1028
  await fias.dataStore.deleteCollection('scores');
926
1029
  ```
927
1030
 
1031
+ ### Panels (dialogs, reward popups, empty states)
1032
+
1033
+ A **panel** is a bounded block of declarative content — a title, an ordered list of leaf
1034
+ elements, some buttons. The platform ships a shared renderer, `@fias/panel-kit`, from its own
1035
+ CDN, so you get the same dialog/reward-popup look as first-party arches without writing modal,
1036
+ scrim or focus-trap code.
1037
+
1038
+ **Opt in** with a permission and a dependency (the platform serves the module; do NOT install it
1039
+ from npm — it isn't there):
1040
+
1041
+ ```json
1042
+ // fias-plugin.json
1043
+ {
1044
+ "permissions": ["sandbox:vendored-libraries"],
1045
+ "dependencies": { "@fias/panel-kit": "0.3.0" }
1046
+ }
1047
+ ```
1048
+
1049
+ The build **pins the version from the platform registry and rejects a manifest that declares a
1050
+ different one**, with the exact string to write. When a new panel-kit ships, bump this on your
1051
+ next submission — already-published builds keep resolving the version they were built against.
1052
+
1053
+ **Render one.** Inline is just a component; modal goes through the host:
1054
+
1055
+ ```tsx
1056
+ import { Panel, PanelHost, usePanel } from '@fias/panel-kit';
1057
+
1058
+ // Inline — in the page's normal flow.
1059
+ <Panel definition={definition} context={{ values: { score }, items }} onAction={handleAction} />;
1060
+
1061
+ // Modal — mount <PanelHost> once near your app root, then:
1062
+ const { showPanel } = usePanel();
1063
+ const outcome = await showPanel(definition, { context: { values, items } });
1064
+ if (outcome.type === 'emit' && outcome.token === 'restart') restart();
1065
+ ```
1066
+
1067
+ `onAction` / the resolved outcome hands you the parsed intent — the renderer never navigates. A
1068
+ button's `action` is a closed namespace: `close`, `emit:<token>` (your own verb, handed back to
1069
+ you), `open_arche:arc_<32 hex>`, `open_url:https://…`.
1070
+
1071
+ **Elements** are leaf kinds only — no nesting, no layout algebra, no conditionals beyond one
1072
+ truthiness check:
1073
+
1074
+ | Kind | What it draws |
1075
+ | ----------------- | --------------------------------------------------------------------------------- |
1076
+ | `text` | Plain text; `{placeholder}` tokens fill from `context.values`. Never HTML. |
1077
+ | `conditionalText` | The same, only when `context.values[showIf]` is truthy. `showIf` is a value NAME. |
1078
+ | `image` | A platform storage key the host resolves. |
1079
+ | `assetImage` | An arche asset-library id (`as_…`). |
1080
+ | `items` | `context.items` — the list you pass at render time. |
1081
+ | `slottedItems` | `context.itemsBySlot[slot]` — several independent lists in one panel. |
1082
+ | `button` | Label + action. |
1083
+ | `spacer` | Vertical whitespace. |
1084
+
1085
+ Both text kinds take `joinNext: true` to share a line with the element after them
1086
+ (`Base Reward: [icon] Fabricanse ×1`).
1087
+
1088
+ **Theming.** A `theme` sets colours, font, radii, spacing and the quantity format. Pass it to the
1089
+ presenter — not to a wrapping element — because the modal portals out of your subtree:
1090
+
1091
+ ```tsx
1092
+ <PanelHost theme={{ bg: '#F6EAD2', accent: '#D8B24A', amountFormat: '×{n}' }} />
1093
+ ```
1094
+
1095
+ Values are grammars, not free CSS: hex or `rgb()/rgba()` colours, `px`/`rem`/`em` lengths, a font
1096
+ stack with no parentheses. Anything else is dropped (a `url()` in a custom property would make
1097
+ every panel you draw fetch a third-party asset).
1098
+
1099
+ **Panels as DATA.** If your panels live in storage rather than in code — a `dataStore` document,
1100
+ an admin-edited blob — validate on the WRITE, using the same rules the platform enforces:
1101
+
1102
+ ```ts
1103
+ import { validatePanelCatalog } from '@fias/arche-sdk';
1104
+
1105
+ const result = validatePanelCatalog(draft); // { panels: [...], theme?: {...} }
1106
+ if (!result.ok) return showErrors(result.issues); // one message per problem, path-prefixed
1107
+ await fias.dataStore.put('panels', 'catalog', draft);
1108
+ ```
1109
+
1110
+ That is the whole pattern for server-driven panel content: **your existing storage plus a shared
1111
+ validator** — no new permission, no platform call. Changing a panel's wording then means editing
1112
+ a document, not shipping a release. `validatePanelDefinition` and `validatePanelTheme` validate
1113
+ the parts individually; the types (`PanelDefinition`, `PanelElement`, `PanelTheme`, `PanelCatalog`)
1114
+ come from `@fias/arche-sdk` too, so the shape you store is the shape the renderer takes.
1115
+
928
1116
  ### Advanced exports (rarely needed)
929
1117
 
930
1118
  The SDK also exports the following for advanced use cases. Most plugins don't need them.
@@ -179,7 +179,9 @@ import { useFiasDataStore } from '@fias/arche-sdk';
179
179
  function MyComponent() {
180
180
  const dataStore = useFiasDataStore();
181
181
 
182
- // Collection management
182
+ // Collection management. PREFER declaring collections in fias-plugin.json
183
+ // (see "Declaring your collections" below) — createCollection is capped at
184
+ // 10/minute, so scaffolding several at startup can silently lose the tail.
183
185
  await dataStore.createCollection('scores', { userScope: 'user' }); // or 'shared'
184
186
  const collections = await dataStore.listCollections();
185
187
  await dataStore.deleteCollection('scores');
@@ -236,6 +238,24 @@ await dataStore.batch([
236
238
  ]);
237
239
  ```
238
240
 
241
+ ### Declaring your collections (preferred)
242
+
243
+ List the collections your plugin needs in `fias-plugin.json` and the platform creates them once at publish, before your plugin ever runs:
244
+
245
+ ```jsonc
246
+ "collections": [
247
+ { "name": "scores", "scope": "user" },
248
+ { "name": "ledger", "scope": "workspace", "readMinRole": "member" },
249
+ { "name": "recipes", "scope": "shared", "writePolicy": "author", "searchable": { "field": "text" } }
250
+ ]
251
+ ```
252
+
253
+ `scope` is `user` | `shared` | `workspace`. `readMinRole` / `writeMinRole` are workspace-only; `writePolicy` is shared-only; `searchable` names the text field to embed. Same options as `createCollection`, checked by `fias-dev validate` before you publish.
254
+
255
+ Why this and not `createCollection` at startup: the runtime op is capped at **10 per minute** while an arche may hold **50** collections, so a plugin creating several on mount can exceed the cap and lose the rest **with no error** — surfacing later as `COLLECTION_NOT_FOUND` on an unrelated call. Declaring has no such window, and a mistake fails your publish instead of a user's session.
256
+
257
+ Re-publishing is safe: existing collections are left alone, a stricter role floor is applied, a looser one is refused, and a collection you stop declaring is kept (never deleted — it may hold user data). Keep using `createCollection` for collections whose names you only know at runtime.
258
+
239
259
  **Rate limits (per minute):** `put` 120, `get` 300, `query` 60, `delete` 60, `batch` 30, `createCollection` 10
240
260
 
241
261
  **Error handling:** Data store calls can reject on infrastructure errors or limit violations. Always use `try/catch`. Common error codes: `COLLECTION_NOT_FOUND`, `DOCUMENT_TOO_LARGE`, `STORAGE_LIMIT_REACHED`, `RATE_LIMIT`.
@@ -724,6 +744,7 @@ if ('canceled' in picked) {
724
744
  const granted = await userDocs.list(); // all granted docs
725
745
  const { document, content } = await userDocs.get(id, { includeContent: true }); // text docs
726
746
  const { url } = await userDocs.getDownloadUrl(id); // binary docs (images, PDFs)
747
+ const { bytes } = await userDocs.getBytes(id); // raw bytes for PROCESSING binary docs
727
748
  ```
728
749
 
729
750
  **The consent model (what to tell your users):**
@@ -732,7 +753,55 @@ const { url } = await userDocs.getDownloadUrl(id); // binary docs (images, PDFs)
732
753
  - After revocation, `get`/`getDownloadUrl` reject with `DOCUMENT_NOT_FOUND` — handle that path gracefully (drop the document from your UI; do not retry in a loop).
733
754
  - `proprietary`-sensitivity documents are never grantable (they don't even appear in the picker).
734
755
  - Every read is audited by the platform; a new document _version_ is a new documentId, so a re-pick is needed after the user replaces a document.
735
- - Not available in the builder preview or the dev harness — `pick()` resolves `{ canceled: true }` there. Test the flow in the published plugin with your own documents.
756
+ - `getDownloadUrl` is for DISPLAY (`<img src>`); your iframe cannot fetch the URL (CSP). To process binary content (parse a PDF, transform an image), use `getBytes(id)` — size-capped at 15 MB (`CONSENTED_DOCUMENT_TOO_LARGE` names the cap; ask the user to open the file manually instead). `getBytes` has a tighter per-minute budget than the rest of the family because it can move megabytes: read sequentially, and surface a rate-limit error rather than retrying in a loop.
757
+ - Revocation behaves differently per method: `getBytes` and `get` re-check the grant on every call, so they start failing immediately. A URL already handed out by `getDownloadUrl` keeps working until it expires (1 hour) — that is the documented contract, not a bug.
758
+ - **Testable in the dev harness (mock mode).** `pick()` grants a small fixture set — a text file, a real PDF, and one deliberately over the 15 MB cap — and `list` / `get` / `getDownloadUrl` / `getBytes` all resolve against it, including the refusals (`BINARY_DOCUMENT` on a text read of a PDF, `CONSENTED_DOCUMENT_TOO_LARGE`, `DOCUMENT_NOT_FOUND`). Run the harness with `FIAS_HARNESS_VAULT_PICK=canceled` to exercise the cancel branch. Not available in the builder preview — `pick()` resolves `{ canceled: true }` there.
759
+
760
+ ### `useFiasAIActions()` — Let the platform's Fias AI assistant operate your plugin
761
+
762
+ **Permission:** `ai:actions`
763
+
764
+ The platform assistant (the Fias AI button in the host header) can perform actions inside your plugin — but only ones you declare. Declared actions become the assistant's tools while your plugin is open; a user can say "rotate the selected pages" and the assistant calls your handler.
765
+
766
+ There are two declaration lanes, one shape:
767
+
768
+ - **Manifest (static, every plugin):** a `fiasAI: { description, actions: [...] }` block in `fias-plugin.json`. Fixed at publish and reviewed with your submission.
769
+ - **Runtime (this hook, trusted arches only):** declare/extend actions from code. The host silently ignores runtime declarations from non-trusted arches — manifest actions still work there, and this hook still handles their dispatches.
770
+
771
+ ```tsx
772
+ import { useFiasAIActions } from '@fias/arche-sdk';
773
+
774
+ useFiasAIActions({
775
+ description: 'Once a document is open, the assistant can rotate its pages.',
776
+ actions: [
777
+ {
778
+ id: 'rotate_pages', // lowercase snake_case — becomes the tool name
779
+ description: 'Rotate the selected pages 90° clockwise.',
780
+ parameterSchema: { type: 'object', properties: {} },
781
+ availableWhen: { documentOpen: true }, // hidden until the state says so
782
+ },
783
+ ],
784
+ state: { documentOpen: doc !== null }, // small, flag-shaped — NOT your data
785
+ onAction: async (actionId, params) => {
786
+ if (actionId === 'rotate_pages') {
787
+ if (!doc) throw new Error('No document is open.'); // ALWAYS re-check
788
+ await rotateSelected();
789
+ return;
790
+ }
791
+ throw new Error(`Unknown action ${actionId}`);
792
+ },
793
+ });
794
+ ```
795
+
796
+ Rules that matter:
797
+
798
+ - **Throw to report failure.** The assistant awaits `onAction` before telling the model the action applied — a batch ("do this to each file") stops on the failing step only if you throw.
799
+ - **Re-check preconditions in `onAction`.** `availableWhen` filtering is presentation; a stale turn can still dispatch a hidden verb.
800
+ - **Keep `state` tiny** (`{documentOpen: true}`, `hasPages: true`) — it is embedded in the assistant's prompt every turn and oversized snapshots are dropped.
801
+ - **UI state only.** Actions manipulate what the user could do in your interface; anything touching server state stays in your own code paths.
802
+ - `requiresConfirmation: true` makes the assistant ask the user before dispatching. It escalates only — nothing can skip a confirmation the platform requires.
803
+ - Manifest actions win id collisions with runtime ones; the merged list is capped at 50.
804
+ - The assistant is not present in the builder preview or the dev harness — declarations are accepted but nothing dispatches until the published plugin runs with the Fias AI window.
736
805
 
737
806
  ### `useArcheAssets()` — Contributor-published asset library
738
807
 
@@ -756,6 +825,40 @@ const fresh = await getUrl(assetId);
756
825
 
757
826
  Cache the `assetId`; refresh `signedUrl` via `getUrl()` rather than persisting URLs across sessions.
758
827
 
828
+ ### `useCommunityAssets()` — User-published images, visible to this arche's users
829
+
830
+ **Permissions:** `assets:community:read` (browse/view) · `assets:community:publish` (publish/unpublish/listMine)
831
+ **Returns:** `CommunityAssetsApi`
832
+
833
+ The only way one user's content reaches another user. A user publishes an image **they created here**, and after moderation every authenticated user of **this arche** (and no other) can see it. Free to publish.
834
+
835
+ ```tsx
836
+ import { useCommunityAssets, useImageGeneration } from '@fias/arche-sdk';
837
+
838
+ const { publish, publishMany, listCommunity, listMine, getUrls, unpublish } = useCommunityAssets();
839
+ const { generate } = useImageGeneration();
840
+
841
+ // 1. The user makes something, then shares it
842
+ const image = await generate({ prompt: 'a sleepy blue whale' });
843
+ const asset = await publish({ fileId: image.fileId, title: 'Sleepy whale', tags: ['page-art'] });
844
+ // asset.status === 'pending_moderation' ← NOT visible to others yet
845
+
846
+ // 2. Browse what the community published
847
+ const { assets, nextCursor } = await listCommunity({ limit: 30, tag: 'page-art' });
848
+
849
+ // 3. Sign a whole gallery in ONE call (URLs last ~5 min; the hook refreshes them)
850
+ const urls = await getUrls(assets.map((a) => a.assetId));
851
+ // urls[i]: { assetId, url, expiresAt } → drop straight into <img src={url} />
852
+ ```
853
+
854
+ Three things to design around:
855
+
856
+ 1. **Publishing is not instant.** `publish()` returns `status: 'pending_moderation'`. It shows up in `listCommunity()` only once approved — so show the author their own pending item via `listMine()` instead of optimistically adding it to the community feed.
857
+ 2. **Batch your URLs.** Use `getUrls()` for a gallery or a multi-page book. Thirteen separate `getUrl()` calls against a ~5-minute TTL is the shape this exists to avoid. Ids that were taken down or aren't published yet are simply omitted — render around the gap.
858
+ 3. **Structure goes in the Data Store.** Which asset belongs on which page/level lives in a `shared`-scope Data Store collection holding `assetId`s. Community Assets stores the bytes and nothing queryable — `tags` plus cursor paging is the whole query surface, deliberately.
859
+
860
+ Only images the user made or uploaded in **their own** Fias files can be published (pass the `fileId` from a `useImageGeneration()` result). PNG/JPEG/WebP only; every image is re-encoded to a canonical PNG with metadata stripped. Publishers can `unpublish()` their own assets, and any user can `report()` one for review.
861
+
759
862
  ### `useFiasStore()` — In-app purchases (IAP)
760
863
 
761
864
  **Permission:** `store:purchase`
@@ -925,6 +1028,91 @@ await fias.dataStore.listCollections();
925
1028
  await fias.dataStore.deleteCollection('scores');
926
1029
  ```
927
1030
 
1031
+ ### Panels (dialogs, reward popups, empty states)
1032
+
1033
+ A **panel** is a bounded block of declarative content — a title, an ordered list of leaf
1034
+ elements, some buttons. The platform ships a shared renderer, `@fias/panel-kit`, from its own
1035
+ CDN, so you get the same dialog/reward-popup look as first-party arches without writing modal,
1036
+ scrim or focus-trap code.
1037
+
1038
+ **Opt in** with a permission and a dependency (the platform serves the module; do NOT install it
1039
+ from npm — it isn't there):
1040
+
1041
+ ```json
1042
+ // fias-plugin.json
1043
+ {
1044
+ "permissions": ["sandbox:vendored-libraries"],
1045
+ "dependencies": { "@fias/panel-kit": "0.3.0" }
1046
+ }
1047
+ ```
1048
+
1049
+ The build **pins the version from the platform registry and rejects a manifest that declares a
1050
+ different one**, with the exact string to write. When a new panel-kit ships, bump this on your
1051
+ next submission — already-published builds keep resolving the version they were built against.
1052
+
1053
+ **Render one.** Inline is just a component; modal goes through the host:
1054
+
1055
+ ```tsx
1056
+ import { Panel, PanelHost, usePanel } from '@fias/panel-kit';
1057
+
1058
+ // Inline — in the page's normal flow.
1059
+ <Panel definition={definition} context={{ values: { score }, items }} onAction={handleAction} />;
1060
+
1061
+ // Modal — mount <PanelHost> once near your app root, then:
1062
+ const { showPanel } = usePanel();
1063
+ const outcome = await showPanel(definition, { context: { values, items } });
1064
+ if (outcome.type === 'emit' && outcome.token === 'restart') restart();
1065
+ ```
1066
+
1067
+ `onAction` / the resolved outcome hands you the parsed intent — the renderer never navigates. A
1068
+ button's `action` is a closed namespace: `close`, `emit:<token>` (your own verb, handed back to
1069
+ you), `open_arche:arc_<32 hex>`, `open_url:https://…`.
1070
+
1071
+ **Elements** are leaf kinds only — no nesting, no layout algebra, no conditionals beyond one
1072
+ truthiness check:
1073
+
1074
+ | Kind | What it draws |
1075
+ | ----------------- | --------------------------------------------------------------------------------- |
1076
+ | `text` | Plain text; `{placeholder}` tokens fill from `context.values`. Never HTML. |
1077
+ | `conditionalText` | The same, only when `context.values[showIf]` is truthy. `showIf` is a value NAME. |
1078
+ | `image` | A platform storage key the host resolves. |
1079
+ | `assetImage` | An arche asset-library id (`as_…`). |
1080
+ | `items` | `context.items` — the list you pass at render time. |
1081
+ | `slottedItems` | `context.itemsBySlot[slot]` — several independent lists in one panel. |
1082
+ | `button` | Label + action. |
1083
+ | `spacer` | Vertical whitespace. |
1084
+
1085
+ Both text kinds take `joinNext: true` to share a line with the element after them
1086
+ (`Base Reward: [icon] Fabricanse ×1`).
1087
+
1088
+ **Theming.** A `theme` sets colours, font, radii, spacing and the quantity format. Pass it to the
1089
+ presenter — not to a wrapping element — because the modal portals out of your subtree:
1090
+
1091
+ ```tsx
1092
+ <PanelHost theme={{ bg: '#F6EAD2', accent: '#D8B24A', amountFormat: '×{n}' }} />
1093
+ ```
1094
+
1095
+ Values are grammars, not free CSS: hex or `rgb()/rgba()` colours, `px`/`rem`/`em` lengths, a font
1096
+ stack with no parentheses. Anything else is dropped (a `url()` in a custom property would make
1097
+ every panel you draw fetch a third-party asset).
1098
+
1099
+ **Panels as DATA.** If your panels live in storage rather than in code — a `dataStore` document,
1100
+ an admin-edited blob — validate on the WRITE, using the same rules the platform enforces:
1101
+
1102
+ ```ts
1103
+ import { validatePanelCatalog } from '@fias/arche-sdk';
1104
+
1105
+ const result = validatePanelCatalog(draft); // { panels: [...], theme?: {...} }
1106
+ if (!result.ok) return showErrors(result.issues); // one message per problem, path-prefixed
1107
+ await fias.dataStore.put('panels', 'catalog', draft);
1108
+ ```
1109
+
1110
+ That is the whole pattern for server-driven panel content: **your existing storage plus a shared
1111
+ validator** — no new permission, no platform call. Changing a panel's wording then means editing
1112
+ a document, not shipping a release. `validatePanelDefinition` and `validatePanelTheme` validate
1113
+ the parts individually; the types (`PanelDefinition`, `PanelElement`, `PanelTheme`, `PanelCatalog`)
1114
+ come from `@fias/arche-sdk` too, so the shape you store is the shape the renderer takes.
1115
+
928
1116
  ### Advanced exports (rarely needed)
929
1117
 
930
1118
  The SDK also exports the following for advanced use cases. Most plugins don't need them.