@omercnet/paseo-omp 5.4.0-next.403.1 → 5.4.0-next.405.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 +1 -0
- package/client/generated-image.tsx +79 -0
- package/client/omp-config-surface.tsx +34 -4
- package/client/omp-routing-editor.tsx +123 -2
- package/client/provider-image.tsx +1 -1
- package/client/web.ts +34 -0
- package/index.client.tsx +21 -0
- package/index.server.ts +8 -0
- package/package.json +1 -1
- package/server/generated-images.ts +57 -0
- package/server/omp-agents.ts +170 -0
- package/server/omp-settings.ts +3 -3
- package/server/package-version.ts +1 -1
- package/server/provider/image-cache.ts +1 -1
- package/server/regular-file.ts +30 -0
- package/shared/generated-image.ts +68 -0
- package/shared/omp-agents.ts +26 -0
- package/shared/omp-settings.ts +21 -1
- package/shared/provider-image.ts +7 -2
package/OVERVIEW.md
CHANGED
|
@@ -17,6 +17,7 @@ OMP adds an agent provider for the OMP coding agent, plus an OMP sidebar and wor
|
|
|
17
17
|
- While OMP subagents run, a row under each `task` card in the conversation lets you steer one with a message or stop it after confirmation. It needs OMP 18.4.9 or newer.
|
|
18
18
|
- When an OMP rule fires during a turn of an agent on Paseo's bundled `omp` provider, a notice under that turn names the rule and the text it matched. The plugin reads this, best effort, from the end of the agent's OMP session file, which that provider does not report.
|
|
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
|
+
- 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.
|
|
20
21
|
- OMP agents can call Paseo's orchestration tools with the optional `serverId` argument and `list_hosts` to delegate work to other connected Paseo hosts.
|
|
21
22
|
|
|
22
23
|
## Reads and sends
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type PluginTimelineItemProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import { type OmpGeneratedImages, resolveOmpGeneratedImages } from "../shared/generated-image";
|
|
5
|
+
import type { OmpImage } from "../shared/provider-image";
|
|
6
|
+
import { OmpImageTimeline, useOmpImageSource } from "./provider-image";
|
|
7
|
+
import { canDownloadFiles, downloadDataUri } from "./web";
|
|
8
|
+
|
|
9
|
+
const LABEL = "Generated image";
|
|
10
|
+
|
|
11
|
+
function DownloadButton({
|
|
12
|
+
image,
|
|
13
|
+
hostId,
|
|
14
|
+
color,
|
|
15
|
+
}: {
|
|
16
|
+
image: OmpImage;
|
|
17
|
+
hostId: string;
|
|
18
|
+
color: string;
|
|
19
|
+
}) {
|
|
20
|
+
const source = useOmpImageSource(image, hostId);
|
|
21
|
+
if (source.status !== "ready") return null;
|
|
22
|
+
const extension = image.mimeType === "image/jpeg" ? "jpg" : image.mimeType.slice("image/".length);
|
|
23
|
+
return (
|
|
24
|
+
<Pressable
|
|
25
|
+
accessibilityRole="button"
|
|
26
|
+
accessibilityLabel="Download generated image"
|
|
27
|
+
onPress={() => downloadDataUri(source.uri, `generated-image-${image.id}.${extension}`)}
|
|
28
|
+
>
|
|
29
|
+
<Text style={{ color, fontSize: 12, fontWeight: "600" }}>Download</Text>
|
|
30
|
+
</Pressable>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function OmpGeneratedImagesRow(props: PluginTimelineItemProps<OmpGeneratedImages>) {
|
|
35
|
+
const { item, theme, host } = props;
|
|
36
|
+
const resolve = useRpc(resolveOmpGeneratedImages);
|
|
37
|
+
const query = useQuery({
|
|
38
|
+
queryKey: ["omp-generated-images", host.id, item.data.paths],
|
|
39
|
+
queryFn: () => resolve({ paths: item.data.paths }),
|
|
40
|
+
staleTime: (current) =>
|
|
41
|
+
current.state.data?.images.every((result) => result.status === "available")
|
|
42
|
+
? Number.POSITIVE_INFINITY
|
|
43
|
+
: 0,
|
|
44
|
+
retry: 1,
|
|
45
|
+
});
|
|
46
|
+
const muted = { color: theme.colors.foregroundMuted, fontSize: 12 };
|
|
47
|
+
if (query.isError)
|
|
48
|
+
return <Text style={muted}>Unable to load generated images from the host.</Text>;
|
|
49
|
+
if (!query.data) return <Text style={muted}>Loading image...</Text>;
|
|
50
|
+
const images: OmpImage[] = [];
|
|
51
|
+
for (const result of query.data.images) {
|
|
52
|
+
if (result.status === "available") {
|
|
53
|
+
images.push({ id: result.ref.slice(0, 16), ref: result.ref, mimeType: result.mimeType });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return (
|
|
57
|
+
<View style={{ gap: 8 }}>
|
|
58
|
+
{images.length > 0 ? (
|
|
59
|
+
<OmpImageTimeline
|
|
60
|
+
{...props}
|
|
61
|
+
item={{ ...item, kind: "omp-images", data: { label: LABEL, images } }}
|
|
62
|
+
/>
|
|
63
|
+
) : null}
|
|
64
|
+
{canDownloadFiles
|
|
65
|
+
? images.map((image, index) => (
|
|
66
|
+
<DownloadButton
|
|
67
|
+
key={`${index}:${image.id}`}
|
|
68
|
+
image={image}
|
|
69
|
+
hostId={host.id}
|
|
70
|
+
color={theme.colors.accent}
|
|
71
|
+
/>
|
|
72
|
+
))
|
|
73
|
+
: null}
|
|
74
|
+
{images.length < query.data.images.length ? (
|
|
75
|
+
<Text style={muted}>Some generated images are no longer available on the host.</Text>
|
|
76
|
+
) : null}
|
|
77
|
+
</View>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -11,6 +11,7 @@ import type { ReactNode } from "react";
|
|
|
11
11
|
import { useCallback, useMemo, useState } from "react";
|
|
12
12
|
import { Pressable, ScrollView, Switch, Text, View } from "react-native";
|
|
13
13
|
import type { ComposerPillSettings } from "../shared/composer-pill-settings";
|
|
14
|
+
import { listOmpAgents } from "../shared/omp-agents";
|
|
14
15
|
import { listOmpConfig, type OmpConfig } from "../shared/omp-config";
|
|
15
16
|
import { listOmpModels } from "../shared/omp-models";
|
|
16
17
|
import {
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
type OmpSettingCategory,
|
|
24
25
|
orderOmpToolSettings,
|
|
25
26
|
parseOmpStructuredSettingValue,
|
|
27
|
+
structuredSettingType,
|
|
26
28
|
updateOmpSettings,
|
|
27
29
|
} from "../shared/omp-settings";
|
|
28
30
|
import { type OmpStore, storeLabel } from "../shared/omp-store";
|
|
@@ -44,7 +46,11 @@ import {
|
|
|
44
46
|
import { OmpMcpsSection } from "./omp-mcps-section";
|
|
45
47
|
import { normalizeOmpModels } from "./omp-model-picker-state";
|
|
46
48
|
import { OmpPluginManagerSection } from "./omp-plugin-manager";
|
|
47
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
type OmpAgentCatalogState,
|
|
51
|
+
type OmpModelCatalogState,
|
|
52
|
+
StructuredRoutingEditor,
|
|
53
|
+
} from "./omp-routing-editor";
|
|
48
54
|
import { OmpRulesSection } from "./omp-rules-section";
|
|
49
55
|
import { OmpSkillsSection } from "./omp-skills-section";
|
|
50
56
|
import { OmpStorePicker } from "./omp-store-picker";
|
|
@@ -815,6 +821,7 @@ function ConfigurationCategory({
|
|
|
815
821
|
theme,
|
|
816
822
|
modelCatalog,
|
|
817
823
|
modelRoles,
|
|
824
|
+
agentCatalog,
|
|
818
825
|
disabled,
|
|
819
826
|
workspaceScoped,
|
|
820
827
|
onDraft,
|
|
@@ -825,6 +832,7 @@ function ConfigurationCategory({
|
|
|
825
832
|
theme: PluginSurfaceProps["theme"];
|
|
826
833
|
modelCatalog: OmpModelCatalogState;
|
|
827
834
|
modelRoles: Readonly<Record<string, unknown>>;
|
|
835
|
+
agentCatalog: OmpAgentCatalogState;
|
|
828
836
|
settings: readonly OmpSetting[];
|
|
829
837
|
drafts: Readonly<Record<string, SettingDraft>>;
|
|
830
838
|
disabled: boolean;
|
|
@@ -856,7 +864,7 @@ function ConfigurationCategory({
|
|
|
856
864
|
const structuredEditable =
|
|
857
865
|
!setting.redacted &&
|
|
858
866
|
isOmpStructuredSettingPath(setting.path) &&
|
|
859
|
-
setting.type === (setting.path
|
|
867
|
+
setting.type === structuredSettingType(setting.path);
|
|
860
868
|
const settingDocumentation = documentationForSettingPath(setting.path);
|
|
861
869
|
const draft = drafts[setting.path];
|
|
862
870
|
return (
|
|
@@ -905,6 +913,7 @@ function ConfigurationCategory({
|
|
|
905
913
|
theme={theme}
|
|
906
914
|
modelCatalog={modelCatalog}
|
|
907
915
|
modelRoles={modelRoles}
|
|
916
|
+
agentCatalog={agentCatalog}
|
|
908
917
|
onSet={(value) => onDraft(setting.path, { operation: "set", value })}
|
|
909
918
|
onReset={() => onDraft(setting.path, { operation: "reset" })}
|
|
910
919
|
/>
|
|
@@ -973,6 +982,7 @@ function OmpConfigContent({
|
|
|
973
982
|
const loadSettings = useRpc(listOmpSettings);
|
|
974
983
|
const updateSettings = useRpc(updateOmpSettings);
|
|
975
984
|
const loadModels = useRpc(listOmpModels);
|
|
985
|
+
const loadAgents = useRpc(listOmpAgents);
|
|
976
986
|
const queryClient = useQueryClient();
|
|
977
987
|
const context = { store, ...(cwd ? { cwd } : {}) };
|
|
978
988
|
const pendingMutations = useIsMutating({ mutationKey: ["paseo-omp"] });
|
|
@@ -992,6 +1002,18 @@ function OmpConfigContent({
|
|
|
992
1002
|
queryFn: () => loadModels(context),
|
|
993
1003
|
staleTime: 30_000,
|
|
994
1004
|
});
|
|
1005
|
+
const agentsQuery = useQuery({
|
|
1006
|
+
queryKey: ["paseo-omp", "agents", ompStoreKey(store), cwd ?? "global"],
|
|
1007
|
+
queryFn: () => loadAgents(context),
|
|
1008
|
+
staleTime: 5 * 60_000,
|
|
1009
|
+
});
|
|
1010
|
+
const agentCatalog: OmpAgentCatalogState = {
|
|
1011
|
+
agents: agentsQuery.data?.agents ?? [],
|
|
1012
|
+
loading: agentsQuery.isLoading,
|
|
1013
|
+
...(agentsQuery.error || agentsQuery.data?.error
|
|
1014
|
+
? { error: "Could not list every OMP agent. Typed names remain available." }
|
|
1015
|
+
: {}),
|
|
1016
|
+
};
|
|
995
1017
|
const [view, setView] = useState<SurfaceView>("overview");
|
|
996
1018
|
const [activeCategory, setActiveCategory] = useState<OmpSettingCategory>("appearance");
|
|
997
1019
|
const [search, setSearch] = useState("");
|
|
@@ -1227,19 +1249,26 @@ function OmpConfigContent({
|
|
|
1227
1249
|
accessibilityLabel="Refresh OMP configuration"
|
|
1228
1250
|
style={styles.refresh}
|
|
1229
1251
|
disabled={
|
|
1230
|
-
configQuery.isFetching ||
|
|
1252
|
+
configQuery.isFetching ||
|
|
1253
|
+
settingsQuery.isFetching ||
|
|
1254
|
+
modelsQuery.isFetching ||
|
|
1255
|
+
agentsQuery.isFetching
|
|
1231
1256
|
}
|
|
1232
1257
|
onPress={() => {
|
|
1233
1258
|
void Promise.all([
|
|
1234
1259
|
configQuery.refetch(),
|
|
1235
1260
|
settingsQuery.refetch(),
|
|
1236
1261
|
modelsQuery.refetch(),
|
|
1262
|
+
agentsQuery.refetch(),
|
|
1237
1263
|
]);
|
|
1238
1264
|
}}
|
|
1239
1265
|
>
|
|
1240
1266
|
<Icon name="RefreshCw" size={14} color={theme.colors.foreground} />
|
|
1241
1267
|
<Text style={styles.refreshLabel}>
|
|
1242
|
-
{configQuery.isFetching ||
|
|
1268
|
+
{configQuery.isFetching ||
|
|
1269
|
+
settingsQuery.isFetching ||
|
|
1270
|
+
modelsQuery.isFetching ||
|
|
1271
|
+
agentsQuery.isFetching
|
|
1243
1272
|
? "Refreshing…"
|
|
1244
1273
|
: "Refresh"}
|
|
1245
1274
|
</Text>
|
|
@@ -1380,6 +1409,7 @@ function OmpConfigContent({
|
|
|
1380
1409
|
theme={theme}
|
|
1381
1410
|
modelCatalog={modelCatalog}
|
|
1382
1411
|
modelRoles={modelRoles}
|
|
1412
|
+
agentCatalog={agentCatalog}
|
|
1383
1413
|
styles={styles}
|
|
1384
1414
|
settings={catalog.byCategory.get(selectedCategory.id) ?? []}
|
|
1385
1415
|
drafts={drafts}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
|
|
2
2
|
import { TextInput } from "@getpaseo/plugin/client/ui";
|
|
3
3
|
import { useState } from "react";
|
|
4
|
-
import { Pressable, Text, View } from "react-native";
|
|
4
|
+
import { Pressable, Switch, Text, View } from "react-native";
|
|
5
|
+
import type { OmpAgent } from "../shared/omp-agents";
|
|
5
6
|
import {
|
|
6
7
|
formatOmpSettingLabel,
|
|
7
8
|
isOmpStructuredSettingPath,
|
|
@@ -24,6 +25,12 @@ export type OmpModelCatalogState = {
|
|
|
24
25
|
error?: string;
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
export type OmpAgentCatalogState = {
|
|
29
|
+
agents: readonly OmpAgent[];
|
|
30
|
+
loading: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
27
34
|
type StructuredRoutingEditorProps = {
|
|
28
35
|
setting: OmpSetting;
|
|
29
36
|
value: unknown;
|
|
@@ -35,6 +42,7 @@ type StructuredRoutingEditorProps = {
|
|
|
35
42
|
theme: PluginSurfaceProps["theme"];
|
|
36
43
|
modelCatalog: OmpModelCatalogState;
|
|
37
44
|
modelRoles: Readonly<Record<string, unknown>>;
|
|
45
|
+
agentCatalog: OmpAgentCatalogState;
|
|
38
46
|
onSet(value: unknown): void;
|
|
39
47
|
onReset(): void;
|
|
40
48
|
};
|
|
@@ -128,6 +136,99 @@ function OrderedRoleEditor({
|
|
|
128
136
|
);
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
function AgentPicker({
|
|
140
|
+
agents,
|
|
141
|
+
taken,
|
|
142
|
+
disabled,
|
|
143
|
+
styles,
|
|
144
|
+
onSelect,
|
|
145
|
+
}: {
|
|
146
|
+
agents: readonly OmpAgent[];
|
|
147
|
+
taken: readonly string[];
|
|
148
|
+
disabled: boolean;
|
|
149
|
+
styles: OmpConfigStyles;
|
|
150
|
+
onSelect(name: string): void;
|
|
151
|
+
}) {
|
|
152
|
+
const [open, setOpen] = useState(false);
|
|
153
|
+
const choices = agents.filter((agent) => !taken.includes(agent.name));
|
|
154
|
+
if (choices.length === 0) return null;
|
|
155
|
+
return (
|
|
156
|
+
<View style={styles.recordList}>
|
|
157
|
+
<RowButton
|
|
158
|
+
label={open ? "Close agents" : "Choose agent"}
|
|
159
|
+
disabled={disabled}
|
|
160
|
+
styles={styles}
|
|
161
|
+
onPress={() => setOpen((current) => !current)}
|
|
162
|
+
/>
|
|
163
|
+
{open
|
|
164
|
+
? choices.map((agent) => (
|
|
165
|
+
<RowButton
|
|
166
|
+
key={agent.name}
|
|
167
|
+
label={`${agent.name} (${agent.source})`}
|
|
168
|
+
disabled={disabled}
|
|
169
|
+
styles={styles}
|
|
170
|
+
onPress={() => {
|
|
171
|
+
onSelect(agent.name);
|
|
172
|
+
setOpen(false);
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
))
|
|
176
|
+
: null}
|
|
177
|
+
</View>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Turning off the default agent fails every task call that names no agent. */
|
|
182
|
+
const DEFAULT_AGENT = "task";
|
|
183
|
+
|
|
184
|
+
function DisabledAgentsEditor({
|
|
185
|
+
value,
|
|
186
|
+
agentCatalog,
|
|
187
|
+
disabled,
|
|
188
|
+
styles,
|
|
189
|
+
onSet,
|
|
190
|
+
}: Pick<StructuredRoutingEditorProps, "value" | "agentCatalog" | "disabled" | "styles" | "onSet">) {
|
|
191
|
+
const switchedOff = asStringArray(value);
|
|
192
|
+
const listed = agentCatalog.agents.map((agent) => agent.name);
|
|
193
|
+
const names = [...listed, ...switchedOff.filter((name) => !listed.includes(name))];
|
|
194
|
+
return (
|
|
195
|
+
<View style={styles.recordList}>
|
|
196
|
+
{agentCatalog.error ? (
|
|
197
|
+
<Text accessibilityRole="alert" style={styles.error}>
|
|
198
|
+
{agentCatalog.error}
|
|
199
|
+
</Text>
|
|
200
|
+
) : null}
|
|
201
|
+
{names.length === 0 ? (
|
|
202
|
+
<Text style={styles.muted}>
|
|
203
|
+
{agentCatalog.loading ? "Loading agents…" : "No agents found."}
|
|
204
|
+
</Text>
|
|
205
|
+
) : null}
|
|
206
|
+
{names.map((name) => {
|
|
207
|
+
const off = switchedOff.includes(name);
|
|
208
|
+
const locked = name === DEFAULT_AGENT && !off;
|
|
209
|
+
return (
|
|
210
|
+
<View key={name} style={styles.recordRow}>
|
|
211
|
+
<Text style={styles.recordKey}>{name}</Text>
|
|
212
|
+
<Switch
|
|
213
|
+
accessibilityLabel={`Agent ${name} is ${off ? "off" : "on"}`}
|
|
214
|
+
value={!off}
|
|
215
|
+
disabled={disabled || locked}
|
|
216
|
+
onValueChange={(on) =>
|
|
217
|
+
onSet(on ? switchedOff.filter((item) => item !== name) : [...switchedOff, name])
|
|
218
|
+
}
|
|
219
|
+
/>
|
|
220
|
+
{locked ? (
|
|
221
|
+
<Text style={styles.muted}>
|
|
222
|
+
The default agent stays on: without it every task call that names no agent fails.
|
|
223
|
+
</Text>
|
|
224
|
+
) : null}
|
|
225
|
+
</View>
|
|
226
|
+
);
|
|
227
|
+
})}
|
|
228
|
+
</View>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
131
232
|
function RecordRoutingEditor({
|
|
132
233
|
setting,
|
|
133
234
|
value,
|
|
@@ -136,10 +237,19 @@ function RecordRoutingEditor({
|
|
|
136
237
|
theme,
|
|
137
238
|
modelCatalog,
|
|
138
239
|
modelRoles,
|
|
240
|
+
agentCatalog,
|
|
139
241
|
onSet,
|
|
140
242
|
}: Pick<
|
|
141
243
|
StructuredRoutingEditorProps,
|
|
142
|
-
|
|
244
|
+
| "setting"
|
|
245
|
+
| "value"
|
|
246
|
+
| "disabled"
|
|
247
|
+
| "styles"
|
|
248
|
+
| "onSet"
|
|
249
|
+
| "theme"
|
|
250
|
+
| "modelCatalog"
|
|
251
|
+
| "modelRoles"
|
|
252
|
+
| "agentCatalog"
|
|
143
253
|
>) {
|
|
144
254
|
const record = asRecord(value);
|
|
145
255
|
const [keyErrors, setKeyErrors] = useState<Record<string, string>>({});
|
|
@@ -199,6 +309,15 @@ function RecordRoutingEditor({
|
|
|
199
309
|
{keyErrors[key]}
|
|
200
310
|
</Text>
|
|
201
311
|
) : null}
|
|
312
|
+
{setting.path.startsWith("task.") ? (
|
|
313
|
+
<AgentPicker
|
|
314
|
+
agents={agentCatalog.agents}
|
|
315
|
+
taken={Object.keys(record)}
|
|
316
|
+
disabled={disabled}
|
|
317
|
+
styles={styles}
|
|
318
|
+
onSelect={(name) => onSet(replaceRecordKey(record, key, name))}
|
|
319
|
+
/>
|
|
320
|
+
) : null}
|
|
202
321
|
<TextInput
|
|
203
322
|
accessibilityLabel={`${formatOmpSettingLabel(setting.path)} ${valueLabel} ${index + 1}`}
|
|
204
323
|
editable={!disabled}
|
|
@@ -287,6 +406,8 @@ export function StructuredRoutingEditor(props: StructuredRoutingEditorProps) {
|
|
|
287
406
|
<Text style={props.styles.muted}>{props.resetLabel} when changes are applied</Text>
|
|
288
407
|
) : props.setting.path === "cycleOrder" ? (
|
|
289
408
|
<OrderedRoleEditor {...props} />
|
|
409
|
+
) : props.setting.path === "task.disabledAgents" ? (
|
|
410
|
+
<DisabledAgentsEditor {...props} />
|
|
290
411
|
) : (
|
|
291
412
|
<RecordRoutingEditor {...props} />
|
|
292
413
|
)}
|
|
@@ -21,7 +21,7 @@ type OmpImageSource =
|
|
|
21
21
|
/** A decoded screenshot can hold several MB, so drop it soon after nothing shows it. */
|
|
22
22
|
const IMAGE_QUERY_GC_MS = 60_000;
|
|
23
23
|
|
|
24
|
-
function useOmpImageSource(image: OmpImage, hostId: string): OmpImageSource {
|
|
24
|
+
export function useOmpImageSource(image: OmpImage, hostId: string): OmpImageSource {
|
|
25
25
|
const fetchImage = useRpc(getOmpImage);
|
|
26
26
|
const ref = "ref" in image ? image.ref : null;
|
|
27
27
|
const query = useQuery({
|
package/client/web.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
declare const document: {
|
|
4
|
+
createElement(tag: "a"): { href: string; download: string; click(): void };
|
|
5
|
+
};
|
|
6
|
+
declare function atob(data: string): string;
|
|
7
|
+
declare class Blob {
|
|
8
|
+
constructor(parts: Uint8Array[], options: { type: string });
|
|
9
|
+
}
|
|
10
|
+
declare const URL: { createObjectURL(blob: Blob): string; revokeObjectURL(url: string): void };
|
|
11
|
+
|
|
12
|
+
/** Saving a file needs the browser; the desktop app and the web client both run it. */
|
|
13
|
+
export const canDownloadFiles = Platform.OS === "web";
|
|
14
|
+
|
|
15
|
+
const BASE64_DATA_URI = /^data:([^;,]+);base64,(.*)$/su;
|
|
16
|
+
const REVOKE_DELAY_MS = 60_000;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Saves a `data:` URI. Browsers refuse to download a data URL past about 2 MiB, so the bytes go
|
|
20
|
+
* through a Blob and an object URL instead.
|
|
21
|
+
*/
|
|
22
|
+
export function downloadDataUri(uri: string, fileName: string): void {
|
|
23
|
+
if (!canDownloadFiles) return;
|
|
24
|
+
const match = BASE64_DATA_URI.exec(uri);
|
|
25
|
+
const bytes = match ? Uint8Array.from(atob(match[2] ?? ""), (char) => char.charCodeAt(0)) : null;
|
|
26
|
+
const objectUrl =
|
|
27
|
+
match && bytes ? URL.createObjectURL(new Blob([bytes], { type: match[1] ?? "" })) : null;
|
|
28
|
+
const link = document.createElement("a");
|
|
29
|
+
link.href = objectUrl ?? uri;
|
|
30
|
+
link.download = fileName;
|
|
31
|
+
link.click();
|
|
32
|
+
// Safari and Firefox can start the download after the click returns, so revoke late.
|
|
33
|
+
if (objectUrl) setTimeout(() => URL.revokeObjectURL(objectUrl), REVOKE_DELAY_MS);
|
|
34
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
PluginSurfaceProps,
|
|
6
6
|
} from "@getpaseo/plugin/client";
|
|
7
7
|
import { ConfigSidebarItem } from "./client/config-sidebar";
|
|
8
|
+
import { OmpGeneratedImagesRow } from "./client/generated-image";
|
|
8
9
|
import { OMP_ICON } from "./client/hub-icon";
|
|
9
10
|
import { HubPopover } from "./client/hub-popover";
|
|
10
11
|
import { summarizeHubProcesses } from "./client/hub-status";
|
|
@@ -43,6 +44,11 @@ import {
|
|
|
43
44
|
composerPillSettings,
|
|
44
45
|
composerPillSettingsSchema,
|
|
45
46
|
} from "./shared/composer-pill-settings";
|
|
47
|
+
import {
|
|
48
|
+
OMP_GENERATED_IMAGE_KIND,
|
|
49
|
+
ompGeneratedImagesSchema,
|
|
50
|
+
transformOmpGeneratedImageItem,
|
|
51
|
+
} from "./shared/generated-image";
|
|
46
52
|
import { listHubProcesses } from "./shared/hub";
|
|
47
53
|
import {
|
|
48
54
|
OMP_LSP_DIAGNOSTICS_KIND,
|
|
@@ -255,6 +261,19 @@ export default function contribute(client: PluginClientContext) {
|
|
|
255
261
|
return transformOmpImageToolItem(item);
|
|
256
262
|
},
|
|
257
263
|
});
|
|
264
|
+
const removeGeneratedImageRenderer = client.addTimelineRenderer({
|
|
265
|
+
kind: OMP_GENERATED_IMAGE_KIND,
|
|
266
|
+
version: 1,
|
|
267
|
+
schema: ompGeneratedImagesSchema,
|
|
268
|
+
Component: OmpGeneratedImagesRow,
|
|
269
|
+
});
|
|
270
|
+
const removeGeneratedImageTransformer = client.addTimelineTransformer({
|
|
271
|
+
id: "omp-generated-images",
|
|
272
|
+
query: { itemType: "tool_call" },
|
|
273
|
+
transform({ item }) {
|
|
274
|
+
return transformOmpGeneratedImageItem(item);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
258
277
|
const loadStoreQuotas = createStoreQuotaLoader(
|
|
259
278
|
(input) => client.rpc(listOmpQuotas, input),
|
|
260
279
|
QUOTA_POLL_MS,
|
|
@@ -543,6 +562,8 @@ export default function contribute(client: PluginClientContext) {
|
|
|
543
562
|
removeLspDiagnosticsRenderer();
|
|
544
563
|
removeLspTransformer();
|
|
545
564
|
removeImageTransformer();
|
|
565
|
+
removeGeneratedImageRenderer();
|
|
566
|
+
removeGeneratedImageTransformer();
|
|
546
567
|
removeOpenConfig();
|
|
547
568
|
removeConfigEntry();
|
|
548
569
|
removeOpenWorkspace();
|
package/index.server.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { resolveGeneratedImages } from "./server/generated-images";
|
|
2
3
|
import { resolveListHubProcesses, resolveTailHubLog } from "./server/hub";
|
|
3
4
|
import {
|
|
4
5
|
OmpBrowserAuthorizationRegistry,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
} from "./server/mcp-browser";
|
|
7
8
|
import { resolveListOmpMemory } from "./server/memory";
|
|
8
9
|
import { OmpAccounts } from "./server/omp-accounts";
|
|
10
|
+
import { resolveListOmpAgents } from "./server/omp-agents";
|
|
9
11
|
import { resolveListOmpConfig } from "./server/omp-config";
|
|
10
12
|
import { OmpMcps } from "./server/omp-mcps";
|
|
11
13
|
import { resolveListOmpModels } from "./server/omp-models";
|
|
@@ -49,6 +51,7 @@ import {
|
|
|
49
51
|
} from "./server/subagents";
|
|
50
52
|
import { resolveGetOmpSupportReport } from "./server/support-diagnostics";
|
|
51
53
|
import { composerPillSettings } from "./shared/composer-pill-settings";
|
|
54
|
+
import { resolveOmpGeneratedImages } from "./shared/generated-image";
|
|
52
55
|
import { listHubProcesses, tailHubLog } from "./shared/hub";
|
|
53
56
|
import { openOmpMcpAuthorizationInPaseoBrowser } from "./shared/mcp";
|
|
54
57
|
import { listOmpMemory } from "./shared/memory";
|
|
@@ -62,6 +65,7 @@ import {
|
|
|
62
65
|
startOmpAccountLogin,
|
|
63
66
|
submitOmpAccountLoginCode,
|
|
64
67
|
} from "./shared/omp-accounts";
|
|
68
|
+
import { listOmpAgents } from "./shared/omp-agents";
|
|
65
69
|
import { listOmpConfig } from "./shared/omp-config";
|
|
66
70
|
import {
|
|
67
71
|
addOmpMcp,
|
|
@@ -201,6 +205,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
201
205
|
server.handle(listOmpMemory, scoped(resolveListOmpMemory));
|
|
202
206
|
server.handle(listOmpConfig, scoped(resolveListOmpConfig));
|
|
203
207
|
server.handle(listOmpModels, scoped(resolveListOmpModels));
|
|
208
|
+
server.handle(listOmpAgents, scoped(resolveListOmpAgents));
|
|
204
209
|
server.handle(listOmpPlugins, scoped(resolveListOmpPlugins));
|
|
205
210
|
server.handle(listOmpMarketplaces, scoped(resolveListOmpMarketplaces));
|
|
206
211
|
server.handle(browseOmpMarketplace, scoped(resolveBrowseOmpMarketplace));
|
|
@@ -218,6 +223,9 @@ export default function contribute(server: PluginServerContext) {
|
|
|
218
223
|
server.handle(getOmpUpdateStatus, resolveGetOmpUpdateStatus);
|
|
219
224
|
server.handle(installOmpUpdate, resolveInstallOmpUpdate);
|
|
220
225
|
server.handle(getOmpImage, (input) => resolveGetOmpImage(input, ompImageCache()));
|
|
226
|
+
server.handle(resolveOmpGeneratedImages, (input) =>
|
|
227
|
+
resolveGeneratedImages(input, ompImageCache()),
|
|
228
|
+
);
|
|
221
229
|
server.handle(
|
|
222
230
|
getOmpSupportReport,
|
|
223
231
|
scoped((input) => resolveGetOmpSupportReport(input, protocolViolations, operationalFailures)),
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { basename, dirname, extname, isAbsolute, join } from "node:path";
|
|
4
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
5
|
+
import type { resolveOmpGeneratedImages } from "../shared/generated-image";
|
|
6
|
+
import { isValidImagePayload, type OmpImageMimeType } from "./provider/image";
|
|
7
|
+
import { MAX_CACHED_IMAGE_BYTES, type OmpImageCache } from "./provider/image-cache";
|
|
8
|
+
import { readRegularFile } from "./regular-file";
|
|
9
|
+
|
|
10
|
+
/** The name OMP's `generate_image` gives its output files, written to the OS temp directory. */
|
|
11
|
+
const GENERATED_FILE_NAME = /^omp-image-[A-Za-z0-9_-]+\.(?:gif|jpe?g|png|webp)$/u;
|
|
12
|
+
const MIME_BY_EXTENSION: Readonly<Record<string, OmpImageMimeType>> = {
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".jpg": "image/jpeg",
|
|
15
|
+
".jpeg": "image/jpeg",
|
|
16
|
+
".png": "image/png",
|
|
17
|
+
".webp": "image/webp",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Only `omp-image-*` files directly in the temp directory are read; any other path is refused. */
|
|
21
|
+
function readGeneratedImage(
|
|
22
|
+
path: string,
|
|
23
|
+
): { bytes: Buffer; mimeType: OmpImageMimeType } | undefined {
|
|
24
|
+
const name = basename(path);
|
|
25
|
+
const mimeType = MIME_BY_EXTENSION[extname(name).toLowerCase()];
|
|
26
|
+
if (!isAbsolute(path) || !GENERATED_FILE_NAME.test(name) || !mimeType) return undefined;
|
|
27
|
+
let directory: string;
|
|
28
|
+
try {
|
|
29
|
+
directory = realpathSync(dirname(path));
|
|
30
|
+
if (directory !== realpathSync(tmpdir())) return undefined;
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const bytes = readRegularFile(join(directory, name), MAX_CACHED_IMAGE_BYTES);
|
|
35
|
+
// Only the magic bytes are checked, so encode only the header (12 bytes are 16 characters).
|
|
36
|
+
if (!bytes || !isValidImagePayload(bytes.subarray(0, 12).toString("base64"), mimeType, 16)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return { bytes, mimeType };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveGeneratedImages(
|
|
43
|
+
input: RpcInput<typeof resolveOmpGeneratedImages>,
|
|
44
|
+
cache: OmpImageCache,
|
|
45
|
+
): RpcOutput<typeof resolveOmpGeneratedImages> {
|
|
46
|
+
return {
|
|
47
|
+
images: input.paths.map((path) => {
|
|
48
|
+
const image = readGeneratedImage(path);
|
|
49
|
+
if (!image) return { status: "missing" as const };
|
|
50
|
+
return {
|
|
51
|
+
status: "available" as const,
|
|
52
|
+
ref: cache.store(image.bytes, image.mimeType),
|
|
53
|
+
mimeType: image.mimeType,
|
|
54
|
+
};
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { mkdtemp, readdir, readFile, rm, stat } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
4
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
5
|
+
import { parse as parseYaml } from "yaml";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { type listOmpAgents, OMP_AGENT_LIMIT, type OmpAgent } from "../shared/omp-agents";
|
|
8
|
+
import { OmpAgentNameSchema } from "../shared/omp-settings";
|
|
9
|
+
import { resolveOmpExecutable } from "./omp-settings";
|
|
10
|
+
import { currentOmpEnvironment, ompAgentDir } from "./paths";
|
|
11
|
+
import { buildStatefulCommandEnv, defaultSpawn, runBounded } from "./provider-diagnostics";
|
|
12
|
+
|
|
13
|
+
const UNPACK_TIMEOUT_MS = 15_000;
|
|
14
|
+
const KILL_GRACE_MS = 1_000;
|
|
15
|
+
const UNPACK_OUTPUT_LIMIT = 64 * 1024;
|
|
16
|
+
const AGENT_FILE_LIMIT = 256 * 1024;
|
|
17
|
+
const FRONTMATTER = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---/u;
|
|
18
|
+
const BUNDLED_FAILURE = "Bundled agents could not be listed.";
|
|
19
|
+
|
|
20
|
+
/** Everything OMP would use to relocate its config, data, state, cache or agent directory. */
|
|
21
|
+
const OMP_LOCATION_ENV = [
|
|
22
|
+
"OMP_AGENT_DIR",
|
|
23
|
+
"OMP_PROFILE",
|
|
24
|
+
"OMP_SESSION_DIR",
|
|
25
|
+
"PASEO_OMP_AGENT_DIR",
|
|
26
|
+
"PI_CODING_AGENT_DIR",
|
|
27
|
+
"PI_CODING_AGENT_SESSION_DIR",
|
|
28
|
+
"PI_CONFIG_DIR",
|
|
29
|
+
"PI_PROFILE",
|
|
30
|
+
"XDG_CACHE_HOME",
|
|
31
|
+
"XDG_CONFIG_HOME",
|
|
32
|
+
"XDG_DATA_HOME",
|
|
33
|
+
"XDG_STATE_HOME",
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
const UnpackResultSchema = z.object({ written: z.array(z.string()) });
|
|
37
|
+
|
|
38
|
+
export interface OmpAgentDependencies {
|
|
39
|
+
/** Names of the agents OMP ships with. Rejects when OMP cannot list them. */
|
|
40
|
+
bundledNames(): Promise<string[]>;
|
|
41
|
+
userAgentsDir(): string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Names OMP reserves for itself and never registers from an agent file. */
|
|
45
|
+
const RESERVED_AGENT_NAMES: readonly string[] = ["main", "sub"];
|
|
46
|
+
|
|
47
|
+
/** The name OMP registers for an agent file: its frontmatter `name`, which needs a `description`. */
|
|
48
|
+
async function agentNameFromFile(path: string): Promise<string | null> {
|
|
49
|
+
const metadata = await stat(path);
|
|
50
|
+
if (!metadata.isFile() || metadata.size > AGENT_FILE_LIMIT) return null;
|
|
51
|
+
const frontmatter = FRONTMATTER.exec(await readFile(path, "utf8"));
|
|
52
|
+
if (!frontmatter?.[1]) return null;
|
|
53
|
+
let fields: unknown;
|
|
54
|
+
try {
|
|
55
|
+
fields = parseYaml(frontmatter[1]);
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (fields === null || typeof fields !== "object") return null;
|
|
60
|
+
const { name, description } = fields as Record<string, unknown>;
|
|
61
|
+
if (typeof description !== "string" || description.length === 0) return null;
|
|
62
|
+
if (typeof name !== "string" || RESERVED_AGENT_NAMES.includes(name.trim().toLowerCase())) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
// OMP keeps the name as written; one with surrounding whitespace cannot be routed, so skip it.
|
|
66
|
+
const parsed = OmpAgentNameSchema.safeParse(name);
|
|
67
|
+
return parsed.success ? parsed.data : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function agentNamesFrom(paths: readonly string[]): Promise<string[]> {
|
|
71
|
+
const names: string[] = [];
|
|
72
|
+
for (const path of paths.slice(0, OMP_AGENT_LIMIT)) {
|
|
73
|
+
if (!path.endsWith(".md")) continue;
|
|
74
|
+
const name = await agentNameFromFile(path).catch(() => null);
|
|
75
|
+
if (name) names.push(name);
|
|
76
|
+
}
|
|
77
|
+
return names;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function agentNamesIn(directory: string): Promise<string[]> {
|
|
81
|
+
try {
|
|
82
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
83
|
+
return agentNamesFrom(
|
|
84
|
+
entries.filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name)),
|
|
85
|
+
);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A scratch-only OMP environment: nothing inherited can point OMP at a real directory. */
|
|
93
|
+
export function scratchOmpEnvironment(base: NodeJS.ProcessEnv, scratch: string): NodeJS.ProcessEnv {
|
|
94
|
+
const environment = { ...base };
|
|
95
|
+
for (const key of OMP_LOCATION_ENV) delete environment[key];
|
|
96
|
+
return {
|
|
97
|
+
...environment,
|
|
98
|
+
HOME: scratch,
|
|
99
|
+
USERPROFILE: scratch,
|
|
100
|
+
PI_CODING_AGENT_DIR: join(scratch, "agent"),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* OMP has no agent list command, but `agents unpack` writes the bundled set to a folder. The
|
|
106
|
+
* folder and the whole OMP home are throwaway, so an OMP that ignores `--dir` still writes
|
|
107
|
+
* nothing into a real agent directory.
|
|
108
|
+
*/
|
|
109
|
+
async function unpackBundledNames(): Promise<string[]> {
|
|
110
|
+
const executable = await resolveOmpExecutable();
|
|
111
|
+
if (!executable) throw new Error("The OMP executable could not be resolved.");
|
|
112
|
+
const scratch = await mkdtemp(join(tmpdir(), "paseo-omp-agents-"));
|
|
113
|
+
try {
|
|
114
|
+
const result = await runBounded(
|
|
115
|
+
defaultSpawn,
|
|
116
|
+
executable,
|
|
117
|
+
["agents", "unpack", "--dir", join(scratch, "out"), "--json"],
|
|
118
|
+
scratchOmpEnvironment(buildStatefulCommandEnv(currentOmpEnvironment()), scratch),
|
|
119
|
+
UNPACK_TIMEOUT_MS,
|
|
120
|
+
KILL_GRACE_MS,
|
|
121
|
+
UNPACK_OUTPUT_LIMIT,
|
|
122
|
+
scratch,
|
|
123
|
+
);
|
|
124
|
+
if (result.outcome !== "exited" || result.exitCode !== 0 || result.truncated) {
|
|
125
|
+
throw new Error("OMP could not unpack its bundled agents.");
|
|
126
|
+
}
|
|
127
|
+
const { written } = UnpackResultSchema.parse(JSON.parse(result.stdout));
|
|
128
|
+
const inside = written.filter((path) => {
|
|
129
|
+
const within = relative(scratch, path);
|
|
130
|
+
return isAbsolute(path) && !within.startsWith("..") && !isAbsolute(within);
|
|
131
|
+
});
|
|
132
|
+
return await agentNamesFrom(inside);
|
|
133
|
+
} finally {
|
|
134
|
+
await rm(scratch, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const DEFAULT_DEPENDENCIES: OmpAgentDependencies = {
|
|
139
|
+
bundledNames: unpackBundledNames,
|
|
140
|
+
userAgentsDir: () => join(ompAgentDir(), "agents"),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export async function listOmpAgentsWithDependencies(
|
|
144
|
+
input: RpcInput<typeof listOmpAgents>,
|
|
145
|
+
dependencies: OmpAgentDependencies,
|
|
146
|
+
): Promise<{ agents: OmpAgent[]; error?: string }> {
|
|
147
|
+
// The most specific source wins when a name exists in several places.
|
|
148
|
+
const bySource = new Map<string, OmpAgent["source"]>();
|
|
149
|
+
let error: string | undefined;
|
|
150
|
+
try {
|
|
151
|
+
for (const name of await dependencies.bundledNames()) bySource.set(name, "bundled");
|
|
152
|
+
} catch {
|
|
153
|
+
error = BUNDLED_FAILURE;
|
|
154
|
+
}
|
|
155
|
+
for (const name of await agentNamesIn(dependencies.userAgentsDir())) bySource.set(name, "user");
|
|
156
|
+
if (input.cwd && isAbsolute(input.cwd)) {
|
|
157
|
+
for (const name of await agentNamesIn(join(input.cwd, ".omp", "agents"))) {
|
|
158
|
+
bySource.set(name, "project");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const agents = [...bySource]
|
|
162
|
+
.map(([name, source]) => ({ name, source }))
|
|
163
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
164
|
+
.slice(0, OMP_AGENT_LIMIT);
|
|
165
|
+
return error ? { agents, error } : { agents };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function resolveListOmpAgents(input: RpcInput<typeof listOmpAgents>) {
|
|
169
|
+
return listOmpAgentsWithDependencies(input, DEFAULT_DEPENDENCIES);
|
|
170
|
+
}
|
package/server/omp-settings.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type OmpSettingType,
|
|
14
14
|
OmpSettingTypeSchema,
|
|
15
15
|
parseOmpStructuredSettingValue,
|
|
16
|
+
structuredSettingType,
|
|
16
17
|
type updateOmpSettings,
|
|
17
18
|
} from "../shared/omp-settings";
|
|
18
19
|
import { SerialMutationQueue } from "./mutation-queue";
|
|
@@ -315,8 +316,7 @@ async function loadCatalog(
|
|
|
315
316
|
|
|
316
317
|
function serializeSettingValue(setting: OmpSetting, value: unknown): string | null {
|
|
317
318
|
if (isOmpStructuredSettingPath(setting.path)) {
|
|
318
|
-
|
|
319
|
-
if (setting.type !== expectedType) return null;
|
|
319
|
+
if (setting.type !== structuredSettingType(setting.path)) return null;
|
|
320
320
|
const parsed = parseOmpStructuredSettingValue(setting.path, value);
|
|
321
321
|
return parsed === undefined ? null : JSON.stringify(parsed);
|
|
322
322
|
}
|
|
@@ -332,7 +332,7 @@ function isEditableSetting(setting: OmpSetting): boolean {
|
|
|
332
332
|
if (setting.redacted) return false;
|
|
333
333
|
if (["boolean", "number", "string", "enum"].includes(setting.type)) return true;
|
|
334
334
|
if (!isOmpStructuredSettingPath(setting.path)) return false;
|
|
335
|
-
return setting.type === (setting.path
|
|
335
|
+
return setting.type === structuredSettingType(setting.path);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
export async function listOmpSettingsWithDependencies(
|
|
@@ -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.405.1"; // x-release-please-version
|
|
@@ -23,7 +23,7 @@ import type { getOmpImage } from "../../shared/provider-image";
|
|
|
23
23
|
import type { OmpImageMimeType } from "./image";
|
|
24
24
|
|
|
25
25
|
/** Matches the projector's 8 MiB encoded image bound. */
|
|
26
|
-
const MAX_CACHED_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
26
|
+
export const MAX_CACHED_IMAGE_BYTES = 6 * 1024 * 1024;
|
|
27
27
|
const MAX_CACHE_BYTES = 256 * 1024 * 1024;
|
|
28
28
|
const MAX_CACHE_FILES = 1_024;
|
|
29
29
|
const PRIVATE_DIRECTORY_MODE = 0o700;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
/** The bytes of a regular file of at most `maxBytes`; a symlink, FIFO, directory or larger file reads as nothing. */
|
|
4
|
+
export function readRegularFile(path: string, maxBytes: number): Buffer | undefined {
|
|
5
|
+
// O_NONBLOCK keeps a FIFO planted under the file's name from hanging the worker.
|
|
6
|
+
const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
7
|
+
let descriptor: number;
|
|
8
|
+
try {
|
|
9
|
+
if (lstatSync(path).isSymbolicLink()) return undefined;
|
|
10
|
+
descriptor = openSync(path, flags);
|
|
11
|
+
} catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const stat = fstatSync(descriptor);
|
|
16
|
+
if (!stat.isFile() || stat.size > maxBytes) return undefined;
|
|
17
|
+
// A file another user planted in a shared directory is not ours to read.
|
|
18
|
+
if (process.getuid !== undefined && stat.uid !== process.getuid()) return undefined;
|
|
19
|
+
const bytes = Buffer.alloc(stat.size);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
while (offset < bytes.length) {
|
|
22
|
+
const read = readSync(descriptor, bytes, offset, bytes.length - offset, offset);
|
|
23
|
+
if (read === 0) return undefined;
|
|
24
|
+
offset += read;
|
|
25
|
+
}
|
|
26
|
+
return bytes;
|
|
27
|
+
} finally {
|
|
28
|
+
closeSync(descriptor);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ompImageMimeTypeSchema, ompImageRefSchema } from "./provider-image";
|
|
4
|
+
|
|
5
|
+
export const OMP_GENERATED_IMAGE_KIND = "omp-generated-images";
|
|
6
|
+
|
|
7
|
+
const MAX_GENERATED_IMAGES = 8;
|
|
8
|
+
const MAX_PATH_LENGTH = 1024;
|
|
9
|
+
const pathSchema = z.string().min(1).max(MAX_PATH_LENGTH);
|
|
10
|
+
const pathsSchema = z.array(pathSchema).min(1).max(MAX_GENERATED_IMAGES);
|
|
11
|
+
|
|
12
|
+
/** Files OMP's `generate_image` tool saved on the daemon host; the row itself carries no usable bytes. */
|
|
13
|
+
export const ompGeneratedImagesSchema = z.object({ paths: pathsSchema });
|
|
14
|
+
export type OmpGeneratedImages = z.infer<typeof ompGeneratedImagesSchema>;
|
|
15
|
+
|
|
16
|
+
/** Copies each file into the image cache and returns its reference, so the stock image viewer can show it. */
|
|
17
|
+
export const resolveOmpGeneratedImages = defineRpc({
|
|
18
|
+
name: "paseo-omp.resolve-generated-images",
|
|
19
|
+
input: z.strictObject({ paths: pathsSchema }),
|
|
20
|
+
output: z.object({
|
|
21
|
+
images: z.array(
|
|
22
|
+
z.discriminatedUnion("status", [
|
|
23
|
+
z.object({
|
|
24
|
+
status: z.literal("available"),
|
|
25
|
+
ref: ompImageRefSchema,
|
|
26
|
+
mimeType: ompImageMimeTypeSchema,
|
|
27
|
+
}),
|
|
28
|
+
z.object({ status: z.literal("missing") }),
|
|
29
|
+
]),
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const generateImageRowSchema = z.object({
|
|
35
|
+
name: z.literal("generate_image"),
|
|
36
|
+
callId: z.string(),
|
|
37
|
+
status: z.literal("completed"),
|
|
38
|
+
detail: z.object({
|
|
39
|
+
type: z.literal("unknown"),
|
|
40
|
+
output: z.object({
|
|
41
|
+
details: z.object({ imagePaths: z.array(z.string()) }).loose(),
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Replaces a completed built-in `generate_image` row with the images it saved. The provider cuts
|
|
48
|
+
* the row's base64 at 64 KiB, but keeps `details.imagePaths`; a row without paths stays as is.
|
|
49
|
+
*/
|
|
50
|
+
export function transformOmpGeneratedImageItem(item: unknown) {
|
|
51
|
+
const row = generateImageRowSchema.safeParse(item);
|
|
52
|
+
if (!row.success) return undefined;
|
|
53
|
+
const paths = row.data.detail.output.details.imagePaths
|
|
54
|
+
.filter((path) => path.length > 0 && path.length <= MAX_PATH_LENGTH)
|
|
55
|
+
.slice(0, MAX_GENERATED_IMAGES);
|
|
56
|
+
if (paths.length === 0) return undefined;
|
|
57
|
+
return {
|
|
58
|
+
items: [
|
|
59
|
+
{
|
|
60
|
+
type: "plugin" as const,
|
|
61
|
+
kind: OMP_GENERATED_IMAGE_KIND,
|
|
62
|
+
id: row.data.callId,
|
|
63
|
+
version: 1,
|
|
64
|
+
data: { paths },
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineRpc } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OmpWorkspaceCwdSchema } from "./hub";
|
|
4
|
+
import { OmpAgentNameSchema } from "./omp-settings";
|
|
5
|
+
import { OmpStoreSchema } from "./omp-store";
|
|
6
|
+
|
|
7
|
+
export const OMP_AGENT_LIMIT = 256;
|
|
8
|
+
|
|
9
|
+
export const OmpAgentSchema = z
|
|
10
|
+
.object({ name: OmpAgentNameSchema, source: z.enum(["bundled", "user", "project"]) })
|
|
11
|
+
.strict();
|
|
12
|
+
export type OmpAgent = z.infer<typeof OmpAgentSchema>;
|
|
13
|
+
|
|
14
|
+
export const listOmpAgents = defineRpc({
|
|
15
|
+
name: "paseo-omp.list-agents",
|
|
16
|
+
input: z
|
|
17
|
+
.object({ store: OmpStoreSchema.optional(), cwd: OmpWorkspaceCwdSchema.optional() })
|
|
18
|
+
.strict(),
|
|
19
|
+
output: z
|
|
20
|
+
.object({
|
|
21
|
+
agents: z.array(OmpAgentSchema).max(OMP_AGENT_LIMIT),
|
|
22
|
+
/** Set when the bundled agents could not be listed; user and project agents still appear. */
|
|
23
|
+
error: z.string().max(256).optional(),
|
|
24
|
+
})
|
|
25
|
+
.strict(),
|
|
26
|
+
});
|
package/shared/omp-settings.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function isValidOmpModelSelector(value: string): boolean {
|
|
|
67
67
|
return OmpModelSelectorSchema.safeParse(value).success;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const OmpAgentNameSchema = z
|
|
70
|
+
export const OmpAgentNameSchema = z
|
|
71
71
|
.string()
|
|
72
72
|
.min(1)
|
|
73
73
|
.max(128)
|
|
@@ -138,6 +138,11 @@ export const OmpAgentAdvisorSchema = z
|
|
|
138
138
|
"Too many agent advisor overrides.",
|
|
139
139
|
);
|
|
140
140
|
|
|
141
|
+
export const OmpDisabledAgentsSchema = z
|
|
142
|
+
.array(OmpAgentNameSchema)
|
|
143
|
+
.max(MAX_ROUTING_ENTRIES)
|
|
144
|
+
.refine((value) => new Set(value).size === value.length, "Disabled agents must be unique.");
|
|
145
|
+
|
|
141
146
|
export const OMP_STRUCTURED_SETTING_PATHS = [
|
|
142
147
|
"modelRoles",
|
|
143
148
|
"retry.fallbackChains",
|
|
@@ -146,6 +151,7 @@ export const OMP_STRUCTURED_SETTING_PATHS = [
|
|
|
146
151
|
"task.agentServiceTierOverrides",
|
|
147
152
|
"task.agentPrewalk",
|
|
148
153
|
"task.agentAdvisor",
|
|
154
|
+
"task.disabledAgents",
|
|
149
155
|
] as const;
|
|
150
156
|
export type OmpStructuredSettingPath = (typeof OMP_STRUCTURED_SETTING_PATHS)[number];
|
|
151
157
|
|
|
@@ -165,6 +171,8 @@ export function parseOmpStructuredSettingValue(path: string, value: unknown): un
|
|
|
165
171
|
return OmpAgentPrewalkSchema.safeParse(value).data;
|
|
166
172
|
case "task.agentAdvisor":
|
|
167
173
|
return OmpAgentAdvisorSchema.safeParse(value).data;
|
|
174
|
+
case "task.disabledAgents":
|
|
175
|
+
return OmpDisabledAgentsSchema.safeParse(value).data;
|
|
168
176
|
default:
|
|
169
177
|
return undefined;
|
|
170
178
|
}
|
|
@@ -174,6 +182,11 @@ export function isOmpStructuredSettingPath(path: string): path is OmpStructuredS
|
|
|
174
182
|
return (OMP_STRUCTURED_SETTING_PATHS as readonly string[]).includes(path);
|
|
175
183
|
}
|
|
176
184
|
|
|
185
|
+
/** The OMP value type each structured path must have to be editable. */
|
|
186
|
+
export function structuredSettingType(path: OmpStructuredSettingPath): "array" | "record" {
|
|
187
|
+
return path === "cycleOrder" || path === "task.disabledAgents" ? "array" : "record";
|
|
188
|
+
}
|
|
189
|
+
|
|
177
190
|
export const OmpSettingSchema = z
|
|
178
191
|
.object({
|
|
179
192
|
path: z.string(),
|
|
@@ -490,6 +503,13 @@ const OmpStructuredSettingChangeSchema = z.discriminatedUnion("path", [
|
|
|
490
503
|
value: OmpAgentAdvisorSchema,
|
|
491
504
|
})
|
|
492
505
|
.strict(),
|
|
506
|
+
z
|
|
507
|
+
.object({
|
|
508
|
+
operation: z.literal("set"),
|
|
509
|
+
path: z.literal("task.disabledAgents"),
|
|
510
|
+
value: OmpDisabledAgentsSchema,
|
|
511
|
+
})
|
|
512
|
+
.strict(),
|
|
493
513
|
]);
|
|
494
514
|
|
|
495
515
|
const OmpSettingChangeSchema = z.union([
|
package/shared/provider-image.ts
CHANGED
|
@@ -83,10 +83,15 @@ function hasExpectedHeader(mimeType: string, bytes: readonly number[]): boolean
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const ompImageMimeTypeSchema = z.enum([
|
|
86
|
+
export const ompImageMimeTypeSchema = z.enum([
|
|
87
|
+
"image/gif",
|
|
88
|
+
"image/jpeg",
|
|
89
|
+
"image/png",
|
|
90
|
+
"image/webp",
|
|
91
|
+
]);
|
|
87
92
|
const ompImageIdSchema = z.string().regex(/^[A-Za-z0-9_-]{16}$/u);
|
|
88
93
|
/** SHA-256 of the image bytes, naming the file in the server's image cache. */
|
|
89
|
-
const ompImageRefSchema = z.string().regex(/^[0-9a-f]{64}$/u);
|
|
94
|
+
export const ompImageRefSchema = z.string().regex(/^[0-9a-f]{64}$/u);
|
|
90
95
|
|
|
91
96
|
const cachedOmpImageSchema = z.object({
|
|
92
97
|
id: ompImageIdSchema,
|