@vspark/plugin-sdk 0.0.0-stage → 0.1.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.
Files changed (3) hide show
  1. package/README.md +19 -2
  2. package/index.d.ts +494 -0
  3. package/package.json +14 -4
package/README.md CHANGED
@@ -1,3 +1,20 @@
1
- # Temporary Holding Version
1
+ # @vspark/plugin-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript typings of the [vspark](https://github.com/fennsorenn/vspark) plugin
4
+ API (`apiVersion` 1). **Types only:** vspark injects the SDK into each entry
5
+ module's default-exported factory at runtime, so plugin code imports nothing
6
+ but types from here:
7
+
8
+ ```ts
9
+ import type { BackendFactory } from '@vspark/plugin-sdk';
10
+
11
+ const plugin: BackendFactory = (sdk) => {
12
+ const { Node, SignalNode, eventIn } = sdk.signal; // the host's own classes
13
+ // … define node classes here, then:
14
+ return { activate(ctx) { /* ctx.nodes.register(…) */ } };
15
+ };
16
+ export default plugin;
17
+ ```
18
+
19
+ Start a plugin from the `vspark_plugin_template` repository. The package
20
+ major version follows `apiVersion`.
package/index.d.ts ADDED
@@ -0,0 +1,494 @@
1
+ /**
2
+ * @vspark/plugin-sdk — typings of the vspark plugin API (apiVersion 1).
3
+ *
4
+ * vspark INJECTS the SDK into each entry module's default-exported factory;
5
+ * nothing in this package runs. Plugin code must only `import type` from it
6
+ * (bundling vspark's modules would register nodes in a copy the engine never
7
+ * sees). Kept in step with the host by hand: packages/backend/src/plugins/
8
+ * (loader.ts BACKEND_SDK, context.ts, accounts/api.ts) and
9
+ * @vspark/shared/actions (PLUGIN_ACTIONS_SDK, FormField, registries).
10
+ * See vspark dev-notes/modules/plugins.md.
11
+ */
12
+
13
+ export type ApiVersion = 1;
14
+
15
+ // ─────────────────────────────────────────────────────────────────────────────
16
+ // Signal graph
17
+ // ─────────────────────────────────────────────────────────────────────────────
18
+
19
+ /** Port type tags. Subset of vspark's `SignalTypeName` relevant to plugins. */
20
+ export type SignalTypeName =
21
+ | 'Float'
22
+ | 'Bool'
23
+ | 'Trigger'
24
+ | 'String'
25
+ | 'Any'
26
+ | 'Account'
27
+ | 'SceneNode'
28
+ | 'ComposeLayer'
29
+ | 'SceneEntity';
30
+
31
+ export interface SignalEvent<T> {
32
+ readonly payload: T;
33
+ readonly timestamp: number;
34
+ }
35
+
36
+ export interface Emitter<T> {
37
+ emit(value: T): void;
38
+ }
39
+
40
+ export interface NodeDisplay {
41
+ label: string;
42
+ description?: string;
43
+ /** Category tags — a node appears in every palette tab whose tag it carries. */
44
+ tags: string[];
45
+ /** Hex header colour. */
46
+ color: string;
47
+ internal?: boolean;
48
+ /** Which account provider an `Account` input lists (`'<pluginId>:<provider>'`). */
49
+ accountProvider?: string;
50
+ }
51
+
52
+ /** Base class of every signal node (the host's `Node`). */
53
+ export declare abstract class SignalNodeBase {
54
+ /** The node's inline config; also carries host-injected `_projectId`. */
55
+ protected get config(): Record<string, unknown>;
56
+ protected get selfId(): string;
57
+ protected get enabled(): boolean;
58
+ protected getState<T = unknown>(): T;
59
+ protected setState(state: unknown): void;
60
+ protected input(portName: string): unknown;
61
+ protected emitOn(portName: string, value: unknown): void;
62
+ /** Called after the engine wired all ports. */
63
+ protected onBind(): void;
64
+ protected onUnbind(): void;
65
+ }
66
+
67
+ export interface SignalNodeClass {
68
+ /** Must start with `<pluginId>_`. */
69
+ readonly kind: string;
70
+ new (): SignalNodeBase;
71
+ }
72
+
73
+ type FieldDecorator = (value: undefined, ctx: ClassFieldDecoratorContext) => void;
74
+ type MethodDecorator = (
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ value: (...args: any[]) => any,
77
+ ctx: ClassMethodDecoratorContext
78
+ ) => void;
79
+ type ClassDecorator = (
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ value: abstract new (...args: any[]) => unknown,
82
+ ctx: ClassDecoratorContext
83
+ ) => void;
84
+
85
+ export interface SignalSdk {
86
+ Node: typeof SignalNodeBase;
87
+ SignalNode(display: NodeDisplay): ClassDecorator;
88
+ eventIn(name: string, type: SignalTypeName): MethodDecorator;
89
+ valueIn(name: string, type: SignalTypeName): FieldDecorator;
90
+ listIn(name: string, type: SignalTypeName): FieldDecorator;
91
+ eventOut(name: string, type: SignalTypeName): FieldDecorator;
92
+ valueOut(name: string, type: SignalTypeName): FieldDecorator;
93
+ mkEvent<T>(payload: T): SignalEvent<T>;
94
+ }
95
+
96
+ // ─────────────────────────────────────────────────────────────────────────────
97
+ // Graph descriptors (shared by Actions and composites)
98
+ // ─────────────────────────────────────────────────────────────────────────────
99
+
100
+ export interface GraphNodeDescriptor {
101
+ id: string;
102
+ kind: string;
103
+ position: { x: number; y: number };
104
+ defaultConfig?: Record<string, unknown>;
105
+ }
106
+
107
+ export interface GraphEdgeDescriptor {
108
+ fromNodeId: string;
109
+ fromPort: string;
110
+ toNodeId: string;
111
+ toPort: string;
112
+ }
113
+
114
+ export interface TemplateGraph {
115
+ nodes: GraphNodeDescriptor[];
116
+ edges: GraphEdgeDescriptor[];
117
+ }
118
+
119
+ // ─────────────────────────────────────────────────────────────────────────────
120
+ // Declarative form fields (host-rendered; no plugin React needed)
121
+ // ─────────────────────────────────────────────────────────────────────────────
122
+
123
+ export type FieldControl =
124
+ | 'text'
125
+ | 'textarea'
126
+ | 'number'
127
+ | 'slider'
128
+ | 'select'
129
+ | 'toggle'
130
+ | 'color'
131
+ | 'duration'
132
+ | 'account'
133
+ | 'rank'
134
+ | 'cooldown'
135
+ | 'list';
136
+
137
+ export interface FormField {
138
+ /** Dotted settings path. */
139
+ path: string;
140
+ control: FieldControl;
141
+ /** i18n key in the plugin's namespace (`plugin-<id>`). */
142
+ label: string;
143
+ hint?: string;
144
+ options?: readonly string[];
145
+ min?: number;
146
+ max?: number;
147
+ step?: number;
148
+ /** `select` option labels: `option.<path>.<value>` (the value is shown
149
+ * when there is no translation). `account`: provider id
150
+ * (`'overlive'` or `'<pluginId>:<provider>'`). */
151
+ provider?: string;
152
+ /** Placeholders the field accepts (shown as chips under a template field). */
153
+ placeholders?: readonly string[];
154
+ when?: (read: (path: string) => unknown) => boolean;
155
+ }
156
+
157
+ // ─────────────────────────────────────────────────────────────────────────────
158
+ // Actions
159
+ // ─────────────────────────────────────────────────────────────────────────────
160
+
161
+ export type ActionSettings = Record<string, unknown>;
162
+
163
+ export interface ActionSettingField {
164
+ path: string;
165
+ class: 'value' | 'shape';
166
+ }
167
+
168
+ export type PreviewToken =
169
+ | { t: 'text'; text: string }
170
+ | { t: 'msg'; key: string; params?: Record<string, string | number> };
171
+
172
+ export interface ActionPreview {
173
+ headline: PreviewToken[];
174
+ lines: PreviewToken[][];
175
+ }
176
+
177
+ export interface ActionKindDef {
178
+ /** Must start with `<pluginId>_`. */
179
+ kind: string;
180
+ label: string;
181
+ icon: string;
182
+ fields: readonly ActionSettingField[];
183
+ /** The generated form (host `SchemaForm`). Omit when `ui.mjs` provides one. */
184
+ form?: readonly FormField[];
185
+ defaults(): ActionSettings;
186
+ normalize(raw: unknown): ActionSettings;
187
+ build(shape: ActionSettings): TemplateGraph;
188
+ preview(settings: ActionSettings): ActionPreview;
189
+ }
190
+
191
+ /** A response a Hotkey / Chat keyword / Keyword combo / Redemption / Named
192
+ * trigger action can run. */
193
+ export interface ResponseTypeDef {
194
+ /** Sink node kind. */
195
+ nodeKind: string;
196
+ /** Event input the trigger wires into. */
197
+ entryPort: string;
198
+ /** Value inputs of the sink, fed from `response.<field>`. */
199
+ fields: readonly string[];
200
+ /** How the editor renders each field. */
201
+ form: readonly FormField[];
202
+ /** i18n key of the response's label. */
203
+ label: string;
204
+ }
205
+
206
+ export type Out = [nodeId: string, port: string];
207
+
208
+ /** The template builder the built-in Action kinds use (`Tpl`). */
209
+ export interface TemplateBuilder {
210
+ node(id: string, kind: string, x: number, y: number, defaultConfig?: Record<string, unknown>): string;
211
+ wire(fromNodeId: string, fromPort: string, toNodeId: string, toPort: string): void;
212
+ /** Feed settings field `field` into `to.toPort` through a `settings` node. */
213
+ setting(field: string, to: string, toPort: string, x: number, y: number): void;
214
+ out(): TemplateGraph;
215
+ }
216
+
217
+ export interface CooldownSettings {
218
+ seconds: number;
219
+ group: string;
220
+ }
221
+
222
+ export interface ActionsSdk {
223
+ Tpl: new () => TemplateBuilder;
224
+ /** `chat_rank` gate fed by `minRank`. Returns the gate's pass output. */
225
+ addRankGate(b: TemplateBuilder, source: string, entry: Out, x: number): Out;
226
+ /** `cooldown` fed by `cooldown.seconds` / `cooldown.group`. */
227
+ addCooldown(b: TemplateBuilder, entries: Out[], x: number): Out;
228
+ /** Builds `!name` aliases → anchored regex (the Chat command kind's matcher). */
229
+ commandNames(command: unknown, aliases: unknown): string[];
230
+ commandPattern(names: string[]): string;
231
+ escapeRegExp(text: string): string;
232
+ /** Anchored, case-insensitive match of a reward title. */
233
+ rewardPattern(reward: unknown): string;
234
+ normalizeRank(raw: unknown): 'everyone' | 'sub' | 'mod' | 'broadcaster';
235
+ normalizeCooldown(raw: unknown, defaultSeconds: number): CooldownSettings;
236
+ /** Node kinds of the chat / redemption / named-trigger sources. */
237
+ readonly sources: {
238
+ chatCommand: 'overlive_chat_command';
239
+ redemption: 'overlive_redemption';
240
+ namedTrigger: 'on_trigger';
241
+ sendChat: 'overlive_send_chat';
242
+ };
243
+ }
244
+
245
+ // ─────────────────────────────────────────────────────────────────────────────
246
+ // Composites (compound layers)
247
+ // ─────────────────────────────────────────────────────────────────────────────
248
+
249
+ export type PartRtype = 'compose_layer' | 'scene_node' | 'logic' | 'track_clip';
250
+
251
+ export interface SettingLink {
252
+ part: string;
253
+ path: string;
254
+ cssVar?: string;
255
+ }
256
+
257
+ export interface CompositeSetting {
258
+ key: string;
259
+ control: 'text' | 'number' | 'slider' | 'select' | 'color' | 'asset' | 'account' | 'toggle' | 'duration';
260
+ group: string;
261
+ options?: string[];
262
+ min?: number;
263
+ max?: number;
264
+ step?: number;
265
+ percent?: boolean;
266
+ links?: SettingLink[];
267
+ provider?: string;
268
+ when?: (read: (key: string) => unknown) => boolean;
269
+ }
270
+
271
+ /** Labels live in the plugin's namespace under the host's composite keys:
272
+ * `type.<type>`, `group.<group>`, `setting.<key>`, `option.<key>.<option>`. */
273
+ export interface CompositeTypeDef {
274
+ /** Must start with `<pluginId>_`. */
275
+ type: string;
276
+ rootRtype: 'compose_layer' | 'scene_node';
277
+ parts: Record<string, PartRtype>;
278
+ settings: CompositeSetting[];
279
+ }
280
+
281
+ /** A placeable composite: one feed layer (plus optional logic). */
282
+ export interface FeedCompositePreset {
283
+ /** Composite type it instantiates. */
284
+ type: string;
285
+ /** i18n keys (plugin namespace). */
286
+ name: string;
287
+ description: string;
288
+ template: string;
289
+ css: string;
290
+ box: { x: number; y: number; width: number; height: number };
291
+ /** Optional graph owned by the layer (role `flow`); declare the type's
292
+ * `parts.flow: 'logic'`. Edges name their transport. */
293
+ flow?: {
294
+ nodes: GraphNodeDescriptor[];
295
+ edges: Array<GraphEdgeDescriptor & { kind: 'event' | 'value' | 'list' }>;
296
+ };
297
+ }
298
+
299
+ // ─────────────────────────────────────────────────────────────────────────────
300
+ // Entry factories
301
+ // ─────────────────────────────────────────────────────────────────────────────
302
+
303
+ export interface SharedSdk {
304
+ apiVersion: ApiVersion;
305
+ actions: ActionsSdk;
306
+ }
307
+
308
+ export interface SharedPlugin {
309
+ responseTypes?: Record<string, ResponseTypeDef>;
310
+ actionKinds?: ActionKindDef[];
311
+ compositeTypes?: CompositeTypeDef[];
312
+ compositePresets?: FeedCompositePreset[];
313
+ }
314
+
315
+ /** `shared.mjs` default export. Runs in the backend AND the browser. */
316
+ export type SharedFactory = (sdk: SharedSdk) => SharedPlugin;
317
+
318
+ // ── backend ──
319
+
320
+ export type AccountStatus =
321
+ | 'connected'
322
+ | 'connecting'
323
+ | 'reconnecting'
324
+ | 'disconnected'
325
+ | 'error'
326
+ | 'needs_reauth';
327
+
328
+ export interface OAuthTokens {
329
+ accessToken: string;
330
+ refreshToken?: string;
331
+ /** Epoch ms. */
332
+ expiresAt?: number;
333
+ scopes?: string[];
334
+ }
335
+
336
+ export interface AccountRow<Identity = Record<string, unknown>> {
337
+ id: string;
338
+ projectId: string;
339
+ provider: string;
340
+ label: string;
341
+ identity: Identity;
342
+ status: AccountStatus;
343
+ statusMessage: string | null;
344
+ isDefault: boolean;
345
+ }
346
+
347
+ export interface AccountProviderDef<Identity = Record<string, unknown>> {
348
+ /** Unique within the plugin. Full id: `<pluginId>:<id>`. */
349
+ id: string;
350
+ /** i18n key. */
351
+ label: string;
352
+ icon?: string;
353
+ auth: {
354
+ kind: 'oauth_pkce';
355
+ authorizeUrl: string;
356
+ tokenUrl: string;
357
+ scopes: readonly string[];
358
+ /** App credentials the user enters once per project (e.g. `clientId`). */
359
+ /** `secret: true` (e.g. `clientSecret`): kept server-side only and sent to
360
+ * the token endpoint as `client_secret`; the editor shows only whether it
361
+ * is set. */
362
+ appFields: readonly { path: string; control: 'text'; label: string; hint?: string; secret?: boolean }[];
363
+ /** Extra authorize params. */
364
+ extraParams?: Record<string, string>;
365
+ };
366
+ /** Called after a token exchange; returns the identity shown in the list. */
367
+ fetchIdentity(tokens: OAuthTokens): Promise<{ label: string; identity: Identity & Record<string, unknown> }>;
368
+ /** i18n key of a setup walkthrough shown in the add dialog (markdown). */
369
+ setupHelp?: string;
370
+ }
371
+
372
+ export interface AccountsApi {
373
+ defineProvider(def: AccountProviderDef): void;
374
+ list(projectId: string, provider: string): AccountRow[];
375
+ get(accountId: string): AccountRow | undefined;
376
+ /** The project's default account of a provider (empty `account` ports resolve to it). */
377
+ defaultFor(projectId: string, provider: string): AccountRow | undefined;
378
+ /** Runs `fn` with a valid access token, refreshing (and persisting) when expired.
379
+ * On a revoked refresh token the account goes to `needs_reauth` and this rejects. */
380
+ withToken<T>(accountId: string, fn: (accessToken: string) => Promise<T>): Promise<T>;
381
+ /** Forces a refresh on the next `withToken` (e.g. after a 401). */
382
+ invalidate(accountId: string): void;
383
+ setStatus(accountId: string, status: AccountStatus, message?: string): void;
384
+ /** Fires on create / delete / reconnect of an account of this plugin. */
385
+ onChanged(fn: (projectId: string) => void): () => void;
386
+ }
387
+
388
+ export interface LogicApi {
389
+ /** Fire `payload` into the `port` event input of every running node of `kind`
390
+ * in the project whose `account` input resolves to `accountId` (empty = default). */
391
+ routeEvent(projectId: string, kind: string, port: string, payload: unknown, accountId?: string): void;
392
+ /** Whether a running graph in the project contains a node of one of `kinds`. */
393
+ hasConsumers(projectId: string, kinds: readonly string[]): boolean;
394
+ }
395
+
396
+ export interface DataApi {
397
+ /** Publish data fields the project's feed layers see by bare name (mesh
398
+ * `data_field` documents in the project's scope — other projects never see
399
+ * them). Field names must be JS identifiers prefixed with the plugin id
400
+ * (`spotifyNowPlaying`). */
401
+ publish(projectId: string, fields: Record<string, unknown>): void;
402
+ /** Whether a feed layer in the project references `field` in its template. */
403
+ isReferenced(projectId: string, field: string): boolean;
404
+ }
405
+
406
+ export interface StorageApi {
407
+ get<T>(key: string): T | undefined;
408
+ set(key: string, value: unknown): void;
409
+ delete(key: string): void;
410
+ /** Same, namespaced per project (removed with the project). */
411
+ project(projectId: string): Omit<StorageApi, 'project'>;
412
+ }
413
+
414
+ export interface Logger {
415
+ info(...args: unknown[]): void;
416
+ warn(...args: unknown[]): void;
417
+ error(...args: unknown[]): void;
418
+ }
419
+
420
+ export interface BackendContext {
421
+ readonly pluginId: string;
422
+ readonly version: string;
423
+ readonly nodes: { register(...classes: SignalNodeClass[]): void };
424
+ readonly accounts: AccountsApi;
425
+ readonly logic: LogicApi;
426
+ readonly data: DataApi;
427
+ readonly storage: StorageApi;
428
+ readonly projects: {
429
+ loaded(): string[];
430
+ onLoaded(fn: (projectId: string) => void): () => void;
431
+ onUnloaded(fn: (projectId: string) => void): () => void;
432
+ };
433
+ /** Express router mounted at `/api/plugin/<id>/` — for OUTSIDE callers
434
+ * (OAuth redirects, webhooks). Editor features must use mesh documents
435
+ * (data fields), never these routes. Typed loosely on purpose. */
436
+ readonly http: { router(): unknown };
437
+ readonly log: Logger;
438
+ /** The plugin's section of config.json. */
439
+ readonly config: Record<string, unknown>;
440
+ /** The shared module's output, already registered with the host. */
441
+ readonly shared: SharedPlugin;
442
+ onDispose(fn: () => void | Promise<void>): void;
443
+ }
444
+
445
+ export interface BackendSdk extends SharedSdk {
446
+ signal: SignalSdk;
447
+ /** `fetch` routed through the host (proxy, User-Agent). */
448
+ fetch: typeof fetch;
449
+ }
450
+
451
+ export interface BackendPlugin {
452
+ activate(ctx: BackendContext): void | Promise<void>;
453
+ }
454
+
455
+ /** `backend.mjs` default export. */
456
+ export type BackendFactory = (sdk: BackendSdk) => BackendPlugin;
457
+
458
+ // ── browser (optional ui.mjs) ──
459
+
460
+ export interface UiSdk extends SharedSdk {
461
+ // Typed loosely so the preview does not depend on @types/react.
462
+ React: unknown;
463
+ useTranslation: (ns?: string) => { t: (key: string, opts?: Record<string, unknown>) => string };
464
+ components: Record<string, unknown>;
465
+ }
466
+
467
+ export interface UiPlugin {
468
+ /** Custom forms per action kind (instead of the generated `SchemaForm`). */
469
+ actionForms?: Record<string, unknown>;
470
+ }
471
+
472
+ /** `ui.mjs` default export. Reserved: the editor does not load `ui.mjs` yet
473
+ * (apiVersion 1 generates forms from `form`). */
474
+ export type UiFactory = (sdk: UiSdk) => UiPlugin;
475
+
476
+ // ─────────────────────────────────────────────────────────────────────────────
477
+ // plugin.json
478
+ // ─────────────────────────────────────────────────────────────────────────────
479
+
480
+ export interface PluginManifest {
481
+ id: string;
482
+ version: string;
483
+ apiVersion: ApiVersion;
484
+ /** Semver range of vspark versions. */
485
+ vspark: string;
486
+ name: Record<string, string>;
487
+ description: Record<string, string>;
488
+ author: string;
489
+ homepage?: string;
490
+ icon?: string;
491
+ entries: { backend?: string; shared?: string; ui?: string };
492
+ /** Hosts the plugin talks to (shown in the install dialog). */
493
+ network?: string[];
494
+ }
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "@vspark/plugin-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Typings of the vspark plugin API (apiVersion 1). Types only — vspark injects the SDK at runtime.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "types": "index.d.ts",
8
+ "files": ["index.d.ts", "README.md"],
9
+ "publishConfig": { "access": "public" },
10
+ "scripts": {
11
+ "lint": "tsc --noEmit -p ."
12
+ },
13
+ "devDependencies": {
14
+ "typescript": "^5.8.3"
15
+ }
16
+ }