@vspark/plugin-sdk 0.2.0 → 0.2.1

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.
Files changed (3) hide show
  1. package/README.md +21 -0
  2. package/index.d.ts +100 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -31,3 +31,24 @@ write step inputs with. A step type declares **inputs** (`text` or `number`).
31
31
  The user fills each one in as a template (`${message}`, `Song: ${payload.song}`,
32
32
  plain text) or, for a number, as an expression (`${message} - 1`). The step's
33
33
  `build` gets each input already rendered in `ctx.inputs`.
34
+
35
+ Trigger types, step types and presets may set a **category** (0.2.1). The
36
+ action drawer has a tab for each category, and the action list can be grouped
37
+ by category. Use one of vspark's ids (`chat`, `stream`, `input`, `automation`,
38
+ `animation`, `avatar`, `media`, `scene`) to join that category, or your own id
39
+ for a category of your plugin, labelled by the `categories.<id>` key in your
40
+ locales. Without a category, a type goes into one category named after the
41
+ plugin.
42
+
43
+ A composite (overlay) setting with `control: 'template'` (0.2.1) lets the user
44
+ pick one of several looks or edit the code. Its `presets` list
45
+ `{ id, template, css }`, `links` name the template field, then the CSS field
46
+ (`config.template`, `config.css` on a feed layer). The select shows the preset
47
+ whose code matches (CSS custom-property values are ignored, so the other look
48
+ settings don't turn it into "Custom"), and switching presets keeps those
49
+ values. Label each preset with `option.<key>.<id>` in your locales.
50
+
51
+ A composite type's `demo(live)` (0.2.1) returns sample feed fields; the
52
+ settings then get a "Demo data" switch that shows them in the editor preview
53
+ (never in the stream output), laid over the live fields — return only the
54
+ fields events would bring, and keep the user's own ones from `live`.
package/index.d.ts CHANGED
@@ -70,7 +70,10 @@ export interface SignalNodeClass {
70
70
  new (): SignalNodeBase;
71
71
  }
72
72
 
73
- type FieldDecorator = (value: undefined, ctx: ClassFieldDecoratorContext) => void;
73
+ type FieldDecorator = (
74
+ value: undefined,
75
+ ctx: ClassFieldDecoratorContext
76
+ ) => void;
74
77
  type MethodDecorator = (
75
78
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
79
  value: (...args: any[]) => any,
@@ -227,10 +230,27 @@ export interface StepInput {
227
230
  * signal, inputs) are absolute and start with `@` — `wire` accepts both.
228
231
  */
229
232
  export interface TemplateBuilder {
230
- node(id: string, kind: string, x: number, y: number, defaultConfig?: Record<string, unknown>): string;
231
- wire(fromNodeId: string, fromPort: string, toNodeId: string, toPort: string): void;
233
+ node(
234
+ id: string,
235
+ kind: string,
236
+ x: number,
237
+ y: number,
238
+ defaultConfig?: Record<string, unknown>
239
+ ): string;
240
+ wire(
241
+ fromNodeId: string,
242
+ fromPort: string,
243
+ toNodeId: string,
244
+ toPort: string
245
+ ): void;
232
246
  /** Feed a settings field of this part into `to.toPort` (a `settings` node). */
233
- setting(field: string, to: string, toPort: string, x: number, y: number): void;
247
+ setting(
248
+ field: string,
249
+ to: string,
250
+ toPort: string,
251
+ x: number,
252
+ y: number
253
+ ): void;
234
254
  /** A settings field of this part as an output. */
235
255
  value(field: string, x: number, y: number): Out;
236
256
  }
@@ -249,6 +269,12 @@ interface PartDef {
249
269
  preview(settings: ActionSettings): PreviewToken[];
250
270
  /** The generated form (host `SchemaForm`). */
251
271
  form?: readonly FormField[];
272
+ /** Where the drawer and the action list file it. One of vspark's
273
+ * categories (`chat`, `stream`, `input`, `automation`, `animation`,
274
+ * `avatar`, `media`, `scene`) joins that one; any other id is the
275
+ * plugin's own, labelled by its `categories.<id>` key. Default: one
276
+ * category named after the plugin. */
277
+ category?: string;
252
278
  }
253
279
 
254
280
  export interface TriggerParts {
@@ -292,7 +318,12 @@ export interface StepContext {
292
318
  * step's setting `field`: `text` renders a template, `number` evaluates an
293
319
  * expression, `record` renders rows of `{ key, value }` templates.
294
320
  */
295
- format(field: string, as: 'text' | 'number' | 'record', x: number, y: number): Out;
321
+ format(
322
+ field: string,
323
+ as: 'text' | 'number' | 'record',
324
+ x: number,
325
+ y: number
326
+ ): Out;
296
327
  }
297
328
 
298
329
  export interface StepTypeDef extends PartDef {
@@ -317,12 +348,16 @@ export interface ActionPresetDef {
317
348
  stepMode?: StepMode;
318
349
  /** `{ minRank?, cooldown?: { seconds, group }, userCooldown?: { seconds }, counter? }`. */
319
350
  options?: ActionSettings;
351
+ /** As a trigger's / step's; default: its first step's category. */
352
+ category?: string;
320
353
  }
321
354
 
322
355
  /** Turns a stored action of a former (API 1) kind into trigger → steps
323
356
  * settings (`{ trigger, steps: [...], stepMode?, options? }`). Return `null`
324
357
  * to delete the action. Runs once when vspark starts. */
325
- export type LegacyConverter = (settings: ActionSettings) => ActionSettings | null;
358
+ export type LegacyConverter = (
359
+ settings: ActionSettings
360
+ ) => ActionSettings | null;
326
361
 
327
362
  export interface CooldownSettings {
328
363
  seconds: number;
@@ -339,6 +374,8 @@ export interface SinkStepDef {
339
374
  inputs?: readonly StepInput[];
340
375
  form?: readonly FormField[];
341
376
  icon?: string;
377
+ /** As a step's (see `StepTypeDef.category`). */
378
+ category?: string;
342
379
  defaults?: () => ActionSettings;
343
380
  preview?: (settings: ActionSettings) => PreviewToken[];
344
381
  defaultTrigger?: string;
@@ -378,7 +415,23 @@ export interface SettingLink {
378
415
 
379
416
  export interface CompositeSetting {
380
417
  key: string;
381
- control: 'text' | 'number' | 'slider' | 'select' | 'color' | 'asset' | 'account' | 'toggle' | 'duration';
418
+ control:
419
+ | 'text'
420
+ | 'number'
421
+ | 'slider'
422
+ | 'select'
423
+ | 'color'
424
+ | 'asset'
425
+ | 'account'
426
+ | 'toggle'
427
+ | 'duration'
428
+ /** A feed's look as code (host >= SDK 0.2.1): a select of `presets`
429
+ * plus Custom, and a template / CSS editor. `links[0]` is the template
430
+ * field (`config.template`), `links[1]` the CSS (`config.css`). The
431
+ * select shows the preset whose code matches, CSS custom-property values
432
+ * ignored; switching keeps those values. Preset labels:
433
+ * `option.<key>.<presetId>`. */
434
+ | 'template';
382
435
  group: string;
383
436
  options?: string[];
384
437
  min?: number;
@@ -388,6 +441,16 @@ export interface CompositeSetting {
388
441
  links?: SettingLink[];
389
442
  provider?: string;
390
443
  when?: (read: (key: string) => unknown) => boolean;
444
+ /** `template`: the looks to choose from. Each one's CSS should declare
445
+ * the custom properties the type's other settings link. */
446
+ presets?: TemplatePreset[];
447
+ }
448
+
449
+ /** One look of a `template` setting. */
450
+ export interface TemplatePreset {
451
+ id: string;
452
+ template: string;
453
+ css: string;
391
454
  }
392
455
 
393
456
  /** Labels live in the plugin's namespace under the host's composite keys:
@@ -398,6 +461,12 @@ export interface CompositeTypeDef {
398
461
  rootRtype: 'compose_layer' | 'scene_node';
399
462
  parts: Record<string, PartRtype>;
400
463
  settings: CompositeSetting[];
464
+ /** Sample data (0.2.1): with it, the settings get a "Demo data" switch that
465
+ * fills the editor preview with these feed fields, laid over the live ones
466
+ * (`live`), so users can set the overlay up without real events. The
467
+ * viewer / stream output never shows it. Called when switched on (and when
468
+ * the live fields change). */
469
+ demo?: (live: Record<string, unknown>) => Record<string, unknown>;
401
470
  }
402
471
 
403
472
  /** A placeable composite: one feed layer (plus optional logic). */
@@ -484,12 +553,20 @@ export interface AccountProviderDef<Identity = Record<string, unknown>> {
484
553
  /** `secret: true` (e.g. `clientSecret`): kept server-side only and sent to
485
554
  * the token endpoint as `client_secret`; the editor shows only whether it
486
555
  * is set. */
487
- appFields: readonly { path: string; control: 'text'; label: string; hint?: string; secret?: boolean }[];
556
+ appFields: readonly {
557
+ path: string;
558
+ control: 'text';
559
+ label: string;
560
+ hint?: string;
561
+ secret?: boolean;
562
+ }[];
488
563
  /** Extra authorize params. */
489
564
  extraParams?: Record<string, string>;
490
565
  };
491
566
  /** Called after a token exchange; returns the identity shown in the list. */
492
- fetchIdentity(tokens: OAuthTokens): Promise<{ label: string; identity: Identity & Record<string, unknown> }>;
567
+ fetchIdentity(
568
+ tokens: OAuthTokens
569
+ ): Promise<{ label: string; identity: Identity & Record<string, unknown> }>;
493
570
  /** i18n key of a setup walkthrough shown in the add dialog (markdown). */
494
571
  setupHelp?: string;
495
572
  }
@@ -502,7 +579,10 @@ export interface AccountsApi {
502
579
  defaultFor(projectId: string, provider: string): AccountRow | undefined;
503
580
  /** Runs `fn` with a valid access token, refreshing (and persisting) when expired.
504
581
  * On a revoked refresh token the account goes to `needs_reauth` and this rejects. */
505
- withToken<T>(accountId: string, fn: (accessToken: string) => Promise<T>): Promise<T>;
582
+ withToken<T>(
583
+ accountId: string,
584
+ fn: (accessToken: string) => Promise<T>
585
+ ): Promise<T>;
506
586
  /** Forces a refresh on the next `withToken` (e.g. after a 401). */
507
587
  invalidate(accountId: string): void;
508
588
  setStatus(accountId: string, status: AccountStatus, message?: string): void;
@@ -513,7 +593,13 @@ export interface AccountsApi {
513
593
  export interface LogicApi {
514
594
  /** Fire `payload` into the `port` event input of every running node of `kind`
515
595
  * in the project whose `account` input resolves to `accountId` (empty = default). */
516
- routeEvent(projectId: string, kind: string, port: string, payload: unknown, accountId?: string): void;
596
+ routeEvent(
597
+ projectId: string,
598
+ kind: string,
599
+ port: string,
600
+ payload: unknown,
601
+ accountId?: string
602
+ ): void;
517
603
  /** Whether a running graph in the project contains a node of one of `kinds`. */
518
604
  hasConsumers(projectId: string, kinds: readonly string[]): boolean;
519
605
  }
@@ -585,7 +671,9 @@ export type BackendFactory = (sdk: BackendSdk) => BackendPlugin;
585
671
  export interface UiSdk extends SharedSdk {
586
672
  // Typed loosely so the preview does not depend on @types/react.
587
673
  React: unknown;
588
- useTranslation: (ns?: string) => { t: (key: string, opts?: Record<string, unknown>) => string };
674
+ useTranslation: (ns?: string) => {
675
+ t: (key: string, opts?: Record<string, unknown>) => string;
676
+ };
589
677
  components: Record<string, unknown>;
590
678
  }
591
679
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vspark/plugin-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Typings of the vspark plugin API (apiVersion 2). Types only — vspark injects the SDK at runtime.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {