@omercnet/paseo-omp 5.4.0-next.414.1 → 5.4.0-next.415.1
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/client/omp-config-surface.tsx +24 -0
- package/client/omp-local-models-section.tsx +215 -0
- package/index.server.ts +4 -0
- package/package.json +1 -1
- package/server/omp-local-models.ts +202 -0
- package/server/package-version.ts +1 -1
- package/shared/omp-local-models.ts +44 -0
- package/shared/omp-settings.ts +4 -1
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
type OmpDocumentationLink,
|
|
48
48
|
} from "./omp-doc-links";
|
|
49
49
|
import { OmpExtensionsSection } from "./omp-extensions-section";
|
|
50
|
+
import { OmpLocalModelsSection } from "./omp-local-models-section";
|
|
50
51
|
import { OmpMcpsSection } from "./omp-mcps-section";
|
|
51
52
|
import { normalizeOmpModels } from "./omp-model-picker-state";
|
|
52
53
|
import { OmpPluginManagerSection } from "./omp-plugin-manager";
|
|
@@ -1240,6 +1241,15 @@ function OmpConfigContent({
|
|
|
1240
1241
|
? drafts.modelRoles.value
|
|
1241
1242
|
: undefined
|
|
1242
1243
|
: catalog.sourceSettings.find((setting) => setting.path === "modelRoles")?.value;
|
|
1244
|
+
const savedModelRolesValue = catalog.sourceSettings.find(
|
|
1245
|
+
(setting) => setting.path === "modelRoles",
|
|
1246
|
+
)?.value;
|
|
1247
|
+
const savedModelRoles =
|
|
1248
|
+
savedModelRolesValue !== null &&
|
|
1249
|
+
typeof savedModelRolesValue === "object" &&
|
|
1250
|
+
!Array.isArray(savedModelRolesValue)
|
|
1251
|
+
? (savedModelRolesValue as Readonly<Record<string, unknown>>)
|
|
1252
|
+
: {};
|
|
1243
1253
|
const modelRoles =
|
|
1244
1254
|
modelRolesValue !== null &&
|
|
1245
1255
|
typeof modelRolesValue === "object" &&
|
|
@@ -1624,6 +1634,20 @@ function OmpConfigContent({
|
|
|
1624
1634
|
</View>
|
|
1625
1635
|
</View>
|
|
1626
1636
|
) : null}
|
|
1637
|
+
{cwd === undefined ? (
|
|
1638
|
+
<OmpLocalModelsSection
|
|
1639
|
+
styles={styles}
|
|
1640
|
+
store={store}
|
|
1641
|
+
modelRoles={savedModelRoles}
|
|
1642
|
+
settingsRevision={settingsQuery.data?.revision}
|
|
1643
|
+
rolesPending={drafts.modelRoles !== undefined}
|
|
1644
|
+
onRolesChanged={(catalog) => {
|
|
1645
|
+
if (catalog) queryClient.setQueryData(settingsQueryKey, catalog);
|
|
1646
|
+
void queryClient.invalidateQueries({ queryKey: SETTINGS_QUERY_KEY });
|
|
1647
|
+
void queryClient.invalidateQueries({ queryKey: ["paseo-omp", "config"] });
|
|
1648
|
+
}}
|
|
1649
|
+
/>
|
|
1650
|
+
) : null}
|
|
1627
1651
|
</>
|
|
1628
1652
|
) : null}
|
|
1629
1653
|
</ScrollView>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Pressable, Text, View } from "react-native";
|
|
5
|
+
import {
|
|
6
|
+
downloadOmpLocalModel,
|
|
7
|
+
listOmpLocalModels,
|
|
8
|
+
type OmpLocalModel,
|
|
9
|
+
withLocalModelRole,
|
|
10
|
+
} from "../shared/omp-local-models";
|
|
11
|
+
import { type OmpSettingsCatalog, updateOmpSettings } from "../shared/omp-settings";
|
|
12
|
+
import type { OmpStore } from "../shared/omp-store";
|
|
13
|
+
import type { OmpConfigStyles } from "./omp-config-styles";
|
|
14
|
+
import { ompStoreKey } from "./omp-store-state";
|
|
15
|
+
|
|
16
|
+
const POLL_MS = 3_000;
|
|
17
|
+
const ACTION_GROUP = { flexDirection: "row", flexWrap: "wrap", gap: 8 } as const;
|
|
18
|
+
|
|
19
|
+
const ROLES = [
|
|
20
|
+
{ role: "tiny", label: "titles" },
|
|
21
|
+
{ role: "memory", label: "memory" },
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
function Choice({
|
|
25
|
+
styles,
|
|
26
|
+
label,
|
|
27
|
+
accessibilityLabel,
|
|
28
|
+
selected,
|
|
29
|
+
disabled,
|
|
30
|
+
onPress,
|
|
31
|
+
}: {
|
|
32
|
+
styles: OmpConfigStyles;
|
|
33
|
+
label: string;
|
|
34
|
+
accessibilityLabel: string;
|
|
35
|
+
selected?: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
onPress(): void;
|
|
38
|
+
}) {
|
|
39
|
+
return (
|
|
40
|
+
<Pressable
|
|
41
|
+
accessibilityRole="button"
|
|
42
|
+
accessibilityLabel={accessibilityLabel}
|
|
43
|
+
accessibilityState={{ selected: selected === true }}
|
|
44
|
+
disabled={disabled}
|
|
45
|
+
onPress={onPress}
|
|
46
|
+
style={[styles.editorAction, selected ? styles.editorActionPrimary : null]}
|
|
47
|
+
>
|
|
48
|
+
<Text style={[styles.editorActionText, selected ? styles.editorActionTextPrimary : null]}>
|
|
49
|
+
{label}
|
|
50
|
+
</Text>
|
|
51
|
+
</Pressable>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function status(model: OmpLocalModel): string {
|
|
56
|
+
if (model.download === "running") return "Downloading...";
|
|
57
|
+
if (model.download === "failed") return `Download failed: ${model.error ?? "unknown error"}`;
|
|
58
|
+
return model.downloaded ? "Downloaded" : "Not downloaded";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** OMP's own on-device models for titles and memory. Not Paseo's Voice and Dictation models. */
|
|
62
|
+
export function OmpLocalModelsSection({
|
|
63
|
+
styles,
|
|
64
|
+
store,
|
|
65
|
+
modelRoles,
|
|
66
|
+
settingsRevision,
|
|
67
|
+
rolesPending,
|
|
68
|
+
onRolesChanged,
|
|
69
|
+
}: {
|
|
70
|
+
styles: OmpConfigStyles;
|
|
71
|
+
store: OmpStore | undefined;
|
|
72
|
+
modelRoles: Readonly<Record<string, unknown>>;
|
|
73
|
+
settingsRevision: string | undefined;
|
|
74
|
+
/** Unapplied edits to modelRoles would be overwritten by a role assignment made here. */
|
|
75
|
+
rolesPending: boolean;
|
|
76
|
+
onRolesChanged(catalog: OmpSettingsCatalog | undefined): void;
|
|
77
|
+
}) {
|
|
78
|
+
const list = useRpc(listOmpLocalModels);
|
|
79
|
+
const download = useRpc(downloadOmpLocalModel);
|
|
80
|
+
const update = useRpc(updateOmpSettings);
|
|
81
|
+
const queryClient = useQueryClient();
|
|
82
|
+
const [confirming, setConfirming] = useState<string | null>(null);
|
|
83
|
+
const queryKey = ["paseo-omp", "local-models", ompStoreKey(store)];
|
|
84
|
+
const models = useQuery({
|
|
85
|
+
queryKey,
|
|
86
|
+
queryFn: () => list(store ? { store } : {}),
|
|
87
|
+
refetchInterval: (query) =>
|
|
88
|
+
query.state.data?.models.some((model) => model.download === "running") ? POLL_MS : false,
|
|
89
|
+
});
|
|
90
|
+
const start = useMutation({
|
|
91
|
+
mutationKey: ["paseo-omp", "local-model-download"],
|
|
92
|
+
mutationFn: (key: string) => download({ ...(store ? { store } : {}), key }),
|
|
93
|
+
onSettled: () => queryClient.invalidateQueries({ queryKey }),
|
|
94
|
+
});
|
|
95
|
+
const assign = useMutation({
|
|
96
|
+
mutationKey: ["paseo-omp", "settings", ompStoreKey(store)],
|
|
97
|
+
mutationFn: async (next: Record<string, unknown>) => {
|
|
98
|
+
if (!settingsRevision) throw new Error("OMP settings cannot be edited without a revision.");
|
|
99
|
+
const input = updateOmpSettings.input.parse({
|
|
100
|
+
...(store ? { store } : {}),
|
|
101
|
+
revision: settingsRevision,
|
|
102
|
+
changes: [{ operation: "set", path: "modelRoles", value: next }],
|
|
103
|
+
});
|
|
104
|
+
return update(input);
|
|
105
|
+
},
|
|
106
|
+
onSuccess: (result) => onRolesChanged(result.catalog),
|
|
107
|
+
onError: () => onRolesChanged(undefined),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const busy = models.data?.models.some((model) => model.download === "running") === true;
|
|
111
|
+
const blocked = !settingsRevision || rolesPending || assign.isPending;
|
|
112
|
+
const failed = start.data && start.data.outcome !== "started";
|
|
113
|
+
|
|
114
|
+
function assignRole(role: string, selector: string | null) {
|
|
115
|
+
assign.mutate(withLocalModelRole(modelRoles, role, selector));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<View style={styles.card}>
|
|
120
|
+
<View style={styles.cardHeader}>
|
|
121
|
+
<Text style={styles.cardTitle}>OMP local models</Text>
|
|
122
|
+
</View>
|
|
123
|
+
<View style={styles.setting}>
|
|
124
|
+
<Text style={styles.settingDescription}>
|
|
125
|
+
Small models OMP runs on this machine for session titles and memory. They belong to OMP
|
|
126
|
+
only and are separate from Paseo's own Voice and Dictation models. Role changes apply to
|
|
127
|
+
new sessions or after a reload. A local titles role never falls back to an online model:
|
|
128
|
+
if the local model fails, the session stays untitled. The first download can also install
|
|
129
|
+
OMP's inference runtime, so it may take longer and use more disk than the model size.
|
|
130
|
+
</Text>
|
|
131
|
+
{models.error || (models.data && !models.data.available) ? (
|
|
132
|
+
<Text style={styles.error}>OMP could not list its local models.</Text>
|
|
133
|
+
) : null}
|
|
134
|
+
{start.error ? <Text style={styles.error}>Could not start the download.</Text> : null}
|
|
135
|
+
{failed ? (
|
|
136
|
+
<Text style={styles.error}>
|
|
137
|
+
{start.data?.outcome === "busy"
|
|
138
|
+
? "Another download is still running."
|
|
139
|
+
: "OMP could not start that download."}
|
|
140
|
+
</Text>
|
|
141
|
+
) : null}
|
|
142
|
+
{assign.error || (assign.data && (assign.data.conflict || assign.data.failed)) ? (
|
|
143
|
+
<Text style={styles.error}>
|
|
144
|
+
Could not change the role. Refresh the settings and try again.
|
|
145
|
+
</Text>
|
|
146
|
+
) : null}
|
|
147
|
+
</View>
|
|
148
|
+
{models.data?.models.map((model) => (
|
|
149
|
+
<View key={model.key} style={styles.setting}>
|
|
150
|
+
<View style={styles.settingHeader}>
|
|
151
|
+
<Text style={styles.cardTitle}>{model.label}</Text>
|
|
152
|
+
<Text style={styles.source}>{status(model)}</Text>
|
|
153
|
+
</View>
|
|
154
|
+
<Text selectable style={styles.settingPath}>
|
|
155
|
+
{model.key}
|
|
156
|
+
</Text>
|
|
157
|
+
<Text style={styles.settingDescription}>{model.description}</Text>
|
|
158
|
+
{confirming === model.key ? (
|
|
159
|
+
<View style={styles.recordList}>
|
|
160
|
+
<Text style={styles.settingDescription}>
|
|
161
|
+
Download {model.label}
|
|
162
|
+
{model.sizeMb ? ` (about ${model.sizeMb} MB)` : ""} to this machine? OMP shows no
|
|
163
|
+
progress, so this can take several minutes.
|
|
164
|
+
</Text>
|
|
165
|
+
<View style={ACTION_GROUP}>
|
|
166
|
+
<Choice
|
|
167
|
+
styles={styles}
|
|
168
|
+
label="Download"
|
|
169
|
+
accessibilityLabel={`Confirm download of ${model.label}`}
|
|
170
|
+
selected
|
|
171
|
+
disabled={busy || start.isPending}
|
|
172
|
+
onPress={() => {
|
|
173
|
+
setConfirming(null);
|
|
174
|
+
start.mutate(model.key);
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
<Choice
|
|
178
|
+
styles={styles}
|
|
179
|
+
label="Cancel"
|
|
180
|
+
accessibilityLabel={`Cancel download of ${model.label}`}
|
|
181
|
+
onPress={() => setConfirming(null)}
|
|
182
|
+
/>
|
|
183
|
+
</View>
|
|
184
|
+
</View>
|
|
185
|
+
) : (
|
|
186
|
+
<View style={ACTION_GROUP}>
|
|
187
|
+
<Choice
|
|
188
|
+
styles={styles}
|
|
189
|
+
label={model.downloaded ? "Download again" : "Download"}
|
|
190
|
+
accessibilityLabel={`Download ${model.label}`}
|
|
191
|
+
disabled={busy || start.isPending}
|
|
192
|
+
onPress={() => setConfirming(model.key)}
|
|
193
|
+
/>
|
|
194
|
+
{ROLES.map(({ role, label }) => {
|
|
195
|
+
const selector = `local/${model.key}`;
|
|
196
|
+
const assigned = modelRoles[role] === selector;
|
|
197
|
+
return (
|
|
198
|
+
<Choice
|
|
199
|
+
key={role}
|
|
200
|
+
styles={styles}
|
|
201
|
+
label={assigned ? `Using for ${label}` : `Use for ${label}`}
|
|
202
|
+
accessibilityLabel={`${assigned ? "Stop using" : "Use"} ${model.label} for ${label}`}
|
|
203
|
+
selected={assigned}
|
|
204
|
+
disabled={blocked}
|
|
205
|
+
onPress={() => assignRole(role, assigned ? null : selector)}
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
208
|
+
})}
|
|
209
|
+
</View>
|
|
210
|
+
)}
|
|
211
|
+
</View>
|
|
212
|
+
))}
|
|
213
|
+
</View>
|
|
214
|
+
);
|
|
215
|
+
}
|
package/index.server.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { OmpAccounts } from "./server/omp-accounts";
|
|
|
10
10
|
import { resolveListOmpAgents } from "./server/omp-agents";
|
|
11
11
|
import { resolveListOmpConfig } from "./server/omp-config";
|
|
12
12
|
import { resolveListOmpExtensions, resolveSetOmpExtensionEnabled } from "./server/omp-extensions";
|
|
13
|
+
import { resolveDownloadOmpLocalModel, resolveListOmpLocalModels } from "./server/omp-local-models";
|
|
13
14
|
import { OmpMcps } from "./server/omp-mcps";
|
|
14
15
|
import { resolveListOmpModels } from "./server/omp-models";
|
|
15
16
|
import { resolveGetOmpModelsFileStatus, resolveRefreshOmpModels } from "./server/omp-models-file";
|
|
@@ -74,6 +75,7 @@ import {
|
|
|
74
75
|
import { listOmpAgents } from "./shared/omp-agents";
|
|
75
76
|
import { listOmpConfig } from "./shared/omp-config";
|
|
76
77
|
import { listOmpExtensions, setOmpExtensionEnabled } from "./shared/omp-extensions";
|
|
78
|
+
import { downloadOmpLocalModel, listOmpLocalModels } from "./shared/omp-local-models";
|
|
77
79
|
import {
|
|
78
80
|
addOmpMcp,
|
|
79
81
|
cancelOmpMcpAuth,
|
|
@@ -232,6 +234,8 @@ export default function contribute(server: PluginServerContext) {
|
|
|
232
234
|
server.handle(mutateOmpPluginConfig, scoped(resolveMutateOmpPluginConfig));
|
|
233
235
|
server.handle(listOmpSettings, scoped(resolveListOmpSettings));
|
|
234
236
|
server.handle(updateOmpSettings, scoped(resolveUpdateOmpSettings));
|
|
237
|
+
server.handle(listOmpLocalModels, scoped(resolveListOmpLocalModels));
|
|
238
|
+
server.handle(downloadOmpLocalModel, scoped(resolveDownloadOmpLocalModel));
|
|
235
239
|
server.handle(getOmpProviderHealth, scoped(resolveGetOmpProviderHealth));
|
|
236
240
|
// Not `scoped`: the handler also needs the host context to read Paseo's Append system prompt.
|
|
237
241
|
server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
|
package/package.json
CHANGED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import {
|
|
7
|
+
type downloadOmpLocalModel,
|
|
8
|
+
type listOmpLocalModels,
|
|
9
|
+
OmpLocalModelKeySchema,
|
|
10
|
+
} from "../shared/omp-local-models";
|
|
11
|
+
import { resolveOmpExecutable } from "./omp-settings";
|
|
12
|
+
import { currentOmpEnvironment, ompAgentDir, ompCacheDir } from "./paths";
|
|
13
|
+
import {
|
|
14
|
+
type BoundedRun,
|
|
15
|
+
buildStatefulCommandEnv,
|
|
16
|
+
defaultSpawn,
|
|
17
|
+
runBounded,
|
|
18
|
+
} from "./provider-diagnostics";
|
|
19
|
+
|
|
20
|
+
const LIST_TIMEOUT_MS = 30_000;
|
|
21
|
+
const DOWNLOAD_TIMEOUT_MS = 30 * 60_000;
|
|
22
|
+
const KILL_GRACE_MS = 1_000;
|
|
23
|
+
const MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
const ListedModelsSchema = z.object({
|
|
26
|
+
models: z.array(
|
|
27
|
+
z.object({
|
|
28
|
+
key: z.string(),
|
|
29
|
+
repo: z.string(),
|
|
30
|
+
label: z.string(),
|
|
31
|
+
description: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const DownloadResultSchema = z.object({ results: z.array(z.object({ ok: z.boolean() })) });
|
|
37
|
+
|
|
38
|
+
export interface OmpLocalModelsDependencies {
|
|
39
|
+
resolveExecutable(): Promise<string | null>;
|
|
40
|
+
run(executable: string, args: readonly string[], timeoutMs: number): Promise<BoundedRun>;
|
|
41
|
+
/** True when OMP's cache folder already holds the model's repository. */
|
|
42
|
+
isCached(repo: string): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Where a download from a network that needs a proxy or a private CA still works. */
|
|
46
|
+
const NETWORK_VARIABLES = [
|
|
47
|
+
"HTTPS_PROXY",
|
|
48
|
+
"HTTP_PROXY",
|
|
49
|
+
"NO_PROXY",
|
|
50
|
+
"https_proxy",
|
|
51
|
+
"http_proxy",
|
|
52
|
+
"no_proxy",
|
|
53
|
+
"SSL_CERT_FILE",
|
|
54
|
+
"NODE_EXTRA_CA_CERTS",
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
function downloadEnvironment(): NodeJS.ProcessEnv {
|
|
58
|
+
const environment = currentOmpEnvironment();
|
|
59
|
+
const network = NETWORK_VARIABLES.flatMap((name) =>
|
|
60
|
+
environment[name] === undefined ? [] : [[name, environment[name]] as const],
|
|
61
|
+
);
|
|
62
|
+
return { ...buildStatefulCommandEnv(environment), ...Object.fromEntries(network) };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** OMP keeps its tiny models under `cache/tiny-models` of its cache root (the agent folder, or the XDG cache folder's omp). */
|
|
66
|
+
export function tinyModelPath(repo: string): string {
|
|
67
|
+
return join(ompCacheDir(), "cache", "tiny-models", ...repo.split("/"));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DEFAULT_DEPENDENCIES: OmpLocalModelsDependencies = {
|
|
71
|
+
resolveExecutable: resolveOmpExecutable,
|
|
72
|
+
run: (executable, args, timeoutMs) =>
|
|
73
|
+
runBounded(
|
|
74
|
+
defaultSpawn,
|
|
75
|
+
executable,
|
|
76
|
+
args,
|
|
77
|
+
downloadEnvironment(),
|
|
78
|
+
timeoutMs,
|
|
79
|
+
KILL_GRACE_MS,
|
|
80
|
+
MAX_OUTPUT_BYTES,
|
|
81
|
+
tmpdir(),
|
|
82
|
+
),
|
|
83
|
+
async isCached(repo) {
|
|
84
|
+
try {
|
|
85
|
+
return (await stat(tinyModelPath(repo))).isDirectory();
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
interface Job {
|
|
93
|
+
state: "running" | "failed";
|
|
94
|
+
error: string | null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Download progress lives here because a download outlasts the request that started it. */
|
|
98
|
+
const jobs = new Map<string, Job>();
|
|
99
|
+
|
|
100
|
+
function jobKey(key: string): string {
|
|
101
|
+
return `${ompAgentDir()}\0${key}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function anyRunning(): boolean {
|
|
105
|
+
const prefix = `${ompAgentDir()}\0`;
|
|
106
|
+
return [...jobs].some(([key, job]) => key.startsWith(prefix) && job.state === "running");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function sizeFrom(description: string): number | null {
|
|
110
|
+
const match = /(\d+(?:\.\d+)?)\s*MB/u.exec(description);
|
|
111
|
+
return match?.[1] ? Math.round(Number(match[1])) : null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function listModels(executable: string, dependencies: OmpLocalModelsDependencies) {
|
|
115
|
+
const result = await dependencies.run(
|
|
116
|
+
executable,
|
|
117
|
+
["tiny-models", "list", "--json"],
|
|
118
|
+
LIST_TIMEOUT_MS,
|
|
119
|
+
);
|
|
120
|
+
if (result.outcome !== "exited" || result.exitCode !== 0 || result.truncated) return null;
|
|
121
|
+
try {
|
|
122
|
+
const parsed = ListedModelsSchema.safeParse(JSON.parse(result.stdout));
|
|
123
|
+
return parsed.success ? parsed.data.models : null;
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function listOmpLocalModelsWithDependencies(
|
|
130
|
+
dependencies: OmpLocalModelsDependencies,
|
|
131
|
+
): Promise<RpcOutput<typeof listOmpLocalModels>> {
|
|
132
|
+
const executable = await dependencies.resolveExecutable();
|
|
133
|
+
const listed = executable ? await listModels(executable, dependencies) : null;
|
|
134
|
+
if (!listed) return { available: false, models: [] };
|
|
135
|
+
const models = await Promise.all(
|
|
136
|
+
listed
|
|
137
|
+
.filter((model) => OmpLocalModelKeySchema.safeParse(model.key).success)
|
|
138
|
+
.map(async (model) => {
|
|
139
|
+
const job = jobs.get(jobKey(model.key));
|
|
140
|
+
return {
|
|
141
|
+
key: model.key,
|
|
142
|
+
label: model.label,
|
|
143
|
+
description: model.description,
|
|
144
|
+
sizeMb: sizeFrom(model.description),
|
|
145
|
+
downloaded: await dependencies.isCached(model.repo),
|
|
146
|
+
download: job?.state ?? ("idle" as const),
|
|
147
|
+
error: job?.error ?? null,
|
|
148
|
+
};
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
return { available: true, models };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function finishDownload(name: string, result: BoundedRun): void {
|
|
155
|
+
const parsed = (() => {
|
|
156
|
+
try {
|
|
157
|
+
return DownloadResultSchema.safeParse(JSON.parse(result.stdout));
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
const ok =
|
|
163
|
+
result.outcome === "exited" &&
|
|
164
|
+
result.exitCode === 0 &&
|
|
165
|
+
parsed?.success === true &&
|
|
166
|
+
parsed.data.results.every((entry) => entry.ok);
|
|
167
|
+
if (ok) {
|
|
168
|
+
jobs.delete(name);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
jobs.set(name, {
|
|
172
|
+
state: "failed",
|
|
173
|
+
error: result.outcome === "timeout" ? "The download timed out." : "OMP could not download it.",
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function downloadOmpLocalModelWithDependencies(
|
|
178
|
+
input: RpcInput<typeof downloadOmpLocalModel>,
|
|
179
|
+
dependencies: OmpLocalModelsDependencies,
|
|
180
|
+
): Promise<RpcOutput<typeof downloadOmpLocalModel>> {
|
|
181
|
+
const executable = await dependencies.resolveExecutable();
|
|
182
|
+
if (!executable) return { outcome: "unavailable" };
|
|
183
|
+
const listed = await listModels(executable, dependencies);
|
|
184
|
+
if (!listed) return { outcome: "unavailable" };
|
|
185
|
+
if (!listed.some((model) => model.key === input.key)) return { outcome: "unknown-model" };
|
|
186
|
+
if (anyRunning()) return { outcome: "busy" };
|
|
187
|
+
|
|
188
|
+
const name = jobKey(input.key);
|
|
189
|
+
jobs.set(name, { state: "running", error: null });
|
|
190
|
+
void dependencies
|
|
191
|
+
.run(executable, ["tiny-models", "download", input.key, "--json"], DOWNLOAD_TIMEOUT_MS)
|
|
192
|
+
.then((result) => finishDownload(name, result));
|
|
193
|
+
return { outcome: "started" };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function resolveListOmpLocalModels() {
|
|
197
|
+
return listOmpLocalModelsWithDependencies(DEFAULT_DEPENDENCIES);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function resolveDownloadOmpLocalModel(input: RpcInput<typeof downloadOmpLocalModel>) {
|
|
201
|
+
return downloadOmpLocalModelWithDependencies(input, DEFAULT_DEPENDENCIES);
|
|
202
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Release Please keeps this bundle-safe constant aligned with package.json. */
|
|
2
|
-
export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.
|
|
2
|
+
export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.415.1"; // x-release-please-version
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
4
|
+
|
|
5
|
+
/** Model keys come from `omp tiny-models list`, for example `lfm2.5-230m` or `llama3.2:3b`. */
|
|
6
|
+
export const OmpLocalModelKeySchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/u);
|
|
7
|
+
|
|
8
|
+
export const OmpLocalModelSchema = z.object({
|
|
9
|
+
key: OmpLocalModelKeySchema,
|
|
10
|
+
label: z.string(),
|
|
11
|
+
description: z.string(),
|
|
12
|
+
/** Approximate download size parsed from OMP's description, when it names one. */
|
|
13
|
+
sizeMb: z.number().nullable(),
|
|
14
|
+
/** Found in OMP's cache folder. OMP's list does not report this itself. */
|
|
15
|
+
downloaded: z.boolean(),
|
|
16
|
+
download: z.enum(["idle", "running", "failed"]),
|
|
17
|
+
error: z.string().nullable(),
|
|
18
|
+
});
|
|
19
|
+
export type OmpLocalModel = z.infer<typeof OmpLocalModelSchema>;
|
|
20
|
+
|
|
21
|
+
export const listOmpLocalModels = defineRpc({
|
|
22
|
+
name: "paseo-omp.list-local-models",
|
|
23
|
+
input: z.object({ store: OmpStoreSchema.optional() }).strict(),
|
|
24
|
+
output: z.object({
|
|
25
|
+
available: z.boolean(),
|
|
26
|
+
models: z.array(OmpLocalModelSchema),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const downloadOmpLocalModel = defineRpc({
|
|
31
|
+
name: "paseo-omp.download-local-model",
|
|
32
|
+
input: z.object({ store: OmpStoreSchema.optional(), key: OmpLocalModelKeySchema }).strict(),
|
|
33
|
+
output: z.object({ outcome: z.enum(["started", "busy", "unknown-model", "unavailable"]) }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** The roles record with `role` pointed at `selector`, or removed when `selector` is null. */
|
|
37
|
+
export function withLocalModelRole(
|
|
38
|
+
roles: Readonly<Record<string, unknown>>,
|
|
39
|
+
role: string,
|
|
40
|
+
selector: string | null,
|
|
41
|
+
): Record<string, unknown> {
|
|
42
|
+
const { [role]: _replaced, ...rest } = roles;
|
|
43
|
+
return selector === null ? rest : { ...rest, [role]: selector };
|
|
44
|
+
}
|
package/shared/omp-settings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineRpc } from "@getpaseo/plugin";
|
|
1
|
+
import { defineRpc, type RpcOutput } from "@getpaseo/plugin";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { OmpWorkspaceCwdSchema } from "./hub";
|
|
4
4
|
import { OmpStoreSchema } from "./omp-store";
|
|
@@ -642,3 +642,6 @@ export const updateOmpSettings = defineRpc({
|
|
|
642
642
|
}),
|
|
643
643
|
}),
|
|
644
644
|
});
|
|
645
|
+
|
|
646
|
+
/** The settings catalog an update returns, which a cache can take in place of a refetch. */
|
|
647
|
+
export type OmpSettingsCatalog = RpcOutput<typeof updateOmpSettings>["catalog"];
|