lumiverse-spindle-types 0.4.28 → 0.4.29

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.28",
3
+ "version": "0.4.29",
4
4
  "types": "./src/index.ts",
5
5
  "keywords": [
6
6
  "lumiverse",
package/src/api.ts CHANGED
@@ -1029,6 +1029,40 @@ export interface GenerationObserver {
1029
1029
  dispose(): void;
1030
1030
  }
1031
1031
 
1032
+ // ─── Token Count DTOs ───────────────────────────────────────────────────
1033
+
1034
+ /** Which configured model should be used for server-side token counting. */
1035
+ export type TokenModelSourceDTO = "main" | "sidecar";
1036
+
1037
+ /** Optional settings for Spindle token count helpers. */
1038
+ export interface TokenCountOptionsDTO {
1039
+ /**
1040
+ * Which configured model to use when resolving the tokenizer.
1041
+ *
1042
+ * - `"main"` → the user's default main connection profile model
1043
+ * - `"sidecar"` → the user's selected sidecar model (or its backing connection model)
1044
+ *
1045
+ * Defaults to `"main"`.
1046
+ */
1047
+ modelSource?: TokenModelSourceDTO;
1048
+ /** For operator-scoped extensions. */
1049
+ userId?: string;
1050
+ }
1051
+
1052
+ /** Server-resolved token count result for a text or chat payload. */
1053
+ export interface TokenCountResultDTO {
1054
+ total_tokens: number;
1055
+ /** Model ID that was actually used to resolve the tokenizer. */
1056
+ model: string;
1057
+ /** Whether the model came from the main connection or the sidecar selection. */
1058
+ modelSource: TokenModelSourceDTO;
1059
+ /** Null when no exact tokenizer match was found and an approximate fallback was used. */
1060
+ tokenizer_id: string | null;
1061
+ tokenizer_name: string;
1062
+ /** True when Lumiverse had to fall back to its approximate char/4 heuristic. */
1063
+ approximate: boolean;
1064
+ }
1065
+
1032
1066
  // ─── Worker → Host messages ──────────────────────────────────────────────
1033
1067
 
1034
1068
  export type WorkerToHost =
@@ -1320,7 +1354,29 @@ export type WorkerToHost =
1320
1354
  | { type: "commands_unregister"; commandIds: string[] }
1321
1355
  // ─── Version (free tier) ───────────────────────────────────────────────
1322
1356
  | { type: "version_get_backend"; requestId: string }
1323
- | { type: "version_get_frontend"; requestId: string };
1357
+ | { type: "version_get_frontend"; requestId: string }
1358
+ // ─── Token Counting (free tier) ───────────────────────────────────────
1359
+ | {
1360
+ type: "tokens_count_text";
1361
+ requestId: string;
1362
+ text: string;
1363
+ modelSource?: TokenModelSourceDTO;
1364
+ userId?: string;
1365
+ }
1366
+ | {
1367
+ type: "tokens_count_messages";
1368
+ requestId: string;
1369
+ messages: Array<Pick<LlmMessageDTO, "role" | "content">>;
1370
+ modelSource?: TokenModelSourceDTO;
1371
+ userId?: string;
1372
+ }
1373
+ | {
1374
+ type: "tokens_count_chat";
1375
+ requestId: string;
1376
+ chatId: string;
1377
+ modelSource?: TokenModelSourceDTO;
1378
+ userId?: string;
1379
+ };
1324
1380
 
1325
1381
  // ─── Host → Worker messages ──────────────────────────────────────────────
1326
1382
 
package/src/dom.ts CHANGED
@@ -62,6 +62,7 @@ export interface SpindleDrawerTabHandle {
62
62
  setBadge(text: string | null): void;
63
63
  activate(): void;
64
64
  destroy(): void;
65
+ /** Register a callback fired when the active drawer tab switches to this tab. Returns an unsubscribe function. */
65
66
  onActivate(handler: () => void): () => void;
66
67
  }
67
68
 
package/src/index.ts CHANGED
@@ -73,6 +73,9 @@ export type {
73
73
  MessageSwipedPayloadDTO,
74
74
  SwipeEditedPayloadDTO,
75
75
  ToolInvocationPayloadDTO,
76
+ TokenModelSourceDTO,
77
+ TokenCountOptionsDTO,
78
+ TokenCountResultDTO,
76
79
  WorkerToHost,
77
80
  HostToWorker,
78
81
  } from "./api";
@@ -48,6 +48,8 @@ import type {
48
48
  SwipeEditedPayloadDTO,
49
49
  ToolInvocationPayloadDTO,
50
50
  StreamChunkDTO,
51
+ TokenCountOptionsDTO,
52
+ TokenCountResultDTO,
51
53
  } from "./api";
52
54
 
53
55
  /** The global `spindle` object available in backend extension workers */
@@ -465,6 +467,25 @@ export interface SpindleAPI {
465
467
  get(connectionId: string, userId?: string): Promise<ConnectionProfileDTO | null>;
466
468
  };
467
469
 
470
+ /** Server-side token counting helpers (free tier). */
471
+ tokens: {
472
+ /** Count tokens for an arbitrary text string. */
473
+ countText(text: string, options?: TokenCountOptionsDTO): Promise<TokenCountResultDTO>;
474
+ /**
475
+ * Count tokens for an array of chat-style messages.
476
+ *
477
+ * This accepts any array whose items expose `{ role, content }`, so the
478
+ * normalized output of `spindle.chat.getMessages(chatId)` can be passed
479
+ * directly without reshaping.
480
+ */
481
+ countMessages(
482
+ messages: Array<Pick<LlmMessageDTO, "role" | "content">>,
483
+ options?: TokenCountOptionsDTO
484
+ ): Promise<TokenCountResultDTO>;
485
+ /** Count tokens for a live stored chat by ID. */
486
+ countChat(chatId: string, options?: TokenCountOptionsDTO): Promise<TokenCountResultDTO>;
487
+ };
488
+
468
489
  /**
469
490
  * Image generation (permission: "image_gen").
470
491
  * Generate images via the user's configured image gen connection profiles.