@molecule/app-ide-panel-logic 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +2925 -2
- package/dist/chatTimelineOrdering.d.ts +50 -0
- package/dist/chatTimelineOrdering.d.ts.map +1 -0
- package/dist/chatTimelineOrdering.js +46 -0
- package/dist/chatTimelineOrdering.js.map +1 -0
- package/dist/command-metadata.d.ts +117 -0
- package/dist/command-metadata.d.ts.map +1 -0
- package/dist/command-metadata.js +271 -0
- package/dist/command-metadata.js.map +1 -0
- package/dist/components/activity-utilities.d.ts +107 -0
- package/dist/components/activity-utilities.d.ts.map +1 -0
- package/dist/components/activity-utilities.js +154 -0
- package/dist/components/activity-utilities.js.map +1 -0
- package/dist/components/chat-autocommit-utilities.d.ts +172 -0
- package/dist/components/chat-autocommit-utilities.d.ts.map +1 -0
- package/dist/components/chat-autocommit-utilities.js +185 -0
- package/dist/components/chat-autocommit-utilities.js.map +1 -0
- package/dist/components/chat-card-style.d.ts +81 -0
- package/dist/components/chat-card-style.d.ts.map +1 -0
- package/dist/components/chat-card-style.js +78 -0
- package/dist/components/chat-card-style.js.map +1 -0
- package/dist/components/chat-commands.d.ts +17 -0
- package/dist/components/chat-commands.d.ts.map +1 -0
- package/dist/components/chat-commands.js +17 -0
- package/dist/components/chat-commands.js.map +1 -0
- package/dist/components/chat-commit-utilities.d.ts +29 -0
- package/dist/components/chat-commit-utilities.d.ts.map +1 -0
- package/dist/components/chat-commit-utilities.js +31 -0
- package/dist/components/chat-commit-utilities.js.map +1 -0
- package/dist/components/chat-cost-utilities.d.ts +62 -0
- package/dist/components/chat-cost-utilities.d.ts.map +1 -0
- package/dist/components/chat-cost-utilities.js +66 -0
- package/dist/components/chat-cost-utilities.js.map +1 -0
- package/dist/components/chat-effort-utilities.d.ts +104 -0
- package/dist/components/chat-effort-utilities.d.ts.map +1 -0
- package/dist/components/chat-effort-utilities.js +99 -0
- package/dist/components/chat-effort-utilities.js.map +1 -0
- package/dist/components/chat-help-utilities.d.ts +89 -0
- package/dist/components/chat-help-utilities.d.ts.map +1 -0
- package/dist/components/chat-help-utilities.js +131 -0
- package/dist/components/chat-help-utilities.js.map +1 -0
- package/dist/components/chat-model-mode-utilities.d.ts +169 -0
- package/dist/components/chat-model-mode-utilities.d.ts.map +1 -0
- package/dist/components/chat-model-mode-utilities.js +221 -0
- package/dist/components/chat-model-mode-utilities.js.map +1 -0
- package/dist/components/chat-models-utilities.d.ts +162 -0
- package/dist/components/chat-models-utilities.d.ts.map +1 -0
- package/dist/components/chat-models-utilities.js +302 -0
- package/dist/components/chat-models-utilities.js.map +1 -0
- package/dist/components/chat-report-utilities.d.ts +149 -0
- package/dist/components/chat-report-utilities.d.ts.map +1 -0
- package/dist/components/chat-report-utilities.js +151 -0
- package/dist/components/chat-report-utilities.js.map +1 -0
- package/dist/components/chat-scripts-utilities.d.ts +185 -0
- package/dist/components/chat-scripts-utilities.d.ts.map +1 -0
- package/dist/components/chat-scripts-utilities.js +199 -0
- package/dist/components/chat-scripts-utilities.js.map +1 -0
- package/dist/components/chat-settings-utilities.d.ts +72 -0
- package/dist/components/chat-settings-utilities.d.ts.map +1 -0
- package/dist/components/chat-settings-utilities.js +56 -0
- package/dist/components/chat-settings-utilities.js.map +1 -0
- package/dist/components/chat-share-utilities.d.ts +110 -0
- package/dist/components/chat-share-utilities.d.ts.map +1 -0
- package/dist/components/chat-share-utilities.js +90 -0
- package/dist/components/chat-share-utilities.js.map +1 -0
- package/dist/components/chat-skills-utilities.d.ts +242 -0
- package/dist/components/chat-skills-utilities.d.ts.map +1 -0
- package/dist/components/chat-skills-utilities.js +433 -0
- package/dist/components/chat-skills-utilities.js.map +1 -0
- package/dist/components/chat-stream-utilities.d.ts +74 -0
- package/dist/components/chat-stream-utilities.d.ts.map +1 -0
- package/dist/components/chat-stream-utilities.js +103 -0
- package/dist/components/chat-stream-utilities.js.map +1 -0
- package/dist/components/chat-timestamps-utilities.d.ts +123 -0
- package/dist/components/chat-timestamps-utilities.d.ts.map +1 -0
- package/dist/components/chat-timestamps-utilities.js +177 -0
- package/dist/components/chat-timestamps-utilities.js.map +1 -0
- package/dist/components/chat-tips-utilities.d.ts +108 -0
- package/dist/components/chat-tips-utilities.d.ts.map +1 -0
- package/dist/components/chat-tips-utilities.js +137 -0
- package/dist/components/chat-tips-utilities.js.map +1 -0
- package/dist/components/device-cycle.d.ts +84 -0
- package/dist/components/device-cycle.d.ts.map +1 -0
- package/dist/components/device-cycle.js +77 -0
- package/dist/components/device-cycle.js.map +1 -0
- package/dist/components/fileExplorerPersistence.d.ts +50 -0
- package/dist/components/fileExplorerPersistence.d.ts.map +1 -0
- package/dist/components/fileExplorerPersistence.js +63 -0
- package/dist/components/fileExplorerPersistence.js.map +1 -0
- package/dist/components/search-utilities.d.ts +15 -0
- package/dist/components/search-utilities.d.ts.map +1 -0
- package/dist/components/search-utilities.js +26 -0
- package/dist/components/search-utilities.js.map +1 -0
- package/dist/components/tests-bar-utilities.d.ts +106 -0
- package/dist/components/tests-bar-utilities.d.ts.map +1 -0
- package/dist/components/tests-bar-utilities.js +167 -0
- package/dist/components/tests-bar-utilities.js.map +1 -0
- package/dist/components/tests-card-utilities.d.ts +280 -0
- package/dist/components/tests-card-utilities.d.ts.map +1 -0
- package/dist/components/tests-card-utilities.js +591 -0
- package/dist/components/tests-card-utilities.js.map +1 -0
- package/dist/components/tool-call-utilities.d.ts +256 -0
- package/dist/components/tool-call-utilities.d.ts.map +1 -0
- package/dist/components/tool-call-utilities.js +1004 -0
- package/dist/components/tool-call-utilities.js.map +1 -0
- package/dist/components/user-avatar-utilities.d.ts +41 -0
- package/dist/components/user-avatar-utilities.d.ts.map +1 -0
- package/dist/components/user-avatar-utilities.js +56 -0
- package/dist/components/user-avatar-utilities.js.map +1 -0
- package/dist/components/workspace-layout-utilities.d.ts +37 -0
- package/dist/components/workspace-layout-utilities.d.ts.map +1 -0
- package/dist/components/workspace-layout-utilities.js +58 -0
- package/dist/components/workspace-layout-utilities.js.map +1 -0
- package/dist/customEventCards.d.ts +147 -0
- package/dist/customEventCards.d.ts.map +1 -0
- package/dist/customEventCards.js +36 -0
- package/dist/customEventCards.js.map +1 -0
- package/dist/icon-names.d.ts +26 -0
- package/dist/icon-names.d.ts.map +1 -0
- package/dist/icon-names.js +14 -0
- package/dist/icon-names.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard-shortcut-utilities.d.ts +63 -0
- package/dist/keyboard-shortcut-utilities.d.ts.map +1 -0
- package/dist/keyboard-shortcut-utilities.js +100 -0
- package/dist/keyboard-shortcut-utilities.js.map +1 -0
- package/dist/panels.d.ts +26 -0
- package/dist/panels.d.ts.map +1 -0
- package/dist/panels.js +26 -0
- package/dist/panels.js.map +1 -0
- package/dist/settings-metadata.d.ts +78 -0
- package/dist/settings-metadata.d.ts.map +1 -0
- package/dist/settings-metadata.js +137 -0
- package/dist/settings-metadata.js.map +1 -0
- package/dist/types.d.ts +588 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/viewport-queries.d.ts +19 -0
- package/dist/viewport-queries.d.ts.map +1 -0
- package/dist/viewport-queries.js +19 -0
- package/dist/viewport-queries.js.map +1 -0
- package/package.json +74 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/help` content model + plain-text generation.
|
|
3
|
+
*
|
|
4
|
+
* The help content is a concise high-level guide built from the structured
|
|
5
|
+
* {@link HELP_MODES} / {@link HELP_TIPS} constants below — never a
|
|
6
|
+
* hand-maintained string — so the rich {@link module:./HelpCard | HelpCard} and
|
|
7
|
+
* this plain-text fallback can never drift (both read the SAME constants). It
|
|
8
|
+
* explains the three conversation modes (discovery / plan / execute) and lists
|
|
9
|
+
* efficiency tips. It deliberately does NOT relist the slash commands — typing
|
|
10
|
+
* `/` opens the command menu, which does that better.
|
|
11
|
+
*
|
|
12
|
+
* `buildHelpText` is the i18n plain-text fallback (used as the system card's
|
|
13
|
+
* copy/screen-reader text and in any non-React consumer); `HelpCard` renders the
|
|
14
|
+
* same model as a card matching the `/settings` / `/skills` cards.
|
|
15
|
+
*
|
|
16
|
+
* All prose is i18n-ready via `t(key, values, { defaultValue })`.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { DEFAULT_AGENT_IDENTITY } from '@molecule/app-ai-chat';
|
|
21
|
+
import { t } from '@molecule/app-i18n';
|
|
22
|
+
/**
|
|
23
|
+
* The `/help` intro paragraph (i18n key + English default). Shared by the
|
|
24
|
+
* plain-text {@link buildHelpText} fallback and the rich `HelpCard`. May
|
|
25
|
+
* interpolate the `{{agentName}}` / `{{productName}}` tokens.
|
|
26
|
+
*/
|
|
27
|
+
export const HELP_INTRO = {
|
|
28
|
+
/** i18n key for the intro paragraph. */
|
|
29
|
+
key: 'ide.chat.help.intro',
|
|
30
|
+
/** English default for {@link HELP_INTRO.key}. */
|
|
31
|
+
defaultValue: "{{agentName}} is {{productName}}'s AI coding agent. Describe what you want to build and it will scaffold, code, and iterate with you.",
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The three conversation modes, in the order shown in `/help`. The single
|
|
35
|
+
* source of truth for both the plain-text fallback and the `HelpCard`.
|
|
36
|
+
*/
|
|
37
|
+
export const HELP_MODES = [
|
|
38
|
+
{
|
|
39
|
+
id: 'discovery',
|
|
40
|
+
icon: 'question',
|
|
41
|
+
key: 'ide.chat.help.modeDiscovery',
|
|
42
|
+
defaultValue: 'Discovery — new conversations start here. {{agentName}} asks clarifying questions to nail down requirements before writing any code.',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'plan',
|
|
46
|
+
icon: 'search',
|
|
47
|
+
key: 'ide.chat.help.modePlan',
|
|
48
|
+
defaultValue: 'Plan — {{agentName}} researches the codebase and proposes a plan WITHOUT editing files. Toggle with /plan. Best for big or risky changes.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'execute',
|
|
52
|
+
icon: 'pencil',
|
|
53
|
+
key: 'ide.chat.help.modeExecute',
|
|
54
|
+
defaultValue: 'Execute — the default working mode. {{agentName}} writes code, runs tools, and applies changes, then verifies them.',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
/** The efficiency tips, in the order shown in `/help`. */
|
|
58
|
+
export const HELP_TIPS = [
|
|
59
|
+
{
|
|
60
|
+
id: 'mention',
|
|
61
|
+
key: 'ide.chat.help.tipMention',
|
|
62
|
+
defaultValue: '• Type @filename to attach a project file as context (or drag & drop any file).',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'slash',
|
|
66
|
+
key: 'ide.chat.help.tipSlash',
|
|
67
|
+
defaultValue: '• Type / to browse every command.',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'plan',
|
|
71
|
+
key: 'ide.chat.help.tipPlan',
|
|
72
|
+
defaultValue: '• Use /plan to have {{agentName}} research before making changes.',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'undo',
|
|
76
|
+
key: 'ide.chat.help.tipUndo',
|
|
77
|
+
defaultValue: "• Use /undo to revert the last AI turn's file changes if it goes off track.",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'compact',
|
|
81
|
+
key: 'ide.chat.help.tipCompact',
|
|
82
|
+
defaultValue: '• Use /compact to compress context when the conversation gets long.',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'specific',
|
|
86
|
+
key: 'ide.chat.help.tipSpecific',
|
|
87
|
+
defaultValue: '• Be specific — "Add a login page with email/password and Google OAuth" beats "add auth".',
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
/** The keyboard-shortcuts footer line shown at the end of `/help`. */
|
|
91
|
+
export const HELP_SHORTCUTS = {
|
|
92
|
+
/** i18n key for the shortcuts footer. */
|
|
93
|
+
key: 'ide.chat.help.shortcuts',
|
|
94
|
+
/** English default for {@link HELP_SHORTCUTS.key}. */
|
|
95
|
+
defaultValue: 'Press Cmd+/ (Ctrl+/ on Windows/Linux) to view all keyboard shortcuts.',
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Builds the `/help` body — a concise high-level guide covering the conversation
|
|
99
|
+
* modes and efficiency tips. It deliberately does NOT relist the slash commands;
|
|
100
|
+
* typing `/` opens the command menu, which does that better. Generated from the
|
|
101
|
+
* shared {@link HELP_MODES} / {@link HELP_TIPS} constants so it stays in sync
|
|
102
|
+
* automatically — and never drifts from the rich `HelpCard`, which renders the
|
|
103
|
+
* same model.
|
|
104
|
+
*
|
|
105
|
+
* @param identity - Agent/product display identity used to interpolate the
|
|
106
|
+
* `{{agentName}}` / `{{productName}}` tokens in the help copy (defaults to the
|
|
107
|
+
* neutral {@link DEFAULT_AGENT_IDENTITY} so the shared package never hardcodes
|
|
108
|
+
* a product name).
|
|
109
|
+
* @returns The fully-formatted, newline-delimited help text.
|
|
110
|
+
*/
|
|
111
|
+
export function buildHelpText(identity = DEFAULT_AGENT_IDENTITY) {
|
|
112
|
+
const { agentName, productName } = identity;
|
|
113
|
+
const values = { agentName, productName };
|
|
114
|
+
const lines = [];
|
|
115
|
+
// ── Getting started ──
|
|
116
|
+
lines.push(t('ide.chat.help.introHeading', undefined, { defaultValue: '── Getting Started ──' }), t(HELP_INTRO.key, values, { defaultValue: HELP_INTRO.defaultValue }), '');
|
|
117
|
+
// ── Modes ──
|
|
118
|
+
lines.push(t('ide.chat.help.modesHeading', undefined, { defaultValue: '── Modes ──' }));
|
|
119
|
+
for (const helpMode of HELP_MODES) {
|
|
120
|
+
lines.push(t(helpMode.key, values, { defaultValue: helpMode.defaultValue }));
|
|
121
|
+
}
|
|
122
|
+
lines.push('');
|
|
123
|
+
// ── Efficiency tips ──
|
|
124
|
+
lines.push(t('ide.chat.help.tipsHeading', undefined, { defaultValue: '── Tips ──' }));
|
|
125
|
+
for (const tip of HELP_TIPS) {
|
|
126
|
+
lines.push(t(tip.key, values, { defaultValue: tip.defaultValue }));
|
|
127
|
+
}
|
|
128
|
+
lines.push('', t(HELP_SHORTCUTS.key, undefined, { defaultValue: HELP_SHORTCUTS.defaultValue }));
|
|
129
|
+
return lines.join('\n');
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=chat-help-utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-help-utilities.js","sourceRoot":"","sources":["../../src/components/chat-help-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAsB,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAClF,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,wCAAwC;IACxC,GAAG,EAAE,qBAAqB;IAC1B,kDAAkD;IAClD,YAAY,EACV,uIAAuI;CACjI,CAAA;AAiBV;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAwB;IAC7C;QACE,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,6BAA6B;QAClC,YAAY,EACV,sIAAsI;KACzI;IACD;QACE,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,wBAAwB;QAC7B,YAAY,EACV,2IAA2I;KAC9I;IACD;QACE,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,2BAA2B;QAChC,YAAY,EACV,qHAAqH;KACxH;CACO,CAAA;AAgBV,0DAA0D;AAC1D,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC3C;QACE,EAAE,EAAE,SAAS;QACb,GAAG,EAAE,0BAA0B;QAC/B,YAAY,EAAE,iFAAiF;K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UAAU,EAAE,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;IAC9E,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,wBAAwB;IACxB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,2BAA2B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,CAAC,CAAA;IACrF,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;IAE/F,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers backing the per-mode model pickers (`/model --plan`,
|
|
3
|
+
* `/model --execute`, `/model --commit`, and `/model --compact`).
|
|
4
|
+
*
|
|
5
|
+
* A project stores optional per-mode model ids in its settings — `planModel`
|
|
6
|
+
* (used in plan mode) and `executeModel` (used in execute mode) alongside the
|
|
7
|
+
* legacy single `chatModel`, plus two auxiliary jobs: `commitModel` (the
|
|
8
|
+
* commit-message generator) and `compactModel` (conversation compaction), which
|
|
9
|
+
* fall back to the server's own fast default (never `chatModel`) when unset.
|
|
10
|
+
* These helpers parse the mode flag, map a mode to its settings field, resolve
|
|
11
|
+
* the effective model for a mode, and compute the free-tier clamp.
|
|
12
|
+
*
|
|
13
|
+
* The clamp is entirely SERVER-DRIVEN — no model id is ever named here. A
|
|
14
|
+
* free/anon user may use, in any mode, a model the catalog flags `freeTier`,
|
|
15
|
+
* plus the server-sent per-mode default for that mode (`GET /ai/models`
|
|
16
|
+
* `defaults`, which the server resolves from its own free-tier policy). Two
|
|
17
|
+
* earlier generations of this file hardcoded the clamp ids (first a Sonnet
|
|
18
|
+
* planner, then `deepseek-v4-pro`); each went stale the moment the server's
|
|
19
|
+
* policy moved and the picker advertised a model the server would not use.
|
|
20
|
+
*
|
|
21
|
+
* Everything here is deterministic and side-effect free so it can be unit tested
|
|
22
|
+
* without rendering or a backend. The component owns persistence (`PATCH
|
|
23
|
+
* /projects/:id { settings }`) and any `t()` prose.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import type { AppModelDefinition, AppModeModelDefaults } from '@molecule/app-ai-models';
|
|
28
|
+
/** A conversation mode or auxiliary job that can have its own model. */
|
|
29
|
+
export type ModelMode = 'plan' | 'execute' | 'commit' | 'compact';
|
|
30
|
+
/**
|
|
31
|
+
* The server-sent per-mode defaults (`GET /ai/models` `defaults`) — the
|
|
32
|
+
* server's own resolution of what each mode uses for this requester's tier.
|
|
33
|
+
* Partial/absent while the catalog is loading or on servers that don't send it.
|
|
34
|
+
*/
|
|
35
|
+
export type ServerModeDefaults = Partial<AppModeModelDefaults> | undefined;
|
|
36
|
+
/** The subset of project settings this module reads for model resolution. */
|
|
37
|
+
export interface PerModeModelSettings {
|
|
38
|
+
/** Model id used in plan mode (falls back to {@link PerModeModelSettings.chatModel}). */
|
|
39
|
+
planModel?: string;
|
|
40
|
+
/** Model id used in execute mode (falls back to {@link PerModeModelSettings.chatModel}). */
|
|
41
|
+
executeModel?: string;
|
|
42
|
+
/** Model id for commit-message generation (server's fast default when unset). */
|
|
43
|
+
commitModel?: string;
|
|
44
|
+
/** Model id for conversation compaction (server's fast default when unset). */
|
|
45
|
+
compactModel?: string;
|
|
46
|
+
/** Legacy single model id, used when the plan/execute field is unset. */
|
|
47
|
+
chatModel?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parses a `/model --plan`, `--execute`, `--commit`, or `--compact` command.
|
|
51
|
+
* Returns the targeted mode plus any trailing filter `query` (the text after
|
|
52
|
+
* the flag), or `null` when the input is not a mode-scoped `/model` command.
|
|
53
|
+
* Use this *before* the generic `/model <name>` handler so the flag is not
|
|
54
|
+
* mistaken for a model name.
|
|
55
|
+
*
|
|
56
|
+
* @param input - The raw chat input.
|
|
57
|
+
* @returns `{ mode, query }` for a mode-scoped command, else `null`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseModelModeCommand(input: string): {
|
|
60
|
+
mode: ModelMode;
|
|
61
|
+
query: string;
|
|
62
|
+
} | null;
|
|
63
|
+
/**
|
|
64
|
+
* Maps a mode to the project-settings field that stores its model id.
|
|
65
|
+
*
|
|
66
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
67
|
+
* @returns The settings field for the mode (e.g. `'planModel'` for plan mode).
|
|
68
|
+
*/
|
|
69
|
+
export declare function modeSettingKey(mode: ModelMode): 'planModel' | 'executeModel' | 'commitModel' | 'compactModel';
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the effective model id for a mode. The conversation modes
|
|
72
|
+
* (plan/execute) fall back to the legacy single `chatModel` when the per-mode
|
|
73
|
+
* field is unset (back-compat); the auxiliary jobs (commit/compact) do NOT —
|
|
74
|
+
* the server applies its own fast default for them, mirrored here by returning
|
|
75
|
+
* `undefined`.
|
|
76
|
+
*
|
|
77
|
+
* @param settings - The project's model settings.
|
|
78
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
79
|
+
* @returns The resolved model id, or `undefined` when nothing is configured.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveModeModel(settings: PerModeModelSettings, mode: ModelMode): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The model a free/anon user gets in a mode when nothing else applies: the
|
|
84
|
+
* server-sent default for that mode, else the catalog's `freeTier`-flagged
|
|
85
|
+
* model, else the supplied `fallback`. Never names a model id — the server's
|
|
86
|
+
* free-tier policy (and the catalog flag it publishes) is the only source.
|
|
87
|
+
*
|
|
88
|
+
* @param models - The available models from the catalog.
|
|
89
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
90
|
+
* @param fallback - The free-tier model id to use when neither source has one.
|
|
91
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
92
|
+
* @returns The free-tier model id for the mode.
|
|
93
|
+
*/
|
|
94
|
+
export declare function freeTierModeModelId(models: readonly AppModelDefinition[], mode: ModelMode, fallback: string, serverDefaults?: ServerModeDefaults): string;
|
|
95
|
+
/**
|
|
96
|
+
* The model id that will ACTUALLY serve a conversation mode, for display.
|
|
97
|
+
*
|
|
98
|
+
* Mirrors the server's `selectModelForMode` candidate chain (minus the
|
|
99
|
+
* per-request override, which the UI never has): the project's per-mode model,
|
|
100
|
+
* then the project's SAVED legacy `chatModel`, each skipped when the free-tier
|
|
101
|
+
* clamp would reject it — then the server-sent per-mode default (which already
|
|
102
|
+
* folds in the owner's account-level settings and tier), then the catalog's
|
|
103
|
+
* free-tier model as the last resort.
|
|
104
|
+
*
|
|
105
|
+
* `settings.chatModel` must be the PERSISTED value only — never a UI-seeded
|
|
106
|
+
* default. Seeding the catalog's free-tier model as "current" once made every
|
|
107
|
+
* plan-mode surface label the wrong model while the server planned with its
|
|
108
|
+
* own plan default.
|
|
109
|
+
*
|
|
110
|
+
* @param mode - The conversation mode to resolve.
|
|
111
|
+
* @param settings - Persisted per-mode + legacy model settings (saved only).
|
|
112
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
113
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
114
|
+
* @param models - The available models from the catalog.
|
|
115
|
+
* @param fallback - The free-tier model id to use when no other source exists.
|
|
116
|
+
* @returns The model id the mode resolves to.
|
|
117
|
+
*/
|
|
118
|
+
export declare function effectiveModeModelId(mode: 'plan' | 'execute', settings: PerModeModelSettings, serverDefaults: ServerModeDefaults, isFreeTier: boolean, models: readonly AppModelDefinition[], fallback: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Why a model is locked for a free-tier user in a given mode — `'paid'` for a
|
|
121
|
+
* genuinely paid model, `'mode'` for a model the free tier CAN use, just in a
|
|
122
|
+
* different mode (e.g. another mode's server default shown in this picker).
|
|
123
|
+
*/
|
|
124
|
+
export type FreeTierLockReason = 'paid' | 'mode';
|
|
125
|
+
/**
|
|
126
|
+
* The lock reason for a model in a mode under the free-tier clamp, or `null`
|
|
127
|
+
* when it is selectable. Pro users and `provider: 'custom'` (bring-your-own
|
|
128
|
+
* AI) models are never locked; a free/anon user may pick a `freeTier`-flagged
|
|
129
|
+
* model in any mode, or the server-sent default for the scoped mode.
|
|
130
|
+
*
|
|
131
|
+
* A locked model splits into two very different cases the UI must not
|
|
132
|
+
* conflate: `'paid'` (upgrade actually unlocks it) versus `'mode'` (the model
|
|
133
|
+
* is free-tier-usable in ANOTHER mode, so a "Pro" badge would be flatly wrong).
|
|
134
|
+
*
|
|
135
|
+
* @param modelId - The candidate model id.
|
|
136
|
+
* @param mode - The conversation mode the picker is scoped to.
|
|
137
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
138
|
+
* @param models - The available models from the catalog.
|
|
139
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
140
|
+
* @returns `'paid'` / `'mode'` when locked, `null` when selectable.
|
|
141
|
+
*/
|
|
142
|
+
export declare function freeTierLockReason(modelId: string, mode: ModelMode, isFreeTier: boolean, models: readonly AppModelDefinition[], serverDefaults?: ServerModeDefaults): FreeTierLockReason | null;
|
|
143
|
+
/**
|
|
144
|
+
* The mode a free-tier user can actually use this model in — `'plan'` /
|
|
145
|
+
* `'execute'` when the free tier allows it there, `'commit'` (standing for
|
|
146
|
+
* both auxiliary jobs) when only an aux job allows it, `null` when the free
|
|
147
|
+
* tier can't use it anywhere. Drives the "free in <mode>" labeling next to a
|
|
148
|
+
* `'mode'`-locked row.
|
|
149
|
+
*
|
|
150
|
+
* @param modelId - The candidate model id.
|
|
151
|
+
* @param models - The available models from the catalog.
|
|
152
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
153
|
+
* @returns The mode the model is free-tier-usable in, or `null`.
|
|
154
|
+
*/
|
|
155
|
+
export declare function freeTierUsableMode(modelId: string, models: readonly AppModelDefinition[], serverDefaults?: ServerModeDefaults): ModelMode | null;
|
|
156
|
+
/**
|
|
157
|
+
* Whether a model is locked (not selectable) for the given mode under the
|
|
158
|
+
* free-tier clamp — the boolean view of {@link freeTierLockReason} (which see
|
|
159
|
+
* for the rules).
|
|
160
|
+
*
|
|
161
|
+
* @param modelId - The candidate model id.
|
|
162
|
+
* @param mode - The conversation mode the picker is scoped to.
|
|
163
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
164
|
+
* @param models - The available models from the catalog.
|
|
165
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
166
|
+
* @returns `true` when the model is locked for this user and mode.
|
|
167
|
+
*/
|
|
168
|
+
export declare function isModeModelLocked(modelId: string, mode: ModelMode, isFreeTier: boolean, models: readonly AppModelDefinition[], serverDefaults?: ServerModeDefaults): boolean;
|
|
169
|
+
//# sourceMappingURL=chat-model-mode-utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-model-mode-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-model-mode-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAEvF,wEAAwE;AACxE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEjE;;;;GA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G;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAA;AAKhD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,cAAc,CAAC,EAAE,kBAAkB,GAClC,kBAAkB,GAAG,IAAI,CAS3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,cAAc,CAAC,EAAE,kBAAkB,GAClC,SAAS,GAAG,IAAI,CAWlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,cAAc,CAAC,EAAE,kBAAkB,GAClC,OAAO,CAET"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers backing the per-mode model pickers (`/model --plan`,
|
|
3
|
+
* `/model --execute`, `/model --commit`, and `/model --compact`).
|
|
4
|
+
*
|
|
5
|
+
* A project stores optional per-mode model ids in its settings — `planModel`
|
|
6
|
+
* (used in plan mode) and `executeModel` (used in execute mode) alongside the
|
|
7
|
+
* legacy single `chatModel`, plus two auxiliary jobs: `commitModel` (the
|
|
8
|
+
* commit-message generator) and `compactModel` (conversation compaction), which
|
|
9
|
+
* fall back to the server's own fast default (never `chatModel`) when unset.
|
|
10
|
+
* These helpers parse the mode flag, map a mode to its settings field, resolve
|
|
11
|
+
* the effective model for a mode, and compute the free-tier clamp.
|
|
12
|
+
*
|
|
13
|
+
* The clamp is entirely SERVER-DRIVEN — no model id is ever named here. A
|
|
14
|
+
* free/anon user may use, in any mode, a model the catalog flags `freeTier`,
|
|
15
|
+
* plus the server-sent per-mode default for that mode (`GET /ai/models`
|
|
16
|
+
* `defaults`, which the server resolves from its own free-tier policy). Two
|
|
17
|
+
* earlier generations of this file hardcoded the clamp ids (first a Sonnet
|
|
18
|
+
* planner, then `deepseek-v4-pro`); each went stale the moment the server's
|
|
19
|
+
* policy moved and the picker advertised a model the server would not use.
|
|
20
|
+
*
|
|
21
|
+
* Everything here is deterministic and side-effect free so it can be unit tested
|
|
22
|
+
* without rendering or a backend. The component owns persistence (`PATCH
|
|
23
|
+
* /projects/:id { settings }`) and any `t()` prose.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Parses a `/model --plan`, `--execute`, `--commit`, or `--compact` command.
|
|
29
|
+
* Returns the targeted mode plus any trailing filter `query` (the text after
|
|
30
|
+
* the flag), or `null` when the input is not a mode-scoped `/model` command.
|
|
31
|
+
* Use this *before* the generic `/model <name>` handler so the flag is not
|
|
32
|
+
* mistaken for a model name.
|
|
33
|
+
*
|
|
34
|
+
* @param input - The raw chat input.
|
|
35
|
+
* @returns `{ mode, query }` for a mode-scoped command, else `null`.
|
|
36
|
+
*/
|
|
37
|
+
export function parseModelModeCommand(input) {
|
|
38
|
+
const match = input.trim().match(/^\/model\s+--(plan|execute|commit|compact)\b\s*(.*)$/i);
|
|
39
|
+
if (!match)
|
|
40
|
+
return null;
|
|
41
|
+
return { mode: match[1].toLowerCase(), query: match[2].trim() };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Maps a mode to the project-settings field that stores its model id.
|
|
45
|
+
*
|
|
46
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
47
|
+
* @returns The settings field for the mode (e.g. `'planModel'` for plan mode).
|
|
48
|
+
*/
|
|
49
|
+
export function modeSettingKey(mode) {
|
|
50
|
+
switch (mode) {
|
|
51
|
+
case 'plan':
|
|
52
|
+
return 'planModel';
|
|
53
|
+
case 'execute':
|
|
54
|
+
return 'executeModel';
|
|
55
|
+
case 'commit':
|
|
56
|
+
return 'commitModel';
|
|
57
|
+
case 'compact':
|
|
58
|
+
return 'compactModel';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the effective model id for a mode. The conversation modes
|
|
63
|
+
* (plan/execute) fall back to the legacy single `chatModel` when the per-mode
|
|
64
|
+
* field is unset (back-compat); the auxiliary jobs (commit/compact) do NOT —
|
|
65
|
+
* the server applies its own fast default for them, mirrored here by returning
|
|
66
|
+
* `undefined`.
|
|
67
|
+
*
|
|
68
|
+
* @param settings - The project's model settings.
|
|
69
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
70
|
+
* @returns The resolved model id, or `undefined` when nothing is configured.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveModeModel(settings, mode) {
|
|
73
|
+
switch (mode) {
|
|
74
|
+
case 'plan':
|
|
75
|
+
return settings.planModel ?? settings.chatModel;
|
|
76
|
+
case 'execute':
|
|
77
|
+
return settings.executeModel ?? settings.chatModel;
|
|
78
|
+
case 'commit':
|
|
79
|
+
return settings.commitModel;
|
|
80
|
+
case 'compact':
|
|
81
|
+
return settings.compactModel;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The model a free/anon user gets in a mode when nothing else applies: the
|
|
86
|
+
* server-sent default for that mode, else the catalog's `freeTier`-flagged
|
|
87
|
+
* model, else the supplied `fallback`. Never names a model id — the server's
|
|
88
|
+
* free-tier policy (and the catalog flag it publishes) is the only source.
|
|
89
|
+
*
|
|
90
|
+
* @param models - The available models from the catalog.
|
|
91
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
92
|
+
* @param fallback - The free-tier model id to use when neither source has one.
|
|
93
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
94
|
+
* @returns The free-tier model id for the mode.
|
|
95
|
+
*/
|
|
96
|
+
export function freeTierModeModelId(models, mode, fallback, serverDefaults) {
|
|
97
|
+
return serverDefaults?.[mode] || models.find((m) => m.freeTier === true)?.id || fallback;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Whether a free/anon user may use a (non-custom) model in a mode: the catalog
|
|
101
|
+
* flags it `freeTier` (free in every mode, as the server's `freeTierAllows`
|
|
102
|
+
* treats it), or it is the server-sent default for that very mode (the server
|
|
103
|
+
* only sends a free user defaults it would itself dispatch to).
|
|
104
|
+
*
|
|
105
|
+
* @param model - The candidate's catalog entry (undefined when unknown).
|
|
106
|
+
* @param modelId - The candidate model id.
|
|
107
|
+
* @param mode - The conversation mode or auxiliary job.
|
|
108
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
109
|
+
* @returns `true` when the free tier may use the model in that mode.
|
|
110
|
+
*/
|
|
111
|
+
function freeTierAllowsIn(model, modelId, mode, serverDefaults) {
|
|
112
|
+
return model?.freeTier === true || (!!serverDefaults?.[mode] && serverDefaults[mode] === modelId);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The model id that will ACTUALLY serve a conversation mode, for display.
|
|
116
|
+
*
|
|
117
|
+
* Mirrors the server's `selectModelForMode` candidate chain (minus the
|
|
118
|
+
* per-request override, which the UI never has): the project's per-mode model,
|
|
119
|
+
* then the project's SAVED legacy `chatModel`, each skipped when the free-tier
|
|
120
|
+
* clamp would reject it — then the server-sent per-mode default (which already
|
|
121
|
+
* folds in the owner's account-level settings and tier), then the catalog's
|
|
122
|
+
* free-tier model as the last resort.
|
|
123
|
+
*
|
|
124
|
+
* `settings.chatModel` must be the PERSISTED value only — never a UI-seeded
|
|
125
|
+
* default. Seeding the catalog's free-tier model as "current" once made every
|
|
126
|
+
* plan-mode surface label the wrong model while the server planned with its
|
|
127
|
+
* own plan default.
|
|
128
|
+
*
|
|
129
|
+
* @param mode - The conversation mode to resolve.
|
|
130
|
+
* @param settings - Persisted per-mode + legacy model settings (saved only).
|
|
131
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
132
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
133
|
+
* @param models - The available models from the catalog.
|
|
134
|
+
* @param fallback - The free-tier model id to use when no other source exists.
|
|
135
|
+
* @returns The model id the mode resolves to.
|
|
136
|
+
*/
|
|
137
|
+
export function effectiveModeModelId(mode, settings, serverDefaults, isFreeTier, models, fallback) {
|
|
138
|
+
const candidates = mode === 'plan'
|
|
139
|
+
? [settings.planModel, settings.chatModel]
|
|
140
|
+
: [settings.executeModel, settings.chatModel];
|
|
141
|
+
for (const candidate of candidates) {
|
|
142
|
+
if (!candidate)
|
|
143
|
+
continue;
|
|
144
|
+
// Mirror the server: a candidate the free-tier clamp rejects falls
|
|
145
|
+
// through to the next, it does not stick as the label.
|
|
146
|
+
if (freeTierLockReason(candidate, mode, isFreeTier, models, serverDefaults) === null) {
|
|
147
|
+
return candidate;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return freeTierModeModelId(models, mode, fallback, serverDefaults);
|
|
151
|
+
}
|
|
152
|
+
/** Every mode a per-mode clamp exists for — used to test "free elsewhere". */
|
|
153
|
+
const MODEL_MODES = ['plan', 'execute', 'commit', 'compact'];
|
|
154
|
+
/**
|
|
155
|
+
* The lock reason for a model in a mode under the free-tier clamp, or `null`
|
|
156
|
+
* when it is selectable. Pro users and `provider: 'custom'` (bring-your-own
|
|
157
|
+
* AI) models are never locked; a free/anon user may pick a `freeTier`-flagged
|
|
158
|
+
* model in any mode, or the server-sent default for the scoped mode.
|
|
159
|
+
*
|
|
160
|
+
* A locked model splits into two very different cases the UI must not
|
|
161
|
+
* conflate: `'paid'` (upgrade actually unlocks it) versus `'mode'` (the model
|
|
162
|
+
* is free-tier-usable in ANOTHER mode, so a "Pro" badge would be flatly wrong).
|
|
163
|
+
*
|
|
164
|
+
* @param modelId - The candidate model id.
|
|
165
|
+
* @param mode - The conversation mode the picker is scoped to.
|
|
166
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
167
|
+
* @param models - The available models from the catalog.
|
|
168
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
169
|
+
* @returns `'paid'` / `'mode'` when locked, `null` when selectable.
|
|
170
|
+
*/
|
|
171
|
+
export function freeTierLockReason(modelId, mode, isFreeTier, models, serverDefaults) {
|
|
172
|
+
if (!isFreeTier)
|
|
173
|
+
return null;
|
|
174
|
+
const candidate = models.find((m) => m.id === modelId);
|
|
175
|
+
if (candidate?.provider === 'custom')
|
|
176
|
+
return null;
|
|
177
|
+
if (freeTierAllowsIn(candidate, modelId, mode, serverDefaults))
|
|
178
|
+
return null;
|
|
179
|
+
const freeElsewhere = MODEL_MODES.some((other) => other !== mode && freeTierAllowsIn(candidate, modelId, other, serverDefaults));
|
|
180
|
+
return freeElsewhere ? 'mode' : 'paid';
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The mode a free-tier user can actually use this model in — `'plan'` /
|
|
184
|
+
* `'execute'` when the free tier allows it there, `'commit'` (standing for
|
|
185
|
+
* both auxiliary jobs) when only an aux job allows it, `null` when the free
|
|
186
|
+
* tier can't use it anywhere. Drives the "free in <mode>" labeling next to a
|
|
187
|
+
* `'mode'`-locked row.
|
|
188
|
+
*
|
|
189
|
+
* @param modelId - The candidate model id.
|
|
190
|
+
* @param models - The available models from the catalog.
|
|
191
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
192
|
+
* @returns The mode the model is free-tier-usable in, or `null`.
|
|
193
|
+
*/
|
|
194
|
+
export function freeTierUsableMode(modelId, models, serverDefaults) {
|
|
195
|
+
const candidate = models.find((m) => m.id === modelId);
|
|
196
|
+
if (freeTierAllowsIn(candidate, modelId, 'plan', serverDefaults))
|
|
197
|
+
return 'plan';
|
|
198
|
+
if (freeTierAllowsIn(candidate, modelId, 'execute', serverDefaults))
|
|
199
|
+
return 'execute';
|
|
200
|
+
if (freeTierAllowsIn(candidate, modelId, 'commit', serverDefaults) ||
|
|
201
|
+
freeTierAllowsIn(candidate, modelId, 'compact', serverDefaults)) {
|
|
202
|
+
return 'commit';
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Whether a model is locked (not selectable) for the given mode under the
|
|
208
|
+
* free-tier clamp — the boolean view of {@link freeTierLockReason} (which see
|
|
209
|
+
* for the rules).
|
|
210
|
+
*
|
|
211
|
+
* @param modelId - The candidate model id.
|
|
212
|
+
* @param mode - The conversation mode the picker is scoped to.
|
|
213
|
+
* @param isFreeTier - Whether the current user is on the free/anon tier.
|
|
214
|
+
* @param models - The available models from the catalog.
|
|
215
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
216
|
+
* @returns `true` when the model is locked for this user and mode.
|
|
217
|
+
*/
|
|
218
|
+
export function isModeModelLocked(modelId, mode, isFreeTier, models, serverDefaults) {
|
|
219
|
+
return freeTierLockReason(modelId, mode, isFreeTier, models, serverDefaults) !== null;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=chat-model-mode-utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-model-mode-utilities.js","sourceRoot":"","sources":["../../src/components/chat-model-mode-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AA4BH;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAA;IACzF,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAe,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAA;AAC9E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAe;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