@lynn123411/dsh-model-submenu 0.3.14 → 0.3.16

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.
@@ -2,13 +2,12 @@
2
2
  * Catalog flattening, tab derivation, and query matching for the picker.
3
3
  *
4
4
  * The model catalog groups models by provider; the picker shows one flat list
5
- * with a tab per provider, so both surfaces read from these rows. Matching
6
- * delegates to the shell's own ranker, which is why a query behaves the same
7
- * here as in the built-in menu: case-insensitive, ordered subsequence, prefix
8
- * hits first.
5
+ * with a tab per provider. The shared text search index matches model and
6
+ * provider names and IDs.
9
7
  */
10
8
 
11
9
  import type { ModelDirectoryState } from '@deepseek-ai/dsh-client-ui-model-selection/client'
10
+ import { TextSearchIndex } from '@deepseek-ai/dsh-util-text-search'
12
11
 
13
12
  /** One provider group of the shared catalog. */
14
13
  export type ProviderGroup = ModelDirectoryState['groups'][number]
@@ -76,21 +75,11 @@ export function rowsForTab(rows: readonly ModelRow[], tab: string): readonly Mod
76
75
  return tab === ALL_TAB ? rows : rows.filter((row) => row.provider === tab)
77
76
  }
78
77
 
79
- /** One row handed to the shell's ranker, carrying both searchable keys. */
80
- export interface SearchCandidate {
81
- readonly name: string
82
- readonly label: string
83
- readonly row: ModelRow
84
- }
85
-
86
- /**
87
- * Shape rows as the shell's ranker candidates: the model name is the name, the
88
- * provider display name is the second key, so a query reaches either.
89
- * @param rows - the rows to search.
90
- * @returns candidates in row order.
91
- */
92
- export function searchCandidates(rows: readonly ModelRow[]): readonly SearchCandidate[] {
93
- return rows.map((row) => ({ name: row.entry.name, label: row.providerName, row }))
78
+ /** Build a reusable search index for the rows in the current provider tab. */
79
+ export function createModelSearch(rows: readonly ModelRow[]): TextSearchIndex<ModelRow> {
80
+ return new TextSearchIndex(rows, (row) => ({
81
+ fuzzy: [row.entry.name, row.model, row.providerName, row.provider],
82
+ }))
94
83
  }
95
84
 
96
85
  /**
@@ -106,20 +95,3 @@ export function reasoningOf(
106
95
  ?.models.find((candidate) => candidate.id === model)
107
96
  ?.reasoning
108
97
  }
109
-
110
- /**
111
- * Filter rows by a query over the model name and the provider name.
112
- * @param rows - the rows to search.
113
- * @param query - the typed text; an empty or blank query keeps every row.
114
- * @param rank - the shell's own ranker, so this search behaves like every other one.
115
- * @returns the matching rows.
116
- */
117
- export function searchRows(
118
- rows: readonly ModelRow[],
119
- query: string,
120
- rank: (items: readonly SearchCandidate[], query: string) => readonly SearchCandidate[],
121
- ): readonly ModelRow[] {
122
- const trimmed = query.trim()
123
- if (trimmed === '') return rows
124
- return rank(searchCandidates(rows), trimmed).map((match) => match.row)
125
- }
@@ -94,12 +94,16 @@ export function planModelCommit(
94
94
  * @returns the metadata, or undefined when no model is live or it advertises none.
95
95
  */
96
96
  export function liveReasoning(state: ModelDirectoryState): ModelReasoning | undefined {
97
+ return currentCatalogModel(state)?.reasoning
98
+ }
99
+
100
+ /** Find the current model by its provider and model IDs. */
101
+ export function currentCatalogModel(state: ModelDirectoryState) {
97
102
  const current = state.current
98
103
  if (current === null) return undefined
99
104
  return state.groups
100
105
  .find((group) => group.id === current.provider)
101
106
  ?.models.find((model) => model.id === current.model)
102
- ?.reasoning
103
107
  }
104
108
 
105
109
  /**
@@ -1,4 +1,5 @@
1
1
  declare module '*.module.css' {
2
+ export const stylesheet: string
2
3
  const classes: Record<string, string>
3
4
  export default classes
4
5
  }