@omercnet/paseo-omp 5.4.0-next.409.1 → 5.4.0-next.410.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.
@@ -14,6 +14,7 @@ import type { ComposerPillSettings } from "../shared/composer-pill-settings";
14
14
  import { listOmpAgents } from "../shared/omp-agents";
15
15
  import { listOmpConfig, type OmpConfig } from "../shared/omp-config";
16
16
  import { listOmpModels } from "../shared/omp-models";
17
+ import { getOmpModelsFileStatus, refreshOmpModels } from "../shared/omp-models-file";
17
18
  import { getOmpPromptFiles } from "../shared/omp-prompt-files";
18
19
  import {
19
20
  categorizeOmpSetting,
@@ -34,7 +35,7 @@ import { getOmpProviderHealth, type OmpProviderHealth } from "../shared/provider
34
35
  import { getOmpSupportReport, OMP_SUPPORT_ISSUE_URL } from "../shared/support-diagnostics";
35
36
  import { ComposerPillSettingsSection } from "./composer-pill-settings";
36
37
  import { openOmpExternalUrl } from "./external-url";
37
- import { OmpAccountsSection } from "./omp-accounts-section";
38
+ import { ActionButton, OmpAccountsSection } from "./omp-accounts-section";
38
39
  import { type OmpConfigStyles, useConfigStyles } from "./omp-config-styles";
39
40
  import { type OmpConfigSurfaceView as SurfaceView, surfaceViewsForScope } from "./omp-config-views";
40
41
  import {
@@ -89,6 +90,7 @@ const SETTINGS_QUERY_KEY = ["paseo-omp", "settings"] as const;
89
90
  const CONFIG_POLL_MS = 30_000;
90
91
  const HEALTH_QUERY_KEY = ["paseo-omp", "provider-health"] as const;
91
92
  const PROMPT_FILES_QUERY_KEY = ["paseo-omp", "prompt-files"] as const;
93
+ const MODELS_FILE_QUERY_KEY = ["paseo-omp", "models-file"] as const;
92
94
  const PROVIDERS_QUERY_KEY = ["paseo-omp", "provider-snapshot"] as const;
93
95
 
94
96
  function KeyValueRow({
@@ -416,6 +418,72 @@ function PromptFilesSection({
416
418
  );
417
419
  }
418
420
 
421
+ function ModelsSection({
422
+ theme,
423
+ styles,
424
+ store,
425
+ onRefreshed,
426
+ }: {
427
+ theme: PluginSurfaceProps["theme"];
428
+ styles: OmpConfigStyles;
429
+ store?: OmpStore;
430
+ onRefreshed(): void;
431
+ }) {
432
+ const loadStatus = useRpc(getOmpModelsFileStatus);
433
+ const refreshModels = useRpc(refreshOmpModels);
434
+ const status = useQuery({
435
+ queryKey: [...MODELS_FILE_QUERY_KEY, ompStoreKey(store)],
436
+ queryFn: () => loadStatus({ store }),
437
+ });
438
+ const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null);
439
+ const refresh = useMutation({
440
+ mutationFn: () => refreshModels({ store }),
441
+ onSuccess: (result) => {
442
+ setMessage({
443
+ ok: result.ok,
444
+ text: result.ok
445
+ ? "OMP refreshed its model lists. Paseo's list updates next."
446
+ : result.message,
447
+ });
448
+ if (result.ok) onRefreshed();
449
+ },
450
+ onError: () => setMessage({ ok: false, text: "Could not refresh models. Try again." }),
451
+ });
452
+ const current = status.data;
453
+ return (
454
+ <SectionCard styles={styles} title="Models">
455
+ {status.isLoading ? <Text style={styles.muted}>Checking models.yml…</Text> : null}
456
+ {current?.state === "ok" ? (
457
+ <KeyValueRow styles={styles} label="models.yml" value="No errors reported" />
458
+ ) : null}
459
+ {current?.state === "invalid" ? (
460
+ <KeyValueRow
461
+ styles={styles}
462
+ label="models.yml"
463
+ value={`OMP dropped your custom providers: ${current.detail}`}
464
+ valueColor={theme.colors.statusDanger}
465
+ />
466
+ ) : null}
467
+ {current?.state === "unknown" || status.error ? (
468
+ <KeyValueRow styles={styles} label="models.yml" value="Could not check" />
469
+ ) : null}
470
+ <View style={styles.row}>
471
+ <Text style={styles.rowLabel}>Model lists</Text>
472
+ <ActionButton
473
+ styles={styles}
474
+ theme={theme}
475
+ label={refresh.isPending ? "Refreshing models…" : "Refresh models"}
476
+ disabled={refresh.isPending}
477
+ onPress={() => refresh.mutate()}
478
+ />
479
+ </View>
480
+ {message ? (
481
+ <Text style={message.ok ? styles.muted : styles.error}>{message.text}</Text>
482
+ ) : null}
483
+ </SectionCard>
484
+ );
485
+ }
486
+
419
487
  function ProviderHealthSection({
420
488
  theme,
421
489
  styles,
@@ -459,6 +527,7 @@ function ProviderHealthSection({
459
527
  ]);
460
528
  if (update) queryClient.setQueryData(UPDATE_QUERY_KEY, update);
461
529
  await queryClient.invalidateQueries({ queryKey: PROMPT_FILES_QUERY_KEY });
530
+ await queryClient.invalidateQueries({ queryKey: MODELS_FILE_QUERY_KEY });
462
531
  if (result.failed) throw new Error("Could not fully refresh OMP provider health.");
463
532
  },
464
533
  });
@@ -515,6 +584,15 @@ function ProviderHealthSection({
515
584
  {health.data ? <StorageSection theme={theme} styles={styles} health={health.data} /> : null}
516
585
  {health.data ? <ProcessSection theme={theme} styles={styles} health={health.data} /> : null}
517
586
  <PromptFilesSection theme={theme} styles={styles} cwd={cwd} store={store} />
587
+ <ModelsSection
588
+ theme={theme}
589
+ styles={styles}
590
+ store={store}
591
+ onRefreshed={() => {
592
+ void queryClient.invalidateQueries({ queryKey: ["paseo-omp", "models"] });
593
+ refresh.mutate();
594
+ }}
595
+ />
518
596
 
519
597
  {providers.isLoading ? <Text style={styles.muted}>Loading provider status…</Text> : null}
520
598
  {providers.error ? (
package/index.server.ts CHANGED
@@ -12,6 +12,7 @@ import { resolveListOmpConfig } from "./server/omp-config";
12
12
  import { resolveListOmpExtensions, resolveSetOmpExtensionEnabled } from "./server/omp-extensions";
13
13
  import { OmpMcps } from "./server/omp-mcps";
14
14
  import { resolveListOmpModels } from "./server/omp-models";
15
+ import { resolveGetOmpModelsFileStatus, resolveRefreshOmpModels } from "./server/omp-models-file";
15
16
  import {
16
17
  resolveBrowseOmpMarketplace,
17
18
  resolveInspectOmpPluginConfig,
@@ -79,6 +80,7 @@ import {
79
80
  submitOmpMcpAuthCode,
80
81
  } from "./shared/omp-mcps";
81
82
  import { listOmpModels } from "./shared/omp-models";
83
+ import { getOmpModelsFileStatus, refreshOmpModels } from "./shared/omp-models-file";
82
84
  import {
83
85
  browseOmpMarketplace,
84
86
  inspectOmpPluginConfig,
@@ -230,6 +232,11 @@ export default function contribute(server: PluginServerContext) {
230
232
  server.handle(getOmpPromptFiles, ({ store, cwd }, { paseo }) =>
231
233
  withOmpStore(store, async () => readOmpPromptFiles(cwd, await readHostAppendPrompt(paseo))),
232
234
  );
235
+ server.handle(getOmpModelsFileStatus, scoped(resolveGetOmpModelsFileStatus));
236
+ server.handle(
237
+ refreshOmpModels,
238
+ scoped(async (input) => resolveRefreshOmpModels(input, await resolveHostInheritEnv())),
239
+ );
233
240
  server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
234
241
  server.handle(installOmpUpdate, resolveInstallOmpUpdate);
235
242
  server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.4.0-next.409.1",
3
+ "version": "5.4.0-next.410.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,178 @@
1
+ import { tmpdir } from "node:os";
2
+ import type { RpcInput } from "@getpaseo/plugin";
3
+ import type {
4
+ getOmpModelsFileStatus,
5
+ OmpModelsFileStatus,
6
+ refreshOmpModels,
7
+ } from "../shared/omp-models-file";
8
+ import { SerialMutationQueue } from "./mutation-queue";
9
+ import { resolveOmpExecutable } from "./omp-settings";
10
+ import { currentOmpEnvironment } from "./paths";
11
+ import { buildOmpEnvironment } from "./provider/omp-rpc-environment";
12
+ import {
13
+ type BoundedRun,
14
+ buildStatefulCommandEnv,
15
+ defaultSpawn,
16
+ runBounded,
17
+ } from "./provider-diagnostics";
18
+
19
+ const CHECK_TIMEOUT_MS = 30_000;
20
+ const REFRESH_TIMEOUT_MS = 90_000;
21
+ const KILL_GRACE_MS = 1_000;
22
+ const MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
23
+ const MAX_STDERR_BYTES = 16 * 1024;
24
+ const MAX_DETAIL_CHARS = 300;
25
+
26
+ export interface OmpModelsDependencies {
27
+ resolveExecutable(): Promise<string | null>;
28
+ run(
29
+ executable: string,
30
+ args: readonly string[],
31
+ timeoutMs: number,
32
+ stderrLimit: number,
33
+ providerEnvironment: boolean,
34
+ ): Promise<BoundedRun>;
35
+ }
36
+
37
+ /**
38
+ * A refresh asks hosted catalogs for their lists with the API keys Paseo's own omp provider
39
+ * would hand OMP, so it gets that launch environment (runtime variables, provider-auth families
40
+ * and the host's inherited names; loader controls and other daemon secrets stay out). The
41
+ * models.yml check only needs the stateful probe environment.
42
+ */
43
+ export function modelsEnvironment(
44
+ providerEnvironment: boolean,
45
+ inheritEnv: readonly string[] = [],
46
+ ): NodeJS.ProcessEnv {
47
+ const source = currentOmpEnvironment();
48
+ if (!providerEnvironment) return buildStatefulCommandEnv(source);
49
+ const { env } = buildOmpEnvironment(undefined, inheritEnv, source);
50
+ env.NO_COLOR = "1";
51
+ return env;
52
+ }
53
+
54
+ function runOmp(
55
+ executable: string,
56
+ args: readonly string[],
57
+ timeoutMs: number,
58
+ stderrLimit: number,
59
+ providerEnvironment: boolean,
60
+ inheritEnv: readonly string[],
61
+ ): Promise<BoundedRun> {
62
+ return runBounded(
63
+ defaultSpawn,
64
+ executable,
65
+ args,
66
+ modelsEnvironment(providerEnvironment, inheritEnv),
67
+ timeoutMs,
68
+ KILL_GRACE_MS,
69
+ MAX_OUTPUT_BYTES,
70
+ tmpdir(),
71
+ stderrLimit,
72
+ );
73
+ }
74
+
75
+ function dependenciesFor(inheritEnv: readonly string[]): OmpModelsDependencies {
76
+ return {
77
+ resolveExecutable: resolveOmpExecutable,
78
+ run: (executable, args, timeoutMs, stderrLimit, providerEnvironment) =>
79
+ runOmp(executable, args, timeoutMs, stderrLimit, providerEnvironment, inheritEnv),
80
+ };
81
+ }
82
+
83
+ function succeeded(run: BoundedRun): boolean {
84
+ return (
85
+ run.outcome === "exited" &&
86
+ run.exitCode === 0 &&
87
+ run.signal === null &&
88
+ !run.truncated &&
89
+ !run.cleanupFailed
90
+ );
91
+ }
92
+
93
+ // OMP prints these lines to stderr and exits 0 when it drops a bad models.yml:
94
+ // Warning: models.yml validation failed ...
95
+ // Failed to load config file models, <label>: <message>
96
+ // and a schema error may continue with indented " - <path>: <message>" lines.
97
+ const WARNING_LINE = /^Warning: models\.yml validation failed/m;
98
+ const FAILURE_PREFIX = /^Failed to load config file models, [^:]*:\s*/;
99
+ const BULLET = /^\s+- /;
100
+ // Schema errors echo the offending value as "(was ...)": a key in the wrong field would leak.
101
+ const ECHOED_VALUE = /\s*\(was .*\)\s*$/;
102
+
103
+ /** Reads OMP's models.yml warning. The detail is bounded, free of control characters and values. */
104
+ export function parseOmpModelsWarning(stderr: string): OmpModelsFileStatus {
105
+ if (!WARNING_LINE.test(stderr)) return { state: "ok" };
106
+ const lines = stderr.split(/\r?\n/);
107
+ const start = lines.findIndex((line) => FAILURE_PREFIX.test(line));
108
+ const pieces: string[] = [];
109
+ if (start >= 0) {
110
+ pieces.push((lines[start] ?? "").replace(FAILURE_PREFIX, ""));
111
+ for (const line of lines.slice(start + 1)) {
112
+ if (!BULLET.test(line)) break;
113
+ pieces.push(line.replace(BULLET, ""));
114
+ }
115
+ }
116
+ const detail = pieces
117
+ .map((piece) => piece.replace(ECHOED_VALUE, "").trim())
118
+ .filter((piece) => piece !== "")
119
+ .join("; ");
120
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: strips terminal control characters
121
+ const clean = detail.replace(/[\u0000-\u001f\u007f]/g, " ");
122
+ return {
123
+ state: "invalid",
124
+ detail: (clean || "OMP could not load it").slice(0, MAX_DETAIL_CHARS),
125
+ };
126
+ }
127
+
128
+ export async function getOmpModelsFileStatusWithDependencies(
129
+ dependencies: OmpModelsDependencies,
130
+ ): Promise<OmpModelsFileStatus> {
131
+ const executable = await dependencies.resolveExecutable();
132
+ if (!executable) return { state: "unknown" };
133
+ const run = await dependencies.run(
134
+ executable,
135
+ ["models", "--json", "--no-extensions"],
136
+ CHECK_TIMEOUT_MS,
137
+ MAX_STDERR_BYTES,
138
+ false,
139
+ );
140
+ return succeeded(run) ? parseOmpModelsWarning(run.stderr ?? "") : { state: "unknown" };
141
+ }
142
+
143
+ function refreshMessage(run: BoundedRun): string {
144
+ if (run.cleanupFailed) return "OMP models process cleanup could not be confirmed.";
145
+ if (run.outcome === "timeout") return "OMP took too long to refresh its model lists.";
146
+ if (!succeeded(run)) return "OMP could not refresh its model lists.";
147
+ return "OMP refreshed its model lists.";
148
+ }
149
+
150
+ export async function refreshOmpModelsWithDependencies(
151
+ dependencies: OmpModelsDependencies,
152
+ ): Promise<{ ok: boolean; message: string }> {
153
+ const executable = await dependencies.resolveExecutable();
154
+ if (!executable) return { ok: false, message: "The OMP executable could not be resolved." };
155
+ const run = await dependencies.run(
156
+ executable,
157
+ ["models", "refresh", "--no-extensions"],
158
+ REFRESH_TIMEOUT_MS,
159
+ 0,
160
+ true,
161
+ );
162
+ return { ok: succeeded(run), message: refreshMessage(run) };
163
+ }
164
+
165
+ const refreshQueue = new SerialMutationQueue();
166
+
167
+ export function resolveGetOmpModelsFileStatus(
168
+ _input: RpcInput<typeof getOmpModelsFileStatus>,
169
+ ): Promise<OmpModelsFileStatus> {
170
+ return getOmpModelsFileStatusWithDependencies(dependenciesFor([]));
171
+ }
172
+
173
+ export function resolveRefreshOmpModels(
174
+ _input: RpcInput<typeof refreshOmpModels>,
175
+ hostInheritEnv: readonly string[],
176
+ ): Promise<{ ok: boolean; message: string }> {
177
+ return refreshQueue.run(() => refreshOmpModelsWithDependencies(dependenciesFor(hostInheritEnv)));
178
+ }
@@ -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.409.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.4.0-next.410.1"; // x-release-please-version
@@ -200,7 +200,7 @@ function inheritedEnvironmentNames(inheritEnv: readonly string[] | undefined): R
200
200
  return names;
201
201
  }
202
202
 
203
- function buildOmpEnvironment(
203
+ export function buildOmpEnvironment(
204
204
  sessionEnv: Readonly<Record<string, string>> | undefined,
205
205
  inheritEnv: readonly string[] | undefined,
206
206
  sourceEnv: NodeJS.ProcessEnv,
@@ -356,6 +356,8 @@ export interface BoundedRun {
356
356
  spawnErrorCode: string | null;
357
357
  /** True when tree termination/verification failed or the leader missed its final close bound. */
358
358
  cleanupFailed: boolean;
359
+ /** Only present when the caller asked for it with `stderrLimit`. Never forwarded across RPC. */
360
+ stderr?: string;
359
361
  }
360
362
 
361
363
  /**
@@ -375,6 +377,7 @@ export function runBounded(
375
377
  killGraceMs: number,
376
378
  maxBytes: number,
377
379
  cwd?: string,
380
+ stderrLimit = 0,
378
381
  ): Promise<BoundedRun> {
379
382
  const { promise, resolve } = Promise.withResolvers<BoundedRun>();
380
383
  let child: ProbeChildProcess;
@@ -397,6 +400,8 @@ export function runBounded(
397
400
  const stdoutChunks: Buffer[] = [];
398
401
  let stdoutBytes = 0;
399
402
  let truncated = false;
403
+ const stderrChunks: Buffer[] = [];
404
+ let stderrBytes = 0;
400
405
  let timedOut = false;
401
406
  let leaderClosed = false;
402
407
  let leaderExitCode: number | null = null;
@@ -405,6 +410,7 @@ export function runBounded(
405
410
  let treeCleanupSucceeded = false;
406
411
  let finalLeaderTimer: ReturnType<typeof setTimeout> | undefined;
407
412
  const getStdout = () => Buffer.concat(stdoutChunks, stdoutBytes).toString("utf8");
413
+ const getStderr = () => Buffer.concat(stderrChunks, stderrBytes).toString("utf8");
408
414
 
409
415
  const cleanupListeners = () => {
410
416
  child.stdout.removeAllListeners();
@@ -428,6 +434,7 @@ export function runBounded(
428
434
  signal: leaderSignal,
429
435
  spawnErrorCode: null,
430
436
  cleanupFailed,
437
+ ...(stderrLimit > 0 ? { stderr: getStderr() } : {}),
431
438
  });
432
439
  };
433
440
  const settleAfterCleanup = () => {
@@ -482,8 +489,14 @@ export function runBounded(
482
489
  stdoutChunks.push(accepted);
483
490
  stdoutBytes += accepted.length;
484
491
  });
485
- child.stderr.on("data", () => {
486
- // Intentionally discarded: never stored, parsed, or forwarded across the RPC boundary.
492
+ child.stderr.on("data", (chunk: Buffer) => {
493
+ // Discarded unless the caller opted in with `stderrLimit`; then kept, bounded, for that
494
+ // caller to parse. It is never forwarded across the RPC boundary as-is.
495
+ const remaining = stderrLimit - stderrBytes;
496
+ if (remaining <= 0) return;
497
+ const accepted = chunk.subarray(0, remaining);
498
+ stderrChunks.push(accepted);
499
+ stderrBytes += accepted.length;
487
500
  });
488
501
  child.onClose((code, signal) => {
489
502
  leaderClosed = true;
@@ -501,6 +514,7 @@ export function runBounded(
501
514
  signal,
502
515
  spawnErrorCode: null,
503
516
  cleanupFailed: false,
517
+ ...(stderrLimit > 0 ? { stderr: getStderr() } : {}),
504
518
  });
505
519
  });
506
520
 
@@ -0,0 +1,30 @@
1
+ import { defineRpc } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+ import { OmpStoreSchema } from "./omp-store";
4
+
5
+ /**
6
+ * Whether OMP loaded `models.yml`. A typo makes OMP drop every custom provider with only a
7
+ * warning, so the card says so. `unknown` means the check could not run: never a guess.
8
+ */
9
+ export const OmpModelsFileStatusSchema = z.discriminatedUnion("state", [
10
+ z.object({ state: z.literal("ok") }),
11
+ /**
12
+ * OMP's own validation message, control characters stripped and bounded. Values OMP echoes as
13
+ * "(was ...)" are removed; field paths and the provider and model names from the file remain.
14
+ */
15
+ z.object({ state: z.literal("invalid"), detail: z.string().max(400) }),
16
+ z.object({ state: z.literal("unknown") }),
17
+ ]);
18
+ export type OmpModelsFileStatus = z.infer<typeof OmpModelsFileStatusSchema>;
19
+
20
+ export const getOmpModelsFileStatus = defineRpc({
21
+ name: "paseo-omp.get-models-file-status",
22
+ input: z.object({ store: OmpStoreSchema.optional() }),
23
+ output: OmpModelsFileStatusSchema,
24
+ });
25
+
26
+ export const refreshOmpModels = defineRpc({
27
+ name: "paseo-omp.refresh-models",
28
+ input: z.object({ store: OmpStoreSchema.optional() }),
29
+ output: z.object({ ok: z.boolean(), message: z.string() }),
30
+ });