@emesoft/tokenhub 0.8.9 → 0.8.11

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/README.md CHANGED
@@ -69,11 +69,14 @@ Prefer not to install? Use `npx @emesoft/tokenhub connect <your tenant name>` in
69
69
  - Asks whether to install the **TokenHub model picker**, unless you pass `--no-model-picker` or there is no terminal
70
70
  to ask on. On yes it copies a Claude Code plugin to `~/.tokenhub/claude-plugin` and registers it as
71
71
  `extraKnownMarketplaces.tokenhub` and `enabledPlugins["tokenhub-models@tokenhub"]`. After a restart, a bare `/model`
72
- opens a picker of TokenHub models above the prompt: providers side by side, ↑/↓ and Enter, a click or `1`–`9` to pick,
72
+ opens a picker of TokenHub models above the prompt: providers side by side, ↑/↓ and Enter or a click to pick (rows are numbered by position),
73
73
  `,` / `.` or a click for effort (hover highlights), and `[` or a click for **1M**: each model shows its context window, and with 1M on, a model whose window is 1M is picked as `<id>[1m]` so Claude Code compacts at 1M instead of 200K (only for models whose window TokenHub knows to be 1M). `/model <id>` and other hosts keep Claude Code's own picker. The list is read from your tenant
74
74
  (`/member/api/models`: the providers your key may use, with a skeleton while it loads); when the pool does not
75
75
  answer within a few seconds it falls back to a built-in list, marked "offline list". The plugin relies on Claude
76
- Code's early-access plugin hooks, which can change between Claude Code releases.
76
+ Code's early-access plugin hooks, which can change between Claude Code releases. Claude Code reports the mouse
77
+ only in its fullscreen layout, so after installing the picker `connect` asks whether to turn that on
78
+ (`"tui": "fullscreen"`, default no); in the classic layout the picker works from the keyboard and says
79
+ `/tui fullscreen` turns the mouse on. `disconnect` leaves `tui` as it is.
77
80
  - Keeps every other setting, and saves the previous file as `settings.json.bak`.
78
81
 
79
82
  Each machine gets its own key, which you can revoke from the pool's **Keys** page. `disconnect` removes exactly these entries (and the model picker's copy) and nothing else.
package/bin/tokenhub.js CHANGED
@@ -16,7 +16,8 @@ Usage:
16
16
  Pair this machine and write ~/.claude/settings.json, including the status line
17
17
  (today's spend under the prompt) unless --no-statusline. Then offers to install the
18
18
  TokenHub model picker (a bare /model in Claude Code lists TokenHub models) unless
19
- --no-model-picker.
19
+ --no-model-picker, and then Claude Code's fullscreen layout, the only one that gives
20
+ the picker the mouse (default no).
20
21
  tenant is your tenant name (acme = https://acme.${TENANT_DOMAIN}) or a full URL;
21
22
  it is asked for when left out
22
23
  tokenhub connect [tenant] --admin
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenhub-models",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "A bare /model opens a TokenHub model picker above the prompt when ANTHROPIC_BASE_URL points at TokenHub",
5
5
  "author": { "name": "Emesoft" },
6
6
  "license": "MIT",
@@ -107,6 +107,7 @@ const Picker: ClientModule<Props, State> = (props, s) => {
107
107
  </Text>,
108
108
  ])
109
109
  let i = 0
110
+ const numberWidth = String(flat.length).length
110
111
  // Skeleton: three columns of placeholder bars where the providers and their models will be.
111
112
  const skeleton = (
112
113
  <Box flexDirection="row">
@@ -136,12 +137,13 @@ const Picker: ClientModule<Props, State> = (props, s) => {
136
137
  const at = i++
137
138
  const isCursor = at === props.cursor
138
139
  const isCurrent = matches(m.id, props.current)
139
- const digit = at < 9 ? `${at + 1}.` : ' '
140
+ // Every row's position, padded so the names line up; a number is not a key (#751).
141
+ const digit = `${String(at + 1).padStart(numberWidth)}.`
140
142
  const label = windowLabel(m.contextWindow)
141
143
  return (
142
144
  <Text wrap="truncate" color={isCursor ? 'suggestion' : undefined} dimColor={!isCursor && !isCurrent}>
143
145
  {isCursor ? '› ' : ' '}{digit} {m.name}{isCurrent ? ' ✔' : ''}
144
- {label ? <Text dimColor> {label}</Text> : ''}
146
+ {label ? <Text dimColor>{` ${label}`}</Text> : ''}
145
147
  </Text>
146
148
  )
147
149
  })}
@@ -164,7 +166,7 @@ const Picker: ClientModule<Props, State> = (props, s) => {
164
166
  <Text dimColor>{contextNote}</Text>
165
167
  </Text>
166
168
  <Text dimColor>
167
- {props.loading ? 'Loading your TokenHub models…' : `${cursorModel?.id ?? ''}${props.use1m && cursorTakes1m ? '[1m]' : ''} · ↑/↓ or hover · Enter, click or 1-9 picks · type anything to close`}
169
+ {props.loading ? 'Loading your TokenHub models…' : `${cursorModel?.id ?? ''}${props.use1m && cursorTakes1m ? '[1m]' : ''} · ↑/↓ or hover · Enter or click picks · type anything to close`}
168
170
  </Text>
169
171
  </Box>
170
172
  )
