latentcode 0.1.0-alpha.1 → 0.1.0-alpha.2
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/README.md +30 -1
- package/dist/latentcode.mjs +392 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,13 +26,42 @@ Type `/` for the command palette.
|
|
|
26
26
|
| --- | --- |
|
|
27
27
|
| `/model [name]` | Model picker: search across every provider, `tab` to filter by provider, `←` `→` to set the effort level, `ctrl+t` to test a model with your account. `✓` marks models proven to work with your account. |
|
|
28
28
|
| `/providers` | Connected providers, how each is connected (account sign-in, API key, env var, built in) and how many models it offers. |
|
|
29
|
-
| `/connect [provider]` | Connect a provider without leaving the app: paste an API key or sign in through the browser. Credentials are stored by the local engine. |
|
|
29
|
+
| `/connect [provider]` | Connect a provider without leaving the app: paste an API key or sign in through the browser. Credentials are stored by the local engine. The last entry, **+ Custom provider…** (or `/connect custom`), adds any OpenAI- or Anthropic-compatible endpoint — see below. |
|
|
30
30
|
| `/login` | Connect the wallet Earn mode pays into: browser sign-in, or an address you control. |
|
|
31
31
|
| `/earn`, `/ads on\|off` | Earnings so far; Earn mode on or off. |
|
|
32
32
|
| `/new`, `/compact`, `/status`, `/help`, `/exit` | Session and app. |
|
|
33
33
|
|
|
34
34
|
The agent's own commands (`/init`, `/review`, `/goal`) are in the palette too.
|
|
35
35
|
|
|
36
|
+
### Custom providers
|
|
37
|
+
|
|
38
|
+
`/connect` → **+ Custom provider…** adds an endpoint the engine does not know by name: a self-hosted gateway, a reseller, vLLM, Ollama, LM Studio. It asks for
|
|
39
|
+
|
|
40
|
+
1. a name (shown in the model picker),
|
|
41
|
+
2. the API style — **OpenAI-compatible** (`/chat/completions`) or **Anthropic-compatible** (`/messages`),
|
|
42
|
+
3. the base URL, usually ending in `/v1`,
|
|
43
|
+
4. an API key (optional — leave empty for local servers),
|
|
44
|
+
5. the model ids, comma-separated — or leave empty to import every model from the endpoint's `/models` list.
|
|
45
|
+
|
|
46
|
+
The endpoint is written to the `providers` section of the engine's global config (`~/.config/opencode/opencode.json`, or `opencode.jsonc` if that is the one you have) and the engine reloads it without a restart. The key goes into the engine's credential store, not into the config file. Adding a provider with the same name again updates it. Then pick a model with `/model`, or start with `latentcode --model <id>/<model>`.
|
|
47
|
+
|
|
48
|
+
The same entry can be written by hand:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"providers": {
|
|
53
|
+
"my-gateway": {
|
|
54
|
+
"name": "My Gateway",
|
|
55
|
+
"package": "@opencode/ai/providers/openai-compatible",
|
|
56
|
+
"settings": { "baseURL": "https://api.example.com/v1" },
|
|
57
|
+
"models": { "gpt-4.1": { "name": "gpt-4.1" } }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For an Anthropic-style endpoint the package is `@opencode/ai/providers/anthropic-compatible`.
|
|
64
|
+
|
|
36
65
|
Keys: `esc` interrupts, `↑` `↓` recall earlier prompts, `ctrl+a` / `ctrl+e` and `alt+←` / `alt+→` move in the line, `ctrl+o` opens the sponsored link, `ctrl+c` twice quits. Pasted text keeps its line breaks.
|
|
37
66
|
|
|
38
67
|
### From the shell
|
package/dist/latentcode.mjs
CHANGED
|
@@ -33965,6 +33965,9 @@ function describeConnection(provider, integration) {
|
|
|
33965
33965
|
if (conn.method === "external") return { kind: "local", via: "local login" };
|
|
33966
33966
|
return { kind: "key", via: "API key" };
|
|
33967
33967
|
}
|
|
33968
|
+
if (provider.settings?.apiKey !== "public" && provider.activation === "enabled" && /-compatible$/.test(provider.package ?? "")) {
|
|
33969
|
+
return { kind: "local", via: "custom endpoint" };
|
|
33970
|
+
}
|
|
33968
33971
|
if (provider.settings?.apiKey === "public" || provider.activation === "enabled") {
|
|
33969
33972
|
return { kind: "builtin", via: "built in \xB7 free models" };
|
|
33970
33973
|
}
|
|
@@ -34233,6 +34236,41 @@ ${seen.slice(-800)}`));
|
|
|
34233
34236
|
return buildCatalog(providers.data, integrations, models.data);
|
|
34234
34237
|
}
|
|
34235
34238
|
/** Store an API key for a provider. The key goes to the local engine only. */
|
|
34239
|
+
/** The engine's global config directory, as it reports it (`GET /api/config`). */
|
|
34240
|
+
async configDir() {
|
|
34241
|
+
try {
|
|
34242
|
+
const r = await this.call(
|
|
34243
|
+
"GET",
|
|
34244
|
+
"/api/config"
|
|
34245
|
+
);
|
|
34246
|
+
const list = Array.isArray(r) ? r : r.data ?? [];
|
|
34247
|
+
const dir = list.find((x) => x.type === "directory" && x.path);
|
|
34248
|
+
return dir?.path ?? null;
|
|
34249
|
+
} catch {
|
|
34250
|
+
return null;
|
|
34251
|
+
}
|
|
34252
|
+
}
|
|
34253
|
+
/**
|
|
34254
|
+
* Re-read the config files. Running sessions carry on; the event stream
|
|
34255
|
+
* stays open. The new providers can lag the response by a moment, so
|
|
34256
|
+
* `waitForIntegration` polls for the one we expect.
|
|
34257
|
+
*/
|
|
34258
|
+
async reloadConfig() {
|
|
34259
|
+
await this.call("POST", "/api/location/reload");
|
|
34260
|
+
}
|
|
34261
|
+
async waitForIntegration(id, timeoutMs = 1e4) {
|
|
34262
|
+
const until = Date.now() + timeoutMs;
|
|
34263
|
+
let last;
|
|
34264
|
+
while (Date.now() < until) {
|
|
34265
|
+
try {
|
|
34266
|
+
return (await this.call("GET", `/api/integration/${encodeURIComponent(id)}`)).data;
|
|
34267
|
+
} catch (e) {
|
|
34268
|
+
last = e;
|
|
34269
|
+
}
|
|
34270
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
34271
|
+
}
|
|
34272
|
+
throw new EngineError(`The engine did not pick up provider "${id}" after reloading its config. ${last instanceof Error ? last.message : ""}`.trim());
|
|
34273
|
+
}
|
|
34236
34274
|
async connectKey(integrationID, key) {
|
|
34237
34275
|
await this.call("POST", `/api/integration/${encodeURIComponent(integrationID)}/connect/key`, { key });
|
|
34238
34276
|
}
|
|
@@ -35219,7 +35257,7 @@ function firstLine(e) {
|
|
|
35219
35257
|
|
|
35220
35258
|
// src/ui/App.tsx
|
|
35221
35259
|
var import_react26 = __toESM(require_react(), 1);
|
|
35222
|
-
import { homedir as
|
|
35260
|
+
import { homedir as homedir4 } from "node:os";
|
|
35223
35261
|
|
|
35224
35262
|
// src/util/open.ts
|
|
35225
35263
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -36294,6 +36332,154 @@ function ModelPicker(p) {
|
|
|
36294
36332
|
|
|
36295
36333
|
// src/ui/panels/ProviderPanel.tsx
|
|
36296
36334
|
var import_react24 = __toESM(require_react(), 1);
|
|
36335
|
+
|
|
36336
|
+
// src/engine/customProvider.ts
|
|
36337
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync, writeFileSync as writeFileSync4, copyFileSync } from "node:fs";
|
|
36338
|
+
import { homedir as homedir3 } from "node:os";
|
|
36339
|
+
import { join as join6 } from "node:path";
|
|
36340
|
+
var KIND_PACKAGE = {
|
|
36341
|
+
openai: "@opencode/ai/providers/openai-compatible",
|
|
36342
|
+
anthropic: "@opencode/ai/providers/anthropic-compatible"
|
|
36343
|
+
};
|
|
36344
|
+
var KIND_LABEL = {
|
|
36345
|
+
openai: "OpenAI-compatible",
|
|
36346
|
+
anthropic: "Anthropic-compatible"
|
|
36347
|
+
};
|
|
36348
|
+
var CONFIG_FILES = ["opencode.json", "opencode.jsonc"];
|
|
36349
|
+
function slugify(name) {
|
|
36350
|
+
return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
36351
|
+
}
|
|
36352
|
+
function providerIdFor(name, taken, custom) {
|
|
36353
|
+
const base = slugify(name) || "custom";
|
|
36354
|
+
if (custom.has(base) || !taken.has(base)) return base;
|
|
36355
|
+
for (let i = 0; ; i++) {
|
|
36356
|
+
const id = i === 0 ? `${base}-custom` : `${base}-custom-${i + 1}`;
|
|
36357
|
+
if (custom.has(id) || !taken.has(id)) return id;
|
|
36358
|
+
}
|
|
36359
|
+
}
|
|
36360
|
+
function normalizeBaseURL(raw) {
|
|
36361
|
+
const s2 = raw.trim();
|
|
36362
|
+
let u;
|
|
36363
|
+
try {
|
|
36364
|
+
u = new URL(s2);
|
|
36365
|
+
} catch {
|
|
36366
|
+
throw new Error("That is not a URL. Example: https://api.example.com/v1");
|
|
36367
|
+
}
|
|
36368
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("The base URL must start with https:// or http://");
|
|
36369
|
+
if (u.search || u.hash) throw new Error("Leave out the query string \u2014 just the base URL, e.g. https://api.example.com/v1");
|
|
36370
|
+
return u.toString().replace(/\/+$/, "");
|
|
36371
|
+
}
|
|
36372
|
+
function parseModelList(raw) {
|
|
36373
|
+
const seen = /* @__PURE__ */ new Set();
|
|
36374
|
+
for (const part of raw.split(/[\s,]+/)) {
|
|
36375
|
+
const id = part.trim();
|
|
36376
|
+
if (id) seen.add(id);
|
|
36377
|
+
}
|
|
36378
|
+
return [...seen];
|
|
36379
|
+
}
|
|
36380
|
+
function providerEntry(input) {
|
|
36381
|
+
const models = {};
|
|
36382
|
+
for (const id of input.models) models[id] = { name: id };
|
|
36383
|
+
return {
|
|
36384
|
+
name: input.name.trim(),
|
|
36385
|
+
package: KIND_PACKAGE[input.kind],
|
|
36386
|
+
settings: { baseURL: input.baseURL },
|
|
36387
|
+
models
|
|
36388
|
+
};
|
|
36389
|
+
}
|
|
36390
|
+
function parseJsonc(text) {
|
|
36391
|
+
let out = "";
|
|
36392
|
+
let hadComments = false;
|
|
36393
|
+
let i = 0;
|
|
36394
|
+
while (i < text.length) {
|
|
36395
|
+
const ch = text[i];
|
|
36396
|
+
if (ch === '"') {
|
|
36397
|
+
let j = i + 1;
|
|
36398
|
+
while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
|
|
36399
|
+
out += text.slice(i, j + 1);
|
|
36400
|
+
i = j + 1;
|
|
36401
|
+
} else if (ch === "/" && text[i + 1] === "/") {
|
|
36402
|
+
hadComments = true;
|
|
36403
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
36404
|
+
} else if (ch === "/" && text[i + 1] === "*") {
|
|
36405
|
+
hadComments = true;
|
|
36406
|
+
const end2 = text.indexOf("*/", i + 2);
|
|
36407
|
+
i = end2 < 0 ? text.length : end2 + 2;
|
|
36408
|
+
} else {
|
|
36409
|
+
if (ch === "}" || ch === "]") {
|
|
36410
|
+
const m = out.match(/,\s*$/);
|
|
36411
|
+
if (m) out = out.slice(0, out.length - m[0].length) + m[0].slice(1);
|
|
36412
|
+
}
|
|
36413
|
+
out += ch;
|
|
36414
|
+
i++;
|
|
36415
|
+
}
|
|
36416
|
+
}
|
|
36417
|
+
return { value: out.trim() ? JSON.parse(out) : {}, hadComments };
|
|
36418
|
+
}
|
|
36419
|
+
function mergeProvider(existing, id, entry) {
|
|
36420
|
+
const { value, hadComments } = existing ? parseJsonc(existing) : { value: {}, hadComments: false };
|
|
36421
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The engine config file is not a JSON object.");
|
|
36422
|
+
const config = value;
|
|
36423
|
+
const providers = config.providers;
|
|
36424
|
+
if (providers !== void 0 && (typeof providers !== "object" || providers === null || Array.isArray(providers))) {
|
|
36425
|
+
throw new Error('The engine config has a "providers" value that is not an object.');
|
|
36426
|
+
}
|
|
36427
|
+
const next = { ...config, providers: { ...providers ?? {}, [id]: entry } };
|
|
36428
|
+
if (!("$schema" in next)) next.$schema = "https://opencode.ai/config.json";
|
|
36429
|
+
return { text: JSON.stringify(next, null, 2) + "\n", hadComments };
|
|
36430
|
+
}
|
|
36431
|
+
function configuredProviderIds(text) {
|
|
36432
|
+
if (!text) return /* @__PURE__ */ new Set();
|
|
36433
|
+
try {
|
|
36434
|
+
const v = parseJsonc(text).value;
|
|
36435
|
+
return new Set(Object.keys(v?.providers ?? {}));
|
|
36436
|
+
} catch {
|
|
36437
|
+
return /* @__PURE__ */ new Set();
|
|
36438
|
+
}
|
|
36439
|
+
}
|
|
36440
|
+
function defaultConfigDir(env3 = process.env) {
|
|
36441
|
+
return join6(env3.XDG_CONFIG_HOME || join6(homedir3(), ".config"), "opencode");
|
|
36442
|
+
}
|
|
36443
|
+
function configFileIn(dir, exists = existsSync5) {
|
|
36444
|
+
const present = CONFIG_FILES.map((f) => join6(dir, f)).filter(exists);
|
|
36445
|
+
return present.at(-1) ?? join6(dir, "opencode.json");
|
|
36446
|
+
}
|
|
36447
|
+
function readConfigText(file) {
|
|
36448
|
+
try {
|
|
36449
|
+
return readFileSync7(file, "utf8");
|
|
36450
|
+
} catch {
|
|
36451
|
+
return null;
|
|
36452
|
+
}
|
|
36453
|
+
}
|
|
36454
|
+
function writeProviderConfig(file, id, input) {
|
|
36455
|
+
const existing = readConfigText(file);
|
|
36456
|
+
const { text, hadComments } = mergeProvider(existing, id, providerEntry(input));
|
|
36457
|
+
mkdirSync4(join6(file, ".."), { recursive: true });
|
|
36458
|
+
let backup;
|
|
36459
|
+
if (existing !== null && hadComments) {
|
|
36460
|
+
backup = file + ".bak";
|
|
36461
|
+
copyFileSync(file, backup);
|
|
36462
|
+
}
|
|
36463
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
36464
|
+
writeFileSync4(tmp, text);
|
|
36465
|
+
renameSync(tmp, file);
|
|
36466
|
+
return { file, backup };
|
|
36467
|
+
}
|
|
36468
|
+
async function discoverModels(kind, baseURL, key, timeoutMs = 1e4) {
|
|
36469
|
+
const headers = kind === "anthropic" ? { "anthropic-version": "2023-06-01", ...key ? { "x-api-key": key } : {} } : key ? { authorization: `Bearer ${key}` } : {};
|
|
36470
|
+
const res = await fetch(baseURL + "/models", { headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
36471
|
+
if (!res.ok) throw new Error(`${baseURL}/models answered ${res.status}`);
|
|
36472
|
+
return parseModelsResponse(await res.json());
|
|
36473
|
+
}
|
|
36474
|
+
function parseModelsResponse(body) {
|
|
36475
|
+
const data = body?.data ?? body?.models;
|
|
36476
|
+
if (!Array.isArray(data)) throw new Error("The /models answer has no model list.");
|
|
36477
|
+
return parseModelList(
|
|
36478
|
+
data.map((m) => typeof m === "string" ? m : typeof m === "object" && m ? String(m.id ?? "") : "").join(" ")
|
|
36479
|
+
);
|
|
36480
|
+
}
|
|
36481
|
+
|
|
36482
|
+
// src/ui/panels/ProviderPanel.tsx
|
|
36297
36483
|
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
36298
36484
|
var usable = (i) => i.methods.filter((m) => m.type === "key" || m.type === "oauth");
|
|
36299
36485
|
var needsForm = (m) => "form" in m && Array.isArray(m.form) && m.form.some((f) => !f.hidden && f.required);
|
|
@@ -36333,10 +36519,10 @@ function ProviderPanel(p) {
|
|
|
36333
36519
|
}
|
|
36334
36520
|
go({ v: "oauth", integration, method });
|
|
36335
36521
|
};
|
|
36336
|
-
const finish = async (integration) => {
|
|
36522
|
+
const finish = async (integration, note) => {
|
|
36337
36523
|
const next = await p.onConnected(integration.name);
|
|
36338
36524
|
const models = next.providers.filter((x) => x.integrationID === integration.id).reduce((n, x) => n + x.models, 0);
|
|
36339
|
-
go({ v: "done", name: integration.name, models });
|
|
36525
|
+
go({ v: "done", name: integration.name, models, note });
|
|
36340
36526
|
};
|
|
36341
36527
|
const common = { width: p.width, color: C.accent };
|
|
36342
36528
|
switch (view.v) {
|
|
@@ -36360,9 +36546,21 @@ function ProviderPanel(p) {
|
|
|
36360
36546
|
query: p.query,
|
|
36361
36547
|
error,
|
|
36362
36548
|
onPick: choose,
|
|
36549
|
+
onCustom: () => go({ v: "custom" }),
|
|
36363
36550
|
onBack: () => p.connect ? p.onClose() : go({ v: "list" })
|
|
36364
36551
|
}
|
|
36365
36552
|
);
|
|
36553
|
+
case "custom":
|
|
36554
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
36555
|
+
CustomProviderForm,
|
|
36556
|
+
{
|
|
36557
|
+
...common,
|
|
36558
|
+
engine: p.engine,
|
|
36559
|
+
taken: /* @__PURE__ */ new Set([...(integrations ?? []).map((i) => i.id), ...p.catalog.providers.map((x) => x.id)]),
|
|
36560
|
+
onDone: (integration, note) => finish(integration, note),
|
|
36561
|
+
onBack: () => go({ v: "pick" })
|
|
36562
|
+
}
|
|
36563
|
+
);
|
|
36366
36564
|
case "method":
|
|
36367
36565
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
36368
36566
|
MethodPicker,
|
|
@@ -36398,7 +36596,7 @@ function ProviderPanel(p) {
|
|
|
36398
36596
|
}
|
|
36399
36597
|
);
|
|
36400
36598
|
case "done":
|
|
36401
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Done, { ...common, name: view.name, models: view.models, onClose: p.onClose, onModels: () => p.onBrowse("") });
|
|
36599
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Done, { ...common, name: view.name, models: view.models, note: view.note, onClose: p.onClose, onModels: () => p.onBrowse("") });
|
|
36402
36600
|
}
|
|
36403
36601
|
}
|
|
36404
36602
|
function ProviderList(p) {
|
|
@@ -36487,9 +36685,10 @@ function IntegrationPicker(p) {
|
|
|
36487
36685
|
return true;
|
|
36488
36686
|
}
|
|
36489
36687
|
if (key.upArrow) return void setSel((s2) => Math.max(0, s2 - 1)), true;
|
|
36490
|
-
if (key.downArrow) return void setSel((s2) => Math.min(list.length
|
|
36688
|
+
if (key.downArrow) return void setSel((s2) => Math.min(list.length, s2 + 1)), true;
|
|
36491
36689
|
if (key.return) {
|
|
36492
|
-
|
|
36690
|
+
if (selected === list.length) return p.onCustom(), true;
|
|
36691
|
+
const it = list[selected];
|
|
36493
36692
|
if (it) p.onPick(it);
|
|
36494
36693
|
return true;
|
|
36495
36694
|
}
|
|
@@ -36497,9 +36696,9 @@ function IntegrationPicker(p) {
|
|
|
36497
36696
|
}
|
|
36498
36697
|
});
|
|
36499
36698
|
const list = (0, import_react24.useMemo)(() => searchIntegrations(p.integrations ?? [], field.text), [p.integrations, field.text]);
|
|
36500
|
-
const selected = Math.min(sel,
|
|
36501
|
-
const visible = Math.max(5, Math.min(11, p.rows -
|
|
36502
|
-
const win = windowAround(list.length, selected, visible);
|
|
36699
|
+
const selected = Math.min(sel, list.length);
|
|
36700
|
+
const visible = Math.max(5, Math.min(11, p.rows - 15));
|
|
36701
|
+
const win = windowAround(list.length, Math.min(selected, Math.max(0, list.length - 1)), visible);
|
|
36503
36702
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
36504
36703
|
Panel,
|
|
36505
36704
|
{
|
|
@@ -36561,6 +36760,14 @@ function IntegrationPicker(p) {
|
|
|
36561
36760
|
" ",
|
|
36562
36761
|
list.length - win.end,
|
|
36563
36762
|
" more"
|
|
36763
|
+
] }) : null,
|
|
36764
|
+
p.integrations ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36765
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
36766
|
+
selected === list.length ? G.prompt : " ",
|
|
36767
|
+
" "
|
|
36768
|
+
] }),
|
|
36769
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.accent2, bold: selected === list.length, children: pad("+ Custom provider\u2026", 26) }),
|
|
36770
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: " any OpenAI- or Anthropic-compatible endpoint" })
|
|
36564
36771
|
] }) : null
|
|
36565
36772
|
] }),
|
|
36566
36773
|
p.error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
@@ -36757,26 +36964,192 @@ function OAuthFlow(p) {
|
|
|
36757
36964
|
}
|
|
36758
36965
|
);
|
|
36759
36966
|
}
|
|
36967
|
+
var KINDS = ["openai", "anthropic"];
|
|
36968
|
+
function CustomProviderForm(p) {
|
|
36969
|
+
const [step, setStep] = (0, import_react24.useState)("name");
|
|
36970
|
+
const [name, setName] = (0, import_react24.useState)("");
|
|
36971
|
+
const [kind, setKind] = (0, import_react24.useState)("openai");
|
|
36972
|
+
const [url, setUrl] = (0, import_react24.useState)("");
|
|
36973
|
+
const [key, setKey] = (0, import_react24.useState)("");
|
|
36974
|
+
const [busy, setBusy] = (0, import_react24.useState)("");
|
|
36975
|
+
const [error, setError] = (0, import_react24.useState)("");
|
|
36976
|
+
const order = ["name", "kind", "url", "key", "models"];
|
|
36977
|
+
const back = () => {
|
|
36978
|
+
setError("");
|
|
36979
|
+
const i = order.indexOf(step);
|
|
36980
|
+
if (i <= 0) return p.onBack();
|
|
36981
|
+
const prev = order[i - 1];
|
|
36982
|
+
setStep(prev);
|
|
36983
|
+
field.set(prev === "name" ? name : prev === "url" ? url : prev === "key" ? key : "");
|
|
36984
|
+
};
|
|
36985
|
+
const next = (to, initial = "") => {
|
|
36986
|
+
setError("");
|
|
36987
|
+
setStep(to);
|
|
36988
|
+
field.set(initial);
|
|
36989
|
+
};
|
|
36990
|
+
const save2 = async (modelText) => {
|
|
36991
|
+
setError("");
|
|
36992
|
+
try {
|
|
36993
|
+
let models = parseModelList(modelText);
|
|
36994
|
+
if (!models.length) {
|
|
36995
|
+
setBusy(`Asking ${url}/models\u2026`);
|
|
36996
|
+
try {
|
|
36997
|
+
models = await discoverModels(kind, url, key);
|
|
36998
|
+
} catch (e) {
|
|
36999
|
+
throw new Error(`Could not list the models (${errText(e)}). Type the model ids, separated by commas.`);
|
|
37000
|
+
}
|
|
37001
|
+
if (!models.length) throw new Error("The endpoint lists no models. Type the model ids, separated by commas.");
|
|
37002
|
+
}
|
|
37003
|
+
setBusy("Saving to the engine config\u2026");
|
|
37004
|
+
const dir = await p.engine.configDir() ?? defaultConfigDir();
|
|
37005
|
+
const file = configFileIn(dir);
|
|
37006
|
+
const id = providerIdFor(name, p.taken, configuredProviderIds(readConfigText(file)));
|
|
37007
|
+
const written = writeProviderConfig(file, id, { name, kind, baseURL: url, models });
|
|
37008
|
+
setBusy("Reloading the engine\u2026");
|
|
37009
|
+
await p.engine.reloadConfig();
|
|
37010
|
+
const integration = await p.engine.waitForIntegration(id);
|
|
37011
|
+
if (key) {
|
|
37012
|
+
setBusy("Saving the key\u2026");
|
|
37013
|
+
await p.engine.connectKey(id, key);
|
|
37014
|
+
}
|
|
37015
|
+
const note = `Added as "${id}" (${KIND_LABEL[kind]}, ${models.length} model${models.length === 1 ? "" : "s"}) in ${written.file}.` + (written.backup ? ` Comments in that file could not be kept; the original is at ${written.backup}.` : "") + ` Use it with --model ${id}/${models[0]}.`;
|
|
37016
|
+
await p.onDone(integration, note);
|
|
37017
|
+
} catch (e) {
|
|
37018
|
+
setError(errText(e));
|
|
37019
|
+
setBusy("");
|
|
37020
|
+
}
|
|
37021
|
+
};
|
|
37022
|
+
const field = useLineField({
|
|
37023
|
+
active: !busy && step !== "kind",
|
|
37024
|
+
onChange: () => setError(""),
|
|
37025
|
+
onKey: (_ch, k) => {
|
|
37026
|
+
if (k.escape) return back(), true;
|
|
37027
|
+
if (!k.return) return false;
|
|
37028
|
+
const text = field.text.trim();
|
|
37029
|
+
if (step === "name") {
|
|
37030
|
+
if (!text) return setError("Give it a name, e.g. My Gateway."), true;
|
|
37031
|
+
setName(text);
|
|
37032
|
+
next("kind");
|
|
37033
|
+
} else if (step === "url") {
|
|
37034
|
+
try {
|
|
37035
|
+
const u = normalizeBaseURL(text);
|
|
37036
|
+
setUrl(u);
|
|
37037
|
+
next("key", key);
|
|
37038
|
+
} catch (e) {
|
|
37039
|
+
setError(errText(e));
|
|
37040
|
+
}
|
|
37041
|
+
} else if (step === "key") {
|
|
37042
|
+
setKey(text);
|
|
37043
|
+
next("models");
|
|
37044
|
+
} else if (step === "models") {
|
|
37045
|
+
void save2(text);
|
|
37046
|
+
}
|
|
37047
|
+
return true;
|
|
37048
|
+
}
|
|
37049
|
+
});
|
|
37050
|
+
use_input_default(
|
|
37051
|
+
(_ch, k) => {
|
|
37052
|
+
if (k.escape) return back();
|
|
37053
|
+
if (k.upArrow || k.downArrow || k.tab) return setKind((x) => x === "openai" ? "anthropic" : "openai");
|
|
37054
|
+
if (k.return) next("url", url);
|
|
37055
|
+
},
|
|
37056
|
+
{ isActive: !busy && step === "kind" }
|
|
37057
|
+
);
|
|
37058
|
+
const done = (label2, value) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37059
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.ok, children: [
|
|
37060
|
+
G.ok,
|
|
37061
|
+
" "
|
|
37062
|
+
] }),
|
|
37063
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: pad(label2, 10) }),
|
|
37064
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { children: value })
|
|
37065
|
+
] });
|
|
37066
|
+
const at = order.indexOf(step);
|
|
37067
|
+
const prompt = {
|
|
37068
|
+
name: { label: "Name", hint: "What to call it in the model picker.", placeholder: "e.g. My Gateway" },
|
|
37069
|
+
url: {
|
|
37070
|
+
label: "Base URL",
|
|
37071
|
+
hint: kind === "openai" ? "The URL before /chat/completions \u2014 usually ends in /v1." : "The URL before /messages \u2014 usually ends in /v1.",
|
|
37072
|
+
placeholder: "https://api.example.com/v1"
|
|
37073
|
+
},
|
|
37074
|
+
key: { label: "API key", hint: "Leave empty if the endpoint needs no key (e.g. a local server).", placeholder: "paste the key, or enter to skip" },
|
|
37075
|
+
models: {
|
|
37076
|
+
label: "Models",
|
|
37077
|
+
hint: "Model ids, separated by commas. Leave empty to import every model from the endpoint's /models list.",
|
|
37078
|
+
placeholder: "e.g. gpt-4.1, claude-sonnet-4"
|
|
37079
|
+
}
|
|
37080
|
+
};
|
|
37081
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
37082
|
+
Panel,
|
|
37083
|
+
{
|
|
37084
|
+
title: "Custom provider",
|
|
37085
|
+
right: `step ${at + 1} of ${order.length}`,
|
|
37086
|
+
width: p.width,
|
|
37087
|
+
color: p.color,
|
|
37088
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
37089
|
+
Hints,
|
|
37090
|
+
{
|
|
37091
|
+
items: step === "kind" ? [["\u2191\u2193", "choose"], ["enter", "continue"], ["esc", "back"]] : [["enter", step === "models" ? "save" : "continue"], ["esc", "back"]]
|
|
37092
|
+
}
|
|
37093
|
+
),
|
|
37094
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37095
|
+
at > 0 ? done("Name", name) : null,
|
|
37096
|
+
at > 1 ? done("Type", KIND_LABEL[kind]) : null,
|
|
37097
|
+
at > 2 ? done("Base URL", url) : null,
|
|
37098
|
+
at > 3 ? done("API key", key ? "\u2022".repeat(Math.min(key.length, 12)) : "none") : null,
|
|
37099
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: at > 0 ? 1 : 0, flexDirection: "column", children: step === "kind" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
37100
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: "Which API does the endpoint speak?" }),
|
|
37101
|
+
KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { children: [
|
|
37102
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
37103
|
+
k === kind ? G.prompt : " ",
|
|
37104
|
+
" "
|
|
37105
|
+
] }),
|
|
37106
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: k === kind, children: pad(KIND_LABEL[k], 24) }),
|
|
37107
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: k === "openai" ? "/chat/completions \u2014 most gateways, vLLM, Ollama" : "/messages \u2014 Anthropic-style proxies" })
|
|
37108
|
+
] }, k))
|
|
37109
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
37110
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: prompt[step].hint }),
|
|
37111
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37112
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
37113
|
+
step === "key" ? G.key : G.prompt,
|
|
37114
|
+
" "
|
|
37115
|
+
] }),
|
|
37116
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, children: pad(prompt[step].label, 10) }),
|
|
37117
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldText, { state: field.state, mask: step === "key", placeholder: prompt[step].placeholder })
|
|
37118
|
+
] })
|
|
37119
|
+
] }) }),
|
|
37120
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { children: [
|
|
37121
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Spinner, {}),
|
|
37122
|
+
" ",
|
|
37123
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: busy })
|
|
37124
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "The endpoint goes into the engine config; the key into the engine's credential store. Never sent to Latent." }) }),
|
|
37125
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, wrap: "wrap", children: error }) : null
|
|
37126
|
+
] })
|
|
37127
|
+
}
|
|
37128
|
+
);
|
|
37129
|
+
}
|
|
36760
37130
|
function Done(p) {
|
|
36761
37131
|
use_input_default((_ch, key) => {
|
|
36762
37132
|
if (key.return) return p.onModels();
|
|
36763
37133
|
if (key.escape) p.onClose();
|
|
36764
37134
|
});
|
|
36765
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.
|
|
37135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
36766
37136
|
Panel,
|
|
36767
37137
|
{
|
|
36768
37138
|
title: "Connected",
|
|
36769
37139
|
width: p.width,
|
|
36770
37140
|
color: C.ok,
|
|
36771
37141
|
footer: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Hints, { items: [["enter", "pick a model"], ["esc", "close"]] }),
|
|
36772
|
-
children:
|
|
36773
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.
|
|
36774
|
-
|
|
36775
|
-
|
|
36776
|
-
|
|
36777
|
-
|
|
36778
|
-
|
|
36779
|
-
|
|
37142
|
+
children: [
|
|
37143
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { children: [
|
|
37144
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.ok, children: [
|
|
37145
|
+
G.ok,
|
|
37146
|
+
" "
|
|
37147
|
+
] }),
|
|
37148
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, children: p.name }),
|
|
37149
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: p.models ? ` is connected \u2014 ${p.models} models available.` : " is connected. Its models will appear after a moment." })
|
|
37150
|
+
] }) }),
|
|
37151
|
+
p.note ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, wrap: "wrap", children: p.note }) }) : null
|
|
37152
|
+
]
|
|
36780
37153
|
}
|
|
36781
37154
|
);
|
|
36782
37155
|
}
|
|
@@ -37180,7 +37553,7 @@ function BootCard(p) {
|
|
|
37180
37553
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37181
37554
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.faint, children: "\xB7 " }),
|
|
37182
37555
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.faint, children: pad("Project", wLabel) }),
|
|
37183
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: shortPath(p.cwd,
|
|
37556
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: shortPath(p.cwd, homedir4(), inner - wLabel - 4) })
|
|
37184
37557
|
] })
|
|
37185
37558
|
] }),
|
|
37186
37559
|
p.error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginLeft: 1, marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.err, wrap: "wrap", children: p.error }) }) : null,
|
package/package.json
CHANGED