lumiverse-spindle-types 0.5.17 → 0.5.19

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.5.17",
3
+ "version": "0.5.19",
4
4
  "types": "./src/index.ts",
5
5
  "keywords": [
6
6
  "lumiverse",
package/src/api.ts CHANGED
@@ -159,12 +159,25 @@ export interface MacroInterceptorCtxDTO {
159
159
  readonly userId?: string;
160
160
  }
161
161
 
162
+ /**
163
+ * Lets an interceptor that resolves the template report its real cache
164
+ * dependencies so the host's display-regex cache can store the result
165
+ * and invalidate it precisely.
166
+ */
167
+ export interface MacroInterceptorRichResultDTO {
168
+ text: string;
169
+ touchedVars?: readonly string[];
170
+ volatile?: boolean;
171
+ }
172
+
162
173
  /**
163
174
  * Return value of a macro interceptor handler.
164
175
  * - `string` replaces the template for subsequent interceptors + parsing.
176
+ * (forces a non-cacheable resolution when it changes the template).
177
+ * - {@link MacroInterceptorRichResultDTO}
165
178
  * - `void` / `undefined` passes the template through unchanged.
166
179
  */
167
- export type MacroInterceptorResultDTO = string | void;
180
+ export type MacroInterceptorResultDTO = string | MacroInterceptorRichResultDTO | void;
168
181
 
169
182
  // ─── Message Content Processor (permission: "chat_mutation") ───────────
170
183
 
@@ -774,6 +787,26 @@ export interface ChatChangedPayloadDTO {
774
787
  changedFields?: string[];
775
788
  }
776
789
 
790
+ /**
791
+ * Payload for `CHAT_FORKED` events. Emitted when a chat is forked (branched)
792
+ * from a specific message — the messages up to and including the fork point are
793
+ * copied into a brand-new chat that shares the source chat's character.
794
+ */
795
+ export interface ChatForkedPayloadDTO {
796
+ /** Id of the source chat that was forked. */
797
+ sourceChatId: string;
798
+ /** Id of the newly created forked chat. Equal to `chat.id`. */
799
+ forkedChatId: string;
800
+ /** The new forked chat row, including its `metadata` (carries `branched_from` and `branch_at_message`). */
801
+ chat: { id: string; [key: string]: unknown };
802
+ /** The `branch_id` assigned to every message copied into the forked chat. */
803
+ branchId: string;
804
+ /** Id of the message in the source chat the fork was taken at. Messages up to and including this one were copied into the forked chat. */
805
+ forkedAtMessageId: string;
806
+ /** Zero-based index of the fork-point message within the source chat. */
807
+ forkedAtMessageIndex: number;
808
+ }
809
+
777
810
  // ─── User Preset DTOs ───────────────────────────────────────────────────
778
811
 
779
812
  /** Option entry for `select` and `multiselect` prompt variables. */
package/src/dom.ts CHANGED
@@ -630,6 +630,71 @@ export interface SpindleFrontendProcessRegistry {
630
630
  ): () => void;
631
631
  }
632
632
 
633
+ export interface SpindleDisplayContext {
634
+ chatId?: string;
635
+ characterId?: string;
636
+ personaId?: string;
637
+ isUser: boolean;
638
+ depth: number;
639
+ messageId?: string;
640
+ messageIndex?: number;
641
+ role?: string;
642
+ dynamicMacros?: Record<string, string>;
643
+ }
644
+
645
+ export interface SpindleDisplayResolveResult {
646
+ content: string;
647
+ touchedVars?: string[];
648
+ cacheable?: boolean;
649
+ }
650
+
651
+ export interface SpindleDisplayTemplatesResult {
652
+ resolved: Record<string, string>;
653
+ touchedVars?: Record<string, string[]>;
654
+ cacheable?: Record<string, boolean>;
655
+ }
656
+
657
+ export interface SpindleDisplayBodyArgs {
658
+ content: string;
659
+ context: SpindleDisplayContext;
660
+ }
661
+
662
+ export interface SpindleDisplayTemplatesArgs {
663
+ templates: Record<string, string>;
664
+ context: SpindleDisplayContext;
665
+ }
666
+
667
+ export interface SpindleDisplayScriptsArgs {
668
+ content: string;
669
+ scripts: unknown[];
670
+ context: SpindleDisplayContext;
671
+ resolvedFindPatterns?: Record<string, string>;
672
+ resolvedReplacements?: Record<string, string>;
673
+ }
674
+
675
+ /**
676
+ * A frontend display resolver lets an extension take over display-time content
677
+ * resolution in the browser instead of round-tripping to the host backend. The
678
+ * host consults the registered resolver while rendering messages and falls back
679
+ * to its own backend resolution whenever the resolver is absent, reports it is
680
+ * not ready for the chat, throws, or returns `null`.
681
+ */
682
+ export interface SpindleDisplayResolver {
683
+ ready(chatId: string): boolean;
684
+ resolveBody(args: SpindleDisplayBodyArgs): Promise<SpindleDisplayResolveResult | null>;
685
+ resolveTemplates(args: SpindleDisplayTemplatesArgs): Promise<SpindleDisplayTemplatesResult | null>;
686
+ applyScripts(args: SpindleDisplayScriptsArgs): Promise<SpindleDisplayResolveResult | null>;
687
+ }
688
+
689
+ export interface SpindleDisplayResolverRegistry {
690
+ /** Register this extension's frontend display resolver. */
691
+ registerResolver(resolver: SpindleDisplayResolver): () => void;
692
+ /** Ask the host to invalidate cached display resolutions whose dependencies (a `<scope>:<name>` set) changed. */
693
+ invalidate(touchedVars: string[]): void;
694
+ /** Publish the set of character IDs whose display this extension owns. The host uses it to decide synchronously, at render time, whether a chat is owned by this resolver. */
695
+ setOwnedCharacters(characterIds: string[]): void;
696
+ }
697
+
633
698
  /** Context object provided to frontend extension modules */
