lumiverse-spindle-types 0.4.28 → 0.4.30

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.30",
4
4
  "types": "./src/index.ts",
5
5
  "keywords": [
6
6
  "lumiverse",
package/src/api.ts CHANGED
@@ -1029,6 +1029,46 @@ export interface GenerationObserver {
1029
1029
  dispose(): void;
1030
1030
  }
1031
1031
 
1032
+ // ─── Token Count DTOs ───────────────────────────────────────────────────
1033
+
1034
+ /** Where the model used for server-side token counting came from. */
1035
+ export type TokenModelSourceDTO = "main" | "sidecar" | "explicit";
1036
+
1037
+ /** Optional settings for Spindle token count helpers. */
1038
+ export interface TokenCountOptionsDTO {
1039
+ /**
1040
+ * Explicit model ID to resolve the tokenizer against.
1041
+ *
1042
+ * When provided, this takes precedence over `modelSource`.
1043
+ */
1044
+ model?: string;
1045
+ /**
1046
+ * Which configured model to use when resolving the tokenizer.
1047
+ *
1048
+ * - `"main"` → the user's default main connection profile model
1049
+ * - `"sidecar"` → the user's selected sidecar model (or its backing connection model)
1050
+ *
1051
+ * Defaults to `"main"`.
1052
+ */
1053
+ modelSource?: TokenModelSourceDTO;
1054
+ /** For operator-scoped extensions. */
1055
+ userId?: string;
1056
+ }
1057
+
1058
+ /** Server-resolved token count result for a text or chat payload. */
1059
+ export interface TokenCountResultDTO {
1060
+ total_tokens: number;
1061
+ /** Model ID that was actually used to resolve the tokenizer. */
1062
+ model: string;
1063
+ /** Whether the model came from the main connection, sidecar selection, or an explicit override. */
1064
+ modelSource: TokenModelSourceDTO;
1065
+ /** Null when no exact tokenizer match was found and an approximate fallback was used. */
1066
+ tokenizer_id: string | null;
1067
+ tokenizer_name: string;
1068
+ /** True when Lumiverse had to fall back to its approximate char/4 heuristic. */
1069
+ approximate: boolean;
1070
+ }
1071
+
1032
1072
  // ─── Worker → Host messages ──────────────────────────────────────────────
1033
1073
 
1034
1074
  export type WorkerToHost =
@@ -1320,7 +1360,32 @@ export type WorkerToHost =
1320
1360
  | { type: "commands_unregister"; commandIds: string[] }
1321
1361
  // ─── Version (free tier) ───────────────────────────────────────────────
1322
1362
  | { type: "version_get_backend"; requestId: string }
1323
- | { type: "version_get_frontend"; requestId: string };
1363
+ | { type: "version_get_frontend"; requestId: string }
1364
+ // ─── Token Counting (free tier) ───────────────────────────────────────
1365
+ | {
1366
+ type: "tokens_count_text";
1367
+ requestId: string;
1368
+ text: string;
1369
+ model?: string;
1370
+ modelSource?: TokenModelSourceDTO;
1371
+ userId?: string;
1372
+ }
1373
+ | {
1374
+ type: "tokens_count_messages";
1375
+ requestId: string;
1376
+ messages: Array<Pick<LlmMessageDTO, "role" | "content">>;
1377
+ model?: string;
1378
+ modelSource?: TokenModelSourceDTO;
1379
+ userId?: string;
1380
+ }
1381
+ | {
1382
+ type: "tokens_count_chat";
1383
+ requestId: string;
1384
+ chatId: string;
1385
+ model?: string;
1386
+ modelSource?: TokenModelSourceDTO;
1387
+ userId?: string;
1388
+ };
1324
1389
 
1325
1390
  // ─── Host → Worker messages ──────────────────────────────────────────────
1326
1391
 
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. `options.model` overrides `options.modelSource`. */
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. `options.model` overrides `options.modelSource`.
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. `options.model` overrides `options.modelSource`. */
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.