@mcowger/pi-plexus 0.4.2 → 0.5.3
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/dist/extension.js +429 -0
- package/package.json +17 -34
- package/index.ts +0 -196
- package/src/map-models.ts +0 -112
- package/src/pi-compat.ts +0 -7
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/extension.ts
|
|
3
|
+
import * as os from "os";
|
|
4
|
+
import * as path4 from "path";
|
|
5
|
+
|
|
6
|
+
// ../plexus-models/src/convert.ts
|
|
7
|
+
var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
|
|
8
|
+
var API_DIALECT_MAP = {
|
|
9
|
+
chat_completions: "openai-completions",
|
|
10
|
+
messages: "anthropic-messages",
|
|
11
|
+
gemini: "google-generative-ai",
|
|
12
|
+
responses: "openai-responses"
|
|
13
|
+
};
|
|
14
|
+
function mapPreferredApi(raw) {
|
|
15
|
+
if (raw === undefined)
|
|
16
|
+
return "openai-completions";
|
|
17
|
+
const candidates = Array.isArray(raw) ? raw : [raw];
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
const mapped = API_DIALECT_MAP[candidate];
|
|
20
|
+
if (mapped !== undefined)
|
|
21
|
+
return mapped;
|
|
22
|
+
}
|
|
23
|
+
return "openai-completions";
|
|
24
|
+
}
|
|
25
|
+
function adjustBaseUrl(baseUrl, preferredApi) {
|
|
26
|
+
const stripped = baseUrl.replace(/\/+$/, "");
|
|
27
|
+
switch (preferredApi) {
|
|
28
|
+
case "anthropic-messages":
|
|
29
|
+
return stripped.endsWith("/v1") ? stripped.slice(0, -3) : stripped;
|
|
30
|
+
case "google-generative-ai":
|
|
31
|
+
return stripped.endsWith("/v1") ? `${stripped.slice(0, -3)}/v1beta` : stripped;
|
|
32
|
+
default:
|
|
33
|
+
return stripped;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function mapInputModalities(model) {
|
|
37
|
+
const raw = model.architecture?.input_modalities;
|
|
38
|
+
if (!raw || raw.length === 0)
|
|
39
|
+
return ["text"];
|
|
40
|
+
const result = [];
|
|
41
|
+
for (const m of raw) {
|
|
42
|
+
if (m === "text" || m === "image")
|
|
43
|
+
result.push(m);
|
|
44
|
+
}
|
|
45
|
+
return result.length > 0 ? result : ["text"];
|
|
46
|
+
}
|
|
47
|
+
function inferReasoning(model) {
|
|
48
|
+
const params = model.supported_parameters;
|
|
49
|
+
if (!params)
|
|
50
|
+
return false;
|
|
51
|
+
return params.some((p) => REASONING_PARAMS.has(p));
|
|
52
|
+
}
|
|
53
|
+
function parsePrice(raw) {
|
|
54
|
+
if (raw === undefined)
|
|
55
|
+
return 0;
|
|
56
|
+
const n = parseFloat(raw);
|
|
57
|
+
return isFinite(n) && n >= 0 ? n : 0;
|
|
58
|
+
}
|
|
59
|
+
function resolveContextWindow(model) {
|
|
60
|
+
const v = model.context_length ?? model.top_provider?.context_length ?? null;
|
|
61
|
+
return v != null && v > 0 ? v : 8192;
|
|
62
|
+
}
|
|
63
|
+
function resolveMaxTokens(model, contextWindow) {
|
|
64
|
+
const v = model.top_provider?.max_completion_tokens ?? null;
|
|
65
|
+
return v != null && v > 0 ? v : contextWindow;
|
|
66
|
+
}
|
|
67
|
+
function convertToDescriptor(raw, baseUrl) {
|
|
68
|
+
const preferredApi = mapPreferredApi(raw.preferred_api);
|
|
69
|
+
const adjustedBaseUrl = adjustBaseUrl(baseUrl, preferredApi);
|
|
70
|
+
const contextWindow = resolveContextWindow(raw);
|
|
71
|
+
const maxTokens = resolveMaxTokens(raw, contextWindow);
|
|
72
|
+
const descriptor = {
|
|
73
|
+
id: raw.id,
|
|
74
|
+
name: raw.name ?? raw.id,
|
|
75
|
+
preferredApi,
|
|
76
|
+
provider: "plexus",
|
|
77
|
+
baseUrl: adjustedBaseUrl,
|
|
78
|
+
reasoning: inferReasoning(raw),
|
|
79
|
+
input: mapInputModalities(raw),
|
|
80
|
+
cost: {
|
|
81
|
+
input: parsePrice(raw.pricing?.prompt),
|
|
82
|
+
output: parsePrice(raw.pricing?.completion),
|
|
83
|
+
cacheRead: parsePrice(raw.pricing?.input_cache_read),
|
|
84
|
+
cacheWrite: parsePrice(raw.pricing?.input_cache_write)
|
|
85
|
+
},
|
|
86
|
+
contextWindow,
|
|
87
|
+
maxTokens
|
|
88
|
+
};
|
|
89
|
+
if (raw.pi_provider)
|
|
90
|
+
descriptor.piProvider = raw.pi_provider;
|
|
91
|
+
if (raw.pi_model)
|
|
92
|
+
descriptor.piModel = raw.pi_model;
|
|
93
|
+
if (raw.pi_options && Object.keys(raw.pi_options).length > 0)
|
|
94
|
+
descriptor.piOptions = raw.pi_options;
|
|
95
|
+
return descriptor;
|
|
96
|
+
}
|
|
97
|
+
function convertDescriptors(models, baseUrl) {
|
|
98
|
+
const result = [];
|
|
99
|
+
for (const m of models) {
|
|
100
|
+
if (!m.id)
|
|
101
|
+
continue;
|
|
102
|
+
result.push(convertToDescriptor(m, baseUrl));
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
function detectOpenAICompletionsCompat(providerName, baseUrl) {
|
|
107
|
+
const name = providerName.toLowerCase();
|
|
108
|
+
let host = "";
|
|
109
|
+
try {
|
|
110
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
111
|
+
} catch {}
|
|
112
|
+
const isCerebras = name === "cerebras" || host.includes("cerebras");
|
|
113
|
+
const isChutes = name === "chutes.ai" || host.includes("chutes.ai");
|
|
114
|
+
const isXai = name === "xai" || host === "api.x.ai";
|
|
115
|
+
const isZai = name === "zai" || host === "api.zai.com" || host.includes("z.ai");
|
|
116
|
+
const isMoonshot = name === "moonshotai" || name === "moonshotai-cn" || host.includes("moonshot") || host.includes("kimi");
|
|
117
|
+
const isOpencode = name === "opencode" || host.includes("opencode");
|
|
118
|
+
const isCloudflareWorkers = host.includes("workers.cloudflare.com") || host.includes("ai.cloudflare.com");
|
|
119
|
+
const isCloudflareGateway = host.includes("gateway.ai.cloudflare.com");
|
|
120
|
+
const isCloudflare = isCloudflareWorkers || isCloudflareGateway;
|
|
121
|
+
const isDeepSeek = name === "deepseek" || host.includes("deepseek");
|
|
122
|
+
const isOpenRouter = name === "openrouter" || host.includes("openrouter.ai");
|
|
123
|
+
const isNonStandard = isCerebras || isChutes || isXai || isZai || isMoonshot || isOpencode || isCloudflare || isDeepSeek;
|
|
124
|
+
const supportsStore = !isNonStandard;
|
|
125
|
+
const supportsDeveloperRole = !isNonStandard;
|
|
126
|
+
const supportsReasoningEffort = !isXai && !isZai && !isMoonshot && !isCloudflareGateway;
|
|
127
|
+
let maxTokensField = "max_completion_tokens";
|
|
128
|
+
if (isChutes || isMoonshot || isCloudflareGateway) {
|
|
129
|
+
maxTokensField = "max_tokens";
|
|
130
|
+
}
|
|
131
|
+
let thinkingFormat = "openai";
|
|
132
|
+
if (isDeepSeek)
|
|
133
|
+
thinkingFormat = "deepseek";
|
|
134
|
+
else if (isZai)
|
|
135
|
+
thinkingFormat = "zai";
|
|
136
|
+
else if (isOpenRouter)
|
|
137
|
+
thinkingFormat = "openrouter";
|
|
138
|
+
const requiresReasoningContentOnAssistantMessages = isDeepSeek;
|
|
139
|
+
const cacheControlFormat = isOpenRouter ? "anthropic" : undefined;
|
|
140
|
+
const supportsStrictMode = !isMoonshot && !isCloudflareGateway;
|
|
141
|
+
const supportsLongCacheRetention = !isCloudflare;
|
|
142
|
+
const compat = {
|
|
143
|
+
supportsStore,
|
|
144
|
+
supportsDeveloperRole,
|
|
145
|
+
supportsReasoningEffort,
|
|
146
|
+
supportsUsageInStreaming: true,
|
|
147
|
+
maxTokensField,
|
|
148
|
+
requiresToolResultName: false,
|
|
149
|
+
requiresAssistantAfterToolResult: false,
|
|
150
|
+
requiresThinkingAsText: false,
|
|
151
|
+
requiresReasoningContentOnAssistantMessages,
|
|
152
|
+
thinkingFormat,
|
|
153
|
+
openRouterRouting: {},
|
|
154
|
+
vercelGatewayRouting: {},
|
|
155
|
+
zaiToolStream: false,
|
|
156
|
+
supportsStrictMode,
|
|
157
|
+
sendSessionAffinityHeaders: false,
|
|
158
|
+
supportsLongCacheRetention
|
|
159
|
+
};
|
|
160
|
+
if (cacheControlFormat !== undefined) {
|
|
161
|
+
compat.cacheControlFormat = cacheControlFormat;
|
|
162
|
+
}
|
|
163
|
+
return compat;
|
|
164
|
+
}
|
|
165
|
+
async function fetchPlexusModels(apiKey, modelsUrl) {
|
|
166
|
+
const res = await fetch(modelsUrl, {
|
|
167
|
+
headers: {
|
|
168
|
+
Authorization: `Bearer ${apiKey}`,
|
|
169
|
+
Accept: "application/json"
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
|
|
174
|
+
}
|
|
175
|
+
const raw = await res.json();
|
|
176
|
+
return { models: raw.data ?? [], raw };
|
|
177
|
+
}
|
|
178
|
+
// ../plexus-models/src/config.ts
|
|
179
|
+
import * as fs from "fs";
|
|
180
|
+
import * as path from "path";
|
|
181
|
+
var PLEXUS_DIR = "extensions/plexus";
|
|
182
|
+
var CONFIG_FILE = "config.json";
|
|
183
|
+
function getConfigPath(agentDir) {
|
|
184
|
+
return path.join(agentDir, PLEXUS_DIR, CONFIG_FILE);
|
|
185
|
+
}
|
|
186
|
+
function getConfigSync(agentDir) {
|
|
187
|
+
try {
|
|
188
|
+
const raw = fs.readFileSync(getConfigPath(agentDir), "utf8");
|
|
189
|
+
const parsed = JSON.parse(raw);
|
|
190
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
191
|
+
return parsed;
|
|
192
|
+
}
|
|
193
|
+
return {};
|
|
194
|
+
} catch {
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function saveBaseUrl(agentDir, baseUrl, defaultModel) {
|
|
199
|
+
const configPath = getConfigPath(agentDir);
|
|
200
|
+
const dir = path.dirname(configPath);
|
|
201
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
202
|
+
const existing = getConfigSync(agentDir);
|
|
203
|
+
const updated = {
|
|
204
|
+
...existing,
|
|
205
|
+
baseUrl: baseUrl.replace(/\/+$/, "")
|
|
206
|
+
};
|
|
207
|
+
if (defaultModel !== undefined) {
|
|
208
|
+
updated.defaultModel = defaultModel;
|
|
209
|
+
}
|
|
210
|
+
await fs.promises.writeFile(configPath, JSON.stringify(updated, null, 2) + `
|
|
211
|
+
`, "utf8");
|
|
212
|
+
}
|
|
213
|
+
function getRawBaseUrl(agentDir) {
|
|
214
|
+
const cfg = getConfigSync(agentDir);
|
|
215
|
+
const raw = cfg.baseUrl ?? process.env["PLEXUS_BASE_URL"] ?? null;
|
|
216
|
+
if (!raw)
|
|
217
|
+
return null;
|
|
218
|
+
return raw.replace(/\/+$/, "");
|
|
219
|
+
}
|
|
220
|
+
function getBaseUrl(agentDir) {
|
|
221
|
+
const raw = getRawBaseUrl(agentDir);
|
|
222
|
+
return raw ? `${raw}/v1` : null;
|
|
223
|
+
}
|
|
224
|
+
function getModelsUrl(agentDir) {
|
|
225
|
+
const raw = getRawBaseUrl(agentDir);
|
|
226
|
+
return raw ? `${raw}/v1/models` : null;
|
|
227
|
+
}
|
|
228
|
+
// ../plexus-models/src/cache.ts
|
|
229
|
+
import * as fs2 from "fs";
|
|
230
|
+
import * as path2 from "path";
|
|
231
|
+
var PLEXUS_DIR2 = "extensions/plexus";
|
|
232
|
+
var CACHE_FILE = "plexus-models-cache.json";
|
|
233
|
+
var RAW_RESPONSE_FILE = "plexus-models-response.json";
|
|
234
|
+
function getCachePath(agentDir) {
|
|
235
|
+
return path2.join(agentDir, PLEXUS_DIR2, CACHE_FILE);
|
|
236
|
+
}
|
|
237
|
+
function getRawResponsePath(agentDir) {
|
|
238
|
+
return path2.join(agentDir, PLEXUS_DIR2, RAW_RESPONSE_FILE);
|
|
239
|
+
}
|
|
240
|
+
function parseCacheData(raw) {
|
|
241
|
+
try {
|
|
242
|
+
const parsed = JSON.parse(raw);
|
|
243
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
244
|
+
return null;
|
|
245
|
+
const obj = parsed;
|
|
246
|
+
if (!Array.isArray(obj["models"]))
|
|
247
|
+
return null;
|
|
248
|
+
return {
|
|
249
|
+
models: obj["models"],
|
|
250
|
+
timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0
|
|
251
|
+
};
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function readCachedModelsSync(agentDir) {
|
|
257
|
+
try {
|
|
258
|
+
const raw = fs2.readFileSync(getCachePath(agentDir), "utf8");
|
|
259
|
+
return parseCacheData(raw);
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function writeCachedModels(agentDir, models) {
|
|
265
|
+
const cachePath = getCachePath(agentDir);
|
|
266
|
+
await fs2.promises.mkdir(path2.dirname(cachePath), { recursive: true });
|
|
267
|
+
const payload = { models, timestamp: Date.now() };
|
|
268
|
+
await fs2.promises.writeFile(cachePath, JSON.stringify(payload, null, 2) + `
|
|
269
|
+
`, "utf8");
|
|
270
|
+
}
|
|
271
|
+
async function writeRawResponse(agentDir, data) {
|
|
272
|
+
const rawPath = getRawResponsePath(agentDir);
|
|
273
|
+
await fs2.promises.mkdir(path2.dirname(rawPath), { recursive: true });
|
|
274
|
+
await fs2.promises.writeFile(rawPath, JSON.stringify(data, null, 2) + `
|
|
275
|
+
`, "utf8");
|
|
276
|
+
}
|
|
277
|
+
// ../plexus-models/src/log.ts
|
|
278
|
+
import * as fs3 from "fs";
|
|
279
|
+
import * as path3 from "path";
|
|
280
|
+
var PLEXUS_DIR3 = "extensions/plexus";
|
|
281
|
+
var LOG_FILE = "plexus.log";
|
|
282
|
+
function log(agentDir, message, data) {
|
|
283
|
+
try {
|
|
284
|
+
const logPath = path3.join(agentDir, PLEXUS_DIR3, LOG_FILE);
|
|
285
|
+
const dir = path3.dirname(logPath);
|
|
286
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
287
|
+
const ts = new Date().toISOString();
|
|
288
|
+
const line = data !== undefined ? `${ts} ${message} ${JSON.stringify(data)}
|
|
289
|
+
` : `${ts} ${message}
|
|
290
|
+
`;
|
|
291
|
+
fs3.appendFileSync(logPath, line, "utf8");
|
|
292
|
+
} catch {}
|
|
293
|
+
}
|
|
294
|
+
// src/mapper.ts
|
|
295
|
+
function descriptorToPiModel(descriptor) {
|
|
296
|
+
const cost = {
|
|
297
|
+
input: descriptor.cost.input * 1e6,
|
|
298
|
+
output: descriptor.cost.output * 1e6,
|
|
299
|
+
cacheRead: descriptor.cost.cacheRead * 1e6,
|
|
300
|
+
cacheWrite: descriptor.cost.cacheWrite * 1e6
|
|
301
|
+
};
|
|
302
|
+
let compat;
|
|
303
|
+
if (descriptor.preferredApi === "openai-completions") {
|
|
304
|
+
const heuristic = detectOpenAICompletionsCompat(descriptor.provider, descriptor.baseUrl);
|
|
305
|
+
const merged = descriptor.piOptions ? { ...heuristic, ...descriptor.piOptions } : heuristic;
|
|
306
|
+
compat = merged;
|
|
307
|
+
} else if (descriptor.piOptions) {
|
|
308
|
+
compat = descriptor.piOptions;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
id: descriptor.id,
|
|
312
|
+
name: descriptor.name,
|
|
313
|
+
api: descriptor.preferredApi,
|
|
314
|
+
baseUrl: descriptor.baseUrl,
|
|
315
|
+
reasoning: descriptor.reasoning,
|
|
316
|
+
input: descriptor.input,
|
|
317
|
+
cost,
|
|
318
|
+
contextWindow: descriptor.contextWindow,
|
|
319
|
+
maxTokens: descriptor.maxTokens,
|
|
320
|
+
...compat !== undefined ? { compat } : {}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/extension.ts
|
|
325
|
+
var PROVIDER_NAME = "plexus";
|
|
326
|
+
function getAgentDir() {
|
|
327
|
+
const override = process.env["PI_CODING_AGENT_DIR"];
|
|
328
|
+
if (override)
|
|
329
|
+
return path4.resolve(override);
|
|
330
|
+
const configDir = process.env["PI_CONFIG_DIR"] || ".pi";
|
|
331
|
+
return path4.join(os.homedir(), configDir, "agent");
|
|
332
|
+
}
|
|
333
|
+
function getApiKey() {
|
|
334
|
+
return process.env["PLEXUS_API_KEY"];
|
|
335
|
+
}
|
|
336
|
+
function plexusExtension(pi) {
|
|
337
|
+
const agentDir = getAgentDir();
|
|
338
|
+
const key = getApiKey();
|
|
339
|
+
if (key) {
|
|
340
|
+
const cached = readCachedModelsSync(agentDir);
|
|
341
|
+
if (cached && cached.models.length > 0) {
|
|
342
|
+
const baseUrl = getBaseUrl(agentDir);
|
|
343
|
+
if (baseUrl) {
|
|
344
|
+
pi.registerProvider(PROVIDER_NAME, {
|
|
345
|
+
baseUrl,
|
|
346
|
+
apiKey: key,
|
|
347
|
+
api: "openai-completions",
|
|
348
|
+
authHeader: true,
|
|
349
|
+
models: cached.models.map(descriptorToPiModel)
|
|
350
|
+
});
|
|
351
|
+
log(agentDir, "startup: registered from cache", { count: cached.models.length });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
pi.on("session_start", async () => {
|
|
356
|
+
await doRefresh(pi, agentDir, null);
|
|
357
|
+
});
|
|
358
|
+
pi.registerCommand("plexus", {
|
|
359
|
+
description: "Manage Plexus AI model proxy. Sub-commands: login, refresh",
|
|
360
|
+
async handler(args, ctx) {
|
|
361
|
+
const sub = args.trim().toLowerCase();
|
|
362
|
+
if (sub === "login" || sub === "") {
|
|
363
|
+
await handleLogin(pi, ctx, agentDir);
|
|
364
|
+
} else if (sub === "refresh") {
|
|
365
|
+
await handleRefresh(pi, ctx, agentDir);
|
|
366
|
+
} else {
|
|
367
|
+
ctx.ui.notify(`Unknown sub-command: "${args}". Use: /plexus login | /plexus refresh`, "warning");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
async function handleLogin(pi, ctx, agentDir) {
|
|
373
|
+
if (!getApiKey()) {
|
|
374
|
+
ctx.ui.notify("PLEXUS_API_KEY env var is not set. Set it and restart omp.", "error");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const baseUrlInput = await ctx.ui.input("Plexus base URL", "https://plexus.example.com");
|
|
378
|
+
if (!baseUrlInput) {
|
|
379
|
+
ctx.ui.notify("Login cancelled.", "info");
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const defaultModelInput = await ctx.ui.input("Default model (optional \u2014 Enter to skip)", "");
|
|
383
|
+
await saveBaseUrl(agentDir, baseUrlInput.trim(), defaultModelInput?.trim() || undefined);
|
|
384
|
+
ctx.ui.notify("Plexus config saved. Refreshing models\u2026", "info");
|
|
385
|
+
await doRefresh(pi, agentDir, ctx);
|
|
386
|
+
}
|
|
387
|
+
async function handleRefresh(pi, ctx, agentDir) {
|
|
388
|
+
ctx.ui.notify("Refreshing Plexus models\u2026", "info");
|
|
389
|
+
await doRefresh(pi, agentDir, ctx);
|
|
390
|
+
}
|
|
391
|
+
async function doRefresh(pi, agentDir, notify) {
|
|
392
|
+
const modelsUrl = getModelsUrl(agentDir);
|
|
393
|
+
const baseUrl = getBaseUrl(agentDir);
|
|
394
|
+
const key = getApiKey();
|
|
395
|
+
if (!key) {
|
|
396
|
+
if (notify)
|
|
397
|
+
notify.ui.notify("PLEXUS_API_KEY env var is not set.", "error");
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!modelsUrl || !baseUrl) {
|
|
401
|
+
if (notify)
|
|
402
|
+
notify.ui.notify("Plexus base URL not configured. Run /plexus login first.", "warning");
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const { models: raw, raw: rawResponse } = await fetchPlexusModels(key, modelsUrl);
|
|
407
|
+
const descriptors = convertDescriptors(raw, baseUrl);
|
|
408
|
+
await writeCachedModels(agentDir, descriptors);
|
|
409
|
+
await writeRawResponse(agentDir, rawResponse);
|
|
410
|
+
pi.registerProvider(PROVIDER_NAME, {
|
|
411
|
+
baseUrl,
|
|
412
|
+
apiKey: key,
|
|
413
|
+
api: "openai-completions",
|
|
414
|
+
authHeader: true,
|
|
415
|
+
models: descriptors.map(descriptorToPiModel)
|
|
416
|
+
});
|
|
417
|
+
log(agentDir, "refresh: ok", { count: descriptors.length });
|
|
418
|
+
if (notify)
|
|
419
|
+
notify.ui.notify(`Plexus: loaded ${descriptors.length} models.`, "info");
|
|
420
|
+
} catch (err) {
|
|
421
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
422
|
+
log(agentDir, "refresh: error", { error: message });
|
|
423
|
+
if (notify)
|
|
424
|
+
notify.ui.notify(`Plexus refresh failed: ${message}`, "error");
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
export {
|
|
428
|
+
plexusExtension as default
|
|
429
|
+
};
|
package/package.json
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcowger/pi-plexus",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "Plexus AI provider extension for pi (earendil-works fork)",
|
|
6
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.5.3",
|
|
4
|
+
"description": "Plexus AI proxy plugin for pi and oh-my-pi coding agents",
|
|
7
5
|
"type": "module",
|
|
8
|
-
"
|
|
9
|
-
"pi-package",
|
|
10
|
-
"pi",
|
|
11
|
-
"pi-extension",
|
|
12
|
-
"plexus",
|
|
13
|
-
"provider"
|
|
14
|
-
],
|
|
15
|
-
"engines": {
|
|
16
|
-
"bun": ">=1.0"
|
|
17
|
-
},
|
|
6
|
+
"main": "./dist/extension.js",
|
|
18
7
|
"files": [
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"README.md",
|
|
22
|
-
"LICENSE"
|
|
8
|
+
"dist/extension.js",
|
|
9
|
+
"package.json"
|
|
23
10
|
],
|
|
11
|
+
"pi": {
|
|
12
|
+
"extensions": [
|
|
13
|
+
"dist/extension.js"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
24
16
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"test": "bun test"
|
|
17
|
+
"build": "bun run build.ts"
|
|
27
18
|
},
|
|
28
19
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"@earendil-works/pi-ai": ">=0.75.0",
|
|
33
|
-
"@earendil-works/pi-coding-agent": ">=0.75.0"
|
|
20
|
+
"plexus-models": "workspace:*"
|
|
34
21
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"./index.ts"
|
|
38
|
-
]
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/bun": "latest"
|
|
39
24
|
},
|
|
40
25
|
"repository": {
|
|
41
26
|
"type": "git",
|
|
42
|
-
"url": "
|
|
43
|
-
"directory": "packages/pi
|
|
27
|
+
"url": "https://github.com/mcowger/plexus-agent-plugins.git",
|
|
28
|
+
"directory": "packages/plexus-pi"
|
|
44
29
|
},
|
|
45
|
-
"
|
|
46
|
-
"access": "public"
|
|
47
|
-
}
|
|
30
|
+
"license": "MIT"
|
|
48
31
|
}
|
package/index.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ProviderConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { Api } from "@earendil-works/pi-ai";
|
|
3
|
-
import {
|
|
4
|
-
readCachedModelsSync,
|
|
5
|
-
writeCachedModels,
|
|
6
|
-
writeRawResponse,
|
|
7
|
-
getBaseUrl,
|
|
8
|
-
getModelsUrl,
|
|
9
|
-
saveBaseUrl,
|
|
10
|
-
getDefaultModel,
|
|
11
|
-
fetchPlexusModels,
|
|
12
|
-
convertDescriptors,
|
|
13
|
-
log,
|
|
14
|
-
} from "@mcowger/plexus-models";
|
|
15
|
-
import type { PlexusModelDescriptor } from "@mcowger/plexus-models";
|
|
16
|
-
import { getAgentDir } from "./src/pi-compat.js";
|
|
17
|
-
import { mapDescriptorsToPiModels } from "./src/map-models.js";
|
|
18
|
-
import type { PiModel } from "./src/map-models.js";
|
|
19
|
-
|
|
20
|
-
const PLEXUS_PROVIDER = "plexus";
|
|
21
|
-
|
|
22
|
-
const createProviderConfig = (models: PiModel[], baseUrl: string): ProviderConfig => ({
|
|
23
|
-
api: "openai-completions" as Api,
|
|
24
|
-
apiKey: "PLEXUS_API_KEY",
|
|
25
|
-
authHeader: true,
|
|
26
|
-
baseUrl,
|
|
27
|
-
models,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Store current descriptors globally for use by setDefaultModel
|
|
31
|
-
let currentDescriptors: PlexusModelDescriptor[] = [];
|
|
32
|
-
|
|
33
|
-
const attemptLiveRefresh = async (
|
|
34
|
-
pi: ExtensionAPI,
|
|
35
|
-
apiKey: string,
|
|
36
|
-
agentDir: string,
|
|
37
|
-
setDefault = true,
|
|
38
|
-
): Promise<void> => {
|
|
39
|
-
const baseUrl = getBaseUrl(agentDir);
|
|
40
|
-
const modelsUrl = getModelsUrl(agentDir);
|
|
41
|
-
|
|
42
|
-
log(agentDir, "attemptLiveRefresh", { hasApiKey: !!apiKey, baseUrl, modelsUrl });
|
|
43
|
-
|
|
44
|
-
if (!baseUrl || !modelsUrl) {
|
|
45
|
-
log(agentDir, "attemptLiveRefresh: missing baseUrl, skipping");
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
|
|
51
|
-
const descriptors = convertDescriptors(apiModels, baseUrl);
|
|
52
|
-
const piModels = mapDescriptorsToPiModels(descriptors, baseUrl);
|
|
53
|
-
|
|
54
|
-
log(agentDir, "attemptLiveRefresh: fetched models", { count: piModels.length });
|
|
55
|
-
|
|
56
|
-
await Promise.all([writeCachedModels(agentDir, descriptors), writeRawResponse(agentDir, raw)]);
|
|
57
|
-
currentDescriptors = descriptors;
|
|
58
|
-
pi.registerProvider(PLEXUS_PROVIDER, createProviderConfig(piModels, baseUrl));
|
|
59
|
-
log(agentDir, "attemptLiveRefresh: provider registered");
|
|
60
|
-
|
|
61
|
-
if (setDefault) {
|
|
62
|
-
await setDefaultModel(pi, agentDir, descriptors);
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
log(agentDir, "attemptLiveRefresh: fetch failed", { error: String(error) });
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const setDefaultModel = async (
|
|
70
|
-
pi: ExtensionAPI,
|
|
71
|
-
agentDir: string,
|
|
72
|
-
descriptors?: PlexusModelDescriptor[],
|
|
73
|
-
): Promise<void> => {
|
|
74
|
-
const defaultModelId = getDefaultModel(agentDir);
|
|
75
|
-
if (!defaultModelId) return;
|
|
76
|
-
|
|
77
|
-
const list = descriptors ?? currentDescriptors;
|
|
78
|
-
if (!list || list.length === 0) {
|
|
79
|
-
log(agentDir, "setDefaultModel: no models available", { defaultModelId });
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const descriptor = list.find((d) => d.id === defaultModelId);
|
|
84
|
-
if (!descriptor) {
|
|
85
|
-
log(agentDir, "setDefaultModel: model not found", { defaultModelId });
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const baseUrl = getBaseUrl(agentDir) ?? descriptor.baseUrl;
|
|
90
|
-
const piModel = mapDescriptorsToPiModels([descriptor], baseUrl)[0];
|
|
91
|
-
if (!piModel) return;
|
|
92
|
-
|
|
93
|
-
const success = await pi.setModel(piModel);
|
|
94
|
-
log(agentDir, "setDefaultModel", { defaultModelId, success });
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export default function plexusExtension(pi: ExtensionAPI) {
|
|
98
|
-
const agentDir = getAgentDir();
|
|
99
|
-
const cached = readCachedModelsSync(agentDir);
|
|
100
|
-
const startupBaseUrl = getBaseUrl(agentDir) ?? "http://localhost/v1";
|
|
101
|
-
const startupDescriptors = cached?.models ?? [];
|
|
102
|
-
const startupModels = mapDescriptorsToPiModels(startupDescriptors, startupBaseUrl);
|
|
103
|
-
|
|
104
|
-
log(agentDir, "startup", {
|
|
105
|
-
cachedModelCount: startupModels.length,
|
|
106
|
-
startupBaseUrl,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
pi.registerProvider(PLEXUS_PROVIDER, createProviderConfig(startupModels, startupBaseUrl));
|
|
110
|
-
currentDescriptors = startupDescriptors;
|
|
111
|
-
|
|
112
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
113
|
-
const apiKey = await ctx.modelRegistry.authStorage.getApiKey(PLEXUS_PROVIDER);
|
|
114
|
-
const baseUrl = getBaseUrl(agentDir);
|
|
115
|
-
|
|
116
|
-
log(agentDir, "session_start", { hasApiKey: !!apiKey, baseUrl });
|
|
117
|
-
|
|
118
|
-
if (!apiKey || !baseUrl) {
|
|
119
|
-
log(agentDir, "session_start: no auth configured, skipping refresh");
|
|
120
|
-
await setDefaultModel(pi, agentDir, startupDescriptors);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
await attemptLiveRefresh(pi, apiKey, agentDir, true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
pi.registerCommand("plexus", {
|
|
128
|
-
description: "Plexus provider commands: login, refresh",
|
|
129
|
-
getArgumentCompletions: () => [
|
|
130
|
-
{ value: "login", label: "login", description: "Configure Plexus base URL and API key" },
|
|
131
|
-
{ value: "refresh", label: "refresh", description: "Refresh Plexus models from the API" },
|
|
132
|
-
],
|
|
133
|
-
handler: async (args, ctx) => {
|
|
134
|
-
const sub = args.trim();
|
|
135
|
-
|
|
136
|
-
if (sub === "login") {
|
|
137
|
-
const baseUrl = await ctx.ui.input("Plexus base URL", "https://plexus.example.com");
|
|
138
|
-
if (!baseUrl) return;
|
|
139
|
-
|
|
140
|
-
const apiKey = await ctx.ui.input("Plexus API key");
|
|
141
|
-
if (!apiKey) return;
|
|
142
|
-
|
|
143
|
-
const defaultModel = await ctx.ui.input("Default model (optional)", "");
|
|
144
|
-
const defaultModelTrimmed = defaultModel?.trim() || undefined;
|
|
145
|
-
|
|
146
|
-
await saveBaseUrl(agentDir, baseUrl.trim(), defaultModelTrimmed);
|
|
147
|
-
ctx.modelRegistry.authStorage.set(PLEXUS_PROVIDER, { type: "api_key", key: apiKey.trim() });
|
|
148
|
-
|
|
149
|
-
log(agentDir, "login: saved", { baseUrl: baseUrl.trim(), defaultModel: defaultModelTrimmed });
|
|
150
|
-
ctx.ui.notify("Plexus credentials saved", "info");
|
|
151
|
-
|
|
152
|
-
await attemptLiveRefresh(pi, apiKey.trim(), agentDir, false);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (sub === "refresh") {
|
|
157
|
-
const apiKey = await ctx.modelRegistry.authStorage.getApiKey(PLEXUS_PROVIDER);
|
|
158
|
-
const baseUrl = getBaseUrl(agentDir);
|
|
159
|
-
const modelsUrl = getModelsUrl(agentDir);
|
|
160
|
-
|
|
161
|
-
log(agentDir, "refresh command", { hasApiKey: !!apiKey, baseUrl });
|
|
162
|
-
|
|
163
|
-
if (!apiKey) {
|
|
164
|
-
ctx.ui.notify("No Plexus API key configured. Run /plexus login first.", "error");
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (!baseUrl || !modelsUrl) {
|
|
168
|
-
ctx.ui.notify("No Plexus base URL configured. Run /plexus login first.", "error");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
ctx.ui.notify("Fetching Plexus models...", "info");
|
|
174
|
-
const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
|
|
175
|
-
const descriptors = convertDescriptors(apiModels, baseUrl);
|
|
176
|
-
const piModels = mapDescriptorsToPiModels(descriptors, baseUrl);
|
|
177
|
-
|
|
178
|
-
await Promise.all([writeCachedModels(agentDir, descriptors), writeRawResponse(agentDir, raw)]);
|
|
179
|
-
currentDescriptors = descriptors;
|
|
180
|
-
pi.registerProvider(PLEXUS_PROVIDER, createProviderConfig(piModels, baseUrl));
|
|
181
|
-
|
|
182
|
-
log(agentDir, "refresh command: done", { count: piModels.length });
|
|
183
|
-
ctx.ui.notify(`Refreshed ${piModels.length} Plexus models`, "info");
|
|
184
|
-
|
|
185
|
-
await setDefaultModel(pi, agentDir);
|
|
186
|
-
} catch (error) {
|
|
187
|
-
log(agentDir, "refresh command: failed", { error: String(error) });
|
|
188
|
-
ctx.ui.notify(`Refresh failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
ctx.ui.notify("Usage: /plexus login | /plexus refresh", "info");
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
}
|
package/src/map-models.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Api,
|
|
3
|
-
Model,
|
|
4
|
-
OpenAICompletionsCompat,
|
|
5
|
-
OpenAIResponsesCompat,
|
|
6
|
-
AnthropicMessagesCompat,
|
|
7
|
-
} from "@earendil-works/pi-ai";
|
|
8
|
-
import type { PlexusModelDescriptor } from "@mcowger/plexus-models";
|
|
9
|
-
import { adjustBaseUrl, detectOpenAICompletionsCompat } from "@mcowger/plexus-models";
|
|
10
|
-
import { lookupModel } from "./pi-compat.js";
|
|
11
|
-
|
|
12
|
-
export type PiModel = Model<Api>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Look up a curated model definition from pi's built-in MODELS registry
|
|
16
|
-
* using the piProvider/piModel hints from the descriptor.
|
|
17
|
-
* Returns null if either hint is missing or the model isn't found.
|
|
18
|
-
*/
|
|
19
|
-
const lookupPiModel = (piProvider?: string, piModel?: string): Model<Api> | null => {
|
|
20
|
-
if (!piProvider || !piModel) return null;
|
|
21
|
-
return (lookupModel as (p: string, m: string) => Model<Api> | undefined)(piProvider, piModel) ?? null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Resolve a fully-specified compat object for a plexus-proxied model by
|
|
26
|
-
* merging the pi model's stored compat overrides onto the detected defaults
|
|
27
|
-
* from the pi model's original provider/baseUrl.
|
|
28
|
-
*/
|
|
29
|
-
const resolveCompat = (
|
|
30
|
-
piModel: Model<Api>,
|
|
31
|
-
): OpenAICompletionsCompat | OpenAIResponsesCompat | AnthropicMessagesCompat | undefined => {
|
|
32
|
-
if (piModel.api === "openai-completions") {
|
|
33
|
-
const detected = detectOpenAICompletionsCompat(piModel.provider, piModel.baseUrl) as OpenAICompletionsCompat;
|
|
34
|
-
const overrides = piModel.compat as OpenAICompletionsCompat | undefined;
|
|
35
|
-
if (!overrides) return detected;
|
|
36
|
-
return {
|
|
37
|
-
supportsStore: overrides.supportsStore ?? detected.supportsStore,
|
|
38
|
-
supportsDeveloperRole: overrides.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
|
39
|
-
supportsReasoningEffort: overrides.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
|
40
|
-
supportsUsageInStreaming: overrides.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
|
41
|
-
maxTokensField: overrides.maxTokensField ?? detected.maxTokensField,
|
|
42
|
-
requiresToolResultName: overrides.requiresToolResultName ?? detected.requiresToolResultName,
|
|
43
|
-
requiresAssistantAfterToolResult:
|
|
44
|
-
overrides.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
45
|
-
requiresThinkingAsText: overrides.requiresThinkingAsText ?? detected.requiresThinkingAsText,
|
|
46
|
-
requiresReasoningContentOnAssistantMessages:
|
|
47
|
-
overrides.requiresReasoningContentOnAssistantMessages ?? detected.requiresReasoningContentOnAssistantMessages,
|
|
48
|
-
thinkingFormat: overrides.thinkingFormat ?? detected.thinkingFormat,
|
|
49
|
-
openRouterRouting: overrides.openRouterRouting ?? detected.openRouterRouting,
|
|
50
|
-
vercelGatewayRouting: overrides.vercelGatewayRouting ?? detected.vercelGatewayRouting,
|
|
51
|
-
zaiToolStream: overrides.zaiToolStream ?? detected.zaiToolStream,
|
|
52
|
-
supportsStrictMode: overrides.supportsStrictMode ?? detected.supportsStrictMode,
|
|
53
|
-
cacheControlFormat: overrides.cacheControlFormat ?? detected.cacheControlFormat,
|
|
54
|
-
sendSessionAffinityHeaders: overrides.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
55
|
-
supportsLongCacheRetention: overrides.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return piModel.compat;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Map a PlexusModelDescriptor to a pi PiModel (Model<Api>).
|
|
63
|
-
*
|
|
64
|
-
* When piProvider/piModel hints are present, looks up the curated definition
|
|
65
|
-
* from pi's MODELS registry and merges it with plexus-specific fields for
|
|
66
|
-
* maximum fidelity (correct compat, thinkingLevelMap, etc.).
|
|
67
|
-
*
|
|
68
|
-
* Falls back to the descriptor's own fields when no registry match is found.
|
|
69
|
-
*/
|
|
70
|
-
export const mapDescriptorToPiModel = (descriptor: PlexusModelDescriptor, baseUrl: string): PiModel => {
|
|
71
|
-
const piModelDef = lookupPiModel(descriptor.piProvider, descriptor.piModel);
|
|
72
|
-
|
|
73
|
-
if (piModelDef) {
|
|
74
|
-
const resolvedCompat = resolveCompat(piModelDef);
|
|
75
|
-
return {
|
|
76
|
-
id: descriptor.id,
|
|
77
|
-
name: descriptor.name ?? piModelDef.name ?? descriptor.id,
|
|
78
|
-
api: piModelDef.api,
|
|
79
|
-
provider: "plexus",
|
|
80
|
-
baseUrl: adjustBaseUrl(baseUrl, piModelDef.api),
|
|
81
|
-
reasoning: piModelDef.reasoning,
|
|
82
|
-
...(piModelDef.thinkingLevelMap && { thinkingLevelMap: piModelDef.thinkingLevelMap }),
|
|
83
|
-
input: piModelDef.input,
|
|
84
|
-
cost: {
|
|
85
|
-
input: descriptor.cost.input || piModelDef.cost.input,
|
|
86
|
-
output: descriptor.cost.output || piModelDef.cost.output,
|
|
87
|
-
cacheRead: descriptor.cost.cacheRead || piModelDef.cost.cacheRead,
|
|
88
|
-
cacheWrite: descriptor.cost.cacheWrite || piModelDef.cost.cacheWrite,
|
|
89
|
-
},
|
|
90
|
-
contextWindow: piModelDef.contextWindow,
|
|
91
|
-
maxTokens: piModelDef.maxTokens,
|
|
92
|
-
...(resolvedCompat && { compat: resolvedCompat }),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// No registry match — use descriptor fields directly
|
|
97
|
-
return {
|
|
98
|
-
id: descriptor.id,
|
|
99
|
-
name: descriptor.name,
|
|
100
|
-
api: descriptor.preferredApi as Api,
|
|
101
|
-
provider: "plexus",
|
|
102
|
-
baseUrl: descriptor.baseUrl,
|
|
103
|
-
reasoning: descriptor.reasoning,
|
|
104
|
-
input: descriptor.input,
|
|
105
|
-
cost: descriptor.cost,
|
|
106
|
-
contextWindow: descriptor.contextWindow,
|
|
107
|
-
maxTokens: descriptor.maxTokens,
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export const mapDescriptorsToPiModels = (descriptors: PlexusModelDescriptor[], baseUrl: string): PiModel[] =>
|
|
112
|
-
descriptors.map((d) => mapDescriptorToPiModel(d, baseUrl));
|
package/src/pi-compat.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { getModel } from "@earendil-works/pi-ai";
|
|
3
|
-
|
|
4
|
-
export { getAgentDir };
|
|
5
|
-
|
|
6
|
-
// biome-ignore lint/suspicious/noExplicitAny: getModel uses branded generic types; dynamic string args require any
|
|
7
|
-
export const lookupModel = getModel as (...args: any[]) => any;
|