@fias/create-fias-plugin 1.2.1 → 1.4.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.2.1",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -63,6 +63,55 @@ function MyComponent() {
63
63
  - `fonts`: `{ body, heading, mono }` (font-family strings)
64
64
  - `components`: `{ borderRadius, buttonRadius, cardRadius, inputRadius, shadowSm, shadowMd, shadowLg, borderWidth }`
65
65
 
66
+ ### `useFiasFonts()` — Platform font catalog
67
+
68
+ **Permission:** none
69
+ **Returns:** `{ fonts, ensureFontLoaded }`
70
+
71
+ The platform vendors a catalog of fonts and injects every family's
72
+ `@font-face` into your plugin iframe automatically (the `.woff2` bytes
73
+ load lazily, only when a glyph is actually painted). So you can use any
74
+ catalog `family` name directly in CSS — no `<link>`, no `@import`, no
75
+ bundled font files, and **no Google Fonts** (those are blocked by the
76
+ plugin CSP). Build a font picker from `fonts`:
77
+
78
+ ```tsx
79
+ import { useFiasFonts } from '@fias/arche-sdk';
80
+
81
+ function FontPicker({ value, onChange }: { value: string; onChange: (f: string) => void }) {
82
+ const { fonts } = useFiasFonts();
83
+ return (
84
+ <select value={value} onChange={(e) => onChange(e.target.value)} style={{ fontFamily: value }}>
85
+ {fonts.map((f) => (
86
+ <option key={f.family} value={f.family} style={{ fontFamily: f.family }}>
87
+ {f.displayName}
88
+ </option>
89
+ ))}
90
+ </select>
91
+ );
92
+ }
93
+ ```
94
+
95
+ - `fonts`: `FontCatalogEntry[]` — `{ family, displayName, category, system }`.
96
+ `category` is one of `sans | serif | display | mono | handwriting | system`;
97
+ `system: true` marks OS fonts (always available, no web font needed).
98
+ - `ensureFontLoaded(family, sizePx?)`: `Promise<void>` — **canvas / PDF only.**
99
+ Normal DOM text needs nothing (the browser fetches the face when it
100
+ paints). But `<canvas>` (incl. Konva / Fabric) and PDF exporters measure
101
+ glyph metrics synchronously, so they rasterize the fallback face if the
102
+ bytes aren't in yet. Call and `await` this before drawing. It never
103
+ rejects, resolves instantly for already-loaded / system fonts, and
104
+ resolves after a 3s timeout if the CDN is unreachable.
105
+
106
+ ```tsx
107
+ const { ensureFontLoaded } = useFiasFonts();
108
+ await ensureFontLoaded(selectedFamily); // then draw to the canvas
109
+ ```
110
+
111
+ `FONT_CATALOG` and `ensureFontLoaded` are also exported standalone for use
112
+ outside React (e.g. an export routine). For curated heading/body theme
113
+ pairings instead of the flat catalog, see `FONT_PAIRINGS`.
114
+
66
115
  ### `useFiasUser()` — Current user profile
67
116
 
68
117
  **Permission:** `user:profile:read`
