latentcode 0.1.0-alpha.2 → 0.1.0-alpha.6
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 +4 -3
- package/dist/latentcode.mjs +943 -635
- package/package.json +4 -1
package/dist/latentcode.mjs
CHANGED
|
@@ -25333,7 +25333,7 @@ var require_websocket = __commonJS({
|
|
|
25333
25333
|
var http = __require("http");
|
|
25334
25334
|
var net = __require("net");
|
|
25335
25335
|
var tls = __require("tls");
|
|
25336
|
-
var { randomBytes: randomBytes2, createHash } = __require("crypto");
|
|
25336
|
+
var { randomBytes: randomBytes2, createHash: createHash2 } = __require("crypto");
|
|
25337
25337
|
var { Duplex, Readable } = __require("stream");
|
|
25338
25338
|
var { URL: URL2 } = __require("url");
|
|
25339
25339
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -26019,7 +26019,7 @@ var require_websocket = __commonJS({
|
|
|
26019
26019
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
26020
26020
|
return;
|
|
26021
26021
|
}
|
|
26022
|
-
const digest =
|
|
26022
|
+
const digest = createHash2("sha1").update(key + GUID).digest("base64");
|
|
26023
26023
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
26024
26024
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
26025
26025
|
return;
|
|
@@ -26388,7 +26388,7 @@ var require_websocket_server = __commonJS({
|
|
|
26388
26388
|
var EventEmitter3 = __require("events");
|
|
26389
26389
|
var http = __require("http");
|
|
26390
26390
|
var { Duplex } = __require("stream");
|
|
26391
|
-
var { createHash } = __require("crypto");
|
|
26391
|
+
var { createHash: createHash2 } = __require("crypto");
|
|
26392
26392
|
var extension2 = require_extension();
|
|
26393
26393
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
26394
26394
|
var subprotocol2 = require_subprotocol();
|
|
@@ -26695,7 +26695,7 @@ var require_websocket_server = __commonJS({
|
|
|
26695
26695
|
);
|
|
26696
26696
|
}
|
|
26697
26697
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
26698
|
-
const digest =
|
|
26698
|
+
const digest = createHash2("sha1").update(key + GUID).digest("base64");
|
|
26699
26699
|
const headers = [
|
|
26700
26700
|
"HTTP/1.1 101 Switching Protocols",
|
|
26701
26701
|
"Upgrade: websocket",
|
|
@@ -28208,11 +28208,11 @@ var require_react_jsx_runtime_development = __commonJS({
|
|
|
28208
28208
|
return jsxWithValidation(type, props, key, false);
|
|
28209
28209
|
}
|
|
28210
28210
|
}
|
|
28211
|
-
var
|
|
28212
|
-
var
|
|
28211
|
+
var jsx10 = jsxWithValidationDynamic;
|
|
28212
|
+
var jsxs8 = jsxWithValidationStatic;
|
|
28213
28213
|
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
28214
|
-
exports.jsx =
|
|
28215
|
-
exports.jsxs =
|
|
28214
|
+
exports.jsx = jsx10;
|
|
28215
|
+
exports.jsxs = jsxs8;
|
|
28216
28216
|
})();
|
|
28217
28217
|
}
|
|
28218
28218
|
}
|
|
@@ -33576,6 +33576,12 @@ function Static(props) {
|
|
|
33576
33576
|
|
|
33577
33577
|
// node_modules/ink/build/components/Transform.js
|
|
33578
33578
|
var import_react12 = __toESM(require_react(), 1);
|
|
33579
|
+
function Transform({ children, transform }) {
|
|
33580
|
+
if (children === void 0 || children === null) {
|
|
33581
|
+
return null;
|
|
33582
|
+
}
|
|
33583
|
+
return import_react12.default.createElement("ink-text", { style: { flexGrow: 0, flexShrink: 1, flexDirection: "row" }, internal_transform: transform }, children);
|
|
33584
|
+
}
|
|
33579
33585
|
|
|
33580
33586
|
// node_modules/ink/build/components/Newline.js
|
|
33581
33587
|
var import_react13 = __toESM(require_react(), 1);
|
|
@@ -34389,9 +34395,10 @@ import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync a
|
|
|
34389
34395
|
import { join as join3 } from "node:path";
|
|
34390
34396
|
|
|
34391
34397
|
// src/ads/config.ts
|
|
34392
|
-
import {
|
|
34398
|
+
import { createHash } from "node:crypto";
|
|
34399
|
+
import { homedir as homedir2, hostname } from "node:os";
|
|
34393
34400
|
import { join as join2 } from "node:path";
|
|
34394
|
-
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
34401
|
+
import { chmodSync, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
34395
34402
|
var DEFAULT_SERVER = "https://api.latentprotocol.xyz";
|
|
34396
34403
|
var AGENT_LATENTCODE = "latentcode";
|
|
34397
34404
|
function configDir() {
|
|
@@ -34415,7 +34422,13 @@ function loadConfig() {
|
|
|
34415
34422
|
function saveConfig(data) {
|
|
34416
34423
|
mkdirSync(configDir(), { recursive: true });
|
|
34417
34424
|
const next = { ...loadConfig(), ...data };
|
|
34418
|
-
writeFileSync(configFile(), JSON.stringify(next, null, 2) + "\n");
|
|
34425
|
+
writeFileSync(configFile(), JSON.stringify(next, null, 2) + "\n", { mode: 384 });
|
|
34426
|
+
if (next.latent_key) {
|
|
34427
|
+
try {
|
|
34428
|
+
chmodSync(configFile(), 384);
|
|
34429
|
+
} catch {
|
|
34430
|
+
}
|
|
34431
|
+
}
|
|
34419
34432
|
return next;
|
|
34420
34433
|
}
|
|
34421
34434
|
function resolveServer(cfg = loadConfig()) {
|
|
@@ -34425,10 +34438,10 @@ function resolveWallet(cfg = loadConfig()) {
|
|
|
34425
34438
|
const w = cfg.wallet || process.env.ADS_WALLET || "";
|
|
34426
34439
|
return WALLET_RE.test(w) ? w : "";
|
|
34427
34440
|
}
|
|
34428
|
-
function adsEnabled(cfg = loadConfig()) {
|
|
34441
|
+
function adsEnabled(cfg = loadConfig(), key = "latentcode_ads") {
|
|
34429
34442
|
const env3 = process.env.ADS_ENABLED;
|
|
34430
34443
|
if (env3 !== void 0) return !["false", "0", "no"].includes(env3.toLowerCase());
|
|
34431
|
-
return cfg
|
|
34444
|
+
return cfg[key] !== false;
|
|
34432
34445
|
}
|
|
34433
34446
|
function deviceId() {
|
|
34434
34447
|
try {
|
|
@@ -34438,6 +34451,12 @@ function deviceId() {
|
|
|
34438
34451
|
}
|
|
34439
34452
|
return "";
|
|
34440
34453
|
}
|
|
34454
|
+
function deviceKeyId() {
|
|
34455
|
+
const cred = deviceId();
|
|
34456
|
+
if (cred) return cred.split(".")[0];
|
|
34457
|
+
return createHash("sha256").update(`${hostname()}
|
|
34458
|
+
${homedir2()}`).digest("hex").slice(0, 32);
|
|
34459
|
+
}
|
|
34441
34460
|
async function ensureDeviceCredential(server) {
|
|
34442
34461
|
const current = deviceId();
|
|
34443
34462
|
if (current) return current;
|
|
@@ -34538,6 +34557,96 @@ function chooseStartModel(def, all, store) {
|
|
|
34538
34557
|
return ok ? { model: ok, switchedFrom: def } : { model: def };
|
|
34539
34558
|
}
|
|
34540
34559
|
|
|
34560
|
+
// src/ads/controller.ts
|
|
34561
|
+
import { randomUUID } from "node:crypto";
|
|
34562
|
+
|
|
34563
|
+
// src/ads/sanitize.ts
|
|
34564
|
+
var ESC_SEQ = /\x1b\][\s\S]*?(?:\x07|\x1b\\|$)|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[ -/]*[0-~]|\x1b[@-_]/g;
|
|
34565
|
+
var CONTROL = /[\x00-\x1f\x7f-\x9f]/g;
|
|
34566
|
+
var BIDI = /[--]/g;
|
|
34567
|
+
function sanitizeAdText(input, max = 140) {
|
|
34568
|
+
let s2 = String(input ?? "");
|
|
34569
|
+
s2 = s2.replace(ESC_SEQ, "").replace(CONTROL, " ").replace(BIDI, "");
|
|
34570
|
+
s2 = s2.replace(/\s+/g, " ").trim();
|
|
34571
|
+
if (max > 0 && s2.length > max) s2 = `${s2.slice(0, Math.max(0, max - 1)).trimEnd()}\u2026`;
|
|
34572
|
+
return s2;
|
|
34573
|
+
}
|
|
34574
|
+
var AD_LIMITS = { title: 30, body: 140, cta_text: 24 };
|
|
34575
|
+
|
|
34576
|
+
// src/ads/adline.ts
|
|
34577
|
+
var WORD = /[\p{L}\p{N}]/u;
|
|
34578
|
+
var LEAD_SEP = /^[\s\-:–—]+/;
|
|
34579
|
+
function clampField(value, max) {
|
|
34580
|
+
const t = value.trim();
|
|
34581
|
+
if (t.length <= max) return t;
|
|
34582
|
+
return `${t.slice(0, Math.max(1, max - 1)).trimEnd()}\u2026`;
|
|
34583
|
+
}
|
|
34584
|
+
function dedupeBrand(brand, body) {
|
|
34585
|
+
let t = body.trim();
|
|
34586
|
+
const b = brand.trim();
|
|
34587
|
+
if (!b) return t;
|
|
34588
|
+
const lb = b.toLowerCase();
|
|
34589
|
+
while (t.toLowerCase().startsWith(lb)) {
|
|
34590
|
+
const after = t.charAt(b.length);
|
|
34591
|
+
if (after !== "" && WORD.test(after)) break;
|
|
34592
|
+
const rest = t.slice(b.length).replace(LEAD_SEP, "");
|
|
34593
|
+
if (rest === t) break;
|
|
34594
|
+
t = rest;
|
|
34595
|
+
if (t === "") break;
|
|
34596
|
+
}
|
|
34597
|
+
return t;
|
|
34598
|
+
}
|
|
34599
|
+
function composeAdCopy(title, body) {
|
|
34600
|
+
const brandRaw = sanitizeAdText(title, 0);
|
|
34601
|
+
const bodyRaw = sanitizeAdText(body, 0);
|
|
34602
|
+
return { brand: clampField(brandRaw, 30), line: clampField(dedupeBrand(brandRaw, bodyRaw), 60) };
|
|
34603
|
+
}
|
|
34604
|
+
function isSafeUrl(raw, allowLoopbackHttp = false) {
|
|
34605
|
+
if (typeof raw !== "string" || !raw) return false;
|
|
34606
|
+
if (/[\x00-\x20\x7f-\x9f]/.test(raw)) return false;
|
|
34607
|
+
try {
|
|
34608
|
+
const u = new URL(raw);
|
|
34609
|
+
if (u.username || u.password) return false;
|
|
34610
|
+
if (u.protocol === "https:") return true;
|
|
34611
|
+
return allowLoopbackHttp && u.protocol === "http:" && (u.hostname === "127.0.0.1" || u.hostname === "localhost");
|
|
34612
|
+
} catch {
|
|
34613
|
+
return false;
|
|
34614
|
+
}
|
|
34615
|
+
}
|
|
34616
|
+
function displayUrl(url) {
|
|
34617
|
+
return url.startsWith("https://") ? url.slice("https://".length).replace(/\/$/, "") : "";
|
|
34618
|
+
}
|
|
34619
|
+
function clickLink(server, ad, wallet, ctaUrl) {
|
|
34620
|
+
const base = server.replace(/\/+$/, "");
|
|
34621
|
+
if (!ad.click_token || !isSafeUrl(base, true)) return ctaUrl;
|
|
34622
|
+
return `${base}/ad/click?ad=${encodeURIComponent(ad.ad_id)}&w=${encodeURIComponent(wallet)}&t=${encodeURIComponent(ad.click_token)}`;
|
|
34623
|
+
}
|
|
34624
|
+
function linkShape(env3 = process.env, platform2 = process.platform) {
|
|
34625
|
+
if (env3.LATENTCODE_LINKS === "osc8" || env3.LATENTCODE_LINKS === "plain" || env3.LATENTCODE_LINKS === "hybrid") {
|
|
34626
|
+
return env3.LATENTCODE_LINKS;
|
|
34627
|
+
}
|
|
34628
|
+
if (env3.TMUX) return "plain";
|
|
34629
|
+
if (env3.SSH_TTY || env3.SSH_CONNECTION) return "hybrid";
|
|
34630
|
+
if (env3.KITTY_WINDOW_ID || env3.WEZTERM_PANE || env3.ITERM_SESSION_ID || env3.GHOSTTY_RESOURCES_DIR) return "osc8";
|
|
34631
|
+
if (env3.ALACRITTY_SOCKET || env3.ALACRITTY_WINDOW_ID) return "plain";
|
|
34632
|
+
const term = env3.TERM_PROGRAM || "";
|
|
34633
|
+
if (term === "vscode" || term === "iTerm.app" || term === "WezTerm" || term === "ghostty") return "osc8";
|
|
34634
|
+
if (term === "Apple_Terminal" || term === "WarpTerminal") return "plain";
|
|
34635
|
+
if (env3.WT_SESSION) return "osc8";
|
|
34636
|
+
return platform2 === "win32" ? "plain" : "hybrid";
|
|
34637
|
+
}
|
|
34638
|
+
function osc8(text, url) {
|
|
34639
|
+
if (!isSafeUrl(url, true)) return text;
|
|
34640
|
+
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
34641
|
+
}
|
|
34642
|
+
var BADGE_COLORS = ["#F87171", "#FB923C", "#FBBF24", "#A3E635", "#34D399", "#22D3EE", "#60A5FA", "#A78BFA", "#F472B6"];
|
|
34643
|
+
function adBadge(brand) {
|
|
34644
|
+
const letter = ([...brand].find((c) => /[\p{L}\p{N}]/u.test(c)) ?? "").toLocaleUpperCase();
|
|
34645
|
+
let h = 2166136261;
|
|
34646
|
+
for (const c of brand.toLowerCase()) h = Math.imul(h ^ c.codePointAt(0), 16777619);
|
|
34647
|
+
return { letter: letter || "\u2022", color: BADGE_COLORS[(h >>> 0) % BADGE_COLORS.length] };
|
|
34648
|
+
}
|
|
34649
|
+
|
|
34541
34650
|
// src/ads/classify.ts
|
|
34542
34651
|
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "node:fs";
|
|
34543
34652
|
import { join as join4 } from "node:path";
|
|
@@ -34733,43 +34842,28 @@ function classifyPrompt(prompt, cwd2 = process.cwd()) {
|
|
|
34733
34842
|
return best;
|
|
34734
34843
|
}
|
|
34735
34844
|
|
|
34736
|
-
// src/ads/sanitize.ts
|
|
34737
|
-
var ESC_SEQ = /\x1b\][\s\S]*?(?:\x07|\x1b\\|$)|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[ -/]*[0-~]|\x1b[@-_]/g;
|
|
34738
|
-
var CONTROL = /[\x00-\x1f\x7f-\x9f]/g;
|
|
34739
|
-
var BIDI = /[--]/g;
|
|
34740
|
-
function sanitizeAdText(input, max = 140) {
|
|
34741
|
-
let s2 = String(input ?? "");
|
|
34742
|
-
s2 = s2.replace(ESC_SEQ, "").replace(CONTROL, " ").replace(BIDI, "");
|
|
34743
|
-
s2 = s2.replace(/\s+/g, " ").trim();
|
|
34744
|
-
if (max > 0 && s2.length > max) s2 = `${s2.slice(0, Math.max(0, max - 1)).trimEnd()}\u2026`;
|
|
34745
|
-
return s2;
|
|
34746
|
-
}
|
|
34747
|
-
var AD_LIMITS = { title: 30, body: 140, cta_text: 24 };
|
|
34748
|
-
|
|
34749
34845
|
// src/ads/controller.ts
|
|
34750
|
-
var MIN_VISIBLE_MS =
|
|
34751
|
-
var ROTATE_MS =
|
|
34846
|
+
var MIN_VISIBLE_MS = 1e4;
|
|
34847
|
+
var ROTATE_MS = 1e4;
|
|
34848
|
+
var HOLD_MS = 27e4;
|
|
34752
34849
|
function safeUrl(raw) {
|
|
34753
|
-
|
|
34754
|
-
if (/[\x00-\x1f\x7f-\x9f\s]/.test(raw)) return "";
|
|
34755
|
-
try {
|
|
34756
|
-
const u = new URL(raw);
|
|
34757
|
-
return u.protocol === "https:" ? u.toString() : "";
|
|
34758
|
-
} catch {
|
|
34759
|
-
return "";
|
|
34760
|
-
}
|
|
34850
|
+
return raw && isSafeUrl(raw) ? new URL(raw).toString() : "";
|
|
34761
34851
|
}
|
|
34762
|
-
function toDisplayAd(ad) {
|
|
34763
|
-
const
|
|
34764
|
-
|
|
34765
|
-
|
|
34852
|
+
function toDisplayAd(ad, opts = {}) {
|
|
34853
|
+
const { brand, line } = composeAdCopy(ad.title, ad.body);
|
|
34854
|
+
if (!brand && !line) return null;
|
|
34855
|
+
const url = safeUrl(ad.cta_url);
|
|
34766
34856
|
return {
|
|
34767
34857
|
ad,
|
|
34768
|
-
title,
|
|
34769
|
-
body,
|
|
34858
|
+
title: brand,
|
|
34859
|
+
body: line,
|
|
34770
34860
|
ctaText: sanitizeAdText(ad.cta_text, AD_LIMITS.cta_text) || "Learn more",
|
|
34771
|
-
url
|
|
34772
|
-
|
|
34861
|
+
url,
|
|
34862
|
+
link: url && opts.server && opts.wallet ? clickLink(opts.server, ad, opts.wallet, url) : url,
|
|
34863
|
+
shownUrl: displayUrl(url),
|
|
34864
|
+
earn: typeof ad.earn_amount === "number" && Number.isFinite(ad.earn_amount) ? ad.earn_amount : 0,
|
|
34865
|
+
eventUuid: randomUUID(),
|
|
34866
|
+
fetchedAt: opts.now ?? Date.now()
|
|
34773
34867
|
};
|
|
34774
34868
|
}
|
|
34775
34869
|
var AdController = class {
|
|
@@ -34795,6 +34889,7 @@ var AdController = class {
|
|
|
34795
34889
|
now: opts.now ?? Date.now,
|
|
34796
34890
|
minVisibleMs: opts.minVisibleMs ?? MIN_VISIBLE_MS,
|
|
34797
34891
|
rotateMs: opts.rotateMs ?? ROTATE_MS,
|
|
34892
|
+
holdMs: opts.holdMs ?? HOLD_MS,
|
|
34798
34893
|
classify: opts.classify ?? ((p, cwd2) => classifyPrompt(p, cwd2))
|
|
34799
34894
|
};
|
|
34800
34895
|
opts.focus.onChange(() => this.emit());
|
|
@@ -34841,29 +34936,49 @@ var AdController = class {
|
|
|
34841
34936
|
this.lastTick = this.o.now();
|
|
34842
34937
|
if (working) {
|
|
34843
34938
|
this.context = this.o.classify(prompt, this.o.cwd);
|
|
34844
|
-
|
|
34845
|
-
|
|
34939
|
+
if (!this.holding()) {
|
|
34940
|
+
this.clear();
|
|
34941
|
+
void this.fetchNext();
|
|
34942
|
+
}
|
|
34943
|
+
} else if (this.billed || !this.current) {
|
|
34846
34944
|
this.clear();
|
|
34945
|
+
} else {
|
|
34946
|
+
this.generation += 1;
|
|
34847
34947
|
}
|
|
34848
34948
|
this.emit();
|
|
34849
34949
|
}
|
|
34950
|
+
/** An un-billed ad that may still be shown and billed. */
|
|
34951
|
+
holding() {
|
|
34952
|
+
return !!this.current && !this.billed && this.o.now() - this.current.fetchedAt < this.o.holdMs;
|
|
34953
|
+
}
|
|
34850
34954
|
/** Advance the attention clock. Call every ~250ms. */
|
|
34851
34955
|
tick() {
|
|
34852
34956
|
const now = this.o.now();
|
|
34853
34957
|
const dt = Math.max(0, now - this.lastTick);
|
|
34854
34958
|
this.lastTick = now;
|
|
34855
34959
|
if (!this.working || !this.current) return;
|
|
34960
|
+
if (!this.billed && !this.holding()) {
|
|
34961
|
+
this.clear();
|
|
34962
|
+
void this.fetchNext();
|
|
34963
|
+
return;
|
|
34964
|
+
}
|
|
34856
34965
|
if (this.o.focus.focused) this.visibleMs += dt;
|
|
34857
34966
|
if (!this.billed && this.visibleMs >= this.o.minVisibleMs) {
|
|
34858
34967
|
this.billed = true;
|
|
34859
|
-
this.
|
|
34860
|
-
this.sessionEarned += this.current.earn;
|
|
34968
|
+
const shown = this.current;
|
|
34861
34969
|
void this.o.api.impression({
|
|
34862
|
-
ad:
|
|
34970
|
+
ad: shown.ad,
|
|
34863
34971
|
wallet: this.o.wallet,
|
|
34864
34972
|
context: this.context,
|
|
34865
34973
|
displayedMs: this.visibleMs,
|
|
34866
|
-
focusTracked: this.o.focus.known
|
|
34974
|
+
focusTracked: this.o.focus.known,
|
|
34975
|
+
eventUuid: shown.eventUuid
|
|
34976
|
+
}).then((result) => {
|
|
34977
|
+
if (result !== "tracked") return;
|
|
34978
|
+
this.impressions += 1;
|
|
34979
|
+
this.sessionEarned += shown.earn;
|
|
34980
|
+
this.emit();
|
|
34981
|
+
}).catch(() => {
|
|
34867
34982
|
});
|
|
34868
34983
|
this.emit();
|
|
34869
34984
|
}
|
|
@@ -34871,12 +34986,10 @@ var AdController = class {
|
|
|
34871
34986
|
void this.fetchNext();
|
|
34872
34987
|
}
|
|
34873
34988
|
}
|
|
34874
|
-
/** User
|
|
34989
|
+
/** User asked to open the ad (keyboard): the tracked link, or null. The server counts the click on redirect. */
|
|
34875
34990
|
click() {
|
|
34876
34991
|
const ad = this.working ? this.current : null;
|
|
34877
|
-
|
|
34878
|
-
void this.o.api.click({ ad: ad.ad, wallet: this.o.wallet, context: this.context });
|
|
34879
|
-
return ad.url;
|
|
34992
|
+
return ad?.link || null;
|
|
34880
34993
|
}
|
|
34881
34994
|
clear() {
|
|
34882
34995
|
this.generation += 1;
|
|
@@ -34891,7 +35004,7 @@ var AdController = class {
|
|
|
34891
35004
|
try {
|
|
34892
35005
|
const ad = await this.o.api.request({ wallet: this.o.wallet, context: this.context, sessionId: this.o.sessionId });
|
|
34893
35006
|
if (gen !== this.generation || !this.working || this.status !== "ok") return;
|
|
34894
|
-
const display = ad ? toDisplayAd(ad) : null;
|
|
35007
|
+
const display = ad ? toDisplayAd(ad, { server: this.o.api.server, wallet: this.o.wallet, now: this.o.now() }) : null;
|
|
34895
35008
|
if (!display) {
|
|
34896
35009
|
if (this.current) this.shownAt = this.o.now();
|
|
34897
35010
|
return;
|
|
@@ -34912,9 +35025,6 @@ var AdController = class {
|
|
|
34912
35025
|
}
|
|
34913
35026
|
};
|
|
34914
35027
|
|
|
34915
|
-
// src/ads/api.ts
|
|
34916
|
-
import { randomUUID } from "node:crypto";
|
|
34917
|
-
|
|
34918
35028
|
// src/ads/killswitch.ts
|
|
34919
35029
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
34920
35030
|
import { join as join5 } from "node:path";
|
|
@@ -34995,8 +35105,11 @@ function recordServerResult(ok, now = Date.now()) {
|
|
|
34995
35105
|
|
|
34996
35106
|
// src/ads/api.ts
|
|
34997
35107
|
var SURFACE_WORKING_BAR = "status_line";
|
|
34998
|
-
function httpAdApi(server = resolveServer()) {
|
|
35108
|
+
function httpAdApi(server = resolveServer(), identity = {}) {
|
|
35109
|
+
const agent = identity.agent ?? AGENT_LATENTCODE;
|
|
35110
|
+
const surface = identity.surface ?? SURFACE_WORKING_BAR;
|
|
34999
35111
|
return {
|
|
35112
|
+
server,
|
|
35000
35113
|
async request({ wallet, context, sessionId }) {
|
|
35001
35114
|
void refreshKillswitch(server);
|
|
35002
35115
|
if (!shouldServe().ok) return null;
|
|
@@ -35007,9 +35120,9 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35007
35120
|
headers: { "Content-Type": "application/json" },
|
|
35008
35121
|
body: JSON.stringify({
|
|
35009
35122
|
user_wallet: wallet,
|
|
35010
|
-
agent
|
|
35123
|
+
agent,
|
|
35011
35124
|
context: context.slice(0, 100),
|
|
35012
|
-
surface
|
|
35125
|
+
surface,
|
|
35013
35126
|
tags: context ? [context] : [],
|
|
35014
35127
|
session_id: sessionId,
|
|
35015
35128
|
device_id: device
|
|
@@ -35025,8 +35138,8 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35025
35138
|
return null;
|
|
35026
35139
|
}
|
|
35027
35140
|
},
|
|
35028
|
-
async impression({ ad, wallet, context, displayedMs, focusTracked }) {
|
|
35029
|
-
if (!shouldServe().ok) return;
|
|
35141
|
+
async impression({ ad, wallet, context, displayedMs, focusTracked, eventUuid }) {
|
|
35142
|
+
if (!shouldServe().ok) return "error";
|
|
35030
35143
|
const device = await ensureDeviceCredential(server);
|
|
35031
35144
|
try {
|
|
35032
35145
|
const res = await fetch(`${server}/ad/impression`, {
|
|
@@ -35036,11 +35149,11 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35036
35149
|
ad_id: ad.ad_id,
|
|
35037
35150
|
user_wallet: wallet,
|
|
35038
35151
|
token: ad.impression_token ?? "",
|
|
35039
|
-
agent
|
|
35040
|
-
surface
|
|
35152
|
+
agent,
|
|
35153
|
+
surface,
|
|
35041
35154
|
context,
|
|
35042
35155
|
device_id: device,
|
|
35043
|
-
event_uuid:
|
|
35156
|
+
event_uuid: eventUuid,
|
|
35044
35157
|
displayed_ms: Math.round(displayedMs),
|
|
35045
35158
|
// Attention signal: the dwell above was measured with real terminal
|
|
35046
35159
|
// focus events, not assumed. Servers that don't know it ignore it.
|
|
@@ -35049,34 +35162,45 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35049
35162
|
signal: AbortSignal.timeout(2e3)
|
|
35050
35163
|
});
|
|
35051
35164
|
recordServerResult(res.status < 500);
|
|
35165
|
+
if (!res.ok) return "error";
|
|
35166
|
+
const status2 = (await res.json().catch(() => ({}))).status;
|
|
35167
|
+
return status2 === "tracked" || status2 === "skipped" || status2 === "unearned" ? status2 : "error";
|
|
35052
35168
|
} catch {
|
|
35053
35169
|
recordServerResult(false);
|
|
35170
|
+
return "error";
|
|
35054
35171
|
}
|
|
35055
35172
|
},
|
|
35056
|
-
async
|
|
35057
|
-
const device = await ensureDeviceCredential(server);
|
|
35173
|
+
async creditQuote() {
|
|
35058
35174
|
try {
|
|
35059
|
-
await fetch(`${server}/
|
|
35060
|
-
|
|
35061
|
-
|
|
35062
|
-
|
|
35063
|
-
|
|
35064
|
-
|
|
35065
|
-
|
|
35066
|
-
|
|
35067
|
-
context,
|
|
35068
|
-
device_id: device
|
|
35069
|
-
}),
|
|
35070
|
-
signal: AbortSignal.timeout(2e3)
|
|
35071
|
-
});
|
|
35175
|
+
const res = await fetch(`${server}/credit/quote`, { signal: AbortSignal.timeout(4e3) });
|
|
35176
|
+
if (!res.ok) return null;
|
|
35177
|
+
const q = await res.json();
|
|
35178
|
+
return {
|
|
35179
|
+
bonus: Number(q.bonus ?? 1),
|
|
35180
|
+
buybackPrice: Number(q.sell_price ?? q.buyback_price ?? 0),
|
|
35181
|
+
buybackEnabled: Boolean(q.buyback_enabled)
|
|
35182
|
+
};
|
|
35072
35183
|
} catch {
|
|
35184
|
+
return null;
|
|
35073
35185
|
}
|
|
35074
35186
|
},
|
|
35075
35187
|
async balance(wallet) {
|
|
35076
35188
|
try {
|
|
35077
35189
|
const res = await fetch(`${server}/earnings/${wallet}`, { signal: AbortSignal.timeout(4e3) });
|
|
35078
35190
|
if (!res.ok) return null;
|
|
35079
|
-
|
|
35191
|
+
const e = await res.json();
|
|
35192
|
+
return Number(e.credits ?? e.balance ?? 0);
|
|
35193
|
+
} catch {
|
|
35194
|
+
return null;
|
|
35195
|
+
}
|
|
35196
|
+
},
|
|
35197
|
+
async creditSummary(wallet) {
|
|
35198
|
+
try {
|
|
35199
|
+
const res = await fetch(`${server}/credit/${wallet}/summary`, { signal: AbortSignal.timeout(4e3) });
|
|
35200
|
+
if (!res.ok) return null;
|
|
35201
|
+
const c = await res.json();
|
|
35202
|
+
const mode = c.mode === "auto_sell" || c.mode === "auto_list" ? c.mode : "keep";
|
|
35203
|
+
return { credits: Number(c.credits ?? 0), mode, bonus: Number(c.bonus ?? 1), sellPrice: Number(c.sell_price ?? 0) };
|
|
35080
35204
|
} catch {
|
|
35081
35205
|
return null;
|
|
35082
35206
|
}
|
|
@@ -35084,6 +35208,191 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35084
35208
|
};
|
|
35085
35209
|
}
|
|
35086
35210
|
|
|
35211
|
+
// src/engine/customProvider.ts
|
|
35212
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync, writeFileSync as writeFileSync4, copyFileSync } from "node:fs";
|
|
35213
|
+
import { homedir as homedir3 } from "node:os";
|
|
35214
|
+
import { join as join6 } from "node:path";
|
|
35215
|
+
var KIND_PACKAGE = {
|
|
35216
|
+
openai: "@opencode/ai/providers/openai-compatible",
|
|
35217
|
+
anthropic: "@opencode/ai/providers/anthropic-compatible"
|
|
35218
|
+
};
|
|
35219
|
+
var KIND_LABEL = {
|
|
35220
|
+
openai: "OpenAI-compatible",
|
|
35221
|
+
anthropic: "Anthropic-compatible"
|
|
35222
|
+
};
|
|
35223
|
+
var CONFIG_FILES = ["opencode.json", "opencode.jsonc"];
|
|
35224
|
+
function slugify(name) {
|
|
35225
|
+
return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
35226
|
+
}
|
|
35227
|
+
function providerIdFor(name, taken, custom) {
|
|
35228
|
+
const base = slugify(name) || "custom";
|
|
35229
|
+
if (custom.has(base) || !taken.has(base)) return base;
|
|
35230
|
+
for (let i = 0; ; i++) {
|
|
35231
|
+
const id = i === 0 ? `${base}-custom` : `${base}-custom-${i + 1}`;
|
|
35232
|
+
if (custom.has(id) || !taken.has(id)) return id;
|
|
35233
|
+
}
|
|
35234
|
+
}
|
|
35235
|
+
function normalizeBaseURL(raw) {
|
|
35236
|
+
const s2 = raw.trim();
|
|
35237
|
+
let u;
|
|
35238
|
+
try {
|
|
35239
|
+
u = new URL(s2);
|
|
35240
|
+
} catch {
|
|
35241
|
+
throw new Error("That is not a URL. Example: https://api.example.com/v1");
|
|
35242
|
+
}
|
|
35243
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("The base URL must start with https:// or http://");
|
|
35244
|
+
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");
|
|
35245
|
+
return u.toString().replace(/\/+$/, "");
|
|
35246
|
+
}
|
|
35247
|
+
function parseModelList(raw) {
|
|
35248
|
+
const seen = /* @__PURE__ */ new Set();
|
|
35249
|
+
for (const part of raw.split(/[\s,]+/)) {
|
|
35250
|
+
const id = part.trim();
|
|
35251
|
+
if (id) seen.add(id);
|
|
35252
|
+
}
|
|
35253
|
+
return [...seen];
|
|
35254
|
+
}
|
|
35255
|
+
function providerEntry(input) {
|
|
35256
|
+
const models = {};
|
|
35257
|
+
for (const id of input.models) models[id] = { name: id };
|
|
35258
|
+
return {
|
|
35259
|
+
name: input.name.trim(),
|
|
35260
|
+
package: KIND_PACKAGE[input.kind],
|
|
35261
|
+
settings: { baseURL: input.baseURL },
|
|
35262
|
+
models
|
|
35263
|
+
};
|
|
35264
|
+
}
|
|
35265
|
+
function parseJsonc(text) {
|
|
35266
|
+
let out = "";
|
|
35267
|
+
let hadComments = false;
|
|
35268
|
+
let i = 0;
|
|
35269
|
+
while (i < text.length) {
|
|
35270
|
+
const ch = text[i];
|
|
35271
|
+
if (ch === '"') {
|
|
35272
|
+
let j = i + 1;
|
|
35273
|
+
while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
|
|
35274
|
+
out += text.slice(i, j + 1);
|
|
35275
|
+
i = j + 1;
|
|
35276
|
+
} else if (ch === "/" && text[i + 1] === "/") {
|
|
35277
|
+
hadComments = true;
|
|
35278
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
35279
|
+
} else if (ch === "/" && text[i + 1] === "*") {
|
|
35280
|
+
hadComments = true;
|
|
35281
|
+
const end2 = text.indexOf("*/", i + 2);
|
|
35282
|
+
i = end2 < 0 ? text.length : end2 + 2;
|
|
35283
|
+
} else {
|
|
35284
|
+
if (ch === "}" || ch === "]") {
|
|
35285
|
+
const m = out.match(/,\s*$/);
|
|
35286
|
+
if (m) out = out.slice(0, out.length - m[0].length) + m[0].slice(1);
|
|
35287
|
+
}
|
|
35288
|
+
out += ch;
|
|
35289
|
+
i++;
|
|
35290
|
+
}
|
|
35291
|
+
}
|
|
35292
|
+
return { value: out.trim() ? JSON.parse(out) : {}, hadComments };
|
|
35293
|
+
}
|
|
35294
|
+
function mergeProvider(existing, id, entry, defaultModel) {
|
|
35295
|
+
const { value, hadComments } = existing ? parseJsonc(existing) : { value: {}, hadComments: false };
|
|
35296
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The engine config file is not a JSON object.");
|
|
35297
|
+
const config = value;
|
|
35298
|
+
const providers = config.providers;
|
|
35299
|
+
if (providers !== void 0 && (typeof providers !== "object" || providers === null || Array.isArray(providers))) {
|
|
35300
|
+
throw new Error('The engine config has a "providers" value that is not an object.');
|
|
35301
|
+
}
|
|
35302
|
+
const next = { ...config, providers: { ...providers ?? {}, [id]: entry } };
|
|
35303
|
+
if (!("$schema" in next)) next.$schema = "https://opencode.ai/config.json";
|
|
35304
|
+
if (defaultModel && !next.model) next.model = defaultModel;
|
|
35305
|
+
return { text: JSON.stringify(next, null, 2) + "\n", hadComments };
|
|
35306
|
+
}
|
|
35307
|
+
function configuredProviderIds(text) {
|
|
35308
|
+
if (!text) return /* @__PURE__ */ new Set();
|
|
35309
|
+
try {
|
|
35310
|
+
const v = parseJsonc(text).value;
|
|
35311
|
+
return new Set(Object.keys(v?.providers ?? {}));
|
|
35312
|
+
} catch {
|
|
35313
|
+
return /* @__PURE__ */ new Set();
|
|
35314
|
+
}
|
|
35315
|
+
}
|
|
35316
|
+
function defaultConfigDir(env3 = process.env) {
|
|
35317
|
+
return join6(env3.XDG_CONFIG_HOME || join6(homedir3(), ".config"), "opencode");
|
|
35318
|
+
}
|
|
35319
|
+
function configFileIn(dir, exists = existsSync5) {
|
|
35320
|
+
const present = CONFIG_FILES.map((f) => join6(dir, f)).filter(exists);
|
|
35321
|
+
return present.at(-1) ?? join6(dir, "opencode.json");
|
|
35322
|
+
}
|
|
35323
|
+
function readConfigText(file) {
|
|
35324
|
+
try {
|
|
35325
|
+
return readFileSync7(file, "utf8");
|
|
35326
|
+
} catch {
|
|
35327
|
+
return null;
|
|
35328
|
+
}
|
|
35329
|
+
}
|
|
35330
|
+
function writeProviderConfig(file, id, input, defaultModel) {
|
|
35331
|
+
const existing = readConfigText(file);
|
|
35332
|
+
const { text, hadComments } = mergeProvider(existing, id, providerEntry(input), defaultModel);
|
|
35333
|
+
mkdirSync4(join6(file, ".."), { recursive: true });
|
|
35334
|
+
let backup;
|
|
35335
|
+
if (existing !== null && hadComments) {
|
|
35336
|
+
backup = file + ".bak";
|
|
35337
|
+
copyFileSync(file, backup);
|
|
35338
|
+
}
|
|
35339
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
35340
|
+
writeFileSync4(tmp, text);
|
|
35341
|
+
renameSync(tmp, file);
|
|
35342
|
+
return { file, backup };
|
|
35343
|
+
}
|
|
35344
|
+
async function discoverModels(kind, baseURL, key, timeoutMs = 1e4) {
|
|
35345
|
+
const headers = kind === "anthropic" ? { "anthropic-version": "2023-06-01", ...key ? { "x-api-key": key } : {} } : key ? { authorization: `Bearer ${key}` } : {};
|
|
35346
|
+
const res = await fetch(baseURL + "/models", { headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
35347
|
+
if (!res.ok) throw new Error(`${baseURL}/models answered ${res.status}`);
|
|
35348
|
+
return parseModelsResponse(await res.json());
|
|
35349
|
+
}
|
|
35350
|
+
function parseModelsResponse(body) {
|
|
35351
|
+
const data = body?.data ?? body?.models;
|
|
35352
|
+
if (!Array.isArray(data)) throw new Error("The /models answer has no model list.");
|
|
35353
|
+
return parseModelList(
|
|
35354
|
+
data.map((m) => typeof m === "string" ? m : typeof m === "object" && m ? String(m.id ?? "") : "").join(" ")
|
|
35355
|
+
);
|
|
35356
|
+
}
|
|
35357
|
+
|
|
35358
|
+
// src/engine/latentProvider.ts
|
|
35359
|
+
var LATENT_PROVIDER_ID = "latent";
|
|
35360
|
+
var LATENT_KEY_RE = /^lk_[A-Za-z0-9_-]{20,}$/;
|
|
35361
|
+
function latentBaseURL(server) {
|
|
35362
|
+
return server.replace(/\/+$/, "") + "/v1";
|
|
35363
|
+
}
|
|
35364
|
+
async function connectLatentKey(engine, server, key, discover = discoverModels, suggested) {
|
|
35365
|
+
const k = key.trim();
|
|
35366
|
+
if (!LATENT_KEY_RE.test(k)) throw new Error("That is not a Latent Key \u2014 it starts with lk_. Get one at latentprotocol.xyz/app/earn.");
|
|
35367
|
+
const baseURL = latentBaseURL(server);
|
|
35368
|
+
let models;
|
|
35369
|
+
try {
|
|
35370
|
+
models = await discover("openai", baseURL, k);
|
|
35371
|
+
} catch (e) {
|
|
35372
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
35373
|
+
throw new Error(/ 401/.test(why) ? "The ad server does not know this key \u2014 it may have been rotated." : `Could not reach Latent (${why}).`);
|
|
35374
|
+
}
|
|
35375
|
+
if (!models.length) throw new Error("Latent lists no models right now. Try again in a minute.");
|
|
35376
|
+
const file = configFileIn(await engine.configDir() ?? defaultConfigDir());
|
|
35377
|
+
const pick = suggested && models.includes(suggested) ? suggested : void 0;
|
|
35378
|
+
const defaultModel = pick ? `${LATENT_PROVIDER_ID}/${pick}` : void 0;
|
|
35379
|
+
const written = writeProviderConfig(file, LATENT_PROVIDER_ID, { name: "Latent", kind: "openai", baseURL, models }, defaultModel);
|
|
35380
|
+
await engine.reloadConfig();
|
|
35381
|
+
await engine.waitForIntegration(LATENT_PROVIDER_ID);
|
|
35382
|
+
await engine.connectKey(LATENT_PROVIDER_ID, k);
|
|
35383
|
+
return { id: LATENT_PROVIDER_ID, models, file: written.file, backup: written.backup, defaultModel };
|
|
35384
|
+
}
|
|
35385
|
+
async function connectPendingLatentKey(engine, server, store, discover = discoverModels) {
|
|
35386
|
+
const cfg = store.load();
|
|
35387
|
+
if (!cfg.latent_key) return null;
|
|
35388
|
+
const res = await connectLatentKey(engine, server, cfg.latent_key, discover, cfg.latent_default_model);
|
|
35389
|
+
store.save({ latent_key: void 0, latent_default_model: void 0 });
|
|
35390
|
+
return res;
|
|
35391
|
+
}
|
|
35392
|
+
function credits(balanceUsd, bonus) {
|
|
35393
|
+
return balanceUsd * (bonus > 0 ? bonus : 1);
|
|
35394
|
+
}
|
|
35395
|
+
|
|
35087
35396
|
// src/ui/theme.ts
|
|
35088
35397
|
var C = {
|
|
35089
35398
|
accent: "#A78BFA",
|
|
@@ -35186,20 +35495,31 @@ async function boot(args, focus, report) {
|
|
|
35186
35495
|
return { value, detail: `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only` };
|
|
35187
35496
|
});
|
|
35188
35497
|
const models = new ModelStore();
|
|
35498
|
+
let latentStart;
|
|
35499
|
+
let latentNote = "";
|
|
35189
35500
|
const [catalog, commands] = await step("providers", async () => {
|
|
35501
|
+
try {
|
|
35502
|
+
const res = await connectPendingLatentKey(engine, resolveServer(), { load: loadConfig, save: (p) => void saveConfig(p) });
|
|
35503
|
+
if (res) {
|
|
35504
|
+
latentStart = res.defaultModel;
|
|
35505
|
+
latentNote = "Latent connected";
|
|
35506
|
+
}
|
|
35507
|
+
} catch (e) {
|
|
35508
|
+
latentNote = `Latent not connected yet (${firstLine(e)})`;
|
|
35509
|
+
}
|
|
35190
35510
|
const value = await Promise.all([engine.catalog(), engine.commands()]);
|
|
35191
35511
|
const c = value[0];
|
|
35192
35512
|
const verified = c.models.filter((m) => models.get(m.key)?.status === "ok").length;
|
|
35193
35513
|
return {
|
|
35194
35514
|
value,
|
|
35195
35515
|
status: c.models.length ? "ok" : "warn",
|
|
35196
|
-
detail: c.models.length ? `${listNames(c.providers.map((p) => p.name))} \xB7 ${c.models.length} models${verified ? `, ${verified} verified` : ""}` : "none connected yet \u2014 /connect to add one"
|
|
35516
|
+
detail: (c.models.length ? `${listNames(c.providers.map((p) => p.name))} \xB7 ${c.models.length} models${verified ? `, ${verified} verified` : ""}` : "none connected yet \u2014 /connect to add one") + (latentNote ? ` \xB7 ${latentNote}` : "")
|
|
35197
35517
|
};
|
|
35198
35518
|
});
|
|
35199
35519
|
const permissions = args.auto ? [] : SAFE_PERMISSIONS;
|
|
35200
35520
|
let startNotice;
|
|
35201
35521
|
const session = await step("model", async () => {
|
|
35202
|
-
let start = args.model;
|
|
35522
|
+
let start = args.model ?? (latentStart ? parseKey(latentStart) ?? void 0 : void 0);
|
|
35203
35523
|
if (!start) {
|
|
35204
35524
|
const def = await engine.defaultModel();
|
|
35205
35525
|
const defKey = def ? `${def.providerID}/${def.id}` : null;
|
|
@@ -35490,15 +35810,60 @@ function reduce(state, ev, now = Date.now()) {
|
|
|
35490
35810
|
}
|
|
35491
35811
|
}
|
|
35492
35812
|
|
|
35493
|
-
// src/ui/
|
|
35494
|
-
var
|
|
35495
|
-
|
|
35496
|
-
|
|
35497
|
-
|
|
35498
|
-
|
|
35499
|
-
|
|
35500
|
-
|
|
35501
|
-
|
|
35813
|
+
// src/ui/SponsoredLine.tsx
|
|
35814
|
+
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
35815
|
+
var MAX_BARE_URL = 60;
|
|
35816
|
+
var SHAPE = linkShape();
|
|
35817
|
+
function SponsoredLine({ ad, billed, shape = SHAPE }) {
|
|
35818
|
+
const linked = !!ad.link && shape !== "plain";
|
|
35819
|
+
const showUrl = !!ad.shownUrl && shape !== "osc8" && ad.shownUrl.length <= MAX_BARE_URL;
|
|
35820
|
+
const badge = adBadge(ad.title || ad.body);
|
|
35821
|
+
const copy = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
|
|
35822
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, underline: linked, children: ad.title || ad.body }),
|
|
35823
|
+
ad.title && ad.body ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.muted, children: [
|
|
35824
|
+
" \u2014 ",
|
|
35825
|
+
ad.body
|
|
35826
|
+
] }) : null
|
|
35827
|
+
] });
|
|
35828
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
35829
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
35830
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
|
|
35831
|
+
G.earn,
|
|
35832
|
+
" Sponsored"
|
|
35833
|
+
] }),
|
|
35834
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
35835
|
+
" ",
|
|
35836
|
+
G.thin,
|
|
35837
|
+
" "
|
|
35838
|
+
] }),
|
|
35839
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { backgroundColor: badge.color, color: "#111827", bold: true, children: ` ${badge.letter} ` }),
|
|
35840
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
|
|
35841
|
+
linked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Transform, { transform: (out) => osc8(out, ad.link), children: copy }) : copy,
|
|
35842
|
+
showUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.accent2, children: [
|
|
35843
|
+
" \xB7 ",
|
|
35844
|
+
ad.shownUrl
|
|
35845
|
+
] }) : null,
|
|
35846
|
+
ad.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
35847
|
+
" \xB7 ctrl+o ",
|
|
35848
|
+
ad.ctaText
|
|
35849
|
+
] }) : null
|
|
35850
|
+
] }),
|
|
35851
|
+
billed && ad.earn > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
|
|
35852
|
+
" +$",
|
|
35853
|
+
ad.earn.toFixed(4)
|
|
35854
|
+
] }) : null
|
|
35855
|
+
] });
|
|
35856
|
+
}
|
|
35857
|
+
|
|
35858
|
+
// src/ui/components.tsx
|
|
35859
|
+
var import_react22 = __toESM(require_react(), 1);
|
|
35860
|
+
|
|
35861
|
+
// src/ui/editor.ts
|
|
35862
|
+
var emptyEditor = (history = []) => ({
|
|
35863
|
+
text: "",
|
|
35864
|
+
cursor: 0,
|
|
35865
|
+
history,
|
|
35866
|
+
historyIndex: null,
|
|
35502
35867
|
draft: ""
|
|
35503
35868
|
});
|
|
35504
35869
|
function sanitizeInput(s2) {
|
|
@@ -35706,7 +36071,7 @@ function parseDiff(patch, max = 14) {
|
|
|
35706
36071
|
}
|
|
35707
36072
|
|
|
35708
36073
|
// src/ui/components.tsx
|
|
35709
|
-
var
|
|
36074
|
+
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
35710
36075
|
function useTermSize() {
|
|
35711
36076
|
const { stdout } = use_stdout_default();
|
|
35712
36077
|
const read = () => ({ cols: stdout.columns || 80, rows: stdout.rows || 24 });
|
|
@@ -35726,21 +36091,21 @@ function Spinner({ color = C.accent }) {
|
|
|
35726
36091
|
const t = setInterval(() => setI((n) => (n + 1) % SPINNER.length), 90);
|
|
35727
36092
|
return () => clearInterval(t);
|
|
35728
36093
|
}, []);
|
|
35729
|
-
return /* @__PURE__ */ (0,
|
|
36094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color, children: SPINNER[i] });
|
|
35730
36095
|
}
|
|
35731
36096
|
function Logo({ version }) {
|
|
35732
|
-
return /* @__PURE__ */ (0,
|
|
35733
|
-
/* @__PURE__ */ (0,
|
|
35734
|
-
/* @__PURE__ */ (0,
|
|
35735
|
-
/* @__PURE__ */ (0,
|
|
35736
|
-
row2 === 1 && version ? /* @__PURE__ */ (0,
|
|
36097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box_default, { flexDirection: "column", children: [0, 1].map((row2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36098
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.accent, children: LOGO.latent[row2] }),
|
|
36099
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
36100
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.accent2, children: LOGO.code[row2] }),
|
|
36101
|
+
row2 === 1 && version ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35737
36102
|
" v",
|
|
35738
36103
|
version
|
|
35739
36104
|
] }) : null
|
|
35740
36105
|
] }, row2)) });
|
|
35741
36106
|
}
|
|
35742
36107
|
function Panel(props) {
|
|
35743
|
-
return /* @__PURE__ */ (0,
|
|
36108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
35744
36109
|
Box_default,
|
|
35745
36110
|
{
|
|
35746
36111
|
flexDirection: "column",
|
|
@@ -35750,21 +36115,21 @@ function Panel(props) {
|
|
|
35750
36115
|
width: props.width,
|
|
35751
36116
|
marginTop: 1,
|
|
35752
36117
|
children: [
|
|
35753
|
-
/* @__PURE__ */ (0,
|
|
35754
|
-
/* @__PURE__ */ (0,
|
|
35755
|
-
props.right ? /* @__PURE__ */ (0,
|
|
36118
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36119
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { bold: true, color: props.color ?? C.accent, children: props.title }),
|
|
36120
|
+
props.right ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: props.right }) : null
|
|
35756
36121
|
] }),
|
|
35757
36122
|
props.children,
|
|
35758
|
-
props.footer ? /* @__PURE__ */ (0,
|
|
36123
|
+
props.footer ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box_default, { marginTop: 1, children: props.footer }) : null
|
|
35759
36124
|
]
|
|
35760
36125
|
}
|
|
35761
36126
|
);
|
|
35762
36127
|
}
|
|
35763
36128
|
function Hints({ items }) {
|
|
35764
|
-
return /* @__PURE__ */ (0,
|
|
35765
|
-
i ? /* @__PURE__ */ (0,
|
|
35766
|
-
/* @__PURE__ */ (0,
|
|
35767
|
-
/* @__PURE__ */ (0,
|
|
36129
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { wrap: "truncate-end", children: items.map(([k, label2], i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36130
|
+
i ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: " \xB7 " }) : null,
|
|
36131
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.muted, children: k }),
|
|
36132
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35768
36133
|
" ",
|
|
35769
36134
|
label2
|
|
35770
36135
|
] })
|
|
@@ -35782,16 +36147,16 @@ function usePaste(handler, active = true) {
|
|
|
35782
36147
|
}
|
|
35783
36148
|
function FieldText({ state, mask, placeholder }) {
|
|
35784
36149
|
if (!state.text && placeholder) {
|
|
35785
|
-
return /* @__PURE__ */ (0,
|
|
35786
|
-
/* @__PURE__ */ (0,
|
|
35787
|
-
/* @__PURE__ */ (0,
|
|
36150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36151
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { inverse: true, children: " " }),
|
|
36152
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: placeholder })
|
|
35788
36153
|
] });
|
|
35789
36154
|
}
|
|
35790
36155
|
const shown = mask ? { ...state, text: "\u2022".repeat(state.text.length) } : state;
|
|
35791
36156
|
const { before, at, after } = splitAtCursor(shown);
|
|
35792
|
-
return /* @__PURE__ */ (0,
|
|
36157
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
35793
36158
|
before,
|
|
35794
|
-
/* @__PURE__ */ (0,
|
|
36159
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { inverse: true, children: at }),
|
|
35795
36160
|
after
|
|
35796
36161
|
] });
|
|
35797
36162
|
}
|
|
@@ -35817,64 +36182,64 @@ function useLineField(opts) {
|
|
|
35817
36182
|
return { state, text: state.text, set: (t) => update(setText(ref.current, t)) };
|
|
35818
36183
|
}
|
|
35819
36184
|
function Spans({ spans }) {
|
|
35820
|
-
return /* @__PURE__ */ (0,
|
|
36185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: spans.map((s2, i) => {
|
|
35821
36186
|
switch (s2.t) {
|
|
35822
36187
|
case "bold":
|
|
35823
|
-
return /* @__PURE__ */ (0,
|
|
36188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { bold: true, children: s2.v }, i);
|
|
35824
36189
|
case "italic":
|
|
35825
|
-
return /* @__PURE__ */ (0,
|
|
36190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { italic: true, children: s2.v }, i);
|
|
35826
36191
|
case "code":
|
|
35827
|
-
return /* @__PURE__ */ (0,
|
|
36192
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.code, children: s2.v }, i);
|
|
35828
36193
|
case "link":
|
|
35829
|
-
return /* @__PURE__ */ (0,
|
|
35830
|
-
/* @__PURE__ */ (0,
|
|
35831
|
-
s2.url !== s2.v ? /* @__PURE__ */ (0,
|
|
36194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36195
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { underline: true, children: s2.v }),
|
|
36196
|
+
s2.url !== s2.v ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35832
36197
|
" (",
|
|
35833
36198
|
s2.url,
|
|
35834
36199
|
")"
|
|
35835
36200
|
] }) : null
|
|
35836
36201
|
] }, i);
|
|
35837
36202
|
default:
|
|
35838
|
-
return /* @__PURE__ */ (0,
|
|
36203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: s2.v }, i);
|
|
35839
36204
|
}
|
|
35840
36205
|
}) });
|
|
35841
36206
|
}
|
|
35842
36207
|
function BlockView({ b }) {
|
|
35843
36208
|
switch (b.t) {
|
|
35844
36209
|
case "h":
|
|
35845
|
-
return /* @__PURE__ */ (0,
|
|
36210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { bold: true, color: b.level <= 2 ? C.accent : void 0, underline: b.level === 1, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) });
|
|
35846
36211
|
case "li":
|
|
35847
|
-
return /* @__PURE__ */ (0,
|
|
35848
|
-
/* @__PURE__ */ (0,
|
|
36212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { marginLeft: b.indent * 2, children: [
|
|
36213
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.accent, children: [
|
|
35849
36214
|
b.marker,
|
|
35850
36215
|
" "
|
|
35851
36216
|
] }),
|
|
35852
|
-
/* @__PURE__ */ (0,
|
|
36217
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) })
|
|
35853
36218
|
] });
|
|
35854
36219
|
case "quote":
|
|
35855
|
-
return /* @__PURE__ */ (0,
|
|
35856
|
-
/* @__PURE__ */ (0,
|
|
36220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { children: [
|
|
36221
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35857
36222
|
G.thin,
|
|
35858
36223
|
" "
|
|
35859
36224
|
] }),
|
|
35860
|
-
/* @__PURE__ */ (0,
|
|
36225
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.muted, italic: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) })
|
|
35861
36226
|
] });
|
|
35862
36227
|
case "code":
|
|
35863
|
-
return /* @__PURE__ */ (0,
|
|
35864
|
-
b.lang ? /* @__PURE__ */ (0,
|
|
35865
|
-
/* @__PURE__ */ (0,
|
|
36228
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { flexDirection: "column", borderStyle: "single", borderColor: C.border, borderTop: false, borderRight: false, borderBottom: false, paddingLeft: 1, children: [
|
|
36229
|
+
b.lang ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: b.lang }) : null,
|
|
36230
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.code, children: b.lines.join("\n") || " " })
|
|
35866
36231
|
] });
|
|
35867
36232
|
case "rule":
|
|
35868
|
-
return /* @__PURE__ */ (0,
|
|
36233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" });
|
|
35869
36234
|
case "gap":
|
|
35870
|
-
return /* @__PURE__ */ (0,
|
|
36235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " });
|
|
35871
36236
|
default:
|
|
35872
|
-
return /* @__PURE__ */ (0,
|
|
36237
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) });
|
|
35873
36238
|
}
|
|
35874
36239
|
}
|
|
35875
36240
|
function Markdown({ text }) {
|
|
35876
36241
|
const blocks = parseMarkdown(text);
|
|
35877
|
-
return /* @__PURE__ */ (0,
|
|
36242
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box_default, { flexDirection: "column", children: blocks.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BlockView, { b }, i)) });
|
|
35878
36243
|
}
|
|
35879
36244
|
function windowAround(total, selected, size) {
|
|
35880
36245
|
if (total <= size) return { start: 0, end: total };
|
|
@@ -35895,7 +36260,9 @@ var COMMANDS = [
|
|
|
35895
36260
|
{ name: "providers", desc: "Connected providers and what each one offers", group: "Models" },
|
|
35896
36261
|
{ name: "connect", args: "[provider]", desc: "Connect a provider: API key or account sign-in", group: "Models" },
|
|
35897
36262
|
{ name: "login", desc: "Connect the wallet Earn mode pays into", group: "Earn", aliases: ["wallet"] },
|
|
35898
|
-
{ name: "earn", desc: "Earnings: this session and your
|
|
36263
|
+
{ name: "earn", desc: "Earnings: this session and your Latent Credit", group: "Earn" },
|
|
36264
|
+
{ name: "credits", desc: "Latent Credit: balance, bonus, mode, sell price", group: "Earn", aliases: ["credit"] },
|
|
36265
|
+
{ name: "key", args: "lk_\u2026", desc: "Use your Latent Key as a provider \u2014 earnings become model usage", group: "Earn" },
|
|
35899
36266
|
{ name: "ads", args: "on|off", desc: "Turn Earn mode (the sponsored line) on or off", group: "Earn" },
|
|
35900
36267
|
{ name: "new", desc: "Start a fresh session", group: "Session" },
|
|
35901
36268
|
{ name: "compact", desc: "Summarise the conversation to free up context", group: "Session" },
|
|
@@ -35920,7 +36287,7 @@ function parseCommandLine(line) {
|
|
|
35920
36287
|
}
|
|
35921
36288
|
|
|
35922
36289
|
// src/ui/Transcript.tsx
|
|
35923
|
-
var
|
|
36290
|
+
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
|
35924
36291
|
function lastLines(text, n) {
|
|
35925
36292
|
const lines = text.trimEnd().split("\n");
|
|
35926
36293
|
return lines.length <= n ? lines.join("\n") : lines.slice(-n).join("\n");
|
|
@@ -35975,55 +36342,55 @@ function ToolView({ item, cwd: cwd2, width }) {
|
|
|
35975
36342
|
const diff2 = item.diff ? parseDiff(item.diff) : null;
|
|
35976
36343
|
const showOutput = item.output && (failed || !QUIET.has(item.name)) && !diff2;
|
|
35977
36344
|
const out = showOutput ? firstLines(item.output, failed ? 8 : 6) : null;
|
|
35978
|
-
return /* @__PURE__ */ (0,
|
|
35979
|
-
/* @__PURE__ */ (0,
|
|
35980
|
-
running ? /* @__PURE__ */ (0,
|
|
35981
|
-
/* @__PURE__ */ (0,
|
|
36345
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", width, children: [
|
|
36346
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36347
|
+
running ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Spinner, { color: C.warn }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: failed ? C.err : C.ok, children: G.dot }),
|
|
36348
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { bold: true, color: t.verb === "$" ? C.accent2 : void 0, children: [
|
|
35982
36349
|
" ",
|
|
35983
36350
|
t.verb
|
|
35984
36351
|
] }),
|
|
35985
|
-
/* @__PURE__ */ (0,
|
|
36352
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
35986
36353
|
" ",
|
|
35987
36354
|
clip(t.target, Math.max(20, width - t.verb.length - 24))
|
|
35988
36355
|
] }),
|
|
35989
|
-
t.extra ? /* @__PURE__ */ (0,
|
|
36356
|
+
t.extra ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35990
36357
|
" ",
|
|
35991
36358
|
t.extra
|
|
35992
36359
|
] }) : null,
|
|
35993
|
-
item.additions || item.deletions ? /* @__PURE__ */ (0,
|
|
35994
|
-
/* @__PURE__ */ (0,
|
|
36360
|
+
item.additions || item.deletions ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
36361
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.add, children: [
|
|
35995
36362
|
" +",
|
|
35996
36363
|
item.additions ?? 0
|
|
35997
36364
|
] }),
|
|
35998
|
-
/* @__PURE__ */ (0,
|
|
36365
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.del, children: [
|
|
35999
36366
|
" \u2212",
|
|
36000
36367
|
item.deletions ?? 0
|
|
36001
36368
|
] })
|
|
36002
36369
|
] }) : null,
|
|
36003
|
-
item.ms !== void 0 && item.ms >= 1e3 ? /* @__PURE__ */ (0,
|
|
36370
|
+
item.ms !== void 0 && item.ms >= 1e3 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36004
36371
|
" \xB7 ",
|
|
36005
36372
|
fmtDuration(item.ms)
|
|
36006
36373
|
] }) : null
|
|
36007
36374
|
] }),
|
|
36008
|
-
diff2 && diff2.lines.length ? /* @__PURE__ */ (0,
|
|
36009
|
-
diff2.lines.map((l, i) => /* @__PURE__ */ (0,
|
|
36375
|
+
diff2 && diff2.lines.length ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", marginLeft: 2, children: [
|
|
36376
|
+
diff2.lines.map((l, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { wrap: "truncate-end", color: l.t === "add" ? C.add : l.t === "del" ? C.del : C.faint, children: [
|
|
36010
36377
|
l.t === "add" ? "+ " : l.t === "del" ? "\u2212 " : l.t === "hunk" ? "" : " ",
|
|
36011
36378
|
l.t === "hunk" ? "\u22EF" : l.text
|
|
36012
36379
|
] }, i)),
|
|
36013
|
-
diff2.more ? /* @__PURE__ */ (0,
|
|
36380
|
+
diff2.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36014
36381
|
"\u2026 ",
|
|
36015
36382
|
diff2.more,
|
|
36016
36383
|
" more lines"
|
|
36017
36384
|
] }) : null
|
|
36018
36385
|
] }) : null,
|
|
36019
|
-
out ? /* @__PURE__ */ (0,
|
|
36020
|
-
/* @__PURE__ */ (0,
|
|
36386
|
+
out ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginLeft: 2, children: [
|
|
36387
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36021
36388
|
G.elbow,
|
|
36022
36389
|
" "
|
|
36023
36390
|
] }) }),
|
|
36024
|
-
/* @__PURE__ */ (0,
|
|
36025
|
-
/* @__PURE__ */ (0,
|
|
36026
|
-
out.more ? /* @__PURE__ */ (0,
|
|
36391
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
36392
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: failed ? C.err : C.muted, children: out.text }),
|
|
36393
|
+
out.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36027
36394
|
"\u2026 ",
|
|
36028
36395
|
out.more,
|
|
36029
36396
|
" more lines"
|
|
@@ -36037,25 +36404,25 @@ var NOTICE_MARK = { info: G.bullet, ok: G.ok, warn: G.warn, error: G.no };
|
|
|
36037
36404
|
function ItemView({ item, live, cwd: cwd2, width, maxLines }) {
|
|
36038
36405
|
switch (item.kind) {
|
|
36039
36406
|
case "user":
|
|
36040
|
-
return /* @__PURE__ */ (0,
|
|
36041
|
-
/* @__PURE__ */ (0,
|
|
36407
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
36408
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.accent, bold: true, children: [
|
|
36042
36409
|
G.prompt,
|
|
36043
36410
|
" "
|
|
36044
36411
|
] }) }),
|
|
36045
|
-
/* @__PURE__ */ (0,
|
|
36412
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { bold: true, children: item.text })
|
|
36046
36413
|
] });
|
|
36047
36414
|
case "reasoning": {
|
|
36048
36415
|
const text = item.text.trim();
|
|
36049
36416
|
if (!text) return null;
|
|
36050
36417
|
const shown = live ? lastLines(text, 4) : firstLines(text, 2);
|
|
36051
|
-
return /* @__PURE__ */ (0,
|
|
36052
|
-
/* @__PURE__ */ (0,
|
|
36418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
36419
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36053
36420
|
G.thin,
|
|
36054
36421
|
" "
|
|
36055
36422
|
] }) }),
|
|
36056
|
-
/* @__PURE__ */ (0,
|
|
36057
|
-
/* @__PURE__ */ (0,
|
|
36058
|
-
typeof shown !== "string" && shown.more ? /* @__PURE__ */ (0,
|
|
36423
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
36424
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.faint, italic: true, children: typeof shown === "string" ? shown : shown.text }),
|
|
36425
|
+
typeof shown !== "string" && shown.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36059
36426
|
"\u2026 thought for ",
|
|
36060
36427
|
shown.more,
|
|
36061
36428
|
" more lines"
|
|
@@ -36064,25 +36431,25 @@ function ItemView({ item, live, cwd: cwd2, width, maxLines }) {
|
|
|
36064
36431
|
] });
|
|
36065
36432
|
}
|
|
36066
36433
|
case "text":
|
|
36067
|
-
return /* @__PURE__ */ (0,
|
|
36434
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { marginTop: 1, width, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Markdown, { text: live ? lastLines(item.text, maxLines) : item.text }) });
|
|
36068
36435
|
case "tool":
|
|
36069
|
-
return /* @__PURE__ */ (0,
|
|
36436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolView, { item, cwd: cwd2, width });
|
|
36070
36437
|
case "error":
|
|
36071
|
-
return /* @__PURE__ */ (0,
|
|
36072
|
-
/* @__PURE__ */ (0,
|
|
36438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
36439
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.err, children: [
|
|
36073
36440
|
G.no,
|
|
36074
36441
|
" "
|
|
36075
36442
|
] }) }),
|
|
36076
|
-
/* @__PURE__ */ (0,
|
|
36443
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.err, wrap: "wrap", children: item.text })
|
|
36077
36444
|
] });
|
|
36078
36445
|
case "notice": {
|
|
36079
36446
|
const tone = item.tone ?? "info";
|
|
36080
|
-
return /* @__PURE__ */ (0,
|
|
36081
|
-
/* @__PURE__ */ (0,
|
|
36447
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
36448
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: NOTICE_COLOR[tone], children: [
|
|
36082
36449
|
NOTICE_MARK[tone],
|
|
36083
36450
|
" "
|
|
36084
36451
|
] }) }),
|
|
36085
|
-
/* @__PURE__ */ (0,
|
|
36452
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: tone === "info" ? C.muted : NOTICE_COLOR[tone], wrap: "wrap", children: item.text })
|
|
36086
36453
|
] });
|
|
36087
36454
|
}
|
|
36088
36455
|
}
|
|
@@ -36096,19 +36463,19 @@ function PermissionPrompt({ perm, selected, cwd: cwd2, width }) {
|
|
|
36096
36463
|
const options = ["Allow once", "Always allow", "Reject"];
|
|
36097
36464
|
const keys = ["y", "a", "n"];
|
|
36098
36465
|
const what = perm.resources.map((r) => relPath(r, cwd2)).join(", ") || perm.message || "";
|
|
36099
|
-
return /* @__PURE__ */ (0,
|
|
36100
|
-
/* @__PURE__ */ (0,
|
|
36101
|
-
/* @__PURE__ */ (0,
|
|
36102
|
-
/* @__PURE__ */ (0,
|
|
36466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, borderStyle: "round", borderColor: C.warn, paddingX: 1, flexDirection: "column", width, children: [
|
|
36467
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36468
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { bold: true, color: C.warn, children: PERMISSION_TITLE[perm.action] ?? `Allow ${perm.action}?` }),
|
|
36469
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.faint, children: perm.action })
|
|
36103
36470
|
] }),
|
|
36104
|
-
/* @__PURE__ */ (0,
|
|
36471
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { marginY: 1, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: perm.action === "shell" ? C.accent2 : void 0, wrap: "wrap", children: [
|
|
36105
36472
|
perm.action === "shell" ? "$ " : "",
|
|
36106
36473
|
clip(what, 600)
|
|
36107
36474
|
] }) }),
|
|
36108
|
-
/* @__PURE__ */ (0,
|
|
36475
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
36109
36476
|
i ? " " : "",
|
|
36110
|
-
/* @__PURE__ */ (0,
|
|
36111
|
-
/* @__PURE__ */ (0,
|
|
36477
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: i === selected ? i === 2 ? C.err : C.ok : C.muted, bold: i === selected, inverse: i === selected, children: ` ${o} ` }),
|
|
36478
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36112
36479
|
" ",
|
|
36113
36480
|
keys[i]
|
|
36114
36481
|
] })
|
|
@@ -36118,22 +36485,22 @@ function PermissionPrompt({ perm, selected, cwd: cwd2, width }) {
|
|
|
36118
36485
|
|
|
36119
36486
|
// src/ui/panels/ModelPicker.tsx
|
|
36120
36487
|
var import_react23 = __toESM(require_react(), 1);
|
|
36121
|
-
var
|
|
36488
|
+
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
36122
36489
|
function Mark({ status: status2, testing }) {
|
|
36123
|
-
if (testing) return /* @__PURE__ */ (0,
|
|
36490
|
+
if (testing) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Spinner, {});
|
|
36124
36491
|
switch (status2) {
|
|
36125
36492
|
case "ok":
|
|
36126
|
-
return /* @__PURE__ */ (0,
|
|
36493
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.ok, children: G.ok });
|
|
36127
36494
|
case "unsupported":
|
|
36128
|
-
return /* @__PURE__ */ (0,
|
|
36495
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, children: G.no });
|
|
36129
36496
|
case "rate-limited":
|
|
36130
|
-
return /* @__PURE__ */ (0,
|
|
36497
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.warn, children: G.wait });
|
|
36131
36498
|
case "auth":
|
|
36132
|
-
return /* @__PURE__ */ (0,
|
|
36499
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.warn, children: G.key });
|
|
36133
36500
|
case "error":
|
|
36134
|
-
return /* @__PURE__ */ (0,
|
|
36501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, children: G.warn });
|
|
36135
36502
|
default:
|
|
36136
|
-
return /* @__PURE__ */ (0,
|
|
36503
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "\xB7" });
|
|
36137
36504
|
}
|
|
36138
36505
|
}
|
|
36139
36506
|
function ModelPicker(p) {
|
|
@@ -36222,14 +36589,14 @@ function ModelPicker(p) {
|
|
|
36222
36589
|
const wId = Math.max(0, rest - wName);
|
|
36223
36590
|
const kindOf = (id) => p.catalog.providers.find((x) => x.id === id)?.kind ?? "unknown";
|
|
36224
36591
|
const verified = p.catalog.models.filter((m) => p.status(m.key) === "ok").length;
|
|
36225
|
-
return /* @__PURE__ */ (0,
|
|
36592
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
36226
36593
|
Panel,
|
|
36227
36594
|
{
|
|
36228
36595
|
title: "Models",
|
|
36229
36596
|
right: `${p.catalog.models.length} models \xB7 ${verified} verified with your account`,
|
|
36230
36597
|
width: p.width,
|
|
36231
36598
|
color: C.accent,
|
|
36232
|
-
footer: /* @__PURE__ */ (0,
|
|
36599
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
36233
36600
|
Hints,
|
|
36234
36601
|
{
|
|
36235
36602
|
items: [
|
|
@@ -36243,36 +36610,36 @@ function ModelPicker(p) {
|
|
|
36243
36610
|
}
|
|
36244
36611
|
),
|
|
36245
36612
|
children: [
|
|
36246
|
-
/* @__PURE__ */ (0,
|
|
36247
|
-
/* @__PURE__ */ (0,
|
|
36613
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { marginTop: 1, children: [
|
|
36614
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
36248
36615
|
G.search,
|
|
36249
36616
|
" "
|
|
36250
36617
|
] }),
|
|
36251
|
-
/* @__PURE__ */ (0,
|
|
36618
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldText, { state: field.state, placeholder: "type to search \u2014 name, id or provider" })
|
|
36252
36619
|
] }),
|
|
36253
|
-
/* @__PURE__ */ (0,
|
|
36620
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, flexWrap: "wrap", children: tabs.map((id, i) => {
|
|
36254
36621
|
const prov = p.catalog.providers.find((x) => x.id === id);
|
|
36255
36622
|
const text = prov ? `${prov.name} ${prov.models}` : `All ${p.catalog.models.length}`;
|
|
36256
|
-
return /* @__PURE__ */ (0,
|
|
36623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginRight: 2, children: i === tab2 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, color: C.accent, underline: true, children: text }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.muted, children: text }) }, id ?? "all");
|
|
36257
36624
|
}) }),
|
|
36258
|
-
/* @__PURE__ */ (0,
|
|
36259
|
-
above ? /* @__PURE__ */ (0,
|
|
36625
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
36626
|
+
above ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36260
36627
|
" ",
|
|
36261
36628
|
G.up,
|
|
36262
36629
|
" ",
|
|
36263
36630
|
above,
|
|
36264
36631
|
" more"
|
|
36265
36632
|
] }) : null,
|
|
36266
|
-
shown.length === 0 ? /* @__PURE__ */ (0,
|
|
36633
|
+
shown.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.muted, children: [
|
|
36267
36634
|
" No model matches \u201C",
|
|
36268
36635
|
field.text,
|
|
36269
36636
|
"\u201D."
|
|
36270
36637
|
] }) : null,
|
|
36271
36638
|
shown.map((r, i) => {
|
|
36272
36639
|
if (r.t === "head") {
|
|
36273
|
-
return /* @__PURE__ */ (0,
|
|
36274
|
-
/* @__PURE__ */ (0,
|
|
36275
|
-
/* @__PURE__ */ (0,
|
|
36640
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36641
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, color: C.muted, children: r.label }),
|
|
36642
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36276
36643
|
" ",
|
|
36277
36644
|
r.hint
|
|
36278
36645
|
] })
|
|
@@ -36283,33 +36650,33 @@ function ModelPicker(p) {
|
|
|
36283
36650
|
const st = p.status(m.key);
|
|
36284
36651
|
const dead = st === "unsupported";
|
|
36285
36652
|
const note = m.key === p.current ? "current" : st === "unsupported" ? "not on your plan" : st !== "unknown" && st !== "ok" ? label(st) : "";
|
|
36286
|
-
return /* @__PURE__ */ (0,
|
|
36287
|
-
/* @__PURE__ */ (0,
|
|
36653
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36654
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
36288
36655
|
on2 ? G.prompt : " ",
|
|
36289
36656
|
" "
|
|
36290
36657
|
] }),
|
|
36291
|
-
/* @__PURE__ */ (0,
|
|
36292
|
-
/* @__PURE__ */ (0,
|
|
36293
|
-
/* @__PURE__ */ (0,
|
|
36294
|
-
/* @__PURE__ */ (0,
|
|
36658
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Mark, { status: st, testing: testing.has(m.key) }),
|
|
36659
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { children: " " }),
|
|
36660
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: on2, color: dead ? C.faint : on2 ? C.text : void 0, children: pad(m.name, wName) }),
|
|
36661
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36295
36662
|
" ",
|
|
36296
36663
|
pad(field.text || !provider ? m.key : m.id, wId)
|
|
36297
36664
|
] }),
|
|
36298
|
-
/* @__PURE__ */ (0,
|
|
36665
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.muted, children: [
|
|
36299
36666
|
" ",
|
|
36300
36667
|
padStart(fmtContext(m.context), wCtx)
|
|
36301
36668
|
] }),
|
|
36302
|
-
/* @__PURE__ */ (0,
|
|
36669
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: m.costIn === 0 && m.costOut === 0 ? C.ok : C.muted, children: [
|
|
36303
36670
|
" ",
|
|
36304
36671
|
padStart(fmtPrice(m, kindOf(m.providerID)), wPrice)
|
|
36305
36672
|
] }),
|
|
36306
|
-
note ? /* @__PURE__ */ (0,
|
|
36673
|
+
note ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: m.key === p.current ? C.accent2 : dead ? C.faint : C.warn, children: [
|
|
36307
36674
|
" ",
|
|
36308
36675
|
note
|
|
36309
36676
|
] }) : null
|
|
36310
36677
|
] }, m.key);
|
|
36311
36678
|
}),
|
|
36312
|
-
below ? /* @__PURE__ */ (0,
|
|
36679
|
+
below ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36313
36680
|
" ",
|
|
36314
36681
|
G.down,
|
|
36315
36682
|
" ",
|
|
@@ -36317,13 +36684,13 @@ function ModelPicker(p) {
|
|
|
36317
36684
|
" more"
|
|
36318
36685
|
] }) : null
|
|
36319
36686
|
] }),
|
|
36320
|
-
chosen ? /* @__PURE__ */ (0,
|
|
36321
|
-
/* @__PURE__ */ (0,
|
|
36322
|
-
efforts.length > 1 ? efforts.map((e, i) => /* @__PURE__ */ (0,
|
|
36687
|
+
chosen ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36688
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "effort " }),
|
|
36689
|
+
efforts.length > 1 ? efforts.map((e, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: i === effortAt ? C.accent2 : C.faint, bold: i === effortAt, children: [
|
|
36323
36690
|
i === effortAt ? `\u2039 ${e} \u203A` : e,
|
|
36324
36691
|
i < efforts.length - 1 ? " " : ""
|
|
36325
|
-
] }, e)) : /* @__PURE__ */ (0,
|
|
36326
|
-
/* @__PURE__ */ (0,
|
|
36692
|
+
] }, e)) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "fixed for this model" }),
|
|
36693
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: " ctx \xB7 $ in/out per 1M tokens" })
|
|
36327
36694
|
] }) }) : null
|
|
36328
36695
|
]
|
|
36329
36696
|
}
|
|
@@ -36332,155 +36699,7 @@ function ModelPicker(p) {
|
|
|
36332
36699
|
|
|
36333
36700
|
// src/ui/panels/ProviderPanel.tsx
|
|
36334
36701
|
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
|
|
36483
|
-
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
36702
|
+
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
|
|
36484
36703
|
var usable = (i) => i.methods.filter((m) => m.type === "key" || m.type === "oauth");
|
|
36485
36704
|
var needsForm = (m) => "form" in m && Array.isArray(m.form) && m.form.some((f) => !f.hidden && f.required);
|
|
36486
36705
|
var methodLabel = (m) => m.type === "key" ? m.label || "API key" : m.label;
|
|
@@ -36527,7 +36746,7 @@ function ProviderPanel(p) {
|
|
|
36527
36746
|
const common = { width: p.width, color: C.accent };
|
|
36528
36747
|
switch (view.v) {
|
|
36529
36748
|
case "list":
|
|
36530
|
-
return /* @__PURE__ */ (0,
|
|
36749
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36531
36750
|
ProviderList,
|
|
36532
36751
|
{
|
|
36533
36752
|
...p,
|
|
@@ -36536,7 +36755,7 @@ function ProviderPanel(p) {
|
|
|
36536
36755
|
}
|
|
36537
36756
|
);
|
|
36538
36757
|
case "pick":
|
|
36539
|
-
return /* @__PURE__ */ (0,
|
|
36758
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36540
36759
|
IntegrationPicker,
|
|
36541
36760
|
{
|
|
36542
36761
|
...common,
|
|
@@ -36551,7 +36770,7 @@ function ProviderPanel(p) {
|
|
|
36551
36770
|
}
|
|
36552
36771
|
);
|
|
36553
36772
|
case "custom":
|
|
36554
|
-
return /* @__PURE__ */ (0,
|
|
36773
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36555
36774
|
CustomProviderForm,
|
|
36556
36775
|
{
|
|
36557
36776
|
...common,
|
|
@@ -36562,7 +36781,7 @@ function ProviderPanel(p) {
|
|
|
36562
36781
|
}
|
|
36563
36782
|
);
|
|
36564
36783
|
case "method":
|
|
36565
|
-
return /* @__PURE__ */ (0,
|
|
36784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36566
36785
|
MethodPicker,
|
|
36567
36786
|
{
|
|
36568
36787
|
...common,
|
|
@@ -36573,7 +36792,7 @@ function ProviderPanel(p) {
|
|
|
36573
36792
|
}
|
|
36574
36793
|
);
|
|
36575
36794
|
case "key":
|
|
36576
|
-
return /* @__PURE__ */ (0,
|
|
36795
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36577
36796
|
KeyEntry,
|
|
36578
36797
|
{
|
|
36579
36798
|
...common,
|
|
@@ -36584,7 +36803,7 @@ function ProviderPanel(p) {
|
|
|
36584
36803
|
}
|
|
36585
36804
|
);
|
|
36586
36805
|
case "oauth":
|
|
36587
|
-
return /* @__PURE__ */ (0,
|
|
36806
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36588
36807
|
OAuthFlow,
|
|
36589
36808
|
{
|
|
36590
36809
|
...common,
|
|
@@ -36596,7 +36815,7 @@ function ProviderPanel(p) {
|
|
|
36596
36815
|
}
|
|
36597
36816
|
);
|
|
36598
36817
|
case "done":
|
|
36599
|
-
return /* @__PURE__ */ (0,
|
|
36818
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Done, { ...common, name: view.name, models: view.models, note: view.note, onClose: p.onClose, onModels: () => p.onBrowse("") });
|
|
36600
36819
|
}
|
|
36601
36820
|
}
|
|
36602
36821
|
function ProviderList(p) {
|
|
@@ -36617,39 +36836,39 @@ function ProviderList(p) {
|
|
|
36617
36836
|
const inner = p.width - 4;
|
|
36618
36837
|
const wName = Math.min(24, Math.max(12, ...items.map((x) => x.name.length)) + 1);
|
|
36619
36838
|
const wVia = Math.min(26, Math.max(10, ...items.map((x) => x.via.length)) + 1);
|
|
36620
|
-
return /* @__PURE__ */ (0,
|
|
36839
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36621
36840
|
Panel,
|
|
36622
36841
|
{
|
|
36623
36842
|
title: "Providers",
|
|
36624
36843
|
right: `${items.length} connected \xB7 ${p.catalog.models.length} models`,
|
|
36625
36844
|
width: p.width,
|
|
36626
36845
|
color: C.accent,
|
|
36627
|
-
footer: /* @__PURE__ */ (0,
|
|
36846
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "browse models"], ["c", "connect a provider"], ["esc", "close"]] }),
|
|
36628
36847
|
children: [
|
|
36629
|
-
/* @__PURE__ */ (0,
|
|
36848
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
36630
36849
|
items.map((prov, i) => {
|
|
36631
36850
|
const ok = p.catalog.models.filter((m) => m.providerID === prov.id && p.status(m.key) === "ok").length;
|
|
36632
36851
|
const dot = prov.kind === "builtin" ? C.faint : C.ok;
|
|
36633
|
-
return /* @__PURE__ */ (0,
|
|
36634
|
-
/* @__PURE__ */ (0,
|
|
36852
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36853
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36635
36854
|
i === sel ? G.prompt : " ",
|
|
36636
36855
|
" "
|
|
36637
36856
|
] }),
|
|
36638
|
-
/* @__PURE__ */ (0,
|
|
36857
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: dot, children: [
|
|
36639
36858
|
G.dot,
|
|
36640
36859
|
" "
|
|
36641
36860
|
] }),
|
|
36642
|
-
/* @__PURE__ */ (0,
|
|
36643
|
-
/* @__PURE__ */ (0,
|
|
36861
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: i === sel, children: pad(prov.name, wName) }),
|
|
36862
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36644
36863
|
" ",
|
|
36645
36864
|
pad(prov.via, wVia)
|
|
36646
36865
|
] }),
|
|
36647
|
-
/* @__PURE__ */ (0,
|
|
36866
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36648
36867
|
" ",
|
|
36649
36868
|
String(prov.models).padStart(3),
|
|
36650
36869
|
" models"
|
|
36651
36870
|
] }),
|
|
36652
|
-
ok ? /* @__PURE__ */ (0,
|
|
36871
|
+
ok ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
36653
36872
|
" ",
|
|
36654
36873
|
G.ok,
|
|
36655
36874
|
" ",
|
|
@@ -36658,16 +36877,16 @@ function ProviderList(p) {
|
|
|
36658
36877
|
] }) : null
|
|
36659
36878
|
] }, prov.id);
|
|
36660
36879
|
}),
|
|
36661
|
-
/* @__PURE__ */ (0,
|
|
36662
|
-
/* @__PURE__ */ (0,
|
|
36880
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
36881
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36663
36882
|
sel === items.length ? G.prompt : " ",
|
|
36664
36883
|
" "
|
|
36665
36884
|
] }),
|
|
36666
|
-
/* @__PURE__ */ (0,
|
|
36885
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, bold: sel === items.length, children: "+ Connect a provider\u2026" })
|
|
36667
36886
|
] })
|
|
36668
36887
|
] }),
|
|
36669
|
-
/* @__PURE__ */ (0,
|
|
36670
|
-
p.error ? /* @__PURE__ */ (0,
|
|
36888
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, wrap: "wrap", children: clipTo("Bring your own access: an API key, or a subscription where the provider allows third-party clients. Credentials stay in the local engine.", inner * 2) }) }),
|
|
36889
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36671
36890
|
]
|
|
36672
36891
|
}
|
|
36673
36892
|
);
|
|
@@ -36699,34 +36918,34 @@ function IntegrationPicker(p) {
|
|
|
36699
36918
|
const selected = Math.min(sel, list.length);
|
|
36700
36919
|
const visible = Math.max(5, Math.min(11, p.rows - 15));
|
|
36701
36920
|
const win = windowAround(list.length, Math.min(selected, Math.max(0, list.length - 1)), visible);
|
|
36702
|
-
return /* @__PURE__ */ (0,
|
|
36921
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36703
36922
|
Panel,
|
|
36704
36923
|
{
|
|
36705
36924
|
title: "Connect a provider",
|
|
36706
36925
|
right: p.integrations ? `${list.length} available` : "",
|
|
36707
36926
|
width: p.width,
|
|
36708
36927
|
color: p.color,
|
|
36709
|
-
footer: /* @__PURE__ */ (0,
|
|
36928
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "choose"], ["esc", field.text ? "clear" : "back"]] }),
|
|
36710
36929
|
children: [
|
|
36711
|
-
/* @__PURE__ */ (0,
|
|
36712
|
-
/* @__PURE__ */ (0,
|
|
36930
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
36931
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36713
36932
|
G.search,
|
|
36714
36933
|
" "
|
|
36715
36934
|
] }),
|
|
36716
|
-
/* @__PURE__ */ (0,
|
|
36935
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, placeholder: "search \u2014 Anthropic, OpenRouter, Google\u2026" })
|
|
36717
36936
|
] }),
|
|
36718
|
-
/* @__PURE__ */ (0,
|
|
36719
|
-
!p.integrations && !p.error ? /* @__PURE__ */ (0,
|
|
36720
|
-
/* @__PURE__ */ (0,
|
|
36937
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
36938
|
+
!p.integrations && !p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
36939
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36721
36940
|
" ",
|
|
36722
|
-
/* @__PURE__ */ (0,
|
|
36941
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Loading providers\u2026" })
|
|
36723
36942
|
] }) : null,
|
|
36724
|
-
p.integrations && !list.length ? /* @__PURE__ */ (0,
|
|
36943
|
+
p.integrations && !list.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36725
36944
|
" Nothing matches \u201C",
|
|
36726
36945
|
field.text,
|
|
36727
36946
|
"\u201D."
|
|
36728
36947
|
] }) : null,
|
|
36729
|
-
win.start > 0 ? /* @__PURE__ */ (0,
|
|
36948
|
+
win.start > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36730
36949
|
" ",
|
|
36731
36950
|
G.up,
|
|
36732
36951
|
" ",
|
|
@@ -36737,40 +36956,40 @@ function IntegrationPicker(p) {
|
|
|
36737
36956
|
const on2 = win.start + i === selected;
|
|
36738
36957
|
const labels = usable(it).map((m) => m.type === "key" ? "API key" : m.label);
|
|
36739
36958
|
const methods = labels.slice(0, 2).join(" \xB7 ") + (labels.length > 2 ? ` +${labels.length - 2}` : "");
|
|
36740
|
-
return /* @__PURE__ */ (0,
|
|
36741
|
-
/* @__PURE__ */ (0,
|
|
36959
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36960
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36742
36961
|
on2 ? G.prompt : " ",
|
|
36743
36962
|
" "
|
|
36744
36963
|
] }),
|
|
36745
|
-
/* @__PURE__ */ (0,
|
|
36746
|
-
/* @__PURE__ */ (0,
|
|
36964
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: on2, children: pad(it.name, 26) }),
|
|
36965
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36747
36966
|
" ",
|
|
36748
36967
|
methods
|
|
36749
36968
|
] }),
|
|
36750
|
-
p.connected.has(it.id) ? /* @__PURE__ */ (0,
|
|
36969
|
+
p.connected.has(it.id) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
36751
36970
|
" ",
|
|
36752
36971
|
G.ok,
|
|
36753
36972
|
" connected"
|
|
36754
36973
|
] }) : null
|
|
36755
36974
|
] }, it.id);
|
|
36756
36975
|
}),
|
|
36757
|
-
win.end < list.length ? /* @__PURE__ */ (0,
|
|
36976
|
+
win.end < list.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36758
36977
|
" ",
|
|
36759
36978
|
G.down,
|
|
36760
36979
|
" ",
|
|
36761
36980
|
list.length - win.end,
|
|
36762
36981
|
" more"
|
|
36763
36982
|
] }) : null,
|
|
36764
|
-
p.integrations ? /* @__PURE__ */ (0,
|
|
36765
|
-
/* @__PURE__ */ (0,
|
|
36983
|
+
p.integrations ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36984
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36766
36985
|
selected === list.length ? G.prompt : " ",
|
|
36767
36986
|
" "
|
|
36768
36987
|
] }),
|
|
36769
|
-
/* @__PURE__ */ (0,
|
|
36770
|
-
/* @__PURE__ */ (0,
|
|
36988
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, bold: selected === list.length, children: pad("+ Custom provider\u2026", 26) }),
|
|
36989
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: " any OpenAI- or Anthropic-compatible endpoint" })
|
|
36771
36990
|
] }) : null
|
|
36772
36991
|
] }),
|
|
36773
|
-
p.error ? /* @__PURE__ */ (0,
|
|
36992
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36774
36993
|
]
|
|
36775
36994
|
}
|
|
36776
36995
|
);
|
|
@@ -36786,31 +37005,31 @@ function MethodPicker(p) {
|
|
|
36786
37005
|
});
|
|
36787
37006
|
const wLabel = Math.min(40, Math.max(...methods.map((m) => methodLabel(m).length)) + 2);
|
|
36788
37007
|
const env3 = p.integration.methods.find((m) => m.type === "env");
|
|
36789
|
-
return /* @__PURE__ */ (0,
|
|
37008
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36790
37009
|
Panel,
|
|
36791
37010
|
{
|
|
36792
37011
|
title: `Connect ${p.integration.name}`,
|
|
36793
37012
|
width: p.width,
|
|
36794
37013
|
color: p.color,
|
|
36795
|
-
footer: /* @__PURE__ */ (0,
|
|
37014
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "continue"], ["esc", "back"]] }),
|
|
36796
37015
|
children: [
|
|
36797
|
-
/* @__PURE__ */ (0,
|
|
36798
|
-
/* @__PURE__ */ (0,
|
|
36799
|
-
methods.map((m, i) => /* @__PURE__ */ (0,
|
|
36800
|
-
/* @__PURE__ */ (0,
|
|
37016
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37017
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "How do you want to connect?" }),
|
|
37018
|
+
methods.map((m, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37019
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36801
37020
|
i === sel ? G.prompt : " ",
|
|
36802
37021
|
" "
|
|
36803
37022
|
] }),
|
|
36804
|
-
/* @__PURE__ */ (0,
|
|
36805
|
-
/* @__PURE__ */ (0,
|
|
37023
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: i === sel, children: pad(methodLabel(m), wLabel) }),
|
|
37024
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, children: m.type === "oauth" ? "opens your browser" : "paste a key" })
|
|
36806
37025
|
] }, m.type + ("id" in m ? m.id : "")))
|
|
36807
37026
|
] }),
|
|
36808
|
-
env3 ? /* @__PURE__ */ (0,
|
|
37027
|
+
env3 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36809
37028
|
"Or set ",
|
|
36810
37029
|
env3.names[0],
|
|
36811
37030
|
" in your shell before starting LatentCode."
|
|
36812
37031
|
] }) }) : null,
|
|
36813
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37032
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36814
37033
|
]
|
|
36815
37034
|
}
|
|
36816
37035
|
);
|
|
@@ -36836,33 +37055,33 @@ function KeyEntry(p) {
|
|
|
36836
37055
|
return false;
|
|
36837
37056
|
}
|
|
36838
37057
|
});
|
|
36839
|
-
return /* @__PURE__ */ (0,
|
|
37058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36840
37059
|
Panel,
|
|
36841
37060
|
{
|
|
36842
37061
|
title: `Connect ${p.integration.name}`,
|
|
36843
37062
|
right: "API key",
|
|
36844
37063
|
width: p.width,
|
|
36845
37064
|
color: p.color,
|
|
36846
|
-
footer: /* @__PURE__ */ (0,
|
|
36847
|
-
children: /* @__PURE__ */ (0,
|
|
36848
|
-
/* @__PURE__ */ (0,
|
|
37065
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["enter", "save"], ["esc", "back"]] }),
|
|
37066
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37067
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36849
37068
|
"Paste your ",
|
|
36850
37069
|
p.integration.name,
|
|
36851
37070
|
" API key."
|
|
36852
37071
|
] }),
|
|
36853
|
-
/* @__PURE__ */ (0,
|
|
36854
|
-
/* @__PURE__ */ (0,
|
|
37072
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37073
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36855
37074
|
G.key,
|
|
36856
37075
|
" "
|
|
36857
37076
|
] }),
|
|
36858
|
-
/* @__PURE__ */ (0,
|
|
37077
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, mask: true, placeholder: "paste the key here" })
|
|
36859
37078
|
] }),
|
|
36860
|
-
/* @__PURE__ */ (0,
|
|
36861
|
-
/* @__PURE__ */ (0,
|
|
37079
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37080
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36862
37081
|
" ",
|
|
36863
|
-
/* @__PURE__ */ (0,
|
|
36864
|
-
] }) : /* @__PURE__ */ (0,
|
|
36865
|
-
error ? /* @__PURE__ */ (0,
|
|
37082
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Saving\u2026" })
|
|
37083
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, children: "Stored by the local engine on this machine. Never sent to Latent." }) }),
|
|
37084
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: error }) : null
|
|
36866
37085
|
] })
|
|
36867
37086
|
}
|
|
36868
37087
|
);
|
|
@@ -36929,37 +37148,37 @@ function OAuthFlow(p) {
|
|
|
36929
37148
|
return false;
|
|
36930
37149
|
}
|
|
36931
37150
|
});
|
|
36932
|
-
return /* @__PURE__ */ (0,
|
|
37151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36933
37152
|
Panel,
|
|
36934
37153
|
{
|
|
36935
37154
|
title: `Connect ${p.integration.name}`,
|
|
36936
37155
|
right: p.method.label,
|
|
36937
37156
|
width: p.width,
|
|
36938
37157
|
color: p.color,
|
|
36939
|
-
footer: /* @__PURE__ */ (0,
|
|
36940
|
-
children: /* @__PURE__ */ (0,
|
|
36941
|
-
!attempt && !error ? /* @__PURE__ */ (0,
|
|
36942
|
-
/* @__PURE__ */ (0,
|
|
37158
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: codeMode ? [["enter", "submit code"], ["esc", "cancel"]] : [["esc", "cancel"]] }),
|
|
37159
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37160
|
+
!attempt && !error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37161
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36943
37162
|
" ",
|
|
36944
|
-
/* @__PURE__ */ (0,
|
|
37163
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Starting sign-in\u2026" })
|
|
36945
37164
|
] }) : null,
|
|
36946
|
-
attempt ? /* @__PURE__ */ (0,
|
|
36947
|
-
/* @__PURE__ */ (0,
|
|
36948
|
-
/* @__PURE__ */ (0,
|
|
36949
|
-
attempt.instructions ? /* @__PURE__ */ (0,
|
|
36950
|
-
/* @__PURE__ */ (0,
|
|
36951
|
-
/* @__PURE__ */ (0,
|
|
37165
|
+
attempt ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
37166
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Your browser should open. If it does not, open this link:" }),
|
|
37167
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, wrap: "wrap", children: attempt.url }),
|
|
37168
|
+
attempt.instructions ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: true, children: attempt.instructions }) }) : null,
|
|
37169
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: codeMode ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37170
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36952
37171
|
G.key,
|
|
36953
37172
|
" "
|
|
36954
37173
|
] }),
|
|
36955
|
-
/* @__PURE__ */ (0,
|
|
36956
|
-
] }) : error ? null : /* @__PURE__ */ (0,
|
|
36957
|
-
/* @__PURE__ */ (0,
|
|
37174
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, placeholder: "paste the code from the browser" })
|
|
37175
|
+
] }) : error ? null : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37176
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36958
37177
|
" ",
|
|
36959
|
-
/* @__PURE__ */ (0,
|
|
37178
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Waiting for you to finish in the browser\u2026" })
|
|
36960
37179
|
] }) })
|
|
36961
37180
|
] }) : null,
|
|
36962
|
-
error ? /* @__PURE__ */ (0,
|
|
37181
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: error }) : null
|
|
36963
37182
|
] })
|
|
36964
37183
|
}
|
|
36965
37184
|
);
|
|
@@ -37055,13 +37274,13 @@ function CustomProviderForm(p) {
|
|
|
37055
37274
|
},
|
|
37056
37275
|
{ isActive: !busy && step === "kind" }
|
|
37057
37276
|
);
|
|
37058
|
-
const done = (label2, value) => /* @__PURE__ */ (0,
|
|
37059
|
-
/* @__PURE__ */ (0,
|
|
37277
|
+
const done = (label2, value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37278
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
37060
37279
|
G.ok,
|
|
37061
37280
|
" "
|
|
37062
37281
|
] }),
|
|
37063
|
-
/* @__PURE__ */ (0,
|
|
37064
|
-
/* @__PURE__ */ (0,
|
|
37282
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: pad(label2, 10) }),
|
|
37283
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { children: value })
|
|
37065
37284
|
] });
|
|
37066
37285
|
const at = order.indexOf(step);
|
|
37067
37286
|
const prompt = {
|
|
@@ -37078,51 +37297,51 @@ function CustomProviderForm(p) {
|
|
|
37078
37297
|
placeholder: "e.g. gpt-4.1, claude-sonnet-4"
|
|
37079
37298
|
}
|
|
37080
37299
|
};
|
|
37081
|
-
return /* @__PURE__ */ (0,
|
|
37300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
37082
37301
|
Panel,
|
|
37083
37302
|
{
|
|
37084
37303
|
title: "Custom provider",
|
|
37085
37304
|
right: `step ${at + 1} of ${order.length}`,
|
|
37086
37305
|
width: p.width,
|
|
37087
37306
|
color: p.color,
|
|
37088
|
-
footer: /* @__PURE__ */ (0,
|
|
37307
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
37089
37308
|
Hints,
|
|
37090
37309
|
{
|
|
37091
37310
|
items: step === "kind" ? [["\u2191\u2193", "choose"], ["enter", "continue"], ["esc", "back"]] : [["enter", step === "models" ? "save" : "continue"], ["esc", "back"]]
|
|
37092
37311
|
}
|
|
37093
37312
|
),
|
|
37094
|
-
children: /* @__PURE__ */ (0,
|
|
37313
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37095
37314
|
at > 0 ? done("Name", name) : null,
|
|
37096
37315
|
at > 1 ? done("Type", KIND_LABEL[kind]) : null,
|
|
37097
37316
|
at > 2 ? done("Base URL", url) : null,
|
|
37098
37317
|
at > 3 ? done("API key", key ? "\u2022".repeat(Math.min(key.length, 12)) : "none") : null,
|
|
37099
|
-
/* @__PURE__ */ (0,
|
|
37100
|
-
/* @__PURE__ */ (0,
|
|
37101
|
-
KINDS.map((k) => /* @__PURE__ */ (0,
|
|
37102
|
-
/* @__PURE__ */ (0,
|
|
37318
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: at > 0 ? 1 : 0, flexDirection: "column", children: step === "kind" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
37319
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Which API does the endpoint speak?" }),
|
|
37320
|
+
KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37321
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
37103
37322
|
k === kind ? G.prompt : " ",
|
|
37104
37323
|
" "
|
|
37105
37324
|
] }),
|
|
37106
|
-
/* @__PURE__ */ (0,
|
|
37107
|
-
/* @__PURE__ */ (0,
|
|
37325
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: k === kind, children: pad(KIND_LABEL[k], 24) }),
|
|
37326
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, children: k === "openai" ? "/chat/completions \u2014 most gateways, vLLM, Ollama" : "/messages \u2014 Anthropic-style proxies" })
|
|
37108
37327
|
] }, k))
|
|
37109
|
-
] }) : /* @__PURE__ */ (0,
|
|
37110
|
-
/* @__PURE__ */ (0,
|
|
37111
|
-
/* @__PURE__ */ (0,
|
|
37112
|
-
/* @__PURE__ */ (0,
|
|
37328
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
37329
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: prompt[step].hint }),
|
|
37330
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37331
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
37113
37332
|
step === "key" ? G.key : G.prompt,
|
|
37114
37333
|
" "
|
|
37115
37334
|
] }),
|
|
37116
|
-
/* @__PURE__ */ (0,
|
|
37117
|
-
/* @__PURE__ */ (0,
|
|
37335
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: true, children: pad(prompt[step].label, 10) }),
|
|
37336
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, mask: step === "key", placeholder: prompt[step].placeholder })
|
|
37118
37337
|
] })
|
|
37119
37338
|
] }) }),
|
|
37120
|
-
/* @__PURE__ */ (0,
|
|
37121
|
-
/* @__PURE__ */ (0,
|
|
37339
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37340
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
37122
37341
|
" ",
|
|
37123
|
-
/* @__PURE__ */ (0,
|
|
37124
|
-
] }) : /* @__PURE__ */ (0,
|
|
37125
|
-
error ? /* @__PURE__ */ (0,
|
|
37342
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: busy })
|
|
37343
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.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." }) }),
|
|
37344
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, wrap: "wrap", children: error }) : null
|
|
37126
37345
|
] })
|
|
37127
37346
|
}
|
|
37128
37347
|
);
|
|
@@ -37132,23 +37351,23 @@ function Done(p) {
|
|
|
37132
37351
|
if (key.return) return p.onModels();
|
|
37133
37352
|
if (key.escape) p.onClose();
|
|
37134
37353
|
});
|
|
37135
|
-
return /* @__PURE__ */ (0,
|
|
37354
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
37136
37355
|
Panel,
|
|
37137
37356
|
{
|
|
37138
37357
|
title: "Connected",
|
|
37139
37358
|
width: p.width,
|
|
37140
37359
|
color: C.ok,
|
|
37141
|
-
footer: /* @__PURE__ */ (0,
|
|
37360
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["enter", "pick a model"], ["esc", "close"]] }),
|
|
37142
37361
|
children: [
|
|
37143
|
-
/* @__PURE__ */ (0,
|
|
37144
|
-
/* @__PURE__ */ (0,
|
|
37362
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37363
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
37145
37364
|
G.ok,
|
|
37146
37365
|
" "
|
|
37147
37366
|
] }),
|
|
37148
|
-
/* @__PURE__ */ (0,
|
|
37149
|
-
/* @__PURE__ */ (0,
|
|
37367
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: true, children: p.name }),
|
|
37368
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.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
37369
|
] }) }),
|
|
37151
|
-
p.note ? /* @__PURE__ */ (0,
|
|
37370
|
+
p.note ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, wrap: "wrap", children: p.note }) }) : null
|
|
37152
37371
|
]
|
|
37153
37372
|
}
|
|
37154
37373
|
);
|
|
@@ -37259,6 +37478,25 @@ async function pollDeviceToken(appId, deviceCode, opts) {
|
|
|
37259
37478
|
}
|
|
37260
37479
|
throw new Error("Auth link timed out \u2014 run `latentcode login` again.");
|
|
37261
37480
|
}
|
|
37481
|
+
async function issueLoginKey(server, accessToken, deviceId2, fetchImpl = fetch) {
|
|
37482
|
+
let res;
|
|
37483
|
+
try {
|
|
37484
|
+
res = await fetchImpl(`${trimServer(server)}/auth/latent-key`, {
|
|
37485
|
+
method: "POST",
|
|
37486
|
+
headers: { "Content-Type": "application/json" },
|
|
37487
|
+
body: JSON.stringify({ access_token: accessToken, device_id: deviceId2 })
|
|
37488
|
+
});
|
|
37489
|
+
} catch {
|
|
37490
|
+
return null;
|
|
37491
|
+
}
|
|
37492
|
+
if ([404, 405, 503].includes(res.status)) return null;
|
|
37493
|
+
const body = await readJson(res);
|
|
37494
|
+
if (!res.ok) {
|
|
37495
|
+
throw new Error(typeof body.detail === "string" ? body.detail : `latent-key HTTP ${res.status}`);
|
|
37496
|
+
}
|
|
37497
|
+
if (!body.wallet || !body.privy_user_id || !body.key) return null;
|
|
37498
|
+
return { wallet: body.wallet, privy_user_id: body.privy_user_id, key: body.key, default_model: body.default_model ?? null };
|
|
37499
|
+
}
|
|
37262
37500
|
async function resolveSession(server, accessToken, fetchImpl = fetch) {
|
|
37263
37501
|
const res = await fetchImpl(`${trimServer(server)}/auth/session`, {
|
|
37264
37502
|
method: "POST",
|
|
@@ -37311,16 +37549,28 @@ You can still connect an address you control: latentcode login --wallet 0x\u2026
|
|
|
37311
37549
|
sleep: deps2.sleep,
|
|
37312
37550
|
now: deps2.now
|
|
37313
37551
|
});
|
|
37314
|
-
const
|
|
37552
|
+
const withKey = deps2.deviceId ? await issueLoginKey(deps2.server, tokens.access_token, deps2.deviceId(), deps2.fetchImpl) : null;
|
|
37553
|
+
const earner = withKey ?? await resolveSession(deps2.server, tokens.access_token, deps2.fetchImpl);
|
|
37315
37554
|
if (!WALLET_RE.test(earner.wallet)) throw new Error("The server returned an invalid wallet address.");
|
|
37316
37555
|
const prev = deps2.load().wallet;
|
|
37317
|
-
deps2.save({
|
|
37556
|
+
deps2.save({
|
|
37557
|
+
wallet: earner.wallet,
|
|
37558
|
+
privy_user_id: earner.privy_user_id,
|
|
37559
|
+
auth: "privy",
|
|
37560
|
+
...withKey ? { latent_key: withKey.key, latent_default_model: withKey.default_model ?? void 0 } : {}
|
|
37561
|
+
});
|
|
37318
37562
|
deps2.log(`Signed in. Earn mode pays into ${short(earner.wallet)}.`);
|
|
37319
|
-
|
|
37563
|
+
if (withKey) deps2.log("Latent provider ready: your earnings pay for model usage.");
|
|
37564
|
+
return {
|
|
37565
|
+
wallet: earner.wallet,
|
|
37566
|
+
method: "privy",
|
|
37567
|
+
replaced: prev && prev !== earner.wallet ? prev : void 0,
|
|
37568
|
+
latentKey: Boolean(withKey)
|
|
37569
|
+
};
|
|
37320
37570
|
}
|
|
37321
37571
|
|
|
37322
37572
|
// src/ui/panels/WalletPanel.tsx
|
|
37323
|
-
var
|
|
37573
|
+
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
|
37324
37574
|
var deps = (server, extra) => ({
|
|
37325
37575
|
server,
|
|
37326
37576
|
log: () => {
|
|
@@ -37328,6 +37578,7 @@ var deps = (server, extra) => ({
|
|
|
37328
37578
|
open: openUrl,
|
|
37329
37579
|
load: loadConfig,
|
|
37330
37580
|
save: (patch) => void saveConfig(patch),
|
|
37581
|
+
deviceId: deviceKeyId,
|
|
37331
37582
|
...extra
|
|
37332
37583
|
});
|
|
37333
37584
|
function WalletPanel(p) {
|
|
@@ -37338,13 +37589,13 @@ function WalletPanel(p) {
|
|
|
37338
37589
|
};
|
|
37339
37590
|
switch (view.v) {
|
|
37340
37591
|
case "menu":
|
|
37341
|
-
return /* @__PURE__ */ (0,
|
|
37592
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Menu, { ...p, onPick: (v) => setView({ v }) });
|
|
37342
37593
|
case "link":
|
|
37343
|
-
return /* @__PURE__ */ (0,
|
|
37594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AuthLink, { ...p, onDone: done, onBack: () => setView({ v: "menu" }) });
|
|
37344
37595
|
case "address":
|
|
37345
|
-
return /* @__PURE__ */ (0,
|
|
37596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Address, { ...p, onDone: done, onBack: () => setView({ v: "menu" }) });
|
|
37346
37597
|
case "done":
|
|
37347
|
-
return /* @__PURE__ */ (0,
|
|
37598
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Done2, { width: p.width, wallet: view.wallet, onClose: p.onClose });
|
|
37348
37599
|
}
|
|
37349
37600
|
}
|
|
37350
37601
|
function Menu(p) {
|
|
@@ -37358,23 +37609,23 @@ function Menu(p) {
|
|
|
37358
37609
|
if (key.upArrow || key.downArrow || key.tab) return setSel((s2) => (s2 + 1) % options.length);
|
|
37359
37610
|
if (key.return) p.onPick(options[sel].id);
|
|
37360
37611
|
});
|
|
37361
|
-
return /* @__PURE__ */ (0,
|
|
37612
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
37362
37613
|
Panel,
|
|
37363
37614
|
{
|
|
37364
37615
|
title: "Wallet",
|
|
37365
37616
|
right: p.wallet ? `connected \xB7 ${shortWallet(p.wallet)}` : "not connected",
|
|
37366
37617
|
width: p.width,
|
|
37367
37618
|
color: C.earn,
|
|
37368
|
-
footer: /* @__PURE__ */ (0,
|
|
37369
|
-
children: /* @__PURE__ */ (0,
|
|
37370
|
-
/* @__PURE__ */ (0,
|
|
37371
|
-
/* @__PURE__ */ (0,
|
|
37372
|
-
/* @__PURE__ */ (0,
|
|
37619
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "continue"], ["esc", "close"]] }),
|
|
37620
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37621
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, wrap: "wrap", children: p.wallet ? "Earn mode pays into this wallet. Connect a different one:" : "Earn mode pays you in Latent Credit while the agent works \u2014 model usage, or USDG when you sell. Connect the wallet it should pay into:" }),
|
|
37622
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { flexDirection: "column", marginTop: 1, children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
37623
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37373
37624
|
i === sel ? G.prompt : " ",
|
|
37374
37625
|
" "
|
|
37375
37626
|
] }),
|
|
37376
|
-
/* @__PURE__ */ (0,
|
|
37377
|
-
/* @__PURE__ */ (0,
|
|
37627
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: i === sel, children: o.label.padEnd(27) }),
|
|
37628
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.faint, children: o.hint })
|
|
37378
37629
|
] }, o.id)) })
|
|
37379
37630
|
] })
|
|
37380
37631
|
}
|
|
@@ -37403,34 +37654,34 @@ function AuthLink(p) {
|
|
|
37403
37654
|
if (key.escape) p.onBack();
|
|
37404
37655
|
if (key.return && link2) openUrl(link2.url);
|
|
37405
37656
|
});
|
|
37406
|
-
return /* @__PURE__ */ (0,
|
|
37657
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
37407
37658
|
Panel,
|
|
37408
37659
|
{
|
|
37409
37660
|
title: "Sign in",
|
|
37410
37661
|
right: "Latent wallet",
|
|
37411
37662
|
width: p.width,
|
|
37412
37663
|
color: C.earn,
|
|
37413
|
-
footer: /* @__PURE__ */ (0,
|
|
37414
|
-
children: /* @__PURE__ */ (0,
|
|
37415
|
-
!link2 && !error ? /* @__PURE__ */ (0,
|
|
37416
|
-
/* @__PURE__ */ (0,
|
|
37664
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "open the link again"], ["esc", "cancel"]] }),
|
|
37665
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37666
|
+
!link2 && !error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
37667
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Spinner, { color: C.earn }),
|
|
37417
37668
|
" ",
|
|
37418
|
-
/* @__PURE__ */ (0,
|
|
37669
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Preparing your sign-in link\u2026" })
|
|
37419
37670
|
] }) : null,
|
|
37420
|
-
link2 ? /* @__PURE__ */ (0,
|
|
37421
|
-
/* @__PURE__ */ (0,
|
|
37422
|
-
/* @__PURE__ */ (0,
|
|
37423
|
-
/* @__PURE__ */ (0,
|
|
37424
|
-
/* @__PURE__ */ (0,
|
|
37425
|
-
/* @__PURE__ */ (0,
|
|
37671
|
+
link2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
37672
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Your browser should open. If it does not, open:" }),
|
|
37673
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.accent2, wrap: "wrap", children: link2.url }),
|
|
37674
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
37675
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Code " }),
|
|
37676
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: true, color: C.earn, children: link2.code })
|
|
37426
37677
|
] }) }),
|
|
37427
|
-
error ? null : /* @__PURE__ */ (0,
|
|
37428
|
-
/* @__PURE__ */ (0,
|
|
37678
|
+
error ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
37679
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Spinner, { color: C.earn }),
|
|
37429
37680
|
" ",
|
|
37430
|
-
/* @__PURE__ */ (0,
|
|
37681
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Waiting for you to finish in the browser\u2026" })
|
|
37431
37682
|
] }) })
|
|
37432
37683
|
] }) : null,
|
|
37433
|
-
error ? /* @__PURE__ */ (0,
|
|
37684
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.err, wrap: "wrap", children: error }) }) : null
|
|
37434
37685
|
] })
|
|
37435
37686
|
}
|
|
37436
37687
|
);
|
|
@@ -37453,23 +37704,23 @@ function Address(p) {
|
|
|
37453
37704
|
return false;
|
|
37454
37705
|
}
|
|
37455
37706
|
});
|
|
37456
|
-
return /* @__PURE__ */ (0,
|
|
37707
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
37457
37708
|
Panel,
|
|
37458
37709
|
{
|
|
37459
37710
|
title: "Wallet address",
|
|
37460
37711
|
width: p.width,
|
|
37461
37712
|
color: C.earn,
|
|
37462
|
-
footer: /* @__PURE__ */ (0,
|
|
37463
|
-
children: /* @__PURE__ */ (0,
|
|
37464
|
-
/* @__PURE__ */ (0,
|
|
37465
|
-
/* @__PURE__ */ (0,
|
|
37466
|
-
/* @__PURE__ */ (0,
|
|
37713
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "save"], ["esc", "back"]] }),
|
|
37714
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37715
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Credit is earned on this address; sales pay USDG here. Use one you control." }),
|
|
37716
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37717
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37467
37718
|
G.earn,
|
|
37468
37719
|
" "
|
|
37469
37720
|
] }),
|
|
37470
|
-
/* @__PURE__ */ (0,
|
|
37721
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FieldText, { state: field.state, placeholder: "0x\u2026" })
|
|
37471
37722
|
] }),
|
|
37472
|
-
error ? /* @__PURE__ */ (0,
|
|
37723
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.err, children: error }) : null
|
|
37473
37724
|
] })
|
|
37474
37725
|
}
|
|
37475
37726
|
);
|
|
@@ -37478,19 +37729,21 @@ function Done2(p) {
|
|
|
37478
37729
|
use_input_default((_ch, key) => {
|
|
37479
37730
|
if (key.return || key.escape) p.onClose();
|
|
37480
37731
|
});
|
|
37481
|
-
return /* @__PURE__ */ (0,
|
|
37482
|
-
/* @__PURE__ */ (0,
|
|
37732
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Panel, { title: "Wallet connected", width: p.width, color: C.ok, footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "continue"]] }), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
37733
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.ok, children: [
|
|
37483
37734
|
G.ok,
|
|
37484
37735
|
" "
|
|
37485
37736
|
] }),
|
|
37486
|
-
/* @__PURE__ */ (0,
|
|
37487
|
-
/* @__PURE__ */ (0,
|
|
37488
|
-
/* @__PURE__ */ (0,
|
|
37737
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { children: "Earn mode pays into " }),
|
|
37738
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: true, children: shortWallet(p.wallet) }),
|
|
37739
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: ". You earn while the agent works." })
|
|
37489
37740
|
] }) }) });
|
|
37490
37741
|
}
|
|
37491
37742
|
|
|
37492
37743
|
// src/ui/App.tsx
|
|
37493
|
-
var
|
|
37744
|
+
var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
|
|
37745
|
+
var DASHBOARD = "latentprotocol.xyz/app";
|
|
37746
|
+
var MODE = { keep: "keep and spend (bonus)", auto_sell: "sell automatically for USDG", auto_list: "list at my price" };
|
|
37494
37747
|
var notice = (text, tone = "info") => ({
|
|
37495
37748
|
type: "latentcode.notice",
|
|
37496
37749
|
created: Date.now(),
|
|
@@ -37522,42 +37775,42 @@ function activityLabel(s2) {
|
|
|
37522
37775
|
function StepMark({ status: status2 }) {
|
|
37523
37776
|
switch (status2) {
|
|
37524
37777
|
case "run":
|
|
37525
|
-
return /* @__PURE__ */ (0,
|
|
37778
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, {});
|
|
37526
37779
|
case "ok":
|
|
37527
|
-
return /* @__PURE__ */ (0,
|
|
37780
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.ok, children: G.ok });
|
|
37528
37781
|
case "warn":
|
|
37529
|
-
return /* @__PURE__ */ (0,
|
|
37782
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.warn, children: G.ring });
|
|
37530
37783
|
case "fail":
|
|
37531
|
-
return /* @__PURE__ */ (0,
|
|
37784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.err, children: G.no });
|
|
37532
37785
|
default:
|
|
37533
|
-
return /* @__PURE__ */ (0,
|
|
37786
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, children: "\xB7" });
|
|
37534
37787
|
}
|
|
37535
37788
|
}
|
|
37536
37789
|
function BootCard(p) {
|
|
37537
37790
|
const wLabel = 10;
|
|
37538
37791
|
const inner = p.width - 4;
|
|
37539
|
-
return /* @__PURE__ */ (0,
|
|
37540
|
-
/* @__PURE__ */ (0,
|
|
37541
|
-
/* @__PURE__ */ (0,
|
|
37542
|
-
/* @__PURE__ */ (0,
|
|
37792
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
37793
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { marginTop: 1, marginLeft: 1, flexDirection: "column", children: [
|
|
37794
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Logo, { version: p.version }),
|
|
37795
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: TAGLINE })
|
|
37543
37796
|
] }),
|
|
37544
|
-
/* @__PURE__ */ (0,
|
|
37545
|
-
p.steps.map((st) => /* @__PURE__ */ (0,
|
|
37546
|
-
/* @__PURE__ */ (0,
|
|
37547
|
-
/* @__PURE__ */ (0,
|
|
37797
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", borderStyle: "round", borderColor: p.error ? C.err : C.border, paddingX: 1, width: p.width, children: [
|
|
37798
|
+
p.steps.map((st) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37799
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StepMark, { status: st.status }),
|
|
37800
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { bold: st.status === "run", color: st.status === "pending" ? C.faint : void 0, children: [
|
|
37548
37801
|
" ",
|
|
37549
37802
|
pad(st.label, wLabel)
|
|
37550
37803
|
] }),
|
|
37551
|
-
/* @__PURE__ */ (0,
|
|
37804
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: st.status === "fail" ? C.err : st.status === "warn" ? C.warn : C.muted, children: st.status === "run" && !st.detail ? "starting\u2026" : clip(st.detail, inner - wLabel - 4) })
|
|
37552
37805
|
] }, st.id)),
|
|
37553
|
-
/* @__PURE__ */ (0,
|
|
37554
|
-
/* @__PURE__ */ (0,
|
|
37555
|
-
/* @__PURE__ */ (0,
|
|
37556
|
-
/* @__PURE__ */ (0,
|
|
37806
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37807
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, children: "\xB7 " }),
|
|
37808
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, children: pad("Project", wLabel) }),
|
|
37809
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: shortPath(p.cwd, homedir4(), inner - wLabel - 4) })
|
|
37557
37810
|
] })
|
|
37558
37811
|
] }),
|
|
37559
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37560
|
-
p.ready ? /* @__PURE__ */ (0,
|
|
37812
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { marginLeft: 1, marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.err, wrap: "wrap", children: p.error }) }) : null,
|
|
37813
|
+
p.ready ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { marginLeft: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
37561
37814
|
Hints,
|
|
37562
37815
|
{
|
|
37563
37816
|
items: [
|
|
@@ -37586,26 +37839,26 @@ function HelpPanel({ width, commands, onClose }) {
|
|
|
37586
37839
|
["ctrl+o", "open the sponsored link"],
|
|
37587
37840
|
["ctrl+c", "clear the line, twice to quit"]
|
|
37588
37841
|
];
|
|
37589
|
-
return /* @__PURE__ */ (0,
|
|
37842
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Panel, { title: "Help", width, color: C.accent, footer: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Hints, { items: [["esc", "close"]] }), children: [
|
|
37590
37843
|
groups.map((g) => {
|
|
37591
37844
|
const list = commands.filter((c) => c.group === g);
|
|
37592
37845
|
if (!list.length) return null;
|
|
37593
|
-
return /* @__PURE__ */ (0,
|
|
37594
|
-
/* @__PURE__ */ (0,
|
|
37595
|
-
list.map((c) => /* @__PURE__ */ (0,
|
|
37596
|
-
/* @__PURE__ */ (0,
|
|
37597
|
-
/* @__PURE__ */ (0,
|
|
37846
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37847
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { bold: true, color: C.muted, children: g }),
|
|
37848
|
+
list.map((c) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37849
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.accent2, children: pad(`/${c.name}${c.args ? " " + c.args : ""}`, 22) }),
|
|
37850
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: c.desc })
|
|
37598
37851
|
] }, c.name))
|
|
37599
37852
|
] }, g);
|
|
37600
37853
|
}),
|
|
37601
|
-
/* @__PURE__ */ (0,
|
|
37602
|
-
/* @__PURE__ */ (0,
|
|
37603
|
-
keys.map(([k, d]) => /* @__PURE__ */ (0,
|
|
37604
|
-
/* @__PURE__ */ (0,
|
|
37605
|
-
/* @__PURE__ */ (0,
|
|
37854
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37855
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { bold: true, color: C.muted, children: "Keys" }),
|
|
37856
|
+
keys.map(([k, d]) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { children: [
|
|
37857
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.accent2, children: pad(k, 22) }),
|
|
37858
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: d })
|
|
37606
37859
|
] }, k))
|
|
37607
37860
|
] }),
|
|
37608
|
-
/* @__PURE__ */ (0,
|
|
37861
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, wrap: "wrap", children: `Privacy: ads never enter the model's context or its answers. The only thing sent to the ad server is a coarse category (for example "backend"), worked out on this machine.` }) })
|
|
37609
37862
|
] });
|
|
37610
37863
|
}
|
|
37611
37864
|
function App2(props) {
|
|
@@ -37659,11 +37912,15 @@ function App2(props) {
|
|
|
37659
37912
|
const say = (text, tone = "info") => dispatch(notice(text, tone));
|
|
37660
37913
|
const statusOf = (key) => store.get(key)?.status ?? "unknown";
|
|
37661
37914
|
const modelName = (key) => catalog.models.find((m) => m.key === key)?.name ?? key;
|
|
37915
|
+
const [bonus, setBonus] = (0, import_react26.useState)(1);
|
|
37916
|
+
(0, import_react26.useEffect)(() => {
|
|
37917
|
+
void api.creditQuote().then((q) => q && setBonus(q.bonus));
|
|
37918
|
+
}, [api]);
|
|
37662
37919
|
props.summary.current = {
|
|
37663
37920
|
turns: state.turns,
|
|
37664
37921
|
tokens: state.tokens.input + state.tokens.output,
|
|
37665
37922
|
cost: state.cost,
|
|
37666
|
-
earned: ad.sessionEarned,
|
|
37923
|
+
earned: credits(ad.sessionEarned, bonus),
|
|
37667
37924
|
impressions: ad.impressions
|
|
37668
37925
|
};
|
|
37669
37926
|
(0, import_react26.useEffect)(() => {
|
|
@@ -37734,6 +37991,19 @@ function App2(props) {
|
|
|
37734
37991
|
function changeWallet(next) {
|
|
37735
37992
|
setWallet(next);
|
|
37736
37993
|
controller.setWallet(next);
|
|
37994
|
+
void connectLoginKey();
|
|
37995
|
+
}
|
|
37996
|
+
async function connectLoginKey() {
|
|
37997
|
+
try {
|
|
37998
|
+
const res = await connectPendingLatentKey(engine, props.server, { load: loadConfig, save: (p) => void saveConfig(p) });
|
|
37999
|
+
if (!res) return;
|
|
38000
|
+
const next = await reloadCatalog();
|
|
38001
|
+
const m = res.defaultModel ? next.models.find((x) => x.key === res.defaultModel) : void 0;
|
|
38002
|
+
if (m) await pickModel(m, "");
|
|
38003
|
+
say(`Latent connected: ${res.models.length} models, paid from your earnings.${m ? "" : " Pick one with /model latent."}`, "ok");
|
|
38004
|
+
} catch (e) {
|
|
38005
|
+
say(`Latent not connected: ${e instanceof Error ? e.message : String(e)}. Try /key lk_\u2026 with a key from the dashboard.`, "warn");
|
|
38006
|
+
}
|
|
37737
38007
|
}
|
|
37738
38008
|
async function runCommand(line) {
|
|
37739
38009
|
const { name, arg } = parseCommandLine(line);
|
|
@@ -37785,13 +38055,54 @@ function App2(props) {
|
|
|
37785
38055
|
say("No wallet connected yet. /login takes a minute and you start earning right away.", "warn");
|
|
37786
38056
|
return;
|
|
37787
38057
|
}
|
|
37788
|
-
const
|
|
38058
|
+
const c = await api.creditSummary(wallet);
|
|
38059
|
+
const hasLatent = catalog.providers.some((p) => p.id === LATENT_PROVIDER_ID);
|
|
37789
38060
|
say(
|
|
37790
|
-
`This session: ${ad.impressions} sponsored view${ad.impressions === 1 ? "" : "s"} \u2248
|
|
37791
|
-
Wallet ${shortWallet(wallet)} \xB7
|
|
38061
|
+
`This session: ${ad.impressions} sponsored view${ad.impressions === 1 ? "" : "s"} \u2248 ${credits(ad.sessionEarned, bonus).toFixed(3)} credits (indicative)
|
|
38062
|
+
Wallet ${shortWallet(wallet)} \xB7 ${c === null ? "balance unavailable right now" : `${c.credits.toFixed(2)} Latent Credit ($1 of model usage each)`}` + (c ? `
|
|
38063
|
+
Mode: ${MODE[c.mode]} \u2014 change it at ${DASHBOARD}/settings` : "") + (hasLatent ? "" : `
|
|
38064
|
+
Spend it here: /login connects the Latent provider (or /key lk_\u2026 with a key from ${DASHBOARD}/earn).`)
|
|
37792
38065
|
);
|
|
37793
38066
|
return;
|
|
37794
38067
|
}
|
|
38068
|
+
case "credits": {
|
|
38069
|
+
if (!wallet) {
|
|
38070
|
+
say("No wallet connected yet. /login first.", "warn");
|
|
38071
|
+
return;
|
|
38072
|
+
}
|
|
38073
|
+
const [c, q] = await Promise.all([api.creditSummary(wallet), api.creditQuote()]);
|
|
38074
|
+
if (!c) {
|
|
38075
|
+
say("Credit balance unavailable right now.", "warn");
|
|
38076
|
+
return;
|
|
38077
|
+
}
|
|
38078
|
+
say(
|
|
38079
|
+
[
|
|
38080
|
+
`Latent Credit ${c.credits.toFixed(2)} credits \xB7 $1 of model usage at list price each`,
|
|
38081
|
+
`Bonus ${c.bonus}\xD7 \u2014 every $1 earned from ads becomes ${c.bonus} credits`,
|
|
38082
|
+
`Mode ${MODE[c.mode]}`,
|
|
38083
|
+
q?.buybackEnabled ? `Sell now ${q.buybackPrice.toFixed(2)} USDG per credit, paid on Robinhood Chain` : `Sell now opens soon`,
|
|
38084
|
+
`Change it ${DASHBOARD}/settings \xB7 sell or list at ${DASHBOARD}/earn \xB7 buy at ${DASHBOARD}/credits`
|
|
38085
|
+
].join("\n")
|
|
38086
|
+
);
|
|
38087
|
+
return;
|
|
38088
|
+
}
|
|
38089
|
+
case "key": {
|
|
38090
|
+
const k = arg.trim();
|
|
38091
|
+
if (!k) {
|
|
38092
|
+
say("/login connects the Latent provider for you. Or paste a key from latentprotocol.xyz/app/earn: /key lk_\u2026");
|
|
38093
|
+
return;
|
|
38094
|
+
}
|
|
38095
|
+
say("Connecting your Latent Key\u2026");
|
|
38096
|
+
try {
|
|
38097
|
+
const res = await connectLatentKey(engine, props.server, k);
|
|
38098
|
+
await reloadCatalog();
|
|
38099
|
+
const note = res.backup ? ` (Comments in ${res.file} could not be kept; the original is at ${res.backup}.)` : "";
|
|
38100
|
+
say(`Latent connected: ${res.models.length} models, paid from your earnings. Pick one with /model latent.${note}`, "ok");
|
|
38101
|
+
} catch (e) {
|
|
38102
|
+
say(e instanceof Error ? e.message : String(e), "warn");
|
|
38103
|
+
}
|
|
38104
|
+
return;
|
|
38105
|
+
}
|
|
37795
38106
|
case "status": {
|
|
37796
38107
|
const prov = catalog.providers.map((p) => p.name).join(", ");
|
|
37797
38108
|
say(
|
|
@@ -37799,7 +38110,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37799
38110
|
`Model ${describeModel(state.model, catalog)}${state.variant ? ` \xB7 effort ${state.variant}` : ""}`,
|
|
37800
38111
|
`Providers ${prov || "none"}`,
|
|
37801
38112
|
`Session ${state.turns} turn${state.turns === 1 ? "" : "s"} \xB7 ${fmtTokens(state.tokens.input)} in / ${fmtTokens(state.tokens.output)} out${state.cost ? ` \xB7 ${fmtUsd(state.cost)}` : ""}`,
|
|
37802
|
-
`Earn ${ad.status === "disabled" ? "off" : wallet ? `on \xB7 ${shortWallet(wallet)} \xB7 \u2248
|
|
38113
|
+
`Earn ${ad.status === "disabled" ? "off" : wallet ? `on \xB7 ${shortWallet(wallet)} \xB7 \u2248 ${credits(ad.sessionEarned, bonus).toFixed(3)} credits this session` : "no wallet \u2014 /login"}`,
|
|
37803
38114
|
`Safety ${props.permissions.length ? "asks before shell commands and file changes" : "--auto (no confirmation)"}`
|
|
37804
38115
|
].join("\n")
|
|
37805
38116
|
);
|
|
@@ -37903,19 +38214,19 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37903
38214
|
const current = catalog.models.find((m) => m.key === state.model);
|
|
37904
38215
|
const provider = catalog.providers.find((p) => p.id === (current?.providerID ?? parseKey(state.model)?.providerID));
|
|
37905
38216
|
const close = () => setOverlay(null);
|
|
37906
|
-
return /* @__PURE__ */ (0,
|
|
37907
|
-
/* @__PURE__ */ (0,
|
|
37908
|
-
live.map((it) => /* @__PURE__ */ (0,
|
|
37909
|
-
perm ? /* @__PURE__ */ (0,
|
|
37910
|
-
state.working ? /* @__PURE__ */ (0,
|
|
37911
|
-
/* @__PURE__ */ (0,
|
|
37912
|
-
/* @__PURE__ */ (0,
|
|
37913
|
-
/* @__PURE__ */ (0,
|
|
38217
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
38218
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Static, { items: [header, ...done.map((it) => ({ id: it.id, it }))], children: (entry) => "it" in entry ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ItemView, { item: entry.it, live: false, cwd: cwd2, width, maxLines }, entry.id) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BootCard, { steps: props.bootSteps, version, cwd: cwd2, width, ready: true }, entry.id) }),
|
|
38219
|
+
live.map((it) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ItemView, { item: it, live: true, cwd: cwd2, width, maxLines }, it.id)),
|
|
38220
|
+
perm ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PermissionPrompt, { perm, selected: permAt, cwd: cwd2, width }) : null,
|
|
38221
|
+
state.working ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", width, children: [
|
|
38222
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38223
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, {}),
|
|
38224
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { children: [
|
|
37914
38225
|
" ",
|
|
37915
38226
|
activityLabel(state),
|
|
37916
38227
|
"\u2026"
|
|
37917
38228
|
] }),
|
|
37918
|
-
/* @__PURE__ */ (0,
|
|
38229
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
37919
38230
|
" ",
|
|
37920
38231
|
elapsed,
|
|
37921
38232
|
"s \xB7 ",
|
|
@@ -37927,34 +38238,9 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37927
38238
|
" \xB7 esc to interrupt"
|
|
37928
38239
|
] })
|
|
37929
38240
|
] }),
|
|
37930
|
-
ad.current ? /* @__PURE__ */ (0,
|
|
37931
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37932
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37933
|
-
G.earn,
|
|
37934
|
-
" Sponsored"
|
|
37935
|
-
] }),
|
|
37936
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37937
|
-
" ",
|
|
37938
|
-
G.thin,
|
|
37939
|
-
" "
|
|
37940
|
-
] }),
|
|
37941
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: true, children: ad.current.title }),
|
|
37942
|
-
ad.current.body ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.muted, children: [
|
|
37943
|
-
" \u2014 ",
|
|
37944
|
-
ad.current.body
|
|
37945
|
-
] }) : null,
|
|
37946
|
-
ad.current.url ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37947
|
-
" \xB7 ctrl+o ",
|
|
37948
|
-
ad.current.ctaText
|
|
37949
|
-
] }) : null
|
|
37950
|
-
] }),
|
|
37951
|
-
ad.billed && ad.current.earn > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37952
|
-
" +$",
|
|
37953
|
-
ad.current.earn.toFixed(4)
|
|
37954
|
-
] }) : null
|
|
37955
|
-
] }) : null
|
|
38241
|
+
ad.current ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SponsoredLine, { ad: ad.current, billed: ad.billed }) : null
|
|
37956
38242
|
] }) : null,
|
|
37957
|
-
overlay?.t === "model" ? /* @__PURE__ */ (0,
|
|
38243
|
+
overlay?.t === "model" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
37958
38244
|
ModelPicker,
|
|
37959
38245
|
{
|
|
37960
38246
|
catalog,
|
|
@@ -37973,7 +38259,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37973
38259
|
onClose: close
|
|
37974
38260
|
}
|
|
37975
38261
|
) : null,
|
|
37976
|
-
overlay?.t === "providers" ? /* @__PURE__ */ (0,
|
|
38262
|
+
overlay?.t === "providers" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
37977
38263
|
ProviderPanel,
|
|
37978
38264
|
{
|
|
37979
38265
|
engine,
|
|
@@ -37992,10 +38278,10 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37992
38278
|
onClose: close
|
|
37993
38279
|
}
|
|
37994
38280
|
) : null,
|
|
37995
|
-
overlay?.t === "wallet" ? /* @__PURE__ */ (0,
|
|
37996
|
-
overlay?.t === "help" ? /* @__PURE__ */ (0,
|
|
37997
|
-
overlay === null && !perm && !leaving ? /* @__PURE__ */ (0,
|
|
37998
|
-
/* @__PURE__ */ (0,
|
|
38281
|
+
overlay?.t === "wallet" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(WalletPanel, { server: props.server, wallet, width, onWallet: changeWallet, onClose: close }) : null,
|
|
38282
|
+
overlay?.t === "help" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HelpPanel, { width, commands: allCommands, onClose: close }) : null,
|
|
38283
|
+
overlay === null && !perm && !leaving ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
38284
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
37999
38285
|
Box_default,
|
|
38000
38286
|
{
|
|
38001
38287
|
marginTop: 1,
|
|
@@ -38004,45 +38290,45 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
38004
38290
|
paddingX: 1,
|
|
38005
38291
|
width,
|
|
38006
38292
|
children: [
|
|
38007
|
-
/* @__PURE__ */ (0,
|
|
38293
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.accent, bold: true, children: [
|
|
38008
38294
|
G.prompt,
|
|
38009
38295
|
" "
|
|
38010
38296
|
] }) }),
|
|
38011
|
-
/* @__PURE__ */ (0,
|
|
38297
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FieldText, { state: editor, placeholder: state.turns ? "reply, or / for commands" : "ask anything, or / for commands" })
|
|
38012
38298
|
]
|
|
38013
38299
|
}
|
|
38014
38300
|
),
|
|
38015
|
-
paletteOpen ? /* @__PURE__ */ (0,
|
|
38016
|
-
matches.slice(0, 8).map((c, i) => /* @__PURE__ */ (0,
|
|
38017
|
-
/* @__PURE__ */ (0,
|
|
38301
|
+
paletteOpen ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { flexDirection: "column", paddingX: 2, width, children: [
|
|
38302
|
+
matches.slice(0, 8).map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38303
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.accent, children: [
|
|
38018
38304
|
i === paletteSel ? G.prompt : " ",
|
|
38019
38305
|
" "
|
|
38020
38306
|
] }),
|
|
38021
|
-
/* @__PURE__ */ (0,
|
|
38022
|
-
/* @__PURE__ */ (0,
|
|
38307
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { bold: i === paletteSel, color: i === paletteSel ? C.accent2 : C.text, children: pad(`/${c.name}${c.args ? " " + c.args : ""}`, 20) }),
|
|
38308
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: c.desc })
|
|
38023
38309
|
] }, c.name)),
|
|
38024
|
-
matches.length > 8 ? /* @__PURE__ */ (0,
|
|
38310
|
+
matches.length > 8 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38025
38311
|
" ",
|
|
38026
38312
|
G.down,
|
|
38027
38313
|
" ",
|
|
38028
38314
|
matches.length - 8,
|
|
38029
38315
|
" more \u2014 keep typing"
|
|
38030
38316
|
] }) : null,
|
|
38031
|
-
/* @__PURE__ */ (0,
|
|
38317
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["tab", "complete"], ["enter", "run"], ["esc", "dismiss"]] })
|
|
38032
38318
|
] }) : null
|
|
38033
38319
|
] }) : null,
|
|
38034
|
-
paletteOpen || leaving ? null : /* @__PURE__ */ (0,
|
|
38035
|
-
/* @__PURE__ */ (0,
|
|
38036
|
-
/* @__PURE__ */ (0,
|
|
38037
|
-
state.variant ? /* @__PURE__ */ (0,
|
|
38320
|
+
paletteOpen || leaving ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { width, justifyContent: "space-between", paddingX: 1, children: [
|
|
38321
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { wrap: "truncate-end", children: quitArmed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.warn, children: "Press ctrl+c again to quit" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
38322
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: current ? C.text : C.warn, children: current?.name ?? (state.model || "no model") }),
|
|
38323
|
+
state.variant ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.accent2, children: [
|
|
38038
38324
|
" ",
|
|
38039
38325
|
state.variant
|
|
38040
38326
|
] }) : null,
|
|
38041
|
-
provider ? /* @__PURE__ */ (0,
|
|
38327
|
+
provider ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38042
38328
|
" \xB7 ",
|
|
38043
38329
|
provider.name
|
|
38044
38330
|
] }) : null,
|
|
38045
|
-
state.tokens.input + state.tokens.output ? /* @__PURE__ */ (0,
|
|
38331
|
+
state.tokens.input + state.tokens.output ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38046
38332
|
" ",
|
|
38047
38333
|
"\xB7 ",
|
|
38048
38334
|
fmtTokens(state.tokens.input + state.tokens.output),
|
|
@@ -38050,21 +38336,21 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
38050
38336
|
state.cost ? ` \xB7 ${fmtUsd(state.cost)}` : ""
|
|
38051
38337
|
] }) : null
|
|
38052
38338
|
] }) }),
|
|
38053
|
-
/* @__PURE__ */ (0,
|
|
38339
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { wrap: "truncate-end", children: ad.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.earn, children: [
|
|
38054
38340
|
G.earn,
|
|
38055
|
-
"
|
|
38056
|
-
ad.sessionEarned.toFixed(
|
|
38057
|
-
" earned",
|
|
38058
|
-
/* @__PURE__ */ (0,
|
|
38341
|
+
" ",
|
|
38342
|
+
credits(ad.sessionEarned, bonus).toFixed(3),
|
|
38343
|
+
" cr earned",
|
|
38344
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38059
38345
|
" \xB7 ",
|
|
38060
38346
|
ad.impressions,
|
|
38061
38347
|
" view",
|
|
38062
38348
|
ad.impressions === 1 ? "" : "s"
|
|
38063
38349
|
] })
|
|
38064
|
-
] }) : ad.status === "disabled" ? /* @__PURE__ */ (0,
|
|
38350
|
+
] }) : ad.status === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38065
38351
|
G.earn,
|
|
38066
38352
|
" Earn off \xB7 /ads on"
|
|
38067
|
-
] }) : /* @__PURE__ */ (0,
|
|
38353
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.warn, children: [
|
|
38068
38354
|
G.earn,
|
|
38069
38355
|
" /login to start earning"
|
|
38070
38356
|
] }) })
|
|
@@ -38073,7 +38359,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
38073
38359
|
}
|
|
38074
38360
|
|
|
38075
38361
|
// src/ui/Root.tsx
|
|
38076
|
-
var
|
|
38362
|
+
var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
|
|
38077
38363
|
function Root(p) {
|
|
38078
38364
|
const { exit } = use_app_default();
|
|
38079
38365
|
const { cols } = useTermSize();
|
|
@@ -38095,7 +38381,7 @@ function Root(p) {
|
|
|
38095
38381
|
{ isActive: !booted }
|
|
38096
38382
|
);
|
|
38097
38383
|
if (!booted) {
|
|
38098
|
-
return /* @__PURE__ */ (0,
|
|
38384
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38099
38385
|
BootCard,
|
|
38100
38386
|
{
|
|
38101
38387
|
steps,
|
|
@@ -38107,7 +38393,7 @@ function Root(p) {
|
|
|
38107
38393
|
}
|
|
38108
38394
|
);
|
|
38109
38395
|
}
|
|
38110
|
-
return /* @__PURE__ */ (0,
|
|
38396
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PasteContext.Provider, { value: p.paste, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(App2, { ...booted, version: p.version, bootSteps: steps, summary: p.summary }) });
|
|
38111
38397
|
}
|
|
38112
38398
|
|
|
38113
38399
|
// src/ads/attention.ts
|
|
@@ -38157,6 +38443,27 @@ var FocusTracker = class {
|
|
|
38157
38443
|
}
|
|
38158
38444
|
};
|
|
38159
38445
|
|
|
38446
|
+
// src/ui/syncOutput.ts
|
|
38447
|
+
var BSU = "\x1B[?2026h";
|
|
38448
|
+
var ESU = "\x1B[?2026l";
|
|
38449
|
+
function wrapFrame(chunk) {
|
|
38450
|
+
if (typeof chunk === "string") return chunk ? BSU + chunk + ESU : chunk;
|
|
38451
|
+
if (!chunk.length) return chunk;
|
|
38452
|
+
return Buffer.concat([Buffer.from(BSU), chunk, Buffer.from(ESU)]);
|
|
38453
|
+
}
|
|
38454
|
+
function syncedStdout(stream = process.stdout, env3 = process.env) {
|
|
38455
|
+
if (env3.LATENTCODE_SYNC_OUTPUT === "off") return stream;
|
|
38456
|
+
return new Proxy(stream, {
|
|
38457
|
+
get(target, prop) {
|
|
38458
|
+
if (prop === "write") {
|
|
38459
|
+
return (chunk, ...rest) => target.write(wrapFrame(chunk), ...rest);
|
|
38460
|
+
}
|
|
38461
|
+
const v = Reflect.get(target, prop, target);
|
|
38462
|
+
return typeof v === "function" ? v.bind(target) : v;
|
|
38463
|
+
}
|
|
38464
|
+
});
|
|
38465
|
+
}
|
|
38466
|
+
|
|
38160
38467
|
// src/ui/stdin.ts
|
|
38161
38468
|
import { PassThrough as PassThrough2 } from "node:stream";
|
|
38162
38469
|
var PASTE_ENABLE = "\x1B[?2004h";
|
|
@@ -38302,8 +38609,8 @@ function row(mark, label2, value, width = 10) {
|
|
|
38302
38609
|
}
|
|
38303
38610
|
|
|
38304
38611
|
// src/index.tsx
|
|
38305
|
-
var
|
|
38306
|
-
var VERSION = "0.1.0-alpha.
|
|
38612
|
+
var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
|
|
38613
|
+
var VERSION = "0.1.0-alpha.6";
|
|
38307
38614
|
var usage = () => `${logo()}
|
|
38308
38615
|
${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
|
|
38309
38616
|
|
|
@@ -38363,7 +38670,8 @@ function loginDeps() {
|
|
|
38363
38670
|
log: (l) => process.stdout.write(styleLoginLine(l) + "\n"),
|
|
38364
38671
|
open: openUrl,
|
|
38365
38672
|
load: loadConfig,
|
|
38366
|
-
save: (patch) => void saveConfig(patch)
|
|
38673
|
+
save: (patch) => void saveConfig(patch),
|
|
38674
|
+
deviceId: deviceKeyId
|
|
38367
38675
|
};
|
|
38368
38676
|
}
|
|
38369
38677
|
function styleLoginLine(l) {
|
|
@@ -38411,7 +38719,7 @@ async function status() {
|
|
|
38411
38719
|
if (wallet) {
|
|
38412
38720
|
const bal = await httpAdApi(server).balance(wallet);
|
|
38413
38721
|
lines.push(
|
|
38414
|
-
row(a.earn("\u25C6"), "
|
|
38722
|
+
row(a.earn("\u25C6"), "Credit", bal === null ? a.dim("unavailable (ad server unreachable)") : `${a.earn(bal.toFixed(2) + " credits")} ${a.dim("($1 of model usage each)")}`)
|
|
38415
38723
|
);
|
|
38416
38724
|
}
|
|
38417
38725
|
process.stdout.write(lines.join("\n") + "\n");
|
|
@@ -38420,7 +38728,7 @@ function goodbye(s2) {
|
|
|
38420
38728
|
const parts = s2.turns ? [`${s2.turns} turn${s2.turns === 1 ? "" : "s"}`] : [];
|
|
38421
38729
|
if (s2.tokens) parts.push(`${fmtTokens(s2.tokens)} tokens`);
|
|
38422
38730
|
if (s2.cost) parts.push(`$${s2.cost.toFixed(3)} model cost`);
|
|
38423
|
-
const earned = s2.impressions ? a.earn(`\u25C6 earned \u2248
|
|
38731
|
+
const earned = s2.impressions ? a.earn(`\u25C6 earned \u2248 ${s2.earned.toFixed(3)} credits from ${s2.impressions} view${s2.impressions === 1 ? "" : "s"}`) : "";
|
|
38424
38732
|
return ` ${a.dim(parts.join(" \xB7 "))}${earned ? ` ${earned}` : ""}
|
|
38425
38733
|
`;
|
|
38426
38734
|
}
|
|
@@ -38443,7 +38751,7 @@ async function main() {
|
|
|
38443
38751
|
const summary = { current: { turns: 0, tokens: 0, cost: 0, earned: 0, impressions: 0 } };
|
|
38444
38752
|
let fatal = false;
|
|
38445
38753
|
const app = render_default(
|
|
38446
|
-
/* @__PURE__ */ (0,
|
|
38754
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
38447
38755
|
Root,
|
|
38448
38756
|
{
|
|
38449
38757
|
args: { cwd: cwd2, model: args.model, noAds: args.noAds, auto: args.auto },
|
|
@@ -38456,7 +38764,7 @@ async function main() {
|
|
|
38456
38764
|
}
|
|
38457
38765
|
}
|
|
38458
38766
|
),
|
|
38459
|
-
{ stdin, exitOnCtrlC: false }
|
|
38767
|
+
{ stdin, stdout: syncedStdout(), exitOnCtrlC: false }
|
|
38460
38768
|
);
|
|
38461
38769
|
await app.waitUntilExit();
|
|
38462
38770
|
if (!fatal && (summary.current.turns || summary.current.impressions)) process.stdout.write(goodbye(summary.current));
|