dsh-subscriptions 0.1.4 → 0.2.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.
Files changed (62) hide show
  1. package/README.md +31 -5
  2. package/lib/auth/device-flow.js +6 -3
  3. package/lib/auth/oauth-flow.js +41 -8
  4. package/lib/auth/rpc.d.ts +73 -2
  5. package/lib/auth/rpc.js +53 -3
  6. package/lib/client/ExternalUsageCards.js +1 -1
  7. package/lib/client/OllamaCard.d.ts +13 -0
  8. package/lib/client/OllamaCard.js +76 -0
  9. package/lib/client/OllamaSettingsManager.d.ts +24 -0
  10. package/lib/client/OllamaSettingsManager.js +246 -0
  11. package/lib/client/ProviderModelEditor.js +4 -2
  12. package/lib/client/SubscriptionUsageBadge.d.ts +1 -1
  13. package/lib/client/SubscriptionUsageBadge.js +3 -2
  14. package/lib/client/SubscriptionsSection.d.ts +2 -74
  15. package/lib/client/SubscriptionsSection.js +4 -67
  16. package/lib/client/UsageMeter.js +11 -7
  17. package/lib/client/locales.d.ts +68 -0
  18. package/lib/client/locales.js +77 -0
  19. package/lib/client/ollama-draft.d.ts +229 -0
  20. package/lib/client/ollama-draft.js +246 -0
  21. package/lib/client/usage-pace.d.ts +7 -0
  22. package/lib/client/usage-pace.js +15 -0
  23. package/lib/client.js +1385 -244
  24. package/lib/client.js.map +1 -1
  25. package/lib/index.d.ts +25 -0
  26. package/lib/index.js +11060 -9733
  27. package/lib/model-defaults.d.ts +4 -5
  28. package/lib/model-defaults.js +18 -14
  29. package/lib/provider-settings.d.ts +2 -1
  30. package/lib/provider-settings.js +6 -4
  31. package/lib/providers/antigravity.d.ts +0 -2
  32. package/lib/providers/antigravity.js +5 -9
  33. package/lib/providers/claude.d.ts +14 -1
  34. package/lib/providers/claude.js +25 -13
  35. package/lib/providers/codex-search.js +5 -2
  36. package/lib/providers/codex.js +7 -7
  37. package/lib/providers/common.d.ts +27 -0
  38. package/lib/providers/common.js +70 -0
  39. package/lib/providers/copilot.js +3 -3
  40. package/lib/providers/cursor-adapter.d.ts +35 -0
  41. package/lib/providers/cursor-adapter.js +245 -4
  42. package/lib/providers/cursor-auth.js +11 -4
  43. package/lib/providers/cursor-usage.js +2 -1
  44. package/lib/providers/external-usage-controller.d.ts +9 -2
  45. package/lib/providers/external-usage-controller.js +19 -5
  46. package/lib/providers/external-usage.d.ts +8 -0
  47. package/lib/providers/external-usage.js +93 -8
  48. package/lib/providers/grok.js +14 -9
  49. package/lib/providers/minimax-usage.js +2 -1
  50. package/lib/providers/ollama-settings.d.ts +90 -0
  51. package/lib/providers/ollama-settings.js +197 -0
  52. package/lib/providers/ollama-web.d.ts +46 -0
  53. package/lib/providers/ollama-web.js +213 -0
  54. package/lib/providers/ollama.d.ts +107 -0
  55. package/lib/providers/ollama.js +545 -0
  56. package/lib/tools/image-generate.js +2 -1
  57. package/lib/tools/video-generate.d.ts +0 -5
  58. package/lib/tools/video-generate.js +25 -14
  59. package/lib/tools/x-search.js +2 -2
  60. package/lib/translate/resolved.d.ts +5 -2
  61. package/lib/translate/resolved.js +5 -2
  62. package/package.json +1 -1