@@ -175,7 +224,7 @@ function AISummarizer() {
175
224
 
176
225
  async function summarize(text: string) {
177
226
  await invoke({
178
- entityId: 'ent_fias_ai', // the AI model capability
227
+ entityId: { capability: 'text-standard' }, // a platform text capability — see "Choosing a text model" below
179
228
  input: text, // what to process
180
229
  systemPrompt: 'You are a concise summarizer. Return a 2-3 sentence summary.',
181
230
  });
@@ -198,7 +247,44 @@ function AISummarizer() {
198
247
  }
199
248
  ```
200
249
 
201
- The `entityId` references a published model entity. Browse available models with `npx fias-dev entities`. The `systemPrompt` tells the AI how to behave — this is where your plugin's intelligence lives.
250
+ The `systemPrompt` tells the AI how to behave — this is where your plugin's intelligence lives.
251
+
252
+ #### Choosing a text model
253
+
254
+ The `entityId` parameter accepts three forms. **Prefer the capability selector** over a hardcoded model id: the platform's models evolve and get retired, and a capability lets your plugin pick up the current best model automatically without a code edit. When the platform retires the model behind a capability, it re-points the capability — your plugin keeps working.
255
+
256
+ ```tsx
257
+ // 1. By capability (recommended) — resolved to the platform's current model
258
+ // for that tier, and re-pointed automatically if that model is retired.
259
+ await invoke({
260
+ entityId: { capability: 'text-standard' }, // 'text-fast' | 'text-standard' | 'text-advanced'
261
+ input,
262
+ systemPrompt: '...',
263
+ });
264
+
265
+ // 2. AI router — let the platform pick a model per request based on the
266
+ // query's complexity. Optionally bias the tier with routingPreference.
267
+ await invoke({
268
+ entityId: 'ent_fias_ai',
269
+ input,
270
+ systemPrompt: '...',
271
+ routingPreference: 'cost', // 'auto' (default) | 'speed' | 'cost' | 'balanced' | 'performance'
272
+ });
273
+
274
+ // 3. A specific model id (back-compat) — pins one model. It will stop working
275
+ // if that model is retired; use a capability for retirement resilience.
276
+ await invoke({ entityId: 'ent_modeldef_haiku_45', input, systemPrompt: '...' });
277
+ ```
278
+
279
+ The text capabilities:
280
+
281
+ | Capability | Use it for |
282
+ | --------------- | ---------------------------------------------------------------------------- |
283
+ | `text-fast` | Cheapest, fastest — classification, extraction, short responses, high volume |
284
+ | `text-standard` | Balanced, general-purpose text generation (the sensible default) |
285
+ | `text-advanced` | Most capable — complex reasoning, nuanced writing, long-form output |
286
+
287
+ Browse specific models with `npx fias-dev entities`.
202
288
 
203
289
  ### `useImageGeneration()` — Generate images via AI models
204
290
 
@@ -63,6 +63,55 @@ function MyComponent() {
63
63
  - `fonts`: `{ body, heading, mono }` (font-family strings)
64
64
  - `components`: `{ borderRadius, buttonRadius, cardRadius, inputRadius, shadowSm, shadowMd, shadowLg, borderWidth }`
65
65
 
66
+ ### `useFiasFonts()` — Platform font catalog
67
+
68
+ **Permission:** none
69
+ **Returns:** `{ fonts, ensureFontLoaded }`
70
+
71
+ The platform vendors a catalog of fonts and injects every family's
72
+ `@font-face` into your plugin iframe automatically (the `.woff2` bytes
73
+ load lazily, only when a glyph is actually painted). So you can use any
74
+ catalog `family` name directly in CSS — no `<link>`, no `@import`, no
75
+ bundled font files, and **no Google Fonts** (those are blocked by the
76
+ plugin CSP). Build a font picker from `fonts`:
77
+
78
+ ```tsx
79
+ import { useFiasFonts } from '@fias/arche-sdk';
80
+
81
+ function FontPicker({ value, onChange }: { value: string; onChange: (f: string) => void }) {
82
+ const { fonts } = useFiasFonts();
83
+ return (
84
+ <select value={value} onChange={(e) => onChange(e.target.value)} style={{ fontFamily: value }}>
85
+ {fonts.map((f) => (
86
+ <option key={f.family} value={f.family} style={{ fontFamily: f.family }}>
87
+ {f.displayName}
88
+ </option>
89
+ ))}
90
+ </select>
91
+ );
92
+ }
93
+ ```
94
+
95
+ - `fonts`: `FontCatalogEntry[]` — `{ family, displayName, category, system }`.
96
+ `category` is one of `sans | serif | display | mono | handwriting | system`;
97
+ `system: true` marks OS fonts (always available, no web font needed).
98
+ - `ensureFontLoaded(family, sizePx?)`: `Promise<void>` — **canvas / PDF only.**
99
+ Normal DOM text needs nothing (the browser fetches the face when it
100
+ paints). But `<canvas>` (incl. Konva / Fabric) and PDF exporters measure
101
+ glyph metrics synchronously, so they rasterize the fallback face if the
102
+ bytes aren't in yet. Call and `await` this before drawing. It never
103
+ rejects, resolves instantly for already-loaded / system fonts, and
104
+ resolves after a 3s timeout if the CDN is unreachable.
105
+
106
+ ```tsx
107
+ const { ensureFontLoaded } = useFiasFonts();
108
+ await ensureFontLoaded(selectedFamily); // then draw to the canvas
109
+ ```
110
+
111
+ `FONT_CATALOG` and `ensureFontLoaded` are also exported standalone for use
112
+ outside React (e.g. an export routine). For curated heading/body theme
113
+ pairings instead of the flat catalog, see `FONT_PAIRINGS`.
114
+
66
115
  ### `useFiasUser()` — Current user profile
67
116
 
68
117
  **Permission:** `user:profile:read`
@@ -175,7 +224,7 @@ function AISummarizer() {
175
224
 
176
225
  async function summarize(text: string) {
177
226
  await invoke({
178
- entityId: 'ent_fias_ai', // the AI model capability
227
+ entityId: { capability: 'text-standard' }, // a platform text capability — see "Choosing a text model" below
179
228
  input: text, // what to process
180
229
  systemPrompt: 'You are a concise summarizer. Return a 2-3 sentence summary.',
181
230
  });
@@ -198,7 +247,44 @@ function AISummarizer() {
198
247
  }
199
248
  ```
200
249
 
201
- The `entityId` references a published model entity. Browse available models with `npx fias-dev entities`. The `systemPrompt` tells the AI how to behave — this is where your plugin's intelligence lives.
250
+ The `systemPrompt` tells the AI how to behave — this is where your plugin's intelligence lives.
251
+
252
+ #### Choosing a text model
253
+
254
+ The `entityId` parameter accepts three forms. **Prefer the capability selector** over a hardcoded model id: the platform's models evolve and get retired, and a capability lets your plugin pick up the current best model automatically without a code edit. When the platform retires the model behind a capability, it re-points the capability — your plugin keeps working.
255
+
256
+ ```tsx
257
+ // 1. By capability (recommended) — resolved to the platform's current model
258
+ // for that tier, and re-pointed automatically if that model is retired.
259
+ await invoke({
260
+ entityId: { capability: 'text-standard' }, // 'text-fast' | 'text-standard' | 'text-advanced'
261
+ input,
262
+ systemPrompt: '...',
263
+ });
264
+
265
+ // 2. AI router — let the platform pick a model per request based on the
266
+ // query's complexity. Optionally bias the tier with routingPreference.
267
+ await invoke({
268
+ entityId: 'ent_fias_ai',
269
+ input,
270
+ systemPrompt: '...',
271
+ routingPreference: 'cost', // 'auto' (default) | 'speed' | 'cost' | 'balanced' | 'performance'
272
+ });
273
+
274
+ // 3. A specific model id (back-compat) — pins one model. It will stop working
275
+ // if that model is retired; use a capability for retirement resilience.
276
+ await invoke({ entityId: 'ent_modeldef_haiku_45', input, systemPrompt: '...' });
277
+ ```
278
+
279
+ The text capabilities:
280
+
281
+ | Capability | Use it for |
282
+ | --------------- | ---------------------------------------------------------------------------- |
283
+ | `text-fast` | Cheapest, fastest — classification, extraction, short responses, high volume |
284
+ | `text-standard` | Balanced, general-purpose text generation (the sensible default) |
285
+ | `text-advanced` | Most capable — complex reasoning, nuanced writing, long-form output |
286
+
287
+ Browse specific models with `npx fias-dev entities`.
202
288
 
203
289
  ### `useImageGeneration()` — Generate images via AI models
204
290