ompchamber 1.0.0 → 1.1.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/client/index.html +1 -1
- package/dist/client/static/css/index.b859cc1cc5.css +2 -0
- package/dist/client/static/js/async/{5b.0d6ae50fe8.js → 5b.a5ccbc19dc.js} +2 -2
- package/dist/client/static/js/index.6e065017eb.js +33 -0
- package/package.json +1 -1
- package/src/client/components/common/ComposerPicker.tsx +16 -4
- package/src/client/components/common/ComposerTextarea.tsx +1 -0
- package/src/client/components/layout/RightActivityBar.tsx +1 -1
- package/src/client/components/layout/desktop-layout/ResizeHandle.tsx +2 -2
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +13 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +107 -56
- package/src/client/components/layout/desktop-layout/index.tsx +25 -96
- package/src/client/components/layout/desktop-layout/resizer/index.tsx +79 -118
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +140 -0
- package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +26 -12
- package/src/client/components/layout/session-sidebar/SubagentList.tsx +6 -4
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/SubagentView.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +23 -3
- package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Goal.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/groups.ts +35 -2
- package/src/client/components/workspace/model-dropdown/index.tsx +48 -7
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +28 -4
- package/src/client/hooks/chat/composer/index.ts +28 -8
- package/src/client/hooks/chat/timeline/actions.ts +24 -3
- package/src/client/hooks/chat/timeline/deferred-model.test.ts +219 -0
- package/src/client/hooks/chat/timeline/deferred-model.ts +92 -0
- package/src/client/hooks/chat/timeline/index.ts +13 -1
- package/src/client/hooks/chat/timeline/send.ts +16 -5
- package/src/client/hooks/workspace/available-width.ts +33 -0
- package/src/client/hooks/workspace/panel-widths.ts +34 -37
- package/src/server/lib/models/preferences.server.ts +110 -0
- package/src/server/lib/models/registry.server.ts +206 -0
- package/src/server/lib/omp/rpc/utility.ts +7 -1
- package/src/server/lib/queue/delivery.server.test.ts +203 -0
- package/src/server/lib/queue/delivery.server.ts +38 -8
- package/src/server/routes/models/root.ts +88 -215
- package/src/server/routes/settings/commands.ts +59 -18
- package/src/shared/lib/chat/composer/client.ts +17 -8
- package/src/shared/lib/chat/composer/commands.ts +290 -0
- package/src/shared/lib/chat/composer/composer.test.ts +157 -0
- package/src/shared/lib/chat/composer/filter.ts +21 -7
- package/src/shared/lib/chat/composer/trigger.ts +109 -20
- package/src/shared/lib/models/preferences.test.ts +131 -0
- package/src/shared/lib/models/preferences.ts +88 -0
- package/src/shared/lib/models/provider-models.ts +8 -1
- package/src/shared/lib/omp/subagent/label.test.ts +94 -0
- package/src/shared/lib/omp/subagent/label.ts +84 -0
- package/src/shared/lib/workspace/panel-widths.test.ts +113 -18
- package/src/shared/lib/workspace/panel-widths.ts +161 -30
- package/src/shared/lib/workspace/right-panels.ts +50 -11
- package/src/shared/lib/workspace/session-state/store.ts +3 -0
- package/src/shared/types/chat.ts +38 -65
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +101 -0
- package/src/shared/types/omp/subagent.ts +4 -0
- package/src/shared/types/settings/command.ts +13 -0
- package/dist/client/static/css/index.e880517fcd.css +0 -2
- package/dist/client/static/js/index.0de15c5e17.js +0 -33
- /package/dist/client/static/js/async/{5b.0d6ae50fe8.js.LICENSE.txt → 5b.a5ccbc19dc.js.LICENSE.txt} +0 -0
- /package/dist/client/static/js/{index.0de15c5e17.js.LICENSE.txt → index.6e065017eb.js.LICENSE.txt} +0 -0
|
@@ -3,190 +3,28 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-
|
|
|
3
3
|
import { getDb } from '@/server/db.server';
|
|
4
4
|
import { INITIAL_MODELS_CATALOG } from '@/client/data/models/catalog';
|
|
5
5
|
import { isMockMode } from '@/server/mock.server';
|
|
6
|
-
import type { AIModelOption,
|
|
6
|
+
import type { AIModelOption, ModelsData, ProviderItem } from '@/shared/types';
|
|
7
7
|
import { readSettingsJson, writeSettingsJson } from '@/server/lib/db/settings-store';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
import { modelKey } from '@/shared/lib/models/identity';
|
|
9
|
+
import {
|
|
10
|
+
EMPTY_MODELS,
|
|
11
|
+
SAFE_MODEL_LOAD_FAILURE_MESSAGE,
|
|
12
|
+
invalidateModelsCache,
|
|
13
|
+
loadModelsWithCache,
|
|
14
|
+
readStoredProvidersForModels,
|
|
15
|
+
} from '@/server/lib/models/registry.server';
|
|
16
|
+
import {
|
|
17
|
+
readModelPreferencesFor,
|
|
18
|
+
recordRecentPreference,
|
|
19
|
+
toggleFavoritePreference,
|
|
20
|
+
} from '@/server/lib/models/preferences.server';
|
|
11
21
|
|
|
12
22
|
const MODELS_CATALOG_KEY = 'omp_models_catalog';
|
|
13
23
|
const SELECTED_MODEL_KEY = 'omp_selected_model';
|
|
14
|
-
const PROVIDERS_CONFIG_KEY = 'omp_providers_config';
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const modelNameCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
|
20
|
-
|
|
21
|
-
function compareModelEntries(a: { id: string; name: string; provider: string }, b: { id: string; name: string; provider: string }): number {
|
|
22
|
-
return modelNameCollator.compare(a.name || a.id, b.name || b.id)
|
|
23
|
-
|| modelNameCollator.compare(a.provider, b.provider)
|
|
24
|
-
|| modelNameCollator.compare(a.id, b.id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// "off" is always a valid selector; the concrete efforts come from the model's
|
|
28
|
-
// baked thinking metadata (omp: getSupportedEfforts = reasoning ? efforts : []).
|
|
29
|
-
function thinkingLevelsFor(model: OmpModel): string[] {
|
|
30
|
-
if (!model.reasoning) return ['off'];
|
|
31
|
-
return ['off', ...(model.thinking?.efforts ?? [])];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function supportsFastMode(model: OmpModel): boolean {
|
|
35
|
-
return model.provider === 'anthropic' || model.provider === 'openai' || model.provider === 'google';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Disabled providers recorded in the chamber's own provider overlay. Used only
|
|
40
|
-
* by the MOCK path of `/api/models`, which has no config.yml `disabledProviders`
|
|
41
|
-
* to read — real mode gets the same answer natively.
|
|
42
|
-
*/
|
|
43
|
-
async function readStoredProvidersForModels(): Promise<ProviderItem[]> {
|
|
44
|
-
try {
|
|
45
|
-
const db = await getDb();
|
|
46
|
-
const parsed = await readSettingsJson<unknown>(db, PROVIDERS_CONFIG_KEY, null);
|
|
47
|
-
if (!Array.isArray(parsed)) return [];
|
|
48
|
-
return parsed.filter((provider): provider is ProviderItem => (
|
|
49
|
-
typeof provider === 'object' && provider !== null
|
|
50
|
-
&& typeof (provider as ProviderItem).slug === 'string'
|
|
51
|
-
&& (provider as ProviderItem).disabled === true
|
|
52
|
-
));
|
|
53
|
-
} catch {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function hiddenModelKey(provider: string, modelId: string): string {
|
|
59
|
-
return `${provider.trim().toLowerCase()}:${modelId}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function readHiddenModelKeys(): Promise<Set<string>> {
|
|
63
|
-
try {
|
|
64
|
-
const db = await getDb();
|
|
65
|
-
const parsed = await readSettingsJson<unknown>(db, PROVIDERS_CONFIG_KEY, null);
|
|
66
|
-
if (!Array.isArray(parsed)) return new Set();
|
|
67
|
-
const hidden = new Set<string>();
|
|
68
|
-
for (const provider of parsed) {
|
|
69
|
-
if (typeof provider?.slug !== 'string' || !Array.isArray(provider.models)) continue;
|
|
70
|
-
for (const model of provider.models) {
|
|
71
|
-
if (typeof model?.id === 'string' && model.isVisible === false) {
|
|
72
|
-
hidden.add(hiddenModelKey(provider.slug, model.id));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return hidden;
|
|
77
|
-
} catch {
|
|
78
|
-
return new Set();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* A model is offered only when its provider is neither disabled in omp's
|
|
84
|
-
* config.yml (`disabledProviders`) nor carrying a per-model hide in the
|
|
85
|
-
* chamber overlay. Disabling the provider is the coarse switch — Settings →
|
|
86
|
-
* Providers flips it so the whole provider leaves the chat picker.
|
|
87
|
-
*/
|
|
88
|
-
function filterSelectableModels(
|
|
89
|
-
available: OmpModel[],
|
|
90
|
-
disabledProviders: Set<string>,
|
|
91
|
-
hiddenModelKeys: Set<string>,
|
|
92
|
-
): OmpModel[] {
|
|
93
|
-
return available.filter((model) => (
|
|
94
|
-
!disabledProviders.has(model.provider)
|
|
95
|
-
&& !hiddenModelKeys.has(hiddenModelKey(model.provider, model.id))
|
|
96
|
-
));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function loadModels(): Promise<ModelsData> {
|
|
100
|
-
const availableResponse = await runUtilityCommand<{ models?: unknown }>(
|
|
101
|
-
{ type: 'get_available_models' },
|
|
102
|
-
120_000,
|
|
103
|
-
);
|
|
104
|
-
const available = Array.isArray(availableResponse.models)
|
|
105
|
-
? availableResponse.models
|
|
106
|
-
.filter((model): model is OmpModel => (
|
|
107
|
-
typeof model === 'object' && model !== null
|
|
108
|
-
&& typeof (model as OmpModel).id === 'string'
|
|
109
|
-
&& typeof (model as OmpModel).provider === 'string'
|
|
110
|
-
))
|
|
111
|
-
.map((model) => ({
|
|
112
|
-
...model,
|
|
113
|
-
name: typeof model.name === 'string' && model.name.trim().length > 0 ? model.name : model.id,
|
|
114
|
-
}))
|
|
115
|
-
: [];
|
|
116
|
-
|
|
117
|
-
const disabledProviders = await readDisabledProviders();
|
|
118
|
-
const hiddenModelKeys = await readHiddenModelKeys();
|
|
119
|
-
const nameMap: Record<string, string> = {};
|
|
120
|
-
const thinkingLevels: Record<string, string[]> = {};
|
|
121
|
-
const modelList: ModelEntry[] = filterSelectableModels(available, disabledProviders, hiddenModelKeys)
|
|
122
|
-
.map((m) => ({
|
|
123
|
-
id: m.id,
|
|
124
|
-
name: m.name,
|
|
125
|
-
provider: m.provider,
|
|
126
|
-
thinkingLevels: thinkingLevelsFor(m),
|
|
127
|
-
supportsFastMode: supportsFastMode(m),
|
|
128
|
-
contextWindow: m.contextWindow ?? undefined,
|
|
129
|
-
maxTokens: m.maxTokens ?? undefined,
|
|
130
|
-
cost: m.cost,
|
|
131
|
-
}))
|
|
132
|
-
.sort(compareModelEntries);
|
|
133
|
-
|
|
134
|
-
const loginResponse = await runUtilityCommand<{ providers?: unknown }>(
|
|
135
|
-
{ type: 'get_login_providers' },
|
|
136
|
-
30_000,
|
|
137
|
-
);
|
|
138
|
-
const loginProviders = Array.isArray(loginResponse.providers)
|
|
139
|
-
? loginResponse.providers.filter((provider): provider is { id: string; name: string; authenticated: boolean } => (
|
|
140
|
-
typeof provider === 'object' && provider !== null
|
|
141
|
-
&& typeof (provider as { id?: unknown }).id === 'string'
|
|
142
|
-
&& typeof (provider as { name?: unknown }).name === 'string'
|
|
143
|
-
&& typeof (provider as { authenticated?: unknown }).authenticated === 'boolean'
|
|
144
|
-
))
|
|
145
|
-
: [];
|
|
146
|
-
const connectedProviders = loginProviders
|
|
147
|
-
.filter((provider) => provider.authenticated)
|
|
148
|
-
.map((provider) => ({ id: provider.id, name: provider.name, disabled: disabledProviders.has(provider.id) }));
|
|
149
|
-
for (const m of available) {
|
|
150
|
-
const key = `${m.provider}:${m.id}`;
|
|
151
|
-
nameMap[key] = m.name;
|
|
152
|
-
thinkingLevels[key] = thinkingLevelsFor(m);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let defaultModel: { provider: string; modelId: string } | null = null;
|
|
156
|
-
try {
|
|
157
|
-
const state = await runUtilityCommand<{ model?: { provider?: string; id?: string } }>(
|
|
158
|
-
{ type: 'get_state' },
|
|
159
|
-
30_000,
|
|
160
|
-
);
|
|
161
|
-
const provider = state.model?.provider;
|
|
162
|
-
const modelId = state.model?.id;
|
|
163
|
-
if (provider && modelId && available.some((m) => m.provider === provider && m.id === modelId)) {
|
|
164
|
-
defaultModel = { provider, modelId };
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
// Default model is cosmetic — the models list is still useful without it.
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return { models: nameMap, modelList, defaultModel, thinkingLevels, connectedProviders };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const EMPTY_MODELS: ModelsData = {
|
|
174
|
-
models: {},
|
|
175
|
-
modelList: [],
|
|
176
|
-
defaultModel: null,
|
|
177
|
-
thinkingLevels: {},
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
async function loadModelsWithCache(): Promise<ModelsData> {
|
|
181
|
-
const cached = globalThis.__ompChamberModelsCache;
|
|
182
|
-
if (cached && cached.expiresAt > Date.now()) return cached.data;
|
|
183
|
-
const data = await loadModels();
|
|
184
|
-
globalThis.__ompChamberModelsCache = { data, expiresAt: Date.now() + MODELS_CACHE_TTL_MS };
|
|
185
|
-
return data;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function invalidateModelsCache(): void {
|
|
189
|
-
invalidateModelsCaches();
|
|
25
|
+
/** Error text for a 500 envelope without leaking a non-Error throw as `undefined`. */
|
|
26
|
+
function errorMessage(error: unknown): string {
|
|
27
|
+
return error instanceof Error ? error.message : String(error);
|
|
190
28
|
}
|
|
191
29
|
|
|
192
30
|
/** Parse a persisted { provider, modelId|id } reference without trusting the JSON shape. */
|
|
@@ -200,7 +38,7 @@ function readSelectedModelRef(value: unknown): { provider: string; modelId: stri
|
|
|
200
38
|
}
|
|
201
39
|
|
|
202
40
|
/** The user's persisted pick resolved against the live registry; null when stale or unparseable. */
|
|
203
|
-
async function loadPersistedModelOption(modelList:
|
|
41
|
+
async function loadPersistedModelOption(modelList: ModelsData['modelList']): Promise<AIModelOption | null> {
|
|
204
42
|
try {
|
|
205
43
|
const db = await getDb();
|
|
206
44
|
const selected = readSelectedModelRef(await readSettingsJson<unknown>(db, SELECTED_MODEL_KEY, null));
|
|
@@ -220,37 +58,44 @@ async function loadPersistedModelOption(modelList: ModelEntry[]): Promise<AIMode
|
|
|
220
58
|
}
|
|
221
59
|
}
|
|
222
60
|
|
|
223
|
-
|
|
224
|
-
|
|
61
|
+
/**
|
|
62
|
+
* MOCK mode keeps the SQLite-backed demo catalog, but the favorite/recent
|
|
63
|
+
* rails come from the same preference store as real mode — the catalog's own
|
|
64
|
+
* `isFavorite`/`isRecent` flags are only its seed.
|
|
65
|
+
*/
|
|
66
|
+
async function loadMockModels() {
|
|
67
|
+
const db = await getDb();
|
|
68
|
+
const catalog = await readSettingsJson<unknown>(db, MODELS_CATALOG_KEY, null);
|
|
69
|
+
const stored: AIModelOption[] = Array.isArray(catalog) && catalog.length > 0 ? catalog : INITIAL_MODELS_CATALOG;
|
|
70
|
+
// Demo mode has no config.yml to read, so the disable flag lives on the
|
|
71
|
+
// stored provider overlay. Filtering here keeps the model picker honest
|
|
72
|
+
// in MOCK=true too — the settings page must be able to prove the switch.
|
|
73
|
+
const disabledSlugs = new Set(
|
|
74
|
+
(await readStoredProvidersForModels()).map((provider: ProviderItem) => provider.slug.trim().toLowerCase()),
|
|
75
|
+
);
|
|
76
|
+
const models = stored.filter((model) => !disabledSlugs.has(model.provider.trim().toLowerCase()));
|
|
77
|
+
const persisted = await readSettingsJson<AIModelOption | null>(db, SELECTED_MODEL_KEY, null);
|
|
78
|
+
// Every provider disabled ⇒ empty list and no selection; the composer must
|
|
79
|
+
// see that honestly instead of holding on to a hidden provider's model.
|
|
80
|
+
let selectedModel: AIModelOption | null = models[5] || models[0] || null;
|
|
81
|
+
if (persisted && persisted.id && persisted.provider) {
|
|
82
|
+
const match = models.find(m => m.id === persisted.id && m.provider === persisted.provider);
|
|
83
|
+
if (match) selectedModel = match;
|
|
84
|
+
}
|
|
85
|
+
return { models, selectedModel, modelPreferences: await readModelPreferencesFor(models), isMock: true };
|
|
86
|
+
}
|
|
225
87
|
|
|
88
|
+
export async function loader({ request }: LoaderFunctionArgs) {
|
|
226
89
|
// MOCK mode keeps the SQLite-backed catalog (chamber demo behavior).
|
|
227
|
-
if (
|
|
90
|
+
if (isMockMode()) {
|
|
228
91
|
try {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const stored: AIModelOption[] = Array.isArray(catalog) && catalog.length > 0 ? catalog : INITIAL_MODELS_CATALOG;
|
|
232
|
-
// Demo mode has no config.yml to read, so the disable flag lives on the
|
|
233
|
-
// stored provider overlay. Filtering here keeps the model picker honest
|
|
234
|
-
// in MOCK=true too — the settings page must be able to prove the switch.
|
|
235
|
-
const disabledSlugs = new Set(
|
|
236
|
-
(await readStoredProvidersForModels()).map((provider) => provider.slug.trim().toLowerCase()),
|
|
237
|
-
);
|
|
238
|
-
const models = stored.filter((model) => !disabledSlugs.has(model.provider.trim().toLowerCase()));
|
|
239
|
-
const persisted = await readSettingsJson<AIModelOption | null>(db, SELECTED_MODEL_KEY, null);
|
|
240
|
-
// Every provider disabled ⇒ empty list and no selection; the composer must
|
|
241
|
-
// see that honestly instead of holding on to a hidden provider's model.
|
|
242
|
-
let selectedModel: AIModelOption | null = models[5] || models[0] || null;
|
|
243
|
-
if (persisted && persisted.id && persisted.provider) {
|
|
244
|
-
const match = models.find(m => m.id === persisted.id && m.provider === persisted.provider);
|
|
245
|
-
if (match) selectedModel = match;
|
|
246
|
-
}
|
|
247
|
-
return json({ models, selectedModel, isMock: mock });
|
|
248
|
-
} catch (error: any) {
|
|
92
|
+
return json(await loadMockModels());
|
|
93
|
+
} catch (error: unknown) {
|
|
249
94
|
return json({
|
|
250
|
-
error: error
|
|
95
|
+
error: errorMessage(error),
|
|
251
96
|
models: INITIAL_MODELS_CATALOG,
|
|
252
97
|
selectedModel: INITIAL_MODELS_CATALOG[5] || INITIAL_MODELS_CATALOG[0] || null,
|
|
253
|
-
isMock:
|
|
98
|
+
isMock: true,
|
|
254
99
|
}, { status: 500 });
|
|
255
100
|
}
|
|
256
101
|
}
|
|
@@ -261,8 +106,13 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
261
106
|
void request;
|
|
262
107
|
try {
|
|
263
108
|
const data = await loadModelsWithCache();
|
|
264
|
-
// The selection
|
|
265
|
-
|
|
109
|
+
// The selection and the preferences change independently of the 60s
|
|
110
|
+
// registry cache, so both are read fresh on every request.
|
|
111
|
+
return json({
|
|
112
|
+
...data,
|
|
113
|
+
selectedModel: await loadPersistedModelOption(data.modelList),
|
|
114
|
+
modelPreferences: await readModelPreferencesFor(data.modelList),
|
|
115
|
+
});
|
|
266
116
|
} catch {
|
|
267
117
|
return json({ ...EMPTY_MODELS, modelError: SAFE_MODEL_LOAD_FAILURE_MESSAGE });
|
|
268
118
|
}
|
|
@@ -272,23 +122,42 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
272
122
|
try {
|
|
273
123
|
const db = await getDb();
|
|
274
124
|
const body = await request.json();
|
|
125
|
+
const mock = isMockMode();
|
|
275
126
|
|
|
276
127
|
const catalog = await readSettingsJson<unknown>(db, MODELS_CATALOG_KEY, null);
|
|
277
128
|
// The shipped demo catalog is MOCK-only: a real install starts from an empty
|
|
278
129
|
// list, so a demo model can never be persisted into its stored catalog.
|
|
279
130
|
let models: AIModelOption[] = Array.isArray(catalog)
|
|
280
131
|
? catalog
|
|
281
|
-
: (
|
|
132
|
+
: (mock ? INITIAL_MODELS_CATALOG : []);
|
|
282
133
|
|
|
283
134
|
const { actionType, modelId, provider, thinkingLevel, model, models: newModels } = body;
|
|
284
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Composite keys the registry currently serves. Preference writes prune
|
|
138
|
+
* against it so a model that left models.yml — or whose provider was
|
|
139
|
+
* disconnected — cannot hold one of the five recent slots. Real mode reads
|
|
140
|
+
* the same 60s-cached registry the loader serves; MOCK uses its demo list.
|
|
141
|
+
*/
|
|
142
|
+
const knownModelKeys = async (): Promise<Set<string>> => {
|
|
143
|
+
const live = mock ? models : (await loadModelsWithCache()).modelList;
|
|
144
|
+
return new Set(live.map((entry) => modelKey(entry)));
|
|
145
|
+
};
|
|
146
|
+
|
|
285
147
|
// Model-scoped mutations must match provider + id: the registry serves the
|
|
286
148
|
// same model id from several providers, so an id-only match rewrites the
|
|
287
149
|
// first provider's entry instead of the one the user acted on.
|
|
288
150
|
if (actionType === 'toggleFavorite' && modelId && provider) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
151
|
+
// Favorites live in the preference store, NOT in the model catalog: the
|
|
152
|
+
// catalog is a MOCK-only demo list that real mode never reads back, so a
|
|
153
|
+
// star written there vanished on the next render.
|
|
154
|
+
const preferences = await toggleFavoritePreference(modelKey({ provider, id: modelId }), await knownModelKeys());
|
|
155
|
+
// Keep the demo catalog's flag in step so MOCK mode's own views agree.
|
|
156
|
+
if (mock) {
|
|
157
|
+
models = models.map(m => m.id === modelId && m.provider === provider ? { ...m, isFavorite: !m.isFavorite } : m);
|
|
158
|
+
await writeSettingsJson(db, MODELS_CATALOG_KEY, models);
|
|
159
|
+
}
|
|
160
|
+
return json({ success: true, models, modelPreferences: preferences });
|
|
292
161
|
}
|
|
293
162
|
|
|
294
163
|
if (actionType === 'setThinking' && modelId && provider && thinkingLevel) {
|
|
@@ -308,8 +177,12 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
308
177
|
const parsedModel = readSelectedModelRef(model);
|
|
309
178
|
if (parsedModel) {
|
|
310
179
|
invalidateModelsCache();
|
|
311
|
-
//
|
|
312
|
-
//
|
|
180
|
+
// "The user picked this model" is one event: recording the recent here
|
|
181
|
+
// keeps a second request from ever disagreeing with the selection.
|
|
182
|
+
await recordRecentPreference(
|
|
183
|
+
modelKey({ provider: parsedModel.provider, id: parsedModel.modelId }),
|
|
184
|
+
await knownModelKeys(),
|
|
185
|
+
);
|
|
313
186
|
}
|
|
314
187
|
return json({ success: true, selectedModel: model });
|
|
315
188
|
}
|
|
@@ -326,7 +199,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
326
199
|
}
|
|
327
200
|
|
|
328
201
|
return json({ error: 'Invalid action or parameters' }, { status: 400 });
|
|
329
|
-
} catch (error:
|
|
330
|
-
return json({ error: error
|
|
202
|
+
} catch (error: unknown) {
|
|
203
|
+
return json({ error: errorMessage(error) }, { status: 500 });
|
|
331
204
|
}
|
|
332
205
|
}
|
|
@@ -5,6 +5,7 @@ import { getDb } from '@/server/db.server';
|
|
|
5
5
|
import { DEFAULT_COMMANDS_LIST } from '@/client/data/settings/command';
|
|
6
6
|
import { isMockMode } from '@/server/mock.server';
|
|
7
7
|
import type { CommandItem } from '@/shared/types';
|
|
8
|
+
import { isRecord } from '@/shared/lib/util/guards';
|
|
8
9
|
import { createSettingsListStore } from '@/server/lib/db/settings-store';
|
|
9
10
|
import { runUtilityCommand } from '@/server/lib/omp/rpc/utility';
|
|
10
11
|
|
|
@@ -16,27 +17,67 @@ const commandsStore = createSettingsListStore<CommandItem>({
|
|
|
16
17
|
plural: 'commands',
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
/**
|
|
20
|
+
/** Command sources the chamber surfaces in the composer (mcp_prompt is not user-typable). */
|
|
21
|
+
const AGENT_COMMAND_SOURCES: Record<string, true> = {
|
|
22
|
+
builtin: true,
|
|
23
|
+
skill: true,
|
|
24
|
+
custom: true,
|
|
25
|
+
extension: true,
|
|
26
|
+
file: true,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Live slash commands from the agent's `get_available_commands`, mapped into
|
|
31
|
+
* the chamber's CommandItem. Aliases, subcommands and the argument hint ride
|
|
32
|
+
* along: they are what the composer's `/` popup needs to behave like omp's own
|
|
33
|
+
* editor (`/models` completing to the alias, `/fast ` offering on|off|status).
|
|
34
|
+
* Anything malformed is dropped rather than trusted.
|
|
35
|
+
*/
|
|
36
|
+
function toLiveCommandItem(value: unknown): CommandItem | null {
|
|
37
|
+
if (!isRecord(value)) return null;
|
|
38
|
+
const name = typeof value.name === 'string' ? value.name : '';
|
|
39
|
+
if (!name) return null;
|
|
40
|
+
if (typeof value.source !== 'string' || !AGENT_COMMAND_SOURCES[value.source]) return null;
|
|
41
|
+
|
|
42
|
+
const aliases = Array.isArray(value.aliases)
|
|
43
|
+
? value.aliases.filter((alias): alias is string => typeof alias === 'string' && alias.length > 0)
|
|
44
|
+
: [];
|
|
45
|
+
|
|
46
|
+
const hint = isRecord(value.input) && typeof value.input.hint === 'string' ? value.input.hint : undefined;
|
|
47
|
+
|
|
48
|
+
const subcommands = Array.isArray(value.subcommands)
|
|
49
|
+
? value.subcommands.flatMap((sub) => {
|
|
50
|
+
if (!isRecord(sub) || typeof sub.name !== 'string' || !sub.name) return [];
|
|
51
|
+
return [{
|
|
52
|
+
name: sub.name,
|
|
53
|
+
...(typeof sub.description === 'string' ? { description: sub.description } : {}),
|
|
54
|
+
...(typeof sub.usage === 'string' ? { usage: sub.usage } : {}),
|
|
55
|
+
}];
|
|
56
|
+
})
|
|
57
|
+
: [];
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
id: `omp-live-${name}`,
|
|
61
|
+
name,
|
|
62
|
+
description: typeof value.description === 'string' ? value.description : '',
|
|
63
|
+
scope: 'user',
|
|
64
|
+
template: `/${name}`,
|
|
65
|
+
isBuiltIn: true,
|
|
66
|
+
...(aliases.length ? { aliases } : {}),
|
|
67
|
+
...(subcommands.length ? { subcommands } : {}),
|
|
68
|
+
...(hint ? { inputHint: hint } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Read live agent commands (builtin/skill/custom/extension/file sources) via RPC. */
|
|
20
73
|
async function loadAgentCommands(): Promise<CommandItem[]> {
|
|
21
74
|
try {
|
|
22
75
|
const data = await runUtilityCommand<{ commands?: unknown }>({ type: 'get_available_commands' }, 30_000);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const command = c as { name?: string; description?: string; source?: string };
|
|
29
|
-
const name = typeof command.name === 'string' ? command.name : '';
|
|
30
|
-
return {
|
|
31
|
-
id: `omp-live-${name}`,
|
|
32
|
-
name,
|
|
33
|
-
description: typeof command.description === 'string' ? command.description : '',
|
|
34
|
-
scope: 'user' as const,
|
|
35
|
-
template: `/${name}`,
|
|
36
|
-
isBuiltIn: true,
|
|
37
|
-
};
|
|
38
|
-
})
|
|
39
|
-
.filter((c) => c.name.length > 0);
|
|
76
|
+
if (!Array.isArray(data.commands)) return [];
|
|
77
|
+
return data.commands.flatMap((command) => {
|
|
78
|
+
const item = toLiveCommandItem(command);
|
|
79
|
+
return item ? [item] : [];
|
|
80
|
+
});
|
|
40
81
|
} catch {
|
|
41
82
|
return [];
|
|
42
83
|
}
|
|
@@ -56,8 +56,13 @@ export function toFilePickItems(files: FsFileEntry[]): ComposerPickItem[] {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Combine
|
|
60
|
-
*
|
|
59
|
+
* Combine live command items (`/name`, including omp's own `skill:<name>`
|
|
60
|
+
* entries) with the chamber's skill list. Commands win: a skill whose plain or
|
|
61
|
+
* `skill:`-namespaced name a command already covers is skipped, so the two
|
|
62
|
+
* sources never double-list the same skill.
|
|
63
|
+
*
|
|
64
|
+
* The description carries the argument hint exactly as oh-my-pi renders it
|
|
65
|
+
* (`[on|off|status] - Toggle fast mode`) so the popup matches the CLI.
|
|
61
66
|
*/
|
|
62
67
|
export function mergeCommandAndSkillItems(commands: CommandItem[], skills: SkillItem[]): ComposerPickItem[] {
|
|
63
68
|
const result: ComposerPickItem[] = [];
|
|
@@ -67,13 +72,17 @@ export function mergeCommandAndSkillItems(commands: CommandItem[], skills: Skill
|
|
|
67
72
|
const key = command.name.toLowerCase();
|
|
68
73
|
if (seen.has(key)) continue;
|
|
69
74
|
seen.add(key);
|
|
75
|
+
const description = command.description ?? '';
|
|
70
76
|
result.push({
|
|
71
77
|
id: `command-${command.name}`,
|
|
72
78
|
name: command.name,
|
|
73
|
-
description: command.description,
|
|
74
|
-
kind: 'command',
|
|
75
|
-
source: 'command',
|
|
79
|
+
description: command.inputHint ? (description ? `${command.inputHint} - ${description}` : command.inputHint) : description,
|
|
80
|
+
kind: command.name.toLowerCase().startsWith('skill:') ? 'skill' : 'command',
|
|
81
|
+
source: command.name.toLowerCase().startsWith('skill:') ? 'skill' : 'command',
|
|
76
82
|
token: `/${command.name}`,
|
|
83
|
+
...(command.aliases?.length ? { aliases: command.aliases } : {}),
|
|
84
|
+
...(command.subcommands?.length ? { subcommands: command.subcommands } : {}),
|
|
85
|
+
...(command.inputHint ? { inputHint: command.inputHint } : {}),
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
|
|
@@ -84,11 +93,11 @@ export function mergeCommandAndSkillItems(commands: CommandItem[], skills: Skill
|
|
|
84
93
|
seen.add(prefixed);
|
|
85
94
|
result.push({
|
|
86
95
|
id: `skill-${skill.name}`,
|
|
87
|
-
name:
|
|
96
|
+
name: prefixed,
|
|
88
97
|
description: skill.description,
|
|
89
|
-
kind: '
|
|
98
|
+
kind: 'skill',
|
|
90
99
|
source: 'skill',
|
|
91
|
-
token:
|
|
100
|
+
token: `/${prefixed}`,
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
|