@omercnet/paseo-omp 5.4.0-next.413.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/OVERVIEW.md CHANGED
@@ -19,6 +19,7 @@ OMP adds an agent provider for the OMP coding agent, plus an OMP sidebar and wor
19
19
  - When an agent on Paseo's bundled `omp` provider calls OMP's `lsp` tool for diagnostics, the call shows as a card grouped by file with an icon per severity. Output the plugin does not recognize keeps the original row.
20
20
  - When an agent on Paseo's bundled `omp` provider generates an image with OMP's `generate_image` tool, the row shows the image with a Download button on web and desktop. The plugin reads the saved `omp-image-*` file from the daemon host's temp directory, so the image is gone once the host cleans that directory.
21
21
  - When an agent on Paseo's bundled `omp` provider previews an OMP `ast_edit` rewrite, the call shows as a read-only diff card per file. It is built from the preview text and does not apply or discard anything; OMP's follow-up `xd://resolve` or `xd://reject` write stays a separate row. A preview the plugin cannot parse keeps the original row.
22
+ - When an agent on Paseo's bundled `omp` provider takes screenshots in an `eval` cell, a **Screenshots** row under that turn shows them. The bundled provider keeps only the text of `eval`, so the plugin reads the screenshot blobs from the end of the agent's OMP session file after the turn, copies them into its image cache, and shows them once the turn ends, not live. Rows do not survive a daemon restart.
22
23
  - OMP agents can call Paseo's orchestration tools with the optional `serverId` argument and `list_hosts` to delegate work to other connected Paseo hosts.
23
24
 
24
25
  ## Reads and sends
@@ -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";
@@ -47,13 +48,15 @@ import { OmpPublicError } from "./server/provider/security";
47
48
  import { OmpSessionLimit } from "./server/provider/session-limit";
48
49
  import { resolveGetOmpProviderHealth } from "./server/provider-diagnostics";
49
50
  import { resolveListOmpQuotas } from "./server/quota";
50
- import { registerOmpRuleNotices } from "./server/rule-notices";
51
+ import { ompRuleNoticeRow } from "./server/rule-notices";
51
52
  import {
52
53
  OmpSubagentControlRegistry,
53
54
  resolveCancelOmpSubagent,
54
55
  resolveSteerOmpSubagent,
55
56
  } from "./server/subagents";
56
57
  import { resolveGetOmpSupportReport } from "./server/support-diagnostics";
58
+ import { registerOmpTurnRows } from "./server/turn-rows";
59
+ import { ompScreenshotRow } from "./server/turn-screenshots";
57
60
  import { composerPillSettings } from "./shared/composer-pill-settings";
58
61
  import { resolveOmpGeneratedImages } from "./shared/generated-image";
59
62
  import { listHubProcesses, tailHubLog } from "./shared/hub";
