@emesoft/tokenhub 0.8.6 → 0.8.7
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,8 +69,8 @@ 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 or `1`–`9` to pick,
|
|
73
|
-
`,` / `.` for effort. `/model <id>` and other hosts keep Claude Code's own picker. The list is fixed in the plugin and
|
|
72
|
+
opens a picker of TokenHub models above the prompt: providers side by side, ↑/↓ and Enter, a click or `1`–`9` to pick,
|
|
73
|
+
`,` / `.` or a click for effort (hover highlights). `/model <id>` and other hosts keep Claude Code's own picker. The list is fixed in the plugin and
|
|
74
74
|
does not follow what your key may use; the plugin relies on Claude Code's early-access plugin hooks, which can change
|
|
75
75
|
between Claude Code releases.
|
|
76
76
|
- Keeps every other setting, and saves the previous file as `settings.json.bak`.
|
|
@@ -13,7 +13,10 @@ type Props = {
|
|
|
13
13
|
|
|
14
14
|
const matches = (id: string, current: string) => id === current || id.endsWith('/' + current)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Local to the drawing: the effort level under the mouse, which only highlights.
|
|
17
|
+
type State = { hoverEffort?: string }
|
|
18
|
+
|
|
19
|
+
const Picker: ClientModule<Props, State> = (props, s) => {
|
|
17
20
|
const { Box, Text } = s.elements
|
|
18
21
|
const flat = props.groups.flatMap(g => g.models)
|
|
19
22
|
s.onKey(k => {
|
|
@@ -24,6 +27,49 @@ const Picker: ClientModule<Props> = (props, s) => {
|
|
|
24
27
|
else if (k.key === 'return') s.post({ pick: true })
|
|
25
28
|
})
|
|
26
29
|
const colWidth = Math.max(20, Math.floor((s.columns || 90) / Math.max(1, props.groups.length)))
|
|
30
|
+
// Rows as drawn: 0 the provider names, 1..tallest the models, a blank, then the effort line.
|
|
31
|
+
const tallest = Math.max(0, ...props.groups.map(g => g.models.length))
|
|
32
|
+
const effortRow = tallest + 2
|
|
33
|
+
const EFFORT_START = '● Effort: '.length
|
|
34
|
+
/** The flat model index under a cell, or -1. */
|
|
35
|
+
const modelAt = (x: number, y: number) => {
|
|
36
|
+
const col = Math.floor(x / colWidth)
|
|
37
|
+
const group = props.groups[col]
|
|
38
|
+
if (!group || y < 1 || y > group.models.length) return -1
|
|
39
|
+
return props.groups.slice(0, col).reduce((n, g) => n + g.models.length, 0) + (y - 1)
|
|
40
|
+
}
|
|
41
|
+
/** The effort level under a column of the effort line, or undefined. */
|
|
42
|
+
const effortAt = (x: number) => {
|
|
43
|
+
let start = EFFORT_START
|
|
44
|
+
for (const e of props.efforts) {
|
|
45
|
+
const width = (e === props.effort ? `[${e}]` : e).length
|
|
46
|
+
if (x >= start && x < start + width) return e
|
|
47
|
+
start += width + 2
|
|
48
|
+
}
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
const hoverEffort = s.state?.hoverEffort
|
|
52
|
+
const setHover = (level: string | undefined) => {
|
|
53
|
+
if (level !== hoverEffort) s.setState({ hoverEffort: level })
|
|
54
|
+
}
|
|
55
|
+
// The mouse as Claude Code's own picker: hovering a model moves the highlight, a click picks it;
|
|
56
|
+
// hovering an effort level highlights it, a click sets it.
|
|
57
|
+
s.onPointer(p => {
|
|
58
|
+
if (p.type === 'leave') {
|
|
59
|
+
setHover(undefined)
|
|
60
|
+
} else if (p.type === 'move' && !p.button) {
|
|
61
|
+
const at = modelAt(p.x, p.y)
|
|
62
|
+
if (at >= 0 && at !== props.cursor) s.post({ cursorTo: at })
|
|
63
|
+
setHover(p.y === effortRow ? effortAt(p.x) : undefined)
|
|
64
|
+
} else if (p.type === 'up' && p.button === 'left') {
|
|
65
|
+
const at = modelAt(p.x, p.y)
|
|
66
|
+
if (at >= 0) s.post({ pickAt: at })
|
|
67
|
+
else if (p.y === effortRow) {
|
|
68
|
+
const level = effortAt(p.x)
|
|
69
|
+
if (level && level !== props.effort) s.post({ effortTo: level })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
27
73
|
let i = 0
|
|
28
74
|
return (
|
|
29
75
|
<Box flexDirection="column">
|
|
@@ -49,12 +95,18 @@ const Picker: ClientModule<Props> = (props, s) => {
|
|
|
49
95
|
<Text>
|
|
50
96
|
<Text color="warning">● </Text>
|
|
51
97
|
{'Effort: '}
|
|
52
|
-
{props.efforts.
|
|
53
|
-
|
|
98
|
+
{props.efforts.flatMap((e, j) => [
|
|
99
|
+
...(j > 0 ? [<Text>{' '}</Text>] : []),
|
|
100
|
+
<Text color={e === hoverEffort ? 'suggestion' : undefined}
|
|
101
|
+
dimColor={e !== props.effort && e !== hoverEffort}>
|
|
102
|
+
{e === props.effort ? `[${e}]` : e}
|
|
103
|
+
</Text>,
|
|
104
|
+
])}
|
|
105
|
+
<Text dimColor> , / . or click to adjust</Text>
|
|
54
106
|
</Text>
|
|
55
107
|
</Box>
|
|
56
108
|
<Text dimColor>
|
|
57
|
-
{flat[props.cursor]?.id ?? ''} · ↑/↓
|
|
109
|
+
{flat[props.cursor]?.id ?? ''} · ↑/↓ or hover · Enter, click or 1-9 picks · type anything to close
|
|
58
110
|
</Text>
|
|
59
111
|
</Box>
|
|
60
112
|
)
|
|
@@ -144,8 +144,24 @@ export const register: Register = on => {
|
|
|
144
144
|
|
|
145
145
|
on('ui.message', async ($, e, next) => {
|
|
146
146
|
if (e.element !== 'picker') return next(e)
|
|
147
|
-
const data = e.data as {
|
|
148
|
-
|
|
147
|
+
const data = e.data as {
|
|
148
|
+
move?: number
|
|
149
|
+
effort?: number
|
|
150
|
+
pick?: boolean
|
|
151
|
+
cursorTo?: number
|
|
152
|
+
pickAt?: number
|
|
153
|
+
effortTo?: string
|
|
154
|
+
}
|
|
155
|
+
const isIndex = (n: unknown): n is number => Number.isInteger(n) && (n as number) >= 0 && (n as number) < FLAT.length
|
|
156
|
+
if (isIndex(data.pickAt)) {
|
|
157
|
+
await pick($, data.pickAt)
|
|
158
|
+
} else if (isIndex(data.cursorTo)) {
|
|
159
|
+
const to = data.cursorTo
|
|
160
|
+
await update($, cursorAt, () => to)
|
|
161
|
+
} else if (typeof data.effortTo === 'string' && EFFORTS.includes(data.effortTo)) {
|
|
162
|
+
const to = data.effortTo
|
|
163
|
+
await update($, effortPick, () => to)
|
|
164
|
+
} else if (data.move) {
|
|
149
165
|
const at = await cursorOf($)
|
|
150
166
|
await update($, cursorAt, () => (at + data.move! + FLAT.length) % FLAT.length)
|
|
151
167
|
} else if (data.effort) {
|