@omercnet/paseo-omp 5.4.0 → 5.5.0-next.429.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 +7 -1
- package/README.md +2 -1
- package/client/ast-edit.tsx +53 -0
- package/client/composer-pill-settings.tsx +0 -5
- package/client/config-sidebar.tsx +15 -0
- package/client/generated-image.tsx +79 -0
- package/client/lsp-diagnostics.tsx +69 -0
- package/client/omp-config-surface.tsx +438 -108
- package/client/omp-config-views.ts +32 -5
- package/client/omp-extensions-section.tsx +145 -0
- package/client/omp-local-models-section.tsx +215 -0
- package/client/omp-plugin-manager.tsx +198 -3
- package/client/omp-routing-editor.tsx +123 -2
- package/client/omp-rule-test.tsx +140 -0
- package/client/omp-rules-section.tsx +353 -0
- package/client/omp-security-section.tsx +99 -0
- package/client/omp-security-state.ts +14 -0
- package/client/omp-skills-section.tsx +195 -0
- package/client/omp-tool-config-section.tsx +204 -0
- package/client/omp-tool-policy-state.ts +101 -0
- package/client/omp-tool-policy.tsx +435 -0
- package/client/omp-update-row.tsx +87 -0
- package/client/provider-diagnostics-state.ts +38 -1
- package/client/provider-image.tsx +1 -1
- package/client/rule-notice.tsx +33 -0
- package/client/sidebar-compat.ts +0 -109
- package/client/web.ts +34 -0
- package/index.client.tsx +79 -46
- package/index.server.ts +77 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
- package/server/generated-images.ts +57 -0
- package/server/omp-agents.ts +170 -0
- package/server/omp-extensions.ts +235 -0
- package/server/omp-list-setting.ts +98 -0
- package/server/omp-local-models.ts +202 -0
- package/server/omp-models-file.ts +178 -0
- package/server/omp-plugins.ts +182 -0
- package/server/omp-prompt-files.ts +41 -0
- package/server/omp-rule-firings.ts +211 -0
- package/server/omp-rule-switch.ts +38 -0
- package/server/omp-rule-test.ts +82 -0
- package/server/omp-rules.ts +452 -0
- package/server/omp-security.ts +169 -0
- package/server/omp-settings.ts +92 -16
- package/server/omp-skills.ts +179 -0
- package/server/omp-tool-config.ts +144 -0
- package/server/omp-update.ts +203 -0
- package/server/package-version.ts +1 -1
- package/server/provider/connection.ts +1 -1
- package/server/provider/image-cache.ts +1 -1
- package/server/provider/omp-rpc-environment.ts +1 -1
- package/server/provider/session-descriptors.ts +3 -0
- package/server/provider-diagnostics.ts +26 -4
- package/server/regular-file.ts +30 -0
- package/server/rule-notices.ts +112 -0
- package/server/turn-rows.ts +59 -0
- package/server/turn-screenshots.ts +140 -0
- package/shared/ast-edit.ts +124 -0
- package/shared/composer-pill-settings.ts +0 -2
- package/shared/generated-image.ts +68 -0
- package/shared/lsp-diagnostics.ts +141 -0
- package/shared/omp-agents.ts +26 -0
- package/shared/omp-extensions.ts +45 -0
- package/shared/omp-local-models.ts +44 -0
- package/shared/omp-models-file.ts +30 -0
- package/shared/omp-plugins.ts +90 -0
- package/shared/omp-prompt-files.ts +24 -0
- package/shared/omp-rules.ts +134 -0
- package/shared/omp-security.ts +50 -0
- package/shared/omp-settings.ts +211 -2
- package/shared/omp-skills.ts +80 -0
- package/shared/omp-tool-config.ts +283 -0
- package/shared/omp-update.ts +27 -0
- package/shared/provider-image.ts +10 -3
- package/shared/rule-notices.ts +20 -0
- package/client/hub-sidebar.tsx +0 -99
- package/client/sessions-popover.tsx +0 -78
- package/server/sessions.ts +0 -58
- package/shared/sessions.ts +0 -24
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
package/server/omp-plugins.ts
CHANGED
|
@@ -3,20 +3,28 @@ import { delimiter, isAbsolute, join } from "node:path";
|
|
|
3
3
|
import type { RpcInput } from "@getpaseo/plugin";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import {
|
|
6
|
+
type browseOmpMarketplace,
|
|
6
7
|
type inspectOmpPluginConfig,
|
|
8
|
+
type listOmpMarketplaces,
|
|
7
9
|
type listOmpPlugins,
|
|
10
|
+
type mutateOmpMarketplace,
|
|
8
11
|
type mutateOmpPlugin,
|
|
9
12
|
type mutateOmpPluginConfig,
|
|
13
|
+
OMP_CATALOG_PLUGIN_LIMIT,
|
|
10
14
|
OMP_PLUGIN_LIMIT,
|
|
15
|
+
type OmpCatalogState,
|
|
11
16
|
type OmpInstalledPlugin,
|
|
12
17
|
OmpInstalledPluginSchema,
|
|
18
|
+
OmpMarketplaceNameSchema,
|
|
13
19
|
OmpMarketplacePluginIdSchema,
|
|
20
|
+
type OmpMarketplaceState,
|
|
14
21
|
type OmpPluginConfigMutation,
|
|
15
22
|
type OmpPluginConfigSetting,
|
|
16
23
|
type OmpPluginConfigState,
|
|
17
24
|
type OmpPluginMutation,
|
|
18
25
|
OmpPluginNameSchema,
|
|
19
26
|
type OmpPluginState,
|
|
27
|
+
redactSourceCredentials,
|
|
20
28
|
} from "../shared/omp-plugins";
|
|
21
29
|
import { SerialMutationQueue } from "./mutation-queue";
|
|
22
30
|
import { currentOmpEnvironment } from "./paths";
|
|
@@ -674,3 +682,177 @@ export function resolveMutateOmpPlugin(
|
|
|
674
682
|
mutateOmpPluginWithDependencies(input, DEFAULT_DEPENDENCIES),
|
|
675
683
|
);
|
|
676
684
|
}
|
|
685
|
+
|
|
686
|
+
// OMP prints marketplace listings as text only (`--json` is ignored), so parse the stable
|
|
687
|
+
// "name source" and "name[@version]" / indented description shapes and reject anything else.
|
|
688
|
+
|
|
689
|
+
export function parseOmpMarketplaceList(stdout: string): OmpMarketplaceState["marketplaces"] {
|
|
690
|
+
const lines = stdout.split(/\r?\n/u);
|
|
691
|
+
if (!lines.some((line) => line.startsWith("Configured Marketplaces:"))) {
|
|
692
|
+
if (lines.some((line) => line.startsWith("No marketplaces configured"))) return [];
|
|
693
|
+
throw new Error("OMP returned an invalid marketplace list");
|
|
694
|
+
}
|
|
695
|
+
const marketplaces: OmpMarketplaceState["marketplaces"] = [];
|
|
696
|
+
for (const line of lines) {
|
|
697
|
+
const match = /^ {2}(\S+) {2}(\S.*)$/u.exec(line);
|
|
698
|
+
if (!match?.[1] || !match[2]) continue;
|
|
699
|
+
const name = OmpMarketplaceNameSchema.safeParse(match[1]);
|
|
700
|
+
const source = boundedText(redactSourceCredentials(match[2].trim()), 4_096);
|
|
701
|
+
if (name.success && source) marketplaces.push({ name: name.data, source });
|
|
702
|
+
if (marketplaces.length === OMP_PLUGIN_LIMIT) break;
|
|
703
|
+
}
|
|
704
|
+
return marketplaces;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
export function parseOmpCatalog(stdout: string, marketplace: string): OmpCatalogState["plugins"] {
|
|
708
|
+
const lines = stdout.split(/\r?\n/u);
|
|
709
|
+
if (!lines.some((line) => line.startsWith("Available Plugins"))) {
|
|
710
|
+
if (lines.some((line) => line.startsWith("No plugins found"))) return [];
|
|
711
|
+
throw new Error("OMP returned an invalid plugin catalog");
|
|
712
|
+
}
|
|
713
|
+
const plugins: OmpCatalogState["plugins"] = [];
|
|
714
|
+
let current: OmpCatalogState["plugins"][number] | null = null;
|
|
715
|
+
for (const line of lines) {
|
|
716
|
+
const entry = /^ {2}(\S+)$/u.exec(line);
|
|
717
|
+
if (entry?.[1]) {
|
|
718
|
+
const [name, version] = entry[1].split("@");
|
|
719
|
+
const id = `${name}@${marketplace}`;
|
|
720
|
+
// OMP allows mixed-case names and caps the assembled id at 128 characters.
|
|
721
|
+
const valid = OmpMarketplaceNameSchema.safeParse(name).success && id.length <= 128;
|
|
722
|
+
current = valid ? { id, version: boundedText(version, 128), description: null } : null;
|
|
723
|
+
if (!current) continue;
|
|
724
|
+
plugins.push(current);
|
|
725
|
+
if (plugins.length === OMP_CATALOG_PLUGIN_LIMIT) break;
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
const description = /^ {4}(\S.*)$/u.exec(line);
|
|
729
|
+
if (description?.[1] && current && current.description === null) {
|
|
730
|
+
current.description = boundedText(description[1].trim(), DESCRIPTION_LIMIT);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return plugins;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async function loadMarketplaces(
|
|
737
|
+
executable: string,
|
|
738
|
+
dependencies: OmpPluginDependencies,
|
|
739
|
+
): Promise<OmpMarketplaceState> {
|
|
740
|
+
const result = await dependencies.runPlugin(
|
|
741
|
+
executable,
|
|
742
|
+
["plugin", "marketplace", "list"],
|
|
743
|
+
LIST_OUTPUT_LIMIT,
|
|
744
|
+
READ_TIMEOUT_MS,
|
|
745
|
+
);
|
|
746
|
+
if (!runSucceeded(result)) {
|
|
747
|
+
return { available: false, marketplaces: [], error: readFailure(result) };
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
return { available: true, marketplaces: parseOmpMarketplaceList(result.stdout) };
|
|
751
|
+
} catch {
|
|
752
|
+
return {
|
|
753
|
+
available: false,
|
|
754
|
+
marketplaces: [],
|
|
755
|
+
error: "OMP returned an invalid marketplace list.",
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export async function listOmpMarketplacesWithDependencies(
|
|
761
|
+
dependencies: OmpPluginDependencies,
|
|
762
|
+
): Promise<OmpMarketplaceState> {
|
|
763
|
+
const executable = await dependencies.resolveExecutable();
|
|
764
|
+
if (!executable) {
|
|
765
|
+
return {
|
|
766
|
+
available: false,
|
|
767
|
+
marketplaces: [],
|
|
768
|
+
error: "The OMP executable could not be resolved.",
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
return loadMarketplaces(executable, dependencies);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
export function resolveListOmpMarketplaces(
|
|
775
|
+
_input: RpcInput<typeof listOmpMarketplaces>,
|
|
776
|
+
): Promise<OmpMarketplaceState> {
|
|
777
|
+
return listOmpMarketplacesWithDependencies(DEFAULT_DEPENDENCIES);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export async function browseOmpMarketplaceWithDependencies(
|
|
781
|
+
input: RpcInput<typeof browseOmpMarketplace>,
|
|
782
|
+
dependencies: OmpPluginDependencies,
|
|
783
|
+
): Promise<OmpCatalogState> {
|
|
784
|
+
const unavailable = (error: string): OmpCatalogState => ({
|
|
785
|
+
available: false,
|
|
786
|
+
marketplace: input.marketplace,
|
|
787
|
+
plugins: [],
|
|
788
|
+
error,
|
|
789
|
+
});
|
|
790
|
+
const executable = await dependencies.resolveExecutable();
|
|
791
|
+
if (!executable) return unavailable("The OMP executable could not be resolved.");
|
|
792
|
+
const result = await dependencies.runPlugin(
|
|
793
|
+
executable,
|
|
794
|
+
["plugin", "discover", input.marketplace],
|
|
795
|
+
LIST_OUTPUT_LIMIT,
|
|
796
|
+
READ_TIMEOUT_MS,
|
|
797
|
+
);
|
|
798
|
+
if (!runSucceeded(result)) return unavailable(readFailure(result));
|
|
799
|
+
try {
|
|
800
|
+
return {
|
|
801
|
+
available: true,
|
|
802
|
+
marketplace: input.marketplace,
|
|
803
|
+
plugins: parseOmpCatalog(result.stdout, input.marketplace),
|
|
804
|
+
};
|
|
805
|
+
} catch {
|
|
806
|
+
return unavailable("OMP returned an invalid plugin catalog.");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
export function resolveBrowseOmpMarketplace(
|
|
811
|
+
input: RpcInput<typeof browseOmpMarketplace>,
|
|
812
|
+
): Promise<OmpCatalogState> {
|
|
813
|
+
return browseOmpMarketplaceWithDependencies(input, DEFAULT_DEPENDENCIES);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export function buildOmpMarketplaceMutationArgs(
|
|
817
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
818
|
+
): string[] {
|
|
819
|
+
return [
|
|
820
|
+
"plugin",
|
|
821
|
+
"marketplace",
|
|
822
|
+
input.action,
|
|
823
|
+
input.action === "add" ? input.source : input.marketplace,
|
|
824
|
+
];
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export async function mutateOmpMarketplaceWithDependencies(
|
|
828
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
829
|
+
dependencies: OmpPluginDependencies,
|
|
830
|
+
): Promise<{ ok: boolean; message: string; state: OmpMarketplaceState }> {
|
|
831
|
+
const executable = await dependencies.resolveExecutable();
|
|
832
|
+
if (!executable) {
|
|
833
|
+
const message = "The OMP executable could not be resolved.";
|
|
834
|
+
return { ok: false, message, state: { available: false, marketplaces: [], error: message } };
|
|
835
|
+
}
|
|
836
|
+
const mutation = await dependencies.runPlugin(
|
|
837
|
+
executable,
|
|
838
|
+
buildOmpMarketplaceMutationArgs(input),
|
|
839
|
+
MUTATION_OUTPUT_LIMIT,
|
|
840
|
+
MUTATION_TIMEOUT_MS,
|
|
841
|
+
);
|
|
842
|
+
const ok = runSucceeded(mutation);
|
|
843
|
+
const state = await loadMarketplaces(executable, dependencies);
|
|
844
|
+
if (!ok) return { ok, message: mutationFailure(mutation), state };
|
|
845
|
+
return {
|
|
846
|
+
ok,
|
|
847
|
+
message: input.action === "add" ? "Marketplace added." : "Marketplace removed.",
|
|
848
|
+
state,
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
export function resolveMutateOmpMarketplace(
|
|
853
|
+
input: RpcInput<typeof mutateOmpMarketplace>,
|
|
854
|
+
): Promise<{ ok: boolean; message: string; state: OmpMarketplaceState }> {
|
|
855
|
+
return pluginMutationQueue.run(() =>
|
|
856
|
+
mutateOmpMarketplaceWithDependencies(input, DEFAULT_DEPENDENCIES),
|
|
857
|
+
);
|
|
858
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
|
+
import type { OmpPromptFiles } from "../shared/omp-prompt-files";
|
|
5
|
+
import { ompAgentDir } from "./paths";
|
|
6
|
+
|
|
7
|
+
// OMP checks for the file's existence, so an empty file still counts. A `.omp` that is a file
|
|
8
|
+
// (ENOTDIR) simply has no prompt files in it.
|
|
9
|
+
async function hasFile(path: string): Promise<boolean> {
|
|
10
|
+
try {
|
|
11
|
+
return (await stat(path)).isFile();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
14
|
+
if (code === "ENOENT" || code === "ENOTDIR") return false;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function hasPromptFile(directories: readonly string[], name: string): Promise<boolean> {
|
|
20
|
+
const found = await Promise.all(directories.map((directory) => hasFile(join(directory, name))));
|
|
21
|
+
return found.some(Boolean);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Paseo's host Append system prompt as a yes/no; the text never leaves this function. */
|
|
25
|
+
export async function readHostAppendPrompt(paseo: PluginHandlerContext["paseo"]): Promise<boolean> {
|
|
26
|
+
const { config } = await paseo.config.get();
|
|
27
|
+
return config.appendSystemPrompt.trim() !== "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Where OMP looks: the agent directory, plus the workspace's `.omp/` for a project view. */
|
|
31
|
+
export async function readOmpPromptFiles(
|
|
32
|
+
cwd: string | undefined,
|
|
33
|
+
hostAppendPrompt: boolean,
|
|
34
|
+
): Promise<OmpPromptFiles> {
|
|
35
|
+
const directories = [ompAgentDir(), ...(cwd ? [join(cwd, ".omp")] : [])];
|
|
36
|
+
const [appendSystemFile, systemFile] = await Promise.all([
|
|
37
|
+
hasPromptFile(directories, "APPEND_SYSTEM.md"),
|
|
38
|
+
hasPromptFile(directories, "SYSTEM.md"),
|
|
39
|
+
]);
|
|
40
|
+
return { appendSystemFile, systemFile, hostAppendPrompt };
|
|
41
|
+
}
|