634
699
  export interface SpindleFrontendContext {
635
700
  dom: SpindleDOMHelper;
@@ -784,6 +849,8 @@ export interface SpindleFrontendContext {
784
849
  /** Update a message through the host app's authenticated API. */
785
850
  updateMessage(chatId: string, messageId: string, input: { content?: string }): Promise<unknown>;
786
851
  };
852
+ /** Take over display-time content resolution in the browser. */
853
+ display?: SpindleDisplayResolverRegistry;
787
854
  manifest: import("./manifest").SpindleManifest;
788
855
  }
789
856
 
package/src/events.ts CHANGED
@@ -14,6 +14,7 @@ export enum CoreEventType {
14
14
  CONNECTED = "CONNECTED",
15
15
  CHAT_CHANGED = "CHAT_CHANGED",
16
16
  CHAT_SWITCHED = "CHAT_SWITCHED",
17
+ CHAT_FORKED = "CHAT_FORKED",
17
18
  MESSAGE_SENT = "MESSAGE_SENT",
18
19
  MESSAGE_EDITED = "MESSAGE_EDITED",
19
20
  MESSAGE_DELETED = "MESSAGE_DELETED",
package/src/index.ts CHANGED
@@ -49,6 +49,7 @@ export type {
49
49
  ChatUpdateDTO,
50
50
  ChatSwitchedPayloadDTO,
51
51
  ChatChangedPayloadDTO,
52
+ ChatForkedPayloadDTO,
52
53
  PromptVariableOptionDTO,
53
54
  PromptVariableDefDTO,
54
55
  PromptVariableTypeDTO,
@@ -161,6 +162,7 @@ export type {
161
162
  MacroInterceptorEnvDTO,
162
163
  MacroInterceptorCtxDTO,
163
164
  MacroInterceptorResultDTO,
165
+ MacroInterceptorRichResultDTO,
164
166
  MessageContentProcessorOrigin,
165
167
  MessageContentProcessorCtxDTO,
166
168
  MessageContentProcessorResultDTO,
@@ -221,6 +223,14 @@ export type {
221
223
  SpindleUIEventsHelper,
222
224
  SpindleFrontendProcessContext,
223
225
  SpindleFrontendProcessRegistry,
226
+ SpindleDisplayResolver,
227
+ SpindleDisplayResolverRegistry,
228
+ SpindleDisplayContext,
229
+ SpindleDisplayBodyArgs,
230
+ SpindleDisplayTemplatesArgs,
231
+ SpindleDisplayScriptsArgs,
232
+ SpindleDisplayResolveResult,
233
+ SpindleDisplayTemplatesResult,
224
234
  } from "./dom";
225
235
 
226
236
  export type {
@@ -85,6 +85,7 @@ import type {
85
85
  BackendProcessLifecycleEventDTO,
86
86
  BackendProcessStopOptionsDTO,
87
87
  ChatChangedPayloadDTO,
88
+ ChatForkedPayloadDTO,
88
89
  ChatMessageDTO,
89
90
  GenerationStartedPayloadDTO,
90
91
  StreamTokenPayloadDTO,
@@ -220,6 +221,8 @@ export interface SpindleAPI {
220
221
  on(event: "GENERATION_STOPPED", handler: (payload: GenerationStoppedPayloadDTO, userId?: string) => void): () => void;
221
222
  /** Subscribe to `CHAT_CHANGED` events. `changedFields` lists the dot-paths that differed when emitted by the standard `updateChat` path; absent on emits from other sources. */
222
223
  on(event: "CHAT_CHANGED", handler: (payload: ChatChangedPayloadDTO, userId?: string) => void): () => void;
224
+ /** Subscribe to `CHAT_FORKED` events. Emitted when a chat is forked (branched) from a message into a new chat. The payload carries the source/forked chat ids, the full forked chat row, and the fork point. */
225
+ on(event: "CHAT_FORKED", handler: (payload: ChatForkedPayloadDTO, userId?: string) => void): () => void;
223
226
  /**
224
227
  * Subscribe to swipe lifecycle events. The payload's `action` discriminator
225
228
  * tells you whether a swipe was added, updated, deleted, or navigated, and