lumiverse-spindle-types 0.4.44 → 0.4.46
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 +1 -1
- package/src/api.ts +104 -0
- package/src/events.ts +1 -0
- package/src/index.ts +19 -5
- package/src/spindle-api.ts +91 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -475,6 +475,12 @@ export interface ChatUpdateDTO {
|
|
|
475
475
|
metadata?: Record<string, unknown>;
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
+
/** Payload for `CHAT_SWITCHED` events. */
|
|
479
|
+
export interface ChatSwitchedPayloadDTO {
|
|
480
|
+
/** The chat the user switched to, or `null` when returning to the home screen. */
|
|
481
|
+
chatId: string | null;
|
|
482
|
+
}
|
|
483
|
+
|
|
478
484
|
// ─── World Book DTOs ─────────────────────────────────────────────────────
|
|
479
485
|
|
|
480
486
|
/**
|
|
@@ -1169,6 +1175,96 @@ export interface FrontendProcessStopOptionsDTO {
|
|
|
1169
1175
|
reason?: string;
|
|
1170
1176
|
}
|
|
1171
1177
|
|
|
1178
|
+
// ─── Backend Process Lifecycle DTOs ─────────────────────────────────────
|
|
1179
|
+
|
|
1180
|
+
/** High-level lifecycle state for an isolated backend subprocess tracked by the host. */
|
|
1181
|
+
export type BackendProcessStateDTO =
|
|
1182
|
+
| "starting"
|
|
1183
|
+
| "running"
|
|
1184
|
+
| "stopping"
|
|
1185
|
+
| "stopped"
|
|
1186
|
+
| "completed"
|
|
1187
|
+
| "failed"
|
|
1188
|
+
| "timed_out";
|
|
1189
|
+
|
|
1190
|
+
/** Terminal reason attached to backend-process lifecycle events and snapshots when available. */
|
|
1191
|
+
export type BackendProcessExitReasonDTO =
|
|
1192
|
+
| "completed"
|
|
1193
|
+
| "failed"
|
|
1194
|
+
| "stopped"
|
|
1195
|
+
| "timed_out"
|
|
1196
|
+
| "backend_unloaded"
|
|
1197
|
+
| "replaced";
|
|
1198
|
+
|
|
1199
|
+
/** Options used when spawning an isolated backend subprocess from the backend worker. */
|
|
1200
|
+
export interface BackendProcessSpawnOptionsDTO {
|
|
1201
|
+
/** Built JS entry file under the extension repo, typically in `dist/`. */
|
|
1202
|
+
entry: string;
|
|
1203
|
+
/** Optional logical label used for lifecycle filtering and dedupe semantics. Defaults to `entry`. */
|
|
1204
|
+
kind?: string;
|
|
1205
|
+
/** Optional extension-defined stable key used for dedupe / replacement semantics. */
|
|
1206
|
+
key?: string;
|
|
1207
|
+
/** Optional process-scoped startup payload delivered to the subprocess entry. */
|
|
1208
|
+
payload?: unknown;
|
|
1209
|
+
/** Arbitrary metadata stored alongside the process snapshot for backend bookkeeping. */
|
|
1210
|
+
metadata?: Record<string, unknown>;
|
|
1211
|
+
/** For operator-scoped extensions only. */
|
|
1212
|
+
userId?: string;
|
|
1213
|
+
/** Reject spawn if the subprocess does not call `process.ready()` within this window. */
|
|
1214
|
+
startupTimeoutMs?: number;
|
|
1215
|
+
/** Mark the subprocess timed out if it stops heartbeating for this long after ready. */
|
|
1216
|
+
heartbeatTimeoutMs?: number;
|
|
1217
|
+
/** Replace any existing process with the same `key` for the target user. */
|
|
1218
|
+
replaceExisting?: boolean;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/** Filter used for backend subprocess list queries. */
|
|
1222
|
+
export interface BackendProcessListOptionsDTO {
|
|
1223
|
+
userId?: string;
|
|
1224
|
+
kind?: string;
|
|
1225
|
+
key?: string;
|
|
1226
|
+
state?: BackendProcessStateDTO;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/** Current host-tracked snapshot of an isolated backend subprocess. */
|
|
1230
|
+
export interface BackendProcessInfoDTO {
|
|
1231
|
+
processId: string;
|
|
1232
|
+
entry: string;
|
|
1233
|
+
kind: string;
|
|
1234
|
+
key?: string;
|
|
1235
|
+
state: BackendProcessStateDTO;
|
|
1236
|
+
userId?: string;
|
|
1237
|
+
metadata?: Record<string, unknown>;
|
|
1238
|
+
startedAt: string;
|
|
1239
|
+
readyAt?: string;
|
|
1240
|
+
lastHeartbeatAt?: string;
|
|
1241
|
+
endedAt?: string;
|
|
1242
|
+
exitReason?: BackendProcessExitReasonDTO;
|
|
1243
|
+
error?: string;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
/** Lifecycle event emitted to backend workers for isolated backend subprocesses. */
|
|
1247
|
+
export interface BackendProcessLifecycleEventDTO {
|
|
1248
|
+
processId: string;
|
|
1249
|
+
entry: string;
|
|
1250
|
+
kind: string;
|
|
1251
|
+
key?: string;
|
|
1252
|
+
userId?: string;
|
|
1253
|
+
state: BackendProcessStateDTO;
|
|
1254
|
+
previousState?: BackendProcessStateDTO;
|
|
1255
|
+
at: string;
|
|
1256
|
+
exitReason?: BackendProcessExitReasonDTO;
|
|
1257
|
+
error?: string;
|
|
1258
|
+
metadata?: Record<string, unknown>;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/** Options for graceful isolated-backend-process termination. */
|
|
1262
|
+
export interface BackendProcessStopOptionsDTO {
|
|
1263
|
+
userId?: string;
|
|
1264
|
+
/** Optional reason surfaced to the subprocess stop handler. */
|
|
1265
|
+
reason?: string;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1172
1268
|
// ─── Generation Event Payload DTOs ──────────────────────────────────────
|
|
1173
1269
|
|
|
1174
1270
|
/** Payload for `GENERATION_STARTED` events. */
|
|
@@ -1735,6 +1831,12 @@ export type WorkerToHost =
|
|
|
1735
1831
|
| { type: "frontend_process_get"; requestId: string; processId: string }
|
|
1736
1832
|
| { type: "frontend_process_stop"; requestId: string; processId: string; options?: FrontendProcessStopOptionsDTO }
|
|
1737
1833
|
| { type: "frontend_process_send"; processId: string; payload: unknown; userId?: string }
|
|
1834
|
+
// ─── Backend Process Lifecycle (free tier) ────────────────────────────
|
|
1835
|
+
| { type: "backend_process_spawn"; requestId: string; options: BackendProcessSpawnOptionsDTO }
|
|
1836
|
+
| { type: "backend_process_list"; requestId: string; filter?: BackendProcessListOptionsDTO }
|
|
1837
|
+
| { type: "backend_process_get"; requestId: string; processId: string }
|
|
1838
|
+
| { type: "backend_process_stop"; requestId: string; processId: string; options?: BackendProcessStopOptionsDTO }
|
|
1839
|
+
| { type: "backend_process_send"; processId: string; payload: unknown; userId?: string }
|
|
1738
1840
|
// ─── Macro Resolution (free tier) ──────────────────────────────────
|
|
1739
1841
|
| { type: "macros_resolve"; requestId: string; template: string; chatId?: string; characterId?: string; userId?: string; commit?: boolean }
|
|
1740
1842
|
// ─── Image Generation (gated: "image_gen") ──────────────────────────
|
|
@@ -1853,6 +1955,8 @@ export type HostToWorker =
|
|
|
1853
1955
|
| { type: "frontend_message"; payload: unknown; userId: string }
|
|
1854
1956
|
| { type: "frontend_process_lifecycle"; event: FrontendProcessLifecycleEventDTO }
|
|
1855
1957
|
| { type: "frontend_process_message"; processId: string; payload: unknown; userId: string }
|
|
1958
|
+
| { type: "backend_process_lifecycle"; event: BackendProcessLifecycleEventDTO }
|
|
1959
|
+
| { type: "backend_process_message"; processId: string; payload: unknown; userId: string }
|
|
1856
1960
|
| {
|
|
1857
1961
|
type: "oauth_callback";
|
|
1858
1962
|
requestId: string;
|
package/src/events.ts
CHANGED
|
@@ -13,6 +13,7 @@ export enum SpindleEvent {
|
|
|
13
13
|
export enum CoreEventType {
|
|
14
14
|
CONNECTED = "CONNECTED",
|
|
15
15
|
CHAT_CHANGED = "CHAT_CHANGED",
|
|
16
|
+
CHAT_SWITCHED = "CHAT_SWITCHED",
|
|
16
17
|
MESSAGE_SENT = "MESSAGE_SENT",
|
|
17
18
|
MESSAGE_EDITED = "MESSAGE_EDITED",
|
|
18
19
|
MESSAGE_DELETED = "MESSAGE_DELETED",
|
package/src/index.ts
CHANGED
|
@@ -33,9 +33,10 @@ export type {
|
|
|
33
33
|
CharacterCreateDTO,
|
|
34
34
|
CharacterAvatarUploadDTO,
|
|
35
35
|
CharacterUpdateDTO,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
ChatDTO,
|
|
37
|
+
ChatUpdateDTO,
|
|
38
|
+
ChatSwitchedPayloadDTO,
|
|
39
|
+
WorldBookDTO,
|
|
39
40
|
WorldBookCreateDTO,
|
|
40
41
|
WorldBookUpdateDTO,
|
|
41
42
|
WorldBookEntryDTO,
|
|
@@ -84,7 +85,14 @@ export type {
|
|
|
84
85
|
FrontendProcessInfoDTO,
|
|
85
86
|
FrontendProcessLifecycleEventDTO,
|
|
86
87
|
FrontendProcessStopOptionsDTO,
|
|
87
|
-
|
|
88
|
+
BackendProcessStateDTO,
|
|
89
|
+
BackendProcessExitReasonDTO,
|
|
90
|
+
BackendProcessSpawnOptionsDTO,
|
|
91
|
+
BackendProcessListOptionsDTO,
|
|
92
|
+
BackendProcessInfoDTO,
|
|
93
|
+
BackendProcessLifecycleEventDTO,
|
|
94
|
+
BackendProcessStopOptionsDTO,
|
|
95
|
+
GenerationStartedPayloadDTO,
|
|
88
96
|
StreamTokenPayloadDTO,
|
|
89
97
|
GenerationEndedPayloadDTO,
|
|
90
98
|
GenerationStoppedPayloadDTO,
|
|
@@ -145,7 +153,13 @@ export type {
|
|
|
145
153
|
|
|
146
154
|
export type { ExtensionInfo } from "./extension-info";
|
|
147
155
|
|
|
148
|
-
export type {
|
|
156
|
+
export type {
|
|
157
|
+
SpindleAPI,
|
|
158
|
+
FrontendProcessHandle,
|
|
159
|
+
BackendProcessHandle,
|
|
160
|
+
SpindleBackendProcessContext,
|
|
161
|
+
SpindleBackendProcessModule,
|
|
162
|
+
} from "./spindle-api";
|
|
149
163
|
|
|
150
164
|
export type {
|
|
151
165
|
CouncilMember,
|
package/src/spindle-api.ts
CHANGED
|
@@ -58,6 +58,11 @@ import type {
|
|
|
58
58
|
FrontendProcessInfoDTO,
|
|
59
59
|
FrontendProcessLifecycleEventDTO,
|
|
60
60
|
FrontendProcessStopOptionsDTO,
|
|
61
|
+
BackendProcessSpawnOptionsDTO,
|
|
62
|
+
BackendProcessListOptionsDTO,
|
|
63
|
+
BackendProcessInfoDTO,
|
|
64
|
+
BackendProcessLifecycleEventDTO,
|
|
65
|
+
BackendProcessStopOptionsDTO,
|
|
61
66
|
GenerationStartedPayloadDTO,
|
|
62
67
|
StreamTokenPayloadDTO,
|
|
63
68
|
GenerationEndedPayloadDTO,
|
|
@@ -92,6 +97,62 @@ export interface FrontendProcessHandle {
|
|
|
92
97
|
refresh(): Promise<FrontendProcessInfoDTO | null>;
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
export interface BackendProcessHandle {
|
|
101
|
+
/** Host-assigned process ID unique within the extension runtime. */
|
|
102
|
+
readonly processId: string;
|
|
103
|
+
/** Built subprocess entry file spawned by the host. */
|
|
104
|
+
readonly entry: string;
|
|
105
|
+
/** Logical process kind used for filtering and dedupe semantics. */
|
|
106
|
+
readonly kind: string;
|
|
107
|
+
/** Optional extension-defined stable key. */
|
|
108
|
+
readonly key?: string;
|
|
109
|
+
/** Current known snapshot at the time the handle was created or last refreshed. */
|
|
110
|
+
readonly info: BackendProcessInfoDTO;
|
|
111
|
+
/** Send a process-scoped message to the isolated subprocess. */
|
|
112
|
+
send(payload: unknown): void;
|
|
113
|
+
/** Request graceful termination. */
|
|
114
|
+
stop(options?: BackendProcessStopOptionsDTO): Promise<void>;
|
|
115
|
+
/** Fetch the latest authoritative snapshot from the host. */
|
|
116
|
+
refresh(): Promise<BackendProcessInfoDTO | null>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Controller passed to a backend subprocess entry exported by the extension. */
|
|
120
|
+
export interface SpindleBackendProcessContext {
|
|
121
|
+
/** Host-assigned ID unique within the extension runtime. */
|
|
122
|
+
processId: string;
|
|
123
|
+
/** Built entry file the host spawned. */
|
|
124
|
+
entry: string;
|
|
125
|
+
/** Logical process kind supplied during spawn. */
|
|
126
|
+
kind: string;
|
|
127
|
+
/** Optional extension-defined stable key passed at spawn time. */
|
|
128
|
+
key?: string;
|
|
129
|
+
/** Arbitrary spawn payload provided by the parent backend runtime. */
|
|
130
|
+
payload: unknown;
|
|
131
|
+
/** Optional backend-side bookkeeping metadata snapshot. */
|
|
132
|
+
metadata?: Record<string, unknown>;
|
|
133
|
+
/** Target user for operator-scoped spawns. */
|
|
134
|
+
userId?: string;
|
|
135
|
+
/** Signal that startup completed successfully. Required for startup watchdogs. */
|
|
136
|
+
ready(): void;
|
|
137
|
+
/** Refresh the host-side heartbeat timer for long-lived loops. */
|
|
138
|
+
heartbeat(): void;
|
|
139
|
+
/** Send a process-scoped message back to the parent backend runtime. */
|
|
140
|
+
send(payload: unknown): void;
|
|
141
|
+
/** Subscribe to process-scoped messages from the parent backend runtime. */
|
|
142
|
+
onMessage(handler: (payload: unknown) => void): () => void;
|
|
143
|
+
/** Mark the subprocess as completed and release host tracking. */
|
|
144
|
+
complete(result?: unknown): void;
|
|
145
|
+
/** Mark the subprocess as failed. */
|
|
146
|
+
fail(error: string): void;
|
|
147
|
+
/** Called when the parent backend runtime requests graceful termination. */
|
|
148
|
+
onStop(handler: (detail: { reason?: string }) => void): () => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type SpindleBackendProcessModule = {
|
|
152
|
+
default?: (process: SpindleBackendProcessContext) => void | (() => void) | Promise<void | (() => void)>;
|
|
153
|
+
run?: (process: SpindleBackendProcessContext) => void | (() => void) | Promise<void | (() => void)>;
|
|
154
|
+
};
|
|
155
|
+
|
|
95
156
|
/** The global `spindle` object available in backend extension workers */
|
|
96
157
|
export interface SpindleAPI {
|
|
97
158
|
/** Subscribe to generation-started events (requires `generation` permission). The optional `userId` identifies which user triggered the event. */
|
|
@@ -870,6 +931,36 @@ export interface SpindleAPI {
|
|
|
870
931
|
): () => void;
|
|
871
932
|
};
|
|
872
933
|
|
|
934
|
+
/**
|
|
935
|
+
* Host-owned lifecycle controller for isolated backend subprocesses.
|
|
936
|
+
*
|
|
937
|
+
* Use this when one slice of backend extension logic may block or hang and
|
|
938
|
+
* you need the host to retain kill authority via startup and heartbeat
|
|
939
|
+
* watchdogs. The spawned entry receives a
|
|
940
|
+
* {@link SpindleBackendProcessContext} and communicates only with its parent
|
|
941
|
+
* backend runtime through process-scoped messages.
|
|
942
|
+
*/
|
|
943
|
+
backendProcesses: {
|
|
944
|
+
/**
|
|
945
|
+
* Spawn an isolated backend subprocess and wait for the entry to call
|
|
946
|
+
* `process.ready()`. If `startupTimeoutMs` elapses first, the promise
|
|
947
|
+
* rejects and the process transitions to `timed_out`.
|
|
948
|
+
*/
|
|
949
|
+
spawn(options: BackendProcessSpawnOptionsDTO): Promise<BackendProcessHandle>;
|
|
950
|
+
/** List tracked backend subprocesses visible to this extension runtime. */
|
|
951
|
+
list(filter?: BackendProcessListOptionsDTO): Promise<BackendProcessInfoDTO[]>;
|
|
952
|
+
/** Get a single tracked subprocess by ID. Returns `null` if it no longer exists. */
|
|
953
|
+
get(processId: string): Promise<BackendProcessInfoDTO | null>;
|
|
954
|
+
/** Request graceful termination of a tracked subprocess. */
|
|
955
|
+
stop(processId: string, options?: BackendProcessStopOptionsDTO): Promise<void>;
|
|
956
|
+
/** Subscribe to lifecycle transitions (`starting`, `running`, `timed_out`, etc.). */
|
|
957
|
+
onLifecycle(handler: (event: BackendProcessLifecycleEventDTO) => void): () => void;
|
|
958
|
+
/** Receive process-scoped messages sent from the subprocess entry. */
|
|
959
|
+
onMessage(
|
|
960
|
+
handler: (event: { processId: string; payload: unknown; userId: string }) => void,
|
|
961
|
+
): () => void;
|
|
962
|
+
};
|
|
963
|
+
|
|
873
964
|
/** Logging */
|
|
874
965
|
log: {
|
|
875
966
|
info(msg: string): void;
|