latentcode 0.1.0-alpha.3 → 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 +1 -1
- package/dist/latentcode.mjs +367 -183
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Terminal coding agent that pays you for its idle time.
|
|
4
4
|
|
|
5
5
|
- **Bring your own model access.** API keys or a provider subscription where the provider allows third-party clients. Connect them inside the app with `/connect`.
|
|
6
|
-
- **Earn mode.** While the agent works, one clearly labelled sponsored line sits in the working bar. You earn
|
|
6
|
+
- **Earn mode.** While the agent works, one clearly labelled sponsored line sits in the working bar. You earn Latent Credit from it on your Latent wallet (the same wallet the other Latent surfaces use): $1 of model usage per credit with a bonus when you keep it — spend it with `/key`, or sell it for USDG.
|
|
7
7
|
- **The model is never for sale.** Ads never enter the model's context or output, and the agent never recommends sponsored tools. The only targeting signal that leaves your machine is a coarse category slug (for example `backend`), classified locally.
|
|
8
8
|
- **Real attention.** An impression is billed once, and only after the ad has been on screen for 10 s while the terminal is focused (xterm focus events, DEC 1004) — the ad server's view floor, the same rule as every other Latent surface. A turn that ends earlier keeps the ad for the next turn instead of wasting it. Only impressions the server confirms count toward the session tally.
|
|
9
9
|
- **Clickable.** In terminals with hyperlinks (iTerm2, Ghostty, Kitty, WezTerm, VS Code, Windows Terminal) the sponsored copy itself is a link; elsewhere the short URL is shown beside it. A coloured monogram badge (stable per brand) leads the line in every terminal. `ctrl+o` works everywhere. Every click goes through the ad server's tracked redirect. `LATENTCODE_LINKS=osc8|plain|hybrid` overrides the detection.
|
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",
|
|
@@ -34395,9 +34395,10 @@ import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync a
|
|
|
34395
34395
|
import { join as join3 } from "node:path";
|
|
34396
34396
|
|
|
34397
34397
|
// src/ads/config.ts
|
|
34398
|
-
import {
|
|
34398
|
+
import { createHash } from "node:crypto";
|
|
34399
|
+
import { homedir as homedir2, hostname } from "node:os";
|
|
34399
34400
|
import { join as join2 } from "node:path";
|
|
34400
|
-
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
34401
|
+
import { chmodSync, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "node:fs";
|
|
34401
34402
|
var DEFAULT_SERVER = "https://api.latentprotocol.xyz";
|
|
34402
34403
|
var AGENT_LATENTCODE = "latentcode";
|
|
34403
34404
|
function configDir() {
|
|
@@ -34421,7 +34422,13 @@ function loadConfig() {
|
|
|
34421
34422
|
function saveConfig(data) {
|
|
34422
34423
|
mkdirSync(configDir(), { recursive: true });
|
|
34423
34424
|
const next = { ...loadConfig(), ...data };
|
|
34424
|
-
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
|
+
}
|
|
34425
34432
|
return next;
|
|
34426
34433
|
}
|
|
34427
34434
|
function resolveServer(cfg = loadConfig()) {
|
|
@@ -34431,10 +34438,10 @@ function resolveWallet(cfg = loadConfig()) {
|
|
|
34431
34438
|
const w = cfg.wallet || process.env.ADS_WALLET || "";
|
|
34432
34439
|
return WALLET_RE.test(w) ? w : "";
|
|
34433
34440
|
}
|
|
34434
|
-
function adsEnabled(cfg = loadConfig()) {
|
|
34441
|
+
function adsEnabled(cfg = loadConfig(), key = "latentcode_ads") {
|
|
34435
34442
|
const env3 = process.env.ADS_ENABLED;
|
|
34436
34443
|
if (env3 !== void 0) return !["false", "0", "no"].includes(env3.toLowerCase());
|
|
34437
|
-
return cfg
|
|
34444
|
+
return cfg[key] !== false;
|
|
34438
34445
|
}
|
|
34439
34446
|
function deviceId() {
|
|
34440
34447
|
try {
|
|
@@ -34444,6 +34451,12 @@ function deviceId() {
|
|
|
34444
34451
|
}
|
|
34445
34452
|
return "";
|
|
34446
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
|
+
}
|
|
34447
34460
|
async function ensureDeviceCredential(server) {
|
|
34448
34461
|
const current = deviceId();
|
|
34449
34462
|
if (current) return current;
|
|
@@ -35092,7 +35105,9 @@ function recordServerResult(ok, now = Date.now()) {
|
|
|
35092
35105
|
|
|
35093
35106
|
// src/ads/api.ts
|
|
35094
35107
|
var SURFACE_WORKING_BAR = "status_line";
|
|
35095
|
-
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;
|
|
35096
35111
|
return {
|
|
35097
35112
|
server,
|
|
35098
35113
|
async request({ wallet, context, sessionId }) {
|
|
@@ -35105,9 +35120,9 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35105
35120
|
headers: { "Content-Type": "application/json" },
|
|
35106
35121
|
body: JSON.stringify({
|
|
35107
35122
|
user_wallet: wallet,
|
|
35108
|
-
agent
|
|
35123
|
+
agent,
|
|
35109
35124
|
context: context.slice(0, 100),
|
|
35110
|
-
surface
|
|
35125
|
+
surface,
|
|
35111
35126
|
tags: context ? [context] : [],
|
|
35112
35127
|
session_id: sessionId,
|
|
35113
35128
|
device_id: device
|
|
@@ -35134,8 +35149,8 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35134
35149
|
ad_id: ad.ad_id,
|
|
35135
35150
|
user_wallet: wallet,
|
|
35136
35151
|
token: ad.impression_token ?? "",
|
|
35137
|
-
agent
|
|
35138
|
-
surface
|
|
35152
|
+
agent,
|
|
35153
|
+
surface,
|
|
35139
35154
|
context,
|
|
35140
35155
|
device_id: device,
|
|
35141
35156
|
event_uuid: eventUuid,
|
|
@@ -35155,11 +35170,37 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35155
35170
|
return "error";
|
|
35156
35171
|
}
|
|
35157
35172
|
},
|
|
35173
|
+
async creditQuote() {
|
|
35174
|
+
try {
|
|
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
|
+
};
|
|
35183
|
+
} catch {
|
|
35184
|
+
return null;
|
|
35185
|
+
}
|
|
35186
|
+
},
|
|
35158
35187
|
async balance(wallet) {
|
|
35159
35188
|
try {
|
|
35160
35189
|
const res = await fetch(`${server}/earnings/${wallet}`, { signal: AbortSignal.timeout(4e3) });
|
|
35161
35190
|
if (!res.ok) return null;
|
|
35162
|
-
|
|
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) };
|
|
35163
35204
|
} catch {
|
|
35164
35205
|
return null;
|
|
35165
35206
|
}
|
|
@@ -35167,6 +35208,191 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35167
35208
|
};
|
|
35168
35209
|
}
|
|
35169
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
|
+
|
|
35170
35396
|
// src/ui/theme.ts
|
|
35171
35397
|
var C = {
|
|
35172
35398
|
accent: "#A78BFA",
|
|
@@ -35269,20 +35495,31 @@ async function boot(args, focus, report) {
|
|
|
35269
35495
|
return { value, detail: `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only` };
|
|
35270
35496
|
});
|
|
35271
35497
|
const models = new ModelStore();
|
|
35498
|
+
let latentStart;
|
|
35499
|
+
let latentNote = "";
|
|
35272
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
|
+
}
|
|
35273
35510
|
const value = await Promise.all([engine.catalog(), engine.commands()]);
|
|
35274
35511
|
const c = value[0];
|
|
35275
35512
|
const verified = c.models.filter((m) => models.get(m.key)?.status === "ok").length;
|
|
35276
35513
|
return {
|
|
35277
35514
|
value,
|
|
35278
35515
|
status: c.models.length ? "ok" : "warn",
|
|
35279
|
-
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}` : "")
|
|
35280
35517
|
};
|
|
35281
35518
|
});
|
|
35282
35519
|
const permissions = args.auto ? [] : SAFE_PERMISSIONS;
|
|
35283
35520
|
let startNotice;
|
|
35284
35521
|
const session = await step("model", async () => {
|
|
35285
|
-
let start = args.model;
|
|
35522
|
+
let start = args.model ?? (latentStart ? parseKey(latentStart) ?? void 0 : void 0);
|
|
35286
35523
|
if (!start) {
|
|
35287
35524
|
const def = await engine.defaultModel();
|
|
35288
35525
|
const defKey = def ? `${def.providerID}/${def.id}` : null;
|
|
@@ -36023,7 +36260,9 @@ var COMMANDS = [
|
|
|
36023
36260
|
{ name: "providers", desc: "Connected providers and what each one offers", group: "Models" },
|
|
36024
36261
|
{ name: "connect", args: "[provider]", desc: "Connect a provider: API key or account sign-in", group: "Models" },
|
|
36025
36262
|
{ name: "login", desc: "Connect the wallet Earn mode pays into", group: "Earn", aliases: ["wallet"] },
|
|
36026
|
-
{ 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" },
|
|
36027
36266
|
{ name: "ads", args: "on|off", desc: "Turn Earn mode (the sponsored line) on or off", group: "Earn" },
|
|
36028
36267
|
{ name: "new", desc: "Start a fresh session", group: "Session" },
|
|
36029
36268
|
{ name: "compact", desc: "Summarise the conversation to free up context", group: "Session" },
|
|
@@ -36460,154 +36699,6 @@ function ModelPicker(p) {
|
|
|
36460
36699
|
|
|
36461
36700
|
// src/ui/panels/ProviderPanel.tsx
|
|
36462
36701
|
var import_react24 = __toESM(require_react(), 1);
|
|
36463
|
-
|
|
36464
|
-
// src/engine/customProvider.ts
|
|
36465
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync, writeFileSync as writeFileSync4, copyFileSync } from "node:fs";
|
|
36466
|
-
import { homedir as homedir3 } from "node:os";
|
|
36467
|
-
import { join as join6 } from "node:path";
|
|
36468
|
-
var KIND_PACKAGE = {
|
|
36469
|
-
openai: "@opencode/ai/providers/openai-compatible",
|
|
36470
|
-
anthropic: "@opencode/ai/providers/anthropic-compatible"
|
|
36471
|
-
};
|
|
36472
|
-
var KIND_LABEL = {
|
|
36473
|
-
openai: "OpenAI-compatible",
|
|
36474
|
-
anthropic: "Anthropic-compatible"
|
|
36475
|
-
};
|
|
36476
|
-
var CONFIG_FILES = ["opencode.json", "opencode.jsonc"];
|
|
36477
|
-
function slugify(name) {
|
|
36478
|
-
return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
36479
|
-
}
|
|
36480
|
-
function providerIdFor(name, taken, custom) {
|
|
36481
|
-
const base = slugify(name) || "custom";
|
|
36482
|
-
if (custom.has(base) || !taken.has(base)) return base;
|
|
36483
|
-
for (let i = 0; ; i++) {
|
|
36484
|
-
const id = i === 0 ? `${base}-custom` : `${base}-custom-${i + 1}`;
|
|
36485
|
-
if (custom.has(id) || !taken.has(id)) return id;
|
|
36486
|
-
}
|
|
36487
|
-
}
|
|
36488
|
-
function normalizeBaseURL(raw) {
|
|
36489
|
-
const s2 = raw.trim();
|
|
36490
|
-
let u;
|
|
36491
|
-
try {
|
|
36492
|
-
u = new URL(s2);
|
|
36493
|
-
} catch {
|
|
36494
|
-
throw new Error("That is not a URL. Example: https://api.example.com/v1");
|
|
36495
|
-
}
|
|
36496
|
-
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("The base URL must start with https:// or http://");
|
|
36497
|
-
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");
|
|
36498
|
-
return u.toString().replace(/\/+$/, "");
|
|
36499
|
-
}
|
|
36500
|
-
function parseModelList(raw) {
|
|
36501
|
-
const seen = /* @__PURE__ */ new Set();
|
|
36502
|
-
for (const part of raw.split(/[\s,]+/)) {
|
|
36503
|
-
const id = part.trim();
|
|
36504
|
-
if (id) seen.add(id);
|
|
36505
|
-
}
|
|
36506
|
-
return [...seen];
|
|
36507
|
-
}
|
|
36508
|
-
function providerEntry(input) {
|
|
36509
|
-
const models = {};
|
|
36510
|
-
for (const id of input.models) models[id] = { name: id };
|
|
36511
|
-
return {
|
|
36512
|
-
name: input.name.trim(),
|
|
36513
|
-
package: KIND_PACKAGE[input.kind],
|
|
36514
|
-
settings: { baseURL: input.baseURL },
|
|
36515
|
-
models
|
|
36516
|
-
};
|
|
36517
|
-
}
|
|
36518
|
-
function parseJsonc(text) {
|
|
36519
|
-
let out = "";
|
|
36520
|
-
let hadComments = false;
|
|
36521
|
-
let i = 0;
|
|
36522
|
-
while (i < text.length) {
|
|
36523
|
-
const ch = text[i];
|
|
36524
|
-
if (ch === '"') {
|
|
36525
|
-
let j = i + 1;
|
|
36526
|
-
while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
|
|
36527
|
-
out += text.slice(i, j + 1);
|
|
36528
|
-
i = j + 1;
|
|
36529
|
-
} else if (ch === "/" && text[i + 1] === "/") {
|
|
36530
|
-
hadComments = true;
|
|
36531
|
-
while (i < text.length && text[i] !== "\n") i++;
|
|
36532
|
-
} else if (ch === "/" && text[i + 1] === "*") {
|
|
36533
|
-
hadComments = true;
|
|
36534
|
-
const end2 = text.indexOf("*/", i + 2);
|
|
36535
|
-
i = end2 < 0 ? text.length : end2 + 2;
|
|
36536
|
-
} else {
|
|
36537
|
-
if (ch === "}" || ch === "]") {
|
|
36538
|
-
const m = out.match(/,\s*$/);
|
|
36539
|
-
if (m) out = out.slice(0, out.length - m[0].length) + m[0].slice(1);
|
|
36540
|
-
}
|
|
36541
|
-
out += ch;
|
|
36542
|
-
i++;
|
|
36543
|
-
}
|
|
36544
|
-
}
|
|
36545
|
-
return { value: out.trim() ? JSON.parse(out) : {}, hadComments };
|
|
36546
|
-
}
|
|
36547
|
-
function mergeProvider(existing, id, entry) {
|
|
36548
|
-
const { value, hadComments } = existing ? parseJsonc(existing) : { value: {}, hadComments: false };
|
|
36549
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The engine config file is not a JSON object.");
|
|
36550
|
-
const config = value;
|
|
36551
|
-
const providers = config.providers;
|
|
36552
|
-
if (providers !== void 0 && (typeof providers !== "object" || providers === null || Array.isArray(providers))) {
|
|
36553
|
-
throw new Error('The engine config has a "providers" value that is not an object.');
|
|
36554
|
-
}
|
|
36555
|
-
const next = { ...config, providers: { ...providers ?? {}, [id]: entry } };
|
|
36556
|
-
if (!("$schema" in next)) next.$schema = "https://opencode.ai/config.json";
|
|
36557
|
-
return { text: JSON.stringify(next, null, 2) + "\n", hadComments };
|
|
36558
|
-
}
|
|
36559
|
-
function configuredProviderIds(text) {
|
|
36560
|
-
if (!text) return /* @__PURE__ */ new Set();
|
|
36561
|
-
try {
|
|
36562
|
-
const v = parseJsonc(text).value;
|
|
36563
|
-
return new Set(Object.keys(v?.providers ?? {}));
|
|
36564
|
-
} catch {
|
|
36565
|
-
return /* @__PURE__ */ new Set();
|
|
36566
|
-
}
|
|
36567
|
-
}
|
|
36568
|
-
function defaultConfigDir(env3 = process.env) {
|
|
36569
|
-
return join6(env3.XDG_CONFIG_HOME || join6(homedir3(), ".config"), "opencode");
|
|
36570
|
-
}
|
|
36571
|
-
function configFileIn(dir, exists = existsSync5) {
|
|
36572
|
-
const present = CONFIG_FILES.map((f) => join6(dir, f)).filter(exists);
|
|
36573
|
-
return present.at(-1) ?? join6(dir, "opencode.json");
|
|
36574
|
-
}
|
|
36575
|
-
function readConfigText(file) {
|
|
36576
|
-
try {
|
|
36577
|
-
return readFileSync7(file, "utf8");
|
|
36578
|
-
} catch {
|
|
36579
|
-
return null;
|
|
36580
|
-
}
|
|
36581
|
-
}
|
|
36582
|
-
function writeProviderConfig(file, id, input) {
|
|
36583
|
-
const existing = readConfigText(file);
|
|
36584
|
-
const { text, hadComments } = mergeProvider(existing, id, providerEntry(input));
|
|
36585
|
-
mkdirSync4(join6(file, ".."), { recursive: true });
|
|
36586
|
-
let backup;
|
|
36587
|
-
if (existing !== null && hadComments) {
|
|
36588
|
-
backup = file + ".bak";
|
|
36589
|
-
copyFileSync(file, backup);
|
|
36590
|
-
}
|
|
36591
|
-
const tmp = `${file}.${process.pid}.tmp`;
|
|
36592
|
-
writeFileSync4(tmp, text);
|
|
36593
|
-
renameSync(tmp, file);
|
|
36594
|
-
return { file, backup };
|
|
36595
|
-
}
|
|
36596
|
-
async function discoverModels(kind, baseURL, key, timeoutMs = 1e4) {
|
|
36597
|
-
const headers = kind === "anthropic" ? { "anthropic-version": "2023-06-01", ...key ? { "x-api-key": key } : {} } : key ? { authorization: `Bearer ${key}` } : {};
|
|
36598
|
-
const res = await fetch(baseURL + "/models", { headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
36599
|
-
if (!res.ok) throw new Error(`${baseURL}/models answered ${res.status}`);
|
|
36600
|
-
return parseModelsResponse(await res.json());
|
|
36601
|
-
}
|
|
36602
|
-
function parseModelsResponse(body) {
|
|
36603
|
-
const data = body?.data ?? body?.models;
|
|
36604
|
-
if (!Array.isArray(data)) throw new Error("The /models answer has no model list.");
|
|
36605
|
-
return parseModelList(
|
|
36606
|
-
data.map((m) => typeof m === "string" ? m : typeof m === "object" && m ? String(m.id ?? "") : "").join(" ")
|
|
36607
|
-
);
|
|
36608
|
-
}
|
|
36609
|
-
|
|
36610
|
-
// src/ui/panels/ProviderPanel.tsx
|
|
36611
36702
|
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
|
|
36612
36703
|
var usable = (i) => i.methods.filter((m) => m.type === "key" || m.type === "oauth");
|
|
36613
36704
|
var needsForm = (m) => "form" in m && Array.isArray(m.form) && m.form.some((f) => !f.hidden && f.required);
|
|
@@ -37387,6 +37478,25 @@ async function pollDeviceToken(appId, deviceCode, opts) {
|
|
|
37387
37478
|
}
|
|
37388
37479
|
throw new Error("Auth link timed out \u2014 run `latentcode login` again.");
|
|
37389
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
|
+
}
|
|
37390
37500
|
async function resolveSession(server, accessToken, fetchImpl = fetch) {
|
|
37391
37501
|
const res = await fetchImpl(`${trimServer(server)}/auth/session`, {
|
|
37392
37502
|
method: "POST",
|
|
@@ -37439,12 +37549,24 @@ You can still connect an address you control: latentcode login --wallet 0x\u2026
|
|
|
37439
37549
|
sleep: deps2.sleep,
|
|
37440
37550
|
now: deps2.now
|
|
37441
37551
|
});
|
|
37442
|
-
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);
|
|
37443
37554
|
if (!WALLET_RE.test(earner.wallet)) throw new Error("The server returned an invalid wallet address.");
|
|
37444
37555
|
const prev = deps2.load().wallet;
|
|
37445
|
-
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
|
+
});
|
|
37446
37562
|
deps2.log(`Signed in. Earn mode pays into ${short(earner.wallet)}.`);
|
|
37447
|
-
|
|
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
|
+
};
|
|
37448
37570
|
}
|
|
37449
37571
|
|
|
37450
37572
|
// src/ui/panels/WalletPanel.tsx
|
|
@@ -37456,6 +37578,7 @@ var deps = (server, extra) => ({
|
|
|
37456
37578
|
open: openUrl,
|
|
37457
37579
|
load: loadConfig,
|
|
37458
37580
|
save: (patch) => void saveConfig(patch),
|
|
37581
|
+
deviceId: deviceKeyId,
|
|
37459
37582
|
...extra
|
|
37460
37583
|
});
|
|
37461
37584
|
function WalletPanel(p) {
|
|
@@ -37495,7 +37618,7 @@ function Menu(p) {
|
|
|
37495
37618
|
color: C.earn,
|
|
37496
37619
|
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "continue"], ["esc", "close"]] }),
|
|
37497
37620
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37498
|
-
/* @__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
|
|
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:" }),
|
|
37499
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: [
|
|
37500
37623
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37501
37624
|
i === sel ? G.prompt : " ",
|
|
@@ -37589,7 +37712,7 @@ function Address(p) {
|
|
|
37589
37712
|
color: C.earn,
|
|
37590
37713
|
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "save"], ["esc", "back"]] }),
|
|
37591
37714
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37592
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, 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." }),
|
|
37593
37716
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37594
37717
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37595
37718
|
G.earn,
|
|
@@ -37619,6 +37742,8 @@ function Done2(p) {
|
|
|
37619
37742
|
|
|
37620
37743
|
// src/ui/App.tsx
|
|
37621
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" };
|
|
37622
37747
|
var notice = (text, tone = "info") => ({
|
|
37623
37748
|
type: "latentcode.notice",
|
|
37624
37749
|
created: Date.now(),
|
|
@@ -37787,11 +37912,15 @@ function App2(props) {
|
|
|
37787
37912
|
const say = (text, tone = "info") => dispatch(notice(text, tone));
|
|
37788
37913
|
const statusOf = (key) => store.get(key)?.status ?? "unknown";
|
|
37789
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]);
|
|
37790
37919
|
props.summary.current = {
|
|
37791
37920
|
turns: state.turns,
|
|
37792
37921
|
tokens: state.tokens.input + state.tokens.output,
|
|
37793
37922
|
cost: state.cost,
|
|
37794
|
-
earned: ad.sessionEarned,
|
|
37923
|
+
earned: credits(ad.sessionEarned, bonus),
|
|
37795
37924
|
impressions: ad.impressions
|
|
37796
37925
|
};
|
|
37797
37926
|
(0, import_react26.useEffect)(() => {
|
|
@@ -37862,6 +37991,19 @@ function App2(props) {
|
|
|
37862
37991
|
function changeWallet(next) {
|
|
37863
37992
|
setWallet(next);
|
|
37864
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
|
+
}
|
|
37865
38007
|
}
|
|
37866
38008
|
async function runCommand(line) {
|
|
37867
38009
|
const { name, arg } = parseCommandLine(line);
|
|
@@ -37913,13 +38055,54 @@ function App2(props) {
|
|
|
37913
38055
|
say("No wallet connected yet. /login takes a minute and you start earning right away.", "warn");
|
|
37914
38056
|
return;
|
|
37915
38057
|
}
|
|
37916
|
-
const
|
|
38058
|
+
const c = await api.creditSummary(wallet);
|
|
38059
|
+
const hasLatent = catalog.providers.some((p) => p.id === LATENT_PROVIDER_ID);
|
|
38060
|
+
say(
|
|
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).`)
|
|
38065
|
+
);
|
|
38066
|
+
return;
|
|
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
|
+
}
|
|
37917
38078
|
say(
|
|
37918
|
-
|
|
37919
|
-
|
|
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")
|
|
37920
38086
|
);
|
|
37921
38087
|
return;
|
|
37922
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
|
+
}
|
|
37923
38106
|
case "status": {
|
|
37924
38107
|
const prov = catalog.providers.map((p) => p.name).join(", ");
|
|
37925
38108
|
say(
|
|
@@ -37927,7 +38110,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37927
38110
|
`Model ${describeModel(state.model, catalog)}${state.variant ? ` \xB7 effort ${state.variant}` : ""}`,
|
|
37928
38111
|
`Providers ${prov || "none"}`,
|
|
37929
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)}` : ""}`,
|
|
37930
|
-
`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"}`,
|
|
37931
38114
|
`Safety ${props.permissions.length ? "asks before shell commands and file changes" : "--auto (no confirmation)"}`
|
|
37932
38115
|
].join("\n")
|
|
37933
38116
|
);
|
|
@@ -38155,9 +38338,9 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
38155
38338
|
] }) }),
|
|
38156
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: [
|
|
38157
38340
|
G.earn,
|
|
38158
|
-
"
|
|
38159
|
-
ad.sessionEarned.toFixed(
|
|
38160
|
-
" earned",
|
|
38341
|
+
" ",
|
|
38342
|
+
credits(ad.sessionEarned, bonus).toFixed(3),
|
|
38343
|
+
" cr earned",
|
|
38161
38344
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38162
38345
|
" \xB7 ",
|
|
38163
38346
|
ad.impressions,
|
|
@@ -38427,7 +38610,7 @@ function row(mark, label2, value, width = 10) {
|
|
|
38427
38610
|
|
|
38428
38611
|
// src/index.tsx
|
|
38429
38612
|
var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
|
|
38430
|
-
var VERSION = "0.1.0-alpha.
|
|
38613
|
+
var VERSION = "0.1.0-alpha.6";
|
|
38431
38614
|
var usage = () => `${logo()}
|
|
38432
38615
|
${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
|
|
38433
38616
|
|
|
@@ -38487,7 +38670,8 @@ function loginDeps() {
|
|
|
38487
38670
|
log: (l) => process.stdout.write(styleLoginLine(l) + "\n"),
|
|
38488
38671
|
open: openUrl,
|
|
38489
38672
|
load: loadConfig,
|
|
38490
|
-
save: (patch) => void saveConfig(patch)
|
|
38673
|
+
save: (patch) => void saveConfig(patch),
|
|
38674
|
+
deviceId: deviceKeyId
|
|
38491
38675
|
};
|
|
38492
38676
|
}
|
|
38493
38677
|
function styleLoginLine(l) {
|
|
@@ -38535,7 +38719,7 @@ async function status() {
|
|
|
38535
38719
|
if (wallet) {
|
|
38536
38720
|
const bal = await httpAdApi(server).balance(wallet);
|
|
38537
38721
|
lines.push(
|
|
38538
|
-
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)")}`)
|
|
38539
38723
|
);
|
|
38540
38724
|
}
|
|
38541
38725
|
process.stdout.write(lines.join("\n") + "\n");
|
|
@@ -38544,7 +38728,7 @@ function goodbye(s2) {
|
|
|
38544
38728
|
const parts = s2.turns ? [`${s2.turns} turn${s2.turns === 1 ? "" : "s"}`] : [];
|
|
38545
38729
|
if (s2.tokens) parts.push(`${fmtTokens(s2.tokens)} tokens`);
|
|
38546
38730
|
if (s2.cost) parts.push(`$${s2.cost.toFixed(3)} model cost`);
|
|
38547
|
-
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"}`) : "";
|
|
38548
38732
|
return ` ${a.dim(parts.join(" \xB7 "))}${earned ? ` ${earned}` : ""}
|
|
38549
38733
|
`;
|
|
38550
38734
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latentcode",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "Terminal coding agent that pays you for idle time. Bring your own subscription; the model is never for sale.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,8 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@babel/core": "^7.29.13",
|
|
26
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
25
27
|
"@types/node": "^26.6.6",
|
|
26
28
|
"@types/react": "^18.3.31",
|
|
29
|
+
"babel-preset-solid": "^1.9.19",
|
|
27
30
|
"esbuild": "^0.28.2",
|
|
28
31
|
"ink": "^5.2.1",
|
|
29
32
|
"react": "^18.3.1",
|