lumiverse-spindle-types 0.4.16 → 0.4.17
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 +75 -0
- package/src/index.ts +3 -0
- package/src/spindle-api.ts +7 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -799,6 +799,81 @@ export interface GenerationStoppedPayloadDTO {
|
|
|
799
799
|
content?: string;
|
|
800
800
|
}
|
|
801
801
|
|
|
802
|
+
// ─── Chat Message Event Payload DTOs ────────────────────────────────────
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Wire shape of a chat message as delivered in WebSocket event payloads
|
|
806
|
+
* (e.g. `MESSAGE_SENT`, `MESSAGE_EDITED`, `MESSAGE_SWIPED`).
|
|
807
|
+
*
|
|
808
|
+
* This is the raw backend message shape and is distinct from the normalized
|
|
809
|
+
* `{ id, role, content, ... }` object returned by `spindle.chat.getMessages()`,
|
|
810
|
+
* which collapses `is_user`/`name` into a `role` discriminator.
|
|
811
|
+
*/
|
|
812
|
+
export interface ChatMessageDTO {
|
|
813
|
+
id: string;
|
|
814
|
+
chat_id: string;
|
|
815
|
+
index_in_chat: number;
|
|
816
|
+
is_user: boolean;
|
|
817
|
+
name: string;
|
|
818
|
+
/** The currently active swipe content (mirrors `swipes[swipe_id]`). */
|
|
819
|
+
content: string;
|
|
820
|
+
send_date: number;
|
|
821
|
+
/** Index of the active swipe in `swipes`. `0` when the message has no alternates. */
|
|
822
|
+
swipe_id: number;
|
|
823
|
+
/** All swipe variants for this message, including the currently active one. */
|
|
824
|
+
swipes: string[];
|
|
825
|
+
/** Per-swipe creation timestamps (unix epoch seconds), aligned with `swipes`. */
|
|
826
|
+
swipe_dates: number[];
|
|
827
|
+
/** Free-form metadata bag (attachments, spindle metadata, reasoning, etc.). */
|
|
828
|
+
extra: Record<string, unknown>;
|
|
829
|
+
parent_message_id: string | null;
|
|
830
|
+
branch_id: string | null;
|
|
831
|
+
created_at: number;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Distinguishes the four ways a `MESSAGE_SWIPED` event can be triggered.
|
|
836
|
+
*
|
|
837
|
+
* - `'added'` — a new swipe variant was created (e.g. regenerate, manual add)
|
|
838
|
+
* - `'updated'` — an existing swipe's content was edited in place
|
|
839
|
+
* - `'deleted'` — a swipe variant was removed from the message
|
|
840
|
+
* - `'navigated'` — the user (or an extension) cycled the active swipe slot
|
|
841
|
+
*/
|
|
842
|
+
export type MessageSwipeAction = "added" | "updated" | "deleted" | "navigated";
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Payload for `MESSAGE_SWIPED` events.
|
|
846
|
+
*
|
|
847
|
+
* The discriminator fields (`action`, `swipeId`, `previousSwipeId`) let
|
|
848
|
+
* extensions tell the four swipe operations apart and maintain swipe-keyed
|
|
849
|
+
* state correctly without diffing the `swipes` array on every event.
|
|
850
|
+
*/
|
|
851
|
+
export interface MessageSwipedPayloadDTO {
|
|
852
|
+
chatId: string;
|
|
853
|
+
/** The full message after the mutation. */
|
|
854
|
+
message: ChatMessageDTO;
|
|
855
|
+
/** Distinguishes which swipe operation produced this event. */
|
|
856
|
+
action: MessageSwipeAction;
|
|
857
|
+
/**
|
|
858
|
+
* The swipe index this event concerns. Semantics depend on `action`:
|
|
859
|
+
*
|
|
860
|
+
* - `'added'` — index of the new swipe (equal to `message.swipe_id` post-add)
|
|
861
|
+
* - `'updated'` — index of the edited swipe (may or may not equal `message.swipe_id`)
|
|
862
|
+
* - `'deleted'` — index that was removed. Note: this slot is no longer present
|
|
863
|
+
* in `message.swipes`, and `message.swipe_id` may have shifted
|
|
864
|
+
* if the deleted slot was at or before the previously active one.
|
|
865
|
+
* - `'navigated'` — destination index (equal to `message.swipe_id`)
|
|
866
|
+
*/
|
|
867
|
+
swipeId: number;
|
|
868
|
+
/**
|
|
869
|
+
* For `'navigated'` and `'deleted'` events: the active swipe index *before*
|
|
870
|
+
* the change. Useful for direction detection on navigation, and for detecting
|
|
871
|
+
* whether the active slot was the one removed on deletion. Omitted for
|
|
872
|
+
* `'added'` and `'updated'`.
|
|
873
|
+
*/
|
|
874
|
+
previousSwipeId?: number;
|
|
875
|
+
}
|
|
876
|
+
|
|
802
877
|
/**
|
|
803
878
|
* Observer handle returned by `spindle.generate.observe()`.
|
|
804
879
|
* Provides a high-level API for watching an in-flight generation on a
|
package/src/index.ts
CHANGED
package/src/spindle-api.ts
CHANGED
|
@@ -44,6 +44,7 @@ import type {
|
|
|
44
44
|
GenerationEndedPayloadDTO,
|
|
45
45
|
GenerationStoppedPayloadDTO,
|
|
46
46
|
GenerationObserver,
|
|
47
|
+
MessageSwipedPayloadDTO,
|
|
47
48
|
} from "./api";
|
|
48
49
|
|
|
49
50
|
/** The global `spindle` object available in backend extension workers */
|
|
@@ -56,6 +57,12 @@ export interface SpindleAPI {
|
|
|
56
57
|
on(event: "GENERATION_ENDED", handler: (payload: GenerationEndedPayloadDTO) => void): () => void;
|
|
57
58
|
/** Subscribe to generation-stopped events (requires `generation` permission). */
|
|
58
59
|
on(event: "GENERATION_STOPPED", handler: (payload: GenerationStoppedPayloadDTO) => void): () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to swipe lifecycle events. The payload's `action` discriminator
|
|
62
|
+
* tells you whether a swipe was added, updated, deleted, or navigated, and
|
|
63
|
+
* `swipeId` identifies which slot the event concerns.
|
|
64
|
+
*/
|
|
65
|
+
on(event: "MESSAGE_SWIPED", handler: (payload: MessageSwipedPayloadDTO) => void): () => void;
|
|
59
66
|
/** Subscribe to a Lumiverse event. */
|
|
60
67
|
on(event: string, handler: (payload: unknown) => void): () => void;
|
|
61
68
|
|