lumiverse-spindle-types 0.4.57 → 0.4.59
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 +187 -1
- package/src/events.ts +2 -0
- package/src/index.ts +14 -0
- package/src/permissions.ts +2 -0
- package/src/spindle-api.ts +58 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -97,6 +97,12 @@ export interface MacroInterceptorEnvDTO {
|
|
|
97
97
|
readonly global: Record<string, string>;
|
|
98
98
|
readonly chat: Record<string, string>;
|
|
99
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* Per-call dynamic macros injected by the caller (e.g. display-regex
|
|
102
|
+
* pre-resolution passes `chat_index` here). Keys merge into the macro
|
|
103
|
+
* lookup table for the duration of one resolve() call.
|
|
104
|
+
*/
|
|
105
|
+
readonly dynamicMacros: Record<string, string>;
|
|
100
106
|
readonly extra: Record<string, unknown>;
|
|
101
107
|
}
|
|
102
108
|
|
|
@@ -138,7 +144,8 @@ export type MessageContentProcessorOrigin =
|
|
|
138
144
|
| "create"
|
|
139
145
|
| "update"
|
|
140
146
|
| "swipe_add"
|
|
141
|
-
| "swipe_update"
|
|
147
|
+
| "swipe_update"
|
|
148
|
+
| "render";
|
|
142
149
|
|
|
143
150
|
/**
|
|
144
151
|
* Context passed to a message content processor before a user-initiated
|
|
@@ -667,6 +674,166 @@ export interface WorldBookEntryCreateDTO {
|
|
|
667
674
|
|
|
668
675
|
export type WorldBookEntryUpdateDTO = WorldBookEntryCreateDTO;
|
|
669
676
|
|
|
677
|
+
// ─── Regex Script DTOs ──────────────────────────────────────────────────
|
|
678
|
+
|
|
679
|
+
export type RegexPlacementDTO = "user_input" | "ai_output" | "world_info" | "reasoning";
|
|
680
|
+
export type RegexScopeDTO = "global" | "character" | "chat";
|
|
681
|
+
export type RegexTargetDTO = "prompt" | "response" | "display";
|
|
682
|
+
export type RegexMacroModeDTO = "none" | "raw" | "escaped";
|
|
683
|
+
|
|
684
|
+
export interface RegexScriptDTO {
|
|
685
|
+
id: string;
|
|
686
|
+
name: string;
|
|
687
|
+
script_id: string;
|
|
688
|
+
find_regex: string;
|
|
689
|
+
replace_string: string;
|
|
690
|
+
flags: string;
|
|
691
|
+
placement: RegexPlacementDTO[];
|
|
692
|
+
scope: RegexScopeDTO;
|
|
693
|
+
scope_id: string | null;
|
|
694
|
+
target: RegexTargetDTO;
|
|
695
|
+
min_depth: number | null;
|
|
696
|
+
max_depth: number | null;
|
|
697
|
+
trim_strings: string[];
|
|
698
|
+
run_on_edit: boolean;
|
|
699
|
+
substitute_macros: RegexMacroModeDTO;
|
|
700
|
+
disabled: boolean;
|
|
701
|
+
sort_order: number;
|
|
702
|
+
description: string;
|
|
703
|
+
folder: string;
|
|
704
|
+
metadata: Record<string, unknown>;
|
|
705
|
+
created_at: number;
|
|
706
|
+
updated_at: number;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
export interface RegexScriptListOptionsDTO {
|
|
710
|
+
scope?: RegexScopeDTO;
|
|
711
|
+
scopeId?: string;
|
|
712
|
+
target?: RegexTargetDTO;
|
|
713
|
+
limit?: number;
|
|
714
|
+
offset?: number;
|
|
715
|
+
userId?: string;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
export interface RegexScriptActiveOptionsDTO {
|
|
719
|
+
target: RegexTargetDTO;
|
|
720
|
+
characterId?: string;
|
|
721
|
+
chatId?: string;
|
|
722
|
+
userId?: string;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export interface RegexScriptCreateDTO {
|
|
726
|
+
name: string;
|
|
727
|
+
find_regex: string;
|
|
728
|
+
replace_string?: string;
|
|
729
|
+
flags?: string;
|
|
730
|
+
placement?: RegexPlacementDTO[];
|
|
731
|
+
scope?: RegexScopeDTO;
|
|
732
|
+
scope_id?: string | null;
|
|
733
|
+
target?: RegexTargetDTO;
|
|
734
|
+
min_depth?: number | null;
|
|
735
|
+
max_depth?: number | null;
|
|
736
|
+
trim_strings?: string[];
|
|
737
|
+
run_on_edit?: boolean;
|
|
738
|
+
substitute_macros?: RegexMacroModeDTO;
|
|
739
|
+
disabled?: boolean;
|
|
740
|
+
sort_order?: number;
|
|
741
|
+
description?: string;
|
|
742
|
+
folder?: string;
|
|
743
|
+
metadata?: Record<string, unknown>;
|
|
744
|
+
script_id?: string;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export type RegexScriptUpdateDTO = Partial<RegexScriptCreateDTO>;
|
|
748
|
+
|
|
749
|
+
// ─── World Info Interceptor (permission: "generation") ─────────────────
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* One world info entry exposed to a `registerWorldInfoInterceptor` handler.
|
|
753
|
+
* Subset of `WorldBookEntryDTO` covering the fields the interceptor needs to
|
|
754
|
+
* inspect for activation gating.
|
|
755
|
+
*/
|
|
756
|
+
export interface WorldInfoInterceptorEntryDTO {
|
|
757
|
+
readonly id: string;
|
|
758
|
+
readonly world_book_id: string;
|
|
759
|
+
readonly comment: string;
|
|
760
|
+
readonly disabled: boolean;
|
|
761
|
+
readonly constant: boolean;
|
|
762
|
+
readonly extensions: Readonly<Record<string, unknown>>;
|
|
763
|
+
readonly key: readonly string[];
|
|
764
|
+
readonly keysecondary: readonly string[];
|
|
765
|
+
readonly position: number;
|
|
766
|
+
readonly depth: number;
|
|
767
|
+
readonly priority: number;
|
|
768
|
+
readonly probability: number;
|
|
769
|
+
readonly use_probability: boolean;
|
|
770
|
+
readonly content: string;
|
|
771
|
+
readonly automation_id: string | null;
|
|
772
|
+
readonly selective: boolean;
|
|
773
|
+
readonly selective_logic: number;
|
|
774
|
+
readonly match_whole_words: boolean;
|
|
775
|
+
readonly case_sensitive: boolean;
|
|
776
|
+
readonly use_regex: boolean;
|
|
777
|
+
readonly prevent_recursion: boolean;
|
|
778
|
+
readonly exclude_recursion: boolean;
|
|
779
|
+
readonly delay_until_recursion: boolean;
|
|
780
|
+
readonly scan_depth: number | null;
|
|
781
|
+
readonly order_value: number;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* One chat message exposed to a `registerWorldInfoInterceptor` handler.
|
|
786
|
+
* `index_in_chat` is the zero-based position in the chat's message list and
|
|
787
|
+
* `is_greeting` is true for the synthetic greeting row at index 0.
|
|
788
|
+
*/
|
|
789
|
+
export interface WorldInfoInterceptorMessageDTO {
|
|
790
|
+
readonly id: string;
|
|
791
|
+
readonly role: "system" | "user" | "assistant";
|
|
792
|
+
readonly content: string;
|
|
793
|
+
readonly is_user: boolean;
|
|
794
|
+
readonly is_greeting: boolean;
|
|
795
|
+
readonly greeting_index?: number;
|
|
796
|
+
readonly swipe_id: number;
|
|
797
|
+
readonly index_in_chat: number;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Context passed to a `registerWorldInfoInterceptor` handler. Fires inside
|
|
802
|
+
* `assemblePrompt` immediately before `activateWorldInfo` runs, so any
|
|
803
|
+
* `disabled` / `enabled` / `forced` votes affect activation and downstream
|
|
804
|
+
* token-budget calculation.
|
|
805
|
+
*/
|
|
806
|
+
export interface WorldInfoInterceptorCtxDTO {
|
|
807
|
+
readonly chatId: string;
|
|
808
|
+
readonly characterId: string;
|
|
809
|
+
readonly userId?: string;
|
|
810
|
+
readonly entries: readonly WorldInfoInterceptorEntryDTO[];
|
|
811
|
+
readonly messages: readonly WorldInfoInterceptorMessageDTO[];
|
|
812
|
+
readonly chatTurn: number;
|
|
813
|
+
readonly chatMetadata: Readonly<Record<string, unknown>>;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Per-entry content override emitted by a `registerWorldInfoInterceptor`
|
|
818
|
+
* handler. `content` replaces the entry's `content` for this prompt only.
|
|
819
|
+
*/
|
|
820
|
+
export interface WorldInfoInterceptorMutationDTO {
|
|
821
|
+
readonly id: string;
|
|
822
|
+
readonly content?: string;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Return value of a `registerWorldInfoInterceptor` handler. Each list is
|
|
827
|
+
* additive — handlers chain in priority order and a later handler sees the
|
|
828
|
+
* prior handlers' votes applied.
|
|
829
|
+
*/
|
|
830
|
+
export interface WorldInfoInterceptorResultDTO {
|
|
831
|
+
readonly disabled?: readonly string[];
|
|
832
|
+
readonly enabled?: readonly string[];
|
|
833
|
+
readonly forced?: readonly string[];
|
|
834
|
+
readonly mutated?: readonly WorldInfoInterceptorMutationDTO[];
|
|
835
|
+
}
|
|
836
|
+
|
|
670
837
|
// ─── Databank DTOs ───────────────────────────────────────────────────────
|
|
671
838
|
|
|
672
839
|
export type DatabankScopeDTO = "global" | "character" | "chat";
|
|
@@ -1796,6 +1963,13 @@ export type WorkerToHost =
|
|
|
1796
1963
|
requestId: string;
|
|
1797
1964
|
result: MacroInterceptorResultDTO;
|
|
1798
1965
|
}
|
|
1966
|
+
// ─── World Info Interceptor (gated: "generation") ──────────────────
|
|
1967
|
+
| { type: "register_world_info_interceptor"; priority?: number }
|
|
1968
|
+
| {
|
|
1969
|
+
type: "world_info_interceptor_result";
|
|
1970
|
+
requestId: string;
|
|
1971
|
+
result: WorldInfoInterceptorResultDTO | null;
|
|
1972
|
+
}
|
|
1799
1973
|
// ─── Message Content Processor (gated: "chat_mutation") ────────────
|
|
1800
1974
|
| { type: "register_message_content_processor"; priority?: number }
|
|
1801
1975
|
| {
|
|
@@ -1911,6 +2085,13 @@ export type WorkerToHost =
|
|
|
1911
2085
|
| { type: "council_get_available_lumia_items"; requestId: string; userId?: string }
|
|
1912
2086
|
// ─── Activated World Info (gated: "world_books") ───────────────────
|
|
1913
2087
|
| { type: "world_books_get_activated"; requestId: string; chatId: string; userId?: string }
|
|
2088
|
+
// ─── Regex Scripts (gated: "regex_scripts") ────────────────────────
|
|
2089
|
+
| { type: "regex_scripts_list"; requestId: string; scope?: RegexScopeDTO; scopeId?: string; target?: RegexTargetDTO; limit?: number; offset?: number; userId?: string }
|
|
2090
|
+
| { type: "regex_scripts_get"; requestId: string; scriptId: string; userId?: string }
|
|
2091
|
+
| { type: "regex_scripts_get_active"; requestId: string; target: RegexTargetDTO; characterId?: string; chatId?: string; userId?: string }
|
|
2092
|
+
| { type: "regex_scripts_create"; requestId: string; input: RegexScriptCreateDTO; userId?: string }
|
|
2093
|
+
| { type: "regex_scripts_update"; requestId: string; scriptId: string; input: RegexScriptUpdateDTO; userId?: string }
|
|
2094
|
+
| { type: "regex_scripts_delete"; requestId: string; scriptId: string; userId?: string }
|
|
1914
2095
|
// ─── Dry Run (gated: "generation") ────────────────────────────────
|
|
1915
2096
|
| { type: "generate_dry_run"; requestId: string; input: DryRunRequestDTO; userId?: string }
|
|
1916
2097
|
// ─── Chat Memories (gated: "chats") ───────────────────────────────
|
|
@@ -2050,6 +2231,11 @@ export type HostToWorker =
|
|
|
2050
2231
|
requestId: string;
|
|
2051
2232
|
ctx: MacroInterceptorCtxDTO;
|
|
2052
2233
|
}
|
|
2234
|
+
| {
|
|
2235
|
+
type: "world_info_interceptor_request";
|
|
2236
|
+
requestId: string;
|
|
2237
|
+
ctx: WorldInfoInterceptorCtxDTO;
|
|
2238
|
+
}
|
|
2053
2239
|
| {
|
|
2054
2240
|
type: "message_content_processor_request";
|
|
2055
2241
|
requestId: string;
|
package/src/events.ts
CHANGED
|
@@ -36,6 +36,8 @@ export enum CoreEventType {
|
|
|
36
36
|
CONNECTION_PROFILE_LOADED = "CONNECTION_PROFILE_LOADED",
|
|
37
37
|
MAIN_API_CHANGED = "MAIN_API_CHANGED",
|
|
38
38
|
WORLD_INFO_ACTIVATED = "WORLD_INFO_ACTIVATED",
|
|
39
|
+
REGEX_SCRIPT_CHANGED = "REGEX_SCRIPT_CHANGED",
|
|
40
|
+
REGEX_SCRIPT_DELETED = "REGEX_SCRIPT_DELETED",
|
|
39
41
|
MESSAGE_TAG_INTERCEPTED = "MESSAGE_TAG_INTERCEPTED",
|
|
40
42
|
TOOL_INVOCATION = "TOOL_INVOCATION",
|
|
41
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,20 @@ export type {
|
|
|
42
42
|
WorldBookEntryDTO,
|
|
43
43
|
WorldBookEntryCreateDTO,
|
|
44
44
|
WorldBookEntryUpdateDTO,
|
|
45
|
+
RegexPlacementDTO,
|
|
46
|
+
RegexScopeDTO,
|
|
47
|
+
RegexTargetDTO,
|
|
48
|
+
RegexMacroModeDTO,
|
|
49
|
+
RegexScriptDTO,
|
|
50
|
+
RegexScriptCreateDTO,
|
|
51
|
+
RegexScriptUpdateDTO,
|
|
52
|
+
RegexScriptListOptionsDTO,
|
|
53
|
+
RegexScriptActiveOptionsDTO,
|
|
54
|
+
WorldInfoInterceptorEntryDTO,
|
|
55
|
+
WorldInfoInterceptorMessageDTO,
|
|
56
|
+
WorldInfoInterceptorCtxDTO,
|
|
57
|
+
WorldInfoInterceptorMutationDTO,
|
|
58
|
+
WorldInfoInterceptorResultDTO,
|
|
45
59
|
DatabankScopeDTO,
|
|
46
60
|
DatabankDocumentStatusDTO,
|
|
47
61
|
DatabankDTO,
|
package/src/permissions.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type SpindlePermission =
|
|
|
31
31
|
| "characters"
|
|
32
32
|
| "chats"
|
|
33
33
|
| "world_books"
|
|
34
|
+
| "regex_scripts"
|
|
34
35
|
| "databanks"
|
|
35
36
|
| "personas"
|
|
36
37
|
| "push_notification"
|
|
@@ -54,6 +55,7 @@ export const ALL_PERMISSIONS: readonly SpindlePermission[] = [
|
|
|
54
55
|
"characters",
|
|
55
56
|
"chats",
|
|
56
57
|
"world_books",
|
|
58
|
+
"regex_scripts",
|
|
57
59
|
"databanks",
|
|
58
60
|
"personas",
|
|
59
61
|
"push_notification",
|
package/src/spindle-api.ts
CHANGED
|
@@ -27,6 +27,11 @@ import type {
|
|
|
27
27
|
WorldBookEntryDTO,
|
|
28
28
|
WorldBookEntryCreateDTO,
|
|
29
29
|
WorldBookEntryUpdateDTO,
|
|
30
|
+
RegexScriptDTO,
|
|
31
|
+
RegexScriptCreateDTO,
|
|
32
|
+
RegexScriptUpdateDTO,
|
|
33
|
+
RegexScriptListOptionsDTO,
|
|
34
|
+
RegexScriptActiveOptionsDTO,
|
|
30
35
|
DatabankDTO,
|
|
31
36
|
DatabankCreateDTO,
|
|
32
37
|
DatabankUpdateDTO,
|
|
@@ -81,6 +86,8 @@ import type {
|
|
|
81
86
|
TokenCountResultDTO,
|
|
82
87
|
MacroInterceptorCtxDTO,
|
|
83
88
|
MacroInterceptorResultDTO,
|
|
89
|
+
WorldInfoInterceptorCtxDTO,
|
|
90
|
+
WorldInfoInterceptorResultDTO,
|
|
84
91
|
MessageContentProcessorCtxDTO,
|
|
85
92
|
MessageContentProcessorResultDTO,
|
|
86
93
|
SharedRpcRequestContextDTO,
|
|
@@ -741,6 +748,24 @@ export interface SpindleAPI {
|
|
|
741
748
|
getActivated(chatId: string, userId?: string): Promise<ActivatedWorldInfoEntryDTO[]>;
|
|
742
749
|
};
|
|
743
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Regex Scripts CRUD (permission: "regex_scripts").
|
|
753
|
+
* Full access to regex scripts attached to the user's account, including
|
|
754
|
+
* global, character-scoped, and chat-scoped rules. Same shape Lumiverse uses
|
|
755
|
+
* internally during prompt assembly, response baking, and display rendering.
|
|
756
|
+
* For user-scoped extensions, userId is inferred from the extension owner.
|
|
757
|
+
* For operator-scoped extensions, pass userId to scope to a specific user.
|
|
758
|
+
*/
|
|
759
|
+
regex_scripts: {
|
|
760
|
+
list(options?: RegexScriptListOptionsDTO): Promise<{ data: RegexScriptDTO[]; total: number }>;
|
|
761
|
+
get(scriptId: string, userId?: string): Promise<RegexScriptDTO | null>;
|
|
762
|
+
create(input: RegexScriptCreateDTO, userId?: string): Promise<RegexScriptDTO>;
|
|
763
|
+
update(scriptId: string, input: RegexScriptUpdateDTO, userId?: string): Promise<RegexScriptDTO>;
|
|
764
|
+
delete(scriptId: string, userId?: string): Promise<boolean>;
|
|
765
|
+
/** Resolve the enabled scripts that would actually fire for the given target + character/chat context, merged across global + character + chat scopes and ordered by scope tier then sort_order. */
|
|
766
|
+
getActive(options: RegexScriptActiveOptionsDTO): Promise<RegexScriptDTO[]>;
|
|
767
|
+
};
|
|
768
|
+
|
|
744
769
|
/**
|
|
745
770
|
* Databank CRUD (permission: "databanks").
|
|
746
771
|
* Manage databanks plus the documents they contain.
|
|
@@ -893,6 +918,39 @@ export interface SpindleAPI {
|
|
|
893
918
|
priority?: number
|
|
894
919
|
): void;
|
|
895
920
|
|
|
921
|
+
/**
|
|
922
|
+
* Register a world info interceptor (permission: `generation`).
|
|
923
|
+
*
|
|
924
|
+
* Fires inside `assemblePrompt` immediately before `activateWorldInfo`
|
|
925
|
+
* runs. Handlers can disable, force-enable, or content-override world info
|
|
926
|
+
* entries based on chat state, message history, or external rules.
|
|
927
|
+
* Multiple handlers chain in priority order and a later handler sees the
|
|
928
|
+
* prior handlers' votes applied — useful for cross-entry injection
|
|
929
|
+
* patterns where one entry merges into another and then disables itself.
|
|
930
|
+
*
|
|
931
|
+
* Returning `void` passes the activation set through unchanged. Per-handler
|
|
932
|
+
* 10s timeout; errors are logged and the chain continues.
|
|
933
|
+
*
|
|
934
|
+
* @param handler Returns the disabled / enabled / forced / mutated lists, or `void`.
|
|
935
|
+
* @param priority Lower values run first. Default `100`.
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```ts
|
|
939
|
+
* spindle.registerWorldInfoInterceptor(async (ctx) => {
|
|
940
|
+
* const disabled = ctx.entries
|
|
941
|
+
* .filter((e) => e.comment.startsWith("[debug]"))
|
|
942
|
+
* .map((e) => e.id)
|
|
943
|
+
* return { disabled }
|
|
944
|
+
* }, 100)
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
registerWorldInfoInterceptor(
|
|
948
|
+
handler: (
|
|
949
|
+
ctx: WorldInfoInterceptorCtxDTO
|
|
950
|
+
) => Promise<WorldInfoInterceptorResultDTO | void>,
|
|
951
|
+
priority?: number
|
|
952
|
+
): void;
|
|
953
|
+
|
|
896
954
|
/**
|
|
897
955
|
* Register a message content processor (permission: `chat_mutation`).
|
|
898
956
|
*
|