@@ -73,6 +73,7 @@ export declare const en: {
73
73
  usageRefresh: string;
74
74
  usageLoading: string;
75
75
  usageEmpty: string;
76
+ usageUnsupported: string;
76
77
  usageError: string;
77
78
  usageSession: string;
78
79
  usageWeekly: string;
@@ -199,6 +200,39 @@ export declare const en: {
199
200
  speedFastDescription: string;
200
201
  commandFast: string;
201
202
  commandFastUnavailable: string;
203
+ ollamaTitle: string;
204
+ ollamaStatus: string;
205
+ ollamaStatusNone: string;
206
+ ollamaWebOn: string;
207
+ ollamaWebOff: string;
208
+ ollamaManageTitle: string;
209
+ ollamaManageHint: string;
210
+ ollamaFetch: string;
211
+ ollamaFetching: string;
212
+ ollamaKeyPlaceholder: string;
213
+ ollamaKeyHint: string;
214
+ ollamaFetchFailed: string;
215
+ ollamaCandidatesCount: string;
216
+ ollamaCandidatesEmpty: string;
217
+ ollamaModelsEmpty: string;
218
+ ollamaModelsLoadFailed: string;
219
+ ollamaModelsSaveFailed: string;
220
+ ollamaConfigureHint: string;
221
+ ollamaDisplayName: string;
222
+ ollamaRowDetails: string;
223
+ ollamaEffortsUnknown: string;
224
+ ollamaMoveUp: string;
225
+ ollamaMoveDown: string;
226
+ ollamaBaseURL: string;
227
+ ollamaApiKeyRef: string;
228
+ ollamaConnectionHint: string;
229
+ ollamaWebHint: string;
230
+ ollamaCatalogOverride: string;
231
+ ollamaResetDefaults: string;
232
+ ollamaResetConfirm: string;
233
+ ollamaCapVision: string;
234
+ ollamaCapThinking: string;
235
+ ollamaContext: string;
202
236
  };
203
237
  /** zh strings, one per {@link en} key. */
204
238
  export declare const zh: {
@@ -274,6 +308,7 @@ export declare const zh: {
274
308
  usageRefresh: string;
275
309
  usageLoading: string;
276
310
  usageEmpty: string;
311
+ usageUnsupported: string;
277
312
  usageError: string;
278
313
  usageSession: string;
279
314
  usageWeekly: string;
@@ -400,6 +435,39 @@ export declare const zh: {
400
435
  speedFastDescription: string;
401
436
  commandFast: string;
402
437
  commandFastUnavailable: string;
438
+ ollamaTitle: string;
439
+ ollamaStatus: string;
440
+ ollamaStatusNone: string;
441
+ ollamaWebOn: string;
442
+ ollamaWebOff: string;
443
+ ollamaManageTitle: string;
444
+ ollamaManageHint: string;
445
+ ollamaFetch: string;
446
+ ollamaFetching: string;
447
+ ollamaKeyPlaceholder: string;
448
+ ollamaKeyHint: string;
449
+ ollamaFetchFailed: string;
450
+ ollamaCandidatesCount: string;
451
+ ollamaCandidatesEmpty: string;
452
+ ollamaModelsEmpty: string;
453
+ ollamaModelsLoadFailed: string;
454
+ ollamaModelsSaveFailed: string;
455
+ ollamaConfigureHint: string;
456
+ ollamaDisplayName: string;
457
+ ollamaRowDetails: string;
458
+ ollamaEffortsUnknown: string;
459
+ ollamaMoveUp: string;
460
+ ollamaMoveDown: string;
461
+ ollamaBaseURL: string;
462
+ ollamaApiKeyRef: string;
463
+ ollamaConnectionHint: string;
464
+ ollamaWebHint: string;
465
+ ollamaCatalogOverride: string;
466
+ ollamaResetDefaults: string;
467
+ ollamaResetConfirm: string;
468
+ ollamaCapVision: string;
469
+ ollamaCapThinking: string;
470
+ ollamaContext: string;
403
471
  };
404
472
  /** The Subscriptions namespace key union (en is the key-set source of truth). */
405
473
  export type SubscriptionsKey = keyof typeof en;
@@ -73,6 +73,7 @@ export const en = {
73
73
  usageRefresh: 'Refresh',
74
74
  usageLoading: 'Loading usage…',
75
75
  usageEmpty: 'No usage windows reported.',
76
+ usageUnsupported: 'This endpoint has no usage surface.',
76
77
  usageError: 'Usage lookup failed: {message}',
77
78
  usageSession: '5-hour window',
78
79
  usageWeekly: 'Weekly',
@@ -199,6 +200,47 @@ export const en = {
199
200
  speedFastDescription: '1.5x speed, more usage',
200
201
  commandFast: 'Switch the Codex speed tier (Standard/Fast)',
201
202
  commandFastUnavailable: 'The current model has no fast tier; /fast only works on Codex models whose catalog advertises one',
203
+ ollamaTitle: 'Ollama Cloud',
204
+ ollamaStatus: '{count} model(s) in the picker',
205
+ ollamaStatusNone: 'No models configured',
206
+ ollamaWebOn: 'Web search/fetch enabled',
207
+ ollamaWebOff: 'Web search/fetch off',
208
+ ollamaManageTitle: 'Manage Ollama Cloud',
209
+ ollamaManageHint: 'Fetch the Cloud list, tick the models this route serves, then Save. The picker '
210
+ + 'shows the ticked models in order; the API key itself stays in DSH credentials.',
211
+ ollamaFetch: 'Fetch cloud models',
212
+ ollamaFetching: 'Fetching…',
213
+ ollamaKeyPlaceholder: 'One-time API key (optional)',
214
+ ollamaKeyHint: 'A key typed here is used for this fetch only and is never saved. Leave it '
215
+ + 'blank to use the stored credential.',
216
+ ollamaFetchFailed: 'Could not fetch cloud models: {message}',
217
+ ollamaCandidatesCount: '{count} returned',
218
+ ollamaCandidatesEmpty: 'No cloud models returned.',
219
+ ollamaModelsEmpty: 'No models configured. Fetch the cloud list and tick the ones to keep.',
220
+ ollamaModelsLoadFailed: 'Could not load Ollama settings: {message}',
221
+ ollamaModelsSaveFailed: 'Could not save Ollama settings: {message}',
222
+ ollamaConfigureHint: 'No API key found at {ref}. Add it to the credentials file '
223
+ + '(~/.dsh/.credentials.yaml).',
224
+ ollamaDisplayName: 'Display name',
225
+ ollamaRowDetails: 'Details',
226
+ ollamaEffortsUnknown: 'This model reasons; its level set will come from live discovery.',
227
+ ollamaMoveUp: 'Move up',
228
+ ollamaMoveDown: 'Move down',
229
+ ollamaBaseURL: 'Base URL',
230
+ ollamaApiKeyRef: 'API key reference',
231
+ ollamaConnectionHint: "The base URL receives this route's requests and the credential lookup; the "
232
+ + "reference names the DSH credential, not the key itself. Requests send "
233
+ + "the resolved key to that address, so point it only at a host you trust.",
234
+ ollamaWebHint: 'Enables the Ollama Cloud web search and fetch providers. The host still '
235
+ + 'has to select them before the web tools use them.',
236
+ ollamaCatalogOverride: "A profile pins this route's model list; the picker ignores store models "
237
+ + "until that override is removed.",
238
+ ollamaResetDefaults: 'Restore deployment defaults',
239
+ ollamaResetConfirm: 'Clear every saved Ollama override? The profile values and built-in '
240
+ + 'defaults apply again.',
241
+ ollamaCapVision: 'vision',
242
+ ollamaCapThinking: 'thinking',
243
+ ollamaContext: 'context {tokens}',
202
244
  };
203
245
  /** zh strings, one per {@link en} key. */
204
246
  export const zh = {
@@ -274,6 +316,7 @@ export const zh = {
274
316
  usageRefresh: '刷新',
275
317
  usageLoading: '用量加载中…',
276
318
  usageEmpty: '服务商未返回任何用量窗口。',
319
+ usageUnsupported: '该端点不提供用量查询。',
277
320
  usageError: '用量查询失败:{message}',
278
321
  usageSession: '5 小时窗口',
279
322
  usageWeekly: '每周',
@@ -400,4 +443,38 @@ export const zh = {
400
443
  speedFastDescription: '约 1.5 倍速度,消耗更多用量',
401
444
  commandFast: '切换 Codex 速度档(标准/快速)',
402
445
  commandFastUnavailable: '当前模型不支持快速档;/fast 仅对目录声明了 fast tier 的 Codex 模型可用',
446
+ ollamaTitle: 'Ollama Cloud',
447
+ ollamaStatus: '选择器中 {count} 个模型',
448
+ ollamaStatusNone: '尚未配置模型',
449
+ ollamaWebOn: '网页搜索/抓取已启用',
450
+ ollamaWebOff: '网页搜索/抓取已关闭',
451
+ ollamaManageTitle: '管理 Ollama Cloud',
452
+ ollamaManageHint: '选择此路由提供的云端模型后保存。模型选择器按此顺序显示这份列表;API 密钥本身仍保存在 DSH 凭据中。',
453
+ ollamaFetch: '拉取云端模型',
454
+ ollamaFetching: '拉取中…',
455
+ ollamaKeyPlaceholder: '一次性 API 密钥(可选)',
456
+ ollamaKeyHint: '在此输入的密钥仅用于本次拉取,不会保存。留空则使用已存凭据。',
457
+ ollamaFetchFailed: '拉取云端模型失败:{message}',
458
+ ollamaCandidatesCount: '返回 {count} 个',
459
+ ollamaCandidatesEmpty: '未返回任何云端模型。',
460
+ ollamaModelsEmpty: '尚未配置模型。请拉取云端列表并勾选需要保留的模型。',
461
+ ollamaModelsLoadFailed: 'Ollama 设置加载失败:{message}',
462
+ ollamaModelsSaveFailed: 'Ollama 设置保存失败:{message}',
463
+ ollamaConfigureHint: '未在 {ref} 找到 API 密钥。请在凭据文件(~/.dsh/.credentials.yaml)中添加。',
464
+ ollamaDisplayName: '显示名',
465
+ ollamaRowDetails: '详情',
466
+ ollamaEffortsUnknown: '该模型支持思考,推理档位将由实时发现补充。',
467
+ ollamaMoveUp: '上移',
468
+ ollamaMoveDown: '下移',
469
+ ollamaBaseURL: '基础 URL',
470
+ ollamaApiKeyRef: 'API 密钥引用',
471
+ ollamaConnectionHint: '基础 URL 用于此路由的请求与凭据查询;引用是 DSH 凭据的名称,不是密钥本身。'
472
+ + '请求会把解析出的密钥发往该地址,请只填写可信主机。',
473
+ ollamaWebHint: '启用 Ollama Cloud 的网页搜索与抓取能力。宿主仍需选择它们,网页工具才会使用。',
474
+ ollamaCatalogOverride: '配置档案固定了此路由的模型列表;在移除该覆盖前,选择器会忽略存储中的模型。',
475
+ ollamaResetDefaults: '恢复部署默认值',
476
+ ollamaResetConfirm: '清除全部已保存的 Ollama 覆盖项?将重新使用配置档案值与内置默认值。',
477
+ ollamaCapVision: '视觉',
478
+ ollamaCapThinking: '思考',
479
+ ollamaContext: '上下文 {tokens}',
403
480
  };
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Draft rules of the Ollama Cloud settings dialog, kept free of React and the
3
+ * DOM so they can be unit tested. The node half owns the shapes below; the
4
+ * client restates them locally because the browser bundle does not import
5
+ * node-side modules.
6
+ */
7
+ /** One model entry as stored in the route settings. */
8
+ export interface OllamaModelSetting {
9
+ id: string;
10
+ name?: string;
11
+ contextWindow?: number;
12
+ /** The user's explicit local context window; absent follows the endpoint. */
13
+ contextOverride?: number;
14
+ maxTokens?: number;
15
+ vision?: boolean;
16
+ thinking?: boolean;
17
+ efforts?: string[];
18
+ defaultEffort?: string;
19
+ }
20
+ /** One model row of the editable draft (same fields as the stored entry). */
21
+ export interface OllamaModelDraft {
22
+ id: string;
23
+ name?: string;
24
+ contextWindow?: number;
25
+ /** The user's explicit local context window; absent follows the endpoint. */
26
+ contextOverride?: number;
27
+ maxTokens?: number;
28
+ vision?: boolean;
29
+ thinking?: boolean;
30
+ efforts?: string[];
31
+ defaultEffort?: string;
32
+ }
33
+ /** The editable settings draft; every field is an override of the deployment value. */
34
+ export interface OllamaSettingsDraft {
35
+ models?: OllamaModelDraft[];
36
+ web?: boolean;
37
+ baseURL?: string;
38
+ apiKeyRef?: string;
39
+ }
40
+ /** `ollamaSettings` endpoint value. */
41
+ export interface OllamaSettingsView {
42
+ provider: 'ollama-cloud';
43
+ settings: {
44
+ models?: OllamaModelSetting[];
45
+ web?: boolean;
46
+ baseURL?: string;
47
+ apiKeyRef?: string;
48
+ };
49
+ effective: {
50
+ baseURL: string;
51
+ apiKeyRef: string;
52
+ web: boolean;
53
+ };
54
+ models: {
55
+ id: string;
56
+ name: string;
57
+ vision: boolean;
58
+ thinking: boolean;
59
+ contextWindow?: number;
60
+ /** Advertised reasoning levels and the endpoint default, when the model reasons. */
61
+ efforts?: {
62
+ id: string;
63
+ name: string;
64
+ }[];
65
+ defaultEffort?: string;
66
+ }[];
67
+ configOverridesModels: boolean;
68
+ }
69
+ /** One cloud catalog entry returned by the `ollamaModels` endpoint. */
70
+ export interface OllamaCloudCandidate {
71
+ /** Normalized wire id; this is what the store keeps. */
72
+ id: string;
73
+ /** Listing id before normalization. */
74
+ rawId: string;
75
+ /** Display basename. */
76
+ name: string;
77
+ vision: boolean;
78
+ thinking: boolean;
79
+ contextWindow?: number;
80
+ efforts: string[];
81
+ defaultEffort?: string;
82
+ }
83
+ /**
84
+ * Append the checked candidates to the draft's model list. Existing rows are
85
+ * never replaced or reordered, ids already present are skipped, and adopted
86
+ * rows keep the candidate order. Optional fields are set only when the
87
+ * candidate advertises a value, because `exactOptionalPropertyTypes` (and the
88
+ * store) must not see an explicit `undefined`.
89
+ * @param current - the draft list before adoption.
90
+ * @param candidates - the cloud list as fetched, in display order.
91
+ * @param selectedIds - ids the user checked.
92
+ * @returns a new list; the input array is not mutated.
93
+ */
94
+ export declare function adoptCandidates(current: readonly OllamaModelDraft[] | undefined, candidates: readonly OllamaCloudCandidate[], selectedIds: readonly string[]): OllamaModelDraft[];
95
+ /**
96
+ * Swap one model with its neighbour. An id that is absent or a move past
97
+ * either end returns the same order.
98
+ * @param models - the current list.
99
+ * @param id - the row to move.
100
+ * @param delta - `-1` moves up, `1` moves down.
101
+ * @returns a new list; the input array is not mutated.
102
+ */
103
+ export declare function moveModel(models: readonly OllamaModelDraft[], id: string, delta: -1 | 1): OllamaModelDraft[];
104
+ /**
105
+ * Drop one model from the list.
106
+ * @param models - the current list.
107
+ * @param id - the row to drop; an unknown id leaves the list unchanged.
108
+ * @returns a new list; the input array is not mutated.
109
+ */
110
+ export declare function removeModel(models: readonly OllamaModelDraft[], id: string): OllamaModelDraft[];
111
+ /**
112
+ * Short context-window label for a model row.
113
+ * @param contextWindow - the advertised window in tokens.
114
+ * @returns `'1M'`, `'262K'`, the bare number below 1000, or `undefined` when unknown.
115
+ */
116
+ export declare function contextLabel(contextWindow: number | undefined): string | undefined;
117
+ /**
118
+ * Rename one model row. An empty display name deletes the field so the
119
+ * validator keeps accepting the draft; a blank id leaves the list unchanged.
120
+ * @param models - the current list.
121
+ * @param id - the row to rename; an unknown id leaves the list unchanged.
122
+ * @param name - the new display name; whitespace trims before storing.
123
+ * @returns a new list; the input array is not mutated.
124
+ */
125
+ export declare function renameModel(models: readonly OllamaModelDraft[], id: string, name: string): OllamaModelDraft[];
126
+ /**
127
+ * Set or clear one model row's default reasoning effort. An empty choice
128
+ * deletes the field so the resolver falls back to the vendor or family
129
+ * default.
130
+ * @param models - the current list.
131
+ * @param id - the row to edit; an unknown id leaves the list unchanged.
132
+ * @param effort - the chosen level, or `''` to clear.
133
+ * @returns a new list; the input array is not mutated.
134
+ */
135
+ export declare function setModelEffort(models: readonly OllamaModelDraft[], id: string, effort: string): OllamaModelDraft[];
136
+ /**
137
+ * Set or clear one model row's local context-window override. `undefined`
138
+ * deletes the field so the model follows the endpoint again; the runtime
139
+ * caps a stored value at the advertised window.
140
+ * @param models - the current list.
141
+ * @param id - the row to edit; an unknown id leaves the list unchanged.
142
+ * @param tokens - a positive safe integer, or `undefined` to clear.
143
+ * @returns a new list; the input array is not mutated.
144
+ */
145
+ export declare function setModelContext(models: readonly OllamaModelDraft[], id: string, tokens: number | undefined): OllamaModelDraft[];
146
+ /**
147
+ * Parse the context input's text. Only a positive safe integer is a value;
148
+ * an empty string clears the override.
149
+ * @param text - what the user typed.
150
+ * @returns the number, `undefined` for blank, or `null` for text to reject.
151
+ */
152
+ export declare function parseContextInput(text: string): number | undefined | null;
153
+ /** Models the user unticked in this dialog, kept by id so a re-tick restores them. */
154
+ export type OllamaStash = ReadonlyMap<string, OllamaModelDraft>;
155
+ /**
156
+ * Untick one model: drop it from the list and keep its full row (display
157
+ * name, default effort, context, ...) in the stash so ticking it again is
158
+ * lossless, even when the cloud listing no longer carries the id.
159
+ * @param models - the current list.
160
+ * @param stash - the stash before this untick.
161
+ * @param id - the row to untick; an absent id changes nothing.
162
+ * @returns the new list and stash; neither input is mutated.
163
+ */
164
+ export declare function untickModel(models: readonly OllamaModelDraft[], stash: OllamaStash, id: string): {
165
+ models: OllamaModelDraft[];
166
+ stash: OllamaStash;
167
+ };
168
+ /**
169
+ * Tick one model: restore its stashed row when this dialog unticked it,
170
+ * otherwise adopt it from the fetched candidates (which never copies the
171
+ * vendor default effort). A model already in the list, or unknown to both
172
+ * sources, leaves the list unchanged.
173
+ * @param models - the current list.
174
+ * @param stash - rows unticked earlier in this dialog.
175
+ * @param candidates - the cloud list as fetched.
176
+ * @param id - the row to tick.
177
+ * @returns a new list and the stash without the restored row.
178
+ */
179
+ export declare function tickModel(models: readonly OllamaModelDraft[], stash: OllamaStash, candidates: readonly OllamaCloudCandidate[], id: string): {
180
+ models: OllamaModelDraft[];
181
+ stash: OllamaStash;
182
+ };
183
+ /**
184
+ * Tick every listed id in order. Rows already in the list stay where they
185
+ * are; restored and adopted rows append in the given order.
186
+ * @param models - the current list.
187
+ * @param stash - rows unticked earlier in this dialog.
188
+ * @param candidates - the cloud list as fetched.
189
+ * @param ids - the ids to tick, typically the filtered view.
190
+ * @returns the new list and stash; neither input is mutated.
191
+ */
192
+ export declare function tickModels(models: readonly OllamaModelDraft[], stash: OllamaStash, candidates: readonly OllamaCloudCandidate[], ids: readonly string[]): {
193
+ models: OllamaModelDraft[];
194
+ stash: OllamaStash;
195
+ };
196
+ /**
197
+ * Untick every listed id, stashing each removed row. Ids outside the list,
198
+ * such as filtered-out rows, are untouched.
199
+ * @param models - the current list.
200
+ * @param stash - the stash before this untick.
201
+ * @param ids - the ids to untick, typically the filtered view.
202
+ * @returns the new list and stash; neither input is mutated.
203
+ */
204
+ export declare function untickModels(models: readonly OllamaModelDraft[], stash: OllamaStash, ids: readonly string[]): {
205
+ models: OllamaModelDraft[];
206
+ stash: OllamaStash;
207
+ };
208
+ /** One effort choice shown in a row's selector. */
209
+ export interface EffortOption {
210
+ id: string;
211
+ name: string;
212
+ unavailable?: boolean;
213
+ }
214
+ /**
215
+ * The effort choices for one ticked row. The row's own `efforts` decide the
216
+ * ids because the store rejects a default outside them, so the selector must
217
+ * never offer anything else. A snapshot of the endpoint (`labels`) may only
218
+ * supply friendlier names for the same ids. A saved default the list no
219
+ * longer contains is kept visible and marked unavailable instead of
220
+ * silently reading as "follow the provider".
221
+ * @param row - the draft row.
222
+ * @param fetched - efforts from this dialog's latest fetch, when it returned the row.
223
+ * @param labels - the opened dialog's snapshot of named efforts for the id.
224
+ * @returns the options in picker order.
225
+ */
226
+ export declare function effortOptions(row: OllamaModelDraft, fetched: readonly string[] | undefined, labels: readonly {
227
+ id: string;
228
+ name: string;
229
+ }[] | undefined): EffortOption[];
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Draft rules of the Ollama Cloud settings dialog, kept free of React and the
3
+ * DOM so they can be unit tested. The node half owns the shapes below; the
4
+ * client restates them locally because the browser bundle does not import
5
+ * node-side modules.
6
+ */
7
+ /**
8
+ * Append the checked candidates to the draft's model list. Existing rows are
9
+ * never replaced or reordered, ids already present are skipped, and adopted
10
+ * rows keep the candidate order. Optional fields are set only when the
11
+ * candidate advertises a value, because `exactOptionalPropertyTypes` (and the
12
+ * store) must not see an explicit `undefined`.
13
+ * @param current - the draft list before adoption.
14
+ * @param candidates - the cloud list as fetched, in display order.
15
+ * @param selectedIds - ids the user checked.
16
+ * @returns a new list; the input array is not mutated.
17
+ */
18
+ export function adoptCandidates(current, candidates, selectedIds) {
19
+ const models = [...(current ?? [])];
20
+ const present = new Set(models.map(model => model.id));
21
+ const selected = new Set(selectedIds);
22
+ for (const candidate of candidates) {
23
+ if (!selected.has(candidate.id) || present.has(candidate.id))
24
+ continue;
25
+ present.add(candidate.id);
26
+ models.push({
27
+ id: candidate.id,
28
+ name: candidate.name,
29
+ ...(candidate.contextWindow === undefined ? {} : { contextWindow: candidate.contextWindow }),
30
+ ...(candidate.vision ? { vision: true } : {}),
31
+ ...(candidate.thinking ? { thinking: true } : {}),
32
+ // The vendor's default is not copied: defaultEffort in the store is
33
+ // the user's explicit choice only, so the resolver's priority
34
+ // (user, then vendor, then family) keeps the vendor default live
35
+ // in discovery while the selector stays an override.
36
+ ...(candidate.efforts.length ? { efforts: [...candidate.efforts] } : {}),
37
+ });
38
+ }
39
+ return models;
40
+ }
41
+ /**
42
+ * Swap one model with its neighbour. An id that is absent or a move past
43
+ * either end returns the same order.
44
+ * @param models - the current list.
45
+ * @param id - the row to move.
46
+ * @param delta - `-1` moves up, `1` moves down.
47
+ * @returns a new list; the input array is not mutated.
48
+ */
49
+ export function moveModel(models, id, delta) {
50
+ const next = [...models];
51
+ const index = next.findIndex(model => model.id === id);
52
+ const target = index + delta;
53
+ if (index === -1 || target < 0 || target >= next.length)
54
+ return next;
55
+ const moved = next[index];
56
+ next[index] = next[target];
57
+ next[target] = moved;
58
+ return next;
59
+ }
60
+ /**
61
+ * Drop one model from the list.
62
+ * @param models - the current list.
63
+ * @param id - the row to drop; an unknown id leaves the list unchanged.
64
+ * @returns a new list; the input array is not mutated.
65
+ */
66
+ export function removeModel(models, id) {
67
+ return models.filter(model => model.id !== id);
68
+ }
69
+ /**
70
+ * Short context-window label for a model row.
71
+ * @param contextWindow - the advertised window in tokens.
72
+ * @returns `'1M'`, `'262K'`, the bare number below 1000, or `undefined` when unknown.
73
+ */
74
+ export function contextLabel(contextWindow) {
75
+ if (contextWindow === undefined)
76
+ return undefined;
77
+ if (contextWindow < 1000)
78
+ return String(contextWindow);
79
+ if (contextWindow >= 1_000_000) {
80
+ const millions = contextWindow / 1_000_000;
81
+ return `${Number.isInteger(millions) ? millions : Number(millions.toFixed(1))}M`;
82
+ }
83
+ return `${Math.round(contextWindow / 1000)}K`;
84
+ }
85
+ /**
86
+ * Rename one model row. An empty display name deletes the field so the
87
+ * validator keeps accepting the draft; a blank id leaves the list unchanged.
88
+ * @param models - the current list.
89
+ * @param id - the row to rename; an unknown id leaves the list unchanged.
90
+ * @param name - the new display name; whitespace trims before storing.
91
+ * @returns a new list; the input array is not mutated.
92
+ */
93
+ export function renameModel(models, id, name) {
94
+ return models.map(model => {
95
+ if (model.id !== id)
96
+ return model;
97
+ const next = { ...model };
98
+ if (name === '')
99
+ delete next.name;
100
+ else
101
+ next.name = name;
102
+ return next;
103
+ });
104
+ }
105
+ /**
106
+ * Set or clear one model row's default reasoning effort. An empty choice
107
+ * deletes the field so the resolver falls back to the vendor or family
108
+ * default.
109
+ * @param models - the current list.
110
+ * @param id - the row to edit; an unknown id leaves the list unchanged.
111
+ * @param effort - the chosen level, or `''` to clear.
112
+ * @returns a new list; the input array is not mutated.
113
+ */
114
+ export function setModelEffort(models, id, effort) {
115
+ return models.map(model => {
116
+ if (model.id !== id)
117
+ return model;
118
+ if (effort === '') {
119
+ const next = { ...model };
120
+ delete next.defaultEffort;
121
+ return next;
122
+ }
123
+ return { ...model, defaultEffort: effort };
124
+ });
125
+ }
126
+ /**
127
+ * Set or clear one model row's local context-window override. `undefined`
128
+ * deletes the field so the model follows the endpoint again; the runtime
129
+ * caps a stored value at the advertised window.
130
+ * @param models - the current list.
131
+ * @param id - the row to edit; an unknown id leaves the list unchanged.
132
+ * @param tokens - a positive safe integer, or `undefined` to clear.
133
+ * @returns a new list; the input array is not mutated.
134
+ */
135
+ export function setModelContext(models, id, tokens) {
136
+ return models.map(model => {
137
+ if (model.id !== id)
138
+ return model;
139
+ const next = { ...model };
140
+ if (tokens === undefined)
141
+ delete next.contextOverride;
142
+ else
143
+ next.contextOverride = tokens;
144
+ return next;
145
+ });
146
+ }
147
+ /**
148
+ * Parse the context input's text. Only a positive safe integer is a value;
149
+ * an empty string clears the override.
150
+ * @param text - what the user typed.
151
+ * @returns the number, `undefined` for blank, or `null` for text to reject.
152
+ */
153
+ export function parseContextInput(text) {
154
+ const trimmed = text.trim();
155
+ if (trimmed === '')
156
+ return undefined;
157
+ if (!/^\d+$/.test(trimmed))
158
+ return null;
159
+ const value = Number(trimmed);
160
+ return Number.isSafeInteger(value) && value > 0 ? value : null;
161
+ }
162
+ /**
163
+ * Untick one model: drop it from the list and keep its full row (display
164
+ * name, default effort, context, ...) in the stash so ticking it again is
165
+ * lossless, even when the cloud listing no longer carries the id.
166
+ * @param models - the current list.
167
+ * @param stash - the stash before this untick.
168
+ * @param id - the row to untick; an absent id changes nothing.
169
+ * @returns the new list and stash; neither input is mutated.
170
+ */
171
+ export function untickModel(models, stash, id) {
172
+ const row = models.find(model => model.id === id);
173
+ if (row === undefined)
174
+ return { models: [...models], stash };
175
+ return { models: removeModel(models, id), stash: new Map(stash).set(id, row) };
176
+ }
177
+ /**
178
+ * Tick one model: restore its stashed row when this dialog unticked it,
179
+ * otherwise adopt it from the fetched candidates (which never copies the
180
+ * vendor default effort). A model already in the list, or unknown to both
181
+ * sources, leaves the list unchanged.
182
+ * @param models - the current list.
183
+ * @param stash - rows unticked earlier in this dialog.
184
+ * @param candidates - the cloud list as fetched.
185
+ * @param id - the row to tick.
186
+ * @returns a new list and the stash without the restored row.
187
+ */
188
+ export function tickModel(models, stash, candidates, id) {
189
+ if (models.some(model => model.id === id))
190
+ return { models: [...models], stash };
191
+ const stashed = stash.get(id);
192
+ if (stashed === undefined)
193
+ return { models: adoptCandidates(models, candidates, [id]), stash };
194
+ const next = new Map(stash);
195
+ next.delete(id);
196
+ return { models: [...models, stashed], stash: next };
197
+ }
198
+ /**
199
+ * Tick every listed id in order. Rows already in the list stay where they
200
+ * are; restored and adopted rows append in the given order.
201
+ * @param models - the current list.
202
+ * @param stash - rows unticked earlier in this dialog.
203
+ * @param candidates - the cloud list as fetched.
204
+ * @param ids - the ids to tick, typically the filtered view.
205
+ * @returns the new list and stash; neither input is mutated.
206
+ */
207
+ export function tickModels(models, stash, candidates, ids) {
208
+ let state = { models: [...models], stash };
209
+ for (const id of ids)
210
+ state = tickModel(state.models, state.stash, candidates, id);
211
+ return state;
212
+ }
213
+ /**
214
+ * Untick every listed id, stashing each removed row. Ids outside the list,
215
+ * such as filtered-out rows, are untouched.
216
+ * @param models - the current list.
217
+ * @param stash - the stash before this untick.
218
+ * @param ids - the ids to untick, typically the filtered view.
219
+ * @returns the new list and stash; neither input is mutated.
220
+ */
221
+ export function untickModels(models, stash, ids) {
222
+ let state = { models: [...models], stash };
223
+ for (const id of ids)
224
+ state = untickModel(state.models, state.stash, id);
225
+ return state;
226
+ }
227
+ /**
228
+ * The effort choices for one ticked row. The row's own `efforts` decide the
229
+ * ids because the store rejects a default outside them, so the selector must
230
+ * never offer anything else. A snapshot of the endpoint (`labels`) may only
231
+ * supply friendlier names for the same ids. A saved default the list no
232
+ * longer contains is kept visible and marked unavailable instead of
233
+ * silently reading as "follow the provider".
234
+ * @param row - the draft row.
235
+ * @param fetched - efforts from this dialog's latest fetch, when it returned the row.
236
+ * @param labels - the opened dialog's snapshot of named efforts for the id.
237
+ * @returns the options in picker order.
238
+ */
239
+ export function effortOptions(row, fetched, labels) {
240
+ const ids = row.efforts ?? fetched ?? labels?.map(entry => entry.id) ?? [];
241
+ const options = ids.map(id => ({ id, name: labels?.find(entry => entry.id === id)?.name ?? id }));
242
+ if (row.defaultEffort !== undefined && !ids.includes(row.defaultEffort)) {
243
+ options.push({ id: row.defaultEffort, name: row.defaultEffort, unavailable: true });
244
+ }
245
+ return options;
246
+ }
@@ -40,3 +40,10 @@ export declare function isUsageFresh(window: UsageWindow, observation: UsageObse
40
40
  export declare function elapsedPercent(window: UsageWindow, now?: number): number | undefined;
41
41
  export declare function usageColorState(used: number, elapsed: number | undefined, preset: UsageColorPreset, fresh: boolean): UsageColorState;
42
42
  export declare function usageBarColor(used: number, elapsed?: number, preset?: UsageColorPreset, fresh?: boolean): string;
43
+ /**
44
+ * Marker position from the window's display-only assumed start
45
+ * (`displayStartsAt`): the reading and its age are irrelevant, exactly
46
+ * like the verified marker. Returns undefined when the window carries no
47
+ * assumed start or its reset has passed.
48
+ */
49
+ export declare function displayStartPercent(window: UsageWindow, now?: number): number | undefined;