lumiverse-spindle-types 0.4.43 → 0.4.44

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": "lumiverse-spindle-types",
3
- "version": "0.4.43",
3
+ "version": "0.4.44",
4
4
  "types": "./src/index.ts",
5
5
  "keywords": [
6
6
  "lumiverse",
package/src/api.ts CHANGED
@@ -1008,7 +1008,8 @@ export interface ThemeVariablesConfigDTO {
1008
1008
  * This is the safe, presentation-owned path for live extension theming.
1009
1009
  * Extensions provide palette intent only; Lumiverse preserves the user's
1010
1010
  * radius, glass, font, and UI-scale settings and generates the final
1011
- * mode-aware variable maps itself.
1011
+ * mode-aware variable maps itself. Pass `null` to clear a previously applied
1012
+ * palette override when no valid color data is available.
1012
1013
  */
1013
1014
  export interface ThemePaletteConfigDTO {
1014
1015
  /** Primary accent color in HSL. */
@@ -1081,6 +1082,93 @@ export interface SpindleCommandContextDTO {
1081
1082
  isGroupChat?: boolean;
1082
1083
  }
1083
1084
 
1085
+ // ─── Frontend Process Lifecycle DTOs ────────────────────────────────────
1086
+
1087
+ /** High-level lifecycle state for a frontend process tracked by the backend host. */
1088
+ export type FrontendProcessStateDTO =
1089
+ | "starting"
1090
+ | "running"
1091
+ | "stopping"
1092
+ | "stopped"
1093
+ | "completed"
1094
+ | "failed"
1095
+ | "timed_out";
1096
+
1097
+ /** Terminal reason attached to lifecycle events and snapshots when available. */
1098
+ export type FrontendProcessExitReasonDTO =
1099
+ | "completed"
1100
+ | "failed"
1101
+ | "stopped"
1102
+ | "timed_out"
1103
+ | "frontend_unloaded"
1104
+ | "backend_unloaded"
1105
+ | "replaced";
1106
+
1107
+ /** Options used when spawning a tracked frontend process from the backend worker. */
1108
+ export interface FrontendProcessSpawnOptionsDTO {
1109
+ /** Frontend handler key registered via `ctx.processes.register(kind, ...)`. */
1110
+ kind: string;
1111
+ /** Optional extension-defined stable key used for dedupe / replacement semantics. */
1112
+ key?: string;
1113
+ /** Optional process-scoped startup payload delivered to the frontend handler. */
1114
+ payload?: unknown;
1115
+ /** Arbitrary metadata stored alongside the process snapshot for backend bookkeeping. */
1116
+ metadata?: Record<string, unknown>;
1117
+ /** For operator-scoped extensions only. */
1118
+ userId?: string;
1119
+ /** Reject spawn if the frontend does not call `process.ready()` within this window. */
1120
+ startupTimeoutMs?: number;
1121
+ /** Mark the process timed out if the frontend stops heartbeating for this long after ready. */
1122
+ heartbeatTimeoutMs?: number;
1123
+ /** Replace any existing process with the same `key` for the target user. */
1124
+ replaceExisting?: boolean;
1125
+ }
1126
+
1127
+ /** Filter used for controller list queries. */
1128
+ export interface FrontendProcessListOptionsDTO {
1129
+ userId?: string;
1130
+ kind?: string;
1131
+ key?: string;
1132
+ state?: FrontendProcessStateDTO;
1133
+ }
1134
+
1135
+ /** Current host-tracked snapshot of a frontend process. */
1136
+ export interface FrontendProcessInfoDTO {
1137
+ processId: string;
1138
+ kind: string;
1139
+ key?: string;
1140
+ state: FrontendProcessStateDTO;
1141
+ userId?: string;
1142
+ metadata?: Record<string, unknown>;
1143
+ startedAt: string;
1144
+ readyAt?: string;
1145
+ lastHeartbeatAt?: string;
1146
+ endedAt?: string;
1147
+ exitReason?: FrontendProcessExitReasonDTO;
1148
+ error?: string;
1149
+ }
1150
+
1151
+ /** Lifecycle event emitted to backend workers for tracked frontend processes. */
1152
+ export interface FrontendProcessLifecycleEventDTO {
1153
+ processId: string;
1154
+ kind: string;
1155
+ key?: string;
1156
+ userId?: string;
1157
+ state: FrontendProcessStateDTO;
1158
+ previousState?: FrontendProcessStateDTO;
1159
+ at: string;
1160
+ exitReason?: FrontendProcessExitReasonDTO;
1161
+ error?: string;
1162
+ metadata?: Record<string, unknown>;
1163
+ }
1164
+
1165
+ /** Options for graceful process termination. */
1166
+ export interface FrontendProcessStopOptionsDTO {
1167
+ userId?: string;
1168
+ /** Optional reason surfaced to the frontend process' stop handler. */
1169
+ reason?: string;
1170
+ }
1171
+
1084
1172
  // ─── Generation Event Payload DTOs ──────────────────────────────────────
1085
1173
 
1086
1174
  /** Payload for `GENERATION_STARTED` events. */
@@ -1641,6 +1729,12 @@ export type WorkerToHost =
1641
1729
  | { type: "modal_close"; requestId: string; openRequestId: string; userId?: string }
1642
1730
  | { type: "confirm_open"; requestId: string; title: string; message: string; variant?: "info" | "warning" | "danger" | "success"; confirmLabel?: string; cancelLabel?: string; userId?: string }
1643
1731
  | { type: "input_prompt_open"; requestId: string; title: string; message?: string; placeholder?: string; defaultValue?: string; submitLabel?: string; cancelLabel?: string; multiline?: boolean; userId?: string }
1732
+ // ─── Frontend Process Lifecycle (free tier) ───────────────────────────
1733
+ | { type: "frontend_process_spawn"; requestId: string; options: FrontendProcessSpawnOptionsDTO }
1734
+ | { type: "frontend_process_list"; requestId: string; filter?: FrontendProcessListOptionsDTO }
1735
+ | { type: "frontend_process_get"; requestId: string; processId: string }
1736
+ | { type: "frontend_process_stop"; requestId: string; processId: string; options?: FrontendProcessStopOptionsDTO }
1737
+ | { type: "frontend_process_send"; processId: string; payload: unknown; userId?: string }
1644
1738
  // ─── Macro Resolution (free tier) ──────────────────────────────────
1645
1739
  | { type: "macros_resolve"; requestId: string; template: string; chatId?: string; characterId?: string; userId?: string; commit?: boolean }
1646
1740
  // ─── Image Generation (gated: "image_gen") ──────────────────────────
@@ -1651,7 +1745,7 @@ export type WorkerToHost =
1651
1745
  | { type: "image_gen_models"; requestId: string; connectionId: string; userId?: string }
1652
1746
  // ─── Theme (gated: "app_manipulation") ──────────────────────────────────
1653
1747
  | { type: "theme_apply"; requestId: string; overrides: ThemeOverrideDTO; userId?: string }
1654
- | { type: "theme_apply_palette"; requestId: string; palette: ThemePaletteConfigDTO; userId?: string }
1748
+ | { type: "theme_apply_palette"; requestId: string; palette: ThemePaletteConfigDTO | null; userId?: string }
1655
1749
  | { type: "theme_clear"; requestId: string; userId?: string }
1656
1750
  | { type: "theme_get_current"; requestId: string; userId?: string }
1657
1751
  // ─── Color Extraction (gated: "app_manipulation") ─────────────────────
@@ -1757,6 +1851,8 @@ export type HostToWorker =
1757
1851
  }
1758
1852
  | { type: "shutdown" }
1759
1853
  | { type: "frontend_message"; payload: unknown; userId: string }
1854
+ | { type: "frontend_process_lifecycle"; event: FrontendProcessLifecycleEventDTO }
1855
+ | { type: "frontend_process_message"; processId: string; payload: unknown; userId: string }
1760
1856
  | {
1761
1857
  type: "oauth_callback";
1762
1858
  requestId: string;
package/src/dom.ts CHANGED
@@ -326,6 +326,53 @@ export interface SpindleConfirmResult {
326
326
  confirmed: boolean;
327
327
  }
328
328
 
329
+ // ── Frontend Process Lifecycle ──
330
+
331
+ /** Controller passed to a frontend process instance spawned by the backend runtime. */
332
+ export interface SpindleFrontendProcessContext {
333
+ /** Host-assigned ID unique within the extension runtime. */
334
+ processId: string;
335
+ /** Frontend handler key used when the backend called `spindle.frontendProcesses.spawn()`. */
336
+ kind: string;
337
+ /** Optional extension-defined stable key passed at spawn time. */
338
+ key?: string;
339
+ /** Arbitrary spawn payload provided by the backend. */
340
+ payload: unknown;
341
+ /** Optional backend-side bookkeeping metadata snapshot. */
342
+ metadata?: Record<string, unknown>;
343
+ /** Signal that startup completed successfully. Required for startup watchdogs. */
344
+ ready(): void;
345
+ /** Refresh the host-side heartbeat timer for long-lived loops. */
346
+ heartbeat(): void;
347
+ /** Send a process-scoped message back to the backend runtime. */
348
+ send(payload: unknown): void;
349
+ /** Subscribe to process-scoped messages from the backend runtime. */
350
+ onMessage(handler: (payload: unknown) => void): () => void;
351
+ /** Mark the process as completed and release host tracking. */
352
+ complete(result?: unknown): void;
353
+ /** Mark the process as failed. */
354
+ fail(error: string): void;
355
+ /** Called when the backend requests graceful termination. */
356
+ onStop(handler: (detail: { reason?: string }) => void): () => void;
357
+ }
358
+
359
+ /** Registry exposed to frontend modules for backend-spawned frontend processes. */
360
+ export interface SpindleFrontendProcessRegistry {
361
+ /**
362
+ * Register a process handler for the given `kind`.
363
+ *
364
+ * The returned cleanup function unregisters the handler. If the handler
365
+ * itself returns a cleanup function, the host should call it when the
366
+ * process is stopped, replaced, or the extension is unloaded.
367
+ */
368
+ register(
369
+ kind: string,
370
+ handler: (
371
+ process: SpindleFrontendProcessContext,
372
+ ) => void | (() => void) | Promise<void | (() => void)>,
373
+ ): () => void;
374
+ }
375
+
329
376
  /** Context object provided to frontend extension modules */
330
377
  export interface SpindleFrontendContext {
331
378
  dom: SpindleDOMHelper;
@@ -416,6 +463,8 @@ export interface SpindleFrontendContext {
416
463
  getActiveChat(): { chatId: string | null; characterId: string | null };
417
464
  sendToBackend(payload: unknown): void;
418
465
  onBackendMessage(handler: (payload: unknown) => void): () => void;
466
+ /** Structured lifecycle hooks for backend-spawned frontend processes. */
467
+ processes: SpindleFrontendProcessRegistry;
419
468
  messages: {
420
469
  registerTagInterceptor(
421
470
  options: SpindleMessageTagInterceptorOptions,
package/src/index.ts CHANGED
@@ -75,9 +75,16 @@ export type {
75
75
  ColorRGB,
76
76
  ColorHSL,
77
77
  SpindleModalItemDTO,
78
- SpindleCommandDTO,
79
- SpindleCommandContextDTO,
80
- GenerationStartedPayloadDTO,
78
+ SpindleCommandDTO,
79
+ SpindleCommandContextDTO,
80
+ FrontendProcessStateDTO,
81
+ FrontendProcessExitReasonDTO,
82
+ FrontendProcessSpawnOptionsDTO,
83
+ FrontendProcessListOptionsDTO,
84
+ FrontendProcessInfoDTO,
85
+ FrontendProcessLifecycleEventDTO,
86
+ FrontendProcessStopOptionsDTO,
87
+ GenerationStartedPayloadDTO,
81
88
  StreamTokenPayloadDTO,
82
89
  GenerationEndedPayloadDTO,
83
90
  GenerationStoppedPayloadDTO,
@@ -129,14 +136,16 @@ export type {
129
136
  SpindleContextMenuResult,
130
137
  SpindleModalOptions,
131
138
  SpindleModalHandle,
132
- SpindleConfirmVariant,
133
- SpindleConfirmOptions,
134
- SpindleConfirmResult,
139
+ SpindleConfirmVariant,
140
+ SpindleConfirmOptions,
141
+ SpindleConfirmResult,
142
+ SpindleFrontendProcessContext,
143
+ SpindleFrontendProcessRegistry,
135
144
  } from "./dom";
136
145
 
137
146
  export type { ExtensionInfo } from "./extension-info";
138
147
 
139
- export type { SpindleAPI } from "./spindle-api";
148
+ export type { SpindleAPI, FrontendProcessHandle } from "./spindle-api";
140
149
 
141
150
  export type {
142
151
  CouncilMember,
@@ -53,6 +53,11 @@ import type {
53
53
  SpindleModalItemDTO,
54
54
  SpindleCommandDTO,
55
55
  SpindleCommandContextDTO,
56
+ FrontendProcessSpawnOptionsDTO,
57
+ FrontendProcessListOptionsDTO,
58
+ FrontendProcessInfoDTO,
59
+ FrontendProcessLifecycleEventDTO,
60
+ FrontendProcessStopOptionsDTO,
56
61
  GenerationStartedPayloadDTO,
57
62
  StreamTokenPayloadDTO,
58
63
  GenerationEndedPayloadDTO,
@@ -70,6 +75,23 @@ import type {
70
75
  MessageContentProcessorResultDTO,
71
76
  } from "./api";
72
77
 
78
+ export interface FrontendProcessHandle {
79
+ /** Host-assigned process ID unique within the extension runtime. */
80
+ readonly processId: string;
81
+ /** Frontend handler key the process was spawned against. */
82
+ readonly kind: string;
83
+ /** Optional extension-defined stable key. */
84
+ readonly key?: string;
85
+ /** Current known snapshot at the time the handle was created or last refreshed. */
86
+ readonly info: FrontendProcessInfoDTO;
87
+ /** Send a process-scoped message to the frontend instance. */
88
+ send(payload: unknown): void;
89
+ /** Request graceful termination. */
90
+ stop(options?: FrontendProcessStopOptionsDTO): Promise<void>;
91
+ /** Fetch the latest authoritative snapshot from the host. */
92
+ refresh(): Promise<FrontendProcessInfoDTO | null>;
93
+ }
94
+
73
95
  /** The global `spindle` object available in backend extension workers */
74
96
  export interface SpindleAPI {
75
97
  /** Subscribe to generation-started events (requires `generation` permission). The optional `userId` identifies which user triggered the event. */
@@ -815,6 +837,39 @@ export interface SpindleAPI {
815
837
  /** Receive messages from the frontend module (userId is the sender) */
816
838
  onFrontendMessage(handler: (payload: unknown, userId: string) => void): () => void;
817
839
 
840
+ /**
841
+ * Backend-owned lifecycle controller for tracked frontend processes.
842
+ *
843
+ * Use this when the frontend needs to run one or more long-lived loops,
844
+ * workers, or UI-adjacent controllers whose liveness must be observable from
845
+ * the backend runtime. The frontend side registers handlers by `kind` via
846
+ * `ctx.processes.register(kind, handler)`.
847
+ *
848
+ * This is layered on top of the existing backend/frontend messaging model,
849
+ * but adds startup acknowledgement, heartbeat timeouts, process-scoped
850
+ * messaging, and structured lifecycle events.
851
+ */
852
+ frontendProcesses: {
853
+ /**
854
+ * Spawn a frontend process and wait for the frontend handler to call
855
+ * `process.ready()`. If `startupTimeoutMs` elapses first, the promise
856
+ * rejects and the process transitions to `timed_out`.
857
+ */
858
+ spawn(options: FrontendProcessSpawnOptionsDTO): Promise<FrontendProcessHandle>;
859
+ /** List tracked frontend processes visible to this extension runtime. */
860
+ list(filter?: FrontendProcessListOptionsDTO): Promise<FrontendProcessInfoDTO[]>;
861
+ /** Get a single tracked process by ID. Returns `null` if it no longer exists. */
862
+ get(processId: string): Promise<FrontendProcessInfoDTO | null>;
863
+ /** Request graceful termination of a tracked process. */
864
+ stop(processId: string, options?: FrontendProcessStopOptionsDTO): Promise<void>;
865
+ /** Subscribe to lifecycle transitions (`starting`, `running`, `timed_out`, etc.). */
866
+ onLifecycle(handler: (event: FrontendProcessLifecycleEventDTO) => void): () => void;
867
+ /** Receive process-scoped messages sent from the frontend side. */
868
+ onMessage(
869
+ handler: (event: { processId: string; payload: unknown; userId: string }) => void,
870
+ ): () => void;
871
+ };
872
+
818
873
  /** Logging */
819
874
  log: {
820
875
  info(msg: string): void;
@@ -1005,14 +1060,15 @@ export interface SpindleAPI {
1005
1060
  * Unlike `apply()`, this method does not let extensions push raw CSS
1006
1061
  * variables. Lumiverse derives the full light/dark variable maps from the
1007
1062
  * provided accent and preserves the user's glass, radius, font, and UI
1008
- * scale settings.
1063
+ * scale settings. Pass `null` to clear the extension's active palette
1064
+ * override when no valid color data is available.
1009
1065
  */
1010
- applyPalette(palette: ThemePaletteConfigDTO, userId?: string): Promise<void>;
1066
+ applyPalette(palette: ThemePaletteConfigDTO | null, userId?: string): Promise<void>;
1011
1067
  /**
1012
1068
  * Remove all CSS variable overrides previously applied by this extension.
1013
1069
  * The UI reverts to the user's base theme.
1014
1070
  */
1015
- clear(): Promise<void>;
1071
+ clear(userId?: string): Promise<void>;
1016
1072
  /**
1017
1073
  * Get a read-only snapshot of the user's current theme configuration.
1018
1074
  * Returns the base theme info (not including any extension overrides).