@chances-ai/tui 14.0.0 → 15.0.0
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/dist/api-key-prompt.d.ts +8 -15
- package/dist/api-key-prompt.d.ts.map +1 -1
- package/dist/api-key-prompt.js +18 -30
- package/dist/api-key-prompt.js.map +1 -1
- package/dist/app.d.ts +5 -8
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +120 -98
- package/dist/app.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/modal.d.ts +3 -2
- package/dist/modal.d.ts.map +1 -1
- package/dist/modal.js +3 -2
- package/dist/modal.js.map +1 -1
- package/dist/model-picker.d.ts +7 -39
- package/dist/model-picker.d.ts.map +1 -1
- package/dist/model-picker.js +14 -67
- package/dist/model-picker.js.map +1 -1
- package/dist/select.d.ts +59 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +114 -0
- package/dist/select.js.map +1 -0
- package/dist/session-picker.d.ts +7 -15
- package/dist/session-picker.d.ts.map +1 -1
- package/dist/session-picker.js +14 -42
- package/dist/session-picker.js.map +1 -1
- package/dist/slash-typeahead.d.ts +34 -0
- package/dist/slash-typeahead.d.ts.map +1 -0
- package/dist/slash-typeahead.js +78 -0
- package/dist/slash-typeahead.js.map +1 -0
- package/package.json +5 -4
package/dist/model-picker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { JSX } from "react";
|
|
2
2
|
export interface PickableModel {
|
|
3
3
|
/** Display id, e.g. "claude-opus-4-7". */
|
|
4
4
|
id: string;
|
|
@@ -7,45 +7,13 @@ export interface PickableModel {
|
|
|
7
7
|
/** True for the currently-active model, rendered with a marker. */
|
|
8
8
|
current?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export interface ModelPickerState {
|
|
11
|
-
filter: string;
|
|
12
|
-
cursor: number;
|
|
13
|
-
}
|
|
14
|
-
/** Subset of Ink's Key shape that the reducer cares about. Defined locally so
|
|
15
|
-
* the reducer has no dependency on Ink at all — unit tests can drive it as
|
|
16
|
-
* plain data without needing a TTY. */
|
|
17
|
-
export interface PickerKey {
|
|
18
|
-
return?: boolean;
|
|
19
|
-
escape?: boolean;
|
|
20
|
-
upArrow?: boolean;
|
|
21
|
-
downArrow?: boolean;
|
|
22
|
-
backspace?: boolean;
|
|
23
|
-
delete?: boolean;
|
|
24
|
-
ctrl?: boolean;
|
|
25
|
-
meta?: boolean;
|
|
26
|
-
}
|
|
27
|
-
/** Subset of the active match list the reducer needs — kept as a generic
|
|
28
|
-
* function over PickableModel for ergonomics. */
|
|
29
|
-
export declare function filterModels(models: PickableModel[], filter: string): PickableModel[];
|
|
30
|
-
/**
|
|
31
|
-
* Pure reducer for the ModelPicker. Returns the next state plus an optional
|
|
32
|
-
* `resolved` value: a `PickableModel` when the user picked, `null` when they
|
|
33
|
-
* cancelled (Esc or Enter on empty matches), `undefined` when the keystroke
|
|
34
|
-
* was a navigation/filter edit and the picker should stay open.
|
|
35
|
-
*
|
|
36
|
-
* The component just plumbs Ink's useInput into this function — extracted so
|
|
37
|
-
* the keystroke logic is testable without ink-testing-library's stdin
|
|
38
|
-
* limitations.
|
|
39
|
-
*/
|
|
40
|
-
export declare function reduceModelPicker(state: ModelPickerState, char: string, key: PickerKey, models: PickableModel[]): {
|
|
41
|
-
state: ModelPickerState;
|
|
42
|
-
resolved?: PickableModel | null;
|
|
43
|
-
};
|
|
44
10
|
/**
|
|
45
|
-
* Fuzzy-filter model picker
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
11
|
+
* (5.10 A4) Fuzzy-filter model picker — now a thin wrapper over the generic
|
|
12
|
+
* {@link Select} (which owns all keystroke logic via the ink-ext `Select`
|
|
13
|
+
* context). The old per-component `useInput` + `reduceModelPicker` reducer are
|
|
14
|
+
* gone; their behavior (filter, ↑↓ clamp, Enter/Esc) is the Select's, covered by
|
|
15
|
+
* `select.test`. Signature is unchanged so `apps/cli/src/slash/model.ts` still
|
|
16
|
+
* renders `<ModelPicker models onChoose/>` verbatim.
|
|
49
17
|
*/
|
|
50
18
|
export declare function ModelPicker({ models, onChoose, }: {
|
|
51
19
|
models: PickableModel[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-picker.d.ts","sourceRoot":"","sources":["../src/model-picker.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-picker.d.ts","sourceRoot":"","sources":["../src/model-picker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjC,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;CACjD,GAAG,GAAG,CAAC,OAAO,CAed"}
|
package/dist/model-picker.js
CHANGED
|
@@ -1,72 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { useTheme } from "./theme-context.js";
|
|
5
|
-
/** Subset of the active match list the reducer needs — kept as a generic
|
|
6
|
-
* function over PickableModel for ergonomics. */
|
|
7
|
-
export function filterModels(models, filter) {
|
|
8
|
-
const lower = filter.toLowerCase();
|
|
9
|
-
if (!lower)
|
|
10
|
-
return models;
|
|
11
|
-
return models.filter((m) => `${m.provider}/${m.id}`.toLowerCase().includes(lower));
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Pure reducer for the ModelPicker. Returns the next state plus an optional
|
|
15
|
-
* `resolved` value: a `PickableModel` when the user picked, `null` when they
|
|
16
|
-
* cancelled (Esc or Enter on empty matches), `undefined` when the keystroke
|
|
17
|
-
* was a navigation/filter edit and the picker should stay open.
|
|
18
|
-
*
|
|
19
|
-
* The component just plumbs Ink's useInput into this function — extracted so
|
|
20
|
-
* the keystroke logic is testable without ink-testing-library's stdin
|
|
21
|
-
* limitations.
|
|
22
|
-
*/
|
|
23
|
-
export function reduceModelPicker(state, char, key, models) {
|
|
24
|
-
const matches = filterModels(models, state.filter);
|
|
25
|
-
const safeCursor = Math.min(state.cursor, Math.max(0, matches.length - 1));
|
|
26
|
-
if (key.escape)
|
|
27
|
-
return { state, resolved: null };
|
|
28
|
-
if (key.return) {
|
|
29
|
-
const choice = matches[safeCursor];
|
|
30
|
-
return { state, resolved: choice ?? null };
|
|
31
|
-
}
|
|
32
|
-
if (key.upArrow) {
|
|
33
|
-
return { state: { ...state, cursor: Math.max(0, safeCursor - 1) } };
|
|
34
|
-
}
|
|
35
|
-
if (key.downArrow) {
|
|
36
|
-
return { state: { ...state, cursor: Math.min(matches.length - 1, safeCursor + 1) } };
|
|
37
|
-
}
|
|
38
|
-
if (key.backspace || key.delete) {
|
|
39
|
-
return { state: { filter: state.filter.slice(0, -1), cursor: 0 } };
|
|
40
|
-
}
|
|
41
|
-
if (char && !key.ctrl && !key.meta) {
|
|
42
|
-
return { state: { filter: state.filter + char, cursor: 0 } };
|
|
43
|
-
}
|
|
44
|
-
return { state };
|
|
45
|
-
}
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Select } from "./select.js";
|
|
46
3
|
/**
|
|
47
|
-
* Fuzzy-filter model picker
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
4
|
+
* (5.10 A4) Fuzzy-filter model picker — now a thin wrapper over the generic
|
|
5
|
+
* {@link Select} (which owns all keystroke logic via the ink-ext `Select`
|
|
6
|
+
* context). The old per-component `useInput` + `reduceModelPicker` reducer are
|
|
7
|
+
* gone; their behavior (filter, ↑↓ clamp, Enter/Esc) is the Select's, covered by
|
|
8
|
+
* `select.test`. Signature is unchanged so `apps/cli/src/slash/model.ts` still
|
|
9
|
+
* renders `<ModelPicker models onChoose/>` verbatim.
|
|
51
10
|
*/
|
|
52
11
|
export function ModelPicker({ models, onChoose, }) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (next !== state)
|
|
62
|
-
setState(next);
|
|
63
|
-
});
|
|
64
|
-
const matches = filterModels(models, state.filter);
|
|
65
|
-
const safeCursor = Math.min(state.cursor, Math.max(0, matches.length - 1));
|
|
66
|
-
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.permission, paddingX: 1, children: [_jsx(Text, { color: theme.permission, children: "Pick a model \u00B7 type to filter \u00B7 \u2191\u2193 \u00B7 Enter \u00B7 Esc" }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { children: "filter: " }), _jsx(Text, { color: theme.warning, children: state.filter || "(any)" })] }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [matches.length === 0 ? (_jsx(Text, { dimColor: true, children: "no models match" })) : (matches.slice(0, 10).map((m, i) => {
|
|
67
|
-
const selected = i === safeCursor;
|
|
68
|
-
const marker = m.current ? "●" : " ";
|
|
69
|
-
return (_jsxs(Text, { color: selected ? theme.permission : undefined, children: [selected ? "▸ " : " ", marker, " ", _jsxs(Text, { dimColor: true, children: [m.provider, "/"] }), m.id] }, `${m.provider}/${m.id}`));
|
|
70
|
-
})), matches.length > 10 ? (_jsxs(Text, { dimColor: true, children: ["\u2026 ", matches.length - 10, " more (type to narrow)"] })) : null] })] }));
|
|
12
|
+
const options = models.map((m) => ({
|
|
13
|
+
label: `${m.provider}/${m.id}`,
|
|
14
|
+
value: m,
|
|
15
|
+
current: m.current,
|
|
16
|
+
}));
|
|
17
|
+
return (_jsx(Select, { heading: "Pick a model \u00B7 type to filter \u00B7 \u2191\u2193 \u00B7 Enter \u00B7 Esc", options: options, filterable: true, onSelect: onChoose, onCancel: () => onChoose(null) }));
|
|
71
18
|
}
|
|
72
19
|
//# sourceMappingURL=model-picker.js.map
|
package/dist/model-picker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-picker.js","sourceRoot":"","sources":["../src/model-picker.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"model-picker.js","sourceRoot":"","sources":["../src/model-picker.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC;AAWxD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,MAAM,EACN,QAAQ,GAIT;IACC,MAAM,OAAO,GAAkC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChE,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE,EAAE;QAC9B,KAAK,EAAE,CAAC;QACR,OAAO,EAAE,CAAC,CAAC,OAAO;KACnB,CAAC,CAAC,CAAC;IACJ,OAAO,CACL,KAAC,MAAM,IACL,OAAO,EAAC,gFAAkD,EAC1D,OAAO,EAAE,OAAO,EAChB,UAAU,QACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAC9B,CACH,CAAC;AACJ,CAAC"}
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type JSX, type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* (5.10 A2) The ONE generic single-select primitive. Generalizes the
|
|
4
|
+
* `reduceModelPicker` pure-reducer pattern so `/model`, `/resume`, and (v16)
|
|
5
|
+
* `AskUserQuestion` all drive the same list UI with identical keys/marks — the
|
|
6
|
+
* mistake pi and oh-my-pi both made was letting each call site re-roll its own
|
|
7
|
+
* list loop. Navigation comes entirely from the `Select` keybinding context
|
|
8
|
+
* (ink-ext A1); this component owns no `useInput`.
|
|
9
|
+
*
|
|
10
|
+
* `SelectMulti` (checkbox multi-select) lands in v16 alongside its only consumer,
|
|
11
|
+
* `AskUserQuestion` — building it now would be speculative.
|
|
12
|
+
*/
|
|
13
|
+
export interface SelectOption<T> {
|
|
14
|
+
/** Row text. */
|
|
15
|
+
label: string;
|
|
16
|
+
/** The value handed to `onSelect`. */
|
|
17
|
+
value: T;
|
|
18
|
+
/** Optional dim trailing description. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Non-selectable row (skipped by cursor movement, dimmed). */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Marks the currently-active choice (rendered with a `●`). */
|
|
23
|
+
current?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Case-insensitive substring filter over `label`+`description`. Empty filter
|
|
26
|
+
* returns the list unchanged. */
|
|
27
|
+
export declare function filterOptions<T>(options: SelectOption<T>[], filter: string): SelectOption<T>[];
|
|
28
|
+
/** Move the cursor by `delta`, clamped to `[0, count-1]` (no wrap — matches
|
|
29
|
+
* claude-code's Select + our model-picker), skipping `disabled` rows in the
|
|
30
|
+
* direction of travel. Returns the original cursor when there's nowhere to go. */
|
|
31
|
+
export declare function moveCursor<T>(options: SelectOption<T>[], cursor: number, delta: number): number;
|
|
32
|
+
/** Page the cursor by a window, clamped to range, then settle onto the nearest
|
|
33
|
+
* enabled row (search in the travel direction first, else the other way). */
|
|
34
|
+
export declare function pageCursor<T>(options: SelectOption<T>[], cursor: number, dir: -1 | 1, visibleRows: number): number;
|
|
35
|
+
/** The slice of options visible given the cursor + window, centered like the
|
|
36
|
+
* model picker. Returns `{ slice, offset }` so the renderer can mark the cursor
|
|
37
|
+
* and show "N more" affordances. */
|
|
38
|
+
export declare function visibleWindow<T>(options: SelectOption<T>[], cursor: number, visibleRows: number): {
|
|
39
|
+
slice: SelectOption<T>[];
|
|
40
|
+
offset: number;
|
|
41
|
+
};
|
|
42
|
+
/** Clamp a cursor into range against a (possibly re-filtered) list. */
|
|
43
|
+
export declare function clampCursor<T>(options: SelectOption<T>[], cursor: number): number;
|
|
44
|
+
export interface SelectProps<T> {
|
|
45
|
+
options: SelectOption<T>[];
|
|
46
|
+
onSelect: (value: T) => void;
|
|
47
|
+
onCancel: () => void;
|
|
48
|
+
/** Header line above the list. */
|
|
49
|
+
heading?: ReactNode;
|
|
50
|
+
/** Max rows shown at once (default 10). */
|
|
51
|
+
visibleRows?: number;
|
|
52
|
+
/** When true, typing narrows the list (model picker); otherwise typed chars
|
|
53
|
+
* are ignored (session picker). Default false. */
|
|
54
|
+
filterable?: boolean;
|
|
55
|
+
/** Whether this select owns input right now (pushes the `Select` context). */
|
|
56
|
+
active?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export declare function Select<T>({ options, onSelect, onCancel, heading, visibleRows, filterable, active, }: SelectProps<T>): JSX.Element;
|
|
59
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../src/select.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,KAAK,EAAE,CAAC,CAAC;IACT,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAID;kCACkC;AAClC,wBAAgB,aAAa,CAAC,CAAC,E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AM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,EACxB,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,WAAgB,EAChB,UAAkB,EAClB,MAAa,GACd,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CA6F9B"}
|
package/dist/select.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useKeybinding, useKeybindingContext, useTextInput } from "@chances-ai/ink-ext";
|
|
5
|
+
import { useTheme } from "./theme-context.js";
|
|
6
|
+
// -- pure helpers (unit-tested without a TTY, the reduceModelPicker convention) --
|
|
7
|
+
/** Case-insensitive substring filter over `label`+`description`. Empty filter
|
|
8
|
+
* returns the list unchanged. */
|
|
9
|
+
export function filterOptions(options, filter) {
|
|
10
|
+
const lower = filter.trim().toLowerCase();
|
|
11
|
+
if (!lower)
|
|
12
|
+
return options;
|
|
13
|
+
return options.filter((o) => `${o.label} ${o.description ?? ""}`.toLowerCase().includes(lower));
|
|
14
|
+
}
|
|
15
|
+
/** Move the cursor by `delta`, clamped to `[0, count-1]` (no wrap — matches
|
|
16
|
+
* claude-code's Select + our model-picker), skipping `disabled` rows in the
|
|
17
|
+
* direction of travel. Returns the original cursor when there's nowhere to go. */
|
|
18
|
+
export function moveCursor(options, cursor, delta) {
|
|
19
|
+
if (options.length === 0)
|
|
20
|
+
return 0;
|
|
21
|
+
const step = delta < 0 ? -1 : 1;
|
|
22
|
+
let next = cursor;
|
|
23
|
+
for (let i = 0; i < options.length; i++) {
|
|
24
|
+
next += step;
|
|
25
|
+
if (next < 0 || next > options.length - 1)
|
|
26
|
+
return cursor; // hit an edge → stay
|
|
27
|
+
if (!options[next]?.disabled)
|
|
28
|
+
return next;
|
|
29
|
+
}
|
|
30
|
+
return cursor;
|
|
31
|
+
}
|
|
32
|
+
/** Page the cursor by a window, clamped to range, then settle onto the nearest
|
|
33
|
+
* enabled row (search in the travel direction first, else the other way). */
|
|
34
|
+
export function pageCursor(options, cursor, dir, visibleRows) {
|
|
35
|
+
if (options.length === 0)
|
|
36
|
+
return 0;
|
|
37
|
+
const target = Math.min(options.length - 1, Math.max(0, cursor + dir * visibleRows));
|
|
38
|
+
if (!options[target]?.disabled)
|
|
39
|
+
return target;
|
|
40
|
+
const towards = moveCursor(options, target, dir);
|
|
41
|
+
if (towards !== target)
|
|
42
|
+
return towards;
|
|
43
|
+
return moveCursor(options, target, dir === 1 ? -1 : 1);
|
|
44
|
+
}
|
|
45
|
+
/** The slice of options visible given the cursor + window, centered like the
|
|
46
|
+
* model picker. Returns `{ slice, offset }` so the renderer can mark the cursor
|
|
47
|
+
* and show "N more" affordances. */
|
|
48
|
+
export function visibleWindow(options, cursor, visibleRows) {
|
|
49
|
+
if (options.length <= visibleRows)
|
|
50
|
+
return { slice: options, offset: 0 };
|
|
51
|
+
const half = Math.floor(visibleRows / 2);
|
|
52
|
+
let offset = cursor - half;
|
|
53
|
+
offset = Math.max(0, Math.min(offset, options.length - visibleRows));
|
|
54
|
+
return { slice: options.slice(offset, offset + visibleRows), offset };
|
|
55
|
+
}
|
|
56
|
+
/** Clamp a cursor into range against a (possibly re-filtered) list. */
|
|
57
|
+
export function clampCursor(options, cursor) {
|
|
58
|
+
return Math.min(Math.max(0, cursor), Math.max(0, options.length - 1));
|
|
59
|
+
}
|
|
60
|
+
export function Select({ options, onSelect, onCancel, heading, visibleRows = 10, filterable = false, active = true, }) {
|
|
61
|
+
const { theme } = useTheme();
|
|
62
|
+
const [filter, setFilter] = useState("");
|
|
63
|
+
const [cursor, setCursor] = useState(0);
|
|
64
|
+
// Select is a MODAL context: while it's up, the chat below receives nothing.
|
|
65
|
+
useKeybindingContext("Select", active);
|
|
66
|
+
const matches = filterOptions(options, filter);
|
|
67
|
+
const safeCursor = clampCursor(matches, cursor);
|
|
68
|
+
useKeybinding("select:previous", () => setCursor(moveCursor(matches, safeCursor, -1)), {
|
|
69
|
+
context: "Select",
|
|
70
|
+
active,
|
|
71
|
+
});
|
|
72
|
+
useKeybinding("select:next", () => setCursor(moveCursor(matches, safeCursor, 1)), {
|
|
73
|
+
context: "Select",
|
|
74
|
+
active,
|
|
75
|
+
});
|
|
76
|
+
useKeybinding("select:pageUp", () => setCursor(pageCursor(matches, safeCursor, -1, visibleRows)), {
|
|
77
|
+
context: "Select",
|
|
78
|
+
active,
|
|
79
|
+
});
|
|
80
|
+
useKeybinding("select:pageDown", () => setCursor(pageCursor(matches, safeCursor, 1, visibleRows)), {
|
|
81
|
+
context: "Select",
|
|
82
|
+
active,
|
|
83
|
+
});
|
|
84
|
+
useKeybinding("select:accept", () => {
|
|
85
|
+
const choice = matches[safeCursor];
|
|
86
|
+
if (choice && !choice.disabled)
|
|
87
|
+
onSelect(choice.value);
|
|
88
|
+
else
|
|
89
|
+
onCancel(); // accept on empty/disabled = cancel, matching reduceModelPicker
|
|
90
|
+
}, { context: "Select", active });
|
|
91
|
+
useKeybinding("select:cancel", onCancel, { context: "Select", active });
|
|
92
|
+
// Free-text: narrows the filter when filterable; backspace edits it. Typed
|
|
93
|
+
// chars are otherwise ignored (no Other row in v15 — that's v16/AskUserQuestion).
|
|
94
|
+
useTextInput("Select", (input, key) => {
|
|
95
|
+
if (!filterable)
|
|
96
|
+
return;
|
|
97
|
+
if (key.backspace || key.delete) {
|
|
98
|
+
setFilter((f) => f.slice(0, -1));
|
|
99
|
+
setCursor(0);
|
|
100
|
+
}
|
|
101
|
+
else if (input && !key.ctrl && !key.meta) {
|
|
102
|
+
setFilter((f) => f + input);
|
|
103
|
+
setCursor(0);
|
|
104
|
+
}
|
|
105
|
+
}, { active });
|
|
106
|
+
const { slice, offset } = visibleWindow(matches, safeCursor, visibleRows);
|
|
107
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.permission, paddingX: 1, children: [heading ? _jsx(Text, { color: theme.permission, children: heading }) : null, filterable ? (_jsxs(Box, { marginTop: heading ? 1 : 0, children: [_jsx(Text, { children: "filter: " }), _jsx(Text, { color: theme.warning, children: filter || "(any)" })] })) : null, _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [matches.length === 0 ? (_jsx(Text, { dimColor: true, children: "no matches" })) : (slice.map((o, i) => {
|
|
108
|
+
const idx = offset + i;
|
|
109
|
+
const selected = idx === safeCursor;
|
|
110
|
+
const marker = o.current ? "●" : " ";
|
|
111
|
+
return (_jsxs(Text, { color: selected ? theme.permission : undefined, dimColor: o.disabled, children: [selected ? "❯ " : " ", marker, " ", o.label, o.description ? _jsxs(Text, { dimColor: true, children: [" \u2014 ", o.description] }) : null] }, `${idx}-${o.label}`));
|
|
112
|
+
})), matches.length > slice.length ? (_jsxs(Text, { dimColor: true, children: ["\u2026 ", matches.length - slice.length, " more"] })) : null] })] }));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../src/select.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,QAAQ,EAA4B,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA0B9C,mFAAmF;AAEnF;kCACkC;AAClC,MAAM,UAAU,aAAa,CAAI,OAA0B,EAAE,MAAc;IACzE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,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AOnB,CACR,CAAC;oBACJ,CAAC,CAAC,CACH,EACA,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAC/B,MAAC,IAAI,IAAC,QAAQ,8BAAI,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,aAAa,CAC7D,CAAC,CAAC,CAAC,IAAI,IACJ,IACF,CACP,CAAC;AACJ,CAAC"}
|
package/dist/session-picker.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { PickerKey } from "./model-picker.js";
|
|
1
|
+
import type { JSX } from "react";
|
|
3
2
|
export interface PickableSession {
|
|
4
3
|
id: string;
|
|
5
4
|
title: string;
|
|
@@ -10,19 +9,12 @@ export interface PickableSession {
|
|
|
10
9
|
preview?: string;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
resolved?: PickableSession | null;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Vertical list of recent sessions with arrow-key cursor + Enter to resume.
|
|
23
|
-
* Modeled on oh-my-pi's `session-selector.ts`; simplified — no fuzzy filter
|
|
24
|
-
* yet (defer until lists exceed ~20 entries in practice). All keystroke
|
|
25
|
-
* logic in {@link reduceSessionPicker} for testability.
|
|
12
|
+
* (5.10 A4) Recent-session picker — a thin wrapper over the generic
|
|
13
|
+
* {@link Select}. The old `useInput` + `reduceSessionPicker` reducer are gone;
|
|
14
|
+
* the ↑↓/Enter/Esc behavior is the Select's (see `select.test`). Not filterable
|
|
15
|
+
* (lists are short — last ~10 by updatedAt). Signature unchanged so
|
|
16
|
+
* `apps/cli/src/slash/resume.ts` renders `<SessionPicker sessions onChoose/>`
|
|
17
|
+
* verbatim.
|
|
26
18
|
*/
|
|
27
19
|
export declare function SessionPicker({ sessions, onChoose, }: {
|
|
28
20
|
sessions: PickableSession[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-picker.d.ts","sourceRoot":"","sources":["../src/session-picker.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-picker.d.ts","sourceRoot":"","sources":["../src/session-picker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjC,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB;qEACiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC;CACrD,GAAG,GAAG,CAAC,OAAO,CAcd"}
|
package/dist/session-picker.js
CHANGED
|
@@ -1,47 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { useTheme } from "./theme-context.js";
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Select } from "./select.js";
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (key.escape)
|
|
13
|
-
return { cursor: safe, resolved: null };
|
|
14
|
-
if (key.return)
|
|
15
|
-
return { cursor: safe, resolved: sessions[safe] ?? null };
|
|
16
|
-
if (key.upArrow)
|
|
17
|
-
return { cursor: Math.max(0, safe - 1) };
|
|
18
|
-
if (key.downArrow)
|
|
19
|
-
return { cursor: Math.min(sessions.length - 1, safe + 1) };
|
|
20
|
-
return { cursor: safe };
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Vertical list of recent sessions with arrow-key cursor + Enter to resume.
|
|
24
|
-
* Modeled on oh-my-pi's `session-selector.ts`; simplified — no fuzzy filter
|
|
25
|
-
* yet (defer until lists exceed ~20 entries in practice). All keystroke
|
|
26
|
-
* logic in {@link reduceSessionPicker} for testability.
|
|
4
|
+
* (5.10 A4) Recent-session picker — a thin wrapper over the generic
|
|
5
|
+
* {@link Select}. The old `useInput` + `reduceSessionPicker` reducer are gone;
|
|
6
|
+
* the ↑↓/Enter/Esc behavior is the Select's (see `select.test`). Not filterable
|
|
7
|
+
* (lists are short — last ~10 by updatedAt). Signature unchanged so
|
|
8
|
+
* `apps/cli/src/slash/resume.ts` renders `<SessionPicker sessions onChoose/>`
|
|
9
|
+
* verbatim.
|
|
27
10
|
*/
|
|
28
11
|
export function SessionPicker({ sessions, onChoose, }) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onChoose(resolved);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (next !== cursor)
|
|
39
|
-
setCursor(next);
|
|
40
|
-
});
|
|
41
|
-
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.permission, paddingX: 1, children: [_jsx(Text, { color: theme.permission, children: "Resume a session \u00B7 \u2191\u2193 \u00B7 Enter \u00B7 Esc" }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: sessions.length === 0 ? (_jsx(Text, { dimColor: true, children: "no saved sessions in this workspace" })) : (sessions.slice(0, 10).map((s, i) => {
|
|
42
|
-
const selected = i === safeCursor;
|
|
43
|
-
const date = s.updatedAt.slice(0, 10);
|
|
44
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: selected ? theme.permission : undefined, children: [selected ? "▸ " : " ", _jsx(Text, { dimColor: true, children: date }), " ", s.title] }), s.preview ? (_jsxs(Text, { dimColor: true, children: [" ", s.preview.slice(0, 60)] })) : null] }, s.id));
|
|
45
|
-
})) })] }));
|
|
12
|
+
const options = sessions.map((s) => ({
|
|
13
|
+
label: `${s.updatedAt.slice(0, 10)} ${s.title}`,
|
|
14
|
+
value: s,
|
|
15
|
+
description: s.preview ? s.preview.slice(0, 60) : undefined,
|
|
16
|
+
}));
|
|
17
|
+
return (_jsx(Select, { heading: "Resume a session \u00B7 \u2191\u2193 \u00B7 Enter \u00B7 Esc", options: options, onSelect: onChoose, onCancel: () => onChoose(null) }));
|
|
46
18
|
}
|
|
47
19
|
//# sourceMappingURL=session-picker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-picker.js","sourceRoot":"","sources":["../src/session-picker.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"session-picker.js","sourceRoot":"","sources":["../src/session-picker.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC;AAYxD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,QAAQ,EACR,QAAQ,GAIT;IACC,MAAM,OAAO,GAAoC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpE,KAAK,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE;QAC/C,KAAK,EAAE,CAAC;QACR,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;KAC5D,CAAC,CAAC,CAAC;IACJ,OAAO,CACL,KAAC,MAAM,IACL,OAAO,EAAC,8DAAqC,EAC7C,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAC9B,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type JSX } from "react";
|
|
2
|
+
export interface SlashSuggestion {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
/** (5.10 A3) Ghost-text shown after the name, e.g. `<provider> <url>`. */
|
|
6
|
+
argumentHint?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Pure helper for picking the suggestions to show for a partial input. The
|
|
9
|
+
* typeahead is only meaningful before the first space (while typing the command
|
|
10
|
+
* NAME); once args begin, the menu hides and Enter submits normally. */
|
|
11
|
+
export declare function suggestSlashCommands(input: string, available: SlashSuggestion[]): SlashSuggestion[];
|
|
12
|
+
/**
|
|
13
|
+
* (5.10 A3) Stateful slash-command typeahead — replaces the old passive
|
|
14
|
+
* ghost-text list. While visible it owns the **non-modal** `Autocomplete`
|
|
15
|
+
* context (ink-ext A1), so the user keeps typing into chat to filter, but
|
|
16
|
+
* `↑/↓` select, `Tab` completes the name, `Enter` executes the SELECTED command
|
|
17
|
+
* (not the raw text), and `Esc` dismisses. The Enter interception is real
|
|
18
|
+
* submit-gating: `Autocomplete.return → autocomplete:execute` resolves before
|
|
19
|
+
* `Chat.chat:submit` on the bus, so the menu must be acted on or dismissed.
|
|
20
|
+
*
|
|
21
|
+
* Visible only while typing the command name (input starts with `/`, no space
|
|
22
|
+
* yet, ≥1 match, not dismissed). Tab inserts a trailing space → the menu closes
|
|
23
|
+
* and the user types args, which Enter then submits via the normal chat path.
|
|
24
|
+
*/
|
|
25
|
+
export declare function SlashTypeahead({ input, available, busy, onComplete, onExecute, }: {
|
|
26
|
+
input: string;
|
|
27
|
+
available: SlashSuggestion[];
|
|
28
|
+
busy: boolean;
|
|
29
|
+
/** Tab: replace the draft with the completed `"/name "` (trailing space). */
|
|
30
|
+
onComplete: (newInput: string) => void;
|
|
31
|
+
/** Enter: run the selected command line `"/name"`. */
|
|
32
|
+
onExecute: (line: string) => void;
|
|
33
|
+
}): JSX.Element | null;
|
|
34
|
+
//# sourceMappingURL=slash-typeahead.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash-typeahead.d.ts","sourceRoot":"","sources":["../src/slash-typeahead.tsx"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAItD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;yEAEyE;AACzE,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,eAAe,EAAE,GAC3B,eAAe,EAAE,CAKnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,SAAS,EACT,IAAI,EACJ,UAAU,EACV,SAAS,GACV,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,6EAA6E;IAC7E,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,sDAAsD;IACtD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAgErB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useKeybinding, useKeybindingContext } from "@chances-ai/ink-ext";
|
|
5
|
+
import { useTheme } from "./theme-context.js";
|
|
6
|
+
/** Pure helper for picking the suggestions to show for a partial input. The
|
|
7
|
+
* typeahead is only meaningful before the first space (while typing the command
|
|
8
|
+
* NAME); once args begin, the menu hides and Enter submits normally. */
|
|
9
|
+
export function suggestSlashCommands(input, available) {
|
|
10
|
+
if (!input.startsWith("/"))
|
|
11
|
+
return [];
|
|
12
|
+
const partial = input.slice(1).toLowerCase();
|
|
13
|
+
if (partial === "")
|
|
14
|
+
return available.slice(0, 5);
|
|
15
|
+
return available.filter((c) => c.name.toLowerCase().startsWith(partial)).slice(0, 5);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* (5.10 A3) Stateful slash-command typeahead — replaces the old passive
|
|
19
|
+
* ghost-text list. While visible it owns the **non-modal** `Autocomplete`
|
|
20
|
+
* context (ink-ext A1), so the user keeps typing into chat to filter, but
|
|
21
|
+
* `↑/↓` select, `Tab` completes the name, `Enter` executes the SELECTED command
|
|
22
|
+
* (not the raw text), and `Esc` dismisses. The Enter interception is real
|
|
23
|
+
* submit-gating: `Autocomplete.return → autocomplete:execute` resolves before
|
|
24
|
+
* `Chat.chat:submit` on the bus, so the menu must be acted on or dismissed.
|
|
25
|
+
*
|
|
26
|
+
* Visible only while typing the command name (input starts with `/`, no space
|
|
27
|
+
* yet, ≥1 match, not dismissed). Tab inserts a trailing space → the menu closes
|
|
28
|
+
* and the user types args, which Enter then submits via the normal chat path.
|
|
29
|
+
*/
|
|
30
|
+
export function SlashTypeahead({ input, available, busy, onComplete, onExecute, }) {
|
|
31
|
+
const { theme } = useTheme();
|
|
32
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
33
|
+
const [dismissed, setDismissed] = useState(false);
|
|
34
|
+
const matches = suggestSlashCommands(input, available);
|
|
35
|
+
const isCommandName = input.startsWith("/") && !input.includes(" ");
|
|
36
|
+
const visible = isCommandName && matches.length > 0 && !dismissed;
|
|
37
|
+
// Any edit to the draft re-opens the menu and resets the selection — the
|
|
38
|
+
// filter changed, so a stale index/dismiss must not stick.
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setDismissed(false);
|
|
41
|
+
setSelectedIndex(0);
|
|
42
|
+
}, [input]);
|
|
43
|
+
const safeIndex = Math.min(selectedIndex, Math.max(0, matches.length - 1));
|
|
44
|
+
useKeybindingContext("Autocomplete", visible);
|
|
45
|
+
useKeybinding("autocomplete:previous", () => setSelectedIndex(Math.max(0, safeIndex - 1)), {
|
|
46
|
+
context: "Autocomplete",
|
|
47
|
+
active: visible,
|
|
48
|
+
});
|
|
49
|
+
useKeybinding("autocomplete:next", () => setSelectedIndex(Math.min(matches.length - 1, safeIndex + 1)), {
|
|
50
|
+
context: "Autocomplete",
|
|
51
|
+
active: visible,
|
|
52
|
+
});
|
|
53
|
+
useKeybinding("autocomplete:accept", // Tab — complete the name, leave args to the user
|
|
54
|
+
() => {
|
|
55
|
+
const m = matches[safeIndex];
|
|
56
|
+
if (m)
|
|
57
|
+
onComplete(`/${m.name} `);
|
|
58
|
+
}, { context: "Autocomplete", active: visible });
|
|
59
|
+
useKeybinding("autocomplete:execute", // Enter — run the selected command
|
|
60
|
+
() => {
|
|
61
|
+
if (busy)
|
|
62
|
+
return; // mirror chat:submit's streaming guard
|
|
63
|
+
const m = matches[safeIndex];
|
|
64
|
+
if (m)
|
|
65
|
+
onExecute(`/${m.name}`);
|
|
66
|
+
}, { context: "Autocomplete", active: visible });
|
|
67
|
+
useKeybinding("autocomplete:dismiss", () => setDismissed(true), {
|
|
68
|
+
context: "Autocomplete",
|
|
69
|
+
active: visible,
|
|
70
|
+
});
|
|
71
|
+
if (!visible)
|
|
72
|
+
return null;
|
|
73
|
+
return (_jsx(Box, { flexDirection: "column", marginLeft: 2, children: matches.map((m, i) => {
|
|
74
|
+
const selected = i === safeIndex;
|
|
75
|
+
return (_jsxs(Text, { color: selected ? theme.permission : undefined, dimColor: !selected, children: [selected ? "❯ " : " ", "/", m.name, m.argumentHint ? _jsxs(Text, { dimColor: true, children: [" ", m.argumentHint] }) : null, _jsxs(Text, { dimColor: true, children: [" \u2014 ", m.description] })] }, m.name));
|
|
76
|
+
}) }));
|
|
77
|
+
}
|
|
78
|
+
//#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