@@ -182,7 +182,8 @@ export const register: Register = on => {
182
182
  })
183
183
 
184
184
  // While the picker is open and the prompt is empty, the prompt drives it: up/down move the
185
- // cursor, `,` / `.` step the effort, `[` switches 1M, 1-9 pick a model. Anything else types as usual.
185
+ // cursor, `,` / `.` step the effort, `[` switches 1M (the row numbers are positions, not keys). Anything else typed closes the
186
+ // picker and types as usual.
186
187
  on('prompt.edit', async ($, e, next) => {
187
188
  const arrow = e.key?.key === 'up' || e.key?.key === 'down' ? e.key.key : undefined
188
189
  if (arrow && e.text === '') {
@@ -198,7 +199,12 @@ export const register: Register = on => {
198
199
  return { ...r, text: '', cursor: 0 }
199
200
  }
200
201
  const typed = e.inputText
201
- if (e.text !== '' || !(typed === ',' || typed === '.' || typed === '[' || /^[1-9]$/.test(typed))) return next(e)
202
+ const isPickerKey = e.text === '' && (typed === ',' || typed === '.' || typed === '[')
203
+ if (!isPickerKey) {
204
+ // Anything else typed while the picker is open closes it, as its hint says; the text stays in the prompt.
205
+ if (typed !== '' && (await read($, isOpen).catch(() => false))) await update($, isOpen, () => false).catch(() => undefined)
206
+ return next(e)
207
+ }
202
208
  let open = false
203
209
  try {
204
210
  open = await read($, isOpen)
@@ -208,8 +214,7 @@ export const register: Register = on => {
208
214
  if (!open) return next(e)
209
215
  const r = await next(e)
210
216
  if (typed === ',' || typed === '.') await stepEffort($, typed === '.' ? 1 : -1).catch(() => undefined)
211
- else if (typed === '[') await update($, use1m, isOn => !isOn).catch(() => undefined)
212
- else await pick($, Number(typed) - 1).catch(() => undefined)
217
+ else await update($, use1m, isOn => !isOn).catch(() => undefined)
213
218
  return { ...r, text: '', cursor: 0 }
214
219
  })
215
220
 
@@ -235,6 +240,8 @@ export const register: Register = on => {
235
240
  </Box>
236
241
  <Client key="picker" module="./picker.tsx"
237
242
  props={{ groups, loading: groups.length === 0, current, cursor, effort, efforts: EFFORTS, use1m: await read($, use1m) }} />
243
+ {/* Claude Code reports the mouse only in its fullscreen layout (#766); say so where it says it is not. */}
244
+ {e.viewport?.isFullscreen === false ? <Text dimColor>Mouse needs Claude Code's fullscreen layout: /tui fullscreen</Text> : ''}
238
245
  </Box>
239
246
  )
240
247
  })
@@ -7,5 +7,7 @@ export function installModelPicker(settingsFile: string, dir: string, source?: s
7
7
  export function uninstallModelPicker(settingsFile: string, dir: string): boolean;
8
8
  export function askYesNo(
9
9
  question: string,
10
- io?: { input?: NodeJS.ReadableStream & { isTTY?: boolean }; output?: NodeJS.WritableStream },
10
+ io?: { input?: NodeJS.ReadableStream & { isTTY?: boolean }; output?: NodeJS.WritableStream; defaultYes?: boolean },
11
11
  ): Promise<boolean>;
12
+ export function enableFullscreen(settingsFile: string): boolean;
13
+ export function layoutUnset(settingsFile: string): boolean;
@@ -106,22 +106,44 @@ export function uninstallModelPicker(settingsFile, dir) {
106
106
  }
107
107
 
108
108
  /**
109
- * Ask a yes/no question on the terminal; Enter alone answers yes.
110
- * @param {string} question The question, without the `(Y/n)` suffix.
111
- * @param {{ input?: NodeJS.ReadableStream & { isTTY?: boolean }, output?: NodeJS.WritableStream }} [io] Streams (tests).
109
+ * Ask a yes/no question on the terminal; Enter alone answers the default (yes unless `defaultYes` is false).
110
+ * @param {string} question The question, without the `(Y/n)` / `(y/N)` suffix.
111
+ * @param {{ input?: NodeJS.ReadableStream & { isTTY?: boolean }, output?: NodeJS.WritableStream, defaultYes?: boolean }} [io] Streams (tests) and the default answer.
112
112
  * @returns {Promise<boolean>} The answer; false when there is no terminal to ask on.
113
113
  */
114
- export async function askYesNo(question, { input = process.stdin, output = process.stdout } = {}) {
114
+ export async function askYesNo(question, { input = process.stdin, output = process.stdout, defaultYes = true } = {}) {
115
115
  if (!input.isTTY) return false;
116
116
  const rl = createInterface({ input, output });
117
117
  try {
118
- const answer = (await rl.question(`${question} (Y/n) `)).trim().toLowerCase();
119
- return answer === "" || answer === "y" || answer === "yes";
118
+ const answer = (await rl.question(`${question} ${defaultYes ? "(Y/n)" : "(y/N)"} `)).trim().toLowerCase();
119
+ return answer === "" ? defaultYes : answer === "y" || answer === "yes";
120
120
  } finally {
121
121
  rl.close();
122
122
  }
123
123
  }
124
124
 
125
+ /**
126
+ * Turn on Claude Code's fullscreen layout (`"tui": "fullscreen"`), the only one that reports the mouse to the picker
127
+ * (#766). A `tui` the user already chose is left alone.
128
+ * @param {string} settingsFile Path of settings.json.
129
+ * @returns {boolean} True when it was written, false when `tui` was already set.
130
+ * @throws {Error} When the existing file is invalid JSON (left untouched).
131
+ */
132
+ export function enableFullscreen(settingsFile) {
133
+ const { settings } = readSettings(settingsFile);
134
+ if (settings.tui !== undefined) return false;
135
+ writeSettings(settingsFile, { ...settings, tui: "fullscreen" });
136
+ return true;
137
+ }
138
+
139
+ /**
140
+ * @param {string} settingsFile Path of settings.json.
141
+ * @returns {boolean} Whether the user has not chosen a Claude Code layout (`tui`) yet.
142
+ */
143
+ export function layoutUnset(settingsFile) {
144
+ return readSettings(settingsFile).settings.tui === undefined;
145
+ }
146
+
125
147
  /**
126
148
  * @param {unknown} value Value to test.
127
149
  * @returns {value is Record<string, any>} True for non-null, non-array objects.
package/lib/pair.d.ts CHANGED
@@ -34,5 +34,5 @@ export function runConnect(options: {
34
34
  /** Where the picker is installed; `modelPickerDir()` by default. */
35
35
  modelPickerDir?: string;
36
36
  /** Yes/no prompt; answers false without a terminal. */
37
- ask?: (question: string) => Promise<boolean>;
37
+ ask?: (question: string, defaultYes?: boolean) => Promise<boolean>;
38
38
  }): Promise<number>;
package/lib/pair.js CHANGED
@@ -3,7 +3,7 @@ import { hostname } from "node:os";
3
3
  import { emitKeypressEvents } from "node:readline";
4
4
  import { createInterface } from "node:readline/promises";
5
5
  import { writeAdminConfig } from "./admin.js";
6
- import { askYesNo, installModelPicker, modelPickerDir } from "./model-picker.js";
6
+ import { askYesNo, enableFullscreen, installModelPicker, layoutUnset, modelPickerDir } from "./model-picker.js";
7
7
  import { connectSettings, normalizeUrl, overridingEnvVars, readSettings } from "./settings.js";
8
8
 
9
9
  const MAX_WAIT_MS = 15 * 60 * 1000;
@@ -230,7 +230,7 @@ async function postJson(url, body, signal) {
230
230
  * @param {string} [options.adminFile] Path from `adminConfigPath`; required with `admin`.
231
231
  * @param {boolean} [options.modelPicker] Offer to install the Claude Code model picker after pairing (default true).
232
232
  * @param {string} [options.modelPickerDir] Where the picker is installed (`modelPickerDir()` by default).
233
- * @param {(question: string) => Promise<boolean>} [options.ask] Yes/no prompt (tests); false without a terminal.
233
+ * @param {(question: string, defaultYes?: boolean) => Promise<boolean>} [options.ask] Yes/no prompt (tests); false without a terminal.
234
234
  * @returns {Promise<number>} Process exit code.
235
235
  */
236
236
  export async function runConnect({
@@ -247,7 +247,7 @@ export async function runConnect({
247
247
  adminFile,
248
248
  modelPicker = true,
249
249
  modelPickerDir: pickerDir = modelPickerDir(),
250
- ask = askYesNo,
250
+ ask = (question, defaultYes = true) => askYesNo(question, { defaultYes }),
251
251
  }) {
252
252
  let pool;
253
253
  try {
@@ -316,6 +316,11 @@ export async function runConnect({
316
316
  try {
317
317
  installModelPicker(settingsFile, pickerDir);
318
318
  log("Model picker installed. Restart Claude Code, then type /model to pick a TokenHub model.");
319
+ // Claude Code reports the mouse only in its fullscreen layout (#766): offer it, never force it.
320
+ if (layoutUnset(settingsFile) && (await ask("Turn on Claude Code's fullscreen layout so the picker takes the mouse?", false))) {
321
+ enableFullscreen(settingsFile);
322
+ log('Fullscreen layout on ("tui": "fullscreen"). Switch back any time with /tui default.');
323
+ }
319
324
  } catch (error) {
320
325
  log(`Model picker not installed: ${error.message}`);
321
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emesoft/tokenhub",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "description": "Connect Claude Code to a TokenHub pool in one command, and track your spend from the terminal",
5
5
  "keywords": [
6
6
  "claude",