@@ -72,6 +75,7 @@ import {
72
75
  import { listOmpAgents } from "./shared/omp-agents";
73
76
  import { listOmpConfig } from "./shared/omp-config";
74
77
  import { listOmpExtensions, setOmpExtensionEnabled } from "./shared/omp-extensions";
78
+ import { downloadOmpLocalModel, listOmpLocalModels } from "./shared/omp-local-models";
75
79
  import {
76
80
  addOmpMcp,
77
81
  cancelOmpMcpAuth,
@@ -230,6 +234,8 @@ export default function contribute(server: PluginServerContext) {
230
234
  server.handle(mutateOmpPluginConfig, scoped(resolveMutateOmpPluginConfig));
231
235
  server.handle(listOmpSettings, scoped(resolveListOmpSettings));
232
236
  server.handle(updateOmpSettings, scoped(resolveUpdateOmpSettings));
237
+ server.handle(listOmpLocalModels, scoped(resolveListOmpLocalModels));
238
+ server.handle(downloadOmpLocalModel, scoped(resolveDownloadOmpLocalModel));
233
239
  server.handle(getOmpProviderHealth, scoped(resolveGetOmpProviderHealth));
234
240
  // Not `scoped`: the handler also needs the host context to read Paseo's Append system prompt.
235
241
  server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
@@ -259,7 +265,7 @@ export default function contribute(server: PluginServerContext) {
259
265
  server.handle(steerOmpSubagent, (input) =>
260
266
  resolveSteerOmpSubagent(input, subagentControlRegistry),
261
267
  );
262
- const removeRuleNotices = registerOmpRuleNotices(server);
268
+ const removeTurnRows = registerOmpTurnRows(server, [ompRuleNoticeRow, ompScreenshotRow]);
263
269
  const removeSessionOpenHook = server.before("agent.session_open", ({ request }) => {
264
270
  if (request.provider !== "omp-plugin" && !request.provider.startsWith("omp-plugin-")) return;
265
271
  return withOmpSessionOpenEnv(request);
@@ -280,7 +286,7 @@ export default function contribute(server: PluginServerContext) {
280
286
  mcps.stop();
281
287
  removeSessionLimitListener();
282
288
  subagentControlRegistry.clear();
283
- removeRuleNotices();
289
+ removeTurnRows();
284
290
  removeSessionOpenHook();
285
291
  };
286
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.4.0-next.413.1",
3
+ "version": "5.4.0-next.415.1",
4
4
  "type": "module",
5
5
  "description": "Paseo integration for OMP, including its direct provider and workspace tooling.",
6
6
  "license": "MIT",
@@ -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.413.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.415.1"; // x-release-please-version
@@ -1,7 +1,6 @@
1
1
  import { constants } from "node:fs";
2
2
  import { type FileHandle, open } from "node:fs/promises";
3
3
  import { isAbsolute } from "node:path";
4
- import type { PluginServerContext } from "@getpaseo/plugin/server";
5
4
  import {
6
5
  MAX_OMP_RULE_NOTICE_RULES,
7
6
  OMP_RULE_MATCH_MAX_LENGTH,
@@ -9,8 +8,9 @@ import {
9
8
  OMP_RULE_NOTICE_KIND,
10
9
  type OmpRuleNotice,
11
10
  } from "../shared/rule-notices";
11
+ import type { OmpTurnRow } from "./turn-rows";
12
12
 
13
- /** Rule firings are read from the end of the session file; a turn rarely writes more. */
13
+ /** Turn rows are read from the end of the session file; a turn rarely writes more. */
14
14
  const TAIL_BYTES = 1024 * 1024;
15
15
 
16
16
  function bounded(value: string, max: number): string {
@@ -23,7 +23,7 @@ function stringArray(value: unknown): string[] {
23
23
  : [];
24
24
  }
25
25
 
26
- async function readTail(file: string): Promise<string | undefined> {
26
+ export async function readTail(file: string): Promise<string | undefined> {
27
27
  let handle: FileHandle;
28
28
  try {
29
29
  handle = await open(
@@ -100,38 +100,13 @@ export async function readOmpRuleNotice(
100
100
  };
101
101
  }
102
102
 
103
- /** Paseo's bundled `omp` provider drops OMP rule events, so surface them from its session file. */
104
- export function registerOmpRuleNotices(server: Pick<PluginServerContext, "addHook">): () => void {
105
- // One Paseo turn can report several native turn starts; keep the earliest. Hooks run
106
- // concurrently, so state is read and cleared before the first await.
107
- const turnStarts = new Map<string, number>();
108
- const turnKey = (agentId: string, turnId: string | null) => `${agentId}\0${turnId ?? ""}`;
109
- const removeBefore = server.addHook("agent.turn.before", async ({ agent, turnId }) => {
110
- const key = turnKey(agent.id, turnId);
111
- if (agent.provider === "omp" && !turnStarts.has(key)) turnStarts.set(key, Date.now());
112
- });
113
- const removeAfter = server.addHook("agent.turn.after", async ({ agent, turnId }, { paseo }) => {
114
- const key = turnKey(agent.id, turnId);
115
- const since = turnStarts.get(key);
116
- const until = Date.now();
117
- turnStarts.delete(key);
118
- if (agent.provider !== "omp" || since === undefined) return;
119
- const ref = paseo.agents.ref(agent.id);
120
- const sessionFile = (await ref.refresh())?.agent.persistence?.nativeHandle;
121
- if (!sessionFile) return;
122
- const found = await readOmpRuleNotice(sessionFile, since, until);
123
- if (!found) return;
124
- await ref.timeline.append({
125
- type: "plugin",
126
- id: `rule-notice:${found.id}`,
127
- kind: OMP_RULE_NOTICE_KIND,
128
- version: 1,
129
- data: found.notice,
130
- });
131
- });
132
- return () => {
133
- removeBefore();
134
- removeAfter();
135
- turnStarts.clear();
136
- };
103
+ /** The OMP rule notice of one turn as a timeline row; Paseo's bundled `omp` provider drops rule events. */
104
+ export async function ompRuleNoticeRow(
105
+ sessionFile: string,
106
+ since: number,
107
+ until: number,
108
+ ): Promise<OmpTurnRow | undefined> {
109
+ const found = await readOmpRuleNotice(sessionFile, since, until);
110
+ if (!found) return;
111
+ return { id: `rule-notice:${found.id}`, kind: OMP_RULE_NOTICE_KIND, data: found.notice };
137
112
  }
@@ -0,0 +1,59 @@
1
+ import type { PluginServerContext } from "@getpaseo/plugin/server";
2
+ import type { JsonValue } from "@getpaseo/protocol/agent-types";
3
+
4
+ export interface OmpTurnRow {
5
+ id: string;
6
+ kind: string;
7
+ data: JsonValue;
8
+ }
9
+
10
+ /** Reads one row from an OMP session file for the turn between `since` and `until` (epoch ms). */
11
+ export type OmpTurnRowReader = (
12
+ sessionFile: string,
13
+ since: number,
14
+ until: number,
15
+ ) => Promise<OmpTurnRow | undefined>;
16
+
17
+ /**
18
+ * Paseo's bundled `omp` provider drops parts of what OMP persists to its session file. After each
19
+ * turn of such an agent, every reader may append one timeline row built from that file.
20
+ */
21
+ export function registerOmpTurnRows(
22
+ server: Pick<PluginServerContext, "addHook">,
23
+ readers: readonly OmpTurnRowReader[],
24
+ ): () => void {
25
+ // One Paseo turn can report several native turn starts; keep the earliest. Hooks run
26
+ // concurrently, so state is read and cleared before the first await.
27
+ const turnStarts = new Map<string, number>();
28
+ const turnKey = (agentId: string, turnId: string | null) => `${agentId}\0${turnId ?? ""}`;
29
+ const removeBefore = server.addHook("agent.turn.before", async ({ agent, turnId }) => {
30
+ const key = turnKey(agent.id, turnId);
31
+ if (agent.provider === "omp" && !turnStarts.has(key)) turnStarts.set(key, Date.now());
32
+ });
33
+ const removeAfter = server.addHook("agent.turn.after", async ({ agent, turnId }, { paseo }) => {
34
+ const key = turnKey(agent.id, turnId);
35
+ const since = turnStarts.get(key);
36
+ const until = Date.now();
37
+ turnStarts.delete(key);
38
+ if (agent.provider !== "omp" || since === undefined) return;
39
+ const ref = paseo.agents.ref(agent.id);
40
+ const sessionFile = (await ref.refresh())?.agent.persistence?.nativeHandle;
41
+ if (!sessionFile) return;
42
+ for (const read of readers) {
43
+ const row = await read(sessionFile, since, until);
44
+ if (!row) continue;
45
+ await ref.timeline.append({
46
+ type: "plugin",
47
+ id: row.id,
48
+ kind: row.kind,
49
+ version: 1,
50
+ data: row.data,
51
+ });
52
+ }
53
+ });
54
+ return () => {
55
+ removeBefore();
56
+ removeAfter();
57
+ turnStarts.clear();
58
+ };
59
+ }
@@ -0,0 +1,140 @@
1
+ import { createHash } from "node:crypto";
2
+ import { isAbsolute, join } from "node:path";
3
+ import { setImmediate as yieldToEventLoop } from "node:timers/promises";
4
+ import { z } from "zod";
5
+ import { OMP_IMAGE_TIMELINE_KIND, ompImageTimelineSchema } from "../shared/provider-image";
6
+ import { ompDataDir } from "./paths";
7
+ import { isOmpImageMimeType, isValidImagePayload, type OmpImageMimeType } from "./provider/image";
8
+ import { MAX_CACHED_IMAGE_BYTES, type OmpImageCache, ompImageCache } from "./provider/image-cache";
9
+ import { readRegularFile } from "./regular-file";
10
+ import { readTail } from "./rule-notices";
11
+ import type { OmpTurnRow } from "./turn-rows";
12
+
13
+ const BLOB_REFERENCE = /^blob:sha256:([0-9a-f]{64})$/u;
14
+ const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/u;
15
+ /** OMP moves image data of 1,024 or more base64 characters into a blob; shorter stays inline. */
16
+ const MAX_INLINE_BASE64_LENGTH = 1_023;
17
+ const MAX_SCREENSHOTS = 16;
18
+ const LABEL = "Screenshots";
19
+
20
+ interface ScreenshotImage {
21
+ /** SHA-256 of the image bytes; names the blob file. */
22
+ hash: string;
23
+ mimeType: OmpImageMimeType;
24
+ /** Present for an image persisted inline instead of as a blob. */
25
+ bytes?: Buffer;
26
+ }
27
+
28
+ const evalResultEntrySchema = z.object({
29
+ id: z.string(),
30
+ timestamp: z.string(),
31
+ message: z.object({
32
+ role: z.literal("toolResult"),
33
+ toolName: z.literal("eval"),
34
+ content: z.array(
35
+ z.looseObject({
36
+ type: z.string(),
37
+ data: z.string().optional(),
38
+ mimeType: z.string().optional(),
39
+ }),
40
+ ),
41
+ }),
42
+ });
43
+
44
+ /** One persisted `eval` tool result: its image blocks, as blob references or small inline data. */
45
+ function parseEvalResult(
46
+ line: string,
47
+ ): { id: string; at: number; images: ScreenshotImage[] } | undefined {
48
+ let json: unknown;
49
+ try {
50
+ json = JSON.parse(line);
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ const entry = evalResultEntrySchema.safeParse(json);
55
+ if (!entry.success) return undefined;
56
+ const images = entry.data.message.content.flatMap((block): ScreenshotImage[] => {
57
+ const mimeType = block.mimeType ?? "";
58
+ const data = block.data ?? "";
59
+ if (block.type !== "image" || !isOmpImageMimeType(mimeType)) return [];
60
+ const hash = BLOB_REFERENCE.exec(data)?.[1];
61
+ if (hash) return [{ hash, mimeType }];
62
+ if (data.length > MAX_INLINE_BASE64_LENGTH || !BASE64.test(data)) return [];
63
+ const bytes = Buffer.from(data, "base64");
64
+ return [{ hash: createHash("sha256").update(bytes).digest("hex"), mimeType, bytes }];
65
+ });
66
+ return { id: entry.data.id, at: Date.parse(entry.data.timestamp), images };
67
+ }
68
+
69
+ function copyToCache(
70
+ directory: string,
71
+ image: ScreenshotImage,
72
+ cache: OmpImageCache,
73
+ ): string | undefined {
74
+ const bytes = image.bytes ?? readRegularFile(join(directory, image.hash), MAX_CACHED_IMAGE_BYTES);
75
+ if (!bytes || createHash("sha256").update(bytes).digest("hex") !== image.hash) return undefined;
76
+ // Only the magic bytes are checked, so encode only the header (12 bytes are 16 characters).
77
+ if (!isValidImagePayload(bytes.subarray(0, 12).toString("base64"), image.mimeType, 16)) {
78
+ return undefined;
79
+ }
80
+ return cache.store(bytes, image.mimeType);
81
+ }
82
+
83
+ /**
84
+ * The `eval` screenshots of the turn between `since` and `until` (epoch ms). OMP persists each as
85
+ * a content-addressed file in `blobDirectory` (or inline when it is tiny); they are copied into
86
+ * the image cache so the row can name them by cache reference and the stock image renderer shows
87
+ * them.
88
+ */
89
+ export async function readOmpScreenshots(
90
+ sessionFile: string,
91
+ since: number,
92
+ until: number,
93
+ cache: OmpImageCache,
94
+ blobDirectory: string,
95
+ ): Promise<OmpTurnRow | undefined> {
96
+ if (!isAbsolute(sessionFile) || !sessionFile.endsWith(".jsonl")) return;
97
+ const tail = await readTail(sessionFile);
98
+ if (!tail) return;
99
+ let id: string | undefined;
100
+ const found: ScreenshotImage[] = [];
101
+ for (const line of tail.split("\n")) {
102
+ if (!line.includes("toolResult")) continue;
103
+ const result = parseEvalResult(line);
104
+ if (!result || !(result.at >= since && result.at <= until) || result.images.length === 0)
105
+ continue;
106
+ id ??= result.id;
107
+ found.push(...result.images);
108
+ }
109
+ if (!id) return;
110
+ const unique = new Map(found.map((image) => [image.hash, image]));
111
+ const images: z.infer<typeof ompImageTimelineSchema>["images"] = [];
112
+ for (const image of unique.values()) {
113
+ if (images.length >= MAX_SCREENSHOTS) break;
114
+ const ref = copyToCache(blobDirectory, image, cache);
115
+ if (ref) images.push({ id: ref.slice(0, 16), ref, mimeType: image.mimeType });
116
+ // Each copy reads and hashes up to 6 MiB synchronously; let other daemon work run between images.
117
+ await yieldToEventLoop();
118
+ }
119
+ if (images.length === 0) return;
120
+ return {
121
+ id: `screenshots:${id}`,
122
+ kind: OMP_IMAGE_TIMELINE_KIND,
123
+ data: ompImageTimelineSchema.parse({ label: LABEL, images }),
124
+ };
125
+ }
126
+
127
+ /** Paseo's bundled `omp` provider keeps only the text of `eval`, so its screenshots are read from the session file. */
128
+ export function ompScreenshotRow(
129
+ sessionFile: string,
130
+ since: number,
131
+ until: number,
132
+ ): Promise<OmpTurnRow | undefined> {
133
+ return readOmpScreenshots(
134
+ sessionFile,
135
+ since,
136
+ until,
137
+ ompImageCache(),
138
+ join(ompDataDir(), "blobs"),
139
+ );
140
+ }
@@ -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
+ }
@@ -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"];
@@ -109,6 +109,8 @@ const inlineOmpImageSchema = z.object({
109
109
  const ompImageSchema = z.union([cachedOmpImageSchema, inlineOmpImageSchema]);
110
110
  export type OmpImage = z.infer<typeof ompImageSchema>;
111
111
 
112
+ export const OMP_IMAGE_TIMELINE_KIND = "omp-images";
113
+
112
114
  export const getOmpImage = defineRpc({
113
115
  name: "paseo-omp.get-image",
114
116
  input: z.strictObject({ ref: ompImageRefSchema, mimeType: ompImageMimeTypeSchema }),
@@ -200,7 +202,7 @@ export function transformOmpImageToolItem(item: { callId: string; metadata?: unk
200
202
  items: [
201
203
  {
202
204
  type: "plugin" as const,
203
- kind: "omp-images",
205
+ kind: OMP_IMAGE_TIMELINE_KIND,
204
206
  id: item.callId,
205
207
  version: 1,
206
208
  data: metadata.data.ompImage,